From rantingrick at gmail.com Mon Nov 1 00:00:32 2010 From: rantingrick at gmail.com (rantingrick) Date: Sun, 31 Oct 2010 21:00:32 -0700 (PDT) Subject: I heard about python needing some sort of _VariableName_ boiler plate? References: Message-ID: <49ac60cd-9c07-4f9d-8ac6-58bdaec42993@c20g2000yqj.googlegroups.com> On Oct 31, 10:18?pm, Chris Rebert wrote: > On Sun, Oct 31, 2010 at 7:09 PM, Braden Faulkner wrote: > > I heard about python needing some sort of _VariableName_ boiler plate? > > Can anyone explain to me how this works, I don't seem to have to do it in > > IDLE? Oh thats just more FUD and spin from the legions of "Perl mongers" and "Lisp leaches" who continually try to sow discontent within the ranks of our newbies here at c.l.p. As you have found yourself Python is a super clean language. However, since they cannot argue the language on merits and facts they will resort to these despicable (and might i say desperate) lies and political propagandas in a feeble attempt to sway the masses against us. However, do not be fearful of their threats or influenced by such bombastic claims and nonsensical rubbish. Go and tell Xerxes he faces free men here... not slaves! From rantingrick at gmail.com Mon Nov 1 00:34:46 2010 From: rantingrick at gmail.com (rantingrick) Date: Sun, 31 Oct 2010 21:34:46 -0700 (PDT) Subject: I heard about python needing some sort of_VariableName_ boiler plate? References: Message-ID: <37de0154-f623-41e7-8268-2bad525357c0@s4g2000yql.googlegroups.com> On Oct 31, 10:37?pm, brad... at hotmail.com wrote: > Sorry, to clarify I heard that when you declare a variable in python you have to use some sort of standard boiler plate _variable_ however this has not been my experience using IDLE so is this even true? Halloween night and i am bored... hmm... i know! plan A: Ask a really perplexing and insane question on c.l.p. ...hmm, well i did not get the answer i wanted so i'll just open a new thread and... plan B: Ask ask the same question again! ...surely i'll get a better answer with this plan!! urm, rinse and repeat maybe? From rantingrick at gmail.com Mon Nov 1 00:37:37 2010 From: rantingrick at gmail.com (rantingrick) Date: Sun, 31 Oct 2010 21:37:37 -0700 (PDT) Subject: I heard about python needing some sort of_VariableName_ boiler plate? References: Message-ID: Brad, Serously, i have never heard of any boilerplate variables in Python. Could you show us an example using Python code that compiles? Of could you even show us some puesdo that resembles any thing that you are suggesting? I am perplexed! Is this a troll or are you really serious? From lanyjie at yahoo.com Mon Nov 1 00:44:47 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Sun, 31 Oct 2010 21:44:47 -0700 (PDT) Subject: A bug for raw string literals in Py3k? In-Reply-To: <4CCE395D.9050806@mrabarnett.plus.com> Message-ID: <935717.4038.qm@web54206.mail.re2.yahoo.com> > According to msg56377, the behaviour is "optimal" for regular > expressions. Well, I use regular expressions a lot, and I > still think it's a nuisance! Thanks for bringing that up. Using an otherwise 'dead' backlash to escape quotes in raw strings seems like the black magic of necromancy to me. :) To include quotes in a string, there are a couple of known choices: If you need single quotes in the string, start the literal by a double-quote, and vice versa. In case you need both, you can use a long string: >>> r''''ab\c"''' Note that when the last character is also a quote, we can use the other type of quote three times to delimit the long string. Of course, there are still some corner cases: 1. when we need three consecutive single quotes AND three consecutive double quotes in the string. 2. When the last is a single quote, and we also need three consecutive double-quotes in the string, or the other way around. Then we can abandon the raw string literal, or use concatenation of string literals wisely to get it done. But in total, I still would vote against the nacromancy. Yingjie From prologic at shortcircuit.net.au Mon Nov 1 00:50:04 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Mon, 1 Nov 2010 14:50:04 +1000 Subject: [Beginer Question] I heard about python needing some sort of_VariableName_ boiler plate? In-Reply-To: <2112376356-1288582649-cardhu_decombobulator_blackberry.rim.net-1426431676-@bda480.bisx.prod.on.blackberry> References: <2112376356-1288582649-cardhu_decombobulator_blackberry.rim.net-1426431676-@bda480.bisx.prod.on.blackberry> Message-ID: On Mon, Nov 1, 2010 at 1:37 PM, wrote: > Sorry, to clarify I heard that when you declare a variable in python you have to use some sort of standard boiler plate _variable_ however this has not been my experience using IDLE so is this even true? Boilerplate, what boilerplate ? To define variables, just assign a value to a name: >>> x = 1 >>> x 1 cheers James -- -- James Mills -- -- "Problems are solved by method" From ben+python at benfinney.id.au Mon Nov 1 00:51:42 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 01 Nov 2010 15:51:42 +1100 Subject: [Beginer Question] I heard about python needing some sort of_VariableName_ boiler plate? References: Message-ID: <878w1dlk81.fsf@benfinney.id.au> bradenf at hotmail.com writes: > Sorry, to clarify I heard that when you declare a variable in python > you have to use some sort of standard boiler plate _variable_ however > this has not been my experience using IDLE so is this even true? I don't know what ?some sort of boiler plate _variable_? might mean. Can you point to someone's actual message saying this, so we can see what they might be talking about? -- \ ?With Lisp or Forth, a master programmer has unlimited power | `\ and expressiveness. With Python, even a regular guy can reach | _o__) for the stars.? ?Raymond Hettinger | Ben Finney From lanyjie at yahoo.com Mon Nov 1 01:03:52 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Sun, 31 Oct 2010 22:03:52 -0700 (PDT) Subject: with block for multiple files Message-ID: <942901.77636.qm@web54203.mail.re2.yahoo.com> Hi, Suppose I am working with two files simultaneously, it might make sense to do this: with open('scores.csv'), open('grades.csv', wt) as f,g: g.write(f.read()) sure, you can do this with nested with-blocks, but the one above does not seem too complicated, it is like having a multiple assignment... Any thoughts? Another mini-proposal: Allow the conditions in the if-, elif-, while-, for-, and with-clauses to span multiple lines without using a backlalsh, just like when you specify literal lists, tuples, dicts, etc. across multiple lines (similar to comprehensions too). My reason is this: because they all must end with a required colon ':', so nobody will mistake it. Just some half-baked ideas, would appreciate thos who shed light on these issues. Yingjie From clp2 at rebertia.com Mon Nov 1 01:10:25 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 31 Oct 2010 22:10:25 -0700 Subject: with block for multiple files In-Reply-To: <942901.77636.qm@web54203.mail.re2.yahoo.com> References: <942901.77636.qm@web54203.mail.re2.yahoo.com> Message-ID: On Sun, Oct 31, 2010 at 10:03 PM, Yingjie Lan wrote: > Hi, > > Suppose I am working with two files simultaneously, > it might make sense to do this: > > with open('scores.csv'), open('grades.csv', wt) as f,g: > ? ? g.write(f.read()) > > sure, you can do this with nested with-blocks, > but the one above does not seem too complicated, > it is like having a multiple assignment... > > Any thoughts? Guido's time machine strikes again! It's already in Python 3; your example would be spelled: with open('scores.csv') as f, open('grades.csv', wt) as g: g.write(f.read()) Cheers, Chris -- Where does GvR source his flux capacitors from? http://blog.rebertia.com From prologic at shortcircuit.net.au Mon Nov 1 01:13:44 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Mon, 1 Nov 2010 15:13:44 +1000 Subject: with block for multiple files In-Reply-To: <942901.77636.qm@web54203.mail.re2.yahoo.com> References: <942901.77636.qm@web54203.mail.re2.yahoo.com> Message-ID: On Mon, Nov 1, 2010 at 3:03 PM, Yingjie Lan wrote: > with open('scores.csv'), open('grades.csv', wt) as f,g: > ? ? g.write(f.read()) One could write their own ContextManager here... cheers James -- -- James Mills -- -- "Problems are solved by method" From lanyjie at yahoo.com Mon Nov 1 02:02:21 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Sun, 31 Oct 2010 23:02:21 -0700 (PDT) Subject: Allow multiline conditions and the like Message-ID: <291834.82757.qm@web54201.mail.re2.yahoo.com> Hi, This is a mini-proposal I piggy-tailed in the other topic: Allow the conditions in the if-, elif-, while-, for-, and with-clauses to span multiple lines without using a backlalsh at the end of a line, just like when you specify literal lists, tuples, dicts, etc. across multiple lines (similar to comprehensions too). My reasons: because they all must end with a required colon ':', so nobody will mistake it. also, if we don't allow it, people just have to use parenthesis around the expressions to make that happen. Just a half-baked idea, appreciate all comments. Yingjie From lanyjie at yahoo.com Mon Nov 1 02:05:00 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Sun, 31 Oct 2010 23:05:00 -0700 (PDT) Subject: with block for multiple files In-Reply-To: Message-ID: <403882.60405.qm@web54208.mail.re2.yahoo.com> > Guido's time machine strikes again! It's already in Python > 3; your > example would be spelled: > > with open('scores.csv') as f, open('grades.csv', wt) as g: > ? ? g.write(f.read()) > Indeed! Thanks, Chris and James. Yingjie From lanyjie at yahoo.com Mon Nov 1 02:13:19 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Sun, 31 Oct 2010 23:13:19 -0700 (PDT) Subject: Allowing comments after the line continuation backslash Message-ID: <628312.39922.qm@web54205.mail.re2.yahoo.com> Hi, Sorry if I am baking too many ideas today. I am just having trouble with the backslashes.... I would like to have comments after the line continuation backslash. >>> if a > 0 \ #comments for this condition and b > 0: #do something here This is currently not OK, but this might be a good thing to have. Yingjie From charugangal at gmail.com Mon Nov 1 02:16:11 2010 From: charugangal at gmail.com (charu gangal) Date: Sun, 31 Oct 2010 23:16:11 -0700 (PDT) Subject: python script to read google spreadsheet Message-ID: <0b6f704c-e108-4fb9-afc2-3616d92d6694@t13g2000yqm.googlegroups.com> import gdata.spreadsheet.service username = 'prakhil.purchase at gmail.com' passwd = 'purchase' doc_name = 'googleapps_spreadsheet' gd_client = gdata.spreadsheet.service.SpreadsheetsService() gd_client.email = username gd_client.password =passwd #gd_client.source = 'pythonsample12' gd_client.ProgrammaticLogin() q = gdata.spreadsheet.service.DocumentQuery() q['title'] = doc_name q['title-exact'] = 'true' feed = gd_client.GetSpreadsheetsFeed(query=q) spreadsheet_id = feed.entry[0].id.text.rsplit('/',1)[1] feed = gd_client.GetWorksheetsFeed(spreadsheet_id) worksheet_id = feed.entry[0].id.text.rsplit('/',1)[1] rows = gd_client.GetListFeed(spreadsheet_id, worksheet_id).entry for row in rows: for key in row.custom: print " %s: %s" % (key, row.custom[key].text) This is the python code I was trying to access the cell information from a google spreadsheet but the issue is that i am able to make it work on Eclipse but when i deploy it, it is not showing me the result. Maybe I am missing some of the google packages to import that is making it unable to run on google environment. Kindly guide me.Thanks in advance. From iwawi123 at gmail.com Mon Nov 1 02:46:29 2010 From: iwawi123 at gmail.com (iwawi) Date: Sun, 31 Oct 2010 23:46:29 -0700 (PDT) Subject: text file reformatting References: <78daefd1-59a1-4b3a-9bc2-5910315515ce@r14g2000yqa.googlegroups.com> Message-ID: <57ec83dd-3f30-4000-acf6-f49a44568d22@k22g2000yqh.googlegroups.com> On 31 loka, 21:48, Tim Chase wrote: > > PRJ01001 4 00100END > > PRJ01002 3 00110END > > > I would like to pick only some columns to a new file and put them to a > > certain places (to match previous data) - definition file (def.csv) > > could be something like this: > > > VARIABLE ? FIELDSTARTS ? ? FIELD SIZE ? ? ?NEW PLACE IN NEW DATA FILE > > ProjID ? ? ; ? ? ? 1 ? ? ? ; ? ? ? 5 ? ? ? ; ? ? ? 1 > > CaseID ? ? ; ? ? ? 6 ? ? ? ; ? ? ? 3 ? ? ? ; ? ? ? 10 > > UselessV ?; ? ? ? ?10 ? ? ?; ? ? ? 1 ? ? ? ; > > Zipcode ? ?; ? ? ? 12 ? ? ?; ? ? ? 5 ? ? ? ; ? ? ? 15 > > > So the new datafile should look like this: > > > PRJ01 ? ?001 ? ? ? 00100END > > PRJ01 ? ?002 ? ? ? 00110END > > How flexible is the def.csv format? ?The difficulty I see with > your def.csv format is that it leaves undefined gaps (presumably > to be filled in with spaces) and that you also have a blank "new > place in new file" value. ?If instead, you could specify the > width to which you want to pad it and omit variables you don't > want in the output, ordering the variables in the same order you > want them in the output: > > ? Variable; Start; Size; Width > ? ProjID; 1; 5; 10 > ? CaseID; 6; 3; 10 > ? Zipcode; 12; 5; 5 > ? End; 16; 3; 3 > > (note that I lazily use the same method to copy the END from the > source to the destination, rather than coding specially for it) > you could do something like this (untested) > > ? ?import csv > ? ?f = file('def.csv', 'rb') > ? ?f.next() # discard the header row > ? ?r = csv.reader(f, delimiter=';') > ? ?fields = [ > ? ? ?(varname, slice(int(start), int(start)+int(size)), width) > ? ? ?for varname, start, size, width > ? ? ?in r > ? ? ?] > ? ?f.close() > ? ?out = file('out.txt', 'w') > ? ?try: > ? ? ?for row in file('data.txt'): > ? ? ? ?for varname, slc, width in fields: > ? ? ? ? ?out.write(row[slc].ljust(width)) > ? ? ? ?out.write('\n') > ? ?finally: > ? ? ?out.close() > > Hope that's fairly easy to follow and makes sense. ?There might > be some fence-posting errors (particularly your use of "1" as the > initial offset, while python uses "0" as the initial offset for > strings) > > If you can't modify the def.csv format, then things are a bit > more complex and I'd almost be tempted to write a script to try > and convert your existing def.csv format into something simpler > to process like what I describe. > > -tkc- Piilota siteerattu teksti - > > - N?yt? siteerattu teksti - Hi, Thanks for your reply. Def.csv could be modified so that every line has the same structure: variable name, field start, field size and new place and would be separated with semicolomns as you mentioned. I tried your script (which seems quite logical) but I get this Traceback (most recent call last): File "testing.py", line 16, in out.write (row[slc].ljust(width)) TypeError: an integer is required Yes - you said it was untested, but I can't figure out how to proceed... From bob.martin at excite.com Mon Nov 1 03:01:08 2010 From: bob.martin at excite.com (Bob Martin) Date: Mon, 01 Nov 2010 07:01:08 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> Message-ID: <8j76tkFs4dU1@mid.individual.net> in 645437 20101031 230912 Lawrence D'Oliveiro wrote: >In message <4ccd5ad9$0$19151$426a74cc at news.free.fr>, jf wrote: > >> I edit each file to remove tabs ... > >expand -i newfile > >> Do you know a tools to compare the initial file with the cleaned one to >> know if the algorithms are the same ? > >diff -b oldfile newfile meld From ben+python at benfinney.id.au Mon Nov 1 03:13:13 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 01 Nov 2010 18:13:13 +1100 Subject: Allow multiline conditions and the like References: Message-ID: <874oc1ldo6.fsf@benfinney.id.au> Yingjie Lan writes: > Allow the conditions in the if-, elif-, while-, for-, and with-clauses > to span multiple lines without using a backlalsh at the end of a line, You can already do this with any expression: use parentheses. Yingjie Lan writes: > I would like to have comments after the line continuation backslash. I have almost never needed a line continuation backslash; I consider them a code smell. > >>> if a > 0 \ #comments for this condition > and b > 0: > #do something here if (a > 0 # Comments for this condition and b > 0): # Do something here -- \ ?Alternative explanations are always welcome in science, if | `\ they are better and explain more. Alternative explanations that | _o__) explain nothing are not welcome.? ?Victor J. Stenger, 2001-11-05 | Ben Finney From ldo at geek-central.gen.new_zealand Mon Nov 1 03:16:34 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 01 Nov 2010 20:16:34 +1300 Subject: Allow multiline conditions and the like References: <874oc1ldo6.fsf@benfinney.id.au> Message-ID: In message <874oc1ldo6.fsf at benfinney.id.au>, Ben Finney wrote: > Yingjie Lan writes: > >> Allow the conditions in the if-, elif-, while-, for-, and with-clauses >> to span multiple lines without using a backlalsh at the end of a line, > > You can already do this with any expression: use parentheses. It?s easy enough to do things like this: if ( TheMesh.vertices[OtherVertex].select and OtherVertex != ThatVertex and OtherVertex != ThisLine[-2] and OtherVertex != ThisVertex ) : ... #end if From ldo at geek-central.gen.new_zealand Mon Nov 1 03:18:34 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 01 Nov 2010 20:18:34 +1300 Subject: Allowing comments after the line continuation backslash References: Message-ID: In message , Yingjie Lan wrote: > I would like to have comments after the line continuation backslash. What language allows that? From ldo at geek-central.gen.new_zealand Mon Nov 1 03:20:42 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 01 Nov 2010 20:20:42 +1300 Subject: How on Factorial References: <1cf81147-06f4-4e48-9255-ea87bf3f93be@k22g2000yqh.googlegroups.com> Message-ID: In message , Ulrich Eckhardt wrote: > Geobird wrote: > >> def fact(x): >> return x > 1 and x * fact(x - 1) or 1 > > I'd say this is about as small as it gets. fact = lambda x : x > 1 and x * fact(x - 1) or 1 -- Lawrence ?Functionalism Strikes Again? D?Oliveiro From ldo at geek-central.gen.new_zealand Mon Nov 1 03:23:42 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 01 Nov 2010 20:23:42 +1300 Subject: How on Factorial References: <1cf81147-06f4-4e48-9255-ea87bf3f93be@k22g2000yqh.googlegroups.com> <85dcd37b-871d-4058-b6af-8fc825afcc96@a37g2000yqi.googlegroups.com> Message-ID: In message , Jussi Piitulainen wrote: > (I agree that no one should write factorial like that, except as > a joke. I have nothing against (x if (a > b) else y). The trick > with and and or was used before Python had an actual conditional > expression.) You know what, I think I actually prefer the trick to Python?s backwards-if syntax... From ldo at geek-central.gen.new_zealand Mon Nov 1 03:26:18 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 01 Nov 2010 20:26:18 +1300 Subject: Why "flat is better than nested"? References: <4CC58C87.6030306@chamonix.reportlab.co.uk> Message-ID: In message , Stefan Behnel wrote: > What's a "that boy"? A boy who?s the opposite of fin. From martin at v.loewis.de Mon Nov 1 03:44:54 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Mon, 01 Nov 2010 08:44:54 +0100 Subject: Allowing comments after the line continuation backslash In-Reply-To: References: Message-ID: <4CCE6FF6.2050408@v.loewis.de> > Sorry if I am baking too many ideas today. > I am just having trouble with the backslashes.... > > I would like to have comments after the line continuation backslash. > >>>> if a > 0 \ #comments for this condition > and b > 0: > #do something here > > This is currently not OK, but this might be a good thing to have. Can you say why it would be a good idea? FWIW, I would write your fragment as if (a > 0 #comments for this condition and b > 0): #do something here i.e. avoid the backslash for multi-line conditions altogether (in fact, I can't think any situation where I would use the backslash). Regards, Martin From ldo at geek-central.gen.new_zealand Mon Nov 1 03:46:22 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 01 Nov 2010 20:46:22 +1300 Subject: python script to read google spreadsheet References: <0b6f704c-e108-4fb9-afc2-3616d92d6694@t13g2000yqm.googlegroups.com> Message-ID: In message <0b6f704c-e108-4fb9-afc2-3616d92d6694 at t13g2000yqm.googlegroups.com>, charu gangal wrote: > This is the python code I was trying to access the cell information > from a google spreadsheet but the issue is that i am able to make it > work on Eclipse but when i deploy it, it is not showing me the result. What does it do instead? From eckhardt at satorlaser.com Mon Nov 1 03:50:36 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Mon, 01 Nov 2010 08:50:36 +0100 Subject: Allowing comments after the line continuation backslash References: Message-ID: Yingjie Lan wrote: > I would like to have comments after the line continuation backslash. > >>>> if a > 0 \ #comments for this condition > and b > 0: > #do something here Historically, and also in Python, the backslash escapes the immediately following character. That means that _nothing_ may follow the backslash and that the backslash is not a "line continuation backslash" per se. Now, there are ways around this, just add parens: if (a > 0 and b > 0): Note that this also applies to (), [] and {} when forming tuples, lists and dicts, which you can spread across different lines. > This is currently not OK, but this might be a good thing to have. I'd actually argue that even the currently used backslash is a bad idea to have. Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From steve-REMOVE-THIS at cybersource.com.au Mon Nov 1 03:51:50 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 01 Nov 2010 07:51:50 GMT Subject: Allow multiline conditions and the like References: Message-ID: <4cce7196$0$29965$c3e8da3$5496439d@news.astraweb.com> On Sun, 31 Oct 2010 23:02:21 -0700, Yingjie Lan wrote: > Hi, > > This is a mini-proposal I piggy-tailed in the other topic: > > Allow the conditions in the if-, elif-, while-, for-, and with-clauses > to span multiple lines [...] > also, if we don't allow it, people just have to use > parenthesis around the expressions to make that happen. You say that like it's a bad thing. That is kind of like saying "We should allow people to speed through red traffic lights, because if we don't, they'll just wait for the light to turn green!". Er, yes, and the problem is? If you need a multi-line conditional, wrap it in parentheses. -- Steven From cbrown at cbrownsystems.com Mon Nov 1 03:59:10 2010 From: cbrown at cbrownsystems.com (cbrown at cbrownsystems.com) Date: Mon, 1 Nov 2010 00:59:10 -0700 (PDT) Subject: text file reformatting References: <78daefd1-59a1-4b3a-9bc2-5910315515ce@r14g2000yqa.googlegroups.com> <57ec83dd-3f30-4000-acf6-f49a44568d22@k22g2000yqh.googlegroups.com> Message-ID: On Oct 31, 11:46?pm, iwawi wrote: > On 31 loka, 21:48, Tim Chase wrote: > > > > > > PRJ01001 4 00100END > > > PRJ01002 3 00110END > > > > I would like to pick only some columns to a new file and put them to a > > > certain places (to match previous data) - definition file (def.csv) > > > could be something like this: > > > > VARIABLE ? FIELDSTARTS ? ? FIELD SIZE ? ? ?NEW PLACE IN NEW DATA FILE > > > ProjID ? ? ; ? ? ? 1 ? ? ? ; ? ? ? 5 ? ? ? ; ? ? ? 1 > > > CaseID ? ? ; ? ? ? 6 ? ? ? ; ? ? ? 3 ? ? ? ; ? ? ? 10 > > > UselessV ?; ? ? ? ?10 ? ? ?; ? ? ? 1 ? ? ? ; > > > Zipcode ? ?; ? ? ? 12 ? ? ?; ? ? ? 5 ? ? ? ; ? ? ? 15 > > > > So the new datafile should look like this: > > > > PRJ01 ? ?001 ? ? ? 00100END > > > PRJ01 ? ?002 ? ? ? 00110END > > > How flexible is the def.csv format? ?The difficulty I see with > > your def.csv format is that it leaves undefined gaps (presumably > > to be filled in with spaces) and that you also have a blank "new > > place in new file" value. ?If instead, you could specify the > > width to which you want to pad it and omit variables you don't > > want in the output, ordering the variables in the same order you > > want them in the output: > > > ? Variable; Start; Size; Width > > ? ProjID; 1; 5; 10 > > ? CaseID; 6; 3; 10 > > ? Zipcode; 12; 5; 5 > > ? End; 16; 3; 3 > > > (note that I lazily use the same method to copy the END from the > > source to the destination, rather than coding specially for it) > > you could do something like this (untested) > > > ? ?import csv > > ? ?f = file('def.csv', 'rb') > > ? ?f.next() # discard the header row > > ? ?r = csv.reader(f, delimiter=';') > > ? ?fields = [ > > ? ? ?(varname, slice(int(start), int(start)+int(size)), width) > > ? ? ?for varname, start, size, width > > ? ? ?in r > > ? ? ?] > > ? ?f.close() > > ? ?out = file('out.txt', 'w') > > ? ?try: > > ? ? ?for row in file('data.txt'): > > ? ? ? ?for varname, slc, width in fields: > > ? ? ? ? ?out.write(row[slc].ljust(width)) > > ? ? ? ?out.write('\n') > > ? ?finally: > > ? ? ?out.close() > > > Hope that's fairly easy to follow and makes sense. ?There might > > be some fence-posting errors (particularly your use of "1" as the > > initial offset, while python uses "0" as the initial offset for > > strings) > > > If you can't modify the def.csv format, then things are a bit > > more complex and I'd almost be tempted to write a script to try > > and convert your existing def.csv format into something simpler > > to process like what I describe. > > > -tkc- Piilota siteerattu teksti - > > > - N?yt? siteerattu teksti - > > Hi, > > Thanks for your reply. > > Def.csv could be modified so that every line has the same structure: > variable name, field start, field size and new place and would be > separated with semicolomns as you mentioned. > > I tried your script (which seems quite logical) but I get this > > Traceback (most recent call last): > ? File "testing.py", line 16, in > ? ? out.write (row[slc].ljust(width)) > TypeError: an integer is required > > Yes - you said it was untested, but I can't figure out how to > proceed... The line (varname, slice(int(start), int(start)+int(size)), width) should instead be (varname, slice(int(start), int(start)+int(size)), int(width)) although you give an example where there is no width - what does that imply? In the above case, it will throw an exception. Anyway, I think you'll find there's something a bit off in the output loop with the parameter passed to ljust() as well. The value given in your csv seems to be the absolute position, but as it's implemented by Tim, it acts as the relative position. Given Tim's parsing into the list fields, I have a feeling that what you really want instead of for varname, slc, width in fields: out.write(row[slc].ljust(width)) out.write('\n') is to have s = '' for varname, slc, width in fields: s += " "*(width - len(s)) + row[slc] out.write(s+'\n') And if that is what you want, then you will surely want to globally replace the name 'width' with for example 'start_column', because then it all makes sense :). Cheers - Chas From steve-REMOVE-THIS at cybersource.com.au Mon Nov 1 04:02:37 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 01 Nov 2010 08:02:37 GMT Subject: Allowing comments after the line continuation backslash References: Message-ID: <4cce741d$0$29965$c3e8da3$5496439d@news.astraweb.com> On Sun, 31 Oct 2010 23:13:19 -0700, Yingjie Lan wrote: > Hi, > > Sorry if I am baking too many ideas today. I am just having trouble with > the backslashes.... Then don't use them. If you are having so much trouble keeping your lines short, then I suggest you're trying to do too much in one line. > I would like to have comments after the line continuation backslash. > >>>> if a > 0 \ #comments for this condition > and b > 0: > #do something here I'm actually sympathetic to the idea of having a backslash followed by any whitespace mean line continuation, allowing comments after the line. The problem is, what should you do here? Presumably if you follow the backslash with anything other than whitespace or a comment, you get a SyntaxError: if a > 0 \ and b > 0: # do something In any case, there is a moratorium on language changes, so it will probably be 2 or 3 years before this could even be considered. What you can do instead: if a > 0 and b > 0: # comment for a condition # comment for b condition do_something() There's nothing wrong with that. But if you insist on in-line comments: if (a > 0 # comment for a condition and b > 0 # comment for b condition ): do_something() But best of all, write literate code that doesn't need comments because it documents itself: if number_of_pages > 0 and not all(page.is_blank() for page in pages): do_something() -- Steven From charugangal at gmail.com Mon Nov 1 04:14:09 2010 From: charugangal at gmail.com (charu gangal) Date: Mon, 1 Nov 2010 01:14:09 -0700 (PDT) Subject: python script to read google spreadsheet References: <0b6f704c-e108-4fb9-afc2-3616d92d6694@t13g2000yqm.googlegroups.com> Message-ID: <45e3864a-6a63-49e9-ae0f-df3aeb8740c5@j2g2000yqf.googlegroups.com> This is the page i am getting on localhost 8080. The code is showing me thr result only in Eclipse but not through google app engine launcher. Traceback (most recent call last): File "C:\Program Files (x86)\Google\google_appengine\google\appengine \tools\dev_appserver.py", line 3211, in _HandleRequest self._Dispatch(dispatcher, self.rfile, outfile, env_dict) File "C:\Program Files (x86)\Google\google_appengine\google\appengine \tools\dev_appserver.py", line 3154, in _Dispatch base_env_dict=env_dict) File "C:\Program Files (x86)\Google\google_appengine\google\appengine \tools\dev_appserver.py", line 527, in Dispatch base_env_dict=base_env_dict) File "C:\Program Files (x86)\Google\google_appengine\google\appengine \tools\dev_appserver.py", line 2404, in Dispatch self._module_dict) File "C:\Program Files (x86)\Google\google_appengine\google\appengine \tools\dev_appserver.py", line 2314, in ExecuteCGI reset_modules = exec_script(handler_path, cgi_path, hook) File "C:\Program Files (x86)\Google\google_appengine\google\appengine \tools\dev_appserver.py", line 2210, in ExecuteOrImportScript exec module_code in script_module.__dict__ File "C:\Users\Admin\Pythonworkspace\pythonsample12\src \engineapp202\main.py", line 4, in import gdata.spreadsheet.service ImportError: No module named gdata.spreadsheet.service From steve-REMOVE-THIS at cybersource.com.au Mon Nov 1 04:16:41 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 01 Nov 2010 08:16:41 GMT Subject: Py3: Import relative path module References: <044f2fb7-a6a9-4bb9-b2a6-8ee1d0c19612@u17g2000yqi.googlegroups.com> Message-ID: <4cce7768$0$29965$c3e8da3$5496439d@news.astraweb.com> On Mon, 01 Nov 2010 01:08:52 -0700, Gnarlodious wrote: > On Oct 31, 11:09?am, ?????? ??????????? wrote: >> from .. import Data.DumpHT as DumpHT > > That doesn't work. Any more ideas? Define "doesn't work". Does it? Print a warning message but continue execution? Import the wrong module? Abort Python without warning? Dump core? Reboot the operating system without warning? Lock up the computer? Something else? -- Steven From whitequill.bj at gmail.com Mon Nov 1 04:19:26 2010 From: whitequill.bj at gmail.com (Bj Raz) Date: Mon, 1 Nov 2010 04:19:26 -0400 Subject: factorial of negative one (-1) In-Reply-To: References: Message-ID: On Fri, Oct 29, 2010 at 1:02 AM, Chris Rebert wrote: > On Thu, Oct 28, 2010 at 9:41 PM, Bj Raz wrote: > > I am working with differential equations of the higher roots of negative > > one. (dividing enormous numbers into other enormous numbers to come out > with > > very reasonable numbers). > > I am mixing this in to a script for Maya (the final output is graph-able > as > > a spiral.) > > I have heard that Sage, would be a good program to do this in, but I'd > like > > to try and get this to work in native python if I can. > > The script I am trying to port to Python is; > http://pastebin.com/sc1jW1n4. > > Unless your code is really long, just include it in the message in the > future. > So, for the archive: > indvar = 200; > q = 0; > lnanswer = 0; > for m = 1:150 > lnanswer = (3 * m) * log(indvar) - log(factorial(3 * m)) ; > q(m+1) = q(m)+ ((-1)^m) * exp(lnanswer); > end > lnanswer > q > > Also, it helps to point out *what language non-Python code is in*. I'm > guessing MATLAB in this case. > > Naive translation attempt (Disclaimer: I don't know much MATLAB): > > from math import log, factorial, exp > indvar = 200 > q = [0] > lnanswer = 0 > for m in range(1, 151): > lnanswer = (3 * m) * log(indvar) - log(factorial(3 * m)) > q.append(q[-1] + (1 if m % 2 == 0 else -1) * exp(lnanswer)) > print(lnanswer) > print(q) > > Cheers, > Chris > -- > http://blog.rebertia.com > I'm sorry I didn't read the thread very carefully. thank you for your help Chris. :) -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Mon Nov 1 04:22:15 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 1 Nov 2010 01:22:15 -0700 Subject: Allow multiline conditions and the like In-Reply-To: <4cce7196$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <4cce7196$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Nov 1, 2010 at 12:51 AM, Steven D'Aprano wrote: > On Sun, 31 Oct 2010 23:02:21 -0700, Yingjie Lan wrote: >> Hi, >> >> This is a mini-proposal I piggy-tailed in the other topic: >> >> Allow the conditions in the if-, elif-, while-, for-, and with-clauses >> to span multiple lines > [...] >> ? ?also, if we don't allow it, people just have to use >> parenthesis around the expressions to make that happen. > > You say that like it's a bad thing. > > That is kind of like saying "We should allow people to speed through red > traffic lights, because if we don't, they'll just wait for the light to > turn green!". Er, yes, and the problem is? > > If you need a multi-line conditional, wrap it in parentheses. Or, if possible, refactor the conditional into a function (call) so it's no longer multiline in the first place. Cheers, Chris From whitequill.bj at gmail.com Mon Nov 1 04:23:28 2010 From: whitequill.bj at gmail.com (Bj Raz) Date: Mon, 1 Nov 2010 04:23:28 -0400 Subject: factorial of negative one (-1) In-Reply-To: References: Message-ID: Simply out of curiosity is there a way to force python to print more then 16 places from the decimal? For better accuracy. On Mon, Nov 1, 2010 at 4:19 AM, Bj Raz wrote: > > > On Fri, Oct 29, 2010 at 1:02 AM, Chris Rebert wrote: > >> On Thu, Oct 28, 2010 at 9:41 PM, Bj Raz wrote: >> > I am working with differential equations of the higher roots of negative >> > one. (dividing enormous numbers into other enormous numbers to come out >> with >> > very reasonable numbers). >> > I am mixing this in to a script for Maya (the final output is graph-able >> as >> > a spiral.) >> > I have heard that Sage, would be a good program to do this in, but I'd >> like >> > to try and get this to work in native python if I can. >> > The script I am trying to port to Python is; >> http://pastebin.com/sc1jW1n4. >> >> Unless your code is really long, just include it in the message in the >> future. >> So, for the archive: >> indvar = 200; >> q = 0; >> lnanswer = 0; >> for m = 1:150 >> lnanswer = (3 * m) * log(indvar) - log(factorial(3 * m)) ; >> q(m+1) = q(m)+ ((-1)^m) * exp(lnanswer); >> end >> lnanswer >> q >> >> Also, it helps to point out *what language non-Python code is in*. I'm >> guessing MATLAB in this case. >> >> Naive translation attempt (Disclaimer: I don't know much MATLAB): >> >> from math import log, factorial, exp >> indvar = 200 >> q = [0] >> lnanswer = 0 >> for m in range(1, 151): >> lnanswer = (3 * m) * log(indvar) - log(factorial(3 * m)) >> q.append(q[-1] + (1 if m % 2 == 0 else -1) * exp(lnanswer)) >> print(lnanswer) >> print(q) >> >> Cheers, >> Chris >> -- >> http://blog.rebertia.com >> > I'm sorry I didn't read the thread very carefully. thank you for your help > Chris. :) -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Mon Nov 1 04:36:32 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 1 Nov 2010 01:36:32 -0700 Subject: factorial of negative one (-1) In-Reply-To: References: Message-ID: > On Mon, Nov 1, 2010 at 4:19 AM, Bj Raz wrote: >> On Fri, Oct 29, 2010 at 1:02 AM, Chris Rebert wrote: >>> On Thu, Oct 28, 2010 at 9:41 PM, Bj Raz wrote: >>> > I am working with differential equations of the higher roots of >>> > negative >>> > one. (dividing enormous numbers into other enormous numbers to come out >>> > with >>> > very reasonable numbers). >>> > I am mixing this in to a script for Maya (the final output is >>> > graph-able as >>> > a spiral.) >>> > I have heard that Sage, would be a good program to do this in, but I'd >>> > like >>> > to try and get this to work in native python if I can. >>> > The script I am trying to port to Python >>> > is;?http://pastebin.com/sc1jW1n4. >>> >>> Unless your code is really long, just include it in the message in the >>> future. >>> So, for the archive: >>> indvar = 200; >>> q = 0; >>> lnanswer = 0; >>> for m = 1:150 >>> ?lnanswer = (3 * m) * log(indvar) - log(factorial(3 * m)) ?; >>> q(m+1) = q(m)+ ((-1)^m) * exp(lnanswer); >>> end >>> lnanswer >>> q On Mon, Nov 1, 2010 at 1:23 AM, Bj Raz wrote: > Simply out of curiosity is there a way to force python to print more then 16 > places from the decimal? For better accuracy. (1) Please don't top-post. (http://en.wikipedia.org/wiki/Top-post ) (2) The underlying double-precision floating-point number only has ~16 decimal digits of precision, so it's pointless to print out "further" digits. (3) If you actually need more than 16 decimal places, use something like the `decimal.Decimal` datatype: http://docs.python.org/library/decimal.html Cheers, Chris -- http://blog.rebertia.com From qq263020776 at gmail.com Mon Nov 1 04:38:21 2010 From: qq263020776 at gmail.com (nu) Date: Mon, 1 Nov 2010 01:38:21 -0700 (PDT) Subject: how to sync file on client and server Message-ID: I want to sync the file foder in different server,and I can't use ftp protocl. I try to sync files during defferent server and not use username and password to login. Anyone has good ideas? From steve-REMOVE-THIS at cybersource.com.au Mon Nov 1 04:43:44 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 01 Nov 2010 08:43:44 GMT Subject: How on Factorial References: <1cf81147-06f4-4e48-9255-ea87bf3f93be@k22g2000yqh.googlegroups.com> <85dcd37b-871d-4058-b6af-8fc825afcc96@a37g2000yqi.googlegroups.com> Message-ID: <4cce7dc0$0$29965$c3e8da3$5496439d@news.astraweb.com> On Mon, 01 Nov 2010 20:23:42 +1300, Lawrence D'Oliveiro wrote: > In message , Jussi Piitulainen > wrote: > >> (I agree that no one should write factorial like that, except as a >> joke. I have nothing against (x if (a > b) else y). The trick with and >> and or was used before Python had an actual conditional expression.) > > You know what, I think I actually prefer the trick to Python?s > backwards-if syntax... What backwards-if syntax? I tried writing it backwards: true_clause fi condition esle false_clause and got a syntax error, so I tried writing it backwards another way: false_clause else condition if true_clause and still got a syntax error, so I can only conclude that you're using some hacked version of Python with non-standard syntax, if you're serious, else you're unaware that Python's ternary if operator follows English syntax. -- Steven From iwawi123 at gmail.com Mon Nov 1 04:58:50 2010 From: iwawi123 at gmail.com (iwawi) Date: Mon, 1 Nov 2010 01:58:50 -0700 (PDT) Subject: text file reformatting References: <78daefd1-59a1-4b3a-9bc2-5910315515ce@r14g2000yqa.googlegroups.com> <57ec83dd-3f30-4000-acf6-f49a44568d22@k22g2000yqh.googlegroups.com> Message-ID: On 1 marras, 09:59, "cbr... at cbrownsystems.com" wrote: > On Oct 31, 11:46?pm, iwawi wrote: > > > > > > > On 31 loka, 21:48, Tim Chase wrote: > > > > > PRJ01001 4 00100END > > > > PRJ01002 3 00110END > > > > > I would like to pick only some columns to a new file and put them to a > > > > certain places (to match previous data) - definition file (def.csv) > > > > could be something like this: > > > > > VARIABLE ? FIELDSTARTS ? ? FIELD SIZE ? ? ?NEW PLACE IN NEW DATA FILE > > > > ProjID ? ? ; ? ? ? 1 ? ? ? ; ? ? ? 5 ? ? ? ; ? ? ? 1 > > > > CaseID ? ? ; ? ? ? 6 ? ? ? ; ? ? ? 3 ? ? ? ; ? ? ? 10 > > > > UselessV ?; ? ? ? ?10 ? ? ?; ? ? ? 1 ? ? ? ; > > > > Zipcode ? ?; ? ? ? 12 ? ? ?; ? ? ? 5 ? ? ? ; ? ? ? 15 > > > > > So the new datafile should look like this: > > > > > PRJ01 ? ?001 ? ? ? 00100END > > > > PRJ01 ? ?002 ? ? ? 00110END > > > > How flexible is the def.csv format? ?The difficulty I see with > > > your def.csv format is that it leaves undefined gaps (presumably > > > to be filled in with spaces) and that you also have a blank "new > > > place in new file" value. ?If instead, you could specify the > > > width to which you want to pad it and omit variables you don't > > > want in the output, ordering the variables in the same order you > > > want them in the output: > > > > ? Variable; Start; Size; Width > > > ? ProjID; 1; 5; 10 > > > ? CaseID; 6; 3; 10 > > > ? Zipcode; 12; 5; 5 > > > ? End; 16; 3; 3 > > > > (note that I lazily use the same method to copy the END from the > > > source to the destination, rather than coding specially for it) > > > you could do something like this (untested) > > > > ? ?import csv > > > ? ?f = file('def.csv', 'rb') > > > ? ?f.next() # discard the header row > > > ? ?r = csv.reader(f, delimiter=';') > > > ? ?fields = [ > > > ? ? ?(varname, slice(int(start), int(start)+int(size)), width) > > > ? ? ?for varname, start, size, width > > > ? ? ?in r > > > ? ? ?] > > > ? ?f.close() > > > ? ?out = file('out.txt', 'w') > > > ? ?try: > > > ? ? ?for row in file('data.txt'): > > > ? ? ? ?for varname, slc, width in fields: > > > ? ? ? ? ?out.write(row[slc].ljust(width)) > > > ? ? ? ?out.write('\n') > > > ? ?finally: > > > ? ? ?out.close() > > > > Hope that's fairly easy to follow and makes sense. ?There might > > > be some fence-posting errors (particularly your use of "1" as the > > > initial offset, while python uses "0" as the initial offset for > > > strings) > > > > If you can't modify the def.csv format, then things are a bit > > > more complex and I'd almost be tempted to write a script to try > > > and convert your existing def.csv format into something simpler > > > to process like what I describe. > > > > -tkc- Piilota siteerattu teksti - > > > > - N?yt? siteerattu teksti - > > > Hi, > > > Thanks for your reply. > > > Def.csv could be modified so that every line has the same structure: > > variable name, field start, field size and new place and would be > > separated with semicolomns as you mentioned. > > > I tried your script (which seems quite logical) but I get this > > > Traceback (most recent call last): > > ? File "testing.py", line 16, in > > ? ? out.write (row[slc].ljust(width)) > > TypeError: an integer is required > > > Yes - you said it was untested, but I can't figure out how to > > proceed... > > The line > > ? ? (varname, slice(int(start), int(start)+int(size)), width) > > should instead be > > ? ? (varname, slice(int(start), int(start)+int(size)), int(width)) > > although you give an example where there is no width - what does that > imply? In the above case, it will throw an exception. > > Anyway, I think you'll find there's something a bit off in the output > loop with the parameter passed to ljust() as well. The value given in > your csv seems to be the absolute position, but as it's implemented by > Tim, it acts as the relative position. > > Given Tim's parsing into the list fields, I have a feeling that what > you really want instead of > > ? ? for varname, slc, width in fields: > ? ? ? ? out.write(row[slc].ljust(width)) > ? ? out.write('\n') > > is to have > > ? ? s = '' > ? ? for varname, slc, width in fields: > ? ? ? ? s += " "*(width - len(s)) + row[slc] > ? ? out.write(s+'\n') > > And if that is what you want, then you will surely want to globally > replace the name 'width' with for example 'start_column', because then > it all makes sense :). > > Cheers - Chas- Piilota siteerattu teksti - > > - N?yt? siteerattu teksti - Yes, it's meant to be the absolute column position in a new file like you said. I used your changes to the csv-reading cause it seems more flexible, but the end of the code is still not working. Here's were I stand now: import re parse_columns = re.compile(r'\s*;\s*') f = file('def.csv', 'rb') f.readline() # discard the header row r = (parse_columns.split(line.strip()) for line in f) fields = [ (varname, slice(int(start), int(start)+int(size), int(width) if width else 0)) for varname, start, size, width in r ] f.close() print fields out = file('out.txt', 'w') try: for row in file('data.txt'): s = ' ' for varname, slc, width in fields: s += " "*(width - len(s)) + row[slc] out.write(s+'\n') finally: out.close() When executed, I get this: File "toimi.py", line 20, in for varname, slc, width in fields: ValueError: need more than 2 values to unpack From charugangal at gmail.com Mon Nov 1 05:05:43 2010 From: charugangal at gmail.com (charu gangal) Date: Mon, 1 Nov 2010 02:05:43 -0700 (PDT) Subject: using google app through python Message-ID: Hey! Can anyone help me with python script for reading google spreadsheets? what all packages do i need to import to make the code run successfully after deploying it on google environment..thnx in advance From hniksic at xemacs.org Mon Nov 1 05:42:06 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Mon, 01 Nov 2010 10:42:06 +0100 Subject: factorial of negative one (-1) References: Message-ID: <87r5f55qj5.fsf@xemacs.org> Chris Rebert writes: > (2) The underlying double-precision floating-point number only has ~16 > decimal digits of precision, so it's pointless to print out "further" > digits. A digression which has nothing to do with Raj's desire for "better accuracy"... Printing out further digits (without quotes) is not pointless if you want to find out the exact representation of your number in python's floating point, for educational purposes or otherwise. Python has a little-known but very instructive method for determining the makeup of a float: >>> 1.1 .as_integer_ratio() (2476979795053773, 2251799813685248) 1.1 is represented with the closest fraction with a power-of-two denominator, 2476979795053773/2251799813685248. As is the case with all Python floats, this fraction has an exact decimal representation, 1.100000000000000088817841970012523233890533447265625. It is not that unreasonable to request that the whole number be printed, and python will happily oblige: >>> "%.100g" % 1.1 '1.100000000000000088817841970012523233890533447265625' The digits after the first cluster of zeros are not garbage, at least not in the sense of what you get reading uninitialized memory and such; they're mathematically precise decimal digits of the number that "1.1" has turned into during conversion to float. From phil at riverbankcomputing.com Mon Nov 1 06:52:03 2010 From: phil at riverbankcomputing.com (Phil Thompson) Date: Mon, 01 Nov 2010 10:52:03 +0000 Subject: ANN: PyQt v4.8.1 Released Message-ID: PyQt v4.8.1 has been released and is available from http://www.riverbankcomputing.com/software/pyqt/. PyQt is a comprehensive set of bindings for the Qt application and UI framework from Nokia. It supports the same platforms as Qt (Windows, Linux and MacOS/X). PyQt supports Python v3 and Python v2.3 and later. The highlight of this release is full support for Qt v4.7.0 including the ability to integrate Python with QML, the new declarative markup language for building highly dynamic user interfaces. Windows installers are provided for the GPL version of PyQt which contains everything needed for PyQt development (including Qt, Qt Designer, QScintilla, and MySQL, PostgreSQL, SQLite and ODBC drivers) except Python itself. PyQt v4 is implemented as a set of 19 extension modules containing over 400 classes and over 6,000 functions and methods. QtCore The non-GUI infrastructure including event loops, threads, i18n, Unicode, signals and slots, user and application settings, mapped files and shared memory. QtDeclarative A set of classes that implement a framework for building highly dynamic user interfaces using the QML declarative language that can be integrated with Python. QtDesigner A set of classes that allow the Qt Designer GUI design tool to be extended with PyQt. QtGui A rich collection of GUI widgets. QtHelp A set of classes for creating and viewing searchable documentation and being able to integrate online help with PyQt applications. It includes the C++ port of the Lucene text search engine. QtNetwork A set of classes to support TCP and UDP socket programming and higher level protocols (eg. HTTP, SSL). QtOpenGL A set of classes that allows PyOpenGL to render onto Qt widgets. QtScript A set of classes that implements a JavaScript interpreter. Python objects may be exposed in the interpreter as JavaScript objects. QtScriptTools A debugger for the JavaScript interpreter. QtSql A set of classes that implement SQL data models and interfaces to industry standard databases. The Windows installers include support for SQLite, MySQL, PostgreSQL and ODBC. QtSvg A set of classes to render SVG files onto Qt widgets. QtTest A set of classes to automate unit testing of PyQt applications and GUIs. QtWebKit This implements a web browser engine based on the WebKit engine used by Apple's Safari browser. It allows the methods and properties of Python objects to be published and appear as JavaScript objects to scripts embedded in HTML pages. QtXML A set of classes that implement DOM and SAX parsers. QtXMLPatterns A set of classes that implement XQuery and XPath support for XML and custom data models. QAxContainer A set of classes for Windows that allows the integration of ActiveX controls and COM objects. phonon A cross-platform multimedia framework that enables the use of audio and video content in PyQt applications. DirectX is used as the Windows backend, QuickTime as the MacOS/X backend, and GStreamer as the Linux backend. QtMultimedia A set of classes that provide low-level multimedia functions. Application developers would normally use the phonon module. DBus PyQt includes dbus.mainloop.qt that allows the Qt event loop to be used with the standard DBus Python bindings. PyQt includes the pyuic4 utility which generates Python code to implement user interfaces created with Qt Designer in the same way that the uic utility generates C++ code. It is also able to load Designer XML files dynamically. PyQt is available under the GPL and a commercial license. Unlike Qt, PyQt is not available under the LGPL. The commercial PyQt license allows GPL applications to be relicensed at any time. From gnarlodious at gmail.com Mon Nov 1 06:54:31 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Mon, 1 Nov 2010 03:54:31 -0700 (PDT) Subject: Py3: Import relative path module References: <044f2fb7-a6a9-4bb9-b2a6-8ee1d0c19612@u17g2000yqi.googlegroups.com> <4cce7768$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Nov 1, 2:16?am, Steven D'Aprano wrote: > On Mon, 01 Nov 2010 01:08:52 -0700, Gnarlodious wrote: > > On Oct 31, 11:09?am, ?????? ??????????? wrote: > >> from .. import Data.DumpHT as DumpHT > > > That doesn't work. Any more ideas? > > Define "doesn't work". LOL. I get error: from .. import Data.DumpHT as DumpHT ^ SyntaxError: invalid syntax Rewording gets me closer: from ..Data import DumpHT ValueError: Attempted relative import in non-package I do have the empty __init__.py file in the Data folder. What is wrong? -- Gnarlie From alex at moreati.org.uk Mon Nov 1 06:55:37 2010 From: alex at moreati.org.uk (Alex Willmer) Date: Mon, 1 Nov 2010 03:55:37 -0700 (PDT) Subject: Would you recommend python as a first programming language? References: Message-ID: On Oct 30, 7:16?pm, brad... at hotmail.com wrote: > I was thinking of recommending this to a friend but what do you all think? > I think 1. Python is a great language, and a good starting point for many people. 2. You really haven't given us much to go on. Regards, Alex From xwraithanx at gmail.com Mon Nov 1 07:23:25 2010 From: xwraithanx at gmail.com (Chris McDonald) Date: Mon, 1 Nov 2010 04:23:25 -0700 Subject: 2to3 urllib.URLopener -> urllib.request.URLopener Message-ID: Howdy, I was going through, evaluating how hard a project would be to move over to a hybrid codebase of python2 and python3 using 2to3. I found that while it would convert most other urllib renames and moves, 2to3 currently leaves urllib.URLopener as is, instead of changing it to go via the request module. Not sure if this is a bug or intended, so thought I'd bring it up to the list. -Chris 'Wraithan' McDonald From kwatford+python at gmail.com Mon Nov 1 07:26:30 2010 From: kwatford+python at gmail.com (Ken Watford) Date: Mon, 1 Nov 2010 07:26:30 -0400 Subject: factorial of negative one (-1) In-Reply-To: <87r5f55qj5.fsf@xemacs.org> References: <87r5f55qj5.fsf@xemacs.org> Message-ID: On Mon, Nov 1, 2010 at 5:42 AM, Hrvoje Niksic wrote: > > Printing out further digits (without quotes) is not pointless if you > want to find out the exact representation of your number in python's > floating point, for educational purposes or otherwise. ?Python has a > little-known but very instructive method for determining the makeup of a > float: > >>>> 1.1 .as_integer_ratio() > (2476979795053773, 2251799813685248) > Handy, but if you need the exact representation, my preference is float.hex, which seems to be the same as C99's %a format. >>> math.pi.hex() '0x1.921fb54442d18p+1' >>> float.fromhex(math.pi.hex()) == math.pi True Granted, it's not as easy for humans to interpret, but it's useful for certain things. From neilc at norwich.edu Mon Nov 1 07:27:59 2010 From: neilc at norwich.edu (Neil Cerutti) Date: 1 Nov 2010 11:27:59 GMT Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> Message-ID: <8j7mhvFk3eU1@mid.individual.net> On 2010-11-01, Martin v. Loewis wrote: > i.e. avoid the backslash for multi-line conditions altogether > (in fact, I can't think any situation where I would use the > backslash). The horrible-to-nest with statement. -- Neil Cerutti From __peter__ at web.de Mon Nov 1 07:36:26 2010 From: __peter__ at web.de (Peter Otten) Date: Mon, 01 Nov 2010 12:36:26 +0100 Subject: Py3: Import relative path module References: <044f2fb7-a6a9-4bb9-b2a6-8ee1d0c19612@u17g2000yqi.googlegroups.com> <4cce7768$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: Gnarlodious wrote: > On Nov 1, 2:16 am, Steven D'Aprano T... at cybersource.com.au> wrote: >> On Mon, 01 Nov 2010 01:08:52 -0700, Gnarlodious wrote: >> > On Oct 31, 11:09 am, ?????? ??????????? wrote: >> >> from .. import Data.DumpHT as DumpHT >> >> > That doesn't work. Any more ideas? >> >> Define "doesn't work". > > LOL. > I get error: > > from .. import Data.DumpHT as DumpHT > ^ > SyntaxError: invalid syntax > > Rewording gets me closer: > > from ..Data import DumpHT > ValueError: Attempted relative import in non-package > > I do have the empty __init__.py file in the Data folder. What is > wrong? Remove the directory containing the importing file from your sys.path. E. g. if you have $ tree . `-- alpha |-- __init__.py |-- beta | |-- __init__.py | `-- one.py `-- gamma |-- __init__.py `-- two.py only the parent of alpha should be in your sys.path. Then to import alpha/gamma/two.py from alpha/beta/one.py use from ..gamma import two Peter From python.list at tim.thechases.com Mon Nov 1 08:10:18 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 01 Nov 2010 07:10:18 -0500 Subject: [Beginer Question] I heard about python needing some sort of_VariableName_ boiler plate? In-Reply-To: <878w1dlk81.fsf@benfinney.id.au> References: <878w1dlk81.fsf@benfinney.id.au> Message-ID: <4CCEAE2A.8030802@tim.thechases.com> On 10/31/10 23:51, Ben Finney wrote: >> Sorry, to clarify I heard that when you declare a variable in python >> you have to use some sort of standard boiler plate _variable_ however >> this has not been my experience using IDLE so is this even true? > > I don't know what ?some sort of boiler plate _variable_? might mean. With the same lack of context as everybody else, two ideas occur to me, both involve thinking the OP means "__variable__" (with the double-underscores) instead of with single underscores: 1) the *completely optional and certainly not manditory CONVENTION* of using things like __author__ or __version__ in a module for various meta-data. For some projects, these sorts of faux-special-variables may be more demanded, but that's a project-thing, not a Python-thing 2) the use of the __foo__ magic methods such as __init__ or __add__ to hook into language bindings/functionality. In this case, there's not a lot of use a boiler-plate template would do for you...what? perhaps create def __|__(self): """Docstring""" (leaving the cursor on the "|") But this isn't really much different from a generic function template with extra underscores and automatically adding "self" as the first parameter. But I've never found that terribly hard to type in the first place -- this is Python, not Pascal (where I'd have to distinguish between "procedure" and "function" and remember to correctly spell both) Or, it could be way too early on a Monday morning and I don't have a clue what the OP is talking about...which doesn't put me any further behind the other folks on the list. :*) -tkc From sadashiv.linux at gmail.com Mon Nov 1 08:52:11 2010 From: sadashiv.linux at gmail.com (Sadashiv) Date: Mon, 1 Nov 2010 05:52:11 -0700 (PDT) Subject: pcs pcap not able to recognize interface Message-ID: I'm facing following error while running Python script. Any idea what causing this error -- execute_local_command: Traceback (most recent call last): File "./pcapreplay/flowreplay.py", line 376, in main() File "./pcapreplay/flowreplay.py", line 177, in main cPcapC = pcs.PcapConnector(clientIface) File "/usr/lib/python2.7/site-packages/pcs/__init__.py", line 1850, in __init__ self.file = pcap.pcap(name, snaplen, promisc, timeout_ms) File "pcap.pyx", line 215, in pcs.pcap.pcap.__init__ (pcs/pcap/ pcap.c:1673) OSError: ioctl: No such device [53334 refs] start.py: ERROR connection_036: execute_local_command: Traceback (most recent call last): File "./pcapreplay/flowreplay.py", line 376, in main() File "./pcapreplay/flowreplay.py", line 177, in main cPcapC = pcs.PcapConnector(clientIface) File "/usr/lib/python2.7/site-packages/pcs/__init__.py", line 1850, in __init__ self.file = pcap.pcap(name, snaplen, promisc, timeout_ms) File "pcap.pyx", line 215, in pcs.pcap.pcap.__init__ (pcs/pcap/ pcap.c:1673) OSError: ioctl: No such device [53334 refs] From whitequill.bj at gmail.com Mon Nov 1 08:52:44 2010 From: whitequill.bj at gmail.com (Bj Raz) Date: Mon, 1 Nov 2010 08:52:44 -0400 Subject: factorial of negative one (-1) In-Reply-To: <87r5f55qj5.fsf@xemacs.org> References: <87r5f55qj5.fsf@xemacs.org> Message-ID: On Nov 1, 2010, at 5:42 AM, Hrvoje Niksic wrote: > Chris Rebert writes: > >> (2) The underlying double-precision floating-point number only has ~16 >> decimal digits of precision, so it's pointless to print out "further" >> digits. > > A digression which has nothing to do with Raj's desire for "better > accuracy"... > > Printing out further digits (without quotes) is not pointless if you > want to find out the exact representation of your number in python's > floating point, for educational purposes or otherwise. Python has a > little-known but very instructive method for determining the makeup of a > float: > >>>> 1.1 .as_integer_ratio() > (2476979795053773, 2251799813685248) > > 1.1 is represented with the closest fraction with a power-of-two > denominator, 2476979795053773/2251799813685248. As is the case with all > Python floats, this fraction has an exact decimal representation, > 1.100000000000000088817841970012523233890533447265625. It is not that > unreasonable to request that the whole number be printed, and python > will happily oblige: > >>>> "%.100g" % 1.1 > '1.100000000000000088817841970012523233890533447265625' > > The digits after the first cluster of zeros are not garbage, at least > not in the sense of what you get reading uninitialized memory and such; > they're mathematically precise decimal digits of the number that "1.1" > has turned into during conversion to float. Thank you Chris. > -- > http://mail.python.org/mailman/listinfo/python-list From invalid at invalid.invalid Mon Nov 1 09:03:28 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 1 Nov 2010 13:03:28 +0000 (UTC) Subject: Would you recommend python as a first programming language? References: Message-ID: On 2010-10-30, bradenf at hotmail.com wrote: > I was thinking of recommending this to a friend but what do you all think? Sounds like a great idea to me. > Sent wirelessly from my BlackBerry. Well bully for you! -- Grant Edwards grant.b.edwards Yow! I am having FUN... at I wonder if it's NET FUN or gmail.com GROSS FUN? From dan.kluev at gmail.com Mon Nov 1 09:21:36 2010 From: dan.kluev at gmail.com (Daniel Kluev) Date: Mon, 1 Nov 2010 23:21:36 +1000 Subject: Would you recommend python as a first programming language? In-Reply-To: <1852590440-1288466169-cardhu_decombobulator_blackberry.rim.net-702637351-@bda480.bisx.prod.on.blackberry> References: <1852590440-1288466169-cardhu_decombobulator_blackberry.rim.net-702637351-@bda480.bisx.prod.on.blackberry> Message-ID: > > I was thinking of recommending this to a friend but what do you all think? > Python is great language to learn programming. I've heard MIT switched from Scheme to Python as introductory language for their students. -- With best regards, Daniel Kluev -------------- next part -------------- An HTML attachment was scrubbed... URL: From dan at catfolks.net Mon Nov 1 11:03:41 2010 From: dan at catfolks.net (Dan M) Date: Mon, 01 Nov 2010 10:03:41 -0500 Subject: python script to read google spreadsheet References: <0b6f704c-e108-4fb9-afc2-3616d92d6694@t13g2000yqm.googlegroups.com> <45e3864a-6a63-49e9-ae0f-df3aeb8740c5@j2g2000yqf.googlegroups.com> Message-ID: On Mon, 01 Nov 2010 01:14:09 -0700, charu gangal wrote: > This is the page i am getting on localhost 8080. The code is showing me > thr result only in Eclipse but not through google app engine launcher. > > Traceback (most recent call last): > File "C:\Program Files (x86)\Google\google_appengine\google\appengine > \tools\dev_appserver.py", line 3211, in _HandleRequest > self._Dispatch(dispatcher, self.rfile, outfile, env_dict) > File "C:\Program Files (x86)\Google\google_appengine\google\appengine > \tools\dev_appserver.py", line 3154, in _Dispatch > base_env_dict=env_dict) > File "C:\Program Files (x86)\Google\google_appengine\google\appengine > \tools\dev_appserver.py", line 527, in Dispatch > base_env_dict=base_env_dict) > File "C:\Program Files (x86)\Google\google_appengine\google\appengine > \tools\dev_appserver.py", line 2404, in Dispatch > self._module_dict) > File "C:\Program Files (x86)\Google\google_appengine\google\appengine > \tools\dev_appserver.py", line 2314, in ExecuteCGI > reset_modules = exec_script(handler_path, cgi_path, hook) > File "C:\Program Files (x86)\Google\google_appengine\google\appengine > \tools\dev_appserver.py", line 2210, in ExecuteOrImportScript > exec module_code in script_module.__dict__ > File "C:\Users\Admin\Pythonworkspace\pythonsample12\src > \engineapp202\main.py", line 4, in > import gdata.spreadsheet.service > ImportError: No module named gdata.spreadsheet.service I'm something of a Python newbie, but could Eclipse be modifying your PYTHONPATH by adding the directory in which gdata.spreadsheet.service is installed? From gnarlodious at gmail.com Mon Nov 1 11:30:34 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Mon, 1 Nov 2010 08:30:34 -0700 (PDT) Subject: Py3: Import relative path module References: <044f2fb7-a6a9-4bb9-b2a6-8ee1d0c19612@u17g2000yqi.googlegroups.com> <4cce7768$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <770dd3de-25f5-404c-a05a-7bdd2eb07179@26g2000yqv.googlegroups.com> On Nov 1, 5:36?am, Peter Otten wrote: > Remove the directory containing the importing file from your sys.path. I removed all sys.path customizations and rebooted. In the following scenario, I am programming in one.py attempting to import Data.py which is in the alpha folder: > $ tree > . > `-- alpha > ? ? |-- __init__.py > ? ? |-- beta > ? ? | ? |-- __init__.py > ? ? | ? `-- one.py > ? ? `-- gamma > ? ? ? ? |-- __init__.py > ? ? ? ? `-- two.py However, all I can get is error: from .. import Data ValueError: Attempted relative import in non-package Why is the parent folder not recognized as a package? Because right now I am liberally using sys.path, which works but is a little too messy. -- Gnarlie From __peter__ at web.de Mon Nov 1 12:02:25 2010 From: __peter__ at web.de (Peter Otten) Date: Mon, 01 Nov 2010 17:02:25 +0100 Subject: Py3: Import relative path module References: <044f2fb7-a6a9-4bb9-b2a6-8ee1d0c19612@u17g2000yqi.googlegroups.com> <4cce7768$0$29965$c3e8da3$5496439d@news.astraweb.com> <770dd3de-25f5-404c-a05a-7bdd2eb07179@26g2000yqv.googlegroups.com> Message-ID: Gnarlodious wrote: > On Nov 1, 5:36 am, Peter Otten wrote: > >> Remove the directory containing the importing file from your sys.path. > I removed all sys.path customizations and rebooted. > > In the following scenario, I am programming in one.py attempting to > import Data.py which is in the alpha folder: >> $ tree >> . >> `-- alpha >> |-- __init__.py >> |-- beta >> | |-- __init__.py >> | `-- one.py >> `-- gamma >> |-- __init__.py >> `-- two.py > > However, all I can get is error: > > from .. import Data > ValueError: Attempted relative import in non-package > > Why is the parent folder not recognized as a package? Because right > now I am liberally using sys.path, which works but is a little too > messy. If you didn't add '/path/to/alpha' to your path explicitly then you may be starting one.py as a script with $ python /path/to/alpha/beta/one.py one.py then becomes the __main__ module instead of alpha.beta.one. Or your working directory is /path/to/alpha and you import one.py with import beta.one which makes beta instead of alpha the toplevel package. Peter From darcy at druid.net Mon Nov 1 12:26:19 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Mon, 1 Nov 2010 12:26:19 -0400 Subject: Would you recommend python as a first programming language? In-Reply-To: <1852590440-1288466169-cardhu_decombobulator_blackberry.rim.net-702637351-@bda480.bisx.prod.on.blackberry> References: <1852590440-1288466169-cardhu_decombobulator_blackberry.rim.net-702637351-@bda480.bisx.prod.on.blackberry> Message-ID: <20101101122619.7ed69524.darcy@druid.net> On Sat, 30 Oct 2010 19:16:10 +0000 bradenf at hotmail.com wrote: > I was thinking of recommending this to a friend but what do you all think? Of course! But then, what did you expect from this group. :-) -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From zak.mc.kraken at libero.it Mon Nov 1 12:41:40 2010 From: zak.mc.kraken at libero.it (Vito 'ZeD' De Tullio) Date: Mon, 01 Nov 2010 17:41:40 +0100 Subject: How on Factorial References: <1cf81147-06f4-4e48-9255-ea87bf3f93be@k22g2000yqh.googlegroups.com> <85dcd37b-871d-4058-b6af-8fc825afcc96@a37g2000yqi.googlegroups.com> Message-ID: Lawrence D'Oliveiro wrote: > You know what, I think I actually prefer the trick to Python?s > backwards-if syntax... fact = lambda x: x*fact(x-1) if x>1 else 1 naa, it's not too bad... -- By ZeD From cbrown at cbrownsystems.com Mon Nov 1 12:50:16 2010 From: cbrown at cbrownsystems.com (cbrown at cbrownsystems.com) Date: Mon, 1 Nov 2010 09:50:16 -0700 (PDT) Subject: text file reformatting References: <78daefd1-59a1-4b3a-9bc2-5910315515ce@r14g2000yqa.googlegroups.com> <57ec83dd-3f30-4000-acf6-f49a44568d22@k22g2000yqh.googlegroups.com> Message-ID: <31a905d6-982d-479d-b988-e8324a1a16c7@j25g2000yqa.googlegroups.com> On Nov 1, 1:58?am, iwawi wrote: > On 1 marras, 09:59, "cbr... at cbrownsystems.com" > > > > wrote: > > On Oct 31, 11:46?pm, iwawi wrote: > > > > On 31 loka, 21:48, Tim Chase wrote: > > > > > > PRJ01001 4 00100END > > > > > PRJ01002 3 00110END > > > > > > I would like to pick only some columns to a new file and put them to a > > > > > certain places (to match previous data) - definition file (def.csv) > > > > > could be something like this: > > > > > > VARIABLE ? FIELDSTARTS ? ? FIELD SIZE ? ? ?NEW PLACE IN NEW DATA FILE > > > > > ProjID ? ? ; ? ? ? 1 ? ? ? ; ? ? ? 5 ? ? ? ; ? ? ? 1 > > > > > CaseID ? ? ; ? ? ? 6 ? ? ? ; ? ? ? 3 ? ? ? ; ? ? ? 10 > > > > > UselessV ?; ? ? ? ?10 ? ? ?; ? ? ? 1 ? ? ? ; > > > > > Zipcode ? ?; ? ? ? 12 ? ? ?; ? ? ? 5 ? ? ? ; ? ? ? 15 > > > > > > So the new datafile should look like this: > > > > > > PRJ01 ? ?001 ? ? ? 00100END > > > > > PRJ01 ? ?002 ? ? ? 00110END > > > > > How flexible is the def.csv format? ?The difficulty I see with > > > > your def.csv format is that it leaves undefined gaps (presumably > > > > to be filled in with spaces) and that you also have a blank "new > > > > place in new file" value. ?If instead, you could specify the > > > > width to which you want to pad it and omit variables you don't > > > > want in the output, ordering the variables in the same order you > > > > want them in the output: > > > > > ? Variable; Start; Size; Width > > > > ? ProjID; 1; 5; 10 > > > > ? CaseID; 6; 3; 10 > > > > ? Zipcode; 12; 5; 5 > > > > ? End; 16; 3; 3 > > > > > (note that I lazily use the same method to copy the END from the > > > > source to the destination, rather than coding specially for it) > > > > you could do something like this (untested) > > > > > ? ?import csv > > > > ? ?f = file('def.csv', 'rb') > > > > ? ?f.next() # discard the header row > > > > ? ?r = csv.reader(f, delimiter=';') > > > > ? ?fields = [ > > > > ? ? ?(varname, slice(int(start), int(start)+int(size)), width) > > > > ? ? ?for varname, start, size, width > > > > ? ? ?in r > > > > ? ? ?] > > > > ? ?f.close() > > > > ? ?out = file('out.txt', 'w') > > > > ? ?try: > > > > ? ? ?for row in file('data.txt'): > > > > ? ? ? ?for varname, slc, width in fields: > > > > ? ? ? ? ?out.write(row[slc].ljust(width)) > > > > ? ? ? ?out.write('\n') > > > > ? ?finally: > > > > ? ? ?out.close() > > > > > Hope that's fairly easy to follow and makes sense. ?There might > > > > be some fence-posting errors (particularly your use of "1" as the > > > > initial offset, while python uses "0" as the initial offset for > > > > strings) > > > > > If you can't modify the def.csv format, then things are a bit > > > > more complex and I'd almost be tempted to write a script to try > > > > and convert your existing def.csv format into something simpler > > > > to process like what I describe. > > > > > -tkc- Piilota siteerattu teksti - > > > > > - N?yt? siteerattu teksti - > > > > Hi, > > > > Thanks for your reply. > > > > Def.csv could be modified so that every line has the same structure: > > > variable name, field start, field size and new place and would be > > > separated with semicolomns as you mentioned. > > > > I tried your script (which seems quite logical) but I get this > > > > Traceback (most recent call last): > > > ? File "testing.py", line 16, in > > > ? ? out.write (row[slc].ljust(width)) > > > TypeError: an integer is required > > > > Yes - you said it was untested, but I can't figure out how to > > > proceed... > > > The line > > > ? ? (varname, slice(int(start), int(start)+int(size)), width) > > > should instead be > > > ? ? (varname, slice(int(start), int(start)+int(size)), int(width)) > > > although you give an example where there is no width - what does that > > imply? In the above case, it will throw an exception. > > > Anyway, I think you'll find there's something a bit off in the output > > loop with the parameter passed to ljust() as well. The value given in > > your csv seems to be the absolute position, but as it's implemented by > > Tim, it acts as the relative position. > > > Given Tim's parsing into the list fields, I have a feeling that what > > you really want instead of > > > ? ? for varname, slc, width in fields: > > ? ? ? ? out.write(row[slc].ljust(width)) > > ? ? out.write('\n') > > > is to have > > > ? ? s = '' > > ? ? for varname, slc, width in fields: > > ? ? ? ? s += " "*(width - len(s)) + row[slc] > > ? ? out.write(s+'\n') > > > And if that is what you want, then you will surely want to globally > > replace the name 'width' with for example 'start_column', because then > > it all makes sense :). > > > Cheers - Chas- Piilota siteerattu teksti - > > > - N?yt? siteerattu teksti - > > Yes, it's meant to be the absolute column position in a new file like > you said. > > I used your changes to the csv-reading cause it seems more flexible, > but the end of the code is still not working. Here's were I stand now: > > import re > > parse_columns = re.compile(r'\s*;\s*') > > f = file('def.csv', 'rb') > f.readline() # discard the header row > r = (parse_columns.split(line.strip()) for line in f) > fields = [ > ?(varname, slice(int(start), int(start)+int(size), int(width) if width > else 0)) there's a misplaced parentheses; replace the above line (which yields a 2-tuple of values) with: (varname, slice(int(start), int(start)+int(size)), int(width) if width else 0) which yields a 3-tuple. Cheers - Chas > ? for varname, start, size, width in r > ?] > f.close() > print fields > > out = file('out.txt', 'w') > > try: > ?for row in file('data.txt'): > ? s = ' ' > ? for varname, slc, width in fields: > ? ?s += " "*(width - len(s)) + row[slc] > ? out.write(s+'\n') > finally: > ?out.close() > > When executed, I get this: > ? File "toimi.py", line 20, in > ? ? for varname, slc, width in fields: > ValueError: need more than 2 values to unpack From mygogo2011 at gmail.com Mon Nov 1 12:54:47 2010 From: mygogo2011 at gmail.com (PHP.CCC) Date: Mon, 1 Nov 2010 09:54:47 -0700 (PDT) Subject: PHP (PHP Hypertext Preprocessor) Programming is Similar to C ... Message-ID: PHP (PHP Hypertext Preprocessor) Programming is Similar to C ... PHP programming is similar to C / JavaScript and Java. ... Modeling Agencies - Helping Teen Models ? Fashion and Success - Starting a Retail ... Read More http://childschooledu.blogspot.com/ From ppearson at nowhere.invalid Mon Nov 1 13:11:33 2010 From: ppearson at nowhere.invalid (Peter Pearson) Date: 1 Nov 2010 17:11:33 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> Message-ID: <8j8am4Fk2jU1@mid.individual.net> On Mon, 01 Nov 2010 12:09:12 +1300, Lawrence D'Oliveiro wrote: > In message <4ccd5ad9$0$19151$426a74cc at news.free.fr>, jf wrote: > >> I edit each file to remove tabs ... > > expand -i newfile > >> Do you know a tools to compare the initial file with the cleaned one to >> know if the algorithms are the same ? > > diff -b oldfile newfile Warning: "diff -b" won't detect changes in indentation. Changes in indentation can change a Python program. -- To email me, substitute nowhere->spamcop, invalid->net. From python at mrabarnett.plus.com Mon Nov 1 13:33:22 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 01 Nov 2010 17:33:22 +0000 Subject: [Beginer Question] I heard about python needing some sort of_VariableName_ boiler plate? In-Reply-To: <878w1dlk81.fsf@benfinney.id.au> References: <878w1dlk81.fsf@benfinney.id.au> Message-ID: <4CCEF9E2.2000803@mrabarnett.plus.com> On 01/11/2010 04:51, Ben Finney wrote: > bradenf at hotmail.com writes: > >> Sorry, to clarify I heard that when you declare a variable in python >> you have to use some sort of standard boiler plate _variable_ however >> this has not been my experience using IDLE so is this even true? > > I don't know what ?some sort of boiler plate _variable_? might mean. > > Can you point to someone's actual message saying this, so we can see > what they might be talking about? > Perhaps the OP means: if __name__ == "__main__": ... although the "declare a variable" bit has me puzzled. From nagle at animats.com Mon Nov 1 13:56:51 2010 From: nagle at animats.com (John Nagle) Date: Mon, 01 Nov 2010 10:56:51 -0700 Subject: Exception Handling in Python 3 In-Reply-To: References: Message-ID: <4cceff62$0$1672$742ec2ed@news.sonic.net> On 10/24/2010 5:36 AM, Steve Holden wrote: > On 10/24/2010 2:22 AM, Lawrence D'Oliveiro wrote: >> In message, Steve >> Holden wrote: > Yes, *if the exception is caught* then it doesn't make any difference. > If the exception creates a traceback, however, I maintain that the > additional information is confusing to the consumer (while helpful to > the debugger of the consumed code). If an exception propagates all the way out to the top level and all the user gets is a system traceback, the program isn't very good. Really. If you're concerned about the display format of Python tracebacks seen by end users, you have bigger problems with your code. If it's a server-side program, you need to catch exceptions and log them somewhere, traceback and all. If it's a client-side GUI program, letting an exception unwind all the way out of the program loses whatever the user was doing. It's usually desirable to at least catch EnviromentError near the top level of your program. If some external problem causes a program abort, the user should get an error message, not a traceback. If it's a program bug, you can let the traceback unwind, displaying information that should be sent in with a bug report. John Nagle From bradenf at hotmail.com Mon Nov 1 14:18:45 2010 From: bradenf at hotmail.com (bradenf at hotmail.com) Date: Mon, 1 Nov 2010 18:18:45 +0000 Subject: [Beginer Question] I heard about python needing somesort of_VariableName_ boiler plate? In-Reply-To: <4CCEF9E2.2000803@mrabarnett.plus.com> References: <878w1dlk81.fsf@benfinney.id.au><4CCEF9E2.2000803@mrabarnett.plus.com> Message-ID: <1946543087-1288635527-cardhu_decombobulator_blackberry.rim.net-1324044669-@bda480.bisx.prod.on.blackberry> Sorry that is what I mean. What is it for? Sent wirelessly from my BlackBerry. -----Original Message----- From: MRAB Sender: python-list-bounces+bradenf=hotmail.com at python.org Date: Mon, 01 Nov 2010 17:33:22 To: Reply-To: python-list at python.org Subject: Re: [Beginer Question] I heard about python needing some sort of_VariableName_ boiler plate? On 01/11/2010 04:51, Ben Finney wrote: > bradenf at hotmail.com writes: > >> Sorry, to clarify I heard that when you declare a variable in python >> you have to use some sort of standard boiler plate _variable_ however >> this has not been my experience using IDLE so is this even true? > > I don't know what ?some sort of boiler plate _variable_? might mean. > > Can you point to someone's actual message saying this, so we can see > what they might be talking about? > Perhaps the OP means: if __name__ == "__main__": ... although the "declare a variable" bit has me puzzled. -- http://mail.python.org/mailman/listinfo/python-list From python at mrabarnett.plus.com Mon Nov 1 14:40:12 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 01 Nov 2010 18:40:12 +0000 Subject: [Beginer Question] I heard about python needing somesort of_VariableName_ boiler plate? In-Reply-To: <1946543087-1288635527-cardhu_decombobulator_blackberry.rim.net-1324044669-@bda480.bisx.prod.on.blackberry> References: <878w1dlk81.fsf@benfinney.id.au><4CCEF9E2.2000803@mrabarnett.plus.com> <1946543087-1288635527-cardhu_decombobulator_blackberry.rim.net-1324044669-@bda480.bisx.prod.on.blackberry> Message-ID: <4CCF098C.3070503@mrabarnett.plus.com> On 01/11/2010 18:18, bradenf at hotmail.com wrote: > Sorry that is what I mean. What is it for? > Sent wirelessly from my BlackBerry. > > -----Original Message----- > From: MRAB > Sender: python-list-bounces+bradenf=hotmail.com at python.org > Date: Mon, 01 Nov 2010 17:33:22 > To: > Reply-To: python-list at python.org > Subject: Re: [Beginer Question] I heard about python needing some > sort of_VariableName_ boiler plate? > > On 01/11/2010 04:51, Ben Finney wrote: >> bradenf at hotmail.com writes: >> >>> Sorry, to clarify I heard that when you declare a variable in python >>> you have to use some sort of standard boiler plate _variable_ however >>> this has not been my experience using IDLE so is this even true? >> >> I don't know what ?some sort of boiler plate _variable_? might mean. >> >> Can you point to someone's actual message saying this, so we can see >> what they might be talking about? >> > Perhaps the OP means: > > if __name__ == "__main__": > ... > > although the "declare a variable" bit has me puzzled. When a module is imported __name__ is bound to the name of the module, but when the module is run directly __name__ is bound to "__main__". See: http://docs.python.org/faq/programming.html?highlight=__name__ From benjamin.kaplan at case.edu Mon Nov 1 14:45:38 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 1 Nov 2010 14:45:38 -0400 Subject: [Beginer Question] I heard about python needing somesort of_VariableName_ boiler plate? In-Reply-To: <1946543087-1288635527-cardhu_decombobulator_blackberry.rim.net-1324044669-@bda480.bisx.prod.on.blackberry> References: <878w1dlk81.fsf@benfinney.id.au> <4CCEF9E2.2000803@mrabarnett.plus.com> <1946543087-1288635527-cardhu_decombobulator_blackberry.rim.net-1324044669-@bda480.bisx.prod.on.blackberry> Message-ID: On Mon, Nov 1, 2010 at 2:18 PM, wrote: > Sorry that is what I mean. What is it for? > Sent wirelessly from my BlackBerry. > What is what for? There is no boiler plate on variable names. *BY CONVENTION*, variables and methods with a special meaning will start and end with two underscores. *BY CONVENTION* something that you want to identify as an internal variable (what would be private in languages that enforce this) is prefixed with a single underscore. But neither of these are actually enforced by the language. For instance, an object's doc-string is stored as it's __doc__ attribute. The constructor is the __init__ method. The method that controls attribute access (which you can override) is __getattr__. Using str(object) to get the string representation works by calling the object's __str__ method. a + b is the same thing as a.__add__(b) > -----Original Message----- > From: MRAB > Sender: python-list-bounces+bradenf=hotmail.com at python.org > Date: Mon, 01 Nov 2010 17:33:22 > To: > Reply-To: python-list at python.org > Subject: Re: [Beginer Question] I heard about python needing some > ? ? ? ?sort ? ?of_VariableName_ boiler plate? > > On 01/11/2010 04:51, Ben Finney wrote: >> bradenf at hotmail.com writes: >> >>> Sorry, to clarify I heard that when you declare a variable in python >>> you have to use some sort of standard boiler plate _variable_ however >>> this has not been my experience using IDLE so is this even true? >> >> I don't know what ?some sort of boiler plate _variable_? might mean. >> >> Can you point to someone's actual message saying this, so we can see >> what they might be talking about? >> > Perhaps the OP means: > > ? ? if __name__ == "__main__": > ? ? ? ? ... > > although the "declare a variable" bit has me puzzled. > -- > http://mail.python.org/mailman/listinfo/python-list > -- > http://mail.python.org/mailman/listinfo/python-list > From usenot at geekmail.INVALID Mon Nov 1 15:38:35 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Mon, 1 Nov 2010 15:38:35 -0400 Subject: [Beginer Question] I heard about python needing somesort of_VariableName_ boiler plate? References: <878w1dlk81.fsf@benfinney.id.au> <4CCEF9E2.2000803@mrabarnett.plus.com> Message-ID: <20101101153835.08a5a02f@geekmail.INVALID> On Mon, 1 Nov 2010 18:18:45 +0000 bradenf at hotmail.com wrote: > Sorry that is what I mean. What is it for? > Sent wirelessly from my BlackBerry. > >>> andreas.quick_hot_anger = True Braden! Stop Top-Posting already! Please. If your BlackBerry makes this hard, then get another mail client. It gets confusing. And thereby, annoying. >>> andreas.quick_hot_anger = False /W -- To reach me via email, replace INVALID with the country code of my home country. But if you spam me, I'll be one sour Kraut. From tjreedy at udel.edu Mon Nov 1 15:42:52 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 01 Nov 2010 15:42:52 -0400 Subject: [Beginer Question] I heard about python needing somesort of_VariableName_ boiler plate? In-Reply-To: <1946543087-1288635527-cardhu_decombobulator_blackberry.rim.net-1324044669-@bda480.bisx.prod.on.blackberry> References: <878w1dlk81.fsf@benfinney.id.au><4CCEF9E2.2000803@mrabarnett.plus.com> <1946543087-1288635527-cardhu_decombobulator_blackberry.rim.net-1324044669-@bda480.bisx.prod.on.blackberry> Message-ID: On 11/1/2010 2:18 PM, bradenf at hotmail.com wrote: > Sorry that is what I mean. What is it for? > Sent wirelessly from my BlackBerry. Does it require you to toppost? Understanding the above requires one to guess what 'that' forward references. > Perhaps the OP means: > > if __name__ == "__main__": I presume that this is the 'that' which you forward-referenced. If so... Python reserves names of the form __xyz__ for itself. This is intentionally a bit awkward so as to stand out in code and not conflict with names a programmer might choose. This form is used for names that programmers *mostly* do not need to use. The system names that we do need to use constantly, like 'None', 'def', and 'int' have normal spellings. These are easy to type, but may conflict with a name that a programmer might be using. Every module has a name stored in its __name__ attribute. The the interpreter starts, it names the top level module, which is run directly instead of being imported, as '__main__'. When a module is run indirectly, by being imported, its name is what you expect from the docs or from the name of its file. So: 1. a module can have one of two runtime names (as defined by it __name__ attribute): '__main__' or its proper name. 2. a module's runtime name depends on whether it is run directly or imported. 3. a module can therefor tell how it is being run; this is usually done with "if __name__ == '__main__'. 4. a module can change its behavior depending on how it is run by putting code in the body of the conditional statement. Such a conditional statement is entirely OPTIONAL. There are two things people do in such a body. a. If the module is meant either imported or run as a useful standalone program (such as the stdlib trace module), check for arguments in sys.argv, do some useful work, and report. b. If the module is normally only meant to be imported, run a test. If a module is only meant to run as a program, or if it is only meant to be imported and all its tests are in a separate file, there there is no need for the conditional statement. -- Terry Jan Reedy From whitequill.bj at gmail.com Mon Nov 1 15:46:33 2010 From: whitequill.bj at gmail.com (Bj Raz) Date: Mon, 1 Nov 2010 15:46:33 -0400 Subject: factorial of negative one (-1) In-Reply-To: References: <87r5f55qj5.fsf@xemacs.org> Message-ID: On Mon, Nov 1, 2010 at 8:52 AM, Bj Raz wrote: > On Nov 1, 2010, at 5:42 AM, Hrvoje Niksic wrote: > > > Chris Rebert writes: > > > >> (2) The underlying double-precision floating-point number only has ~16 > >> decimal digits of precision, so it's pointless to print out "further" > >> digits. > > > > A digression which has nothing to do with Raj's desire for "better > > accuracy"... > > > > Printing out further digits (without quotes) is not pointless if you > > want to find out the exact representation of your number in python's > > floating point, for educational purposes or otherwise. Python has a > > little-known but very instructive method for determining the makeup of a > > float: > > > >>>> 1.1 .as_integer_ratio() > > (2476979795053773, 2251799813685248) > > > > 1.1 is represented with the closest fraction with a power-of-two > > denominator, 2476979795053773/2251799813685248. As is the case with all > > Python floats, this fraction has an exact decimal representation, > > 1.100000000000000088817841970012523233890533447265625. It is not that > > unreasonable to request that the whole number be printed, and python > > will happily oblige: > > > >>>> "%.100g" % 1.1 > > '1.100000000000000088817841970012523233890533447265625' > > > > The digits after the first cluster of zeros are not garbage, at least > > not in the sense of what you get reading uninitialized memory and such; > > they're mathematically precise decimal digits of the number that "1.1" > > has turned into during conversion to float. > > Thank you Chris. > > -- > > http://mail.python.org/mailman/listinfo/python-list > Would "math.fsum" be of any use to me? and what is a good application of the ".as_integer_ratio()" for the out put? Also I really just need the last number that starts to replete at the end of each iteration. Is there a way to isolate that number that repeats a whole bunch of times? Or at least cut off the output when it stops repeating? So I get an output that looks like; "[0, -1.3333333333333333, -1.2444444444444445, -1.2458553791887126, -1.2458468280690504, -1.2458468531272766, -1.2458468530863318, -1.2458468530863729]" or "[-1.2458468530863729]" and not: [0, -1.3333333333333333, -1.2444444444444445, -1.2458553791887126, -1.2458468280690504, -1.2458468531272766, -1.2458468530863318, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729]. and when I am working with, other numbers; is there a way to get more repetitions if I really need it? Thank you everyone for all your suggestions and help. :) -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Mon Nov 1 15:54:53 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 01 Nov 2010 15:54:53 -0400 Subject: Py3: Import relative path module In-Reply-To: References: <044f2fb7-a6a9-4bb9-b2a6-8ee1d0c19612@u17g2000yqi.googlegroups.com> <4cce7768$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 11/1/2010 6:54 AM, Gnarlodious wrote: > On Nov 1, 2:16 am, Steven D'Aprano T... at cybersource.com.au> wrote: >> On Mon, 01 Nov 2010 01:08:52 -0700, Gnarlodious wrote: >>> On Oct 31, 11:09 am, ?????? ??????????? wrote: >>>> from .. import Data.DumpHT as DumpHT >> >>> That doesn't work. Any more ideas? >> >> Define "doesn't work". > > LOL. > I get error: > > from .. import Data.DumpHT as DumpHT > ^ > SyntaxError: invalid syntax > > Rewording gets me closer: > > from ..Data import DumpHT > ValueError: Attempted relative import in non-package > > I do have the empty __init__.py file in the Data folder. What is > wrong? What about the folder above it? As far as I know, the main reason to use relative imports is if you have a subpackage that you expect to use within more then one package. Otherwise, it is usually a lot easier to use absolute imports starting with the top-level package. -- Terry Jan Reedy From tjreedy at udel.edu Mon Nov 1 16:30:30 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 01 Nov 2010 16:30:30 -0400 Subject: 2to3 urllib.URLopener -> urllib.request.URLopener In-Reply-To: References: Message-ID: On 11/1/2010 7:23 AM, Chris McDonald wrote: > Howdy, > > I was going through, evaluating how hard a project would be to move > over to a hybrid codebase of python2 and python3 using 2to3. I found > that while it would convert most other urllib renames and moves, 2to3 > currently leaves urllib.URLopener as is, instead of changing it to go > via the request module. > > Not sure if this is a bug or intended, so thought I'd bring it up to the list. Good catch. Bug. Thanks for reporting. Lib/lib2to3/fixes/fix_urllib.py has (near the top) ''' MAPPING = {'urllib': [ ('urllib.request', ['URLOpener', 'FancyURLOpener', 'urlretrieve', ''' I reported the double misspelling of 'opener' as 'Opener' in http://bugs.python.org/issue10286 You can fix your local copy now. Good luck with the conversion. -- Terry Jan Reedy From fetchinson at googlemail.com Mon Nov 1 16:31:07 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Mon, 1 Nov 2010 21:31:07 +0100 Subject: playful coding problems for 10 year olds Message-ID: Hi folks, My niece is interested in programming and python looks like a good choice (she already wrote a couple of lines :)) She is 10 and I thought it would be good to have a bunch of playful coding problems for her, stuff that she could code herself maybe after some initial help. Do you guys know problems like these? Or a good resource where to look them up? Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From invalid at invalid.invalid Mon Nov 1 16:57:24 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 1 Nov 2010 20:57:24 +0000 (UTC) Subject: [Beginer Question] I heard about python needing somesort of_VariableName_ boiler plate? References: <878w1dlk81.fsf@benfinney.id.au> <4CCEF9E2.2000803@mrabarnett.plus.com> <1946543087-1288635527-cardhu_decombobulator_blackberry.rim.net-1324044669-@bda480.bisx.prod.on.blackberry> Message-ID: On 2010-11-01, Benjamin Kaplan wrote: > On Mon, Nov 1, 2010 at 2:18 PM, wrote: >> Sorry that is what I mean. What is it for? >> Sent wirelessly from my BlackBerry. > > What is what for? I think I smell troll... -- Grant Edwards grant.b.edwards Yow! hubub, hubub, HUBUB, at hubub, hubub, hubub, HUBUB, gmail.com hubub, hubub, hubub. From dirknbr at gmail.com Mon Nov 1 16:58:36 2010 From: dirknbr at gmail.com (Dirk Nachbar) Date: Mon, 1 Nov 2010 13:58:36 -0700 (PDT) Subject: playful coding problems for 10 year olds References: Message-ID: <3385082a-7b24-4a9d-b452-c3fa7db44cd1@26g2000yqv.googlegroups.com> This is in JS but have a look here http://github.com/ryanmcgrath/splash On 1 Nov, 20:31, Daniel Fetchinson wrote: > Hi folks, > > My niece is interested in programming and python looks like a good > choice (she already wrote a couple of lines :)) She is 10 and I > thought it would be good to have a bunch of playful coding problems > for her, stuff that she could code herself maybe after some initial > help. > > Do you guys know problems like these? Or a good resource where to look them up? > > Cheers, > Daniel > > -- > Psss, psss, put it down! -http://www.cafepress.com/putitdown From dirknbr at gmail.com Mon Nov 1 17:03:07 2010 From: dirknbr at gmail.com (Dirk Nachbar) Date: Mon, 1 Nov 2010 14:03:07 -0700 (PDT) Subject: using google app through python References: Message-ID: Why don't you start here http://code.google.com/apis/spreadsheets/data/1.0/developers_guide_python.html On 1 Nov, 09:05, charu gangal wrote: > Hey! Can anyone help me with python script for reading google > spreadsheets? what all packages do i need to import to make the code > run successfully after deploying it on google environment..thnx in > advance From iamforufriends at gmail.com Mon Nov 1 17:03:09 2010 From: iamforufriends at gmail.com (ADULTS GROUP FOR FUN WITH SE ^X) Date: Mon, 1 Nov 2010 14:03:09 -0700 (PDT) Subject: HAI ALL... U KNOW, NOW DATING WITH SWEETHARTS IS EAZY AND FREE....... Message-ID: <522e2b5b-d5be-4768-848a-4e2afdab3627@26g2000yqv.googlegroups.com> HAI ALL... U KNOW, NOW DATING WITH SWEETHARTS IS EAZY AND FREE....... HAI ALL... U KNOW, NOW DATING WITH SWEETHARTS IS EAZY AND FREE....... JUST FOLLOW THE LINK....... http://tinyurl.com/eazy-dating http://tinyurl.com/eazy-dating http://tinyurl.com/eazy-dating http://tinyurl.com/eazy-dating http://tinyurl.com/eazy-dating http://tinyurl.com/eazy-dating http://tinyurl.com/eazy-dating http://tinyurl.com/eazy-dating http://tinyurl.com/eazy-dating From arnodel at gmail.com Mon Nov 1 17:13:42 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Mon, 01 Nov 2010 21:13:42 +0000 Subject: playful coding problems for 10 year olds References: Message-ID: <87d3qo692x.fsf@gmail.com> Daniel Fetchinson writes: > Hi folks, > > My niece is interested in programming and python looks like a good > choice (she already wrote a couple of lines :)) She is 10 and I > thought it would be good to have a bunch of playful coding problems > for her, stuff that she could code herself maybe after some initial > help. > > Do you guys know problems like these? Or a good resource where to look > them up? > > Cheers, > Daniel I don't have a list of problems, but I think it's nice to have an environment that provides a very easy way to draw graphics and interact with the user (the way it could be done in the 80s on most personal computers). If you want to use Python, Pyprocessing [1] is an attempt to provide such an environment. Python has a sig that might be relevant: edu-sig [2]. The web page has a lot of links. Finally, I have written an online programming game [3] provisionally called "Robo2flags" where the player has to direct a robot through a maze to catch all the flags it contains. But the robot can't be controlled in real-time; you have to design a circuit board for it (in fact, a program). It's not quite the finished product, but it works and the server is in Python! It needs a browser that implements canvas though (e.g. Firefox, Chrome, Safari). [1] http://code.google.com/p/pyprocessing/ [2] http://www.python.org/community/sigs/current/edu-sig/ [3] http://www.marooned.org.uk/robo -- Arnaud From martin at v.loewis.de Mon Nov 1 17:48:05 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Mon, 01 Nov 2010 22:48:05 +0100 Subject: playful coding problems for 10 year olds In-Reply-To: References: Message-ID: <4CCF3595.2060102@v.loewis.de> > My niece is interested in programming and python looks like a good > choice (she already wrote a couple of lines :)) She is 10 and I > thought it would be good to have a bunch of playful coding problems > for her, stuff that she could code herself maybe after some initial > help. I think anything that has to do with drawing and colors will be attractive, animated if possible. It has to look nice. Take a look at the turtle demos. Regards, Martin From mskcrpttnrmt at gmail.com Mon Nov 1 17:55:06 2010 From: mskcrpttnrmt at gmail.com (Fossil) Date: Mon, 1 Nov 2010 14:55:06 -0700 (PDT) Subject: serial I/O install fail -- DLL not found Message-ID: Just starting with Python. Installed: Python 2.7 pywin32-214.win32-py2.7.exe pyserial-2.5.win32.exe on a Home WinXP SP3 Toshiba laptop with 2GB memory. Open Python and try to do simple I/O test and can't even get past first line. Transcript below. You will see that __name__ is defined as '__main__" but path is not defined. Could this be due to creating the folder holding the Python.exe being on the E: drive or for some other obscure reason? The DOS path environmental variable includes: e:\Program Files\Python27 Thanks in advance for for any help. **********transcript************* Python 2.7 (r27:82525, Jul 4 2010, 09:01:59) [MSC v.1500 32 bit (Intel)] on win 32 Type "help", "copyright", "credits" or "license" for more information. >>> from uspp import * Traceback (most recent call last): File "", line 1, in File "E:\Python27\lib\uspp.py", line 189, in from SerialPort_win import * File "E:\Python27\lib\SerialPort_win.py", line 54, in from win32file import * File "E:\Python27\lib\win32file.py", line 12, in __load() File "E:\Python27\lib\win32file.py", line 10, in __load mod = imp.load_dynamic(__name__, path) ImportError: DLL load failed: The specified module could not be found. >>> path Traceback (most recent call last): File "", line 1, in NameError: name 'path' is not defined >>> __name__ '__main__' >>> From ldo at geek-central.gen.new_zealand Mon Nov 1 18:16:46 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 02 Nov 2010 11:16:46 +1300 Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> Message-ID: In message <4CCE6FF6.2050408 at v.loewis.de>, Martin v. Loewis wrote: > (in fact, I can't think any situation where I would use the backslash). for \ Description, Attr, ColorList \ in \ ( ("normal", "image", MainWindow.ColorsNormalList), ("highlighted", "highlight", MainWindow.ColorsHighlightedList), ("selected", "select", MainWindow.ColorsSelectedList), ) \ : ... #end for From ldo at geek-central.gen.new_zealand Mon Nov 1 18:18:23 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 02 Nov 2010 11:18:23 +1300 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: In message <8j8am4Fk2jU1 at mid.individual.net>, Peter Pearson wrote: > On Mon, 01 Nov 2010 12:09:12 +1300, Lawrence D'Oliveiro wrote: > >> In message <4ccd5ad9$0$19151$426a74cc at news.free.fr>, jf wrote: >> >>> I edit each file to remove tabs ... >> >> expand -i newfile >> >>> Do you know a tools to compare the initial file with the cleaned one to >>> know if the algorithms are the same ? >> >> diff -b oldfile newfile > > Warning: "diff -b" won't detect changes in indentation. Changes in > indentation can change a Python program. I?m getting less and less keen on that particular feature of Python... From invalid at invalid.invalid Mon Nov 1 18:24:03 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 1 Nov 2010 22:24:03 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: On 2010-11-01, Lawrence D'Oliveiro wrote: > In message <8j8am4Fk2jU1 at mid.individual.net>, Peter Pearson wrote: >> >>> diff -b oldfile newfile >> >> Warning: "diff -b" won't detect changes in indentation. Changes in >> indentation can change a Python program. > > I'm getting less and less keen on that particular feature of Python... Why? Other languages have similar problems if you remove salient bits of syntax before comparing two source files files. For exmaple, if you remove all of the curly-braces from two C source files before comparing them, you don't get useful results. -- Grant Edwards grant.b.edwards Yow! I'm continually AMAZED at at th'breathtaking effects gmail.com of WIND EROSION!! From ldo at geek-central.gen.new_zealand Mon Nov 1 18:25:14 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 02 Nov 2010 11:25:14 +1300 Subject: playful coding problems for 10 year olds References: <4CCF3595.2060102@v.loewis.de> Message-ID: In message <4CCF3595.2060102 at v.loewis.de>, Martin v. Loewis wrote: > Take a look at the turtle demos. Are turtle graphics still enough to hold the kids? interest these days? I?ve been visiting a local Computer Clubhouse, and it seems like they mostly spend their time in Google SketchUp and Photoshop. I managed to get one older one interested in Blender. What kind of easy programming exercises could compare with that? From benjamin.kaplan at case.edu Mon Nov 1 18:32:51 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 1 Nov 2010 18:32:51 -0400 Subject: serial I/O install fail -- DLL not found In-Reply-To: References: Message-ID: On Mon, Nov 1, 2010 at 5:55 PM, Fossil wrote: > Just starting with Python. > Installed: > ?Python 2.7 > ?pywin32-214.win32-py2.7.exe > ?pyserial-2.5.win32.exe > on a Home WinXP SP3 Toshiba laptop with 2GB memory. ?Open Python and > try to do simple I/O test and can't even get past first line. > Transcript below. ?You will see that > __name__ is defined as '__main__" > but path is not defined. ?Could this be due to creating the folder > holding the Python.exe being on the E: drive or for some other obscure > reason? ?The DOS path environmental variable includes: > e:\Program Files\Python27 > Thanks in advance for for any help. > **********transcript************* > > Python 2.7 (r27:82525, Jul ?4 2010, 09:01:59) [MSC v.1500 32 bit > (Intel)] on win > 32 > Type "help", "copyright", "credits" or "license" for more information. >>>> from uspp import * > Traceback (most recent call last): > ?File "", line 1, in > ?File "E:\Python27\lib\uspp.py", line 189, in > ? ?from SerialPort_win import * > ?File "E:\Python27\lib\SerialPort_win.py", line 54, in > ? ?from win32file import * > ?File "E:\Python27\lib\win32file.py", line 12, in > ? ?__load() > ?File "E:\Python27\lib\win32file.py", line 10, in __load > ? ?mod = imp.load_dynamic(__name__, path) > ImportError: DLL load failed: The specified module could not be found. >>>> path > Traceback (most recent call last): > ?File "", line 1, in > NameError: name 'path' is not defined >>>> __name__ > '__main__' >>>> > -- Python does not have true globals. At most, a variable is global to the module. __name__ in win32file.py is going to be 'win32file'. path is going to be something else. Without looking at the source of the file, I can't tell you what it is. The fact that you From emile at fenx.com Mon Nov 1 18:36:43 2010 From: emile at fenx.com (Emile van Sebille) Date: Mon, 01 Nov 2010 15:36:43 -0700 Subject: playful coding problems for 10 year olds In-Reply-To: <4CCF3595.2060102@v.loewis.de> References: <4CCF3595.2060102@v.loewis.de> Message-ID: On 11/1/2010 2:48 PM Martin v. Loewis said... >> My niece is interested in programming and python looks like a good >> choice (she already wrote a couple of lines :)) She is 10 and I >> thought it would be good to have a bunch of playful coding problems >> for her, stuff that she could code herself maybe after some initial >> help. > > I think anything that has to do with drawing and colors will be > attractive, animated if possible. It has to look nice. > > Take a look at the turtle demos. > Six or eight years ago when my kids were about that age I got them to play around with pygame, but frankly, I had more success getting them to read html and identify cut n paste-able fragments to put in their myspaceface places. Emile From exarkun at twistedmatrix.com Mon Nov 1 18:43:23 2010 From: exarkun at twistedmatrix.com (exarkun at twistedmatrix.com) Date: Mon, 01 Nov 2010 22:43:23 -0000 Subject: [ANN] pyOpenSSL 0.11 released Message-ID: <20101101224323.2040.732989284.divmod.xquotient.500@localhost.localdomain> Hello all, I'm happy to announce the release of pyOpenSSL 0.11. The primary change from the last release is that Python 3.2 is now supported. Python 2.4 through Python 2.7 are still supported as well. This release also fixes a handful of bugs in error handling code. It also adds APIs for generating and verifying cryptographic signatures and it improves the test suite to cover nearly 80% of the implementation. Downloads and more details about the release can be found on the release page: https://launchpad.net/pyopenssl/main/0.11 Enjoy, Jean-Paul From dalist0 at gmail.com Mon Nov 1 18:44:01 2010 From: dalist0 at gmail.com (Daniel) Date: Mon, 1 Nov 2010 15:44:01 -0700 (PDT) Subject: extracting variables accessed and written from function / rule-based function calls Message-ID: <0d74ca46-657c-41cc-a582-0d78f11350a3@30g2000yql.googlegroups.com> Hello, I have a class with some members that depend on others. Initially most of them are None. For each one there is a function to calculate it as soon as some other dependencies become available. In the end, all values can be computed by the right sequence of function applications. class A: def __init__(self): self.a = None self.b = None self.c = none def f1(self): # compute a given b and c self.a = 2*self.b + math.sin(self.c) Now I am looking for a way to call these functions only when the preconditions are met (in this case b and c are not None) and when the result is needed (a is None). I could wrap each function in a class like this: class rule_a_from_b_and_c: def __init__(self, parent): self.parent = parent def pre(self): return self.parent.b is not None and self.parent.c is not None def needed(self): return self.parent.a is None def rule(self): self.parent.a = 2*self.parent.b + math.sin(self.parent.c) This way I have to replicate the inputs an the output of the function for each rule, which is a lot of work. Is there a way to access the values read by the function and written to by the function f? Like values _read(f) returns (self.b, self.c), values_written(f) returns (self.a,) Dan From ben+python at benfinney.id.au Mon Nov 1 18:46:03 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 02 Nov 2010 09:46:03 +1100 Subject: [Beginer Question] I heard about python needing somesort of_VariableName_ boiler plate? References: <878w1dlk81.fsf@benfinney.id.au> <4CCEF9E2.2000803@mrabarnett.plus.com> Message-ID: <87zktsk6hg.fsf@benfinney.id.au> bradenf at hotmail.com writes: > Sorry that is what I mean. What is it for? Branden, you're welcome to ask questions about Python here. But please, help us help you: Don't top-post. It makes the flow of conversation difficult to follow. Instead, respond in-line beneath the point you're responding to, and remove extraneous quoted material that you're not responding to (this message is an example). That way, references like ?that is what I mean? make a whole lot more sense. > Sent wirelessly from my BlackBerry. If you are using a mail client that spams us with its advertising, and makes normal message composition difficult, then please don't; instead compose your messages using a better mail client. Hope that helps, and good hunting to you as you learn Python :-) -- \ ?What if the Hokey Pokey IS what it's all about?? ?anonymous | `\ | _o__) | Ben Finney From ppearson at nowhere.invalid Mon Nov 1 18:48:16 2010 From: ppearson at nowhere.invalid (Peter Pearson) Date: 1 Nov 2010 22:48:16 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: <8j8udgFlkvU1@mid.individual.net> On Mon, 1 Nov 2010 22:24:03 +0000 (UTC), Grant Edwards wrote: > On 2010-11-01, Lawrence D'Oliveiro wrote: >> In message <8j8am4Fk2jU1 at mid.individual.net>, Peter Pearson wrote: >>> >>>> diff -b oldfile newfile >>> >>> Warning: "diff -b" won't detect changes in indentation. Changes in >>> indentation can change a Python program. >> >> I'm getting less and less keen on that particular feature of Python... > > Why? > > Other languages have similar problems if you remove salient bits of > syntax before comparing two source files files. > > For exmaple, if you remove all of the curly-braces from two C source > files before comparing them, you don't get useful results. True, but diff doesn't come with an "ignore curly braces" option. I'm not personally repelled by Python's use of significant indentation, but I must concede that some awkwardness results from assigning significance to something (whitespace) that many tools are inclined to treat as insignificant. -- To email me, substitute nowhere->spamcop, invalid->net. From gherron at digipen.edu Mon Nov 1 19:17:37 2010 From: gherron at digipen.edu (Gary Herron) Date: Mon, 01 Nov 2010 16:17:37 -0700 Subject: playful coding problems for 10 year olds In-Reply-To: References: Message-ID: <4CCF4A91.3070007@digipen.edu> On 11/01/2010 01:31 PM, Daniel Fetchinson wrote: > Hi folks, > > My niece is interested in programming and python looks like a good > choice (she already wrote a couple of lines :)) She is 10 and I > thought it would be good to have a bunch of playful coding problems > for her, stuff that she could code herself maybe after some initial > help. > > Do you guys know problems like these? Or a good resource where to look them up? > > Cheers, > Daniel > > Does she like robots? My kid's school started a program last year (for 5th and 6th graders) that taught some Python programming in the guise of controlling a small robot. The programs was created by Institute for Personal Robots in Education (IPRE) at http://wiki.roboteducation.org/Main_Page. The hardware is the scribbler robot (http://wiki.roboteducation.org/Myro_Hardware) controlled via a bluetooth connection. It has the ability to move forward/backward at varying speeds and turn radii, dragging a pen for drawing if you wish. It has IR and light sensors, and a camera. It also has several programmable LEDs, and can play music and make beeps. The software is a Python library called Myro (http://wiki.roboteducation.org/Myro_Reference_Manual) that allows to control the scribbler interactively (through Idle) or via written/save Python files. By the end of one semester, (some of) the kids were able to program small Python loops and a few if statements based on sensor values for object avoidance or light following and such. Great fun (and a bit of Python programming) was had by all. -- Gary Herron, PhD. Department of Computer Science DigiPen Institute of Technology (425) 895-4418 From emile at fenx.com Mon Nov 1 19:18:20 2010 From: emile at fenx.com (Emile van Sebille) Date: Mon, 01 Nov 2010 16:18:20 -0700 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: On 11/1/2010 3:18 PM Lawrence D'Oliveiro said... > In message<8j8am4Fk2jU1 at mid.individual.net>, Peter Pearson wrote: >> Warning: "diff -b" won't detect changes in indentation. Changes in >> indentation can change a Python program. > > I?m getting less and less keen on that particular feature of Python... That feature being indentation based structure? At least you can look at python code and _know_ that spurious placement of required line noise don't have the ability to impact what the code does. Emile From ldo at geek-central.gen.new_zealand Mon Nov 1 19:22:41 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 02 Nov 2010 12:22:41 +1300 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: In message , Emile van Sebille wrote: > At least you can look at python code and _know_ that spurious placement of > required line noise don't have the ability to impact what the code does. But it does. What is spurious whitespace if not noise, after all? From python at mrabarnett.plus.com Mon Nov 1 19:23:47 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 01 Nov 2010 23:23:47 +0000 Subject: extracting variables accessed and written from function / rule-based function calls In-Reply-To: <0d74ca46-657c-41cc-a582-0d78f11350a3@30g2000yql.googlegroups.com> References: <0d74ca46-657c-41cc-a582-0d78f11350a3@30g2000yql.googlegroups.com> Message-ID: <4CCF4C03.2020203@mrabarnett.plus.com> On 01/11/2010 22:44, Daniel wrote: > Hello, > > > I have a class with some members that depend on others. Initially most > of them are None. > For each one there is a function to calculate it as soon as some other > dependencies become available. > In the end, all values can be computed by the right sequence of > function applications. > > class A: > def __init__(self): > self.a = None > self.b = None > self.c = none > > def f1(self): # compute a given b and c > self.a = 2*self.b + math.sin(self.c) > > Now I am looking for a way to call these functions only when the > preconditions are met (in this case b and c are not None) and when the > result is needed (a is None). > I could wrap each function in a class like this: > class rule_a_from_b_and_c: > def __init__(self, parent): self.parent = parent > def pre(self): return self.parent.b is not None and self.parent.c > is not None > def needed(self): return self.parent.a is None > def rule(self): self.parent.a = 2*self.parent.b + > math.sin(self.parent.c) > > This way I have to replicate the inputs an the output of the function > for each rule, which is a lot of work. > Is there a way to access the values read by the function and written > to by the function f? > Like values _read(f) returns (self.b, self.c), values_written(f) > returns (self.a,) > You might be interested by the story of how AstraZeneca tackled that kind of problem in PyDrone: http://www.python.org/about/success/astra/ From ldo at geek-central.gen.new_zealand Mon Nov 1 19:24:12 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 02 Nov 2010 12:24:12 +1300 Subject: how to sync file on client and server References: Message-ID: In message , nu wrote: > I want to sync the file foder in different server,and I can't use ftp > protocl. > I try to sync files during defferent server and not use username and > password to login. Set up an SSH public/private key pair. Then run Rsync over SSH. Job done. From ldo at geek-central.gen.new_zealand Mon Nov 1 19:30:39 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 02 Nov 2010 12:30:39 +1300 Subject: import ImageGrab fails on Ubuntu 10.04 References: <4ccd9394$0$4326$426a74cc@news.free.fr> <4ccd954f$0$12350$426a74cc@news.free.fr> Message-ID: In message <4ccd954f$0$12350$426a74cc at news.free.fr>, News123 wrote: > Is there any other way to make screen shots in Linux, ideally without > creating an intermediate file The ImageMagick ?import? command lets you grab the contents of any window (including the root window) from your X server . It wants an output filename, but of course that can be /dev/stdout, e.g. import -window root /dev/stdout | display From ian.g.kelly at gmail.com Mon Nov 1 19:37:55 2010 From: ian.g.kelly at gmail.com (Ian) Date: Mon, 1 Nov 2010 16:37:55 -0700 (PDT) Subject: serial I/O install fail -- DLL not found References: Message-ID: <59d3eeea-3776-479e-b754-04e188f9be07@u17g2000yqi.googlegroups.com> On Nov 1, 3:55?pm, Fossil wrote: > Just starting with Python. > Installed: > ? Python 2.7 > ? pywin32-214.win32-py2.7.exe > ? pyserial-2.5.win32.exe > on a Home WinXP SP3 Toshiba laptop with 2GB memory. ?Open Python and > try to do simple I/O test and can't even get past first line. > Transcript below. ?You will see that > __name__ is defined as '__main__" > but path is not defined. ?Could this be due to creating the folder > holding the Python.exe being on the E: drive or for some other obscure > reason? ?The DOS path environmental variable includes: > e:\Program Files\Python27 Unlikely. Where I work we run Python with pywin32 across the company from a network drive and don't have any problems like this one. > **********transcript************* > > Python 2.7 (r27:82525, Jul ?4 2010, 09:01:59) [MSC v.1500 32 bit > (Intel)] on win > 32 > Type "help", "copyright", "credits" or "license" for more information.>>> from uspp import * > > Traceback (most recent call last): > ? File "", line 1, in > ? File "E:\Python27\lib\uspp.py", line 189, in > ? ? from SerialPort_win import * > ? File "E:\Python27\lib\SerialPort_win.py", line 54, in > ? ? from win32file import * > ? File "E:\Python27\lib\win32file.py", line 12, in > ? ? __load() > ? File "E:\Python27\lib\win32file.py", line 10, in __load > ? ? mod = imp.load_dynamic(__name__, path) > ImportError: DLL load failed: The specified module could not be found. The paths in this traceback are weird. If E:\Python27 is where Python is installed, E:\Python27\lib should be where the files in the Python standard library reside. Installed third-party modules such as the ones above should be located in E:\Python27\lib\site-packages. It would appear that some zip files were incorrectly extracted into this folder. Anyway, your problem appears to be the win32file.py in E: \Python27\lib. This is a wrapper file that the isapi package includes when creating an executable with py2exe. It doesn't make any sense for it to be found in this location, and all it's succeeding in doing is obscuring the real win32file import, which should be a dll at E: \Python27\lib\site-packages\win32\win32file.pyd. I suggest reinstalling, putting things into their proper directories this time, and skipping whatever you unzipped that got you that win32file.py file. Hope this helps, Ian From prologic at shortcircuit.net.au Mon Nov 1 19:38:47 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Tue, 2 Nov 2010 09:38:47 +1000 Subject: extracting variables accessed and written from function / rule-based function calls In-Reply-To: <4CCF4C03.2020203@mrabarnett.plus.com> References: <0d74ca46-657c-41cc-a582-0d78f11350a3@30g2000yql.googlegroups.com> <4CCF4C03.2020203@mrabarnett.plus.com> Message-ID: On Tue, Nov 2, 2010 at 9:23 AM, MRAB wrote: > You might be interested by the story of how AstraZeneca tackled that > kind of problem in PyDrone: http://www.python.org/about/success/astra/ This might be a good use-case (if I'm reading the post correctly) for "Traits" (1) cheers James 1. http://pypi.python.org/pypi/Traits/3.5.0 -- -- James Mills -- -- "Problems are solved by method" From clp2 at rebertia.com Mon Nov 1 19:42:41 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 1 Nov 2010 16:42:41 -0700 Subject: Allowing comments after the line continuation backslash In-Reply-To: References: <4CCE6FF6.2050408@v.loewis.de> Message-ID: On Mon, Nov 1, 2010 at 3:16 PM, Lawrence D'Oliveiro wrote: > In message <4CCE6FF6.2050408 at v.loewis.de>, Martin v. Loewis wrote: > >> (in fact, I can't think any situation where I would use the backslash). > > ? ?for \ > ? ? ? ?Description, Attr, ColorList \ > ? ?in \ > ? ? ? ?( > ? ? ? ? ? ?("normal", "image", MainWindow.ColorsNormalList), > ? ? ? ? ? ?("highlighted", "highlight", MainWindow.ColorsHighlightedList), > ? ? ? ? ? ?("selected", "select", MainWindow.ColorsSelectedList), > ? ? ? ?) \ > ? ?: > ? ? ? ... > ? ?#end for > > I find the level of deviation from PEP 8 in that file rather disturbing. In any case, the backslashes are easily avoided, and readability improved IMHO, via refactoring: desc_attr_colors_triples = (("normal", "image", MainWindow.ColorsNormalList), ("highlighted", "highlight", MainWindow.ColorsHighlightedList), ("selected", "select", MainWindow.ColorsSelectedList)) for in description, attr, color_list in desc_attr_colors_triples: ... Cheers, Chris -- http://blog.rebertia.com From ian.g.kelly at gmail.com Mon Nov 1 19:54:20 2010 From: ian.g.kelly at gmail.com (Ian) Date: Mon, 1 Nov 2010 16:54:20 -0700 (PDT) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <8j8udgFlkvU1@mid.individual.net> Message-ID: <0c3f009d-631f-4e39-9c0f-99628566d794@s5g2000yqm.googlegroups.com> On Nov 1, 4:48?pm, Peter Pearson wrote: > True, but diff doesn't come with an "ignore curly braces" option. > I'm not personally repelled by Python's use of significant indentation, > but I must concede that some awkwardness results from assigning > significance to something (whitespace) that many tools are inclined > to treat as insignificant. Beyond Compare at least is smart enough to know that leading whitespace is significant in .py files, using the default configuration. Cheers, Ian From python at mrabarnett.plus.com Mon Nov 1 20:15:14 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 02 Nov 2010 00:15:14 +0000 Subject: extracting variables accessed and written from function / rule-based function calls In-Reply-To: References: <0d74ca46-657c-41cc-a582-0d78f11350a3@30g2000yql.googlegroups.com> <4CCF4C03.2020203@mrabarnett.plus.com> Message-ID: <4CCF5812.40007@mrabarnett.plus.com> On 01/11/2010 23:38, James Mills wrote: > On Tue, Nov 2, 2010 at 9:23 AM, MRAB wrote: >> You might be interested by the story of how AstraZeneca tackled that >> kind of problem in PyDrone: http://www.python.org/about/success/astra/ > > This might be a good use-case (if I'm reading the post correctly) for > "Traits" (1) > > cheers > James > > 1. http://pypi.python.org/pypi/Traits/3.5.0 > There's a difference between "Traits" and what PyDrone does. In Traits, when a value changes, it notifies other values which depend on it. In PyDrone, there are constants, some of which depend on other constants and need to be calculated. When a value is first requested it is calculated, which might trigger the calculation of other values if it's the first time that they've been requested, so no calculation (work) is done until it's needed. From mskcrpttnrmt at gmail.com Mon Nov 1 20:44:58 2010 From: mskcrpttnrmt at gmail.com (Fossil) Date: Mon, 1 Nov 2010 17:44:58 -0700 (PDT) Subject: serial I/O install fail -- DLL not found References: <59d3eeea-3776-479e-b754-04e188f9be07@u17g2000yqi.googlegroups.com> Message-ID: Thank you, Ian. You put your finger on the problem. As I thrashed around earlier, I had installed serial i/o pieces before the clean install pieces of pywin32-214.win32-py2.7.exe pyserial-2.5.win32.exe I did a complete de-install and re-install. Now the serial i/o is functioning -- I'm still stumbling along with the typical mistakes of a 'newbie'. Thanks again. Chas. From lightsilver3 at gmail.com Mon Nov 1 21:10:36 2010 From: lightsilver3 at gmail.com (silver light) Date: Mon, 1 Nov 2010 18:10:36 -0700 (PDT) Subject: *** FBI gets a warm welcome in Chicago for their EXCELLENT performance - cheers to NEW CONS *** Message-ID: <26f97f70-9043-490c-9e6e-35159f38d76b@r29g2000yqj.googlegroups.com> *** FBI gets a warm welcome in Chicago for their EXCELLENT performance - cheers to NEW CONS *** http://www.youtube.com/watch?v=eq2ZvSd-z0M&feature=player_embedded&related http://www.youtube.com/watch?v=eq2ZvSd-z0M&feature=player_embedded&related http://www.youtube.com/watch?v=eq2ZvSd-z0M&feature=player_embedded&related http://www.youtube.com/watch?v=eq2ZvSd-z0M&feature=player_embedded&related http://www.youtube.com/watch?v=eq2ZvSd-z0M&feature=player_embedded&related From glyph at twistedmatrix.com Mon Nov 1 21:15:22 2010 From: glyph at twistedmatrix.com (Glyph Lefkowitz) Date: Mon, 1 Nov 2010 21:15:22 -0400 Subject: [pyOpenSSL] [ANN] pyOpenSSL 0.11 released In-Reply-To: <20101101224323.2040.732989284.divmod.xquotient.500@localhost.localdomain> References: <20101101224323.2040.732989284.divmod.xquotient.500@localhost.localdomain> Message-ID: On Nov 1, 2010, at 6:43 PM, exarkun at twistedmatrix.com wrote: > I'm happy to announce the release of pyOpenSSL 0.11. Congratulations, JP! It's great to see this effort coming together. -------------- next part -------------- An HTML attachment was scrubbed... URL: From brf256 at gmail.com Mon Nov 1 21:21:56 2010 From: brf256 at gmail.com (brf256 at gmail.com) Date: Tue, 2 Nov 2010 01:21:56 +0000 Subject: *** FBI gets a warm welcome in Chicago for their EXCELLENTperformance - cheers to NEW CONS *** In-Reply-To: <26f97f70-9043-490c-9e6e-35159f38d76b@r29g2000yqj.googlegroups.com> References: <26f97f70-9043-490c-9e6e-35159f38d76b@r29g2000yqj.googlegroups.com> Message-ID: <787900953-1288660917-cardhu_decombobulator_blackberry.rim.net-361156004-@bda480.bisx.prod.on.blackberry> How exactly does this relate to python? Sent wirelessly from my BlackBerry device on the Bell network. Envoy? sans fil par mon terminal mobile BlackBerry sur le r?seau de Bell. -----Original Message----- From: silver light Sender: python-list-bounces+brf256=gmail.com at python.org Date: Mon, 1 Nov 2010 18:10:36 To: Cc: Subject: *** FBI gets a warm welcome in Chicago for their EXCELLENT performance - cheers to NEW CONS *** *** FBI gets a warm welcome in Chicago for their EXCELLENT performance - cheers to NEW CONS *** http://www.youtube.com/watch?v=eq2ZvSd-z0M&feature=player_embedded&related http://www.youtube.com/watch?v=eq2ZvSd-z0M&feature=player_embedded&related http://www.youtube.com/watch?v=eq2ZvSd-z0M&feature=player_embedded&related http://www.youtube.com/watch?v=eq2ZvSd-z0M&feature=player_embedded&related http://www.youtube.com/watch?v=eq2ZvSd-z0M&feature=player_embedded&related -- http://mail.python.org/mailman/listinfo/python-list From clp2 at rebertia.com Mon Nov 1 21:35:12 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 1 Nov 2010 18:35:12 -0700 Subject: *** FBI gets a warm welcome in Chicago for their EXCELLENTperformance - cheers to NEW CONS *** In-Reply-To: <787900953-1288660917-cardhu_decombobulator_blackberry.rim.net-361156004-@bda480.bisx.prod.on.blackberry> References: <26f97f70-9043-490c-9e6e-35159f38d76b@r29g2000yqj.googlegroups.com> <787900953-1288660917-cardhu_decombobulator_blackberry.rim.net-361156004-@bda480.bisx.prod.on.blackberry> Message-ID: > -----Original Message----- > From: silver light > Sender: python-list-bounces+brf256=gmail.com at python.org > Date: Mon, 1 Nov 2010 18:10:36 > To: > Cc: > Subject: *** FBI gets a warm welcome in Chicago for their EXCELLENT > ? ? ? ?performance - cheers to NEW CONS *** > > *** FBI gets a warm welcome in Chicago for their EXCELLENT performance > - cheers to NEW CONS *** On Mon, Nov 1, 2010 at 6:21 PM, wrote: > How exactly does this relate to python? It doesn't. It's spam that was apparently also cross-posted to sci.math, sci.physics, comp.text.tex, and comp.unix.shell. I advise reporting the sender, lightsilver3 at gmail.com, to Gmail's abuse team: http://mail.google.com/support/bin/request.py?contact_type=abuse Cheers, Chris From wuwei23 at gmail.com Mon Nov 1 22:00:00 2010 From: wuwei23 at gmail.com (alex23) Date: Mon, 1 Nov 2010 19:00:00 -0700 (PDT) Subject: Allow multiline conditions and the like References: <4cce7196$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: Chris Rebert wrote: > Or, if possible, refactor the conditional into a function (call) so > it's no longer multiline in the first place. Or even simpler, assign the condition result to a variable: a_b_positive = a > 0 and b > 0 if a_b_positive: ... From ldo at geek-central.gen.new_zealand Mon Nov 1 23:15:03 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 02 Nov 2010 16:15:03 +1300 Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> Message-ID: In message , Chris Rebert wrote: > desc_attr_colors_triples = (("normal", "image", > MainWindow.ColorsNormalList), > ("highlighted", "highlight", MainWindow.ColorsHighlightedList), > ("selected", "select", MainWindow.ColorsSelectedList)) > for in description, attr, color_list in desc_attr_colors_triples: > ... And so you have managed to separate one set of looping conditions into two parts. What is the significance of the name ?desc_attr_colors_triples?? None at all. What purpose does it serve? None, really. Does it ease the maintenance burden? No, but by splitting your attention across two places, it actually adds to it. If this is all your PEP-8 can achieve, then a pox on it. From ldo at geek-central.gen.new_zealand Mon Nov 1 23:18:09 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 02 Nov 2010 16:18:09 +1300 Subject: serial I/O install fail -- DLL not found References: <59d3eeea-3776-479e-b754-04e188f9be07@u17g2000yqi.googlegroups.com> Message-ID: In message , Fossil wrote: > I did a complete de-install and re-install. Standard solution to Dimdows problems, really... From smallpox911 at gmail.com Mon Nov 1 23:18:28 2010 From: smallpox911 at gmail.com (small Pox) Date: Mon, 1 Nov 2010 20:18:28 -0700 (PDT) Subject: *** FBI gets a warm welcome in Chicago for their EXCELLENTperformance - cheers to NEW CONS *** References: <26f97f70-9043-490c-9e6e-35159f38d76b@r29g2000yqj.googlegroups.com> <787900953-1288660917-cardhu_decombobulator_blackberry.rim.net-361156004-@bda480.bisx.prod.on.blackberry> Message-ID: <4d568ef3-e637-4408-9e02-818faaf440c3@r14g2000yqa.googlegroups.com> On Nov 1, 6:35?pm, Chris Rebert wrote: > > -----Original Message----- > > From: silver light > > Sender: python-list-bounces+brf256=gmail.... at python.org > > Date: Mon, 1 Nov 2010 18:10:36 > > To: > > Cc: > > Subject: *** FBI gets a warm welcome in Chicago for their EXCELLENT > > ? ? ? ?performance - cheers to NEW CONS *** > > > *** FBI gets a warm welcome in Chicago for their EXCELLENT performance > > - cheers to NEW CONS *** > > > > On Mon, Nov 1, 2010 at 6:21 PM, ? wrote: > > How exactly does this relate to python? > > It doesn't. It's spam that was apparently also cross-posted to > sci.math, sci.physics, comp.text.tex, and comp.unix.shell. IT IS MOST CERTAINLY NOTTTTTT a SPAM. THIS FBI CENSORSHIP MOTHER FOCKER is the REAL SPAMMER AND CRIMINAL who wants to limit the news of their HEINOUS CRIMES and INCOMPETENCE to be SPREAD. The fact is that the real spammers are those who post PORNOGRAPHIC and COMMERCIAL messages on which the FBI CIA BLACKWATER and MOSSAD mother fockers masterbate and rape their mothers daily. AND NEVER SPEAK OUT. The truth of 911 bites them like the sting of a snake and truth it is. > I advise reporting the sender, lightsilv... at gmail.com, to Gmail's abuse team:http://mail.google.com/support/bin/request.py?contact_type=abuse > > Cheers, > Chris From ldo at geek-central.gen.new_zealand Mon Nov 1 23:21:42 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 02 Nov 2010 16:21:42 +1300 Subject: factorial of negative one (-1) References: <87r5f55qj5.fsf@xemacs.org> Message-ID: In message <87r5f55qj5.fsf at xemacs.org>, Hrvoje Niksic wrote: > Python has a little-known but very instructive method for determining the > makeup of a float: > >>>> 1.1 .as_integer_ratio() > (2476979795053773, 2251799813685248) Only available in 2.6 or later. Are we already talking as though 2.5 doesn?t exist any more? I still have client machines running that (Debian Stable 5.0). :) From ldo at geek-central.gen.new_zealand Mon Nov 1 23:26:46 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 02 Nov 2010 16:26:46 +1300 Subject: ANN: PyQt v4.8.1 Released References: Message-ID: In message , Phil Thompson wrote: > PyQt is available under the GPL and a commercial license. Surely you mean ?proprietary? rather than ?commercial?. There is nothing about the GPL that prevents ?commercial? use. From ldo at geek-central.gen.new_zealand Mon Nov 1 23:30:40 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 02 Nov 2010 16:30:40 +1300 Subject: functions, list, default parameters References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <20101021235138.609fe668@geekmail.INVALID> Message-ID: In message <20101021235138.609fe668 at geekmail.INVALID>, Andreas Waldenburger wrote: > While not very commonly needed, why should a shared default argument be > forbidden? Because it?s safer to disallow it than to allow it. From ldo at geek-central.gen.new_zealand Mon Nov 1 23:31:18 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 02 Nov 2010 16:31:18 +1300 Subject: functions, list, default parameters References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <8ivelpFif1U1@mid.individual.net> <4cca88bc$0$29987$c3e8da3$5496439d@news.astraweb.com> <8j1seqFa1eU2@mid.individual.net> Message-ID: In message <8j1seqFa1eU2 at mid.individual.net>, Gregory Ewing wrote: > Steven D'Aprano wrote: > >> And how does Python know whether some arbitrary default object is mutable >> or not? > > It doesn't, that's the whole point. Of course it knows. It is the one defining the concept in the first place, after all. From ldo at geek-central.gen.new_zealand Mon Nov 1 23:34:38 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 02 Nov 2010 16:34:38 +1300 Subject: str(int_var) formatted References: <4ccaef45$0$27972$4fafbaef@reader5.news.tin.it> Message-ID: In message , John Yeung wrote: > I will give zfill a little exposure, as it seems unloved/underused: > > str(x).zfill(2) The inside of my brain is a finite place. Each thing I put in there leaves less room for something else. So I have to think very carefully before deciding what to keep in there. Up to this point I have learned to do all this kind of formatting using format strings; is it worth making room in my brain to remember about zfill as well? Somehow, I think not. From python at mrabarnett.plus.com Mon Nov 1 23:58:14 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 02 Nov 2010 03:58:14 +0000 Subject: *** FBI gets a warm welcome in Chicago for their EXCELLENTperformance - cheers to NEW CONS *** In-Reply-To: <4d568ef3-e637-4408-9e02-818faaf440c3@r14g2000yqa.googlegroups.com> References: <26f97f70-9043-490c-9e6e-35159f38d76b@r29g2000yqj.googlegroups.com> <787900953-1288660917-cardhu_decombobulator_blackberry.rim.net-361156004-@bda480.bisx.prod.on.blackberry> <4d568ef3-e637-4408-9e02-818faaf440c3@r14g2000yqa.googlegroups.com> Message-ID: <4CCF8C56.5010409@mrabarnett.plus.com> On 02/11/2010 03:18, small Pox wrote: > On Nov 1, 6:35 pm, Chris Rebert wrote: >>> -----Original Message----- >>> From: silver light >>> Sender: python-list-bounces+brf256=gmail.... at python.org >>> Date: Mon, 1 Nov 2010 18:10:36 >>> To: >>> Cc: >>> Subject: *** FBI gets a warm welcome in Chicago for their EXCELLENT >>> performance - cheers to NEW CONS *** >> >>> *** FBI gets a warm welcome in Chicago for their EXCELLENT performance >>> - cheers to NEW CONS *** >> >> >> >> On Mon, Nov 1, 2010 at 6:21 PM, wrote: >>> How exactly does this relate to python? >> >> It doesn't. It's spam that was apparently also cross-posted to >> sci.math, sci.physics, comp.text.tex, and comp.unix.shell. > > IT IS MOST CERTAINLY NOTTTTTT a SPAM. > [snip] You should look up the definition sometime. From astronautameya at gmail.com Tue Nov 2 00:03:16 2010 From: astronautameya at gmail.com (Ameya the ______) Date: Mon, 1 Nov 2010 21:03:16 -0700 (PDT) Subject: Would you recommend python as a first programming language? References: Message-ID: <19a4eb7e-fe30-4894-966a-586799062239@k22g2000yqh.googlegroups.com> Post this question on the C/C++ group... and do post those replie here :P From robert.kern at gmail.com Tue Nov 2 00:07:00 2010 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 01 Nov 2010 23:07:00 -0500 Subject: functions, list, default parameters In-Reply-To: References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <8ivelpFif1U1@mid.individual.net> <4cca88bc$0$29987$c3e8da3$5496439d@news.astraweb.com> <8j1seqFa1eU2@mid.individual.net> Message-ID: On 2010-11-01 22:31 , Lawrence D'Oliveiro wrote: > In message<8j1seqFa1eU2 at mid.individual.net>, Gregory Ewing wrote: > >> Steven D'Aprano wrote: >> >>> And how does Python know whether some arbitrary default object is mutable >>> or not? >> >> It doesn't, that's the whole point. > > Of course it knows. It is the one defining the concept in the first place, > after all. No, the Python interpreter doesn't define the concept. The Python language developers did. "Immutable objects" are just those without an obvious API for modifying them. With various trickeries, I can mutate any immutable object. The Python interpreter doesn't know what's an "obvious API" and what isn't. It's a reasonably vague concept that doesn't have an algorithmic formulation. -- 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 usenet-nospam at seebs.net Tue Nov 2 00:16:28 2010 From: usenet-nospam at seebs.net (Seebs) Date: 02 Nov 2010 04:16:28 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: On 2010-11-01, Grant Edwards wrote: > On 2010-11-01, Lawrence D'Oliveiro wrote: >> In message <8j8am4Fk2jU1 at mid.individual.net>, Peter Pearson wrote: >>> Warning: "diff -b" won't detect changes in indentation. Changes in >>> indentation can change a Python program. >> I'm getting less and less keen on that particular feature of Python... > Why? > Other languages have similar problems if you remove salient bits of > syntax before comparing two source files files. Sure. > For exmaple, if you remove all of the curly-braces from two C source > files before comparing them, you don't get useful results. Right. But there's no *reason* to do that, while there are many common daily events which result in whitespace changes. e.g., any email sent to my work account is being magically transformed into HTML (no one knows why) on the server, so I can't get correct indentation except in attachments. Many editors helpfully convert spaces to tabs by default some or all of the time. And so on. The more I use it, the more I think it was an interesting experiment which has worked out about as well as scanf. The "problem" it fixes is something that's hardly ever been a problem for me in C or related languages -- and which could be completely eliminated by automated indenters, which were actually conceptually possible. I've lost more time to indentation issues in Python in a month than I've lost to mismatches between indentation and flow in C in twenty years. In theory, it sounds like it would help to eliminate the ambiguity. In practice, eliminating the question of whether code was intended to follow explicit flow rather than indentation just means that when there's a mistake you don't even get a warning that someone was confused. At least in C, if I see: if (foo) a; else b; c; I *know* that something is wrong. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From lanyjie at yahoo.com Tue Nov 2 00:31:12 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Mon, 1 Nov 2010 21:31:12 -0700 (PDT) Subject: Why this result with the re module Message-ID: <853660.45854.qm@web54207.mail.re2.yahoo.com> Hi, I am rather confused by these results below. I am not a re expert at all. the module version of re is 2.2.1 with python 3.1.2 >>> import re >>> re.findall('.a.', 'Mary has a lamb') #OK ['Mar', 'has', ' a ', 'lam'] >>> re.findall('(.a.)*', 'Mary has a lamb') #?? ['Mar', '', '', 'lam', '', ''] >>> re.findall('(.a.)+', 'Mary has a lamb') #?? ['Mar', 'lam'] Thanks in advance for any comments. Yingjie From darcy at druid.net Tue Nov 2 00:40:31 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 2 Nov 2010 00:40:31 -0400 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: <20101102004031.43d99537.darcy@druid.net> On 02 Nov 2010 04:16:28 GMT Seebs wrote: > But there's no *reason* to do that, while there are many common daily > events which result in whitespace changes. e.g., any email sent > to my work account is being magically transformed into HTML (no one > knows why) on the server, so I can't get correct indentation except > in attachments. Many editors helpfully convert spaces to tabs > by default some or all of the time. And so on. You have problems. Indentation as syntax isn't one of them. "No one knows why" email is being "magically" transformed? Your editor has a mind of its own? Yikes! > I've lost more time to indentation issues in Python in a month than > I've lost to mismatches between indentation and flow in C in twenty Your experience is 180 from mine. > years. In theory, it sounds like it would help to eliminate the > ambiguity. In practice, eliminating the question of whether code > was intended to follow explicit flow rather than indentation just > means that when there's a mistake you don't even get a warning that > someone was confused. > > At least in C, if I see: > if (foo) > a; > else > b; > c; > > I *know* that something is wrong. Does it look right? With Python looking right and being right are the same thing. Once I realized that indentation should only be done using spaces in Python I never had a problem. I certainly had problems with C when the code looked right. Sometimes you can't even see the problem because it's hidden in a badly defined macro. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From lists at asd-group.com Tue Nov 2 01:30:59 2010 From: lists at asd-group.com (John Bond) Date: Tue, 02 Nov 2010 05:30:59 +0000 Subject: Why this result with the re module In-Reply-To: <853660.45854.qm@web54207.mail.re2.yahoo.com> References: <853660.45854.qm@web54207.mail.re2.yahoo.com> Message-ID: <4CCFA213.5090209@asd-group.com> On 2/11/2010 4:31 AM, Yingjie Lan wrote: > Hi, I am rather confused by these results below. > I am not a re expert at all. the module version > of re is 2.2.1 with python 3.1.2 > >>>> import re >>>> re.findall('.a.', 'Mary has a lamb') #OK > ['Mar', 'has', ' a ', 'lam'] >>>> re.findall('(.a.)*', 'Mary has a lamb') #?? > ['Mar', '', '', 'lam', '', ''] >>>> re.findall('(.a.)+', 'Mary has a lamb') #?? > ['Mar', 'lam'] > > > Thanks in advance for any comments. > > Yingjie > > > It's because you're using capturing groups, and because of how they work - specifically they only return the LAST match if used with repetition (and multiple matches occur). For example, take the second example and make it non-capturing: re.findall('(?:.a.)+', 'Mary has a lamb') ['Mar', 'has a lam'] That shows you there are two matches: 1) a three character one at the start of the string (matching one occurance of '.a.'), and 2) a 9 character one a bit later in the string (matching three occurances of '.a.') Turn that back into a capturing group: re.findall('(.a.)+', 'Mary has a lamb') ['Mar', 'lam'] You still have the same two matches as before, but in using the capturing group you're telling findall to return its value each time it matches (not what's actually matched overall). That doesn't affect the first result as it matched a single occurance of what's in the group ('Mar'). But the second one matched three occurances of what's in the group ('has', ' a ', and 'lam'), and the nature of capturing groups is that they only return the last match, so the second returned value is now just 'lam'. So - see if you can explain the first "problematic" result now. From mygogo2011 at gmail.com Tue Nov 2 01:31:27 2010 From: mygogo2011 at gmail.com (PHP.CCC) Date: Mon, 1 Nov 2010 22:31:27 -0700 (PDT) Subject: Advance I.T Training 2011 Message-ID: Advance I.T Training 2011 Advance Excel VBA There are lot of erp software in market erp like Peachtree ,tally software ,account software ,medi cal billing ,tax software, financial soft wares or Software for Finance But We bring you a web site which teach you or guide you to developed a good account, of medi cal billing or Tax Software etc, at you own. We all know that microsoft excel give a unique platform in excel 2003 and excel 2007 as spreadsheet on excel which give excellent opportunity to build our own software. Read more >>> http://childschooledu.blogspot.com/ From vinirma2008 at yahoo.com Tue Nov 2 02:03:59 2010 From: vinirma2008 at yahoo.com (VAM SYSTEMS) Date: Mon, 1 Nov 2010 23:03:59 -0700 (PDT) Subject: Urgent :Required for Oracle DBA in Qatar Message-ID: VAM SYSTEMS is a Business Consulting, IT Solutions and Services company with operations in UAE, Qatar, Bahrain, USA, Australia, Singapore & India. VAM SYSTEMS is currently looking for Oracle DBA for our Qatar operations with the following skill set and terms and conditions: Skill Set required: Strong administration experience in Oracle. Banking experience is mandatory. Experience Required: 5+ years. Terms and conditions: Joining time frame: Immediate (maximum 2 weeks) The selected candidates shall join VAM SYSTEMS ? Qatar and shall be deputed to one of the leading banks in Qatar. Should you be interested in this opportunity, please send your latest resume in MS Word format at the earliest at ambili.krishnan at vamsystems.com or call us +91 0476 2680150. From lanyjie at yahoo.com Tue Nov 2 03:00:52 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Tue, 2 Nov 2010 00:00:52 -0700 (PDT) Subject: Why this result with the re module In-Reply-To: <4CCFA213.5090209@asd-group.com> Message-ID: <589172.15864.qm@web54202.mail.re2.yahoo.com> > From: John Bond > Subject: Re: Why this result with the re module > >>>> re.findall('(.a.)*', 'Mary has a lamb') > > ['Mar', '', '', 'lam', '', ''] > So - see if you can explain the first "problematic" result > now. Thanks a lot for explaining to me the second "problematic" result! But the first one is even more puzzling...mainly because the pattern matches any empty string. Here are more examples: >>> re.findall('(.a.)*','') [''] >>> re.findall('(.a.)*',' ') #one space ['', ''] >>> re.findall('(.a.)*',' ') #two spaces ['', '', ''] >>> len(re.findall('(.a.)*',' '*4)) #four 5 >>> len(re.findall('(.a.)*',' '*8)) #eight 9 I must need more details of the matching algorithm to explain this? Regards, Yingjie From lanyjie at yahoo.com Tue Nov 2 03:05:19 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Tue, 2 Nov 2010 00:05:19 -0700 (PDT) Subject: Why this result with the re module In-Reply-To: <4CCFA213.5090209@asd-group.com> Message-ID: <21513.57929.qm@web54203.mail.re2.yahoo.com> > From: John Bond > >>>> re.findall('(.a.)+', 'Mary has a lamb') > > ['Mar', 'lam'] > It's because you're using capturing groups, and because of > how they work - specifically they only return the LAST match > if used with repetition (and multiple matches occur). It seems capturing groups is assumed by default, but this is somehow against my intuition... Ituitively, it should be what matches the whole regex '(.a.)+', shouldn't it? Regards, Yingjie From ldo at geek-central.gen.new_zealand Tue Nov 2 03:07:13 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 02 Nov 2010 20:07:13 +1300 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: In message , Seebs wrote: > At least in C, if I see: > if (foo) > a; > else > b; > c; > > I *know* that something is wrong. This is why, when I started learning Python, I soon developed the habit of inserting explicit ?#end? markers. To Pythonize your example my way, it would have come out as if foo : a else : b #end if c which should also give a hint that something might be wrong. From ldo at geek-central.gen.new_zealand Tue Nov 2 03:12:49 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 02 Nov 2010 20:12:49 +1300 Subject: functions, list, default parameters References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <8ivelpFif1U1@mid.individual.net> <4cca88bc$0$29987$c3e8da3$5496439d@news.astraweb.com> <8j1seqFa1eU2@mid.individual.net> Message-ID: In message , Robert Kern wrote: > On 2010-11-01 22:31 , Lawrence D'Oliveiro wrote: > >> In message<8j1seqFa1eU2 at mid.individual.net>, Gregory Ewing wrote: >> >>> Steven D'Aprano wrote: >>> >>>> And how does Python know whether some arbitrary default object is >>>> mutable or not? >>> >>> It doesn't, that's the whole point. >> >> Of course it knows. It is the one defining the concept in the first >> place, after all. > > No, the Python interpreter doesn't define the concept. The Python language > developers did. The Python language developers said ?let there be light?, and the Python interpreter gave forth light. So which one defines the concept of ?light?? > "Immutable objects" are just those without an obvious API for modifying > them. They are ones with NO legal language constructs for modifying them. Hint: if a selector of some part of such an object were to occur on the LHS of an assignment, and that would raise an error, then the object is immutable. The interpreter already knows all this. > With various trickeries, I can mutate any immutable object. None within the Python language itself. Which is what we?re talking about here: a language construct which is probably one of the top 3 sources of grief to Python newbies. And not-so-newbies. From clp2 at rebertia.com Tue Nov 2 03:40:17 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 2 Nov 2010 00:40:17 -0700 Subject: functions, list, default parameters In-Reply-To: <4cc13ef5$0$29979$c3e8da3$5496439d@news.astraweb.com> References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <4cc13ef5$0$29979$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Oct 22, 2010 at 12:36 AM, Steven D'Aprano wrote: > On Thu, 21 Oct 2010 19:53:53 -0700, John Nagle wrote: >>> This is a common newbie stumbling-block: Don't use lists (or anything >>> mutable) as default argument values >> >> ? ? ?That really should be an error. > > No it shouldn't. Punishing everybody for a newbie mistake that nobody > makes twice would be the error. > > Default mutable arguments have their place But it's a rather obscure one where it is almost never strictly necessary to venture. Cheers, Chris From lists at asd-group.com Tue Nov 2 03:50:35 2010 From: lists at asd-group.com (John Bond) Date: Tue, 02 Nov 2010 07:50:35 +0000 Subject: Why this result with the re module In-Reply-To: <589172.15864.qm@web54202.mail.re2.yahoo.com> References: <589172.15864.qm@web54202.mail.re2.yahoo.com> Message-ID: <4CCFC2CB.2080500@asd-group.com> On 2/11/2010 7:00 AM, Yingjie Lan wrote: >>> re.findall('(.a.)*',' ') #two spaces > ['', '', ''] > I must need more details of the matching algorithm to explain this? > > Regards, > > Yingjie > > > > Sorry - I hit enter prematurely on my last message. To take the above as an example (all your examples boil down to the same issue), you're asking findall to look for all occurances of something that can exist ZERO or more times, in a string where it doesn't actually exist anywhere. So you get three matches of zero occurrences each - one before the first space, one between the two spaces, and one after the last space. An empty string (indicating that the match consumed no text) is returned for each. The spaces themselves don't match because they aren't zero or more occurrences of '.a.', so they are skipped. You might wonder why something that can match no input text, doesn't return an infinite number of those matches at every possible position, but they would be overlapping, and findall explicitly says matches have to be non-overlapping. Cheers, JB From usenet-nospam at seebs.net Tue Nov 2 04:12:18 2010 From: usenet-nospam at seebs.net (Seebs) Date: 02 Nov 2010 08:12:18 GMT Subject: *** FBI gets a warm welcome in Chicago for their EXCELLENTperformance - cheers to NEW CONS *** References: <26f97f70-9043-490c-9e6e-35159f38d76b@r29g2000yqj.googlegroups.com> Message-ID: On 2010-11-02, brf256 at gmail.com wrote: > How exactly does this relate to python? 1. It doesn't. It's spam. Duh. 2. Don't respond to spam. 3. Don't top-post. 4. If I see even one more post from you where the entire previous post is quoted under your text, I will plonk you. I warn you now because most posters will do the same thing, and you will get very lonely once no one bothers to read your posts. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From lanyjie at yahoo.com Tue Nov 2 04:53:17 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Tue, 2 Nov 2010 01:53:17 -0700 (PDT) Subject: Why this result with the re module In-Reply-To: <4CCFC2CB.2080500@asd-group.com> Message-ID: <512575.3904.qm@web54204.mail.re2.yahoo.com> > From: John Bond > You might wonder why something that can match no input > text, doesn't return an infinite number of those matches at > every possible position, but they would be overlapping, and > findall explicitly says matches have to be non-overlapping. That scrabbed my itches, though the notion of overlapping empty strings is quite interesting in itself. Obviously we have to assume there is one and only one empty string between two consecutive characters. Now I slightly modified my regex, and it suddenly looks self-explanatory: >>> re.findall('((.a.)+)', 'Mary has a lamb') [('Mar', 'Mar'), ('has a lam', 'lam')] >>> re.findall('((.a.)*)', 'Mary has a lamb') [('Mar', 'Mar'), ('', ''), ('', ''), ('has a lam', 'lam'), ('', ''), ('', '')] BUT, but. 1. I expected findall to find matches of the whole regex '(.a.)+', not just the subgroup (.a.) from >>> re.findall('(.a.)+', 'Mary has a lamb') Thus it is probably a misunderstanding/bug?? 2. Here is an statement from the documentation on non-capturing groups: see http://docs.python.org/dev/howto/regex.html "Except for the fact that you can?t retrieve the contents of what the group matched, a non-capturing group behaves exactly the same as a capturing group; " Thus, I'm again confused, despite of your previous explanation. This might be a better explanation: when a subgroup is repeated, it only captures the last repetition. 3. It would be convenient to have '(*...)' for non-capturing groups -- but of course, that's only a remote suggestion. 4. By reason of greediness of '*', and the concept of non-overlapping, it should go like this for re.findall('((.a.)*)', 'Mary has a lamb') step 1: Match 'Mar' + '' (gready!) step 2: skip 'y' step 3: Match '' step 4: skip ' ' step 5: Match ''+'has'+' a '+'lam'+'' (greedy!) step 7: skip 'b' step 8: Match '' So there should be 4 matches in total: 'Mar', '', 'has a lam', '' Also, if a repeated subgroup only captures the last repetition, the repeated subgroup (.a.)* should always be ''. Yet the execution in Python results in 6 matches. Here is the documentation of re.findall: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ findall(pattern, string, flags=0) Return a list of all non-overlapping matches in the string. If one or more groups are present in the pattern, return a list of groups; this will be a list of tuples if the pattern has more than one group. Empty matches are included in the result. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Thus from >>> re.findall('(.a.)*', 'Mary has a lamb') I should get this result [('',), ('',), ('',), ('',)] Finally, The name findall implies all matches should be returned, whether there are subgroups in the pattern or not. It might be best to return all the match objects (like a re.match call) instead of the matched strings. Then there is no need to return tuples of subgroups. Even if tuples of subgroups were to be returned, group(0) must also be included in the returned tuple. Regards, Yingjie From johann.spies at gmail.com Tue Nov 2 04:58:24 2010 From: johann.spies at gmail.com (Johann Spies) Date: Tue, 2 Nov 2010 10:58:24 +0200 Subject: Python equivalent of SOAP-ISIWoK Message-ID: SOAP-ISIWoK is a Perl library for assessing Thomson Reuters Web of Knowledge Web Services. I don't know Perl well enough to use that library without spending too much time on it. Is there a Python equivalent available? Regards Johann -- ?May grace and peace be yours in abundance through the full knowledge of God and of Jesus our Lord! ?His divine power has given us everything we need for life and godliness through the full knowledge of the one who called us by his own glory and excellence. ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ?2 Pet. 1:2b,3a From ldo at geek-central.gen.new_zealand Tue Nov 2 05:06:40 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 02 Nov 2010 22:06:40 +1300 Subject: functions, list, default parameters References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <4cc13ef5$0$29979$c3e8da3$5496439d@news.astraweb.com> Message-ID: In message , Chris Rebert wrote: > On Fri, Oct 22, 2010 at 12:36 AM, Steven D'Aprano > wrote: >> >> Default mutable arguments have their place > > But it's a rather obscure one where it is almost never strictly > necessary to venture. Mediocre programmers with a hankering towards cleverness latch onto it as an ingenious way of maintaing persistent context in-between calls to a function, completely overlooking the fact that Python offers much more straightforward, comprehensible, flexible, and above all maintainable ways of doing that sort of thing. From tartley at tartley.com Tue Nov 2 05:19:08 2010 From: tartley at tartley.com (Jonathan Hartley) Date: Tue, 2 Nov 2010 02:19:08 -0700 (PDT) Subject: playful coding problems for 10 year olds References: Message-ID: On Nov 1, 8:31?pm, Daniel Fetchinson wrote: > Hi folks, > > My niece is interested in programming and python looks like a good > choice (she already wrote a couple of lines :)) She is 10 and I > thought it would be good to have a bunch of playful coding problems > for her, stuff that she could code herself maybe after some initial > help. > > Do you guys know problems like these? Or a good resource where to look them up? > > Cheers, > Daniel > > -- > Psss, psss, put it down! -http://www.cafepress.com/putitdown There's a great book valled 'Invent your own computer games using Python', aimed at kids, which teaches programming from tne ground up, in the context of writing games, starting with terminal word games, ending with Pygame fullscreen 2D vector graphic & bitmaps affairs. http://inventwithpython.com/ The website says aimed at kids 'ages 10 to 12 and upwards', so it sounds like she's on the minimum cusp. (now I come to look at the website, one of the quotes he features is from an Amazon review I wrote months ago! :-) From paul at subsignal.org Tue Nov 2 05:37:54 2010 From: paul at subsignal.org (=?UTF-8?B?UGF1bCBLw7ZsbGU=?=) Date: Tue, 02 Nov 2010 10:37:54 +0100 Subject: [Beginer Question] I heard about python needing somesort of_VariableName_ boiler plate? In-Reply-To: <1946543087-1288635527-cardhu_decombobulator_blackberry.rim.net-1324044669-@bda480.bisx.prod.on.blackberry> References: <878w1dlk81.fsf@benfinney.id.au><4CCEF9E2.2000803@mrabarnett.plus.com> <1946543087-1288635527-cardhu_decombobulator_blackberry.rim.net-1324044669-@bda480.bisx.prod.on.blackberry> Message-ID: <4CCFDBF2.4030305@subsignal.org> Its the entry point if the script is executed directly. This message was sent from my 7 years old Dell D800 (without cables) Am 01.11.2010 19:18, schrieb bradenf at hotmail.com: > Sorry that is what I mean. What is it for? > Sent wirelessly from my BlackBerry. > > -----Original Message----- > From: MRAB > Sender: python-list-bounces+bradenf=hotmail.com at python.org > Date: Mon, 01 Nov 2010 17:33:22 > To: > Reply-To: python-list at python.org > Subject: Re: [Beginer Question] I heard about python needing some > sort of_VariableName_ boiler plate? > > On 01/11/2010 04:51, Ben Finney wrote: >> bradenf at hotmail.com writes: >> >>> Sorry, to clarify I heard that when you declare a variable in python >>> you have to use some sort of standard boiler plate _variable_ however >>> this has not been my experience using IDLE so is this even true? >> >> I don't know what ?some sort of boiler plate _variable_? might mean. >> >> Can you point to someone's actual message saying this, so we can see >> what they might be talking about? >> > Perhaps the OP means: > > if __name__ == "__main__": > ... > > although the "declare a variable" bit has me puzzled. From paul at subsignal.org Tue Nov 2 05:37:54 2010 From: paul at subsignal.org (=?UTF-8?B?UGF1bCBLw7ZsbGU=?=) Date: Tue, 02 Nov 2010 10:37:54 +0100 Subject: [Beginer Question] I heard about python needing somesort of_VariableName_ boiler plate? In-Reply-To: <1946543087-1288635527-cardhu_decombobulator_blackberry.rim.net-1324044669-@bda480.bisx.prod.on.blackberry> References: <878w1dlk81.fsf@benfinney.id.au><4CCEF9E2.2000803@mrabarnett.plus.com> <1946543087-1288635527-cardhu_decombobulator_blackberry.rim.net-1324044669-@bda480.bisx.prod.on.blackberry> Message-ID: <4CCFDBF2.4030305@subsignal.org> Its the entry point if the script is executed directly. This message was sent from my 7 years old Dell D800 (without cables) Am 01.11.2010 19:18, schrieb bradenf at hotmail.com: > Sorry that is what I mean. What is it for? > Sent wirelessly from my BlackBerry. > > -----Original Message----- > From: MRAB > Sender: python-list-bounces+bradenf=hotmail.com at python.org > Date: Mon, 01 Nov 2010 17:33:22 > To: > Reply-To: python-list at python.org > Subject: Re: [Beginer Question] I heard about python needing some > sort of_VariableName_ boiler plate? > > On 01/11/2010 04:51, Ben Finney wrote: >> bradenf at hotmail.com writes: >> >>> Sorry, to clarify I heard that when you declare a variable in python >>> you have to use some sort of standard boiler plate _variable_ however >>> this has not been my experience using IDLE so is this even true? >> >> I don't know what ?some sort of boiler plate _variable_? might mean. >> >> Can you point to someone's actual message saying this, so we can see >> what they might be talking about? >> > Perhaps the OP means: > > if __name__ == "__main__": > ... > > although the "declare a variable" bit has me puzzled. From hniksic at xemacs.org Tue Nov 2 06:11:52 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Tue, 02 Nov 2010 11:11:52 +0100 Subject: factorial of negative one (-1) References: <87r5f55qj5.fsf@xemacs.org> Message-ID: <87vd4gm3vb.fsf@xemacs.org> Ken Watford writes: >>>>> 1.1 .as_integer_ratio() >> (2476979795053773, 2251799813685248) > > Handy, but if you need the exact representation, my preference is > float.hex, which seems to be the same as C99's %a format. [...] > Granted, it's not as easy for humans to interpret, but it's useful for > certain things. Since it's used by both C99 and Java, supporting it is a nice interoperability feature: http://download.oracle.com/javase/6/docs/api/java/lang/Double.html#toHexString(double) In fact, the float output provides educational insight of its own because it shows rounding effects without the apparent "garbage digits" syndrome: >>> 1.1 .hex() '0x1.199999999999ap+0' Here it is immediately obvious that the final digit of the infinite sequence "1.1999..." is rounded from 9 to a. Printing the number with any more digits would just reveal zeros, as expected. Does anyone know why Python doesn't accept hex float literals in source code? From lists at asd-group.com Tue Nov 2 06:23:10 2010 From: lists at asd-group.com (John Bond) Date: Tue, 02 Nov 2010 10:23:10 +0000 Subject: Why this result with the re module In-Reply-To: <512575.3904.qm@web54204.mail.re2.yahoo.com> References: <512575.3904.qm@web54204.mail.re2.yahoo.com> Message-ID: <4CCFE68E.4070208@asd-group.com> On 2/11/2010 8:53 AM, Yingjie Lan wrote: > > BUT, but. > > 1. I expected findall to find matches of the whole > regex '(.a.)+', not just the subgroup (.a.) from >>>> re.findall('(.a.)+', 'Mary has a lamb') > Thus it is probably a misunderstanding/bug?? Again, as soon as you put a capturing group in your expression, you change the nature of what findall returns as described in the documentation. It then returns what gets assigned to each capturing group, not what chunk of text was matched by the whole expression at each matching point in the string. A capturing group returns what was matched by the regex fregment *inside it*. If you put repetition *outside it* (as you have - "(.a.)*+*") that doesn't change but, if the repetition clause results in it being matched multiple times, only the last match is returned as the capturing groups single, only allowed return value. I find that strange, and limiting (why not return a list of all matches caused by the repetition?) but that's the way it is. Have you read the "Regular Exp[ression HOWTO" in the docs? It explains all this stuff. > 2. Here is an statement from the documentation on > non-capturing groups: > see http://docs.python.org/dev/howto/regex.html > > "Except for the fact that you can?t retrieve the > contents of what the group matched, a non-capturing > group behaves exactly the same as a capturing group; " In terms of how the regular expression works when matching text, which is what the above is addressing, that's true. In terms of how the results are returned to API callers, it isn't true. > Thus, I'm again confused, despite of your > previous explanation. This might be a better > explanation: when a subgroup is repeated, it > only captures the last repetition. That's true, but it's not related to the above. > 3. It would be convenient to have '(*...)' for > non-capturing groups -- but of course, that's > only a remote suggestion. Fair enough - each to their own preferences. > 4. By reason of greediness of '*', and the concept > of non-overlapping, it should go like this for > re.findall('((.a.)*)', 'Mary has a lamb') > > step 1: Match 'Mar' + '' (gready!) > step 2: skip 'y' > step 3: Match '' > step 4: skip ' ' > step 5: Match ''+'has'+' a '+'lam'+'' (greedy!) > step 7: skip 'b' > step 8: Match '' > > So there should be 4 matches in total: > > 'Mar', '', 'has a lam', '' > > Also, if a repeated subgroup only captures > the last repetition, the repeated > subgroup (.a.)* should always be ''. > > Yet the execution in Python results in 6 matches. > > ..... All you have done is wrapped one of your earlier regexes, '*(*.a.*)**' in another, outer capturing group, to make '*(*(.a.)**)*'. This doesn't change what is actually matched, so there are still the same six matches found. However it does change what is *returned *- you now have two capturing groups that findall has to return information about (at each match), so you will see that it returns 6 tuples (each with two items - one for each capturing group) instead of six strings, ie: re.findall('(.a.)*', 'Mary has a lamb') ['Mar', '', '', 'lam', '', ''] becomes: re.findall('((.a.)*)', 'Mary has a lamb') [('Mar', 'Mar'), ('', ''), ('', ''), ('has a lam', 'lam'), ('', ''), ('', '')] As you can see, the top set of results appear in the bottom set (in the second item in each tuple, because the original capturing group is the second one now - the new, outer one is the first). If you look at the fourth tuple, ('has a lam', 'lam'), you can see the "capturing group with repetition only returns the last match" rule in action. The inner capturing group (which has repetition) returns 'lam' because that was the last occurrence of ".a." in the three ("has", " a ", "lam") that it matched that time. However the outer capturing group, which doesn't have repetition, returns the whole thing ('has a lam'). > Finally, The name findall implies all matches > should be returned, whether there are subgroups in > the pattern or not. It might be best to return all > the match objects (like a re.match call) instead > of the matched strings. Then there is no need > to return tuples of subgroups. Even if tuples > of subgroups were to be returned, group(0) must > also be included in the returned tuple. > > Regards, > > Yingjie > > > All matches are returned by findall, so I don't understand that. I really do suggest that you read the above-mentioned HOWTO, or any of the numerous tutorials on the net. Regexes are hard to get your head around at first, not helped by a few puzzling API design choices, but it's worth the effort, and those will be far more useful than lots of typed explanations here. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dylan at contentfree.info Tue Nov 2 06:32:13 2010 From: dylan at contentfree.info (Dylan Evans) Date: Tue, 2 Nov 2010 20:32:13 +1000 Subject: Mail Merge from python data Message-ID: I'm setting up a database for an organisation who want to do mail merges in office 2010. I know i can use the MySQL ODBC driver for the mail merge but i have set up the database with lots of relations and many-to-many links which i'm sure will lead to a huge amount of confusion (I think, i don't really know much about mail merge). What i want to know is, is there anyway to send data from python, which the UI is written in, to office templates and mail merges? -- "The UNIX system has a command, nice ... in order to be nice to the other users. Nobody ever uses it." - Andrew S. Tanenbaum -------------- next part -------------- An HTML attachment was scrubbed... URL: From sanjo_ie at yahoo.com Tue Nov 2 06:42:22 2010 From: sanjo_ie at yahoo.com (jk) Date: Tue, 2 Nov 2010 03:42:22 -0700 (PDT) Subject: Python documentation too difficult for beginners Message-ID: Hi, I've been coding in PHP and Java for years, and their documentation is concise, well structured and easy to scan. Others have mentioned this apparently for years (see: http://stackoverflow.com/questions/4046166/easy-to-navigate-online-python-reference-manual/4070851 and http://www.russellbeattie.com/blog/python-library-docs-still-suck and http://xahlee.org/perl-python/xlali_skami_cukta.html). Compare for instance the differences in ease of use, and speed of use, of these: http://docs.python.org/library/functions.html#open http://uk.php.net/manual/en/function.fopen.php The former is difficult to find (try searching for 'open' in the search box and see what you get). It is simply a collection of paragraphs without strong enough contrast to differentiate the different parts - parameters, parameter values, return types, exceptions and related functions. It is slow to read and doesn't allow easy visual scanning. The latter has clearly delineated, standardised content areas for each of these without excessive text. It uses tables which are easy to scan for possible opening modes and allows users to contribute their own examples. Sadly, the use of restructured text by python doesn't allow a new document generator to be written - all existing documentation would need updating with docblocks or something similar. Has anyone else struggled while trying to learn the language? The whole documentation system seems geared towards people who already know what they're looking for and is close to useless for beginners. I'm not the only one who finds google an easier way to find documentation about python. Is there much chance that the Python maintainers will change their documentation system to make it more like Java or PHP? How would I go about trying to make that happen? From hnsri49 at gmail.com Tue Nov 2 06:48:40 2010 From: hnsri49 at gmail.com (srinivas hn) Date: Tue, 2 Nov 2010 16:48:40 +0600 Subject: Python documentation too difficult for beginners In-Reply-To: References: Message-ID: If you are really beginner in python you can look into the dive into python,search as in google as the same its quite helpful for beginners.Also you can go for the byte of python. CHEERS CNA 9986229891 On Tue, Nov 2, 2010 at 4:42 PM, jk wrote: > Hi, > > I've been coding in PHP and Java for years, and their documentation is > concise, well structured and easy to scan. > > Others have mentioned this apparently for years (see: > > http://stackoverflow.com/questions/4046166/easy-to-navigate-online-python-reference-manual/4070851 > and http://www.russellbeattie.com/blog/python-library-docs-still-suck > and http://xahlee.org/perl-python/xlali_skami_cukta.html). > > Compare for instance the differences in ease of use, and speed of use, > of these: > > http://docs.python.org/library/functions.html#open > http://uk.php.net/manual/en/function.fopen.php > > The former is difficult to find (try searching for 'open' in the > search box and see what you get). It is simply a collection of > paragraphs without strong enough contrast to differentiate the > different parts - parameters, parameter values, return types, > exceptions and related functions. It is slow to read and doesn't allow > easy visual scanning. > > The latter has clearly delineated, standardised content areas for each > of these without excessive text. It uses tables which are easy to scan > for possible opening modes and allows users to contribute their own > examples. > > Sadly, the use of restructured text by python doesn't allow a new > document generator to be written - all existing documentation would > need updating with docblocks or something similar. > > Has anyone else struggled while trying to learn the language? The > whole documentation system seems geared towards people who already > know what they're looking for and is close to useless for beginners. > I'm not the only one who finds google an easier way to find > documentation about python. > > Is there much chance that the Python maintainers will change their > documentation system to make it more like Java or PHP? How would I go > about trying to make that happen? > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Tue Nov 2 07:02:30 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 02 Nov 2010 11:02:30 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: <4ccfefc6$0$29966$c3e8da3$5496439d@news.astraweb.com> On Mon, 01 Nov 2010 22:24:03 +0000, Grant Edwards wrote: > On 2010-11-01, Lawrence D'Oliveiro > wrote: [...] >> I'm getting less and less keen on that particular feature of Python... > > Why? > > Other languages have similar problems if you remove salient bits of > syntax before comparing two source files files. > > For exmaple, if you remove all of the curly-braces from two C source > files before comparing them, you don't get useful results. Ah, but other languages don't make the guarantee that you can add or remove random whitespace in arbitrary places and still have code that works correctly! Of course, neither does Python, but there's a certain type of personality that is never happy unless they are bitching and moaning, and if they can't find something more substantial to bitch and moan about, they'll bitch and moan about the fact that they can't make random changes to syntactically significant tokens in their source code without things breaking. Boo hoo, cry me a river. Personally, I'm more disturbed by the default prompt in the interactive interpreter. >>> clashes with the symbol used for quoting text in email and news. That causes me far more distress than indentation. Doing a bit of my own bitching and moaning'ly y'rs, -- Steven From steve at REMOVE-THIS-cybersource.com.au Tue Nov 2 07:22:19 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 02 Nov 2010 11:22:19 GMT Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> Message-ID: <4ccff46b$0$29966$c3e8da3$5496439d@news.astraweb.com> On Tue, 02 Nov 2010 11:16:46 +1300, Lawrence D'Oliveiro wrote: > In message <4CCE6FF6.2050408 at v.loewis.de>, Martin v. Loewis wrote: > >> (in fact, I can't think any situation where I would use the backslash). > > for \ > Description, Attr, ColorList \ > in \ > ( > ("normal", "image", MainWindow.ColorsNormalList), > ("highlighted", "highlight", > MainWindow.ColorsHighlightedList), ("selected", "select", > MainWindow.ColorsSelectedList), > ) \ > : > ... > #end for If it were your intention to show why backslashes should be avoided, you succeeded admirably. The above can be written much more cleanly as: for Description, Attr, ColorList in ( ("normal", "image", MainWindow.ColorsNormalList), ("highlighted", "highlight", MainWindow.ColorsHighlightedList), ("selected", "select", MainWindow.ColorsSelectedList), ): pass with no backslashes required. An even better way would be to given the tuples descriptive names, so that anyone maintaining this software can easily see what they are for: # States should be tuples (description, attribute name, colour list). standard = ("normal", "image", MainWindow.ColorsNormalList) highlighted = ("highlighted", "highlight", MainWindow.ColorsHighlightedList) selected = ("selected", "select", MainWindow.ColorsSelectedList) for desc, attr, color_list in (standard, highlighted, selected): pass -- Steven From steve at REMOVE-THIS-cybersource.com.au Tue Nov 2 07:23:48 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 02 Nov 2010 11:23:48 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <8j8udgFlkvU1@mid.individual.net> Message-ID: <4ccff4c4$0$29966$c3e8da3$5496439d@news.astraweb.com> On Mon, 01 Nov 2010 22:48:16 +0000, Peter Pearson wrote: > I must concede that some awkwardness results from assigning significance > to something (whitespace) that many tools are inclined to treat as > insignificant. Then the tools are broken. Or perhaps I should say: Th enth etool sarebroke n. -- Steven From sanjo_ie at yahoo.com Tue Nov 2 07:23:49 2010 From: sanjo_ie at yahoo.com (jk) Date: Tue, 2 Nov 2010 04:23:49 -0700 (PDT) Subject: Python documentation too difficult for beginners References: Message-ID: This (http://epydoc.sourceforge.net/stdlib/) is what I'm talking about. Why aren't the official docs like this, and why has it taken me 2 days of searching? All this needs is a search engine behind it and it'd be perfect. From fetchinson at googlemail.com Tue Nov 2 07:32:14 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Tue, 2 Nov 2010 12:32:14 +0100 Subject: playful coding problems for 10 year olds In-Reply-To: References: Message-ID: >> Hi folks, >> >> My niece is interested in programming and python looks like a good >> choice (she already wrote a couple of lines :)) She is 10 and I >> thought it would be good to have a bunch of playful coding problems >> for her, stuff that she could code herself maybe after some initial >> help. >> >> Do you guys know problems like these? Or a good resource where to look >> them up? >> >> Cheers, >> Daniel >> > > There's a great book valled 'Invent your own computer games using > Python', aimed at kids, which teaches programming from tne ground up, > in the context of writing games, starting with terminal word games, > ending with Pygame fullscreen 2D vector graphic & bitmaps affairs. > http://inventwithpython.com/ > > The website says aimed at kids 'ages 10 to 12 and upwards', so it > sounds like she's on the minimum cusp. > > (now I come to look at the website, one of the quotes he features is > from an Amazon review I wrote months ago! :-) Thanks a lot for everyone for the suggestions, I think I'll be able to cook things up from all the references you sent! Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From steve at REMOVE-THIS-cybersource.com.au Tue Nov 2 07:36:34 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 02 Nov 2010 11:36:34 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> On Tue, 02 Nov 2010 04:16:28 +0000, Seebs wrote: > e.g., any email sent > to my work account is being magically transformed into HTML (no one > knows why) on the server, so I can't get correct indentation except > in attachments. I suppose then you're going to insist that Python should stop using > and < for comparison operators, because your mail server converts them to > and < escapes? > I've lost more time to indentation issues in Python in a month than I've > lost to mismatches between indentation and flow in C in twenty years. I've lost more time to reading people's bitching about indentation than I have dealing with indentation problems. But then, I don't insist on using tools which are broken by design. If your email server converts plain text to HTML, it is broken. If your editor changes spaces to tabs, or visa versa, without being told to do so (either by an explicit command or an obvious setting), then your editor is broken. If you are stuck with broken mail servers and broken editors and broken tools because of political reasons, then you have my sympathy. But stop insisting that everybody has to carry the overhead of your work-arounds for your broken tools. -- Steven From tim.wintle at teamrubber.com Tue Nov 2 07:41:26 2010 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Tue, 02 Nov 2010 11:41:26 +0000 Subject: Python documentation too difficult for beginners In-Reply-To: References: Message-ID: <1288698086.9950.28.camel@tim-laptop.config> On Tue, 2010-11-02 at 04:23 -0700, jk wrote: > This (http://epydoc.sourceforge.net/stdlib/) is what I'm talking > about. Aaaarrrgggghhhh > Why aren't the official docs like this, Because not everyone likes documentation like that. Personally I far prefer the existing documentation to the JavaDoc-style link you sent. > and why has it taken me 2 days of searching? > All this needs is a search engine behind it and it'd be > perfect. Personally I use Google, e.g. "list site:docs.python.org" to bring up documentation about the list type. From roy at panix.com Tue Nov 2 07:46:23 2010 From: roy at panix.com (Roy Smith) Date: Tue, 02 Nov 2010 07:46:23 -0400 Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> Message-ID: In article , Chris Rebert wrote: > I find the level of deviation from PEP 8 in that file rather disturbing. > In any case, the backslashes are easily avoided, and readability > improved IMHO, via refactoring: > > desc_attr_colors_triples = (("normal", "image", MainWindow.ColorsNormalList), > ("highlighted", "highlight", MainWindow.ColorsHighlightedList), > ("selected", "select", MainWindow.ColorsSelectedList)) > for in description, attr, color_list in desc_attr_colors_triples: > ... I like and use PEP-8. At the start of any project involving myself, other people, and Python, I'll generally suggest we follow PEP-8 style, and I can't remember ever getting any pushback. That being said, I don't hold it in awe. Likewise, I don't worry in the least about deviating when readability would be improved by doing so. In this case, I think I would do: styles = [("normal", "image", MainWindow.ColorsNormalList), ("highlighted", "highlight", MainWindow.ColorsHighlightedList), ("selected", "select", MainWindow.ColorsSelectedList)] for in description, attr, color_list in styles: blah, blah, blah For those reading this in a non-fixed width font, I've laid out the definition of styles as a table, with spaces inserted to make the columns line up. For data like this, I think it makes it easier to read and comprehend. As a minor nit, note that I made it a list of tuples, not a tuple of tuples. I'm tempted to do an additional refactoring to get rid of the verbose color list names: CL_Normal = MainWindow.ColorsNormalList) CL_Highlighted = MainWindow.ColorsHighlightedList CL_Selected = MainWindow.ColorsSelectedList styles = [("normal", "image", CL_Normal), ("highlighted", "highlight", CL_Highlighted), ("selected", "select", CL_Selected)] I haven't decided if this makes things better or worse. For this small table, I'm inclined to say worse. If the table were much larger and I were reusing many of the color list names over and over, I would certainly do that. If MainWindow were a well-designed module and I could do import * from MainWindow without cluttering up my namespace too much, I would do that, then just use the unadorned names. Also, depending on what I was doing inside the loop, I might pick shorter names. For example: for in d, a, c in styles: window.set_description(d) window.set_attribute(a) window.set_color_list(c) is perfectly clear. Normally, I don't use single-letter variable names, but in this particular case, the descriptive function names provide all the context that's need to explain what they are. From mail at timgolden.me.uk Tue Nov 2 07:49:42 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 02 Nov 2010 11:49:42 +0000 Subject: Python documentation too difficult for beginners In-Reply-To: References: Message-ID: <4CCFFAD6.9020601@timgolden.me.uk> On 02/11/2010 11:23, jk wrote: > This (http://epydoc.sourceforge.net/stdlib/) is what I'm talking > about. > > Why aren't the official docs like this, and why has it taken me 2 days > of searching? All this needs is a search engine behind it and it'd be > perfect. I'm glad you find the epydoc format useful. And I'm glad that various people have taken the trouble to produce documentation for Python in various formats that suit them. But why do you imagine that the core Python documentation -- developed and maintained by a group of people who clearly have some idea what they're doing -- should change to a format which happens to suit you? The Python documentation source and the source code of Python itself are all freely available. Any initiative by you or by others to produce alternative, possibly searchable and commentable, versions of them would I'm sure be welcomed by many. But not everyone finds, eg, the PHP style of user annotation helpful. Not everyone likes epydoc output: I don't myself. In short, please feel free to contribute directly to the core documentation effort, or to produce alternatives yourself and to advertise them here or elsewhere within the Python community. But please don't come along and say "Why aren't the Python docs like which happens to suit me better?" TJG From martin.hellwig at dcuktec.org Tue Nov 2 07:52:07 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Tue, 02 Nov 2010 11:52:07 +0000 Subject: Python documentation too difficult for beginners In-Reply-To: References: Message-ID: On 11/02/10 10:42, jk wrote: > Is there much chance that the Python maintainers will change their > documentation system to make it more like Java or PHP? How would I go > about trying to make that happen? I am by no means an authority however since you ask it here I feel compelled to give you my opinion :-) In general I would think that more documentation is always welcome, if you feel like you can make a contribution, excellent, please do! However, I found that the documentation available was enough for me, and I didn't even have to go to the googles for that. Typing help(thing_i_want_info_of) in the interpreter gives me precise consistent information for what I need to do with whatever it is I am doing and yes that is largely a replication of what is mentioned on the site itself (well more the other way around actually). In the odd cases this doesn't help me, I google for examples. If that doesn't help I look at the modules __file__ and open that module to read the source. And when I started 10 odd years ago with Python it was my first language with no prior confusion of other languages, since then I extended my knowledge with C and assembler but on a day to day basis I still use Python. -- mph From steve at REMOVE-THIS-cybersource.com.au Tue Nov 2 07:59:25 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 02 Nov 2010 11:59:25 GMT Subject: functions, list, default parameters References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <4cc13ef5$0$29979$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4ccffd1c$0$29966$c3e8da3$5496439d@news.astraweb.com> On Tue, 02 Nov 2010 22:06:40 +1300, Lawrence D'Oliveiro wrote: > In message , Chris > Rebert wrote: > >> On Fri, Oct 22, 2010 at 12:36 AM, Steven D'Aprano >> wrote: >>> >>> Default mutable arguments have their place >> >> But it's a rather obscure one where it is almost never strictly >> necessary to venture. > > Mediocre programmers with a hankering towards cleverness latch onto it > as an ingenious way of maintaing persistent context in-between calls to > a function, completely overlooking the fact that Python offers much more > straightforward, comprehensible, flexible, and above all maintainable > ways of doing that sort of thing. Perhaps. Or maybe it's the mediocre programmers who find mutable defaults confusing, incomprehensible and unmaintainable. Certainly it's the mediocre programmers who seem to be incapable of understanding that Python has no way of telling whether arbitrary objects are mutable or not. def foo(x, y=list()): pass Is y a mutable default or not? For the benefit of any mediocre programmers out there, be careful before you answer. This *is* a trick question. -- Steven From brf256 at gmail.com Tue Nov 2 08:04:29 2010 From: brf256 at gmail.com (brf256 at gmail.com) Date: Tue, 2 Nov 2010 12:04:29 +0000 Subject: Python documentation too difficult for beginners Message-ID: <802401459-1288699467-cardhu_decombobulator_blackberry.rim.net-753506867-@bda480.bisx.prod.on.blackberry> A tutorial type book can also be great for reference and documentation (as long as its current). I would recommend a non-programmers tutorial to python even if you have started programming in other languages before. Also its a wiki book and is free. -Braden Faulkner Sent wirelessly from my BlackBerry device on the Bell network. Envoy? sans fil par mon terminal mobile BlackBerry sur le r?seau de Bell. From steve at REMOVE-THIS-cybersource.com.au Tue Nov 2 08:14:55 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 02 Nov 2010 12:14:55 GMT Subject: functions, list, default parameters References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <8ivelpFif1U1@mid.individual.net> <4cca88bc$0$29987$c3e8da3$5496439d@news.astraweb.com> <8j1seqFa1eU2@mid.individual.net> Message-ID: <4cd000bf$0$29966$c3e8da3$5496439d@news.astraweb.com> On Tue, 02 Nov 2010 20:12:49 +1300, Lawrence D'Oliveiro wrote about mutable defaults: > Which is what we?re talking about > here: a language construct which is probably one of the top 3 sources of > grief to Python newbies. And not-so-newbies. I call bullshit. Maybe you should spend some time on the tutor at python.org mailing list for a while to see what the common problems newbies actually have. Mutable defaults are *way* down the list. In any case, Python isn't written solely for newbies. Most people will make this mistake once, or twice if they're particularly slow learning. If newbies have a problem with mutable defaults, oh well, they'll learn, or they'll give up and go back to griefing their friends on Facebook. Either way, problem solved. -- Steven From steve at REMOVE-THIS-cybersource.com.au Tue Nov 2 08:16:58 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 02 Nov 2010 12:16:58 GMT Subject: functions, list, default parameters References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <4cc13ef5$0$29979$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4cd00139$0$29966$c3e8da3$5496439d@news.astraweb.com> On Tue, 02 Nov 2010 00:40:17 -0700, Chris Rebert wrote: > On Fri, Oct 22, 2010 at 12:36 AM, Steven D'Aprano > wrote: >> On Thu, 21 Oct 2010 19:53:53 -0700, John Nagle wrote: >>>> This is a common newbie stumbling-block: Don't use lists (or anything >>>> mutable) as default argument values >>> >>> ? ? ?That really should be an error. >> >> No it shouldn't. Punishing everybody for a newbie mistake that nobody >> makes twice would be the error. >> >> Default mutable arguments have their place > > But it's a rather obscure one where it is almost never strictly > necessary to venture. Very few language features are *strictly* necessary. I mean, all you really need is the ability to set the current memory location, a way to read and write to it, and a way to branch. Everything else is just gravy. Not that I'm suggesting we should all use Turing machines, but there are many things which aren't strictly necessary but are nice to have. In any case, this discussion is pointless. There is code out there that uses this feature, whether you (generic you) like it or not, and changing the behaviour *can't* happen until the moratorium ends. Even if there was consensus to make this change -- and there won't be -- it almost certainly won't happen before Python 4000. Even if it did happen, adding extra type-checks to every def statement with a default value, or adding extra complexity to the parser, won't and can't catch every mutable default because there is no way of telling whether an arbitrary object is mutable. It will just slow down the language for bugger-all benefit. -- Steven From lanyjie at yahoo.com Tue Nov 2 08:19:15 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Tue, 2 Nov 2010 05:19:15 -0700 (PDT) Subject: Why this result with the re module Message-ID: <552223.15146.qm@web54201.mail.re2.yahoo.com> > From: John Bond > Subject: Re: Why this result with the re module Firstly, thanks a lot for your patient explanation. this time I have understood all your points perfectly. Secondly, I'd like to clarify some of my points, which did not get through because of my poor presentation. I suggested findall return a tuple of re.MatchObject(s), with each MatchObject instance representing a match. This is consistent with the re.match() function anyway. And it will eliminate the need of returning tuples, and it is much more precise and information rich. If that's not possible, and a tuple must be returned, then the whole match (not just subgroups) should always be included as the first element in the tuple, as that's group(0) or '\0'. Less surprise would arise. Finally, it seems to me the algo for findall is WRONG. To re.findall('(.a.)*', 'Mary has a lamb'), by reason of greediness of '*', and the requirement of non-overlapping, it should go like this (suppose an '' is at the beginning and at the end, and between two consecutive characters there is one and only one empty string ''. To show the match of empty strings clearly, I am concatenating each repeated match below): Steps for re.findall('(.a.)*', 'Mary has a lamb'): step 1: Match '' + 'Mar' + '' (gready!) step 2: skip 'y' step 3: Match '' step 4: skip ' ' step 5: Match ''+'has'+' a '+'lam'+'' (greedy!) step 6: skip 'b' step 7: Match '' So there should be exactly 4 matches in total: 'Mar', '', 'has a lam', '' Also, the matches above shows that if a repeated subgroup only captures the last match, the subgroup (.a.)* should always capture '' here (see steps 1, 3, 5, 7) above. Yet the execution in Python results in 6 matches! And, the capturing subgroup with repetition sometimes got the wrong guy. So I believe the algorithm for findall must be WRONG. Regards, Yingjie From solipsis at pitrou.net Tue Nov 2 08:19:28 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Tue, 2 Nov 2010 13:19:28 +0100 Subject: Python documentation too difficult for beginners References: Message-ID: <20101102131928.27216029@pitrou.net> On Tue, 2 Nov 2010 04:23:49 -0700 (PDT) jk wrote: > This (http://epydoc.sourceforge.net/stdlib/) is what I'm talking > about. > > Why aren't the official docs like this, and why has it taken me 2 days > of searching? What's wrong with this: http://docs.python.org/library/ ? If you have specific ideas for improvements, you can open issues at http://bugs.python.org. Thank you Antoine. From vlastimil.brom at gmail.com Tue Nov 2 08:34:56 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Tue, 2 Nov 2010 13:34:56 +0100 Subject: Why this result with the re module In-Reply-To: <552223.15146.qm@web54201.mail.re2.yahoo.com> References: <552223.15146.qm@web54201.mail.re2.yahoo.com> Message-ID: 2010/11/2 Yingjie Lan : >> From: John Bond >> Subject: Re: Why this result with the re module > ... > I suggested findall return a tuple of re.MatchObject(s), > with each MatchObject instance representing a match. > This is consistent with the re.match() function anyway. > And it will eliminate the need of returning tuples, > and it is much more precise and information rich. > > Hi, in that case you may use re.finditer(...), which seem to provide, what you need here. (It returns an iterator over the Match objects, which can be easily fed to tuple(...) if it were needed.) hth, vbr From neilc at norwich.edu Tue Nov 2 08:34:59 2010 From: neilc at norwich.edu (Neil Cerutti) Date: 2 Nov 2010 12:34:59 GMT Subject: playful coding problems for 10 year olds References: <4CCF3595.2060102@v.loewis.de> Message-ID: <8jaerjFjdaU6@mid.individual.net> On 2010-11-01, Martin v. Loewis wrote: >> My niece is interested in programming and python looks like a good >> choice (she already wrote a couple of lines :)) She is 10 and I >> thought it would be good to have a bunch of playful coding problems >> for her, stuff that she could code herself maybe after some initial >> help. > > I think anything that has to do with drawing and colors will be > attractive, animated if possible. It has to look nice. > > Take a look at the turtle demos. The book _Simply Scheme_ contains a lot of word problems, which I think is quite nice. possessive,is_palindrom, pig_latin, and so forth might make good Python exercises, too. -- Neil Cerutti From emile at fenx.com Tue Nov 2 09:19:31 2010 From: emile at fenx.com (Emile van Sebille) Date: Tue, 02 Nov 2010 06:19:31 -0700 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: On 11/1/2010 4:22 PM Lawrence D'Oliveiro said... > In message, Emile van > Sebille wrote: > >> At least you can look at python code and _know_ that spurious placement of >> required line noise don't have the ability to impact what the code does. > > But it does. What is spurious whitespace if not noise, after all? But it does so by intent. Other languages lend only an appearance of structure through the indentation style of the writer. It's as good as outdated comments. Emile From sanjo_ie at yahoo.com Tue Nov 2 09:23:43 2010 From: sanjo_ie at yahoo.com (jk) Date: Tue, 2 Nov 2010 06:23:43 -0700 (PDT) Subject: Python documentation too difficult for beginners References: Message-ID: <9a58b8bd-9716-41d6-a497-33c5eb56e60a@a37g2000yqi.googlegroups.com> On Nov 2, 11:49 am, Tim Golden wrote: > But why do you imagine that the core > Python documentation -- developed and maintained by a group of people > who clearly have some idea what they're doing -- should change to a > format which happens to suit you? It's not just me who's found the current documentation frustrating. And sure, the developers know how to code, but they probably can't see the project with the eyes of a beginner any more. Making a change to how code is documented to allow more javadoc-style documentation to be produced could help people migrate from a java background and ease the learning curve for them, leading to wider adoption of the language. It wouldn't necessarily mean that the current documentation style would need to change either. > In short, please feel free to contribute directly to the core > documentation effort, or to produce alternatives yourself I may well do that. @Tim Wintle > Personally I use Google, e.g. > "list site:docs.python.org" > to bring up documentation about the list type. Surely you shouldn't have to go to google though? Or the interpreter? Maybe it's just what you're used to, but I'd expect the language's web site to provide enough of a reference in itself, while using google for examples. From msarro at gmail.com Tue Nov 2 09:40:00 2010 From: msarro at gmail.com (Matty Sarro) Date: Tue, 2 Nov 2010 09:40:00 -0400 Subject: Learning book recommendation? Message-ID: Hey Everyone! I'm looking for a Python book to start really learning the language since I've been using it more and more. Something similar to what you'd see in a computer science class - a few pages of theory and explanation of commands/syntax/constructs/data structures and then some exercises to help you learn how to put it to work. I've tried the MIT OCW intro to python/CS but it quickly went beyond my abilities (sadly, I am no MIT student). -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Tue Nov 2 09:42:17 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 02 Nov 2010 13:42:17 GMT Subject: Python documentation too difficult for beginners References: Message-ID: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> On Tue, 02 Nov 2010 03:42:22 -0700, jk wrote: > Hi, > > I've been coding in PHP and Java for years, and their documentation is > concise, well structured and easy to scan. Well, that's one opinion. > Others have mentioned this apparently for years (see: > http://stackoverflow.com/questions/4046166/easy-to-navigate-online- python-reference-manual/4070851 > and http://www.russellbeattie.com/blog/python-library-docs-still-suck > and http://xahlee.org/perl-python/xlali_skami_cukta.html). > > Compare for instance the differences in ease of use, and speed of use, > of these: > > http://docs.python.org/library/functions.html#open > http://uk.php.net/manual/en/function.fopen.php > > The former is difficult to find (try searching for 'open' in the search > box and see what you get). A fair point -- the built-in open comes up as hit #30, whereas searching for open in the PHP page brings up fopen as hit #1. But the PHP search also brings up many, many hits -- ten pages worth. But in any case, the Python search functionality could be smarter. If I had a complaint about the docs, that would be it. Fortunately, I have google :) > It is simply a collection of paragraphs > without strong enough contrast to differentiate the different parts - > parameters, parameter values, return types, exceptions and related > functions. It is slow to read and doesn't allow easy visual scanning. It's *nine* paragraphs, three of which are one-liners, the longest of which is eight lines. If you have trouble reading that, well, you have a problem. The PHP docs for fopen are FIFTY-EIGHT paragraphs. Okay, okay, I was unfair. I counted section headings as separate paragraphs. A more reasonable count is... twenty-six paragraphs, tables, sections and subsections. Plus *dozens* of user-contributed recipes, bug reports, tricks, tips and comments. And you call this concise??? Reading the docs, I'd say that PHP needs all this extra documentation because it's so much more complicated. fopen has all this implicit magic behaviour that needs documenting -- it will try to guess a scheme from the file name, if it can't guess the scheme it will guess that it's a local file, and the behaviour depends on various globals. In comparison, Python's open is very simple: it only opens files. No wonder Python's docs are simpler. The PHP docs felt it necessary to give a warning *three times*, one after the other, about using binary mode when opening files. Apparently once was not enough. The Description subsection of the PHP fopen doc says: fopen() binds a named resource, specified by filename, to a stream. What's a stream? So I read, and read, and read, and eventually, almost at the bottom of the official docs, I find the section "Return Values": Returns a file pointer resource on success, or FALSE on error. Great! Now, what's a file pointer resource, and how does it differ from a stream? No idea. Contrast that with the Python docs. In the *very first sentence*, it says: Open a file, returning an object of the file type described in section File Objects. with both "file" and "File Objects" being hyperlinks to the appropriate part of the docs. I think I'll stick with the Python style, thank you very much. > The latter has clearly delineated, standardised content areas for each > of these without excessive text. It uses tables which are easy to scan > for possible opening modes and allows users to contribute their own > examples. There has been discussion on python-dev about user contributed examples. The pros are that users can add tricks and tips. The cons are that, without constant attention, the user-contributed content will grow old and stale, or worse, be filled with nonsense. However, there is a Python wiki. It doesn't get anywhere near as much love as it deserves, and (I think) the consensus was that the official Python docs should stay official, but link to the wiki for user- contributed content. This hasn't happened yet. http://wiki.python.org/moin/ > Sadly, the use of restructured text by python doesn't allow a new > document generator to be written - all existing documentation would need > updating with docblocks or something similar. > > Has anyone else struggled while trying to learn the language? The whole > documentation system seems geared towards people who already know what > they're looking for and is close to useless for beginners. I'm not the > only one who finds google an easier way to find documentation about > python. Why do you think this is a bad thing? The Python docs are the reference manual, not a tutorial. Quite frankly, if I were a PHP developer, I'd be pretty annoyed at having to read this in the docs for fopen: If you use the wrong line ending characters when writing your files, you might find that other applications that open those files will "look funny". Gosh, really? Thanks for the tip, Captain Obvious. It's always difficult to know how much information is too much. The PHP docs seem to take an "everything including the kitchen sink" approach. Given that approach, it makes sense to divide everything into subsections, one page per function. But with Python's minimalist approach, it would just be annoying. Compare the four lines of: http://docs.python.org/library/functions.html#id with this re-write in the PHP fashion: ===== id ===== (Python 1.x, Python 2.x, Python 3.x) id -- id of an object Description ----------- id(object) id returns the numeric "identity" of an object, which is guaranteed to be unique and constant for this object during its lifetime. Note: two objects with non-overlapping lifetimes may have the same id() value. Note: CPython implementation detail: This is the address of the object. Parameters ---------- * object Any object. Note: all data in Python are objects, even ints and strings. Note: there are no undefined objects in Python. If you call id(variable) on an unbound variable name, Python will raise an exception. Return values ------------- Returns an integer or long integer object representing the ID of the argument. Errors/exceptions ----------------- If the argument to id() is a named variable rather than a literal, and that name is not bound to any object, then a NameError will be raised. Otherwise every call to id() must succeed. Note: if the call to id() is inside a function, the exception may be a subclass of NameError such as UnboundLocalError. Note: literals are not guaranteed to always refer to the same object. Changelog --------- 0.9 First version added (I think). Examples -------- id(x) id(alist[1]) id(instance.attribute) id(module.name.attribute['key'].method(arg1, arg2).seq[2]) Notes ----- If you're still reading, I admire your persistence. See also -------- Python's object model Exceptions > Is there much chance that the Python maintainers will change their > documentation system to make it more like Java or PHP? How would I go > about trying to make that happen? Unlikely. You could raise the issue on the python-dev list, or see if there is a SIG mailing list specifically for the docs. Frankly, I think that the best thing you could do is start a fork of the docs and see if you get any interest from people. If you do, then you can go back to python-dev with proof that there is a genuine popular desire for more structured, PHP-style documentation. -- Steven From brf256 at gmail.com Tue Nov 2 09:50:53 2010 From: brf256 at gmail.com (brf256 at gmail.com) Date: Tue, 2 Nov 2010 13:50:53 +0000 Subject: Learning book recommendation? Message-ID: <1053302592-1288705850-cardhu_decombobulator_blackberry.rim.net-148438442-@bda480.bisx.prod.on.blackberry> Hey there, I would reccomend a non-programmers tutorial to python by Josh coglatti and its a free wiki book. Also I would recommend byte into python. Both are great for beginers. Best of luck! -- Braden Faulkner Sent wirelessly from my BlackBerry device on the Bell network. Envoy? sans fil par mon terminal mobile BlackBerry sur le r?seau de Bell. From invalid at invalid.invalid Tue Nov 2 10:14:32 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 2 Nov 2010 14:14:32 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <8j8udgFlkvU1@mid.individual.net> Message-ID: On 2010-11-01, Peter Pearson wrote: > On Mon, 1 Nov 2010 22:24:03 +0000 (UTC), Grant Edwards wrote: >> On 2010-11-01, Lawrence D'Oliveiro wrote: >>> In message <8j8am4Fk2jU1 at mid.individual.net>, Peter Pearson wrote: >>>> >>>>> diff -b oldfile newfile >>>> >>>> Warning: "diff -b" won't detect changes in indentation. Changes in >>>> indentation can change a Python program. >>> >>> I'm getting less and less keen on that particular feature of Python... >> >> Why? >> >> Other languages have similar problems if you remove salient bits of >> syntax before comparing two source files files. >> >> For exmaple, if you remove all of the curly-braces from two C source >> files before comparing them, you don't get useful results. > > True, but diff doesn't come with an "ignore curly braces" option. True, but the fact that diff has an option that for Python sources will produces useless results doesn't seem like a valid indictment of Python's syntax and semantics. > I'm not personally repelled by Python's use of significant > indentation, but I must concede that some awkwardness results from > assigning significance to something (whitespace) that many tools are > inclined to treat as insignificant. However, the human brain does treat whitespace as significant. -- Grant Edwards grant.b.edwards Yow! I joined scientology at at a garage sale!! gmail.com From invalid at invalid.invalid Tue Nov 2 10:20:21 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 2 Nov 2010 14:20:21 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: On 2010-11-02, Seebs wrote: > On 2010-11-01, Grant Edwards wrote: >> On 2010-11-01, Lawrence D'Oliveiro wrote: >>> I'm getting less and less keen on that particular feature of >>> Python... > >> Why? > >> Other languages have similar problems if you remove salient bits of >> syntax before comparing two source files files. > > Sure. > >> For exmaple, if you remove all of the curly-braces from two C source >> files before comparing them, you don't get useful results. > > Right. > > But there's no *reason* to do that, while there are many common daily > events which result in whitespace changes. e.g., any email sent to > my work account is being magically transformed into HTML (no one > knows why) on the server, so I can't get correct indentation except > in attachments. And you think compatibility with your broken e-mail server is a good reason to change the syntax of a programming language? > Many editors helpfully convert spaces to tabs by default some or all > of the time. And so on. Such editors are broken. > The more I use it, the more I think it was an interesting experiment > which has worked out about as well as scanf. I think it's brilliant (indentation that actually means something, not scanf). > The "problem" it fixes is something that's hardly ever been a problem > for me in C or related languages -- and which could be completely > eliminated by automated indenters, which were actually conceptually > possible. They're only possible if you put redundant block markers in the source. > I've lost more time to indentation issues in Python in a month than > I've lost to mismatches between indentation and flow in C in twenty > years. Then you're doing something terribly wrong. I find indentation-based structure to be completely effortless. Are you using an editor that doesn't have a Python mode? > In theory, it sounds like it would help to eliminate the ambiguity. > In practice, eliminating the question of whether code was intended to > follow explicit flow rather than indentation just means that when > there's a mistake you don't even get a warning that someone was > confused. > > At least in C, if I see: > if (foo) > a; > else > b; > c; > > I *know* that something is wrong. I suppose you can add comments to Python if you some syntactically null "redudundacy" to indicate the intended structure. Personally, -- Grant Edwards grant.b.edwards Yow! I'm having a at quadrophonic sensation gmail.com of two winos alone in a steel mill! From invalid at invalid.invalid Tue Nov 2 10:27:49 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 2 Nov 2010 14:27:49 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccfefc6$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-02, Steven D'Aprano wrote: > Ah, but other languages don't make the guarantee that you can add or > remove random whitespace in arbitrary places and still have code that > works correctly! > > Of course, neither does Python, but there's a certain type of > personality that is never happy unless they are bitching and moaning, > and if they can't find something more substantial to bitch and moan > about, they'll bitch and moan about the fact that they can't make > random changes to syntactically significant tokens in their source > code without things breaking. Boo hoo, cry me a river. :) > Personally, I'm more disturbed by the default prompt in the > interactive interpreter. >>> clashes with the symbol used for quoting > text in email and news. That causes me far more distress than > indentation. I've tripped over that as well. Not very often, but it's a bigger problem than significant whitespace. I must admit that the first few minutes I worked with Python having significant whitespace seemed awkward -- probably because it invoked unpleasant memories of Fortran IV on punch-cards. After a short time, I suddenly realized that Python got it right: the compiler and my brain are using the _same_thing_ to denote program structure. All those years of my brain using one thing and the compiler using a different thing were (and are) obviously the wrong way to do it. -- Grant Edwards grant.b.edwards Yow! My BIOLOGICAL ALARM at CLOCK just went off ... It gmail.com has noiseless DOZE FUNCTION and full kitchen!! From invalid at invalid.invalid Tue Nov 2 10:33:29 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 2 Nov 2010 14:33:29 +0000 (UTC) Subject: Python documentation too difficult for beginners References: Message-ID: On 2010-11-02, brf256 at gmail.com wrote: > A tutorial type book can also be great for reference and > documentation (as long as its current). I would recommend a > non-programmers tutorial to python even if you have started > programming in other languages before. Also its a wiki book and is > free. To what does "it" refer in the last sentence? > Sent wirelessly from my BlackBerry device on the Bell network. That's nice, thank's for sharing. -- Grant Edwards grant.b.edwards Yow! Do you think the at "Monkees" should get gas on gmail.com odd or even days? From lanyjie at yahoo.com Tue Nov 2 10:37:51 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Tue, 2 Nov 2010 07:37:51 -0700 (PDT) Subject: Why this result with the re module In-Reply-To: Message-ID: <415473.28393.qm@web54204.mail.re2.yahoo.com> > From: Vlastimil Brom > Subject: Re: Why this result with the re module > in that case you may use re.finditer(...) Thanks for pointing this out. Still I'd love to see re.findall never discards the whole match, even if a tuple is returned. Yingjie From sanjo_ie at yahoo.com Tue Nov 2 10:47:29 2010 From: sanjo_ie at yahoo.com (jk) Date: Tue, 2 Nov 2010 07:47:29 -0700 (PDT) Subject: Python documentation too difficult for beginners References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <024ef21a-9ef9-48a6-8372-1d66895583c3@v16g2000yqn.googlegroups.com> On Nov 2, 1:42?pm, Steven D'Aprano wrote: > It's always difficult to know how much information is too much. The PHP > docs seem to take an "everything including the kitchen sink" approach. > Given that approach, it makes sense to divide everything into > subsections, one page per function. But with Python's minimalist > approach, it would just be annoying. Compare the four lines of: > > http://docs.python.org/library/functions.html#id > > with this re-write in the PHP fashion: > > ===== > id > ===== > (Python 1.x, Python 2.x, Python 3.x) > > id -- id of an object > > Description > ----------- > > id(object) > > id returns the numeric "identity" of an object, which is guaranteed to be > unique and constant for this object during its lifetime. > > Note: two objects with non-overlapping lifetimes may have the same id() > value. > > Note: CPython implementation detail: This is the address of the object. > > Parameters > ---------- > > * object > > ? Any object. > > ? Note: all data in Python are objects, even ints and strings. > > ? Note: there are no undefined objects in Python. If you call > ? id(variable) on an unbound variable name, Python will raise an > ? exception. > > Return values > ------------- > > Returns an integer or long integer object representing the ID of the > argument. > > Errors/exceptions > ----------------- > > If the argument to id() is a named variable rather than a literal, and > that name is not bound to any object, then a NameError will be raised. > Otherwise every call to id() must succeed. > > Note: if the call to id() is inside a function, the exception may be a > subclass of NameError such as UnboundLocalError. > > Note: literals are not guaranteed to always refer to the same object. > > Changelog > --------- > > ? 0.9 ?First version added (I think). > > Examples > -------- > > ? ?id(x) > ? ?id(alist[1]) > ? ?id(instance.attribute) > ? ?id(module.name.attribute['key'].method(arg1, arg2).seq[2]) > > Notes > ----- > > ? ?If you're still reading, I admire your persistence. > > See also > -------- > > ? ?Python's object model > ? ?Exceptions > > Steven You're right in that the python docs in this case are less lines, but that's one of the problems. It doesn't mention anywhere the extra detail you've added regarding exceptions thrown. That's the kind of thing that probably comes through experience or some kind of convention which isn't obvious to beginners. Having things split into sections - parameters, return types, exceptions, etc - lets me find what I'm looking for quickly. As for the 9 paragraphs statement, there's a usability book that applies here - it's called "Don't make me think". I shouldn't have to go through freeform text to find what I'm looking for when a list would make that information easier to find. And splitting the docs into sections would allow me to skip to what I'm looking for. I really would be much happier with your example documentation. I think the key difference is that I don't want to have to *read* the python docs - I want to be able to scan for what I'm looking for and find it easily. That makes me productive. From paul.nospam at rudin.co.uk Tue Nov 2 10:53:34 2010 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Tue, 02 Nov 2010 14:53:34 +0000 Subject: Python documentation too difficult for beginners References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <871v73kc9d.fsf@rudin.co.uk> Steven D'Aprano writes: > A fair point -- the built-in open comes up as hit #30, whereas searching > for open in the PHP page brings up fopen as hit #1. But the PHP search > also brings up many, many hits -- ten pages worth. > OTOH googling for "python open" gives you the correct (for 2.7) page as hit #1 - although you then have to use your browser's "find" facilty to actually get to the description of the function in question. From dalist0 at gmail.com Tue Nov 2 10:57:12 2010 From: dalist0 at gmail.com (Daniel) Date: Tue, 2 Nov 2010 07:57:12 -0700 (PDT) Subject: extracting variables accessed and written from function / rule-based function calls References: <0d74ca46-657c-41cc-a582-0d78f11350a3@30g2000yql.googlegroups.com> <4CCF4C03.2020203@mrabarnett.plus.com> Message-ID: <58a67616-d3b8-4186-8ca8-d9ce95a1839e@y23g2000yqd.googlegroups.com> > >> You might be interested by the story of how AstraZeneca tackled that > >> kind of problem in PyDrone:http://www.python.org/about/success/astra/ that is interesting! So it seems they store the values in a dictionary. For each value they associate a function that gets called when the value is not available. This function uses the same dictionary to access the other values, which might trigger more evaluations. I like this approach. Unfortunately in my case it would not work, because I might have more than one rule associated with each function, depending on which values are available. If the wrong rule gets called which needs to call other (wrong) rules I could end up in a loop, even though everything could be computed in principle. lets say a follows from b or c (r1, r2) , b follows from a or c (r3, r4) and c is given. Using this approach I would end up in a loop of rules r1 and r3 to compute a. I don't see how this approach could be made to work the other way round, each value could have a rule attached that, given the availability of other dependencies computes the dependent values. That seems complicated, because one rule would need to be associated with several values. One possibility I thought of was to write the rules as python functions and use the ast module to extract all the variables that are being referenced. In principle this should be possible. Is there any library around that does that? Dan From bruno.42.desthuilliers at websiteburo.invalid Tue Nov 2 11:28:28 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 02 Nov 2010 16:28:28 +0100 Subject: Python documentation too difficult for beginners In-Reply-To: References: Message-ID: <4cd02e1b$0$7393$426a74cc@news.free.fr> jk a ?crit : > Hi, > > I've been coding in PHP and Java for years, and their documentation is > concise, well structured and easy to scan. > > Others have mentioned this apparently for years (see: > http://stackoverflow.com/questions/4046166/easy-to-navigate-online-python-reference-manual/4070851 > and http://www.russellbeattie.com/blog/python-library-docs-still-suck > and http://xahlee.org/perl-python/xlali_skami_cukta.html). Totally unrelated, but the last example is nothing but a reference - xahlee is one of the worst internet troll ever. > Compare for instance the differences in ease of use, and speed of use, > of these: > > http://docs.python.org/library/functions.html#open > http://uk.php.net/manual/en/function.fopen.php Sorry but as far as I'm concerned, PHP doc sucks big time, and I find Javadoc-style stuff close to useless. (snip) > Has anyone else struggled while trying to learn the language? Not as far as I'm concerned. I found Python the easiest language to learn right from the beginning. Not to say the doc couldn't be improved, or that alternate documentations could help, but I never had any problem with it. From lists at asd-group.com Tue Nov 2 12:09:59 2010 From: lists at asd-group.com (John Bond) Date: Tue, 02 Nov 2010 16:09:59 +0000 Subject: Why this result with the re module In-Reply-To: <552223.15146.qm@web54201.mail.re2.yahoo.com> References: <552223.15146.qm@web54201.mail.re2.yahoo.com> Message-ID: <4CD037D7.7070408@asd-group.com> On 2/11/2010 12:19 PM, Yingjie Lan wrote: >> From: John Bond >> Subject: Re: Why this result with the re module > Firstly, thanks a lot for your patient explanation. > this time I have understood all your points perfectly. > > Secondly, I'd like to clarify some of my points, which > did not get through because of my poor presentation. > > I suggested findall return a tuple of re.MatchObject(s), > with each MatchObject instance representing a match. > This is consistent with the re.match() function anyway. > And it will eliminate the need of returning tuples, > and it is much more precise and information rich. > > If that's not possible, and a tuple must be returned, > then the whole match (not just subgroups) should > always be included as the first element in the tuple, > as that's group(0) or '\0'. Less surprise would arise. > > Finally, it seems to me the algo for findall is WRONG. > > To re.findall('(.a.)*', 'Mary has a lamb'), > by reason of greediness of '*', and the requirement > of non-overlapping, it should go like this > (suppose an '' is at the beginning and at the end, > and between two consecutive characters there is > one and only one empty string ''. To show the > match of empty strings clearly, > I am concatenating each repeated match below): > > Steps for re.findall('(.a.)*', 'Mary has a lamb'): > > step 1: Match '' + 'Mar' + '' (gready!) > step 2: skip 'y' > step 3: Match '' > step 4: skip ' ' > step 5: Match ''+'has'+' a '+'lam'+'' (greedy!) > step 6: skip 'b' > step 7: Match '' > > So there should be exactly 4 matches in total: > > 'Mar', '', 'has a lam', '' > > Also, the matches above shows > that if a repeated subgroup only captures > the last match, the subgroup (.a.)* > should always capture '' here (see steps > 1, 3, 5, 7) above. > > Yet the execution in Python results in 6 matches! > And, the capturing subgroup with repetition > sometimes got the wrong guy. > > So I believe the algorithm for findall must be WRONG. > > Regards, > > Yingjie At a guess, I'd say what is happening is something like this: Steps for re.findall('(.a.)*', 'Mary has a lamb'): step 1: Match 'Mar' at string index 0 step 2: Match '' at string index 3 (before 'y') step 3: skip 'y' step 4: Match '' at string index 4 (before ' ') step 5: skip ' ' step 6: Match 'has a lam' at string index 5 step 7: Match '' at string index 14 (before 'b') step 8: skip 'b' step 9: Match '' at string index 15 (before EOS) matches: ('Mar', '', '', 'has a lam', '', '') returns: ['Mar', '', '', 'lam', '', ''] (*) (*) "has a " lost due to not being last repetition at that match point Which seems about right to me! Greediness has nothing to do with it, except that it causes 'has a lam' to be matched in one match, instead of as three separate matches (of 'has', ' a ' and 'lam'). From tjreedy at udel.edu Tue Nov 2 12:57:59 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 02 Nov 2010 12:57:59 -0400 Subject: factorial of negative one (-1) In-Reply-To: <87vd4gm3vb.fsf@xemacs.org> References: <87r5f55qj5.fsf@xemacs.org> <87vd4gm3vb.fsf@xemacs.org> Message-ID: On 11/2/2010 6:11 AM, Hrvoje Niksic wrote: >>>> 1.1 .hex() > '0x1.199999999999ap+0' > > Here it is immediately obvious that the final digit of the infinite > sequence "1.1999..." is rounded from 9 to a. Printing the number with > any more digits would just reveal zeros, as expected. > > Does anyone know why Python doesn't accept hex float literals in source > code? Assuming that the parser would have no problem with them: 1. the format is relatively recent 2. you can write float.fromhex('') 3. it never occurred to anyone to do so 4. literals are values supplied by the programmer; hex float values are rare and when they do occur, they are usually the stored output of a previous .hex() in Python or similar in other languages. 5. too easy to confuse in quick reading with normal float literals 6. the format is a bit weird and too esoteric for most programmers; they should not be part of the basic syntax that everyone has to learn; someone who reads float.fromhex(something) can look it up. -- Terry Jan Reedy From tjreedy at udel.edu Tue Nov 2 13:16:27 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 02 Nov 2010 13:16:27 -0400 Subject: functions, list, default parameters In-Reply-To: References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <8ivelpFif1U1@mid.individual.net> <4cca88bc$0$29987$c3e8da3$5496439d@news.astraweb.com> <8j1seqFa1eU2@mid.individual.net> Message-ID: On 11/2/2010 3:12 AM, Lawrence D'Oliveiro wrote: >> "Immutable objects" are just those without an obvious API for modifying >> them. After initial creation ;-)/ > They are ones with NO legal language constructs for modifying them. Suppose I write an nasty C extension that mutates tuples. What then would be illegal about import tuple_mutator t = (1,2) tuple_mutator.inc(t) t # (2,3) > Hint: if > a selector of some part of such an object were to occur on the LHS of an > assignment, and that would raise an error, then the object is immutable. I am not sure what you are saying here, and how it applies to >>> lt = [(0,)] >>> lt[0][0] = 1 Traceback (most recent call last): File "", line 1, in lt[0][0] = 1 TypeError: 'tuple' object does not support item assignment >>> tl = ([0],) >>> tl[0][0] = 1 >>> tl ([1],) -- Terry Jan Reedy From robert.kern at gmail.com Tue Nov 2 13:24:44 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 02 Nov 2010 12:24:44 -0500 Subject: functions, list, default parameters In-Reply-To: References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <8ivelpFif1U1@mid.individual.net> <4cca88bc$0$29987$c3e8da3$5496439d@news.astraweb.com> <8j1seqFa1eU2@mid.individual.net> Message-ID: On 11/2/10 2:12 AM, Lawrence D'Oliveiro wrote: > In message, Robert Kern > wrote: > >> On 2010-11-01 22:31 , Lawrence D'Oliveiro wrote: >> >>> In message<8j1seqFa1eU2 at mid.individual.net>, Gregory Ewing wrote: >>> >>>> Steven D'Aprano wrote: >>>> >>>>> And how does Python know whether some arbitrary default object is >>>>> mutable or not? >>>> >>>> It doesn't, that's the whole point. >>> >>> Of course it knows. It is the one defining the concept in the first >>> place, after all. >> >> No, the Python interpreter doesn't define the concept. The Python language >> developers did. > > The Python language developers said ?let there be light?, and the Python > interpreter gave forth light. So which one defines the concept of ?light?? I'm sorry, but that's not even a meaningful reply. They said no such thing and the interpreter does no such thing. Let's talk about things the developers did say and the things the interpreter does do, shall we? The Python language developers defined the concept of mutable objects. However, they defined it in human terms, not algorithmic ones. They did not imbue the interpreter with a way of determining immutability. >> "Immutable objects" are just those without an obvious API for modifying >> them. > > They are ones with NO legal language constructs for modifying them. Hint: if > a selector of some part of such an object were to occur on the LHS of an > assignment, and that would raise an error, then the object is immutable. The > interpreter already knows all this. Incorrect. RHS method calls can often modify objects. set.add() mutates the set even though it does not have the usual LHS mutation methods like .__setitem__(). And even among the LHS APIs, raising an error does not determine immutability. int.__iadd__() does not raise an error, but ints are still immutable. list.__iadd__() does not raise an error, and lists are mutable. And even if it were reliable, how would the interpreter know what arguments to pass? list.__iadd__() doesn't work for any object. And why do you think that testing mutability in such a way would be safe since attempting those would necessarily alter the object if it is mutable? Show me the algorithm that the interpreter can use to determine whether or not an object is mutable. Or better, since you think the interpreter already knows this, show me the implementation in the interpreter's source code. >> With various trickeries, I can mutate any immutable object. > > None within the Python language itself. Which is what we?re talking about > here: a language construct which is probably one of the top 3 sources of > grief to Python newbies. And not-so-newbies. "import ctypes" is within the Python language. -- 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 ian.g.kelly at gmail.com Tue Nov 2 13:34:27 2010 From: ian.g.kelly at gmail.com (Ian) Date: Tue, 2 Nov 2010 10:34:27 -0700 (PDT) Subject: functions, list, default parameters References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <4cc13ef5$0$29979$c3e8da3$5496439d@news.astraweb.com> <4ccffd1c$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5f6eceec-1eef-4db7-82a6-e5f553349229@k22g2000yqh.googlegroups.com> On Nov 2, 5:59?am, Steven D'Aprano wrote: > Certainly it's the mediocre programmers who seem to be incapable of > understanding that Python has no way of telling whether arbitrary objects > are mutable or not. > > def foo(x, y=list()): > ? ? pass > > Is y a mutabledefaultor not? > > For the benefit of any mediocre programmers out there, be careful before > you answer. This *is* a trick question. I fail to see your point. You might as well argue that Python has no way of knowing whether it should raise a TypeError in the following example: my_tuple = (1, 2, 3) + list(xrange(4, 7)) Dynamic typing means that these sorts of checks must be delayed until runtime, but that doesn't make them useless or impossible. It seems to me that there is a rather simple case to be made for allowing mutable default arguments: instances of user-defined classes are fundamentally mutable. Disallowing mutable default arguments would mean disallowing instances of user-defined classes entirely. That would be excessive and would violate Python's general rule of staying out of the programmer's way. Cheers, Ian From paul.nospam at rudin.co.uk Tue Nov 2 13:45:46 2010 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Tue, 02 Nov 2010 17:45:46 +0000 Subject: functions, list, default parameters References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <8ivelpFif1U1@mid.individual.net> <4cca88bc$0$29987$c3e8da3$5496439d@news.astraweb.com> <8j1seqFa1eU2@mid.individual.net> Message-ID: <87tyjzippx.fsf@rudin.co.uk> Terry Reedy writes: > Suppose I write an nasty C extension that mutates tuples. What then > would be illegal about... Depends on exactly what we mean by legal. If immutability is part of the language spec (rather than an artifact of a particular implementation) then a compiler could assume immutability. From tjreedy at udel.edu Tue Nov 2 13:47:07 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 02 Nov 2010 13:47:07 -0400 Subject: Python documentation too difficult for beginners In-Reply-To: References: Message-ID: On 11/2/2010 6:42 AM, jk wrote: > Compare for instance the differences in ease of use, and speed of use, > of these: > > http://docs.python.org/library/functions.html#open > http://uk.php.net/manual/en/function.fopen.php > > The former is difficult to find (try searching for 'open' in the > search box and see what you get). duh. 'open' is a common word and if you make an unstructured search for it in all text, you should get a lot of hits. The Python docs have both a Global Module Index (which I use constantly) and a General Index of functions (methods), classes, and terms. Learn to use them. If you look in the [o] section for 'open', the first entry is "open() (built-in function)" -- just what you were looking for. There are also about 30 more nicely labelled entries for 'open' in various modules. > It is simply a collection of > paragraphs without strong enough contrast to differentiate the > different parts - parameters, parameter values, return types, > exceptions and related functions. It is slow to read and doesn't allow > easy visual scanning. It is possible that this particular entry could be improved. > Is there much chance that the Python maintainers will change their > documentation system to make it more like Java or PHP? There are plans to make doc feedback from users easier. -- Terry Jan Reedy From nagle at animats.com Tue Nov 2 13:54:46 2010 From: nagle at animats.com (John Nagle) Date: Tue, 02 Nov 2010 10:54:46 -0700 Subject: Python equivalent of SOAP-ISIWoK In-Reply-To: References: Message-ID: <4cd05064$0$1662$742ec2ed@news.sonic.net> On 11/2/2010 1:58 AM, Johann Spies wrote: > SOAP-ISIWoK is a Perl library for assessing Thomson Reuters Web of > Knowledge Web Services. I don't know Perl well enough to use that > library without spending too much time on it. > > Is there a Python equivalent available? The "Suds" library can call SOAP interfaces, and is not difficult to use. https://fedorahosted.org/suds/ > > Regards > Johann > -- > May grace and peace be yours in abundance through the full knowledge > of God and of Jesus our Lord! His divine power has given us > everything we need for life and godliness through the full knowledge > of the one who called us by his own glory and excellence. > 2 Pet. 1:2b,3a God helps those who help themselves. Benj. Franklin From usenet-nospam at seebs.net Tue Nov 2 13:58:06 2010 From: usenet-nospam at seebs.net (Seebs) Date: 02 Nov 2010 17:58:06 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: On 2010-11-02, D'Arcy J.M. Cain wrote: > You have problems. Indentation as syntax isn't one of them. In the absence of indentation as syntax, they haven't bugged me. > "No one > knows why" email is being "magically" transformed? Yay for a large company IT department with both MS and Blackberry stuff involved. > Your editor has a > mind of its own? Yikes! It is extremely useful to me to have spaces converted to tabs for every other file I edit. >> I've lost more time to indentation issues in Python in a month than >> I've lost to mismatches between indentation and flow in C in twenty > Your experience is 180 from mine. Could be. But really, I've simply never seen a real problem with flow/indentation mismatches in C. >> At least in C, if I see: >> if (foo) >> a; >> else >> b; >> c; >> >> I *know* that something is wrong. > Does it look right? With Python looking right and being right are the > same thing. No, they aren't. See... That would work *if I knew for sure what the intent was*. if foo: bar else: baz quux Does it look right? We have *no idea*, because we don't actually know whether quux was *intended* to be in the else branch or whether that's a typo. So the only way I can figure that out is by fully figuring out the function of all the code bits -- meaning I have to fully understand the code, same as I would to debug the C. The fact that indentation is flow control just means I have only one set of cues, so I can't watch for mismatches. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From hobson42 at gmaiil.com Tue Nov 2 14:07:15 2010 From: hobson42 at gmaiil.com (Ian) Date: Tue, 02 Nov 2010 18:07:15 +0000 Subject: Python documentation too difficult for beginners In-Reply-To: <024ef21a-9ef9-48a6-8372-1d66895583c3@v16g2000yqn.googlegroups.com> References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> <024ef21a-9ef9-48a6-8372-1d66895583c3@v16g2000yqn.googlegroups.com> Message-ID: <4CD05353.1040002@gmaiil.com> On 02/11/2010 14:47, jk wrote: > I think the key difference is that I don't want to have to*read* the > python docs - I want to be able to scan for what I'm looking for and > find it easily. That makes me productive. Hi jk, I totally agree. But you will get nowhere. A few weeks back I complained that http://docs.python.org/reference/executionmodel.html#naming-and-binding was more than a little opaque - and was not understood by Python noobs such as myself. I was invited to rewrite it and submit an improved version. Remember I said I was a noob and did not understand it. Just how can I rewrite it from that base? But I'm sure that the trouble is with me. It is clear from this statement (rom that page)... "If a name binding operation occurs anywhere within a code block, all uses of the name within the block are treated as references to the current block." that, (in the given situation), name binding does not bind a name to a variable but to a block. Just for the record, I really know it is not me. English is my mother tongue, and I have some programming experience, in a variety of languages. I wrote my first program in 1964, and have been earning a living programming since '74. I have used Cobol, Lisp, Smalltalk, C, Javascript, Notes, PHP and many other languages in a commercial environment over the last 36 (good gracious!) years. This lack of documentation is almost universal. You will have heard of the "with batteries" tag. This means that, whatever you want to do, there are usually many libraries available to help you do it. Every one will be poorly documented and most are hard to find. Yes there are batteries - but it is not clear which is more productive: write what is needed from scratch, or investigate what "batteries" are available and risk finding that the one you chose is missing some important feature down the line? Observe though that having poor introductory documentation sells a lot of "How to Program in Python" type books. Its sad really. Python is a great little language, and deserves better. Without an on-ramp, noobs will struggle to get on the freeway. And yet, enough will get on, that these pleas for better documentation can be ignored by those who know and could do something about it. Regards Ian -------------- next part -------------- An HTML attachment was scrubbed... URL: From usenet-nospam at seebs.net Tue Nov 2 14:10:48 2010 From: usenet-nospam at seebs.net (Seebs) Date: 02 Nov 2010 18:10:48 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-02, Steven D'Aprano wrote: > I've lost more time to reading people's bitching about indentation than I > have dealing with indentation problems. Doesn't totally surprise me. :) > But then, I don't insist on using tools which are broken by design. Neither do I. > If your email server converts plain text to HTML, it is broken. Yup. I have an open ticket with the IT department. :) > If your > editor changes spaces to tabs, or visa versa, without being told to do so > (either by an explicit command or an obvious setting), then your editor > is broken. Yes. But that's the thing -- I *want* that behavior for every other tool, file format, or other thing I work with. > If you are stuck with broken mail servers and broken editors and broken > tools because of political reasons, then you have my sympathy. But stop > insisting that everybody has to carry the overhead of your work-arounds > for your broken tools. I have made no such insistance. I have not said Python should change. I have not said other people should want what I want. I'm not the one telling other people that editors they've used happily for twenty years without any problems are clearly wrong. I have merely observed that Python is, in this respect, gratuitously brittle. It doesn't observe the robustness principle; it is conservative in what it accepts, and in particular, is vulnerable to a category of problem which is fairly common, well-known, and likely to remain common for the next few decades. There are reasons for it to be this way, and I don't object to the existence of people who prefer that side of the tradeoff. I do dislike it when people smugly tell me off for having different preferences. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From invalid at invalid.invalid Tue Nov 2 14:15:03 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 2 Nov 2010 18:15:03 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: On 2010-11-02, Seebs wrote: > On 2010-11-02, D'Arcy J.M. Cain wrote: >> You have problems. Indentation as syntax isn't one of them. > > In the absence of indentation as syntax, they haven't bugged me. > >> "No one >> knows why" email is being "magically" transformed? > > Yay for a large company IT department with both MS and Blackberry > stuff involved. > >> Your editor has a >> mind of its own? Yikes! > > It is extremely useful to me to have spaces converted to tabs > for every other file I edit. > >>> I've lost more time to indentation issues in Python in a month than >>> I've lost to mismatches between indentation and flow in C in twenty > >> Your experience is 180 from mine. > > Could be. But really, I've simply never seen a real problem with > flow/indentation mismatches in C. > >>> At least in C, if I see: >>> if (foo) >>> a; >>> else >>> b; >>> c; >>> >>> I *know* that something is wrong. > >> Does it look right? With Python looking right and being right are the >> same thing. > > No, they aren't. See... That would work *if I knew for sure what the intent > was*. > > if foo: > bar > else: > baz > quux > > Does it look right? We have *no idea*, because we don't actually know > whether quux was *intended* to be in the else branch or whether that's a typo. > > So the only way I can figure that out is by fully figuring out the function > of all the code bits -- meaning I have to fully understand the code, same > as I would to debug the C. The fact that indentation is flow control > just means I have only one set of cues, so I can't watch for mismatches. You can add redundant, semantically empty structure info to Python programs just as easily as you can to C programs: if foo: bar else: baz quux #endif -- Grant Edwards grant.b.edwards Yow! With YOU, I can be at MYSELF ... We don't NEED gmail.com Dan Rather ... From emile at fenx.com Tue Nov 2 14:18:50 2010 From: emile at fenx.com (Emile van Sebille) Date: Tue, 02 Nov 2010 11:18:50 -0700 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: On 11/2/2010 10:58 AM Seebs said... > No, they aren't. See... That would work *if I knew for sure what the intent > was*. > > if foo: > bar > else: > baz > quux > > Does it look right? We have *no idea*, because we don't actually know > whether quux was *intended* to be in the else branch or whether that's a typo. What is right is that there's no question that quux is subsequent to baz in all cases barring exceptions (and assuming no tabs intermixed) The apparent structure in python _is_ the structure, whereas otherwise you've got to count your ;'s and {}'s etc to determine and verify the structure matches the apparent structure provided by the programmer. Whether that's what the specs called for or not is always a source for bugs. Emile From invalid at invalid.invalid Tue Nov 2 14:22:57 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 2 Nov 2010 18:22:57 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: On 2010-11-02, Emile van Sebille wrote: > On 11/2/2010 10:58 AM Seebs said... >> No, they aren't. See... That would work *if I knew for sure what the intent >> was*. >> >> if foo: >> bar >> else: >> baz >> quux >> >> Does it look right? We have *no idea*, because we don't actually know >> whether quux was *intended* to be in the else branch or whether that's a typo. > > What is right is that there's no question that quux is subsequent to baz > in all cases barring exceptions (and assuming no tabs intermixed) > > The apparent structure in python _is_ the structure, whereas otherwise > you've got to count your ;'s and {}'s etc to determine and verify the > structure matches the apparent structure provided by the programmer. > > Whether that's what the specs called for or not is always a source > for bugs. Yup. I've never found that the ability to write incorrect code that _appears_ correct to be a good thing. Nor do I find the ability to write correct code that appears to be incorrect to be valuable. In Python, if the structure looks right, then structure _is_ right. -- Grant Edwards grant.b.edwards Yow! Now we can become at alcoholics! gmail.com From darcy at druid.net Tue Nov 2 14:37:40 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 2 Nov 2010 14:37:40 -0400 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: <20101102143740.603f2769.darcy@druid.net> On 02 Nov 2010 17:58:06 GMT Seebs wrote: > On 2010-11-02, D'Arcy J.M. Cain wrote: > > "No one > > knows why" email is being "magically" transformed? > > Yay for a large company IT department with both MS and Blackberry > stuff involved. "Large" is no excuse for incompetency. > > Your editor has a > > mind of its own? Yikes! > > It is extremely useful to me to have spaces converted to tabs > for every other file I edit. So configure it to recognize Python files and act accordingly. > No, they aren't. See... That would work *if I knew for sure what the intent > was*. > > if foo: > bar > else: > baz > quux > > Does it look right? We have *no idea*, because we don't actually know > whether quux was *intended* to be in the else branch or whether that's a typo. And C has the same problem. if (foo) bar; else baz; quux; Is quux meant to be part of the else clause? The writer's indentation suggests "yes" but the code says "no". > So the only way I can figure that out is by fully figuring out the function Same is true for the C code. In both cases you can tell what the code will do (modulo weird macros in the C code) but the intention is impossible to determine without mind reading abilities in both cases. We do know that the Python code *appears* to be doing exactly what the author intended and the C code *appears* to not be. In either case, != . -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From darcy at druid.net Tue Nov 2 14:42:14 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 2 Nov 2010 14:42:14 -0400 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: <20101102144214.23f3b738.darcy@druid.net> On Tue, 2 Nov 2010 18:15:03 +0000 (UTC) Grant Edwards wrote: > You can add redundant, semantically empty structure info to Python > programs just as easily as you can to C programs: > > if foo: > bar > else: > baz > quux > #endif "Redundant" is right. However, there is a use for such comments: if foo: bar else: baz if snafu: cookie #endif snafu quux #endif foo Useful in more complicated code, of course. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From usernet at ilthio.net Tue Nov 2 14:43:08 2010 From: usernet at ilthio.net (Tim Harig) Date: Tue, 2 Nov 2010 18:43:08 +0000 (UTC) Subject: Python documentation too difficult for beginners References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> <024ef21a-9ef9-48a6-8372-1d66895583c3@v16g2000yqn.googlegroups.com> Message-ID: On 2010-11-02, jk wrote: > As for the 9 paragraphs statement, there's a usability book that > applies here - it's called "Don't make me think". I shouldn't have to Anything that promotes a lack of thinking sends up red flags in my head. We want to recruit smart people who think, not idiots. > go through freeform text to find what I'm looking for when a list > would make that information easier to find. And splitting the docs > into sections would allow me to skip to what I'm looking for. I really > would be much happier with your example documentation. ctrl-f will bring up a search dialog in most graphical browsers. '/' will in many others. With some practice, your fingers will be able to find something far faster then your eyes can see it happen. There is a religious war in the GNU community between info page as documentation versus the traditional manual format. The manual format contains all of the information on one page that can be easily searched whereas the info pages are split into sections that must be viewed individually. With the man pages, you can almost always find what you want with a quick search through the document. Info pages are much harder to use because you have to try and figure out which section the author decided to place the information that you are looking for. The information may be stored several levels deep, which means that it can be a deep productivity hit if you don't guess the proper location on the first try. > I think the key difference is that I don't want to have to *read* the > python docs - I want to be able to scan for what I'm looking for and > find it easily. That makes me productive. The real question is what do you want to gain by your posts here. You should already know that most groups are, by their very nature, slow to make changes to the status quo. The problem tends to be exasperated in open source projects where any changes mean that people have to donate their time to make anything happen. You will in general find two things to be true: 1. Since they are dontating their time, you will find that people tend to scratch their own iches first. 2. People who do take the time to contribute to open source projects are people of action. They don't tend to be appreciative of those who constantly generate feature requests but have no inclination to do any of the work themselves. They do appreciate other people of action who are interested in making the project better. Therefore, if you truly want changes in the documentation, I suggest that, rather then whining to the group, you make some of the changes yourself. When you are finished, you can post a link to your alternate documentation to this group. If you documentation is truly better then the existing documentation, you will not have to say another word. People within the community will rally around it and promote it. If it gains wide enough support, then there will be a movement to use it to supplant the existing documentation. It is the difference between whining from the sidelines and actively participating in the game. From ian.g.kelly at gmail.com Tue Nov 2 14:51:42 2010 From: ian.g.kelly at gmail.com (Ian) Date: Tue, 2 Nov 2010 11:51:42 -0700 (PDT) Subject: Python documentation too difficult for beginners References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> <024ef21a-9ef9-48a6-8372-1d66895583c3@v16g2000yqn.googlegroups.com> Message-ID: <7be6c287-dd46-4931-8d26-d1aef1a1df23@p1g2000yqm.googlegroups.com> On Nov 2, 8:47?am, jk wrote: > You're right in that the python docs in this case are less lines, but > that's one of the problems. It doesn't mention anywhere the extra > detail you've added regarding exceptions thrown. That's the kind of > thing that probably comes through experience or some kind of > convention which isn't obvious to beginners. Having things split into > sections - parameters, return types, exceptions, etc - lets me find > what I'm looking for quickly. It doesn't mention it because those exceptions don't actually have anything to do with the id() function. They're just what happens any time an unbound variable name is evaluated, in any context. The exact same thing could be said about any Python function in existence that takes at least one argument. Cheers, Ian From kee at kagi.com Tue Nov 2 14:56:57 2010 From: kee at kagi.com (Kee Nethery) Date: Tue, 2 Nov 2010 11:56:57 -0700 Subject: Python documentation too difficult for beginners In-Reply-To: <4CD05353.1040002@gmaiil.com> References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> <024ef21a-9ef9-48a6-8372-1d66895583c3@v16g2000yqn.googlegroups.com> <4CD05353.1040002@gmaiil.com> Message-ID: On Nov 2, 2010, at 11:07 AM, Ian wrote: > On 02/11/2010 14:47, jk wrote: >> I think the key difference is that I don't want to have to *read* >> the >> python docs - I want to be able to scan for what I'm looking for and >> find it easily. That makes me productive. >> > Hi jk, > > I totally agree. But you will get nowhere. > > A few weeks back I complained that > http://docs.python.org/reference/executionmodel.html#naming-and-binding > was more than a little opaque - and was not understood by Python noobs such as myself. > > I was invited to rewrite it and submit an improved version. In this world of moderated wikis one would think that noobs such as myself could enhance the docs when we find something confusing in the docs. Kee From tlikonen at iki.fi Tue Nov 2 15:04:05 2010 From: tlikonen at iki.fi (Teemu Likonen) Date: Tue, 02 Nov 2010 21:04:05 +0200 Subject: Man pages and info pages (was: Python documentation too difficult for beginners) References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> <024ef21a-9ef9-48a6-8372-1d66895583c3@v16g2000yqn.googlegroups.com> Message-ID: <87zktr5yze.fsf_-_@mithlond.arda> * 2010-11-02 18:43 (UTC), Tim Harig wrote: > The manual format contains all of the information on one page that can > be easily searched whereas the info pages are split into sections that > must be viewed individually. With the man pages, you can almost always > find what you want with a quick search through the document. Info > pages are much harder to use because you have to try and figure out > which section the author decided to place the information that you are > looking for. There is also the problem that people are less familiar with info browsers than the usual "less" pager which is used by "man" command. With the text terminal info browser called "info" as well as Emacs' info browser you can use command "s" (stands for "search"). It prompts for a regexp pattern to search in the whole document, including subsections etc. From nagle at animats.com Tue Nov 2 15:04:39 2010 From: nagle at animats.com (John Nagle) Date: Tue, 02 Nov 2010 12:04:39 -0700 Subject: Python documentation too difficult for beginners In-Reply-To: <871v73kc9d.fsf@rudin.co.uk> References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> <871v73kc9d.fsf@rudin.co.uk> Message-ID: <4cd060c5$0$1633$742ec2ed@news.sonic.net> On 11/2/2010 7:53 AM, Paul Rudin wrote: > Steven D'Aprano writes: > >> A fair point -- the built-in open comes up as hit #30, whereas searching >> for open in the PHP page brings up fopen as hit #1. But the PHP search >> also brings up many, many hits -- ten pages worth. >> > > OTOH googling for "python open" gives you the correct (for 2.7) page as > hit #1 - although you then have to use your browser's "find" facilty to > actually get to the description of the function in question. Right. Google does a far better job of organizing Python's documentation than the Python community does. I don't even try looking up anything starting at Python.org; I always start with a Google search. Even though Python.org's search is powered by Google, it's inferior to a general search. Compare: http://www.google.com/search?domains=www.python.org&sitesearch=www.python.org&q=open http://www.google.com/search?q=Python+open John Nagle From ethan at stoneleaf.us Tue Nov 2 15:08:34 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 02 Nov 2010 12:08:34 -0700 Subject: Compare source code In-Reply-To: <4ccfefc6$0$29966$c3e8da3$5496439d@news.astraweb.com> References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccfefc6$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4CD061B2.6040404@stoneleaf.us> Steven D'Aprano wrote: > Personally, I'm more disturbed by the default prompt in the interactive > interpreter. >>> clashes with the symbol used for quoting text in email > and news. That causes me far more distress than indentation. Here here! I finally did "sys.ps1 = '--> '" in my interactive startup file. :) ~Ethan~ From gdamjan at gmail.com Tue Nov 2 15:15:36 2010 From: gdamjan at gmail.com (=?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLRgdC60Lg=?=) Date: Tue, 02 Nov 2010 20:15:36 +0100 Subject: ANN: PyQt v4.8.1 Released References: Message-ID: >> PyQt is available under the GPL and a commercial license. > > Surely you mean ?proprietary? rather than ?commercial?. There is > nothing about the GPL that prevents ?commercial? use. I think he means a license that *he* sells comercially :) -- ?????? ((( http://damjan.softver.org.mk/ ))) Religion ends and philosophy begins, just as alchemy ends and chemistry begins and astrology ends, and astronomy begins. From usenet-nospam at seebs.net Tue Nov 2 15:24:44 2010 From: usenet-nospam at seebs.net (Seebs) Date: 02 Nov 2010 19:24:44 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <8j8udgFlkvU1@mid.individual.net> Message-ID: On 2010-11-02, Grant Edwards wrote: > True, but the fact that diff has an option that for Python sources > will produces useless results doesn't seem like a valid indictment of > Python's syntax and semantics. The question is *why* diff has that option. The answer is because whitespace changes (spaces to tabs, different tab stops, etcetera) are an extremely common failure mode, such that it's quite common for files to end up with unintentional whitespace changes. This, in turn, is why there are so many tools to automatically fix up whitespace type issues, such as cb/indent for C, auto-indentation for many languages (including stuff like XML) features in editors, and so on -- because it's a common problem. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usernet at ilthio.net Tue Nov 2 15:26:56 2010 From: usernet at ilthio.net (Tim Harig) Date: Tue, 2 Nov 2010 19:26:56 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-02, Seebs wrote: > On 2010-11-02, Steven D'Aprano wrote: >> If your >> editor changes spaces to tabs, or visa versa, without being told to do so >> (either by an explicit command or an obvious setting), then your editor >> is broken. > > Yes. But that's the thing -- I *want* that behavior for every other tool, > file format, or other thing I work with. I agree with Seebs, Python is the only language I know that promotes the use of spaces over tabs; and there are equally picky syntaxs (ie, Makefiles) that mandate the use of tabs. I personally prefer tabs as it lets *me* decide how far the apparent indentations are in the code. You may like four spaces; but, I agree with Linus Torvalds that eight spaces is much clearer. The beautiful thing about tabs is that we can both set our tab stops to match our own viewing preferences. >> If you are stuck with broken mail servers and broken editors and broken >> tools because of political reasons, then you have my sympathy. But stop >> insisting that everybody has to carry the overhead of your work-arounds >> for your broken tools. > > I have made no such insistance. I have not said Python should change. I > have not said other people should want what I want. I'm not the one telling > other people that editors they've used happily for twenty years without > any problems are clearly wrong. Indeed, a simple script is enough to identify how levels are indented and convert the present indenting to whatever is your preference. > There are reasons for it to be this way, and I don't object to the > existence of people who prefer that side of the tradeoff. I do dislike > it when people smugly tell me off for having different preferences. This is Python's most noticable blemish outside of the community. Everybody knows that Python is the language that forces you to use a particular style of formatting; and, that is a turn-off for many people. It is a big mistake that whenever the issue arises, the community effectively attacks anybody who might have disagreements with the tradeoffs made for the Python language. This tends to set people on the defensive and gives them a bad taste about the language as a whole. It would be much better if the community would simply acknowledge that this is a tradeoff the the language has made and one which is often misunderstood by many first time Python programmers. Then it is possible transition to Python's strengths. Don't simply ignore that there *are* potential downfalls to this approach. From usenet-nospam at seebs.net Tue Nov 2 15:28:05 2010 From: usenet-nospam at seebs.net (Seebs) Date: 02 Nov 2010 19:28:05 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: On 2010-11-02, Grant Edwards wrote: > And you think compatibility with your broken e-mail server is a good > reason to change the syntax of a programming language? No. I never said that. >> Many editors helpfully convert spaces to tabs by default some or all >> of the time. And so on. > Such editors are broken. If I use an editor for twenty years, and it works beautifully with fifteen different programming languages across five operating systems, and someone comes along with a file format which tends to silently break when treated the same way, my first response is not to blame the editor. > I think it's brilliant (indentation that actually means something, not > scanf). It is. However, it's also brittle. >> The "problem" it fixes is something that's hardly ever been a problem >> for me in C or related languages -- and which could be completely >> eliminated by automated indenters, which were actually conceptually >> possible. > They're only possible if you put redundant block markers in the > source. Yes. Or make the block markers not-redundant. > Then you're doing something terribly wrong. I find indentation-based > structure to be completely effortless. And it is *ABSOLUTELY CERTAIN* that, if any two people have different experiences of how easy or hard something is, it's because one of them is doing something wrong, right? Because people are *never* actually different. There is no such thing as "preferences". There is no such thing as a "matter of taste". No, no. If one person finds something comfortable, and another dislikes it, it's because the second one is *doing something terribly wrong*. > Are you using an editor that > doesn't have a Python mode? Yes. I haven't used "modes" in editors until now. I've never needed to. Every other file format I work with is robust about this. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usernet at ilthio.net Tue Nov 2 15:36:11 2010 From: usernet at ilthio.net (Tim Harig) Date: Tue, 2 Nov 2010 19:36:11 +0000 (UTC) Subject: Man pages and info pages (was: Python documentation too difficult for beginners) References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> <024ef21a-9ef9-48a6-8372-1d66895583c3@v16g2000yqn.googlegroups.com> <87zktr5yze.fsf_-_@mithlond.arda> Message-ID: On 2010-11-02, Teemu Likonen wrote: > * 2010-11-02 18:43 (UTC), Tim Harig wrote: > >> The manual format contains all of the information on one page that can >> be easily searched whereas the info pages are split into sections that >> must be viewed individually. With the man pages, you can almost always >> find what you want with a quick search through the document. Info >> pages are much harder to use because you have to try and figure out >> which section the author decided to place the information that you are >> looking for. > > There is also the problem that people are less familiar with info > browsers than the usual "less" pager which is used by "man" command. I thoroughly agree. The default info viewers are quite possibly the most counterintuitive programs I have ever encountered. I never did bother to learn how to use them. I instead installed the more intuitive pinfo program. > With the text terminal info browser called "info" as well as Emacs' info > browser you can use command "s" (stands for "search"). It prompts for a > regexp pattern to search in the whole document, including subsections > etc. Right, pinfo offers this as well; but, then you have to figure out where in the nodes that the search has taken you and how to navigate from that node to find additional information that you may need. I have, in general, come to think of info pages as a failed experiment and I know very few people who actually prefer them over the simpler man pages. From rustompmody at gmail.com Tue Nov 2 15:38:45 2010 From: rustompmody at gmail.com (rustom) Date: Tue, 2 Nov 2010 12:38:45 -0700 (PDT) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> Message-ID: <20472710-e3ac-4e61-8d1a-1822d7702cd3@j25g2000yqa.googlegroups.com> Sigh! How flame-wars tend to lose the original question: On Oct 31, 5:02?pm, jf wrote: > Hi, > > I've a project with tabs and spaces mixed (yes I know it's bad). Do python aficionados want to suggest that mixing spaces and tabs is a 'good thing'? From lists at asd-group.com Tue Nov 2 15:48:35 2010 From: lists at asd-group.com (John Bond) Date: Tue, 02 Nov 2010 19:48:35 +0000 Subject: Ways of accessing this mailing list? Message-ID: <4CD06B13.3040008@asd-group.com> Hope this isn't too O/T - I was just wondering how people read/send to this mailing list, eg. normal email client, gmane, some other software or online service? My normal inbox is getting unmanageable, and I think I need to find a new way of following this and other lists. Thanks for any suggestions. Cheers, JB. From usernet at ilthio.net Tue Nov 2 16:02:02 2010 From: usernet at ilthio.net (Tim Harig) Date: Tue, 2 Nov 2010 20:02:02 +0000 (UTC) Subject: Man pages and info pages (was: Python documentation too difficult for beginners) References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> <024ef21a-9ef9-48a6-8372-1d66895583c3@v16g2000yqn.googlegroups.com> <87zktr5yze.fsf_-_@mithlond.arda> Message-ID: On 2010-11-02, Tim Harig wrote: > On 2010-11-02, Teemu Likonen wrote: >> With the text terminal info browser called "info" as well as Emacs' info >> browser you can use command "s" (stands for "search"). It prompts for a >> regexp pattern to search in the whole document, including subsections >> etc. > > Right, pinfo offers this as well; but, then you have to figure out where in > the nodes that the search has taken you and how to navigate from that node > to find additional information that you may need. I have, in general, come > to think of info pages as a failed experiment and I know very few people > who actually prefer them over the simpler man pages. I should add two more things here: 1. Another confusing aspect of the info pages is that you often have to know what package a command came from or you don't get the information that you are looking for. 2. Series of man pages can be used in a way that seem like they have a structure as they can effectively link to other pages. If I open one of the ncurses man pages in pinfo, I can follow what seem like links to other man pages. I can open the main curses page and I effectively get an index to all of the other curses functions. From invalid at invalid.invalid Tue Nov 2 16:11:23 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 2 Nov 2010 20:11:23 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccfefc6$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-02, Ethan Furman wrote: > Steven D'Aprano wrote: >> Personally, I'm more disturbed by the default prompt in the interactive >> interpreter. >>> clashes with the symbol used for quoting text in email >> and news. That causes me far more distress than indentation. > > Here here! > > I finally did "sys.ps1 = '--> '" in my interactive startup file. :) So _now_ what are going to whinge about? -- Grant Edwards grant.b.edwards Yow! I am NOT a nut.... at gmail.com From smallpox911 at gmail.com Tue Nov 2 16:39:04 2010 From: smallpox911 at gmail.com (small Pox) Date: Tue, 2 Nov 2010 13:39:04 -0700 (PDT) Subject: *** FBI gets a warm welcome in Chicago for their EXCELLENTperformance - cheers to NEW CONS *** References: <26f97f70-9043-490c-9e6e-35159f38d76b@r29g2000yqj.googlegroups.com> Message-ID: <47e0b3a3-54fb-4489-95a8-b5ec6015c99d@j25g2000yqa.googlegroups.com> If you want to act like a NETCOP then you must identify yourself and your organization or else you are considered a FACELESS COWARD CRIMINAL whose sole intent is to carry out CENSORSHIP of truth. Unless you ACTIVELY apply the same PURSUIT to ALL OTHER IRRELEVANT postings, you will be considered a STALKER, A CRIMINAL, A RACIST, A CENSORER, and SUPPRESSOR OF TRUTH and PARTNER CRIMINAL in the CRIME WE ARE TRYING TO EXPOSE. On Nov 1, 6:35 pm, Chris Rebert wrote: - Hide quoted text - - Show quoted text - > > -----Original Message----- > > From: silver light > > Sender: python-list-bounces+brf256=gmail.... at python.org > > Date: Mon, 1 Nov 2010 18:10:36 > > To: > > Cc: > > Subject: *** FBI gets a warm welcome in Chicago for their EXCELLENT > > performance - cheers to NEW CONS *** > > *** FBI gets a warm welcome in Chicago for their EXCELLENT performance > > - cheers to NEW CONS *** > > On Mon, Nov 1, 2010 at 6:21 PM, wrote: > > How exactly does this relate to python? > It doesn't. It's spam that was apparently also cross-posted to > sci.math, sci.physics, comp.text.tex, and comp.unix.shell. IT IS MOST CERTAINLY NOTTTTTT a SPAM. THIS FBI CENSORSHIP MOTHER FOCKER is the REAL SPAMMER AND CRIMINAL who wants to limit the news of their HEINOUS CRIMES and INCOMPETENCE to be SPREAD. The fact is that the real spammers are those who post PORNOGRAPHIC and COMMERCIAL messages on which the FBI CIA BLACKWATER and MOSSAD mother fockers masterbate and rape their mothers daily. AND NEVER SPEAK OUT. The truth of 911 bites them like the sting of a snake and truth it is. - Hide quoted text - - Show quoted text - > I advise reporting the sender, lightsilv... at gmail.com, to Gmail's abuse team:http://mail.google.com/support/bin/request.py?contact_type=abuse > Cheers, > Chris On Nov 2, 1:12?am, Seebs wrote: > On 2010-11-02, brf... at gmail.com wrote: > > > How exactly does this relate to python? > > 1. ?It doesn't. ?It's spam. ?Duh. > 2. ?Don't respond to spam. > 3. ?Don't top-post. > 4. ?If I see even one more post from you where the entire previous post > is quoted under your text, I will plonk you. ?I warn you now because > most posters will do the same thing, and you will get very lonely > once no one bothers to read your posts. > > -s > -- > Copyright 2010, all wrongs reversed. ?Peter Seebach / usenet-nos... at seebs.nethttp://www.seebs.net/log/<-- lawsuits, religion, and funny pictureshttp://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! > I am not speaking for my employer, although they do rent some of my opinions. If you want to act like a NETCOP then you must identify yourself and your organization or else you are considered a FACELESS COWARD CRIMINAL whose sole intent is to carry out CENSORSHIP of truth. Unless you ACTIVELY apply the same PURSUIT to ALL OTHER IRRELEVANT postings, you will be considered a STALKER, A CRIMINAL, A RACIST, A CENSORER, and SUPPRESSOR OF TRUTH and PARTNER CRIMINAL in the CRIME WE ARE TRYING TO EXPOSE. I am doing a sandwich posting - its called the BIG MAC ... cheers From zkinion at gmail.com Tue Nov 2 16:55:15 2010 From: zkinion at gmail.com (Zak Kinion) Date: Tue, 2 Nov 2010 13:55:15 -0700 Subject: problem with opening a new python program in a new window (and keeping track of the process) Message-ID: Hello all, What I want to do: launch seperate python programs from one main program (multi-threading will not achieve this because the mechanize library uses one shared global opener object which will not suit my needs) I want the scripts launched to be in seperate windows that i can see the output of on screen, seperate processes. I can accomplish this in win32 by: import subprocess; args = ["cmd", "/c", "START", "python", "myScript.py"]; process1 = subprocess.Popen(args, shell=False); however, doing will open a new window, but will lose the process id: e.g. process1.poll() will always return 0 no matter if the process is open or not, meaning that python always thinks its closed. It should return None if the process is still running. I can do it without using cmd /c start, but then the newly launched python script is trapped in my original cmd terminal where i launched the script from in the first place. I can keep track of the process now, but the one cmd window open is insufficient to keep track of the output that a multitude of programs running will produce. Doing it without the /c argument will still keep the new script in the same console. Yes, I have read I can do this in linux with Konsole or whatever like: child = subprocess.Popen("konsole -e python foo.py", shell=True) however, I need this to run in windows. Any help or solution is appreciated, -- Zak Kinion zkinion at gmail.com From richgrise at example.net Tue Nov 2 16:58:16 2010 From: richgrise at example.net (Rich Grise) Date: Tue, 02 Nov 2010 13:58:16 -0700 Subject: *** FBI gets a warm welcome in Chicago for their EXCELLENTperformance - cheers to NEW CONS *** References: <26f97f70-9043-490c-9e6e-35159f38d76b@r29g2000yqj.googlegroups.com> <47e0b3a3-54fb-4489-95a8-b5ec6015c99d@j25g2000yqa.googlegroups.com> Message-ID: On Tue, 02 Nov 2010 14:17:29 -0700, Gunner Asch wrote: > > But...shrug..there will be far less after the Great Cull........ I think some people might be surprised as to exactly _who_ gets "culled". Good Luck! Rich From malaclypse2 at gmail.com Tue Nov 2 17:01:41 2010 From: malaclypse2 at gmail.com (Jerry Hill) Date: Tue, 2 Nov 2010 17:01:41 -0400 Subject: Trouble with importing In-Reply-To: References: Message-ID: On Tue, Nov 2, 2010 at 3:33 PM, Ben Ahrens wrote: > Jerry, thanks for the reply, I was swamped with other things for the > better part of a week.. Anyway, I tried using the verbose flag when > attempting the import. ?I didn't see anything that meant anything to > me, but here's the bit surrounding the part where it fails: > > # /usr/lib/python2.6/dist-packages/gnuradio/__init__.pyc matches > /usr/lib/python2.6/dist-packages/gnuradio/__init__.py > import gnuradio # precompiled from > /usr/lib/python2.6/dist-packages/gnuradio/__init__.pyc > # /usr/lib/python2.6/re.pyc matches /usr/lib/python2.6/re.py > import re # precompiled from /usr/lib/python2.6/re.pyc > # /usr/lib/python2.6/sre_compile.pyc matches /usr/lib/python2.6/sre_compile.py > import sre_compile # precompiled from /usr/lib/python2.6/sre_compile.pyc > import _sre # builtin > # /usr/lib/python2.6/sre_parse.pyc matches /usr/lib/python2.6/sre_parse.py > import sre_parse # precompiled from /usr/lib/python2.6/sre_parse.pyc > # /usr/lib/python2.6/sre_constants.pyc matches > /usr/lib/python2.6/sre_constants.py > import sre_constants # precompiled from /usr/lib/python2.6/sre_constants.pyc > Traceback (most recent call last): > ?File "", line 1, in > ImportError: cannot import name rfid > # clear __builtin__._ > # clear sys.path > # clear sys.argv > > > As for the permissions, as a bit of a python novice, I wasn't sure > whether permissions on the package referred to the gnuradio folder or > to something else. ?The permissions on the gnuradio folder are > drwxr-sr-x. ?I have sort of the same problem with the rfid module, but > hopefully this gives you the info you were asking about: > > -rwxr-xr-x 1 root staff ? 1067 2010-10-14 15:27 _rfid.la > -rw-r--r-- 1 root staff ?17988 2010-10-14 15:27 rfid.py > -rw-r--r-- 1 root staff ?30771 2010-10-14 15:27 rfid.pyc > -rw-r--r-- 1 root staff ?30771 2010-10-14 15:27 rfid.pyo > -rwxr-xr-x 1 root staff 939872 2010-10-14 15:27 _rfid.so > > > Thanks again for giving this some thought. ?Let me know if you have > any other tips! I'm copying your reply back to the list. You'll get more and better responses if you keep all of the discussion on there. I don't see anything unusual going on there either. I do see that the project page for gen2_rfid is asking for a particular SVN revision of gnuradio with custom edits applied. Is that how you installed gnuradio? I'm looking at the notes in https://www.cgran.org/browser/projects/gen2_rfid/trunk/README.txt and https://www.noisebridge.net/wiki/RFID_Hacking/usrp/ -- Jerry From ethan at stoneleaf.us Tue Nov 2 17:09:33 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 02 Nov 2010 14:09:33 -0700 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccfefc6$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4CD07E0D.7020008@stoneleaf.us> Grant Edwards wrote: > On 2010-11-02, Ethan Furman wrote: >> Steven D'Aprano wrote: >>> Personally, I'm more disturbed by the default prompt in the interactive >>> interpreter. >>> clashes with the symbol used for quoting text in email >>> and news. That causes me far more distress than indentation. >> >> I finally did "sys.ps1 = '--> '" in my interactive startup file. :) > > So _now_ what are going to whinge about? ^- \ missing a word? ;) If the word is "you" -- how about complaints about the documentation? elif the word is "we" -- maybe lack of reading comprehension? elif the word is "Steven" -- absolutely no clue ;) else -- maybe multiple inheritance being a bug... http://bugs.python.org/issue2667 ~Ethan~ From gunnerasch at gmail.com Tue Nov 2 17:17:29 2010 From: gunnerasch at gmail.com (Gunner Asch) Date: Tue, 02 Nov 2010 14:17:29 -0700 Subject: *** FBI gets a warm welcome in Chicago for their EXCELLENTperformance - cheers to NEW CONS *** References: <26f97f70-9043-490c-9e6e-35159f38d76b@r29g2000yqj.googlegroups.com> <47e0b3a3-54fb-4489-95a8-b5ec6015c99d@j25g2000yqa.googlegroups.com> Message-ID: On Tue, 02 Nov 2010 22:13:40 GMT, david.bostwick at chemistry.gatech.edu (David Bostwick) wrote: >In article <47e0b3a3-54fb-4489-95a8-b5ec6015c99d at j25g2000yqa.googlegroups.com>, small Pox wrote: >[...] > >Some WD40 on your keyboard might help keep the Caps Lock key from sticking so >often. The mentally ill often use mostly caps lock key strokes to emphasize their postings as they rant and rave. Shrug Get used to it. There are a lot of those poor sick bastards out there. But...shrug..there will be far less after the Great Cull........ Gunner "Confiscating wealth from those who have earned it, inherited it, or got lucky is never going to help 'the poor.' Poverty isn't caused by some people having more money than others, just as obesity isn't caused by McDonald's serving super-sized orders of French fries Poverty, like obesity, is caused by the life choices that dictate results." - John Tucci, From bahrens at gmail.com Tue Nov 2 17:27:44 2010 From: bahrens at gmail.com (Ben Ahrens) Date: Tue, 2 Nov 2010 16:27:44 -0500 Subject: Trouble with importing In-Reply-To: References: Message-ID: I did indeed use the particular revision compiled with the addons. I discovered that if I log in as root or make myself a user with full privileges I can successfully import the rfid module, just not using sudo. Of course neither of those options are particularly good ones, but that's the only way I've gotten it to work thus far. Ben On Tue, Nov 2, 2010 at 4:01 PM, Jerry Hill wrote: > On Tue, Nov 2, 2010 at 3:33 PM, Ben Ahrens wrote: >> Jerry, thanks for the reply, I was swamped with other things for the >> better part of a week.. Anyway, I tried using the verbose flag when >> attempting the import. ?I didn't see anything that meant anything to >> me, but here's the bit surrounding the part where it fails: >> >> # /usr/lib/python2.6/dist-packages/gnuradio/__init__.pyc matches >> /usr/lib/python2.6/dist-packages/gnuradio/__init__.py >> import gnuradio # precompiled from >> /usr/lib/python2.6/dist-packages/gnuradio/__init__.pyc >> # /usr/lib/python2.6/re.pyc matches /usr/lib/python2.6/re.py >> import re # precompiled from /usr/lib/python2.6/re.pyc >> # /usr/lib/python2.6/sre_compile.pyc matches /usr/lib/python2.6/sre_compile.py >> import sre_compile # precompiled from /usr/lib/python2.6/sre_compile.pyc >> import _sre # builtin >> # /usr/lib/python2.6/sre_parse.pyc matches /usr/lib/python2.6/sre_parse.py >> import sre_parse # precompiled from /usr/lib/python2.6/sre_parse.pyc >> # /usr/lib/python2.6/sre_constants.pyc matches >> /usr/lib/python2.6/sre_constants.py >> import sre_constants # precompiled from /usr/lib/python2.6/sre_constants.pyc >> Traceback (most recent call last): >> ?File "", line 1, in >> ImportError: cannot import name rfid >> # clear __builtin__._ >> # clear sys.path >> # clear sys.argv >> >> >> As for the permissions, as a bit of a python novice, I wasn't sure >> whether permissions on the package referred to the gnuradio folder or >> to something else. ?The permissions on the gnuradio folder are >> drwxr-sr-x. ?I have sort of the same problem with the rfid module, but >> hopefully this gives you the info you were asking about: >> >> -rwxr-xr-x 1 root staff ? 1067 2010-10-14 15:27 _rfid.la >> -rw-r--r-- 1 root staff ?17988 2010-10-14 15:27 rfid.py >> -rw-r--r-- 1 root staff ?30771 2010-10-14 15:27 rfid.pyc >> -rw-r--r-- 1 root staff ?30771 2010-10-14 15:27 rfid.pyo >> -rwxr-xr-x 1 root staff 939872 2010-10-14 15:27 _rfid.so >> >> >> Thanks again for giving this some thought. ?Let me know if you have >> any other tips! > > I'm copying your reply back to the list. ?You'll get more and better > responses if you keep all of the discussion on there. > > I don't see anything unusual going on there either. ?I do see that the > project page for gen2_rfid is asking for a particular SVN revision of > gnuradio with custom edits applied. ?Is that how you installed > gnuradio? ?I'm looking at the notes in > https://www.cgran.org/browser/projects/gen2_rfid/trunk/README.txt and > https://www.noisebridge.net/wiki/RFID_Hacking/usrp/ > > -- > Jerry > From david.bostwick at chemistry.gatech.edu Tue Nov 2 18:13:40 2010 From: david.bostwick at chemistry.gatech.edu (David Bostwick) Date: Tue, 02 Nov 2010 22:13:40 GMT Subject: *** FBI gets a warm welcome in Chicago for their EXCELLENTperformance - cheers to NEW CONS *** References: <26f97f70-9043-490c-9e6e-35159f38d76b@r29g2000yqj.googlegroups.com> <47e0b3a3-54fb-4489-95a8-b5ec6015c99d@j25g2000yqa.googlegroups.com> Message-ID: In article <47e0b3a3-54fb-4489-95a8-b5ec6015c99d at j25g2000yqa.googlegroups.com>, small Pox wrote: [...] Some WD40 on your keyboard might help keep the Caps Lock key from sticking so often. From jmcmonagle at NO.SPAM.velseis.com.au Tue Nov 2 18:27:42 2010 From: jmcmonagle at NO.SPAM.velseis.com.au (John McMonagle) Date: Wed, 03 Nov 2010 08:27:42 +1000 Subject: Python documentation too difficult for beginners In-Reply-To: <4cd060c5$0$1633$742ec2ed@news.sonic.net> References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> <871v73kc9d.fsf@rudin.co.uk> <4cd060c5$0$1633$742ec2ed@news.sonic.net> Message-ID: <4CD0905E.4000600@NO.SPAM.velseis.com.au> On 03/11/10 05:04, John Nagle wrote: > Right. Google does a far better job of organizing Python's > documentation than the Python community does. I don't even try > looking up anything starting at Python.org; I always start > with a Google search. Even though Python.org's search is > powered by Google, it's inferior to a general search. > > Compare: > > http://www.google.com/search?domains=www.python.org&sitesearch=www.python.org&q=open > > > http://www.google.com/search?q=Python+open > Even better: http://www.google.com/search?sitesearch=docs.python.org&q=open Regards, John McMonagle From lightsilver3 at gmail.com Tue Nov 2 18:28:03 2010 From: lightsilver3 at gmail.com (silver light) Date: Tue, 2 Nov 2010 15:28:03 -0700 (PDT) Subject: *** FBI gets a warm welcome in Chicago for their EXCELLENT performance - cheers to NEW CONS *** References: <73cd58e5-5aae-4d90-93fa-5bd481f8da62@y23g2000yqd.googlegroups.com> Message-ID: <0367d386-3175-4e4e-8b10-d33937322292@s4g2000yql.googlegroups.com> On Nov 2, 11:03?am, t... at sevak.isi.edu (Thomas A. Russ) wrote: > silver light writes: > > *** FBI gets a warm welcome in Chicago for their EXCELLENT performance > > - cheers to NEW CONS *** > > Oh geez. ?Just when we've beaten back the infix hordes, someone comes up > and suggests replacing CONS with something, new different and most > likely inferior. > > - Grumpy Old Programmer. > > -- > Thomas A. Russ, ?USC/Information Sciences Institute Google censored my post and deleted it not because they are trying to defend the FBI or cover them up. They just dont like silverlight which is from Microsoft. It is well known that google and oracle are trying to get control of the whole cyberspace either alone or in alliance with each other. This way they can control the federal government. Most senators and congressmen are pea brain and go along with whatever the corporations show them with music, viagra, champagne, food, cruise tickets, girls and pocket money. ========== Submitted by jkeogh on Tue, 11/02/2010 - 6:44am http://911blogger.com/news/2010-10-20/foia-funds-request Litigation seeking the release of never before seen 9/11 FBI records is currently underway in the federal courts. There is a immediate need for a FOIA attorney to assist with the case. The defendants are operating with a nearly unlimited funding and have a large body of legal experts working to prevent the release of these records. A public interest FOIA attorney has offered their services at a reduced public interest rate. We need the research communities help to raise the required funds. Release of these requested records may help settle questions surrounding the Pentagon and Shanksville controversies, as well as others. Release of these records could also help overcome future claims of release exemption by the FBI for other 9/11 records requests. From lightsilver3 at gmail.com Tue Nov 2 18:30:17 2010 From: lightsilver3 at gmail.com (silver light) Date: Tue, 2 Nov 2010 15:30:17 -0700 (PDT) Subject: *** FBI gets a warm welcome in Chicago for their EXCELLENTperformance - cheers to NEW CONS *** References: <26f97f70-9043-490c-9e6e-35159f38d76b@r29g2000yqj.googlegroups.com> <47e0b3a3-54fb-4489-95a8-b5ec6015c99d@j25g2000yqa.googlegroups.com> Message-ID: On Nov 2, 1:58?pm, Rich Grise wrote: > On Tue, 02 Nov 2010 14:17:29 -0700, Gunner Asch wrote: > > > But...shrug..there will be far less after the Great Cull........ > > I think some people might be surprised as to exactly _who_ gets "culled". > > Good Luck! > Rich On Nov 2, 11:03 am, t... at sevak.isi.edu (Thomas A. Russ) wrote: > silver light writes: > > *** FBI gets a warm welcome in Chicago for their EXCELLENT performance > > - cheers to NEW CONS *** > > Oh geez. Just when we've beaten back the infix hordes, someone comes up > and suggests replacing CONS with something, new different and most > likely inferior. > > - Grumpy Old Programmer. > > -- > Thomas A. Russ, USC/Information Sciences Institute Google censored my post and deleted it not because they are trying to defend the FBI or cover them up. They just dont like silverlight which is from Microsoft. It is well known that google and oracle are trying to get control of the whole cyberspace either alone or in alliance with each other. This way they can control the federal government. Most senators and congressmen are pea brain and go along with whatever the corporations show them with music, viagra, champagne, food, cruise tickets, girls and pocket money. ========== Submitted by jkeogh on Tue, 11/02/2010 - 6:44am http://911blogger.com/news/2010-10-20/foia-funds-request Litigation seeking the release of never before seen 9/11 FBI records is currently underway in the federal courts. There is a immediate need for a FOIA attorney to assist with the case. The defendants are operating with a nearly unlimited funding and have a large body of legal experts working to prevent the release of these records. A public interest FOIA attorney has offered their services at a reduced public interest rate. We need the research communities help to raise the required funds. Release of these requested records may help settle questions surrounding the Pentagon and Shanksville controversies, as well as others. Release of these records could also help overcome future claims of release exemption by the FBI for other 9/11 records requests. From evilmrhenry at emhsoft.com Tue Nov 2 18:50:39 2010 From: evilmrhenry at emhsoft.com (evilmrhenry) Date: Tue, 02 Nov 2010 15:50:39 -0700 Subject: Multiple cookie headers and urllib2 Message-ID: <4CD095BF.9010207@emhsoft.com> Python 2.6.4 on Ubuntu. I'm not sure if this is a bug or if I'm just doing this wrong... I'm trying to include two cookies when I use urllib2 to view a page. #Code Start import urllib2 opener = urllib2.build_opener(urllib2.HTTPCookieProcessor()) opener.addheaders.append(("Cookie", "user=abcd")) opener.addheaders.append(("Cookie", "password=12345")) print opener.addheaders r = opener.open("http://emhsoft.com/docs/cookies.php") print r.readlines() #Code End http://emhsoft.com/docs/cookies.php is live, and just includes The output is [('User-agent', 'Python-urllib/2.6'), ('Cookie', 'user=abcd'), ('Cookie', 'password=12345')] ['Array\n', '(\n', ' [user] => abcd\n', ')\n', ' '] I expected both of the cookies to show up, not just one. From ldo at geek-central.gen.new_zealand Tue Nov 2 18:54:47 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 03 Nov 2010 11:54:47 +1300 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: In message , Emile van Sebille wrote: > On 11/1/2010 4:22 PM Lawrence D'Oliveiro said... > >> In message, Emile van >> Sebille wrote: >> >>> At least you can look at python code and _know_ that spurious placement >>> of required line noise don't have the ability to impact what the code >>> does. >> >> But it does. What is spurious whitespace if not noise, after all? > > But it does so by intent. Other languages lend only an appearance of > structure through the indentation style of the writer. No, the indentation is there to make the structure clearer, not to act as a substitute for the structure. Try to conflate the two, and you end up with problems such as we are discussing. > It's as good as outdated comments. Outdated comments are a bug like any other, and should be fixed. From tjreedy at udel.edu Tue Nov 2 18:55:59 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 02 Nov 2010 18:55:59 -0400 Subject: Python documentation too difficult for beginners In-Reply-To: References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> <024ef21a-9ef9-48a6-8372-1d66895583c3@v16g2000yqn.googlegroups.com> Message-ID: On 11/2/2010 2:43 PM, Tim Harig wrote: > The real question is what do you want to gain by your posts here. You > should already know that most groups are, by their very nature, slow to > make changes to the status quo. The problem tends to be exasperated in > open source projects where any changes mean that people have to donate > their time to make anything happen. You will in general find two things to > be true: > > 1. Since they are dontating their time, you will find that people tend to > scratch their own iches first. > > 2. People who do take the time to contribute to open source projects are > people of action. They don't tend to be appreciative of those who > constantly generate feature requests but have no inclination to do > any of the work themselves. They do appreciate other people of > action who are interested in making the project better. > > Therefore, if you truly want changes in the documentation, I suggest that, > rather then whining to the group, you make some of the changes yourself. I agree up to here, with a different interpretation of the last clause. Work within the existing system. There are currently 250 open doc issues on the tracker at bugs.python.org. After registering, go to the search page http://bugs.python.org/issue?@template=search&status=1 select Components: Documentation and hit Return (or [Search]) Find an issue that is waiting for someone to suggest a new or replacement sentence or paragraph, and make one. No .diff patch required, just put it in the message. Or look at existing suggestions and comment. -- Terry Jan Reedy From ldo at geek-central.gen.new_zealand Tue Nov 2 19:01:06 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 03 Nov 2010 12:01:06 +1300 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: In message , Grant Edwards wrote: > On 2010-11-01, Lawrence D'Oliveiro > wrote: > >> In message <8j8am4Fk2jU1 at mid.individual.net>, Peter Pearson wrote: >>> >>>> diff -b oldfile newfile >>> >>> Warning: "diff -b" won't detect changes in indentation. Changes in >>> indentation can change a Python program. >> >> I'm getting less and less keen on that particular feature of Python... > > Why? > > Other languages have similar problems if you remove salient bits of > syntax before comparing two source files files. But other languages don?t make those ?salient bits of syntax? invisible. I.e. they are actually ?salient?. From nizumzen at mcnuggets.com Tue Nov 2 19:05:03 2010 From: nizumzen at mcnuggets.com (Nizumzen) Date: Tue, 2 Nov 2010 23:05:03 +0000 Subject: Python documentation too difficult for beginners References: Message-ID: <2010110223050345181-nizumzen@mcnuggetscom> On 2010-11-02 10:42:22 +0000, jk said: > Hi, > > I've been coding in PHP and Java for years, and their documentation is > concise, well structured and easy to scan. Are you mad? Javadoc is one of the worst examples of source code documentation I can possibly imagine. I would go as far to say that the Python guys should do exactly the opposite of Javadoc. From ldo at geek-central.gen.new_zealand Tue Nov 2 19:06:30 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 03 Nov 2010 12:06:30 +1300 Subject: Python documentation too difficult for beginners References: Message-ID: In message , jk wrote: > This (http://epydoc.sourceforge.net/stdlib/) is what I'm talking > about. Framesets? Is that really your idea of well-laid-out documentation? Using a feature which has been derided (and dropped in HTML5) because of its effect on usability and accessibility? From ldo at geek-central.gen.new_zealand Tue Nov 2 19:11:52 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 03 Nov 2010 12:11:52 +1300 Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> Message-ID: In message , Roy Smith wrote: > In this case, I think I would do: > > styles = [("normal", "image", MainWindow.ColorsNormalList), > ("highlighted", "highlight", MainWindow.ColorsHighlightedList), > ("selected", "select", MainWindow.ColorsSelectedList)] > > for in description, attr, color_list in styles: > blah, blah, blah And so you have managed to separate one set of looping conditions into two parts. What is the significance of the name ?styles?? None at all. What purpose does it serve? None, really. Does it ease the maintenance burden? No, but by splitting your attention across two places, it actually adds to it. Here?s another example for you to chew on: for \ name, reg, doindir \ in \ ( ("R0", 0, True), ("R1", 1, True), ("R2", 2, True), ("R3", 3, True), ("R4", 4, True), ("R5", 5, True), ("R6", 6, True), ("SP", 6, True), ("R7", 7, False), ("PC", 7, False), ) \ : ... #end for From mike.terrell at earthlink.net Tue Nov 2 19:16:27 2010 From: mike.terrell at earthlink.net (Michael A. Terrell) Date: Tue, 02 Nov 2010 19:16:27 -0400 Subject: *** FBI gets a warm welcome in Chicago for their EXCELLENTperformance - cheers to NEW CONS *** References: <26f97f70-9043-490c-9e6e-35159f38d76b@r29g2000yqj.googlegroups.com> <47e0b3a3-54fb-4489-95a8-b5ec6015c99d@j25g2000yqa.googlegroups.com> Message-ID: Gunner Asch wrote: > > On Tue, 02 Nov 2010 22:13:40 GMT, david.bostwick at chemistry.gatech.edu > (David Bostwick) wrote: > > ?In article ?47e0b3a3-54fb-4489-95a8-b5ec6015c99d at j25g2000yqa.googlegroups.com?, small Pox ?smallpox911 at gmail.com? wrote: > ?[...] > ? > ?Some WD40 on your keyboard might help keep the Caps Lock key from sticking so > ?often. > > The mentally ill often use mostly caps lock key strokes to emphasize > their postings as they rant and rave. > > Shrug > > Get used to it. > > There are a lot of those poor sick bastards out there. > > But...shrug..there will be far less after the Great Cull........ Concertina neckties. They won't dare move. -- Politicians should only get paid if the budget is balanced, and there is enough left over to pay them. From anton.list at gmail.com Tue Nov 2 19:32:39 2010 From: anton.list at gmail.com (AD.) Date: Tue, 2 Nov 2010 16:32:39 -0700 (PDT) Subject: Python documentation too difficult for beginners References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> <024ef21a-9ef9-48a6-8372-1d66895583c3@v16g2000yqn.googlegroups.com> Message-ID: <4716193c-2e9f-4469-b8c7-bba600fba8a2@p1g2000yqm.googlegroups.com> On Nov 3, 7:43?am, Tim Harig wrote: > On 2010-11-02, jk wrote: > > > As for the 9 paragraphs statement, there's a usability book that > > applies here - it's called "Don't make me think". I shouldn't have to > > Anything that promotes a lack of thinking sends up red flags in my head. > We want to recruit smart people who think, not idiots. "Don't make me think" is the UI equivalent of "There should be one and preferably only one obvious way to do it". Not about advocating no thinking, but about reducing the amount of unimportant decisions you require your users to make. But I don't think the book specifically addresses Dutch users though. Back on topic - I do like the Python docs overall. Especially compared to the PHP docs. I like the overall look and format of the new Sphinx generated ones too. My only criticism is that the content can sometimes be a little too terse/concise. It's fine for experienced developers, but in some places a little more explanation and/or examples would help out the less experienced. I can usually figure out how to do something eventually, but the docs for some modules take more deciphering than others. -- Cheers Anton From invalid at invalid.invalid Tue Nov 2 19:36:46 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 2 Nov 2010 23:36:46 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: On 2010-11-02, Lawrence D'Oliveiro wrote: > In message , Grant Edwards wrote: > >> On 2010-11-01, Lawrence D'Oliveiro >> wrote: >> >>> In message <8j8am4Fk2jU1 at mid.individual.net>, Peter Pearson wrote: >>>> >>>>> diff -b oldfile newfile >>>> >>>> Warning: "diff -b" won't detect changes in indentation. Changes in >>>> indentation can change a Python program. >>> >>> I'm getting less and less keen on that particular feature of Python... >> >> Why? >> >> Other languages have similar problems if you remove salient bits of >> syntax before comparing two source files files. > > But other languages don???t make those ???salient bits of syntax??? > invisible. Huh? Indentation is invisible? You can't see the indentation in Python source code? I'm baffled... -- Grant From prologic at shortcircuit.net.au Tue Nov 2 19:38:58 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 3 Nov 2010 09:38:58 +1000 Subject: Python documentation too difficult for beginners In-Reply-To: <2010110223050345181-nizumzen@mcnuggetscom> References: <2010110223050345181-nizumzen@mcnuggetscom> Message-ID: On Wed, Nov 3, 2010 at 9:05 AM, Nizumzen wrote: > Are you mad? Javadoc is one of the worst examples of source code > documentation I can possibly imagine. I would go as far to say that the > Python guys should do exactly the opposite of Javadoc. For what it's worth, I concur. cheers James -- -- James Mills -- -- "Problems are solved by method" From roy at panix.com Tue Nov 2 20:17:06 2010 From: roy at panix.com (Roy Smith) Date: Tue, 02 Nov 2010 20:17:06 -0400 Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> Message-ID: In article , Lawrence D'Oliveiro wrote: > In message , Roy Smith wrote: > > > In this case, I think I would do: > > > > styles = [("normal", "image", MainWindow.ColorsNormalList), > > ("highlighted", "highlight", MainWindow.ColorsHighlightedList), > > ("selected", "select", MainWindow.ColorsSelectedList)] > > > > for in description, attr, color_list in styles: > > blah, blah, blah > > And so you have managed to separate one set of looping conditions into two > parts. What is the significance of the name ???styles???? None at all. What > purpose does it serve? None, really. Does it ease the maintenance burden? > No, but by splitting your attention across two places, it actually adds to > it. I suppose readability is in the eye of the reader, but, yes, I agree that I have split this into two parts. The parts are 1) The table of data 2) The looping construct Where we seem to disagree is whether that makes things more or less readable :-) To me, it makes is more readable because it lets me understand one chunk, then move on to understanding the next chunk. You may disagree. That's OK. From usernet at ilthio.net Tue Nov 2 20:41:46 2010 From: usernet at ilthio.net (Tim Harig) Date: Wed, 3 Nov 2010 00:41:46 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: On 2010-11-02, D'Arcy J.M. Cain wrote: > "Redundant" is right. However, there is a use for such comments: > > if foo: > bar > else: > baz > if snafu: > cookie > #endif snafu > quux > #endif foo Actually, I have found similar markers to be useful everywhere. I don't like the way my editor tries to fold Python code, so I started inserting folding markers myself: # foo {{{ if foo: bar else: baz # snafu {{{ if snafu: cookie # }}} quux # }}} If the bar, baz, and quux blocks are large enough logical units, I will fold them as well. What I found is that the makers become an incredibly useful form of organzational tool. From kee at kagi.com Tue Nov 2 20:43:24 2010 From: kee at kagi.com (Kee Nethery) Date: Tue, 2 Nov 2010 17:43:24 -0700 Subject: Python documentation too difficult for beginners In-Reply-To: References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> <024ef21a-9ef9-48a6-8372-1d66895583c3@v16g2000yqn.googlegroups.com> Message-ID: > >> >> Therefore, if you truly want changes in the documentation, I suggest that, >> rather then whining to the group, you make some of the changes yourself. > > I agree up to here, with a different interpretation of the last clause. > Work within the existing system. There are currently 250 open doc issues on the tracker at bugs.python.org. wow, a backlog of 250. Either 250 is the weekly submittal amount and they get dealt with within a week, OR the backlog is months old and the bug system is not an effective way to get changes or enhancements to the documentation. Either way, 250 open doc issues gives me the feeling that the existing documentation system is not working for the people trying to use it. > After registering, go to the search page > http://bugs.python.org/issue?@template=search&status=1 > select Components: Documentation and hit Return (or [Search]) > > Find an issue that is waiting for someone to suggest a new or replacement sentence or paragraph, and make one. No .diff patch required, just put it in the message. Or look at existing suggestions and comment. Given that newbies are the ones who run into these issues and have a great desire to spare others the pain they have suffered trying to learn Python, and newbies typically do not know about the bug tracking system as the way to request enhancements to the docs (that's not how wikipedia and other sites do changes to information), perhaps it would be useful to put a link to a page that explains how to improve the docs, on each doc page? I have to agree with others. My preferred Python documentation is either the books I have, or a search on Google. A google search typically has several postings from people on non-official sites with the exact same confusion I have, and what they have tried and what ultimately worked. The suggestion was made that people create their own documentation if they don't like the official documentation, and that does seem to be a good source for python documentation. Kee Nethery From ben+python at benfinney.id.au Tue Nov 2 20:46:01 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 03 Nov 2010 11:46:01 +1100 Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> Message-ID: <87aalrjkty.fsf@benfinney.id.au> Roy Smith writes: > In article , > Lawrence D'Oliveiro wrote: > > > In message , Roy Smith wrote: > > > > > In this case, I think I would do: > > > > > > styles = [("normal", "image", MainWindow.ColorsNormalList), > > > ("highlighted", "highlight", MainWindow.ColorsHighlightedList), > > > ("selected", "select", MainWindow.ColorsSelectedList)] > > > > > > for in description, attr, color_list in styles: > > > blah, blah, blah I would do the same, but fix the indentation. Making indentation depend on the *length* of the previous line is needlessly making a maintenance burden. Instead, I'd do:: styles = [ ("normal", "image", MainWindow.ColorsNormalList), ("highlighted", "highlight", MainWindow.ColorsHighlightedList), ("selected", "select", MainWindow.ColorsSelectedList)] for in description, attr, color_list in styles: # blah, blah, blah A single consistent level of indentation on continuation lines, no matter what happens to the first line. > Where we seem to disagree is whether that makes things more or less > readable :-) To me, it makes is more readable because it lets me > understand one chunk, then move on to understanding the next chunk. Agreed. > You may disagree. That's OK. It's okay until that code gets out in the wild; then it's no longer just a matter of one person's taste. Hence the need for conventions. -- \ ?Anyone who puts a small gloss on [a] fundamental technology, | `\ calls it proprietary, and then tries to keep others from | _o__) building on it, is a thief.? ?Tim O'Reilly, 2000-01-25 | Ben Finney From ian.g.kelly at gmail.com Tue Nov 2 20:52:13 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 2 Nov 2010 18:52:13 -0600 Subject: Multiple cookie headers and urllib2 In-Reply-To: <4CD095BF.9010207@emhsoft.com> References: <4CD095BF.9010207@emhsoft.com> Message-ID: On Tue, Nov 2, 2010 at 4:50 PM, evilmrhenry wrote: > Python 2.6.4 on Ubuntu. I'm not sure if this is a bug or if I'm just doing > this wrong... > > I'm trying to include two cookies when I use urllib2 to view a page. > #Code Start > import urllib2 > > opener = urllib2.build_opener(urllib2.HTTPCookieProcessor()) > opener.addheaders.append(("Cookie", "user=abcd")) > opener.addheaders.append(("Cookie", "password=12345")) > print opener.addheaders > r = opener.open("http://emhsoft.com/docs/cookies.php") > print r.readlines() > #Code End > > http://emhsoft.com/docs/cookies.php is live, and just includes > > The output is > [('User-agent', 'Python-urllib/2.6'), ('Cookie', 'user=abcd'), ('Cookie', > 'password=12345')] > ['Array\n', '(\n', ' [user] => abcd\n', ')\n', ' '] > > I expected both of the cookies to show up, not just one. > It is expected that all the cookies are contained within a single header, e.g.: opener.addheaders.append(("Cookie", "user=abcd; password=12345")) You probably shouldn't be manually adding Cookie headers if you're using HTTPCookieProcessor; they will tend to clobber each other. You could add the cookies to the cookie jar object directly, although it's not really designed for that use case. Better to just let the web app set the cookies -- if you want to log in programmatically, pass the username and password in the POST data, and then the web app can set whatever cookies it wants to remember the session. And in case you aren't aware, storing the user's password in a cookie is generally considered bad form as it poses a greater security risk than storing an opaque session token. That way the password need only be sent across the wire once and cannot be discovered by inspecting the user's browser cache. Cheers, Ian -------------- next part -------------- An HTML attachment was scrubbed... URL: From evilmrhenry at emhsoft.com Tue Nov 2 21:12:20 2010 From: evilmrhenry at emhsoft.com (evilmrhenry) Date: Tue, 02 Nov 2010 18:12:20 -0700 Subject: Multiple cookie headers and urllib2 In-Reply-To: References: <4CD095BF.9010207@emhsoft.com> Message-ID: <4CD0B6F4.20708@emhsoft.com> Ian Kelly wrote: > > > On Tue, Nov 2, 2010 at 4:50 PM, evilmrhenry > wrote: > > Python 2.6.4 on Ubuntu. I'm not sure if this is a bug or if I'm just > doing this wrong... > > I'm trying to include two cookies when I use urllib2 to view a page. > #Code Start > import urllib2 > > opener = urllib2.build_opener(urllib2.HTTPCookieProcessor()) > opener.addheaders.append(("Cookie", "user=abcd")) > opener.addheaders.append(("Cookie", "password=12345")) > print opener.addheaders > r = opener.open("http://emhsoft.com/docs/cookies.php") > print r.readlines() > #Code End > > http://emhsoft.com/docs/cookies.php is live, and just includes > > The output is > [('User-agent', 'Python-urllib/2.6'), ('Cookie', 'user=abcd'), > ('Cookie', 'password=12345')] > ['Array\n', '(\n', ' [user] => abcd\n', ')\n', ' '] > > I expected both of the cookies to show up, not just one. > > > It is expected that all the cookies are contained within a single > header, e.g.: > > opener.addheaders.append(("Cookie", "user=abcd; password=12345")) > > You probably shouldn't be manually adding Cookie headers if you're using > HTTPCookieProcessor; they will tend to clobber each other. You could > add the cookies to the cookie jar object directly, although it's not > really designed for that use case. Better to just let the web app set > the cookies -- if you want to log in programmatically, pass the username > and password in the POST data, and then the web app can set whatever > cookies it wants to remember the session. > > And in case you aren't aware, storing the user's password in a cookie is > generally considered bad form as it poses a greater security risk than > storing an opaque session token. That way the password need only be > sent across the wire once and cannot be discovered by inspecting the > user's browser cache. > > Cheers, > Ian Yes, this works. Thank you. (I am aware of the cookie jar, and would normally use it. It just wouldn't work well in this case. Also, the user/pass was just an example, and *not* how I was going to do this.) From usenet-nospam at seebs.net Tue Nov 2 21:20:16 2010 From: usenet-nospam at seebs.net (Seebs) Date: 03 Nov 2010 01:20:16 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: On 2010-11-02, D'Arcy J.M. Cain wrote: > "Large" is no excuse for incompetency. It is in practice. > So configure it to recognize Python files and act accordingly. So far as I know, it doesn't have a feature to do this. In any event, I work around it okay. >> No, they aren't. See... That would work *if I knew for sure what the intent >> was*. >> >> if foo: >> bar >> else: >> baz >> quux >> >> Does it look right? We have *no idea*, because we don't actually know >> whether quux was *intended* to be in the else branch or whether that's a typo. > And C has the same problem. Not quite! > if (foo) > bar; > else > baz; > > quux; > Is quux meant to be part of the else clause? The writer's indentation > suggests "yes" but the code says "no". Right. And that's the thing: In C, I know there's something wrong here. I may not know what it is, but I know *something* is wrong. > Same is true for the C code. Pretty much! > In both cases you can tell what the code > will do (modulo weird macros in the C code) but the intention is > impossible to determine without mind reading abilities in both cases. > We do know that the Python code *appears* to be doing exactly what the > author intended and the C code *appears* to not be. Yes. And in my experience, that means that since the code must be wrong (or I wouldn't be looking at it), it's very nice that in one of them, I've just been told for sure that the writer was confused right here at this line. In the other, I have no way of knowing that the writer was confused. What was it someone once said? "Explicit is better than implicit." I *like* my parity bits. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Tue Nov 2 21:20:40 2010 From: usenet-nospam at seebs.net (Seebs) Date: 03 Nov 2010 01:20:40 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: On 2010-11-02, Emile van Sebille wrote: > What is right is that there's no question that quux is subsequent to baz > in all cases barring exceptions (and assuming no tabs intermixed) Yes, but that doesn't mean it does what the programmer intended, just that it does what it does. > The apparent structure in python _is_ the structure, whereas otherwise > you've got to count your ;'s and {}'s etc to determine and verify the > structure matches the apparent structure provided by the programmer. Yes. I understand this. However, I have probably seen all of two or three bugs ever related to mis-indented C, and I've had various things screw up or wreck indentation on dozens of occasions. Being able to recover has been nice. (So's being able to use fence matching to jump to the other end of a block.) -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Tue Nov 2 21:25:56 2010 From: usenet-nospam at seebs.net (Seebs) Date: 03 Nov 2010 01:25:56 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-02, Tim Harig wrote: > This is Python's most noticable blemish outside of the community. > Everybody knows that Python is the language that forces you to use a > particular style of formatting; and, that is a turn-off for many people. Honestly, I could probably live with that; the killer is the impossibility of recovering from white space damage. I have had many things happen to code over the years which required someone to run them through indent/cb. > It is a big mistake that whenever the issue arises, the community > effectively attacks anybody who might have disagreements with the tradeoffs > made for the Python language. This tends to set people on the defensive > and gives them a bad taste about the language as a whole. Yes. It does not create an impression that this is an engineering tradeoff which has been considered and understood; it creates the impression that people are defensive enough about it that they're not able to confidently acknowledge the shortcomings while maintaining that the tradeoff is worth it. I like C. If you tell me that C's macro processor sucks, I will agree with you. I don't have to make excuses or pretend that there's no downsides; I can justify my preference for the language even *granting* those downsides (and downsides aplenty are to be found). > It would be much better if the community would simply acknowledge that > this is a tradeoff the the language has made and one which is often > misunderstood by many first time Python programmers. Then it is possible > transition to Python's strengths. Don't simply ignore that there *are* > potential downfalls to this approach. Amen. I am fine with this tradeoff. It's not what I would have picked, but hey, I'm not Dutch. What I'm not fine with is people telling me that it's not a tradeoff and that all the problems are my fault. If someone designed a protocol where a particular kind of file was required to be sent via email, as plain text, with many lines starting "From ", and the protocol died horribly whenever it encountered ">From " at the beginning of a line, no amount of pointing out that the mail servers in question were wrong would make it a good design for a protocol. Whitespace damage is, indeed, wrong. It's a bad thing. It is an *extremely common* bad thing, and I fundamentally don't think it was a good choice to build a system with no redundancy against it. That "redundant" information saves our hides on a regular basis in an imperfect world. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Tue Nov 2 21:27:35 2010 From: usenet-nospam at seebs.net (Seebs) Date: 03 Nov 2010 01:27:35 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: On 2010-11-02, Grant Edwards wrote: > Huh? Indentation is invisible? You can't see the indentation in > Python source code? The difference between tabs and spaces is invisible on a great number of the devices on which people display code. Indentation is visible, but the underlying structure of it may not be. (It's worse than that, because for instance " " is quite hard to distinguish from the quite similar " ".) And at least one of them is clearly wrong. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From darcy at druid.net Tue Nov 2 21:29:02 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 2 Nov 2010 21:29:02 -0400 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: <20101102212902.001ce7d0.darcy@druid.net> On Wed, 3 Nov 2010 00:41:46 +0000 (UTC) Tim Harig wrote: > On 2010-11-02, D'Arcy J.M. Cain wrote: > Actually, I have found similar markers to be useful everywhere. I don't > like the way my editor tries to fold Python code, so I started inserting > folding markers myself: > > # foo {{{ > if foo: Now that is redundant. We know it's "foo" at the top of the block. Identifying the end of the block has some value. And the braces just make the code noisy. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From darcy at druid.net Tue Nov 2 21:35:44 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 2 Nov 2010 21:35:44 -0400 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: <20101102213544.f22111bb.darcy@druid.net> On 03 Nov 2010 01:20:40 GMT Seebs wrote: > However, I have probably seen all of two or three bugs ever related to > mis-indented C, and I've had various things screw up or wreck indentation Really? I have never seen bugs in C related to indentation. I have seen plenty related to braces. What I have seen is bugs hidden by the indentation not matching the block structure. Wrong indentation in Python *is* a bug. There's no other visual signal to hide the error. > on dozens of occasions. Being able to recover has been nice. (So's being > able to use fence matching to jump to the other end of a block.) But I can see the other end of the block in Python. I don't need any tricks to make sure that it is the end. And if your block is too big to see the structure easily then that just means that some code should be factored out to a method. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From lanyjie at yahoo.com Tue Nov 2 21:41:55 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Tue, 2 Nov 2010 18:41:55 -0700 (PDT) Subject: Must be a bug in the re module [was: Why this result with the re module] In-Reply-To: <4CD037D7.7070408@asd-group.com> Message-ID: <259282.72742.qm@web54208.mail.re2.yahoo.com> > From: John Bond > Subject: Re: Why this result with the re module > To: "Yingjie Lan" > Cc: python-list at python.org > Date: Tuesday, November 2, 2010, 8:09 PM > On 2/11/2010 12:19 PM, Yingjie Lan > wrote: > >> From: John Bond > >> Subject: Re: Why this result with the re module > > Firstly, thanks a lot for your patient explanation. > > this time I have understood all your points > perfectly. > > > > Secondly, I'd like to clarify some of my points, > which > > did not get through because of my poor presentation. > > > > I suggested findall return a tuple of > re.MatchObject(s), > > with each MatchObject instance representing a match. > > This is consistent with the re.match() function > anyway. > > And it will eliminate the need of returning tuples, > > and it is much more precise and information rich. > > > > If that's not possible, and a tuple must be returned, > > then the whole match (not just subgroups) should > > always be included as the first element in the tuple, > > as that's group(0) or '\0'. Less surprise would > arise. > > > > Finally, it seems to me the algo for findall is > WRONG. > > > > To re.findall('(.a.)*', 'Mary has a lamb'), > > by reason of greediness of '*', and the requirement > > of non-overlapping, it should go like this > > (suppose an '' is at the beginning and at the end, > > and between two consecutive characters there is > > one and only one empty string ''. To show the > > match of empty strings clearly, > > I am concatenating each repeated match below): > > > > Steps for re.findall('(.a.)*', 'Mary has a lamb'): > > > > step 1: Match '' + 'Mar' + '' (gready!) > > step 2: skip 'y' > > step 3: Match '' > > step 4: skip ' ' > > step 5: Match ''+'has'+' a '+'lam'+'' (greedy!) > > step 6: skip 'b' > > step 7: Match '' > > > > So there should be exactly 4 matches in total: > > > > 'Mar', '', 'has a lam', '' > > > > Also, the matches above shows > > that if a repeated subgroup only captures > > the last match, the subgroup (.a.)* > > should always capture '' here (see steps > > 1, 3, 5, 7) above. > > > > Yet the execution in Python results in 6 matches! > > And, the capturing subgroup with repetition > > sometimes got the wrong guy. > > > > So I believe the algorithm for findall must be WRONG. > > > > Regards, > > > > Yingjie > At a guess, I'd say what is happening is something like > this: > > Steps for re.findall('(.a.)*', 'Mary has a lamb'): > > step 1: Match 'Mar' at string index 0 > step 2: Match '' at string index 3 (before 'y') > step 3: skip 'y' > step 4: Match '' at string index 4 (before ' ') > step 5: skip ' ' > step 6: Match 'has a lam' at string index 5 > step 7: Match '' at string index 14 (before 'b') > step 8: skip 'b' > step 9: Match '' at string index 15 (before EOS) > > > > matches: ('Mar', '', '', 'has a lam', '', '') > returns: ['Mar', '', '', 'lam', '', ''] (*) > > (*) "has a " lost due to not being last repetition at that > match point > > Which seems about right to me! Greediness has nothing to do > with it, except that it causes 'has a lam' to be matched in > one match, instead of as three separate matches (of 'has', ' > a ' and 'lam'). Disagree in this case, where the whole regex matches an empty string. Greadiness will match as much as possible. So it will also match the empty strings between consecutive characters as much as possible, once we have properly defined all the unique empty strings. Because of greadiness, fewer matches should be found. In this case, it should find only 4 matches (shown in my steps) instead of 6 matches (shown in your steps). Yingjie From gnarlodious at gmail.com Tue Nov 2 21:48:37 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Tue, 2 Nov 2010 18:48:37 -0700 (PDT) Subject: Py3: Import relative path module References: <044f2fb7-a6a9-4bb9-b2a6-8ee1d0c19612@u17g2000yqi.googlegroups.com> <4cce7768$0$29965$c3e8da3$5496439d@news.astraweb.com> <770dd3de-25f5-404c-a05a-7bdd2eb07179@26g2000yqv.googlegroups.com> Message-ID: <3e7dbd88-4d44-43fa-a0e2-6987c025ccdb@26g2000yqv.googlegroups.com> I admit I don't understand any of what was said here. Or why it is so hard what I am trying to do. I searched Google for a few hours looking for a way to import a module from an absolute path, but that was a waste of time too. To reiterate, I am trying to import a Def function from a file one level up. Let's say relative import is unreasonable to expect from Python. If it is possible using an absolute path, please let me know how, in plain language. Otherwise I can continue to copy and paste my programming into several files. Thank you for any help. -- Gnarlie From usernet at ilthio.net Tue Nov 2 22:20:49 2010 From: usernet at ilthio.net (Tim Harig) Date: Wed, 3 Nov 2010 02:20:49 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: On 2010-11-03, D'Arcy J.M. Cain wrote: > On Wed, 3 Nov 2010 00:41:46 +0000 (UTC) > Tim Harig wrote: >> On 2010-11-02, D'Arcy J.M. Cain wrote: >> Actually, I have found similar markers to be useful everywhere. I don't >> like the way my editor tries to fold Python code, so I started inserting >> folding markers myself: >> >> # foo {{{ >> if foo: > > Now that is redundant. We know it's "foo" at the top of the block. In practice the comment would explain why and how the conditional is being used just like any other comment. Since your example as abstract, I didn't have anything useful to say about it as I would for real code. When the code is folded, I will see nothing but the comments. It is often helpful to look at a section of code with all of the code blocks folded to gain a high level understanding of the code before zeroing in on the specific section that I wish to edit. When I do edit a section, I unfold no more code blocks then necessary. If I have to unfold too many blocks to to edit a single section of code, then it is a powerful indication that either the code block is not properly self contained or that the comments of the surrounding code blocks are insufficient to convey information about their code block. > Identifying the end of the block has some value. And the braces just > make the code noisy. With good syntax highlighting, you don't notice them unless you are looking for something because the markers are in comments and the markers for a block are only visible when the block is unfolded. As a benefit, they allow the folding stucture to provide expression of the code structure that cannot be expressed in the code itself. I often group blocks together that would not otherwise be indented or otherwise expressed together as they were in your example. # top level group {{{ # part 1 {{{ code # }}} # part 2 {{{ code # }}} # part 3 {{{ code # }}} # }}} Folded in my editor, it looks like this: 44 +--- 15 lines: # top level group ------------------------------------------- Unfolding the top level group, it looks like this: 44 # top level group {{{ 45 46 +---- 3 lines: # part 1 --------------------------------------------------- 49 50 +---- 3 lines: # part 2 --------------------------------------------------- 53 54 +---- 3 lines: # part 3 --------------------------------------------------- 57 58 # }}} It is therefore clear that all three of the parts are logically connected. I can keep them all folded and view them as a group or a can look into the group and edit just the relevant section of the group: 44 # top level group {{{ 45 46 +---- 3 lines: # part 1 --------------------------------------------------- 49 50 # part 2 {{{ 51 code 52 # }}} 53 54 +---- 3 lines: # part 3 --------------------------------------------------- 57 58 # }}} I have effectively added a meta structure to the blocks inside of the fuction at a finer grain then is supported by the syntax itself. Should I decide later that the top level group is becoming autonomous enough to warrant moving to a separate function, I can simply grab the entire folded block as an entity and move it to its own function body. From python at mrabarnett.plus.com Tue Nov 2 22:29:30 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 03 Nov 2010 02:29:30 +0000 Subject: Py3: Import relative path module In-Reply-To: <3e7dbd88-4d44-43fa-a0e2-6987c025ccdb@26g2000yqv.googlegroups.com> References: <044f2fb7-a6a9-4bb9-b2a6-8ee1d0c19612@u17g2000yqi.googlegroups.com> <4cce7768$0$29965$c3e8da3$5496439d@news.astraweb.com> <770dd3de-25f5-404c-a05a-7bdd2eb07179@26g2000yqv.googlegroups.com> <3e7dbd88-4d44-43fa-a0e2-6987c025ccdb@26g2000yqv.googlegroups.com> Message-ID: <4CD0C90A.7030307@mrabarnett.plus.com> On 03/11/2010 01:48, Gnarlodious wrote: > I admit I don't understand any of what was said here. Or why it is so > hard what I am trying to do. I searched Google for a few hours looking > for a way to import a module from an absolute path, but that was a > waste of time too. > > To reiterate, I am trying to import a Def function from a file one > level up. Let's say relative import is unreasonable to expect from > Python. If it is possible using an absolute path, please let me know > how, in plain language. Otherwise I can continue to copy and paste my > programming into several files. > > Thank you for any help. > After some experimentation (and Googling!) I think the problem is that a module can do your relative import but a main script can't. Or, to put it another way, if __name__ is "__main__" then it won't work. From pub at melv.org Tue Nov 2 22:30:36 2010 From: pub at melv.org (Chris Melville) Date: Wed, 03 Nov 2010 02:30:36 +0000 Subject: Must be a bug in the re module [was: Why this result with the re module] In-Reply-To: <259282.72742.qm@web54208.mail.re2.yahoo.com> References: <259282.72742.qm@web54208.mail.re2.yahoo.com> Message-ID: <4CD0C94C.30701@melv.org> > Disagree in this case, where the whole regex > matches an empty string. Greadiness will match > as much as possible. So it will also match > the empty strings between consecutive > characters as much as possible, once > we have properly defined all the unique > empty strings. Because of greadiness, > fewer matches should be found. In this > case, it should find only 4 matches > (shown in my steps) instead of 6 matches > (shown in your steps). > > Yingjie > I'm sorry but I really don't understand where your coming from. Your regex says "Zero or more consecutive occurrences of something, always returning the most possible". That's what it does, at every position - only matching emptyness where it couldn't match anything (findall then skips a character to avoid overlapping/infinite empty matches), and at all other times matching the most possible (eg. "has a lam" not "has", " a ", "lam"). Perhaps someone else can look at this and comment on whether findall is doing what it is supposed to, or not. To me, it is. Cheers, JB From usernet at ilthio.net Tue Nov 2 22:34:43 2010 From: usernet at ilthio.net (Tim Harig) Date: Wed, 3 Nov 2010 02:34:43 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: On 2010-11-03, Tim Harig wrote: > On 2010-11-03, D'Arcy J.M. Cain wrote: >> On Wed, 3 Nov 2010 00:41:46 +0000 (UTC) >> Tim Harig wrote: >> Identifying the end of the block has some value. And the braces just >> make the code noisy. > > With good syntax highlighting, you don't notice them unless you are looking > for something because the markers are in comments and the markers for > a block are only visible when the block is unfolded. As a benefit, they allow the folding > stucture to provide expression of the code structure that cannot be > expressed in the code itself. Also note that you can use whatever you like for the folding markers if the braces intimidate you. {{{ just happens to be the most recognized standard. The Erlang crowd like to use ## for this sort of thing. From usenet-nospam at seebs.net Tue Nov 2 22:40:11 2010 From: usenet-nospam at seebs.net (Seebs) Date: 03 Nov 2010 02:40:11 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: On 2010-11-03, D'Arcy J.M. Cain wrote: > On 03 Nov 2010 01:20:40 GMT > Seebs wrote: >> However, I have probably seen all of two or three bugs ever related to >> mis-indented C, and I've had various things screw up or wreck indentation > Really? I have never seen bugs in C related to indentation. I have > seen plenty related to braces. What I have seen is bugs hidden by the > indentation not matching the block structure. Right. That's *related to* indentation -- it wouldn't be there (we hope) had the indentation been right. > Wrong indentation in > Python *is* a bug. There's no other visual signal to hide the error. Sure, but there's also no way for you to spot that something looks suspicious. In Python, if something is misindented, it does what you told it to do, and there's no way for you to tell, by looking at it, that it isn't what was intended. In C, if something is misindented, it does what you told it to do, but it's obvious looking at the code that something went wrong. > But I can see the other end of the block in Python. I don't need any > tricks to make sure that it is the end. And if your block is too big > to see the structure easily then that just means that some code should > be factored out to a method. This level of dogmatism about what should always be the case is not conducive to good software engineering practices. It is not obvious to me that it's *always* the case. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Tue Nov 2 22:41:31 2010 From: usenet-nospam at seebs.net (Seebs) Date: 03 Nov 2010 02:41:31 GMT Subject: Trouble with importing References: Message-ID: On 2010-11-02, Ben Ahrens wrote: > I did indeed continue to top-post, and you should plonk me. Edited for accuracy. Done. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From ldo at geek-central.gen.new_zealand Tue Nov 2 22:45:02 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 03 Nov 2010 15:45:02 +1300 Subject: Python documentation too difficult for beginners References: <2010110223050345181-nizumzen@mcnuggetscom> Message-ID: In message <2010110223050345181-nizumzen at mcnuggetscom>, Nizumzen wrote: > On 2010-11-02 10:42:22 +0000, jk said: > >> I've been coding in PHP and Java for years, and their documentation is >> concise, well structured and easy to scan. > > Are you mad? Javadoc is one of the worst examples of source code > documentation I can possibly imagine. It appeals to corporate herds of code-cutter drones, though. It follows tedious rules that can be officially adopted as corporation policy, and cited as a conformance feature by third-party products that these corporations seem happy to spend money on. So the comments can be extracted from the code, sorted, collated, stamped, filed, indexed, and collated again, all as part of the make-work activity that seems to pass for actual productivity in so many big corporations. From python at mrabarnett.plus.com Tue Nov 2 23:01:17 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 03 Nov 2010 03:01:17 +0000 Subject: Must be a bug in the re module [was: Why this result with the re module] In-Reply-To: <259282.72742.qm@web54208.mail.re2.yahoo.com> References: <259282.72742.qm@web54208.mail.re2.yahoo.com> Message-ID: <4CD0D07D.5030903@mrabarnett.plus.com> On 03/11/2010 01:41, Yingjie Lan wrote: >> From: John Bond >> Subject: Re: Why this result with the re module >> To: "Yingjie Lan" >> Cc: python-list at python.org >> Date: Tuesday, November 2, 2010, 8:09 PM >> On 2/11/2010 12:19 PM, Yingjie Lan >> wrote: >>>> From: John Bond >>>> Subject: Re: Why this result with the re module >>> Firstly, thanks a lot for your patient explanation. >>> this time I have understood all your points >> perfectly. >>> >>> Secondly, I'd like to clarify some of my points, >> which >>> did not get through because of my poor presentation. >>> >>> I suggested findall return a tuple of >> re.MatchObject(s), >>> with each MatchObject instance representing a match. >>> This is consistent with the re.match() function >> anyway. >>> And it will eliminate the need of returning tuples, >>> and it is much more precise and information rich. >>> >>> If that's not possible, and a tuple must be returned, >>> then the whole match (not just subgroups) should >>> always be included as the first element in the tuple, >>> as that's group(0) or '\0'. Less surprise would >> arise. >>> >>> Finally, it seems to me the algo for findall is >> WRONG. >>> >>> To re.findall('(.a.)*', 'Mary has a lamb'), >>> by reason of greediness of '*', and the requirement >>> of non-overlapping, it should go like this >>> (suppose an '' is at the beginning and at the end, >>> and between two consecutive characters there is >>> one and only one empty string ''. To show the >>> match of empty strings clearly, >>> I am concatenating each repeated match below): >>> >>> Steps for re.findall('(.a.)*', 'Mary has a lamb'): >>> >>> step 1: Match '' + 'Mar' + '' (gready!) >>> step 2: skip 'y' >>> step 3: Match '' >>> step 4: skip ' ' >>> step 5: Match ''+'has'+' a '+'lam'+'' (greedy!) >>> step 6: skip 'b' >>> step 7: Match '' >>> >>> So there should be exactly 4 matches in total: >>> >>> 'Mar', '', 'has a lam', '' >>> >>> Also, the matches above shows >>> that if a repeated subgroup only captures >>> the last match, the subgroup (.a.)* >>> should always capture '' here (see steps >>> 1, 3, 5, 7) above. >>> >>> Yet the execution in Python results in 6 matches! >>> And, the capturing subgroup with repetition >>> sometimes got the wrong guy. >>> >>> So I believe the algorithm for findall must be WRONG. >>> >>> Regards, >>> >>> Yingjie >> At a guess, I'd say what is happening is something like >> this: >> >> Steps for re.findall('(.a.)*', 'Mary has a lamb'): >> >> step 1: Match 'Mar' at string index 0 >> step 2: Match '' at string index 3 (before 'y') >> step 3: skip 'y' >> step 4: Match '' at string index 4 (before ' ') >> step 5: skip ' ' >> step 6: Match 'has a lam' at string index 5 >> step 7: Match '' at string index 14 (before 'b') >> step 8: skip 'b' >> step 9: Match '' at string index 15 (before EOS) >> >> >> >> matches: ('Mar', '', '', 'has a lam', '', '') >> returns: ['Mar', '', '', 'lam', '', ''] (*) >> >> (*) "has a " lost due to not being last repetition at that >> match point >> >> Which seems about right to me! Greediness has nothing to do >> with it, except that it causes 'has a lam' to be matched in >> one match, instead of as three separate matches (of 'has', ' >> a ' and 'lam'). > > Disagree in this case, where the whole regex > matches an empty string. Greadiness will match > as much as possible. So it will also match > the empty strings between consecutive > characters as much as possible, once > we have properly defined all the unique > empty strings. Because of greadiness, > fewer matches should be found. In this > case, it should find only 4 matches > (shown in my steps) instead of 6 matches > (shown in your steps). > Attempt 1 starts at the beginning of the string: [Mar]y has a lamb Matches once, returns 'Mar' Attempt 2 starts where the previous match ended: Mar[]y has a lamb Matches an empty string, returns '' Attempt 3 starts where the previous match ended: Mary[] has a lamb Matches an empty string, returns '' Attempt 4 starts where the previous match ended: Mary [has][ a ][lam]b Matches 3 times, returns 'lam' Attempt 5 starts where the previous match ended: Mary has a lam[]b Matches an empty string, returns '' Attempt 6 starts where the previous match ended: Mary has a lamb[] Matches an empty string, returns '' The result is therefore ['Mar', '', '', 'lam', '', ''] From lists at asd-group.com Tue Nov 2 23:20:38 2010 From: lists at asd-group.com (John Bond) Date: Wed, 03 Nov 2010 03:20:38 +0000 Subject: Python documentation too difficult for beginners In-Reply-To: References: <2010110223050345181-nizumzen@mcnuggetscom> Message-ID: <4CD0D506.3080904@asd-group.com> My 2c: I use the ActiveState distro, and it's winhelp doco. It's generally ok and some things, like Dive Into Python, I've found excellent. But I do quite regularly find myself cursing at the vagueness of the index, and some of the content seems to require that you know it before you read it (I wish I could remember an example). Like everything, it could be improved. Cheers, JB From robert.kern at gmail.com Tue Nov 2 23:26:10 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 02 Nov 2010 22:26:10 -0500 Subject: Allowing comments after the line continuation backslash In-Reply-To: <87aalrjkty.fsf@benfinney.id.au> References: <4CCE6FF6.2050408@v.loewis.de> <87aalrjkty.fsf@benfinney.id.au> Message-ID: On 2010-11-02 19:46 , Ben Finney wrote: > Instead, I'd do:: > > styles = [ > ("normal", "image", MainWindow.ColorsNormalList), > ("highlighted", "highlight", MainWindow.ColorsHighlightedList), > ("selected", "select", MainWindow.ColorsSelectedList)] I'd go one step further: styles = [ ("normal", "image", MainWindow.ColorsNormalList), ("highlighted", "highlight", MainWindow.ColorsHighlightedList), ("selected", "select", MainWindow.ColorsSelectedList), ] Keeping the []s separate from the items and using the trailing comma means that I can easily add new items or reorder the items. -- 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 lanyjie at yahoo.com Tue Nov 2 23:28:09 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Tue, 2 Nov 2010 20:28:09 -0700 (PDT) Subject: Must be a bug in the re module [was: Why this result with the re module] In-Reply-To: <4CD0C94C.30701@melv.org> Message-ID: <495005.91127.qm@web54207.mail.re2.yahoo.com> > Your regex says "Zero or more consecutive occurrences of > something, always returning the most possible".? That's > what it does, at every position - only matching emptyness > where it couldn't match anything (findall then skips a > character to avoid overlapping/infinite empty > matches),? and at all other times matching the most > possible (eg. "has a lam" not "has", " a ", "lam"). You are about to convince me now. You are correct for the regex '(.a.)*'. What I thought was for this regex: '((.a.)*)*', I confused myself when I added an enclosing (). Could you please reconsider how would you work with this new one and see if my steps are correct? If you agree with my 7-step execution for the new regex, then: We finally found a real bug for re.findall: >>> re.findall('((.a.)*)*', 'Mary has a lamb') [('', 'Mar'), ('', ''), ('', ''), ('', 'lam'), ('', ''), ('', '')] Cheers, Yingjie From gunnerasch at gmail.com Tue Nov 2 23:33:18 2010 From: gunnerasch at gmail.com (Gunner Asch) Date: Tue, 02 Nov 2010 20:33:18 -0700 Subject: *** FBI gets a warm welcome in Chicago for their EXCELLENTperformance - cheers to NEW CONS *** References: <26f97f70-9043-490c-9e6e-35159f38d76b@r29g2000yqj.googlegroups.com> <47e0b3a3-54fb-4489-95a8-b5ec6015c99d@j25g2000yqa.googlegroups.com> Message-ID: <6vl1d6lbohrsgg6fucilc0dj235qfs5ak6@4ax.com> On Tue, 02 Nov 2010 13:58:16 -0700, Rich Grise wrote: >On Tue, 02 Nov 2010 14:17:29 -0700, Gunner Asch wrote: >> >> But...shrug..there will be far less after the Great Cull........ > >I think some people might be surprised as to exactly _who_ gets "culled". > >Good Luck! >Rich Indeed. So stock up, and watch your six. Gunner "Confiscating wealth from those who have earned it, inherited it, or got lucky is never going to help 'the poor.' Poverty isn't caused by some people having more money than others, just as obesity isn't caused by McDonald's serving super-sized orders of French fries Poverty, like obesity, is caused by the life choices that dictate results." - John Tucci, From lanyjie at yahoo.com Tue Nov 2 23:42:37 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Tue, 2 Nov 2010 20:42:37 -0700 (PDT) Subject: Must be a bug in the re module [was: Why this result with the re module] In-Reply-To: <4CD0D07D.5030903@mrabarnett.plus.com> Message-ID: <292222.415.qm@web54207.mail.re2.yahoo.com> > Matches an empty string, returns '' > > The result is therefore ['Mar', '', '', 'lam', '', ''] Thanks, now I see it through with clarity. Both you and JB are right about this case. However, what if the regex is ((.a.)*)* ? From lists at asd-group.com Tue Nov 2 23:55:44 2010 From: lists at asd-group.com (John Bond) Date: Wed, 03 Nov 2010 03:55:44 +0000 Subject: Must be a bug in the re module [was: Why this result with the re module] In-Reply-To: <495005.91127.qm@web54207.mail.re2.yahoo.com> References: <495005.91127.qm@web54207.mail.re2.yahoo.com> Message-ID: <4CD0DD40.6030306@asd-group.com> > Could you please reconsider how would you > work with this new one and see if my steps > are correct? If you agree with my 7-step > execution for the new regex, then: > > We finally found a real bug for re.findall: > >>>> re.findall('((.a.)*)*', 'Mary has a lamb') > [('', 'Mar'), ('', ''), ('', ''), ('', 'lam'), ('', ''), ('', '')] > > > Cheers, > > Yingjie > > > Nope, I'm afraid it is lack of understanding again. The outer capturing group that you've added is matching the entirety of what's matched by the inner one (which is six matches, that you now accept). Because it only returns the last of them, it returns one thing - an empty string (that being the last thing that the inner group matched). Findall is simply returning that in each of the six return values it needs to return because of the inner one. You just need to accept that findall (like all of re) works fine, and if it doesn't seem to do what you expect, it's because the expectation is wrong. Cheers, JB From python at mrabarnett.plus.com Wed Nov 3 00:02:45 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 03 Nov 2010 04:02:45 +0000 Subject: Must be a bug in the re module [was: Why this result with the re module] In-Reply-To: <292222.415.qm@web54207.mail.re2.yahoo.com> References: <292222.415.qm@web54207.mail.re2.yahoo.com> Message-ID: <4CD0DEE5.2060702@mrabarnett.plus.com> On 03/11/2010 03:42, Yingjie Lan wrote: >> Matches an empty string, returns '' >> >> The result is therefore ['Mar', '', '', 'lam', '', ''] > > Thanks, now I see it through with clarity. > Both you and JB are right about this case. > However, what if the regex is ((.a.)*)* ? > Actually, in hindsight, my explanation is slightly wrong! re.search and the others return None for an unmatched group, but re.findall returns '' for an unmatched group, so instead of saying: Matches an empty string, returns '' I should have said: The group doesn't match at all, so .findall returns '' As for "((.a.)*)*", the inner group and repeat match like before, but then the outer repeat and group try again. The inner group can't match again, so it's unchanged (and it still remembers the last successful capture), and the outer group therefore matches an empty string. Therefore the outer (first) group is always an empty string and the inner (second) group is the same as the previous example (the last capture or '' if no capture). From lists at asd-group.com Wed Nov 3 00:09:17 2010 From: lists at asd-group.com (John Bond) Date: Wed, 03 Nov 2010 04:09:17 +0000 Subject: Must be a bug in the re module [was: Why this result with the re module] In-Reply-To: <4CD0DD40.6030306@asd-group.com> References: <495005.91127.qm@web54207.mail.re2.yahoo.com> <4CD0DD40.6030306@asd-group.com> Message-ID: <4CD0E06D.6010400@asd-group.com> On 3/11/2010 3:55 AM, John Bond wrote: > >> Could you please reconsider how would you >> work with this new one and see if my steps >> are correct? If you agree with my 7-step >> execution for the new regex, then: >> >> We finally found a real bug for re.findall: >> >>>>> re.findall('((.a.)*)*', 'Mary has a lamb') >> [('', 'Mar'), ('', ''), ('', ''), ('', 'lam'), ('', ''), ('', '')] >> >> >> Cheers, >> >> Yingjie >> >> >> > > Nope, I'm afraid it is lack of understanding again. > > The outer capturing group that you've added is matching the entirety > of what's matched by the inner one (which is six matches, that you now > accept). Because it only returns the last of them, it returns one > thing - an empty string (that being the last thing that the inner > group matched). Findall is simply returning that in each of the six > return values it needs to return because of the inner one. > > You just need to accept that findall (like all of re) works fine, and > if it doesn't seem to do what you expect, it's because the expectation > is wrong. > > Cheers, JB Just to clarify - findall is returning: [ (only match in outer group, 1st match in inner group) , (only match in outer group, 2nd match in inner group) , (only match in outer group, 3rd match in inner group) , (only match in outer group, 4th match in inner group) , (only match in outer group, 5th match in inner group) , (only match in outer group, 6th match in inner group) ] Where "only match in outer group" = "6th match in inner group" owing to the way that capturing groups with repetition only return the last thing they matched. Cheers, JB From lists at asd-group.com Wed Nov 3 00:10:57 2010 From: lists at asd-group.com (John Bond) Date: Wed, 03 Nov 2010 04:10:57 +0000 Subject: Must be a bug in the re module [was: Why this result with the re module] In-Reply-To: <4CD0DEE5.2060702@mrabarnett.plus.com> References: <292222.415.qm@web54207.mail.re2.yahoo.com> <4CD0DEE5.2060702@mrabarnett.plus.com> Message-ID: <4CD0E0D1.7070902@asd-group.com> On 3/11/2010 4:02 AM, MRAB wrote: > On 03/11/2010 03:42, Yingjie Lan wrote: >>> Matches an empty string, returns '' >>> >>> The result is therefore ['Mar', '', '', 'lam', '', ''] >> >> Thanks, now I see it through with clarity. >> Both you and JB are right about this case. >> However, what if the regex is ((.a.)*)* ? >> > Actually, in hindsight, my explanation is slightly wrong! > > re.search and the others return None for an unmatched group, but > re.findall returns '' for an unmatched group, so instead of saying: > > Matches an empty string, returns '' > > I should have said: > > The group doesn't match at all, so .findall returns '' > > As for "((.a.)*)*", the inner group and repeat match like before, but > then the outer repeat and group try again. > > The inner group can't match again, so it's unchanged (and it still > remembers the last successful capture), and the outer group therefore > matches an empty string. > > Therefore the outer (first) group is always an empty string and the > inner (second) group is the same as the previous example (the last > capture or '' if no capture). Now I'm confused - how can something with "zero or more occurrences" not match? Cheers, JB From gnarlodious at gmail.com Wed Nov 3 00:16:11 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Tue, 2 Nov 2010 21:16:11 -0700 (PDT) Subject: Py3: decode subprocess output Message-ID: Under Python 2.6, commands.getoutput returns text type str containing ANSI Terminal formatting hex characters: "\x1b[1;31mSun : \x1b[1;36m114.902\x1b[0m - 0\xf800' (-)\x1b[1;33m I have a system for parsing out the relevant parts and I prefer to keep using that system. Under Python 3, subprocess.check_output returns a bytestring that doesn't parse. Since the CLI program (written in the 1990's) will never send Unicode, is there a way to downconvert the bytestring into type str so as to emulate Py2.6 behavior? Or alternatively, is there a whizbang Py3 method to parse out strings delimited by hex? I tried several tricks but it is all beyond my skills. Thanks. -- Gnarlie From lanyjie at yahoo.com Wed Nov 3 00:17:07 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Tue, 2 Nov 2010 21:17:07 -0700 (PDT) Subject: Must be a bug in the re module [was: Why this result with the re module] In-Reply-To: <4CD0E06D.6010400@asd-group.com> Message-ID: <333352.24512.qm@web54202.mail.re2.yahoo.com> --- On Wed, 11/3/10, John Bond wrote: > Just to clarify - findall is returning: > > [ (only match in outer group, 1st match in inner group) > , (only match in outer group, 2nd match in inner group) > , (only match in outer group, 3rd match in inner group) > , (only match in outer group, 4th match in inner group) > , (only match in outer group, 5th match in inner group) > , (only match in outer group, 6th match in inner group) > ] > > Where "only match in outer group" = "6th match in inner > group" owing to the way that capturing groups with > repetition only return the last thing they matched. > ---On Wed, 11/3/10, MRAB wrote------- > Therefore the outer (first) group is always an empty string and the > inner (second) group is the same as the previous example (the last > capture or '' if no capture). OK, I've got that, and I have no problem with the capturing part. My real problem is with the number of total matches. I think it should be 4 matches in total but findall gives 6 matches, for the new regex '((.a.)*)*'. I'd love to know what you think about this. Many thanks! Yingjie From lanyjie at yahoo.com Wed Nov 3 00:23:11 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Tue, 2 Nov 2010 21:23:11 -0700 (PDT) Subject: Must be a bug in the re module [was: Why this result with the re module] In-Reply-To: <4CD0DEE5.2060702@mrabarnett.plus.com> Message-ID: <66841.34190.qm@web54202.mail.re2.yahoo.com> --- On Wed, 11/3/10, MRAB wrote: > From: MRAB > Subject: Re: Must be a bug in the re module [was: Why this result with the re module] > To: python-list at python.org > Date: Wednesday, November 3, 2010, 8:02 AM > On 03/11/2010 03:42, Yingjie Lan > wrote: > Therefore the outer (first) group is always an empty string > and the > inner (second) group is the same as the previous example > (the last > capture or '' if no capture). Now I am confused also: If the outer group \1 is empty, how could the inner group \2 actually have something? Yingjie From ben+python at benfinney.id.au Wed Nov 3 00:24:15 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 03 Nov 2010 15:24:15 +1100 Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> <87aalrjkty.fsf@benfinney.id.au> Message-ID: <87wrovhw5s.fsf@benfinney.id.au> Robert Kern writes: > I'd go one step further: > > styles = [ > ("normal", "image", MainWindow.ColorsNormalList), > ("highlighted", "highlight", MainWindow.ColorsHighlightedList), > ("selected", "select", MainWindow.ColorsSelectedList), > ] > > Keeping the []s separate from the items and using the trailing comma > means that I can easily add new items or reorder the items. No problem with that, except I'd still keep the closing character indented:: styles = [ ("normal", "image", MainWindow.ColorsNormalList), ("highlighted", "highlight", MainWindow.ColorsHighlightedList), ("selected", "select", MainWindow.ColorsSelectedList), ] because it's consistent with how lines are grouped everywhere else in Python: the grouping continues while the same indentation level continues, and stops once the indentation stops. -- \ ?By instructing students how to learn, unlearn, and relearn, a | `\ powerful new dimension can be added to education.? ?Alvin | _o__) Toffler, _Future Shock_, 1970 | Ben Finney From lists at asd-group.com Wed Nov 3 00:33:15 2010 From: lists at asd-group.com (John Bond) Date: Wed, 03 Nov 2010 04:33:15 +0000 Subject: Must be a bug in the re module [was: Why this result with the re module] In-Reply-To: <333352.24512.qm@web54202.mail.re2.yahoo.com> References: <333352.24512.qm@web54202.mail.re2.yahoo.com> Message-ID: <4CD0E60B.7010402@asd-group.com> > OK, I've got that, and I have no problem with the capturing part. > My real problem is with the number of total matches. > *I think it should be 4 matches in total but findall > gives 6 matches*, for the new regex '((.a.)*)*'. > I'd love to know what you think about this. > > Many thanks! > Yingjie > > > > We've already been through that, and nothing's changed - all you've done is: 1) taken something that you know (now!) has six matches: (.a.)* 2) added an outer capturing group (which does not change the actual matches, only what gets returned): ((.a.)*) 3) then said there must be >=0 occurrences of what's inside it, which of course there is, so that has no effect. ((.a.)*)* End result: the matching is exactly the same, findall still needs to return the 6 things it did in the first place, but now it also has to return an extra value at each return location (that being what's captured by the new outer group) hence the tuples. Cheers, JB -------------- next part -------------- An HTML attachment was scrubbed... URL: From tlikonen at iki.fi Wed Nov 3 00:34:20 2010 From: tlikonen at iki.fi (Teemu Likonen) Date: Wed, 03 Nov 2010 06:34:20 +0200 Subject: Man pages and info pages References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> <024ef21a-9ef9-48a6-8372-1d66895583c3@v16g2000yqn.googlegroups.com> <87zktr5yze.fsf_-_@mithlond.arda> Message-ID: <877hgv2fg3.fsf@mithlond.arda> * 2010-11-02 19:36 (UTC), Tim Harig wrote: > On 2010-11-02, Teemu Likonen wrote: >> There is also the problem that people are less familiar with info >> browsers than the usual "less" pager which is used by "man" command. > > I thoroughly agree. The default info viewers are quite possibly the > most counterintuitive programs I have ever encountered. I never did > bother to learn how to use them. I instead installed the more > intuitive pinfo program. It seems that we only agree on the part that I explicitly wrote about: people are less familiar with info browsers than "less" pager. I didn't mean to imply any reasons why this might be the case. I think "info" browser is intuitive and easy to use. The basic commands: Enter Follow a link (down to node) u up node level h help (general how-to) ? help (commands) s search Arrow keys, page up, page down keys work as usual. What's counter-intuitive in it? >> With the text terminal info browser called "info" as well as Emacs' >> info browser you can use command "s" (stands for "search"). It >> prompts for a regexp pattern to search in the whole document, >> including subsections etc. > > Right, pinfo offers this as well; but, then you have to figure out > where in the nodes that the search has taken you and how to navigate > from that node to find additional information that you may need. I usually return to the top node with "t" command or go one or more levels up in the tree with "u" command. The first line in the window tells where I am. From lists at asd-group.com Wed Nov 3 00:43:18 2010 From: lists at asd-group.com (John Bond) Date: Wed, 03 Nov 2010 04:43:18 +0000 Subject: Must be a bug in the re module [was: Why this result with the re module] In-Reply-To: <66841.34190.qm@web54202.mail.re2.yahoo.com> References: <66841.34190.qm@web54202.mail.re2.yahoo.com> Message-ID: <4CD0E866.7070707@asd-group.com> On 3/11/2010 4:23 AM, Yingjie Lan wrote: > --- On Wed, 11/3/10, MRAB wrote: > >> From: MRAB >> Subject: Re: Must be a bug in the re module [was: Why this result with the re module] >> To: python-list at python.org >> Date: Wednesday, November 3, 2010, 8:02 AM >> On 03/11/2010 03:42, Yingjie Lan >> wrote: >> Therefore the outer (first) group is always an empty string >> and the >> inner (second) group is the same as the previous example >> (the last >> capture or '' if no capture). > Now I am confused also: > > If the outer group \1 is empty, how could the inner > group \2 actually have something? > > Yingjie > > > I just explained that (I think!)! The outer capturing group uses repetition, so it returns the last thing that was matched by the inner group, which was an empty string. I If you took away the outer groups repetition: re.findall('((.a.)*)', 'Mary has a lamb') then, for each of the six matches, it returns the full thing that was matched: ('Mar', 'Mar'), ('', ''), ('', ''), ('has a lam', 'lam'), ('', ''), ('', '')] Cheers, JB From mygogo2011 at gmail.com Wed Nov 3 00:56:43 2010 From: mygogo2011 at gmail.com (PHP.CCC) Date: Tue, 2 Nov 2010 21:56:43 -0700 (PDT) Subject: Coca Cola Scholarship: Are You Qualified? Message-ID: <4fc593c3-9e29-47dd-9051-b165ebff80c6@s5g2000yqm.googlegroups.com> Coca Cola Scholarship: Are You Qualified? Before you apply for Coca Cola scholarship, here are the things you should know: Coca-Cola Scholars Foundation programs There are two types of Coca-Cola Scholars Foundation programs: ?2-Year Colleges Scholarship Program ? Scholars Program for high school seniors 1. 2-Year Colleges Scholarship Program Read more.... http://childschooledu.blogspot.com From usernet at ilthio.net Wed Nov 3 01:08:45 2010 From: usernet at ilthio.net (Tim Harig) Date: Wed, 3 Nov 2010 05:08:45 +0000 (UTC) Subject: Man pages and info pages References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> <024ef21a-9ef9-48a6-8372-1d66895583c3@v16g2000yqn.googlegroups.com> <87zktr5yze.fsf_-_@mithlond.arda> <877hgv2fg3.fsf@mithlond.arda> Message-ID: On 2010-11-03, Teemu Likonen wrote: > * 2010-11-02 19:36 (UTC), Tim Harig wrote: >> I thoroughly agree. The default info viewers are quite possibly the >> most counterintuitive programs I have ever encountered. I never did >> bother to learn how to use them. I instead installed the more >> intuitive pinfo program. > > It seems that we only agree on the part that I explicitly wrote about: > people are less familiar with info browsers than "less" pager. I didn't > mean to imply any reasons why this might be the case. I think "info" The reason is really simple. Less' interface derives from more. Less and more have a long history on the *nix platform and many programs have emulated their interface. When the GNU folk decided to clone *nix they decided that they knew better and simply decided to create their own interfaces. I guess they figured that everybody loves to have to learn multiple varying interfaces to use different programs. > browser is intuitive and easy to use. The basic commands: [SNIP] > Arrow keys, page up, page down keys work as usual. Actually, the left arrow key does not work at all intuitively. One would expect that it should go back to the previous page as it would in lynx, etc. It does not. By tradition 'n' and 'p' are broken for scrolling in a page. 'b' is often used in place of p but that seems to take one back to the top of the page. The s key for a search is another example that has already been discussed. > What's counter-intuitive in it? Maybe its intutitive to an emacs user; but, I find pinfo's default key bindings much easier. >>> With the text terminal info browser called "info" as well as Emacs' >>> info browser you can use command "s" (stands for "search"). It >>> prompts for a regexp pattern to search in the whole document, >>> including subsections etc. >> >> Right, pinfo offers this as well; but, then you have to figure out >> where in the nodes that the search has taken you and how to navigate >> from that node to find additional information that you may need. > > I usually return to the top node with "t" command or go one or more > levels up in the tree with "u" command. The first line in the window > tells where I am. That assumes that you understand the node structure used or that you don't mind returning to the top and having to re-walk the node structure every time that you want to find new piece of information. I already discussed that just finding the info pages can be difficult because you have to know that they are stored under the package name and that multiple pages can be used for man page structure. From rantingrick at gmail.com Wed Nov 3 01:17:20 2010 From: rantingrick at gmail.com (rantingrick) Date: Tue, 2 Nov 2010 22:17:20 -0700 (PDT) Subject: Python documentation too difficult for beginners References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> <024ef21a-9ef9-48a6-8372-1d66895583c3@v16g2000yqn.googlegroups.com> <4716193c-2e9f-4469-b8c7-bba600fba8a2@p1g2000yqm.googlegroups.com> Message-ID: <13cc0ada-88a3-4a95-9fb8-d376664bed0c@p1g2000yqm.googlegroups.com> AD i agree with you! The official python tutorial and the official docs are pretty much a twisted mass of confusion to the initiated programmer. Even today when i try yo search the docs i find the result quite frankly useless. And the search reminds me of the old XP "puppy dog" search. The doc ARE fairly well written HOWEVER the search engine needs an update. For me, i just Google it, and forget it! From usernet at ilthio.net Wed Nov 3 01:20:52 2010 From: usernet at ilthio.net (Tim Harig) Date: Wed, 3 Nov 2010 05:20:52 +0000 (UTC) Subject: Mail Merge from python data References: Message-ID: This page didn't make it to through to my nntp server so I appologize if I miss something that was covered. On 2010-11-03, Dennis Lee Bieber wrote: > On Tue, 2 Nov 2010 20:32:13 +1000, Dylan Evans > declaimed the following in gmane.comp.python.general: > >> I'm setting up a database for an organisation who want to do mail merges in >> office 2010. I know i can use the MySQL ODBC driver for the mail merge but i >> have set up the database with lots of relations and many-to-many links which >> i'm sure will lead to a huge amount of confusion (I think, i don't really >> know much about mail merge). Many to many relationships without some kind of intersection table are considered a rather poor practice in general. >> What i want to know is, is there anyway to send data from python, which the >> UI is written in, to office templates and mail merges? > > If a long lived form, I'd probably define a query or view (I think > MySQL 5.x has output-only views) that isolates just to the data fields > used in the mail merge. I agree that a view would be the best solution if you have the access to do so; but, a couple of other alternatives come to mind in case you do not. 1. Do the mail merge in Python using a Word template. Then you can add any kind of logic that you need to the merge. 2. Add some kind of export function to your python UI that allows you to export the data to an Excel sheet, CSV, or even another ODBC data source (like another MySQL table or database that you might have access to). From lanyjie at yahoo.com Wed Nov 3 02:16:29 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Tue, 2 Nov 2010 23:16:29 -0700 (PDT) Subject: Must be a bug in the re module [was: Why this result with the re module] Message-ID: <869719.99302.qm@web54202.mail.re2.yahoo.com> --- On Wed, 11/3/10, John Bond wrote: > 3) then said there must be >=0 occurrences of what's inside it, > which of course there is, so that has no effect. > > ((.a.)*)* Hi, I think there should be a difference: unlike before, now what's inside the outer group can match an empty string. And so by reason of the greediness of the quantifier * of the outer group (that is, the last *), it should take up the empty string after each non-empty match. So, the first match in 'Mary has a lamb' must be: '' + 'Mar' + '' (the empty string before the 'y') (note the first '' is before the 'M') Then, after skipping the 'y' (remember, the empty string before 'y' is already taken), comes a second: '' (the one between 'y' and ' ') Then after skipping the space ' ', comes a third: 'has' + ' a ' + 'lam' + '' (the empty string before the 'b') And finally, it matches the empty string after 'b': '' So there should be total of four matches -- isn't it? Yingjie From iwawi123 at gmail.com Wed Nov 3 02:26:06 2010 From: iwawi123 at gmail.com (iwawi) Date: Tue, 2 Nov 2010 23:26:06 -0700 (PDT) Subject: text file reformatting References: <78daefd1-59a1-4b3a-9bc2-5910315515ce@r14g2000yqa.googlegroups.com> <57ec83dd-3f30-4000-acf6-f49a44568d22@k22g2000yqh.googlegroups.com> <31a905d6-982d-479d-b988-e8324a1a16c7@j25g2000yqa.googlegroups.com> Message-ID: On Nov 1, 6:50?pm, "cbr... at cbrownsystems.com" wrote: > On Nov 1, 1:58?am, iwawi wrote: > > > > > > > On 1 marras, 09:59, "cbr... at cbrownsystems.com" > > > wrote: > > > On Oct 31, 11:46?pm, iwawi wrote: > > > > > On 31 loka, 21:48, Tim Chase wrote: > > > > > > > PRJ01001 4 00100END > > > > > > PRJ01002 3 00110END > > > > > > > I would like to pick only some columns to a new file and put them to a > > > > > > certain places (to match previous data) - definition file (def.csv) > > > > > > could be something like this: > > > > > > > VARIABLE ? FIELDSTARTS ? ? FIELD SIZE ? ? ?NEW PLACE IN NEW DATA FILE > > > > > > ProjID ? ? ; ? ? ? 1 ? ? ? ; ? ? ? 5 ? ? ? ; ? ? ? 1 > > > > > > CaseID ? ? ; ? ? ? 6 ? ? ? ; ? ? ? 3 ? ? ? ; ? ? ? 10 > > > > > > UselessV ?; ? ? ? ?10 ? ? ?; ? ? ? 1 ? ? ? ; > > > > > > Zipcode ? ?; ? ? ? 12 ? ? ?; ? ? ? 5 ? ? ? ; ? ? ? 15 > > > > > > > So the new datafile should look like this: > > > > > > > PRJ01 ? ?001 ? ? ? 00100END > > > > > > PRJ01 ? ?002 ? ? ? 00110END > > > > > > How flexible is the def.csv format? ?The difficulty I see with > > > > > your def.csv format is that it leaves undefined gaps (presumably > > > > > to be filled in with spaces) and that you also have a blank "new > > > > > place in new file" value. ?If instead, you could specify the > > > > > width to which you want to pad it and omit variables you don't > > > > > want in the output, ordering the variables in the same order you > > > > > want them in the output: > > > > > > ? Variable; Start; Size; Width > > > > > ? ProjID; 1; 5; 10 > > > > > ? CaseID; 6; 3; 10 > > > > > ? Zipcode; 12; 5; 5 > > > > > ? End; 16; 3; 3 > > > > > > (note that I lazily use the same method to copy the END from the > > > > > source to the destination, rather than coding specially for it) > > > > > you could do something like this (untested) > > > > > > ? ?import csv > > > > > ? ?f = file('def.csv', 'rb') > > > > > ? ?f.next() # discard the header row > > > > > ? ?r = csv.reader(f, delimiter=';') > > > > > ? ?fields = [ > > > > > ? ? ?(varname, slice(int(start), int(start)+int(size)), width) > > > > > ? ? ?for varname, start, size, width > > > > > ? ? ?in r > > > > > ? ? ?] > > > > > ? ?f.close() > > > > > ? ?out = file('out.txt', 'w') > > > > > ? ?try: > > > > > ? ? ?for row in file('data.txt'): > > > > > ? ? ? ?for varname, slc, width in fields: > > > > > ? ? ? ? ?out.write(row[slc].ljust(width)) > > > > > ? ? ? ?out.write('\n') > > > > > ? ?finally: > > > > > ? ? ?out.close() > > > > > > Hope that's fairly easy to follow and makes sense. ?There might > > > > > be some fence-posting errors (particularly your use of "1" as the > > > > > initial offset, while python uses "0" as the initial offset for > > > > > strings) > > > > > > If you can't modify the def.csv format, then things are a bit > > > > > more complex and I'd almost be tempted to write a script to try > > > > > and convert your existing def.csv format into something simpler > > > > > to process like what I describe. > > > > > > -tkc- Piilota siteerattu teksti - > > > > > > - N?yt? siteerattu teksti - > > > > > Hi, > > > > > Thanks for your reply. > > > > > Def.csv could be modified so that every line has the same structure: > > > > variable name, field start, field size and new place and would be > > > > separated with semicolomns as you mentioned. > > > > > I tried your script (which seems quite logical) but I get this > > > > > Traceback (most recent call last): > > > > ? File "testing.py", line 16, in > > > > ? ? out.write (row[slc].ljust(width)) > > > > TypeError: an integer is required > > > > > Yes - you said it was untested, but I can't figure out how to > > > > proceed... > > > > The line > > > > ? ? (varname, slice(int(start), int(start)+int(size)), width) > > > > should instead be > > > > ? ? (varname, slice(int(start), int(start)+int(size)), int(width)) > > > > although you give an example where there is no width - what does that > > > imply? In the above case, it will throw an exception. > > > > Anyway, I think you'll find there's something a bit off in the output > > > loop with the parameter passed to ljust() as well. The value given in > > > your csv seems to be the absolute position, but as it's implemented by > > > Tim, it acts as the relative position. > > > > Given Tim's parsing into the list fields, I have a feeling that what > > > you really want instead of > > > > ? ? for varname, slc, width in fields: > > > ? ? ? ? out.write(row[slc].ljust(width)) > > > ? ? out.write('\n') > > > > is to have > > > > ? ? s = '' > > > ? ? for varname, slc, width in fields: > > > ? ? ? ? s += " "*(width - len(s)) + row[slc] > > > ? ? out.write(s+'\n') > > > > And if that is what you want, then you will surely want to globally > > > replace the name 'width' with for example 'start_column', because then > > > it all makes sense :). > > > > Cheers - Chas- Piilota siteerattu teksti - > > > > - N?yt? siteerattu teksti - > > > Yes, it's meant to be the absolute column position in a new file like > > you said. > > > I used your changes to the csv-reading cause it seems more flexible, > > but the end of the code is still not working. Here's were I stand now: > > > import re > > > parse_columns = re.compile(r'\s*;\s*') > > > f = file('def.csv', 'rb') > > f.readline() # discard the header row > > r = (parse_columns.split(line.strip()) for line in f) > > fields = [ > > ?(varname, slice(int(start), int(start)+int(size), int(width) if width > > else 0)) > > there's a misplaced parentheses; replace the above line (which yields > a 2-tuple of values) with: > > ? (varname, slice(int(start), int(start)+int(size)), int(width) if > width else 0) > > which yields a 3-tuple. > > Cheers - Chas > > > > > ? for varname, start, size, width in r > > ?] > > f.close() > > print fields > > > out = file('out.txt', 'w') > > > try: > > ?for row in file('data.txt'): > > ? s = ' ' > > ? for varname, slc, width in fields: > > ? ?s += " "*(width - len(s)) + row[slc] > > ? out.write(s+'\n') > > finally: > > ?out.close() > > > When executed, I get this: > > ? File "toimi.py", line 20, in > > ? ? for varname, slc, width in fields: > > ValueError: need more than 2 values to unpack- Hide quotedtext- > > - Show quotedtext-- Hide quotedtext- > > - Show quotedtext- I could not thank you enough - you totally solved my problem and speeded up my routine about 1500 %, if not more. Many thanks man! -iwawi From vgnulinux at gmail.com Wed Nov 3 02:32:04 2010 From: vgnulinux at gmail.com (VGNU Linux) Date: Wed, 3 Nov 2010 12:02:04 +0530 Subject: How to highlight Label/Text in tkinter ? Message-ID: Hi, I am writing a program teach myself python and tkinter. Below given is a program which displays label with different fonts and sizes. How to highlight text and change font size if the up/down arrow keys are pressed ? from Tkinter import * import tkFont class MyFrame(Frame): def __init__(self, root): Frame.__init__(self, root) self.txt = Label(self, text="Arial 10 bold", font=("Arial",10,"bold")) self.txt.grid(row=1,column=1) self.txt = Label(self, text="Courier 12 bold", font=("Courier",12,"bold")) self.txt.grid(row=2,column=1) self.txt = Label(self, text="Comic Sans MS 14 bold", font=("Comic Sans MS",14,"bold")) self.txt.grid(row=3,column=1) self.txt = Label(self, text="Fixedsys 16 bold", font=("Fixedsys",16,"bold")) self.txt.grid(row=4,column=1) self.txt = Label(self, text="MS Sans Serif 18 bold", font=("MS Sans Serif",18,"bold")) self.txt.grid(row=5,column=1) self.txt = Label(self, text="MS Serif, Symbol 20 bold", font=("MS Serif, Symbol",20,"bold")) self.txt.grid(row=6,column=1) self.txt = Label(self, text="System 22 bold", font=("System",22,"bold")) self.txt.grid(row=7,column=1) self.txt = Label(self, text="Verdana 24 bold", font=("Verdana",24,"bold")) self.txt.grid(row=8,column=1) if __name__ == '__main__': root = Tk() c = MyFrame(root) c.pack(fill=BOTH, expand=1) root.mainloop() any help? Regards, VGNU -------------- next part -------------- An HTML attachment was scrubbed... URL: From lanyjie at yahoo.com Wed Nov 3 02:32:18 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Tue, 2 Nov 2010 23:32:18 -0700 (PDT) Subject: Must be a bug in the re module [was: Why this result with the re module] In-Reply-To: <4CD0E866.7070707@asd-group.com> Message-ID: <844169.1635.qm@web54201.mail.re2.yahoo.com> --- On Wed, 11/3/10, John Bond wrote: > I just explained that (I think!)! The outer capturing group > uses > repetition, so it returns the last thing that was matched > by the inner > group, which was an empty string. > According to yourself, the last match of the inner group is also empty! Generally speaking, as a match for the outer group always contains some matches for the inner group, it must be the case that the last match for the inner group must be contained inside the last match of the outer group. So if the last match of the outer group is empty, then the last match for the inner group must also be empty. Regards, Yingjie --- On Wed, 11/3/10, John Bond wrote: > From: John Bond > Subject: Re: Must be a bug in the re module [was: Why this result with the re module] > To: python-list at python.org > Date: Wednesday, November 3, 2010, 8:43 AM > On 3/11/2010 4:23 AM, Yingjie Lan > wrote: > > --- On Wed, 11/3/10, MRAB? > wrote: > > > >> From: MRAB > >> Subject: Re: Must be a bug in the re module [was: > Why this result with the re module] > >> To: python-list at python.org > >> Date: Wednesday, November 3, 2010, 8:02 AM > >> On 03/11/2010 03:42, Yingjie Lan > >> wrote: > >> Therefore the outer (first) group is always an > empty string > >> and the > >> inner (second) group is the same as the previous > example > >> (the last > >> capture or '' if no capture). > > Now I am confused also: > > > > If the outer group \1 is empty, how could the inner > > group \2 actually have something? > > > > Yingjie > > > > > > > I just explained that (I think!)! The outer capturing group > uses > repetition, so it returns the last thing that was matched > by the inner > group, which was an empty string. I > > If you took away the outer groups repetition: > > re.findall('((.a.)*)', 'Mary has a lamb') > > then, for each of the six matches, it returns the full > thing that was > matched: > > ('Mar', 'Mar'), ('', ''), ('', ''), ('has a lam', 'lam'), > ('', ''), ('', > '')] > > Cheers, JB > -- > http://mail.python.org/mailman/listinfo/python-list > From martin at v.loewis.de Wed Nov 3 03:34:19 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Wed, 03 Nov 2010 08:34:19 +0100 Subject: Py3: decode subprocess output In-Reply-To: References: Message-ID: > Under Python 3, subprocess.check_output returns a bytestring that > doesn't parse. Since the CLI program (written in the 1990's) will > never send Unicode, is there a way to downconvert the bytestring into > type str so as to emulate Py2.6 behavior? What do you mean by "that doesn't parse"? Returning a byte string is *already* emulating 2.6's behaviour: in 2.6, you also get a byte string, and most likely the very same string. > Or alternatively, is there a whizbang Py3 method to parse out strings > delimited by hex? I tried several tricks but it is all beyond my > skills. Please understand that there really aren't "hex characters" here. Each individual character is a byte, i.e. "Sun" == "\x53\x75\x6d". So the strings you get aren't delimited by a "hex character", but by a "control character". That said: how did you try to parse it, and how did that fail? Regards, Martin From ldo at geek-central.gen.new_zealand Wed Nov 3 03:48:10 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 03 Nov 2010 20:48:10 +1300 Subject: Python documentation too difficult for beginners References: Message-ID: In message , Dennis Lee Bieber wrote: > Whereas I have a whole shelf of Java documentation and it still > takes me an hour to write "Hello World"... Java's one class per file > results in a plethora of bloody names one has to remember just to find > out where to start looking for a standard library operation. You know Alan Kay?s dictum that ?simple things should be simple, and complex things should be possible?? Well, Java isn?t designed to make simple things simple. :) From ldo at geek-central.gen.new_zealand Wed Nov 3 03:50:40 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 03 Nov 2010 20:50:40 +1300 Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> Message-ID: In message , Roy Smith wrote: > In article , > Lawrence D'Oliveiro wrote: > >> In message , Roy Smith wrote: >> >> > In this case, I think I would do: >> > >> > styles = [("normal", "image", MainWindow.ColorsNormalList), >> > ("highlighted", "highlight", >> > MainWindow.ColorsHighlightedList), >> > ("selected", "select", MainWindow.ColorsSelectedList)] >> > >> > for in description, attr, color_list in styles: >> > blah, blah, blah >> >> And so you have managed to separate one set of looping conditions into >> two parts. What is the significance of the name ?styles?? None at all. >> What purpose does it serve? None, really. Does it ease the maintenance >> burden? No, but by splitting your attention across two places, it >> actually adds to it. > > I suppose readability is in the eye of the reader, but, yes, I agree > that I have split this into two parts. The parts are > > 1) The table of data > > 2) The looping construct But the table of data makes no sense outside of the looping construct. That table does nothing other than define the bounds of the loop. Without the loop, it has no reason to exist. It makes no more sense than styles = range(0, 100) for i in styles : ... > Where we seem to disagree is whether that makes things more or less > readable :-) To me, it makes is more readable because it lets me > understand one chunk, then move on to understanding the next chunk. Which means you don?t understand the purpose of the code at all. Go look at it in its entirety, and you?ll see what I mean. From ldo at geek-central.gen.new_zealand Wed Nov 3 03:52:16 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 03 Nov 2010 20:52:16 +1300 Subject: functions, list, default parameters References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <4cc13ef5$0$29979$c3e8da3$5496439d@news.astraweb.com> <4ccffd1c$0$29966$c3e8da3$5496439d@news.astraweb.com> <5f6eceec-1eef-4db7-82a6-e5f553349229@k22g2000yqh.googlegroups.com> Message-ID: In message <5f6eceec-1eef-4db7-82a6-e5f553349229 at k22g2000yqh.googlegroups.com>, Ian wrote: > It seems to me that there is a rather simple case to be made for > allowing mutable default arguments: instances of user-defined classes > are fundamentally mutable. Disallowing mutable default arguments > would mean disallowing instances of user-defined classes entirely. > That would be excessive and would violate Python's general rule of > staying out of the programmer's way. Unless you offered a way for user-defined classes to declare that they were immutable. From clp2 at rebertia.com Wed Nov 3 04:02:27 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 3 Nov 2010 01:02:27 -0700 Subject: Allowing comments after the line continuation backslash In-Reply-To: References: <4CCE6FF6.2050408@v.loewis.de> Message-ID: On Mon, Nov 1, 2010 at 8:15 PM, Lawrence D'Oliveiro wrote: > In message , Chris > Rebert wrote: > >> desc_attr_colors_triples = (("normal", "image", >> MainWindow.ColorsNormalList), >> ? ? ("highlighted", "highlight", MainWindow.ColorsHighlightedList), >> ? ? ("selected", "select", MainWindow.ColorsSelectedList)) >> for in description, attr, color_list in desc_attr_colors_triples: >> ? ? ... > > And so you have managed to separate one set of looping conditions into two > parts. What is the significance of the name ?desc_attr_colors_triples?? None > at all. What purpose does it serve? None, really. Does it ease the > maintenance burden? No, but by splitting your attention across two places, > it actually adds to it. > > If this is all your PEP-8 can achieve, then a pox on it. Actually, my PEP 8 reference was in regards to the (imo, terrible) UseOfCamelCaseForNonClasses (Python != C#), not the formatting of the for-loop; hence the "In any case" qualification. Cheers, Chris From lists at asd-group.com Wed Nov 3 04:02:29 2010 From: lists at asd-group.com (John Bond) Date: Wed, 3 Nov 2010 08:02:29 +0000 (UTC) Subject: What people are using to access this mailing list Message-ID: Hope this isn't too O/T - I was just wondering how people read/send to this mailing list, eg. normal email client, gmane, some other software or online service? My normal inbox is getting unmanageable, and I think I need to find a new way of following this and other lists. Thanks for any suggestions. Cheers, JB. From usernet at ilthio.net Wed Nov 3 04:03:54 2010 From: usernet at ilthio.net (Tim Harig) Date: Wed, 3 Nov 2010 08:03:54 +0000 (UTC) Subject: Py3: decode subprocess output References: Message-ID: On 2010-11-03, Gnarlodious wrote: > Under Python 3, subprocess.check_output returns a bytestring that > doesn't parse. Since the CLI program (written in the 1990's) will > never send Unicode, is there a way to downconvert the bytestring into > type str so as to emulate Py2.6 behavior? str() will convert a bytestring into a Python string object which you will be able to parse so long as the output remains ASCII (which your example is). If the input uses another encoding or contains characters with the high order bit set, you might need to fiddle with the strings encoding. From dylan at contentfree.info Wed Nov 3 04:09:08 2010 From: dylan at contentfree.info (Dylan Evans) Date: Wed, 3 Nov 2010 18:09:08 +1000 Subject: Mail Merge from python data In-Reply-To: References: Message-ID: On Wed, Nov 3, 2010 at 3:20 PM, Tim Harig wrote: > This page didn't make it to through to my nntp server so I appologize if I > miss something that was covered. > > On 2010-11-03, Dennis Lee Bieber wrote: > > On Tue, 2 Nov 2010 20:32:13 +1000, Dylan Evans > > declaimed the following in gmane.comp.python.general: > > > >> I'm setting up a database for an organisation who want to do mail merges > in > >> office 2010. I know i can use the MySQL ODBC driver for the mail merge > but i > >> have set up the database with lots of relations and many-to-many links > which > >> i'm sure will lead to a huge amount of confusion (I think, i don't > really > >> know much about mail merge). > > Many to many relationships without some kind of intersection table are > considered a rather poor practice in general. Yes an intersection table with a description char field. > > >> What i want to know is, is there anyway to send data from python, which > the > >> UI is written in, to office templates and mail merges? > > > > If a long lived form, I'd probably define a query or view (I think > > MySQL 5.x has output-only views) that isolates just to the data fields > > used in the mail merge. > > I agree that a view would be the best solution if you have the access to do > so; but, a couple of other alternatives come to mind in case you do not. > > That would help alot, it would certainly make it easier for then, i didn't know about views, i will rtfm. > 1. Do the mail merge in Python using a Word template. Then you can add any > kind of logic that you need to the merge. > > Can this be done in pure python? Bearing in mind that the server will be linux > 2. Add some kind of export function to your python UI that allows you to > export the data to an Excel sheet, CSV, or even another ODBC data > source (like another MySQL table or database that you might have > access to). > I have considered this one, ideally the file saving would be skipped, since it's only temporary and i am concerned that users may save many files mixing them up, or try to use old export files which are out of sync with the database. This is a community organisation with volunteers, so i expect technical competency to be low. However if i can send the data directly from python to office somehow i could avoid that issue. What would be perfect is an ODBC driver which connected via XMLRPC or some other simple protocol. Thanks for the help. -- > > http://mail.python.org/mailman/listinfo/python-list > -- "The UNIX system has a command, nice ... in order to be nice to the other users. Nobody ever uses it." - Andrew S. Tanenbaum -- "The UNIX system has a command, nice ... in order to be nice to the other users. Nobody ever uses it." - Andrew S. Tanenbaum -------------- next part -------------- An HTML attachment was scrubbed... URL: From sanjo_ie at yahoo.com Wed Nov 3 04:50:48 2010 From: sanjo_ie at yahoo.com (jk) Date: Wed, 3 Nov 2010 01:50:48 -0700 (PDT) Subject: Python documentation too difficult for beginners References: Message-ID: <0ba75a36-b9b9-4bb8-9aad-db6fc9a40135@r14g2000yqa.googlegroups.com> On Nov 2, 11:06?pm, Lawrence D'Oliveiro wrote: > In message > , jk > wrote: > > > This (http://epydoc.sourceforge.net/stdlib/) is what I'm talking > > about. > > Framesets? Is that really your idea of well-laid-out documentation? Using a > feature which has been derided (and dropped in HTML5) because of its effect > on usability and accessibility? No, the framesets suck, and I agree that Javadoc isn't perfect. Actually, I do think the PHP docs are the best I've found as a reference. Javadocs just need a few tweaks and they'd be better (an index at the top so you don't have to scroll down, no framesets, a search engine). Still think they're better than the python docs though. From __peter__ at web.de Wed Nov 3 04:51:46 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 03 Nov 2010 09:51:46 +0100 Subject: Py3: Import relative path module References: <044f2fb7-a6a9-4bb9-b2a6-8ee1d0c19612@u17g2000yqi.googlegroups.com> <4cce7768$0$29965$c3e8da3$5496439d@news.astraweb.com> <770dd3de-25f5-404c-a05a-7bdd2eb07179@26g2000yqv.googlegroups.com> <3e7dbd88-4d44-43fa-a0e2-6987c025ccdb@26g2000yqv.googlegroups.com> Message-ID: MRAB wrote: > On 03/11/2010 01:48, Gnarlodious wrote: >> I admit I don't understand any of what was said here. Or why it is so >> hard what I am trying to do. I searched Google for a few hours looking >> for a way to import a module from an absolute path, but that was a >> waste of time too. >> >> To reiterate, I am trying to import a Def function from a file one >> level up. Let's say relative import is unreasonable to expect from >> Python. If it is possible using an absolute path, please let me know >> how, in plain language. Otherwise I can continue to copy and paste my >> programming into several files. >> >> Thank you for any help. >> > After some experimentation (and Googling!) I think the problem is that > a module can do your relative import but a main script can't. > > Or, to put it another way, if __name__ is "__main__" then it won't work. Slightly generalized: have the importing module print its __name__. There has to be at least one dot in the name for from .. import whatever to succeed. From hniksic at xemacs.org Wed Nov 3 05:31:18 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Wed, 03 Nov 2010 10:31:18 +0100 Subject: functions, list, default parameters References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <8ivelpFif1U1@mid.individual.net> <4cca88bc$0$29987$c3e8da3$5496439d@news.astraweb.com> <8j1seqFa1eU2@mid.individual.net> <87tyjzippx.fsf@rudin.co.uk> Message-ID: <87oca6n47t.fsf@xemacs.org> Paul Rudin writes: > Terry Reedy writes: > >> Suppose I write an nasty C extension that mutates tuples. What then >> would be illegal about... > > Depends on exactly what we mean by legal. If immutability is part of the > language spec (rather than an artifact of a particular implementation) > then a compiler could assume immutability. And, indeed, it does exactly that. Tuples of constant literals are created at compilation time and reused across function invocations. Mutating a tuple using a C extension is "illegal" in that it breaks the rules of the system, by changing the semantics of valid code in unexpected ways. A more extreme example of this would be mutating the constant 0 or the empty tuple. From hniksic at xemacs.org Wed Nov 3 05:39:11 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Wed, 03 Nov 2010 10:39:11 +0100 Subject: Man pages and info pages References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> <024ef21a-9ef9-48a6-8372-1d66895583c3@v16g2000yqn.googlegroups.com> <87zktr5yze.fsf_-_@mithlond.arda> <877hgv2fg3.fsf@mithlond.arda> Message-ID: <87hbfyn3uo.fsf@xemacs.org> Teemu Likonen writes: > Enter Follow a link (down to node) > u up node level > h help (general how-to) > ? help (commands) > s search And don't forget: l last viewed page (aka "back") That one seems to be the info reader's best-kept secret. From contact at xavierho.com Wed Nov 3 05:57:27 2010 From: contact at xavierho.com (Xavier Ho) Date: Wed, 3 Nov 2010 19:57:27 +1000 Subject: What people are using to access this mailing list In-Reply-To: References: Message-ID: Gmail. -Xav On 3 November 2010 18:02, John Bond wrote: > Hope this isn't too O/T - I was just wondering how people read/send to this > mailing list, eg. normal email client, gmane, some other software or online > service? > > My normal inbox is getting unmanageable, and I think I need to find a new > way > of following this and other lists. > > Thanks for any suggestions. > > Cheers, JB. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dan.kluev at gmail.com Wed Nov 3 06:04:18 2010 From: dan.kluev at gmail.com (Daniel Kluev) Date: Wed, 3 Nov 2010 20:04:18 +1000 Subject: What people are using to access this mailing list In-Reply-To: References: Message-ID: I use gmail with according filters and labels, so each mailing list has its own label and is removed from inbox. -- With best regards, Daniel Kluev -------------- next part -------------- An HTML attachment was scrubbed... URL: From ddasilva at umd.edu Wed Nov 3 06:11:40 2010 From: ddasilva at umd.edu (Daniel da Silva) Date: Wed, 3 Nov 2010 06:11:40 -0400 Subject: Man pages and info pages In-Reply-To: <87hbfyn3uo.fsf@xemacs.org> References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> <024ef21a-9ef9-48a6-8372-1d66895583c3@v16g2000yqn.googlegroups.com> <87zktr5yze.fsf_-_@mithlond.arda> <877hgv2fg3.fsf@mithlond.arda> <87hbfyn3uo.fsf@xemacs.org> Message-ID: Guys, this really has nothing to do with python. On Wednesday, November 3, 2010, Hrvoje Niksic wrote: > Teemu Likonen writes: > >> ? ? Enter ? Follow a link (down to node) >> ? ? u ? ? ? up node level >> ? ? h ? ? ? help (general how-to) >> ? ? ? ? ? ? help (commands) >> ? ? s ? ? ? search > > And don't forget: > > ? ? ?l ? ? ? last viewed page (aka "back") > > That one seems to be the info reader's best-kept secret. > -- > http://mail.python.org/mailman/listinfo/python-list > From h.b.furuseth at usit.uio.no Wed Nov 3 06:27:05 2010 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: Wed, 03 Nov 2010 11:27:05 +0100 Subject: Python documentation too difficult for beginners References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano writes: > On Tue, 02 Nov 2010 03:42:22 -0700, jk wrote: >> The former is difficult to find (try searching for 'open' in the search >> box and see what you get). > > A fair point -- the built-in open comes up as hit #30, whereas searching > for open in the PHP page brings up fopen as hit #1. But the PHP search > also brings up many, many hits -- ten pages worth. > > But in any case, the Python search functionality could be smarter. If I > had a complaint about the docs, that would be it. Fortunately, I have > google :) Actually that was one of the hair-tearing attitudes I heard a web search guru complain about. The smartest part of the search engine is the people running it, so why not apply their brains directly? Read the log like you did, look for poor results (like "open"), put in exceptions by hand. This might be a fraction of the work it takes to program that kind of smarts into the engine. Or you might discover a group of exceptions to put in - like all Python keywords. That makes it at least partially programmed, which may be preferable. -- Hallvard From rustompmody at gmail.com Wed Nov 3 06:31:07 2010 From: rustompmody at gmail.com (rustom) Date: Wed, 3 Nov 2010 03:31:07 -0700 (PDT) Subject: Man pages and info pages References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> <024ef21a-9ef9-48a6-8372-1d66895583c3@v16g2000yqn.googlegroups.com> <87zktr5yze.fsf_-_@mithlond.arda> <877hgv2fg3.fsf@mithlond.arda> <87hbfyn3uo.fsf@xemacs.org> Message-ID: <1bdce24e-4406-44c5-9133-bfd0acd0283d@p1g2000yqm.googlegroups.com> On Nov 3, 3:11?pm, Daniel da Silva wrote: > Guys, this really has nothing to do with python. ?? python docs have nothing to do with python?? python docs by default on linux are read with info and many seem to find info unpleasant to use. Myself an old emacs user and cant say info helps me as much as google. However comparing info and man is also a bit strange. The printed python docs come to several thousand pages. Do we want them to be 1 manpage? a hundred? a thousand? From vgnulinux at gmail.com Wed Nov 3 06:47:44 2010 From: vgnulinux at gmail.com (VGNU Linux) Date: Wed, 3 Nov 2010 16:17:44 +0530 Subject: How to highlight Label/Text in tkinter ? In-Reply-To: References: Message-ID: I was able to solve the problem. But unable to use Label or Text widget. Any idea as to why focus does not work with Label or Text widget. Here is the program using button widget. from Tkinter import * import tkFont class DisplayFrame: """ Uses GUI to display contacts """ def __init__(self, root): self.b = Button(root, text="Peter Pan",font=("Arial",10,"bold"), anchor=W, justify=LEFT, relief=FLAT) self.b.pack(fill=BOTH) self.b.focus_set() self.b = Button(root, text="Marry Joe", font=("Arial",10,"bold"), anchor=W, justify=LEFT, relief=FLAT) self.b.pack(fill=BOTH) self.b = Button(root, text="Michael Kin", font=("Arial",10,"bold"), anchor=W, justify=LEFT, relief=FLAT) self.b.pack(fill=BOTH) self.b = Button(root, text="Jennifer McConelly", font=("Arial",10,"bold"), anchor=W, justify=LEFT, relief=FLAT) self.b.pack(fill=BOTH) self.b = Button(root, text="Jonathen Broady", font=("Arial",10,"bold"), anchor=W, justify=LEFT, relief=FLAT) self.b.pack(fill=BOTH) def handleReturn(event): event.widget["font"] = "Arial 16 bold" print event.widget.focus_get() nxtwid = event.widget.tk_focusNext() prewid = event.widget.tk_focusPrev() prewid["font"] = "Arial 10 bold" nxtwid.focus_set() if __name__ == '__main__': root = Tk() frame = DisplayFrame(root) root.bind("",handleReturn) root.mainloop() Regards, VGNU On Wed, Nov 3, 2010 at 12:02 PM, VGNU Linux wrote: > Hi, > I am writing a program teach myself python and tkinter. > Below given is a program which displays label with different fonts and > sizes. > How to highlight text and change font size if the up/down arrow keys are > pressed ? > from Tkinter import * > import tkFont > > class MyFrame(Frame): > > def __init__(self, root): > Frame.__init__(self, root) > self.txt = Label(self, text="Arial 10 bold", > font=("Arial",10,"bold")) > self.txt.grid(row=1,column=1) > self.txt = Label(self, text="Courier 12 bold", > font=("Courier",12,"bold")) > self.txt.grid(row=2,column=1) > self.txt = Label(self, text="Comic Sans MS 14 bold", font=("Comic > Sans MS",14,"bold")) > self.txt.grid(row=3,column=1) > self.txt = Label(self, text="Fixedsys 16 bold", > font=("Fixedsys",16,"bold")) > self.txt.grid(row=4,column=1) > self.txt = Label(self, text="MS Sans Serif 18 bold", font=("MS Sans > Serif",18,"bold")) > self.txt.grid(row=5,column=1) > self.txt = Label(self, text="MS Serif, Symbol 20 bold", font=("MS > Serif, Symbol",20,"bold")) > self.txt.grid(row=6,column=1) > self.txt = Label(self, text="System 22 bold", > font=("System",22,"bold")) > self.txt.grid(row=7,column=1) > self.txt = Label(self, text="Verdana 24 bold", > font=("Verdana",24,"bold")) > self.txt.grid(row=8,column=1) > > if __name__ == '__main__': > root = Tk() > c = MyFrame(root) > c.pack(fill=BOTH, expand=1) > root.mainloop() > > any help? > > Regards, > VGNU > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Wed Nov 3 07:17:32 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 03 Nov 2010 11:17:32 GMT Subject: What people are using to access this mailing list References: Message-ID: <4cd144cc$0$29966$c3e8da3$5496439d@news.astraweb.com> On Wed, 03 Nov 2010 08:02:29 +0000, John Bond wrote: > Hope this isn't too O/T - I was just wondering how people read/send to > this mailing list, eg. normal email client, gmane, some other software > or online service? Usenet via my ISP, on comp.lang.python. -- Steven From python.list at tim.thechases.com Wed Nov 3 07:25:07 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 03 Nov 2010 06:25:07 -0500 Subject: What people are using to access this mailing list In-Reply-To: References: Message-ID: <4CD14693.6070104@tim.thechases.com> On 11/03/10 03:02, John Bond wrote: > Hope this isn't too O/T - I was just wondering how people read/send to this > mailing list, eg. normal email client, gmane, some other software or online > service? > > My normal inbox is getting unmanageable, and I think I need to find a new way > of following this and other lists. Currently using Gmane NNTP via Thunderbird. If TB offered the ability to kill-thread normal email (the "kill thread" functionality only seems to work in newsgroups), I'd stick to getting them via email, filtered into my Python folder. -tkc From cs at zip.com.au Wed Nov 3 07:32:29 2010 From: cs at zip.com.au (Cameron Simpson) Date: Wed, 3 Nov 2010 22:32:29 +1100 Subject: What people are using to access this mailing list In-Reply-To: References: Message-ID: <20101103113229.GA6045@cskk.homeip.net> On 03Nov2010 08:02, John Bond wrote: | Hope this isn't too O/T - I was just wondering how people read/send to this | mailing list, eg. normal email client, gmane, some other software or online | service? | | My normal inbox is getting unmanageable, and I think I need to find a new way | of following this and other lists. I use mutt to read my python folder. I use getmail to collect email via POP and deliver via procmail, which files this list (and python-ideas etc) into a "python" folder, out of my main inbox. -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ It is impossible to travel faster than light, and certainly not desirable as ones hat keeps blowing off. - Woody Allen From steve at REMOVE-THIS-cybersource.com.au Wed Nov 3 07:36:20 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 03 Nov 2010 11:36:20 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> On Tue, 02 Nov 2010 19:26:56 +0000, Tim Harig wrote: > I agree with Seebs, Python is the only language I know that promotes the > use of spaces over tabs; Really? I'm not aware of *any* language that promotes tabs over spaces. I thought the tabs vs spaces war was mostly won by spaces over a decade ago (apart from a few plucky freedom fighters who will never surrender). > and there are equally picky syntaxs (ie, > Makefiles) that mandate the use of tabs. I personally prefer tabs as it > lets *me* decide how far the apparent indentations are in the code. You > may like four spaces; but, I agree with Linus Torvalds that eight spaces > is much clearer. The beautiful thing about tabs is that we can both set > our tab stops to match our own viewing preferences. Actually I agree with you about tabs. I think tabs are far more logical and sensible. But I'm stuck with broken tools that don't deal with tabs, and with PEP 8 that mandates the use of spaces, and popular opinion that says make is crazy for using tabs. So, I bite my lip, stop using broken tools that make dealing with space- indents painful, and just deal with it. And you know what? It's not so bad after all. > This is Python's most noticable blemish outside of the community. > Everybody knows that Python is the language that forces you to use a > particular style of formatting; and, that is a turn-off for many people. Their loss. I don't miss the flame wars over the One True Brace Style. There are enough disagreements over coding conventions without adding to them. > It is a big mistake that whenever the issue arises, the community > effectively attacks anybody who might have disagreements with the > tradeoffs made for the Python language. This tends to set people on the > defensive and gives them a bad taste about the language as a whole. That's very insightful. Why don't you apply some of that insight to the other side? It is *incredibly* annoying to see the same old people making the same old snide remarks about the same old issues over and over again, particularly when: * it's not an issue for thousands of other users; * even if it were an issue, if you use the right tool for the job, the issue disappears; * and even if there is no right tool for the job, the feature isn't going to change; * and even if it would change, the people doing the whinging aren't going to volunteer to make the change. > It would be much better if the community would simply acknowledge that > this is a tradeoff the the language has made and one which is often > misunderstood by many first time Python programmers. Been there, done that. This is *old news*. -- Steven From steve at REMOVE-THIS-cybersource.com.au Wed Nov 3 07:37:03 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 03 Nov 2010 11:37:03 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: <4cd1495f$0$29966$c3e8da3$5496439d@news.astraweb.com> On Wed, 03 Nov 2010 12:01:06 +1300, Lawrence D'Oliveiro wrote: > In message , Grant Edwards wrote: >> Other languages have similar problems if you remove salient bits of >> syntax before comparing two source files files. > > But other languages don?t make those ?salient bits of syntax? invisible. > I.e. they are actually ?salient?. (1) Indentation is visible. Compare: This line has leading visible whitespace. This line has leading invisible characters. See the difference? (2) Salient doesn't mean visible. It means "prominent, conspicuous, noticeable". Something can be conspicuous by its absence; conspicuous whitespace can be very noticeable. -- Steven From tinnews at isbd.co.uk Wed Nov 3 07:54:34 2010 From: tinnews at isbd.co.uk (tinnews at isbd.co.uk) Date: Wed, 3 Nov 2010 11:54:34 +0000 Subject: What people are using to access this mailing list References: Message-ID: John Bond wrote: > Hope this isn't too O/T - I was just wondering how people read/send to this > mailing list, eg. normal email client, gmane, some other software or online > service? > > My normal inbox is getting unmanageable, and I think I need to find a new way > of following this and other lists. > > Thanks for any suggestions. > I read it as a Usenet newsgroup, far better than as an E-Mail list IMHO. Wherever I have a choice (quite a few mailing lists are 'gatewayed' with newsgroups) I choose the newsgroup, newsreaders are much more able to manage this sort of discussion group. Alternatively, if you want to stay with the E-Mail format then use some sort of filtering that will allow you to send each mailing list to its own folder. I do this with a home-grown python script but most E-Mail programs have the ability to do this themselves nowadays. -- Chris Green From lists at asd-group.com Wed Nov 3 07:58:07 2010 From: lists at asd-group.com (John Bond) Date: Wed, 03 Nov 2010 11:58:07 +0000 Subject: What people are using to access this mailing list In-Reply-To: <4cd144cc$0$29966$c3e8da3$5496439d@news.astraweb.com> References: <4cd144cc$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4CD14E4F.1020508@asd-group.com> On 3/11/2010 11:17 AM, Steven D'Aprano wrote: > On Wed, 03 Nov 2010 08:02:29 +0000, John Bond wrote: > >> Hope this isn't too O/T - I was just wondering how people read/send to >> this mailing list, eg. normal email client, gmane, some other software >> or online service? > Usenet via my ISP, on comp.lang.python. > > > Using what client (or web client)? Cheers, JB From paul.nospam at rudin.co.uk Wed Nov 3 08:01:58 2010 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Wed, 03 Nov 2010 12:01:58 +0000 Subject: What people are using to access this mailing list References: <4cd144cc$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87r5f2wr7t.fsf@rudin.co.uk> John Bond writes: > On 3/11/2010 11:17 AM, Steven D'Aprano wrote: >> On Wed, 03 Nov 2010 08:02:29 +0000, John Bond wrote: >> >>> Hope this isn't too O/T - I was just wondering how people read/send to >>> this mailing list, eg. normal email client, gmane, some other software >>> or online service? >> Usenet via my ISP, on comp.lang.python. >> >> >> > Using what client (or web client)? > Emacs, of course :-; From roy at panix.com Wed Nov 3 08:17:46 2010 From: roy at panix.com (Roy Smith) Date: Wed, 03 Nov 2010 08:17:46 -0400 Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> Message-ID: In article , Lawrence D'Oliveiro wrote: > > I suppose readability is in the eye of the reader, but, yes, I agree > > that I have split this into two parts. The parts are > > > > 1) The table of data > > > > 2) The looping construct > > But the table of data makes no sense outside of the looping construct. That > table does nothing other than define the bounds of the loop. I look at it the other way around. The data is the important part, and the loop is just plumbing. Once I've got the data in an easy to manage form, I can do lots of things with it. I could iterate over it (as originally written) with a "for" loop. I could refactor the code to pass the data to some function which processes it. I could refactor it a different way and use map() to process the data. > Which means you don???t understand the purpose of the code at all. Go look at > it in its entirety, and you???ll see what I mean. > > That URL takes me to a github page. Can you be more specific about which file I should be looking at? I did take a look at one file, overscan_margins.py. Here's a few stylistic comments. 1) I like the fact that the file starts out with a block comment describing what it does, how to install it, and how to run it. Documentation is A Good Thing, and most people don't do enough of it. 2) You have provided comments for each function, such as (lines 36-37): def NewLayer(svg, LayerName) : # adds a new layer to the SVG document and returns it. This is good, but would be even more useful if it were turned into a docstring, such as: def NewLayer(svg, LayerName) : "adds a new layer to the SVG document and returns it." For the same amount of typing, you now have a piece of text which can be retrieved by help() and processed in various useful ways with other tools. 3) I find the deeply nested style you use very difficult to read. For example, on lines 80-103. As I read this, here's how I mentally process it: "OK, here's a function call (minor stumble over the open paren not being on the same line as the function name, but I can get past that). The first argument is TheLayer. The second argument is whatever inkex.addNS() returns. Umm..." At that point, I can't scan quickly any more. It took me a while to understand that the third argument was a dictionary. The nesting is just too deep for me to continue to mentally hold the context of "I'm looking at a function call and gathering up the arguments" while I drill down through the dictionary structure to understand what it is. This would be a lot easier to scan if it were written as: inkex.etree.SubElement(TheLayer, inkex.addNS("path", "svg"), stuff) where "stuff" is the big complicated dictionary, which is defined before the call. Of course, "stuff" is not a useful name for it, but not being familiar with the domain, I don't know what a useful name would be. Hmmm, googling for inkex.etree.SubElement found me some Inkscape documentation. Looks like "attribs" would be a good name for the dictionary, since that's the name they use in the docs. In fact, if you look at http://tinyurl.com/24wa3q8, you'll see they use exactly the style I describe above (modulo whitespace). From awilliam at whitemice.org Wed Nov 3 08:26:48 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Wed, 03 Nov 2010 08:26:48 -0400 Subject: What people are using to access this mailing list In-Reply-To: <4cd144cc$0$29966$c3e8da3$5496439d@news.astraweb.com> References: <4cd144cc$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1288787208.3988.2.camel@linux-yu4c.site> On Wed, 2010-11-03 at 11:17 +0000, Steven D'Aprano wrote: > On Wed, 03 Nov 2010 08:02:29 +0000, John Bond wrote: > > Hope this isn't too O/T - I was just wondering how people read/send to > > this mailing list, eg. normal email client, gmane, some other software > > or online service? GNOME's awesome Evolution mail (IMAP) client. Via a SIEVE script on a Cyrus IMAP server the mailist traffic is automatically placed in a folder. Then it can be read with any IMAP traffic. Delete the silly traffic and that folder becomes an invaluable resource of useful information [no wading through pages and pages of search-result-swill]. -- Adam Tauno Williams LPIC-1, Novell CLA OpenGroupware, Cyrus IMAPd, Postfix, OpenLDAP, Samba From roy at panix.com Wed Nov 3 08:31:03 2010 From: roy at panix.com (Roy Smith) Date: Wed, 03 Nov 2010 08:31:03 -0400 Subject: What people are using to access this mailing list References: Message-ID: In article , John Bond wrote: > Hope this isn't too O/T - I was just wondering how people read/send to this > mailing list, eg. normal email client, gmane, some other software or online > service? Usenet group comp.lang.python. Most of the time, using MT-NewsWatcher on my Mac. Occasionally via the Google Groups web interface. From neilc at norwich.edu Wed Nov 3 08:42:49 2010 From: neilc at norwich.edu (Neil Cerutti) Date: 3 Nov 2010 12:42:49 GMT Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> <87aalrjkty.fsf@benfinney.id.au> Message-ID: <8jd3m9Fr55U7@mid.individual.net> On 2010-11-03, Ben Finney wrote: > I would do the same, but fix the indentation. Making > indentation depend on the *length* of the previous line is > needlessly making a maintenance burden. > > Instead, I'd do:: > > styles = [ > ("normal", "image", MainWindow.ColorsNormalList), > ("highlighted", "highlight", MainWindow.ColorsHighlightedList), > ("selected", "select", MainWindow.ColorsSelectedList)] Agreed, except cute stuff like putting those three items in columns is just as bad. Code should be utilitarian rather than ornate, Shaker rather than Victorian. -- Neil Cerutti From roy at panix.com Wed Nov 3 08:48:38 2010 From: roy at panix.com (Roy Smith) Date: Wed, 03 Nov 2010 08:48:38 -0400 Subject: Subclassing unittest.TestCase? Message-ID: I'm using Python 2.6, with unittest2 imported as unittest. I'm writing a test suite for a web application. There is a subclass of TestCase for each basic page type. One thing that's in common between all the pages is that every page must have a valid copyright notice. It seems like the logical thing would be to put the common test(s) in a subclass unittest.TestCase and have all my real test cases derive from that: class CommonTestCase(unittest.TestCase): def test_copyright(self): self.assert_(find copyright notice in DOM tree) class HomepageTestCase(CommonTestCase): def setUp(self): self.url = "http://site.com" def test_whatever(self): self.assert_(whatever) This works fine as far as HomepageTestCase running test_copyright() and test_whatever(). The problem is that CommonTestCase *also* runs test_copyright(), which fails because there's no setUp(), and thus no retrieved page for it to work on. The hack that I came up with is: class CommonTestCase(unittest.TestCase): def test_copyright(self): if self.__class__.__name__ == 'CommonTestCase': return self.assert_(find copyright notice in DOM tree) which works, but it's ugly. It also counts CommonTestCase.test_copyright() as passing, which messes up the statistics. Is there a cleaner way to define some common test methods which all of my test cases can inherit, without having them be run in the base class? From invalid at invalid.invalid Wed Nov 3 08:57:46 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 3 Nov 2010 12:57:46 +0000 (UTC) Subject: Ways of accessing this mailing list? References: Message-ID: On 2010-11-02, John Bond wrote: > Hope this isn't too O/T - I was just wondering how people read/send to > this mailing list, eg. normal email client, gmane, some other software > or online service? > > My normal inbox is getting unmanageable, and I think I need to find a > new way of following this and other lists. Point an NNTP client at new.gmane.org. This "list" is also a Usenet newsgroup (comp.lang.python), and there are a number of cheap/low-cost text-only Usenet providers. -- Grant Edwards grant.b.edwards Yow! ... or were you at driving the PONTIAC that gmail.com HONKED at me in MIAMI last Tuesday? From invalid at invalid.invalid Wed Nov 3 09:00:47 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 3 Nov 2010 13:00:47 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: On 2010-11-03, D'Arcy J.M. Cain wrote: > On 03 Nov 2010 01:20:40 GMT > Seebs wrote: >> However, I have probably seen all of two or three bugs ever related to >> mis-indented C, and I've had various things screw up or wreck indentation > > Really? I have never seen bugs in C related to indentation. I have > seen plenty related to braces. Same here. > What I have seen is bugs hidden by the indentation not matching the > block structure. Wrong indentation in Python *is* a bug. There's no > other visual signal to hide the error. Exactly. -- Grant Edwards grant.b.edwards Yow! I selected E5 ... but at I didn't hear "Sam the Sham gmail.com and the Pharoahs"! From invalid at invalid.invalid Wed Nov 3 09:02:22 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 3 Nov 2010 13:02:22 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: On 2010-11-03, Seebs wrote: > On 2010-11-02, Grant Edwards wrote: >> Huh? Indentation is invisible? You can't see the indentation in >> Python source code? > > The difference between tabs and spaces is invisible on a great > number of the devices on which people display code. Allowing a mixture of tabs/spaces for indentation was a mistake, and pretty much everybody agrees on that. However, that isn't what's being discussed. > Indentation is visible, but the underlying structure of it may not > be. (It's worse than that, because for instance " " is quite hard to > distinguish from the quite similar " ".) And at least one of them is > clearly wrong. -- Grant Edwards grant.b.edwards Yow! An air of FRENCH FRIES at permeates my nostrils!! gmail.com From invalid at invalid.invalid Wed Nov 3 09:05:23 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 3 Nov 2010 13:05:23 +0000 (UTC) Subject: What people are using to access this mailing list References: <4cd144cc$0$29966$c3e8da3$5496439d@news.astraweb.com> <87r5f2wr7t.fsf@rudin.co.uk> Message-ID: On 2010-11-03, Paul Rudin wrote: > John Bond writes: > >> On 3/11/2010 11:17 AM, Steven D'Aprano wrote: >>> On Wed, 03 Nov 2010 08:02:29 +0000, John Bond wrote: >>> >>>> Hope this isn't too O/T - I was just wondering how people read/send to >>>> this mailing list, eg. normal email client, gmane, some other software >>>> or online service? >>> Usenet via my ISP, on comp.lang.python. >>> >> Using what client (or web client)? > > Emacs, of course :-; Slrn, of course. -- Grant Edwards grant.b.edwards Yow! I am having FUN... at I wonder if it's NET FUN or gmail.com GROSS FUN? From gnarlodious at gmail.com Wed Nov 3 09:05:43 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Wed, 3 Nov 2010 06:05:43 -0700 (PDT) Subject: Py3: Import relative path module References: <044f2fb7-a6a9-4bb9-b2a6-8ee1d0c19612@u17g2000yqi.googlegroups.com> <4cce7768$0$29965$c3e8da3$5496439d@news.astraweb.com> <770dd3de-25f5-404c-a05a-7bdd2eb07179@26g2000yqv.googlegroups.com> <3e7dbd88-4d44-43fa-a0e2-6987c025ccdb@26g2000yqv.googlegroups.com> Message-ID: <01c6e36a-c4e0-499a-adc1-cb61d7b53725@r14g2000yqa.googlegroups.com> On Nov 3, 2:51?am, Peter Otten wrote: > Slightly generalized: have the importing module print its __name__. There > has to be at least one dot in the name for > > from .. import whatever > > to succeed. Just spent about 3 hours trying every permutation I could think of, and searching Google for exactly how to do it, but all I get is: ValueError: Attempted relative import in non-package How do I import a module so that a dot will appear in its name? -- Gnarlie From __peter__ at web.de Wed Nov 3 09:42:10 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 03 Nov 2010 14:42:10 +0100 Subject: Py3: Import relative path module References: <044f2fb7-a6a9-4bb9-b2a6-8ee1d0c19612@u17g2000yqi.googlegroups.com> <4cce7768$0$29965$c3e8da3$5496439d@news.astraweb.com> <770dd3de-25f5-404c-a05a-7bdd2eb07179@26g2000yqv.googlegroups.com> <3e7dbd88-4d44-43fa-a0e2-6987c025ccdb@26g2000yqv.googlegroups.com> <01c6e36a-c4e0-499a-adc1-cb61d7b53725@r14g2000yqa.googlegroups.com> Message-ID: Gnarlodious wrote: > On Nov 3, 2:51 am, Peter Otten wrote: > >> Slightly generalized: have the importing module print its __name__. There >> has to be at least one dot in the name for >> >> from .. import whatever >> >> to succeed. > > Just spent about 3 hours trying every permutation I could think of, > and searching Google for exactly how to do it, but all I get is: > > ValueError: Attempted relative import in non-package > > How do I import a module so that a dot will appear in its name? Make sure the no path in sys.path leads into a directory that contains an __init__.py. In particular, ensure that you aren't invoking the python interpreter from a working directory that contains an __init__.py and that the main script is in a directory that doesn't contain an __init__.py. Peter From dan at catfolks.net Wed Nov 3 09:47:37 2010 From: dan at catfolks.net (Dan M) Date: Wed, 03 Nov 2010 08:47:37 -0500 Subject: What people are using to access this mailing list References: Message-ID: On Wed, 03 Nov 2010 08:02:29 +0000, John Bond wrote: > Hope this isn't too O/T - I was just wondering how people read/send to > this mailing list, eg. normal email client, gmane, some other software > or online service? > > My normal inbox is getting unmanageable, and I think I need to find a > new way of following this and other lists. > > Thanks for any suggestions. > > Cheers, JB. Pan newsreader From __peter__ at web.de Wed Nov 3 09:50:45 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 03 Nov 2010 14:50:45 +0100 Subject: Py3: Import relative path module References: <044f2fb7-a6a9-4bb9-b2a6-8ee1d0c19612@u17g2000yqi.googlegroups.com> <4cce7768$0$29965$c3e8da3$5496439d@news.astraweb.com> <770dd3de-25f5-404c-a05a-7bdd2eb07179@26g2000yqv.googlegroups.com> <3e7dbd88-4d44-43fa-a0e2-6987c025ccdb@26g2000yqv.googlegroups.com> <01c6e36a-c4e0-499a-adc1-cb61d7b53725@r14g2000yqa.googlegroups.com> Message-ID: Peter Otten wrote: > Gnarlodious wrote: > >> On Nov 3, 2:51 am, Peter Otten wrote: >> >>> Slightly generalized: have the importing module print its __name__. >>> There has to be at least one dot in the name for >>> >>> from .. import whatever >>> >>> to succeed. >> >> Just spent about 3 hours trying every permutation I could think of, >> and searching Google for exactly how to do it, but all I get is: >> >> ValueError: Attempted relative import in non-package >> >> How do I import a module so that a dot will appear in its name? > > Make sure the no path in sys.path leads into a directory that contains an > __init__.py. In particular, ensure that you aren't invoking the python > interpreter from a working directory that contains an __init__.py and that > the main script is in a directory that doesn't contain an __init__.py. > > Peter Here's a working example that you can use as a starting point: $ tree . |-- alpha | |-- __init__.py | |-- beta | | |-- __init__.py | | `-- one.py | `-- two.py `-- main.py 2 directories, 5 files $ cat main.py import alpha.beta.one $ cat alpha/beta/one.py from ..alpha import two $ cat alpha/two.py print "success!" $ python main.py success! Peter From email at invalid.net Wed Nov 3 09:53:18 2010 From: email at invalid.net (QoS) Date: Wed, 03 Nov 2010 13:53:18 GMT Subject: What people are using to access this mailing list References: Message-ID: Dan M wrote in message-id: > > On Wed, 03 Nov 2010 08:02:29 +0000, John Bond wrote: > > > Hope this isn't too O/T - I was just wondering how people read/send to > > this mailing list, eg. normal email client, gmane, some other software > > or online service? > > > > My normal inbox is getting unmanageable, and I think I need to find a > > new way of following this and other lists. > > > > Thanks for any suggestions. > > > > Cheers, JB. > > Pan newsreader Using Perl and NewsSurfer to read this newsgroup (check headers). Thanks, J From __peter__ at web.de Wed Nov 3 10:02:34 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 03 Nov 2010 15:02:34 +0100 Subject: Py3: Import relative path module References: <044f2fb7-a6a9-4bb9-b2a6-8ee1d0c19612@u17g2000yqi.googlegroups.com> <4cce7768$0$29965$c3e8da3$5496439d@news.astraweb.com> <770dd3de-25f5-404c-a05a-7bdd2eb07179@26g2000yqv.googlegroups.com> <3e7dbd88-4d44-43fa-a0e2-6987c025ccdb@26g2000yqv.googlegroups.com> <01c6e36a-c4e0-499a-adc1-cb61d7b53725@r14g2000yqa.googlegroups.com> Message-ID: Peter Otten wrote: > Peter Otten wrote: > >> Gnarlodious wrote: >> >>> On Nov 3, 2:51 am, Peter Otten wrote: >>> >>>> Slightly generalized: have the importing module print its __name__. >>>> There has to be at least one dot in the name for >>>> >>>> from .. import whatever >>>> >>>> to succeed. >>> >>> Just spent about 3 hours trying every permutation I could think of, >>> and searching Google for exactly how to do it, but all I get is: >>> >>> ValueError: Attempted relative import in non-package >>> >>> How do I import a module so that a dot will appear in its name? >> >> Make sure the no path in sys.path leads into a directory that contains an >> __init__.py. In particular, ensure that you aren't invoking the python >> interpreter from a working directory that contains an __init__.py and >> that the main script is in a directory that doesn't contain an >> __init__.py. >> >> Peter > > Here's a working example that you can use as a starting point: > > $ tree > . > |-- alpha > | |-- __init__.py > | |-- beta > | | |-- __init__.py > | | `-- one.py > | `-- two.py > `-- main.py > > 2 directories, 5 files > $ cat main.py > import alpha.beta.one > $ cat alpha/beta/one.py > from ..alpha import two > $ cat alpha/two.py > print "success!" > $ python main.py > success! Hmm, now I'm puzzled myself. > $ cat alpha/beta/one.py > from ..alpha import two That line should have been from .. import two For some reason (bug?) it seems to work with and without the extra alpha. Peter From felipe.bastosn at gmail.com Wed Nov 3 10:15:36 2010 From: felipe.bastosn at gmail.com (Felipe Bastos Nunes) Date: Wed, 3 Nov 2010 12:15:36 -0200 Subject: Learning book recommendation? In-Reply-To: <1053302592-1288705850-cardhu_decombobulator_blackberry.rim.net-148438442-@bda480.bisx.prod.on.blackberry> References: <1053302592-1288705850-cardhu_decombobulator_blackberry.rim.net-148438442-@bda480.bisx.prod.on.blackberry> Message-ID: The pyschools dot com have so many exercises that 'forces' you to learn. It shows some results, explains the algorithm and checks the results of your code. 2010/11/2, brf256 at gmail.com : > Hey there, > > I would reccomend a non-programmers tutorial to python by Josh coglatti and > its a free wiki book. Also I would recommend byte into python. Both are > great for beginers. Best of luck! > > -- Braden Faulkner > Sent wirelessly from my BlackBerry device on the Bell network. > Envoy? sans fil par mon terminal mobile BlackBerry sur le r?seau de Bell. > -- > http://mail.python.org/mailman/listinfo/python-list > -- Felipe Bastos Nunes From __peter__ at web.de Wed Nov 3 10:16:36 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 03 Nov 2010 15:16:36 +0100 Subject: Subclassing unittest.TestCase? References: Message-ID: Roy Smith wrote: > I'm using Python 2.6, with unittest2 imported as unittest. > > I'm writing a test suite for a web application. There is a subclass of > TestCase for each basic page type. One thing that's in common between > all the pages is that every page must have a valid copyright notice. It > seems like the logical thing would be to put the common test(s) in a > subclass unittest.TestCase and have all my real test cases derive from > that: > > class CommonTestCase(unittest.TestCase): > def test_copyright(self): > self.assert_(find copyright notice in DOM tree) > > class HomepageTestCase(CommonTestCase): > def setUp(self): > self.url = "http://site.com" > > def test_whatever(self): > self.assert_(whatever) > > This works fine as far as HomepageTestCase running test_copyright() and > test_whatever(). The problem is that CommonTestCase *also* runs > test_copyright(), which fails because there's no setUp(), and thus no > retrieved page for it to work on. > > The hack that I came up with is: > > class CommonTestCase(unittest.TestCase): > def test_copyright(self): > if self.__class__.__name__ == 'CommonTestCase': > return > self.assert_(find copyright notice in DOM tree) > > which works, but it's ugly. It also counts > CommonTestCase.test_copyright() as passing, which messes up the > statistics. Is there a cleaner way to define some common test methods > which all of my test cases can inherit, without having them be run in > the base class? Remove the base class from the module with del CommonTestCase before you invoke unittest.main(). Peter From mail at timgolden.me.uk Wed Nov 3 10:48:55 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 03 Nov 2010 14:48:55 +0000 Subject: problem with opening a new python program in a new window (and keeping track of the process) In-Reply-To: References: Message-ID: <4CD17657.7090307@timgolden.me.uk> On 02/11/2010 20:55, Zak Kinion wrote: > What I want to do: launch seperate python programs from one main > program (multi-threading will not achieve this because the mechanize > library uses one shared global opener object which will not suit my > needs) I want the scripts launched to be in seperate windows that i > can see the output of on screen, seperate processes. I can accomplish > this in win32 by: > > import subprocess; > args = ["cmd", "/c", "START", "python", "myScript.py"]; > process1 = subprocess.Popen(args, shell=False); Pass CREATE_NEW_CONSOLE as one of the creationflags: import os, sys import subprocess processes = [] cmd = [sys.executable, "-c", "import os; print os.getpid (); raw_input ()"] for i in range (3): processes.append (subprocess.Popen (cmd, creationflags=subprocess.CREATE_NEW_CONSOLE)) # # Keep looping round to see the current status # while True: for p in processes: print p.poll () raw_input () TJG From bruno.42.desthuilliers at websiteburo.invalid Wed Nov 3 10:58:27 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 03 Nov 2010 15:58:27 +0100 Subject: functions, list, default parameters In-Reply-To: References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <20101021235138.609fe668@geekmail.INVALID> Message-ID: <4cd1788b$0$5231$426a74cc@news.free.fr> Lawrence D'Oliveiro a ?crit : > In message <20101021235138.609fe668 at geekmail.INVALID>, Andreas Waldenburger > wrote: > >> While not very commonly needed, why should a shared default argument be >> forbidden? > > Because it?s safer to disallow it than to allow it. Then there are quite a few python features (or misfeatures depending on your personal tastes and whatnot) that should be "disabled" too. What about rebinding some_object.__class__ ?-) From theimmortalbum at gmail.com Wed Nov 3 11:30:00 2010 From: theimmortalbum at gmail.com (T.J. Simmons) Date: Wed, 3 Nov 2010 10:30:00 -0500 Subject: Serializing a user-defined class Message-ID: Hi all, got a question regarding serializing classes that I've defined. I have some classes like class Foo: def __init__(self, x, y): self.x = x, self.y = y then a class that can contain multiple Foos, such as: class Bar: def __init__(self): self.foos = [Foo(a, b), Foo(1, 2)] While that's a gross oversimplification of the real structure (it gets much, much more nested than that), that's a pretty decent overview. The actual data for this is coming from a pseudo-XML file without any actual structure, so I wrote a parser according to the spec given to me, so I now have all the data in a series of classes I've defined, with actual structure. What I'm wanting to do is take this data I have and spit it out into JSON, but I really don't see a good way (I'm new to Python, this is my first real project with it). I've defined a method in Foo, such as: def toDict(self): return dict(x = self.x, y = self.y) but that obviously isn't going to work out like I hope when I try to serialize Bar, with the multiple Foos. Does anyone have a great way of doing this? This has been a pretty much non-stop learning/codefest the past few days and I'm out of ideas for this, which is the last part of the project. Let me know if I can clarify in any way. Thanks, T.J. -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Wed Nov 3 11:35:33 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 3 Nov 2010 08:35:33 -0700 Subject: Serializing a user-defined class In-Reply-To: References: Message-ID: On Wed, Nov 3, 2010 at 8:30 AM, T.J. Simmons wrote: > Hi all, got a question regarding serializing classes that I've defined. I > have some classes like > class Foo: > ?? ? def __init__(self, x, y): > ?? ? ? ? ?self.x = x, self.y = y > then a class that can contain multiple Foos, such as: > class Bar: > ?? ? def __init__(self): > ?? ? ? ? ?self.foos = [Foo(a, b), Foo(1, 2)] > > While that's a gross oversimplification of the real structure (it gets much, > much more nested than that), that's a pretty decent overview. The actual > data for this is coming from a pseudo-XML file without any actual structure, > so I wrote a parser according to the spec given to me, so I now have all the > data in a series of classes I've defined, with actual structure. > What I'm wanting to do is take this data I have and spit it out into JSON, > but I really don't see a good way (I'm new to Python, this is my first real > project with it). Did you google for "python json"? The std lib `json` module is the very first hit: http://docs.python.org/library/json.html For future reference, here's the Global Module Index: http://docs.python.org/modindex.html Cheers, Chris -- http://blog.rebertia.com From darcy at druid.net Wed Nov 3 11:38:11 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Wed, 3 Nov 2010 11:38:11 -0400 Subject: What people are using to access this mailing list In-Reply-To: References: Message-ID: <20101103113811.270c1236.darcy@druid.net> On Wed, 3 Nov 2010 08:02:29 +0000 (UTC) John Bond wrote: > Hope this isn't too O/T - I was just wondering how people read/send to this It is completely off topic. What you need to do is research your own email client to see how to filter mailing lists into their own folders. Failing that look for a forum dedicated to your email client. There is nothing specific about Python in this regard. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From lists at asd-group.com Wed Nov 3 11:53:41 2010 From: lists at asd-group.com (John Bond) Date: Wed, 03 Nov 2010 15:53:41 +0000 Subject: What people are using to access this mailing list In-Reply-To: <20101103113811.270c1236.darcy@druid.net> References: <20101103113811.270c1236.darcy@druid.net> Message-ID: <4CD18585.7020207@asd-group.com> On 3/11/2010 3:38 PM, D'Arcy J.M. Cain wrote: > On Wed, 3 Nov 2010 08:02:29 +0000 (UTC) > John Bond wrote: >> Hope this isn't too O/T - I was just wondering how people read/send to this > It is completely off topic. What you need to do is research your own > email client to see how to filter mailing lists into their own > folders. Failing that look for a forum dedicated to your email > client. There is nothing specific about Python in this regard. > I know how to do that, thanks, but I was looking at broader options. Apologies to anyone whose time has been wasted by this heinous request, and thanks to those who have responded and given me ideas. I hope they'll help me better contribute to this (Python) list. Cheers, JB From gnarlodious at gmail.com Wed Nov 3 11:59:21 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Wed, 3 Nov 2010 08:59:21 -0700 (PDT) Subject: Py3: decode subprocess output References: Message-ID: <6c284fea-0831-4d48-b244-9c7ba1856908@c20g2000yqj.googlegroups.com> OK, it turns out I had to tweak the parsing minimally for Python3: 1) Substrings such as st[5] no longer work (returns an ascii number), instead st[5:6] selects one character 2) Replacements need to specified as bytes: s.replace('R','*') change to s.replace(b'R',b'*') So I think this problem is solved. -- Gnarlie From lists at asd-group.com Wed Nov 3 12:04:40 2010 From: lists at asd-group.com (John Bond) Date: Wed, 03 Nov 2010 16:04:40 +0000 Subject: Serializing a user-defined class In-Reply-To: References: Message-ID: <4CD18818.70109@asd-group.com> On 3/11/2010 3:30 PM, T.J. Simmons wrote: > Hi all, got a question regarding serializing classes that I've > defined. I have some classes like > > class Foo: > def __init__(self, x, y): > self.x = x, self.y = y > > then a class that can contain multiple Foos, such as: > > class Bar: > def __init__(self): > self.foos = [Foo(a, b), Foo(1, 2)] > > > While that's a gross oversimplification of the real structure (it gets > much, much more nested than that), that's a pretty decent overview. > The actual data for this is coming from a pseudo-XML file without any > actual structure, so I wrote a parser according to the spec given to > me, so I now have all the data in a series of classes I've defined, > with actual structure. > > What I'm wanting to do is take this data I have and spit it out into > JSON, but I really don't see a good way (I'm new to Python, this is my > first real project with it). > > I've defined a method in Foo, such as: > > def toDict(self): > return dict(x = self.x, y = self.y) > > but that obviously isn't going to work out like I hope when I try to > serialize Bar, with the multiple Foos. > > Does anyone have a great way of doing this? This has been a pretty > much non-stop learning/codefest the past few days and I'm out of ideas > for this, which is the last part of the project. > > Let me know if I can clarify in any way. > > Thanks, > T.J. Python has a JSON lib that may be what you want, alternatively you could have a common base class with a method that iterates through its own member variables (see dir() function) as key/value pairs, recursing when it finds further instances of that base class (see isinstance() function). That would let you iterate through all member variables in the object hierarchy from the top level object, and do what you wish with them. I'm sure there are other ways too. Cheers, JB -------------- next part -------------- An HTML attachment was scrubbed... URL: From darcy at druid.net Wed Nov 3 12:10:51 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Wed, 3 Nov 2010 12:10:51 -0400 Subject: What people are using to access this mailing list In-Reply-To: <4CD18585.7020207@asd-group.com> References: <20101103113811.270c1236.darcy@druid.net> <4CD18585.7020207@asd-group.com> Message-ID: <20101103121051.6aa164d7.darcy@druid.net> On Wed, 03 Nov 2010 15:53:41 +0000 John Bond wrote: > > It is completely off topic. What you need to do is research your own > > email client to see how to filter mailing lists into their own > > folders. Failing that look for a forum dedicated to your email > > client. There is nothing specific about Python in this regard. > > I know how to do that, thanks, but I was looking at broader options. Well, still off-topic but the question could have been put better. If you knew how to do that you should have mentioned it and explained why it wasn't suitable for your needs. You would have got a more focussed response. This applies to asking any questions here or elsewhere. The more information you provide in your question, the more relevant the responses will be. By the way, I am seeing two copies of every message from you. How are you posting? -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From clp2 at rebertia.com Wed Nov 3 12:18:52 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 3 Nov 2010 09:18:52 -0700 Subject: Serializing a user-defined class In-Reply-To: References: Message-ID: > On Wed, Nov 3, 2010 at 10:35 AM, Chris Rebert wrote: >> On Wed, Nov 3, 2010 at 8:30 AM, T.J. Simmons >> wrote: >> > Hi all, got a question regarding serializing classes that I've defined. >> > I >> > have some classes like >> > class Foo: >> > ?? ? def __init__(self, x, y): >> > ?? ? ? ? ?self.x = x, self.y = y >> > then a class that can contain multiple Foos, such as: >> > class Bar: >> > ?? ? def __init__(self): >> > ?? ? ? ? ?self.foos = [Foo(a, b), Foo(1, 2)] >> > >> > While that's a gross oversimplification of the real structure (it gets >> > much, >> > much more nested than that), that's a pretty decent overview. The actual >> > data for this is coming from a pseudo-XML file without any actual >> > structure, >> > so I wrote a parser according to the spec given to me, so I now have all >> > the >> > data in a series of classes I've defined, with actual structure. >> > What I'm wanting to do is take this data I have and spit it out into >> > JSON, >> > but I really don't see a good way (I'm new to Python, this is my first >> > real >> > project with it). >> >> Did you google for "python json"? The std lib `json` module is the >> very first hit: >> http://docs.python.org/library/json.html On Wed, Nov 3, 2010 at 8:39 AM, T.J. Simmons wrote: > Right, I know about the json module; that's not the problem. My problem is > with the fact that different instances of the same class, with different > data, have the same keys. Foo, in this instance, can be both a list of Foos > inside Bar, and also a list of Foos outside Bar. I'm just unsure of how to > get the data into a serializable form. So, if I'm understanding you correctly, your classes make use of dynamic typing and you think this will cause serialization problems? In that case, just define an appropriate JSONEncoder or object_hook; see the module docs, they give an example for complex numbers. If I've misunderstood you, a specific (pseudo-)code example of your problem would be helpful. Cheers, Chris From jed at jedsmith.org Wed Nov 3 12:20:32 2010 From: jed at jedsmith.org (Jed Smith) Date: Wed, 3 Nov 2010 12:20:32 -0400 Subject: What people are using to access this mailing list In-Reply-To: References: Message-ID: On Wed, Nov 3, 2010 at 4:02 AM, John Bond wrote: > My normal inbox is getting unmanageable, and I think I need to find a new way > of following this and other lists. I have to second (or third) the Gmail suggestion. I use Google Apps against my domain, and the Gmail interface is frightfully good at creating filters. For example, on most lists (particularly Mailman), I can hit "Filter messages like this", and Gmail automatically harvests the List header and writes a filter for it. I just prefer the Gmail philosophy to mail, with tags that are *like* folders but not really. -- Jed Smith jed at jedsmith.org From python at bdurham.com Wed Nov 3 12:29:12 2010 From: python at bdurham.com (python at bdurham.com) Date: Wed, 03 Nov 2010 12:29:12 -0400 Subject: Tkinter/ttk compatibility with Citrix/WTS (Windows Terminal Services)? Message-ID: <1288801752.27919.1403416637@webmail.messagingengine.com> Anyone have any experience using Python Tkinter/ttk applications with Citrix or WTS (Windows Terminal Services)? Any concerns, gotchas, or workarounds we should be aware of? I googled this topic [1], [2] and came up with nothing. No news is good news ... but just checking to make sure. Thanks, Malcolm [1] tkinter (citrix | ts|terminal services) [2] tcl (citrix | ts|terminal services) -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Wed Nov 3 12:43:20 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 3 Nov 2010 09:43:20 -0700 Subject: Serializing a user-defined class In-Reply-To: References: Message-ID: > On Wed, Nov 3, 2010 at 11:18 AM, Chris Rebert wrote: >> > On Wed, Nov 3, 2010 at 10:35 AM, Chris Rebert wrote: >> >> On Wed, Nov 3, 2010 at 8:30 AM, T.J. Simmons >> >> wrote: >> >> > Hi all, got a question regarding serializing classes that I've >> >> > defined. >> >> > I >> >> > have some classes like >> >> > class Foo: >> >> > ?? ? def __init__(self, x, y): >> >> > ?? ? ? ? ?self.x = x, self.y = y >> >> > then a class that can contain multiple Foos, such as: >> >> > class Bar: >> >> > ?? ? def __init__(self): >> >> > ?? ? ? ? ?self.foos = [Foo(a, b), Foo(1, 2)] >> >> > >> >> > While that's a gross oversimplification of the real structure (it >> >> > gets >> >> > much, >> >> > much more nested than that), that's a pretty decent overview. The >> >> > actual >> >> > data for this is coming from a pseudo-XML file without any actual >> >> > structure, >> >> > so I wrote a parser according to the spec given to me, so I now have >> >> > all >> >> > the >> >> > data in a series of classes I've defined, with actual structure. >> >> > What I'm wanting to do is take this data I have and spit it out into >> >> > JSON, >> >> > but I really don't see a good way (I'm new to Python, this is my >> >> > first >> >> > real >> >> > project with it). >> >> >> >> Did you google for "python json"? The std lib `json` module is the >> >> very first hit: >> >> http://docs.python.org/library/json.html >> >> On Wed, Nov 3, 2010 at 8:39 AM, T.J. Simmons >> wrote: >> > Right, I know about the json module; that's not the problem. My problem >> > is >> > with the fact that different instances of the same class, with different >> > data, have the same keys. Foo, in this instance, can be both a list of >> > Foos >> > inside Bar, and also a list of Foos outside Bar. I'm just unsure of how >> > to >> > get the data into a serializable form. >> >> So, if I'm understanding you correctly, your classes make use of >> dynamic typing and you think this will cause serialization problems? >> In that case, just define an appropriate JSONEncoder or object_hook; >> see the module docs, they give an example for complex numbers. >> If I've misunderstood you, a specific (pseudo-)code example of your >> problem would be helpful. On Wed, Nov 3, 2010 at 9:26 AM, T.J. Simmons wrote: > The issue with serialization is how I'm giving the data back to the > serializer, since I'm using dicts. Multiple dictionaries with a key of Foo > will overwrite each other, which isn't my desired behavior. Eh? There should be no key collision. The *outer attribute's* name (e.g. "foos") should be the key, not the value's type's name (e.g. "Foo"). The type information for an object should go inside that object's own dict. Again, see the example for `complex` in the json module docs. Also, avoid top-posting in the future. Cheers, Chris -- http://blog.rebertia.com From ben.wbr20 at gmail.com Wed Nov 3 12:47:21 2010 From: ben.wbr20 at gmail.com (bw) Date: Wed, 3 Nov 2010 09:47:21 -0700 (PDT) Subject: imaplib Search for Messages by Time Message-ID: Hello everyone. I've been writing a program that interfaces with a user's GMail account using OAuth, and I'm trying to find a way to search for messages that were received only after a certain date AND time. It seems pretty easy to get messages after a certain date. Here's the relevant code that I have now, which works: ... imap_conn = imaplib.IMAP4_SSL(imap_hostname) imap_conn.authenticate('XOAUTH', lambda x: xoauth_string) imap_conn.select('INBOX') (typ, data) = imap_conn.search(None, '(SINCE "01-Nov-2010")') ... But ideally I'd be able to do something like '(SINCE "01-Nov-2010 10:00:00")'. I know that I can do this locally, but time is a critical factor here so I'd like to avoid downloading any messages that I don't need. Thanks! From theimmortalbum at gmail.com Wed Nov 3 12:48:17 2010 From: theimmortalbum at gmail.com (T.J. Simmons) Date: Wed, 3 Nov 2010 11:48:17 -0500 Subject: Serializing a user-defined class In-Reply-To: References: Message-ID: The way it actually is now, there will be key collision in the dictionaries because each Foo has the same keys. I'm about to dive into the json docs for how it's done on complex, because that seems to be pretty much what I'm looking for. And I was about to ask what top-posting was, but then I realized I wasn't sending this back to the list. So I'm going to assume what that was. Thanks. On Wed, Nov 3, 2010 at 11:42 AM, Chris Rebert wrote: > > On Wed, Nov 3, 2010 at 11:18 AM, Chris Rebert wrote: > >> > On Wed, Nov 3, 2010 at 10:35 AM, Chris Rebert > wrote: > >> >> On Wed, Nov 3, 2010 at 8:30 AM, T.J. Simmons < > theimmortalbum at gmail.com> > >> >> wrote: > >> >> > Hi all, got a question regarding serializing classes that I've > >> >> > defined. > >> >> > I > >> >> > have some classes like > >> >> > class Foo: > >> >> > def __init__(self, x, y): > >> >> > self.x = x, self.y = y > >> >> > then a class that can contain multiple Foos, such as: > >> >> > class Bar: > >> >> > def __init__(self): > >> >> > self.foos = [Foo(a, b), Foo(1, 2)] > >> >> > > >> >> > While that's a gross oversimplification of the real structure (it > >> >> > gets > >> >> > much, > >> >> > much more nested than that), that's a pretty decent overview. The > >> >> > actual > >> >> > data for this is coming from a pseudo-XML file without any actual > >> >> > structure, > >> >> > so I wrote a parser according to the spec given to me, so I now > have > >> >> > all > >> >> > the > >> >> > data in a series of classes I've defined, with actual structure. > >> >> > What I'm wanting to do is take this data I have and spit it out > into > >> >> > JSON, > >> >> > but I really don't see a good way (I'm new to Python, this is my > >> >> > first > >> >> > real > >> >> > project with it). > >> >> > >> >> Did you google for "python json"? The std lib `json` module is the > >> >> very first hit: > >> >> http://docs.python.org/library/json.html > >> > >> On Wed, Nov 3, 2010 at 8:39 AM, T.J. Simmons > >> wrote: > >> > Right, I know about the json module; that's not the problem. My > problem > >> > is > >> > with the fact that different instances of the same class, with > different > >> > data, have the same keys. Foo, in this instance, can be both a list of > >> > Foos > >> > inside Bar, and also a list of Foos outside Bar. I'm just unsure of > how > >> > to > >> > get the data into a serializable form. > >> > >> So, if I'm understanding you correctly, your classes make use of > >> dynamic typing and you think this will cause serialization problems? > >> In that case, just define an appropriate JSONEncoder or object_hook; > >> see the module docs, they give an example for complex numbers. > >> If I've misunderstood you, a specific (pseudo-)code example of your > >> problem would be helpful. > > On Wed, Nov 3, 2010 at 9:26 AM, T.J. Simmons > wrote: > > The issue with serialization is how I'm giving the data back to the > > serializer, since I'm using dicts. Multiple dictionaries with a key of > Foo > > will overwrite each other, which isn't my desired behavior. > > Eh? There should be no key collision. The *outer attribute's* name > (e.g. "foos") should be the key, not the value's type's name (e.g. > "Foo"). The type information for an object should go inside that > object's own dict. Again, see the example for `complex` in the json > module docs. > > Also, avoid top-posting in the future. > > Cheers, > Chris > -- > http://blog.rebertia.com > -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Wed Nov 3 12:53:56 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 3 Nov 2010 09:53:56 -0700 Subject: Serializing a user-defined class In-Reply-To: References: Message-ID: On Wed, Nov 3, 2010 at 9:48 AM, T.J. Simmons wrote: > And I was about to ask what top-posting was, but then I realized I wasn't > sending this back to the list. So I'm going to assume what that was. Nope, actually it's about placing your reply below the quoted message you're replying to. (See Wikipedia's "Posting style" article) Though yes, you should also generally Reply-All on a mailinglist. Cheers, Chris From python at mrabarnett.plus.com Wed Nov 3 13:53:08 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 03 Nov 2010 17:53:08 +0000 Subject: Must be a bug in the re module [was: Why this result with the re module] In-Reply-To: <4CD0E0D1.7070902@asd-group.com> References: <292222.415.qm@web54207.mail.re2.yahoo.com> <4CD0DEE5.2060702@mrabarnett.plus.com> <4CD0E0D1.7070902@asd-group.com> Message-ID: <4CD1A184.1060400@mrabarnett.plus.com> On 03/11/2010 04:10, John Bond wrote: > On 3/11/2010 4:02 AM, MRAB wrote: >> On 03/11/2010 03:42, Yingjie Lan wrote: >>>> Matches an empty string, returns '' >>>> >>>> The result is therefore ['Mar', '', '', 'lam', '', ''] >>> >>> Thanks, now I see it through with clarity. >>> Both you and JB are right about this case. >>> However, what if the regex is ((.a.)*)* ? >>> >> Actually, in hindsight, my explanation is slightly wrong! >> >> re.search and the others return None for an unmatched group, but >> re.findall returns '' for an unmatched group, so instead of saying: >> >> Matches an empty string, returns '' >> >> I should have said: >> >> The group doesn't match at all, so .findall returns '' >> >> As for "((.a.)*)*", the inner group and repeat match like before, but >> then the outer repeat and group try again. >> >> The inner group can't match again, so it's unchanged (and it still >> remembers the last successful capture), and the outer group therefore >> matches an empty string. >> >> Therefore the outer (first) group is always an empty string and the >> inner (second) group is the same as the previous example (the last >> capture or '' if no capture). > > Now I'm confused - how can something with "zero or more occurrences" not > match? > Perhaps I just phrased it badly. Given a regex like "(.a.)*", the group might not match, but the regex itself will. From python at mrabarnett.plus.com Wed Nov 3 13:59:35 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 03 Nov 2010 17:59:35 +0000 Subject: Must be a bug in the re module [was: Why this result with the re module] In-Reply-To: <844169.1635.qm@web54201.mail.re2.yahoo.com> References: <844169.1635.qm@web54201.mail.re2.yahoo.com> Message-ID: <4CD1A307.2010809@mrabarnett.plus.com> On 03/11/2010 06:32, Yingjie Lan wrote: > --- On Wed, 11/3/10, John Bond wrote: >> I just explained that (I think!)! The outer capturing group >> uses >> repetition, so it returns the last thing that was matched >> by the inner >> group, which was an empty string. >> > According to yourself, the last match of the > inner group is also empty! > > Generally speaking, > as a match for the outer group always > contains some matches for the inner group, > it must be the case that the last match > for the inner group must be contained > inside the last match of the outer group. > So if the last match of the > outer group is empty, then the last > match for the inner group must > also be empty. > [snip] The outer group is repeated, so it can match again, but the inner group can't match again because it captured all it could the previous time. Therefore the outer group matches and captures an empty string and the inner group remembers its last capture. From jearl at notengoamigos.org Wed Nov 3 14:22:18 2010 From: jearl at notengoamigos.org (Jason Earl) Date: Wed, 03 Nov 2010 12:22:18 -0600 Subject: Man pages and info pages References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> <024ef21a-9ef9-48a6-8372-1d66895583c3@v16g2000yqn.googlegroups.com> <87zktr5yze.fsf_-_@mithlond.arda> <877hgv2fg3.fsf@mithlond.arda> <87hbfyn3uo.fsf@xemacs.org> <1bdce24e-4406-44c5-9133-bfd0acd0283d@p1g2000yqm.googlegroups.com> Message-ID: <87fwvigtd1.fsf@notengoamigos.org> On Wed, Nov 03 2010, rustom wrote: > On Nov 3, 3:11?pm, Daniel da Silva wrote: >> Guys, this really has nothing to do with python. > > ?? python docs have nothing to do with python?? python docs by > default on linux are read with info and many seem to find info > unpleasant to use. Actually, the Python documentation is no longer available in info format. Which is unfortunate, as that was the documentation format that I personally preferred. > Myself an old emacs user and cant say info helps me as much as google. > However comparing info and man is also a bit strange. The printed > python docs come to several thousand pages. Do we want them to be 1 > manpage? a hundred? a thousand? I am pretty conversant with the Python documentation. I almost never need to search them. I do miss being able to read (and search) the documentation in my editor though. Jason From news3 at mystrobl.de Wed Nov 3 14:35:02 2010 From: news3 at mystrobl.de (Wolfgang Strobl) Date: Wed, 03 Nov 2010 19:35:02 +0100 Subject: What people are using to access this mailing list References: Message-ID: <9v83d6pkpn7gt977lcn7072cqfcod9gq3m@4ax.com> John Bond : >Hope this isn't too O/T - I was just wondering how people read/send to this >mailing list, eg. normal email client, gmane, some other software or online >service? I'm reading comp.lang.python on usenet, using Fort? Agent as a newsreader, which connects via nntp to a locally managed leafnode, which in turn is fed by http://news.individual.net/ (for most newsgroups) and http://news.gmane.org/ (for some mailing lists which are only available there). I usually try to avoid reading mailing lists as mail. >My normal inbox is getting unmanageable, and I think I need to find a new way >of following this and other lists. Another way to regain control is to use separate mail adresses for different purposes. I'm adding another alias for a new subscription or a new registration email adress each time I subscribe to something. -- Thank you for observing all safety precautions From usernet at ilthio.net Wed Nov 3 14:49:06 2010 From: usernet at ilthio.net (Tim Harig) Date: Wed, 3 Nov 2010 18:49:06 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-03, Steven D'Aprano wrote: > On Tue, 02 Nov 2010 19:26:56 +0000, Tim Harig wrote: > >> I agree with Seebs, Python is the only language I know that promotes the >> use of spaces over tabs; > > Really? I'm not aware of *any* language that promotes tabs over spaces. I > thought the tabs vs spaces war was mostly won by spaces over a decade ago > (apart from a few plucky freedom fighters who will never surrender). Python is the only language that I know that *needs* to specify tabs versus spaces since it is the only language I know of which uses whitespace formating as part of its syntax and structure. Mixed usage may be annoying in other languages; but, it breaks Python. Otherwise, it is my experience that the preference for tabs versus spaces depends on the users chosen platform. *nix users prefer tabs while Windows users prefer spaces. >> and there are equally picky syntaxs (ie, >> Makefiles) that mandate the use of tabs. I personally prefer tabs as it >> lets *me* decide how far the apparent indentations are in the code. You >> may like four spaces; but, I agree with Linus Torvalds that eight spaces >> is much clearer. The beautiful thing about tabs is that we can both set >> our tab stops to match our own viewing preferences. > > Actually I agree with you about tabs. I think tabs are far more logical > and sensible. But I'm stuck with broken tools that don't deal with tabs, Where you not the one a few posts back telling Seebs that he needed to change his broken tools? > and with PEP 8 that mandates the use of spaces, and popular opinion that > says make is crazy for using tabs. Stupid rules are meant to be broken. > So, I bite my lip, stop using broken tools that make dealing with space- > indents painful, and just deal with it. And you know what? It's not so > bad after all. If I am using somebody elses project, then I will post my output using their code conventions. I have smart conversion scripts that convert between different indent formats. I edit in the format that I prefer and, in my projects, the indentation in the SCM is in my preferred format. >> This is Python's most noticable blemish outside of the community. >> Everybody knows that Python is the language that forces you to use a >> particular style of formatting; and, that is a turn-off for many people. > > Their loss. I don't miss the flame wars over the One True Brace Style. > There are enough disagreements over coding conventions without adding to > them. This choice has obviously not been effective in stopping flame wars. I can cite multiple threads where it has caused them. >> It is a big mistake that whenever the issue arises, the community >> effectively attacks anybody who might have disagreements with the >> tradeoffs made for the Python language. This tends to set people on the >> defensive and gives them a bad taste about the language as a whole. > > That's very insightful. Why don't you apply some of that insight to the > other side? It is *incredibly* annoying to see the same old people making > the same old snide remarks about the same old issues over and over again, > particularly when: A large part of the reason that the issue keeps coming up is that the community never really deals with it when it does. I have enough customer support experience to know that a client is never really satisfied until you acknowledge their problem. Until the problem is acknowledged, the client will have put up psychological communcation block that prevents them from hearing any workarounds that you might have. The community never acknowledges the problem. It simply sweeps the problem under the rug telling the people raising these issues that they don't know what they are talking about; strengthening the psychological block and further impeding the communication. The people with these problems therefore never feel that they have been heard, become unwilling to listen to the solutions, and will thus keep bringing the problem back up. > * it's not an issue for thousands of other users; You are now hearing the testimony of those who have had problems. I also know that it is human nature for advocates to simply overlook the problems when they arise. That doesn't mean that the problem is there. I have used Python for over a decade in spite of its problems because I believe that the benefits outway the detriments. I am however objective enough to be congnizant of the problems; and, I am fully aware of there effects on new members of the community. When prospective Python programmers approach me with these problems I: 1. Acknowledge that the problem exits. 2. Explain the trade-offs that have lead to the problem. 3. Suggest ways to work around the problem. 4. Point out why I believe the benefits of using Python outway its idiosyncrasies. I don't just tell them that there is no problem or that the problems they may be experiencing are their fault because they choose to do something differently then I might. > * even if it were an issue, if you use the right tool for the job, the > issue disappears; That a tools is needed is in itself an indication that the problem exists. That isn't to say that good tools don't have their place or that they cannot contribute to the solution. > * and even if it would change, the people doing the whinging aren't going > to volunteer to make the change. Funny that. I *do* have a history of submitting patches to open source projects. >> It would be much better if the community would simply acknowledge that >> this is a tradeoff the the language has made and one which is often >> misunderstood by many first time Python programmers. > > Been there, done that. This is *old news*. Except that you are not. Your general attitude is that since you don't experience problems nobody else must either. From iamforufriends at gmail.com Wed Nov 3 14:52:22 2010 From: iamforufriends at gmail.com (ADULTS GROUP FOR FUN WITH SE ^X) Date: Wed, 3 Nov 2010 11:52:22 -0700 (PDT) Subject: HAY... U KNOW, NOW DATING WITH SWEET AND CUTYS IS EAZY... AND FREE... Message-ID: <62e83987-6e72-432b-a0e7-f1503835111e@p20g2000prf.googlegroups.com> HAY... U KNOW, NOW DATING WITH SWEET AND CUTYS IS EAZY... AND FREE... JUST FOLLOW THE LINK....... http://tinyurl.com/eazy-dating http://tinyurl.com/eazy-dating http://tinyurl.com/eazy-dating http://tinyurl.com/eazy-dating http://tinyurl.com/eazy-dating http://tinyurl.com/eazy-dating http://tinyurl.com/eazy-dating http://tinyurl.com/eazy-dating http://tinyurl.com/eazy-dating http://tinyurl.com/eazy-dating http://tinyurl.com/eazy-dating From martin at address-in-sig.invalid Wed Nov 3 15:00:32 2010 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Wed, 3 Nov 2010 19:00:32 +0000 (UTC) Subject: What people are using to access this mailing list References: <4cd144cc$0$29966$c3e8da3$5496439d@news.astraweb.com> <87r5f2wr7t.fsf@rudin.co.uk> Message-ID: On Wed, 03 Nov 2010 13:05:23 +0000, Grant Edwards wrote: > On 2010-11-03, Paul Rudin wrote: >> John Bond writes: >> >>> On 3/11/2010 11:17 AM, Steven D'Aprano wrote: >>>> On Wed, 03 Nov 2010 08:02:29 +0000, John Bond wrote: >>>> >>>>> Hope this isn't too O/T - I was just wondering how people read/send >>>>> to this mailing list, eg. normal email client, gmane, some other >>>>> software or online service? >>>> Usenet via my ISP, on comp.lang.python. >>>> >>> Using what client (or web client)? >> >> Emacs, of course :-; > > Slrn, of course. Pan since I'm on Linux. Agent if I was still a Windows user. Its the best news reader I've used. -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From usernet at ilthio.net Wed Nov 3 15:07:48 2010 From: usernet at ilthio.net (Tim Harig) Date: Wed, 3 Nov 2010 19:07:48 +0000 (UTC) Subject: What people are using to access this mailing list References: <4cd144cc$0$29966$c3e8da3$5496439d@news.astraweb.com> <87r5f2wr7t.fsf@rudin.co.uk> Message-ID: On 2010-11-03, Grant Edwards wrote: > On 2010-11-03, Paul Rudin wrote: >> John Bond writes: >> >>> On 3/11/2010 11:17 AM, Steven D'Aprano wrote: >>>> On Wed, 03 Nov 2010 08:02:29 +0000, John Bond wrote: >>>> >>>>> Hope this isn't too O/T - I was just wondering how people read/send to >>>>> this mailing list, eg. normal email client, gmane, some other software >>>>> or online service? >>>> Usenet via my ISP, on comp.lang.python. >>>> >>> Using what client (or web client)? >> >> Emacs, of course :-; > > Slrn, of course. Of, course. From invalid at invalid.invalid Wed Nov 3 15:16:41 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 3 Nov 2010 19:16:41 +0000 (UTC) Subject: What people are using to access this mailing list References: <4cd144cc$0$29966$c3e8da3$5496439d@news.astraweb.com> <87r5f2wr7t.fsf@rudin.co.uk> Message-ID: On 2010-11-03, Tim Harig wrote: > On 2010-11-03, Grant Edwards wrote: >> On 2010-11-03, Paul Rudin wrote: >>> John Bond writes: >>> >>>> On 3/11/2010 11:17 AM, Steven D'Aprano wrote: >>>>> On Wed, 03 Nov 2010 08:02:29 +0000, John Bond wrote: >>>>> >>>>>> Hope this isn't too O/T - I was just wondering how people read/send to >>>>>> this mailing list, eg. normal email client, gmane, some other software >>>>>> or online service? >>>>> >>>>> Usenet via my ISP, on comp.lang.python. >>>> >>>> Using what client (or web client)? >>> >>> Emacs, of course :-; >> >> Slrn, of course. > > Of, course. The OP could have figured all this out by himself by merely looking at the headers for a sampling of articles. Heck, with about 50 lines of Python, one could probably produced a fairly comprehensive statistical report on access methods and clients used by posters to "this mailing list". [An NNTP client module is one of the "batteries", and that module's docs contains most of the code needed to access the articles.] Finding out the access methods used by people who don't post is somewhat more difficult. :) -- Grant Edwards grant.b.edwards Yow! Boy, am I glad it's at only 1971... gmail.com From steve at REMOVE-THIS-cybersource.com.au Wed Nov 3 15:21:40 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 03 Nov 2010 19:21:40 GMT Subject: What people are using to access this mailing list References: <4cd144cc$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4cd1b643$0$29966$c3e8da3$5496439d@news.astraweb.com> On Wed, 03 Nov 2010 11:58:07 +0000, John Bond wrote: > On 3/11/2010 11:17 AM, Steven D'Aprano wrote: >> On Wed, 03 Nov 2010 08:02:29 +0000, John Bond wrote: >> >>> Hope this isn't too O/T - I was just wondering how people read/send to >>> this mailing list, eg. normal email client, gmane, some other software >>> or online service? >> Usenet via my ISP, on comp.lang.python. >> >> >> > Using what client (or web client)? Usually Pan, sometimes KNode. -- Steven From steve at REMOVE-THIS-cybersource.com.au Wed Nov 3 15:36:05 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 03 Nov 2010 19:36:05 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> On Wed, 03 Nov 2010 02:40:11 +0000, Seebs wrote: > Sure, but there's also no way for you to spot that something looks > suspicious. In Python, if something is misindented, it does what you > told it to do, and there's no way for you to tell, by looking at it, > that it isn't what was intended. In C, if something is misindented, it > does what you told it to do, but it's obvious looking at the code that > something went wrong. If it's that obvious, why do people keep causing those indentation- related bugs in C? I'm glad for you that you have a finely trained attention to detail that is able to instantly spot misindented C code (or is that misplaced braces and correctly indented?), but it is a notoriously common error which suggests that it's not anywhere near as obvious as you think. It's *far* more common than Python code being misindented. There's even a commonly suggested style for C programmers: always use braces any time the syntax allows them, even when they're not needed, because the next guy who maintains the file may not be as careful and may forget to add the braces when needed. >> But I can see the other end of the block in Python. I don't need any >> tricks to make sure that it is the end. And if your block is too big >> to see the structure easily then that just means that some code should >> be factored out to a method. > > This level of dogmatism about what should always be the case is not > conducive to good software engineering practices. I question that assertion. Good engineering practices is about setting best practices, and following them, not avoiding them because there might be the odd exception here and there. > It is not obvious to me that it's *always* the case. So what if there is an exception one time in twenty thousand? You don't design a tool (such as a programming language) on the basis of what's good for the rare exceptional cases, but on what's good for the common cases. The common case is that functions and methods should be short enough to see the structure by eye. If it isn't, you have more problems than just the lack of begin/end markers. The language shouldn't make everyone carry the burden of supporting two-page functions all the time, just to save you an insignificant amount of trouble on the vanishingly rare occasion you need a function that is two pages long. -- Steven From emile at fenx.com Wed Nov 3 15:37:26 2010 From: emile at fenx.com (Emile van Sebille) Date: Wed, 03 Nov 2010 12:37:26 -0700 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 11/3/2010 11:49 AM Tim Harig said... > A large part of the reason that the issue keeps coming up is that the > community never really deals with it when it does. I have enough customer > support experience to know that a client is never really satisfied until > you acknowledge their problem. Then you likely also have enough experience to know that once the customer has made the decision you accept their call. As a consultant you move on after having done your duty bringing the issue to light. The same applies here -- it's not changing, so you (generic you) accept it and move on. The community has dealt with the issue by acknowledging that differing opinions exist and the BDFL makes the final call, which is certainly something the community accepts. I imagine a PEP could be submitted suggesting change, and it hasn't been done because the outcome is certain. Otherwise, there's always whython... http://writeonly.wordpress.com/2010/04/01/whython-python-for-people-who-hate-whitespace/ Emile From steve at REMOVE-THIS-cybersource.com.au Wed Nov 3 16:03:15 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 03 Nov 2010 20:03:15 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4cd1c003$0$29966$c3e8da3$5496439d@news.astraweb.com> On Wed, 03 Nov 2010 18:49:06 +0000, Tim Harig wrote: >> Actually I agree with you about tabs. I think tabs are far more logical >> and sensible. But I'm stuck with broken tools that don't deal with >> tabs, > > Where you not the one a few posts back telling Seebs that he needed to > change his broken tools? Yes, and I also said that I sympathized with him if he couldn't. >>> It is a big mistake that whenever the issue arises, the community >>> effectively attacks anybody who might have disagreements with the >>> tradeoffs made for the Python language. This tends to set people on >>> the defensive and gives them a bad taste about the language as a >>> whole. >> >> That's very insightful. Why don't you apply some of that insight to the >> other side? It is *incredibly* annoying to see the same old people >> making the same old snide remarks about the same old issues over and >> over again, particularly when: > > A large part of the reason that the issue keeps coming up is that the > community never really deals with it when it does. No. The community does deal with it. It deals with it by saying "It isn't going to change." If you want a language that forces you to wrap ever block in BEGIN END tags, you have a thousand choices. Python is not one of them. What is so hard to understand about this? > I have enough > customer support experience to know that a client is never really > satisfied until you acknowledge their problem. Until the problem is > acknowledged, the client will have put up psychological communcation > block that prevents them from hearing any workarounds that you might > have. Yes, well that too goes both ways. *I* have a psychological communication block that prevents me from hearing any complaints about the lack of braces from people who refuse to acknowledge that having to type braces is stupid and annoying, and that the use of braces in a language hurts readability. Frankly, I DON'T CARE how often your editor breaks your source code. I don't care about Seeb's mail server that converts his Python code to HTML. I don't give a rat's arse about how many times some buggy ftp client has mangled the indentation on Python files. Not my problem. Your pain is not my pain, and any solution to these problems that involves changing the way I read and write Python code is an anti-solution to a non-problem to me. Until the "Python is broken 'cos it has no braces" crowd acknowledge this fact, I just harden my heart against their complaints. Why should *I* have to acknowledge their issues when they don't acknowledge mine? -- Steven From steve at REMOVE-THIS-cybersource.com.au Wed Nov 3 16:05:58 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 03 Nov 2010 20:05:58 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4cd1c0a6$0$29966$c3e8da3$5496439d@news.astraweb.com> On Wed, 03 Nov 2010 01:25:56 +0000, Seebs wrote: > Whitespace damage is, indeed, wrong. It's a bad thing. It is an > *extremely common* bad thing, I question that. You've claimed that you have to deal with broken indentation on a regular basis. I've *never* had to deal with broken whitespace, except for certain websites that mangle leading whitespace when you post a comment. So I don't post code on those websites. > and I fundamentally don't think it was a > good choice to build a system with no redundancy against it. Python does have some redundancy against indentation mangling. Not all combinations of indentation are legal. # Not legal: y = x + 1 z = x*y # Not legal: if x: do_something() # Not legal: if x: do something() else: do_something_else() And so on. True, there are some failure modes which can't be easily recovered from without reading and understanding the code. That's okay. Such failure modes are vanishingly rare -- for every twenty thousand braces you avoid typing, you might, if you're unlucky, need to fix an instance of broken indentation. > That > "redundant" information saves our hides on a regular basis in an > imperfect world. So you say. -- Steven From usenet-nospam at seebs.net Wed Nov 3 16:30:43 2010 From: usenet-nospam at seebs.net (Seebs) Date: 03 Nov 2010 20:30:43 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-03, Steven D'Aprano wrote: > On Tue, 02 Nov 2010 19:26:56 +0000, Tim Harig wrote: >> I agree with Seebs, Python is the only language I know that promotes the >> use of spaces over tabs; > Really? Yes. > I'm not aware of *any* language that promotes tabs over spaces. Makefiles. > I > thought the tabs vs spaces war was mostly won by spaces over a decade ago > (apart from a few plucky freedom fighters who will never surrender). No. However, you've got a fallacy of the excluded middle here -- you're ignoring the very large set of "doesn't care either way", and looking only at things that prefer one or the other. > So, I bite my lip, stop using broken tools that make dealing with space- > indents painful, and just deal with it. And you know what? It's not so > bad after all. I don't consider it broken for a tool to favor a more logical style which is *actually* required by at least one format, and not a problem for anything I've ever used except (sort of) Python. In fact, Python works perfectly with tabs; it's just other Python programmers who get fussy. :) > Their loss. I don't miss the flame wars over the One True Brace Style. > There are enough disagreements over coding conventions without adding to > them. I don't miss them, or care about them; after all, I can just run indent/cb to format something however I like, and run it again to match any given coding style standard. Problem solved. > * it's not an issue for thousands of other users; This is a non-argument. That something isn't a problem for other people makes no difference to the people for whom it's a problem. > * even if it were an issue, if you use the right tool for the job, the > issue disappears; I have never found any other editor that I like as much as the one I use now. > * and even if there is no right tool for the job, the feature isn't going > to change; I think you miss the point of the observation. I'm not expecting it to change; I'm pointing out that insisting that it's not a problem is *insulting* to the people for whom it is a problem. > * and even if it would change, the people doing the whinging aren't going > to volunteer to make the change. Oh, I'd happily contribute code if it'd matter. But it wouldn't. >> It would be much better if the community would simply acknowledge that >> this is a tradeoff the the language has made and one which is often >> misunderstood by many first time Python programmers. > Been there, done that. This is *old news*. I haven't seen it done yet. I've seen a whole lot of people tell me that an editor I've been using for twenty years is "broken" because I found a program that is brittle with regards to its inputs that is prone to being triggered by a behavior which has been free of problems (and indeed in some cases *mandatory*) for everything else. I've seen people smugly tell me that I'd love this if I just tried it. That didn't work for pickles, it didn't work for Player-vs-Player fighting in video games, and it's not gonna work for the lack of end markers. Explicit is better than implicit. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Wed Nov 3 16:35:20 2010 From: usenet-nospam at seebs.net (Seebs) Date: 03 Nov 2010 20:35:20 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-03, Steven D'Aprano wrote: > On Wed, 03 Nov 2010 02:40:11 +0000, Seebs wrote: >> Sure, but there's also no way for you to spot that something looks >> suspicious. In Python, if something is misindented, it does what you >> told it to do, and there's no way for you to tell, by looking at it, >> that it isn't what was intended. In C, if something is misindented, it >> does what you told it to do, but it's obvious looking at the code that >> something went wrong. > If it's that obvious, why do people keep causing those indentation- > related bugs in C? I don't think they do. I can't remember the last time I've seen one. > I'm glad for you that you have a finely trained attention to detail that > is able to instantly spot misindented C code (or is that misplaced braces > and correctly indented?), but it is a notoriously common error which > suggests that it's not anywhere near as obvious as you think. It's "notoriously common", but can you show me an actual example of it happening in real code? Not a "hey guys look how misleading this would be" example conjured up for illustration, but an *actual* example in live code? I can't remember one, except I think maybe I saw one somewhere in... hmm. No, wait, that was perl. >> This level of dogmatism about what should always be the case is not >> conducive to good software engineering practices. > I question that assertion. Good engineering practices is about setting > best practices, and following them, not avoiding them because there might > be the odd exception here and there. I don't think I buy this. I've seen a whole lot of good writers and good programmers, and in both groups, they consistently report that you have to know how the rules work before you break them. > The language shouldn't make > everyone carry the burden of supporting two-page functions all the time, > just to save you an insignificant amount of trouble on the vanishingly > rare occasion you need a function that is two pages long. I don't think there's a particularly big burden there. Explicit is better than implicit. It is *better* to explicitly mark the ends of things than to have it be implicit in dropping indentation. That's not a burden, it's good engineering practice. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Wed Nov 3 16:39:47 2010 From: usenet-nospam at seebs.net (Seebs) Date: 03 Nov 2010 20:39:47 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1c0a6$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-03, Steven D'Aprano wrote: > On Wed, 03 Nov 2010 01:25:56 +0000, Seebs wrote: >> Whitespace damage is, indeed, wrong. It's a bad thing. It is an >> *extremely common* bad thing, > I question that. > You've claimed that you have to deal with broken indentation on a regular > basis. I'd guess I see something which got screwed up somehow every couple of weeks, usually while refactoring stuff. >> and I fundamentally don't think it was a >> good choice to build a system with no redundancy against it. > Python does have some redundancy against indentation mangling. Not all > combinations of indentation are legal. True, but it doesn't seem to catch the most common failure modes. > And so on. True, there are some failure modes which can't be easily > recovered from without reading and understanding the code. That's okay. > Such failure modes are vanishingly rare -- for every twenty thousand > braces you avoid typing, you might, if you're unlucky, need to fix an > instance of broken indentation. This is ridiculous overstatement. Moving a single block of overly-nested code out into a separate method could generate several indentation mishaps if Something Goes Wrong, which it does sometimes. I haven't written more than a couple hundred blocks in Python, so I'm a factor of a hundred out from twenty thousand braces, and I've had six or seven indentation problems. And yes, I can just recreate it, but it takes more effort, since I can't do things like just handing it to an automated tool that can correct it completely automatically. Furthermore, I don't WANT to skip closing braces. EXPLICIT IS BETTER THAN IMPLICIT. I *WANT* to have the beginnings and ends marked. I want end braces or "end" or something at the end of a block for the same reason that I prefer: x = "hello, world" to x = "hello, world where we just assume the string ends at the end of the line. >> That >> "redundant" information saves our hides on a regular basis in an >> imperfect world. > So you say. Well, it works for me. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From invalid at invalid.invalid Wed Nov 3 16:46:22 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 3 Nov 2010 20:46:22 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-03, Seebs wrote: > Explicit is better than implicit. It is *better* to explicitly mark the > ends of things than to have it be implicit in dropping indentation. That's > not a burden, it's good engineering practice. Dededenting does explicitly mark the end of a block. -- Grant Edwards grant.b.edwards Yow! What PROGRAM are they at watching? gmail.com From cs at zip.com.au Wed Nov 3 16:48:09 2010 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 4 Nov 2010 07:48:09 +1100 Subject: Python documentation too difficult for beginners In-Reply-To: References: Message-ID: <20101103204809.GA5306@cskk.homeip.net> On 02Nov2010 03:42, jk wrote: | I've been coding in PHP and Java for years, and their documentation is | concise, well structured and easy to scan. While I agree about Java, at least the core Java docs, and javadoc output in general (_great_ cross referencing!) I have mixed feelings about the PHP docs. Though I suspect that stems from a dislike of the PHP library API in general more than the docs, perhaps. | Others have mentioned this apparently for years (see: | http://stackoverflow.com/questions/4046166/easy-to-navigate-online-python-reference-manual/4070851 | and http://www.russellbeattie.com/blog/python-library-docs-still-suck | and http://xahlee.org/perl-python/xlali_skami_cukta.html). | | Compare for instance the differences in ease of use, and speed of use, | of these: | | http://docs.python.org/library/functions.html#open | http://uk.php.net/manual/en/function.fopen.php | | The former is difficult to find (try searching for 'open' in the | search box and see what you get). I confess I almost never use the search box - as you say the result relevance can be dodgy. However, I do find the docs easy to use and pleasant to read on the whole. My use is as follows: For speed and convenience I have the docs locally stored. I open the front page and then usually both the modules and index in adjacent brwoser tabs. I go to the index if I'm not sure of the module. The strength of the index is that it tends to contain stuff that people thought should be indexed (versus searches, which often have no contextual understanding of the text, so their relevance is weaker). The weakness of the index is that it can be hard to pick the relevant entry. Open-link-in-new-tab is my friend here:-( | It is simply a collection of | paragraphs without strong enough contrast to differentiate the | different parts - parameters, parameter values, return types, | exceptions and related functions. It is slow to read and doesn't allow | easy visual scanning. That is true (the scanning). But by contrast, it does read like prose and lends itself to a visit that gets you a complete feel for the function. [...] | Has anyone else struggled while trying to learn the language? The | whole documentation system seems geared towards people who already | know what they're looking for and is close to useless for beginners. | I'm not the only one who finds google an easier way to find | documentation about python. I certainly don't find the core docs hard to use (with some exceptions; I still don't really understand the urllib stuff for the cases where configuration is needed - weird proxy setups etc). I've only been using Python for a few years and have generally found that language easy to learn and the docs easy to read. I rarely reach for The Google unless I'm seeking examples; the docs could do with a few more of these IMHO. I understand the attraction of the structured layout javadoc yields but find it leads to "drier" documentation. It also works well for Java because it is strongly typed - a great deal of the structure in the docs can come directly from the code because argument counts, names and types are always explicit (or deducable). These are just initial responses. Now to wade the whole thread:-) -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ On the contrary of what you may think, your hacker is fully aware of your company's dress code. He is fully aware of the fact that it doesn't help him to do his job. - Gregory Hosler From usenet-nospam at seebs.net Wed Nov 3 16:59:46 2010 From: usenet-nospam at seebs.net (Seebs) Date: 03 Nov 2010 20:59:46 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-03, Grant Edwards wrote: > On 2010-11-03, Seebs wrote: >> Explicit is better than implicit. It is *better* to explicitly mark the >> ends of things than to have it be implicit in dropping indentation. That's >> not a burden, it's good engineering practice. > Dededenting does explicitly mark the end of a block. If you can't point to the token, it's implicit. :) -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From cs at zip.com.au Wed Nov 3 17:03:37 2010 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 4 Nov 2010 08:03:37 +1100 Subject: Python documentation too difficult for beginners In-Reply-To: References: Message-ID: <20101103210336.GA9858@cskk.homeip.net> On 02Nov2010 04:23, jk wrote: | This (http://epydoc.sourceforge.net/stdlib/) is what I'm talking | about. | | Why aren't the official docs like this, and why has it taken me 2 days | of searching? All this needs is a search engine behind it and it'd be | perfect. It looks a lot like javadoc. But its weakness is stuff like this: http://epydoc.sourceforge.net/stdlib/Canvas.Polygon-class.html Automatic docness, no useful information. And of course the ugliness; I find the python docs much nicer to look at. But I do wish the cross referencing was a bit better, often. -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ In an insane society, the sane man must appear insane. - Keith A. Schauer From martin at address-in-sig.invalid Wed Nov 3 17:18:17 2010 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Wed, 3 Nov 2010 21:18:17 +0000 (UTC) Subject: Python documentation too difficult for beginners References: Message-ID: On Thu, 04 Nov 2010 08:03:37 +1100, Cameron Simpson wrote: > On 02Nov2010 04:23, jk wrote: | This > (http://epydoc.sourceforge.net/stdlib/) is what I'm talking | about. > | > | Why aren't the official docs like this, and why has it taken me 2 days > | of searching? All this needs is a search engine behind it and it'd be > | perfect. > > It looks a lot like javadoc. But its weakness is stuff like this: > > http://epydoc.sourceforge.net/stdlib/Canvas.Polygon-class.html > > Automatic docness, no useful information. > You get the same problem in Java and it has exactly the same root: a lazy programmer who can't be arsed to document his code. -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From ben+python at benfinney.id.au Wed Nov 3 17:27:14 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 04 Nov 2010 08:27:14 +1100 Subject: Ways of accessing this mailing list? References: Message-ID: <87lj5ahzd9.fsf@benfinney.id.au> Grant Edwards writes: > On 2010-11-02, John Bond wrote: > > My normal inbox is getting unmanageable, and I think I need to find > > a new way of following this and other lists. > > Point an NNTP client at new.gmane.org. Ditto, but the correct hostname is ?news.gmane.org?. > This "list" is also a Usenet newsgroup (comp.lang.python), and there > are a number of cheap/low-cost text-only Usenet providers. Moreover, Gmane is (as John probably knows) an NNTP interface to many forums that would otherwise not be available via NNTP. -- \ ?Members of the general public commonly find copyright rules | `\ implausible, and simply disbelieve them.? ?Jessica Litman, | _o__) _Digital Copyright_ | Ben Finney From ben+python at benfinney.id.au Wed Nov 3 17:30:09 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 04 Nov 2010 08:30:09 +1100 Subject: What people are using to access this mailing list References: <4cd144cc$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87hbfyhz8e.fsf@benfinney.id.au> John Bond writes: > On 3/11/2010 11:17 AM, Steven D'Aprano wrote: > > Usenet via my ISP, on comp.lang.python. > Using what client (or web client)? Gnus on Emacs. -- \ ?Perchance you who pronounce my sentence are in greater fear | `\ than I who receive it.? ?Giordano Bruno, burned at the stake by | _o__) the Catholic church for the heresy of heliocentrism, 1600-02-16 | Ben Finney From usernet at ilthio.net Wed Nov 3 17:56:00 2010 From: usernet at ilthio.net (Tim Harig) Date: Wed, 3 Nov 2010 21:56:00 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1c003$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-03, Steven D'Aprano wrote: > On Wed, 03 Nov 2010 18:49:06 +0000, Tim Harig wrote: >>> Actually I agree with you about tabs. I think tabs are far more logical >>> and sensible. But I'm stuck with broken tools that don't deal with >>> tabs, >> >> Where you not the one a few posts back telling Seebs that he needed to >> change his broken tools? > > Yes, and I also said that I sympathized with him if he couldn't. Perhaps it would be more constructive, for everybody, to make suggestions on how to reliably transfer code using channels that distort whitespace. >>> That's very insightful. Why don't you apply some of that insight to the >>> other side? It is *incredibly* annoying to see the same old people >>> making the same old snide remarks about the same old issues over and >>> over again, particularly when: >> >> A large part of the reason that the issue keeps coming up is that the >> community never really deals with it when it does. > > No. The community does deal with it. It deals with it by saying "It isn't > going to change." If you want a language that forces you to wrap ever > block in BEGIN END tags, you have a thousand choices. Python is not one > of them. What is so hard to understand about this? Please to not mix my contentions with somebody else's. I have not, anywhere in this thread, asked to change the language. I certainly didn't say *anything* about adding "BEGIN END" tags to the code itself. I did say that I found code folding markers in the comments to be a useful form for expressing code structure; but, that has nothing to with chainging Python itself. I also expressed my opinion that I felt spaces for indenting was a poor choice for the standard; but, since it is also not part of the language proper, it can safely be ignored. What I did suggest was a more constructive way of dealing with these criticisms. You said that you found it "*incredibly* annoying" to have this to see the same old "snide remarks" from "the same old people." I merely suggested that if the community changes its attitude towards those making those remarks, that it might go a long way towards silencing some of those descents. The fact that you are unwilling to make these changes makes me question your conviction when you claim to be so annoyed. >> I have enough >> customer support experience to know that a client is never really >> satisfied until you acknowledge their problem. Until the problem is >> acknowledged, the client will have put up psychological communcation >> block that prevents them from hearing any workarounds that you might >> have. > > Yes, well that too goes both ways. *I* have a psychological communication > block that prevents me from hearing any complaints about the lack of > braces from people who refuse to acknowledge that having to type braces > is stupid and annoying, and that the use of braces in a language hurts > readability. I understand that you don't like braces; but, I have nowhere advocated adding them to the Python langauge. That is a different argument that you are having with Seebs. > Frankly, I DON'T CARE how often your editor breaks your source code. I Only you have even mentioned editors in this thread. > don't care about Seeb's mail server that converts his Python code to > HTML. I don't give a rat's arse about how many times some buggy ftp > client has mangled the indentation on Python files. Not my problem. Your Nobody else mentioned ftp servers in this either; but, I must admit that you are doing a good job of providing evidence for the alternate viewpoint. > pain is not my pain, and any solution to these problems that involves > changing the way I read and write Python code is an anti-solution to a > non-problem to me. Then why bother adding to the noise in this thread at all since it has nothing to do with you? I see however, since you have brought all this baggage to the table that was not otherwise in the thread, that you obviously have a axe to grind. > Until the "Python is broken 'cos it has no braces" crowd acknowledge this > fact, I just harden my heart against their complaints. Why should *I* > have to acknowledge their issues when they don't acknowledge mine? Then please state your Python language issues rather simply grinding your axe against those who are stating theirs. From steve-REMOVE-THIS at cybersource.com.au Wed Nov 3 18:30:12 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 03 Nov 2010 22:30:12 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> On Wed, 03 Nov 2010 20:35:20 +0000, Seebs wrote: >>> This level of dogmatism about what should always be the case is not >>> conducive to good software engineering practices. > >> I question that assertion. Good engineering practices is about setting >> best practices, and following them, not avoiding them because there >> might be the odd exception here and there. > > I don't think I buy this. I've seen a whole lot of good writers and > good programmers, and in both groups, they consistently report that you > have to know how the rules work before you break them. Yes. How does that contradict what I said? There is a huge difference between knowing when to break the rules, and avoiding the rules because there might someday be an exception. >> The language shouldn't make >> everyone carry the burden of supporting two-page functions all the >> time, just to save you an insignificant amount of trouble on the >> vanishingly rare occasion you need a function that is two pages long. > > I don't think there's a particularly big burden there. Good for you. > Explicit is better than implicit. Ah, argument by misunderstanding the Zen! > It is *better* to explicitly mark the > ends of things than to have it be implicit in dropping indentation. > That's not a burden, it's good engineering practice. Python does explicitly mark blocks. It does it by changes in indentation. An indent is an explicit start-block. An outdent is an explicit end- block. There is nothing implicit in a change in indent level. To illustrate the difference, this is how a hypothetical language might use implicit end of blocks: if condition: true_clause() another_true_clause() else: false_clause() The if block ends implicitly when you reach an else statement, and the else clause implicitly ends... where? It gets worse: if condition: if another_condition: true_clause() else: false_clause() another_clause() Such a hypothetical language might decide on a rule that else will always match the closest if, or the outermost if that is legal. That would be an implicit end of block. This is not even within the same galaxy as what Python does. It simply isn't possible to have implicit start/end block markers, unless you restrict your language in ways that exclude most blocks. E.g. if all if blocks were restricted to a single statement, then you could have an implicit block -- the block in one statement. Stating that Python uses implicit block markers is simply wrong. -- Steven From ldo at geek-central.gen.new_zealand Wed Nov 3 18:40:12 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 04 Nov 2010 11:40:12 +1300 Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> Message-ID: In message , Chris Rebert wrote: > Actually, my PEP 8 reference was in regards to the (imo, terrible) > UseOfCamelCaseForNonClasses (Python != C#), not the formatting of the > for-loop; hence the "In any case" qualification. Hmm ... OK, I might accept that particular criticism. I have to say it?s a habit I picked up in my Mac programming days, that I find hard to shake. I do sometimes deliberately use lowercase_with_underscores, but then I keep LapsingBackAgain. At least I prefer Bactrian to Dromedary. :) From zkinion at gmail.com Wed Nov 3 18:46:38 2010 From: zkinion at gmail.com (Zak Kinion) Date: Wed, 3 Nov 2010 15:46:38 -0700 Subject: Subject: Re: problem with opening a new python program in a new window (and keeping track of the process) Message-ID: >> What I want to do: ?launch seperate python programs from one main >> program (multi-threading will not achieve this because the mechanize >> library uses one shared global opener object which will not suit my >> needs) ?I want the scripts launched to be in seperate windows that i >> can see the output of on screen, seperate processes. ?I can accomplish >> this in win32 by: >> >> import subprocess; >> args = ["cmd", "/c", "START", "python", "myScript.py"]; >> process1 = subprocess.Popen(args, shell=False); > > Pass CREATE_NEW_CONSOLE as one of the creationflags: > > > import os, sys Yep, that definitely works. :) > import subprocess > > processes = [] > cmd = [sys.executable, "-c", "import os; print os.getpid (); raw_input ()"] > for i in range (3): > ?processes.append (subprocess.Popen (cmd, creationflags=subprocess.CREATE_NEW_CONSOLE)) > > # > # Keep looping round to see the current status > # > while True: > ?for p in processes: > ? ?print p.poll () > > ?raw_input () > > > > TJG > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Zak Kinion zkinion at gmail.com (702) 287-5613 From ldo at geek-central.gen.new_zealand Wed Nov 3 18:51:35 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 04 Nov 2010 11:51:35 +1300 Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> Message-ID: In message , Roy Smith wrote: >> > > That URL takes me to a github page. Can you be more specific about > which file I should be looking at? The extract I previously quoted was from dvd_menu_animator. > 2) You have provided comments for each function, such as (lines 36-37): > > def NewLayer(svg, LayerName) : > # adds a new layer to the SVG document and returns it. > > This is good, but would be even more useful if it were turned into a > docstring ... I am ambivalent about the usefulness of docstrings. I find them mainly handy in stuff imported from library modules, of which this is not one. > 3) I find the deeply nested style you use very difficult to read. For > example, on lines 80-103. As I read this, here's how I mentally process > it: > > "OK, here's a function call (minor stumble over the open paren not being > on the same line as the function name, but I can get past that). The > first argument is TheLayer. The second argument is whatever > inkex.addNS() returns. Umm..." You?re looking at it wrong. It?s building a data structure to go into an SVG file. Think of each piece of the expression as directly mapping to the corresponding piece of the structure being built. The value being built for the ?d? attribute is just a sequence of control points for the path. From rhodri at wildebst.demon.co.uk Wed Nov 3 19:07:00 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 03 Nov 2010 23:07:00 -0000 Subject: What people are using to access this mailing list References: <4cd144cc$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, 03 Nov 2010 11:58:07 -0000, John Bond wrote: > On 3/11/2010 11:17 AM, Steven D'Aprano wrote: >> On Wed, 03 Nov 2010 08:02:29 +0000, John Bond wrote: >> >>> Hope this isn't too O/T - I was just wondering how people read/send to >>> this mailing list, eg. normal email client, gmane, some other software >>> or online service? >> Usenet via my ISP, on comp.lang.python. >> >> >> > Using what client (or web client)? Opera (as an NNTP client, not a web client). -- Rhodri James *-* Wildebeest Herder to the Masses From usenet-nospam at seebs.net Wed Nov 3 19:09:10 2010 From: usenet-nospam at seebs.net (Seebs) Date: 03 Nov 2010 23:09:10 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-03, Steven D'Aprano wrote: > Yes. How does that contradict what I said? Once you understand that you do have to break the rules occasionally, it is a good idea to design things that will be robust when the rules are broken. > Ah, argument by misunderstanding the Zen! I see. So explicit boundaries are a good thing, except when they are one specific special case. Let us imagine a hypothetical mirror-universe person, who is otherwise like you, but: 1. Has a goatee. 2. Actually hates the indentation rules, wishes Python had braces, but has become emotionally invested in defending the status quo because if he had to suffer, dammit, everyone else should have to suffer too. You have not yet made a single argument that he wouldn't have made too. >> It is *better* to explicitly mark the >> ends of things than to have it be implicit in dropping indentation. >> That's not a burden, it's good engineering practice. > Python does explicitly mark blocks. It does it by changes in indentation. > An indent is an explicit start-block. An outdent is an explicit end- > block. There is nothing implicit in a change in indent level. What's the token that marks the end of a block, corresponding to the colon used to introduce it? > It simply isn't possible to have implicit start/end block markers, unless > you restrict your language in ways that exclude most blocks. E.g. if all > if blocks were restricted to a single statement, then you could have an > implicit block -- the block in one statement. Stating that Python uses > implicit block markers is simply wrong. No, it isn't. There's no token telling you where the block ended. C *allows* implicit blocks, and this is widely regarded as a key flaw. However, it also allows you to explicitly mark blocks in a way which is robust against common errors, allowing software to automatically fix up differences between, say, competing indentation styles. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From torriem at gmail.com Wed Nov 3 19:18:27 2010 From: torriem at gmail.com (Michael Torrie) Date: Wed, 03 Nov 2010 17:18:27 -0600 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1c0a6$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4CD1EDC3.3030305@gmail.com> On 11/03/2010 02:39 PM, Seebs wrote: > Furthermore, I don't WANT to skip closing braces. EXPLICIT IS BETTER > THAN IMPLICIT. I *WANT* to have the beginnings and ends marked. I suggest, then that Pascal or Ruby would suit your needs better than Python. > I want end braces or "end" or something at the end of a block for > the same reason that I prefer: > x = "hello, world" > to > x = "hello, world > where we just assume the string ends at the end of the line. Not even close to the same thing, sorry. As for refactoring code, vim makes it really easy to move blocks in and out. The only time I could see this becoming an issue is if functions or blocks of code are too long to see on a page at once. If this is the case, break them up. Sounds to me like your problems with refactoring and indention in python could be do to these kinds of design issues. Having curly braces certainly doesn't help in these situations either. More than once I've had C code I was refactoring that broke due to the fact that while trying to move blocks around I misplaced a brace, an issue I never have in Python. In the meantime, whitespace structure is one of the things about Python that I like the *most* about the language. Being able to crank out executable pseudo-code is pretty addictive. And I never write pseudo-code on paper with begin and end blocks cause it's too much effort when scribbling by hand. From steve-REMOVE-THIS at cybersource.com.au Wed Nov 3 19:20:30 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 03 Nov 2010 23:20:30 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> On Wed, 03 Nov 2010 20:30:43 +0000, Seebs wrote: > I'm not expecting it to change; Then why talk about it? Just to hear the sound of your voice? (Or see the font of your writing?) To waste our time? To feel more virtuous than those who don't see your point of view? If you don't expect a change, what's the point of this discussion? > I'm pointing out that insisting that it's not a problem is > *insulting* to the people for whom it is a problem. And insisting that it is a problem is equally insulting to those for whom it is not a problem. -- Steven From rhodri at wildebst.demon.co.uk Wed Nov 3 19:37:07 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 03 Nov 2010 23:37:07 -0000 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, 03 Nov 2010 18:49:06 -0000, Tim Harig wrote: > On 2010-11-03, Steven D'Aprano > wrote: >> On Tue, 02 Nov 2010 19:26:56 +0000, Tim Harig wrote: >> >>> I agree with Seebs, Python is the only language I know that promotes >>> the >>> use of spaces over tabs; >> >> Really? I'm not aware of *any* language that promotes tabs over spaces. >> I >> thought the tabs vs spaces war was mostly won by spaces over a decade >> ago >> (apart from a few plucky freedom fighters who will never surrender). > > Python is the only language that I know that *needs* to specify tabs > versus > spaces since it is the only language I know of which uses whitespace > formating as part of its syntax and structure. Mixed usage may be > annoying > in other languages; but, it breaks Python. I regard this as a strength. I have wasted far too much time at work writing review comments that could be paraphrased as "your broken editor settings have made this (C code) unreadable." -- Rhodri James *-* Wildebeest Herder to the Masses From python.list at tim.thechases.com Wed Nov 3 19:41:42 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 03 Nov 2010 18:41:42 -0500 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4CD1F336.1050703@tim.thechases.com> On 11/03/10 15:59, Seebs wrote: >> Dededenting does explicitly mark the end of a block. > > If you can't point to the token, it's implicit. :) Just because you asked for it to be pointed to: http://svn.python.org/view/python/trunk/Include/token.h?view=markup The DEDENT token is explicitly defined as the number "6", FWIW... :) -tkc From usenet-nospam at seebs.net Wed Nov 3 19:42:55 2010 From: usenet-nospam at seebs.net (Seebs) Date: 03 Nov 2010 23:42:55 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-03, Steven D'Aprano wrote: > On Wed, 03 Nov 2010 20:30:43 +0000, Seebs wrote: >> I'm not expecting it to change; > Then why talk about it? Because I find technical questions interesting in and of themselves. I will happily talk with people about the reasons for which the C preprocessor is the way it is, even though it's never going to change and we all hate it like poison. >> I'm pointing out that insisting that it's not a problem is >> *insulting* to the people for whom it is a problem. > And insisting that it is a problem is equally insulting to those for whom > it is not a problem. No, it isn't. A friend of mine is colorblind. For him, certain red/green pairings are indistinguishable. For me to insist that it is not a problem that a user interface uses those to distinguish two things is insulting to him; I am dismissing a very real problem. For him to insist that it is a problem for him is in no way insulting me. He's not saying that it's a problem for me. He's merely saying that *there exist* people for whom it is a problem. No one has claimed that this is a problem *for everybody*. Just that there exist real-world workflows for which it is a problem, or people for whom it is a problem. This is an asymmetrical situation. The opposite of "it's never a problem for anybody" isn't "it is always a problem for everybody" but "it is at least sometimes a problem for at least some people." The reality is, the indentation-instead-of-markers thing *does* sometimes lead to problems. We could blame it on tools, but the tools could just as easily blame the language for being brittle. Given the degree to which the rest of the world has standardized on not caring how *much* whitespace is between things (though sometimes caring whether or not there's *any* whitespace between them), it seems to me that the odd man out is the one who is creating the burden. Once many file formats exist which don't care how many spaces you use, and many tools have been developed with those file formats in mind, coming up with a new file format which cares how many spaces you use seems a little short-sighted. Demanding that all tools be changed to fit a new paradigm is a pretty big demand to place on people. On the whole, I don't personally think the benefits have been worth it. I think Python would be a better, richer, language if it used explicit end tokens of some sort. Maybe it wouldn't. I do know, though, that of the programmers I know outside the Python newsgroup, not a single one likes that aspect of Python. It is consistently regarded as an annoying quirk. Some use Python anyway; it has merits, certainly. If I were offered a choice between Python and PHP for a project, I would *absolutely* pick Python. (Subject, of course, to the assumption that the project would in some way involve computers, or programming, or that I would at some point have to either write code for the project use it, or possibly come within twenty feet of someone who was working on it; outside of those limitations, I might consider PHP.) I feel the same way about pretty much every language I use. C would be a much better language if the macro processor weren't such a giant filesystem verification stage for a filesystem distributed across multiple machines*. They all have flaws. Python's the only language I use where an obvious flaw, which is repeatedly observed by everyone I know who uses the language, is militantly and stridently defended by dismissing, insulting, and attacking the character and motives of anyone who suggests that it might be a bit of a nuisance. I suspect part of that is simply because it *is* a tradeoff, and there are good reasons for it. It offers some advantages. It's not something that you'd be insane to like; the problems are easily mitigated once you know about them, and the benefits are worth it. If I worked with a lot more novice-level C programmers who hadn't yet had the importance of careful style drilled into them, I might well find the indentation problems people keep talking about to be a real thing, possibly even a very serious one. But the fact remains, being brittle in the face of whitespace changes *is* a flaw. It breaks code under circumstances which are, for better or worse, common. As I pointed out before: There is a *REASON* that diff has an option for ignoring whitespace changes -- because they are common enough that such an option is commonly useful for distinguishing between real changes and inadvertant ones. Note that "whitespace indentation" in and of itself isn't the thing I'm describing as a flaw; it's the side-effect of being brittle when whitespace changes. The indentation thing as a whole has some definite plusses, and it's a tradeoff that I think may even be a good fit for a language specifically focused on easier readability. -s [*] clusterfsck. -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From ben+python at benfinney.id.au Wed Nov 3 19:53:40 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 04 Nov 2010 10:53:40 +1100 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87sjzige0r.fsf@benfinney.id.au> Seebs writes: > On 2010-11-03, Steven D'Aprano wrote: > > Python does explicitly mark blocks. It does it by changes in > > indentation. An indent is an explicit start-block. An outdent is an > > explicit end- block. There is nothing implicit in a change in indent > > level. > > What's the token that marks the end of a block, corresponding to the > colon used to introduce it? You have introduced this requirement for tokens; it's fallacious. The direct answer is: tokens aren't part of the requirement to be explicit. The more general answer is: the block is explicitly ended where the indentation ends. -- \ ?I must say that I find television very educational. The minute | `\ somebody turns it on, I go to the library and read a book.? | _o__) ?Groucho Marx | Ben Finney From ben+python at benfinney.id.au Wed Nov 3 19:55:14 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 04 Nov 2010 10:55:14 +1100 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1c0a6$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87oca6gdy5.fsf@benfinney.id.au> Seebs writes: > Furthermore, I don't WANT to skip closing braces. EXPLICIT IS BETTER > THAN IMPLICIT. I *WANT* to have the beginnings and ends marked. Python doesn't require that. You're going to be disappointed by most Python code if that's what you want. Which is not a failing of Python. -- \ ?Few things are harder to put up with than the annoyance of a | `\ good example.? ?Mark Twain, _Pudd'n'head Wilson_ | _o__) | Ben Finney From brf256 at gmail.com Wed Nov 3 19:58:10 2010 From: brf256 at gmail.com (brf256 at gmail.com) Date: Wed, 3 Nov 2010 23:58:10 +0000 Subject: What people are using to access this mailing list Message-ID: <1709014163-1288828693-cardhu_decombobulator_blackberry.rim.net-882162190-@bda480.bisx.prod.on.blackberry> I use my blackberry to access the list. - Braden Faulkner Sent wirelessly from my BlackBerry device on the Bell network. Envoy? sans fil par mon terminal mobile BlackBerry sur le r?seau de Bell. From roy at panix.com Wed Nov 3 19:59:05 2010 From: roy at panix.com (Roy Smith) Date: Wed, 03 Nov 2010 19:59:05 -0400 Subject: Subclassing unittest.TestCase? References: Message-ID: In article , Peter Otten <__peter__ at web.de> wrote: > Remove the base class from the module with > > del CommonTestCase > > before you invoke unittest.main(). Wow, what a clever idea! I tried it, and it does exactly what I need. Thanks! From usenet-nospam at seebs.net Wed Nov 3 20:00:04 2010 From: usenet-nospam at seebs.net (Seebs) Date: 04 Nov 2010 00:00:04 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1c0a6$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-03, Michael Torrie wrote: > I suggest, then that Pascal or Ruby would suit your needs better than > Python. In the absence of network effects, I'd just be using Ruby. I have reason to work with projects that have a lot of existing Python, though, so I use it too. > As for refactoring code, vim makes it really easy to move blocks in and > out. Yes, though I mostly use nvi, same thing -- basically. The issue I've had is that the automatic-tab thing (which I actively want for everything else I edit) tends to make it quirky. > The only time I could see this becoming an issue is if functions > or blocks of code are too long to see on a page at once. If this is the > case, break them up. Sounds to me like your problems with refactoring > and indention in python could be do to these kinds of design issues. > Having curly braces certainly doesn't help in these situations either. > More than once I've had C code I was refactoring that broke due to the > fact that while trying to move blocks around I misplaced a brace, an > issue I never have in Python. For me, I'd rather have the compiler choke because I have mismatched braces than have the code run apparently just fine except that something has unintentionally moved in or out of an else clause because there was no marker. I've had both happen, probably. > In the meantime, whitespace structure is one of the things about Python > that I like the *most* about the language. Being able to crank out > executable pseudo-code is pretty addictive. And I never write > pseudo-code on paper with begin and end blocks cause it's too much > effort when scribbling by hand. I never write on paper anyway. :) Anyway, I'm not disputing that there are things that it makes nicer. I'm just observing that there exists a category of failures which is completely unique to Python, which no other language (except BF, which I'm not sure I ought to count) has, which tends to show up occasionally until you've gotten all the changed tools and habits, and even then can show up when dealing with other people who use tools which, well, work perfectly for everything else. But not for this. Only other tool I know with a comparable dependance on spacing is Makefiles, and I have never in my life met someone who used them and didn't think that was a loathesome error which should never have made it into production code. Python's not nearly as bad, actually. :) -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From ldo at geek-central.gen.new_zealand Wed Nov 3 20:01:34 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 04 Nov 2010 13:01:34 +1300 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <8j8udgFlkvU1@mid.individual.net> Message-ID: In message , Seebs wrote: > The question is *why* diff has that option. > > The answer is because whitespace changes (spaces to tabs, different > tab stops, etcetera) are an extremely common failure mode, such that > it's quite common for files to end up with unintentional whitespace > changes. Except the diff option is to *ignore* such differences, not highlight them. From ldo at geek-central.gen.new_zealand Wed Nov 3 20:04:00 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 04 Nov 2010 13:04 +1300 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: In message , Seebs wrote: > It is extremely useful to me to have spaces converted to tabs > for every other file I edit. I?m thinking of going the other way. After many years of treating tabs as four-column steps, I might give up on them and use spaces everywhere. From emile at fenx.com Wed Nov 3 20:07:12 2010 From: emile at fenx.com (Emile van Sebille) Date: Wed, 03 Nov 2010 17:07:12 -0700 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 11/3/2010 4:09 PM Seebs said... > What's the token that marks the end of a block, corresponding to the > colon used to introduce it? > My thoughts tend more towards 'can we get Guido to eliminate the colon requirements' -- The indent level of the next line ought to suffice. Seriously. Emile From ldo at geek-central.gen.new_zealand Wed Nov 3 20:09:08 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 04 Nov 2010 13:09:08 +1300 Subject: Python documentation too difficult for beginners References: Message-ID: In message , Cameron Simpson wrote: > But its weakness is stuff like this: > > http://epydoc.sourceforge.net/stdlib/Canvas.Polygon-class.html > > Automatic docness, no useful information. But it Conforms to Documentation-Production Metrics as decreed by the Corporate Task Force on Policy. So long as the divisions are satisfying the official metrics on documentation production, that must mean the project is meeting its goals. From ldo at geek-central.gen.new_zealand Wed Nov 3 20:10:43 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 04 Nov 2010 13:10:43 +1300 Subject: Man pages and info pages References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> <024ef21a-9ef9-48a6-8372-1d66895583c3@v16g2000yqn.googlegroups.com> <87zktr5yze.fsf_-_@mithlond.arda> <877hgv2fg3.fsf@mithlond.arda> <87hbfyn3uo.fsf@xemacs.org> <1bdce24e-4406-44c5-9133-bfd0acd0283d@p1g2000yqm.googlegroups.com> Message-ID: In message <1bdce24e-4406-44c5-9133-bfd0acd0283d at p1g2000yqm.googlegroups.com>, rustom wrote: > The printed python docs come to several thousand pages. Do we want them > to be 1 manpage? a hundred? a thousand? Perl managed to condense a lot of useful information into a handful of man pages. From usenet-nospam at seebs.net Wed Nov 3 20:12:53 2010 From: usenet-nospam at seebs.net (Seebs) Date: 04 Nov 2010 00:12:53 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <8j8udgFlkvU1@mid.individual.net> Message-ID: On 2010-11-04, Lawrence D'Oliveiro wrote: > In message , Seebs wrote: >> The answer is because whitespace changes (spaces to tabs, different >> tab stops, etcetera) are an extremely common failure mode, such that >> it's quite common for files to end up with unintentional whitespace >> changes. > Except the diff option is to *ignore* such differences, not highlight them. Yes. That's because those changes are irrelevant, so people don't care about them, so they want an option to handle the common case where whitespace got changed but no one cares about that. But unintentional whitespace changes are common enough that you *need* the ability to filter them out and just look at "real" changes. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Wed Nov 3 20:13:44 2010 From: usenet-nospam at seebs.net (Seebs) Date: 04 Nov 2010 00:13:44 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: On 2010-11-04, Lawrence D'Oliveiro wrote: > In message , Seebs wrote: >> It is extremely useful to me to have spaces converted to tabs >> for every other file I edit. > I???m thinking of going the other way. After many years of treating tabs as > four-column steps, I might give up on them and use spaces everywhere. I *absolutely must* use tabs for Makefiles. For code in most other languages, it's merely a factor of 8 improvement in storage. :) -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From aahz at pythoncraft.com Wed Nov 3 21:13:40 2010 From: aahz at pythoncraft.com (Aahz) Date: 3 Nov 2010 18:13:40 -0700 Subject: What people are using to access this mailing list References: <87r5f2wr7t.fsf@rudin.co.uk> Message-ID: In article , Grant Edwards wrote: >On 2010-11-03, Paul Rudin wrote: >> John Bond writes: >>> On 3/11/2010 11:17 AM, Steven D'Aprano wrote: >>>> On Wed, 03 Nov 2010 08:02:29 +0000, John Bond wrote: >>>> >>>>> Hope this isn't too O/T - I was just wondering how people read/send to >>>>> this mailing list, eg. normal email client, gmane, some other software >>>>> or online service? >>>> Usenet via my ISP, on comp.lang.python. >>>> >>> Using what client (or web client)? >> >> Emacs, of course :-; > >Slrn, of course. trn3.6, of course. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." --Red Adair From brf256 at gmail.com Wed Nov 3 21:19:42 2010 From: brf256 at gmail.com (braden faulkner) Date: Wed, 3 Nov 2010 21:19:42 -0400 Subject: Best method for a menu in a command line program? Message-ID: I'm using a menu for my command line app using this method. choice = "foobar" while choice != "q": if choice == "c": temp = input("Celsius temperature:") print "Fahrenheit:",celsius_to_fahrenheit(temp) elif choice == "f": temp = input("Fahrenheit temperature:") print "Celsius:",fahrenheit_to_celsius(temp) elif choice != "q": print_options() choice = raw_input("option:") Just wondering if there is another or more efficient way I should be doing it? Thanks -- Braden Faulkner From email at invalid.net Wed Nov 3 21:37:10 2010 From: email at invalid.net (QoS) Date: Thu, 04 Nov 2010 01:37:10 GMT Subject: What people are using to access this mailing list References: Message-ID: Jed Smith wrote in message-id: > > On Wed, Nov 3, 2010 at 4:02 AM, John Bond wrote: > > My normal inbox is getting unmanageable, and I think I need to find a new way > > of following this and other lists. > > I have to second (or third) the Gmail suggestion. I use Google Apps > against my domain, and the Gmail interface is frightfully good at > creating filters. For example, on most lists (particularly Mailman), I > can hit "Filter messages like this", and Gmail automatically harvests > the List header and writes a filter for it. > > I just prefer the Gmail philosophy to mail, with tags that are *like* > folders but not really. > If that is what you used to post this reply then your client is broken somewhat. Your client did not post using a well-formed references header and so your post may/should not be grouped properly with the OP. Here is what your client determined the references to be, you will se it has no reference to the original posting. References: Below is a reply from someone using a well crafted client, this reply is certain to be organized by other clients in the same thread: References: <87r5f2wr7t.fsf at rudin.co.uk> Hth J From gnarlodious at gmail.com Wed Nov 3 21:38:14 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Wed, 3 Nov 2010 18:38:14 -0700 (PDT) Subject: Py3: Import relative path module References: <044f2fb7-a6a9-4bb9-b2a6-8ee1d0c19612@u17g2000yqi.googlegroups.com> <4cce7768$0$29965$c3e8da3$5496439d@news.astraweb.com> <770dd3de-25f5-404c-a05a-7bdd2eb07179@26g2000yqv.googlegroups.com> <3e7dbd88-4d44-43fa-a0e2-6987c025ccdb@26g2000yqv.googlegroups.com> <01c6e36a-c4e0-499a-adc1-cb61d7b53725@r14g2000yqa.googlegroups.com> Message-ID: <102a52fc-13be-4557-8ee0-279cc2c2ea3e@w38g2000pri.googlegroups.com> > Peter Otten wrote: > |-- alpha > | ? |-- __init__.py > | ? |-- beta > | ? | ? |-- __init__.py > | ? | ? `-- one.py > | ? `-- two.py > `-- main.py > > 2 directories, 5 files > $ cat main.py > import alpha.beta.one > $ cat alpha/beta/one.py > from ..alpha import two > $ cat alpha/two.py > print "success!" > $ python main.py > success! Thank you for that example, it works for me. However, what I want to do is go UP one folder to import the module(s) in some library: python main.py import ..alpha.beta.one ^ SyntaxError: invalid syntax python main.py from .. import alpha.beta.one ^ SyntaxError: invalid syntax So how to specify a relative path? -- Gnarlie From email at invalid.net Wed Nov 3 21:39:42 2010 From: email at invalid.net (QoS) Date: Thu, 04 Nov 2010 01:39:42 GMT Subject: What people are using to access this mailing list References: Message-ID: Jed Smith wrote in message-id: > > On Wed, Nov 3, 2010 at 4:02 AM, John Bond wrote: > > My normal inbox is getting unmanageable, and I think I need to find a new way > > of following this and other lists. > > I have to second (or third) the Gmail suggestion. I use Google Apps > against my domain, and the Gmail interface is frightfully good at > creating filters. For example, on most lists (particularly Mailman), I > can hit "Filter messages like this", and Gmail automatically harvests > the List header and writes a filter for it. > > I just prefer the Gmail philosophy to mail, with tags that are *like* > folders but not really. > If that is what you used to post this reply then your client is broken somewhat. Your client did not post using a well-formed references header and so your post may/should not be grouped properly with the OP. Here is what your client determined the references to be, you will se it has no reference to the original posting. References: Below is a reply from someone using a well crafted client, this reply is certain to be organized by other clients in the same thread: References: <87r5f2wr7t.fsf at rudin.co.uk> Hth J From email at invalid.net Wed Nov 3 21:40:39 2010 From: email at invalid.net (QoS) Date: Thu, 04 Nov 2010 01:40:39 GMT Subject: What people are using to access this mailing list References: Message-ID: Jed Smith wrote in message-id: > > On Wed, Nov 3, 2010 at 4:02 AM, John Bond wrote: > > My normal inbox is getting unmanageable, and I think I need to find a new way > > of following this and other lists. > > I have to second (or third) the Gmail suggestion. I use Google Apps > against my domain, and the Gmail interface is frightfully good at > creating filters. For example, on most lists (particularly Mailman), I > can hit "Filter messages like this", and Gmail automatically harvests > the List header and writes a filter for it. > > I just prefer the Gmail philosophy to mail, with tags that are *like* > folders but not really. > If that is what you used to post this reply then your client is broken somewhat. Your client did not post using a well-formed references header and so your post may/should not be grouped properly with the OP. Here is what your client determined the references to be, you will se it has no reference to the original posting. References: Below is a reply from someone using a well crafted client, this reply is certain to be organized by other clients in the same thread: References: <87r5f2wr7t.fsf at rudin.co.uk> Hth J From email at invalid.net Wed Nov 3 21:41:13 2010 From: email at invalid.net (QoS) Date: Thu, 04 Nov 2010 01:41:13 GMT Subject: What people are using to access this mailing list References: Message-ID: Jed Smith wrote in message-id: > > On Wed, Nov 3, 2010 at 4:02 AM, John Bond wrote: > > My normal inbox is getting unmanageable, and I think I need to find a new way > > of following this and other lists. > > I have to second (or third) the Gmail suggestion. I use Google Apps > against my domain, and the Gmail interface is frightfully good at > creating filters. For example, on most lists (particularly Mailman), I > can hit "Filter messages like this", and Gmail automatically harvests > the List header and writes a filter for it. > > I just prefer the Gmail philosophy to mail, with tags that are *like* > folders but not really. > If that is what you used to post this reply then your client is broken somewhat. Your client did not post using a well-formed references header and so your post may/should not be grouped properly with the OP. Here is what your client determined the references to be, you will se it has no reference to the original posting. References: Below is a reply from someone using a well crafted client, this reply is certain to be organized by other clients in the same thread: References: <87r5f2wr7t.fsf at rudin.co.uk> Hth J From email at invalid.net Wed Nov 3 21:41:53 2010 From: email at invalid.net (QoS) Date: Thu, 04 Nov 2010 01:41:53 GMT Subject: What people are using to access this mailing list References: Message-ID: Jed Smith wrote in message-id: > > On Wed, Nov 3, 2010 at 4:02 AM, John Bond wrote: > > My normal inbox is getting unmanageable, and I think I need to find a new way > > of following this and other lists. > > I have to second (or third) the Gmail suggestion. I use Google Apps > against my domain, and the Gmail interface is frightfully good at > creating filters. For example, on most lists (particularly Mailman), I > can hit "Filter messages like this", and Gmail automatically harvests > the List header and writes a filter for it. > > I just prefer the Gmail philosophy to mail, with tags that are *like* > folders but not really. > If that is what you used to post this reply then your client is broken somewhat. Your client did not post using a well-formed references header and so your post may/should not be grouped properly with the OP. Here is what your client determined the references to be, you will se it has no reference to the original posting. References: Below is a reply from someone using a well crafted client, this reply is certain to be organized by other clients in the same thread: References: <87r5f2wr7t.fsf at rudin.co.uk> Hth J From email at invalid.net Wed Nov 3 21:49:43 2010 From: email at invalid.net (QoS) Date: Thu, 04 Nov 2010 01:49:43 GMT Subject: What people are using to access this mailing list References: Message-ID: Jed Smith wrote in message-id: > > On Wed, Nov 3, 2010 at 4:02 AM, John Bond wrote: > > My normal inbox is getting unmanageable, and I think I need to find a new way > > of following this and other lists. > > I have to second (or third) the Gmail suggestion. I use Google Apps > against my domain, and the Gmail interface is frightfully good at > creating filters. For example, on most lists (particularly Mailman), I > can hit "Filter messages like this", and Gmail automatically harvests > the List header and writes a filter for it. > > I just prefer the Gmail philosophy to mail, with tags that are *like* > folders but not really. > Just in case the client may not display the headers, fyi: If gmail is what you used to post this reply then your client is broken somewhat. Your client did not post using a well-formed references header and so your post may/should not be grouped properly with the OP. Here is what your client determined the references to be, you will se it has no reference to the original posting. References: Below is a reply from someone using a well crafted client, this reply is certain to be organized by other clients in the same thread: References: <87r5f2wr7t.fsf at rudin.co.uk> Hth J From rantingrick at gmail.com Wed Nov 3 22:03:33 2010 From: rantingrick at gmail.com (rantingrick) Date: Wed, 3 Nov 2010 19:03:33 -0700 (PDT) Subject: Best method for a menu in a command line program? References: Message-ID: <8d21da84-66b8-4e87-a1a6-100069aad62c@f33g2000yqh.googlegroups.com> On Nov 3, 8:19?pm, braden faulkner wrote: > Just wondering if there is another or more efficient way I should be doing it? I would move the input inside the respective methods or functions, short of that, what is more efficient than a conditional... nothing, and it reads very intuitively. Sure you could throw all the funcs into a dict and it may clean up a long winded conditional, however then you have to make a trade. So Zero Sum at that point. From ben+python at benfinney.id.au Wed Nov 3 22:03:47 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 04 Nov 2010 13:03:47 +1100 Subject: Best method for a menu in a command line program? References: Message-ID: <87fwvhhmkc.fsf@benfinney.id.au> braden faulkner writes: > I'm using a menu for my command line app using this method. > > choice = "foobar" The default choice for a ?nothing here yet? value is the built-in ?None?. Sometimes that's not the right choice; but if you have no particular reaason in a specific program to avoid ?None? for that purpose, use it. > while choice != "q": > if choice == "c": > temp = input("Celsius temperature:") > print "Fahrenheit:",celsius_to_fahrenheit(temp) > elif choice == "f": > temp = input("Fahrenheit temperature:") > print "Celsius:",fahrenheit_to_celsius(temp) > elif choice != "q": > print_options() > choice = raw_input("option:") Python lacks a ?case? statement. But it does have functions as first-class objects; you can treat functions as data. So your approach above, with a chain of if-elif-elif clauses, is best replaced by a dispatch dictionary into functions specific to each command. Here's my attempt at making it more Pythonic and maintainable:: #! /usr/bin/python # -*- coding: utf-8 -*- import sys import textwrap def print_commands(): commands_display = ", ".join(commands.keys()) sys.stdout.write(textwrap.dedent("""\ Valid commands are: %(commands_display)s. """) % vars()) def quit(): raise SystemExit() def celsius_to_fahrenheit(in_value): return ((in_value * (9.0/5) + 32.0)) def fahrenheit_to_celsius(in_value): return ((in_value - 32.0) * (5.0/9)) def prompt_and_convert_temperature(labels, conversion_func): (from_label, to_label) = labels input = float(raw_input("%(from_label)s: " % vars())) result = conversion_func(input) sys.stdout.write("%(to_label)s temperature: %(result)0.2f\n" % vars()) commands = { 'q': (lambda: quit()), 'c': (lambda: prompt_and_convert_temperature( ["Celsius", "Fahrenheit"], celsius_to_fahrenheit)), 'f': (lambda: prompt_and_convert_temperature( ["Fahrenheit", "Celsius"], fahrenheit_to_celsius)), } if __name__ == '__main__': choice = None while choice is None: choice = raw_input("Command: ") if choice in commands: commands[choice]() else: choice = None print_commands() -- \ ?I am as agnostic about God as I am about fairies and the | `\ Flying Spaghetti Monster.? ?Richard Dawkins, 2006-10-13 | _o__) | Ben Finney From python at mrabarnett.plus.com Wed Nov 3 22:13:25 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 04 Nov 2010 02:13:25 +0000 Subject: Best method for a menu in a command line program? In-Reply-To: References: Message-ID: <4CD216C5.1080704@mrabarnett.plus.com> On 04/11/2010 01:19, braden faulkner wrote: > I'm using a menu for my command line app using this method. > > choice = "foobar" > while choice != "q": > if choice == "c": > temp = input("Celsius temperature:") > print "Fahrenheit:",celsius_to_fahrenheit(temp) > elif choice == "f": > temp = input("Fahrenheit temperature:") > print "Celsius:",fahrenheit_to_celsius(temp) > elif choice != "q": > print_options() > choice = raw_input("option:") > > Just wondering if there is another or more efficient way I should be doing it? > Here's an alternative: def option_c(): temp = input("Celsius temperature:") print "Fahrenheit:", celsius_to_fahrenheit(temp) def option_f(): temp = input("Fahrenheit temperature:") print "Celsius:", fahrenheit_to_celsius(temp) options = {"c": option_c, "f": option_f} while True: choice = raw_input("option:") if choice == "q": break options.get(choice, print_options)() From usernet at ilthio.net Wed Nov 3 22:19:23 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 4 Nov 2010 02:19:23 +0000 (UTC) Subject: Best method for a menu in a command line program? References: Message-ID: On 2010-11-04, braden faulkner wrote: > I'm using a menu for my command line app using this method. > > choice = "foobar" > while choice != "q": > if choice == "c": > temp = input("Celsius temperature:") > print "Fahrenheit:",celsius_to_fahrenheit(temp) > elif choice == "f": > temp = input("Fahrenheit temperature:") > print "Celsius:",fahrenheit_to_celsius(temp) > elif choice != "q": > print_options() > choice = raw_input("option:") > > Just wondering if there is another or more efficient way I should be doing it? You are looking for a dictionary with function references maybe? menu_options = { 'c':io_celsius_to_fahrenheit, 'f':io_fahrenheit_to_celsisus, 'q':print_options } The io versions of the functions would wrap the conversion functions to get the input and print the output. choice = "foobar" while choice != 'q': try: menu_options[choice]() except KeyError: # else code here choice = raw_input("option:") From invalid at invalid.invalid Wed Nov 3 22:20:26 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 4 Nov 2010 02:20:26 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-04, Emile van Sebille wrote: > On 11/3/2010 4:09 PM Seebs said... > >> What's the token that marks the end of a block, corresponding to the >> colon used to introduce it? >> > > > My thoughts tend more towards 'can we get Guido to eliminate the colon > requirements' -- The indent level of the next line ought to suffice. But without the colon, how are people who write programming editors going to know when to increase the indentation level as I enter code? > Seriously. Just as seriously. Syntactic sugar isn't just for humans... -- Grant From invalid at invalid.invalid Wed Nov 3 22:25:04 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 4 Nov 2010 02:25:04 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: On 2010-11-04, Seebs wrote: > On 2010-11-04, Lawrence D'Oliveiro wrote: >> In message , Seebs wrote: >>> It is extremely useful to me to have spaces converted to tabs >>> for every other file I edit. > >> I???m thinking of going the other way. After many years of treating tabs as >> four-column steps, I might give up on them and use spaces everywhere. I quit using tabs (except for Makefiles) about 30 years ago. > I *absolutely must* use tabs for Makefiles. And my editor (emacs) knows that. It uses tabs in Makefiles and spaces everywhere else. > For code in most other languages, it's merely a factor of 8 improvement > in storage. :) That's only true if your source code consists entirely of tabs. ;) -- Grant From brf256 at gmail.com Wed Nov 3 22:25:49 2010 From: brf256 at gmail.com (brf256 at gmail.com) Date: Thu, 4 Nov 2010 02:25:49 +0000 Subject: Best method for a menu in a command line program? Message-ID: <1976176960-1288837552-cardhu_decombobulator_blackberry.rim.net-370756585-@bda480.bisx.prod.on.blackberry> Thanks for the help! Ill incorporate this into my menu. Thanks again, Braden Faulkner Sent wirelessly from my BlackBerry device on the Bell network. Envoy? sans fil par mon terminal mobile BlackBerry sur le r?seau de Bell. From python.list at tim.thechases.com Wed Nov 3 22:26:30 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 03 Nov 2010 21:26:30 -0500 Subject: What people are using to access this mailing list In-Reply-To: References: Message-ID: <4CD219D6.1020702@tim.thechases.com> On 11/03/10 20:41, QoS wrote: > Jed Smith wrote >> I just prefer the Gmail philosophy to mail, with tags that are *like* >> folders but not really. > > If that is what you used to post this reply then your client is broken somewhat. I'm not sure I'd go casting aspersions on other peoples broken-clients when your own client seems to have sent 6 nearly-identical copies of the same message to the newsgroup. None of which appeared (at least in Thunderbird-as-NNTP-reader) as followups to Jed's message, but rather as follow-ups to the OP's initial post. -tkc From invalid at invalid.invalid Wed Nov 3 22:27:06 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 4 Nov 2010 02:27:06 +0000 (UTC) Subject: What people are using to access this mailing list References: Message-ID: On 2010-11-04, QoS wrote: > Jed Smith wrote in message-id: >> I just prefer the Gmail philosophy to mail, with tags that are *like* >> folders but not really. > > Just in case the client may not display the headers, fyi: > > If gmail is what you used to post this reply then your client is > broken somewhat. > > Your client did not post using a well-formed references header and so > your post may/should not be grouped properly with the OP. I prefer that over posting 8 duplicate messages like your client did. :) -- Grant From gnarlodious at gmail.com Wed Nov 3 22:48:35 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Wed, 3 Nov 2010 19:48:35 -0700 (PDT) Subject: Py3: Import relative path module References: <044f2fb7-a6a9-4bb9-b2a6-8ee1d0c19612@u17g2000yqi.googlegroups.com> <4cce7768$0$29965$c3e8da3$5496439d@news.astraweb.com> <770dd3de-25f5-404c-a05a-7bdd2eb07179@26g2000yqv.googlegroups.com> <3e7dbd88-4d44-43fa-a0e2-6987c025ccdb@26g2000yqv.googlegroups.com> <01c6e36a-c4e0-499a-adc1-cb61d7b53725@r14g2000yqa.googlegroups.com> <102a52fc-13be-4557-8ee0-279cc2c2ea3e@w38g2000pri.googlegroups.com> Message-ID: <1b4f9e09-b28a-47c1-b31b-0e0bf53165b2@m20g2000prc.googlegroups.com> OK I've had a modicum of success! However I was forced to add the path to my application folder to sys.path, which I suppose is the closest I can get to what I want. The example given then works in the shell. Apache is another problem. I added the same path to the script then Apache finds the application folder and does the importing. Not an ideal solution, but workable. I hope Apache3 in the future has more smarts about importing relative filepaths. Thank you Peter for your patience on this! -- Rachel http://google.com/profiles/Gnarlodious From calderone.jeanpaul at gmail.com Wed Nov 3 23:00:00 2010 From: calderone.jeanpaul at gmail.com (Jean-Paul Calderone) Date: Wed, 3 Nov 2010 20:00:00 -0700 (PDT) Subject: pyOpenSSL 0.11 released References: Message-ID: <3ae55264-4605-443d-9007-f913c7e292c5@s4g2000yql.googlegroups.com> On Nov 1, 6:43?pm, exar... at twistedmatrix.com wrote: > Hello all, > > I'm happy to announce the release of pyOpenSSL 0.11. ?The primary change > from the last release is that Python 3.2 is now supported. ?Python 2.4 > through Python 2.7 are still supported as well. ?This release also fixes > a handful of bugs in error handling code. ?It also adds APIs for > generating and verifying cryptographic signatures and it improves the > test suite to cover nearly 80% of the implementation. > > Downloads and more details about the release can be found on the release > page: > > ? ?https://launchpad.net/pyopenssl/main/0.11 > It was helpfully pointed out to me that I forgot to mention that the Python 3.2 support in this release of pyOpenSSL was made possible by a grant from the Python Software Foundation. > Enjoy, > Jean-Paul From pavlovevidence at gmail.com Wed Nov 3 23:02:59 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 3 Nov 2010 20:02:59 -0700 (PDT) Subject: Best method for a menu in a command line program? References: Message-ID: <18f366c3-2dc2-4231-89f4-3af433b161f4@r14g2000yqa.googlegroups.com> On Nov 3, 6:19?pm, braden faulkner wrote: > I'm using a menu for my command line app using this method. > > choice = "foobar" > while choice != "q": > ? ? if choice == "c": > ? ? ? ? temp = input("Celsius temperature:") > ? ? ? ? print "Fahrenheit:",celsius_to_fahrenheit(temp) > ? ? elif choice == "f": > ? ? ? ? temp = input("Fahrenheit temperature:") > ? ? ? ? print "Celsius:",fahrenheit_to_celsius(temp) > ? ? elif choice != "q": > ? ? ? ? print_options() > ? ? choice = raw_input("option:") > > Just wondering if there is another or more efficient way I should be doing it? You're not even close to the point where you have to start worrying about efficiency. If you're at a point where efficiency matters, then by that point you should have long ago refactored it into a function-call dispatch (which is what others have posted) for the sake of organizing code. For this program, what you have it fine. Carl Banks From ben+python at benfinney.id.au Wed Nov 3 23:06:20 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 04 Nov 2010 14:06:20 +1100 Subject: Best method for a menu in a command line program? References: <87fwvhhmkc.fsf@benfinney.id.au> Message-ID: <8762wdhjo3.fsf@benfinney.id.au> Ben Finney writes: > Here's my attempt at making it more Pythonic and maintainable:: [?] > def celsius_to_fahrenheit(in_value): > return ((in_value * (9.0/5) + 32.0)) Hmm. I went a bit overboard with the parens. This is what I'd prefer:: def celsius_to_fahrenheit(in_value): return (in_value * (9.0/5) + 32.0) -- \ ?There's a certain part of the contented majority who love | `\ anybody who is worth a billion dollars.? ?John Kenneth | _o__) Galbraith, 1992-05-23 | Ben Finney From jerradgenson at gmail.com Wed Nov 3 23:36:42 2010 From: jerradgenson at gmail.com (Jerrad Genson) Date: Wed, 3 Nov 2010 20:36:42 -0700 (PDT) Subject: Possible bug in multiprocessing.Queue() on Ubuntu Message-ID: Hello, While working with the multiprocessing module in Python 2.6.6 on Ubuntu 10.10 64-bit, the following exception was raised: >>> import multiprocessing >>> input_queue = multiprocessing.Queue() Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.6/multiprocessing/__init__.py", line 213, in Queue return Queue(maxsize) File "/usr/lib/python2.6/multiprocessing/queues.py", line 37, in __init__ self._rlock = Lock() File "/usr/lib/python2.6/multiprocessing/synchronize.py", line 117, in __init__ SemLock.__init__(self, SEMAPHORE, 1, 1) File "/usr/lib/python2.6/multiprocessing/synchronize.py", line 49, in __init__ sl = self._semlock = _multiprocessing.SemLock(kind, value, maxvalue) OSError: [Errno 30] Read-only file system The same exception was also raised in Python 3.1.2 on the same platform: >>> import multiprocessing >>> input_queue = multiprocessing.Queue() Traceback (most recent call last): File "", line 1, in File "/usr/lib/python3.1/multiprocessing/__init__.py", line 212, in Queue return Queue(maxsize) File "/usr/lib/python3.1/multiprocessing/queues.py", line 37, in __init__ self._rlock = Lock() File "/usr/lib/python3.1/multiprocessing/synchronize.py", line 121, in __init__ SemLock.__init__(self, SEMAPHORE, 1, 1) File "/usr/lib/python3.1/multiprocessing/synchronize.py", line 49, in __init__ sl = self._semlock = _multiprocessing.SemLock(kind, value, maxvalue) OSError: [Errno 30] Read-only file system This also occurs in Ubuntu 10.04 64-bit, but it works just fine in Ubuntu 10.10 32-bit. Out of curiosity, I downloaded the latest version of the Python 3.2a3+ source from the official Subversion repository, configured it for debugging mode, compiled, and ran the same commands. >>> import multiprocessing [66271 refs] >>> input_queue = multiprocessing.Queue() Traceback (most recent call last): File "/home/jerrad/Development/py3k/Lib/multiprocessing/ synchronize.py", line 28, in from _multiprocessing import SemLock ImportError: cannot import name SemLock During handling of the above exception, another exception occurred: Traceback (most recent call last): File "", line 1, in File "/home/jerrad/Development/py3k/Lib/multiprocessing/ __init__.py", line 212, in Queue from multiprocessing.queues import Queue File "/home/jerrad/Development/py3k/Lib/multiprocessing/queues.py", line 22, in from multiprocessing.synchronize import Lock, BoundedSemaphore, Semaphore, Condition File "/home/jerrad/Development/py3k/Lib/multiprocessing/ synchronize.py", line 33, in " function, see issue 3770.") ImportError: This platform lacks a functioning sem_open implementation, therefore, the required synchronization primitives needed will not function, see issue 3770. [69570 refs] After checking issue 3770 in Roundup, it appears this is a known issue for FreeBSD and OpenBSD, but not for Ubuntu (and it works fine in 32- bit Ubuntu!). I just want to ensure I'm not doing something stupid before I submit this to the issue tracker. From lists at asd-group.com Thu Nov 4 00:24:00 2010 From: lists at asd-group.com (John Bond) Date: Thu, 04 Nov 2010 04:24:00 +0000 Subject: What people are using to access this mailing list In-Reply-To: References: <4cd144cc$0$29966$c3e8da3$5496439d@news.astraweb.com> <87r5f2wr7t.fsf@rudin.co.uk> Message-ID: <4CD23560.9090101@asd-group.com> On 3/11/2010 7:16 PM, Grant Edwards wrote: > The OP could have figured all this out by himself by merely looking at > the headers for a sampling of articles. > > Heck, with about 50 lines of Python, one could probably produced a > fairly comprehensive statistical report on access methods and clients > used by posters to "this mailing list". [An NNTP client module is one > of the "batteries", and that module's docs contains most of the code > needed to access the articles.] > > Finding out the access methods used by people who don't post is > somewhat more difficult. :) > The OP isn't that clever! :o) Cheers, JB From mygogo2011 at gmail.com Thu Nov 4 00:47:43 2010 From: mygogo2011 at gmail.com (PHP.CCC) Date: Wed, 3 Nov 2010 21:47:43 -0700 (PDT) Subject: SCOLAR SHIP FOR USA UNIVERSITY (University of Phoenix ) Message-ID: SCOLAR SHIP FOR USA UNIVERSITY (University of Phoenix ) The campus location in Concord, California is located near Interstate 680 and State Route 242 in Contra Costa County, California. This location offers undergraduate and graduate degree programs that are targeted to meet the needs of students and working adults as well. Read More>>>> http://studyloc.blogspot.com/ From gstepken at googlemail.com Thu Nov 4 02:45:02 2010 From: gstepken at googlemail.com (Guido Stepken) Date: Thu, 04 Nov 2010 07:45:02 +0100 Subject: cms 4 static pages? Message-ID: hi folks! m looking 4 a framework, that allows to build static community software (similar to facebook) without having to start scripts, database connects, admin cookies, e.t.c. means - should be dynamic without really being dynamic, delivering just static pages. (yes, i know e.g. nginx does that by caching, thats not what i want!) features wanted: a not database driven b password access ist done by just renaming users home directory. User at logout will receive new secret subdirectory name 4 new login. c no clientside scripting. changing layout will be done by rebuilding all relevant static pages in user directory once by serverside script. d new entries e.g. mail, discussions will be queued, user just sees: tnx 4 your new article, page will be rebuilt in ... estimated 3 seconds ... or estimated 10 seconds ... depending on load and todo queue length. e load balancing is done by just replicating static pages between servers after new rebuild of static pages. f simulation of received mail directory through just rebuilding relevant static html tree. attachments not allowed. g intelligent todo queue 4 resorting mail sent, received, discussions, look and feel before rebuilding static user pages. (herein lies the intelligence of the whole system) h notifications 4 new mail, messages, e.t.c. are just updates in static html fields. if user gets offline (measured by time since last update of static pages) user will be informed once a day by mail. i simulation of locking can easily be done by dotfiles. j according 2 my calculations such system should be able 2 satisfy any bandwidth without causing significant load of cpu, due 2 low protocol overhead and no server side scripting, no database load. overload of server should not possible by design. k modules, addon 4 twitter e.g., nice 2 have (and no, no java!) any pointers? tnx in advance, Guido Stepken From ldo at geek-central.gen.new_zealand Thu Nov 4 03:07:31 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 04 Nov 2010 20:07:31 +1300 Subject: functions, list, default parameters References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <8ivelpFif1U1@mid.individual.net> <4cca88bc$0$29987$c3e8da3$5496439d@news.astraweb.com> <8j1seqFa1eU2@mid.individual.net> Message-ID: In message , Robert Kern wrote: > On 11/2/10 2:12 AM, Lawrence D'Oliveiro wrote: > >> In message, Robert >> Kern wrote: >> >>> "Immutable objects" are just those without an obvious API for modifying >>> them. >> >> They are ones with NO legal language constructs for modifying them. Hint: >> if a selector of some part of such an object were to occur on the LHS of >> an assignment, and that would raise an error, then the object is >> immutable. The interpreter already knows all this. > > Incorrect. RHS method calls can often modify objects. So bloody what? > Show me the algorithm that the interpreter can use to determine whether or > not an object is mutable. Go look in the code for the one it already uses in places where immutable objects are currently required. >>> With various trickeries, I can mutate any immutable object. >> >> None within the Python language itself. Which is what we?re talking about >> here: a language construct which is probably one of the top 3 sources of >> grief to Python newbies. And not-so-newbies. > > "import ctypes" is within the Python language. And in the old BASIC days, we had ?PEEK? and ?POKE?. So by your reasoning, that invalidated the language rules, too. From arnodel at gmail.com Thu Nov 4 03:15:33 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Thu, 04 Nov 2010 07:15:33 +0000 Subject: Best method for a menu in a command line program? References: <87fwvhhmkc.fsf@benfinney.id.au> Message-ID: <87hbfxk19m.fsf@gmail.com> Ben Finney writes: [...] > commands = { > 'q': (lambda: quit()), > 'c': (lambda: prompt_and_convert_temperature( > ["Celsius", "Fahrenheit"], celsius_to_fahrenheit)), > 'f': (lambda: prompt_and_convert_temperature( > ["Fahrenheit", "Celsius"], fahrenheit_to_celsius)), None: print_commands, > } > > > if __name__ == '__main__': > choice = None > while choice is None: > choice = raw_input("Command: ") commands.get(choice)() -- Arnaud From steve-REMOVE-THIS at cybersource.com.au Thu Nov 4 03:33:14 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 04 Nov 2010 07:33:14 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4cd261ba$0$29972$c3e8da3$5496439d@news.astraweb.com> On Wed, 03 Nov 2010 23:09:10 +0000, Seebs wrote: > On 2010-11-03, Steven D'Aprano > wrote: >> Yes. How does that contradict what I said? > > Once you understand that you do have to break the rules occasionally, it > is a good idea to design things that will be robust when the rules are > broken. That does not follow. As a general rule, one should not expect that electronic equipment should be safe to operate under water. But there are exceptional cases. So what should we do? (1) Insist that all consumer electronic equipment is designed to operate under water? (All blocks need redundant START/END tags just in case you're operating in an environment where indentation can't be trusted.) (2) Tell people not to drop their toaster into the bath tub, and leave it up to the exceptional cases to deal with the need for water-proof electronics in whatever way they see fit? (Trust the indentation, tell people not to mangle their source files with dodgy mail servers, and if you need redundant tags, build your own solution.) >> Ah, argument by misunderstanding the Zen! > > I see. So explicit boundaries are a good thing, except when they are > one specific special case. INDENT/OUTDENT is an explicit boundary. > Let us imagine a hypothetical mirror-universe person, who is otherwise > like you, but: > > 1. Has a goatee. > 2. Actually hates the indentation rules, wishes Python had braces, but > has become emotionally invested in defending the status quo because if > he had to suffer, dammit, everyone else should have to suffer too. I had to suffer? Funny, I hardly noticed. > You have not yet made a single argument that he wouldn't have made too. The arguments Evil-Steven would make would be your arguments: * redundant BEGIN/END tags make blocks robust in environments where indentation can't be trusted; * there are tools out there that assume that indentation is meaningless, and some people want to use those tools, so the language is poorly designed; I *understand* your arguments, I just don't value them. But in fact, non- evil Steven made the opposite arguments: Re extra redundancy: you aren't going to need it often enough to make up for the extra effort of dealing with BEGIN/END tags that can contradict the indentation. Re tools: if the tools don't fit your use-case, your tools are broken, and you should change your tools. >>> It is *better* to explicitly mark the ends of things than to have it >>> be implicit in dropping indentation. That's not a burden, it's good >>> engineering practice. > >> Python does explicitly mark blocks. It does it by changes in >> indentation. An indent is an explicit start-block. An outdent is an >> explicit end- block. There is nothing implicit in a change in indent >> level. > > What's the token that marks the end of a block, corresponding to the > colon used to introduce it? Your assumption is incorrect. Blocks are introduced by an increase in indentation level, not by a colon. The colon is enforced, but it's there for the benefit of readability rather than to mark a new block. You can write: if condition: true_clause() else: false_clause() No blocks are started, the clauses are limited to a single line, but the colons are still required. To end the block, you need a decrease in indentation limit. In fact, the Python parser actually places overt INDENT/OUTDENT tokens into the token stream. # From token.py: INDENT = 5 DEDENT = 6 >> It simply isn't possible to have implicit start/end block markers, >> unless you restrict your language in ways that exclude most blocks. >> E.g. if all if blocks were restricted to a single statement, then you >> could have an implicit block -- the block in one statement. Stating >> that Python uses implicit block markers is simply wrong. > > No, it isn't. There's no token telling you where the block ended. I disagree, but for the sake of the argument let's suppose you are correct. So what? x = 123+456 There's no tokens telling you where the ints 123 and 456 begin and end either. So where's the problem? Signals, or tokens if you like, can be explicitly made either by placing a distinct marker (a delimiter or separator), or by a change of state. In the case of ints, the explicit end-of-token is a change of state, not a marker: digit digit digit non-digit There's no need for a distinct End Of Int marker, because the change of state is explicit enough. But this is not the case for strings, which you mentioned in an earlier post. Strings require a special BEGIN/END tag because they may be terms in expressions and you can't assume they will end at the end of the line (a change of state). If you have an environment where strings do end at the end of the line, such as INI files, you can avoid the delimiters: [section] x = Hello world. y = Goodnight Gracie! but in a general purpose programming language where strings can be terms in expressions, you need delimiters. Blocks are more like ints than strings. They don't need delimiters, because they start and end according to an explicit change of state. -- Steven From steve-REMOVE-THIS at cybersource.com.au Thu Nov 4 03:37:24 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 04 Nov 2010 07:37:24 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> On Wed, 03 Nov 2010 23:42:55 +0000, Seebs wrote: > No one has claimed that this is a problem *for everybody*. Just that > there exist real-world workflows for which it is a problem, or people > for whom it is a problem. And people have suggested that if your workflow leads to indentation being mangled and your source code no longer running, the solution is to change the workflow. If you can't change the workflow, you have my sympathy, but that's not Python's fault, and Python isn't designed for your use-case of web servers that convert your source code to HTML and text editors that mangle indentation. Nor is Python designed for use on computers where the file system randomly corrupts files, or a work-flow where your Pointy-Haired boss keeps making random changes to production scripts in an effort to prove he knows best. If you have such a work-flow, don't suggest that we should add error-correcting codes to the language in order to fix your problem. We can sympathize with your troubles while still saying Not Our Problem. > Given the > degree to which the rest of the world has standardized on not caring how > *much* whitespace is between things (though sometimes caring whether or > not there's *any* whitespace between them), it seems to me that the odd > man out is the one who is creating the burden. What burden? You keep talking about this burden of not-having-to-type- braces, but I don't see any burden, and nor do the majority of Python programmers. What we see is dozens of languages, and thousands of people, who have built all these wonderful devices and tools for helping them carry a refrigerator on their head (a bar fridge, naturally, it would be foolish to carry a full-sized fridge and freezer combo). That's fine if you need to carry a fridge on your head, and I'm really glad that your tools take 90% of the weight for you. I'm sure you hardly even notice it any more. But then you start arguing that it's *really important* to carry a fridge on your head *everywhere* because you never know when you'll be somewhere where you MUST HAVE a fridge, and all hell will break loose if you don't have one, well, we just think you're a bit strange. It's not that we don't think fridges are useful. And we understand the logic -- yes, if you need a fridge and don't have one, bad things will happen, but why limit it to fridges? Why not a sewing machine, and a jack hammer, and a piano, and ... there's no limit to the number of things you might need, and the difference in risk between not having any of them and not having any of them bar one is negligible. And then you start telling us how we're the weird ones because we have the "burden" of not-carrying-a-fridge everywhere! -- Steven From eckhardt at satorlaser.com Thu Nov 4 03:44:01 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Thu, 04 Nov 2010 08:44:01 +0100 Subject: Subclassing unittest.TestCase? References: Message-ID: <1r4aq7-gs.ln1@satorlaser.homedns.org> Roy Smith wrote: > I'm writing a test suite for a web application. There is a subclass of > TestCase for each basic page type. [...] > class CommonTestCase(unittest.TestCase): > def test_copyright(self): > self.assert_(find copyright notice in DOM tree) > > class HomepageTestCase(CommonTestCase): [...] > This works fine as far as HomepageTestCase running test_copyright() and > test_whatever(). The problem is that CommonTestCase *also* runs > test_copyright(), which fails because there's no setUp(), and thus no > retrieved page for it to work on. Rename the function to _test_copyright and then in the derived class either call it or just test_copyrigth = CommonTestCase._test_copyright > Is there a cleaner way to define some common test methods which all of > my test cases can inherit, without having them be run in the base class? I haven't tried it, but you could put the test into a separate baseclass that doesn't derive from unittest.TestCase. All tests that pull a page and need to check for this then add this class to the baseclasses. Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From usenet-nospam at seebs.net Thu Nov 4 04:17:10 2010 From: usenet-nospam at seebs.net (Seebs) Date: 04 Nov 2010 08:17:10 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-04, Steven D'Aprano wrote: > And people have suggested that if your workflow leads to indentation > being mangled and your source code no longer running, the solution is to > change the workflow. Yup. But it strikes me as unmistakably a shortcoming of Python (and Makefiles, for that matter) that code for them can't survive a common failure mode that everything else I use can. > What burden? The burden of using different tools because suddenly the version of vi I've been using since 1990 is magically "broken" even though it's never caused a problem before. > You keep talking about this burden of not-having-to-type- > braces, but I don't see any burden, and nor do the majority of Python > programmers. Of course not. Most of the people who find it annoying *don't use Python*. Of the programmers I know who don't use Python, 100% have cited the annoyance value *to them* of the whitespace thing as the main reason they don't. Of the programmers I know outside this newsgroup who *do* use Python, 100% have said the whitespace thing is annoying and they wish Python didn't have it, but they have to use Python for some externally-imposed reason, so they put up with it. Outside of people who seem to be deeply emotionally invested in insisting that it is never, at all, in ANY way, for ANY person, annoying, it seems to be pretty consistent to observe that, benefits or no benefits, it has some kind of non-zero annoyance value. Other languages I use are mostly amenable to the development of tools to automatically indent code. Makefiles and Python are the only two exceptions... And if I were an advocate for a language, the fact that it's lumped itself in with Makefiles in a significant way would be a weakness I'd feel obliged to be up front about. :) The underlying issue is this: * Not having to type braces: Yay! * Having structure map to functionality: Some people quite like it, and certainly there exists a class of theoretical errors which it prevents. * Not being able to write an auto-indenter, ever, because it is by design theoretically impossible: Annoying. I guess if people could show me some of these errors in other languages where indentation is misleading and bugs resulted, I'd be more persuaded by the second point there. As is, I find the brittleness more annoying than I've ever found braces or 'end' or whatever. It's not annoying enough for me to refuse to use the language when there are other compelling reasons to, but it's certainly annoying enough that I'll never use Python for something where I have unfettered choice of language. It's less fun to program in, for me. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From goodman.m.w at gmail.com Thu Nov 4 04:22:09 2010 From: goodman.m.w at gmail.com (goodman) Date: Thu, 4 Nov 2010 01:22:09 -0700 (PDT) Subject: subprocess.Popen not replacing current process? Message-ID: <0f1a17f4-b6a9-4e89-ac26-74b1098a065e@b19g2000prj.googlegroups.com> Note: Our server is a Linux machine, but we're restricted to Python 2.4. Hi, I'm wondering why subprocess.Popen does not seem to replace the current process, even when it uses os.execvp (according to the documentation: http://docs.python.org/library/subprocess.html#subprocess.Popen). Specifically, when I try to kill a spawned process with Ctrl-C, the SIGINT does not seem to be sent to the spawned process. Some background: I have a Python script that calls shell scripts or commands. It does not need to regain control after calling these scripts or commands, so up to now I've been using an os.exec* command. It seems the subprocess module is the recommended way for spawning processes, but in this case perhaps it's better I stick with os.exec*? I've seen plenty of discussion about catching KeyboardInterrupt in the parent process and then manually killing the child, but (1) I can't use Popen.kill() on Python 2.4, and (2) this level of process management seems like overkill (pardon the potential for puns) in my case. Thanks for any help. From lanyjie at yahoo.com Thu Nov 4 05:14:25 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Thu, 4 Nov 2010 02:14:25 -0700 (PDT) Subject: Must be a bug in the re module [was: Why this result with the re module] In-Reply-To: <4CD1A307.2010809@mrabarnett.plus.com> Message-ID: <359401.16341.qm@web54203.mail.re2.yahoo.com> --- On Wed, 11/3/10, MRAB wrote: > [snip] > The outer group is repeated, so it can match again, but the > inner group > can't match again because it captured all it could the > previous time. > > Therefore the outer group matches and captures an empty > string and the > inner group remembers its last capture. Thanks, I got it. Basically, '(.a.)*' matched an empty string in the last outer group match, but not '(.a.)'. Now what remains hard for me to figure out is the number of matches: why is it 6 times with '((.a.)*)*' when matched to 'Mary has a lamb'? I think this is probably cuased by the limit of the matchobject: this object does not say anything about if an empty string is appended to the matched pattern or not. Hence some of the empty strings are repeated/overlapped by re.findall(). Regards, Yingjie From csjcg2 at gmail.com Thu Nov 4 05:37:31 2010 From: csjcg2 at gmail.com (Jo Chan) Date: Thu, 4 Nov 2010 17:37:31 +0800 Subject: Is there a OrderedDict which can perform an iteritems() in order? Message-ID: Hello all, I have working on a program which need a ordered dictionary that could perform iteritems() sequentially. I found a package on : http://www.voidspace.org.uk/python/odict.html#creating-an-ordered-dictionary but it could only perform items() in order, but iteritems()... Would you help me here? songjian 11.4 -- ------------------ Best Regards ??? ????????? ???? ????? 510006 Chen Songjian School of Information Science & Technology Sun Yat-sen(Zhongshan) University, Guangzhou Higher Education Mega Center, China, 510006 Mobile: +86-137-6069-6137 Email: csjcg2 at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From vlastimil.brom at gmail.com Thu Nov 4 05:49:29 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Thu, 4 Nov 2010 10:49:29 +0100 Subject: Is there a OrderedDict which can perform an iteritems() in order? In-Reply-To: References: Message-ID: 2010/11/4 Jo Chan : > Hello all, > ?? ? I have working on a program which need a ordered dictionary that could > perform iteritems() sequentially. > ?? ? I found a package on > :?http://www.voidspace.org.uk/python/odict.html#creating-an-ordered-dictionary > ?? ? but it ?could only perform items() in order, but iteritems()... > ?? ? Would you help me here? > songjian > ... Hi, it seems the standard library implementation in collections (OrderedDict) has the iteritems() method (checked on python 2.7). Does it not work the way you need? hth, vbr From pascal22p at parois.net Thu Nov 4 06:13:07 2010 From: pascal22p at parois.net (Pascal) Date: Thu, 04 Nov 2010 11:13:07 +0100 Subject: openmp do loops Message-ID: <4cd28734$0$12350$426a74cc@news.free.fr> Hi, I would like to parallelize this loop: do i=1,hklsize fcalctable(i)=structfact(hkltable(1,i),hkltable(2,i),hkltable(3,i)) end do I thought I would do this: !$OMP PARALLEL DO default(private) shared(hkltable, fcalctable,hklsize) do i=1,hklsize fcalctable(i)=structfact(hkltable(1,i),hkltable(2,i),hkltable(3,i)) end do !$OMP END PARALLEL DO However it seems that the order of the final table is not guarantee compared to the serial version. I need a j element of the table to stay there because I have an other table and I am using the index to match the data. Regards, Pascal From pascal22p at parois.net Thu Nov 4 06:31:20 2010 From: pascal22p at parois.net (Pascal) Date: Thu, 04 Nov 2010 11:31:20 +0100 Subject: openmp do loops In-Reply-To: <4cd28734$0$12350$426a74cc@news.free.fr> References: <4cd28734$0$12350$426a74cc@news.free.fr> Message-ID: <4cd28b78$0$10315$426a34cc@news.free.fr> On 11/04/2010 11:13 AM, Pascal wrote: > Hi, > Oops, wrong group, sorry... Pascal From michele.simionato at gmail.com Thu Nov 4 06:40:55 2010 From: michele.simionato at gmail.com (Michele Simionato) Date: Thu, 4 Nov 2010 03:40:55 -0700 (PDT) Subject: Best method for a menu in a command line program? References: Message-ID: <62c9c1f4-be12-4318-ad10-f9c8f84eabbc@t35g2000yqj.googlegroups.com> On Nov 4, 2:19?am, braden faulkner wrote: > I'm using a menu for my command line app using this method. > > choice = "foobar" > while choice != "q": > ? ? if choice == "c": > ? ? ? ? temp = input("Celsius temperature:") > ? ? ? ? print "Fahrenheit:",celsius_to_fahrenheit(temp) > ? ? elif choice == "f": > ? ? ? ? temp = input("Fahrenheit temperature:") > ? ? ? ? print "Celsius:",fahrenheit_to_celsius(temp) > ? ? elif choice != "q": > ? ? ? ? print_options() > ? ? choice = raw_input("option:") > > Just wondering if there is another or more efficient way I should be doing it? > > Thanks > -- Braden Faulkner Here is a solution using plac (http://pypi.python.org/pypi/plac): $ echo c2f.py import plac class Converter(object): commands = ['celsius_to_fahrenheit', 'fahrenheit_to_celsius'] @plac.annotations(t='convert Celsius to Fahrenheit') def celsius_to_fahrenheit(self, t): return round(32 + float(t) * 9/5) @plac.annotations(t='convert Fahrenheit to Celsius') def fahrenheit_to_celsius(self, t): return round((float(t) - 32) * 5 / 9.0) if __name__ == '__main__': import plac; plac.Interpreter.call(Converter) Here is an example of non-interactive usage: $ python c2f.py fahrenheit_to_celsius 212 100.0 $ python c2f.py celsius_to_fahrenheit 100 212.0 Here is an example of interactive usage:$ python c2f.py -i i> celsius_to_fahrenheit 100 212.0 i> celsius_to_fahrenheit 0 32.0 i> fahrenheit_to_celsius 32 0.0 i> fahrenheit_to_celsius 212 100.0 From stefan_ml at behnel.de Thu Nov 4 06:48:09 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 04 Nov 2010 11:48:09 +0100 Subject: openmp do loops In-Reply-To: <4cd28734$0$12350$426a74cc@news.free.fr> References: <4cd28734$0$12350$426a74cc@news.free.fr> Message-ID: Pascal, 04.11.2010 11:13: > I would like to parallelize this loop: > do i=1,hklsize > fcalctable(i)=structfact(hkltable(1,i),hkltable(2,i),hkltable(3,i)) > end do > > I thought I would do this: > !$OMP PARALLEL DO default(private) shared(hkltable, fcalctable,hklsize) > do i=1,hklsize > fcalctable(i)=structfact(hkltable(1,i),hkltable(2,i),hkltable(3,i)) > end do > !$OMP END PARALLEL DO Seeing this makes me seriously happy that I can write my code in Python (or Cython, for that purpose). Stefan From tinnews at isbd.co.uk Thu Nov 4 07:04:51 2010 From: tinnews at isbd.co.uk (tinnews at isbd.co.uk) Date: Thu, 4 Nov 2010 11:04:51 +0000 Subject: What people are using to access this mailing list References: <4cd144cc$0$29966$c3e8da3$5496439d@news.astraweb.com> <87r5f2wr7t.fsf@rudin.co.uk> Message-ID: Tim Harig wrote: > On 2010-11-03, Grant Edwards wrote: > > On 2010-11-03, Paul Rudin wrote: > >> John Bond writes: > >> > >>> On 3/11/2010 11:17 AM, Steven D'Aprano wrote: > >>>> On Wed, 03 Nov 2010 08:02:29 +0000, John Bond wrote: > >>>> > >>>>> Hope this isn't too O/T - I was just wondering how people read/send to > >>>>> this mailing list, eg. normal email client, gmane, some other software > >>>>> or online service? > >>>> Usenet via my ISP, on comp.lang.python. > >>>> > >>> Using what client (or web client)? > >> > >> Emacs, of course :-; > > > > Slrn, of course. > > Of, course. Well I actually prefer tin to slrn but that's what's good, both are available still and well supported. -- Chris Green From ben+python at benfinney.id.au Thu Nov 4 07:33:00 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 04 Nov 2010 22:33:00 +1100 Subject: Best method for a menu in a command line program? References: <87fwvhhmkc.fsf@benfinney.id.au> <87hbfxk19m.fsf@gmail.com> Message-ID: <871v71gw7n.fsf@benfinney.id.au> Arnaud Delobelle writes: > Ben Finney writes: > [...] > > commands = { > > 'q': (lambda: quit()), > > 'c': (lambda: prompt_and_convert_temperature( > > ["Celsius", "Fahrenheit"], celsius_to_fahrenheit)), > > 'f': (lambda: prompt_and_convert_temperature( > > ["Fahrenheit", "Celsius"], fahrenheit_to_celsius)), > > None: print_commands, This would be counter to the problem as stated by the OP. The program originally described loops *only* if no other command is specified; yours doesn't distinguish. -- \ ?It is far better to grasp the universe as it really is than to | `\ persist in delusion, however satisfying and reassuring.? ?Carl | _o__) Sagan | Ben Finney From jeanmichel at sequans.com Thu Nov 4 07:34:08 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 04 Nov 2010 12:34:08 +0100 Subject: python logging, handling multiline log entries Message-ID: <4CD29A30.30102@sequans.com> Hi python fellows, I'm looking to do the following : import logging l = logging.getLogger('aHeader') l.handlers = [] l.addHandler(logging.StreamHandler()) l.handlers[-1].setFormatter(logging.Formatter("%(asctime)s - %(name)s - %(message)s")) l.error('1st line\n2nd line') output: 2010-11-04 12:22:05,593 - aHeader - 1st line 2nd line I'd like to get something like: 2010-11-04 12:22:05,593 - aHeader - 1st line 2nd line I don't want to get the header on every line, otherwise I would just need to log every lines. Is there a simple way of doing that? anyone already gave a though on that ? The main problem I'm facing is that I cannot alter the log entry itself, I don't know the size of the header and I think it would be anti-pattern. My guess is that it should be handled in the formatter, overriding the format method, but how do you get the header size (i.e. the indentation size). So if anyone has a piece of code doing that, feel free to point it to me. Cheers, JM From ben+python at benfinney.id.au Thu Nov 4 07:35:29 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 04 Nov 2010 22:35:29 +1100 Subject: Best method for a menu in a command line program? References: Message-ID: <87wrotfhj2.fsf@benfinney.id.au> brf256 at gmail.com writes: > Thanks again, > Braden Faulkner > > Sent wirelessly from my BlackBerry device on the Bell network. > Envoy? sans fil par mon terminal mobile BlackBerry sur le r?seau de Bell. Please show your thanks by *not* spamming the forum with each message; compose your messages from a mail client that doesn't feel the need to blather about itself in the message body. -- \ ?For fast acting relief, try slowing down.? ?Jane Wagner, via | `\ Lily Tomlin | _o__) | Ben Finney From __peter__ at web.de Thu Nov 4 07:49:01 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 04 Nov 2010 12:49:01 +0100 Subject: Best method for a menu in a command line program? References: Message-ID: braden faulkner wrote: > I'm using a menu for my command line app using this method. > > choice = "foobar" > while choice != "q": > if choice == "c": > temp = input("Celsius temperature:") > print "Fahrenheit:",celsius_to_fahrenheit(temp) > elif choice == "f": > temp = input("Fahrenheit temperature:") > print "Celsius:",fahrenheit_to_celsius(temp) > elif choice != "q": > print_options() > choice = raw_input("option:") > > Just wondering if there is another or more efficient way I should be doing > it? The user interface will be slightly different, but the cmd module is great to build simple interactive command line apps quickly: # -*- coding: utf-8 -*- from __future__ import division import cmd class Cmd(cmd.Cmd): prompt = "Enter a command (? for help) --> " def do_celsius_to_fahrenheit(self, value): """Convert Celsius to Fahrenheit""" celsius = float(value) print u"%f ?F" % (celsius * 9/5 + 32) def do_fahrenheit_to_celsius(self, value): fahrenheit = float(value) print u"%f ?C" % ((fahrenheit - 32) * 5/9) def do_quit(self, value): return True do_EOF = do_quit Cmd().cmdloop() A sample session: $ python convert_temperature.py Enter a command (? for help) --> ? Documented commands (type help ): ======================================== celsius_to_fahrenheit Undocumented commands: ====================== EOF fahrenheit_to_celsius help quit Enter a command (? for help) --> ? celsius_to_fahrenheit Convert Celsius to Fahrenheit Enter a command (? for help) --> celsius_to_fahrenheit 0 32.000000 ?F Enter a command (? for help) --> fahrenheit_to_celsius 212 100.000000 ?C Enter a command (? for help) --> quit $ Peter From jeanmichel at sequans.com Thu Nov 4 07:57:52 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 04 Nov 2010 12:57:52 +0100 Subject: python logging, handling multiline log entries In-Reply-To: <4CD29A30.30102@sequans.com> References: <4CD29A30.30102@sequans.com> Message-ID: <4CD29FC0.30805@sequans.com> Jean-Michel Pichavant wrote: > Hi python fellows, > > I'm looking to do the following : > > import logging > > l = logging.getLogger('aHeader') > l.handlers = [] > l.addHandler(logging.StreamHandler()) > l.handlers[-1].setFormatter(logging.Formatter("%(asctime)s - %(name)s > - %(message)s")) > l.error('1st line\n2nd line') > > output: > 2010-11-04 12:22:05,593 - aHeader - 1st line > 2nd line > > > > I'd like to get something like: > 2010-11-04 12:22:05,593 - aHeader - 1st line > 2nd line > > I don't want to get the header on every line, otherwise I would just > need to log every lines. > > Is there a simple way of doing that? anyone already gave a though on > that ? > > The main problem I'm facing is that I cannot alter the log entry > itself, I don't know the size of the header and I think it would be > anti-pattern. My guess is that it should be handled in the formatter, > overriding the format method, but how do you get the header size (i.e. > the indentation size). > > So if anyone has a piece of code doing that, feel free to point it to me. > > Cheers, > > JM > > > You can ignore me, I just found an acceptable solution (i think). You guys still have been usefull because writing this mail helped me structure my thoughts :o) JM PS: class MultiLineFormatter(logging.Formatter): def format(self, record): str = logging.Formatter.format(self, record) header, footer = str.split(record.message) str = str.replace('\n', '\n' + ' '*len(header)) return str There could be a problem if "%(message)s" is not in the formatter string, but honestly, who would be doing that :) From Antoon.Pardon at rece.vub.ac.be Thu Nov 4 08:02:09 2010 From: Antoon.Pardon at rece.vub.ac.be (Antoon Pardon) Date: Thu, 4 Nov 2010 13:02:09 +0100 Subject: Compare source code In-Reply-To: <4cd1495f$0$29966$c3e8da3$5496439d@news.astraweb.com> References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1495f$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20101104120209.GA16757@rcpc42.vub.ac.be> On Wed, Nov 03, 2010 at 11:37:03AM +0000, Steven D'Aprano wrote: > On Wed, 03 Nov 2010 12:01:06 +1300, Lawrence D'Oliveiro wrote: > > > In message , Grant Edwards wrote: > > >> Other languages have similar problems if you remove salient bits of > >> syntax before comparing two source files files. > > > > But other languages don???t make those ???salient bits of syntax??? invisible. > > I.e. they are actually ???salient???. > > (1) Indentation is visible. Compare: > > > This line has leading visible whitespace. > > This line has leading invisible characters. > > See the difference? Unless, your code is split over different pages, as when it is printed in a book. You also need to see the next piece of code to notice the dedention. e.g. I have the following code at the bottom of my editor. for i := 0 to 9 do some(code); more(code); end; I can by just looking at this code notice that I'm looking at the whole for block. But when I have similar python code at the bottom of the page. for i in xrange(10): some(code) more(code) Then I can't make out whether I'm looking at the whole for suite or not. Indentation may be visible, but it is not context-free visible, It only becomes visible by looking by introducing context. So because it is only visible by looking at the context I would say the end of a block i made implicitly and not explicitly -- Antoon Pardon From invalid at invalid.invalid Thu Nov 4 09:43:13 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 4 Nov 2010 13:43:13 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-04, Seebs wrote: > On 2010-11-04, Steven D'Aprano wrote: >> And people have suggested that if your workflow leads to indentation >> being mangled and your source code no longer running, the solution is to >> change the workflow. > > Yup. > > But it strikes me as unmistakably a shortcoming of Python (and Makefiles, > for that matter) that code for them can't survive a common failure mode > that everything else I use can. I think the issue is that for whatever reason, white-space mangling is "a common failure mode" for you. I don't ever remember it happening to me. If whitespace mangling is common for you, then you just shouldn't be using Python any more than somebody who works on a system that randomly changes/deletes the strings "begin" and "end" should be using Pascal. -- Grant Edwards grant.b.edwards Yow! PEGGY FLEMMING is at stealing BASKET BALLS to gmail.com feed the babies in VERMONT. From moogyd at yahoo.co.uk Thu Nov 4 10:06:24 2010 From: moogyd at yahoo.co.uk (moogyd) Date: Thu, 4 Nov 2010 07:06:24 -0700 (PDT) Subject: Popen Question Message-ID: <891a9a80-c30d-4415-ac81-bddd0b564fa6@g13g2000yqj.googlegroups.com> Hi, I usually use csh for my simulation control scripts, but these scripts are becoming more complex, so I plan to use python for the next project. To this end, I am looking at subprocess.Popen() to actually call the simulations, and have a very basic question which is demonstrated below. [sde:staff at lbux03 ~]$ python Python 2.6 (r26:66714, Feb 21 2009, 02:16:04) [GCC 4.3.2 [gcc-4_3-branch revision 141291]] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import os, subprocess >>> os.environ['MYVAR'] = "myval" >>> p = subprocess.Popen(['echo', '$MYVAR'],shell=True) >>> >>> p = subprocess.Popen(['echo', '$MYVAR']) >>> $MYVAR >>> p = subprocess.Popen('echo $MYVAR',shell=True) >>> myval >>> p = subprocess.Popen('echo $MYVAR') Traceback (most recent call last): File "", line 1, in File "/usr/lib64/python2.6/subprocess.py", line 595, in __init__ errread, errwrite) File "/usr/lib64/python2.6/subprocess.py", line 1106, in _execute_child raise child_exception OSError: [Errno 2] No such file or directory I am not really sure I understand these results. 1) No idea what is going on 2) As (1). What isn't myval printed out (rather than $MYVAR) 3) Works as I wanted it to 4) Why do I need shell=True ? The documentation isn't very clear to me (it seems you need to understand the underlying system calls). Can anyone explain (or provide link) for this behaviour in simple English? Thanks, Steven From Antoon.Pardon at rece.vub.ac.be Thu Nov 4 10:08:13 2010 From: Antoon.Pardon at rece.vub.ac.be (Antoon Pardon) Date: Thu, 4 Nov 2010 15:08:13 +0100 Subject: Compare source code In-Reply-To: <4CD406A7.8040600@stoneleaf.us> References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1495f$0$29966$c3e8da3$5496439d@news.astraweb.com> <20101104120209.GA16757@rcpc42.vub.ac.be> <4CD406A7.8040600@stoneleaf.us> Message-ID: <20101104140813.GB16757@rcpc42.vub.ac.be> On Fri, Nov 05, 2010 at 06:29:11AM -0700, Ethan Furman wrote: > Antoon Pardon wrote: > >Unless, your code is split over different pages, as when it is printed in a book. > >You also need to see the next piece of code to notice the dedention. > > > >e.g. I have the following code at the bottom of my editor. > > > > for i := 0 to 9 do > > some(code); > > more(code); > > end; > > > >I can by just looking at this code notice that I'm looking at the whole for block. > > > > > >But when I have similar python code at the bottom of the page. > > > > for i in xrange(10): > > some(code) > > more(code) > > > >Then I can't make out whether I'm looking at the whole for suite or not. > These code pieces are not equivalent -- you have four lines of code > in the first piece, only three lines in the python piece; in other > words, if the "end;" were not on screen, you would still have no > idea if it was the whole block or not; in still other words, the > "end;", just like the dedented line, provides the context. That one piece of code is only three lines and the other is four doesn't make them not equivallent. Adding a fourth (empty) line to the python example wouldn't have changed things significantly. These two pieces are equivallent in any significant way. Both are examples of a for loop, one with its block the other with its suite. They are both complete for-statements as defined by the respective grammes. Both perform the same functionality. The complete for-statement is all you need to see, to know you are seeing the complete for-statement in the first example. So all you need is in context information. To know you see the complete for statement in python, you need to see more than just the complete for-statement. You need out of context information. -- Antoon Pardon From alain at dpt-info.u-strasbg.fr Thu Nov 4 10:10:13 2010 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Thu, 04 Nov 2010 15:10:13 +0100 Subject: openmp do loops References: <4cd28734$0$12350$426a74cc@news.free.fr> Message-ID: <87d3qlch8a.fsf@dpt-info.u-strasbg.fr> Stefan Behnel writes: >> !$OMP PARALLEL DO default(private) shared(hkltable, fcalctable,hklsize) >> do i=1,hklsize >> fcalctable(i)=structfact(hkltable(1,i),hkltable(2,i),hkltable(3,i)) >> end do >> !$OMP END PARALLEL DO (This is Fortan, BTW.) > Seeing this makes me seriously happy that I can write my code in > Python (or Cython, for that purpose). Does Cython support OpenMP? I've foudn nothing in the docs. -- Alain. From neilc at norwich.edu Thu Nov 4 10:15:25 2010 From: neilc at norwich.edu (Neil Cerutti) Date: 4 Nov 2010 14:15:25 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8jftftFelnU1@mid.individual.net> On 2010-11-05, Ethan Furman wrote: > Grant Edwards wrote: >> On 2010-11-04, Emile van Sebille wrote: >>> On 11/3/2010 4:09 PM Seebs said... >>>> What's the token that marks the end of a block, >>>> corresponding to the colon used to introduce it? >>> >>> My thoughts tend more towards 'can we get Guido to eliminate >>> the colon requirements' -- The indent level of the next line >>> ought to suffice. >> >> But without the colon, how are people who write programming >> editors going to know when to increase the indentation level >> as I enter code? > > Hopefully by the keywords used to introduce the block: if, > elif, else, for, while, with, etc. etc. It is not legal to > start a new indented block just by appending a colon to the > previous line. The handsome ':' terminator of if/elif/if statements allows us to omit a newline, conserving vertical space. This improves the readability of certain constructs. if x: print(x) elif y: print(y) else: print() versus if x print(x) elif y print(y) else print() Beauty-is-in-the-eye-of-the-BDFLly-yours, -- Neil Cerutti From jlconlin at gmail.com Thu Nov 4 10:53:38 2010 From: jlconlin at gmail.com (Jeremy) Date: Thu, 4 Nov 2010 07:53:38 -0700 (PDT) Subject: Compiling/Installing Python 2.7 on OSX 10.6 Message-ID: <3d9139ae-bd6f-4567-bb02-b21a8ba86e50@o15g2000prh.googlegroups.com> I'm having trouble installing Python 2.7 on OSX 10.6 I was able to successfully compile it from source, but ran into problems when I did make install. The error I got (I received many similar errors) was: /usr/bin/install -c -m 644 ../LICENSE /home/jlconlin/Library/ Frameworks/Python.framework/Versions/2.7/lib/python2.7/LICENSE.txt PYTHONPATH=/home/jlconlin/Library/Frameworks/Python.framework/Versions/ 2.7/lib/python2.7 DYLD_FRAMEWORK_PATH=/home/jlconlin/src/Python-2.7/ build: \ ./python -Wi -tt /home/jlconlin/Library/Frameworks/Python.framework/ Versions/2.7/lib/python2.7/compileall.py \ -d /home/jlconlin/Library/Frameworks/Python.framework/Versions/2.7/ lib/python2.7 -f \ -x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \ /home/jlconlin/Library/Frameworks/Python.framework/Versions/2.7/lib/ python2.7 Listing /home/jlconlin/Library/Frameworks/Python.framework/Versions/ 2.7/lib/python2.7 ... Compiling /home/jlconlin/Library/Frameworks/Python.framework/Versions/ 2.7/lib/python2.7/._BaseHTTPServer.py ... Sorry: TypeError: ('compile() expected string without null bytes',) Compiling /home/jlconlin/Library/Frameworks/Python.framework/Versions/ 2.7/lib/python2.7/._Bastion.py ... Sorry: TypeError: ('compile() expected string without null bytes',) Compiling /home/jlconlin/Library/Frameworks/Python.framework/Versions/ 2.7/lib/python2.7/._CGIHTTPServer.py ... Sorry: TypeError: ('compile() expected string without null bytes',) As you can see I am compiling/installing in my home directory instead of for the whole system. The script I used to compile Python 2.7 is: #! /bin/sh export CFLAGS="-arch x86_64" export LDFLAGS="-arch x86_64" ../configure --prefix=$HOME/usr/local \ --enable-framework=$HOME/Library/Frameworks \ --disable-toolbox-glue \ MACOSX_DEPLOYMENT_TARGET=10.6 make make install Can anyone help me fix the install error? Thanks, Jeremy PS. Python compiled correctly, but a few modules were not found/made but I don't think they are important. Python build finished, but the necessary bits to build these modules were not found: _bsddb dl gdbm imageop linuxaudiodev ossaudiodev spwd sunaudiodev To find the necessary bits, look in setup.py in detect_modules() for the module's name. From ra.ravi.rav at gmail.com Thu Nov 4 11:14:35 2010 From: ra.ravi.rav at gmail.com (Ravi) Date: Thu, 4 Nov 2010 08:14:35 -0700 (PDT) Subject: Popen Question References: <891a9a80-c30d-4415-ac81-bddd0b564fa6@g13g2000yqj.googlegroups.com> Message-ID: <31f5cbe2-112e-4f44-a913-245521e15d13@g28g2000pra.googlegroups.com> On Nov 4, 7:06?pm, moogyd wrote: > Hi, > I usually use csh for my simulation control scripts, but these scripts > are becoming more complex, so I plan to use python for the next > project. > To this end, I am looking at subprocess.Popen() to actually call the > simulations, and have a very basic question which is demonstrated > below. > > [sde:staff at lbux03 ~]$ python > Python 2.6 (r26:66714, Feb 21 2009, 02:16:04) > [GCC 4.3.2 [gcc-4_3-branch revision 141291]] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > > >>> import os, subprocess > >>> os.environ['MYVAR'] = "myval" > >>> p = subprocess.Popen(['echo', '$MYVAR'],shell=True) > > >>> p = subprocess.Popen(['echo', '$MYVAR']) > >>> $MYVAR > >>> p = subprocess.Popen('echo $MYVAR',shell=True) > >>> myval > >>> p = subprocess.Popen('echo $MYVAR') > > Traceback (most recent call last): > ? File "", line 1, in > ? File "/usr/lib64/python2.6/subprocess.py", line 595, in __init__ > ? ? errread, errwrite) > ? File "/usr/lib64/python2.6/subprocess.py", line 1106, in > _execute_child > ? ? raise child_exception > OSError: [Errno 2] No such file or directory > > I am not really sure I understand these results. > 1) No idea what is going on > 2) As (1). What isn't myval printed out (rather than $MYVAR) > 3) Works as I wanted it to > 4) Why do I need shell=True ? > The documentation isn't very clear to me (it seems you need to > understand the underlying system calls). > > Can anyone explain (or provide link) for this behaviour in simple > English? > Thanks, > Steven try giving /bin/echo From fetchinson at googlemail.com Thu Nov 4 11:21:18 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Thu, 4 Nov 2010 16:21:18 +0100 Subject: cms 4 static pages? In-Reply-To: References: Message-ID: > m looking 4 a framework, that allows to build static community software > (similar to facebook) without having to start scripts, database > connects, admin cookies, e.t.c. > > means - should be dynamic without really being dynamic, delivering just > static pages. (yes, i know e.g. nginx does that by caching, thats not > what i want!) > > features wanted: > > a not database driven > > b password access ist done by just renaming users home directory. User > at logout will receive new secret subdirectory name 4 new login. > > c no clientside scripting. changing layout will be done by rebuilding > all relevant static pages in user directory once by serverside script. > > d new entries e.g. mail, discussions will be queued, user just sees: tnx > 4 your new article, page will be rebuilt in ... estimated 3 seconds ... > or estimated 10 seconds ... depending on load and todo queue length. > > e load balancing is done by just replicating static pages between > servers after new rebuild of static pages. > > f simulation of received mail directory through just rebuilding relevant > static html tree. attachments not allowed. > > g intelligent todo queue 4 resorting mail sent, received, discussions, > look and feel before rebuilding static user pages. (herein lies the > intelligence of the whole system) > > h notifications 4 new mail, messages, e.t.c. are just updates in static > html fields. if user gets offline (measured by time since last update of > static pages) user will be informed once a day by mail. > > i simulation of locking can easily be done by dotfiles. > > j according 2 my calculations such system should be able 2 satisfy any > bandwidth without causing significant load of cpu, due 2 low protocol > overhead and no server side scripting, no database load. overload of > server should not possible by design. > > k modules, addon 4 twitter e.g., nice 2 have > > > (and no, no java!) any pointers? Yeah, rethink your design! Seriously, you listed a number of features which are not really features but implementation details and you haven't told us what your original goals are which you think are fulfilled by these implementation details. If you would clearly state what your goals are (regardless of how it is implemented) I'm 100% certain a better implementation can be found than the one you enumerated. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From g.rodola at gmail.com Thu Nov 4 11:29:15 2010 From: g.rodola at gmail.com (=?ISO-8859-1?Q?Giampaolo_Rodol=E0?=) Date: Thu, 4 Nov 2010 16:29:15 +0100 Subject: [ANN] pyOpenSSL 0.11 released In-Reply-To: <20101101224323.2040.732989284.divmod.xquotient.500@localhost.localdomain> References: <20101101224323.2040.732989284.divmod.xquotient.500@localhost.localdomain> Message-ID: 2010/11/1 : > Hello all, > > I'm happy to announce the release of pyOpenSSL 0.11. ?The primary change > from the last release is that Python 3.2 is now supported. ?Python 2.4 > through Python 2.7 are still supported as well. ?This release also fixes a > handful of bugs in error handling code. ?It also adds APIs for generating > and verifying cryptographic signatures and it improves the test suite to > cover nearly 80% of the implementation. > > Downloads and more details about the release can be found on the release > page: > > ? https://launchpad.net/pyopenssl/main/0.11 > > Enjoy, > Jean-Paul > -- > http://mail.python.org/mailman/listinfo/python-list > Congratulations! --- Giampaolo http://code.google.com/p/pyftpdlib/ http://code.google.com/p/psutil/ From macmanes at gmail.com Thu Nov 4 11:37:27 2010 From: macmanes at gmail.com (Matt) Date: Thu, 4 Nov 2010 08:37:27 -0700 (PDT) Subject: execute shell script from python, needs sys.argv Message-ID: Hi All, I am trying to execute a shell script from within python.. This shell script takes the format, where $1 and $2 are variables from the command line: cat $1 | Fastx_trimmer -n COUNT -o $2 straight into the cmd line it would be: cat file.1 | Fastx_trimmer -n COUNT -o file.2 So, know that there is a way to do this in python using the subprocess module, but despite a lot of effort, I can't seem to get this to work, and precisely because of those arguments taken from the command line. I was thinking that the easiest thing to so was to import sys, os, subprocess proc = subprocess.call([cat sys.argv[1] | fastx_trimmer -n COUNT -o sys.argv[2]], shell=True) this clearly does not work... alternatively, I could put the shell command in its own file, say fastx.sh, and pass it's arguments to it vie the command line. import sys, os, subprocess proc = subprocess.call([fastx.sh, sys.argv[1], sys.argv[2]], shell=True) But, this does not seem to work as this is not the proper way to pass arguments to the shell script. in short, I'm sure that this is a easy fix, but given my still limited python vocabulary, it eludes me. Thanks, Matt From alain at dpt-info.u-strasbg.fr Thu Nov 4 11:55:16 2010 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Thu, 04 Nov 2010 16:55:16 +0100 Subject: Popen Question References: <891a9a80-c30d-4415-ac81-bddd0b564fa6@g13g2000yqj.googlegroups.com> Message-ID: <8762wdccd7.fsf@dpt-info.u-strasbg.fr> moogyd writes: >>>> import os, subprocess >>>> os.environ['MYVAR'] = "myval" >>>> p = subprocess.Popen(['echo', '$MYVAR'],shell=True) >>>> >>>> p = subprocess.Popen(['echo', '$MYVAR']) >>>> $MYVAR > >>>> p = subprocess.Popen('echo $MYVAR',shell=True) >>>> myval > >>>> p = subprocess.Popen('echo $MYVAR') > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib64/python2.6/subprocess.py", line 595, in __init__ > errread, errwrite) > File "/usr/lib64/python2.6/subprocess.py", line 1106, in > _execute_child > raise child_exception > OSError: [Errno 2] No such file or directory > > I am not really sure I understand these results. > 1) No idea what is going on > 2) As (1). What isn't myval printed out (rather than $MYVAR) > 3) Works as I wanted it to > 4) Why do I need shell=True ? Expanding $MYVAR into its value is a feature of the shell (afaik all shells use the same syntax). Popen without shell=True uses the execvp() system call directly, without going through the shell variable expansion process (cases 2 and 4 above). For example, case 4 above asks execvp to (find and) execute a program named "echo $MYVAR" (an 11-letter name, where the fifth letter is space and the sixth is $ -- a perfectly valid file/program name). Then, if you use shell=True with a list, only the first word is used as a command, and the others are kept in positional parameters. That's why your first try fails (try 'sh -c echo $HOME' in a shell, without the single quotes, and you'll get empty output). > The documentation isn't very clear to me (it seems you need to > understand the underlying system calls). You're probably right. The base fact here is: the use of variables is a feature of the shell. No shell, no variable. > Can anyone explain (or provide link) for this behaviour in simple > English? Shell variables are explained in detail in any shell man page. The execvp() system call has its own man page. -- Alain. From benjamin.kaplan at case.edu Thu Nov 4 12:06:17 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 4 Nov 2010 12:06:17 -0400 Subject: execute shell script from python, needs sys.argv In-Reply-To: References: Message-ID: On Thu, Nov 4, 2010 at 11:37 AM, Matt wrote: > Hi All, > > I am trying to execute a shell script from within python.. ?This shell > script takes the format, where $1 and $2 are variables from the > command line: cat $1 | Fastx_trimmer -n COUNT -o $2 > > straight into the cmd line it would be: ?cat file.1 | Fastx_trimmer -n > COUNT -o file.2 > > So, ?know that there is a way to do this in python using the > subprocess module, but despite a lot of effort, I can't seem to get > this to work, and precisely because of those arguments taken from the > command line. > > I was thinking that the easiest thing to so was to > > import sys, os, subprocess > proc = subprocess.call([cat sys.argv[1] | fastx_trimmer -n COUNT -o > sys.argv[2]], shell=True) > Python is not the shell. Shell commands are not python commands. You need either a string or a list of strings, so any literal have to be in quotes. Also, subprocess can't handle the redirection. You need to run it as two commands. proc1 = subprocess.Popen(["cat", sys.argv[1]],stdout = subprocess.PIPE, shell = True) proc2 = subprocess.Popen(["fastx_trimmer", "-n", "COUNT", "-o", sys.argv[2]],stdin=proc1.stdout, shell=True) > this clearly does not work... > > alternatively, I could put the shell command in its own file, say > fastx.sh, and pass it's arguments to it vie the command line. > > import sys, os, subprocess > proc = subprocess.call([fastx.sh, sys.argv[1], sys.argv[2]], > shell=True) > Again, you need a string. fastx.sh looks for a python object called fastx and tries accessing an attribute called sh in that object. Ov course, there's no such thing. Put quotes around it and it will work. > But, this does not seem to work as this is not the proper way to pass > arguments to the shell script. > > in short, I'm sure that this is a easy fix, but given my still limited > python vocabulary, it eludes me. > > Thanks, Matt > > > -- > http://mail.python.org/mailman/listinfo/python-list > From __peter__ at web.de Thu Nov 4 12:11:06 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 04 Nov 2010 17:11:06 +0100 Subject: execute shell script from python, needs sys.argv References: Message-ID: Matt wrote: > I am trying to execute a shell script from within python.. This shell > script takes the format, where $1 and $2 are variables from the > command line: cat $1 | Fastx_trimmer -n COUNT -o $2 > > straight into the cmd line it would be: cat file.1 | Fastx_trimmer -n > COUNT -o file.2 > > So, know that there is a way to do this in python using the > subprocess module, but despite a lot of effort, I can't seem to get > this to work, and precisely because of those arguments taken from the > command line. > > I was thinking that the easiest thing to so was to > > import sys, os, subprocess > proc = subprocess.call([cat sys.argv[1] | fastx_trimmer -n COUNT -o > sys.argv[2]], shell=True) > > this clearly does not work... > > alternatively, I could put the shell command in its own file, say > fastx.sh, and pass it's arguments to it vie the command line. > > import sys, os, subprocess > proc = subprocess.call([fastx.sh, sys.argv[1], sys.argv[2]], > shell=True) > > But, this does not seem to work as this is not the proper way to pass > arguments to the shell script. > > in short, I'm sure that this is a easy fix, but given my still limited > python vocabulary, it eludes me. You could do it in two steps: >>> from subprocess import * >>> source = Popen(["cat", "/usr/share/dict/words"], stdout=PIPE) >>> call(["wc"], stdin=source.stdout) 98569 98568 931708 0 >>> A similar example is here, under a "can't miss" headline: http://docs.python.org/library/subprocess.html#replacing-shell-pipeline Peter From moura.mario at gmail.com Thu Nov 4 12:18:44 2010 From: moura.mario at gmail.com (macm) Date: Thu, 4 Nov 2010 09:18:44 -0700 (PDT) Subject: How find all childrens values of a nested dictionary, fast! Message-ID: Hi Folks How find all childrens values of a nested dictionary, fast! >>> a = {'a' : {'b' :{'/' :[1,2,3,4], 'ba' :{'/' :[41,42,44]} ,'bc' :{'/':[51,52,54], 'bcd' :{'/':[68,69,66]}}},'c' :{'/' :[5,6,7,8]}}, 'ab' : {'/' :[12,13,14,15]}, 'ac' :{'/' :[21,22,23]}} >>> a['a'] {'c': {'/': [5, 6, 7, 8]}, 'b': {'ba': {'/': [41, 42, 44]}, '/': [1, 2, 3, 4], 'bc': {'bcd': {'/': [68, 69, 66]}, '/': [51, 52, 54]}}} >>> a['a']['b'] {'ba': {'/': [41, 42, 44]}, '/': [1, 2, 3, 4], 'bc': {'bcd': {'/': [68, 69, 66]}, '/': [51, 52, 54]}} >>> a['a']['b'].values() [{'/': [41, 42, 44]}, [1, 2, 3, 4], {'bcd': {'/': [68, 69, 66]}, '/': [51, 52, 54]}] Now I want find all values of key "/" Desire result is [41, 42, 44, 1, 2, 3, 4, 68, 69, 66, 51, 52, 54] I am trying map, reduce, lambda. Regards macm From darcy at druid.net Thu Nov 4 12:20:45 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Thu, 4 Nov 2010 12:20:45 -0400 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20101104122045.8d466f82.darcy@druid.net> On 04 Nov 2010 08:17:10 GMT Seebs wrote: > Outside of people who seem to be deeply emotionally invested in insisting > that it is never, at all, in ANY way, for ANY person, annoying, it seems > to be pretty consistent to observe that, benefits or no benefits, it has > some kind of non-zero annoyance value. Who are these people that believe that no one finds indentation as syntax annoying? I haven't seen any evidence in this group. Let's leave the straw men out of this. Many of us don't find it annoying ourselves, that's for sure but we aren't trying to read anyone else's mind. We're all pretty sure that *you* find it annoying but there is no telepathy involved there. > * Not having to type braces: Yay! Which I always found annoying given that I was already adding signals (indentation) that I was starting a block. > * Having structure map to functionality: Some people quite like it, and Some of us think that it is a contender for the single greatest thing about Python. > * Not being able to write an auto-indenter, ever, because it is by > design theoretically impossible: Annoying. Right. And in C you can never write an auto-bracer for exactly the same reason. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From shashank.sunny.singh at gmail.com Thu Nov 4 12:42:03 2010 From: shashank.sunny.singh at gmail.com (Shashank Singh) Date: Thu, 4 Nov 2010 22:12:03 +0530 Subject: Final state of underlying sequence in islice Message-ID: Hi, Apologies if this has been discussed in this list before. Google has not been very helpful in locating any such previous discussion. Are there any promises made with regard to final state of the underlying sequence that islice slices? for example consider this >>> from itertools import * >>> c = count() >>> list(islice(c, 1, 3, 50)) [1] >>> c.next() 51 Now, the doc [1] says "If *stop* is None, then iteration continues until the iterator is exhausted, if at all; otherwise, it stops at the specified position". It clearly is not stopping at stop (3). Further, the doc gives an example of how this is *equivalent* to a generator defined in the same section. It turns out, these two are not exactly the same if the side-effect of the code is considered on the underlying sequence. Redefining islice using the generator function defined in the doc gives different (and from one pov, expected) result >>> def islice(iterable, *args): ... # islice('ABCDEFG', 2) --> A B ... >>> c = count() >>> list(islice(c, 1, 3, 50)) [1] >>> c.next() 2 While "fixing" this should be rather easy in terms of the change in code required it might break any code depending on this seemingly incorrect behavior. [1]. http://docs.python.org/library/itertools.html#itertools.islice -- Regards Shashank Singh shashank.sunny.singh at gmail.com http://www.cse.iitb.ac.in/~shashanksingh -------------- next part -------------- An HTML attachment was scrubbed... URL: From robert.kern at gmail.com Thu Nov 4 12:43:34 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 04 Nov 2010 11:43:34 -0500 Subject: functions, list, default parameters In-Reply-To: References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <8ivelpFif1U1@mid.individual.net> <4cca88bc$0$29987$c3e8da3$5496439d@news.astraweb.com> <8j1seqFa1eU2@mid.individual.net> Message-ID: On 11/4/10 2:07 AM, Lawrence D'Oliveiro wrote: > In message, Robert Kern > wrote: > >> On 11/2/10 2:12 AM, Lawrence D'Oliveiro wrote: >> >>> In message, Robert >>> Kern wrote: >>> >>>> "Immutable objects" are just those without an obvious API for modifying >>>> them. >>> >>> They are ones with NO legal language constructs for modifying them. Hint: >>> if a selector of some part of such an object were to occur on the LHS of >>> an assignment, and that would raise an error, then the object is >>> immutable. The interpreter already knows all this. >> >> Incorrect. RHS method calls can often modify objects. > > So bloody what? So examining LHS "selectors" is not sufficient for determining immutability. >> Show me the algorithm that the interpreter can use to determine whether or >> not an object is mutable. > > Go look in the code for the one it already uses in places where immutable > objects are currently required. Like hashes for dictionary keys? The code just calls the __hash__ method and trusts that you designed the object correctly. It does not verify anything. Although, strictly speaking, it doesn't require immutability of keys. This is actually another one of those places where the Python language developers defined a concept but did not equip the interpreter with a way to verify compliance with the concept. A proper hashable object has a __hash__ method and an __eq__ method defined such that if two objects compare equal, they also hash equal. But nothing in the interpreter ever tries to verify that this is true. Nor can it except by an impossible exhaustive search of all the possible objects. Care to point me to specific place in the Python code you are talking about? Or even just a slightly more specific direction would suffice. I don't really know what you might be talking about. >>>> With various trickeries, I can mutate any immutable object. >>> >>> None within the Python language itself. Which is what we?re talking about >>> here: a language construct which is probably one of the top 3 sources of >>> grief to Python newbies. And not-so-newbies. >> >> "import ctypes" is within the Python language. > > And in the old BASIC days, we had ?PEEK? and ?POKE?. So by your reasoning, > that invalidated the language rules, too. I'm not talking about BASIC at all. Nor am I talking about invalidation of language rules in either BASIC or Python. I am only talking about whether or not the Python interpreter is able to determine if an object is immutable or not. But this really is a side point. I'm happy to drop it. -- 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 nagle at animats.com Thu Nov 4 12:48:43 2010 From: nagle at animats.com (John Nagle) Date: Thu, 04 Nov 2010 09:48:43 -0700 Subject: Compare source code In-Reply-To: <4ccd7487$0$30068$426a74cc@news.free.fr> References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <4ccd7487$0$30068$426a74cc@news.free.fr> Message-ID: <4cd2e3e7$0$1586$742ec2ed@news.sonic.net> On 10/31/2010 6:52 AM, jf wrote: > Le 31/10/2010 13:10, Martin v. Loewis a ?crit : >>> I've a project with tabs and spaces mixed (yes I know it's bad). >>> >>> I edit each file to remove tabs, but it's so easy to make a mistake. >>> Do you know a tools to compare the initial file with the cleaned one to >>> know if the algorithms are the same ? >> >> Tools/scripts/reindent.py of the standard Python distribution normalizes >> white space in source code. > > So great, you save my time ! > Should I be worry about this comment in reindent.py "So long as the > input files get a clean bill of health from tabnanny.py, reindent should > do a good job." ? Are both of those tools consistent with the interpretation of mixed tabs and spaces in Python 3.x? The current CPython parser front end is smart about this. Tabs and spaces can be mixed provided that the semantics of the program do not depend on the width of a tab. This was not the case in early 2.x versions. (When did that go in?) The key to doing this right is to compare the whitespace of an indented line with the line above it. The longer whitespace string must start with the shorter whitespace string, whether it's tabs, spaces, or any combination thereof. If it does not, the indentation is ambiguous. For all unambiguous cases, you can then convert tabs to spaces or vice versa with any number of spaces to tabs, and the semantics of the program will not change. It's not clear whether "tabnanny" or "reindent" have smart semantics like CPython. The documentation doesn't say. If they don't, they should, or it should be documented that they're broken. John Nagle From mdw at distorted.org.uk Thu Nov 4 12:49:32 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 04 Nov 2010 16:49:32 +0000 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87r5f13ug3.fsf.mdw@metalzone.distorted.org.uk> Seebs writes: > Python's the only language I use where an obvious flaw, which is > repeatedly observed by everyone I know who uses the language, is > militantly and stridently defended by dismissing, insulting, and > attacking the character and motives of anyone who suggests that it > might be a bit of a nuisance. So you've not tried Lisp, then? Dissing Lisp's parentheses tends to get a pretty similar reaction. My observations on this general discussion. * Python is far from unique in its use of significant whitespace. Miranda was inferring program structure from indentation in 1985. Haskell and F# are more modern examples. * I don't have many problems with tools trashing whitespace in Python programs, though I have seen web forum software mangling indentation; since this makes nontrivial chunks of almost any programming language illegible, I'm more than willing to blame the forum software for this. I haven't personally seen indentation trashed by email software, for example (though I steer well clear of people who try to send me HTML mail). * I /do/ have a significant problem with cutting and pasting code in Python. In most languages, I can haul a chunk of code about, hit C-M-q, and Emacs magically indents the result properly. This is, unfortunately, impossible with Python. It has caused me real bugs, and I have to be extra careful to fix the indentation up. * I've just noticed that Emacs's Python mode has a magic keystroke which appears to do the right thing for cut-and-pasted code. This is symptomatic of a bigger problem: simply by being different from the mainstream, Python requires that one work with it differently. It requires different tools, and different techniques. Many languages use some kind of brackets to mark substructure, so tools have become good at handling bracketed substructure, whether for automatic indentation or navigation. Python marks (some) substructure differently, so users need to learn new techniques or tools for working with it. I /like/ Python. I use it frequently. I /don't/ want to change its structure marked by indentation. I'm /willing/ to put up with some inconvenience because Python makes up for it in other ways. But there /is/ inconvenience, and it does need putting up with. I think the benefits are worth the costs; others may disagree. -- [mdw], a smug Lisp weenie at heart. From mal at egenix.com Thu Nov 4 12:52:04 2010 From: mal at egenix.com (M.-A. Lemburg) Date: Thu, 04 Nov 2010 17:52:04 +0100 Subject: DateTime object In-Reply-To: <4ccaacd6$0$10750$426a74cc@news.free.fr> References: <4ccaacd6$0$10750$426a74cc@news.free.fr> Message-ID: <4CD2E4B4.7090109@egenix.com> jf wrote: > Hi, > > I've a bug in my code and I'm trying de reproduce it. > > To trace the bug I print arguments, and it produces this: > {'date': } > > My question is: what is: ? > > I use mx.DateTime put if I print it I get: > > > So what kind of object is ? You might be using the old Python implementation of mxDateTime (mx/DateTime/mxDateTime/mxDateTime_Python.py): def __repr__(self): return ""% ( self.year, self.month, self.day, self.hour, self.minute, self.second, id(self)) Note however, that there's no "T" in the string shown for the repr(), so perhaps this is some other implementation. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Nov 04 2010) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new 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 mdw at distorted.org.uk Thu Nov 4 12:57:05 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 04 Nov 2010 16:57:05 +0000 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87mxpp3u3i.fsf.mdw@metalzone.distorted.org.uk> Tim Harig writes: > Python is the only language that I know that *needs* to specify tabs > versus spaces since it is the only language I know of which uses > whitespace formating as part of its syntax and structure. You need to get out more. Miranda, Gofer, Haskell, F#, make(1), and many others, all use indentation to indicate structure; YAML isn't a programming language, but it also uses indentation to indicate structure, as do a number of wiki markup languages; there are also representations of Lisp S-expressions which use indentation instead of parentheses. > Mixed usage may be annoying in other languages; but, it breaks Python. I disagree. The Haskell '98 report specifies (correctly) that tabs are every eight columns, and a tab moves to the next tab stop. Python makes the same specification; it's just the users who actually want to stamp out tabs. Flamebait: it's not the tabs that cause the problem: it's that some people are under the mistaken impression that the position of tab stops in text files is a matter for local preference. -- [mdw] From ndbecker2 at gmail.com Thu Nov 4 13:03:12 2010 From: ndbecker2 at gmail.com (Neal Becker) Date: Thu, 04 Nov 2010 13:03:12 -0400 Subject: sigaction? Message-ID: Why doesn't python signal support sigaction? I'm interested in trying sigaction with SA_RESTART to prevent interrupted system calls. Or, would the usage of SA_RESTART within python cause other problems? From neilc at norwich.edu Thu Nov 4 13:11:52 2010 From: neilc at norwich.edu (Neil Cerutti) Date: 4 Nov 2010 17:11:52 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8jg7qoFhbnU2@mid.individual.net> On 2010-11-04, D'Arcy J.M. Cain wrote: >> * Not being able to write an auto-indenter, ever, because it >> is by design theoretically impossible: Annoying. > > Right. And in C you can never write an auto-bracer for exactly > the same reason. It's not right, actually. Auto-indent is fairly easy in Python. Auto-dedent is the impossible part. -- Neil Cerutti From deets at web.de Thu Nov 4 13:21:44 2010 From: deets at web.de (Diez B. Roggisch) Date: Thu, 04 Nov 2010 18:21:44 +0100 Subject: How find all childrens values of a nested dictionary, fast! References: Message-ID: <87r5f1ypg7.fsf@web.de> macm writes: > Hi Folks > > How find all childrens values of a nested dictionary, fast! There is no faster than O(n) here. > >>>> a = {'a' : {'b' :{'/' :[1,2,3,4], 'ba' :{'/' :[41,42,44]} ,'bc' :{'/':[51,52,54], 'bcd' :{'/':[68,69,66]}}},'c' :{'/' :[5,6,7,8]}}, 'ab' : {'/' :[12,13,14,15]}, 'ac' :{'/' :[21,22,23]}} >>>> a['a'] > {'c': {'/': [5, 6, 7, 8]}, 'b': {'ba': {'/': [41, 42, 44]}, '/': [1, > 2, 3, 4], 'bc': {'bcd': {'/': [68, 69, 66]}, '/': [51, 52, 54]}}} >>>> a['a']['b'] > {'ba': {'/': [41, 42, 44]}, '/': [1, 2, 3, 4], 'bc': {'bcd': {'/': > [68, 69, 66]}, '/': [51, 52, 54]}} >>>> a['a']['b'].values() > [{'/': [41, 42, 44]}, [1, 2, 3, 4], {'bcd': {'/': [68, 69, 66]}, '/': > [51, 52, 54]}] > > Now I want find all values of key "/" > > Desire result is [41, 42, 44, 1, 2, 3, 4, 68, 69, 66, 51, 52, 54] a = {'a' : {'b' :{'/' :[1,2,3,4], 'ba' :{'/' :[41,42,44]} ,'bc' :{'/':[51,52,54], 'bcd' :{'/':[68,69,66]}}},'c' :{'/' :[5,6,7,8]}}, 'ab' : {'/' :[12,13,14,15]}, 'ac' :{'/' :[21,22,23]}} def f(d): if "/" in d: for v in d["/"]: yield v for value in d.values(): if isinstance(value, dict): for v in f(value): yield v print list(f(a)) But that gives me a different result: [5, 6, 7, 8, 1, 2, 3, 4, 41, 42, 44, 51, 52, 54, 68, 69, 66, 21, 22, 23, 12, 13, 14, 15] Why don't you expect e.g. 23 in your output? Diez From __peter__ at web.de Thu Nov 4 13:26:03 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 04 Nov 2010 18:26:03 +0100 Subject: How find all childrens values of a nested dictionary, fast! References: Message-ID: macm wrote: > How find all childrens values of a nested dictionary, fast! > >>>> a = {'a' : {'b' :{'/' :[1,2,3,4], 'ba' :{'/' :[41,42,44]} ,'bc' >>>> :{'/':[51,52,54], 'bcd' :{'/':[68,69,66]}}},'c' :{'/' :[5,6,7,8]}}, >>>> 'ab' : {'/' :[12,13,14,15]}, 'ac' :{'/' :[21,22,23]}} a['a'] > {'c': {'/': [5, 6, 7, 8]}, 'b': {'ba': {'/': [41, 42, 44]}, '/': [1, > 2, 3, 4], 'bc': {'bcd': {'/': [68, 69, 66]}, '/': [51, 52, 54]}}} >>>> a['a']['b'] > {'ba': {'/': [41, 42, 44]}, '/': [1, 2, 3, 4], 'bc': {'bcd': {'/': > [68, 69, 66]}, '/': [51, 52, 54]}} >>>> a['a']['b'].values() > [{'/': [41, 42, 44]}, [1, 2, 3, 4], {'bcd': {'/': [68, 69, 66]}, '/': > [51, 52, 54]}] > > Now I want find all values of key "/" > > Desire result is [41, 42, 44, 1, 2, 3, 4, 68, 69, 66, 51, 52, 54] > > I am trying map, reduce, lambda. Hmm, I'm trying none of these and get a different result: >>> def f(d): ... stack = [d.iteritems()] ... while stack: ... for k, v in stack[-1]: ... if k == "/": ... yield v ... else: ... stack.append(v.iteritems()) ... break ... else: ... stack.pop() ... >>> b = [] >>> for v in f(a): ... b.extend(v) ... >>> b [5, 6, 7, 8, 41, 42, 44, 1, 2, 3, 4, 68, 69, 66, 51, 52, 54, 21, 22, 23, 12, 13, 14, 15] What am I missing? Peter From invalid at invalid.invalid Thu Nov 4 13:27:51 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 4 Nov 2010 17:27:51 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> Message-ID: On 2010-11-04, Neil Cerutti wrote: > On 2010-11-04, D'Arcy J.M. Cain wrote: >>> * Not being able to write an auto-indenter, ever, because it >>> is by design theoretically impossible: Annoying. >> >> Right. And in C you can never write an auto-bracer for exactly >> the same reason. > > It's not right, actually. Auto-indent is fairly easy in > Python. Auto-dedent is the impossible part. I think in common usage the term "auto-intender" refers to a program that can automatically control source indentation (which inclulde both "indenting" and "dindenting" source lines). -- Grant Edwards grant.b.edwards Yow! I'm having BEAUTIFUL at THOUGHTS about the INSIPID gmail.com WIVES of smug and wealthy CORPORATE LAWYERS ... From python at mrabarnett.plus.com Thu Nov 4 13:32:21 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 04 Nov 2010 17:32:21 +0000 Subject: Compare source code In-Reply-To: <87r5f13ug3.fsf.mdw@metalzone.distorted.org.uk> References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <87r5f13ug3.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <4CD2EE25.1010008@mrabarnett.plus.com> On 04/11/2010 16:49, Mark Wooding wrote: > Seebs writes: > >> Python's the only language I use where an obvious flaw, which is >> repeatedly observed by everyone I know who uses the language, is >> militantly and stridently defended by dismissing, insulting, and >> attacking the character and motives of anyone who suggests that it >> might be a bit of a nuisance. > > So you've not tried Lisp, then? Dissing Lisp's parentheses tends to get > a pretty similar reaction. > > My observations on this general discussion. > > * Python is far from unique in its use of significant whitespace. > Miranda was inferring program structure from indentation in 1985. > Haskell and F# are more modern examples. > occam was doing it in 1983. > * I don't have many problems with tools trashing whitespace in Python > programs, though I have seen web forum software mangling > indentation; since this makes nontrivial chunks of almost any > programming language illegible, I'm more than willing to blame the > forum software for this. I haven't personally seen indentation > trashed by email software, for example (though I steer well clear of > people who try to send me HTML mail). > If you don't use
 ... 
or some such then any programming language is going to look bad! [snip] From ppearson at nowhere.invalid Thu Nov 4 13:32:54 2010 From: ppearson at nowhere.invalid (Peter Pearson) Date: 4 Nov 2010 17:32:54 GMT Subject: What people are using to access this mailing list References: Message-ID: <8jg925FjpmU1@mid.individual.net> On Wed, 3 Nov 2010 08:02:29 +0000 (UTC), John Bond wrote: > Hope this isn't too O/T - I was just wondering how people read/send to this > mailing list, eg. normal email client, gmane, some other software or online > service? Usenet via a server at news.individual.net, newsgroup name comp.lang.python, client slrn. -- To email me, substitute nowhere->spamcop, invalid->net. From emile at fenx.com Thu Nov 4 13:36:04 2010 From: emile at fenx.com (Emile van Sebille) Date: Thu, 04 Nov 2010 10:36:04 -0700 Subject: Compare source code In-Reply-To: <8jftftFelnU1@mid.individual.net> References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jftftFelnU1@mid.individual.net> Message-ID: On 11/4/2010 7:15 AM Neil Cerutti said... > The handsome ':' terminator of if/elif/if statements allows us to > omit a newline, conserving vertical space. This improves the > readability of certain constructs. > > if x: print(x) > elif y: print(y) > else: print() > Analogously, x+=1;y=f(x);return We don't have to eliminate ':'s. Emile From usernet at ilthio.net Thu Nov 4 13:45:58 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 4 Nov 2010 17:45:58 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <87mxpp3u3i.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On 2010-11-04, Mark Wooding wrote: > Tim Harig writes: > >> Python is the only language that I know that *needs* to specify tabs >> versus spaces since it is the only language I know of which uses >> whitespace formating as part of its syntax and structure. > > You need to get out more. Miranda, Gofer, Haskell, F#, make(1), and I have never heard of Gofer. I have heard the name Miranda and I know that it is a (purely?) functional language; but, that is all that I know. I took a cursory look at Haskell a while back; but, I ultimately chose to learn Erlang instead as its error management constructs had real world application for me. I also looked at F# and Scala; but, neither are really applicable on my chosen platform. With F# being such a new language, I suspect that it borrowed its indent practices either from Haskell or from Python. I already introduced the make tab oriented syntax and Seebs has labeled it as a major anti-pattern. I am also aware of other langauges such as Boo; but, I don't really consider them individually relevant to the conversation as they are explicitly using a Python based syntax. For this discussion I merely group them with Python. >> Mixed usage may be annoying in other languages; but, it breaks Python. > > I disagree. The Haskell '98 report specifies (correctly) that tabs are > every eight columns, and a tab moves to the next tab stop. Python makes > the same specification; it's just the users who actually want to stamp > out tabs. So, your telling me that mixing tabs and spaces is considered a good practice in Haskell? No, mixing tabs and spaces in Python isn't illegal; but, I have never seen good outcomes from doing so. No matter how you define a tab, most people do not have their editor configured to show them the difference between a tab stop and the equivilant number of spaces. I have never experienced ill effects from using tabs alone. > Flamebait: it's not the tabs that cause the problem: it's that some > people are under the mistaken impression that the position of tab stops > in text files is a matter for local preference. I would argue that text files do not have tab stops -- text editors do. So long as you use tabs for all of your indenting, it is quite safe to set the editors tab stops however one likes since the editor's tab stop doesn't effect the output of the file. That way, everybody can edit their code using an apparent indent level that is comfortable for them without being disruptive to the code. It is a win-win situation for everybody. From usernet at ilthio.net Thu Nov 4 13:55:55 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 4 Nov 2010 17:55:55 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> Message-ID: On 2010-11-04, Neil Cerutti wrote: > On 2010-11-04, D'Arcy J.M. Cain wrote: Seebs Wrote: >>> * Not being able to write an auto-indenter, ever, because it >>> is by design theoretically impossible: Annoying. >> >> Right. And in C you can never write an auto-bracer for exactly >> the same reason. > > It's not right, actually. Auto-indent is fairly easy in > Python. Auto-dedent is the impossible part. What Seebs is refering to is that it is difficult or impossible to re-indent Python source automatically after the indent structure has been broken (such as his email being converted to html on the server or a web forum without the possibility of
 or [code] tags).  When C becomes
so obfiscated, you can run it through indent to recover the structure of
the source to something that you are familiar with (I actually think macros
could cause problems; but, Seebs has already admitted weaknesses in the C
preprocessor.).  The same is not always true for Python where information
about the code structure may be destroyed.


From moura.mario at gmail.com  Thu Nov  4 13:56:00 2010
From: moura.mario at gmail.com (macm)
Date: Thu, 4 Nov 2010 10:56:00 -0700 (PDT)
Subject: How find all childrens values of a nested dictionary, fast!
References: 
	
Message-ID: <80f5fd35-4689-4d5d-9937-8641992e4c40@k30g2000vbn.googlegroups.com>

Hi Folks

Thanks a lot

Script from Diez works:

print list(f(a))

but should be

print list(f(a['a']['b']))

to fit my example.



About Peter script

I am receiving

>>> for v in f(a['a']['b']):
...     b.extend(v)
...
Traceback (most recent call last):
  File "", line 2, in 
TypeError: 'int' object is not iterable

I am trying understand this error.

Best Regards and thanks a lot again!

Mario
macm






On 4 nov, 15:26, Peter Otten <__pete... at web.de> wrote:
> macm wrote:
> > How find all childrens values of a nested dictionary, fast!
>
> >>>> a = {'a' : {'b' :{'/' :[1,2,3,4], 'ba' :{'/' :[41,42,44]} ,'bc'
> >>>> :{'/':[51,52,54], 'bcd' :{'/':[68,69,66]}}},'c' :{'/' :[5,6,7,8]}},
> >>>> 'ab' : {'/' :[12,13,14,15]}, 'ac' :{'/' :[21,22,23]}} a['a']
> > {'c': {'/': [5, 6, 7, 8]}, 'b': {'ba': {'/': [41, 42, 44]}, '/': [1,
> > 2, 3, 4], 'bc': {'bcd': {'/': [68, 69, 66]}, '/': [51, 52, 54]}}}
> >>>> a['a']['b']
> > {'ba': {'/': [41, 42, 44]}, '/': [1, 2, 3, 4], 'bc': {'bcd': {'/':
> > [68, 69, 66]}, '/': [51, 52, 54]}}
> >>>> a['a']['b'].values()
> > [{'/': [41, 42, 44]}, [1, 2, 3, 4], {'bcd': {'/': [68, 69, 66]}, '/':
> > [51, 52, 54]}]
>
> > Now I want find all values of key "/"
>
> > Desire result is [41, 42, 44, 1, 2, 3, 4, 68, 69, 66, 51, 52, 54]
>
> > I am trying map, reduce, lambda.
>
> Hmm, I'm trying none of these and get a different result:
>
> >>> def f(d):
>
> ... ? ? stack = [d.iteritems()]
> ... ? ? while stack:
> ... ? ? ? ? ? ? for k, v in stack[-1]:
> ... ? ? ? ? ? ? ? ? ? ? if k == "/":
> ... ? ? ? ? ? ? ? ? ? ? ? ? ? ? yield v
> ... ? ? ? ? ? ? ? ? ? ? else:
> ... ? ? ? ? ? ? ? ? ? ? ? ? ? ? stack.append(v.iteritems())
> ... ? ? ? ? ? ? ? ? ? ? ? ? ? ? break
> ... ? ? ? ? ? ? else:
> ... ? ? ? ? ? ? ? ? ? ? stack.pop()
> ...>>> b = []
> >>> for v in f(a):
>
> ... ? ? b.extend(v)
> ...>>> b
>
> [5, 6, 7, 8, 41, 42, 44, 1, 2, 3, 4, 68, 69, 66, 51, 52, 54, 21, 22, 23, 12,
> 13, 14, 15]
>
> What am I missing?
>
> Peter



From usernet at ilthio.net  Thu Nov  4 13:58:51 2010
From: usernet at ilthio.net (Tim Harig)
Date: Thu, 4 Nov 2010 17:58:51 +0000 (UTC)
Subject: Compare source code
References: <4ccd5ad9$0$19151$426a74cc@news.free.fr>
	 <8j8am4Fk2jU1@mid.individual.net>
	 
	
	<4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com>
	
	
	<4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com>
	
	<4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com>
	
	<87r5f13ug3.fsf.mdw@metalzone.distorted.org.uk>
	
Message-ID: 

On 2010-11-04, MRAB  wrote:
> On 04/11/2010 16:49, Mark Wooding wrote:
>> Seebs  writes:
>>    * I don't have many problems with tools trashing whitespace in Python
>>      programs, though I have seen web forum software mangling
>>      indentation; since this makes nontrivial chunks of almost any
>>      programming language illegible, I'm more than willing to blame the
>>      forum software for this.  I haven't personally seen indentation
>>      trashed by email software, for example (though I steer well clear of
>>      people who try to send me HTML mail).
>>
> If you don't use 
 ... 
or some such then any programming > language is going to look bad! Looking bad and being unrecoverable are two different things. From moura.mario at gmail.com Thu Nov 4 14:01:54 2010 From: moura.mario at gmail.com (macm) Date: Thu, 4 Nov 2010 11:01:54 -0700 (PDT) Subject: How find all childrens values of a nested dictionary, fast! References: <80f5fd35-4689-4d5d-9937-8641992e4c40@k30g2000vbn.googlegroups.com> Message-ID: <7a75c991-5186-4746-8c29-e368673eda74@u10g2000yqk.googlegroups.com> Peter Ok! Both works fine! Thanks a lot! >>> for v in f(a['a']['b']): ... b.extend(v) b Now I will try find which script is the fast! Regards macm On 4 nov, 15:56, macm wrote: > Hi Folks > > Thanks a lot > > Script from Diez works: > > print list(f(a)) > > but should be > > print list(f(a['a']['b'])) > > to fit my example. > > About Peter script > > I am receiving > > >>> for v in f(a['a']['b']): > > ... ? ? b.extend(v) > ... > Traceback (most recent call last): > ? File "", line 2, in > TypeError: 'int' object is not iterable > > I am trying understand this error. > > Best Regards and thanks a lot again! > > Mario > macm > > On 4 nov, 15:26, Peter Otten <__pete... at web.de> wrote: > > > macm wrote: > > > How find all childrens values of a nested dictionary, fast! > > > >>>> a = {'a' : {'b' :{'/' :[1,2,3,4], 'ba' :{'/' :[41,42,44]} ,'bc' > > >>>> :{'/':[51,52,54], 'bcd' :{'/':[68,69,66]}}},'c' :{'/' :[5,6,7,8]}}, > > >>>> 'ab' : {'/' :[12,13,14,15]}, 'ac' :{'/' :[21,22,23]}} a['a'] > > > {'c': {'/': [5, 6, 7, 8]}, 'b': {'ba': {'/': [41, 42, 44]}, '/': [1, > > > 2, 3, 4], 'bc': {'bcd': {'/': [68, 69, 66]}, '/': [51, 52, 54]}}} > > >>>> a['a']['b'] > > > {'ba': {'/': [41, 42, 44]}, '/': [1, 2, 3, 4], 'bc': {'bcd': {'/': > > > [68, 69, 66]}, '/': [51, 52, 54]}} > > >>>> a['a']['b'].values() > > > [{'/': [41, 42, 44]}, [1, 2, 3, 4], {'bcd': {'/': [68, 69, 66]}, '/': > > > [51, 52, 54]}] > > > > Now I want find all values of key "/" > > > > Desire result is [41, 42, 44, 1, 2, 3, 4, 68, 69, 66, 51, 52, 54] > > > > I am trying map, reduce, lambda. > > > Hmm, I'm trying none of these and get a different result: > > > >>> def f(d): > > > ... ? ? stack = [d.iteritems()] > > ... ? ? while stack: > > ... ? ? ? ? ? ? for k, v in stack[-1]: > > ... ? ? ? ? ? ? ? ? ? ? if k == "/": > > ... ? ? ? ? ? ? ? ? ? ? ? ? ? ? yield v > > ... ? ? ? ? ? ? ? ? ? ? else: > > ... ? ? ? ? ? ? ? ? ? ? ? ? ? ? stack.append(v.iteritems()) > > ... ? ? ? ? ? ? ? ? ? ? ? ? ? ? break > > ... ? ? ? ? ? ? else: > > ... ? ? ? ? ? ? ? ? ? ? stack.pop() > > ...>>> b = [] > > >>> for v in f(a): > > > ... ? ? b.extend(v) > > ...>>> b > > > [5, 6, 7, 8, 41, 42, 44, 1, 2, 3, 4, 68, 69, 66, 51, 52, 54, 21, 22, 23, 12, > > 13, 14, 15] > > > What am I missing? > > > Peter > > From __peter__ at web.de Thu Nov 4 14:09:13 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 04 Nov 2010 19:09:13 +0100 Subject: How find all childrens values of a nested dictionary, fast! References: <80f5fd35-4689-4d5d-9937-8641992e4c40@k30g2000vbn.googlegroups.com> Message-ID: macm wrote: > About Peter script > > I am receiving > >>>> for v in f(a['a']['b']): > ... b.extend(v) > ... > Traceback (most recent call last): > File "", line 2, in > TypeError: 'int' object is not iterable > > I am trying understand this error. You are probably mixing Diez' implementation of f() with my invocation code. Or you have modified the input data and now it contains int values. Peter From mdw at distorted.org.uk Thu Nov 4 14:09:47 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 04 Nov 2010 18:09:47 +0000 Subject: Allow multiline conditions and the like References: <4cce7196$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87iq0d3qqc.fsf.mdw@metalzone.distorted.org.uk> Chris Rebert writes: > Or, if possible, refactor the conditional into a function (call) so > it's no longer multiline in the first place. No! This /increases/ cognitive load for readers, because they have to deal with the indirection through the name. If you actually use the function multiple times, the mental overhead of forming the abstraction and associating it with the function name is shared across the various call sites and it's probably worth it. If it's only called once, leave it inline. -- [mdw] From neilc at norwich.edu Thu Nov 4 14:18:28 2010 From: neilc at norwich.edu (Neil Cerutti) Date: 4 Nov 2010 18:18:28 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> Message-ID: <8jgbnkF8q1U1@mid.individual.net> On 2010-11-04, Grant Edwards wrote: > On 2010-11-04, Neil Cerutti wrote: >> On 2010-11-04, D'Arcy J.M. Cain wrote: >>>> * Not being able to write an auto-indenter, ever, because it >>>> is by design theoretically impossible: Annoying. >>> >>> Right. And in C you can never write an auto-bracer for >>> exactly the same reason. >> >> It's not right, actually. Auto-indent is fairly easy in >> Python. Auto-dedent is the impossible part. > > I think in common usage the term "auto-intender" refers to a > program that can automatically control source indentation > (which inclulde both "indenting" and "dindenting" source > lines). Thanks for the correction. Autoindent doesn't mean that to me (I'm a vi user), but I should have figured out what he meant from the context. -- Neil Cerutti From darcy at druid.net Thu Nov 4 14:39:04 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Thu, 4 Nov 2010 14:39:04 -0400 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> Message-ID: <20101104143904.f2ac4a5e.darcy@druid.net> On Thu, 4 Nov 2010 17:55:55 +0000 (UTC) Tim Harig wrote: > What Seebs is refering to is that it is difficult or impossible to > re-indent Python source automatically after the indent structure has been > broken (such as his email being converted to html on the server or a web Right. If you mangle spaces in Python or mangle braces in C then recovery becomes impossible. I don't think anyone is contesting that. What we question is the idea that somehow Python is special in this regard. If you move files around in ways that change them then your tools are broken. The fact that the breakage is somewhat "friendlier" to some types of files is interesting but irrelevant. What would you say to a file transfer program that changed Word documents? What about executable files? -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From mdw at distorted.org.uk Thu Nov 4 14:48:05 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 04 Nov 2010 18:48:05 +0000 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <87mxpp3u3i.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <87aalp3oyi.fsf.mdw@metalzone.distorted.org.uk> Tim Harig writes: > So, your telling me that mixing tabs and spaces is considered a good > practice in Haskell? It doesn't seem to be a matter which is discussed much. I think Haskell programmers are used to worrying their brains with far more complicated things like wobbly[1] types. > I would argue that text files do not have tab stops -- text editors > do. So long as you use tabs for all of your indenting, it is quite > safe to set the editors tab stops however one likes since the editor's > tab stop doesn't effect the output of the file. This is wishful thinking. Firstly, code written with a narrow indentation offset (e.g., two spaces) can take up an uncomfortable width when viewed with a wider offset. Secondly, if you want other parts (e.g., per-line comments) of lines with different indentations to align, then you'll have to take into account the tab width. Technically, you could arrange that between any pair of alignment points of any pair of lines there are the same number of tab characters; but this is also doomed to uncomfortably wide lines; it also suffers because it imposes an /a priori/ upper bound on the indentation level. [1] Proper technical term. I kid you not. -- [mdw] From moura.mario at gmail.com Thu Nov 4 14:48:28 2010 From: moura.mario at gmail.com (macm) Date: Thu, 4 Nov 2010 11:48:28 -0700 (PDT) Subject: How convert list to nested dictionary? Message-ID: <940876cd-2546-4673-aef4-ba11b4156287@fv1g2000vbb.googlegroups.com> Hi Folks How convert list to nested dictionary? >>> l ['k1', 'k2', 'k3', 'k4', 'k5'] >>> result {'k1': {'k2': {'k3': {'k4': {'k5': {}}}}}} Regards macm From clp2 at rebertia.com Thu Nov 4 14:53:36 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 4 Nov 2010 11:53:36 -0700 Subject: How convert list to nested dictionary? In-Reply-To: <940876cd-2546-4673-aef4-ba11b4156287@fv1g2000vbb.googlegroups.com> References: <940876cd-2546-4673-aef4-ba11b4156287@fv1g2000vbb.googlegroups.com> Message-ID: On Thu, Nov 4, 2010 at 11:48 AM, macm wrote: > Hi Folks > > How convert list to nested dictionary? > >>>> l > ['k1', 'k2', 'k3', 'k4', 'k5'] >>>> result > {'k1': {'k2': {'k3': {'k4': {'k5': {}}}}}} We don't do homework. Hint: Iterate through the list in reverse order, building up your result. Using reduce() is one option. Cheers, Chris From nad at acm.org Thu Nov 4 15:12:01 2010 From: nad at acm.org (Ned Deily) Date: Thu, 04 Nov 2010 12:12:01 -0700 Subject: Best method for a menu in a command line program? References: <87wrotfhj2.fsf@benfinney.id.au> Message-ID: In article <87wrotfhj2.fsf at benfinney.id.au>, Ben Finney wrote: > brf256 at gmail.com writes: > > Thanks again, > > Braden Faulkner > > > > Sent wirelessly from my BlackBerry device on the Bell network. > > Envoy? sans fil par mon terminal mobile BlackBerry sur le r?seau de Bell. > > Please show your thanks by *not* spamming the forum with each message; > compose your messages from a mail client that doesn't feel the need to > blather about itself in the message body. > > -- > \ ?For fast acting relief, try slowing down.? ?Jane Wagner, via | > `\ Lily Tomlin | > _o__) | > Ben Finney If I were a rude person, I might observe that "spamming" is relative: some who obsess about "spam" might consider 2 lines less of an evil than 5 lines. But I'm not, so I won't. -- Ned Deily, nad at acm.org From mdw at distorted.org.uk Thu Nov 4 15:16:56 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 04 Nov 2010 19:16:56 +0000 Subject: Man pages and info pages References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> <024ef21a-9ef9-48a6-8372-1d66895583c3@v16g2000yqn.googlegroups.com> <87zktr5yze.fsf_-_@mithlond.arda> <877hgv2fg3.fsf@mithlond.arda> Message-ID: <8762wc526v.fsf.mdw@metalzone.distorted.org.uk> Tim Harig writes: > When the GNU folk decided to clone *nix they decided that they knew > better and simply decided to create their own interfaces. This isn't the case. Actually Info has a long history prior to GNU: it was the way that the documentation was presented at the MIT AI lab. In fact, Info was used rather like a modern wiki. The operating system they used, called ITS, didn't have a concept of file permissions, and users were encouraged to improve documentation (and programs). The original Info viewer was implemented in Emacs (which also originated in ITS, years before GNU). Texinfo was a GNU innovation: the idea that you could build both the Info document and a nice printable manual from a single source was novel, as was the application to Unix. But, since Stallman was documenting large software systems like Emacs and GCC, it doesn't seem unreasonable to provide manuals which are somewhat more discursive and leisurely than traditional Unix manpages. I have a printed copy of the GNU Emacs 18 manual (from 1987): it's almost 300 pages long. The modern manual for Emacs 23 is several /times/ larger than this. Man pages don't scale that well. I do agree it's annoying that the official coreutils documentation is in Texinfo. > Actually, the left arrow key does not work at all intuitively. One > would expect that it should go back to the previous page as it would > in lynx, etc. It does not. It moves the cursor so you can hit links. The l key takes you back through your recent viewing history -- and has done for thirty years. > By tradition 'n' and 'p' are broken for scrolling in a page. 'b' is > often used in place of p but that seems to take one back to the top of > the page. Space and backspace are an older tradition. > The s key for a search is another example that has already been > discussed. I find C-s more useful in Info, because it searches interactively. I frequently get muddled when I try to search in `modern' programs like web browsers, because they've gratuitously made C-s try to save the page (something one hardly ever wants to do) rather than search. (Finding is different: finding is what happens at the end of a /successful/ search. So C-f is poorly chosen.) -- [mdw] From nad at acm.org Thu Nov 4 15:23:28 2010 From: nad at acm.org (Ned Deily) Date: Thu, 04 Nov 2010 12:23:28 -0700 Subject: Compiling/Installing Python 2.7 on OSX 10.6 References: <3d9139ae-bd6f-4567-bb02-b21a8ba86e50@o15g2000prh.googlegroups.com> Message-ID: In article <3d9139ae-bd6f-4567-bb02-b21a8ba86e50 at o15g2000prh.googlegroups.com>, Jeremy wrote: > I'm having trouble installing Python 2.7 on OSX 10.6 I was able to > successfully compile it from source, but ran into problems when I did > make install. The error I got (I received many similar errors) was: > > /usr/bin/install -c -m 644 ../LICENSE /home/jlconlin/Library/ > Frameworks/Python.framework/Versions/2.7/lib/python2.7/LICENSE.txt > PYTHONPATH=/home/jlconlin/Library/Frameworks/Python.framework/Versions/ > 2.7/lib/python2.7 DYLD_FRAMEWORK_PATH=/home/jlconlin/src/Python-2.7/ > build: \ > ./python -Wi -tt /home/jlconlin/Library/Frameworks/Python.framework/ > Versions/2.7/lib/python2.7/compileall.py \ > -d /home/jlconlin/Library/Frameworks/Python.framework/Versions/2.7/ > lib/python2.7 -f \ > -x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \ > /home/jlconlin/Library/Frameworks/Python.framework/Versions/2.7/lib/ > python2.7 > Listing /home/jlconlin/Library/Frameworks/Python.framework/Versions/ > 2.7/lib/python2.7 ... > Compiling /home/jlconlin/Library/Frameworks/Python.framework/Versions/ > 2.7/lib/python2.7/._BaseHTTPServer.py ... > Sorry: TypeError: ('compile() expected string without null bytes',) > Compiling /home/jlconlin/Library/Frameworks/Python.framework/Versions/ > 2.7/lib/python2.7/._Bastion.py ... > Sorry: TypeError: ('compile() expected string without null bytes',) > Compiling /home/jlconlin/Library/Frameworks/Python.framework/Versions/ > 2.7/lib/python2.7/._CGIHTTPServer.py ... > Sorry: TypeError: ('compile() expected string without null bytes',) How did you obtain and unpack the source? It looks like you used something that created the old-style "._" hidden forks when extracting the source. The path names look a little suspicious, too: /home/jlconlin. What file system type are these files on? You shouldn't run into problems if you use an HFS+ file system (for instance) and extract the tarball from the command line using /usr/bin/tar. > PS. Python compiled correctly, but a few modules were not found/made > but I don't think they are important. > > Python build finished, but the necessary bits to build these modules > were not found: > _bsddb dl gdbm > imageop linuxaudiodev ossaudiodev > spwd sunaudiodev Yes, all of those are to be expected on an OS X 64-bit build. -- Ned Deily, nad at acm.org From usernet at ilthio.net Thu Nov 4 15:25:30 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 4 Nov 2010 19:25:30 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <87mxpp3u3i.fsf.mdw@metalzone.distorted.org.uk> <87aalp3oyi.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On 2010-11-04, Mark Wooding wrote: > Tim Harig writes: > This is wishful thinking. Firstly, code written with a narrow > indentation offset (e.g., two spaces) can take up an uncomfortable width > when viewed with a wider offset. I can accept that as a trade-off. People have different ideas about acceptable column width anyway. I use 8 space tab stops and target to no more then 80 columns. If somebody uses 2 space tab stops, its going to go over the 80 columns a little bit; but, not so much as cause a major issue. > Secondly, if you want other parts (e.g., per-line comments) of lines > with different indentations to align, then you'll have to take into > account the tab width. Technically, you could arrange that between any > pair of alignment points of any pair of lines there are the same number > of tab characters; but this is also doomed to uncomfortably wide lines; > it also suffers because it imposes an /a priori/ upper bound on the > indentation level. I use simple comments that are not effected by white space. I don't waste my time trying to make comments look artistic. They are there to convey information; not to look pretty. I really detest having to edit other peoples comment formatting where you have to re-align everything if the length of any of comment lines change. From jlconlin at gmail.com Thu Nov 4 15:33:04 2010 From: jlconlin at gmail.com (Jeremy) Date: Thu, 4 Nov 2010 12:33:04 -0700 (PDT) Subject: Compiling/Installing Python 2.7 on OSX 10.6 References: <3d9139ae-bd6f-4567-bb02-b21a8ba86e50@o15g2000prh.googlegroups.com> Message-ID: <238cec6d-2f47-4c97-8941-e28e6808946c@a9g2000pro.googlegroups.com> On Nov 4, 1:23?pm, Ned Deily wrote: > In article > <3d9139ae-bd6f-4567-bb02-b21a8ba86... at o15g2000prh.googlegroups.com>, > > > > > > ?Jeremy wrote: > > I'm having trouble installing Python 2.7 on OSX 10.6 ?I was able to > > successfully compile it from source, but ran into problems when I did > > make install. ?The error I got (I received many similar errors) was: > > > /usr/bin/install -c -m 644 ../LICENSE /home/jlconlin/Library/ > > Frameworks/Python.framework/Versions/2.7/lib/python2.7/LICENSE.txt > > PYTHONPATH=/home/jlconlin/Library/Frameworks/Python.framework/Versions/ > > 2.7/lib/python2.7 ?DYLD_FRAMEWORK_PATH=/home/jlconlin/src/Python-2.7/ > > build: \ > > ? ? ? ? ? ?./python -Wi -tt /home/jlconlin/Library/Frameworks/Python.framework/ > > Versions/2.7/lib/python2.7/compileall.py \ > > ? ? ? ? ? ?-d /home/jlconlin/Library/Frameworks/Python.framework/Versions/2.7/ > > lib/python2.7 -f \ > > ? ? ? ? ? ?-x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \ > > ? ? ? ? ? ?/home/jlconlin/Library/Frameworks/Python.framework/Versions/2.7/lib/ > > python2.7 > > Listing /home/jlconlin/Library/Frameworks/Python.framework/Versions/ > > 2.7/lib/python2.7 ... > > Compiling /home/jlconlin/Library/Frameworks/Python.framework/Versions/ > > 2.7/lib/python2.7/._BaseHTTPServer.py ... > > Sorry: TypeError: ('compile() expected string without null bytes',) > > Compiling /home/jlconlin/Library/Frameworks/Python.framework/Versions/ > > 2.7/lib/python2.7/._Bastion.py ... > > Sorry: TypeError: ('compile() expected string without null bytes',) > > Compiling /home/jlconlin/Library/Frameworks/Python.framework/Versions/ > > 2.7/lib/python2.7/._CGIHTTPServer.py ... > > Sorry: TypeError: ('compile() expected string without null bytes',) > > How did you obtain and unpack the source? ?It looks like you used > something that created the old-style "._" hidden forks when extracting > the source. ? I downloaded the source from python.org and extracted with 'tar -xzvf Python-2.7.tgz' My home space is on some network somewhere. I think the network filesystem creates the ._ at the beginning of the files. It's really quite annoying. > The path names look a little suspicious, too: > /home/jlconlin. ?What file system type are these files on? ?You > shouldn't run into problems if you use an HFS+ file system (for > instance) and extract the tarball from the command line using > /usr/bin/tar. I am intentionally installing in my home directory (i.e., /home/ jlconlin) because I don't have access to /usr/local. Supposedly this is possible, and in fact common. > > > PS. Python compiled correctly, but a few modules were not found/made > > but I don't think they are important. > > > Python build finished, but the necessary bits to build these modules > > were not found: > > _bsddb ? ? ? ? ? ? dl ? ? ? ? ? ? ? ? gdbm > > imageop ? ? ? ? ? ?linuxaudiodev ? ? ?ossaudiodev > > spwd ? ? ? ? ? ? ? sunaudiodev > > Yes, all of those are to be expected on an OS X 64-bit build. Is it safe to ignore these modules then? Thanks, Jeremy From usernet at ilthio.net Thu Nov 4 15:37:25 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 4 Nov 2010 19:37:25 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> Message-ID: On 2010-11-04, D'Arcy J.M. Cain wrote: > On Thu, 4 Nov 2010 17:55:55 +0000 (UTC) > Tim Harig wrote: >> What Seebs is refering to is that it is difficult or impossible to >> re-indent Python source automatically after the indent structure has been >> broken (such as his email being converted to html on the server or a web > > Right. If you mangle spaces in Python or mangle braces in C then > recovery becomes impossible. I don't think anyone is contesting that. Examples of communication channels that mangle white space abound. I don't know of any that mangle either braces or pascal style start/end blocks. You are the one who seems to be on a crusade against against braces. It would seem to me, that if you want people to accept that white space formatting is superior, that you would be looking for a simple way to solve the white space mangling problem. > What we question is the idea that somehow Python is special in this > regard. If you move files around in ways that change them then your > tools are broken. The fact that the breakage is somewhat "friendlier" The world is full of broken tools that many of us have to use; but, why should we accept that your choice is superior when other choices manage to work with these tools without issues. > tools are broken. The fact that the breakage is somewhat "friendlier" > to some types of files is interesting but irrelevant. What would you > say to a file transfer program that changed Word documents? What about > executable files? Transfering binary programs has always been an issue and using text based communications (preferably human readable) has always been considered a good design decision. I put up with Python's white space idiosyncrasies; I wouldn't even bother looking at a language that requires me to enter the source in binary. I also consider the move toward XML based document formats a move in the right direction. From nad at acm.org Thu Nov 4 15:41:53 2010 From: nad at acm.org (Ned Deily) Date: Thu, 04 Nov 2010 12:41:53 -0700 Subject: Final state of underlying sequence in islice References: Message-ID: In article , Shashank Singh wrote: > Are there any promises made with regard to final state of the underlying > sequence that islice slices? [...] > While "fixing" this should be rather easy in terms of the change in code > required it might break any code depending > on this seemingly incorrect behavior. I suggest you open an issue at http://bugs.python.org/. -- Ned Deily, nad at acm.org From invalid at invalid.invalid Thu Nov 4 15:46:28 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 4 Nov 2010 19:46:28 +0000 (UTC) Subject: Best method for a menu in a command line program? References: <87wrotfhj2.fsf@benfinney.id.au> Message-ID: On 2010-11-04, Ned Deily wrote: > Ben Finney wrote: >> brf256 at gmail.com writes: >> > Thanks again, >> > Braden Faulkner >> > >> > Sent wirelessly from my BlackBerry device on the Bell network. >> > Envoy?? sans fil par mon terminal mobile BlackBerry sur le r??seau de Bell. >> >> Please show your thanks by *not* spamming the forum with each message; >> compose your messages from a mail client that doesn't feel the need to >> blather about itself in the message body. >> >> -- >> \ ???For fast acting relief, try slowing down.??? ???Jane Wagner, via | >> `\ Lily Tomlin | >> _o__) | >> Ben Finney > > If I were a rude person, I might observe that "spamming" is relative: > some who obsess about "spam" might consider 2 lines less of an evil than > 5 lines. > > But I'm not, so I won't. I must admit that I sympathise with Ben: I find those "sent from my iphone/blackberry" lines exruciatingly annoying, and I'm not really sure why. They waste less space than my (or Ben's) sig, and actually do convey some sort of (pointless) information -- unlike randomly chosen Zippy-the-pinhead quotes. Still, I find them very smug, self-satisfied and irritating. Sort of like those doors from the Serious Cybernetics Corporation. I don't know whether it's that somebody is bragging about having a blackberry/iphone (whoop-de-friggin-do!), or that having one is somehow a valid excuse for poorly-written postings. I'm not specifically accusing Braden Faulkner of posting badly written articles, but it does seem to be a trend among people who use iphones and blackberrys to post. -- Grant Edwards grant.b.edwards Yow! I didn't order any at WOO-WOO ... Maybe a YUBBA gmail.com ... But no WOO-WOO! Posted from my Linux computer using mutt! From news1234 at free.fr Thu Nov 4 15:57:30 2010 From: news1234 at free.fr (News123) Date: Thu, 04 Nov 2010 20:57:30 +0100 Subject: Python documentation too difficult for beginners In-Reply-To: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4cd3102a$0$22754$426a74cc@news.free.fr> On 11/02/2010 02:42 PM, Steven D'Aprano wrote: > However, there is a Python wiki. It doesn't get anywhere near as much > love as it deserves, and (I think) the consensus was that the official > Python docs should stay official, but link to the wiki for user- > contributed content. This hasn't happened yet. > > http://wiki.python.org/moin/ That sounds like an excellent idea. I often would have appreciated more examples or discussions about a given module/class/function without having to fall back to Google. It might be a good compromise: clearly separating official doc and examples, but accepting, that the doc is often insufficient without digging into the sources or searching for more xamples. The more one uses python, the easier it becomes to find what one looks for. My first Impression about Python however was: - the basic language is rather easy to learn - the library documentation was more difficult to understand than the one for PHP or for Perl. > Frankly, I think that the best thing you could do is start a fork of the > docs and see if you get any interest from people. If you do, then you can > go back to python-dev with proof that there is a genuine popular desire > for more structured, PHP-style documentation. I'd prefer crosslinking the doc with something, that's easier for beginners of for people who never used a given library before. From mdw at distorted.org.uk Thu Nov 4 15:57:39 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 04 Nov 2010 19:57:39 +0000 Subject: Ways of accessing this mailing list? References: Message-ID: <871v7050b0.fsf.mdw@metalzone.distorted.org.uk> John Bond writes: > Hope this isn't too O/T - I was just wondering how people read/send to > this mailing list, eg. normal email client, gmane, some other software > or online service? > > My normal inbox is getting unmanageable, and I think I need to find a > new way of following this and other lists. I read and post to it as comp.lang.python. I maintain a local NNTP server, which interacts with my ISP's news server. I read and post news (and mail) using GNU Emacs and Gnus. (Interestingly, if enormous folders are your problem, Gnus can apply news-like expiry rules to email folders.) -- [mdw] From darcy at druid.net Thu Nov 4 16:04:47 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Thu, 4 Nov 2010 16:04:47 -0400 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> Message-ID: <20101104160447.a5e72505.darcy@druid.net> On Thu, 4 Nov 2010 19:37:25 +0000 (UTC) Tim Harig wrote: > On 2010-11-04, D'Arcy J.M. Cain wrote: > You are the one who seems to be on a crusade against against braces. It You totally misunderstand me. I am not on a crusade of any sort. I am happy with Python and the number of other people who are happy with it is interesting but does not change my life in any significant way. As long as there are enough people using it to keep it alive that's all I care about. If no one was on a crusade to convince people that indentation as syntax (can we call is IAS from now on?) was evil then I wouldn't be posting anything at all on the subject. I am being totally reactionary here. > would seem to me, that if you want people to accept that white space > formatting is superior, that you would be looking for a simple way to solve > the white space mangling problem. I might if it was a problem for me. > The world is full of broken tools that many of us have to use; but, why > should we accept that your choice is superior when other choices manage to > work with these tools without issues. You don't have to accept anything. Choose your own tools. I happen to choose Python and the tools that I choose to use work fine for me. > the source in binary. I also consider the move toward XML based document > formats a move in the right direction. Don't get me started on XML. ;-) -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From nad at acm.org Thu Nov 4 16:05:22 2010 From: nad at acm.org (Ned Deily) Date: Thu, 04 Nov 2010 13:05:22 -0700 Subject: Compiling/Installing Python 2.7 on OSX 10.6 References: <3d9139ae-bd6f-4567-bb02-b21a8ba86e50@o15g2000prh.googlegroups.com> <238cec6d-2f47-4c97-8941-e28e6808946c@a9g2000pro.googlegroups.com> Message-ID: In article <238cec6d-2f47-4c97-8941-e28e6808946c at a9g2000pro.googlegroups.com>, Jeremy wrote: [...] > I downloaded the source from python.org and extracted with 'tar -xzvf > Python-2.7.tgz' My home space is on some network somewhere. I think > the network filesystem creates the ._ at the beginning of the files. > It's really quite annoying. It is and really shouldn't be happening. If I understand correctly, whoever administers your system is doing its users a disservice by putting OS X home directories on such a file system. > > The path names look a little suspicious, too: > > /home/jlconlin. ?What file system type are these files on? ?You > > shouldn't run into problems if you use an HFS+ file system (for > > instance) and extract the tarball from the command line using > > /usr/bin/tar. > > I am intentionally installing in my home directory (i.e., /home/ > jlconlin) because I don't have access to /usr/local. Supposedly this > is possible, and in fact common. It is common and not normally a problem. I was just noting that the path name was not the OS X default of /Users/jlconlin. That said, there are a couple of options. Either find another file system to install to or, after extracting, you may be able to delete the spurious '._' files by a judicious use of find (-name '\.\_*' perhaps), or you could probably just ignore all the "compiling" errors. Those aren't "compile" errors in the sense of C compiler errors; rather they are from one of the final install steps that produces optimized .pyc and .pyo versions of all of the standard library .py files. The ._ files aren't python files but they do end in .py so compileall mistakenly tries to bytecompile them, too. > Is it safe to ignore these modules then? Yes. -- Ned Deily, nad at acm.org From darcy at druid.net Thu Nov 4 16:11:31 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Thu, 4 Nov 2010 16:11:31 -0400 Subject: Best method for a menu in a command line program? In-Reply-To: References: <87wrotfhj2.fsf@benfinney.id.au> Message-ID: <20101104161131.a74f213c.darcy@druid.net> On Thu, 4 Nov 2010 19:46:28 +0000 (UTC) Grant Edwards wrote: > I don't know whether it's that somebody is bragging about having a > blackberry/iphone (whoop-de-friggin-do!), or that having one is > somehow a valid excuse for poorly-written postings. I'm not It's really just a matter of not knowing or caring how to change the default. Mine says "Sent from my brain". -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From usenet-nospam at seebs.net Thu Nov 4 16:11:36 2010 From: usenet-nospam at seebs.net (Seebs) Date: 04 Nov 2010 20:11:36 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> Message-ID: On 2010-11-04, D'Arcy J.M. Cain wrote: > Right. If you mangle spaces in Python or mangle braces in C then > recovery becomes impossible. I don't think anyone is contesting that. > What we question is the idea that somehow Python is special in this > regard. If you move files around in ways that change them then your > tools are broken. The fact that the breakage is somewhat "friendlier" > to some types of files is interesting but irrelevant. Again, why does "diff -b" exist? It exists because so many things change whitespace unintentionally that it's a common failure mode. Thus, people developing data file formats often put substantial effort into *guaranteeing* that they will survive changes to the contents of blocks of whitespace -- it won't matter whether you used spaces or tabs, or how many spaces there are. This is done because, if you don't do it, your files sometimes get broken. I have never heard of a problem where sending something via a common commercial mail client with its default settings resulted in the destruction of braces. I have regularly seen people report that one mail client or another is losing or adding spaces, converting tabs to spaces, converting spaces to tabs, or whatever. To some extent, it may be largely a matter of convention; it is conceivable that, had Python been a major and influential language in 1970, tools in general would be much more careful about preserving spaces. But that's not what happened. Python was created in a world where the decision had already been made by many engineers (often poor ones) that it was not a big deal to mess up spacing a bit. I'd guess this decision goes back to early typesetting. Spaces are fungible; other content isn't. The distinction that is tracked is "was there space between these characters or not". Given that widespread presupposition, and that many file formats have been adapted to that, I don't think it was a good choice to build something which would be broken by that common failure mode. It's not as though widespread spacing problems are a surprise. They are so commonplace that multiple utility programs provide, as standard options, features to work around them. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Thu Nov 4 16:17:35 2010 From: usenet-nospam at seebs.net (Seebs) Date: 04 Nov 2010 20:17:35 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <87r5f13ug3.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On 2010-11-04, Mark Wooding wrote: > Seebs writes: >> Python's the only language I use where an obvious flaw, which is >> repeatedly observed by everyone I know who uses the language, is >> militantly and stridently defended by dismissing, insulting, and >> attacking the character and motives of anyone who suggests that it >> might be a bit of a nuisance. > So you've not tried Lisp, then? Dissing Lisp's parentheses tends to get > a pretty similar reaction. I don't use it. I'm also not as sure that the parens are an obvious flaw -- I am not aware of whole categories of software which regularly destroy parens. > * I /do/ have a significant problem with cutting and pasting code in > Python. In most languages, I can haul a chunk of code about, hit > C-M-q, and Emacs magically indents the result properly. This is, > unfortunately, impossible with Python. It has caused me real bugs, > and I have to be extra careful to fix the indentation up. That was the thing which bit me the worst. I had a fairly large block of code in a first-pass ugly program. I wanted to start refactoring it, so I moved a big hunk of code into a method (with plans to further refactor). It took about fifteen minutes to redo the logic. > I /like/ Python. I use it frequently. I /don't/ want to change its > structure marked by indentation. I'm /willing/ to put up with some > inconvenience because Python makes up for it in other ways. But there > /is/ inconvenience, and it does need putting up with. I think the > benefits are worth the costs; others may disagree. That makes sense to me. I think it depends a lot on what I compare Python to. I get along quite well with Ruby, but I loathe PHP. Comparing Python to Ruby, I find the indentation quite annoying. Comparing Python to PHP, I find the indentation a very mild price to pay for my sanity. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From tjreedy at udel.edu Thu Nov 4 16:21:21 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 04 Nov 2010 16:21:21 -0400 Subject: Best method for a menu in a command line program? In-Reply-To: References: Message-ID: On 11/3/2010 9:19 PM, braden faulkner wrote: > I'm using a menu for my command line app using this method. > > choice = "foobar" > while choice != "q": > if choice == "c": > temp = input("Celsius temperature:") > print "Fahrenheit:",celsius_to_fahrenheit(temp) > elif choice == "f": > temp = input("Fahrenheit temperature:") > print "Celsius:",fahrenheit_to_celsius(temp) > elif choice != "q": > print_options() > choice = raw_input("option:") > > Just wondering if there is another or more efficient way I should be doing it? Others have answered that, but I would point to the inefficiency for users of having to enter unit and value on two separate lines. The prompt could be "Enter value and unit (f, c, or k) or q to quit: " Allow upper and lower case, with or without a space between. -- Terry Jan Reedy From philip at semanchuk.com Thu Nov 4 16:22:53 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Thu, 4 Nov 2010 16:22:53 -0400 Subject: Compiling/Installing Python 2.7 on OSX 10.6 In-Reply-To: References: <3d9139ae-bd6f-4567-bb02-b21a8ba86e50@o15g2000prh.googlegroups.com> <238cec6d-2f47-4c97-8941-e28e6808946c@a9g2000pro.googlegroups.com> Message-ID: <6F087CE1-5391-4EE3-B92A-5A499FDF0E6C@semanchuk.com> On Nov 4, 2010, at 4:05 PM, Ned Deily wrote: > In article > <238cec6d-2f47-4c97-8941-e28e6808946c at a9g2000pro.googlegroups.com>, > Jeremy wrote: > [...] >> I downloaded the source from python.org and extracted with 'tar -xzvf >> Python-2.7.tgz' My home space is on some network somewhere. I think >> the network filesystem creates the ._ at the beginning of the files. >> It's really quite annoying. > > It is and really shouldn't be happening. If I understand correctly, > whoever administers your system is doing its users a disservice by > putting OS X home directories on such a file system. > >>> The path names look a little suspicious, too: >>> /home/jlconlin. What file system type are these files on? You >>> shouldn't run into problems if you use an HFS+ file system (for >>> instance) and extract the tarball from the command line using >>> /usr/bin/tar. >> >> I am intentionally installing in my home directory (i.e., /home/ >> jlconlin) because I don't have access to /usr/local. Supposedly this >> is possible, and in fact common. > > It is common and not normally a problem. I was just noting that the > path name was not the OS X default of /Users/jlconlin. > > That said, there are a couple of options. Either find another file > system to install to or, after extracting, you may be able to delete the > spurious '._' files by a judicious use of find (-name '\.\_*' perhaps), > or you could probably just ignore all the "compiling" errors. Those > aren't "compile" errors in the sense of C compiler errors; rather they > are from one of the final install steps that produces optimized .pyc and > .pyo versions of all of the standard library .py files. The ._ files > aren't python files but they do end in .py so compileall mistakenly > tries to bytecompile them, too. You might want to try this before running tar to see if it inhibits the ._ files: export COPYFILE_DISABLE=True I know that tells tar to ignore those files (resource forks, no?) when building a tarball. I don't know if it helps with extraction though. Good luck Philip From mdw at distorted.org.uk Thu Nov 4 16:23:31 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 04 Nov 2010 20:23:31 +0000 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <87mxpp3u3i.fsf.mdw@metalzone.distorted.org.uk> <87aalp3oyi.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <87tyjw3kjg.fsf.mdw@metalzone.distorted.org.uk> Tim Harig writes: > I use simple comments that are not effected by white space. I don't > waste my time trying to make comments look artistic. They are there > to convey information; not to look pretty. I really detest having to > edit other peoples comment formatting where you have to re-align > everything if the length of any of comment lines change. I view source code as primarily a means of communication with human readers, and only secondarily as being machine readable. I therefore think it's worth the effort to make source code readily legible, for example by making effective use of horizontal and vertical whitespace. A long time ago, I spent a little while studying graphic design, so I try to keep an eye on this sort of thing. I'm interested in line length for two reasons: firstly, because I believe that there's an optimum line length for easy and rapid reading, which is probably a bit less than 80 columns; and secondly because I find that I make more effective use of the available space on my screen if I have several narrow columns rather than a few wide ones -- since most lines in source files are short, a wide column ends up being mostly empty on the right hand side, which is wasteful. It's true that a source file is not the same as a typeset document: the most obvious difference is that source files are modified over time, sometimes by many hands, and that therefore some of the tradeoffs are different. I dislike `pretty' boxes around large comments, for example, because maintaining the right hand edge is unnecessarily tedious. But sometimes careful alignment can help a reader spot a symmetry or find his way through a repetitive section such a table more easily. (Unfortunately, I appear to have strange ideas about what `legible' means...) -- [mdw] From invalid at invalid.invalid Thu Nov 4 16:54:09 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 4 Nov 2010 20:54:09 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> Message-ID: On 2010-11-04, Seebs wrote: > On 2010-11-04, D'Arcy J.M. Cain wrote: >> Right. If you mangle spaces in Python or mangle braces in C then >> recovery becomes impossible. I don't think anyone is contesting that. >> What we question is the idea that somehow Python is special in this >> regard. If you move files around in ways that change them then your >> tools are broken. The fact that the breakage is somewhat "friendlier" >> to some types of files is interesting but irrelevant. > > Again, why does "diff -b" exist? > > It exists because so many things change whitespace unintentionally that > it's a common failure mode. It exists because so many people change whitespace intentionally in C source code because no two C programmers seem able to agree on how to format code. Diff -b allows you to attempt to ignore semantically null stylistic changes made by programmers. -- Grant Edwards grant.b.edwards Yow! I'm having a RELIGIOUS at EXPERIENCE ... and I don't gmail.com take any DRUGS From bigfatwhale at gmail.com Thu Nov 4 17:00:44 2010 From: bigfatwhale at gmail.com (Pix) Date: Thu, 4 Nov 2010 14:00:44 -0700 (PDT) Subject: 3rd party python module with pyd picking up wrong dlls Message-ID: <4d01a7f1-18d6-44e9-8ce2-37321d20231a@t35g2000yqj.googlegroups.com> Hi, I'm trying to install OpenSSL by placing it in site-packages\OpenSSL. In the directory there the following files, crypto.pyd libeay32.dll rand.pyd SSL.pyd ssleay32.dll When i try to import the module by doing "import OpenSSL" i get an import error saying "ImportError: DLL load failed: The specified module could not be found". It turns out that there is another module (call it XXX) that is install which contains different versions of libeay32.dll and ssleay32.dll. And the path to the XXX appears earlier in os.environ['PATH'] than the OpenSSL dir. So this cause it to pick up the wrong dll which in turn causes the import error. If i renamed the dlls in XXX's dir then the import will work fine. So my question is, shouldn't the import be picking up the dlls in the module directory first before following the PATH in it's search order? Seem that is doesn't make sense because if i put OpenSSL earlier in the path, it would work for OpenSSL, but then XXX will be picking up the wrong dll. Any help is much appreciated! Regards, Pix From clp2 at rebertia.com Thu Nov 4 17:00:56 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 4 Nov 2010 14:00:56 -0700 Subject: Allow multiline conditions and the like In-Reply-To: <87iq0d3qqc.fsf.mdw@metalzone.distorted.org.uk> References: <4cce7196$0$29965$c3e8da3$5496439d@news.astraweb.com> <87iq0d3qqc.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On Thu, Nov 4, 2010 at 11:09 AM, Mark Wooding wrote: > Chris Rebert writes: >> Or, if possible, refactor the conditional into a function (call) so >> it's no longer multiline in the first place. > > No! ?This /increases/ cognitive load for readers, because they have to > deal with the indirection through the name. If it's well-named, then the reader can delay having to read the definition. > If you actually use the > function multiple times, the mental overhead of forming the abstraction > and associating it with the function name is shared across the various > call sites and it's probably worth it. ?If it's only called once, leave > it inline. I'd say it's a judgment call. If the condition is sufficiently complicated and can be well-named, then I see justifying refactoring it into a function even if it's only used once. However, this is admittedly not a common situation. Cheers, Chris -- http://blog.rebertia.com From tjreedy at udel.edu Thu Nov 4 17:04:55 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 04 Nov 2010 17:04:55 -0400 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 11/4/2010 4:17 AM, Seebs wrote: I am sorry you feel compelled to use a language you so dislike. Not our fault though. > Other languages I use are mostly amenable to the development of tools > to automatically indent code. Makefiles and Python are the only two > exceptions... If you add the normally redundant information in the form of explicit dedents (anything starting with '#' and distinguishable from normal comments), then it is not too hard to re-indent even after all indents have been removed. I believe this has been dome more than once. By using a stylized comment, the augmented code runs without preprocessing. I also believe at lease one person has written a preprocessor for 'python-with-braces'. -- Terry Jan Reedy From moura.mario at gmail.com Thu Nov 4 17:10:12 2010 From: moura.mario at gmail.com (macm) Date: Thu, 4 Nov 2010 14:10:12 -0700 (PDT) Subject: How convert list to nested dictionary? References: <940876cd-2546-4673-aef4-ba11b4156287@fv1g2000vbb.googlegroups.com> Message-ID: <44817c9a-647b-4bed-9162-faf0fb5313bc@f20g2000yqi.googlegroups.com> Hi Chris Thanks for your hint. I am reading this http://www.amk.ca/python/writing/functional Do you have good links or books to me learn "Functional Programming"? but I am not asking "...because is easy but because is hard." Show me, please! if you can. Thanks is advance. Best regards macm On 4 nov, 16:53, Chris Rebert wrote: > On Thu, Nov 4, 2010 at 11:48 AM, macm wrote: > > Hi Folks > > > How convert list to nested dictionary? > > >>>> l > > ['k1', 'k2', 'k3', 'k4', 'k5'] > >>>> result > > {'k1': {'k2': {'k3': {'k4': {'k5': {}}}}}} > > We don't do homework. > Hint: Iterate through the list in reverse order, building up your > result. Using reduce() is one option. > > Cheers, > Chris From arnodel at gmail.com Thu Nov 4 17:20:04 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Thu, 04 Nov 2010 21:20:04 +0000 Subject: How find all childrens values of a nested dictionary, fast! References: Message-ID: <87d3qkkcqj.fsf@gmail.com> macm writes: > Hi Folks > > How find all childrens values of a nested dictionary, fast! > >>>> a = {'a' : {'b' :{'/' :[1,2,3,4], 'ba' :{'/' :[41,42,44]} ,'bc' :{'/':[51,52,54], 'bcd' :{'/':[68,69,66]}}},'c' :{'/' :[5,6,7,8]}}, 'ab' : {'/' :[12,13,14,15]}, 'ac' :{'/' :[21,22,23]}} >>>> a['a'] > {'c': {'/': [5, 6, 7, 8]}, 'b': {'ba': {'/': [41, 42, 44]}, '/': [1, > 2, 3, 4], 'bc': {'bcd': {'/': [68, 69, 66]}, '/': [51, 52, 54]}}} >>>> a['a']['b'] > {'ba': {'/': [41, 42, 44]}, '/': [1, 2, 3, 4], 'bc': {'bcd': {'/': > [68, 69, 66]}, '/': [51, 52, 54]}} >>>> a['a']['b'].values() > [{'/': [41, 42, 44]}, [1, 2, 3, 4], {'bcd': {'/': [68, 69, 66]}, '/': > [51, 52, 54]}] > > Now I want find all values of key "/" > > Desire result is [41, 42, 44, 1, 2, 3, 4, 68, 69, 66, 51, 52, 54] > > I am trying map, reduce, lambda. Tough requirement, but I think I've got it. Two lambdas, one reduce, one map ;) >>> a = {'a' : {'b' :{'/' :[1,2,3,4], 'ba' :{'/' :[41,42,44]}, 'bc' :{'/':[51,52,54], 'bcd' :{'/':[68,69,66]}}},'c' :{'/' :[5,6,7,8]}},'ab' : {'/' :[12,13,14,15]}, 'ac' :{'/' :[21,22,23]}} >>> f = lambda v,k=None: v if k=="/" else reduce(list.__add__, map(lambda k: f(v[k],k), v), []) >>> f(a) [5, 6, 7, 8, 41, 42, 44, 1, 2, 3, 4, 68, 69, 66, 51, 52, 54, 21, 22, 23, 12, 13, 14, 15] This doesn't correspond with your desire result though. -- Arnaud From usernet at ilthio.net Thu Nov 4 17:26:00 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 4 Nov 2010 21:26:00 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <87mxpp3u3i.fsf.mdw@metalzone.distorted.org.uk> <87aalp3oyi.fsf.mdw@metalzone.distorted.org.uk> <87tyjw3kjg.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On 2010-11-04, Mark Wooding wrote: > Tim Harig writes: > >> I use simple comments that are not effected by white space. I don't >> waste my time trying to make comments look artistic. They are there >> to convey information; not to look pretty. I really detest having to >> edit other peoples comment formatting where you have to re-align >> everything if the length of any of comment lines change. > > I view source code as primarily a means of communication with human > readers, and only secondarily as being machine readable. I therefore > think it's worth the effort to make source code readily legible, for > example by making effective use of horizontal and vertical whitespace. > A long time ago, I spent a little while studying graphic design, so I > try to keep an eye on this sort of thing. I agree that it should be clean, ledgible, and easy to parse; but, I can that I can achieve this without making too many assumptions about whitespace. Think of it like the way HTML is *supposed* to work. Ideally, the web designer should stipulate the basic layout of the page; but, details such as how wide the display is are better left to the browser to figure out based on the actual conditions that it needs to display the page. > I'm interested in line length for two reasons: firstly, because I > believe that there's an optimum line length for easy and rapid reading, > which is probably a bit less than 80 columns; and secondly because I > find that I make more effective use of the available space on my screen > if I have several narrow columns rather than a few wide ones -- since > most lines in source files are short, a wide column ends up being mostly > empty on the right hand side, which is wasteful. Don't get me wrong, I am not arguing against the eighty column stylistic limit. I totally agree with it within reason. What I am arguing for is choice on how the code is displayed -- not how it is actually written. By using tabs, I can choose the trade-offs myself when reading the code rather then being confined to how the writer made their decision to view it. Assuming that I have sufficient screen space, I might choose a wider indent even though it might make the document wider then 80 columns *when viewed*. Other times, I may resign to view at the shorter column width so that it fits in my window without side scrolling. Either way, its my choice; and, when I am finished editing the file, even if it exceeds 80 columns at my chosen column width, the file will not exceed 80 columns, at the origional column width, in the actual source as it is *written*. Adjusting tab stops is merely for my viewing pleasure and it gives everybody the choice to view it their way without effecting the code. That is why I prefer tabs. From steve at holdenweb.com Thu Nov 4 17:29:19 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 04 Nov 2010 17:29:19 -0400 Subject: using google app through python In-Reply-To: References: Message-ID: On 11/1/2010 5:05 AM, charu gangal wrote: > Hey! Can anyone help me with python script for reading google > spreadsheets? what all packages do i need to import to make the code > run successfully after deploying it on google environment..thnx in > advance I've found the xlrd module very usable. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From brf256 at gmail.com Thu Nov 4 17:30:40 2010 From: brf256 at gmail.com (braden faulkner) Date: Thu, 4 Nov 2010 17:30:40 -0400 Subject: Best method for a menu in a command line program? In-Reply-To: References: <87wrotfhj2.fsf@benfinney.id.au> Message-ID: Sorry, I wasn't aware it was doing that but... I've removed it :-) Sorry about that, Braden Faulkner From clp2 at rebertia.com Thu Nov 4 17:32:59 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 4 Nov 2010 14:32:59 -0700 Subject: How convert list to nested dictionary? In-Reply-To: <44817c9a-647b-4bed-9162-faf0fb5313bc@f20g2000yqi.googlegroups.com> References: <940876cd-2546-4673-aef4-ba11b4156287@fv1g2000vbb.googlegroups.com> <44817c9a-647b-4bed-9162-faf0fb5313bc@f20g2000yqi.googlegroups.com> Message-ID: > On 4 nov, 16:53, Chris Rebert wrote: >> On Thu, Nov 4, 2010 at 11:48 AM, macm wrote: >> > Hi Folks >> >> > How convert list to nested dictionary? >> >> >>>> l >> > ['k1', 'k2', 'k3', 'k4', 'k5'] >> >>>> result >> > {'k1': {'k2': {'k3': {'k4': {'k5': {}}}}}} >> >> We don't do homework. >> Hint: Iterate through the list in reverse order, building up your >> result. Using reduce() is one option. On Thu, Nov 4, 2010 at 2:10 PM, macm wrote: > Thanks for your hint. > Do you have good links or books to me learn "Functional Programming"? Relevant to the particular problem you posed: http://en.wikipedia.org/wiki/Fold_(higher-order_function) > Show me, please! if you can. I will give you this further hint: def reducer(accumulator, elem): # if accumulator = {'k5': {} } # and elem = 'k4' # then we want to return {'k4': {'k5': {} } } now_implement_me() l = ['k1', 'k2', 'k3', 'k4', 'k5'] result = reduce(reducer, reversed(l), {}) Note that: reduce(reducer, reversed(l), {}) Is basically equivalent to: reducer( reducer( reducer( reducer( reducer({}, 'k5'), 'k4'), 'k3'), 'k2'), 'k1') Cheers, Chris -- http://blog.rebertia.com From arnodel at gmail.com Thu Nov 4 17:38:02 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Thu, 04 Nov 2010 21:38:02 +0000 Subject: How convert list to nested dictionary? References: <940876cd-2546-4673-aef4-ba11b4156287@fv1g2000vbb.googlegroups.com> Message-ID: <878w18kbwl.fsf@gmail.com> macm writes: > Hi Folks > > How convert list to nested dictionary? > >>>> l > ['k1', 'k2', 'k3', 'k4', 'k5'] >>>> result > {'k1': {'k2': {'k3': {'k4': {'k5': {}}}}}} > > Regards > > macm reduce(lambda x,y: {y:x}, reversed(l), {}) -- Arnaud From usernet at ilthio.net Thu Nov 4 17:38:54 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 4 Nov 2010 21:38:54 +0000 (UTC) Subject: Man pages and info pages References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> <024ef21a-9ef9-48a6-8372-1d66895583c3@v16g2000yqn.googlegroups.com> <87zktr5yze.fsf_-_@mithlond.arda> <877hgv2fg3.fsf@mithlond.arda> <8762wc526v.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On 2010-11-04, Mark Wooding wrote: > Tim Harig writes: > >> When the GNU folk decided to clone *nix they decided that they knew >> better and simply decided to create their own interfaces. > > This isn't the case. Actually Info has a long history prior to GNU: it > was the way that the documentation was presented at the MIT AI lab. In > fact, Info was used rather like a modern wiki. The operating system > they used, called ITS, didn't have a concept of file permissions, and > users were encouraged to improve documentation (and programs). The > original Info viewer was implemented in Emacs (which also originated in > ITS, years before GNU). I was aware of Emacs history. I was not aware that info actually dated all the way back to ITS. In retrospect, Stallman might have done better cloning ITS as that seems to have been what he wanted to do anyway. I suppose that Emacs is basically just an ITS lookalike shell for making *nix systems look like ITS. Coming from a *nix background and not being an Emacs users, I prefer the traditional *nix methods. > documenting large software systems like Emacs and GCC, it doesn't seem > unreasonable to provide manuals which are somewhat more discursive and > leisurely than traditional Unix manpages. I have a printed copy of the > GNU Emacs 18 manual (from 1987): it's almost 300 pages long. The modern > manual for Emacs 23 is several /times/ larger than this. Man pages > don't scale that well. Actually, they are capable of the same scalability. I would suggest that you read the ncurses man pages as they are displayed by pinfo. The man page links to other man pages that are organized by functionality in the same kind of tree organization that is used for (text)info pages. >> Actually, the left arrow key does not work at all intuitively. One >> would expect that it should go back to the previous page as it would >> in lynx, etc. It does not. > > It moves the cursor so you can hit links. The l key takes you back > through your recent viewing history -- and has done for thirty years. As I said, that is probably intuitive for Emacs users; but, not all *nix users are Emacs users. To those of us that are not, the info interface seems quite alien. >> By tradition 'n' and 'p' are broken for scrolling in a page. 'b' is >> often used in place of p but that seems to take one back to the top of >> the page. > > Space and backspace are an older tradition. Right, and in info with the default key bindings, backspace takes me to the command help. I would have expected it to either scroll up the page or take me to the previously visited node. >> The s key for a search is another example that has already been >> discussed. > > I find C-s more useful in Info, because it searches interactively. I > frequently get muddled when I try to search in `modern' programs like > web browsers, because they've gratuitously made C-s try to save the page > (something one hardly ever wants to do) rather than search. (Finding is > different: finding is what happens at the end of a /successful/ search. > So C-f is poorly chosen.) / is even more intiuitive yet, it works in more, it works in less, it works in vi, and it even works in firefox. From usernet at ilthio.net Thu Nov 4 17:47:59 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 4 Nov 2010 21:47:59 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> Message-ID: On 2010-11-04, Grant Edwards wrote: > On 2010-11-04, Seebs wrote: >> On 2010-11-04, D'Arcy J.M. Cain wrote: >>> Right. If you mangle spaces in Python or mangle braces in C then >>> recovery becomes impossible. I don't think anyone is contesting that. >>> What we question is the idea that somehow Python is special in this >>> regard. If you move files around in ways that change them then your >>> tools are broken. The fact that the breakage is somewhat "friendlier" >>> to some types of files is interesting but irrelevant. >> >> Again, why does "diff -b" exist? >> >> It exists because so many things change whitespace unintentionally that >> it's a common failure mode. > > It exists because so many people change whitespace intentionally in C > source code because no two C programmers seem able to agree on how to > format code. Diff -b allows you to attempt to ignore semantically > null stylistic changes made by programmers. I have seen huge patches caused by nothing more then some edit that accidently added a trailing space to a large number of lines. White space mangling happens all the time without people even knowing about it. From usenet-nospam at seebs.net Thu Nov 4 17:52:01 2010 From: usenet-nospam at seebs.net (Seebs) Date: 04 Nov 2010 21:52:01 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> Message-ID: On 2010-11-04, Grant Edwards wrote: > It exists because so many people change whitespace intentionally in C > source code because no two C programmers seem able to agree on how to > format code. Diff -b allows you to attempt to ignore semantically > null stylistic changes made by programmers. I don't agree with this interpretation, just because the changes it filters out are hardly ever intentional when I actually look at them. They're a mix of space/tab changes which don't affect actual indentation, trailing whitespace, and the like. The kinds of changes that would be made by C programmers trying to change source formatting are usually far beyond what "diff -b" would "fix". -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Thu Nov 4 17:54:56 2010 From: usenet-nospam at seebs.net (Seebs) Date: 04 Nov 2010 21:54:56 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-04, Terry Reedy wrote: > I am sorry you feel compelled to use a language you so dislike. Not our > fault though. I don't dislike it all that much. What I dislike is being told that the problems don't exist. > If you add the normally redundant information in the form of explicit > dedents (anything starting with '#' and distinguishable from normal > comments), then it is not too hard to re-indent even after all indents > have been removed. I believe this has been dome more than once. By using > a stylized comment, the augmented code runs without preprocessing. I > also believe at lease one person has written a preprocessor for > 'python-with-braces'. Yes. They did this because there is no reason that anyone would ever prefer it or find some benefit to it, of course. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From tjreedy at udel.edu Thu Nov 4 17:57:09 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 04 Nov 2010 17:57:09 -0400 Subject: Final state of underlying sequence in islice In-Reply-To: References: Message-ID: On 11/4/2010 12:42 PM, Shashank Singh wrote: > Are there any promises made with regard to final state of the underlying > sequence that islice slices? The one you quote below. > for example consider this > > >>> from itertools import * > >>> c = count() > >>> list(islice(c, 1, 3, 50)) > [1] > >>> c.next() > 51 When posting code and result, it is always a good idea to include version. It is even more important when reporting a (possible) bug, which might have been fixed already. As it turns out, I get the same behavior above and below with 3.1.2. > Now, the doc [1] says "If /stop/ is None, then iteration continues until > the iterator is exhausted, if at all; otherwise, it stops at the > specified position". With a step greater than 1, 'specified position' is ambiguous. Any stop value in [2,51] gives the same result. One could argue that the effective stop value is either last returned + step as above does, or last returned + 1 as Python version does. > It clearly is not stopping at stop (3). > > Further, the doc gives an example of how this is *equivalent* to a > generator defined in the same section. It turns out, these two are not > exactly the > same if the side-effect of the code is considered on the underlying > sequence. > > Redefining islice using the generator function defined in the doc gives > different (and from one pov, expected) result > >>> def islice(iterable, *args): > ... # islice('ABCDEFG', 2) --> A B > ... > >>> c = count() > >>> list(islice(c, 1, 3, 50)) > [1] > >>> c.next() > 2 > > While "fixing" this should be rather easy in terms of the change in code > required it might break any code depending > on this seemingly incorrect behavior. > > [1]. http://docs.python.org/library/itertools.html#itertools.islice If you file a bug report, please give the link. If you do not want to, say so and I will. -- Terry Jan Reedy From brandon.harris at reelfx.com Thu Nov 4 18:13:09 2010 From: brandon.harris at reelfx.com (Brandon Harris) Date: Thu, 04 Nov 2010 17:13:09 -0500 Subject: Passing File Objects into Subprocess.Popen Message-ID: <4CD32FF5.5090101@reelfx.com> I'm running python 2.5 and have bumped into an issue whereby the PIPE in subprocess.Popen locks up after taking too many characters. I found some documentation that discuss this problem and offers some ideas for solutions, the best one being to pass a file object into subprocess instead of PIPE. This will allow for much larger std output. http://thraxil.org/users/anders/posts/2008/03/13/Subprocess-Hanging-PIPE-is-your-enemy/ The problem is that, while I can pass in a tempfile.TemporaryFile() and everything seems to go swimmingly, there doesn't seem to be anything written to file I handed Popen. import tempfile import subprocess def awesome(): # I understand that not everyone has nuke, but it doesn't seem to matter what I run through it # the result is the same. my_cmd = '/usr/local/Nuke6.0v3/Nuke6.0 -V' my_stderr = tempfile.TemporaryFile() my_stdout = tempfile.TemporaryFile() process = subprocess.Popen(my_cmd, stderr=my_stderr, stdout=my_stdout) process.wait() print my_stderr.read() print my_stdout.read() print "Finished!!!" Any help on this issue would be awesome! thanks! Brandon L. Harris From mdw at distorted.org.uk Thu Nov 4 18:34:07 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 04 Nov 2010 22:34:07 +0000 Subject: functions, list, default parameters References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <20101021235138.609fe668@geekmail.INVALID> Message-ID: <87pquk3ehs.fsf.mdw@metalzone.distorted.org.uk> Lawrence D'Oliveiro writes: > In message <20101021235138.609fe668 at geekmail.INVALID>, Andreas > Waldenburger wrote: > > While not very commonly needed, why should a shared default argument be > > forbidden? > > Because it?s safer to disallow it than to allow it. Scissors with rounded ends are safer than scissors without. Chopsticks and plastic sporks are safer than metal cutlery. We have sharp things because they're /useful/. Similarly, having mutable objects as argument defaults can be useful. (Based on experience with other languages, I suspect that evaluating the default expression afresh for each call where it's needed would be more useful; but it's way too late to change that now.) -- [mdw] From solipsis at pitrou.net Thu Nov 4 18:39:54 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Thu, 4 Nov 2010 23:39:54 +0100 Subject: Passing File Objects into Subprocess.Popen References: <4CD32FF5.5090101@reelfx.com> Message-ID: <20101104233954.2e191e35@pitrou.net> On Thu, 04 Nov 2010 17:13:09 -0500 Brandon Harris wrote: > I'm running python 2.5 and have bumped into an issue whereby the PIPE > in subprocess.Popen locks up after taking too many characters. I found > some documentation that discuss this problem and offers some ideas for > solutions, the best one being to pass a file object into subprocess > instead of PIPE. This sounds rather unlikely. Have you used communicate()? > process = subprocess.Popen(my_cmd, stderr=my_stderr, stdout=my_stdout) > process.wait() > > print my_stderr.read() > print my_stdout.read() Try to rewind the file pointer before reading from it. Regards Antoine. From mdw at distorted.org.uk Thu Nov 4 18:42:00 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 04 Nov 2010 22:42:00 +0000 Subject: functions, list, default parameters References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <4cc13ef5$0$29979$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87lj583e4n.fsf.mdw@metalzone.distorted.org.uk> Lawrence D'Oliveiro writes: > Mediocre programmers with a hankering towards cleverness latch onto it > as an ingenious way of maintaing persistent context in-between calls > to a function, completely overlooking the fact that Python offers much > more straightforward, comprehensible, flexible, and above all > maintainable ways of doing that sort of thing. It does nowadays. Once upon a time, Python didn't have proper closures, and argument defaults, evaluated at function-definition time, were the only way of capturing data from the surrounding environment. You may be confusing `mediocre' with `old-fashioned', and `a hankering towards cleverness' with `wanting to run code on old Python interpreters'. This last may be because the relevant code was written back when those `old' interpreters were shiny and new. -- [mdw] From brandon.harris at reelfx.com Thu Nov 4 18:49:19 2010 From: brandon.harris at reelfx.com (Brandon Harris) Date: Thu, 04 Nov 2010 17:49:19 -0500 Subject: Passing File Objects into Subprocess.Popen In-Reply-To: <20101104233954.2e191e35@pitrou.net> References: <4CD32FF5.5090101@reelfx.com> <20101104233954.2e191e35@pitrou.net> Message-ID: <4CD3386F.4030902@reelfx.com> What do you mean by rewind the file pointer before reading from it? Seek back to the beginning? And It sounded very unlikely to me too, but it's the only thing I have found that explains why a very verbose job with tons of feedback locks up at the same point and won't process at all. I did try running communicate before and after the wait() but to no avail. Brandon L. Harris On 11/04/2010 05:39 PM, Antoine Pitrou wrote: > Try to rewind the file pointer before reading from it. From mdw at distorted.org.uk Thu Nov 4 18:51:47 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 04 Nov 2010 22:51:47 +0000 Subject: Man pages and info pages References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> <024ef21a-9ef9-48a6-8372-1d66895583c3@v16g2000yqn.googlegroups.com> <87zktr5yze.fsf_-_@mithlond.arda> <877hgv2fg3.fsf@mithlond.arda> <8762wc526v.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <87eib03doc.fsf.mdw@metalzone.distorted.org.uk> Tim Harig writes: > Right, and in info with the default key bindings, backspace takes me > to the command help. I would have expected it to either scroll up the > page or take me to the previously visited node. Sounds like your terminal is misconfigured. Backspace should produce ^?, not ^H. (Delete should produce some awful escape sequence.) -- [mdw] From brandon.harris at reelfx.com Thu Nov 4 18:57:28 2010 From: brandon.harris at reelfx.com (Brandon Harris) Date: Thu, 04 Nov 2010 17:57:28 -0500 Subject: Passing File Objects into Subprocess.Popen In-Reply-To: <4CD3386F.4030902@reelfx.com> References: <4CD32FF5.5090101@reelfx.com> <20101104233954.2e191e35@pitrou.net> <4CD3386F.4030902@reelfx.com> Message-ID: <4CD33A58.1090806@reelfx.com> ok. Jumping back to the start of the file solved the problem. (file.seek(0)) Big thanks for that insight! Brandon L. Harris On 11/04/2010 05:49 PM, Brandon Harris wrote: > What do you mean by rewind the file pointer before reading from it? > Seek back to the beginning? And It sounded very unlikely to me too, > but it's the only thing I have found that explains why a very verbose > job with tons of feedback locks up at the same point and won't process > at all. > > I did try running communicate before and after the wait() but to no > avail. > > Brandon L. Harris > > > On 11/04/2010 05:39 PM, Antoine Pitrou wrote: >> Try to rewind the file pointer before reading from it. > From nad at acm.org Thu Nov 4 19:08:18 2010 From: nad at acm.org (Ned Deily) Date: Thu, 04 Nov 2010 16:08:18 -0700 Subject: Compiling/Installing Python 2.7 on OSX 10.6 References: <3d9139ae-bd6f-4567-bb02-b21a8ba86e50@o15g2000prh.googlegroups.com> <238cec6d-2f47-4c97-8941-e28e6808946c@a9g2000pro.googlegroups.com> <6F087CE1-5391-4EE3-B92A-5A499FDF0E6C@semanchuk.com> Message-ID: In article <6F087CE1-5391-4EE3-B92A-5A499FDF0E6C at semanchuk.com>, Philip Semanchuk wrote: > You might want to try this before running tar to see if it inhibits the ._ > files: > export COPYFILE_DISABLE=True > > > I know that tells tar to ignore those files (resource forks, no?) when > building a tarball. I don't know if it helps with extraction though. Interesting. It's been so long since I've had to deal with ._ 's (which is where metadata for extended attributes including resource forks are stored), I had forgotten about that poorly documented option for 10.5 and 10.6. A little experiment: from OS X 10.6, I NFS-mount a remote Linux (ext3) file system and have created files on it with extended attributes. Using ls on either the OS X or the Linux side, the ._ files appear as regular files. On the Linux side, I use gnu tar to archive the files and move that archive back to OS X. If I then use the stock Apple 10.6 tar to extract that archive to an HFS+ directory, the extended attributes are by default restored properly (they can be viewed with ls -l@) and no '._' files - great! If I first export COPYFILE_DISABLE=True, then the tar extraction appears to ignore the ._ files: the extended attributes are not set and the ._ files still do not appear. So the COPYFILE_DISABLE trick may very well work for this issue. It still raises the question of why the ._ files are being created in the first place. They shouldn't be on the python.org tarball so it would seem most likely they are due to some operation on the OS X machine that causes extended attributes to be created. Nothing wrong with that, just kind of interesting. -- Ned Deily, nad at acm.org From ldo at geek-central.gen.new_zealand Thu Nov 4 19:43:00 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 05 Nov 2010 12:43 +1300 Subject: subprocess.Popen not replacing current process? References: <0f1a17f4-b6a9-4e89-ac26-74b1098a065e@b19g2000prj.googlegroups.com> Message-ID: In message <0f1a17f4-b6a9-4e89-ac26-74b1098a065e at b19g2000prj.googlegroups.com>, goodman wrote: > Hi, I'm wondering why subprocess.Popen does not seem to replace the > current process, even when it uses os.execvp (according to the > documentation: > http://docs.python.org/library/subprocess.html#subprocess.Popen). You?ll notice that in the list at the top of the functions that subprocess replaces, there are no os.exec* entries. subprocess is only for spawning new processes; if all you need to do is an exec, do an exec ; subprocess can?t offer anything to make that any simpler. From goodman.m.w at gmail.com Thu Nov 4 19:48:25 2010 From: goodman.m.w at gmail.com (goodman) Date: Thu, 4 Nov 2010 16:48:25 -0700 (PDT) Subject: subprocess.Popen not replacing current process? References: <0f1a17f4-b6a9-4e89-ac26-74b1098a065e@b19g2000prj.googlegroups.com> Message-ID: On Nov 4, 1:22?am, goodman wrote: > Note: Our server is a Linux machine, but we're restricted to Python > 2.4. > > Hi, I'm wondering why subprocess.Popen does not seem to replace the > current process, even when it uses os.execvp (according to the > documentation:http://docs.python.org/library/subprocess.html#subprocess.Popen). > Specifically, when I try to kill a spawned process with Ctrl-C, the > SIGINT does not seem to be sent to the spawned process. > > Some background: I have a Python script that calls shell scripts or > commands. It does not need to regain control after calling these > scripts or commands, so up to now I've been using an os.exec* command. > It seems the subprocess module is the recommended way for spawning > processes, but in this case perhaps it's better I stick with os.exec*? > I've seen plenty of discussion about catching KeyboardInterrupt in the > parent process and then manually killing the child, but (1) I can't > use Popen.kill() on Python 2.4, and (2) this level of process > management seems like overkill (pardon the potential for puns) in my > case. > > Thanks for any help. Following up, I can get the effect I want with the following: try: p = subprocess.Popen([cmd, arg1, arg2]) p.wait() except KeyboardInterrupt: import signal os.kill(p.pid, signal.SIGKILL) ...but like I said, I don't think I should be managing this myself, since I don't need to return from the new process. How can I make the new process handle its own signals? From ben+python at benfinney.id.au Thu Nov 4 19:51:26 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 05 Nov 2010 10:51:26 +1100 Subject: Best method for a menu in a command line program? References: Message-ID: <87sjzgfy0x.fsf@benfinney.id.au> Terry Reedy writes: > Others have answered that, but I would point to the inefficiency for > users of having to enter unit and value on two separate lines. The > prompt could be "Enter value and unit (f, c, or k) or q to quit: " > Allow upper and lower case, with or without a space between. Well, if we're going to critique the design, I'd say that I find the GNU Units program to be a good flexible implementation of a command-line units converter. I suspect, though, that the object of the OP was not so much to make a good unit converter, but rather to learn from a simple example exercise. -- \ ?I am too firm in my consciousness of the marvelous to be ever | `\ fascinated by the mere supernatural ?? ?Joseph Conrad, _The | _o__) Shadow-Line_ | Ben Finney From ben+python at benfinney.id.au Thu Nov 4 19:52:19 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 05 Nov 2010 10:52:19 +1100 Subject: Best method for a menu in a command line program? References: <87wrotfhj2.fsf@benfinney.id.au> Message-ID: <87oca4fxzg.fsf@benfinney.id.au> braden faulkner writes: > Sorry, I wasn't aware it was doing that but... I've removed it :-) Thank you, it's good to keep a polite discourse going :-) -- \ ?I don't accept the currently fashionable assertion that any | `\ view is automatically as worthy of respect as any equal and | _o__) opposite view.? ?Douglas Adams | Ben Finney From goodman.m.w at gmail.com Thu Nov 4 19:53:03 2010 From: goodman.m.w at gmail.com (goodman) Date: Thu, 4 Nov 2010 16:53:03 -0700 (PDT) Subject: subprocess.Popen not replacing current process? References: <0f1a17f4-b6a9-4e89-ac26-74b1098a065e@b19g2000prj.googlegroups.com> Message-ID: <7c5be6d7-5782-44ad-aae7-7f7bbc798d43@n32g2000prc.googlegroups.com> On Nov 4, 4:43?pm, Lawrence D'Oliveiro wrote: > In message > <0f1a17f4-b6a9-4e89-ac26-74b1098a0... at b19g2000prj.googlegroups.com>, goodman > wrote: > > > Hi, I'm wondering why subprocess.Popen does not seem to replace the > > current process, even when it uses os.execvp (according to the > > documentation: > >http://docs.python.org/library/subprocess.html#subprocess.Popen). > > You?ll notice that in the list at the top of the functions that subprocess > replaces, there are no os.exec* entries. subprocess is only for spawning new > processes; if all you need to do is an exec, do an exec > ; subprocess > can?t offer anything to make that any simpler. Thanks Lawrence. Forgive my recent followup, as I posted it before I saw your message. I noticed that the exec*s were not replaced by subprocess, so that makes sense to just use exec. Though I'm still a little confused how, if subprocess.Popen is using os.execvp, it still maintains control of things like interrupts. Anyway, my problem is solved. Thanks! From ben+python at benfinney.id.au Thu Nov 4 19:58:45 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 05 Nov 2010 10:58:45 +1100 Subject: Man pages and info pages References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> <024ef21a-9ef9-48a6-8372-1d66895583c3@v16g2000yqn.googlegroups.com> <87zktr5yze.fsf_-_@mithlond.arda> <877hgv2fg3.fsf@mithlond.arda> <8762wc526v.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <87hbfwfxoq.fsf@benfinney.id.au> Tim Harig writes: > On 2010-11-04, Mark Wooding wrote: > > Tim Harig writes: > >> Actually, the left arrow key does not work at all intuitively. One > >> would expect that it should go back to the previous page as it > >> would in lynx, etc. It does not. > > > > It moves the cursor so you can hit links. The l key takes you back > > through your recent viewing history -- and has done for thirty years. > > As I said, that is probably intuitive for Emacs users; but, not all > *nix users are Emacs users. To those of us that are not, the info > interface seems quite alien. You might make more headway in this discussion if you avoided conflating ?intuitive? (no computer UI is intuitive) with ?familiar? (which is relative to each user). As has been noted before, there is no intuitive interface except the nipple. Everything else is not intuitive, but must be learned. -- \ ?Facts are meaningless. You could use facts to prove anything | `\ that's even remotely true!? ?Homer, _The Simpsons_ | _o__) | Ben Finney From lists at cheimes.de Thu Nov 4 19:59:21 2010 From: lists at cheimes.de (Christian Heimes) Date: Fri, 05 Nov 2010 00:59:21 +0100 Subject: Passing File Objects into Subprocess.Popen In-Reply-To: <4CD3386F.4030902@reelfx.com> References: <4CD32FF5.5090101@reelfx.com> <20101104233954.2e191e35@pitrou.net> <4CD3386F.4030902@reelfx.com> Message-ID: Am 04.11.2010 23:49, schrieb Brandon Harris: > What do you mean by rewind the file pointer before reading from it? > Seek back to the beginning? And It sounded very unlikely to me too, but > it's the only thing I have found that explains why a very verbose job > with tons of feedback locks up at the same point and won't process at all. Look at a file handler like an old style magnetic tape. You just have recorded your favorite song from radio onto a tape. What do you have to do in order to listen to the song again? Press play? No, you have to rewind first. The MP3 generation will never understand the hard work of a mix tape created recorded from radio broadcasts. ;) Christian From contact at xavierho.com Thu Nov 4 20:22:26 2010 From: contact at xavierho.com (Xavier Ho) Date: Fri, 5 Nov 2010 10:22:26 +1000 Subject: C++ comment in Javadoc style -> reStructuredText compiler? Message-ID: Hey all, Apologies if I am posting this in the wrong list. Does anyone know of a good compiler for javadoc comment style into reStructuredText, for Sphinx to chew? Cheers, Xavier -------------- next part -------------- An HTML attachment was scrubbed... URL: From usernet at ilthio.net Thu Nov 4 21:21:43 2010 From: usernet at ilthio.net (Tim Harig) Date: Fri, 5 Nov 2010 01:21:43 +0000 (UTC) Subject: Man pages and info pages References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> <024ef21a-9ef9-48a6-8372-1d66895583c3@v16g2000yqn.googlegroups.com> <87zktr5yze.fsf_-_@mithlond.arda> <877hgv2fg3.fsf@mithlond.arda> <8762wc526v.fsf.mdw@metalzone.distorted.org.uk> <87hbfwfxoq.fsf@benfinney.id.au> Message-ID: On 2010-11-04, Ben Finney wrote: > As has been noted before, there is no intuitive interface except the > nipple. Everything else is not intuitive, but must be learned. What exactly is so intuitive about being slapped in the face followed by being slapped with a lawsuit? From jlconlin at gmail.com Thu Nov 4 21:37:47 2010 From: jlconlin at gmail.com (Jeremy) Date: Thu, 4 Nov 2010 18:37:47 -0700 (PDT) Subject: Compiling/Installing Python 2.7 on OSX 10.6 References: <3d9139ae-bd6f-4567-bb02-b21a8ba86e50@o15g2000prh.googlegroups.com> <238cec6d-2f47-4c97-8941-e28e6808946c@a9g2000pro.googlegroups.com> <6F087CE1-5391-4EE3-B92A-5A499FDF0E6C@semanchuk.com> Message-ID: <64cfb3eb-7cc3-46bf-b511-ade07d780c9d@w30g2000prj.googlegroups.com> On Nov 4, 5:08?pm, Ned Deily wrote: > In article <6F087CE1-5391-4EE3-B92A-5A499FDF0... at semanchuk.com>, > ?Philip Semanchuk wrote: > > > You might want to try this before running tar to see if it inhibits the ._ > > files: > > export COPYFILE_DISABLE=True > > > I know that tells tar to ignore those files (resource forks, no?) when > > building a tarball. I don't know if it helps with extraction though. > > Interesting. ?It's been so long since I've had to deal with ._ 's (which > is where metadata for extended attributes including resource forks are > stored), I had forgotten about that poorly documented option for 10.5 > and 10.6. > > A little experiment: from OS X 10.6, I NFS-mount a remote Linux (ext3) > file system and have created files on it with extended attributes. ? > Using ls on either the OS X or the Linux side, the ._ files appear as > regular files. ?On the Linux side, ?I use gnu tar to archive the files > and move that archive back to OS X. ?If I then use the stock Apple 10.6 > tar to extract that archive to an HFS+ directory, the extended > attributes are by default restored properly (they can be viewed with ls > -l@) and no '._' files - great! ?If I first export > COPYFILE_DISABLE=True, then the tar extraction appears to ignore the ._ > files: the extended attributes are not set and the ._ files still do not > appear. > > So the COPYFILE_DISABLE trick may very well work for this issue. ?It > still raises the question of why the ._ files are being created in the > first place. ?They shouldn't be on the python.org tarball so it would > seem most likely they are due to some operation on the OS X machine that > causes extended attributes to be created. ?Nothing wrong with that, just > kind of interesting. > > -- > ?Ned Deily, > ?n... at acm.org What I have done is perform the installation on a local hard drive (not network storage). This prevents any ._* files from being created. Now I just have to copy the installation to ~/Library/ Frameworks or just link to the local copy. I started the compilation when I left, tomorrow I'll finish up and see how it went. I don't anticipate any more problems. Thanks, Jeremy From ldo at geek-central.gen.new_zealand Thu Nov 4 21:54:55 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 05 Nov 2010 14:54:55 +1300 Subject: subprocess.Popen not replacing current process? References: <0f1a17f4-b6a9-4e89-ac26-74b1098a065e@b19g2000prj.googlegroups.com> <7c5be6d7-5782-44ad-aae7-7f7bbc798d43@n32g2000prc.googlegroups.com> Message-ID: In message <7c5be6d7-5782-44ad-aae7-7f7bbc798d43 at n32g2000prc.googlegroups.com>, goodman wrote: > Though I'm still a little confused how, if subprocess.Popen is using > os.execvp, it still maintains control of things like interrupts. The implied point, being that we are spawning subprocesses, is that there is a fork call before the exec. > Anyway, my problem is solved. Thanks! Glad to hear it. From rustompmody at gmail.com Thu Nov 4 22:47:02 2010 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 5 Nov 2010 08:17:02 +0530 Subject: Compare source code Message-ID: The real issue is not tabs/spaces vs braces but academic/scientific orientation vs engineering/commercial needs. Mostly these worlds are so far separated that no dialogue happens -- think C vs Pascal, Java vs Eiffel etc The problem -- actually advantage -- is that Python straddles both worlds. Mailers messing code, even editors messing (large) refactorings are engineering concerns. The visual clarity of (usually small) pieces of code is an academic concern. Ive been in both worlds: being able to have a significant piece of code projected on a single screen is often the single biggest factor which makes something teachable or not. And indentation based structure is not the only thing that aids this in languages like python and haskell -- think of comprehensions, no type declarations, REPL removing the need for (most) print statements etc etc. Conversely there are 'real-world' situations where python's indentation breaks things -- eg python-server-pages where python's indentation mixes badly with html's As far as I am concerned python would not be python if its indentation=structure went. However the original question -- mixing tabs and spaces is bad -- has got lost in the flames. Do the most die-hard python fanboys deny this? And if not is it asking too much (say in python3) that mixing tabs and spaces be flagged as an error or at least warning? From tjreedy at udel.edu Thu Nov 4 23:15:13 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 04 Nov 2010 23:15:13 -0400 Subject: Best method for a menu in a command line program? In-Reply-To: <87sjzgfy0x.fsf@benfinney.id.au> References: <87sjzgfy0x.fsf@benfinney.id.au> Message-ID: On 11/4/2010 7:51 PM, Ben Finney wrote: > Terry Reedy writes: > >> Others have answered that, but I would point to the inefficiency for >> users of having to enter unit and value on two separate lines. The >> prompt could be "Enter value and unit (f, c, or k) or q to quit: " >> Allow upper and lower case, with or without a space between. > > Well, if we're going to critique the design, I'd say that I find the GNU > Units program to be a > good flexible implementation of a command-line units converter. > > I suspect, though, that the object of the OP was not so much to make a > good unit converter, but rather to learn from a simple example exercise. Right. I think he would learn something from the exercize I suggest. -- Terry Jan Reedy From tjreedy at udel.edu Thu Nov 4 23:25:42 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 04 Nov 2010 23:25:42 -0400 Subject: Compare source code In-Reply-To: References: Message-ID: On 11/4/2010 10:47 PM, Rustom Mody wrote: > As far as I am concerned python would not be python if its > indentation=structure went. However the original question -- mixing > tabs and spaces is bad -- has got lost in the flames. Do the most > die-hard python fanboys deny this? Of course not. Not mixing tabs and spaces has been the recommendation for perhaps a decade. > And if not is it asking too much (say in python3) that mixing tabs and spaces > be flagged as an error or at least warning? Making all mixture an error was considered but rejected as causing too much gratuitous breakage. One reason: you cut code from some source with the 'other' style and paste into code with 'your' style. Should you be *forced* (rather than merely advised) to convert before running the result even once. Guido decided that there was enough breakage from important things like unicode text and all new-style classes. On the other hand, someone said that ambiguous mixtures now are prohibited. -- Terry Jan Reedy From rantingrick at gmail.com Fri Nov 5 01:03:36 2010 From: rantingrick at gmail.com (rantingrick) Date: Thu, 4 Nov 2010 22:03:36 -0700 (PDT) Subject: Compare source code References: Message-ID: <7ed584f8-a0c6-4972-8d0f-c847512eba55@s9g2000vby.googlegroups.com> On Nov 4, 9:47?pm, Rustom Mody wrote: > However the original question -- mixing > tabs and spaces is bad -- has got lost in the flames. ?Do the most > die-hard python fanboys deny this? Hey we need to get something strait right now... i am the only true fanboy around here, all the others are puesdo fanboys. Got it! ;-) From hdc1112 at gmail.com Fri Nov 5 02:46:37 2010 From: hdc1112 at gmail.com (dachuan) Date: Fri, 5 Nov 2010 14:46:37 +0800 Subject: Hello, Everyone. I have a problem when using Pexpect module. Message-ID: hi, everyone. When I use Pexpect Module, I met the following problem and don't know how to handle it. Any advice is appreciated ! My environment: Linux node08_xen3.4.3_rhel5_1 2.6.18.8-xen #1 SMP Wed Jul 14 17:20:01 CST 2010 i686 i686 i386 GNU/Linux (FYI: this is a virtual machine.) Python 2.5.5 and by the way, I have installed pexpect in another machine, and it works pretty well, its environment is: Linux WEB1 2.6.9-42.ELlargesmp #1 SMP Wed Jul 12 23:46:39 EDT 2006 x86_64 x86_64 x86_64 GNU/Linux Python 2.5.5 -bash-3.1$ ./ssh_mutual_trust.py -n Traceback (most recent call last): File "./ssh_mutual_trust.py", line 427, in start(sys.argv[1:]) File "./ssh_mutual_trust.py", line 405, in start sshkeygen() File "./ssh_mutual_trust.py", line 137, in sshkeygen keygen_child = pexpect.spawn(new_keygen_cmd) File "/usr/local/lib/python2.5/site-packages/pexpect.py", line 430, in __init__ self._spawn (command, args) File "/usr/local/lib/python2.5/site-packages/pexpect.py", line 530, in _spawn raise ExceptionPexpect('Error! pty.fork() failed: ' + str(e)) pexpect.ExceptionPexpect: Error! pty.fork() failed: out of pty devices -bash-3.1$ -- Dachuan Huang, Graduate Candidate ----------------------------------------------------------- Cluster and Grid Computing Lab Services Computing Technology and System Lab Huazhong University of Science and Technology Wuhan, 430074, China Tel: +86-15902733227 Email: hdc1112 at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From rustompmody at gmail.com Fri Nov 5 03:20:09 2010 From: rustompmody at gmail.com (rustom) Date: Fri, 5 Nov 2010 00:20:09 -0700 (PDT) Subject: Compare source code References: Message-ID: On Nov 5, 8:25?am, Terry Reedy wrote: > On 11/4/2010 10:47 PM, Rustom Mody wrote: > > > As far as I am concerned python would not be python if its > > indentation=structure went. ?However the original question -- mixing > > tabs and spaces is bad -- has got lost in the flames. ?Do the most > > die-hard python fanboys deny this? > > Of course not. Not mixing tabs and spaces has been the recommendation > for perhaps a decade. > > > And if not is it asking too much (say in python3) that mixing tabs and spaces > > ?> be flagged as an error or at least warning? > > Making all mixture an error was considered but rejected as causing too > much gratuitous breakage. One reason: you cut code from some source with > the 'other' style and paste into code with 'your' style. Should you be > *forced* (rather than merely advised) to convert before running the > result even once. Guido decided that there was enough breakage from > important things like unicode text and all new-style classes. That means that obvious and easily repairable-with-trivial-tools breakage is being traded for more insidious breakage > > On the other hand, someone said that ambiguous mixtures now are prohibited. > Not sure I understand the issues here. From python at rcn.com Fri Nov 5 04:58:10 2010 From: python at rcn.com (Raymond Hettinger) Date: Fri, 5 Nov 2010 01:58:10 -0700 (PDT) Subject: Final state of underlying sequence in islice References: Message-ID: <4b599f9b-5d99-4a9a-85a8-4ccba233bdc4@35g2000prb.googlegroups.com> > ?Shashank Singh wrote: > > > Are there any promises made with regard to final state of the underlying > > sequence that islice slices? Currently, there are no promises or guarantees about the final state of the iterator. To the extent the pure Python version in the docs differs from the CPython implementation in this regard, it is an accidental implementation detail. That being said, we could introduce some guarantees (earliest possible stop point, latest possible stop point, or decide to leave it undefined). I'm curious about your use case, as it might guide the decision. Are there any useful invariants that might arise from one choice or the other? The case is question seems a bit rare (the stop argument indexes an element before the iterator terminates, the step argument is more than one, the stop argument is not at the start plus an exact multiple of step, and you care about where the iterator is afterwards). The question is why you would have all of those conditions and not have stop==start+n*step. For regular slices, you seem to get useful invariants only when stop falls along the natural boundaries: s[a:b:step] + s[b:c:step] == s[a:c:step] # only when b == a+n*step So, it's not obvious what the semantics should be when b != a+n*step. Raymond From steve at REMOVE-THIS-cybersource.com.au Fri Nov 5 04:58:19 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Nov 2010 08:58:19 GMT Subject: functions, list, default parameters References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <20101021235138.609fe668@geekmail.INVALID> <87pquk3ehs.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <4cd3c72b$0$30004$c3e8da3$5496439d@news.astraweb.com> On Thu, 04 Nov 2010 22:34:07 +0000, Mark Wooding wrote: > (Based on experience with other languages, I suspect that evaluating the > default expression afresh for each call where it's needed would be more > useful; but it's way too late to change that now.) Let's call the two strategies: defaults initialise on function definition (DID) defaults initialise on function call (DIC) I claim that when designing a general purpose language, DID (Python's existing behaviour) is better than DIC: (1) most function defaults only need to be set once; (2) it's easy to get DIC if the language uses DID, but hard the other way; (3) DIC is needless wasteful for common function definitions; (4) DIC can lead to surprising bugs. That last isn't a big concern, since DID can lead to surprising bugs as well *wink*, but it's worth mentioning the failure mode. #1 Most default values are things like True, False, None, integer or string literals. Since they're literals, they will never change, so you only need to set them once. #2 It's easy to get default values to initialise on function call in a language that uses initialisation on function definition semantics: just move the initialisation into the function body. Python has a particularly short and simple idiom for it: def f(x=None): if x is None: x = some_expression() But if the situations were reversed, it's hard to get the DID semantics: def f(x=None): if x is None: global _f_default_arg try: x = _f_default_arg except NameError: _f_default_arg = x = default_calculation() #3 Re-initialising default values is wasteful for many functions, perhaps the majority of them. (Of course, if you *need* DIC semantics, it isn't wasteful, but I'm talking about the situations where you don't care either way.) In current Python, nobody would write code like this: def f(x=None, y=None, z=None): if x is None: x = 1 if y is None: y = 2 if z is None: z = 3 but that's what the DIC semantics effectively does. When you need it, it's useful, but most of the time it's just a performance hit for no good reason. A smart compiler would factor out the assignment to a constant and do it once, when the function were defined -- which is just what DID semantics are. If you're unconvinced about this being a potential performance hit, consider: def expensive_function(): time.sleep(30) # simulate a lot of computation return 1.23456789 def f(x=expensive_function()): ... What would you prefer, the default value to be calculated once, or every time you called f()? #4 Just as DID leads to surprising behaviour with mutable defaults, so DIC can lead to surprising behaviour: def f(x=expression): do_something_with(x) If expression is anything except a literal, it could be changed after f is defined but before it is called. If so, then f() will change it's behaviour. -- Steven From hdc1112 at gmail.com Fri Nov 5 05:03:55 2010 From: hdc1112 at gmail.com (dachuan) Date: Fri, 5 Nov 2010 17:03:55 +0800 Subject: Hello, Everyone. I have a problem when using Pexpect module. In-Reply-To: References: Message-ID: maybe i found why pexpect doesn't work in my environment. (but still, i don't know how solve it) my machine is actually a xen domain U, whose kernel is host's kernel. when I test pexpect module directly on host machine, it works pretty fine. and that's all I can do about it, maybe pexpect use pseudo-terminal, and domain U doesn't support this well. maybe nobody here has encountered this problem before, and i write here just for everyone's information. On Fri, Nov 5, 2010 at 2:46 PM, dachuan wrote: > hi, everyone. > When I use Pexpect Module, I met the following problem and don't know how > to handle it. > Any advice is appreciated ! > > My environment: > Linux node08_xen3.4.3_rhel5_1 2.6.18.8-xen #1 SMP Wed Jul 14 17:20:01 CST > 2010 i686 i686 i386 GNU/Linux (FYI: this is a virtual machine.) > Python 2.5.5 > > and by the way, I have installed pexpect in another machine, and it works > pretty well, its environment is: > Linux WEB1 2.6.9-42.ELlargesmp #1 SMP Wed Jul 12 23:46:39 EDT 2006 x86_64 > x86_64 x86_64 GNU/Linux > Python 2.5.5 > > > -bash-3.1$ ./ssh_mutual_trust.py -n > Traceback (most recent call last): > File "./ssh_mutual_trust.py", line 427, in > start(sys.argv[1:]) > File "./ssh_mutual_trust.py", line 405, in start > sshkeygen() > File "./ssh_mutual_trust.py", line 137, in sshkeygen > keygen_child = pexpect.spawn(new_keygen_cmd) > File "/usr/local/lib/python2.5/site-packages/pexpect.py", line 430, in > __init__ > self._spawn (command, args) > File "/usr/local/lib/python2.5/site-packages/pexpect.py", line 530, in > _spawn > raise ExceptionPexpect('Error! pty.fork() failed: ' + str(e)) > pexpect.ExceptionPexpect: Error! pty.fork() failed: out of pty devices > -bash-3.1$ > > > -- > Dachuan Huang, Graduate Candidate > ----------------------------------------------------------- > Cluster and Grid Computing Lab > Services Computing Technology and System Lab > Huazhong University of Science and Technology > Wuhan, 430074, China > Tel: +86-15902733227 > > Email: hdc1112 at gmail.com > -- Dachuan Huang, Graduate Candidate ----------------------------------------------------------- Cluster and Grid Computing Lab Services Computing Technology and System Lab Huazhong University of Science and Technology Wuhan, 430074, China Tel: +86-15902733227 Email: hdc1112 at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From nospam at torek.net Fri Nov 5 06:03:07 2010 From: nospam at torek.net (Chris Torek) Date: 5 Nov 2010 10:03:07 GMT Subject: Popen Question References: <891a9a80-c30d-4415-ac81-bddd0b564fa6@g13g2000yqj.googlegroups.com> Message-ID: In article <891a9a80-c30d-4415-ac81-bddd0b564fa6 at g13g2000yqj.googlegroups.com> moogyd wrote: >[sde:staff at lbux03 ~]$ python >Python 2.6 (r26:66714, Feb 21 2009, 02:16:04) >[GCC 4.3.2 [gcc-4_3-branch revision 141291]] on linux2 >Type "help", "copyright", "credits" or "license" for more information. >>>> import os, subprocess >>>> os.environ['MYVAR'] = "myval" >>>> p = subprocess.Popen(['echo', '$MYVAR'],shell=True) Alain Ketterlin has already explained these to some extent. Here is a bit more. This runs, underneath: ['/bin/sh', '-c', 'echo', '$MYVAR'] (with arguments expressed as a Python list). /bin/sh takes the string after '-c' as a command, and the remaining argument(s) if any are assigned to positional parameters ($0, $1, etc). If you replace the command with something a little more explicit, you can see this: >>> p = subprocess.Popen( ... [r'echo \$0=$0 \$1=$1', 'arg0', '$MYVAR'], shell=True) >>> $0=arg0 $1=$MYVAR p.wait() 0 >>> (I like to call p.communicate() or p.wait(), although p.communicate() is pretty much a no-op if you have not done any redirecting. Note that p.communicate() does a p.wait() for you.) >>>> p = subprocess.Popen(['echo', '$MYVAR']) >>>> $MYVAR This time, as Alain noted, the shell does not get involved so no variable expansion occurs. However, you could do it yourself: >>> p = subprocess.Popen(['echo', os.environ['MYVAR']]) >>> myval p.wait() 0 >>> >>>> p = subprocess.Popen('echo $MYVAR',shell=True) >>>> myval (here /bin/sh does the expansion, because you invoked it) >>>> p = subprocess.Popen('echo $MYVAR') >Traceback (most recent call last): > File "", line 1, in > File "/usr/lib64/python2.6/subprocess.py", line 595, in __init__ > errread, errwrite) > File "/usr/lib64/python2.6/subprocess.py", line 1106, in >_execute_child > raise child_exception >OSError: [Errno 2] No such file or directory This attempted to run the executable named 'echo $MYVAR'. It did not exist so the underlying exec (after the fork) failed. The exception was passed back to the subprocess module, which raised it in the parent for you to see. If you were to create an executable named 'echo $MYVAR' (including the blank and dollar sign) somewhere in your path (or use an explicit path to it), it would run. I will also capture the actual output this time: $ cat '/tmp/echo $MYVAR' #! /usr/bin/awk NR>1{print} this is a self-printing file anything after the first line has NR > 1, so gets printed $ chmod +x '/tmp/echo $MYVAR' $ python Python 2.5.1 (r251:54863, Feb 6 2009, 19:02:12) [GCC 4.0.1 (Apple Inc. build 5465)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import subprocess >>> p = subprocess.Popen('/tmp/echo $MYVAR', stdout=subprocess.PIPE) >>> print p.communicate()[0] this is a self-printing file anything after the first line has NR > 1, so gets printed >>> p.returncode 0 >>> Incidentally, fun with #!: you can make self-renaming scripts: sh-3.2$ echo '#! /bin/mv' > /tmp/selfmove; chmod +x /tmp/selfmove sh-3.2$ ls /tmp/*move* /tmp/selfmove sh-3.2$ /tmp/selfmove /tmp/I_moved sh-3.2$ ls /tmp/*move* /tmp/I_moved sh-3.2$ or even self-removing scripts: sh-3.2$ echo '#! /bin/rm' > /tmp/rmme; chmod +x /tmp/rmme sh-3.2$ /tmp/rmme sh-3.2$ /tmp/rmme sh: /tmp/rmme: No such file or directory (nothing to do with python, just the way #! interpreter lines work). -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html From alain at dpt-info.u-strasbg.fr Fri Nov 5 06:21:57 2010 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Fri, 05 Nov 2010 11:21:57 +0100 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87mxpoax4q.fsf@dpt-info.u-strasbg.fr> Terry Reedy writes: > If you add the normally redundant information in the form of explicit > dedents (anything starting with '#' and distinguishable from normal > comments), then it is not too hard to re-indent even after all indents > have been removed. I actually use such a trick in emacs, not with comments but with "pass" (emacs' python mode knows that pass end return end the current block). It's extrememly useful in heavily nested code, or if I need to paste some piece of code from one level to another. This lets my editor's auto-indenter do the right thing. And I see immediately if/when I did the nesting wrong. I really like "indentation as structure" (code is more compact and clearer), but I really hate that it relies on me putting the right spaces at the right place. I would love to be able to put, e.g., a period at the end of a line, to indicate that the next line is one level upper. Something like: for i in ... : for j in ... : whatever(i,j). . No lost vertical space (except when I decide it), no ambiguity. It looks to me like the exact opposite of ':'. End-of-line periods (or exclamation marks) would let tools reindent correctly in all cases. I don't think it conflicts with any other syntax. -- Alain. From steve at REMOVE-THIS-cybersource.com.au Fri Nov 5 06:36:14 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Nov 2010 10:36:14 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <87mxpoax4q.fsf@dpt-info.u-strasbg.fr> Message-ID: <4cd3de1d$0$30004$c3e8da3$5496439d@news.astraweb.com> On Fri, 05 Nov 2010 11:21:57 +0100, Alain Ketterlin wrote: > I really like "indentation as structure" (code is more compact and > clearer), but I really hate that it relies on me putting the right > spaces at the right place. Er what? You really like indentation as structure, but you don't like putting in the indentation? > I would love to be able to put, e.g., a > period at the end of a line, to indicate that the next line is one level > upper. Something like: > > for i in ... : > for j in ... : > whatever(i,j). > . How is that different from this? for i in ... : for j in ... : whatever(i,j) What's the point of the dots? Is that just to save you from having to hit shift-tab (or whatever your editor's decrease-indent command is)? > No lost vertical space (except when I decide it), no ambiguity. What lost vertical space are you worried about? > It looks > to me like the exact opposite of ':'. End-of-line periods (or > exclamation marks) would let tools reindent correctly in all cases. I > don't think it conflicts with any other syntax. for i in ... : for j in ... : n = 2. -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Nov 5 06:37:05 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Nov 2010 10:37:05 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> Message-ID: <4cd3de51$0$30004$c3e8da3$5496439d@news.astraweb.com> On Thu, 04 Nov 2010 21:47:59 +0000, Tim Harig wrote: > I have seen huge patches caused by nothing more then some edit that > accidently added a trailing space to a large number of lines. White > space mangling happens all the time without people even knowing about > it. How does an edit accidentally add a trailing space to a large number of lines? (1) The programmer shifted the cursor to the end of the line, pressed space, moved down a line, shift to eol, press space, repeat a large number of times. I don't call that an "accident". (2) Some programmer used a tool that thought it was okay to add whitespace to the end of lines without being told to. I don't call that an accident either, I call that using a broken tool. So we keep coming back to work-arounds for tools that mangle your data for no good reason... -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Nov 5 06:41:40 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Nov 2010 10:41:40 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <87r5f13ug3.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <4cd3df64$0$30004$c3e8da3$5496439d@news.astraweb.com> On Thu, 04 Nov 2010 20:17:35 +0000, Seebs wrote: >> * I /do/ have a significant problem with cutting and pasting code in >> Python. In most languages, I can haul a chunk of code about, hit >> C-M-q, and Emacs magically indents the result properly. This is, >> unfortunately, impossible with Python. It has caused me real bugs, >> and I have to be extra careful to fix the indentation up. > > That was the thing which bit me the worst. I had a fairly large block > of code in a first-pass ugly program. I wanted to start refactoring it, > so I moved a big hunk of code into a method (with plans to further > refactor). It took about fifteen minutes to redo the logic. Well there's your problem -- you are relying on tools that operate by magic. Rather than re-create the logic, why not just hit Undo and then re-paste the code *without* the magic auto-reformat? Half a second, to undo and re- paste, followed by 10 or 20 seconds to select the appropriate lines and *explicitly* re-indent the lines to the correct level. For somebody who keeps tossing around the mantra that "explicit is better than implicit", you're amazingly reliant on a tool that performs massive, apparently irreversible formatting operations implicitly. And then rather than accept that your magic DWIM tool is unsuitable for the task you are putting it to, you then blame the data for not having error-correction codes that would allow *another* magic tool to fix the breakage caused by the first magic tool! -- Steven From sschwarzer at sschwarzer.net Fri Nov 5 07:34:35 2010 From: sschwarzer at sschwarzer.net (Stefan Schwarzer) Date: Fri, 05 Nov 2010 12:34:35 +0100 Subject: Tools for turning Python code into XMI? In-Reply-To: References: <4CC3FAD1.5080703@sschwarzer.net> Message-ID: <4CD3EBCB.8020206@sschwarzer.net> Hi Lawrence, I missed your answer because I didn't expect someone to respond after all this time. :-) On 2010-10-30 04:07, Lawrence D'Oliveiro wrote: >> I'm looking for a tool which can read Python files and write >> a corresponding XMI file for import into UML tools. > > UML ... isn?t that something more in vogue among the > Java/DotNet corporate-code-cutter-drone crowd? I don't know, that may well be. I still find it useful from time to time. I don't mind using tools I find useful, regardless who else uses them. :-) > Specifically, you?re asking for something that can parse a > dynamic language and generate a static structural > description of that code. I don?t think it?s possible, in > general. The tools I described in my previous post go a great length towards extracting the necessary information. But of course it's not reliably possible to extract all information, for example dynamically generated methods. But few Python programs use this extensively, and a good tool will extract most of the information interesting for me. I'm always surprised about what Pylint finds out about my source code. :) Given the existing open source tools, the problem rather seems to be the effort of implementing XMI generation than to get the information out of the Python code in the first place. Stefan From alain at dpt-info.u-strasbg.fr Fri Nov 5 07:36:44 2010 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Fri, 05 Nov 2010 12:36:44 +0100 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <87mxpoax4q.fsf@dpt-info.u-strasbg.fr> <4cd3de1d$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87sjzggfxv.fsf@dpt-info.u-strasbg.fr> Steven D'Aprano writes: >> I really like "indentation as structure" (code is more compact and >> clearer), but I really hate that it relies on me putting the right >> spaces at the right place. > > Er what? You really like indentation as structure, but you don't like > putting in the indentation? Exactly. I want the extra safety belt of not relying on spaces only. >> for i in ... : >> for j in ... : >> whatever(i,j). >> . > > How is that different from this? > > for i in ... : > for j in ... : > whatever(i,j) At this point exactly, there's no way to know what the indentation of the next line should be. My example above explicitely indicates the next line should be at the same level as "for j ...". Now suppose that, at this very place, you have to paste some other if/for/while block whose original indentation is not exactly aligned with the fragment above. No way to decide automatically how to align it (under "for j"? under "whatever"?). The dots I suggest are nothing more than tiny closing braces. > What's the point of the dots? Is that just to save you from having to hit > shift-tab (or whatever your editor's decrease-indent command is)? Redundancy. I often have deeply nested constructs, that I sometimes need to move around. A real pain, compared to brace-based languages, where constructs are explicitely terminated (i.e., not implicitely by the start of the next construct). Have automatically indented source is a useful and quick check. >> No lost vertical space (except when I decide it), no ambiguity. > > What lost vertical space are you worried about? You've cut the part of my message where I say that python's (vertical) compactness is one of its strong points. >> It looks to me like the exact opposite of ':'. End-of-line periods >> (or exclamation marks) would let tools reindent correctly in all >> cases. I don't think it conflicts with any other syntax. > for i in ... : > for j in ... : > n = 2. You're right, I forgot this one (probably because I never use this kind of elision). No big deal: for i in ... : for j in ... : n = 2. m = 3. . for j in ... : f = 2 . ... -- Alain. From mdw at distorted.org.uk Fri Nov 5 08:17:00 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Fri, 05 Nov 2010 12:17:00 +0000 Subject: functions, list, default parameters References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <20101021235138.609fe668@geekmail.INVALID> <87pquk3ehs.fsf.mdw@metalzone.distorted.org.uk> <4cd3c72b$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8739rg2ceb.fsf.mdw@metalzone.distorted.org.uk> Steven D'Aprano writes: > defaults initialise on function definition (DID) > defaults initialise on function call (DIC) > > I claim that when designing a general purpose language, DID (Python's > existing behaviour) is better than DIC: > > #1 Most default values are things like True, False, None, integer or > string literals. Since they're literals, they will never change, so you > only need to set them once. Right; so a half-decent compiler can notice this and optimize appropriately. Result: negligible difference. > #2 It's easy to get default values to initialise on function call in a > language that uses initialisation on function definition semantics: just > move the initialisation into the function body. Python has a particularly > short and simple idiom for it: > > def f(x=None): > if x is None: > x = some_expression() That's actually rather clumsy. Also, it's using in-band signalling: you've taken None and used it as a magic marker meaning `not supplied'. Suppose you want to distinguish /any/ supplied value from a missing argument: how do you do this /correctly/? The approaches I see are (a) to invent some unforgeable token or (b) emulate the argument processing by rifling through * and ** arguments. Solution (a) looks like this: _missing = ['missing'] def foo(arg = _missing): if arg is _missing: arg = ... ... But now _missing is kicking around in the module's namespace. Fixing that is rather messy. (No, you can't just `del' it.) Maybe this can be improved: def _magic(): _missing = ['missing'] def foo(arg = _missing): if arg is _missing: arg = ... ... return foo foo = _magic() del foo Solution (b) is just too grim. > But if the situations were reversed, it's hard to get the DID semantics: > > def f(x=None): > if x is None: > global _f_default_arg > try: > x = _f_default_arg > except NameError: > _f_default_arg = x = default_calculation() Ugh. This is artificially awful and doesn't correspond to existing Python DID semantics. * Python evaluates the default argument expression at function definition time. You've implemented delayed evaluation for no obvious reason. * Python evaluates the default argument expression in the enclosing environment. You've evaluated the expression in the function, again for no obvious reason. I'm interested to know why you did this. You know Python well enough that it's probably not just a misunderstanding, and you have enough integrity that it's probably not a dishonest debating tactic. A more faithful implementation of the actual semantics is considerably simpler. _default_arg = ... def func(arg = _default_arg): ... This is always correct, and actually simpler than even the standard but incorrect simulation of DIC. > #3 Re-initialising default values is wasteful for many functions, perhaps > the majority of them. (Of course, if you *need* DIC semantics, it isn't > wasteful, but I'm talking about the situations where you don't care > either way.) In current Python, nobody would write code like this: > > def f(x=None, y=None, z=None): > if x is None: x = 1 > if y is None: y = 2 > if z is None: z = 3 > > but that's what the DIC semantics effectively does. When you need it, > it's useful, but most of the time it's just a performance hit for no good > reason. A smart compiler would factor out the assignment to a constant > and do it once, when the function were defined -- which is just what DID > semantics are. Python's compiler is already clever enough to notice a constant expression when it sees one, and memoizing the default argument values is straightforward enough. There's therefore nothing to choose between the two on constant expressions. > If you're unconvinced about this being a potential performance hit, > consider: No, I can see that clearly, thanks. That comes up much less frequently than the case where a default argument value should be a fresh list or dictionary, in my experience. > What would you prefer, the default value to be calculated once, or every > time you called f()? This situation is rare enough that I'd put up with manual memoization. > #4 Just as DID leads to surprising behaviour with mutable defaults, so > DIC can lead to surprising behaviour: > > def f(x=expression): > do_something_with(x) > > If expression is anything except a literal, it could be changed after f > is defined but before it is called. If so, then f() will change it's > behaviour. Yes. Most usefully, the expression may refer to other argument values (to its left, only, presumably). This is frequently handy, not least in object constructors. This is an enormous sidetrack on what I'd hoped would be a parenthetical remark left unremarked. I'm not sure that further discussion will be especially interesting, unless others have experience (not speculation) of DIC semantics that they wish to share. For my part, I've used both and found DIC a winner -- [mdw] From gerlach_joerg at web.de Fri Nov 5 09:19:47 2010 From: gerlach_joerg at web.de (J. Gerlach) Date: Fri, 05 Nov 2010 14:19:47 +0100 Subject: Why "flat is better than nested"? In-Reply-To: <4cc8d49c$0$29982$c3e8da3$5496439d@news.astraweb.com> References: <4cc8d49c$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: Am 28.10.2010 03:40, schrieb Steven D'Aprano: > [ snip a lot of wise words ] Can I put this (translated) in the german python wiki? I guess it might help more people to understand some decisions taken during python's development - and I'm to lazy to do something similar myself ;) Greetings from Berlin J?rg Gerlach From ethan at stoneleaf.us Fri Nov 5 09:29:11 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 05 Nov 2010 06:29:11 -0700 Subject: Compare source code In-Reply-To: <20101104120209.GA16757@rcpc42.vub.ac.be> References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1495f$0$29966$c3e8da3$5496439d@news.astraweb.com> <20101104120209.GA16757@rcpc42.vub.ac.be> Message-ID: <4CD406A7.8040600@stoneleaf.us> Antoon Pardon wrote: > Unless, your code is split over different pages, as when it is printed in a book. > You also need to see the next piece of code to notice the dedention. > > e.g. I have the following code at the bottom of my editor. > > for i := 0 to 9 do > some(code); > more(code); > end; > > I can by just looking at this code notice that I'm looking at the whole for block. > > > But when I have similar python code at the bottom of the page. > > for i in xrange(10): > some(code) > more(code) > > Then I can't make out whether I'm looking at the whole for suite or not. These code pieces are not equivalent -- you have four lines of code in the first piece, only three lines in the python piece; in other words, if the "end;" were not on screen, you would still have no idea if it was the whole block or not; in still other words, the "end;", just like the dedented line, provides the context. ~Ethan~ From bborcic at gmail.com Fri Nov 5 09:42:59 2010 From: bborcic at gmail.com (Boris Borcic) Date: Fri, 05 Nov 2010 14:42:59 +0100 Subject: How convert list to nested dictionary? In-Reply-To: <878w18kbwl.fsf@gmail.com> References: <940876cd-2546-4673-aef4-ba11b4156287@fv1g2000vbb.googlegroups.com> <878w18kbwl.fsf@gmail.com> Message-ID: Arnaud Delobelle wrote: > macm writes: > >> Hi Folks >> >> How convert list to nested dictionary? >> >>>>> l >> ['k1', 'k2', 'k3', 'k4', 'k5'] >>>>> result >> {'k1': {'k2': {'k3': {'k4': {'k5': {}}}}}} >> >> Regards >> >> macm > > reduce(lambda x,y: {y:x}, reversed(l), {}) > d={} while L : d={L.pop():d} From msarro at gmail.com Fri Nov 5 09:43:25 2010 From: msarro at gmail.com (Matty Sarro) Date: Fri, 5 Nov 2010 09:43:25 -0400 Subject: Silly newbie question - Carrot character (^) Message-ID: Hey Everyone, Just curious - I'm working on a program which includes a calculation of a circle, and I found myself trying to use pi*radius^2, and getting errors that data types float and int are unsupported for "^". Now, I realized I was making the mistake of using '^' instead of "**". I've corrected this and its now working. However, what exactly does ^ do? I know its used in regular expressions but I can't seem to find anything about using it as an operator. Sadly my google foo is failing since the character gets filtered out. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Fri Nov 5 09:46:56 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 05 Nov 2010 06:46:56 -0700 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4CD40AD0.4080703@stoneleaf.us> Grant Edwards wrote: > On 2010-11-04, Emile van Sebille wrote: >> On 11/3/2010 4:09 PM Seebs said... >> >>> What's the token that marks the end of a block, corresponding to the >>> colon used to introduce it? >>> >> >> My thoughts tend more towards 'can we get Guido to eliminate the colon >> requirements' -- The indent level of the next line ought to suffice. > > But without the colon, how are people who write programming editors > going to know when to increase the indentation level as I enter code? > Hopefully by the keywords used to introduce the block: if, elif, else, for, while, with, etc. etc. It is not legal to start a new indented block just by appending a colon to the previous line. ~Ethan~ From krister.svanlund at gmail.com Fri Nov 5 09:56:52 2010 From: krister.svanlund at gmail.com (Krister Svanlund) Date: Fri, 5 Nov 2010 14:56:52 +0100 Subject: Silly newbie question - Carrot character (^) In-Reply-To: References: Message-ID: On Fri, Nov 5, 2010 at 2:43 PM, Matty Sarro wrote: > Hey Everyone, > Just curious - I'm working on a program which includes a calculation of a > circle, and I found myself trying to use pi*radius^2, and getting errors > that data types float and int are unsupported for "^". Now, I realized I was > making the mistake of using '^' instead of "**". I've corrected this and its > now working. However, what exactly does ^ do? I know its used in regular > expressions but I can't seem to find anything about using it as an operator. > Sadly my google foo is failing since the character gets filtered out. It's a binary operator i think... something like xor. From __peter__ at web.de Fri Nov 5 09:57:18 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 05 Nov 2010 14:57:18 +0100 Subject: How convert list to nested dictionary? References: <940876cd-2546-4673-aef4-ba11b4156287@fv1g2000vbb.googlegroups.com> <878w18kbwl.fsf@gmail.com> Message-ID: Boris Borcic wrote: > Arnaud Delobelle wrote: >> macm writes: >> >>> Hi Folks >>> >>> How convert list to nested dictionary? >>> >>>>>> l >>> ['k1', 'k2', 'k3', 'k4', 'k5'] >>>>>> result >>> {'k1': {'k2': {'k3': {'k4': {'k5': {}}}}}} >>> >>> Regards >>> >>> macm >> >> reduce(lambda x,y: {y:x}, reversed(l), {}) >> > > d={} > while L : d={L.pop():d} Iterating over the keys in normal order: >>> keys = "abcde" >>> d = outer = {} >>> for key in keys: ... outer[key] = inner = {} ... outer = inner ... >>> d {'a': {'b': {'c': {'d': {'e': {}}}}}} The "functional" variant: >>> d = {} >>> reduce(lambda outer, key: outer.setdefault(key, {}), "abcde", d) {} >>> d {'a': {'b': {'c': {'d': {'e': {}}}}}} In a single expression if you are willing to pay the price: >>> reduce(lambda (accu, outer), key: (accu, outer.setdefault(key, {})), "abcde", ({},)*2)[0] {'a': {'b': {'c': {'d': {'e': {}}}}}} Peter From vlastimil.brom at gmail.com Fri Nov 5 09:57:31 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Fri, 5 Nov 2010 14:57:31 +0100 Subject: Silly newbie question - Carrot character (^) In-Reply-To: References: Message-ID: 2010/11/5 Matty Sarro : > Hey Everyone, > Just curious - I'm working on a program which includes a calculation of a > circle, and I found myself trying to use pi*radius^2, and getting errors > that data types float and int are unsupported for "^". Now, I realized I was > making the mistake of using '^' instead of "**". I've corrected this and its > now working. However, what exactly does ^ do? I know its used in regular > expressions but I can't seem to find anything about using it as an operator. > Sadly my google foo is failing since the character gets filtered out. > > -- > http://mail.python.org/mailman/listinfo/python-list > > Hi, see http://docs.python.org/reference/expressions.html#binary-bitwise-operations for bitwise XOR. The usage in regular expressions is different, of course; hth, vbr From urban.dani at gmail.com Fri Nov 5 10:00:03 2010 From: urban.dani at gmail.com (Daniel Urban) Date: Fri, 5 Nov 2010 15:00:03 +0100 Subject: Silly newbie question - Carrot character (^) In-Reply-To: References: Message-ID: > However, what exactly does ^ do? Bitwise XOR: http://docs.python.org/py3k/reference/expressions.html#binary-bitwise-operations From darcy at druid.net Fri Nov 5 10:00:43 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Fri, 5 Nov 2010 10:00:43 -0400 Subject: Silly newbie question - Carrot character (^) In-Reply-To: References: Message-ID: <20101105100043.70d414aa.darcy@druid.net> On Fri, 5 Nov 2010 09:43:25 -0400 Matty Sarro wrote: > now working. However, what exactly does ^ do? I know its used in regular > expressions but I can't seem to find anything about using it as an operator. It's the XOR operator. Try "help('^')" for more detail. By the way, it's "caret", not "carrot". -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From anand.shashwat at gmail.com Fri Nov 5 10:02:52 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Fri, 5 Nov 2010 19:32:52 +0530 Subject: Silly newbie question - Carrot character (^) In-Reply-To: References: Message-ID: On Fri, Nov 5, 2010 at 7:26 PM, Krister Svanlund wrote: > On Fri, Nov 5, 2010 at 2:43 PM, Matty Sarro wrote: > > Hey Everyone, > > Just curious - I'm working on a program which includes a calculation of a > > circle, and I found myself trying to use pi*radius^2, and getting errors > > that data types float and int are unsupported for "^". Now, I realized I > was > > making the mistake of using '^' instead of "**". I've corrected this and > its > > now working. However, what exactly does ^ do? I know its used in regular > > expressions but I can't seem to find anything about using it as an > operator. > > Sadly my google foo is failing since the character gets filtered out. > > It's a binary operator i think... something like xor. > Yes. Infact '^' is binary XOR. >>> a = 4 >>> bin(a) '0b100' >>> b = 5 >>> bin(b) '0b101' >>> a ^ b 1 100 ^ 101 = 001 > -- > http://mail.python.org/mailman/listinfo/python-list > -- ~l0nwlf -------------- next part -------------- An HTML attachment was scrubbed... URL: From msarro at gmail.com Fri Nov 5 10:05:43 2010 From: msarro at gmail.com (Matty Sarro) Date: Fri, 5 Nov 2010 10:05:43 -0400 Subject: Silly newbie question - Carrot character (^) In-Reply-To: References: Message-ID: Thanks everyone, that explains it :) -Matty On Fri, Nov 5, 2010 at 9:43 AM, Matty Sarro wrote: > Hey Everyone, > Just curious - I'm working on a program which includes a calculation of a > circle, and I found myself trying to use pi*radius^2, and getting errors > that data types float and int are unsupported for "^". Now, I realized I was > making the mistake of using '^' instead of "**". I've corrected this and its > now working. However, what exactly does ^ do? I know its used in regular > expressions but I can't seem to find anything about using it as an operator. > Sadly my google foo is failing since the character gets filtered out. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From philip at semanchuk.com Fri Nov 5 10:12:05 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Fri, 5 Nov 2010 10:12:05 -0400 Subject: Silly newbie question - Carrot character (^) In-Reply-To: References: Message-ID: <386C05F7-692E-4C2C-A75A-E7DC1B7061BF@semanchuk.com> On Nov 5, 2010, at 9:43 AM, Matty Sarro wrote: > Hey Everyone, > Just curious - I'm working on a program which includes a calculation of a > circle, and I found myself trying to use pi*radius^2, and getting errors > that data types float and int are unsupported for "^". Now, I realized I was > making the mistake of using '^' instead of "**". I've corrected this and its > now working. However, what exactly does ^ do? I know its used in regular > expressions but I can't seem to find anything about using it as an operator. > Sadly my google foo is failing since the character gets filtered out. As others have said, ^ is for XOR. That's buried here in the documentation: http://docs.python.org/release/2.7/reference/expressions.html#binary-bitwise-operations Not that I would have expected you to find it there since that's pretty dense. In fact, older versions of the Python doc used to describe this section as "for language lawyers" but I see they've changed that now. BTW the more common name for this character is caret (ka-RAY). Cheers Philip From greenyballz at yahoo.com Fri Nov 5 11:08:19 2010 From: greenyballz at yahoo.com (No Name) Date: Fri, 05 Nov 2010 15:08:19 GMT Subject: newbie qns : how do i use xmldiff? References: Message-ID: <201011511810usenet@eggheadcafe.com> I had to do some fishing around to figure this much out. Hope it helps. from input import * # From the xmldiff directory from fmes import * # From the xmldiff directory from format import * # From the xmldiff directory from StringIO import * # Build your original tree text1 = '123' stream1 = StringIO(text) tree1 = tree_from_stream(stream) # Build your modified tree text2 = '223' stream2 = StringIO(text2) tree2 = tree_from_stream(stream2) # Compare the trees formatter = InternalPrinter() corrector = FmesCorrector(formatter) corrector.process_trees(tree, tree2) ## OUTPUT: ## Instructions for modifying original to modified # [rename, /point[1]/y[1], x] # [insert-after, /point[1]/x[2], # # 2 # # ] # [remove, /point[1]/x[1]] > On Wednesday, February 03, 2010 1:38 AM sWrath swrath wrote: > Hi , > > I am pretty new to python , and reading up on it. > > Basically I am trying to compare xml files . I know difflib have it > but it does not work out as expected. I was looking at xmldiff , > unfortunately I am not able to find documentation how to call it from > python. Anyone knows a link or doc to it as I have been looking high > and low for few days? > > lastly , is there a py (or algorithm) where it behaves exactly like > diff ? Greatly appreciated. > > Thanks > john >> On Wednesday, February 03, 2010 3:34 PM Terry Reedy wrote: >> On 2/3/2010 1:38 AM, sWrath swrath wrote: >> >> When asking such a question, it is good to explain what sort of thing, >> in this case, 'xmldiff' is and where it is is from. Let us assume you >> meant xmldiff from >> >> http://www.logilab.org/859 >> >> It says it is a python tool that can "be used be used as a library or as >> a command line tool." It includes a README file. Have you read that? >> That says "USAGE ... Read the HELP.txt file.". Have you read *that*? >> HELP.txt seems to focus on command line usage. I would start with that. >> To use it as a library (via import ...), you might have to look at the >> source code as I did not see importing covered in my quick look at that >> file. >> >> Terry Jan Reedy >> Submitted via EggHeadCafe - Software Developer Portal of Choice >> FireAndForget Asynchronous Utility Class for SQL Server Inserts and Updates >> http://www.eggheadcafe.com/tutorials/aspnet/7a22d9a4-59fc-40b0-8337-75c76f14fb3b/fireandforget-asynchronous-utility-class-for-sql-server-inserts-and-updates.aspx From cdalten at gmail.com Fri Nov 5 11:16:41 2010 From: cdalten at gmail.com (chad) Date: Fri, 5 Nov 2010 08:16:41 -0700 (PDT) Subject: What is the best way to handle a missing newline in the following case Message-ID: I have an text file with the following numbers 1 3 5 7 3 9 Now the program reads in this file. When it encounters a '\n', it will do some stuff and then move to the next line. For example, it will read 1 and then '\n'. When it sees '\n', it will do some stuff and go on to read 3. The problem is when I get to the last line. When the program sees '\n' after the 9, everything works fine. However, when there isn't a '\n', the program doesn't process the last line. What would be the best approach to handle the case of the possible missing '\n' at the end of the file? From __peter__ at web.de Fri Nov 5 11:32:57 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 05 Nov 2010 16:32:57 +0100 Subject: What is the best way to handle a missing newline in the following case References: Message-ID: chad wrote: > I have an text file with the following numbers > > 1 > 3 > 5 > 7 > 3 > 9 > > > > Now the program reads in this file. When it encounters a '\n', it will > do some stuff and then move to the next line. For example, it will > read 1 and then '\n'. When it sees '\n', it will do some stuff and go > on to read 3. > > The problem is when I get to the last line. When the program sees '\n' > after the 9, everything works fine. However, when there isn't a '\n', > the program doesn't process the last line. > > What would be the best approach to handle the case of the possible > missing '\n' at the end of the file? Don't split the data into lines yourself, delegate to python >>> with open("tmp.txt", "wb") as f: ... f.write("1\n2\n3\r\n4\r5") ... >>> for line in open("tmp.txt", "U"): ... print repr(line) ... '1\n' '2\n' '3\n' '4\n' '5' As you can see "\n", "\r\n" and "\r" are all converted to "\n". This is called universal newline mode and enabled by open(..., "U"). If your client code insists that a line has to end with "\n" and there's no way to change that you can wrap the file >>> def ensure_newline(instream): ... prev = next(instream) ... for cur in instream: ... yield prev ... prev = cur ... if not prev.endswith("\n"): ... prev += "\n" ... yield prev ... >>> for line in ensure_newline(open("tmp.txt", "U")): ... print repr(line) ... '1\n' '2\n' '3\n' '4\n' '5\n' But often the opposite direction, removing any newlines, works just as well and is easier to achieve: >>> for line in open("tmp.txt", "U"): ... print repr(line.strip("\n")) ... '1' '2' '3' '4' '5' Peter From danmcleran at yahoo.com Fri Nov 5 11:37:13 2010 From: danmcleran at yahoo.com (danmcleran at yahoo.com) Date: Fri, 5 Nov 2010 08:37:13 -0700 (PDT) Subject: What is the best way to handle a missing newline in the following case References: Message-ID: <2c298c1f-cb52-4399-a516-897865fd9d89@r4g2000prj.googlegroups.com> > The problem is when I get to the last line. When the program sees '\n' > after the 9, everything works fine. However, when there isn't a '\n', > the program doesn't process the last line. > > What would be the best approach to handle the case of the possible > missing '\n' at the end of the file? use readines to read all lines into a list and then iterate thru the list: f = open(r'c:\test.txt', 'rb') print f.readlines() >> ['1\r\n', '3\r\n', '5\r\n', '7\r\n', '3\r\n', '9'] From paul.nospam at rudin.co.uk Fri Nov 5 11:47:10 2010 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Fri, 05 Nov 2010 15:47:10 +0000 Subject: What is the best way to handle a missing newline in the following case References: <2c298c1f-cb52-4399-a516-897865fd9d89@r4g2000prj.googlegroups.com> Message-ID: <87zktndb7l.fsf@rudin.co.uk> "danmcleran at yahoo.com" writes: >> The problem is when I get to the last line. When the program sees '\n' >> after the 9, everything works fine. However, when there isn't a '\n', >> the program doesn't process the last line. >> >> What would be the best approach to handle the case of the possible >> missing '\n' at the end of the file? > > use readines to read all lines into a list and then iterate thru the > list: > > f = open(r'c:\test.txt', 'rb') > print f.readlines() > >>> > ['1\r\n', '3\r\n', '5\r\n', '7\r\n', '3\r\n', '9'] There's no real point in contructing a list. Just do with open(r'c:\test.txt') as f: for l in f: print int(l) As long as you just have digits and whitespace then that's fine - int() will do as you want. From neilc at norwich.edu Fri Nov 5 11:54:41 2010 From: neilc at norwich.edu (Neil Cerutti) Date: 5 Nov 2010 15:54:41 GMT Subject: What is the best way to handle a missing newline in the following case References: <2c298c1f-cb52-4399-a516-897865fd9d89@r4g2000prj.googlegroups.com> <87zktndb7l.fsf@rudin.co.uk> Message-ID: <8jinm1Ft6eU1@mid.individual.net> On 2010-11-05, Paul Rudin wrote: > "danmcleran at yahoo.com" writes: >>> The problem is when I get to the last line. When the program >>> sees '\n' after the 9, everything works fine. However, when >>> there isn't a '\n', the program doesn't process the last >>> line. >>> >>> What would be the best approach to handle the case of the possible >>> missing '\n' at the end of the file? >> >> use readines to read all lines into a list and then iterate thru the >> list: >> >> f = open(r'c:\test.txt', 'rb') >> print f.readlines() >> >>>> >> ['1\r\n', '3\r\n', '5\r\n', '7\r\n', '3\r\n', '9'] > > There's no real point in contructing a list. Just do > > with open(r'c:\test.txt') as f: > for l in f: > print int(l) > > As long as you just have digits and whitespace then that's fine > - int() will do as you want. Keep in mind that a file that a text file that doesn't end with a newline isn't strictly legal. You can expect problems, or at least warnings, with other tools with such files. -- Neil Cerutti From moura.mario at gmail.com Fri Nov 5 12:41:36 2010 From: moura.mario at gmail.com (macm) Date: Fri, 5 Nov 2010 09:41:36 -0700 (PDT) Subject: How convert list to nested dictionary? References: <940876cd-2546-4673-aef4-ba11b4156287@fv1g2000vbb.googlegroups.com> <878w18kbwl.fsf@gmail.com> Message-ID: <9c917109-92fe-4d1f-9310-b62ff64693f5@k11g2000vbf.googlegroups.com> Hi Folks thanks a lot all. All solutions work fine. while I am doing my home work. Reading "Learning Python" and much more. Let me ask again to close my doubts: >>> l = ['k1', 'k2', 'k3', 'k4', 'k5'] >>> d = reduce(lambda x,y: {y:x}, reversed(l), {'/':[1,2,3]}) >>> d {'k1': {'k2': {'k3': {'k4': {'k5': {'/': [1, 2, 3]}}}}}} >>> d['k1']['k2']['k3']['k4']['k5'] {'/': [1, 2, 3]} >>> d['k1']['k2']['k3']['k4']['k5']['/'] [1, 2, 3] >>> now I want generate the "index" to access the element. ==> d['k1']['k2']['k3']['k4']['k5']['/'] from l So again I have only. >>> l = ['k1', 'k2', 'k3', 'k4', 'k5'] z = ?magicCode? z = d['k1']['k2']['k3']['k4']['k5']['/'] >>> z [1, 2, 3] >>>z.append('4') >>>z [1, 2, 3, 4] Best Regards macm On 5 nov, 11:57, Peter Otten <__pete... at web.de> wrote: > Boris Borcic wrote: > > Arnaud Delobelle wrote: > >> macm ?writes: > > >>> Hi Folks > > >>> How convert list to nested dictionary? > > >>>>>> l > >>> ['k1', 'k2', 'k3', 'k4', 'k5'] > >>>>>> result > >>> {'k1': {'k2': {'k3': {'k4': {'k5': {}}}}}} > > >>> Regards > > >>> macm > > >> reduce(lambda x,y: {y:x}, reversed(l), {}) > > > d={} > > while L : d={L.pop():d} > > Iterating over the keys in normal order: > > >>> keys = "abcde" > >>> d = outer = {} > >>> for key in keys: > > ... ? ? outer[key] = inner = {} > ... ? ? outer = inner > ...>>> d > > {'a': {'b': {'c': {'d': {'e': {}}}}}} > > The "functional" variant: > > >>> d = {} > >>> reduce(lambda outer, key: outer.setdefault(key, {}), "abcde", d) > {} > >>> d > > {'a': {'b': {'c': {'d': {'e': {}}}}}} > > In a single expression if you are willing to pay the price: > > >>> reduce(lambda (accu, outer), key: (accu, outer.setdefault(key, {})), > > "abcde", ({},)*2)[0] > {'a': {'b': {'c': {'d': {'e': {}}}}}} > > Peter From ppearson at nowhere.invalid Fri Nov 5 12:43:37 2010 From: ppearson at nowhere.invalid (Peter Pearson) Date: 5 Nov 2010 16:43:37 GMT Subject: Silly newbie question - Carrot character (^) References: Message-ID: <8jiqhpFmj3U2@mid.individual.net> On Fri, 5 Nov 2010 10:12:05 -0400, Philip Semanchuk wrote: > > BTW the more common name for this character is caret (ka-RAY). Yes, it's caret, but no, it's KA-rit, almost the same as carrot. It's straight from Latin, with no detour through French. -- To email me, substitute nowhere->spamcop, invalid->net. From gb345 at invalid.com Fri Nov 5 12:55:31 2010 From: gb345 at invalid.com (gb345) Date: Fri, 5 Nov 2010 16:55:31 +0000 (UTC) Subject: How to get dynamically-created fxn's source? Message-ID: For a project I'm working on I need a way to retrieve the source code of dynamically generated Python functions. (These functions are implemented dynamically in order to simulate "partial application" in Python.[1]) The ultimate goal is to preserve a textual record of transformations performed on data, along with all the data (both pre- and post- transformation) itself. These transformation functions could be dynamically generated as closures, but I suspect that this would make it more difficult to extract source code that could serve as a reasonably self-contained description of the transformation (because this source code would refer to variables defined outside of the function). An alternative would be to generate the *source code* for the functions dynamically, from a template having slots (within the function's definition) that gets filled in with actual parameter values, and pass this source code to exec. In any case, the problem remains of how to extract the dynamically-generated function's source code. One possibility would be to define a Transformation wrapper class whose __init__ takes the dynamically-generated source code (a string) as argument, keeps it around as an instance attribute for future reference, and exec's it to define its __call__ method. Is this overkill/reinventing the wheel? IOW, does Python already have a built-in way to achieve this same effect? (Also, the wrapper scheme above is somewhat loose: it's relatively easy for the source code instance attribute (as described) to fall out of sync with the function that actually executes when __call__ runs. Maybe a tighter connection between the obtained source code and the code that actually executes when __call__ runs is possible.) I'm aware of the inspect module, but from reading its source code I gather that it is designed for inspecting source code that is explicitly written in files, and would not be too good at inspecting functions that are generated dynamically (i.e. not from source code explicitly given in a source file--I hope that made sense). Your comments and suggestions would be much appreciated. Many thanks in advance! G [1] For example, given a base function spam that has the signature (typeT, typeT, typeT, int, int, int) and three specific integer values X, Y, and Z, dynamically generate a new function spamXYZ with signature (typeT, typeT, typeT) such that spamXYZ(A, B, C) is identical to spam(A, B, C, X, Y, Z), for all possible values of A, B, C. From azeynel1 at gmail.com Fri Nov 5 12:59:38 2010 From: azeynel1 at gmail.com (Zeynel) Date: Fri, 5 Nov 2010 09:59:38 -0700 (PDT) Subject: Exception handling with NameError Message-ID: Hello, I want to append new input to list SESSION_U without erasing its content. I try this: ... try: SESSION_U.append(UNIQUES) except NameError: SESSION_U = [] SESSION_U.append(UNIQUES) ... I would think that at first try I would get the NameError and SESSION_U list would be created and appended; the second time try would work. But it does not. Do you know why? From __peter__ at web.de Fri Nov 5 13:26:27 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 05 Nov 2010 18:26:27 +0100 Subject: Exception handling with NameError References: Message-ID: Zeynel wrote: > I want to append new input to list SESSION_U without erasing its > content. I try this: > > ... > try: > SESSION_U.append(UNIQUES) > except NameError: > SESSION_U = [] > SESSION_U.append(UNIQUES) > ... > I would think that at first try I would get the NameError and > SESSION_U list would be created and appended; the second time try > would work. But it does not. Do you know why? If you want SESSION_U to be global you must say so. E. g.: def your_func(): global SESSION_U # ... > try: > SESSION_U.append(UNIQUES) > except NameError: > SESSION_U = [] > SESSION_U.append(UNIQUES) # ... Of course I'm only guessing because you don't provide enough context. Peter From emile at fenx.com Fri Nov 5 13:32:18 2010 From: emile at fenx.com (Emile van Sebille) Date: Fri, 05 Nov 2010 10:32:18 -0700 Subject: How to get dynamically-created fxn's source? In-Reply-To: References: Message-ID: On 11/5/2010 9:55 AM gb345 said... > In any case, the problem remains of how to extract the > dynamically-generated function's source code. > Are you looking for the source code of the dynamically created wrapper function (effectively the piece that calls the original function) or of the wrapped function? (the piece that ultimately gets called?) I'm pretty sure you can't get source from the executable function (python 2.x anyway), but with your naming scheme, it may be possible to trace into the wrapped function's source. Emile From __peter__ at web.de Fri Nov 5 13:36:30 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 05 Nov 2010 18:36:30 +0100 Subject: How to get dynamically-created fxn's source? References: Message-ID: gb345 wrote: > For a project I'm working on I need a way to retrieve the source > code of dynamically generated Python functions. (These functions > are implemented dynamically in order to simulate "partial application" > in Python.[1]) The ultimate goal is to preserve a textual record > of transformations performed on data, along with all the data (both > pre- and post- transformation) itself. Are you aware of functools.partial? >>> from functools import partial >>> def f(a, b, c, x, y, z): ... return a*x + b*y*y + c*z*z*z ... >>> fstar = partial(f, x=1, y=2, z=3) >>> fstar(1, 0, 0) 1 >>> fstar(0, 1, 0) 4 >>> fstar(0, 0, 1) 27 >>> fstar.args, fstar.keywords ((), {'y': 2, 'x': 1, 'z': 3}) >>> fstar.func From __peter__ at web.de Fri Nov 5 13:40:40 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 05 Nov 2010 18:40:40 +0100 Subject: How convert list to nested dictionary? References: <940876cd-2546-4673-aef4-ba11b4156287@fv1g2000vbb.googlegroups.com> <878w18kbwl.fsf@gmail.com> <9c917109-92fe-4d1f-9310-b62ff64693f5@k11g2000vbf.googlegroups.com> Message-ID: macm wrote: > thanks a lot all. All solutions work fine. > > while I am doing my home work. > Reading "Learning Python" and much more. > > Let me ask again to close my doubts: > >>>> l = ['k1', 'k2', 'k3', 'k4', 'k5'] >>>> d = reduce(lambda x,y: {y:x}, reversed(l), {'/':[1,2,3]}) >>>> d > {'k1': {'k2': {'k3': {'k4': {'k5': {'/': [1, 2, 3]}}}}}} >>>> d['k1']['k2']['k3']['k4']['k5'] > {'/': [1, 2, 3]} >>>> d['k1']['k2']['k3']['k4']['k5']['/'] > [1, 2, 3] >>>> > > now I want generate the "index" to access the element. > > ==> d['k1']['k2']['k3']['k4']['k5']['/'] from l > > So again I have only. >>>> l = ['k1', 'k2', 'k3', 'k4', 'k5'] > > z = ?magicCode? > > z = d['k1']['k2']['k3']['k4']['k5']['/'] You'll eventually have to start and write your first line of code. Why not doing it right now? It is sure more rewarding than copying other people's canned solutions and it can even be fun. Peter From rbroze at yahoo.com Fri Nov 5 13:50:13 2010 From: rbroze at yahoo.com (robert roze) Date: Fri, 5 Nov 2010 10:50:13 -0700 (PDT) Subject: decimal.py ver 2.6,2.7 not working with python 2.7 Message-ID: <281783.63405.qm@web114408.mail.gq1.yahoo.com> I have a 'Python 2.7' installed. It seems like the decimal.py module that comes with the Python2.7 package is not working. I hope I'm wrong, but here's why I think so: If I simply try to import the module, I get this error: >>> import decimal Traceback (most recent call last): File "", line 1, in File "/opt/ictools/python_2_7/lib/python2.7/decimal.py", line 3700, in _numbers.Number.register(Decimal) AttributeError: 'module' object has no attribute 'Number' >>> But, if I download, and import the 2.5 version of decimal.py, it imports with no complaint. In the 2.5 version of decimal.py, there is no reference to '_numbers' like there is in the 2.6 and 2.7 versions. Is this a bug, or is there something I can do to fix it (as a user, with limited permissions)? I don't feel good about continuing to run with the 2.5 decimal.py, since I'll be using alot of numpy and other modules that use decimal, and I don't know how they'll react. Thanks, Bob -------------- next part -------------- An HTML attachment was scrubbed... URL: From usernet at ilthio.net Fri Nov 5 14:02:45 2010 From: usernet at ilthio.net (Tim Harig) Date: Fri, 5 Nov 2010 18:02:45 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> <4cd3de51$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-05, Steven D'Aprano wrote: > On Thu, 04 Nov 2010 21:47:59 +0000, Tim Harig wrote: > >> I have seen huge patches caused by nothing more then some edit that >> accidently added a trailing space to a large number of lines. White >> space mangling happens all the time without people even knowing about >> it. > > How does an edit accidentally add a trailing space to a large number of > lines? Putting it back in context, it doesn't matter. Seeb's point stands. diff -b was designed because there are so many tools and channels that mangle whitespace. Changes in something such as brace style would make non-whitespace changes that would not be eliminated by diff -b. Probably the biggest reason for -b is for handling the differences in line endings used on different platforms. > (1) The programmer shifted the cursor to the end of the line, pressed > space, moved down a line, shift to eol, press space, repeat a large > number of times. I don't call that an "accident". A search and replace operation could easily add extra whitespace and since whitespace is not normally visible, the changes most likely go unnoticed. The bottom line is that it happens and assigning blame really doesn't change that fact. > (2) Some programmer used a tool that thought it was okay to add > whitespace to the end of lines without being told to. I don't call that > an accident either, I call that using a broken tool. Yep, there are probably thousands of tools that mangle whitespace. In many cases, such as differences in line endings, what they are doing is not even wrong. You can blame the tools all you like; but, they are not going away. You keep trying to tell us that using whitespace is superior; but, other languages manage to work with these thousands of imperfect tools without issue. The use of whitespace was a stylistic change and stylistic holy wars exist because it is almost impossible to prove that any reasonable style has benefit over another. That whitespace causes issues is verifiable. I find it hard to concluded that that whitespace based syntax is superior when it tells us that we cannot use thousands of otherwise useful tools that other langauges manage to work with. I find it hard to select a matter of taste with no verifiable benefit over a verifiable disadvantage that happens to strike many people. From invalid at invalid.invalid Fri Nov 5 14:07:07 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 5 Nov 2010 18:07:07 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> <4cd3de51$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-05, Tim Harig wrote: > On 2010-11-05, Steven D'Aprano wrote: >> On Thu, 04 Nov 2010 21:47:59 +0000, Tim Harig wrote: >> >>> I have seen huge patches caused by nothing more then some edit that >>> accidently added a trailing space to a large number of lines. White >>> space mangling happens all the time without people even knowing about >>> it. And how does that affect a Python program? The same as it does a C program. >> How does an edit accidentally add a trailing space to a large number of >> lines? > > Putting it back in context, it doesn't matter. Seeb's point stands. > diff -b was designed because there are so many tools and channels that > mangle whitespace. Changes in something such as brace style would make > non-whitespace changes that would not be eliminated by diff -b. > > Probably the biggest reason for -b is for handling the differences in line > endings used on different platforms. Different line-endings are tolerated by Python just as well as they are by C. -- Grant Edwards grant.b.edwards Yow! They collapsed at ... like nuns in the gmail.com street ... they had no teen appeal! From azeynel1 at gmail.com Fri Nov 5 14:12:49 2010 From: azeynel1 at gmail.com (Zeynel) Date: Fri, 5 Nov 2010 11:12:49 -0700 (PDT) Subject: Exception handling with NameError References: Message-ID: On Nov 5, 1:26?pm, Peter Otten <__pete... at web.de> wrote: > Of course I'm only guessing because you don't provide enough context. > > Peter Thanks. This is the problem I am having, in general: K = [] # a container list K = ["A", "B"] ARCHIVE = [] # a list where items from K is archived ARCHIVE.append(K) # K is updated K = ["C", "D"] # append new K to ARCHIVE ARCHIVE.append(K) The problem I am having is this: If I do: K = [] ARCHIVE = [] ARCHIVE.append(K) any time K is updated (user submits new input) the content of ARCHIVE is erased: If I do this: K = [] ARCHIVE.append(K) I get NameError: "Name ARCHIVE not defined" What is the solution? From usernet at ilthio.net Fri Nov 5 14:13:44 2010 From: usernet at ilthio.net (Tim Harig) Date: Fri, 5 Nov 2010 18:13:44 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> Message-ID: On 2010-11-04, D'Arcy J.M. Cain wrote: > On Thu, 4 Nov 2010 19:37:25 +0000 (UTC) > Tim Harig wrote: >> On 2010-11-04, D'Arcy J.M. Cain wrote: >> You are the one who seems to be on a crusade against against braces. It > > You totally misunderstand me. I am not on a crusade of any sort. I am I appologize that I confused your name with Steven D'Aprano; but, your positions are pretty much the same. > care about. If no one was on a crusade to convince people that > indentation as syntax (can we call is IAS from now on?) was evil then I > wouldn't be posting anything at all on the subject. I am being totally > reactionary here. Neither of you are really adding anything to the conversation other then to assert that you like whitespace syntax and that the problems do not effect you. Good for you; but, that doesn't help the people who are finding that it presents problems. >> would seem to me, that if you want people to accept that white space >> formatting is superior, that you would be looking for a simple way to solve >> the white space mangling problem. > > I might if it was a problem for me. Good for you but telling us that doesn't really help those that do. Your stance is based an a stylistic preference. Holy wars around style continue to exist because, in most cases, it is almost impossible to prove the advantages of one reasonable style over another. It is, however, verifiable that white space syntax causes issues with a large number of common tools. I am a man of science. When choosing between the intangible and verifiable, I choose the verifable truth. >> The world is full of broken tools that many of us have to use; but, why >> should we accept that your choice is superior when other choices manage to >> work with these tools without issues. > > You don't have to accept anything. Choose your own tools. I happen to > choose Python and the tools that I choose to use work fine for me. It is simply hard for me to accept that your solution is better when it is telling us that we have to abandon thousands of tools that other solutions manage to work with without difficulty. From edreamleo at gmail.com Fri Nov 5 14:15:23 2010 From: edreamleo at gmail.com (Edward K. Ream) Date: Fri, 5 Nov 2010 11:15:23 -0700 (PDT) Subject: ANN: Leo 4.8 beta 1 released Message-ID: <3856f751-9440-45c9-871e-4f50b7356c2c@u25g2000pra.googlegroups.com> Leo 4.8 beta 1 is now available at: http://sourceforge.net/project/showfiles.php?group_id=3458&package_id=29106 Leo is a text editor, data organizer, project manager and much more. See: http://webpages.charter.net/edreamleo/intro.html The highlights of Leo 4.8: -------------------------- - Leo now uses the simplest possible sentinel lines in external files. External files with sentinels now look like Emacs org-mode files. - Leo Qt gui now supports Drag and Drop. This was one of the most frequently requested features. - Improved abbreviation commands. You now define abbreviations in Leo settings nodes, not external files. - @url nodes may contain url's in body text. This allows headlines to contain summaries: very useful. - Leo now uses PyEnchant to check spelling. - Leo can now open multiple files from the command line. - Leo's ancient Tangle and Untangle commands are now deprecated. This will help newbies how to learn Leo. - Leo now shows "Resurrected" and "Recovered" nodes. These protect data and show how data have changed. These fix several long-standing data-related problems. - A new "screenshots" plugin for creating slide shows with Leo. I used this plugin to create Leo's introductory slide shows. - A better installer. - Many bug fixes. Links: ------ Leo: http://webpages.charter.net/edreamleo/front.html Forum: http://groups.google.com/group/leo-editor Download: http://sourceforge.net/project/showfiles.php?group_id=3458 Bzr: http://code.launchpad.net/leo-editor/ Quotes: http://webpages.charter.net/edreamleo/testimonials.html From usernet at ilthio.net Fri Nov 5 14:19:05 2010 From: usernet at ilthio.net (Tim Harig) Date: Fri, 5 Nov 2010 18:19:05 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <87mxpoax4q.fsf@dpt-info.u-strasbg.fr> Message-ID: On 2010-11-05, Alain Ketterlin wrote: > Terry Reedy writes: > >> If you add the normally redundant information in the form of explicit >> dedents (anything starting with '#' and distinguishable from normal >> comments), then it is not too hard to re-indent even after all indents >> have been removed. > > I actually use such a trick in emacs, not with comments but with "pass" > (emacs' python mode knows that pass end return end the current block). > It's extrememly useful in heavily nested code, or if I need to paste > some piece of code from one level to another. This lets my editor's > auto-indenter do the right thing. And I see immediately if/when I did > the nesting wrong. Thank-you for your tip. It is nice to know that some people are thinking of ways to work around the trade-offs rather then just asserting that we shouldn't use tools that happen to collide with Python. From msarro at gmail.com Fri Nov 5 14:23:12 2010 From: msarro at gmail.com (Matty Sarro) Date: Fri, 5 Nov 2010 14:23:12 -0400 Subject: Using %x to format number to hex and number of digits Message-ID: I'm currently trying to convert a digit from decimal to hex, however I need the full 4 digit hex form. Python appears to be shortening the form. Example: num = 10 num = "%x"%(num) print(num) >a num = 10 num = "%#x"%(num) print(num) >0xa I need it to output as 0x0a, and the exercise is requiring me to use %x to format the string. Any help would be appreciated. -------------- next part -------------- An HTML attachment was scrubbed... URL: From usernet at ilthio.net Fri Nov 5 14:25:44 2010 From: usernet at ilthio.net (Tim Harig) Date: Fri, 5 Nov 2010 18:25:44 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> <4cd3de51$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-05, Grant Edwards wrote: > On 2010-11-05, Tim Harig wrote: >> On 2010-11-05, Steven D'Aprano wrote: >>> On Thu, 04 Nov 2010 21:47:59 +0000, Tim Harig wrote: >>> >>>> I have seen huge patches caused by nothing more then some edit that >>>> accidently added a trailing space to a large number of lines. White >>>> space mangling happens all the time without people even knowing about >>>> it. > > And how does that affect a Python program? The same as it does a C > program. I wasn't making any statement of C versus Python in this thread. Those have been covered elsewhere. I was responding to your assertion: It exists because so many people change whitespace intentionally in C source code because no two C programmers seem able to agree on how to format code. Diff -b allows you to attempt to ignore semantically null stylistic changes made by programmers. That is clearly wrong. If a C programmer changes the format of the code, it is almost universally true that they will make changes that affect more then just the whitespace on a single line. Diff will register these changes even with the -b option. I provided a couple of common scenerios that are more likely to have justified the -b option. From clp2 at rebertia.com Fri Nov 5 14:35:05 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 5 Nov 2010 11:35:05 -0700 Subject: decimal.py ver 2.6,2.7 not working with python 2.7 In-Reply-To: <281783.63405.qm@web114408.mail.gq1.yahoo.com> References: <281783.63405.qm@web114408.mail.gq1.yahoo.com> Message-ID: On Fri, Nov 5, 2010 at 10:50 AM, robert roze wrote: > I have a 'Python 2.7' installed. > > It seems like the decimal.py module that comes with the Python2.7 package is > not working. I hope I'm wrong, but here's why I think so: > > If I simply try to import the module, I get this error: > >>>> import decimal > Traceback (most recent call last): > ? File "", line 1, in > ? File "/opt/ictools/python_2_7/lib/python2.7/decimal.py", line 3700, in > > ??? _numbers.Number.register(Decimal) > AttributeError: 'module' object has no attribute 'Number' >>>> What does the following output for you?: import numbers print(numbers.__file__) print(dir(numbers)) Cheers, Chris -- http://blog.rebertia.com From nagle at animats.com Fri Nov 5 14:35:31 2010 From: nagle at animats.com (John Nagle) Date: Fri, 05 Nov 2010 11:35:31 -0700 Subject: Compare source code In-Reply-To: <4cd3df64$0$30004$c3e8da3$5496439d@news.astraweb.com> References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <87r5f13ug3.fsf.mdw@metalzone.distorted.org.uk> <4cd3df64$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4cd44e7a$0$1610$742ec2ed@news.sonic.net> On 11/5/2010 3:41 AM, Steven D'Aprano wrote: > On Thu, 04 Nov 2010 20:17:35 +0000, Seebs wrote: > >>> * I /do/ have a significant problem with cutting and pasting code in >>> Python. In most languages, I can haul a chunk of code about, hit >>> C-M-q, and Emacs magically indents the result properly. This is, >>> unfortunately, impossible with Python. It has caused me real bugs, >>> and I have to be extra careful to fix the indentation up. >> >> That was the thing which bit me the worst. I had a fairly large block >> of code in a first-pass ugly program. I wanted to start refactoring it, >> so I moved a big hunk of code into a method (with plans to further >> refactor). It took about fifteen minutes to redo the logic. > > Well there's your problem -- you are relying on tools that operate by > magic. Not magic, just code understanding. INTERLISP's editor allowed the user to select a block of LISP code and make it into a function. The selected block would be analyzed to determine which local variables it referenced, and a new function would be created with those parameters. The block of code at the original point would then be replaced by a call to the function. Today's editors are too dumb to do that right. They're text editors with the illusion of knowing something about the language, not language editors which also format text. John Nagle From emile at fenx.com Fri Nov 5 14:35:55 2010 From: emile at fenx.com (Emile van Sebille) Date: Fri, 05 Nov 2010 11:35:55 -0700 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> Message-ID: On 11/5/2010 11:13 AM Tim Harig said... > It is simply hard for me to accept that your solution is better when > it is telling us that we have to abandon thousands of tools that other > solutions manage to work with without difficulty. I only work with a few tools none of which alter or strip leading whitespace, and I don't try to transport python code in ways that allow harmful transformations to take place, eg, reinterpreted by html or email rendering engines, which aren't effective programming tools anyway. So, which of your tools are you married to that are causing your issues? If-you-got-a-bigger-hammer-you-could-drive-that-phillips-screw-into-anything-ly y'rs, Emile From usenet-nospam at seebs.net Fri Nov 5 14:42:41 2010 From: usenet-nospam at seebs.net (Seebs) Date: 05 Nov 2010 18:42:41 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> <4cd3de51$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-05, Steven D'Aprano wrote: > How does an edit accidentally add a trailing space to a large number of > lines? I would love to know the answer to this question. However, empirically, it happens. My guess would be cutting and pasting in some way. > So we keep coming back to work-arounds for tools that mangle your data > for no good reason... To some extent, this is true. How about this. How about we make the Python TCP Stack. The Python TCP Stack works on the same principles that you advocate for the Python language. For instance, if any packet it receives is malformed or contrary to the applicable specs, it has a 95% chance of dropping the packet, and a 5% chance of interpreting the packet as being of a different type entirely. This will NEVER be a problem, and is a good design, because handling packets which contain any kind of spec violation is just work-arounds for broken tools, right? And the first thing we should do is *always* to ensure that, if anything anywhere does not live up to our proposed specification, it causes us to fail in spectacular ways. Of course, to fully capture the feel of Python's choice here, we have to include some common packet variant, which violates no RFCs, as one of the "broken" ones on the grounds that it doesn't make sense to us and isn't easy for a newcomer to read. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Fri Nov 5 14:45:39 2010 From: usenet-nospam at seebs.net (Seebs) Date: 05 Nov 2010 18:45:39 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <87r5f13ug3.fsf.mdw@metalzone.distorted.org.uk> <4cd3df64$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-05, Steven D'Aprano wrote: > On Thu, 04 Nov 2010 20:17:35 +0000, Seebs wrote: >> That was the thing which bit me the worst. I had a fairly large block >> of code in a first-pass ugly program. I wanted to start refactoring it, >> so I moved a big hunk of code into a method (with plans to further >> refactor). It took about fifteen minutes to redo the logic. > Well there's your problem -- you are relying on tools that operate by > magic. Wrong. > Rather than re-create the logic, why not just hit Undo and then re-paste > the code *without* the magic auto-reformat? Half a second, to undo and re- > paste, followed by 10 or 20 seconds to select the appropriate lines and > *explicitly* re-indent the lines to the correct level. There was no magic auto-reformat. Where did you invent that from? Why are you making stuff up which I never said or referred to? > For somebody who keeps tossing around the mantra that "explicit is better > than implicit", you're amazingly reliant on a tool that performs massive, > apparently irreversible formatting operations implicitly. No, I am not. No such tool was involved. I never mentioned one, referred to one, or hinted at one -- and have never used one, because I hate them. In fact, it is ludicrous to imagine that I was using one, given that I've stated in this very thread that so far as I know such a tool cannot be created for Python. Your decision to invent something I never referred to is not a problem with my approach to the language. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Fri Nov 5 14:48:20 2010 From: usenet-nospam at seebs.net (Seebs) Date: 05 Nov 2010 18:48:20 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> Message-ID: On 2010-11-05, Emile van Sebille wrote: > So, which of your tools are you married to that are causing your issues? Python. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From moura.mario at gmail.com Fri Nov 5 14:51:51 2010 From: moura.mario at gmail.com (macm) Date: Fri, 5 Nov 2010 11:51:51 -0700 (PDT) Subject: How convert list to nested dictionary? References: <940876cd-2546-4673-aef4-ba11b4156287@fv1g2000vbb.googlegroups.com> <878w18kbwl.fsf@gmail.com> <9c917109-92fe-4d1f-9310-b62ff64693f5@k11g2000vbf.googlegroups.com> Message-ID: <471f4f12-f7c4-437d-b435-989bbd8e64c1@o15g2000prh.googlegroups.com> Hi Peter Thanks a lot for your tips and codes, Cake Recipes are good to learn! So I post just basic issues. Hopping a good soul like you can help me! But I am still learning... : ) Best Regards macm On 5 nov, 15:40, Peter Otten <__pete... at web.de> wrote: > macm wrote: > > thanks a lot all. All solutions work fine. > > > while I am doing my home work. > > Reading "Learning Python" and much more. > > > Let me ask again to close my doubts: > > >>>> l = ['k1', 'k2', 'k3', 'k4', 'k5'] > >>>> d = reduce(lambda x,y: {y:x}, reversed(l), {'/':[1,2,3]}) > >>>> d > > {'k1': {'k2': {'k3': {'k4': {'k5': {'/': [1, 2, 3]}}}}}} > >>>> d['k1']['k2']['k3']['k4']['k5'] > > {'/': [1, 2, 3]} > >>>> d['k1']['k2']['k3']['k4']['k5']['/'] > > [1, 2, 3] > > > now I want generate the "index" to access the element. > > > ==> d['k1']['k2']['k3']['k4']['k5']['/'] from l > > > So again I have only. > >>>> l = ['k1', 'k2', 'k3', 'k4', 'k5'] > > > z = ?magicCode? > > > z = d['k1']['k2']['k3']['k4']['k5']['/'] > > You'll eventually have to start and write your first line of code. Why not > doing it right now? It is sure more rewarding than copying other people's > canned solutions and it can even be fun. > > Peter From philip at semanchuk.com Fri Nov 5 14:54:40 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Fri, 5 Nov 2010 14:54:40 -0400 Subject: Silly newbie question - Carrot character (^) In-Reply-To: <8jiqhpFmj3U2@mid.individual.net> References: <8jiqhpFmj3U2@mid.individual.net> Message-ID: On Nov 5, 2010, at 12:43 PM, Peter Pearson wrote: > On Fri, 5 Nov 2010 10:12:05 -0400, Philip Semanchuk wrote: >> >> BTW the more common name for this character is caret (ka-RAY). > > Yes, it's caret, but no, it's KA-rit, almost the same as > carrot. It's straight from Latin, with no detour through > French. This I did not know (obviously). Thanks. I knew all those years of studying French would ruin me somehow. From clp2 at rebertia.com Fri Nov 5 14:57:14 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 5 Nov 2010 11:57:14 -0700 Subject: Using %x to format number to hex and number of digits In-Reply-To: References: Message-ID: On Fri, Nov 5, 2010 at 11:23 AM, Matty Sarro wrote: > I'm currently trying to convert a digit from decimal to hex, however I need > the full 4 digit hex form. Python appears to be shortening the form. > Example: > > num = 10 > num = "%x"%(num) > print(num) > >>a > > num = 10 > num = "%#x"%(num) > print(num) > >>0xa > > I need it to output as 0x0a, and the exercise is requiring me to use %x to > format the string. Any help would be appreciated. Use str.zfill() and add the 0x manually: num = 10 hexdig = "%x" % num padded = hexdig.zfill(2) # pad with 0 if necessary oxd = "0x" + padded print(oxd) Cheers, Chris -- http://blog.rebertia.com From invalid at invalid.invalid Fri Nov 5 15:02:05 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 5 Nov 2010 19:02:05 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> Message-ID: On 2010-11-05, Seebs wrote: > On 2010-11-05, Emile van Sebille wrote: >> So, which of your tools are you married to that are causing your issues? > > Python. I think you should quit using Python and choose a language that works with whatever tools are causing all your white-space corruption problems. -- Grant Edwards grant.b.edwards Yow! My pants just went to at high school in the Carlsbad gmail.com Caverns!!! From invalid at invalid.invalid Fri Nov 5 15:05:42 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 5 Nov 2010 19:05:42 +0000 (UTC) Subject: Using %x to format number to hex and number of digits References: Message-ID: On Fri, Nov 5, 2010 at 11:23 AM, Matty Sarro wrote: > I'm currently trying to convert a digit from decimal to hex, however I need > the full 4 digit hex form. Python appears to be shortening the form. > Example: > > num = 10 > num = "%x"%(num) > print(num) > >>a > > num = 10 > num = "%#x"%(num) > print(num) > >>0xa > > I need it to output as 0x0a, and the exercise is requiring me to use %x to > format the string. Any help would be appreciated. http://docs.python.org/release/2.5.2/lib/typesseq-strings.html What you're asking for is called "zero padding", so if I were you, I'd search the above page for the phrase "zero pad". -- Grant Edwards grant.b.edwards Yow! BARBARA STANWYCK makes at me nervous!! gmail.com From rbroze at yahoo.com Fri Nov 5 15:14:08 2010 From: rbroze at yahoo.com (robert roze) Date: Fri, 5 Nov 2010 12:14:08 -0700 (PDT) Subject: decimal.py ver 2.6,2.7 not working with python 2.7 Message-ID: <954451.88002.qm@web114415.mail.gq1.yahoo.com> Hi Chris, Aha! yes, you figured it out. My PYTHONPATH env variable had an old experiment in it, which happened to be called numbers.py. Take it out, and decimal.py works fine. Thank you, Bob >What does the following output for you?: > >import numbers >print(numbers.__file__) >print(dir(numbers)) > >Cheers, >Chris >-- >http://blog.rebertia.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From msarro at gmail.com Fri Nov 5 15:26:42 2010 From: msarro at gmail.com (Matty Sarro) Date: Fri, 5 Nov 2010 15:26:42 -0400 Subject: Using %x to format number to hex and number of digits In-Reply-To: References: Message-ID: I actually was able to get it working a few minutes after posting the question. My apologies for not posting a followup :) I ended up using the following format: num = 10 num = "%#0.2x"%(num) print(num) It works, however I'm not sure if it'd be considered very "pythonic" or not. Thanks for your thoughts! On Fri, Nov 5, 2010 at 2:57 PM, Chris Rebert wrote: > On Fri, Nov 5, 2010 at 11:23 AM, Matty Sarro wrote: > > I'm currently trying to convert a digit from decimal to hex, however I > need > > the full 4 digit hex form. Python appears to be shortening the form. > > Example: > > > > num = 10 > > num = "%x"%(num) > > print(num) > > > >>a > > > > num = 10 > > num = "%#x"%(num) > > print(num) > > > >>0xa > > > > I need it to output as 0x0a, and the exercise is requiring me to use %x > to > > format the string. Any help would be appreciated. > > Use str.zfill() and add the 0x manually: > > num = 10 > hexdig = "%x" % num > padded = hexdig.zfill(2) # pad with 0 if necessary > oxd = "0x" + padded > print(oxd) > > Cheers, > Chris > -- > http://blog.rebertia.com > -------------- next part -------------- An HTML attachment was scrubbed... URL: From darcy at druid.net Fri Nov 5 15:33:37 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Fri, 5 Nov 2010 15:33:37 -0400 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> Message-ID: <20101105153337.4871389b.darcy@druid.net> On Fri, 5 Nov 2010 18:13:44 +0000 (UTC) Tim Harig wrote: > > care about. If no one was on a crusade to convince people that > > indentation as syntax (can we call is IAS from now on?) was evil then I > > wouldn't be posting anything at all on the subject. I am being totally > > reactionary here. > > Neither of you are really adding anything to the conversation other then to Well, whether I am adding anything is a judgement call. That I don't accept your premise doesn't mean that my postings are content free. > It is, however, verifiable that white space syntax causes issues with a > large number of common tools. I am a man of science. When choosing The simple fact is that the combination of your tools and Python is broken. The combination of my tools and Python is not. That's lucky for me since I really, really like IAS. That's unlucky for people who have to work with tools that mangle code. But don't crusade to change my language. Use Perl or C or even pybraces. > It is simply hard for me to accept that your solution is better when > it is telling us that we have to abandon thousands of tools that other > solutions manage to work with without difficulty. I am offering no solutions. Why would I since I don't see a problem? -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From ethan at stoneleaf.us Fri Nov 5 15:34:28 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 05 Nov 2010 12:34:28 -0700 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> <4cd3de51$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4CD45C44.7010600@stoneleaf.us> Tim Harig wrote: > The use of whitespace was a stylistic change and > stylistic holy wars exist because it is almost impossible to prove that > any reasonable style has benefit over another. That whitespace causes > issues is verifiable. I find it hard to concluded that that whitespace > based syntax is superior when it tells us that we cannot use thousands > of otherwise useful tools that other langauges manage to work with. > I find it hard to select a matter of taste with no verifiable benefit > over a verifiable disadvantage that happens to strike many people. The verifiable benefit for me is ease of use, ease of thought, ease of typing... I realize these are not benefits for everyone, but they are for some -- and I would venture a guess that the ease of thought benefit is one of the primary reasons Python is popular. I am definitely one of those that think indentation based structure is one of Python's best features. I do acknowledge that if you don't think that way, it can be major hassle, and I sympathize. ~Ethan~ From j.reid at mail.cryst.bbk.ac.uk Fri Nov 5 15:39:12 2010 From: j.reid at mail.cryst.bbk.ac.uk (John Reid) Date: Fri, 05 Nov 2010 19:39:12 +0000 Subject: *** glibc detected *** gdb: malloc(): smallbin double linked list Message-ID: Hi, I've compiled Python 2.7 (r27:82500, Nov 2 2010, 09:00:37) [GCC 4.4.3] on linux2 with the following configure options ./configure --prefix=/home/john/local/python-dbg --with-pydebug I've installed numpy and some other packages but when I try to run my extension code under gdb I get the errors below. Does anyone have any ideas of how to track down what's happening here? I imagine I've misconfigured something somewhere. Is valgrind the answer? Thanks, John. *** glibc detected *** gdb: malloc(): smallbin double linked list corrupted: 0x0000000004de7ad0 *** ======= Backtrace: ========= /lib/libc.so.6(+0x775b6)[0x7f0a252215b6] /lib/libc.so.6(+0x7b8e9)[0x7f0a252258e9] /lib/libc.so.6(__libc_malloc+0x6e)[0x7f0a2522658e] gdb(xmalloc+0x18)[0x45bc38] gdb[0x476df1] gdb[0x474c9b] gdb[0x474ee8] gdb(execute_command+0x2dd)[0x458d1d] gdb(catch_exception+0x50)[0x535510] gdb[0x4b5191] gdb(interp_exec+0x17)[0x535637] gdb(mi_cmd_interpreter_exec+0x6c)[0x4b9adc] gdb[0x4ba71a] gdb(catch_exception+0x50)[0x535510] gdb(mi_execute_command+0x97)[0x4ba137] gdb[0x53a0f8] gdb(gdb_do_one_event+0x29a)[0x53b38a] gdb(catch_errors+0x5b)[0x53531b] gdb(start_event_loop+0x1e)[0x53a90e] gdb[0x44f619] gdb(catch_errors+0x5b)[0x53531b] gdb[0x450166] gdb(catch_errors+0x5b)[0x53531b] gdb(gdb_main+0x24)[0x44f554] gdb(main+0x2e)[0x44f51e] /lib/libc.so.6(__libc_start_main+0xfd)[0x7f0a251c8c4d] gdb[0x44f429] ======= Memory map: ======== 00400000-00818000 r-xp 00000000 08:05 4832730 /usr/bin/gdb 00a17000-00a18000 r--p 00417000 08:05 4832730 /usr/bin/gdb 00a18000-00a25000 rw-p 00418000 08:05 4832730 /usr/bin/gdb 00a25000-00a43000 rw-p 00000000 00:00 0 0287f000-0b920000 rw-p 00000000 00:00 0 [heap] 7f0a1c000000-7f0a1c021000 rw-p 00000000 00:00 0 7f0a1c021000-7f0a20000000 ---p 00000000 00:00 0 7f0a20fc0000-7f0a20fd6000 r-xp 00000000 08:05 3498245 /lib/libgcc_s.so.1 7f0a20fd6000-7f0a211d5000 ---p 00016000 08:05 3498245 /lib/libgcc_s.so.1 7f0a211d5000-7f0a211d6000 r--p 00015000 08:05 3498245 /lib/libgcc_s.so.1 7f0a211d6000-7f0a211d7000 rw-p 00016000 08:05 3498245 /lib/libgcc_s.so.1 7f0a211fd000-7f0a21211000 r--p 000dc000 08:05 4825848 /usr/lib/libstdc++.so.6.0.13 7f0a21211000-7f0a21218000 r--p 00018000 08:05 4841756 /usr/lib/debug/lib/librt-2.11.1.so 7f0a21218000-7f0a21226000 r--p 00001000 08:05 4841756 /usr/lib/debug/lib/librt-2.11.1.so 7f0a21226000-7f0a2123e000 r--p 000bc000 08:05 4653290 /home/john/Dev/MyProjects/Bio/MotifSearch/python/stempy/_debug/libboost_python.so.1.44.0 7f0a2123e000-7f0a21287000 r--p 003dd000 08:05 4653290 /home/john/Dev/MyProjects/Bio/MotifSearch/python/stempy/_debug/libboost_python.so.1.44.0 7f0a21287000-7f0a21299000 r--p 00425000 08:05 4653290 /home/john/Dev/MyProjects/Bio/MotifSearch/python/stempy/_debug/libboost_python.so.1.44.0 7f0a21299000-7f0a213e7000 r--p 0018c000 08:05 4653290 /home/john/Dev/MyProjects/Bio/MotifSearch/python/stempy/_debug/libboost_python.so.1.44.0 7f0a213e7000-7f0a2152f000 r--p 0207c000 08:05 4653324 /home/john/Dev/MyProjects/Bio/MotifSearch/python/stempy/_debug/_stempy.so 7f0a2152f000-7f0a22027000 r--p 01585000 08:05 4653324 /home/john/Dev/MyProjects/Bio/MotifSearch/python/stempy/_debug/_stempy.so 7f0a22027000-7f0a22400000 rw-p 00000000 00:00 0 7f0a22408000-7f0a224d1000 r--p 00315000 08:05 4653290 /home/john/Dev/MyProjects/Bio/MotifSearch/python/stempy/_debug/libboost_python.so.1.44.0 7f0a224d1000-7f0a224ff000 r--p 002e8000 08:05 4653290 /home/john/Dev/MyProjects/Bio/MotifSearch/python/stempy/_debug/libboost_python.so.1.44.0 7f0a224ff000-7f0a22526000 r--p 00038000 08:05 4653310 /home/john/Dev/MyProjects/Bio/MotifSearch/python/stempy/_debug/myrrh_pylib-d 7f0a22526000-7f0a2259c000 r--p 01510000 08:05 4653324 /home/john/Dev/MyProjects/Bio/MotifSearch/python/stempy/_debug/_stempy.so 7f0a2259c000-7f0a2280c000 r--p 012a0000 08:05 4653324 /home/john/Dev/MyProjects/Bio/MotifSearch/python/stempy/_debug/_stempy.so 7f0a2280c000-7f0a2343f000 rw-p 00000000 00:00 0 7f0a23443000-7f0a2344c000 r--p 0001a000 08:05 6169643 /home/john/local/python-dbg/lib/python2.7/lib-dynload/datetime.so 7f0a2344c000-7f0a2345c000 r--p 002d9000 08:05 4653290 /home/john/Dev/MyProjects/Bio/MotifSearch/python/stempy/_debug/libboost_python.so.1.44.0 7f0a2345c000-7f0a23461000 r--p 0005e000 08:05 4653310 /home/john/Dev/MyProjects/Bio/MotifSearch/python/stempy/_debug/myrrh_pylib-d 7f0a23461000-7f0a23477000 r--p 0001f000 08:05 4653310 /home/john/Dev/MyProjects/Bio/MotifSearch/python/stempy/_debug/myrrh_pylib-d 7f0a23477000-7f0a2347d000 r--p 00004000 08:05 4653095 /home/john/Dev/MyProjects/Bio/MotifSearch/python/stempy/_debug/libboost_system.so.1.44.0 7f0a2347d000-7f0a2350c000 r--p 00757000 08:05 4653324 /home/john/Dev/MyProjects/Bio/MotifSearch/python/stempy/_debug/_stempy.so 7f0a2350c000-7f0a23555000 r--p 021c3000 08:05 4653324 /home/john/Dev/MyProjects/Bio/MotifSearch/python/stempy/_debug/_stempy.so 7f0a23555000-7f0a2355b000 r--p 00048000 08:05 6169627 /home/john/local/python-dbg/lib/python2.7/lib-dynload/_ctypes.so 7f0a2355b000-7f0a2356f000 r--p 0002d000 08:05 6169627 /home/john/local/python-dbg/lib/python2.7/lib-dynload/_ctypes.so 7f0a2356f000-7f0a23575000 r--p 000b1000 08:05 3489898 /home/john/local/python-dbg/lib/python2.7/site-packages/numpy-1.5.1rc1-py2.7-linux-x86_64.egg/numpy/random/mtrand.so 7f0a23575000-7f0a2357c000 r--p 000ab000 08:05 3489898 /home/john/local/python-dbg/lib/python2.7/site-packages/numpy-1.5.1rc1-py2.7-linux-x86_64.egg/numpy/random/mtrand.so 7f0a2357c000-7f0a2358d000 r--p 0009b000 08:05 3489898 /home/john/local/python-dbg/lib/python2.7/site-packages/numpy-1.5.1rc1-py2.7-linux-x86_64.egg/numpy/random/mtrand.so 7f0a2358d000-7f0a2359b000 r--p 000dd000 08:05 4827887 /usr/lib/libgfortran.so.3.0.0 7f0a2359b000-7f0a235ac000 r--p 00416000 08:05 6709644 /home/john/local/python-dbg/lib/python2.7/site-packages/numpy-1.5.1rc1-py2.7-linux-x86_64.egg/numpy/linalg/lapack_lite.so 7f0a235ac000-7f0a23668000 rw-p 00000000 00:00 0 7f0a23668000-7f0a2366d000 r--p 00033000 08:05 3180358 /home/john/local/python-dbg/lib/python2.7/site-packages/numpy-1.5.1rc1-py2.7-linux-x86_64.egg/numpy/core/scalarmath.so 7f0a2366d000-7f0a23678000 r--p 00052000 08:05 3180358 /home/john/local/python-dbg/lib/python2.7/site-packages/numpy-1.5.1rc1-py2.7-linux-x86_64.egg/numpy/core/scalarmath.so 7f0a23678000-7f0a2367d000 r--p 0004c000 08:05 3180358 /home/john/local/python-dbg/lib/python2.7/site-packages/numpy-1.5.1rc1-py2.7-linux-x86_64.egg/numpy/core/scalarmath.so 7f0a2367d000-7f0a23690000 r--p 00039000 08:05 3180358 /home/john/local/python-dbg/lib/python2.7/site-packages/numpy-1.5.1rc1-py2.7-linux-x86_64.egg/numpy/core/scalarmath.so 7f0a23690000-7f0a23698000 r--p 0001b000 08:05 6169649 /home/john/local/python-dbg/lib/python2.7/lib-dynload/cPickle.so 7f0a23698000-7f0a236a7000 r--p 004fd000 08:05 3180355 /home/john/local/python-dbg/lib/python2.7/site-packages/numpy-1.5.1rc1-py2.7-linux-x86_64.egg/numpy/core/_dotblas.so 7f0a236a7000-7f0a2374f000 rw-p 00000000 00:00 0 7f0a2374f000-7f0a2375a000 r--p 0001b000 08:05 3180353 /home/john/local/python-dbg/lib/python2.7/site-packages/numpy-1.5.1rc1-py2.7-linux-x86_64.egg/numpy/core/_sort.so 7f0a2375a000-7f0a23762000 r--p 00065000 08:05 3180320 /home/john/local/python-dbg/lib/python2.7/site-packages/numpy-1.5.1rc1-py2.7-linux-x86_64.egg/numpy/core/umath.so 7f0a23762000-7f0a23774000 r--p 000ae000 08:05 3180320 /home/john/local/python-dbg/lib/python2.7/site-packages/numpy-1.5.1rc1-py2.7-linux-x86_64.egg/numpy/core/umath.so 7f0a23774000-7f0a2377a000 r--p 000a9000 08:05 3180320 /home/john/local/python-dbg/lib/python2.7/site-packages/numpy-1.5.1rc1-py2.7-linux-x86_64.egg/numpy/core/umath.so 7f0a2377a000-7f0a23780000 r--p 000a4000 08:05 3180320 /home/john/local/python-dbg/lib/python2.7/site-packages/numpy-1.5.1rc1-py2.7-linux-x86_64.egg/numpy/core/umath.so 7f0a23780000-7f0a237b4000 r--p 00071000 08:05 3180320 /home/john/local/python-dbg/lib/python2.7/site-packages/numpy-1.5.1rc1-py2.7-linux-x86_64.egg/numpy/core/umath.so 7f0a237b4000-7f0a23881000 rw-p 00000000 00:00 0 7f0a23883000-7f0a23888000 r--p 0000f000 08:05 3146117 /home/john/local/python-dbg/lib/python2.7/site-packages/numpy-1.5.1rc1-py2.7-linux-x86_64.egg/numpy/fft/fftpack_lite.so 7f0a23888000-7f0a23897000 r--p 000b9000 08:05 3180362 /home/john/local/python-dbg/lib/python2.7/site-packages/numpy-1.5.1rc1-py2.7-linux-x86_64.egg/numpy/core/multiarray.so 7f0a23897000-7f0a238a1000 r--p 00118000 08:05 3180362 /home/john/local/python-dbg/lib/python2.7/site-packages/numpy-1.5.1rc1-py2.7-linux-x86_64.egg/numpy/core/multiarray.so 7f0a238a1000-7f0a238ae000 r--p 0010c000 08:05 3180362 /home/john/local/python-dbg/lib/python2.7/site-packages/numpy-1.5.1rc1-py2.7-linux-x86_64.egg/numpy/core/multiarray.so 7f0a238ae000-7f0a238e8000 r--p 000d3000 08:05 3180362 /home/john/local/python-dbg/lib/python2.7/site-packages/numpy-1.5.1rc1-py2.7-linux-x86_64.egg/numpy/core/multiarray.so 7f0a238e8000-7f0a23aa4000 r--p 004e2000 08:05 4841832 /usr/lib/debug/lib/libc-2.11.1.so 7f0a23aa4000-7f0a23b03000 r--p 0069d000 08:05 4841832 /usr/lib/debug/lib/libc-2.11.1.so 7f0a23b03000-7f0a23b27000 r--p 004bf000 08:05 4841832 /usr/lib/debug/lib/libc-2.11.1.so 7f0a23b27000-7f0a23bc3000 r--p 00424000 08:05 4841832 /usr/lib/debug/lib/libc-2.11.1.so 7f0a23bc3000-7f0a23c3e000 r--p 003aa000 08:05 4841832 /usr/lib/debug/lib/libc-2.11.1.so 7f0a23c3e000-7f0a23fca000 r--p 0001f000 08:05 4841832 /usr/lib/debug/lib/libc-2.11.1.so 7f0a23fca000-7f0a240f6000 rw-p 00000000 00:00 0 7f0a240f8000-7f0a24118000 r--p 00121000 08:05 3180362 /home/john/local/python-dbg/lib/python2.7/site-packages/numpy-1.5.1rc1-py2.7-linux-x86_64.egg/numpy/core/multiarray.so 7f0a24118000-7f0a24129000 r--p 0000e000 08:05 4950482 /usr/lib/debug/lib/libz.so.1.2.3.3 7f0a24129000-7f0a24133000 r--p 00000000 08:05 4950482 /usr/lib/debug/lib/libz.so.1.2.3.3 7f0a24133000-7f0a24154000 r--p 00155000 08:05 2900170 /lib/libc-2.11.1.so 7f0a24154000-7f0a241a2000 r--p 00061000 08:05 4841716 /usr/lib/debug/lib/libm-2.11.1.so 7f0a241a2000-7f0a241a8000 r--p 0005c000 08:05 4841716 /usr/lib/debug/lib/libm-2.11.1.so 7f0a241a8000-7f0a241bb000 r--p 0004a000 08:05 4841716 /usr/lib/debug/lib/libm-2.11.1.so 7f0a241bb000-7f0a241ed000 r--p 00007000 08:05 4841716 /usr/lib/debug/lib/libm-2.11.1.so 7f0a241ed000-7f0a241f4000 r-xp 00000000 08:05 2900165 /lib/libthread_db-1.0.so 7f0a241f4000-7f0a243f3000 ---p 00007000 08:05 2900165 /lib/libthread_db-1.0.so 7f0a243f3000-7f0a243f4000 r--p 00006000 08:05 2900165 /lib/libthread_db-1.0.so 7f0a243f4000-7f0a243f5000 rw-p 00007000 08:05 2900165 /lib/libthread_db-1.0.so 7f0a243f9000-7f0a2440c000 r--p 00038000 08:05 4841716 /usr/lib/debug/lib/libm-2.11.1.so 7f0a2440c000-7f0a2441b000 r--p 00000000 08:05 4841839 /usr/lib/debug/lib/libdl-2.11.1.so 7f0a2441b000-7f0a24431000 r--p 00078000 08:05 4841828 /usr/lib/debug/lib/libpthread-2.11.1.so 7f0a24431000-7f0a24439000 r--p 00071000 08:05 4841828 /usr/lib/debug/lib/libpthread-2.11.1.so 7f0a24439000-7f0a2444c000 r--p 0005f000 08:05 4841828 /usr/lib/debug/lib/libpthread-2.11.1.so 7f0a2444c000-7f0a2445c000 r--p 00050000 08:05 4841828 /usr/lib/debug/lib/libpthread-2.11.1.so 7f0a2445c000-7f0a244a9000 r--p 00004000 08:05 4841828 /usr/lib/debug/lib/libpthread-2.11.1.so 7f0a244a9000-7f0a244cc000 r--p 00063000 08:05 4841753 /usr/lib/debug/lib/ld-2.11.1.so 7f0a244cc000-7f0a244d6000 r--p 00085000 08:05 4841753 /usr/lib/debug/lib/ld-2.11.1.so 7f0a244d6000-7f0a244f3000 r--p 001be000 08:05 221210 /home/john/local/python-dbg/bin/python2.7 7f0a244f3000-7f0a24537000 r--p 00370000 08:05 221210 /home/john/local/python-dbg/bin/python2.7 7f0a24537000-7f0a2453e000 r--p 003b3000 08:05 221210 /home/john/local/python-dbg/bin/python2.7 7f0a2453e000-7f0a2455c000 r--p 00353000 08:05 221210 /home/john/local/python-dbg/bin/python2.7 7f0a2455c000-7f0a24583000 r--p 0032d000 08:05 221210 /home/john/local/python-dbg/bin/python2.7 7f0a24583000-7f0a24591000 r--p 00320000 08:05 221210 /home/john/local/python-dbg/bin/python2.7 7f0a24591000-7f0a2468b000 r--p 00227000 08:05 221210 /home/john/local/python-dbg/bin/python2.7 7f0a2468b000-7f0a247a8000 rw-p 00000000 00:00 0 7f0a247a8000-7f0a247aa000 r-xp 00000000 08:05 2900166 /lib/libutil-2.11.1.so 7f0a247aa000-7f0a249a9000 ---p 00002000 08:05 2900166 /lib/libutil-2.11.1.so 7f0a249a9000-7f0a249aa000 r--p 00001000 08:05 2900166 /lib/libutil-2.11.1.so 7f0a249aa000-7f0a249ab000 rw-p 00002000 08:05 2900166 /lib/libutil-2.11.1.so 7f0a249ab000-7f0a249c3000 r-xp 00000000 08:05 2900168 /lib/libpthread-2.11.1.so 7f0a249c3000-7f0a24bc2000 ---p 00018000 08:05 2900168 /lib/libpthread-2.11.1.so 7f0a24bc2000-7f0a24bc3000 r--p 00017000 08:05 2900168 /lib/libpthread-2.11.1.so 7f0a24bc3000-7f0a24bc4000 rw-p 00018000 08:05 2900168 /lib/libpthread-2.11.1.so 7f0a24bc4000-7f0a24bc8000 rw-p 00000000 00:00 0 7f0a24bc8000-7f0a24d30000 r-xp 00000000 08:05 2901949 /lib/libcrypto.so.0.9.8 7f0a24d30000-7f0a24f2f000 ---p 00168000 08:05 2901949 /lib/libcrypto.so.0.9.8 7f0a24f2f000-7f0a24f3c000 r--p 00167000 08:05 2901949 /lib/libcrypto.so.0.9.8 7f0a24f3c000-7f0a24f54000 rw-p 00174000 08:05 2901949 /lib/libcrypto.so.0.9.8 7f0a24f54000-7f0a24f58000 rw-p 00000000 00:00 0 7f0a24f58000-7f0a24fa3000 r-xp 00000000 08:05 2901950 /lib/libssl.so.0.9.8 7f0a24fa3000-7f0a251a2000 ---p 0004b000 08:05 2901950 /lib/libssl.so.0.9.8 7f0a251a2000-7f0a251a4000 r--p 0004a000 08:05 2901950 /lib/libssl.so.0.9.8 7f0a251a4000-7f0a251a9000 rw-p 0004c000 08:05 2901950 /lib/libssl.so.0.9.8 7f0a251a9000-7f0a251aa000 rw-p 00000000 00:00 0 7f0a251aa000-7f0a25324000 r-xp 00000000 08:05 2900170 /lib/libc-2.11.1.so 7f0a25324000-7f0a25523000 ---p 0017a000 08:05 2900170 /lib/libc-2.11.1.so 7f0a25523000-7f0a25527000 r--p 00179000 08:05 2900170 /lib/libc-2.11.1.so 7f0a25527000-7f0a25528000 rw-p 0017d000 08:05 2900170 /lib/libc-2.11.1.so 7f0a25528000-7f0a2552d000 rw-p 00000000 00:00 0 7f0a2552d000-7f0a2552f000 r-xp 00000000 08:05 2900174 /lib/libdl-2.11.1.so 7f0a2552f000-7f0a2572f000 ---p 00002000 08:05 2900174 /lib/libdl-2.11.1.so 7f0a2572f000-7f0a25730000 r--p 00002000 08:05 2900174 /lib/libdl-2.11.1.so 7f0a25730000-7f0a25731000 rw-p 00003000 08:05 2900174 /lib/libdl-2.11.1.so 7f0a25731000-7f0a25757000 r-xp 00000000 08:05 2900004 /lib/libexpat.so.1.5.2 7f0a25757000-7f0a25957000 ---p 00026000 08:05 2900004 /lib/libexpat.so.1.5.2 7f0a25957000-7f0a25959000 r--p 00026000 08:05 2900004 /lib/libexpat.so.1.5.2 7f0a25959000-7f0a2595a000 rw-p 00028000 08:05 2900004 /lib/libexpat.so.1.5.2 7f0a2595a000-7f0a25b98000 r-xp 00000000 08:05 4827971 /usr/lib/libpython2.6.so.1.0 7f0a25b98000-7f0a25d98000 ---p 0023e000 08:05 4827971 /usr/lib/libpython2.6.so.1.0 7f0a25d98000-7f0a25d9a000 r--p 0023e000 08:05 4827971 /usr/lib/libpython2.6.so.1.0 7f0a25d9a000-7f0a25dfc000 rw-p 00240000 08:05 4827971 /usr/lib/libpython2.6.so.1.0 7f0a25dfc000-7f0a25e0b000 rw-p 00000000 00:00 0 7f0a25e0b000-7f0a25e8d000 r-xp 00000000 08:05 2900011 /lib/libm-2.11.1.so 7f0a25e8d000-7f0a2608c000 ---p 00082000 08:05 2900011 /lib/libm-2.11.1.so 7f0a2608c000-7f0a2608d000 r--p 00081000 08:05 2900011 /lib/libm-2.11.1.so 7f0a2608d000-7f0a2608e000 rw-p 00082000 08:05 2900011 /lib/libm-2.11.1.so 7f0a2608e000-7f0a260a4000 r-xp 00000000 08:05 2900157 /lib/libz.so.1.2.3.3 7f0a260a4000-7f0a262a3000 ---p 00016000 08:05 2900157 /lib/libz.so.1.2.3.3 7f0a262a3000-7f0a262a4000 r--p 00015000 08:05 2900157 /lib/libz.so.1.2.3.3 7f0a262a4000-7f0a262a5000 rw-p 00016000 08:05 2900157 /lib/libz.so.1.2.3.3 7f0a262a5000-7f0a262e3000 r-xp 00000000 08:05 3498266 /lib/libncurses.so.5.7 7f0a262e3000-7f0a264e3000 ---p 0003e000 08:05 3498266 /lib/libncurses.so.5.7 7f0a264e3000-7f0a264e7000 r--p 0003e000 08:05 3498266 /lib/libncurses.so.5.7 7f0a264e7000-7f0a264e8000 rw-p 00042000 08:05 3498266 /lib/libncurses.so.5.7 7f0a264e8000-7f0a26521000 r-xp 00000000 08:05 3498308 /lib/libreadline.so.6.1 7f0a26521000-7f0a26720000 ---p 00039000 08:05 3498308 /lib/libreadline.so.6.1 7f0a26720000-7f0a26722000 r--p 00038000 08:05 3498308 /lib/libreadline.so.6.1 7f0a26722000-7f0a26728000 rw-p 0003a000 08:05 3498308 /lib/libreadline.so.6.1 7f0a26728000-7f0a26729000 rw-p 00000000 00:00 0 7f0a26729000-7f0a26749000 r-xp 00000000 08:05 2900131 /lib/ld-2.11.1.so 7f0a26749000-7f0a2674f000 r--p 00013000 08:05 6169622 /home/john/local/python-dbg/lib/python2.7/lib-dynload/itertools.so 7f0a2674f000-7f0a26758000 r--p 0004c000 08:05 4841753 /usr/lib/debug/lib/ld-2.11.1.so 7f0a26758000-7f0a267a4000 r--p 00001000 08:05 4841753 /usr/lib/debug/lib/ld-2.11.1.so 7f0a267a4000-7f0a26857000 rw-p 00000000 00:00 0 7f0a26857000-7f0a26858000 r--p 00000000 08:05 5792628 /usr/share/locale-langpack/en_GB/LC_MESSAGES/libc.mo 7f0a26858000-7f0a268da000 rw-p 00000000 00:00 0 7f0a268da000-7f0a26919000 r--p 00000000 08:05 4874536 /usr/lib/locale/en_GB.utf8/LC_CTYPE 7f0a26919000-7f0a26920000 rw-p 00000000 00:00 0 7f0a26922000-7f0a26928000 r--p 0005e000 08:05 4841753 /usr/lib/debug/lib/ld-2.11.1.so 7f0a26928000-7f0a26933000 r--p 00054000 08:05 4841753 /usr/lib/debug/lib/ld-2.11.1.so 7f0a26935000-7f0a26938000 rw-p 00000000 00:00 0 7f0a26938000-7f0a2693e000 r--p 00000000 08:05 5792627 /usr/share/locale-langpack/en_GB/LC_MESSAGES/gdb.mo 7f0a2693e000-7f0a26945000 r--s 00000000 08:05 5417899 /usr/lib/gconv/gconv-modules.cache 7f0a26945000-7f0a26946000 r--p 00000000 08:05 4875999 /usr/lib/locale/en_GB.utf8/LC_MESSAGES/SYS_LC_MESSAGES 7f0a26946000-7f0a26948000 rw-p 00000000 00:00 0 7f0a26948000-7f0a26949000 r--p 0001f000 08:05 2900131 /lib/ld-2.11.1.so 7f0a26949000-7f0a2694a000 rw-p 00020000 08:05 2900131 /lib/ld-2.11.1.so 7f0a2694a000-7f0a2694b000 rw-p 00000000 00:00 0 7ffff92d6000-7ffff92f8000 rw-p 00000000 00:00 0 [stack] 7ffff93ff000-7ffff9400000 r-xp 00000000 00:00 0 [vdso] ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall] From moura.mario at gmail.com Fri Nov 5 15:40:35 2010 From: moura.mario at gmail.com (macm) Date: Fri, 5 Nov 2010 12:40:35 -0700 (PDT) Subject: How convert list to nested dictionary? References: <940876cd-2546-4673-aef4-ba11b4156287@fv1g2000vbb.googlegroups.com> <878w18kbwl.fsf@gmail.com> <9c917109-92fe-4d1f-9310-b62ff64693f5@k11g2000vbf.googlegroups.com> <471f4f12-f7c4-437d-b435-989bbd8e64c1@o15g2000prh.googlegroups.com> Message-ID: Ok. Done >>> def appendNested(nest, path, val): ... nest2 = nest ... for key in path[:-1]: ... nest2 = nest2[key] ... nest2[path[-1]].append(val) ... return nest ... >>> >>> l = ['k1','k2','k3','k4','k5'] >>> ndict = reduce(lambda x,y: {y:x}, reversed(l), {'/':[1,2,3]}) >>> x = l + list('/') >>> print appendNested(ndict, x, 5) {'k1': {'k2': {'k3': {'k4': {'k5': {'/': [1, 2, 3, 5]}}}}}} >>> I need make lambda but now is friday night here and I guess I will go drink a beer or three! Cheers! macm On 5 nov, 16:51, macm wrote: > Hi Peter > > Thanks a lot for your tips and codes, > > Cake Recipes are good to learn! So I post just basic issues. > > Hopping a good soul like you can help me! > > But I am still learning... : ) > > Best Regards > > macm > > On 5 nov, 15:40, Peter Otten <__pete... at web.de> wrote: > > > macm wrote: > > > thanks a lot all. All solutions work fine. > > > > while I am doing my home work. > > > Reading "Learning Python" and much more. > > > > Let me ask again to close my doubts: > > > >>>> l = ['k1', 'k2', 'k3', 'k4', 'k5'] > > >>>> d = reduce(lambda x,y: {y:x}, reversed(l), {'/':[1,2,3]}) > > >>>> d > > > {'k1': {'k2': {'k3': {'k4': {'k5': {'/': [1, 2, 3]}}}}}} > > >>>> d['k1']['k2']['k3']['k4']['k5'] > > > {'/': [1, 2, 3]} > > >>>> d['k1']['k2']['k3']['k4']['k5']['/'] > > > [1, 2, 3] > > > > now I want generate the "index" to access the element. > > > > ==> d['k1']['k2']['k3']['k4']['k5']['/'] from l > > > > So again I have only. > > >>>> l = ['k1', 'k2', 'k3', 'k4', 'k5'] > > > > z = ?magicCode? > > > > z = d['k1']['k2']['k3']['k4']['k5']['/'] > > > You'll eventually have to start and write your first line of code. Why not > > doing it right now? It is sure more rewarding than copying other people's > > canned solutions and it can even be fun. > > > Peter > > From msarro at gmail.com Fri Nov 5 15:44:58 2010 From: msarro at gmail.com (Matty Sarro) Date: Fri, 5 Nov 2010 15:44:58 -0400 Subject: Silly newbie question - Carrot character (^) In-Reply-To: References: <8jiqhpFmj3U2@mid.individual.net> Message-ID: It's ok, people who refer to a labret piercing as a "la-BRAY" piercing are also incorrect. It's pronounced lab-RET, as its base word is the latin "labretta." French as a language shall doom us all :) On Fri, Nov 5, 2010 at 2:54 PM, Philip Semanchuk wrote: > > On Nov 5, 2010, at 12:43 PM, Peter Pearson wrote: > > > On Fri, 5 Nov 2010 10:12:05 -0400, Philip Semanchuk wrote: > >> > >> BTW the more common name for this character is caret (ka-RAY). > > > > Yes, it's caret, but no, it's KA-rit, almost the same as > > carrot. It's straight from Latin, with no detour through > > French. > > This I did not know (obviously). Thanks. I knew all those years of studying > French would ruin me somehow. > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Fri Nov 5 15:52:44 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 05 Nov 2010 14:52:44 -0500 Subject: Using %x to format number to hex and number of digits Message-ID: <4CD4608C.3040803@tim.thechases.com> On 11/05/10 13:23, Matty Sarro wrote: >> I'm currently trying to convert a digit from decimal to hex, >> however I need the full 4 digit hex form. Python appears to >> be shortening the form. >> Example: >> >> num = 10 >> num = "%x"%(num) >> print(num) >> >>>> a >> >> num = 10 >> num = "%#x"%(num) >> print(num) >> >>>> 0xa >> >> I need it to output as 0x0a, and the exercise is requiring >> me to use %x to format the string. Any help would be >> appreciated. Though it feels hokey to me, using "%#04x" % 10 works for me. The "#" adds the "0x" prefix (the "alternate form"), the "0" pads with zeros, and the "4" is really "2 places + 2 characters for the prefix". So if you want 4 hex characters + the 2 prefix characters, you'd use "%#06x". IMHO, this would make more sense if it didn't take the 2-character prefix into consideration (being written as "%#02x" for a byte or "%#04x" for a short), but it's not really a burr in my saddle. -tkc From ian.g.kelly at gmail.com Fri Nov 5 15:56:52 2010 From: ian.g.kelly at gmail.com (Ian) Date: Fri, 5 Nov 2010 12:56:52 -0700 (PDT) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <87r5f13ug3.fsf.mdw@metalzone.distorted.org.uk> <4cd3df64$0$30004$c3e8da3$5496439d@news.astraweb.com> <4cd44e7a$0$1610$742ec2ed@news.sonic.net> Message-ID: On Nov 5, 12:35?pm, John Nagle wrote: > ? ? INTERLISP's editor allowed the user to select a block of > LISP code and make it into a function. ?The selected block > would be analyzed to determine which local variables it referenced, > and a new function would be created with those parameters. ?The > block of code at the original point would then be replaced by > a call to the function. > > ? ? Today's editors are too dumb to do that right. ?They're text > editors with the illusion of knowing something about the language, > not language editors which also format text. Eclipse does that. Visual Studio does that. As for Python, I hear that Eric IDE has a plugin to do that, although I haven't tested it myself. Cheers, Ian From arnodel at gmail.com Fri Nov 5 15:59:17 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Fri, 05 Nov 2010 19:59:17 +0000 Subject: How convert list to nested dictionary? References: <940876cd-2546-4673-aef4-ba11b4156287@fv1g2000vbb.googlegroups.com> <878w18kbwl.fsf@gmail.com> Message-ID: <874obvk0dm.fsf@gmail.com> Peter Otten <__peter__ at web.de> writes: > Boris Borcic wrote: > >> Arnaud Delobelle wrote: >>> macm writes: >>> >>>> Hi Folks >>>> >>>> How convert list to nested dictionary? >>>> >>>>>>> l >>>> ['k1', 'k2', 'k3', 'k4', 'k5'] >>>>>>> result >>>> {'k1': {'k2': {'k3': {'k4': {'k5': {}}}}}} >>>> >>>> Regards >>>> >>>> macm >>> >>> reduce(lambda x,y: {y:x}, reversed(l), {}) >>> >> >> d={} >> while L : d={L.pop():d} > > Iterating over the keys in normal order: > >>>> keys = "abcde" >>>> d = outer = {} >>>> for key in keys: > ... outer[key] = inner = {} > ... outer = inner > ... >>>> d > {'a': {'b': {'c': {'d': {'e': {}}}}}} > > The "functional" variant: > >>>> d = {} >>>> reduce(lambda outer, key: outer.setdefault(key, {}), "abcde", d) > {} >>>> d > {'a': {'b': {'c': {'d': {'e': {}}}}}} > > In a single expression if you are willing to pay the price: > >>>> reduce(lambda (accu, outer), key: (accu, outer.setdefault(key, {})), > "abcde", ({},)*2)[0] > {'a': {'b': {'c': {'d': {'e': {}}}}}} > > Peter The most basic functional version: >>> f = lambda l: {l[0]: f(l[1:])} if l else {} >>> f('abcde') {'a': {'b': {'c': {'d': {'e': {}}}}}} -- Arnaud From tjreedy at udel.edu Fri Nov 5 16:05:54 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 05 Nov 2010 16:05:54 -0400 Subject: Final state of underlying sequence in islice In-Reply-To: <4b599f9b-5d99-4a9a-85a8-4ccba233bdc4@35g2000prb.googlegroups.com> References: <4b599f9b-5d99-4a9a-85a8-4ccba233bdc4@35g2000prb.googlegroups.com> Message-ID: On 11/5/2010 4:58 AM, Raymond Hettinger wrote: >> Shashank Singh wrote: >> >>> Are there any promises made with regard to final state of the underlying >>> sequence that islice slices? > > Currently, there are no promises or guarantees about the final state > of the iterator. I interpret the current doc statement as a promise that becomes ambiguous when step > 1. > To the extent the pure Python version in the docs differs from the > CPython implementation in this regard, it is an accidental > implementation detail. > > That being said, we could introduce some guarantees (earliest possible > stop point, latest possible stop point, or decide to leave it > undefined). In between earliest and latest, depending on the stop value, is another possibility. If it is relatively easy to patch the C version to match the Python version (earliest stop point) I would go for that. It is easy to skip over and ignore more items, impossible to go back. -- Terry Jan Reedy From usenet-nospam at seebs.net Fri Nov 5 16:09:37 2010 From: usenet-nospam at seebs.net (Seebs) Date: 05 Nov 2010 20:09:37 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> Message-ID: On 2010-11-05, Grant Edwards wrote: > On 2010-11-05, Seebs wrote: >> On 2010-11-05, Emile van Sebille wrote: >>> So, which of your tools are you married to that are causing your issues? >> Python. > I think you should quit using Python and choose a language that works > with whatever tools are causing all your white-space corruption > problems. Ahh, but that's the thing. I'm married to it -- there's existing projects I want to work on which are in Python. Anyway, it was a sort of frivolous answer, but it's ha-ha-only-serious; after all, there were no serious issues with any of these tools before. There's a saying a friend of mine has; "a lack of communication is never exclusively one party's fault." This applies, in many cases, to things like "issues" that occur when two programs clash in some aspect of their designs. In some cases, there might be a real and unambiguous standard to be violated. In others, though, you can have a problem which arises from a clash in expectations between two programs, either of which is fine on its own. There is a clash between Python and the whole category of things which sometimes lose whitespace. Because that category is reasonably large, and known to be large, and unlikely to vanish, many language designers choose to build their languages to be robust in the face of minor changes in whitespace. Python chose not to, and that is a source of conflicts. Were someone to invent a *new* text editor, which mangled whitespace, I would accuse it of being gratuitously incompatible with Python; I tend to regard compatibility, once you get past the standards, as a matter of temporal precedence. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From invalid at invalid.invalid Fri Nov 5 16:10:29 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 5 Nov 2010 20:10:29 +0000 (UTC) Subject: Using %x to format number to hex and number of digits References: Message-ID: On 2010-11-05, Tim Chase wrote: > On 11/05/10 13:23, Matty Sarro wrote: >>> I'm currently trying to convert a digit from decimal to hex, >>> however I need the full 4 digit hex form. Python appears to >>> be shortening the form. >>> Example: >>> >>> num = 10 >>> num = "%x"%(num) >>> print(num) >>> >>>>> a >>> >>> num = 10 >>> num = "%#x"%(num) >>> print(num) >>> >>>>> 0xa >>> >>> I need it to output as 0x0a, and the exercise is requiring >>> me to use %x to format the string. Any help would be >>> appreciated. > > Though it feels hokey to me, using > > "%#04x" % 10 > > works for me. I think "0x%02x" % 10 is a bit more readable, but it accomplishes the same thing -- you just don't have to do the mental math to add the prefix width to the number of desired hex digits in the output. -- Grant Edwards grant.b.edwards Yow! Quick, sing me the at BUDAPEST NATIONAL ANTHEM!! gmail.com From usenet-nospam at seebs.net Fri Nov 5 16:10:43 2010 From: usenet-nospam at seebs.net (Seebs) Date: 05 Nov 2010 20:10:43 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> <4cd3de51$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-05, Ethan Furman wrote: > The verifiable benefit for me is ease of use, ease of thought, ease of > typing... I realize these are not benefits for everyone, but they are > for some -- and I would venture a guess that the ease of thought benefit > is one of the primary reasons Python is popular. I am definitely one of > those that think indentation based structure is one of Python's best > features. Could you explain more the "ease of thought" thing? I haven't yet noticed it, but it might be something to look out for as I get more experienced. It certainly sounds like something that would be a benefit. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Fri Nov 5 16:14:47 2010 From: usenet-nospam at seebs.net (Seebs) Date: 05 Nov 2010 20:14:47 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> Message-ID: On 2010-11-05, D'Arcy J.M. Cain wrote: > The simple fact is that the combination of your tools and Python is > broken. The combination of my tools and Python is not. That's lucky > for me since I really, really like IAS. That's unlucky for people who > have to work with tools that mangle code. But don't crusade to change > my language. Use Perl or C or even pybraces. No one is crusading to change Python, or even suggesting that it should be changed. > I am offering no solutions. Why would I since I don't see a problem? One of the things many people try to do is develop the ability to "see" problems that affect other people but possibly not themselves. This allows people to offer solutions to those problems, which is often viewed as a kind of contribution to a community. Certainly, it's more useful than posting nothing more than "that's not a problem for me." I can just see how well this attitude must work in other circumstances: Some Guy: Oh, *!@#. I think I just sprained my ankle. Darcy: I didn't. Some Guy: I don't think I can walk up these stairs. Darcy: I don't have a problem with stairs. Stop trying to change this path. It works fine. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From tjreedy at udel.edu Fri Nov 5 16:18:29 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 05 Nov 2010 16:18:29 -0400 Subject: Silly newbie question - Carrot character (^) In-Reply-To: References: Message-ID: On 11/5/2010 9:43 AM, Matty Sarro wrote: > Hey Everyone, > Just curious - I'm working on a program which includes a calculation of > a circle, and I found myself trying to use pi*radius^2, and getting > errors that data types float and int are unsupported for "^". Now, I > realized I was making the mistake of using '^' instead of "**". I've > corrected this and its now working. However, what exactly does ^ do? I > know its used in regular expressions but I can't seem to find anything > about using it as an operator. Sadly my google foo is failing since the > character gets filtered out. All such symbol questions are aswered (or should be) in PySymbols.html: https://code.google.com/p/xploro/downloads/detail?name=PySymbols.html -- Terry Jan Reedy From python at rcn.com Fri Nov 5 16:51:32 2010 From: python at rcn.com (Raymond Hettinger) Date: Fri, 5 Nov 2010 13:51:32 -0700 (PDT) Subject: Final state of underlying sequence in islice References: <4b599f9b-5d99-4a9a-85a8-4ccba233bdc4@35g2000prb.googlegroups.com> Message-ID: On Nov 5, 1:05?pm, Terry Reedy wrote: > > Currently, there are no promises or guarantees about the final state > > of the iterator. > > I interpret the current doc statement as a promise that becomes > ambiguous when step > 1. You may have missed my point. I wrote the tools, the docs, and the tests. If you interpret a "promise" in text, I can assure you it was not intended. The behavior *is* undefined because I never defined it. I'm happy to clarify the docs to make that explicit. Or I can alter the implementation a bit to make a guarantee if it looks like there is a good reason to do so. The OP doesn't have any use cases to light the way and I don't yet see any useful invariants that would arise out of either definition. And since the ambiguity only shows-up in a somewhat rare case, I'm inclined to just mark it as undefined. Raymond From tjreedy at udel.edu Fri Nov 5 16:51:33 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 05 Nov 2010 16:51:33 -0400 Subject: Compare source code In-Reply-To: <20101105153337.4871389b.darcy@druid.net> References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> <20101105153337.4871389b.darcy@druid.net> Message-ID: On 11/5/2010 3:33 PM, D'Arcy J.M. Cain wrote: > my language. Use Perl or C or even pybraces. http://timhatch.com/projects/pybraces/ "I work with a guy who hates Python's significant whitespace and wishes that he could just use curly braces." > I am offering no solutions. Except you just did ;-). And using a braces encoding makes it looks easier than I expected. -- Terry Jan Reedy From tjreedy at udel.edu Fri Nov 5 16:57:44 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 05 Nov 2010 16:57:44 -0400 Subject: decimal.py ver 2.6,2.7 not working with python 2.7 In-Reply-To: <954451.88002.qm@web114415.mail.gq1.yahoo.com> References: <954451.88002.qm@web114415.mail.gq1.yahoo.com> Message-ID: On 11/5/2010 3:14 PM, robert roze wrote: > Aha! yes, you figured it out. My PYTHONPATH env variable had an > old experiment in it, which happened to be called > numbers.py. Take it out, and decimal.py works fine. Python has a large test suite in Lib/test, which includes test_decimal.py. It is run daily on several machines, and must pass before any release. So a gross failure like an import failure is very likely due to a local cause. >>What does the following output for you?: >> >>import numbers >>print(numbers.__file__) >>print(dir(numbers)) These are good test steps for any gross module failure. -- Terry Jan Reedy From nobody at nowhere.com Fri Nov 5 17:21:19 2010 From: nobody at nowhere.com (Nobody) Date: Fri, 05 Nov 2010 21:21:19 +0000 Subject: Silly newbie question - Carrot character (^) References: Message-ID: On Fri, 05 Nov 2010 10:12:05 -0400, Philip Semanchuk wrote: > As others have said, ^ is for XOR. That's buried here in the > documentation: > http://docs.python.org/release/2.7/reference/... > > Not that I would have expected you to find it there since that's pretty > dense. In fact, older versions of the Python doc used to describe this > section as "for language lawyers" but I see they've changed that now. However, it's still written for language lawyers. IMHO, the lack of a reference manual for the language itself is a major hole in Python's documentation. From nobody at nowhere.com Fri Nov 5 17:30:17 2010 From: nobody at nowhere.com (Nobody) Date: Fri, 05 Nov 2010 21:30:17 +0000 Subject: *** glibc detected *** gdb: malloc(): smallbin double linked list References: Message-ID: On Fri, 05 Nov 2010 19:39:12 +0000, John Reid wrote: > I've compiled > Python 2.7 (r27:82500, Nov 2 2010, 09:00:37) [GCC 4.4.3] on linux2 > > with the following configure options > ./configure --prefix=/home/john/local/python-dbg --with-pydebug > > I've installed numpy and some other packages but when I try to run my > extension code under gdb I get the errors below. Does anyone have any > ideas of how to track down what's happening here? I imagine I've > misconfigured something somewhere. Is valgrind the answer? I imagine that your extension code is trashing the heap, in which case, valgrind is probably the answer. My first guess would be that something is writing to a heap block after it has been deallocated (possibly due to omitting a Py_INCREF). Of course, other causes are possible, but writing to deallocated memory is a common problem when writing extensions for languages with garbage collection. From philip at semanchuk.com Fri Nov 5 17:47:32 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Fri, 5 Nov 2010 17:47:32 -0400 Subject: Silly newbie question - Carrot character (^) In-Reply-To: References: Message-ID: <12EC562D-9970-42B3-A05B-7C37DBFDA0E7@semanchuk.com> On Nov 5, 2010, at 5:21 PM, Nobody wrote: > On Fri, 05 Nov 2010 10:12:05 -0400, Philip Semanchuk wrote: > >> As others have said, ^ is for XOR. That's buried here in the >> documentation: >> http://docs.python.org/release/2.7/reference/... >> >> Not that I would have expected you to find it there since that's pretty >> dense. In fact, older versions of the Python doc used to describe this >> section as "for language lawyers" but I see they've changed that now. > > However, it's still written for language lawyers. > > IMHO, the lack of a reference manual for the language itself is a major > hole in Python's documentation. I agree. From ldo at geek-central.gen.new_zealand Fri Nov 5 18:14:38 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 06 Nov 2010 11:14:38 +1300 Subject: ANN: PyQt v4.8.1 Released References: Message-ID: In message , ?????? ??????????? wrote: >>> PyQt is available under the GPL and a commercial license. >> >> Surely you mean ?proprietary? rather than ?commercial?. There is >> nothing about the GPL that prevents ?commercial? use. > > I think he means a license that *he* sells comercially :) Presumably that?s a proprietary licence. From usenet-nospam at seebs.net Fri Nov 5 18:51:10 2010 From: usenet-nospam at seebs.net (Seebs) Date: 05 Nov 2010 22:51:10 GMT Subject: Silly newbie question - Carrot character (^) References: Message-ID: On 2010-11-05, Nobody wrote: > However, it's still written for language lawyers. > IMHO, the lack of a reference manual for the language itself is a major > hole in Python's documentation. I'm a bit lost here. Could you highlight some of the differences between "a reference manual for the language itself" and "something written for language lawyers"? -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From ian.g.kelly at gmail.com Fri Nov 5 18:52:18 2010 From: ian.g.kelly at gmail.com (Ian) Date: Fri, 5 Nov 2010 15:52:18 -0700 (PDT) Subject: Final state of underlying sequence in islice References: <4b599f9b-5d99-4a9a-85a8-4ccba233bdc4@35g2000prb.googlegroups.com> Message-ID: On Nov 5, 2:51?pm, Raymond Hettinger wrote: > You may have missed my point. ?I wrote the tools, the docs, and the > tests. > If you interpret a "promise" in text, I can assure you it was not > intended. ?The behavior *is* undefined because I never defined it. > I'm happy to clarify the docs to make that explicit. Does the existence of a test case imply a guarantee? # Test number of items consumed SF #1171417 it = iter(range(10)) self.assertEqual(list(islice(it, 3)), range(3)) self.assertEqual(list(it), range(3, 10)) From stefan_ml at behnel.de Fri Nov 5 19:21:14 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 06 Nov 2010 00:21:14 +0100 Subject: [ANN] Lupa 0.17 released - Lua in Python Message-ID: Hi all, I am happy to announce the release of Lupa 0.17, Lua in Python. http://pypi.python.org/pypi/lupa/0.17 Have fun, Stefan What is Lupa? -------------- Lupa integrates the LuaJIT2 runtime [1] into CPython. It is a rewrite of LunaticPython in Cython with several advanced features. This release features iteration support for Python objects in Lua. Changes in this release: 0.17 (2010-11-05) * new helper function "python.enumerate()" in Lua that returns a Lua iterator for a Python object and adds the 0-based index to each item. * new helper function "python.iterex()" in Lua that returns a Lua iterator for a Python object and unpacks any tuples that the iterator yields into separate Lua arguments. * new helper function "python.iter()" in Lua that returns a Lua iterator for a Python object. * resurrected the "python.as_function()" helper function for Lua code as it can be needed in cases where Lua cannot determine how to run a Python function. [1] LuaJIT2: http://luajit.org/ Features --------- * separate Lua runtime states through a LuaRuntime class * frees the GIL and supports threading in separate runtimes when calling into Lua * Python compatible coroutine wrapper for Lua coroutines * iteration support for Python objects in Lua and Lua objects in Python * proper encoding and decoding of strings (configurable per runtime, UTF-8 by default) * supports Python 2.x and 3.x, potentially starting with Python 2.3 (currently untested) * written for LuaJIT2, as opposed to the Lua interpreter (tested with LuaJIT 2.0.0-beta5) * easy to hack on and extend as it is written in Cython, not C Why use it? ------------ It complements Python very well. Lua is a language as dynamic as Python, but LuaJIT compiles it to very fast machine code, sometimes faster than many other compiled languages for computational code. The language runtime is extremely small and carefully designed for embedding. The complete binary module of Lupa, including a statically linked LuaJIT2 runtime, is only some 500KB on a 64 bit machine. However, the Lua ecosystem lacks many of the batteries that Python readily includes, either directly in its standard library or as third party packages. This makes real-world Lua applications harder to write than equivalent Python applications. Lua is therefore not commonly used as primary language for large applications, but it makes for a fast, high-level and resource-friendly backup language inside of Python when raw speed is required and the edit-compile-run cycle of binary extension modules is too heavy and too static for agile development or hot-deployment. Lupa is a very fast and thin wrapper around LuaJIT. It makes it easy to write dynamic Lua code that accompanies dynamic Python code by switching between the two languages at runtime, based on the tradeoff between simplicity and speed. Examples --------- >>> from lupa import LuaRuntime >>> lua = LuaRuntime() >>> lua.eval('1+1') 2 >>> lua_func = lua.eval('function(f, n) return f(n) end') >>> def py_add1(n): return n+1 >>> lua_func(py_add1, 2) 3 >>> lua_code = '''\ ... function(N) ... for i=0,N do ... coroutine.yield( i%2 ) ... end ... end ... ''' >>> f = lua.eval(lua_code) >>> gen = f.coroutine(4) >>> list(enumerate(gen)) [(0, 0), (1, 1), (2, 0), (3, 1), (4, 0)] >>> lua_code = '''\ ... function(L) ... for item in python.iter(L) do ... if item == 3 then return 1 end ... end ... return 0 ... end ... ''' >>> f = lua.eval(lua_code) >>> f([1,2,3]) 1 >>> f([1,2]) 0 From darcy at druid.net Fri Nov 5 19:26:48 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Fri, 5 Nov 2010 19:26:48 -0400 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> Message-ID: <20101105192648.45be9606.darcy@druid.net> On 05 Nov 2010 20:14:47 GMT Seebs wrote: > I can just see how well this attitude must work in other circumstances: I guess this message ends the topic for me. Bye. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From python at rcn.com Fri Nov 5 20:32:01 2010 From: python at rcn.com (Raymond Hettinger) Date: Fri, 5 Nov 2010 17:32:01 -0700 (PDT) Subject: Final state of underlying sequence in islice References: <4b599f9b-5d99-4a9a-85a8-4ccba233bdc4@35g2000prb.googlegroups.com> Message-ID: <777bd489-ef2a-4898-8d69-27ebff7832ea@x7g2000prj.googlegroups.com> On Nov 5, 3:52?pm, Ian wrote: > On Nov 5, 2:51?pm, Raymond Hettinger wrote: > > > You may have missed my point. ?I wrote the tools, the docs, and the > > tests. > > If you interpret a "promise" in text, I can assure you it was not > > intended. ?The behavior *is* undefined because I never defined it. > > I'm happy to clarify the docs to make that explicit. > > Does the existence of a test case imply a guarantee? > > ? ? ? ? # Test number of items consumed ? ? SF #1171417 > ? ? ? ? it = iter(range(10)) > ? ? ? ? self.assertEqual(list(islice(it, 3)), range(3)) > ? ? ? ? self.assertEqual(list(it), range(3, 10)) That tests a "natural boundary". In contrast, the OP's issue concerns an odd case where step > 1 and stop != start + n * step and len(list(it)) > start + n * step There's no test for that case and it is not clear what the desired behavior should be. And AFAICT there are no use cases or meaningful invariants to guide the way, so I'm reluctant to lock-in the choice (much like Tim and Guido waited a long time before they guaranteed the stability of list.sort()). If the RightAnswer(tm) is obvious to you, I would like to hear it. If I had to make a choice right now, I would choose stopping at the earlier possible point rather than scanning to the next natural boundary. Raymond From python.list at tim.thechases.com Fri Nov 5 21:22:53 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 05 Nov 2010 20:22:53 -0500 Subject: Using %x to format number to hex and number of digits In-Reply-To: References: Message-ID: <4CD4ADED.1030709@tim.thechases.com> On 11/05/10 15:10, Grant Edwards wrote: > On 2010-11-05, Tim Chase wrote: >> On 11/05/10 13:23, Matty Sarro wrote: >>>> I need it to output as 0x0a, and the exercise is requiring >>>> me to use %x to format the string. Any help would be >>>> appreciated. >> >> Though it feels hokey to me, using >> >> "%#04x" % 10 >> >> works for me. > > I think "0x%02x" % 10 is a bit more readable, but it accomplishes the > same thing -- you just don't have to do the mental math to add the > prefix width to the number of desired hex digits in the output. Which, I confess, is what I usually use because I didn't know about the "#" until this thread, and just made the assumption that one can get the zero-padding along with the "alternate form" in my experimentation this afternoon. So while it _can_ be done with just variants of the "%x" place-holder (as suggested by the OP's exercise), at least two of us on the list prefer to explicitly add the "0x" to the beginning. -tkc From paul.hemans at gmail.com Fri Nov 5 21:25:52 2010 From: paul.hemans at gmail.com (Paul Hemans) Date: Sat, 6 Nov 2010 12:25:52 +1100 Subject: Regular expression Message-ID: I need to extract the quoted text from : _("get this") The following works: re.compile( "_\(['\"]([^'\"]+)['\"]\)" ) However, I don't want to match if there is A-Z or a-z or 0-9 or _ immediately preceding the "_" so I have tried: "[^0-9a-zA-Z]*_\(['\"]([^'\"]+)['\"]\)" "[^\w]{0,1}_\(['\"]([^'\"]+)['\"]\)" "\W*_\(['\"]([^'\"]+)['\"]\)" to match against: skip this text _("get this") Thanks From steve at REMOVE-THIS-cybersource.com.au Fri Nov 5 21:36:36 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Nov 2010 01:36:36 GMT Subject: Why "flat is better than nested"? References: <4cc8d49c$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4cd4b124$0$30004$c3e8da3$5496439d@news.astraweb.com> On Fri, 05 Nov 2010 14:19:47 +0100, J. Gerlach wrote: > Am 28.10.2010 03:40, schrieb Steven D'Aprano: >> [ snip a lot of wise words ] > > Can I put this (translated) in the german python wiki? I guess it might > help more people to understand some decisions taken during python's > development - and I'm to lazy to do something similar myself ;) Sure, go ahead. I would appreciate a link back to my post, and/or credit, but that's not essential. (I understand it's a wiki and there's no guarantee that the link will remain there forever.) -- Steven From pavlovevidence at gmail.com Fri Nov 5 21:58:04 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 5 Nov 2010 18:58:04 -0700 (PDT) Subject: Lupa 0.17 released - Lua in Python References: Message-ID: <39c33bbe-e734-4aea-966a-ecb4e6105980@f20g2000yqi.googlegroups.com> On Nov 5, 4:21?pm, Stefan Behnel wrote: > Hi all, > > I am happy to announce the release of Lupa 0.17, Lua in Python. > > http://pypi.python.org/pypi/lupa/0.17 > > Have fun, > > Stefan Thanks, interesting projection. Good idea. Carl Banks From steve at REMOVE-THIS-cybersource.com.au Fri Nov 5 21:59:41 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Nov 2010 01:59:41 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> Message-ID: <4cd4b68c$0$30004$c3e8da3$5496439d@news.astraweb.com> On Thu, 04 Nov 2010 19:37:25 +0000, Tim Harig wrote: > Examples of communication channels that mangle white space abound. Yes. So what? If your communication channel mangles your data, change your communication channel, don't expect users of clean communication channels to hand-enter error-correcting codes (braces) into the data. > I > don't know of any that mangle either braces or pascal style start/end > blocks. > > You are the one who seems to be on a crusade against against braces. It > would seem to me, that if you want people to accept that white space > formatting is superior, that you would be looking for a simple way to > solve the white space mangling problem. Why is it the responsibility of the programming language syntax to correct the problem with Seebs' faulty mail server? I've experienced the spilled-coke-on-the-keyboard problem more often than mangled whitespace, but you don't see me arguing that what every language needs is error-correcting codes that let me work with keyboards that have had Coke spilled on them. [...] > Transfering binary programs has always been an issue and using text > based communications (preferably human readable) has always been > considered a good design decision. I put up with Python's white space > idiosyncrasies; I wouldn't even bother looking at a language that > requires me to enter the source in binary. I also consider the move > toward XML based document formats a move in the right direction. Okay, now you have zero credibility. XML is not a data format for human use, it is for use by machines. It is slow, inefficient, and uneditable by humans except for the most trivial cases. -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Nov 5 22:01:17 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Nov 2010 02:01:17 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <87mxpp3u3i.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <4cd4b6ed$0$30004$c3e8da3$5496439d@news.astraweb.com> On Thu, 04 Nov 2010 17:45:58 +0000, Tim Harig wrote: >>> Python is the only language that I know that *needs* to specify tabs >>> versus spaces since it is the only language I know of which uses >>> whitespace formating as part of its syntax and structure. [...] > I am also aware of other langauges such as Boo; but, I don't really > consider them individually relevant to the conversation as they are > explicitly using a Python based syntax. For this discussion I merely > group them with Python. You might as well say that C is the only language that uses tags around blocks, since for this discussion "I merely group" Pascal, Algol, Java, etc with C. -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Nov 5 22:13:59 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Nov 2010 02:13:59 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <87r5f13ug3.fsf.mdw@metalzone.distorted.org.uk> <4cd3df64$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4cd4b9e7$0$30004$c3e8da3$5496439d@news.astraweb.com> On Fri, 05 Nov 2010 18:45:39 +0000, Seebs wrote: > On 2010-11-05, Steven D'Aprano > wrote: >> On Thu, 04 Nov 2010 20:17:35 +0000, Seebs wrote: >>> That was the thing which bit me the worst. I had a fairly large block >>> of code in a first-pass ugly program. I wanted to start refactoring >>> it, so I moved a big hunk of code into a method (with plans to further >>> refactor). It took about fifteen minutes to redo the logic. > >> Well there's your problem -- you are relying on tools that operate by >> magic. > > Wrong. Really? Then how did the logic get screwed up from a mere copy-and-paste operation? In context (which you deleted), you were agreeing with Mark Wooding who wrote: "I /do/ have a significant problem with cutting and pasting code in Python. In most languages, I can haul a chunk of code about, hit C-M-q, and Emacs magically indents the result properly. This is, unfortunately, impossible with Python. It has caused me real bugs, and I have to be extra careful to fix the indentation up." [Aside: he isn't having problems with cutting and pasting code in Python, but in Emacs.] You *agreed with him*, and related your story. In context, I think it was perfectly reasonable to conclude that you too used C-M-q in Emacs, which then "magically indents the result". Mark's words, not mine. But perhaps you were using Notepad, and you just hit Ctrl-V, and something else mangled the code so badly you needed to spend 15 minutes re-creating the program logic. I am open to correction either way. >> Rather than re-create the logic, why not just hit Undo and then >> re-paste the code *without* the magic auto-reformat? Half a second, to >> undo and re- paste, followed by 10 or 20 seconds to select the >> appropriate lines and *explicitly* re-indent the lines to the correct >> level. > > There was no magic auto-reformat. Where did you invent that from? Why > are you making stuff up which I never said or referred to? Then how did the logic get mangled from a simple copy and paste operation? What god-awful editor are you using that can't copy and paste text without mangling it? -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Nov 5 22:15:49 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Nov 2010 02:15:49 GMT Subject: Silly newbie question - Carrot character (^) References: Message-ID: <4cd4ba55$0$30004$c3e8da3$5496439d@news.astraweb.com> On Fri, 05 Nov 2010 22:51:10 +0000, Seebs wrote: > On 2010-11-05, Nobody wrote: >> However, it's still written for language lawyers. > >> IMHO, the lack of a reference manual for the language itself is a major >> hole in Python's documentation. > > I'm a bit lost here. Could you highlight some of the differences > between "a reference manual for the language itself" and "something > written for language lawyers"? +1 QOTW -- Steven From python at mrabarnett.plus.com Fri Nov 5 22:16:00 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 06 Nov 2010 02:16:00 +0000 Subject: Regular expression In-Reply-To: References: Message-ID: <4CD4BA60.5090807@mrabarnett.plus.com> On 06/11/2010 01:25, Paul Hemans wrote: > I need to extract the quoted text from : > _("get this") > > The following works: > re.compile( "_\(['\"]([^'\"]+)['\"]\)" ) > However, I don't want to match if there is A-Z or a-z or 0-9 or _ > immediately preceding the "_" so I have tried: > "[^0-9a-zA-Z]*_\(['\"]([^'\"]+)['\"]\)" > "[^\w]{0,1}_\(['\"]([^'\"]+)['\"]\)" > "\W*_\(['\"]([^'\"]+)['\"]\)" > > to match against: > skip this text _("get this") > Use a negative lookbehind: re.compile(r'''(? Hello, In the framework of a project on evolutionary linguistics I wish to have a program to process words and simulate the effect of sound shift, for instance following the Rask's-Grimm's rule. I look to have python take a dictionary file or a string input and replace the consonants in it with the Grimm rule equivalent. For example: b? ? b ? p ? f d? ? d ? t ? ? g? ? g ? k ? x g?? ? g? ? k? ? x? If the dictionary file has the word "Abe" I want the program to replace the letter b with f forming the word "Afe" and write the result in a tabular file. How easy is it to find the python functions to do that? Best regards, Dax Bloom From clp2 at rebertia.com Fri Nov 5 22:36:49 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 5 Nov 2010 19:36:49 -0700 Subject: Using Python for a demonstration in historical linguistics In-Reply-To: <5a85f233-d463-4ef5-a045-342b83873b13@32g2000yqz.googlegroups.com> References: <5a85f233-d463-4ef5-a045-342b83873b13@32g2000yqz.googlegroups.com> Message-ID: On Fri, Nov 5, 2010 at 7:17 PM, Dax Bloom wrote: > Hello, > > In the framework of a project on evolutionary linguistics I wish to > have a program to process words and simulate the effect of sound > shift, for instance following the Rask's-Grimm's rule. I look to have > python take a dictionary file or a string input and replace the > consonants in it with the Grimm rule equivalent. For example: > b? ? b ? p ? f > d? ? d ? t ? ? > g? ? g ? k ? x > g?? ? g? ? k? ? x? > If the dictionary file has the word "Abe" I want the program to > replace the letter b with f forming the word "Afe" and write the > result in a tabular file. How easy is it to find the python functions > to do that? Tabular files: http://docs.python.org/library/csv.html Character substitution: (a) http://docs.python.org/library/string.html#string.maketrans and http://docs.python.org/library/stdtypes.html#str.translate (b) http://docs.python.org/library/stdtypes.html#str.replace In either case, learn about dicts: http://docs.python.org/library/stdtypes.html#dict Cheers, Chris -- http://blog.rebertia.com From python at mrabarnett.plus.com Fri Nov 5 22:37:06 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 06 Nov 2010 02:37:06 +0000 Subject: Using Python for a demonstration in historical linguistics In-Reply-To: <5a85f233-d463-4ef5-a045-342b83873b13@32g2000yqz.googlegroups.com> References: <5a85f233-d463-4ef5-a045-342b83873b13@32g2000yqz.googlegroups.com> Message-ID: <4CD4BF52.9030405@mrabarnett.plus.com> On 06/11/2010 02:17, Dax Bloom wrote: > Hello, > > In the framework of a project on evolutionary linguistics I wish to > have a program to process words and simulate the effect of sound > shift, for instance following the Rask's-Grimm's rule. I look to have > python take a dictionary file or a string input and replace the > consonants in it with the Grimm rule equivalent. For example: > b? ? b ? p ? f > d? ? d ? t ? ? > g? ? g ? k ? x > g?? ? g? ? k? ? x? > If the dictionary file has the word "Abe" I want the program to > replace the letter b with f forming the word "Afe" and write the > result in a tabular file. How easy is it to find the python functions > to do that? > Very. :-) I'd build a dict of each rule: b? ? b b ? p etc, and then use the re module to perform the replacements in one pass, looking up the new sound for each match. From steve at REMOVE-THIS-cybersource.com.au Fri Nov 5 23:09:03 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Nov 2010 03:09:03 GMT Subject: Compare source code References: Message-ID: <4cd4c6cf$0$30004$c3e8da3$5496439d@news.astraweb.com> On Fri, 05 Nov 2010 08:17:02 +0530, Rustom Mody wrote: > However the original question -- mixing tabs and spaces is bad -- has > got lost in the flames. Do the most die-hard python fanboys deny this? > And if not is it asking too much (say in python3) that mixing tabs and > spaces be flagged as an error or at least warning? Mixing spaces and tabs for indentation can be ambiguous. Python 2.x will attempt to ignore the ambiguity, and therefore run the code if it can, but Python 3.x treats mixed indentation in a single block as an error. [steve at sylar ~]$ cat ambiguous.py def f(): print("indented with 8 spaces") print("indented with tab") f() [steve at sylar ~]$ cat unambiguous.py def f(): print("indented with 8 spaces") def g(): print("indented with tab") f() g() Python 2.x will execute both files. Python 3.x will happily execute unambiguous.py, but raises an error on the other: [steve at sylar ~]$ python3 ambiguous.py File "ambiguous.py", line 3 print("indented with tab") ^ TabError: inconsistent use of tabs and spaces in indentation -- Steven From usenet-nospam at seebs.net Fri Nov 5 23:19:53 2010 From: usenet-nospam at seebs.net (Seebs) Date: 06 Nov 2010 03:19:53 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> <4cd4b68c$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-06, Steven D'Aprano wrote: > On Thu, 04 Nov 2010 19:37:25 +0000, Tim Harig wrote: >> Examples of communication channels that mangle white space abound. > Yes. So what? So something which is broken by them is brittle. And in every circumstance *other* than the syntax of Python, specifically, we regard brittleness to common events as a flaw in a design. For instance, Makefiles require tabs to indent rules, and behave strangely if for some reason you use spaces. Many editors, though, can be configured to insert spaces when you hit the tab key. This setup is not intrinsically "broken", it's just a matter of preference. And yet, when used with make, it produces cryptic failures. Everyone, without exception, agrees that this is a flaw in the design of make, and that the "tabs" rule should never have existed. > If your communication channel mangles your data, change > your communication channel, don't expect users of clean communication > channels to hand-enter error-correcting codes (braces) into the data. If you have to hand-enter them, perhaps you should get better tools, as many tools don't require you to hand-enter them. Ahh, but I forgot. You only need to get "better" tools if you're talking about why you *don't* find Python's design to be the one true pinnacle of idealized and perfect engineering. If you're talking about any other language which works fine and is no hassle if you have suitable tools, it is of course ridiculous to suggest that people should need to change away from tools which currently suit them fine. > Why is it the responsibility of the programming language syntax to > correct the problem with Seebs' faulty mail server? It's not. And honestly, if it were just one misconfigured mail server, no one would probably ever start this conversation. But instead it's dozens of mail servers, dozens of web forums, dozens of editors, OCR scanning of printouts, and dozens of other media in which it is easy for small whitespace changes to creep in or appear. All of which were known to exist when the decision was made to design a new file format to be brittle in the face of such changes. > XML is not a data format for human use, it is for use by machines. It is > slow, inefficient, and uneditable by humans except for the most trivial > cases. There are thousands of web pages which have been entered in something which could easily be imagined to be a variant of XML. For that matter, OS X ".plist" files are often stored in XML, which is widely liked because it gives you a nice, robust, human-readable format. Which is amenable to hand-editing if you want to tweak something. XML isn't a *great* format for human use, and it's certainly been aimed much more at use by machines. However, there's a lot to be said for designing machines to use formats which happen also to be easy for humans to read, at the very least, and possibly even easy to write. ("Easy" being, of course a relative term.) -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From philip at semanchuk.com Fri Nov 5 23:21:11 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Fri, 5 Nov 2010 23:21:11 -0400 Subject: Silly newbie question - Carrot character (^) In-Reply-To: References: Message-ID: On Nov 5, 2010, at 6:51 PM, Seebs wrote: > On 2010-11-05, Nobody wrote: >> However, it's still written for language lawyers. > >> IMHO, the lack of a reference manual for the language itself is a major >> hole in Python's documentation. > > I'm a bit lost here. Could you highlight some of the differences > between "a reference manual for the language itself" and "something > written for language lawyers"? The former refers to something that programmers would use to learn the language once they've gone through the tutorial a few times. The latter is great for writing a Python parser but isn't the friendliest guide to language constructs. Take the OP's question. How is one supposed to find out about bitwise operators in Python? AFAICT they're not mentioned in the tutorial, and neither are decorators, assert(), global, exec, the ternary if statement, etc. It seems that plowing through a document written for language lawyers is the only formal way to learn about those language features, and that could be improved upon IMO. Cheers Philip From usenet-nospam at seebs.net Fri Nov 5 23:23:36 2010 From: usenet-nospam at seebs.net (Seebs) Date: 06 Nov 2010 03:23:36 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <87r5f13ug3.fsf.mdw@metalzone.distorted.org.uk> <4cd3df64$0$30004$c3e8da3$5496439d@news.astraweb.com> <4cd4b9e7$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-06, Steven D'Aprano wrote: > On Fri, 05 Nov 2010 18:45:39 +0000, Seebs wrote: >> On 2010-11-05, Steven D'Aprano >> wrote: >>> Well there's your problem -- you are relying on tools that operate by >>> magic. >> Wrong. > Really? Then how did the logic get screwed up from a mere copy-and-paste > operation? I inserted four spaces in front of a bunch of lines. :) > [Aside: he isn't having problems with cutting and pasting code in Python, > but in Emacs.] True. > You *agreed with him*, and related your story. In context, I think it was > perfectly reasonable to conclude that you too used C-M-q in Emacs, which > then "magically indents the result". Mark's words, not mine. Ahh, okay. I can see how you would have inferred that, but no, that's not what I did. > What god-awful editor are you using that can't copy and paste text > without mangling it? It's a side-effect of vi being, by default, configured to prefer to convert things to tabs. The particular vi I'm using doesn't, so far as I know "recognize" file formats, and that default behavior is not merely tolerable but *preferable* for all of the dozens of other kinds of files I edit. I've since learned to work around it, but the fact remains that, given a fairly common behavior, which is *preferable* for every other context, I ended up with a file where an operation which would have worked for re-indenting any other language I use didn't for re-indenting Python. I've long since figured out ways to prevent that, but that wasn't the point; the point was how much harder it was to fix indentation once it had gotten mangled than it would be in, oh, any other programming language or file format I've used. (Even Makefiles are easier to fix, if only because they're so much simpler.) -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From ldo at geek-central.gen.new_zealand Fri Nov 5 23:32:08 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 06 Nov 2010 16:32:08 +1300 Subject: *** glibc detected *** gdb: malloc(): smallbin double linked list References: Message-ID: In message , Nobody wrote: > I imagine that your extension code is trashing the heap, in which case, > valgrind is probably the answer. Something simpler to try first is to run the code with the MALLOC_CHECK_ environment variable set to 2 or 3. That might give a few more clues. From steve at REMOVE-THIS-cybersource.com.au Fri Nov 5 23:33:08 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Nov 2010 03:33:08 GMT Subject: functions, list, default parameters References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <20101021235138.609fe668@geekmail.INVALID> <87pquk3ehs.fsf.mdw@metalzone.distorted.org.uk> <4cd3c72b$0$30004$c3e8da3$5496439d@news.astraweb.com> <8739rg2ceb.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <4cd4cc74$0$30004$c3e8da3$5496439d@news.astraweb.com> On Fri, 05 Nov 2010 12:17:00 +0000, Mark Wooding wrote: >> #1 Most default values are things like True, False, None, integer or >> string literals. Since they're literals, they will never change, so you >> only need to set them once. > > Right; so a half-decent compiler can notice this and optimize > appropriately. Result: negligible difference. You're right, of course, a sufficiently smart compiler could do this. It might even be worth doing in a language that otherwise re-initialises function defaults on every call. But such optimizations don't happen for free, they have costs: somebody has to write it, debug it, maintain it, deal with the added complexity. Python -- at least CPython -- tends to go for the simplest compiler that will work. Perhaps the biggest cost is that now your language has inconsistent semantics: some function defaults are set on every call, and some are set once, when the function is defined, and the choice between the two happens via "magic" -- the compiler decides what to do, you don't. I have mixed feelings about compiler optimizations. Things like constant folding seems to be both harmless and useful, but other optimizations not so much. It sets up a discrepancy between what the source code does and what the compiled code does, and in the case of (say) floating point code, can introduce *serious* bugs. So while I like the idea of compiler optimizations is principle, in practice I tend to think they should be avoided. >> #2 It's easy to get default values to initialise on function call in a >> language that uses initialisation on function definition semantics: >> just move the initialisation into the function body. Python has a >> particularly short and simple idiom for it: >> >> def f(x=None): >> if x is None: >> x = some_expression() > > That's actually rather clumsy. You think so? I think it's quite simple, obvious and neat. > Also, it's using in-band signalling: > you've taken None and used it as a magic marker meaning `not supplied'. > Suppose you want to distinguish /any/ supplied value from a missing > argument: how do you do this /correctly/? > > The approaches I see are (a) to invent some unforgeable token That's the simplest way. _sentinel = object() def f(x=_sentinel): if x is _sentinel: x = some_expression() > or (b) > emulate the argument processing by rifling through * and ** arguments. > > Solution (a) looks like this: > > _missing = ['missing'] > def foo(arg = _missing): > if arg is _missing: arg = ... > ... A curious choice for the sentinel value. We're not using Python 1.5 any longer :) > But now _missing is kicking around in the module's namespace. Er, yes. That's what namespaces are for. >> But if the situations were reversed, it's hard to get the DID >> semantics: >> >> def f(x=None): >> if x is None: >> global _f_default_arg >> try: >> x = _f_default_arg >> except NameError: >> _f_default_arg = x = default_calculation() > > Ugh. This is artificially awful and doesn't correspond to existing > Python DID semantics. [snip] Yes, you're right, those are good points and I stand corrected. -- Steven From ladasky at my-deja.com Sat Nov 6 00:06:14 2010 From: ladasky at my-deja.com (John Ladasky) Date: Fri, 5 Nov 2010 21:06:14 -0700 (PDT) Subject: How find all childrens values of a nested dictionary, fast! References: <87r5f1ypg7.fsf@web.de> Message-ID: <142db8da-536e-48ee-a7a2-ace296a50434@r4g2000prj.googlegroups.com> On Nov 4, 10:21?am, de... at web.de (Diez B. Roggisch) wrote: > macm writes: > ? ? for value in d.values(): > ? ? ? ? if isinstance(value, dict): I'm not a Python guru, but... do you care that you're breaking duck typing here? I've had other programmers warn me against using isinstance() for this reason. Yes, it's part of the Python language, but some people wonder whether it should be there. From ladasky at my-deja.com Sat Nov 6 00:10:14 2010 From: ladasky at my-deja.com (John Ladasky) Date: Fri, 5 Nov 2010 21:10:14 -0700 (PDT) Subject: Exception Handling in Python 3 References: <3d03cc6c-d71a-4d93-8db9-3a3a0297d25d@p1g2000yqm.googlegroups.com> Message-ID: <20e3e6f3-54a3-4f50-b51f-76a6217048ca@s12g2000prs.googlegroups.com> On Oct 29, 8:53?am, rantingrick wrote: > I am the programmer, and when i say to my interpretor "show this > exception instead of that exception" i expect my interpretor to do > exactly as i say or risk total annihilation!! I don't want my > interpreter "interpreting" my intentions and then doing what it > "thinks" is best for me. I have a wife already, i don't need a virtual > one! OK, Ranting Rick, that was funny, and worthy of your name. :^) From usenet-nospam at seebs.net Sat Nov 6 00:14:34 2010 From: usenet-nospam at seebs.net (Seebs) Date: 06 Nov 2010 04:14:34 GMT Subject: Compare source code References: <4cd4c6cf$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-06, Steven D'Aprano wrote: > On Fri, 05 Nov 2010 08:17:02 +0530, Rustom Mody wrote: >> However the original question -- mixing tabs and spaces is bad -- has >> got lost in the flames. Do the most die-hard python fanboys deny this? >> And if not is it asking too much (say in python3) that mixing tabs and >> spaces be flagged as an error or at least warning? > Mixing spaces and tabs for indentation can be ambiguous. Specifically: Four spaces followed by a tab nearly always actually means "eight spaces" to most editors (and Python seems to treat it that way), but it's hard to tell. Worse, a tab may have been intended to be the same thing as four spaces, and someone was expecting it NOT to be the same as eight spaces... -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Sat Nov 6 00:21:44 2010 From: usenet-nospam at seebs.net (Seebs) Date: 06 Nov 2010 04:21:44 GMT Subject: Silly newbie question - Carrot character (^) References: Message-ID: On 2010-11-06, Philip Semanchuk wrote: > The former refers to something that programmers would use to learn >the language once they've gone through the tutorial a few times. >The latter is great for writing a Python parser but isn't the >friendliest guide to language constructs. That sounds, then, like it's not very well written, even for language lawyers. > It seems that plowing through a document written for language >lawyers is the only formal way to learn about those language features, >and that could be improved upon IMO. It sounds to me like it could be improved on, but I don't think the problem is "written for language lawyers", but "not very well done". If you do a good job of writing something useful to language lawyers, any programmer should be able to look things up in it. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From steve at REMOVE-THIS-cybersource.com.au Sat Nov 6 00:33:25 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Nov 2010 04:33:25 GMT Subject: Silly newbie question - Carrot character (^) References: Message-ID: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> On Fri, 05 Nov 2010 23:21:11 -0400, Philip Semanchuk wrote: > Take the OP's question. How is one supposed to find out about bitwise > operators in Python? AFAICT they're not mentioned in the tutorial, and > neither are decorators, assert(), global, exec, the ternary if > statement, etc. The tutorial isn't meant as an exhaustive lesson on every single Python feature. There are plenty of other resources available: learning Python *starts* with the python.org tutorial (or some equivalent), it doesn't end there. As far as the OP's question, I'm kind of surprised that he wasn't told that Google is his friend. The very first hit for "python caret" answers his question. If he had spent even five seconds googling, he would have got his answer. http://www.google.co.uk/search?hl=en&safe=off&q=python+caret&btnG=Search > It seems that plowing through a document written for language lawyers is > the only formal way to learn about those language features, and that > could be improved upon IMO. Google on "Python book" and you will find dozens of other formal ways to learn about language features. At the interactive interpreter, type help("^") and press Enter, and (assuming your help system is set up correctly, which it may not be) you will get a table of operators, including ^ and &. Is it reasonable to assume somebody knows that symbols like + - * and ^ are called "operators" in most programming languages? I think so -- you have to assume some level of knowledge. So you could start at the Python language reference and scan the table of contents by eye for "operators" "operations", "ops" or similar. This gives: 5. Expressions 5.1. Arithmetic conversions 5.2. Atoms 5.3. Primaries 5.4. The power operator 5.5. Unary arithmetic and bitwise operations 5.6. Binary arithmetic operations 5.7. Shifting operations 5.8. Binary bitwise operations ... Admittedly, the language reference is a bit n00b-hostile with it's use of extended BNF notation for syntax. But I don't think it's entirely unreasonable to expect even a newbie to read and understand: "The ^ operator yields the bitwise XOR (exclusive OR) of its arguments, which must be plain or long integers. The arguments are converted to a common type." So, yes, the docs could be improved. They could *always* be improved, because somebody will always find something they don't like -- too detailed, not detailed enough, too long, too short, too hard for newbies, too dumbed down, not dumbed down enough... -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Nov 6 00:38:25 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Nov 2010 04:38:25 GMT Subject: Silly newbie question - Carrot character (^) References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4cd4dbc1$0$30004$c3e8da3$5496439d@news.astraweb.com> On Sat, 06 Nov 2010 04:33:25 +0000, Steven D'Aprano wrote: > As far as the OP's question, I'm kind of surprised that he wasn't told > that Google is his friend. The very first hit for "python caret" answers > his question. If he had spent even five seconds googling, he would have > got his answer. > > http://www.google.co.uk/search?hl=en&safe=off&q=python+caret&btnG=Search Ha, on the other hand googling for "python carrot" isn't helpful at all. But "python carrot operator" *does* give the same link as above. -- Steven From rustompmody at gmail.com Sat Nov 6 01:16:29 2010 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 6 Nov 2010 10:46:29 +0530 Subject: Why "flat is better than nested"? Message-ID: On Oct 26, 12:11 am, kj wrote: > In Steve Holden writes: > > > > >And everyone taking the Zen too seriously should remember that it was > >written by Tim Peters one night during the commercial breaks between > >rounds of wrestling on television. So while it can give useful guidance, > >it's nether prescriptive nor a bible ... > > Well, it's pretty *enshrined*, wouldn't you say? After all, it is > part of the standard distribution, has an easy-to-remember invocation, > etc. *Someone* must have taken it seriously enough to go through > all this bother. If it is as trivial as you suggest (and for all > I know you're absolutely right), then let's knock it off its pedestal > once and for all, and remove it from the standard distribution. > > ~kj If you take zen seriously you dont get it If you dont take zen seriously you dont get it That -- seriously -- is zen From rustompmody at gmail.com Sat Nov 6 01:51:48 2010 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 6 Nov 2010 11:21:48 +0530 Subject: Compare source code Message-ID: As for tools' brokeness regarding spaces/tabs/indentation heres a thread on the emacs list wherein emacs dev Stefan Monnier admits to the fact that emacs' handling in this regard is not perfect. http://groups.google.com/group/gnu.emacs.help/browse_thread/thread/1bd0c33a3e755730/89cbd920ee651b5a?q=tabs+stefan+spaces+group:gnu.emacs.help#89cbd920ee651b5a From tjreedy at udel.edu Sat Nov 6 02:07:18 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 06 Nov 2010 02:07:18 -0400 Subject: Final state of underlying sequence in islice In-Reply-To: References: <4b599f9b-5d99-4a9a-85a8-4ccba233bdc4@35g2000prb.googlegroups.com> Message-ID: On 11/5/2010 4:51 PM, Raymond Hettinger wrote: > On Nov 5, 1:05 pm, Terry Reedy wrote: >>> Currently, there are no promises or guarantees about the final state >>> of the iterator. >> >> I interpret the current doc statement as a promise that becomes >> ambiguous when step> 1. > > You may have missed my point. And you may have missed mine ;-) > I wrote the tools, the docs, and the tests. As I know. Thank you again. > If you interpret a "promise" in text, I can assure you it was not > intended. The behavior *is* undefined because I never defined it. > I'm happy to clarify the docs to make that explicit. Let me be clearer. Looking at that sentence *before* your initial answer to the OP, I interpreted (past tense) it as I said above. > Or I can alter the implementation a bit to make a guarantee > if it looks like there is a good reason to do so. One reason is that it is too easy for someone experimenting with islice to write a call that will run for a l o n g time. I had to cancel a couple of times when I was investigating the C versus Python versions and islice versus range behavior with large numbers (for the other islice issue on the tracker). In other words, the current implementation is a bit of a trap, especially since the C version runs for as long as possible while the Python version as short as possible. -- Terry Jan Reedy From shashank.sunny.singh at gmail.com Sat Nov 6 02:43:21 2010 From: shashank.sunny.singh at gmail.com (Shashank Singh) Date: Sat, 6 Nov 2010 12:13:21 +0530 Subject: Final state of underlying sequence in islice In-Reply-To: References: <4b599f9b-5d99-4a9a-85a8-4ccba233bdc4@35g2000prb.googlegroups.com> Message-ID: I have created an issue in roundup at http://bugs.python.org/issue10323. I was expecting the discussion to move to that place but since it has not, for the sake of completion I am quoting my response to Raymond that I had posted on roundup. > @Raymond: I don't have a particular use case where I had a problem with this behavior. I came across this "problem" when looking at this issue http://bugs.python.org/issue6305. > > An important problem that can happen with this behavior is that it does extra work that is not needed. Consider the case (it appears in Lib/test/test_itertools.py ): > > islice(count(), 1, 10, maxsize) > > where maxsize is MAX_Py_ssize_t > > Current implementation goes all the way up to maxsize when it should have just stopped at 10. > > You are probably right in saying that the caller can make sure that the parameters are such that such cases don't arise but I would still like to see python doing the best possible thing as far as possible. > > -- Regards Shashank Singh shashank.sunny.singh at gmail.com http://www.cse.iitb.ac.in/~shashanksingh -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at asd-group.com Sat Nov 6 03:24:13 2010 From: lists at asd-group.com (John Bond) Date: Sat, 06 Nov 2010 07:24:13 +0000 Subject: Regular expression In-Reply-To: <4CD4BA60.5090807@mrabarnett.plus.com> References: <4CD4BA60.5090807@mrabarnett.plus.com> Message-ID: <4CD5029D.1070905@asd-group.com> On 6/11/2010 2:16 AM, MRAB wrote: > On 06/11/2010 01:25, Paul Hemans wrote: >> I need to extract the quoted text from : >> _("get this") >> >> The following works: >> re.compile( "_\(['\"]([^'\"]+)['\"]\)" ) >> However, I don't want to match if there is A-Z or a-z or 0-9 or _ >> immediately preceding the "_" so I have tried: >> "[^0-9a-zA-Z]*_\(['\"]([^'\"]+)['\"]\)" >> "[^\w]{0,1}_\(['\"]([^'\"]+)['\"]\)" >> "\W*_\(['\"]([^'\"]+)['\"]\)" >> >> to match against: >> skip this text _("get this") >> > Use a negative lookbehind: > > re.compile(r'''(? References: Message-ID: <4CD5029F.4020508@holdenweb.com> On 11/5/2010 3:26 PM, Matty Sarro wrote: > It works, however I'm not sure if it'd be considered very "pythonic" or not. If working isn't pythonic then nothing is. > Thanks for your thoughts! There really are still some amazingly helpful people around here, I am pleased to note. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Open source meetings? When, and where? Call for details PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ Ob Open Source ? http://www.holdenweb.org/ From ldo at geek-central.gen.new_zealand Sat Nov 6 03:24:27 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 06 Nov 2010 20:24:27 +1300 Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> <87aalrjkty.fsf@benfinney.id.au> <8jd3m9Fr55U7@mid.individual.net> Message-ID: In message <8jd3m9Fr55U7 at mid.individual.net>, Neil Cerutti wrote: > On 2010-11-03, Ben Finney wrote: > >> styles = [ >> ("normal", "image", MainWindow.ColorsNormalList), >> ("highlighted", "highlight", MainWindow.ColorsHighlightedList), >> ("selected", "select", MainWindow.ColorsSelectedList)] > > Agreed, except cute stuff like putting those three items in > columns is just as bad. > > Code should be utilitarian rather than ornate, Shaker rather than > Victorian. Tufte?s concept of ?chartjunk? could perhaps be extended to ?formatjunk? or ?prettyprintjunk?. From steve at holdenweb.com Sat Nov 6 03:34:45 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 06 Nov 2010 03:34:45 -0400 Subject: ANN: PyQt v4.8.1 Released In-Reply-To: References: Message-ID: On 11/5/2010 6:14 PM, Lawrence D'Oliveiro wrote: > In message , ?????? ??????????? > wrote: > >>>> PyQt is available under the GPL and a commercial license. >>> >>> Surely you mean ?proprietary? rather than ?commercial?. There is >>> nothing about the GPL that prevents ?commercial? use. >> >> I think he means a license that *he* sells comercially :) > > Presumably that?s a proprietary licence. I don't see why. GPL v2, for example, has nothing to say about the price charged for the software: simply that the source must be made available. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Sat Nov 6 03:41:12 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 06 Nov 2010 03:41:12 -0400 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> Message-ID: On 11/5/2010 4:09 PM, Seebs wrote: > On 2010-11-05, Grant Edwards wrote: >> On 2010-11-05, Seebs wrote: >>> On 2010-11-05, Emile van Sebille wrote: >>>> So, which of your tools are you married to that are causing your issues? > >>> Python. > >> I think you should quit using Python and choose a language that works >> with whatever tools are causing all your white-space corruption >> problems. > > Ahh, but that's the thing. I'm married to it -- there's existing projects > I want to work on which are in Python. > > Anyway, it was a sort of frivolous answer, but it's ha-ha-only-serious; > after all, there were no serious issues with any of these tools before. > > There's a saying a friend of mine has; "a lack of communication is never > exclusively one party's fault." This applies, in many cases, to things > like "issues" that occur when two programs clash in some aspect of their > designs. In some cases, there might be a real and unambiguous standard > to be violated. In others, though, you can have a problem which arises > from a clash in expectations between two programs, either of which is fine > on its own. > > There is a clash between Python and the whole category of things which > sometimes lose whitespace. Because that category is reasonably large, > and known to be large, and unlikely to vanish, many language designers > choose to build their languages to be robust in the face of minor changes > in whitespace. Python chose not to, and that is a source of conflicts. > The whitespace-eating nanovirus was conquered in 2005, and is not expected to reappear. > Were someone to invent a *new* text editor, which mangled whitespace, I > would accuse it of being gratuitously incompatible with Python; I tend > to regard compatibility, once you get past the standards, as a matter > of temporal precedence. > > -s If someone were to use a text editor which had always historically mangled whitespace I would find myself wondering why they found it necessary to restrict themselves to such stone-age tools. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From rustompmody at gmail.com Sat Nov 6 03:47:47 2010 From: rustompmody at gmail.com (rustom) Date: Sat, 6 Nov 2010 00:47:47 -0700 (PDT) Subject: Why "flat is better than nested"? References: Message-ID: On Oct 26, 12:11?am, kj wrote: > In Steve Holden writes: > > > > >On 10/25/2010 10:47 AM, rantingrick wrote: > >> On Oct 25, 5:07 am, kj wrote: > >>> In "The Zen of Python", one of the "maxims" is "flat is better than > >>> nested"? ?Why? ?Can anyone give me a concrete example that illustrates > >>> this point? > > >> Simple. This commandment (endowed by the anointed one, GvR) is > >> directed directly at lisp and those filthy lispers. If you don't know > >> what lisp is then Google it. Then try to program with it for one hour. > >> Very soon after your head will explode from the nested bracket plague > >> and then you shall be enlightened! > > >And everyone taking the Zen too seriously should remember that it was > >written by Tim Peters one night during the commercial breaks between > >rounds of wrestling on television. So while it can give useful guidance, > >it's nether prescriptive nor a bible ... > > Well, it's pretty *enshrined*, wouldn't you say? ?After all, it is > part of the standard distribution, has an easy-to-remember invocation, > etc. ?*Someone* must have taken it seriously enough to go through > all this bother. ?If it is as trivial as you suggest (and for all > I know you're absolutely right), then let's knock it off its pedestal > once and for all, and remove it from the standard distribution. > > ~kj If you take zen seriously you dont get it If you dont take zen seriously you dont get it That -- seriously -- is zen From steve at REMOVE-THIS-cybersource.com.au Sat Nov 6 04:14:54 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Nov 2010 08:14:54 GMT Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> <87aalrjkty.fsf@benfinney.id.au> <8jd3m9Fr55U7@mid.individual.net> Message-ID: <4cd50e7e$0$30004$c3e8da3$5496439d@news.astraweb.com> On Wed, 03 Nov 2010 12:42:49 +0000, Neil Cerutti wrote: > On 2010-11-03, Ben Finney wrote: >> I would do the same, but fix the indentation. Making indentation depend >> on the *length* of the previous line is needlessly making a maintenance >> burden. >> >> Instead, I'd do:: >> >> styles = [ >> ("normal", "image", MainWindow.ColorsNormalList), >> ("highlighted", "highlight", MainWindow.ColorsHighlightedList), >> ("selected", "select", MainWindow.ColorsSelectedList)] > > Agreed, except cute stuff like putting those three items in columns is > just as bad. > > Code should be utilitarian rather than ornate, Shaker rather than > Victorian. Perhaps, but lining up the columns in a 3x3 table is hardly "ornate". I have mixed feelings here. On the one hand, there's no doubt in my mind that the extra whitespace and aligned columns make the data easier to read for me. On the other hand, I know that it is easy to fall into the trap of spending hours carefully aligning code that doesn't need to be aligned. -- Steven From usenet-nospam at seebs.net Sat Nov 6 04:27:00 2010 From: usenet-nospam at seebs.net (Seebs) Date: 06 Nov 2010 08:27:00 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> Message-ID: On 2010-11-06, Steve Holden wrote: > If someone were to use a text editor which had always historically > mangled whitespace I would find myself wondering why they found it > necessary to restrict themselves to such stone-age tools. I have yet to find an editor that allows me to, well, *edit*, more comfortably than vi. As to what it does with whitespace... What it does is exactly what is most desireable in every other kind of file I edit. I wouldn't normally refer to it as "mangling" in the pejorative sense; it mostly leaves spaces alone, but when preserving indentation from one line to the next, uses tabs. That, it turns out, is useful and desireable in nearly all programming languages, and in particular, in all the other programming languages I use. I don't think it's fair to accuse tools of being "stone age" on the grounds that they do something which most users want most of the time by default. The "no tabs, only spaces" thing is an interesting idiosyncrasy of a particular community, which places a high value on telling people to change everything about their computing environment so they can appreciate how robust Python is when you make a point of blaming any and all quirks or nuisances on tools. We might as well insist that everyone use editors which automatically add the braces to C code (such exist) when they complain about the "effort" of typing matching braces. Surely, if you have to type braces by hand, the problem isn't with C, but with your stone age editor? Oh, wait. That kind of smug dismissiveness is considered rude unless it's done in *favor* of Python. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From steve at REMOVE-THIS-cybersource.com.au Sat Nov 6 04:52:13 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Nov 2010 08:52:13 GMT Subject: Split iterator into multiple streams Message-ID: <4cd5173d$0$30004$c3e8da3$5496439d@news.astraweb.com> Suppose I have an iterator that yields tuples of N items (a, b, ... n). I want to split this into N independent iterators: iter1 -> a, a2, a3, ... iter2 -> b, b2, b3, ... ... iterN -> n, n2, n3, ... The iterator may be infinite, or at least too big to collect in a list. My first attempt was this: def split(iterable, n): iterators = [] for i, iterator in enumerate(itertools.tee(iterable, n)): iterators.append((t[i] for t in iterator)) return tuple(iterators) But it doesn't work, as all the iterators see the same values: >>> data = [(1,2,3), (4,5,6), (7,8,9)] >>> a, b, c = split(data, 3) >>> list(a), list(b), list(c) ([3, 6, 9], [3, 6, 9], [3, 6, 9]) I tried changing the t[i] to use operator.itergetter instead, but no luck. Finally I got this: def split(iterable, n): iterators = [] for i, iterator in enumerate(itertools.tee(iterable, n)): f = lambda it, i=i: (t[i] for t in it) iterators.append(f(iterator)) return tuple(iterators) which seems to work: >>> data = [(1,2,3), (4,5,6), (7,8,9)] >>> a, b, c = split(data, 3) >>> list(a), list(b), list(c) ([1, 4, 7], [2, 5, 8], [3, 6, 9]) Is this the right approach, or have I missed something obvious? -- Steven From ian.g.kelly at gmail.com Sat Nov 6 05:24:13 2010 From: ian.g.kelly at gmail.com (Ian) Date: Sat, 6 Nov 2010 02:24:13 -0700 (PDT) Subject: Split iterator into multiple streams References: <4cd5173d$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Nov 6, 2:52?am, Steven D'Aprano wrote: > My first attempt was this: > > def split(iterable, n): > ? ? iterators = [] > ? ? for i, iterator in enumerate(itertools.tee(iterable, n)): > ? ? ? ? iterators.append((t[i] for t in iterator)) > ? ? return tuple(iterators) > > But it doesn't work, as all the iterators see the same values: Because the value of i is not evaluated until the generator is actually run; so all the generators end up seeing only the final value of i rather than the intended values. This is a common problem with generator expressions that are not immediately run. > I tried changing the t[i] to use operator.itergetter instead, but no > luck. Finally I got this: > > def split(iterable, n): > ? ? iterators = [] > ? ? for i, iterator in enumerate(itertools.tee(iterable, n)): > ? ? ? ? f = lambda it, i=i: (t[i] for t in it) > ? ? ? ? iterators.append(f(iterator)) > ? ? return tuple(iterators) > > which seems to work: > > >>> data = [(1,2,3), (4,5,6), (7,8,9)] > >>> a, b, c = split(data, 3) > >>> list(a), list(b), list(c) > > ([1, 4, 7], [2, 5, 8], [3, 6, 9]) > > Is this the right approach, or have I missed something obvious? That avoids the generator problem, but in this case you could get the same result a bit more straight-forwardly by just using imap instead: def split(iterable, n): iterators = [] for i, iterator in enumerate(itertools.tee(iterable, n)): iterators.append(itertools.imap(operator.itemgetter(i), iterator)) return tuple(iterators) >>> map(list, split(data, 3)) [[1, 4, 7], [2, 5, 8], [3, 6, 9]] Cheers, Ian From __peter__ at web.de Sat Nov 6 05:25:42 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 06 Nov 2010 10:25:42 +0100 Subject: Split iterator into multiple streams References: <4cd5173d$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Suppose I have an iterator that yields tuples of N items (a, b, ... n). > > I want to split this into N independent iterators: > > iter1 -> a, a2, a3, ... > iter2 -> b, b2, b3, ... > ... > iterN -> n, n2, n3, ... > > The iterator may be infinite, or at least too big to collect in a list. > > My first attempt was this: > > > def split(iterable, n): > iterators = [] > for i, iterator in enumerate(itertools.tee(iterable, n)): > iterators.append((t[i] for t in iterator)) > return tuple(iterators) > > But it doesn't work, as all the iterators see the same values: > >>>> data = [(1,2,3), (4,5,6), (7,8,9)] >>>> a, b, c = split(data, 3) >>>> list(a), list(b), list(c) > ([3, 6, 9], [3, 6, 9], [3, 6, 9]) > > > I tried changing the t[i] to use operator.itergetter instead, but no > luck. Finally I got this: > > def split(iterable, n): > iterators = [] > for i, iterator in enumerate(itertools.tee(iterable, n)): > f = lambda it, i=i: (t[i] for t in it) > iterators.append(f(iterator)) > return tuple(iterators) > > which seems to work: > >>>> data = [(1,2,3), (4,5,6), (7,8,9)] >>>> a, b, c = split(data, 3) >>>> list(a), list(b), list(c) > ([1, 4, 7], [2, 5, 8], [3, 6, 9]) > > > > > Is this the right approach, or have I missed something obvious? Here's how to do it with operator.itemgetter(): >>> from itertools import * >>> from operator import itemgetter >>> data = [(1,2,3), (4,5,6), (7,8,9)] >>> abc = [imap(itemgetter(i), t) for i, t in enumerate(tee(data, 3))] >>> map(list, abc) [[1, 4, 7], [2, 5, 8], [3, 6, 9]] I'd say the improvement is marginal. If you want to go fancy you can calculate n: >>> def split(items, n=None): ... if n is None: ... items = iter(items) ... first = next(items) ... n = len(first) ... items = chain((first,), items) ... return [imap(itemgetter(i), t) for i, t in enumerate(tee(items, n))] ... >>> map(list, split([(1,2,3), (4,5,6), (7,8,9)])) [[1, 4, 7], [2, 5, 8], [3, 6, 9]] Peter From python at rcn.com Sat Nov 6 05:26:18 2010 From: python at rcn.com (Raymond Hettinger) Date: Sat, 6 Nov 2010 02:26:18 -0700 (PDT) Subject: Split iterator into multiple streams References: <4cd5173d$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9fd95af7-4c56-42e5-92e9-d3e2d11182ea@u25g2000pra.googlegroups.com> On Nov 6, 1:52?am, Steven D'Aprano wrote: > I tried changing the t[i] to use operator.itergetter instead, but no > luck. Finally I got this: > > def split(iterable, n): > ? ? iterators = [] > ? ? for i, iterator in enumerate(itertools.tee(iterable, n)): > ? ? ? ? f = lambda it, i=i: (t[i] for t in it) > ? ? ? ? iterators.append(f(iterator)) > ? ? return tuple(iterators) > > which seems to work: > > >>> data = [(1,2,3), (4,5,6), (7,8,9)] > >>> a, b, c = split(data, 3) > >>> list(a), list(b), list(c) > > ([1, 4, 7], [2, 5, 8], [3, 6, 9]) > > Is this the right approach, or have I missed something obvious? That looks about right to me. It can be compacted a bit: def split(iterable, n): return tuple(imap(itemgetter(i), it) for i, it in enumerate(tee(iterable, n))) Internally, the tee's iterators are going to accumulate a ton of data unless they are consumed roughly in parallel. Of course, if they are consumed *exactly* in lockstep, the you don't need to split them into separate iterables -- just use the tuples as they come. Raymond From no.email at nospam.invalid Sat Nov 6 05:31:03 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 06 Nov 2010 02:31:03 -0700 Subject: Split iterator into multiple streams References: <4cd5173d$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7xk4kqdciw.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > def split(iterable, n): > iterators = [] > for i, iterator in enumerate(itertools.tee(iterable, n)): > f = lambda it, i=i: (t[i] for t in it) > iterators.append(f(iterator)) > return tuple(iterators) > > Is this the right approach, or have I missed something obvious? I think there is no way around using tee. But the for loop looks ugly. This looks more direct to me, if I didn't mess something up: def split(iterable, n): return tuple(imap(itemgetter(i),t) for i,t in enumerate(tee(iterable,n))) From __peter__ at web.de Sat Nov 6 05:31:12 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 06 Nov 2010 10:31:12 +0100 Subject: Final state of underlying sequence in islice References: <4b599f9b-5d99-4a9a-85a8-4ccba233bdc4@35g2000prb.googlegroups.com> <777bd489-ef2a-4898-8d69-27ebff7832ea@x7g2000prj.googlegroups.com> Message-ID: Raymond Hettinger wrote: > If the RightAnswer(tm) is obvious to you, I would > like to hear it. It isnt ;) > If I had to make a choice right > now, I would choose stopping at the earlier possible > point rather than scanning to the next natural > boundary. +1 Not because it leaves the underlying iterator in a more useful state (I think it doesn't), but because I like the principle that generators do as little work as possible. Peter From __peter__ at web.de Sat Nov 6 05:52:07 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 06 Nov 2010 10:52:07 +0100 Subject: Why "flat is better than nested"? References: Message-ID: rustom wrote: > If you take zen seriously you dont get it > If you dont take zen seriously you dont get it You forgot: If you explain zen you don't get it From __peter__ at web.de Sat Nov 6 06:09:34 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 06 Nov 2010 11:09:34 +0100 Subject: Using Python for a demonstration in historical linguistics References: <5a85f233-d463-4ef5-a045-342b83873b13@32g2000yqz.googlegroups.com> Message-ID: Dax Bloom wrote: > Hello, > > In the framework of a project on evolutionary linguistics I wish to > have a program to process words and simulate the effect of sound > shift, for instance following the Rask's-Grimm's rule. I look to have > python take a dictionary file or a string input and replace the > consonants in it with the Grimm rule equivalent. For example: > b? ? b ? p ? f > d? ? d ? t ? ? > g? ? g ? k ? x > g?? ? g? ? k? ? x? > If the dictionary file has the word "Abe" I want the program to > replace the letter b with f forming the word "Afe" and write the > result in a tabular file. How easy is it to find the python functions > to do that? > > Best regards, > > Dax Bloom >>> s = """ ... In the framework of a project on evolutionary linguistics I wish to ... have a program to process words and simulate the effect of sound ... shift, for instance following the Rask's-Grimm's rule. I look to have ... python take a dictionary file or a string input and replace the ... consonants in it with the Grimm rule equivalent. For example: ... """ >>> rules = ["bpf", ("d", "t", "th"), "gkx"] >>> for rule in rules: ... rule = rule[::-1] # go back in time ... for i in range(len(rule)-1): ... s = s.replace(rule[i], rule[i+1]) ... >>> print s In de brameworg ob a brojecd on evoludionary linguisdics I wish do have a brogram do brocess words and simulade de ebbecd ob sound shibd, bor insdance bollowing de Rasg's-Grimm's rule. I loog do have bydon dage a dicdionary bile or a sdring inbud and reblace de consonands in id wid de Grimm rule equivalend. For egamble: ;) If you are using nonascii characters like ? you should use unicode instead of str. Basically this means writing string constants as u"..." instead of "..." and opening your files with f = codecs.open(filename, encoding="utf-8") instead of f = open(filename) Peter From __peter__ at web.de Sat Nov 6 06:23:37 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 06 Nov 2010 11:23:37 +0100 Subject: Exception handling with NameError References: Message-ID: Dennis Lee Bieber wrote: >> The problem I am having is this: If I do: >> >> K = [] >> ARCHIVE = [] >> ARCHIVE.append(K) >> >> any time K is updated (user submits new input) the content of ARCHIVE >> is erased: >> > No, it is NOT erased... It is MUTATED... But he rebinds the ARCHIVE name. From __peter__ at web.de Sat Nov 6 06:32:24 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 06 Nov 2010 11:32:24 +0100 Subject: Exception handling with NameError References: Message-ID: Zeynel wrote: > On Nov 5, 1:26 pm, Peter Otten <__pete... at web.de> wrote: > >> Of course I'm only guessing because you don't provide enough context. >> >> Peter > > Thanks. > > This is the problem I am having, in general: > > K = [] # a container list > K = ["A", "B"] > > ARCHIVE = [] # a list where items from K is archived > > ARCHIVE.append(K) > > # K is updated > K = ["C", "D"] > > # append new K to ARCHIVE > ARCHIVE.append(K) > > The problem I am having is this: If I do: > > K = [] > ARCHIVE = [] > ARCHIVE.append(K) > > any time K is updated (user submits new input) the content of ARCHIVE > is erased: > > If I do this: > > K = [] > ARCHIVE.append(K) > > I get NameError: "Name ARCHIVE not defined" > > What is the solution? archive = [] k = ["a", "b"] for new_k in get_container(): archive.append(k) k = new_k I. e. don't rebind the name archive if you don't want to lose old data. >>> import random, string >>> def get_container(): ... for i in range(5): ... yield [random.choice(string.ascii_lowercase) for _ in range(2)] ... >>> archive = [] >>> k = ["a", "b"] >>> for new_k in get_container(): ... archive.append(k) ... k = new_k ... print "k is now", k ... print "archive contents", archive ... k is now ['h', 'r'] archive contents [['a', 'b']] k is now ['t', 'y'] archive contents [['a', 'b'], ['h', 'r']] k is now ['y', 'q'] archive contents [['a', 'b'], ['h', 'r'], ['t', 'y']] k is now ['p', 'i'] archive contents [['a', 'b'], ['h', 'r'], ['t', 'y'], ['y', 'q']] k is now ['y', 'n'] archive contents [['a', 'b'], ['h', 'r'], ['t', 'y'], ['y', 'q'], ['p', 'i']] Peter From steve at REMOVE-THIS-cybersource.com.au Sat Nov 6 06:33:28 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Nov 2010 10:33:28 GMT Subject: Using Python for a demonstration in historical linguistics References: <5a85f233-d463-4ef5-a045-342b83873b13@32g2000yqz.googlegroups.com> Message-ID: <4cd52ef8$0$30004$c3e8da3$5496439d@news.astraweb.com> On Sat, 06 Nov 2010 11:09:34 +0100, Peter Otten wrote: > If you are using nonascii characters like ? you should use unicode > instead of str. Basically this means writing string constants as u"..." > instead of "..." Or using Python 3.1 instead of 2.x. -- Steven From garabik-news-2005-05 at kassiopeia.juls.savba.sk Sat Nov 6 06:49:28 2010 From: garabik-news-2005-05 at kassiopeia.juls.savba.sk (garabik-news-2005-05 at kassiopeia.juls.savba.sk) Date: Sat, 6 Nov 2010 10:49:28 +0000 (UTC) Subject: Using Python for a demonstration in historical linguistics References: <5a85f233-d463-4ef5-a045-342b83873b13@32g2000yqz.googlegroups.com> Message-ID: Dax Bloom wrote: ... > I look to have > python take a dictionary file or a string input and replace the > consonants in it with the Grimm rule equivalent. ... > How easy is it to find the python functions > to do that? > http://code.activestate.com/recipes/81330-single-pass-multiple-replace/ -- ----------------------------------------------------------- | 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 python at bdurham.com Sat Nov 6 07:04:56 2010 From: python at bdurham.com (python at bdurham.com) Date: Sat, 06 Nov 2010 07:04:56 -0400 Subject: Best practice approach for trapping Tkinter exceptions Message-ID: <1289041496.20059.1403897831@webmail.messagingengine.com> What is the best practice approach for trapping Tkinter exceptions? Example: When using the Text widget with undo=True, attempting an edit_undo or edit_redo raises a Tkinter exception when there are no actions to undo or redo. It doesn't look like there's a Tkinter specific exception being raised - only a general exception. Is there a better way to trap Tkinter exceptions than wrapping certain Tkinter commands like the following: try: widget_with_focus.edit_undo() except Exception as e: pass If I print the exception that I trapped, all I get is the name of the Tkinter method I tried to execute, eg. edit_undo. For bonus points: Is there a way to query a Tkinter Text widget to determine if there are undo or redo actions available to apply? Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Sat Nov 6 07:18:39 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 06 Nov 2010 12:18:39 +0100 Subject: Using Python for a demonstration in historical linguistics References: <5a85f233-d463-4ef5-a045-342b83873b13@32g2000yqz.googlegroups.com> Message-ID: Peter Otten wrote: >>>> s = """ > ... In the framework of a project on evolutionary linguistics I wish to > ... have a program to process words and simulate the effect of sound > ... shift, for instance following the Rask's-Grimm's rule. I look to have > ... python take a dictionary file or a string input and replace the > ... consonants in it with the Grimm rule equivalent. For example: > ... """ >>>> rules = ["bpf", ("d", "t", "th"), "gkx"] >>>> for rule in rules: > ... rule = rule[::-1] # go back in time > ... for i in range(len(rule)-1): > ... s = s.replace(rule[i], rule[i+1]) > ... Warning: this simple-minded approach somewhat limits the possible rules. E. g. it fails for a --> b b --> a >>> "abba".replace("a", "b").replace("b", "a") 'aaaa' while unicode.translate() can deal with it: >>> u"abba".translate({ord(u"a"): u"b", ord(u"b"): u"a"}) u'baab' Or, if you are using Python 3.x as Steven suggested: >>> "abba".translate({ord("a"): "b", ord("b"): "a"}) 'baab' Peter From kevin.p.dwyer at gmail.com Sat Nov 6 07:26:02 2010 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Sat, 6 Nov 2010 11:26:02 +0000 (UTC) Subject: What people are using to access this mailing list References: <4cd144cc$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, 03 Nov 2010 11:17:32 +0000, Steven D'Aprano wrote: > On Wed, 03 Nov 2010 08:02:29 +0000, John Bond wrote: > >> Hope this isn't too O/T - I was just wondering how people read/send to >> this mailing list, eg. normal email client, gmane, some other software >> or online service? > > Usenet via my ISP, on comp.lang.python. news.gmane.org, using Pan. From vlastimil.brom at gmail.com Sat Nov 6 07:41:09 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sat, 6 Nov 2010 12:41:09 +0100 Subject: Using Python for a demonstration in historical linguistics In-Reply-To: <5a85f233-d463-4ef5-a045-342b83873b13@32g2000yqz.googlegroups.com> References: <5a85f233-d463-4ef5-a045-342b83873b13@32g2000yqz.googlegroups.com> Message-ID: 2010/11/6 Dax Bloom : > Hello, > > In the framework of a project on evolutionary linguistics I wish to > have a program to process words and simulate the effect of sound > shift, for instance following the Rask's-Grimm's rule. I look to have > python take a dictionary file or a string input and replace the > consonants in it with the Grimm rule equivalent. For example: > b? ? b ? p ? f > d? ? d ? t ? ? > g? ? g ? k ? x > g?? ? g? ? k? ? x? > If the dictionary file has the word "Abe" I want the program to > replace the letter b with f forming the word "Afe" and write the > result in a tabular file. How easy is it to find the python functions > to do that? > > Best regards, > > Dax Bloom > -- > http://mail.python.org/mailman/listinfo/python-list > Hi, I guess, the most difficult part would be, to select appropriate words, to apply the simple rules on (in order not to get "problems" with Verner's Law or other special rules). You also normally wouldn't want to chain the changes like the above, but to keep them separated b? ? b; p ? f (ie. *b?r?ter- > ... brother and not *p-... (at least without the High German consonant shift)). of course, there are also vowel changes to be dealt with and many more peculiarities ... As for implementation, I guess, the simplest way might be to use regular expression replacements - re.sub(...) with a replace function looking up the appropriate results in a dictionary. maybe something along the lines: ######################################## Rask_Grimm_re = ur"[bdgptk]??" Rask_Grimm_dct = {u"b":u"p", u"b?": u"b", u"t": u"?", } # ... def repl_fn(m): return Rask_Grimm_dct.get(m.group(), m.group()) ie_txt = u" b?r?ter ... " almost_germ_txt = re.sub(Rask_Grimm_re, repl_fn, ie_txt) print u"%s >> %s" % (ie_txt, almost_germ_txt) # vowel changes etc. TBD ######################################## b?r?ter ... >> br??er ... hth, vbr From gerlach_joerg at web.de Sat Nov 6 07:49:39 2010 From: gerlach_joerg at web.de (J. Gerlach) Date: Sat, 06 Nov 2010 12:49:39 +0100 Subject: Why "flat is better than nested"? In-Reply-To: <4cd4b124$0$30004$c3e8da3$5496439d@news.astraweb.com> References: <4cc8d49c$0$29982$c3e8da3$5496439d@news.astraweb.com> <4cd4b124$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: Am 06.11.2010 02:36, schrieb Steven D'Aprano: > On Fri, 05 Nov 2010 14:19:47 +0100, J. Gerlach wrote: > >> Am 28.10.2010 03:40, schrieb Steven D'Aprano: >>> [ snip a lot of wise words ] >> >> Can I put this (translated) in the german python wiki? I guess it might >> help more people to understand some decisions taken during python's >> development - and I'm to lazy to do something similar myself ;) > > > Sure, go ahead. > > I would appreciate a link back to my post, and/or credit, but that's not > essential. (I understand it's a wiki and there's no guarantee that the > link will remain there forever.) > > Thank you, and of course I gave you credit. I linked back to your post via googlegroups. From python.list at tim.thechases.com Sat Nov 6 07:59:58 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 06 Nov 2010 06:59:58 -0500 Subject: Silly newbie question - Carrot character (^) In-Reply-To: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4CD5433E.1000805@tim.thechases.com> On 11/05/10 23:33, Steven D'Aprano wrote: > As far as the OP's question, I'm kind of surprised that he wasn't told > that Google is his friend. The very first hit for "python caret" answers > his question. If he had spent even five seconds googling, he would have > got his answer. > > http://www.google.co.uk/search?hl=en&safe=off&q=python+caret&btnG=Search The OP didn't seem to know the name for the character which makes it difficult. As they wrote in the initial message, "Sadly my google foo is failing since the character gets filtered out." I'm guessing the OP tried to search for "python ^", and the "^" just got filtered out, which makes for a rather unhelpful search for just "python". And since the OP had already tried to google it, they weren't told to attempt it again. ;-) Yes, with a little tweaking to the query, something like "python ^ operator" would get them to pages matching "python operator" in which they could have searched for "^", but at least they made the attempt (the lack of an *attempt* is what usually brings out the "GTFW" responses). -tkc From python.list at tim.thechases.com Sat Nov 6 08:00:20 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 06 Nov 2010 07:00:20 -0500 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> Message-ID: <4CD54354.90208@tim.thechases.com> On 11/06/10 03:27, Seebs wrote: > On 2010-11-06, Steve Holden wrote: >> If someone were to use a text editor which had always historically >> mangled whitespace I would find myself wondering why they found it >> necessary to restrict themselves to such stone-age tools. > > I have yet to find an editor that allows me to, well, *edit*, more > comfortably than vi. > > As to what it does with whitespace... What it does is exactly what > is most desireable in every other kind of file I edit. I wouldn't > normally refer to it as "mangling" in the pejorative sense; it mostly > leaves spaces alone, but when preserving indentation from one line > to the next, uses tabs. That, it turns out, is useful and desireable > in nearly all programming languages, and in particular, in all > the other programming languages I use. I think in a previous thread, you mentioned that you use nvi. While I can't speak to the knobs-and-dials that nvi offers, in vim, you can twiddle the 'expandtab' option (along with the associated 'tabwidth' and 'shiftwidth' settings) to get whatever behavior is deemed "correct" for the project you're working on. So if I'm working on a project with PEP-8 4-spaces-per-indent, I'll :set sw=4 ts=4 et and then if the file erroneously has tabs in it, I'll just issue :retab to fix it[1]. -tkc [1] Yes, if you have string literals with tabs that you want to keep in them, the solution is a little more complex, but doable; though in such cases I'd recommend using "\t" instead of a literal tab. From mdw at distorted.org.uk Sat Nov 6 08:21:34 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Sat, 06 Nov 2010 12:21:34 +0000 Subject: Compare source code References: Message-ID: <87fwveej75.fsf.mdw@metalzone.distorted.org.uk> Rustom Mody writes: > As for tools' brokeness regarding spaces/tabs/indentation heres a > thread on the emacs list wherein emacs dev Stefan Monnier admits to > the fact that emacs' handling in this regard is not perfect. > > http://groups.google.com/group/gnu.emacs.help/browse_thread/thread/1bd0c33a3e755730/89cbd920ee651b5a?q=tabs+stefan+spaces+group:gnu.emacs.help#89cbd920ee651b5a You've misunderstood. That discussion is about configuring Emacs to not do automatic indentation when the `tab' key is pressed or when language-specific punctuation is entered. It has very little to do with tab characters in files. -- [mdw] From mygogo2011 at gmail.com Sat Nov 6 08:29:08 2010 From: mygogo2011 at gmail.com (PHP.CCC) Date: Sat, 6 Nov 2010 05:29:08 -0700 (PDT) Subject: MY X+X NURSE AND NURSING SCHOOL Message-ID: MY X+X NURSE AND NURSING SCHOOL READ MORE >>>>> http://nursingschol.blogspot.com/ From rustompmody at gmail.com Sat Nov 6 08:34:37 2010 From: rustompmody at gmail.com (rustom) Date: Sat, 6 Nov 2010 05:34:37 -0700 (PDT) Subject: Why "flat is better than nested"? References: Message-ID: On Nov 6, 2:52?pm, Peter Otten <__pete... at web.de> wrote: > rustom wrote: > > If you take zen seriously you dont get it > > If you dont take zen seriously you dont get it > > You forgot: > > If you explain zen you don't get it I guess different communities have different settings for 'explanation- toleration' (as also 'seriousness') eg. Classical zen: If you the Buddha on the road kill him! Now :s/the Buddha/Jesus Christ/ and it suddenly seems more offensive -- not because the Buddha and Jesus Christ are all that different but because the respective communities have different seriousness defaults. And as for another teacher whose sphere of influence was a few hundred km from Jesus' I am going to be even more careful because the seriousness-defaults are set lower still... From mdw at distorted.org.uk Sat Nov 6 08:37:42 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Sat, 06 Nov 2010 12:37:42 +0000 Subject: functions, list, default parameters References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <20101021235138.609fe668@geekmail.INVALID> <87pquk3ehs.fsf.mdw@metalzone.distorted.org.uk> <4cd3c72b$0$30004$c3e8da3$5496439d@news.astraweb.com> <8739rg2ceb.fsf.mdw@metalzone.distorted.org.uk> <4cd4cc74$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87bp62eig9.fsf.mdw@metalzone.distorted.org.uk> Steven D'Aprano writes: > On Fri, 05 Nov 2010 12:17:00 +0000, Mark Wooding wrote: > > Right; so a half-decent compiler can notice this and optimize > > appropriately. Result: negligible difference. > > Perhaps the biggest cost is that now your language has inconsistent > semantics: some function defaults are set on every call, and some are set > once, when the function is defined, and the choice between the two > happens via "magic" -- the compiler decides what to do, you don't. The /semantics/ are indistinguishable. The implementations are different, and I'll grant that the performance model is more complex for optimized DIC. > I have mixed feelings about compiler optimizations. Things like constant > folding seems to be both harmless and useful, but other optimizations not > so much. It sets up a discrepancy between what the source code does and > what the compiled code does, and in the case of (say) floating point > code, can introduce *serious* bugs. Oooh, careful now. It's important not to muddle semantics-preserving transformations (like memoizing constant immutable objects, as I'm suggesting, or constant folding) and tolerated semantics-altering transformations such as increasing precision of intermediate floating-point values. (`Tolerated' here means that some language specifications grant specific permission for these optimizations despite the fact that they don't preserve semantics.) Semantics-altering optimizations are scary, to be approached only with great trepidation. Semantics-preserving optimizations are nearly free, except for the potentially complicated performance model. > > _missing = ['missing'] > > A curious choice for the sentinel value. We're not using Python 1.5 any > longer :) Two reasons. Firstly, this comes from my Lisp background: making a list is the obvious way of producing an unforgeable object. Secondly, if you see an objects that prints as ['missing'], you have a chance of working out where it came from; for a loose object() that's kind of hard without a wabbit hunter. -- [mdw] From roy at panix.com Sat Nov 6 08:44:38 2010 From: roy at panix.com (Roy Smith) Date: Sat, 06 Nov 2010 08:44:38 -0400 Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> <87aalrjkty.fsf@benfinney.id.au> <8jd3m9Fr55U7@mid.individual.net> Message-ID: In article , Lawrence D'Oliveiro wrote: > In message <8jd3m9Fr55U7 at mid.individual.net>, Neil Cerutti wrote: > > > On 2010-11-03, Ben Finney wrote: > > > >> styles = [ > >> ("normal", "image", MainWindow.ColorsNormalList), > >> ("highlighted", "highlight", MainWindow.ColorsHighlightedList), > >> ("selected", "select", MainWindow.ColorsSelectedList)] > > > > Agreed, except cute stuff like putting those three items in > > columns is just as bad. > > > > Code should be utilitarian rather than ornate, Shaker rather than > > Victorian. > > Tufte???s concept of ???chartjunk??? could perhaps be extended to ???formatjunk??? or > ???prettyprintjunk???. Not at all. Tufte is all about making data easy to understand visually. The chartjunk he rails about is colors, shadows, 3-d effects, etc, which make a chart "look pretty" but don't add to comprehension. If you take out the extra whitespace, you end up with this: > >> styles = [ > >> ("normal", "image", MainWindow.ColorsNormalList), > >> ("highlighted", "highlight", MainWindow.ColorsHighlightedList), > >> ("selected", "select", MainWindow.ColorsSelectedList)] which I think is more difficult to scan visually. In the first example, I can see from the overall layout, without reading a single character of punctuation, that this is a sequence of groups of three items. That's harder to see in the second example. Likewise, if I want to know what kinds of things are in the second field of all the items, it's easy for me to visually scan down the second column in the first example. To do that in the second example is much more difficult. If you want to talk about "codejunk", my biggest concern here is the things in the third column. They all start with "MainWindow.Color", and they all end with "List". Thus, those bits of text add bulk, and no useful information. It would be even more readable by doing: > >> styles = [ > >> ("normal", "image", Normal), > >> ("highlighted", "highlight", Highlighted), > >> ("selected", "select", Selected)] which, of course would require some more code elsewhere to define the new names. Whether this makes sense in the context of the overall codebase is an open question, but taking the table in isolation, it certainly improves the readability. Tufte would approve. From rustompmody at gmail.com Sat Nov 6 08:53:25 2010 From: rustompmody at gmail.com (rustom) Date: Sat, 6 Nov 2010 05:53:25 -0700 (PDT) Subject: Compare source code References: <87fwveej75.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <4533a1d2-2689-45a5-9e96-e4c6f6b8d9d9@p7g2000prb.googlegroups.com> On Nov 6, 5:21?pm, m... at distorted.org.uk (Mark Wooding) wrote: > Rustom Mody writes: > > As for tools' brokeness regarding spaces/tabs/indentation heres a > > thread on the emacs list wherein emacs dev Stefan Monnier admits to > > the fact that emacs' handling in this regard is not perfect. > > >http://groups.google.com/group/gnu.emacs.help/browse_thread/thread/1b... > > You've misunderstood. ?That discussion is about configuring Emacs to not > do automatic indentation when the `tab' key is pressed or when > language-specific punctuation is entered. ?It has very little to do with > tab characters in files. The OP there clearly says he needs help in dealing consistently with 'tabbed' files. Mixing up these 2 issues (actually 3) is the 'Eternal Holy War' that Jamie Zawinski talks about here http://www.jwz.org/doc/tabs-vs-spaces.html Note: I am in no way supporting the demand that python should suddenly get 'braced' beacuse: a. this would do too much violence to the essential -- 'executable- pseudo-code' -- spirit of the language b. Anyway for me personally python and haskell are two of my favorites and one their common features is this: indentation == program structure I am only pointing to the fact that one of the widely used and super- powerful editors is less than perfect in this regard From darragh.ssa at gmail.com Sat Nov 6 09:06:09 2010 From: darragh.ssa at gmail.com (Kruptein) Date: Sat, 6 Nov 2010 06:06:09 -0700 (PDT) Subject: Deditor 0.2.2 Message-ID: Hey, I released version 0.2.2 of my pythonic text-editor Deditor. It adds the use of projects, a project is a set of files which you can open all at once to make development much faster and easier. For more information visit launchpad: http://launchpad.net/deditor I also uploaded a video to introduce you to deditor: http://www.youtube.com/watch?v=hS8xBu-39VI (note: youtube is still processing the file so you might have to wait a bit to see it) From hniksic at xemacs.org Sat Nov 6 09:29:29 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Sat, 06 Nov 2010 14:29:29 +0100 Subject: Silly newbie question - Carrot character (^) References: Message-ID: <87k4kq60na.fsf@xemacs.org> Seebs writes: > I'm a bit lost here. Could you highlight some of the differences > between "a reference manual for the language itself" and "something > written for language lawyers"? I don't speak for "Nobody", but to me a reference manual would be a document intended for the user of the language. The thing for the language lawyer is something intended for the implementor, or possibly for the very advanced user who argues with the implementor about intricacies of behavior. The latter document is also known as the "specification" or the "standard". These two types of document serve different needs and are written for different audience. In Python the choice was made for the library to be written in a reference-manual way, and for the language reference to be written in a specification way. This choice is reasonable, but it can lead to problems when you want to refer a regular user to documentation about the language for educational purposes. From trevor at jcmanagement.net Sat Nov 6 09:38:34 2010 From: trevor at jcmanagement.net (Trevor J. Christensen) Date: Sat, 06 Nov 2010 07:38:34 -0600 Subject: Deditor 0.2.2 In-Reply-To: References: Message-ID: <1289050714.29221.2.camel@linux> I really like that editor! Great work!! Great ideas!! On Sat, 2010-11-06 at 06:06 -0700, Kruptein wrote: > Hey, > > I released version 0.2.2 of my pythonic text-editor Deditor. > It adds the use of projects, a project is a set of files which you can > open all at once to make development much faster and easier. > > For more information visit launchpad: http://launchpad.net/deditor > > I also uploaded a video to introduce you to deditor: > http://www.youtube.com/watch?v=hS8xBu-39VI > (note: youtube is still processing the file so you might have to wait > a bit to see it) From googler.1.webmaster at spamgourmet.com Sat Nov 6 09:54:49 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Sat, 6 Nov 2010 06:54:49 -0700 (PDT) Subject: Get frame object of last called function Message-ID: Hi, is there any chance to get the frame object of the previous called function? I just find the 'f_back' frame object but this is the frame object of the parent function, not the previous one. I try to get the line number of the exit point of the previous function. (0) def Test(): (1) print "OK" (2) return "Foo" p = Test() #get the line number where Test() returned Any ideas? Thanks a lot! Bye, moerchendiser From philip at semanchuk.com Sat Nov 6 10:22:47 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Sat, 6 Nov 2010 10:22:47 -0400 Subject: Silly newbie question - Carrot character (^) In-Reply-To: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> On Nov 6, 2010, at 12:33 AM, Steven D'Aprano wrote: > On Fri, 05 Nov 2010 23:21:11 -0400, Philip Semanchuk wrote: > >> Take the OP's question. How is one supposed to find out about bitwise >> operators in Python? AFAICT they're not mentioned in the tutorial, and >> neither are decorators, assert(), global, exec, the ternary if >> statement, etc. > > The tutorial isn't meant as an exhaustive lesson on every single Python > feature. I agree, and I don't expect otherwise. My point was that if the tutorial doesn't mention a feature, the only other place to learn about it (on python.org) is the language ref. Some people might think the language ref is a fine place to direct newcomers to Python. I don't. It's not awful, but it's dense and unfriendly for those just starting out. > There are plenty of other resources available: learning Python > *starts* with the python.org tutorial (or some equivalent), it doesn't > end there. Yes, I agree. That's what I said in my email too. One goes through the tutorial a few times and then...? There's not a formal document to turn to after that. There are plenty of resources -- books, mailing lists, etc. But they're 3rd party, unstructured, not maintained, etc. I realize that the Python Foundation doesn't have infinite resources to work with, so maybe they'd love to create & maintain a more readable language reference if they had time/money/people. I don't hear anyone talk about it, though. bye Philip From darcy at druid.net Sat Nov 6 10:45:02 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sat, 6 Nov 2010 10:45:02 -0400 Subject: Silly newbie question - Carrot character (^) In-Reply-To: <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> Message-ID: <20101106104502.dd0456bb.darcy@druid.net> On Sat, 6 Nov 2010 10:22:47 -0400 Philip Semanchuk wrote: > > The tutorial isn't meant as an exhaustive lesson on every single Python > > feature. > > I agree, and I don't expect otherwise. My point was that if the > tutorial doesn't mention a feature, the only other place to learn about > it (on python.org) is the language ref. Some people might think the > language ref is a fine place to direct newcomers to Python. I don't. I don't think that anyone was suggesting the reference as the first place to send newcomers. You send them there when they need something beyond the basics. I think the only issue here is that operators are pretty basic and that specific thing is missing in the tutorial. It would be a mistake to write a whole new document because the tutorial is missing one thing. Better would be to propose an operators section. > I realize that the Python Foundation doesn't have infinite resources > to work with, so maybe they'd love to create & maintain a more readable > language reference if they had time/money/people. I don't hear anyone > talk about it, though. Lots of people talk. Action, not so much. How about you? Are you ready to start writing a new reference manual? How about just that one section on operators that's missing from the tutorial. Remember, Python is "we," not "they." -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From gmcduffee at mcduffee-associates.us Sat Nov 6 10:59:06 2010 From: gmcduffee at mcduffee-associates.us (F. George McDuffee) Date: Sat, 06 Nov 2010 08:59:06 -0600 Subject: *** FBI gets a warm welcome in Chicago for their EXCELLENTperformance - cheers to NEW CONS *** References: <26f97f70-9043-490c-9e6e-35159f38d76b@r29g2000yqj.googlegroups.com> <47e0b3a3-54fb-4489-95a8-b5ec6015c99d@j25g2000yqa.googlegroups.com> <6vl1d6lbohrsgg6fucilc0dj235qfs5ak6@4ax.com> Message-ID: On Tue, 02 Nov 2010 20:33:18 -0700, Gunner Asch wrote: >On Tue, 02 Nov 2010 13:58:16 -0700, Rich Grise >wrote: > >>On Tue, 02 Nov 2010 14:17:29 -0700, Gunner Asch wrote: >>> >>> But...shrug..there will be far less after the Great Cull........ >> >>I think some people might be surprised as to exactly _who_ gets "culled". >> >>Good Luck! >>Rich > >Indeed. So stock up, and watch your six. > >Gunner > ========== Here is an article/book you may like. http://www.spiegel.de/international/europe/0,1518,726672,00.html -- Unka George (George McDuffee) .............................. The past is a foreign country; they do things differently there. L. P. Hartley (1895-1972), British author. The Go-Between, Prologue (1953). From tavares at fe.up.pt Sat Nov 6 11:30:03 2010 From: tavares at fe.up.pt (tavares at fe.up.pt) Date: Sat, 6 Nov 2010 08:30:03 -0700 (PDT) Subject: =?windows-1252?Q?Symposium_=93Image_Processing_and_Analysis_in_Biomed?= =?windows-1252?Q?ical_Engineering=94_within_CompBioMed_2011_=96_Announce_=26_Ca?= =?windows-1252?Q?ll?= Message-ID: Dear Colleague, Within the 2nd International Conference on Computational & Mathematical Biomedical Engineering (CompBioMed 2011), to be held in Washington D.C., USA, in 30th March - 1st April 2011 (www.compbiomed.net), we are organizing the Symposium ?Image Processing and Analysis in Biomedical Engineering?. The main goal of this symposium is to bring together researchers involved in the related fields (image acquisition, signal processing, image processing and analysis, medical imaging, scientific visualization, software development, grid computing, etc.), in order to set the major lines of development for the near future. Therefore, this symposium will consist of researchers representing various fields related to computational vision, computer graphics, computational mechanics, mathematics, statistics, medical imaging, biomedicine, bioengineering, etc. Thus, it endeavours to make a contribution to achieving better solutions for more realistic computational ?living? models from images, and attempts to establish a bridge between clinicians, researchers and hardware manufacturers from these diverse fields. Due to your research activities in those fields, we would like to invite you to submit your work and participate in the Symposium ?Image Processing and Analysis in Biomedical Engineering?. Topics (not limited to): - Image Processing and Analysis for Biomedical Images; - Segmentation, Reconstruction, Tracking and Motion Analyse in Biomedical Images; - Biomedical Signal and Image Acquisition and Processing; - Objects Simulation and Virtual Reality for Biomedicine; - Computer Aided Diagnosis, Surgery, Therapy, Treatment and Telemedicine Systems; - Software Development for Biomedical Images; - Grid and High Performance Computing for Biomedical Images. Instructions and Submission: - For instructions and submission, please access to the conference website at: www.compbiomed.net - Please note that, when submitting your work you should select the Symposium ?Image Processing and Analysis in Biomedical Engineering?. Important dates: - Four page abstract submission - expression of interest: 15 November 2010; - Notification of acceptance: 01 December 2010; - Final camara ready abstract submission deadline: 15 January 2011. Kind regards, Jo?o Manuel R. S. Tavares (University of Porto, Portugal, tavares at fe.up.pt) Renato Natal Jorge (University of Porto, Portugal, rnatal at fe.up.pt) Yongjie Zhang (Carnegie Mellon University, USA, jessicaz at andrew.cmu.edu) (Symposium organizers) From arnodel at gmail.com Sat Nov 6 11:45:18 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Sat, 06 Nov 2010 15:45:18 +0000 Subject: Split iterator into multiple streams References: <4cd5173d$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87zktmihgx.fsf@gmail.com> Steven D'Aprano writes: > Suppose I have an iterator that yields tuples of N items (a, b, ... n). > > I want to split this into N independent iterators: > > iter1 -> a, a2, a3, ... > iter2 -> b, b2, b3, ... > ... > iterN -> n, n2, n3, ... > > The iterator may be infinite, or at least too big to collect in a list. > > My first attempt was this: > > > def split(iterable, n): > iterators = [] > for i, iterator in enumerate(itertools.tee(iterable, n)): > iterators.append((t[i] for t in iterator)) > return tuple(iterators) > > But it doesn't work, as all the iterators see the same values: > >>>> data = [(1,2,3), (4,5,6), (7,8,9)] >>>> a, b, c = split(data, 3) >>>> list(a), list(b), list(c) > ([3, 6, 9], [3, 6, 9], [3, 6, 9]) > > > I tried changing the t[i] to use operator.itergetter instead, but no > luck. Finally I got this: > > def split(iterable, n): > iterators = [] > for i, iterator in enumerate(itertools.tee(iterable, n)): > f = lambda it, i=i: (t[i] for t in it) > iterators.append(f(iterator)) > return tuple(iterators) > > which seems to work: > >>>> data = [(1,2,3), (4,5,6), (7,8,9)] >>>> a, b, c = split(data, 3) >>>> list(a), list(b), list(c) > ([1, 4, 7], [2, 5, 8], [3, 6, 9]) > > > > > Is this the right approach, or have I missed something obvious? It is quite straightforward to implement your "split" function without itertools.tee: from collections import deque def split(iterable): it = iter(iterable) q = [deque([x]) for x in it.next()] def proj(qi): while True: if not qi: for qj, xj in zip(q, it.next()): qj.append(xj) yield qi.popleft() for qi in q: yield proj(qi) >>> data = [(1,2,3), (4,5,6), (7,8,9)] >>> a, b, c = split(data) >>> print list(a), list(b), list(c) [1, 4, 7] [2, 5, 8] [3, 6, 9] Interestingly, given "split" it is very easy to implement "tee": def tee(iterable, n=2): return split(([x]*n for x in iterable)) >>> a, b = tee(range(10), 2) >>> a.next(), a.next(), b.next() (0, 1, 0) >>> a.next(), a.next(), b.next() (2, 3, 1) In fact, split(x) is the same as zip(*x) when x is finite. The difference is that with split(x), x is allowed to be infinite and with zip(*x), each term of x is allowed to be infinite. It may be good to have a function unifying the two. -- Arnaud From robert.kern at gmail.com Sat Nov 6 13:38:03 2010 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 06 Nov 2010 12:38:03 -0500 Subject: ANN: PyQt v4.8.1 Released In-Reply-To: References: Message-ID: On 11/6/10 2:34 AM, Steve Holden wrote: > On 11/5/2010 6:14 PM, Lawrence D'Oliveiro wrote: >> In message, ?????? ??????????? >> wrote: >> >>>>> PyQt is available under the GPL and a commercial license. >>>> >>>> Surely you mean ?proprietary? rather than ?commercial?. There is >>>> nothing about the GPL that prevents ?commercial? use. >>> >>> I think he means a license that *he* sells comercially :) >> >> Presumably that?s a proprietary licence. > > I don't see why. GPL v2, for example, has nothing to say about the price > charged for the software: simply that the source must be made available. Given the context, "PyQt is available under the GPL and a commercial license," the commercial license Phil is talking about is not the GPL. -- 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 usenet-nospam at seebs.net Sat Nov 6 13:48:46 2010 From: usenet-nospam at seebs.net (Seebs) Date: 06 Nov 2010 17:48:46 GMT Subject: Silly newbie question - Carrot character (^) References: <87k4kq60na.fsf@xemacs.org> Message-ID: On 2010-11-06, Hrvoje Niksic wrote: > I don't speak for "Nobody", but to me a reference manual would be a > document intended for the user of the language. The thing for the > language lawyer is something intended for the implementor, or possibly > for the very advanced user who argues with the implementor about > intricacies of behavior. The latter document is also known as the > "specification" or the "standard". I guess I would think that if such a document cannot be used as a reference, it's not very well done. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From xrgtn at yandex.ru Sat Nov 6 13:51:06 2010 From: xrgtn at yandex.ru (Alexander Gattin) Date: Sat, 6 Nov 2010 19:51:06 +0200 Subject: How find all childrens values of a nested dictionary, fast! In-Reply-To: <87d3qkkcqj.fsf@gmail.com> References: <87d3qkkcqj.fsf@gmail.com> Message-ID: <20101106175106.GB20690@xrgtn-q40> Hello, On Thu, Nov 04, 2010 at 09:20:04PM +0000, Arnaud Delobelle wrote: > Tough requirement, but I think I've got it. Two > lambdas, one reduce, one map ;) > > >>> a = {'a' : {'b' :{'/' :[1,2,3,4], 'ba' :{'/' :[41,42,44]}, 'bc' :{'/':[51,52,54], 'bcd' :{'/':[68,69,66]}}},'c' :{'/' :[5,6,7,8]}},'ab' : {'/' :[12,13,14,15]}, 'ac' :{'/' :[21,22,23]}} > >>> f = lambda v,k=None: v if k=="/" else reduce(list.__add__, map(lambda k: f(v[k],k), v), []) Is it that new Python3 thing? :) P.S. Here is my variant that still works in python2: def i(x): r = [] for k, v in x.iteritems(): try: r.extend(i(v)) except: if k == '/': r.extend(v) return r -- With best regards, xrgtn From jon.dufresne at gmail.com Sat Nov 6 14:22:08 2010 From: jon.dufresne at gmail.com (Jon Dufresne) Date: Sat, 6 Nov 2010 11:22:08 -0700 Subject: How to test if a module exists? Message-ID: Hi, My python program has an extension system where the extension can have a optional magic python modules. Meaning if the extension module exists, the program will use it and if not, it will continue without the module. So my program tests if a module exists, if so use it, otherwise continue. This is how I originally did this (pseudo code): try: import extension_magic_module except ImportError: pass else: handle_extension_magic_module() However, if the the extension module exists but throws an ImportError, due to a bug in the extension this idiom will mask the error and I will never see it. Later on in the program I will get unexpected behavior because the module never successfully imported. I want the program to fail if the extension module fails to import, but continue if the module doesn't exist. Is there a correct way to handle this? Jon From clp2 at rebertia.com Sat Nov 6 14:35:26 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 6 Nov 2010 11:35:26 -0700 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: On Sat, Nov 6, 2010 at 11:22 AM, Jon Dufresne wrote: > Hi, > > My python program has an extension system where the extension can have > a optional magic python modules. Meaning if the extension module > exists, the program will use it and if not, it will continue without > the module. So my program tests if a module exists, if so use it, > otherwise continue. This is how I originally did this (pseudo code): > > > try: > ? ?import extension_magic_module > except ImportError: > ? ?pass > else: > ? ?handle_extension_magic_module() > > > However, if the the extension module exists but throws an ImportError, > due to a bug in the extension this idiom will mask the error and I > will never see it. Later on in the program I will get unexpected > behavior because the module never successfully imported. I want the > program to fail if the extension module fails to import, but continue > if the module doesn't exist. Is there a correct way to handle this? Here's what I came up with: try: ? ?import extension_magic_module except ImportError as err: if err.message != "No module named extension_magic_module": raise err else: handle_extension_magic_module() Cheers, Chris -- http://blog.rebertia.com From nad at acm.org Sat Nov 6 14:38:49 2010 From: nad at acm.org (Ned Deily) Date: Sat, 06 Nov 2010 11:38:49 -0700 Subject: Silly newbie question - Carrot character (^) References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> Message-ID: In article <11A0F261-1BF4-4C35-83FA-C47BF968D150 at semanchuk.com>, Philip Semanchuk wrote: > On Nov 6, 2010, at 12:33 AM, Steven D'Aprano wrote: > > On Fri, 05 Nov 2010 23:21:11 -0400, Philip Semanchuk wrote: > > > >> Take the OP's question. How is one supposed to find out about bitwise > >> operators in Python? AFAICT they're not mentioned in the tutorial, and > >> neither are decorators, assert(), global, exec, the ternary if > >> statement, etc. > > > > The tutorial isn't meant as an exhaustive lesson on every single Python > > feature. > > I agree, and I don't expect otherwise. My point was that if the tutorial > doesn't mention a feature, the only other place to learn about it (on > python.org) is the language ref. Some people might think the language ref is > a fine place to direct newcomers to Python. I don't. It's not awful, but it's > dense and unfriendly for those just starting out. In the Python documentation set, the language reference should usually be the second place to send someone. The first place is The Python Standard Library manual where built-in types and the methods supported by them are documented. For bit string operations: http://docs.python.org/library/stdtypes.html#bit-string-operations-on-int eger-types -- Ned Deily, nad at acm.org From jon.dufresne at gmail.com Sat Nov 6 14:50:35 2010 From: jon.dufresne at gmail.com (Jon Dufresne) Date: Sat, 6 Nov 2010 11:50:35 -0700 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: On Sat, Nov 6, 2010 at 11:35 AM, Chris Rebert wrote: > Here's what I came up with: > > try: > ?? ?import extension_magic_module > except ImportError as err: > ? ?if err.message != "No module named extension_magic_module": > ? ? ? ?raise err > else: > ? ?handle_extension_magic_module() > It seems less than ideal to tie my program's behavior to what essentially boils down to a documentation string. Is this the preferred way to handle this? Jon From gunnerasch at gmail.com Sat Nov 6 15:37:54 2010 From: gunnerasch at gmail.com (Gunner Asch) Date: Sat, 06 Nov 2010 12:37:54 -0700 Subject: *** FBI gets a warm welcome in Chicago for their EXCELLENTperformance - cheers to NEW CONS *** References: <26f97f70-9043-490c-9e6e-35159f38d76b@r29g2000yqj.googlegroups.com> <47e0b3a3-54fb-4489-95a8-b5ec6015c99d@j25g2000yqa.googlegroups.com> <6vl1d6lbohrsgg6fucilc0dj235qfs5ak6@4ax.com> Message-ID: On Sat, 06 Nov 2010 08:59:06 -0600, F. George McDuffee wrote: >On Tue, 02 Nov 2010 20:33:18 -0700, Gunner Asch > wrote: > >>On Tue, 02 Nov 2010 13:58:16 -0700, Rich Grise >>wrote: >> >>>On Tue, 02 Nov 2010 14:17:29 -0700, Gunner Asch wrote: >>>> >>>> But...shrug..there will be far less after the Great Cull........ >>> >>>I think some people might be surprised as to exactly _who_ gets "culled". >>> >>>Good Luck! >>>Rich >> >>Indeed. So stock up, and watch your six. >> >>Gunner >> >========== >Here is an article/book you may like. >http://www.spiegel.de/international/europe/0,1518,726672,00.html Like...no. Will have to read...yes. Danke Gunner > > >-- Unka George (George McDuffee) >.............................. >The past is a foreign country; >they do things differently there. >L. P. Hartley (1895-1972), British author. >The Go-Between, Prologue (1953). -- "Confiscating wealth from those who have earned it, inherited it, or got lucky is never going to help 'the poor.' Poverty isn't caused by some people having more money than others, just as obesity isn't caused by McDonald's serving super-sized orders of French fries Poverty, like obesity, is caused by the life choices that dictate results." - John Tucci, From mdw at distorted.org.uk Sat Nov 6 15:57:06 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Sat, 06 Nov 2010 19:57:06 +0000 Subject: functions, list, default parameters References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <20101021235138.609fe668@geekmail.INVALID> <87pquk3ehs.fsf.mdw@metalzone.distorted.org.uk> <4cd3c72b$0$30004$c3e8da3$5496439d@news.astraweb.com> <8739rg2ceb.fsf.mdw@metalzone.distorted.org.uk> <4cd4cc74$0$30004$c3e8da3$5496439d@news.astraweb.com> <87bp62eig9.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <87y696cjjh.fsf.mdw@metalzone.distorted.org.uk> Dennis Lee Bieber writes: > On Sat, 06 Nov 2010 12:37:42 +0000, mdw at distorted.org.uk (Mark Wooding) > declaimed the following in gmane.comp.python.general: > > > > > Two reasons. Firstly, this comes from my Lisp background: making a > > list is the obvious way of producing an unforgeable object. > > Secondly, if you see an objects that prints as ['missing'], you have > > a chance of working out where it came from; for a loose object() > > that's kind of hard without a wabbit hunter. > > > I think the Python form is to create a basic class instance, a la > > >>> class Sentinal(object): > ... pass > ... > >>> _missing = Sentinal() > >>> print _missing > <__main__.Sentinal object at 0x011F01B0> No, that doesn't tell me where it came from at all. Given a thingy that prints like that, I still need a wabbit hunter to tell me what /this/ particular sentinel value means. > Or, if one wants to get fancier (maybe stuff the class definition > into some common package) > > > >>> class Sentinal(object): > ... def __init__(self, text): > ... self.text = text > ... def __str__(self): > ... return "%s : %s" % (repr(self), self.text) > ... > >>> _missing = Sentinal("Missing Items") > >>> print _missing > <__main__.Sentinal object at 0x0120D070> : Missing Items And the advantage of all of this typing over ['missing'] is what, precisely? If I want to write Java, I know where to look; I don't. -- [mdw] From rtw at rtw.me.uk Sat Nov 6 15:59:46 2010 From: rtw at rtw.me.uk (Rob Williscroft) Date: Sat, 6 Nov 2010 19:59:46 +0000 (UTC) Subject: How to test if a module exists? References: Message-ID: Jon Dufresne wrote in news:AANLkTikr5euHQPupA3yRid98OaS92ZFHK8U9Lha5YVrv at mail.gmail.com in gmane.comp.python.general: > try: > import extension_magic_module > except ImportError: > pass > else: > handle_extension_magic_module() > > > However, if the the extension module exists but throws an ImportError, > due to a bug in the extension this idiom will mask the error and I > will never see it. import imp try: m = imp.find_module( "test_1" ) if m[0]: m[0].close() except ImportError: pass else: import test_1 http://docs.python.org/library/imp.html#imp.find_module Rob. From mdw at distorted.org.uk Sat Nov 6 16:01:17 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Sat, 06 Nov 2010 20:01:17 +0000 Subject: How to test if a module exists? References: Message-ID: <87r5eycjci.fsf.mdw@metalzone.distorted.org.uk> Chris Rebert writes: > if err.message != "No module named extension_magic_module": Ugh! Surely this can break if you use Python with different locale settings! -- [mdw] From rantingrick at gmail.com Sat Nov 6 16:41:33 2010 From: rantingrick at gmail.com (rantingrick) Date: Sat, 6 Nov 2010 13:41:33 -0700 (PDT) Subject: Silly newbie question - Carrot character (^) References: Message-ID: On Nov 5, 5:51?pm, Seebs wrote: > On 2010-11-05, Nobody wrote: > > > However, it's still written for language lawyers. > > IMHO, the lack of a reference manual for the language itself is a major > > hole in Python's documentation. > > I'm a bit lost here. ?Could you highlight some of the differences > between "a reference manual for the language itself" and "something > written for language lawyers"? In a word HUMOR! Obviously the commentator who has a lack of the hidden meaning of "language lawyers" has no sense of humor -- sadly another lost virtue of the French! From usenet-nospam at seebs.net Sat Nov 6 16:42:43 2010 From: usenet-nospam at seebs.net (Seebs) Date: 06 Nov 2010 20:42:43 GMT Subject: Silly newbie question - Carrot character (^) References: Message-ID: On 2010-11-06, rantingrick wrote: > On Nov 5, 5:51?pm, Seebs wrote: >> I'm a bit lost here. ?Could you highlight some of the differences >> between "a reference manual for the language itself" and "something >> written for language lawyers"? > In a word HUMOR! Huh? > Obviously the commentator who has a lack of the > hidden meaning of "language lawyers" has no sense of humor -- sadly > another lost virtue of the French! It is a shame that there was a guy standing behind you with a gun preventing you from explaining what the alleged hidden meaning was, so all you could do is allude to it without explaining it. Maybe later you can get away from your captors and post an explanation of what the "hidden meaning" is, in your eyes? -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From steve at holdenweb.com Sat Nov 6 16:52:17 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 06 Nov 2010 16:52:17 -0400 Subject: Silly newbie question - Carrot character (^) In-Reply-To: <20101106104502.dd0456bb.darcy@druid.net> References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> <20101106104502.dd0456bb.darcy@druid.net> Message-ID: <4CD5C001.9000202@holdenweb.com> On 11/6/2010 10:45 AM, D'Arcy J.M. Cain wrote: >> I realize that the Python Foundation doesn't have infinite resources >> > to work with, so maybe they'd love to create & maintain a more readable >> > language reference if they had time/money/people. I don't hear anyone >> > talk about it, though. While that isn't a current priority it certainly seems like a worthy goal to me. But the Python Software Foundation is people, and we certainly don't have the resources to simply enter into a contract with an organization to produce "a more readable language reference" - whether those resources are time, money or people (which can tend to become indistinguishable when planning is underway). We would love for Python's documentation to be even better, but the last major change in the documentation (the dropping of LATEX as the source language and the switch to Sphinx) was largely a result of one person (Georg Brandl) scratching an itch. Maybe a more readable language reference will come about the same way ... > Lots of people talk. Action, not so much. How about you? Are you > ready to start writing a new reference manual? How about just that one > section on operators that's missing from the tutorial. > That ought to be quite a manageable project. > Remember, Python is "we," not "they." > Quite. having-no-wish-to-be-they-ly - steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From roy at panix.com Sat Nov 6 16:52:35 2010 From: roy at panix.com (Roy Smith) Date: Sat, 06 Nov 2010 16:52:35 -0400 Subject: How to test if a module exists? References: Message-ID: In article , Chris Rebert wrote: > On Sat, Nov 6, 2010 at 11:22 AM, Jon Dufresne wrote: [...] > > However, if the the extension module exists but throws an ImportError, > > due to a bug in the extension this idiom will mask the error and I > > will never see it. Later on in the program I will get unexpected > > behavior because the module never successfully imported. I want the > > program to fail if the extension module fails to import, but continue > > if the module doesn't exist. Is there a correct way to handle this? > > Here's what I came up with: > > try: > ?? ??import extension_magic_module > except ImportError as err: > if err.message != "No module named extension_magic_module": > raise err > else: > handle_extension_magic_module() As Mark Wooding pointed out in another post, relying on the text of the exception message is a bad idea. It seems to me that if your module has a bug in it, it's likely to throw something other than ImportError, so catching ImportError is probably good enough. On the other hand, if your module's bug is that it in turn imports some other module, which doesn't exist, you'll also get an ImportError. It sounds like what you want to do is differentiate between ImportError thrown at the top level, and ImportError thrown somewhere deeper in the stack. The best way I can see to do that is to catch ImportError and look to see how long the chain of tb_next references is in sys.exc_traceback. If sys.exc_traceback.tb_next is None, the exception was thrown at the top level (and your magic module doesn't exist). Here's a rough example to illustrate what I'm talking about: import sys try: import xx except ImportError: tb = sys.exc_traceback while tb: print tb tb = tb.tb_next It's a little funky, but I think the concept is sound, and it should be portable. From clp2 at rebertia.com Sat Nov 6 16:54:09 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 6 Nov 2010 13:54:09 -0700 Subject: How to test if a module exists? In-Reply-To: <87r5eycjci.fsf.mdw@metalzone.distorted.org.uk> References: <87r5eycjci.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On Sat, Nov 6, 2010 at 1:01 PM, Mark Wooding wrote: > Chris Rebert writes: > >> ? ? if err.message != "No module named extension_magic_module": > > Ugh! ?Surely this can break if you use Python with different locale > settings! Since when does Python have translated error messages? Cheers, Chris From clp2 at rebertia.com Sat Nov 6 17:09:18 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 6 Nov 2010 14:09:18 -0700 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: On Sat, Nov 6, 2010 at 11:50 AM, Jon Dufresne wrote: > On Sat, Nov 6, 2010 at 11:35 AM, Chris Rebert wrote: >> Here's what I came up with: >> >> try: >> ?? ?import extension_magic_module >> except ImportError as err: >> ? ?if err.message != "No module named extension_magic_module": >> ? ? ? ?raise err >> else: >> ? ?handle_extension_magic_module() >> > > It seems less than ideal to tie my program's behavior to what > essentially boils down to a documentation string. Yeah, personally I was surprised and annoyed that the module name wasn't available by itself as some attribute of the ImportError (e.g. err.module_name); that would have lent itself to a very elegant solution to your problem. Cheers, Chris From mdw at distorted.org.uk Sat Nov 6 18:33:15 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Sat, 06 Nov 2010 22:33:15 +0000 Subject: How to test if a module exists? References: <87r5eycjci.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <877hgqccb8.fsf.mdw@metalzone.distorted.org.uk> Chris Rebert writes: > Since when does Python have translated error messages? It doesn't yet. How much are you willing to bet that it never will? ;-) -- [mdw] From steve at REMOVE-THIS-cybersource.com.au Sat Nov 6 18:37:23 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Nov 2010 22:37:23 GMT Subject: How to test if a module exists? References: <87r5eycjci.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <4cd5d8a3$0$30004$c3e8da3$5496439d@news.astraweb.com> On Sat, 06 Nov 2010 13:54:09 -0700, Chris Rebert wrote: > On Sat, Nov 6, 2010 at 1:01 PM, Mark Wooding > wrote: >> Chris Rebert writes: >> >>> ? ? if err.message != "No module named extension_magic_module": >> >> Ugh! ?Surely this can break if you use Python with different locale >> settings! > > Since when does Python have translated error messages? Since Python 3.2.4. Or will it be 3.3.5? I will forget. *wink* The point is that Python makes no promises about the error messages. The OP might be using a localised version, or some implementation that's not CPython, or the next version of Python might change the error message. Hell, a user should be able to hack their personal copy of Python and customize the error strings without having to fear that code will break. -- Steven From roy at panix.com Sat Nov 6 18:48:46 2010 From: roy at panix.com (Roy Smith) Date: Sat, 06 Nov 2010 18:48:46 -0400 Subject: How to test if a module exists? References: <87r5eycjci.fsf.mdw@metalzone.distorted.org.uk> <4cd5d8a3$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <4cd5d8a3$0$30004$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > > Since when does Python have translated error messages? > > Since Python 3.2.4. Or will it be 3.3.5? I will forget. > > *wink* from __future__ import bugs :-) From timr at probo.com Sat Nov 6 18:53:48 2010 From: timr at probo.com (Tim Roberts) Date: Sat, 06 Nov 2010 15:53:48 -0700 Subject: execute shell script from python, needs sys.argv References: Message-ID: <1vmbd65uaj2snq1v0vo49ktn0lsc2o5m1a@4ax.com> Benjamin Kaplan wrote: > >Python is not the shell. Shell commands are not python commands. You >need either a string or a list of strings, so any literal have to be >in quotes. Also, subprocess can't handle the redirection. You need to >run it as two commands. > >proc1 = subprocess.Popen(["cat", sys.argv[1]],stdout = >subprocess.PIPE, shell = True) >proc2 = subprocess.Popen(["fastx_trimmer", "-n", "COUNT", "-o", >sys.argv[2]],stdin=proc1.stdout, shell=True) I KNOW that we're still working on syntax here, and that it's too early for optimization, but it bothers me to see "cat" as the first thing in a pipeline. You don't actually need two steps here at all: proc1 = subprocess.Popen( ["fastx_trimmer", "-n", "COUNT", "-o", sys.argv[2], stdin=open(sys.argv[1]), shell=True ) With this, I don't think you even need "shell=True". -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From steve at REMOVE-THIS-cybersource.com.au Sat Nov 6 19:07:52 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Nov 2010 23:07:52 GMT Subject: functions, list, default parameters References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <20101021235138.609fe668@geekmail.INVALID> <87pquk3ehs.fsf.mdw@metalzone.distorted.org.uk> <4cd3c72b$0$30004$c3e8da3$5496439d@news.astraweb.com> <8739rg2ceb.fsf.mdw@metalzone.distorted.org.uk> <4cd4cc74$0$30004$c3e8da3$5496439d@news.astraweb.com> <87bp62eig9.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <4cd5dfc8$0$30004$c3e8da3$5496439d@news.astraweb.com> On Sat, 06 Nov 2010 12:37:42 +0000, Mark Wooding wrote: >> > _missing = ['missing'] >> >> A curious choice for the sentinel value. We're not using Python 1.5 any >> longer > > Two reasons. Firstly, this comes from my Lisp background: making a list > is the obvious way of producing an unforgeable object. Secondly, if you > see an objects that prints as ['missing'], you have a chance of working > out where it came from; for a loose object() that's kind of hard without > a wabbit hunter. But surely you shouldn't expect to only have the repr() of the value to go by. You'll have a traceback, which shows you not just that you have a sentinel, but where it ended up. It seems silly to me to fear seeing a bare object() more than all the other objects that give no context as to where they come from. If you see None, or [], or 1, out of context, you're going to have trouble working out what it's used for too. At least object() is rare -- it shouldn't be hard to do a search through the source code to find where it is created and from there find out where it is used. To me, the idiom x = object() says "missing value" MORE strongly than the Lisp-ism x = ['missing']. After all, x = object() has no state, and no methods to speak of, what else could it be other than a sentinel? But ['missing'] has state, it's mutable, it has methods up the whazoo. If you fear your code will expose it to the caller, why don't you fear that your code will mutate it to ['found now'], or something equally confounding? The problem with the Lisp-ism is that the object ['missing'] could have many uses and could be modified. Without context, I'd be wondering whether I'd stumbled across a really short list of gerunds ("the missing kettle") or verbs. If you're writing code that does a lot of text processing, that won't be an outlandish thought. If I had a lot of sentinels in the one module and for some bizarre reason couldn't re-use them, and so needed many different unique sentinels that needed to be distinguished, then I'd probably lean towards using ['the'] ['Lisp'] ['idiom']. But for just one, I stick with my claim that object() says "missing" more strongly than ['missing'], strange as it may seem :) -- Steven From nobody at nowhere.com Sat Nov 6 19:19:18 2010 From: nobody at nowhere.com (Nobody) Date: Sat, 06 Nov 2010 23:19:18 +0000 Subject: Silly newbie question - Carrot character (^) References: Message-ID: On Fri, 05 Nov 2010 22:51:10 +0000, Seebs wrote: >> IMHO, the lack of a reference manual for the language itself is a major >> hole in Python's documentation. > > I'm a bit lost here. Could you highlight some of the differences between > "a reference manual for the language itself" and "something written for > language lawyers"? A reference manual tells you how to use the language. A specification tells you how to implement it. It's possible to /deduce/ how to use the language from a specification, but it could take significant time and effort. A specification is typically designed to be read in its entirety, and may yield little usable information until you've read a substantial portion of it. A reference manual is structured such that you can easily locate the portion which is necessary for the task immediately to hand, and only need to read that portion. OTOH, a tutorial typically isn't exhaustive. And even if it is, the information related to a topic may be scattered throughout multiple sections, making it hard to find a specific piece of information. E.g. the syntax of expressions adheres rather rigidly to the grammar used for parsing, which is fine for a specification, but not how a reference manual would normally be written. From steve at REMOVE-THIS-cybersource.com.au Sat Nov 6 20:06:25 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 07 Nov 2010 00:06:25 GMT Subject: Silly newbie question - Carrot character (^) References: Message-ID: <4cd5ed80$0$30004$c3e8da3$5496439d@news.astraweb.com> On Sat, 06 Nov 2010 23:19:18 +0000, Nobody wrote: > On Fri, 05 Nov 2010 22:51:10 +0000, Seebs wrote: > >>> IMHO, the lack of a reference manual for the language itself is a >>> major hole in Python's documentation. >> >> I'm a bit lost here. Could you highlight some of the differences >> between "a reference manual for the language itself" and "something >> written for language lawyers"? > > A reference manual tells you how to use the language. A specification > tells you how to implement it. Surely a tutorial tells you *how* to use the language. I wouldn't expect a reference manual to teach me how to run and edit programs -- the *how* of using the language. And a specification ("for language lawyers") tells you *what* to implement, not how. E.g. a specification should tell you that the language needs a sorted() function, what arguments it takes, and what it should do. It should not tell you how to implement it (Quicksort or Timsort? Sort pointers to items or an array of items? External sort or in- memory sort?). Any instructions on how to implement the language will depend on what language you're implementing it in. An implementers guide written for C programmers will be very different from one written for Lisp or Forth or Haskell programmers. > It's possible to /deduce/ how to use the language from a specification, > but it could take significant time and effort. I think you're looking for hard distinctions that simply doesn't exist. By it's very nature, documentation of all types falls into a continuum of overlapping fuzzy sets. But to the extent that the terms have any specific meaning, a reference manual and something for the language lawyers (a specification) are the same thing. Different specific reference manuals may be aimed at different levels of sophistication, more or less successfully, but arguments about categories are pointless since we're rarely going to agree on the definition of the categories. If you want to argue that the Python reference manual is aimed at the wrong level of sophistication, specifically that the BNF syntax stuff should be ripped out into another document, then I might agree with you. But to argue that it's entirely the wrong "kind" of thing is, in my opinion, unjustified. -- Steven From usenet-nospam at seebs.net Sat Nov 6 20:34:55 2010 From: usenet-nospam at seebs.net (Seebs) Date: 07 Nov 2010 00:34:55 GMT Subject: How to test if a module exists? References: <87r5eycjci.fsf.mdw@metalzone.distorted.org.uk> <4cd5d8a3$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-06, Roy Smith wrote: > from __future__ import bugs Now I want this. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From mdw at distorted.org.uk Sat Nov 6 20:48:31 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Sun, 07 Nov 2010 00:48:31 +0000 Subject: Silly newbie question - Carrot character (^) References: <4cd5ed80$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87sjzearhc.fsf.mdw@metalzone.distorted.org.uk> Steven D'Aprano writes: > If you want to argue that the Python reference manual is aimed at the > wrong level of sophistication, specifically that the BNF syntax stuff > should be ripped out into another document, then I might agree with > you. But to argue that it's entirely the wrong "kind" of thing is, in > my opinion, unjustified. I certainly wouldn't agree with that. The language's syntax is essential part of the language, and must be described clearly and unambiguously. Formal grammars aren't especially hard to understand, and they're pretty much everywhere, so learning how to read them is an essential skill anyway. To be honest, I reckon the Python language reference is too friendly and fluffy. The manual for F#, say, is a harder read. The Standard ML language reference is a book full of mathematical notation (inference rules for operational semantics, mainly) and little else. The Scheme language used to be described by a page or so of equations giving a translation into lambda calculus (but now that's operational semantics too) -- oh, there are prose descriptions too, but they're not easy going either in places, and the formal semantics are necessary to clear up some of the details. You Python people have it easy. -- [mdw] From usenet-nospam at seebs.net Sat Nov 6 21:05:56 2010 From: usenet-nospam at seebs.net (Seebs) Date: 07 Nov 2010 01:05:56 GMT Subject: Silly newbie question - Carrot character (^) References: <4cd5ed80$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-07, Steven D'Aprano wrote: > Surely a tutorial tells you *how* to use the language. I wouldn't expect > a reference manual to teach me how to run and edit programs -- the *how* > of using the language. There's a sort of fuzzy boundary about how the term "reference manual" is used. Some people view it more in terms of presenting, for each major feature or class of functionality, an overview of what you need to know to use it, which may not be everything you need to know to implement it correctly. Consider: In Python, indentation determines control flow. Statements which take a block of code must be followed by at least one line of a greater indentation level; all following lines of that indentation level are part of the block, ending at the first line which is less indented than the block. Each block should be indented by four spaces from the preceeding block, and tabs should not be used. That might be quite suitable* for a "reference manual" as many people use the term, but would be useless for a language lawyer. A language lawyer needs to know that " \t" at the beginning of a line is construed to be the same indentation level as " " or "\t". A typical reference manual might simply ignore that information because it's telling you what you need to write good code, not what you need to know to write a compatible implementation. That said... I am certainly biased on the issue, but IMHO a reference manual should not "gloss over" things like that, but should be at least as detailed as a formal specification; where it might differ is in *additional* material with explanations and clarifications. YMMV. -s [*] Well, imagine that, only written better and properly edited, and so on. -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From hniksic at xemacs.org Sat Nov 6 21:17:25 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Sun, 07 Nov 2010 02:17:25 +0100 Subject: Silly newbie question - Carrot character (^) References: <87k4kq60na.fsf@xemacs.org> Message-ID: <87fwve53ve.fsf@xemacs.org> Seebs writes: > On 2010-11-06, Hrvoje Niksic wrote: >> I don't speak for "Nobody", but to me a reference manual would be a >> document intended for the user of the language. The thing for the >> language lawyer is something intended for the implementor, or possibly >> for the very advanced user who argues with the implementor about >> intricacies of behavior. The latter document is also known as the >> "specification" or the "standard". > > I guess I would think that if such a document cannot be used as a > reference, it's not very well done. It's not a matter of quality, but of intended audience. To most ordinary programmers the standards documents such as the C standard, the C++ standard, or the Python reference are quite dense and hard to use as a reference, and yet they are considered quite well done. From ldo at geek-central.gen.new_zealand Sat Nov 6 21:51:01 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 07 Nov 2010 14:51:01 +1300 Subject: ANN: PyQt v4.8.1 Released References: Message-ID: In message , Robert Kern wrote: > On 11/6/10 2:34 AM, Steve Holden wrote: > >> On 11/5/2010 6:14 PM, Lawrence D'Oliveiro wrote: >> >>> In message, ?????? >>> ??????????? wrote: >>> >>>>>> PyQt is available under the GPL and a commercial license. >>>>> >>>>> Surely you mean ?proprietary? rather than ?commercial?. There is >>>>> nothing about the GPL that prevents ?commercial? use. >>>> >>>> I think he means a license that *he* sells comercially :) >>> >>> Presumably that?s a proprietary licence. >> >> I don't see why. GPL v2, for example, has nothing to say about the price >> charged for the software: simply that the source must be made available. > > Given the context, "PyQt is available under the GPL and a commercial > license," the commercial license Phil is talking about is not the GPL. Which is a wrong interpretation of ?commercial?. From ldo at geek-central.gen.new_zealand Sat Nov 6 21:53:45 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 07 Nov 2010 14:53:45 +1300 Subject: Compare source code References: <4cd4c6cf$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: In message , Seebs wrote: > Specifically: > > Four spaces followed by a tab nearly always actually means "eight spaces" > to most editors (and Python seems to treat it that way), but it's hard to > tell. Worse, a tab may have been intended to be the same thing as four > spaces, and someone was expecting it NOT to be the same as eight spaces... Whereas explicitly-bracketed languages leave no ambiguity about how many brackets you need and where. From jon.dufresne at gmail.com Sat Nov 6 21:57:36 2010 From: jon.dufresne at gmail.com (Jon Dufresne) Date: Sat, 6 Nov 2010 18:57:36 -0700 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: On Sat, Nov 6, 2010 at 1:52 PM, Roy Smith wrote: > > import sys > try: > ? ?import xx > except ImportError: > ? ?tb = sys.exc_traceback > ? ?while tb: > ? ? ? ?print tb > ? ? ? ?tb = tb.tb_next > I went ahead and implemented this and it now works. I even uncovered a bug I wasn't previously seeing because now the program was failing early! :) I hope there isn't a hidden naivete in using this pattern. Thanks, Jon From usenet-nospam at seebs.net Sat Nov 6 22:19:41 2010 From: usenet-nospam at seebs.net (Seebs) Date: 07 Nov 2010 02:19:41 GMT Subject: Compare source code References: <4cd4c6cf$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-07, Lawrence D'Oliveiro wrote: > In message , Seebs wrote: >> Four spaces followed by a tab nearly always actually means "eight spaces" >> to most editors (and Python seems to treat it that way), but it's hard to >> tell. Worse, a tab may have been intended to be the same thing as four >> spaces, and someone was expecting it NOT to be the same as eight spaces... > Whereas explicitly-bracketed languages leave no ambiguity about how many > brackets you need and where. Well, the good ones don't. :P (I think the optional nature of brackets is probably a flaw in C. It would break too much existing code to fix it, sadly.) -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Sat Nov 6 22:26:01 2010 From: usenet-nospam at seebs.net (Seebs) Date: 07 Nov 2010 02:26:01 GMT Subject: Silly newbie question - Carrot character (^) References: <87k4kq60na.fsf@xemacs.org> <87fwve53ve.fsf@xemacs.org> Message-ID: On 2010-11-07, Hrvoje Niksic wrote: > It's not a matter of quality, but of intended audience. To most > ordinary programmers the standards documents such as the C standard, the > C++ standard, or the Python reference are quite dense and hard to use as > a reference, and yet they are considered quite well done. Huh. I quite liked the C spec as a reference. Yeah, it's a bit dense, but that just means it's all actually *reference*. :) -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From roy at panix.com Sat Nov 6 22:34:28 2010 From: roy at panix.com (Roy Smith) Date: Sat, 06 Nov 2010 22:34:28 -0400 Subject: How to test if a module exists? References: Message-ID: In article , Jon Dufresne wrote: > I went ahead and implemented this and it now works. I even uncovered a > bug I wasn't previously seeing because now the program was failing > early! :) Excellent. Fail early and often, that's what I say. From roy at panix.com Sat Nov 6 23:10:21 2010 From: roy at panix.com (Roy Smith) Date: Sat, 06 Nov 2010 23:10:21 -0400 Subject: Silly newbie question - Carrot character (^) References: <87k4kq60na.fsf@xemacs.org> <87fwve53ve.fsf@xemacs.org> Message-ID: In article <87fwve53ve.fsf at xemacs.org>, Hrvoje Niksic wrote: > It's not a matter of quality, but of intended audience. To most > ordinary programmers the standards documents such as the C standard, the > C++ standard, or the Python reference are quite dense and hard to use as > a reference, and yet they are considered quite well done. Not only is the C++ reference obtuse and dense, it's also not commonly available. It is copyright by ISO and only available for a fee. I own a copy, but I'd venture to say that the vast majority of C++ programmers out there have never seen one. Heck, if was a programmer and wanted to spend money today to buy a copy, I wouldn't even know where to go to order one. I googled for "iso c++ standard" and found http://www.open-std.org/jtc1/sc22/wg21/, which includes a well-hidden link to http://www.open-std.org/jtc1/sc22/wg21/docs/standards, which says, "Published ISO and IEC standards can be purchased from a member body of ISO or IEC". How one would go about figuring out who such member body is, I have no idea. Any self-respecting C++ programmer would have given up the scavenger hunt by now. Just kept throwing typecasts at your code until it compiles, and move on. Python may not have a reference manual which is up to the quality of the C++ manual, but what's there is freely available on docs.python.org. As for the subject of this thread, you might want to check out http://archive.midrange.com/midrange-l/200703/msg00036.html. From aahz at pythoncraft.com Sat Nov 6 23:31:08 2010 From: aahz at pythoncraft.com (Aahz) Date: 6 Nov 2010 20:31:08 -0700 Subject: how to handle network failures References: <7bee5155-f1a1-44aa-90f6-eaabb361729f@v6g2000prd.googlegroups.com> Message-ID: In article <7bee5155-f1a1-44aa-90f6-eaabb361729f at v6g2000prd.googlegroups.com>, harryos wrote: > >class DataGrabber(threading.Thread): > def __init__(self,url): > threading.Thread.__init__(self) > self.url=url > def run(self): > data=self.get_page_data() > process_data(data) > > def get_page_data(): > try: > f=urllib.urlopen(self.url) > data=f.read(1024) > except IOError: > #wait for some time and try again > time.sleep(120) > data=self.get_page_data() > return data Use urllib2 so that you can set a timeout (Python 2.6+). -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." --Red Adair From usenet-nospam at seebs.net Sat Nov 6 23:35:55 2010 From: usenet-nospam at seebs.net (Seebs) Date: 07 Nov 2010 03:35:55 GMT Subject: Silly newbie question - Carrot character (^) References: <87k4kq60na.fsf@xemacs.org> <87fwve53ve.fsf@xemacs.org> Message-ID: On 2010-11-07, Roy Smith wrote: > Any self-respecting C++ programmer would have given > up the scavenger hunt by now. Just kept throwing typecasts at your code > until it compiles, and move on. That does not sound like a self-respecting programmer of anything. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From steve at REMOVE-THIS-cybersource.com.au Sun Nov 7 00:26:16 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 07 Nov 2010 04:26:16 GMT Subject: Compare source code References: <4cd4c6cf$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4cd62a68$0$30004$c3e8da3$5496439d@news.astraweb.com> On Sun, 07 Nov 2010 14:53:45 +1300, Lawrence D'Oliveiro wrote: > In message , Seebs wrote: > >> Specifically: >> >> Four spaces followed by a tab nearly always actually means "eight >> spaces" to most editors (and Python seems to treat it that way), but >> it's hard to tell. Worse, a tab may have been intended to be the same >> thing as four spaces, and someone was expecting it NOT to be the same >> as eight spaces... > > Whereas explicitly-bracketed languages leave no ambiguity about how many > brackets you need and where. Yes, and? The way people[1] go on, and on, and ON about braces and indentation, anyone would think that the hardest part of programming was deciding how many times to press the tab key. Besides, if we used reverse Polish notation, we wouldn't need either brackets or indentation. Forth rules-ly y'rs, -- Steven [1] I include myself. From usenet-nospam at seebs.net Sun Nov 7 00:28:29 2010 From: usenet-nospam at seebs.net (Seebs) Date: 07 Nov 2010 04:28:29 GMT Subject: Compare source code References: <4cd4c6cf$0$30004$c3e8da3$5496439d@news.astraweb.com> <4cd62a68$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-07, Steven D'Aprano wrote: > On Sun, 07 Nov 2010 14:53:45 +1300, Lawrence D'Oliveiro wrote: >> In message , Seebs wrote: >>> Four spaces followed by a tab nearly always actually means "eight >>> spaces" to most editors (and Python seems to treat it that way), but >>> it's hard to tell. Worse, a tab may have been intended to be the same >>> thing as four spaces, and someone was expecting it NOT to be the same >>> as eight spaces... >> Whereas explicitly-bracketed languages leave no ambiguity about how many >> brackets you need and where. > Yes, and? In context, I think the comment was sarcastic, referring to C's famous ambiguities caused by optional braces. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From nobody at nowhere.com Sun Nov 7 00:39:17 2010 From: nobody at nowhere.com (Nobody) Date: Sun, 07 Nov 2010 04:39:17 +0000 Subject: Silly newbie question - Carrot character (^) References: <4cd5ed80$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, 07 Nov 2010 00:06:25 +0000, Steven D'Aprano wrote: >> A reference manual tells you how to use the language. A specification >> tells you how to implement it. > > Surely a tutorial tells you *how* to use the language. I wouldn't expect > a reference manual to teach me how to run and edit programs -- the *how* > of using the language. You're taking "how" too literally, so let me rephrase that: A reference manual tells you what you need to know in order to use the language. A specification tells you what you need to know in order to implement it. >> It's possible to /deduce/ how to use the language from a specification, >> but it could take significant time and effort. > > I think you're looking for hard distinctions that simply doesn't exist. There isn't a /hard/ distinction, but there is a distinction, IMHO. A tutorial provides an overview of the language, but won't necessarily describe every aspect (maybe not even close), and is generally designed to be read in order. In order to provide working examples, it may be necessary to introduce some features in the "wrong" order (e.g. in a language which doesn't provide an interactive read-eval-print loop, I/O may be introduced early on simply so that complete programs can be constructed). And once the feature is covered, it probably won't be repeated when the tutorial gets to a more appropriate section (e.g. the I/O section may omit features covered in the introduction). A reference manual would describe whatever you need to know in order to "use" the language. It shouldn't omit anything short of the "you are not expected to understand this" level. IOW, any omissions shouldn't matter unless you are e.g. writing analysis utilities which need to accept /any/ valid program and interpret it correctly. E.g. a reference manual would need to describe indentation, but details such as the interpretation of a mixture of tabs and spaces can be limited to "don't do this", whereas a specification would need to either specify the details or at least specify that it invokes "undefined behaviour". > If you want to argue that the Python reference manual is aimed at the > wrong level of sophistication, specifically that the BNF syntax stuff > should be ripped out into another document, then I might agree with you. > But to argue that it's entirely the wrong "kind" of thing is, in my > opinion, unjustified. I'm arguing that the reference manual reads too much like a specification. E.g. look at "5.2.4. List displays" and tell me whether you consider that it adequately /explains/ list displays to someone wishing to use them. I note that the "reference manual" contains very few examples. For a specification, this would be quite normal, as examples can serve to undermine precision. For a reference manual, precision has to be traded for clarity, which may mean using examples where appropriate. OTOH, a tutorial often contains little more than a sequence of examples along with informal explanations as to their structure and functioning. As a result, tutorials tend to lack precision; they provide specific cases which will work and some "clues" as to what else is likely to work. Regarding BNF: reference manuals tend to use less formal descriptions. E.g. something akin to to --help syntax, or a "dumbed-down" BNF which may technically be ambiguous, with ambiguities resolved by specifying precedences separately or listing would-be ambiguous cases along with a description of their correct interpretation. From rustompmody at gmail.com Sun Nov 7 01:26:46 2010 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 7 Nov 2010 10:56:46 +0530 Subject: python test frameworks Message-ID: There are a large number of test frameworks in/for python. Apart from what comes builtin with python there seems to be nose, staf, qmtest etc etc. Is there any central place where these are listed with short descriptions? 'Test framework' means widely different things in different contexts. Any explanations/tutorials around? [Disclaimer: I was educated a couple of decades before the TDD rage] From " " at libero.it Sun Nov 7 01:43:48 2010 From: " " at libero.it (not1xor1 (Alessandro)) Date: Sun, 07 Nov 2010 05:43:48 GMT Subject: subclassing str Message-ID: Hi, I'd like to know what is the best way to subclass str I need to add some new methods and that each method (both new and str ones) return my new type For instance I've seen I can do: class mystr(str): def between(self, start, end): i = self.index(start) + len(start) j = self.index(end, i) + len(end) return self[i:j], self[j:] def replace(self, old, new='', count=-1): return mystr(str.replace(self, old, new, count)) if __name__ == '__main__': s = mystr('one two four') print s print type(s) b,r = s.between('<', '>') print b print r print type(b) print type(r) c = s.replace('three', 'five') print c print type(c) when I ran it I get: one two four three> four one two four I guess that if I had redefined the slice method even 'between' would have returned I wonder if I have to redefine all methods one by one or if there is a sort of hook to intercept all methods calls and just change the return type thanks -- bye !(!1|1) From ldo at geek-central.gen.new_zealand Sun Nov 7 01:29:46 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 07 Nov 2010 19:29:46 +1300 Subject: sigaction? References: Message-ID: In message , Neal Becker wrote: > I'm interested in trying sigaction with SA_RESTART to prevent interrupted > system calls. Worse-is-better strikes again ... From ldo at geek-central.gen.new_zealand Sun Nov 7 01:33:52 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 07 Nov 2010 19:33:52 +1300 Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> <87aalrjkty.fsf@benfinney.id.au> <8jd3m9Fr55U7@mid.individual.net> Message-ID: In message , Roy Smith wrote: > In article , > Lawrence D'Oliveiro wrote: > >> In message <8jd3m9Fr55U7 at mid.individual.net>, Neil Cerutti wrote: >> >> > On 2010-11-03, Ben Finney wrote: >> > >> >> styles = [ >> >> ("normal", "image", MainWindow.ColorsNormalList), >> >> ("highlighted", "highlight", >> >> MainWindow.ColorsHighlightedList), >> >> ("selected", "select", MainWindow.ColorsSelectedList)] >> > >> > Agreed, except cute stuff like putting those three items in >> > columns is just as bad. >> > >> > Code should be utilitarian rather than ornate, Shaker rather than >> > Victorian. >> >> Tufte?s concept of ?chartjunk? could perhaps be extended to ?formatjunk? >> or ?prettyprintjunk?. > > Not at all. Tufte is all about making data easy to understand visually. > The chartjunk he rails about is colors, shadows, 3-d effects, etc, which > make a chart "look pretty" but don't add to comprehension. Precisely my point. > If you take out the extra whitespace, you end up with this: > >> >> styles = [ >> >> ("normal", "image", MainWindow.ColorsNormalList), >> >> ("highlighted", "highlight", >> >> MainWindow.ColorsHighlightedList), ("selected", "select", >> >> MainWindow.ColorsSelectedList)] > > which I think is more difficult to scan visually. Not surprising, since the above list has become completely divorced from its original purpose. Anybody remember what that was? It was supposed to be used in a loop, as follows: for \ Description, Attr, ColorList \ in \ ( ("normal", "image", MainWindow.ColorsNormalList), ("highlighted", "highlight", MainWindow.ColorsHighlightedList), ("selected", "select", MainWindow.ColorsSelectedList), ) \ : ... #end for Does this make more sense now? From clp2 at rebertia.com Sun Nov 7 01:41:44 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 6 Nov 2010 23:41:44 -0700 Subject: subclassing str In-Reply-To: References: Message-ID: On Sat, Nov 6, 2010 at 10:43 PM, not1xor1 (Alessandro) <" "@libero.it> wrote: > Hi, > > I'd like to know what is the best way to subclass str > I need to add some new methods and that each method (both new and str ones) > return my new type > > For instance I've seen I can do: > > class mystr(str): > > ? def between(self, start, end): > ? ? ?i = self.index(start) + len(start) > ? ? ?j = self.index(end, i) + len(end) > ? ? ?return self[i:j], self[j:] > > ? def replace(self, old, new='', count=-1): > ? ? ?return mystr(str.replace(self, old, new, count)) > > I wonder if I have to redefine all methods one by one or if there is a sort > of hook to intercept all methods calls and just change the return type You could subclass UserString instead of str; all of UserString's methods seem to ensure that instances of the subclass rather than just plain strs or UserStrings are returned. See http://docs.python.org/library/userdict.html#UserString.UserString But you should also consider whether your additions absolutely *must* be methods. Merely instead defining some functions that take strings as parameters is obviously a simpler, and probably more performant, approach. If you insist on subclassing str, there's no such hook; you'll have to override all the methods yourself.* Cheers, Chris -- *Well, you could override only the __special__ methods and __getattribute__(), or use metaprogramming, but at that point you might as well go the UserString route if possible. http://blog.rebertia.com From usenet-nospam at seebs.net Sun Nov 7 01:43:52 2010 From: usenet-nospam at seebs.net (Seebs) Date: 07 Nov 2010 06:43:52 GMT Subject: Silly newbie question - Carrot character (^) References: <4cd5ed80$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-07, Nobody wrote: > I'm arguing that the reference manual reads too much like a specification. > E.g. look at "5.2.4. List displays" and tell me whether you consider that > it adequately /explains/ list displays to someone wishing to use them. Seems pretty explanatory to me. I mean, maybe it helps that I already basically understood both of the things you could put in [], but it's pretty clear. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From steve at REMOVE-THIS-cybersource.com.au Sun Nov 7 03:00:11 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 07 Nov 2010 08:00:11 GMT Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> <87aalrjkty.fsf@benfinney.id.au> <8jd3m9Fr55U7@mid.individual.net> Message-ID: <4cd65c86$0$30004$c3e8da3$5496439d@news.astraweb.com> On Sun, 07 Nov 2010 19:33:52 +1300, Lawrence D'Oliveiro wrote: > for \ > Description, Attr, ColorList \ > in \ > ( > ("normal", "image", MainWindow.ColorsNormalList), > ("highlighted", "highlight", > MainWindow.ColorsHighlightedList), ("selected", "select", > MainWindow.ColorsSelectedList), > ) \ > : > ... > #end for > > Does this make more sense now? No, it makes less sense, and is ugly too boot. -- Steven From moogyd at yahoo.co.uk Sun Nov 7 03:35:21 2010 From: moogyd at yahoo.co.uk (moogyd) Date: Sun, 7 Nov 2010 01:35:21 -0700 (PDT) Subject: Popen Question References: <891a9a80-c30d-4415-ac81-bddd0b564fa6@g13g2000yqj.googlegroups.com> Message-ID: Hi, Thanks everyone for the replies - it is now clearer. Steven From ldo at geek-central.gen.new_zealand Sun Nov 7 03:48:10 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 07 Nov 2010 21:48:10 +1300 Subject: execute shell script from python, needs sys.argv References: <1vmbd65uaj2snq1v0vo49ktn0lsc2o5m1a@4ax.com> Message-ID: In message <1vmbd65uaj2snq1v0vo49ktn0lsc2o5m1a at 4ax.com>, Tim Roberts wrote: > I KNOW that we're still working on syntax here, and that it's too early > for optimization, but it bothers me to see "cat" as the first thing in a > pipeline. An anti-UUOC instinct. Very good. :) From ldo at geek-central.gen.new_zealand Sun Nov 7 05:26:51 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 07 Nov 2010 23:26:51 +1300 Subject: Silly newbie question - Caret character (^) References: Message-ID: In message , Nobody wrote: > A reference manual tells you how to use the language. A specification > tells you how to implement it. Speaking as someone who has read more reference manuals/specifications/whatever you want to call them than I can count, I have never come across any such distinction. Both programmers and implementors need to understand exactly how the language is defined. Because if there is any disagreement between their respective interpretations, things are not going to work well, are they? > It's possible to /deduce/ how to use the language from a specification, > but it could take significant time and effort. That?s what ?tutorials? are for. > A specification is typically designed to be read in its entirety, and may > yield little usable information until you've read a substantial portion of > it. Sounds like you?re describing a novel, rather than actual technical documentation. > A reference manual is structured such that you can easily locate the > portion which is necessary for the task immediately to hand, and only > need to read that portion. So is a specification. From sustainable.future116 at gmail.com Sun Nov 7 05:31:34 2010 From: sustainable.future116 at gmail.com (........) Date: Sun, 7 Nov 2010 02:31:34 -0800 (PST) Subject: Why you should change your vehicle to flex fuel Message-ID: <9e59040b-8f2d-4432-ada6-f4694d04b85f@g20g2000prg.googlegroups.com> Dear Everyone, as you know the price of the Oil is more and more increasing, while the oil supply is decreasing. Moreover Oil is causing wars, terror, oil spills and a lot of greenhouse gases. By upgrading your car to flex fuel, you will continue to be able to use oil. However you will also have the opportunity to use E85, that means more freedom of choice. The conversion cost is about 200-250 USD. By choosing ethanol, you choose local fuel production, which means labour for farmers, labour for enginneers and workers in the ethanol plant, labour for transportation. Moreover you also help for indirect labour. Since the money stays in your country, this money will turn and produce indirect labour. Since the farmer will gain your additional fuel money, he will buy other things (labour is again needed for their production), which in case of oil the oil-Sheikhs or their people would do. That ethanol production increases the food prices is also not totally right, first there is a by-product called "distillers dried grains with solubles", which is used as feed for livestock, that is also nothing else than food. Moreover, by using ethanol, you put pressure on oil prices, which has also an important effect on food prices. You also give your money for more research (again labour), which will yield in higher efficiency of production and alternative production methods like cellulosic ethanol, which will change the whole equation. Again in case of oil this money would be spent for oil rigs, oil- infrastructure, but also for weapons to defend the oil. By using ethanol, you produce less CO2, since it is produced by corn, which actually consumed the CO2 in the air for its growing. The more people use ethanol, the higher the efficiencies will come for production (similar to solar cells). The prices will go further down, and much less CO2 will be produced during production in the plant. Do you know that the production efficiencies already improved 30% ?* Another reason for using ethanol is that oil prices will come up again, when the barrel price of 150 USD is back you will be very happy to have your vehicle converted. The conversion also increases the value of your vehicle. Yours sincerely. Sources: *http://brownfieldagnews.com/2010/09/21/ethanol-production-efficiency- improves/ From ldo at geek-central.gen.new_zealand Sun Nov 7 05:33:29 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 07 Nov 2010 23:33:29 +1300 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: In message , Tim Harig wrote: > I agree with Seebs, Python is the only language I know that promotes > the use of spaces over tabs; and there are equally picky syntaxs (ie, > Makefiles) that mandate the use of tabs. That?s widely conceded to be a misfeature of Make. > I personally prefer tabs as it lets *me* decide how far the apparent > indentations are in the code. But they don?t. Other people can have different settings, and they will see different indentations for your code, so you don?t have control at all. The only way to ensure they see what you see is to use spaces, not tabs. From ldo at geek-central.gen.new_zealand Sun Nov 7 05:37:11 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 07 Nov 2010 23:37:11 +1300 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: In message , Grant Edwards wrote: > But without the colon, how are people who write programming editors > going to know when to increase the indentation level as I enter code? I hate editors (or editing modes) that think they know when to change indentation level on me. Hate, hate, hate. From ldo at geek-central.gen.new_zealand Sun Nov 7 05:39:40 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 07 Nov 2010 23:39:40 +1300 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jftftFelnU1@mid.individual.net> Message-ID: In message <8jftftFelnU1 at mid.individual.net>, Neil Cerutti wrote: > The handsome ':' terminator of if/elif/if statements allows us to > omit a newline, conserving vertical space. This improves the > readability of certain constructs. > > if x: print(x) > elif y: print(y) > else: print() I would never do that. ?Conserving vertical space? seems a stupid reason for doing it. In C, I even go the opposite way: if (x) { printf(..., x); } else if (y) { printf(..., y); } else { printf(...); } /*if*/ From ldo at geek-central.gen.new_zealand Sun Nov 7 05:40:18 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 07 Nov 2010 23:40:18 +1300 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> <87sjzige0r.fsf@benfinney.id.au> Message-ID: In message <87sjzige0r.fsf at benfinney.id.au>, Ben Finney wrote: > Seebs writes: > >> On 2010-11-03, Steven D'Aprano >> wrote: >> >>> Python does explicitly mark blocks. It does it by changes in >>> indentation. An indent is an explicit start-block. An outdent is an >>> explicit end- block. There is nothing implicit in a change in indent >>> level. >> >> What's the token that marks the end of a block, corresponding to the >> colon used to introduce it? > > You have introduced this requirement for tokens; it's fallacious. The > direct answer is: tokens aren't part of the requirement to be explicit. > > The more general answer is: the block is explicitly ended where the > indentation ends. That?s implicit, not explicit. From ldo at geek-central.gen.new_zealand Sun Nov 7 05:50:08 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 07 Nov 2010 23:50:08 +1300 Subject: cms 4 static pages? References: Message-ID: In message , Guido Stepken wrote: > a not database driven What do you mean by ?database?? Even flat files can be ?databases?. From roy at panix.com Sun Nov 7 07:42:03 2010 From: roy at panix.com (Roy Smith) Date: Sun, 07 Nov 2010 07:42:03 -0500 Subject: Silly newbie question - Carrot character (^) References: <87k4kq60na.fsf@xemacs.org> <87fwve53ve.fsf@xemacs.org> Message-ID: In article , Seebs wrote: > On 2010-11-07, Roy Smith wrote: > > Any self-respecting C++ programmer would have given > > up the scavenger hunt by now. Just kept throwing typecasts at your code > > until it compiles, and move on. > > That does not sound like a self-respecting programmer of anything. Well, maybe I was being a little sarcastic. The real point was that if you make it hard for people to do the right thing (i.e. look up the details in the reference manual), you should not be surprised if they do the wrong thing (i.e. find some way to make it work by trial and error). From mdw at distorted.org.uk Sun Nov 7 07:57:13 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Sun, 07 Nov 2010 12:57:13 +0000 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jftftFelnU1@mid.individual.net> Message-ID: <87oca1b8ba.fsf.mdw@metalzone.distorted.org.uk> Lawrence D'Oliveiro writes: > I would never do that. ?Conserving vertical space? seems a stupid reason for > doing it. Vertical space is a limiting factor on how much code one can see at a time. I use old-fashioned CRT monitors with 4x3 aspect ratios and dizzyingly high resolution; I usually work with two columns of code, but can get four if I give up on things like xterms. I still find it rather limiting: I have to remember everything which won't fit on the screen. I've no idea how people manage with these ridiculous widescreen monitors. -- [mdw] From darragh.ssa at gmail.com Sun Nov 7 08:09:48 2010 From: darragh.ssa at gmail.com (Kruptein) Date: Sun, 7 Nov 2010 05:09:48 -0800 (PST) Subject: Deditor 0.2.2 References: Message-ID: <675c61bd-12f9-46ae-8b7e-b169e14e5064@j2g2000yqf.googlegroups.com> I also uploaded a video with sound because there were a lot of people that asked that. link: http://www.youtube.com/watch?v=zidKSPWBGxU From invalid at invalid.invalid Sun Nov 7 08:23:26 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Sun, 7 Nov 2010 13:23:26 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jftftFelnU1@mid.individual.net> <87oca1b8ba.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On 2010-11-07, Mark Wooding wrote: > Lawrence D'Oliveiro writes: > >> I would never do that. "Conserving vertical space" seems a stupid >> reason for doing it. > > Vertical space is a limiting factor on how much code one can see at a > time. And one study I read shoed that how much code one can see at a time directly affects the number of bugs introduced while editing. The more code you could see at a time, the better off you were (at least as far as the measurements in that study went). IOW, editing a loop or other control structure where you couldn't see both ends was problematic. Conserving vertical space avoids that problem. > I use old-fashioned CRT monitors with 4x3 aspect ratios and > dizzyingly high resolution; I usually work with two columns of code, but > can get four if I give up on things like xterms. I still find it rather > limiting: I have to remember everything which won't fit on the screen. > > I've no idea how people manage with these ridiculous widescreen monitors. Rotate them 90 degrees? My monitors will do that mechanically, but I've never bothered to try setting up X to handle it. (I bought 4:3 monitors before they got replaced by cheap 16:8 screens). -- Grant From invalid at invalid.invalid Sun Nov 7 08:24:21 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Sun, 7 Nov 2010 13:24:21 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> <87sjzige0r.fsf@benfinney.id.au> Message-ID: On 2010-11-07, Lawrence D'Oliveiro wrote: > In message <87sjzige0r.fsf at benfinney.id.au>, Ben Finney wrote: > >> Seebs writes: >> >>> On 2010-11-03, Steven D'Aprano >>> wrote: >>> >>>> Python does explicitly mark blocks. It does it by changes in >>>> indentation. An indent is an explicit start-block. An outdent is an >>>> explicit end- block. There is nothing implicit in a change in indent >>>> level. >>> >>> What's the token that marks the end of a block, corresponding to the >>> colon used to introduce it? >> >> You have introduced this requirement for tokens; it's fallacious. The >> direct answer is: tokens aren't part of the requirement to be explicit. >> >> The more general answer is: the block is explicitly ended where the >> indentation ends. > > That's implicit, not explicit. If you can _see_ it, how is it implicit? -- Grant From mdw at distorted.org.uk Sun Nov 7 08:29:40 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Sun, 07 Nov 2010 13:29:40 +0000 Subject: Silly newbie question - Carrot character (^) References: <4cd5ed80$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87k4kpb6t7.fsf.mdw@metalzone.distorted.org.uk> Nobody writes: > You're taking "how" too literally, so let me rephrase that: > > A reference manual tells you what you need to know in order to use > the language. A specification tells you what you need to know in > order to implement it. I still don't see those as being different. A language reference should set out all of the details of the language syntax and semantics. It should answer every question of the form `what happens if I write this?' In so doing, it /must/ also provide enough information for an implementer to write an new implementation. > A tutorial provides an overview of the language, but won't necessarily > describe every aspect (maybe not even close), and is generally > designed to be read in order. Agreed. > A reference manual would describe whatever you need to know in order > to "use" the language. It shouldn't omit anything short of the "you > are not expected to understand this" level. IOW, any omissions > shouldn't matter unless you are e.g. writing analysis utilities which > need to accept /any/ valid program and interpret it correctly. `Using' a language involves two activities: writing it, and reading it. You're only considering one of those activities, and I think it's the less important one. > E.g. a reference manual would need to describe indentation, but > details such as the interpretation of a mixture of tabs and spaces can > be limited to "don't do this", whereas a specification would need to > either specify the details or at least specify that it invokes > "undefined behaviour". I'm confronted with some code, written by someone else, and when I run it I get an unexpected result. The language reference should be able to explain to me precisely why I get the result that I see. If it can't, it's of no value. > I'm arguing that the reference manual reads too much like a specification. > E.g. look at "5.2.4. List displays" and tell me whether you consider that > it adequately /explains/ list displays to someone wishing to use them. It doesn't adequately specify them either. That section is just poorly written. > I note that the "reference manual" contains very few examples. For a > specification, this would be quite normal, as examples can serve to > undermine precision. For a reference manual, precision has to be traded > for clarity, which may mean using examples where appropriate. I disagree with both claims. Examples cannot undermine precision: if the normative text is correct then an example can only demonstrate an application of the specified rules. If the normative text is wrong then the specification is broken and needs fixing. But the same applies to a reference. Either it supplies enough detail to answer every question about how programs behave or it's broken: precision is essential here, but is not -- and cannot -- be compromised by adding examples. > OTOH, a tutorial often contains little more than a sequence of examples > along with informal explanations as to their structure and functioning. As > a result, tutorials tend to lack precision; they provide specific cases > which will work and some "clues" as to what else is likely to work. Yes, I'm familiar with the `leave the reader to fill in the gaps in my exposition for himself' approach to documentation -- and with the unenjoyable task of fixing the reader's confused mental model afterwards. -- [mdw] From mdw at distorted.org.uk Sun Nov 7 08:41:27 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Sun, 07 Nov 2010 13:41:27 +0000 Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> <87aalrjkty.fsf@benfinney.id.au> <8jd3m9Fr55U7@mid.individual.net> Message-ID: <87fwvdb69k.fsf.mdw@metalzone.distorted.org.uk> Lawrence D'Oliveiro writes: > Not surprising, since the above list has become completely divorced from its > original purpose. Anybody remember what that was? It was supposed to be used > in a loop, as follows: > > for \ > Description, Attr, ColorList \ > in \ > ( > ("normal", "image", MainWindow.ColorsNormalList), > ("highlighted", "highlight", MainWindow.ColorsHighlightedList), > ("selected", "select", MainWindow.ColorsSelectedList), > ) \ > : > ... > #end for > > Does this make more sense now? Ugh, no! for descr, attr, colours in [ ('normal', 'image', 'Normal'), ('highlighted', 'highlight', 'Highlighted'), ('selected', 'select', 'Selected')]: colourlist = getattr(MainWindow, 'Colors%sList' % colours) ## ... To be honest, there's so much regularity in that table that I'd consider generating it from a shorter list. This would obviously involve refactoring something else to eliminate the image/normal asymmetry. I'd also consider making the ColorsMumbleList attribute collection into a dictionary. Note that my columns are aligned to 8-column tab stops for easy maintenance (although my editor has used physical spaces rather than tabs). -- [mdw] From kevin.p.dwyer at gmail.com Sun Nov 7 09:09:32 2010 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Sun, 7 Nov 2010 14:09:32 +0000 (UTC) Subject: python test frameworks References: Message-ID: On Sun, 07 Nov 2010 10:56:46 +0530, Rustom Mody wrote: > There are a large number of test frameworks in/for python. Apart from > what comes builtin with python there seems to be nose, staf, qmtest etc > etc. > > Is there any central place where these are listed with short > descriptions? 'Test framework' means widely different things in > different contexts. Any explanations/tutorials around? > > [Disclaimer: I was educated a couple of decades before the TDD rage] Hello, You could start with http://pycheesecake.org/wiki/PythonTestingToolsTaxonomy Kev From steve at holdenweb.com Sun Nov 7 09:26:33 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Nov 2010 09:26:33 -0500 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jftftFelnU1@mid.individual.net> <87oca1b8ba.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On 11/7/2010 8:23 AM, Grant Edwards wrote: [...] > (I bought 4:3 monitors before they got replaced by cheap 16:8 > screens) I think you'll find the new aspect ration is 16:9. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From roy at panix.com Sun Nov 7 09:39:15 2010 From: roy at panix.com (Roy Smith) Date: Sun, 07 Nov 2010 09:39:15 -0500 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jftftFelnU1@mid.individual.net> <87oca1b8ba.fsf.mdw@metalzone.distorted.org.uk> Message-ID: In article <87oca1b8ba.fsf.mdw at metalzone.distorted.org.uk>, mdw at distorted.org.uk (Mark Wooding) wrote: > Vertical space is a limiting factor on how much code one can see at a > time. Yup. Over three decades of programming, my personal upper bound for how long a function should be has always been "fits on one screen". In the old days, that meant a CRT with 24 lines (by 80 columns). These days, it means about 100-120 lines (depending on how squinty-eyed I'm willing to go). Thus, over the years, my idea of how long a function can be has grown several-fold. I still try to keep things well under 100 lines per function. I'm willing, however, to tolerate anything up to where I can no longer see the entire thing and the font is still big enough to read easily. Of course, in the real old days, with 66 lines to an 11-inch page of line printer paper, and 8 foot high ceilings, you could tape about 500 lines of code to the wall, but I digress :-) > I've no idea how people manage with these ridiculous widescreen monitors. My 15-inch laptop has 1680 x 1050 resolution (the new high-res flavor of the MacBook Pro). I love it. Mostly I use the screen real estate for one main shell window where I'm doing most of my work, and a variety of other windows (browser, pdf viewer, etc) which contain documents I'm referring to in support of what I'm doing in my main window. At work, I've got two 1920 x 1080 monitors side-by-side. I find I don't use the second monitor much. I'll generally shove some windows over there which I watch, but almost never interact with. Mostly things tailing log files or some other kind of status monitor function. I also find that to keep the angle of view comfortable, I can't sit as close to the monitors as I usually keep my laptop screen. So, I have to make the font size a little larger, which in turn means fewer lines of code visible. Ergonomics is complicated. I'm thinking of rotating the monitors 90 degrees, running them in side-by-side portrait mode. I know X11 can handle the video rotation, but I'm not sure I've got the right mounting brackets. Another factor is that the Mac display is sharp as a tack compared to my big LCD panels at work. I think it's party the display hardware itself, and partly that the Mac's text rendering just blows Linux out of the water. I can easily read text on my laptop at much smaller font sizes than I can on my desk monitors at work. From gdamjan at gmail.com Sun Nov 7 09:39:31 2010 From: gdamjan at gmail.com (=?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLRgdC60Lg=?=) Date: Sun, 07 Nov 2010 15:39:31 +0100 Subject: ANN: PyQt v4.8.1 Released References: Message-ID: <3aqiq7-46p.ln1@archaeopteryx.softver.org.mk> >> Given the context, "PyQt is available under the GPL and a commercial >> license," the commercial license Phil is talking about is not the >> GPL. > > Which is a wrong interpretation of ?commercial?. But he is not interpreting either ?commercial? or GPL. What he says is: here's the code for free (gratis, no price) under the GPL, but if you don't like it, I also offer it commercially (under an undisclosed license, maybe a custom one as required by the client). He is NOT offering the GPL version commercially, even if that's allowed by the GPL. For ex. You are free to do it, it's that he is not doing it (or just not advertising it - I'm sure he wouldn't mind someone paying for the GPL version either). -- ?????? ((( http://damjan.softver.org.mk/ ))) "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." - Brian W. Kernighan From python.list at tim.thechases.com Sun Nov 7 09:52:28 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 07 Nov 2010 08:52:28 -0600 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jftftFelnU1@mid.individual.net> <87oca1b8ba.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <4CD6BD2C.5050406@tim.thechases.com> On 11/07/10 08:26, Steve Holden wrote: > On 11/7/2010 8:23 AM, Grant Edwards wrote: > [...] >> (I bought 4:3 monitors before they got replaced by cheap 16:8 >> screens) > > I think you'll find the new aspect ration is 16:9. Unless that's why they're cheap... dual-16x9-widescreen-in-portrait-mode-is-a-wonderful-thing'ly, -tkc From invalid at invalid.invalid Sun Nov 7 10:46:34 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Sun, 7 Nov 2010 15:46:34 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jftftFelnU1@mid.individual.net> <87oca1b8ba.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On 2010-11-07, Steve Holden wrote: > On 11/7/2010 8:23 AM, Grant Edwards wrote: > [...] >> (I bought 4:3 monitors before they got replaced by cheap 16:8 >> screens) > > I think you'll find the new aspect ration is 16:9. I knew that. My keyboard didn't. I recently bought a close-out Lenovo T500 Thinkpad from their outlet because current models are now 16:9 instead of the older 16:10. My old 4:3 Thinkpad was still going strong, but I decided I'd better get a 16:10 while I could -- though I'd still prefer a 4:3. -- Grant From emile at fenx.com Sun Nov 7 10:48:32 2010 From: emile at fenx.com (Emile van Sebille) Date: Sun, 07 Nov 2010 07:48:32 -0800 Subject: Silly newbie question - Caret character (^) In-Reply-To: References: Message-ID: On 11/7/2010 2:26 AM Lawrence D'Oliveiro said... > In message, Nobody wrote: > >> A reference manual tells you how to use the language. A specification >> tells you how to implement it. > > Speaking as someone who has read more reference > manuals/specifications/whatever you want to call them than I can count, I > have never come across any such distinction. Surely you see the difference between RFC5321 and for example Courier's man pages? One's the specification and the other's the reference manual. Emile From ethan at stoneleaf.us Sun Nov 7 11:20:11 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 07 Nov 2010 08:20:11 -0800 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> <4cd3de51$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4CD6D1BB.90204@stoneleaf.us> Seebs wrote: > On 2010-11-05, Ethan Furman wrote: >> The verifiable benefit for me is ease of use, ease of thought, ease of >> typing... I realize these are not benefits for everyone, but they are >> for some -- and I would venture a guess that the ease of thought benefit >> is one of the primary reasons Python is popular. I am definitely one of >> those that think indentation based structure is one of Python's best >> features. > > Could you explain more the "ease of thought" thing? I haven't yet noticed > it, but it might be something to look out for as I get more experienced. Most if my programming experience is in FoxPro versions 2 and 6. Control structures start with if, for, do case, do while, with, procedure, and (I think) function. Control structures end with endif, endfor, endcase, endwhile, endwith, endproc, and (I think) endfunc. In Python, control structures start with if, for, while, try, def, and class, and each one ends with a dedent. This really comes into play when developing -- want to change that if to a while? Go ahead! And no need to worry about tracking down the closing endif to change it to endwhile, plus it's less clutter on the screen. I also really like the dynamic typing and not having to declare nor pre-initialize variable names, as well as the lack of a true global namespace. All in all, I am able to think about the code and what I want to do, and not think about the compiler/interpreter and keeping it happy. Hope this helps. ~Ethan~ From ethan at stoneleaf.us Sun Nov 7 11:36:01 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 07 Nov 2010 08:36:01 -0800 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4CD6D571.8070509@stoneleaf.us> Lawrence D'Oliveiro wrote: > In message , Tim Harig wrote: >> >> I personally prefer tabs as it lets *me* decide how far the apparent >> indentations are in the code. > > But they don?t. Other people can have different settings, and they will see > different indentations for your code That's exactly the point -- each person can decide what level of indentation they prefer to look at. ~Ethan~ From steve at holdenweb.com Sun Nov 7 11:39:38 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Nov 2010 11:39:38 -0500 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jftftFelnU1@mid.individual.net> <87oca1b8ba.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On 11/7/2010 10:46 AM, Grant Edwards wrote: > On 2010-11-07, Steve Holden wrote: >> On 11/7/2010 8:23 AM, Grant Edwards wrote: >> [...] >>> (I bought 4:3 monitors before they got replaced by cheap 16:8 >>> screens) >> >> I think you'll find the new aspect ration is 16:9. > "aspect ration". Sheesh. > I knew that. My keyboard didn't. > > I recently bought a close-out Lenovo T500 Thinkpad from their outlet > because current models are now 16:9 instead of the older 16:10. My > old 4:3 Thinkpad was still going strong, but I decided I'd better get > a 16:10 while I could -- though I'd still prefer a 4:3. > The thing that *really* pisses me off is that you *used* to be able to get 1920 x 1200 15" displays, but *now* you are lucky to go above 1080 vertical pixels even in a 17" laptop display. I don't want the resolution of my displays dictated by the resolution of my (current) media, yet it seems that's what's happened in the laptop market. I got a Lenovo T60 a while back as a touchpad machine. Wondering about switching that to Linux, but I haven't seen any touchpad distros in action yet. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From robert.kern at gmail.com Sun Nov 7 12:01:22 2010 From: robert.kern at gmail.com (Robert Kern) Date: Sun, 07 Nov 2010 11:01:22 -0600 Subject: ANN: PyQt v4.8.1 Released In-Reply-To: <3aqiq7-46p.ln1@archaeopteryx.softver.org.mk> References: <3aqiq7-46p.ln1@archaeopteryx.softver.org.mk> Message-ID: On 2010-11-07 08:39 , ?????? ??????????? wrote: >>> Given the context, "PyQt is available under the GPL and a commercial >>> license," the commercial license Phil is talking about is not the >>> GPL. >> >> Which is a wrong interpretation of ?commercial?. > > But he is not interpreting either ?commercial? or GPL. > > What he says is: here's the code for free (gratis, no price) under the > GPL, but if you don't like it, I also offer it commercially (under an > undisclosed license, maybe a custom one as required by the client). Right. In this case, "commercial" describes the way he is offering the license, not what uses of the software the license allows. Everyone here knew exactly what he meant. -- 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 rustompmody at gmail.com Sun Nov 7 12:01:42 2010 From: rustompmody at gmail.com (rustom) Date: Sun, 7 Nov 2010 09:01:42 -0800 (PST) Subject: python test frameworks References: Message-ID: <009da031-22f2-4719-b030-b1db76e953af@r4g2000prj.googlegroups.com> On Nov 7, 7:09?pm, Kev Dwyer wrote: > On Sun, 07 Nov 2010 10:56:46 +0530, Rustom Mody wrote: > > There are a large number of test frameworks in/for python. ?Apart from > > what comes builtin with python there seems to be nose, staf, qmtest etc > > etc. > > > Is there any central place where these are listed with short > > descriptions? 'Test framework' means widely different things in > > different contexts. Any explanations/tutorials around? > > > [Disclaimer: I was educated a couple of decades before the TDD rage] > > Hello, > > You could start withhttp://pycheesecake.org/wiki/PythonTestingToolsTaxonomy > > Kev Thanks -- that looks like a comprehensive resource. But it does not have staf http://staf.sourceforge.net/current/STAFPython.htm. Is that merely an item missing or a category? From cdalten at gmail.com Sun Nov 7 12:34:48 2010 From: cdalten at gmail.com (chad) Date: Sun, 7 Nov 2010 09:34:48 -0800 (PST) Subject: A question about yield Message-ID: <40dd2ea7-0b1d-4600-8fc7-a2d0027b98c0@f16g2000prj.googlegroups.com> I have an input file named 'freq' which contains the following data 123 0 133 3 146 1 200 0 233 10 400 2 Now I've attempted to write a script that would take a number from the standard input and then have the program return the number in the input file that is closest to that input file. #!/usr/local/bin/python import sys def construct_set(data): for line in data: lines = line.splitlines() for curline in lines: if curline.strip(): key = curline.split(' ') value = int(key[0]) yield value def approximate(first, second): midpoint = (first + second) / 2 return midpoint def format(input): prev = 0 value = int(input) with open("/home/cdalten/oakland/freq") as f: for next in construct_set(f): if value > prev: current = prev prev = next middle = approximate(current, prev) if middle < prev and value > middle: return prev elif value > current and current < middle: return current if __name__ == "__main__": if len(sys.argv) != 2: print >> sys.stderr, "You need to enter a number\n" sys.exit(1) nearest = format(sys.argv[1]) print "The closest value to", sys.argv[1], "is", nearest When I run it, I get the following... [cdalten at localhost oakland]$ ./android4.py 123 The closest value to 123 is 123 [cdalten at localhost oakland]$ ./android4.py 130 The closest value to 130 is 133 [cdalten at localhost oakland]$ ./android4.py 140 The closest value to 140 is 146 [cdalten at localhost oakland]$ ./android4.py 146 The closest value to 146 is 146 [cdalten at localhost oakland]$ ./android4.py 190 The closest value to 190 is 200 [cdalten at localhost oakland]$ ./android4.py 200 The closest value to 200 is 200 [cdalten at localhost oakland]$ ./android4.py 205 The closest value to 205 is 200 [cdalten at localhost oakland]$ ./android4.py 210 The closest value to 210 is 200 [cdalten at localhost oakland]$ ./android4.py 300 The closest value to 300 is 233 [cdalten at localhost oakland]$ ./android4.py 500 The closest value to 500 is 400 [cdalten at localhost oakland]$ ./android4.py 1000000 The closest value to 1000000 is 400 [cdalten at localhost oakland]$ The question is about the construct_set() function. def construct_set(data): for line in data: lines = line.splitlines() for curline in lines: if curline.strip(): key = curline.split(' ') value = int(key[0]) yield value I have it yield on 'value' instead of 'curline'. Will the program still read the input file named freq line by line even though I don't have it yielding on 'curline'? Or since I have it yield on 'value', will it read the entire input file into memory at once? Chad From cdalten at gmail.com Sun Nov 7 12:37:54 2010 From: cdalten at gmail.com (chad) Date: Sun, 7 Nov 2010 09:37:54 -0800 (PST) Subject: A question about yield References: <40dd2ea7-0b1d-4600-8fc7-a2d0027b98c0@f16g2000prj.googlegroups.com> Message-ID: On Nov 7, 9:34?am, chad wrote: > I have an input file named 'freq' which contains the following data > > 123 0 > > 133 3 > 146 1 > 200 0 > 233 10 > 400 2 > > Now I've attempted to write a script that would take a number from the > standard input and then > have the program return the number in the input file that is closest > to that input file. *and then have the program return the number in the input file that is closest to the number the user inputs (or enters).* From usenet-nospam at seebs.net Sun Nov 7 12:41:10 2010 From: usenet-nospam at seebs.net (Seebs) Date: 07 Nov 2010 17:41:10 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jftftFelnU1@mid.individual.net> <87oca1b8ba.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On 2010-11-07, Mark Wooding wrote: > I've no idea how people manage with these ridiculous widescreen monitors. Side space used for Other Stuff. It takes some reworking of the layout, but overall I sorta like it now. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From clp2 at rebertia.com Sun Nov 7 12:47:47 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 7 Nov 2010 09:47:47 -0800 Subject: A question about yield In-Reply-To: <40dd2ea7-0b1d-4600-8fc7-a2d0027b98c0@f16g2000prj.googlegroups.com> References: <40dd2ea7-0b1d-4600-8fc7-a2d0027b98c0@f16g2000prj.googlegroups.com> Message-ID: On Sun, Nov 7, 2010 at 9:34 AM, chad wrote: > #!/usr/local/bin/python > > import sys > > def construct_set(data): > ? ?for line in data: > ? ? ? ?lines = line.splitlines() > ? ? ? ?for curline in lines: > ? ? ? ? ? ?if curline.strip(): > ? ? ? ? ? ? ? ?key = curline.split(' ') > ? ? ? ? ? ? ? ?value = int(key[0]) > ? ? ? ? ? ? ? ?yield value > > def approximate(first, second): > ? ?midpoint = (first + second) / 2 > ? ?return midpoint > > def format(input): > ? ?prev = 0 > ? ?value = int(input) > > ? ?with open("/home/cdalten/oakland/freq") as f: > ? ? ? ?for next in construct_set(f): > ? ? ? ? ? ?if value > prev: > ? ? ? ? ? ? ? ?current = prev > ? ? ? ? ? ? ? ?prev = next > > ? ? ? ?middle = approximate(current, prev) > ? ? ? ?if middle < prev and value > middle: > ? ? ? ? ? ?return prev > ? ? ? ?elif value > current and current < middle: > ? ? ? ? ? ?return current > The question is about the construct_set() function. > I have it yield on 'value' instead of 'curline'. Will the program > still read the input file named freq line by line even though I don't > have it yielding on 'curline'? Or since I have it yield on 'value', > will it read the entire input file into memory at once? The former. The yield has no effect at all on how the file is read. The "for line in data:" iteration over the file object is what makes Python read from the file line-by-line. Incidentally, the use of splitlines() is pointless; you're already getting single lines from the file object by iterating over it, so splitlines() will always return a single-element list. Cheers, Chris -- http://blog.rebertia.com From usenet-nospam at seebs.net Sun Nov 7 12:50:01 2010 From: usenet-nospam at seebs.net (Seebs) Date: 07 Nov 2010 17:50:01 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> <87sjzige0r.fsf@benfinney.id.au> Message-ID: On 2010-11-07, Grant Edwards wrote: > On 2010-11-07, Lawrence D'Oliveiro wrote: >> In message <87sjzige0r.fsf at benfinney.id.au>, Ben Finney wrote: >>> The more general answer is: the block is explicitly ended where the >>> indentation ends. >> That's implicit, not explicit. > If you can _see_ it, how is it implicit? Humans can see negative space. It's still implicit. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Sun Nov 7 12:53:10 2010 From: usenet-nospam at seebs.net (Seebs) Date: 07 Nov 2010 17:53:10 GMT Subject: Silly newbie question - Carrot character (^) References: <87k4kq60na.fsf@xemacs.org> <87fwve53ve.fsf@xemacs.org> Message-ID: On 2010-11-07, Roy Smith wrote: > Well, maybe I was being a little sarcastic. The real point was that if > you make it hard for people to do the right thing (i.e. look up the > details in the reference manual), you should not be surprised if they do > the wrong thing (i.e. find some way to make it work by trial and error). Fair enough. That said, I don't think it's the *writing* of the C spec that would make it hard for people to look up details. Dunno for C++. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From cdalten at gmail.com Sun Nov 7 12:56:46 2010 From: cdalten at gmail.com (chad) Date: Sun, 7 Nov 2010 09:56:46 -0800 (PST) Subject: A question about yield References: <40dd2ea7-0b1d-4600-8fc7-a2d0027b98c0@f16g2000prj.googlegroups.com> Message-ID: On Nov 7, 9:47?am, Chris Rebert wrote: > On Sun, Nov 7, 2010 at 9:34 AM, chad wrote: > > > > > > > #!/usr/local/bin/python > > > import sys > > > def construct_set(data): > > ? ?for line in data: > > ? ? ? ?lines = line.splitlines() > > ? ? ? ?for curline in lines: > > ? ? ? ? ? ?if curline.strip(): > > ? ? ? ? ? ? ? ?key = curline.split(' ') > > ? ? ? ? ? ? ? ?value = int(key[0]) > > ? ? ? ? ? ? ? ?yield value > > > def approximate(first, second): > > ? ?midpoint = (first + second) / 2 > > ? ?return midpoint > > > def format(input): > > ? ?prev = 0 > > ? ?value = int(input) > > > ? ?with open("/home/cdalten/oakland/freq") as f: > > ? ? ? ?for next in construct_set(f): > > ? ? ? ? ? ?if value > prev: > > ? ? ? ? ? ? ? ?current = prev > > ? ? ? ? ? ? ? ?prev = next > > > ? ? ? ?middle = approximate(current, prev) > > ? ? ? ?if middle < prev and value > middle: > > ? ? ? ? ? ?return prev > > ? ? ? ?elif value > current and current < middle: > > ? ? ? ? ? ?return current > > > The question is about the construct_set() function. > > > I have it yield on 'value' instead of 'curline'. Will the program > > still read the input file named freq line by line even though I don't > > have it yielding on 'curline'? Or since I have it yield on 'value', > > will it read the entire input file into memory at once? > > The former. The yield has no effect at all on how the file is read. > The "for line in data:" iteration over the file object is what makes > Python read from the file line-by-line. Incidentally, the use of > splitlines() is pointless; you're already getting single lines from > the file object by iterating over it, so splitlines() will always > return a single-element list. > But what happens if the input file is say 250MB? Will all 250MB be loaded into memory at once? Just curious, because I thought maybe using something like 'yield curline' would prevent this scenario. From clp2 at rebertia.com Sun Nov 7 13:14:12 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 7 Nov 2010 10:14:12 -0800 Subject: A question about yield In-Reply-To: References: <40dd2ea7-0b1d-4600-8fc7-a2d0027b98c0@f16g2000prj.googlegroups.com> Message-ID: On Sun, Nov 7, 2010 at 9:56 AM, chad wrote: > On Nov 7, 9:47?am, Chris Rebert wrote: >> On Sun, Nov 7, 2010 at 9:34 AM, chad wrote: >> >> > #!/usr/local/bin/python >> >> > import sys >> >> > def construct_set(data): >> > ? ?for line in data: >> > ? ? ? ?lines = line.splitlines() >> > ? ? ? ?for curline in lines: >> > ? ? ? ? ? ?if curline.strip(): >> > ? ? ? ? ? ? ? ?key = curline.split(' ') >> > ? ? ? ? ? ? ? ?value = int(key[0]) >> > ? ? ? ? ? ? ? ?yield value >> >> > def approximate(first, second): >> > ? ?midpoint = (first + second) / 2 >> > ? ?return midpoint >> >> > def format(input): >> > ? ?prev = 0 >> > ? ?value = int(input) >> >> > ? ?with open("/home/cdalten/oakland/freq") as f: >> > ? ? ? ?for next in construct_set(f): >> > ? ? ? ? ? ?if value > prev: >> > ? ? ? ? ? ? ? ?current = prev >> > ? ? ? ? ? ? ? ?prev = next >> >> > ? ? ? ?middle = approximate(current, prev) >> > ? ? ? ?if middle < prev and value > middle: >> > ? ? ? ? ? ?return prev >> > ? ? ? ?elif value > current and current < middle: >> > ? ? ? ? ? ?return current >> >> > The question is about the construct_set() function. >> >> > I have it yield on 'value' instead of 'curline'. Will the program >> > still read the input file named freq line by line even though I don't >> > have it yielding on 'curline'? Or since I have it yield on 'value', >> > will it read the entire input file into memory at once? >> >> The former. The yield has no effect at all on how the file is read. >> The "for line in data:" iteration over the file object is what makes >> Python read from the file line-by-line. Incidentally, the use of >> splitlines() is pointless; you're already getting single lines from >> the file object by iterating over it, so splitlines() will always >> return a single-element list. > > But what happens if the input file is say 250MB? Will all 250MB be > loaded into memory at once? No. As I said, the file will be read from 1 line at a time, on an as-needed basis; which is to say, "line-by-line". > Just curious, because I thought maybe > using something like 'yield curline' would prevent this scenario. Using "for line in data:" is what prevents that scenario. The "yield" is only relevant to how the file is read insofar as the the alternative to yield-ing would be to return a list, which would necessitate going through the entire file in continuous go and then returning a very large list; but even then, the file's content would still be read from line-by-line, not all at once as one humongous string. Cheers, Chris -- http://blog.rebertia.com From cwc at cwc.name Sun Nov 7 14:25:42 2010 From: cwc at cwc.name (CWC) Date: Sun, 7 Nov 2010 11:25:42 -0800 (PST) Subject: Making ActivePython and Python co-exist on Windows Message-ID: I'm new to Python. Is it possible to make ActivePython 3.12 and Python 3.12 co-exist on Windows? I've got an app which requires the former, but I want to stay with the latter, since I'm interested in getting into development. The main area of collision appears to be the Registry. From usenet-nospam at seebs.net Sun Nov 7 14:56:32 2010 From: usenet-nospam at seebs.net (Seebs) Date: 07 Nov 2010 19:56:32 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> <4cd3de51$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-07, Ethan Furman wrote: > Seebs wrote: >> On 2010-11-05, Ethan Furman wrote: >>> The verifiable benefit for me is ease of use, ease of thought, ease of >>> typing... I realize these are not benefits for everyone, but they are >>> for some -- and I would venture a guess that the ease of thought benefit >>> is one of the primary reasons Python is popular. I am definitely one of >>> those that think indentation based structure is one of Python's best >>> features. >> Could you explain more the "ease of thought" thing? I haven't yet noticed >> it, but it might be something to look out for as I get more experienced. > Most if my programming experience is in FoxPro versions 2 and 6. > Control structures start with if, for, do case, do while, with, > procedure, and (I think) function. Control structures end with endif, > endfor, endcase, endwhile, endwith, endproc, and (I think) endfunc. Eww. > In Python, control structures start with if, for, while, try, def, and > class, and each one ends with a dedent. So they're more consistent. > This really comes into play when developing -- want to change that if to > a while? Go ahead! And no need to worry about tracking down the > closing endif to change it to endwhile, plus it's less clutter on the > screen. I can see that. I actually mostly prefer an explicit close. Of the things I've used, I'm happiest with braces, because punctuation is good at being interpreted unconsciously, but I'm okay with "end" as long as it's the same for everything. I do like having a things bounded, though; I find it easier to read: if (foo) { bar; } baz; than if foo: bar baz; (I'm not quite sure why, but I think it's because the trailing boundary is part of the thing it bounds, rather than being the start of the thing after it.) I would definitely agree, though, that the Python solution is better than what you describe for FoxPro. It's also better, IMHO, than sh. > I also really like the dynamic typing and not having to declare nor > pre-initialize variable names, as well as the lack of a true global > namespace. I am torn on declarations -- I am pretty sure I make more mistakes with clashing variable names when they aren't explicitly declared, but I do like the much shorter code that results from not having them. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From ozric at web.de Sun Nov 7 15:24:20 2010 From: ozric at web.de (chris) Date: Sun, 7 Nov 2010 12:24:20 -0800 (PST) Subject: { '0':'c->c->a' ,'1':'a->b->a' .........} Message-ID: <8961af78-5f7b-46e1-95d7-014534b6e637@s4g2000yql.googlegroups.com> Hi, have anybody a hint , how i get a dict from non unique id's and their different related values. Thanks for advance Chris ###random data # a=range(10)*3 def seqelem(): i=random.randint(0,2) elem=['a','b','c'][i] return elem s=[seqelem() for t in range(30)] print zip(a,s) ## favored result: { '0':'c->c->a' ,'1':'a->b->a' .........} From ladasky at my-deja.com Sun Nov 7 15:32:46 2010 From: ladasky at my-deja.com (John Ladasky) Date: Sun, 7 Nov 2010 12:32:46 -0800 (PST) Subject: { '0':'c->c->a' ,'1':'a->b->a' .........} References: <8961af78-5f7b-46e1-95d7-014534b6e637@s4g2000yql.googlegroups.com> Message-ID: <7e03db1b-66ac-49ea-bbed-05d782ea4307@g20g2000prg.googlegroups.com> Hi Chris, I may have time to look at the rest of your code later. For now I just want to comment on one line: On Nov 7, 12:24?pm, chris wrote: > ? ? elem=['a','b','c'][i] The string type, just like the list type, is a sequence type. So strings have all the standard sequence methods. You could just write: elem = "abc"[i] From benjamin.kaplan at case.edu Sun Nov 7 15:34:38 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sun, 7 Nov 2010 15:34:38 -0500 Subject: Making ActivePython and Python co-exist on Windows In-Reply-To: References: Message-ID: On Sun, Nov 7, 2010 at 2:25 PM, CWC wrote: > I'm new to Python. ?Is it possible to make ActivePython 3.12 and > Python 3.12 co-exist on Windows? ?I've got an app which requires the > former, but I want to stay with the latter, since I'm interested in > getting into development. ?The main area of collision appears to be > the Registry. > -- ActivePython is the same thing as the "normal" Python. They just bundle the standard Python 3.1.2 distribution with a couple of extra packages in a convenient installer for you. From arnodel at gmail.com Sun Nov 7 15:51:50 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Sun, 07 Nov 2010 20:51:50 +0000 Subject: { '0':'c->c->a' ,'1':'a->b->a' .........} References: <8961af78-5f7b-46e1-95d7-014534b6e637@s4g2000yql.googlegroups.com> Message-ID: <87tyjsyhzt.fsf@gmail.com> chris writes: > Hi, > > have anybody a hint , how i get a dict from non unique id's and their > different related values. > > Thanks for advance > Chris > > ###random data # > a=range(10)*3 > def seqelem(): > i=random.randint(0,2) > elem=['a','b','c'][i] > return elem > > s=[seqelem() for t in range(30)] > print zip(a,s) > > ## favored result: > { '0':'c->c->a' ,'1':'a->b->a' .........} Here's one way: >>> import random >>> >>> a=range(10)*3 >>> def seqelem(): ... i=random.randint(0,2) ... elem=['a','b','c'][i] ... return elem ... >>> s=[seqelem() for t in range(30)] >>> z = zip(a, s) >>> print z [(0, 'b'), (1, 'a'), (2, 'b'), (3, 'a'), (4, 'b'), (5, 'c'), (6, 'b'), (7, 'c'), (8, 'b'), (9, 'b'), (0, 'a'), (1, 'b'), (2, 'b'), (3, 'c'), (4, 'c'), (5, 'b'), (6, 'c'), (7, 'a'), (8, 'a'), (9, 'c'), (0, 'b'), (1, 'c'), (2, 'b'), (3, 'a'), (4, 'c'), (5, 'a'), (6, 'c'), (7, 'b'), (8, 'c'), (9, 'c')] >>> >>> from itertools import groupby >>> from operator import itemgetter >>> >>> z.sort(key=itemgetter(0)) >>> print dict((k, '->'.join(map(itemgetter(1), it))) ... for k, it in groupby(z, itemgetter(0))) {0: 'b->a->b', 1: 'a->b->c', 2: 'b->b->b', 3: 'a->c->a', 4: 'b->c->c', 5: 'c->b->a', 6: 'b->c->c', 7: 'c->a->b', 8: 'b->a->c', 9: 'b->c->c'} HTH -- Arnaud From __peter__ at web.de Sun Nov 7 16:00:38 2010 From: __peter__ at web.de (Peter Otten) Date: Sun, 07 Nov 2010 22:00:38 +0100 Subject: { '0':'c->c->a' ,'1':'a->b->a' .........} References: <8961af78-5f7b-46e1-95d7-014534b6e637@s4g2000yql.googlegroups.com> Message-ID: chris wrote: > have anybody a hint , how i get a dict from non unique id's and their > different related values. > > Thanks for advance > Chris > > ###random data # > a=range(10)*3 > def seqelem(): > i=random.randint(0,2) > elem=['a','b','c'][i] > return elem > > s=[seqelem() for t in range(30)] > print zip(a,s) > > ## favored result: > { '0':'c->c->a' ,'1':'a->b->a' .........} >>> import random >>> from collections import defaultdict >>> a = range(10)*3 >>> s = [random.choice("abc") for _ in a] >>> d = defaultdict(list) >>> for k, v in zip(a, s): ... d[k].append(v) ... >>> d defaultdict(, {0: ['b', 'a', 'a'], 1: ['c', 'a', 'c'], 2: ['c', 'c', 'c'], 3: ['c', 'a', 'a'], 4: ['b', 'c', 'a'], 5: ['b', 'c', 'c'], 6: ['c', 'a', 'b'], 7: ['b', 'b', 'a'], 8: ['a', 'c', 'c'], 9: ['b', 'a', 'b']}) >>> dict((k, "->".join(v)) for k, v in d.iteritems()) {0: 'b->a->a', 1: 'c->a->c', 2: 'c->c->c', 3: 'c->a->a', 4: 'b->c->a', 5: 'b->c->c', 6: 'c->a->b', 7: 'b->b->a', 8: 'a->c->c', 9: 'b->a->b'} Peter From smallpox911 at gmail.com Sun Nov 7 16:01:39 2010 From: smallpox911 at gmail.com (small Pox) Date: Sun, 7 Nov 2010 13:01:39 -0800 (PST) Subject: *** FBI gets a warm welcome in Chicago for their EXCELLENTperformance - cheers to NEW CONS *** References: <26f97f70-9043-490c-9e6e-35159f38d76b@r29g2000yqj.googlegroups.com> <47e0b3a3-54fb-4489-95a8-b5ec6015c99d@j25g2000yqa.googlegroups.com> Message-ID: <75c68fde-988e-4000-99d4-0b7ee596babf@x7g2000prj.googlegroups.com> *** FBI gets a warm welcome in Chicago for their EXCELLENT performance - cheers to NEW CONS *** http://www.youtube.com/watch?v=eq2ZvSd-z0M&feature=player_embedded&related http://www.youtube.com/watch?v=eq2ZvSd-z0M&feature=player_embedded&related http://www.youtube.com/watch?v=eq2ZvSd-z0M&feature=player_embedded&related http://www.youtube.com/watch?v=eq2ZvSd-z0M&feature=player_embedded&related http://www.youtube.com/watch?v=eq2ZvSd-z0M&feature=player_embedded&related On Nov 2, 2:30 pm, silver light wrote: > On Nov 2, 1:58 pm, Rich Grise wrote: > > > On Tue, 02 Nov 2010 14:17:29 -0700, Gunner Asch wrote: > > > > But...shrug..there will be far less after the Great Cull........ > > > I think some people might be surprised as to exactly _who_ gets "culled". > > > Good Luck! > > Rich > > On Nov 2, 11:03 am, t... at sevak.isi.edu (Thomas A. Russ) wrote: > > > silver light writes: > > > *** FBI gets a warm welcome in Chicago for their EXCELLENT performance > > > - cheers to NEW CONS *** > > > Oh geez. Just when we've beaten back the infix hordes, someone comes up > > and suggests replacing CONS with something, new different and most > > likely inferior. > > > - Grumpy Old Programmer. > > > -- > > Thomas A. Russ, USC/Information Sciences Institute > > Google censored my post and deleted it not because they are trying to > defend the FBI or cover them up. They just dont like silverlight which > is from Microsoft. > > It is well known that google and oracle are trying to get control of > the whole cyberspace either alone or in alliance with each other. > > This way they can control the federal government. Most senators and > congressmen are pea brain and go along with whatever the corporations > show them with music, viagra, champagne, food, cruise tickets, girls > and pocket money. > > ========== > Submitted by jkeogh on Tue, 11/02/2010 - 6:44am > > http://911blogger.com/news/2010-10-20/foia-funds-request > > Litigation seeking the release of never before seen 9/11 FBI records > is currently underway in the federal courts. There is a immediate need > for a FOIA attorney to assist with the case. The defendants are > operating with a nearly unlimited funding and have a large body of > legal experts working to prevent the release of these records. A > public interest FOIA attorney has offered their services at a reduced > public interest rate. We need the research communities help to raise > the required funds. Release of these requested records may help settle > questions surrounding the Pentagon and Shanksville controversies, as > well as others. Release of these records could also help overcome > future claims of release exemption by the FBI for other 9/11 records > requests. From smallpox911 at gmail.com Sun Nov 7 17:19:17 2010 From: smallpox911 at gmail.com (small Pox) Date: Sun, 7 Nov 2010 14:19:17 -0800 (PST) Subject: *** FBI gets a warm welcome in Chicago for their EXCELLENT performance - cheers to NEW CONS *** References: <73cd58e5-5aae-4d90-93fa-5bd481f8da62@y23g2000yqd.googlegroups.com> Message-ID: <261215f5-f71e-4728-90ee-284d701fda9c@x4g2000pre.googlegroups.com> On Nov 2, 10:03?am, t... at sevak.isi.edu (Thomas A. Russ) wrote: > silver light writes: > > *** FBI gets a warm welcome in Chicago for their EXCELLENT performance > > - cheers to NEW CONS *** > > Oh geez. ?Just when we've beaten back the infix hordes, someone comes up > and suggests replacing CONS with something, new different and most > likely inferior. > > - Grumpy Old Programmer. > > -- > Thomas A. Russ, ?USC/Information Sciences Institute Little-Known 9/11 Truth Organization Strikes Gold in Court Action Against NIST, Unearths Striking Video/Photo WTC Evidence Written by Eli Rika Saturday, 06 November 2010 Over the last century, the most astounding historical discoveries of man-made artifacts have often been accomplished by well-funded, highly experienced researchers. From the excavation of King Tut?s tomb to the sighting of the sunken Titanic, stunning finds have required immense financial and human resources, as well as the leadership by distinguished. So, how did a mountain of never-before-seen footage used in NIST?s World Trade Center investigations get exposed to the light of day last month? Was it the work of a billionaire adventurer? Not quite. You can thank an upstart non-profit, the International Center for 9/11 Studies, whose efforts have at last borne fruit. The International Center for 9/11 Studies was founded in 2008 by Director James Gourley, a Texas lawyer who began questioning the events of 9/11 after watching a presentation given by David Ray Griffin on C-SPAN. ?I was just floored by what I was hearing,? Gourley explained, ?and I?ve been looking into 9/11 ever since then. From philip at semanchuk.com Sun Nov 7 19:01:10 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Sun, 7 Nov 2010 19:01:10 -0500 Subject: Silly newbie question - Carrot character (^) In-Reply-To: <20101106104502.dd0456bb.darcy@druid.net> References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> <20101106104502.dd0456bb.darcy@druid.net> Message-ID: On Nov 6, 2010, at 10:45 AM, D'Arcy J.M. Cain wrote: > On Sat, 6 Nov 2010 10:22:47 -0400 > Philip Semanchuk wrote: >>> The tutorial isn't meant as an exhaustive lesson on every single Python >>> feature. >> >> I agree, and I don't expect otherwise. My point was that if the >> tutorial doesn't mention a feature, the only other place to learn about >> it (on python.org) is the language ref. Some people might think the >> language ref is a fine place to direct newcomers to Python. I don't. > > I don't think that anyone was suggesting the reference as the first > place to send newcomers. Hi D'Arcy, I agree, no one -- not even I -- suggested that. The tutorial is always the first stop. > You send them there when they need something > beyond the basics. But IMO this is still a problem. After the tutorial, then what? Someone who has read the tutorial can still be new to Python by my definition. You may feel that the current language ref is OK for newcomers. I don't, and that's my point. > I think the only issue here is that operators are > pretty basic and that specific thing is missing in the tutorial. It > would be a mistake to write a whole new document because the tutorial > is missing one thing. Better would be to propose an operators section. The issue is not just operators. As I mentioned, the tutorial doesn't cover decorators, assert, exec, ternary if, and maybe a few other things. IMO that's fine. A tutorial should introduce the basics. I'm sure we could have a fine argument about what features of Python are basic and which are advanced, but I'd rather not as long as we can agree with Steven D'Aprano's comment that "The tutorial isn't meant as an exhaustive lesson on every single Python feature". I certainly agree with that. Personally, I liked using the tutorial for learning Python. It's readable. But after getting familiar with the language I wanted to move on to something more structured. I also realized that the tutorial didn't cover every aspect of the language because I saw references in code and discussions to things that weren't mentioned in the tutorial. I didn't feel like the python.org documentation provided an obvious next step, though, because I started with Python 2.3, and the language reference was still entitled "for language lawyers" back then. The section's name may have changed since then, but it looks like the style hasn't changed much. I believe the lack of a complete, friendly post-tutorial document to read made learning Python more difficult for me. >> I realize that the Python Foundation doesn't have infinite resources >> to work with, so maybe they'd love to create & maintain a more readable >> language reference if they had time/money/people. I don't hear anyone >> talk about it, though. > > Lots of people talk. Action, not so much. How about you? Are you > ready to start writing a new reference manual? First you suggest that writing a whole new document would be a mistake, then you encourage me to do it. =) The old open source challenge of "If you don't like it, fix it" is liberating but it's also a nifty way of changing the subject. Whether or not I can or will fix a problem doesn't make my criticism any more or less legitimate which (I thought) was the issue at hand. To answer your question: no, I'm not willing to start writing a new reference manual. For one thing, I don't think it's wanted judging by the response I've seen here. I see a lot of people saying "what we have is fine". To put it another way, based on this small sample size survey, opinions are mixed on the current state of the documentation. The effort required to make substantial changes (e.g. create a reference manual that's sort of a marriage of the tutorial and the language spec) is large but would likely result in very little net improvement as perceived by the community as a whole. To put it a fifth way (Sir Galahad: "third, sir") -- people learn differently. Cheers Philip From jason.heeris at gmail.com Sun Nov 7 19:19:45 2010 From: jason.heeris at gmail.com (Jason) Date: Sun, 7 Nov 2010 16:19:45 -0800 (PST) Subject: Cross compiling (i386 from amd64) with distutils Message-ID: My situation is this: I have a Diamond Systems single-board computer with a matching GPIO board. DS have a library for controlling the GPIO board... but it's a static library (libdscud-6.02.a) with an accompanying header (dscud.h). I'd like to create a Python extension to use the device. The architecture of the SBC is 486, and it runs Debian Squeeze/Grip. While it is possible to develop on it directly, I'd rather use my desktop machine (Debian Squeeze, amd64). If I write a simple C program to control the device, I'd include the header file and cross-compile it like so: gcc -m32 -march=i386 -lpthread -I/usr/local/dscud-6.02 -o dio dio.c \ /usr/local/dscud-6.02/libdscud-6.02.a To get myself started with the Python extension, I've basically taken the "noddy" demo[1] and thrown in a function call from the DSC library just to see if I can get something to build. My distutils setup.py looks like: ---- from distutils.core import setup, Extension module1 = Extension('noddy', sources = ['src/noddy.c'], libraries = ['pthread'], include_dirs = ['/usr/local/dscud-6.02'], extra_objects = ['/usr/local/dscud-6.02/libdscud-6.02.a'], extra_compile_args = ['-m32', '-march=i386']) setup(name = 'Noddy', version = '1.0', description = 'This is a demo package', ext_modules = [module1]) ---- This works fine on the target machine with "python setup.py build", but when I try it on my desktop machine, I get: ---- $ python setup.py build running build running build_ext building 'noddy' extension creating build creating build/temp.linux-x86_64-2.6 creating build/temp.linux-x86_64-2.6/src gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/local/dscud-6.02 -I/usr/include/ python2.6 -c src/noddy.c -o build/temp.linux-x86_64-2.6/src/noddy.o -m32 - march=i386 In file included from /usr/include/python2.6/Python.h:58, from src/noddy.c:1: /usr/include/python2.6/pyport.h:694:2: error: #error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)." error: command 'gcc' failed with exit status 1 ---- So is it possible to get distutils to cross compile something like this, and if so, what am I missing? Or am I using the wrong tool for the job? Target python ver. is 2.6. GCC is 4.4.5. Cheers, Jason [1] http://docs.python.org/extending/newtypes.html From martin at v.loewis.de Sun Nov 7 19:30:25 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Mon, 08 Nov 2010 01:30:25 +0100 Subject: Cross compiling (i386 from amd64) with distutils In-Reply-To: References: Message-ID: > So is it possible to get distutils to cross compile something like > this, and > if so, what am I missing? Or am I using the wrong tool for the job? At a minimum, you should be using the target's python binary. distutils has close-to-none cross-compiling support. You can solve some of the problems by editing the Makefile which it uses to learn the compiler options from. Regards, Martin From ldo at geek-central.gen.new_zealand Sun Nov 7 19:52:52 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 08 Nov 2010 13:52:52 +1300 Subject: Silly newbie question - Caret character (^) References: Message-ID: In message , Emile van Sebille wrote: > On 11/7/2010 2:26 AM Lawrence D'Oliveiro said... >> In message, Nobody wrote: >> >>> A reference manual tells you how to use the language. A specification >>> tells you how to implement it. >> >> Speaking as someone who has read more reference >> manuals/specifications/whatever you want to call them than I can count, I >> have never come across any such distinction. > > Surely you see the difference between RFC5321 and for example Courier's > man pages? One's the specification and the other's the reference manual. The language in question being ... ? From ldo at geek-central.gen.new_zealand Sun Nov 7 19:53:56 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 08 Nov 2010 13:53:56 +1300 Subject: ANN: PyQt v4.8.1 Released References: <3aqiq7-46p.ln1@archaeopteryx.softver.org.mk> Message-ID: In message , Robert Kern wrote: > Everyone here knew exactly what he meant. But if you don?t banana the right tomato, everybody could be grapefruit, right? You know what I mean. From jason.heeris at gmail.com Sun Nov 7 19:55:36 2010 From: jason.heeris at gmail.com (Jason) Date: Sun, 7 Nov 2010 16:55:36 -0800 (PST) Subject: Cross compiling (i386 from amd64) with distutils References: Message-ID: On Nov 8, 8:30?am, "Martin v. Loewis" wrote: > At a minimum, you should be using the target's python binary. distutils > has close-to-none cross-compiling support. Do you know if virtualenv allows installing a Python environment with a different architecture than that of the system Python install? I suspect not, but maybe there's an option I don't know about. > You can solve some of the > problems by editing the Makefile which it uses to learn the compiler > options from. I don't understand this - do you mean I should edit the Makefile in the actual distutils package, and somehow use that in my project instead of setup.py? ? Jason From invalid at invalid.invalid Sun Nov 7 20:07:03 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 8 Nov 2010 01:07:03 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jftftFelnU1@mid.individual.net> <87oca1b8ba.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On 2010-11-07, Steve Holden wrote: > On 11/7/2010 10:46 AM, Grant Edwards wrote: >> On 2010-11-07, Steve Holden wrote: >>> On 11/7/2010 8:23 AM, Grant Edwards wrote: >>> [...] >>>> (I bought 4:3 monitors before they got replaced by cheap 16:8 >>>> screens) >>> >>> I think you'll find the new aspect ration is 16:9. >> > "aspect ration". Sheesh. > >> I knew that. My keyboard didn't. >> >> I recently bought a close-out Lenovo T500 Thinkpad from their outlet >> because current models are now 16:9 instead of the older 16:10. My >> old 4:3 Thinkpad was still going strong, but I decided I'd better get >> a 16:10 while I could -- though I'd still prefer a 4:3. >> > The thing that *really* pisses me off is that you *used* to be able to > get 1920 x 1200 15" displays, but *now* you are lucky to go above 1080 > vertical pixels even in a 17" laptop display. I don't want the > resolution of my displays dictated by the resolution of my (current) > media, yet it seems that's what's happened in the laptop market. It's getting really hard to find high-DPI displays on laptops any more. 1600x1200 used to be available on 16" laptop displays, and that looked great. Even my old 15" thinkpad at 1400x1050 wasn't bad. > I got a Lenovo T60 a while back as a touchpad machine. Wondering about > switching that to Linux, but I haven't seen any touchpad distros in > action yet. -- Grant From robert.kern at gmail.com Sun Nov 7 20:26:51 2010 From: robert.kern at gmail.com (Robert Kern) Date: Sun, 07 Nov 2010 19:26:51 -0600 Subject: ANN: PyQt v4.8.1 Released In-Reply-To: References: <3aqiq7-46p.ln1@archaeopteryx.softver.org.mk> Message-ID: On 2010-11-07 18:53 , Lawrence D'Oliveiro wrote: > In message, Robert Kern > wrote: > >> Everyone here knew exactly what he meant. > > But if you don?t banana the right tomato, everybody could be grapefruit, > right? > > You know what I mean. And as I reiterated in the part that you snipped, he is not using "commercial" as a synonym for "proprietary". It is the license that he sells commercially. -- 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 yuwenhuan at gmail.com Sun Nov 7 20:30:23 2010 From: yuwenhuan at gmail.com (Wenhuan Yu) Date: Sun, 7 Nov 2010 19:30:23 -0600 Subject: http error 301 for urlopen Message-ID: I tried to open a link with urlopen: import urllib2 alink = " http://feeds.nytimes.com/click.phdo?i=ff074d9e3895247a31e8e5efa5253183" f = urllib2.urlopen(alink) print f.read() and got the followinig error: urllib2.HTTPError: HTTP Error 301: The HTTP server returned a redirect error tha t would lead to an infinite loop. The last 30x error message was: Moved Permanently I can open the link in browser. Any way to get solve this? Thanks. Wen -------------- next part -------------- An HTML attachment was scrubbed... URL: From jason.heeris at gmail.com Sun Nov 7 20:41:20 2010 From: jason.heeris at gmail.com (Jason) Date: Sun, 7 Nov 2010 17:41:20 -0800 (PST) Subject: Cross compiling (i386 from amd64) with distutils References: Message-ID: <8cc6791f-5ed8-479f-bd1c-adc808bd048d@n32g2000pre.googlegroups.com> On Nov 8, 8:55?am, Jason wrote: > Do you know if virtualenv allows installing a Python environment with > a different architecture than that of the system Python install? I > suspect not, but maybe there's an option I don't know about. Found a better solution, which is to just compile Python from source to be 32 bit. This is from: http://indefinitestudies.org/2010/02/08/how-to-build-32-bit-python-on-ubuntu-9-10-x86_64/ Thanks for your help, Jason From darcy at druid.net Sun Nov 7 20:51:50 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sun, 7 Nov 2010 20:51:50 -0500 Subject: http error 301 for urlopen In-Reply-To: References: Message-ID: <20101107205150.ebb06684.darcy@druid.net> On Sun, 7 Nov 2010 19:30:23 -0600 Wenhuan Yu wrote: > I tried to open a link with urlopen: > > import urllib2 > alink = " > http://feeds.nytimes.com/click.phdo?i=ff074d9e3895247a31e8e5efa5253183" > f = urllib2.urlopen(alink) > print f.read() > > and got the followinig error: > > urllib2.HTTPError: HTTP Error 301: The HTTP server returned a redirect error > that would lead to an infinite loop. > The last 30x error message was: > Moved Permanently > > I can open the link in browser. Any way to get solve this? Thanks. I checked with my tools and was told that it redirects more than five times. Maybe it's not infinite but too many for urlopen. Or, maybe the browser just ignores the extra redirects and the part of the page with the redirects isn't critical for viewing it. I think that you are going to have to investigate the HTML manually and follow all the individual links to find the problem. You may have to put in a bug request with the New York Times. Good luck with that. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From roy at panix.com Sun Nov 7 20:54:30 2010 From: roy at panix.com (Roy Smith) Date: Sun, 07 Nov 2010 20:54:30 -0500 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jftftFelnU1@mid.individual.net> <87oca1b8ba.fsf.mdw@metalzone.distorted.org.uk> Message-ID: In article , Grant Edwards wrote: > It's getting really hard to find high-DPI displays on laptops any > more. 1600x1200 used to be available on 16" laptop displays, and that > looked great. Even my old 15" thinkpad at 1400x1050 wasn't bad. My 15" MacBook Pro is 1680 x 1050. From nobody at nowhere.com Sun Nov 7 21:41:29 2010 From: nobody at nowhere.com (Nobody) Date: Mon, 08 Nov 2010 02:41:29 +0000 Subject: http error 301 for urlopen References: Message-ID: On Sun, 07 Nov 2010 20:51:50 -0500, D'Arcy J.M. Cain wrote: >> urllib2.HTTPError: HTTP Error 301: The HTTP server returned a redirect error >> that would lead to an infinite loop. >> The last 30x error message was: >> Moved Permanently >> >> I can open the link in browser. Any way to get solve this? Thanks. > > I checked with my tools and was told that it redirects more than five > times. Maybe it's not infinite but too many for urlopen. The default value of urllib2.HTTPRedirectHandler.max_redirections is 10. Setting it to 11 allows the request to complete. From wuwei23 at gmail.com Sun Nov 7 22:28:52 2010 From: wuwei23 at gmail.com (alex23) Date: Sun, 7 Nov 2010 19:28:52 -0800 (PST) Subject: functions, list, default parameters References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <20101021235138.609fe668@geekmail.INVALID> <87pquk3ehs.fsf.mdw@metalzone.distorted.org.uk> <4cd3c72b$0$30004$c3e8da3$5496439d@news.astraweb.com> <8739rg2ceb.fsf.mdw@metalzone.distorted.org.uk> <4cd4cc74$0$30004$c3e8da3$5496439d@news.astraweb.com> <87bp62eig9.fsf.mdw@metalzone.distorted.org.uk> <87y696cjjh.fsf.mdw@metalzone.distorted.org.uk> Message-ID: m... at distorted.org.uk (Mark Wooding) wrote: > And the advantage of all of this typing over ['missing'] is what, > precisely? No chance of the sentinel object being accidentally mutated would be the big one for me, but clarity of intent would be a close second. From cwc at cwc.name Sun Nov 7 22:50:44 2010 From: cwc at cwc.name (CWC) Date: Sun, 7 Nov 2010 19:50:44 -0800 (PST) Subject: Making ActivePython and Python co-exist on Windows References: Message-ID: On Nov 7, 12:34?pm, Benjamin Kaplan wrote: > ActivePython is the same thing as the "normal" Python. They just > bundle the standard Python 3.1.2 distribution with a couple of extra > packages in a convenient installer for you. Thanks, Ben! Based on your response, I decided to go ahead and install ActivePython 3.1.2. From " " at libero.it Sun Nov 7 23:42:41 2010 From: " " at libero.it (not1xor1 (Alessandro)) Date: Mon, 08 Nov 2010 04:42:41 GMT Subject: subclassing str In-Reply-To: References: Message-ID: <5dLBo.1024$w8.406@twister2.libero.it> Il 07/11/2010 07:41, Chris Rebert wrote: > You could subclass UserString instead of str; all of UserString's > methods seem to ensure that instances of the subclass rather than just > plain strs or UserStrings are returned. See > http://docs.python.org/library/userdict.html#UserString.UserString I'll have a look at it, thanks > But you should also consider whether your additions absolutely *must* > be methods. Merely instead defining some functions that take strings > as parameters is obviously a simpler, and probably more performant, > approach. I regularly save web pages (mostly scientific research abstracts) from various web sites and use a python script to strip them of ads and unneeded informations, embedding the images directly in the html file (as base64 encoded data) and at times joining multiple pages into just one since those sites often change the format of their files I've to modify my script accordingly I'm already using plain functions, but thought that wrapping most of them in a str subclass would let me save some time and yield cleaner and more manageable code > If you insist on subclassing str, there's no such hook; you'll have to > override all the methods yourself.* I'll try this route too (at least for the methods I need) thanks for your help -- bye !(!1|1) From nagle at animats.com Mon Nov 8 01:28:10 2010 From: nagle at animats.com (John Nagle) Date: Sun, 07 Nov 2010 22:28:10 -0800 Subject: http error 301 for urlopen In-Reply-To: References: Message-ID: <4cd7987e$0$1674$742ec2ed@news.sonic.net> On 11/7/2010 5:51 PM, D'Arcy J.M. Cain wrote: > On Sun, 7 Nov 2010 19:30:23 -0600 > Wenhuan Yu wrote: >> I tried to open a link with urlopen: >> >> import urllib2 >> alink = " >> http://feeds.nytimes.com/click.phdo?i=ff074d9e3895247a31e8e5efa5253183" >> f = urllib2.urlopen(alink) >> print f.read() >> >> and got the followinig error: >> >> urllib2.HTTPError: HTTP Error 301: The HTTP server returned a redirect error >> that would lead to an infinite loop. >> The last 30x error message was: >> Moved Permanently >> >> I can open the link in browser. Any way to get solve this? Thanks. > > I checked with my tools and was told that it redirects more than five > times. Maybe it's not infinite but too many for urlopen. Or, maybe > the browser just ignores the extra redirects and the part of the page > with the redirects isn't critical for viewing it. I think that you are > going to have to investigate the HTML manually and follow all the > individual links to find the problem. You may have to put in a bug > request with the New York Times. Good luck with that. It's the New York Times' paywall. They're trying to set a cookie, and will redirect the URL until you store and return the cookie. John Nagle From johann.spies at gmail.com Mon Nov 8 02:47:31 2010 From: johann.spies at gmail.com (Johann Spies) Date: Mon, 8 Nov 2010 09:47:31 +0200 Subject: suds: how to set proxy? Message-ID: According to the suds documentation I can set the proxy setting like this: d = dict(http='host:80', https='host:443', ...) client.set_options(proxy=d) My problem is that you can only do that after 'client' was initiated like this: client = Client(url) And I need the proxy to reach the url. I have tried the following ending in a SYN_SENT each time - ignoring the proxy settings: proxy = dict(http='proxy.sun.ac.za:3128', https='proxy.sun.ac.za:3128') url = 'url_of_wdsl' t = HttpAuthenticated() client = Client(url, proxy = proxy, transport = t, username='myusername', password='pw') or url = 'url_of_wdsl' t = HttpAuthenticated() client = Client(url, transport = t, username='myusername', password='pw') client.set_options(proxy=proxy) So how do I get suds to respect the proxy setting? Regards Johann -- ?May grace and peace be yours in abundance through the full knowledge of God and of Jesus our Lord! ?His divine power has given us everything we need for life and godliness through the full knowledge of the one who called us by his own glory and excellence. ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ?2 Pet. 1:2b,3a From ldo at geek-central.gen.new_zealand Mon Nov 8 03:06:43 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 08 Nov 2010 21:06:43 +1300 Subject: Popen Question References: <891a9a80-c30d-4415-ac81-bddd0b564fa6@g13g2000yqj.googlegroups.com> Message-ID: In message , Chris Torek wrote: > ['/bin/sh', '-c', 'echo', '$MYVAR'] > > (with arguments expressed as a Python list). /bin/sh takes the > string after '-c' as a command, and the remaining argument(s) if > any are assigned to positional parameters ($0, $1, etc). Doesn?t work. I don?t know what happens to the extra arguments, but they just seem to be ignored if -c is specified. sh -c 'echo hi' echoes ?hi?, while sh -c echo hi just outputs a blank line. From ladasky at my-deja.com Mon Nov 8 03:06:46 2010 From: ladasky at my-deja.com (John Ladasky) Date: Mon, 8 Nov 2010 00:06:46 -0800 (PST) Subject: functions, list, default parameters References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <20101021235138.609fe668@geekmail.INVALID> Message-ID: <5061318e-e847-4b63-b5fa-5ea62db7ee17@w38g2000pri.googlegroups.com> On Nov 1, 7:30?pm, Lawrence D'Oliveiro wrote: > In message <20101021235138.609fe... at geekmail.INVALID>, Andreas Waldenburger > wrote: > > > While not very commonly needed, why should a shared default argument be > > forbidden? > > Because it?s safer to disallow it than to allow it. That's why Java is the way that it is, right? It tries -- too hard, some would say -- to "protect" the programmer from making "mistakes." From ldo at geek-central.gen.new_zealand Mon Nov 8 03:07:15 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 08 Nov 2010 21:07:15 +1300 Subject: Why "flat is better than nested"? References: Message-ID: In message , rustom wrote: > If you take zen seriously you dont get it > If you dont take zen seriously you dont get it > That -- seriously -- is zen I don?t get it. From martin at v.loewis.de Mon Nov 8 03:16:28 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Mon, 08 Nov 2010 09:16:28 +0100 Subject: Cross compiling (i386 from amd64) with distutils In-Reply-To: References: Message-ID: <4CD7B1DC.5080306@v.loewis.de> >> You can solve some of the >> problems by editing the Makefile which it uses to learn the compiler >> options from. > > I don't understand this - do you mean I should edit the Makefile in > the actual distutils package, and somehow use that in my project > instead of setup.py? No. A python *installation* has a Makefile, in config/Makefile. If you want distutils to use different options, you could edit this Makefile. Regards, Martin From jason.heeris at gmail.com Mon Nov 8 04:06:31 2010 From: jason.heeris at gmail.com (Jason) Date: Mon, 8 Nov 2010 01:06:31 -0800 (PST) Subject: Cross compiling (i386 from amd64) with distutils References: <4CD7B1DC.5080306@v.loewis.de> Message-ID: On Nov 8, 4:16?pm, "Martin v. Loewis" wrote: > No. A python *installation* has a Makefile, in config/Makefile. If > you want distutils to use different options, you could edit this > Makefile. Oh, I see what you mean. But then it would affect *everything* I build on that machine, so I'll stick with the "separate 32-bit installation" approach. Cheers, Jason From mdw at distorted.org.uk Mon Nov 8 04:43:27 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Mon, 08 Nov 2010 09:43:27 +0000 Subject: Popen Question References: <891a9a80-c30d-4415-ac81-bddd0b564fa6@g13g2000yqj.googlegroups.com> Message-ID: <87hbfs9mm8.fsf.mdw@metalzone.distorted.org.uk> Lawrence D'Oliveiro writes: > In message , Chris Torek wrote: > > > ['/bin/sh', '-c', 'echo', '$MYVAR'] > > > > (with arguments expressed as a Python list). /bin/sh takes the > > string after '-c' as a command, and the remaining argument(s) if > > any are assigned to positional parameters ($0, $1, etc). > > Doesn?t work. What doesn't work? You were being given an explanation, not a solution. > I don?t know what happens to the extra arguments, but they just seem > to be ignored if -c is specified. The argument to -c is taken as a shell script; the remaining arguments are made available as positional parameters to the script as usual (only starting with $0 rather than $1, for some unknown reason). -- [mdw] From see.my.homepage at gmail.com Mon Nov 8 06:06:01 2010 From: see.my.homepage at gmail.com (Maciej Sobczak) Date: Mon, 8 Nov 2010 03:06:01 -0800 (PST) Subject: YAMI4 v. 1.2.0 released Message-ID: <9e796ac5-04db-4bd5-aec4-5122729b604e@x42g2000yqx.googlegroups.com> Hello, I am pleased to announce that the new version of YAMI4, 1.2.0, has been just released and is available for download: http://www.inspirel.com/yami4/ The most important addition for Python programmers is the Python 2.5+ module that complements the already existing Python 3.x library. Thanks to this, both branches of the language are now properly supported. The following functional improvements were added in all modules: - Keepalive option for TCP/IP. - Propagation of events related to connection management. - Ability to customize the management of slow (overflowing) receivers in the publish-subscribe scenario. Please see the changelog.txt file for the detailed list of improvements. -- Maciej Sobczak * http://www.inspirel.com From antoniodeharomillan at gmail.com Mon Nov 8 06:22:45 2010 From: antoniodeharomillan at gmail.com (Antonio de Haro Millan) Date: Mon, 8 Nov 2010 12:22:45 +0100 Subject: Python 2.7 Message-ID: I can not install "*Python Imaging Library 1.1.7 for Python 2.6* (Windows only)" because I have the *Python 2.7. *A solution please... ___________________ Antonio de Haro Millan www.de-haro.es Tf.34.639.972.872 -------------- next part -------------- An HTML attachment was scrubbed... URL: From felipe.bastosn at gmail.com Mon Nov 8 06:50:53 2010 From: felipe.bastosn at gmail.com (Felipe Bastos Nunes) Date: Mon, 8 Nov 2010 09:50:53 -0200 Subject: Python 2.7 In-Reply-To: References: Message-ID: Install the python 2.6.x :-) 2010/11/8, Antonio de Haro Millan : > I can not install "*Python Imaging Library 1.1.7 for Python 2.6* (Windows > only)" > because I have the *Python 2.7. *A solution please... > > ___________________ > Antonio de Haro Millan > www.de-haro.es > Tf.34.639.972.872 > -- Felipe Bastos Nunes From duane.kaufman at gmail.com Mon Nov 8 07:06:11 2010 From: duane.kaufman at gmail.com (TheSeeker) Date: Mon, 8 Nov 2010 04:06:11 -0800 (PST) Subject: Deditor 0.2.2 References: Message-ID: <6cdb5dd1-1868-4a6e-8b59-5b871f8d412e@42g2000prt.googlegroups.com> On Nov 6, 7:06?am, Kruptein wrote: > Hey, > > I released version 0.2.2 of my pythonic text-editor ?Deditor. > It adds the use of projects, a project is a set of files which you can > open all at once to make development much faster and easier. > > For more information visit launchpad:http://launchpad.net/deditor > > I also uploaded a video to introduce you to deditor:http://www.youtube.com/watch?v=hS8xBu-39VI > (note: youtube is still processing the file so you might have to wait > a bit to see it) Hi, I might have missed this, but it seems deditor requires Python above 2.5? It would be nice to mention the requirements on the home page somewhere. Thanks, Duane From brf256 at gmail.com Mon Nov 8 07:14:03 2010 From: brf256 at gmail.com (brf256 at gmail.com) Date: Mon, 8 Nov 2010 12:14:03 +0000 Subject: Python 2.7 Message-ID: <1170667852-1289218443-cardhu_decombobulator_blackberry.rim.net-396203-@bda480.bisx.prod.on.blackberry> use python 2.6 :] - Braden Faulkner From drobinow at gmail.com Mon Nov 8 07:24:38 2010 From: drobinow at gmail.com (David Robinow) Date: Mon, 8 Nov 2010 07:24:38 -0500 Subject: Python 2.7 In-Reply-To: References: Message-ID: On Mon, Nov 8, 2010 at 6:22 AM, Antonio de Haro Millan wrote: > I can not install?"Python Imaging Library 1.1.7 for Python 2.6?(Windows > only)" > because I have the?Python 2.7. A solution please... download http://effbot.org/media/downloads/PIL-1.1.7/win32-py2.7.exe From roy at panix.com Mon Nov 8 07:39:46 2010 From: roy at panix.com (Roy Smith) Date: Mon, 08 Nov 2010 07:39:46 -0500 Subject: functions, list, default parameters References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <20101021235138.609fe668@geekmail.INVALID> Message-ID: In article , Lawrence D'Oliveiro wrote: > In message <20101021235138.609fe668 at geekmail.INVALID>, Andreas Waldenburger > wrote: > > > While not very commonly needed, why should a shared default argument be > > forbidden? > > Because it???s safer to disallow it than to allow it. The best way to deal with this is to have some kind of knob you can turn to enable or disable warnings about these sorts of things. Could be a command-line flag, a stand-alone tool (i.e. pylint), or even something in-line (like perl' 'use strict' directive). Good engineering practice would be use enable "debug mode" during testing and review all the warnings to see which ones surprise you. From simon at brunningonline.net Mon Nov 8 08:13:20 2010 From: simon at brunningonline.net (Simon Brunning) Date: Mon, 8 Nov 2010 13:13:20 +0000 Subject: A question about yield In-Reply-To: References: <40dd2ea7-0b1d-4600-8fc7-a2d0027b98c0@f16g2000prj.googlegroups.com> Message-ID: On 7 November 2010 18:14, Chris Rebert wrote: > On Sun, Nov 7, 2010 at 9:56 AM, chad wrote: >> But what happens if the input file is say 250MB? Will all 250MB be >> loaded into memory at once? > > No. As I said, the file will be read from 1 line at a time, on an > as-needed basis; which is to say, "line-by-line". IIRC, it's somewhere in between. Python will read the file in blocks. If only *looks* like it's reading the file line by line. -- Cheers, Simon B. From neilc at norwich.edu Mon Nov 8 08:29:05 2010 From: neilc at norwich.edu (Neil Cerutti) Date: 8 Nov 2010 13:29:05 GMT Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> <87aalrjkty.fsf@benfinney.id.au> <8jd3m9Fr55U7@mid.individual.net> <4cd50e7e$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8jqc90FbsnU4@mid.individual.net> On 2010-11-06, Steven D'Aprano wrote: >>> styles = [ >>> ("normal", "image", MainWindow.ColorsNormalList), >>> ("highlighted", "highlight", MainWindow.ColorsHighlightedList), >>> ("selected", "select", MainWindow.ColorsSelectedList)] >> >> Code should be utilitarian rather than ornate, Shaker rather >> than Victorian. > > Perhaps, but lining up the columns in a 3x3 table is hardly > "ornate". > > I have mixed feelings here. On the one hand, there's no doubt > in my mind that the extra whitespace and aligned columns make > the data easier to read for me. On the other hand, I know that > it is easy to fall into the trap of spending hours carefully > aligning code that doesn't need to be aligned. Some sort of comprehension test is probably required to know for sure, but I doubt the code benefits much at all from the columns. styles = [ ("normal", "image", MainWindow.ColorsNormalList), ("highlighted", "highlight", MainWindow.ColorsHighlightedList), ("selected", "select", MainWindow.ColorsSelectedList)] Moreover, I jump the gun early on tables like this. styles = [csv.reader(open("styles.csv", newlines=''))] Maybe too early. ;) -- Neil Cerutti From neilc at norwich.edu Mon Nov 8 08:50:55 2010 From: neilc at norwich.edu (Neil Cerutti) Date: 8 Nov 2010 13:50:55 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jftftFelnU1@mid.individual.net> Message-ID: <8jqdhvFbsnU5@mid.individual.net> On 2010-11-07, Lawrence D'Oliveiro wrote: > In message <8jftftFelnU1 at mid.individual.net>, Neil Cerutti wrote: > >> The handsome ':' terminator of if/elif/if statements allows us to >> omit a newline, conserving vertical space. This improves the >> readability of certain constructs. >> >> if x: print(x) >> elif y: print(y) >> else: print() > > I would never do that. ???Conserving vertical space??? seems a > stupid reason for doing it. In C, I even go the opposite way: > > if (x) > { > printf(..., x); > } > else if (y) > { > printf(..., y); > } > else > { > printf(...); > } /*if*/ Interesting. I find conserving vertical space to be a big win. I understand why you'd enforce braces for virtually all code bodies in C. In C, I'm giving up the most obvious form of expression for something obviously more robust. In Python, there's no such trade-off. Forbidding one-line conditional statements in Python would sacrifice succinctness for nothing. -- Neil Cerutti From jeanmichel at sequans.com Mon Nov 8 09:01:42 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 08 Nov 2010 15:01:42 +0100 Subject: Deditor 0.2.2 In-Reply-To: <6cdb5dd1-1868-4a6e-8b59-5b871f8d412e@42g2000prt.googlegroups.com> References: <6cdb5dd1-1868-4a6e-8b59-5b871f8d412e@42g2000prt.googlegroups.com> Message-ID: <4CD802C6.9010603@sequans.com> TheSeeker wrote: > On Nov 6, 7:06 am, Kruptein wrote: > >> Hey, >> >> I released version 0.2.2 of my pythonic text-editor Deditor. >> It adds the use of projects, a project is a set of files which you can >> open all at once to make development much faster and easier. >> >> For more information visit launchpad:http://launchpad.net/deditor >> >> I also uploaded a video to introduce you to deditor:http://www.youtube.com/watch?v=hS8xBu-39VI >> (note: youtube is still processing the file so you might have to wait >> a bit to see it) >> > > Hi, > I might have missed this, but it seems deditor requires Python above > 2.5? > > It would be nice to mention the requirements on the home page > somewhere. > > Thanks, > Duane > I already point that on the last release. You should really just consider writing the requirements (python & wx). JM From invalid at invalid.invalid Mon Nov 8 09:57:18 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 8 Nov 2010 14:57:18 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jftftFelnU1@mid.individual.net> <87oca1b8ba.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On 2010-11-08, Roy Smith wrote: > In article , > Grant Edwards wrote: > >> It's getting really hard to find high-DPI displays on laptops any >> more. 1600x1200 used to be available on 16" laptop displays, and that >> looked great. Even my old 15" thinkpad at 1400x1050 wasn't bad. > > My 15" MacBook Pro is 1680 x 1050. Yep, Apple is one of the holdouts that still offers 16:10 high resolution displays. That's the same format/resolution that Lenovo used to offer before they switched to 16:9. -- Grant Edwards grant.b.edwards Yow! Boy, am I glad it's at only 1971... gmail.com From steve at holdenweb.com Mon Nov 8 10:55:46 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 08 Nov 2010 10:55:46 -0500 Subject: Compare source code In-Reply-To: <8jqdhvFbsnU5@mid.individual.net> References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jftftFelnU1@mid.individual.net> <8jqdhvFbsnU5@mid.individual.net> Message-ID: On 11/8/2010 8:50 AM, Neil Cerutti wrote: [...] > Interesting. I find conserving vertical space to be a big win. I > understand why you'd enforce braces for virtually all code bodies > in C. In C, I'm giving up the most obvious form of expression for > something obviously more robust. In Python, there's no such > trade-off. Forbidding one-line conditional statements in Python > would sacrifice succinctness for nothing. One-line conditional statements aren't "forbidden" or they would not be grammatically correct. Many stylists (and the PEP 8 style guide) eschew the single-line form as less readable because the guarded suites (in this case, simple statements) are not flagged as clearly by indentation or a trailing colon, and are therefore more likely to be missed by the casual reader. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From zinckiwi at gmail.com Mon Nov 8 11:17:30 2010 From: zinckiwi at gmail.com (Scott Gould) Date: Mon, 8 Nov 2010 08:17:30 -0800 (PST) Subject: Question about expression evaluation Message-ID: <295c7760-f122-41c3-9f00-0934d3395ab4@u25g2000pra.googlegroups.com> Hi folks, This is a head-scratcher to me. I occasionally get this error: --- File "/var/www/myproj/account/views.py", line 54, in account if request.account.is_instructor and request.account.contact and request.account.contact.relationship.institution_party_number: AttributeError: 'NoneType' object has no attribute 'relationship' --- I'm leaving out all the supporting code deliberately. My question is simple: if python short-circuits evaluation and "request.account.contact" is None, how is it even getting as far as "request.account.contact.relationship.institution_party_number"? Thanks! From pruebauno at latinmail.com Mon Nov 8 11:38:21 2010 From: pruebauno at latinmail.com (nn) Date: Mon, 8 Nov 2010 08:38:21 -0800 (PST) Subject: Question about expression evaluation References: <295c7760-f122-41c3-9f00-0934d3395ab4@u25g2000pra.googlegroups.com> Message-ID: On Nov 8, 11:17?am, Scott Gould wrote: > Hi folks, > > This is a head-scratcher to me. I occasionally get this error: > > --- > ? File "/var/www/myproj/account/views.py", line 54, in account > ? ? if request.account.is_instructor and request.account.contact and > request.account.contact.relationship.institution_party_number: > > AttributeError: 'NoneType' object has no attribute 'relationship' > --- > > I'm leaving out all the supporting code deliberately. My question is > simple: if python short-circuits evaluation and > "request.account.contact" is None, how is it even getting as far as > "request.account.contact.relationship.institution_party_number"? > > Thanks! Hard to tell without details. Maybe request.account.contact is an impure property with side effects? From gb345 at invalid.com Mon Nov 8 11:45:24 2010 From: gb345 at invalid.com (gb345) Date: Mon, 8 Nov 2010 16:45:24 +0000 (UTC) Subject: How to get dynamically-created fxn's source? References: Message-ID: In Peter Otten <__peter__ at web.de> writes: >gb345 wrote: >> For a project I'm working on I need a way to retrieve the source >> code of dynamically generated Python functions. (These functions >> are implemented dynamically in order to simulate "partial application" >> in Python.[1]) >Are you aware of functools.partial? >>>> from functools import partial >>>> def f(a, b, c, x, y, z): >... return a*x + b*y*y + c*z*z*z >... >>>> fstar = partial(f, x=1, y=2, z=3) >>>> fstar(1, 0, 0) >1 >>>> fstar(0, 1, 0) >4 >>>> fstar(0, 0, 1) >27 >>>> fstar.args, fstar.keywords >((), {'y': 2, 'x': 1, 'z': 3}) >>>> fstar.func > I was not aware of functools.partial. This makes the problem a lot easier. Thanks! G From malaclypse2 at gmail.com Mon Nov 8 11:48:07 2010 From: malaclypse2 at gmail.com (Jerry Hill) Date: Mon, 8 Nov 2010 11:48:07 -0500 Subject: Question about expression evaluation In-Reply-To: <295c7760-f122-41c3-9f00-0934d3395ab4@u25g2000pra.googlegroups.com> References: <295c7760-f122-41c3-9f00-0934d3395ab4@u25g2000pra.googlegroups.com> Message-ID: On Mon, Nov 8, 2010 at 11:17 AM, Scott Gould wrote: > --- > ?File "/var/www/myproj/account/views.py", line 54, in account > ? ?if request.account.is_instructor and request.account.contact and > request.account.contact.relationship.institution_party_number: > > AttributeError: 'NoneType' object has no attribute 'relationship' > --- > > I'm leaving out all the supporting code deliberately. Perhaps request.account is being mutated in another thread? -- Jerry From __peter__ at web.de Mon Nov 8 11:52:21 2010 From: __peter__ at web.de (Peter Otten) Date: Mon, 08 Nov 2010 17:52:21 +0100 Subject: Question about expression evaluation References: <295c7760-f122-41c3-9f00-0934d3395ab4@u25g2000pra.googlegroups.com> Message-ID: Scott Gould wrote: > Hi folks, > > This is a head-scratcher to me. I occasionally get this error: > > --- > File "/var/www/myproj/account/views.py", line 54, in account > if request.account.is_instructor and request.account.contact and > request.account.contact.relationship.institution_party_number: > > AttributeError: 'NoneType' object has no attribute 'relationship' > --- > > I'm leaving out all the supporting code deliberately. My question is > simple: if python short-circuits evaluation and > "request.account.contact" is None, how is it even getting as far as > "request.account.contact.relationship.institution_party_number"? Probably a race condition: contact is set to None after request.account.contact is evaluated, but before request.account.contact.relationship is evaluated. This may happen in your case because the underlying database was modified by a different user (I'm speculating). Here's a simulation: >>> class Contact: ... relationship = "SUCCESS" ... >>> class Account(object): ... def __init__(self): ... self._contact = Contact() ... @property ... def contact(self): ... try: return self._contact ... finally: self._contact = None ... >>> account = Account() >>> account.contact and account.contact.relationship Traceback (most recent call last): File "", line 1, in AttributeError: 'NoneType' object has no attribute 'relationship' You can avoid the problem with a different coding style: >>> account = Account() >>> try: ... print account.contact.relationship ... except AttributeError: ... print "failed" ... SUCCESS Peter From zinckiwi at gmail.com Mon Nov 8 12:45:29 2010 From: zinckiwi at gmail.com (Scott Gould) Date: Mon, 8 Nov 2010 09:45:29 -0800 (PST) Subject: Question about expression evaluation References: <295c7760-f122-41c3-9f00-0934d3395ab4@u25g2000pra.googlegroups.com> Message-ID: Thanks for the ideas, everyone. It's probably obvious that this is in a Django context, and while I do have WSGI configured to multi-thread its processes, there is nothing explicitly shared -- via threading, a multi-user situation, or otherwise -- about this data. It is entirely local to the request so I can't figure out how the "contact" object could change in a single line of code. But obviously there must be something going on like what you all suggest. I just can't figure out how. This is the entirety of the contact-producing code within Account: @property def contact(self): if not hasattr(self, '_contact'): self._contact = get_contact_for_id(self.profile.id) if self.profile and self.profile.id else None return self._contact As you can see, it's essentially read-only so once a self._contact always a self._contact. (Unless I'm misunderstanding something fundamental, which as an admitted amateur I could well be!) On Nov 8, 11:17?am, Scott Gould wrote: > Hi folks, > > This is a head-scratcher to me. I occasionally get this error: > > --- > ? File "/var/www/myproj/account/views.py", line 54, in account > ? ? if request.account.is_instructor and request.account.contact and > request.account.contact.relationship.institution_party_number: > > AttributeError: 'NoneType' object has no attribute 'relationship' > --- > > I'm leaving out all the supporting code deliberately. My question is > simple: if python short-circuits evaluation and > "request.account.contact" is None, how is it even getting as far as > "request.account.contact.relationship.institution_party_number"? > > Thanks! From jeff.hobbs at gmail.com Mon Nov 8 12:54:18 2010 From: jeff.hobbs at gmail.com (Jeff Hobbs) Date: Mon, 8 Nov 2010 09:54:18 -0800 (PST) Subject: Python 2.7 References: Message-ID: On Nov 8, 3:50?am, Felipe Bastos Nunes wrote: > Install the python 2.6.x :-) > > 2010/11/8, Antonio de Haro Millan : > > > I can not install "*Python Imaging Library 1.1.7 for Python 2.6* (Windows > > only)" > > because I have the *Python 2.7. *A solution please... If you need Python 2.7, PIL is available via pypm for ActivePython 2.7: http://code.activestate.com/pypm/pil/ Jeff From ian.g.kelly at gmail.com Mon Nov 8 12:57:08 2010 From: ian.g.kelly at gmail.com (Ian) Date: Mon, 8 Nov 2010 09:57:08 -0800 (PST) Subject: Popen Question References: <891a9a80-c30d-4415-ac81-bddd0b564fa6@g13g2000yqj.googlegroups.com> <87hbfs9mm8.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On Nov 8, 2:43?am, m... at distorted.org.uk (Mark Wooding) wrote: > > I don?t know what happens to the extra arguments, but they just seem > > to be ignored if -c is specified. > > The argument to -c is taken as a shell script; the remaining arguments > are made available as positional parameters to the script as usual (only > starting with $0 rather than $1, for some unknown reason). Perhaps this example better demonstrates what is going on: >>> p = subprocess.Popen(['echo one $0 three $1 five', 'two', 'four'], ... shell=True) one two three four five Cheers, Ian From __peter__ at web.de Mon Nov 8 13:06:18 2010 From: __peter__ at web.de (Peter Otten) Date: Mon, 08 Nov 2010 19:06:18 +0100 Subject: Question about expression evaluation References: <295c7760-f122-41c3-9f00-0934d3395ab4@u25g2000pra.googlegroups.com> Message-ID: Scott Gould wrote: > Thanks for the ideas, everyone. It's probably obvious that this is in > a Django context, and while I do have WSGI configured to multi-thread > its processes, there is nothing explicitly shared -- via threading, a > multi-user situation, or otherwise -- about this data. It is entirely > local to the request so I can't figure out how the "contact" object > could change in a single line of code. > > But obviously there must be something going on like what you all > suggest. I just can't figure out how. This is the entirety of the > contact-producing code within Account: > > @property > def contact(self): > if not hasattr(self, '_contact'): If one thread stops this point the _contact attribute is not yet set and another thread may trigger the if-suite, too. > self._contact = get_contact_for_id(self.profile.id) if self.profile > and self.profile.id else None > return self._contact > > As you can see, it's essentially read-only so once a self._contact > always a self._contact. (Unless I'm misunderstanding something > fundamental, which as an admitted amateur I could well be!) From __peter__ at web.de Mon Nov 8 13:07:23 2010 From: __peter__ at web.de (Peter Otten) Date: Mon, 08 Nov 2010 19:07:23 +0100 Subject: Question about expression evaluation References: <295c7760-f122-41c3-9f00-0934d3395ab4@u25g2000pra.googlegroups.com> Message-ID: Scott Gould wrote: > Thanks for the ideas, everyone. It's probably obvious that this is in > a Django context, and while I do have WSGI configured to multi-thread > its processes, there is nothing explicitly shared -- via threading, a > multi-user situation, or otherwise -- about this data. It is entirely > local to the request so I can't figure out how the "contact" object > could change in a single line of code. > > But obviously there must be something going on like what you all > suggest. I just can't figure out how. This is the entirety of the > contact-producing code within Account: > > @property > def contact(self): > if not hasattr(self, '_contact'): If one thread stops at this point the _contact attribute is not yet set and another thread may trigger the if-suite, too. > self._contact = get_contact_for_id(self.profile.id) if self.profile > and self.profile.id else None > return self._contact > > As you can see, it's essentially read-only so once a self._contact > always a self._contact. (Unless I'm misunderstanding something > fundamental, which as an admitted amateur I could well be!) From sridharr at activestate.com Mon Nov 8 13:30:10 2010 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Mon, 8 Nov 2010 10:30:10 -0800 Subject: Making ActivePython and Python co-exist on Windows In-Reply-To: References: Message-ID: <88FDA881-2EA1-4206-89A9-5E80E4DF6CE8@activestate.com> On 2010-11-07, at 12:34 PM, Benjamin Kaplan wrote: > On Sun, Nov 7, 2010 at 2:25 PM, CWC wrote: >> I'm new to Python. Is it possible to make ActivePython 3.12 and >> Python 3.12 co-exist on Windows? I've got an app which requires the >> former, but I want to stay with the latter, since I'm interested in >> getting into development. The main area of collision appears to be >> the Registry. >> -- > > ActivePython is the same thing as the "normal" Python. They just > bundle the standard Python 3.1.2 distribution with a couple of extra > packages in a convenient installer for you. Yup. And as the documentation details, http://docs.activestate.com/activepython/3.1/whatsincluded.html ActivePython includes PyWin32, Tkinter based on Tk 8.5 ... and PyPM for easy package management, http://code.activestate.com/pypm/ -srid From briank at logan.tv Mon Nov 8 13:42:34 2010 From: briank at logan.tv (Brian Krusic) Date: Mon, 8 Nov 2010 10:42:34 -0800 (PST) Subject: python dpx module Message-ID: <1068407369.51831289241754297.JavaMail.root@zmail> Hi all, Kind of at a loss here. trying to debug some old code belonging to some one else and I keep seeing an error; import dpx no module named dpx Would any one happen to know how I can get a hold if this elusive dpx Python module? From cjdrake at gmail.com Mon Nov 8 14:37:10 2010 From: cjdrake at gmail.com (Drake) Date: Mon, 8 Nov 2010 11:37:10 -0800 (PST) Subject: Intel C Compiler Message-ID: <8e65ce2e-6afd-4fc0-b4c5-741e99b62120@b19g2000prj.googlegroups.com> Hello, I'm an engineer who has access to the Intel C/C++ compiler (icc), and for the heck of it I compiled Python2.7 with it. Unsurprisingly, it compiled fine and functions correctly as far as I know. However, I was interested to discover that the icc compile printed literally thousands of various warnings and remarks. Examples: Parser/node.c(13): remark #2259: non-pointer conversion from "int" to "short" may lose significant bits n->n_type = type; Parser/metagrammar.c(156): warning #1418: external function definition with no prior declaration Py_meta_grammar(void) I was just wondering if anyone from the Python development team uses icc, or finds any value in the icc compilation info. Similarly, I would be interested to know if they use icc for benchmarking comparisons (yes, I know that Intel has been accused of crippling amd processors so let's not have a flame war please). Regards, Drake From stefan-usenet at bytereef.org Mon Nov 8 15:00:43 2010 From: stefan-usenet at bytereef.org (Stefan Krah) Date: Mon, 8 Nov 2010 21:00:43 +0100 Subject: Intel C Compiler In-Reply-To: <8e65ce2e-6afd-4fc0-b4c5-741e99b62120@b19g2000prj.googlegroups.com> References: <8e65ce2e-6afd-4fc0-b4c5-741e99b62120@b19g2000prj.googlegroups.com> Message-ID: <20101108200043.GA21291@yoda.bytereef.org> Drake wrote: > I'm an engineer who has access to the Intel C/C++ compiler (icc), and > for the heck of it I compiled Python2.7 with it. > > Unsurprisingly, it compiled fine and functions correctly as far as I > know. However, I was interested to discover that the icc compile > printed literally thousands of various warnings and remarks. > > Examples: > Parser/node.c(13): remark #2259: non-pointer conversion from "int" to > "short" may lose significant bits > n->n_type = type; I sometimes use icc. This is one of the most annoying warnings of the Intel compiler. See: http://software.intel.com/en-us/forums/showthread.php?t=62308 The problem is that the compiler issues this warning even when there is no way that significant bits could be lost. Stefan Krah From robert.kern at gmail.com Mon Nov 8 16:10:33 2010 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 08 Nov 2010 15:10:33 -0600 Subject: python dpx module In-Reply-To: <1068407369.51831289241754297.JavaMail.root@zmail> References: <1068407369.51831289241754297.JavaMail.root@zmail> Message-ID: On 11/8/10 12:42 PM, Brian Krusic wrote: > Hi all, > > Kind of at a loss here. > > trying to debug some old code belonging to some one else and I keep seeing an error; > > import dpx > no module named dpx > > Would any one happen to know how I can get a hold if this elusive dpx Python module? You'll have to ask them. I've never heard of it. I assume you have already checked Google. It might not be a publicly available module. -- 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 ghw at accutrol.com Mon Nov 8 16:56:50 2010 From: ghw at accutrol.com (ghw at accutrol.com) Date: Mon, 8 Nov 2010 16:56:50 -0500 Subject: populating a doubly-subscripted array Message-ID: <20101108214605.M50754@accutrol.com> What am I missing? I am using Python 3.1.2. ff = [[0.0]*5]*5 ff #(lists 5x5 array of 0.0) for i in range(5): for j in range(3): ff[i][j] = i*10+j print (i,j,ff[i][j]) # correctly prints ff array values ff # try this and see what happens! result of first print of ff [[0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0]] result of second print of ff 0 0 0 0 1 1 0 2 2 1 0 10 1 1 11 1 2 12 2 0 20 2 1 21 2 2 22 3 0 30 3 1 31 3 2 32 4 0 40 4 1 41 4 2 42 result of third print of ff [[40, 41, 42, 0.0, 0.0], [40, 41, 42, 0.0, 0.0], [40, 41, 42, 0.0, 0.0], [40, 41, 42, 0.0, 0.0], [40, 41, 42, 0.0, 0.0]] Obviously there is something missing in my understanding of how array values are populated. Why do all "rows" get populated with the same set of values (40, 41, 42)? Thanks for your help, Hamilton Woods From hansmu at xs4all.nl Mon Nov 8 17:35:13 2010 From: hansmu at xs4all.nl (Hans Mulder) Date: Mon, 08 Nov 2010 23:35:13 +0100 Subject: Popen Question In-Reply-To: References: <891a9a80-c30d-4415-ac81-bddd0b564fa6@g13g2000yqj.googlegroups.com> <87hbfs9mm8.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <4cd87b24$0$81481$e4fe514c@news.xs4all.nl> Ian wrote: > On Nov 8, 2:43 am, m... at distorted.org.uk (Mark Wooding) wrote: >>> I don?t know what happens to the extra arguments, but they just seem >>> to be ignored if -c is specified. >> The argument to -c is taken as a shell script; the remaining arguments >> are made available as positional parameters to the script as usual (only >> starting with $0 rather than $1, for some unknown reason). > > Perhaps this example better demonstrates what is going on: > >>>> p = subprocess.Popen(['echo one $0 three $1 five', 'two', 'four'], > ... shell=True) > one two three four five Maybe I'm thick, but I still don't understand. If I run a shell script, then the name of the script is in $0 and the first positional arguments is in $1, similar to how Python sets up sys.argv. But in this case the first positional argument is in $0. Why is that? Puzzled, -- HansM From robert.kern at gmail.com Mon Nov 8 17:36:36 2010 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 08 Nov 2010 16:36:36 -0600 Subject: populating a doubly-subscripted array In-Reply-To: <20101108214605.M50754@accutrol.com> References: <20101108214605.M50754@accutrol.com> Message-ID: On 11/8/10 3:56 PM, ghw at accutrol.com wrote: > What am I missing? I am using Python 3.1.2. > > ff = [[0.0]*5]*5 http://docs.python.org/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 torriem at gmail.com Mon Nov 8 18:12:54 2010 From: torriem at gmail.com (Michael Torrie) Date: Mon, 08 Nov 2010 16:12:54 -0700 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> Message-ID: <4CD883F6.5050307@gmail.com> On 11/06/2010 02:27 AM, Seebs wrote: > On 2010-11-06, Steve Holden wrote: >> If someone were to use a text editor which had always historically >> mangled whitespace I would find myself wondering why they found it >> necessary to restrict themselves to such stone-age tools. > > I have yet to find an editor that allows me to, well, *edit*, more > comfortably than vi. Indeed vi (or in my case, vim) works wonderfully well with python. I always use the following vim settings on python files: set sw=4 set ts=8 set softtabstop=4 set expandtab set ai If you set up a conditional thing in your vimrc to enable these settings for python files, you shouldn't have any more tab problems. From ldo at geek-central.gen.new_zealand Mon Nov 8 18:24:36 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 09 Nov 2010 12:24:36 +1300 Subject: functions, list, default parameters References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <8ivelpFif1U1@mid.individual.net> <4cca88bc$0$29987$c3e8da3$5496439d@news.astraweb.com> <8j1seqFa1eU2@mid.individual.net> Message-ID: In message , Robert Kern wrote: > On 11/4/10 2:07 AM, Lawrence D'Oliveiro wrote: > >> In message, Robert >> Kern wrote: >> >>> On 11/2/10 2:12 AM, Lawrence D'Oliveiro wrote: >>> >>>> In message, Robert >>>> Kern wrote: >>>> >>>>> "Immutable objects" are just those without an obvious API for >>>>> modifying them. >>>> >>>> They are ones with NO legal language constructs for modifying them. >>>> Hint: if a selector of some part of such an object were to occur on the >>>> LHS of an assignment, and that would raise an error, then the object is >>>> immutable. The interpreter already knows all this. >>> >>> Incorrect. RHS method calls can often modify objects. >> >> So bloody what? > > So examining LHS "selectors" is not sufficient for determining > immutability. Yes it is. All your attempts at counterexamples showed is that it is not necessary, not that it is not sufficient. From ben+python at benfinney.id.au Mon Nov 8 18:27:50 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 09 Nov 2010 10:27:50 +1100 Subject: populating a doubly-subscripted array References: Message-ID: <874obre6q1.fsf@benfinney.id.au> ghw at accutrol.com writes: > What am I missing? You're missing the fact that Python doesn't have a built-in ?array? type, nor really ?subscripts? for them. > ff = [[0.0]*5]*5 This creates a float object, ?0.0?. It then creates a list containing five references to that same object. It then creates a new list containing five references to the first list. It then binds the name ?ff? to the outer list. ff --+ | V +---+---+---+---+---+ | . | . | . | . | . | +-|-+-|-+-|-+-|-+-|-+ | | | | | +---+---+---+---+---+ | V +---+---+---+---+---+ | . | . | . | . | . | +-|-+-|-+-|-+-|-+-|-+ | | | | | +---+---+---+---+---+ | V 0.0 > ff #(lists 5x5 array of 0.0) Nope. It outputs the structure described above, serialised. There is no distinction in that output between objects that are different but have the same value, versus the same object displayed several times. Try the ?is? (identity) and ?==? (equality) operators to see the difference. > for i in range(5): > for j in range(3): > ff[i][j] = i*10+j This binds different integer values at some of the references in the inner list. As the loops continue, the reference used to get at the inner list is different; but it's always the same list. > print (i,j,ff[i][j]) # correctly prints ff array values It prints the values in the inner list immediately after they're assigned. As the loops continue, the references are re-bound to other integer values. > ff # try this and see what happens! After all the changes, the only references which have actually been re-bound are the first three items in the inner list. ff --+ | V +---+---+---+---+---+ | . | . | . | . | . | +-|-+-|-+-|-+-|-+-|-+ | | | | | +---+---+---+---+---+ | V +---+---+---+---+---+ | . | . | . | . | . | +-|-+-|-+-|-+-|-+-|-+ | | | | | | | | +---+---+ | | | | V V V V 40 41 42 0.0 > result of third print of ff > [[40, 41, 42, 0.0, 0.0], [40, 41, 42, 0.0, 0.0], > [40, 41, 42, 0.0, 0.0], [40, 41, 42, 0.0, 0.0], > [40, 41, 42, 0.0, 0.0]] > > Obviously there is something missing in my understanding of how array > values are populated. Why do all "rows" get populated with the same > set of values (40, 41, 42)? Because, as the above diagram hopefully clarifies, a list isn't an array, and its references aren't rows. If you actually want an array, there isn't a built-in type for it. Instead, use the standard library ?array? module , or (for more powerful numeric processing) the types in the third-party NumPy library . -- \ ?When you go in for a job interview, I think a good thing to | `\ ask is if they ever press charges.? ?Jack Handey | _o__) | Ben Finney From mdw at distorted.org.uk Mon Nov 8 18:28:11 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Mon, 08 Nov 2010 23:28:11 +0000 Subject: populating a doubly-subscripted array References: Message-ID: <87aaljmm44.fsf.mdw@metalzone.distorted.org.uk> ghw at accutrol.com writes: > What am I missing? I am using Python 3.1.2. > > ff = [[0.0]*5]*5 > ff #(lists 5x5 array of 0.0) > for i in range(5): > for j in range(3): > ff[i][j] = i*10+j > print (i,j,ff[i][j]) # correctly prints ff array values > > ff # try this and see what happens! > > result of third print of ff > [[40, 41, 42, 0.0, 0.0], [40, 41, 42, 0.0, 0.0], > [40, 41, 42, 0.0, 0.0], [40, 41, 42, 0.0, 0.0], > [40, 41, 42, 0.0, 0.0]] > > Obviously there is something missing in my understanding of > how array values are populated. Why do all "rows" get > populated with the same set of values (40, 41, 42)? [I suppose that the trailing 0.0 entries aren't in question: they're because the individual rows have width 5 -- from `[0.0]*5' -- but only the first three items of each is initialzed -- because j iterates only over range(3).] So, why do they all come out the same? The answer is because in fact there are only two lists involved. You probably thought that you were building something like the thing on the left. In fact, you have the thing on the right. (Try to forgive the rubbish ASCII art.) .--. .--.--.--.--.--. .--. | ----->| | | | | | | --. |__| `--^--^--^--^--' |__| \ | | .--.--.--.--.--. | | \ | ----->| | | | | | | ---. \ |__| `--^--^--^--^--' |__| \v | | .--.--.--.--.--. | | \.--.--.--.--.--. | ----->| | | | | | | ----->| | | | | | |__| `--^--^--^--^--' |__| /`--^--^--^--^--' | | .--.--.--.--.--. | | / ^ | ----->| | | | | | | --' / |__| `--^--^--^--^--' |__| / | | .--.--.--.--.--. | | / | ----->| | | | | | | --' `--' `--^--^--^--^--' `--' What [x] * n does is make a list, whose length is n, and all of whose entries are precisely the value x. If x itself is a list, then you get an outer list all of whose entries are the /same/ inner list -- not copies of it. So when you appear to change entries in one of the inner lists, all the other inner lists seem to change too -- because they're actually the same list. -- [mdw] From ldo at geek-central.gen.new_zealand Mon Nov 8 18:29:13 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 09 Nov 2010 12:29:13 +1300 Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> <87aalrjkty.fsf@benfinney.id.au> <8jd3m9Fr55U7@mid.individual.net> <87fwvdb69k.fsf.mdw@metalzone.distorted.org.uk> Message-ID: In message <87fwvdb69k.fsf.mdw at metalzone.distorted.org.uk>, Mark Wooding wrote: > Lawrence D'Oliveiro writes: > >> for \ >> Description, Attr, ColorList \ >> in \ >> ( >> ("normal", "image", MainWindow.ColorsNormalList), >> ("highlighted", "highlight",MainWindow.ColorsHighlightedList), >> ("selected", "select", MainWindow.ColorsSelectedList), >> ) \ >> : >> ... >> #end for >> >> Does this make more sense now? > > Ugh, no! > > for descr, attr, colours in [ > ('normal', 'image', 'Normal'), > ('highlighted', 'highlight', 'Highlighted'), > ('selected', 'select', 'Selected')]: > colourlist = getattr(MainWindow, 'Colors%sList' % colours) > ## ... But then you lose the ability to match up the bracketing symbols. That?s why I put them on lines by themselves. > To be honest, there's so much regularity in that table that I'd consider > generating it from a shorter list. This would obviously involve > refactoring something else to eliminate the image/normal asymmetry. I'd > also consider making the ColorsMumbleList attribute collection into a > dictionary. Maybe you should look at the code in context , then you can express some more opinions on how to improve it. From ldo at geek-central.gen.new_zealand Mon Nov 8 18:32:30 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 09 Nov 2010 12:32:30 +1300 Subject: Popen Question References: <891a9a80-c30d-4415-ac81-bddd0b564fa6@g13g2000yqj.googlegroups.com> <87hbfs9mm8.fsf.mdw@metalzone.distorted.org.uk> <4cd87b24$0$81481$e4fe514c@news.xs4all.nl> Message-ID: In message <4cd87b24$0$81481$e4fe514c at news.xs4all.nl>, Hans Mulder wrote: > But in this case the first positional argument is in $0. That?s what confused me. From usenet-nospam at seebs.net Mon Nov 8 18:32:58 2010 From: usenet-nospam at seebs.net (Seebs) Date: 08 Nov 2010 23:32:58 GMT Subject: Pythonic/idiomatic? Message-ID: I have an existing hunk of Makefile code: CPPFLAGS = "$(filter -D* -I* -i* -U*,$(TARGET_CFLAGS))" For those not familiar with GNU makeisms, this means "assemble a string which consists of all the words in $(TARGET_CFLAGS) which start with one of -D, -I, -i, or -U". So if you give it foo -Ibar baz it'll say -Ibar I have a similar situation in a Python context, and I am wondering whether this is an idiomatic spelling: ' '.join([x for x in target_cflags.split() if re.match('^-[DIiU]', x)]) This appears to do the same thing, but is it an idiomatic use of list comprehensions, or should I be breaking it out into more bits? You will note that of course, I have carefully made it a one-liner so I don't have to worry about indentation*. -s [*] Kidding, I just thought this seemed like a pretty clear expression. -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From ldo at geek-central.gen.new_zealand Mon Nov 8 18:35:20 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 09 Nov 2010 12:35:20 +1300 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jftftFelnU1@mid.individual.net> <87oca1b8ba.fsf.mdw@metalzone.distorted.org.uk> Message-ID: In message <87oca1b8ba.fsf.mdw at metalzone.distorted.org.uk>, Mark Wooding wrote: > Vertical space is a limiting factor on how much code one can see at a > time. One thing that helps me is that Emacs has commands for quickly jumping between matching brackets. Of course, this only works for languages that have brackets. From ldo at geek-central.gen.new_zealand Mon Nov 8 18:36:29 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 09 Nov 2010 12:36:29 +1300 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jftftFelnU1@mid.individual.net> <87oca1b8ba.fsf.mdw@metalzone.distorted.org.uk> Message-ID: In message , Grant Edwards wrote: > IOW, editing a loop or other control structure where you couldn't see both > ends was problematic. Conserving vertical space avoids that problem. No it doesn?t. It just moves it to a different, arbitrary, point a few percent away?not enough to be worth bothering about. From ldo at geek-central.gen.new_zealand Mon Nov 8 18:39:37 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 09 Nov 2010 12:39:37 +1300 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jftftFelnU1@mid.individual.net> <87oca1b8ba.fsf.mdw@metalzone.distorted.org.uk> Message-ID: In message , Grant Edwards wrote: > ... though I'd still prefer a 4:3. 4:3 still seems to be the best. It gives you a landscape A3-proportional view (or two A4-proportioned portrait pages side by side), and the little bit of space left over at the top or bottom can be used for toolbars, titlebars, that sort of thing. From brf256 at gmail.com Mon Nov 8 18:50:05 2010 From: brf256 at gmail.com (brf256 at gmail.com) Date: Mon, 8 Nov 2010 23:50:05 +0000 Subject: Best exercises for beginers to learn? Message-ID: <430901620-1289260207-cardhu_decombobulator_blackberry.rim.net-713929454-@bda480.bisx.prod.on.blackberry> Hello, I was wondering if there are any good exercises that you would recommend learning? I've already done a menu exercise. Thanks! - Braden Faulkner From robert.kern at gmail.com Mon Nov 8 18:53:56 2010 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 08 Nov 2010 17:53:56 -0600 Subject: functions, list, default parameters In-Reply-To: References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <8ivelpFif1U1@mid.individual.net> <4cca88bc$0$29987$c3e8da3$5496439d@news.astraweb.com> <8j1seqFa1eU2@mid.individual.net> Message-ID: On 11/8/10 5:24 PM, Lawrence D'Oliveiro wrote: > In message, Robert Kern > wrote: > >> On 11/4/10 2:07 AM, Lawrence D'Oliveiro wrote: >> >>> In message, Robert >>> Kern wrote: >>> >>>> On 11/2/10 2:12 AM, Lawrence D'Oliveiro wrote: >>>> >>>>> In message, Robert >>>>> Kern wrote: >>>>> >>>>>> "Immutable objects" are just those without an obvious API for >>>>>> modifying them. >>>>> >>>>> They are ones with NO legal language constructs for modifying them. >>>>> Hint: if a selector of some part of such an object were to occur on the >>>>> LHS of an assignment, and that would raise an error, then the object is >>>>> immutable. The interpreter already knows all this. >>>> >>>> Incorrect. RHS method calls can often modify objects. >>> >>> So bloody what? >> >> So examining LHS "selectors" is not sufficient for determining >> immutability. > > Yes it is. All your attempts at counterexamples showed is that it is not > necessary, not that it is not sufficient. file objects. hashlib hash objects. weakref.ref objects. Again, I ask you to point out a piece of code in the interpreter that makes this determination. You have repeatedly claimed that they exist, but you have not produced a single example. -- 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 kevin.p.dwyer at gmail.com Mon Nov 8 19:01:08 2010 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Tue, 9 Nov 2010 00:01:08 +0000 (UTC) Subject: python test frameworks References: <009da031-22f2-4719-b030-b1db76e953af@r4g2000prj.googlegroups.com> Message-ID: On Sun, 07 Nov 2010 09:01:42 -0800, rustom wrote: > On Nov 7, 7:09?pm, Kev Dwyer wrote: >> On Sun, 07 Nov 2010 10:56:46 +0530, Rustom Mody wrote: >> > There are a large number of test frameworks in/for python. ?Apart >> > from what comes builtin with python there seems to be nose, staf, >> > qmtest etc etc. >> >> > Is there any central place where these are listed with short >> > descriptions? 'Test framework' means widely different things in >> > different contexts. Any explanations/tutorials around? >> >> > [Disclaimer: I was educated a couple of decades before the TDD rage] >> >> Hello, >> >> You could start >> withhttp://pycheesecake.org/wiki/PythonTestingToolsTaxonomy >> >> Kev > > Thanks -- that looks like a comprehensive resource. But it does not > have staf > http://staf.sourceforge.net/current/STAFPython.htm. Is that merely an > item missing or a category? I'm afraid I couldn't say with any certainty - I'd throw that question at the python testing newsgroup, to whom I am cross-posting in the hope that they can help. Kev From debatem1 at gmail.com Mon Nov 8 19:11:47 2010 From: debatem1 at gmail.com (geremy condra) Date: Mon, 8 Nov 2010 19:11:47 -0500 Subject: Pythonic/idiomatic? In-Reply-To: References: Message-ID: On Mon, Nov 8, 2010 at 6:32 PM, Seebs wrote: > I have an existing hunk of Makefile code: > ? ? ? ?CPPFLAGS = "$(filter -D* -I* -i* -U*,$(TARGET_CFLAGS))" > For those not familiar with GNU makeisms, this means "assemble a string > which consists of all the words in $(TARGET_CFLAGS) which start with one > of -D, -I, -i, or -U". ?So if you give it > ? ? ? ?foo -Ibar baz > it'll say > ? ? ? ?-Ibar > > I have a similar situation in a Python context, and I am wondering > whether this is an idiomatic spelling: > > ? ? ? ?' '.join([x for x in target_cflags.split() if re.match('^-[DIiU]', x)]) > > This appears to do the same thing, but is it an idiomatic use of list > comprehensions, or should I be breaking it out into more bits? > > You will note that of course, I have carefully made it a one-liner so I > don't have to worry about indentation*. > > -s > [*] Kidding, I just thought this seemed like a pretty clear expression. I believe this is correct, but I may be wrong. Try and see. CPPFLAGS = ' '.join(filter(lambda x: x.startswith(('-D', '-I', '-i', '-U')), cflags)) Geremy Condra From jbiquez at icsmx.com Mon Nov 8 19:18:17 2010 From: jbiquez at icsmx.com (Jorge Biquez) Date: Mon, 08 Nov 2010 18:18:17 -0600 Subject: Commercial or Famous Applicattions.? Message-ID: <201011090026.oA90QP1S095565@krusty.intranet.com.mx> Hello all. Newbie question. Sorry. Can you mention applications/systems/solutions made with Python that are well known and used by public in general? ANd that maybe we do not know they are done with Python? I had a talk with a friend, "PHP-Only-Fan", and he said (you know the schema of those talks) that "his" language is better and that "just to prove it" there are not too many applications done with Python than the ones done with PHP and that "that of course is for something". That conversation , that by the way I guess is useless at all , makes me thing the idea of ask of applications done with Python. Not for debate the argument of that guy BUT to learn what can be done with Python. In grphical interface, schemas of jobs, etc. I know that there are tons of solutions but would like to hear of possible about the ones you have used most or recommend the most. As an example, I love and have used in the last years MAILMAN, never crashed, always works even on my small and old Intel Pentium III with a 10GB hard disk and 640KB of RAM. Still working and will work for sure (running under FreeBsd by the way). Thanks in advance for your comments. Jorge Biquez From ben+python at benfinney.id.au Mon Nov 8 19:26:53 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 09 Nov 2010 11:26:53 +1100 Subject: Pythonic/idiomatic? References: Message-ID: <87y693cpf6.fsf@benfinney.id.au> Seebs writes: > I have a similar situation in a Python context, and I am wondering > whether this is an idiomatic spelling: > > ' '.join([x for x in target_cflags.split() if re.match('^-[DIiU]', x)]) > > This appears to do the same thing, but is it an idiomatic use of list > comprehensions, or should I be breaking it out into more bits? One thing to know is that, if you want to create a sequence whose only purpose is to feed to something else and then throw away, a generator will be cleaner and (probably) better performing than a list. For this purpose, there is a generator expression syntax , almost identical to a list comprehension except without the enclosing brackets. ' '.join(x for x in target_cflags.split() if re.match('^-[DIiU]', x)) The regex is less clear for the purpose than I'd prefer. For a simple ?is it a member of this small set?, I'd find it more readable to use a simple list of the actual strings:: ' '.join( x for x in target_cflags.split() if x in ['-D', '-I', '-i', '-U']) or even an actual set:: ' '.join( x for x in target_cflags.split() if x in {'-D', '-I', '-i', '-U'}) The latter works only in Python with set literals (Python 2.7 or later). -- \ ?I find the whole business of religion profoundly interesting. | `\ But it does mystify me that otherwise intelligent people take | _o__) it seriously.? ?Douglas Adams | Ben Finney From usenet-nospam at seebs.net Mon Nov 8 19:31:08 2010 From: usenet-nospam at seebs.net (Seebs) Date: 09 Nov 2010 00:31:08 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> Message-ID: On 2010-11-08, Michael Torrie wrote: > On 11/06/2010 02:27 AM, Seebs wrote: >> I have yet to find an editor that allows me to, well, *edit*, more >> comfortably than vi. > Indeed vi (or in my case, vim) works wonderfully well with python. I > always use the following vim settings on python files: Ahh, but I use nvi, not vim. > If you set up a conditional thing in your vimrc to enable these settings > for python files, you shouldn't have any more tab problems. And I don't think I can do that in nvi -- I don't think it has conditionals. Although. You've just caused me to remember something which is in context both amusing and funny. Which is that I believe nvi has support for some embedded scripting functionality, at least as an optional build choice. Which I've never used, on the grounds that I don't know Python... So that may actually be possible. I'll look into it, for sure. Thanks for nudging my memory. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Mon Nov 8 19:31:51 2010 From: usenet-nospam at seebs.net (Seebs) Date: 09 Nov 2010 00:31:51 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jftftFelnU1@mid.individual.net> <87oca1b8ba.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On 2010-11-08, Lawrence D'Oliveiro wrote: > In message <87oca1b8ba.fsf.mdw at metalzone.distorted.org.uk>, Mark Wooding > wrote: >> Vertical space is a limiting factor on how much code one can see at a >> time. > One thing that helps me is that Emacs has commands for quickly jumping > between matching brackets. > Of course, this only works for languages that have brackets. Yes. One of the things I find frustrating about the Ruby idiom of preferring do/end for multiline blocks is that you can't fence-match them. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From wuwei23 at gmail.com Mon Nov 8 19:32:12 2010 From: wuwei23 at gmail.com (alex23) Date: Mon, 8 Nov 2010 16:32:12 -0800 (PST) Subject: Commercial or Famous Applicattions.? References: Message-ID: Jorge Biquez wrote: > Can you mention applications/systems/solutions made with Python that > are well known and used by public in general? ANd that maybe we do > not know they are done with Python? http://python.org/about/success/ This comes up semi-regularly so you might be able to find more examples in past threads. From rantingrick at gmail.com Mon Nov 8 19:33:54 2010 From: rantingrick at gmail.com (rantingrick) Date: Mon, 8 Nov 2010 16:33:54 -0800 (PST) Subject: Commercial or Famous Applicattions.? References: Message-ID: Commenting on which language is better than "this one" or which language boasts the most achievements is nothing more than time very poorly spent. Some people will find Python to be the best thing since sliced bread (and i am one of them!), however others will find Python to be the worst language they ever used (thankfully very few!). These are nothing more than personal opinions and you must leave them at that level. Because as they say... "Opinions are like sphincters -- everybody has at least one" ... or something like that i suppose :) From usenet-nospam at seebs.net Mon Nov 8 19:34:21 2010 From: usenet-nospam at seebs.net (Seebs) Date: 09 Nov 2010 00:34:21 GMT Subject: Pythonic/idiomatic? References: <87y693cpf6.fsf@benfinney.id.au> Message-ID: On 2010-11-09, Ben Finney wrote: > For this purpose, there is a generator expression syntax >, > almost identical to a list comprehension except without the enclosing > brackets. > > ' '.join(x for x in target_cflags.split() if re.match('^-[DIiU]', x)) Ahh, handy. I am torn very much on the generator/comprehension syntax, because on the one hand, I really prefer to have the structure first, but on the other hand, I can't easily figure out a way to make the syntax work for that. > The regex is less clear for the purpose than I'd prefer. For a simple > ???is it a member of this small set???, I'd find it more readable to use a > simple list of the actual strings:: > ' '.join( > x for x in target_cflags.split() > if x in ['-D', '-I', '-i', '-U']) The regex is intentionally not anchored with a $, because I'm looking for "starts with", not "is". > The latter works only in Python with set literals (Python 2.7 or later). I think we're stuck with backwards compatibility at least as far as 2.4. No, I'm not kidding. *sigh* -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Mon Nov 8 19:43:24 2010 From: usenet-nospam at seebs.net (Seebs) Date: 09 Nov 2010 00:43:24 GMT Subject: Commercial or Famous Applicattions.? References: Message-ID: On 2010-11-09, rantingrick wrote: > Commenting on which language is better than "this one" or which > language boasts the most achievements is nothing more than time very > poorly spent. This is mostly true, but I don't think it's entirely true. It is certainly possible for someone else's language choices to affect me (if I get called in to fix their code). And as a result, I do try to do at least a little language advocacy. Specifically, I try to steer people away from PHP. I can live with just about everything else. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From brf256 at gmail.com Mon Nov 8 19:47:08 2010 From: brf256 at gmail.com (brf256 at gmail.com) Date: Tue, 9 Nov 2010 00:47:08 +0000 Subject: Commercial or Famous Applicattions.? Message-ID: <1143731221-1289263630-cardhu_decombobulator_blackberry.rim.net-1731425422-@bda480.bisx.prod.on.blackberry> Mailman is of course. As well as redhats anaconda installer and google uses python internally for many of there "medium sized" projects. Also, calibre, gwibber, portage pms, ubuntu software center, YUM pms and many others including YouTube. Moral is many big companies do both for products and internally. Cheers, - Braden Faulkner From ian.g.kelly at gmail.com Mon Nov 8 19:49:44 2010 From: ian.g.kelly at gmail.com (Ian) Date: Mon, 8 Nov 2010 16:49:44 -0800 (PST) Subject: Popen Question References: <891a9a80-c30d-4415-ac81-bddd0b564fa6@g13g2000yqj.googlegroups.com> <87hbfs9mm8.fsf.mdw@metalzone.distorted.org.uk> <4cd87b24$0$81481$e4fe514c@news.xs4all.nl> Message-ID: On Nov 8, 3:35?pm, Hans Mulder wrote: > > Perhaps this example better demonstrates what is going on: > > >>>> p = subprocess.Popen(['echo one $0 three $1 five', 'two', 'four'], > > ... ? ? ? ? ? ? ? ? ? ? ?shell=True) > > one two three four five > > Maybe I'm thick, but I still don't understand. ?If I run a shell script, > then the name of the script is in $0 and the first positional arguments > is in $1, similar to how Python sets up sys.argv. > > But in this case the first positional argument is in $0. ?Why is that? It's just a quirk in the way the shell handles the -c option. The syntax for the shell invocation boils down to something like this: sh [-c command_string] command_name arg1 arg2 arg3 ... Without the -c option, sh runs the file indicated by command_name, setting $0 to command_name, $1 to arg1, $2 to arg2, etc. With the -c option, it does the same thing; it just runs the command_string instead of a file pointed to by command_name. The latter still conceptually exists as an argument, however, which is why it still gets stored in $0 instead of $1. We could argue about whether this approach is correct or not, but it's what the shell does, and that's not likely to change. Cheers, Ian From nagle at animats.com Mon Nov 8 19:59:05 2010 From: nagle at animats.com (John Nagle) Date: Mon, 08 Nov 2010 16:59:05 -0800 Subject: Commercial or Famous Applicattions.? In-Reply-To: References: Message-ID: <4cd89cdc$0$1588$742ec2ed@news.sonic.net> On 11/8/2010 4:47 PM, brf256 at gmail.com wrote: > Mailman is of course. As well as redhats anaconda installer and > google uses python internally for many of there "medium sized" > projects. Also, calibre, gwibber, portage pms, ubuntu software > center, YUM pms and many others including YouTube. Moral is many big > companies do both for products and internally. > > Cheers, - Braden Faulkner YouTube was rewritten a few years ago, as it was scaled up. Not sure what it's written in now. John Nagle From ben+python at benfinney.id.au Mon Nov 8 20:12:44 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 09 Nov 2010 12:12:44 +1100 Subject: Pythonic/idiomatic? References: <87y693cpf6.fsf@benfinney.id.au> Message-ID: <87lj53cnar.fsf@benfinney.id.au> Seebs writes: > On 2010-11-09, Ben Finney wrote: > > The regex is less clear for the purpose than I'd prefer. For a > > simple ???is it a member of this small set???, I'd find it more > > readable to use a simple list of the actual strings:: > > > ' '.join( > > x for x in target_cflags.split() > > if x in ['-D', '-I', '-i', '-U']) > > The regex is intentionally not anchored with a $, because I'm looking > for "starts with", not "is". Ah, okay. Strings have a built-in ?startswith? method, but it may be less convenient for the current case compared to a regex. Here's an attempt:: ' '.join( x for x in target_cflags.split() if any( x.startswith(opt_name) for opt_name in ['-D', '-I', '-i', '-U'])) I still find that more readable than the version using a regex, but it's pushing the boundaries of verbosity. Better would be to use the fact that ?str.startswith? can do the same as above with a tuple of prefix strings:: ' '.join( x for x in target_cflags.split() if x.startswith(('-D', '-I', '-i', '-U'))) > I think we're stuck with backwards compatibility at least as far as > 2.4. Then you don't yet have the ?any? and ?all? built-in functions, or the tuple-of-prefixes feature of ?str.startswith? either. Bummer. At which point, the Pythonic thing to do is to convince your organisation to use a version of Python that's at least officially supported by the PSF :-) -- \ ?Teach a man to make fire, and he will be warm for a day. Set a | `\ man on fire, and he will be warm for the rest of his life.? | _o__) ?John A. Hrastar | Ben Finney From alan.gauld at btinternet.com Mon Nov 8 20:30:21 2010 From: alan.gauld at btinternet.com (Alan Gauld) Date: Tue, 9 Nov 2010 01:30:21 -0000 Subject: Commercial or Famous Applicattions.? References: <201011090026.oA90QP1S095565@krusty.intranet.com.mx> Message-ID: "Jorge Biquez" wrote > Can you mention applications/systems/solutions made with Python that > are well known and used by public in general? ANd that maybe we do > not know they are done with Python? The Python web site has an advocacy section, you will find several success stories there. HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ From rantingrick at gmail.com Mon Nov 8 20:40:22 2010 From: rantingrick at gmail.com (rantingrick) Date: Mon, 8 Nov 2010 17:40:22 -0800 (PST) Subject: Commercial or Famous Applicattions.? References: Message-ID: On Nov 8, 6:43?pm, Seebs wrote: > On 2010-11-09, rantingrick wrote: > It is certainly possible for someone else's language choices to > affect me (if I get called in to fix their code). ?And as a result, I do > try to do at least a little language advocacy. ?Specifically, I try to > steer people away from PHP. ?I can live with just about everything else. True and i agree with your statements however i was alluding more to the fact that there exist no true winner in the battle of languages. Just as there exists no winners in the battle of composers. You can say "Hey this of group of talented fellows really shines above the rest". However you can NEVER say that "This specific fellow shines above the group of talented fellows". Can you compare the expansive depth and melodic genius of Chopin to the explosive (almost vengeful!) energy of Ludwig van Beethoven? How how about Rachmaninoff to Liszt? But yea i must agree... PHP... :-P" From python.list at tim.thechases.com Mon Nov 8 20:40:32 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 08 Nov 2010 19:40:32 -0600 Subject: Pythonic/idiomatic? In-Reply-To: References: <87y693cpf6.fsf@benfinney.id.au> Message-ID: <4CD8A690.9040103@tim.thechases.com> On 11/08/10 18:34, Seebs wrote: > On 2010-11-09, Ben Finney wrote: >> ' '.join(x for x in target_cflags.split() if re.match('^-[DIiU]', x)) > > Ahh, handy. ... >> The latter works only in Python with set literals (Python >> 2.7 or later). > > I think we're stuck with backwards compatibility at least as > far as 2.4. > > No, I'm not kidding. *sigh* I feel your pain :) At least be glad you don't have to go back to 2.3 where Ben's suggested generator-syntax isn't available. >> The regex is less clear for the purpose than I'd prefer. For a simple >> ???is it a member of this small set???, I'd find it more readable to use a >> simple list of the actual strings:: > >> ' '.join( >> x for x in target_cflags.split() >> if x in ['-D', '-I', '-i', '-U']) > > The regex is intentionally not anchored with a $, because I'm looking > for "starts with", not "is". I suppose you could do ' '.join( x for x in target_cflags.split() if x[:2] in ['-D', '-I', '-i', '-U'] ) or ' '.join( x for x in target_cflags.split() if x.startswith(('-D', '-I', '-i', '-U')) ) or even ' '.join( x for x in target_cflags.split() if x[:1] == '-' and x[1:2] in 'DIiU' ) -tkc From rabidpoobear at gmail.com Mon Nov 8 20:46:36 2010 From: rabidpoobear at gmail.com (Luke Paireepinart) Date: Mon, 8 Nov 2010 19:46:36 -0600 Subject: [Tutor] Commercial or Famous Applicattions.? In-Reply-To: <201011090026.oA90QP1S095565@krusty.intranet.com.mx> References: <201011090026.oA90QP1S095565@krusty.intranet.com.mx> Message-ID: just off the top of my head... NASA uses it. Lots of games use Python as their game logic/scripting language (how many use PHP? probably approaching 0. LUA is more popular than Python but Python is much more popular than PHP). The first ever bittorrent client (the official one) was written in Python. The game Eve Online is written completely in Python. Youtube uses lots of Python, Facebook uses some. Reddit is written in Python as well. Google App Engine has both Python and Java interfaces. They don't have a PHP interface; I wonder why? Lots of jobs at Google (even Java jobs and such) require Python experience; they don't tend to require PHP experience too. Because PHP doesn't really teach you much. The syntax is not nearly as elegant. It's buggy and rough around the edges. They have gross workarounds for a lot of things that should be language features. That's not to say that Python's the only language that is better than PHP for most things. Ruby is also a good option. But these languages are both infinitely more flexible _right now_ (not based almost solely for web apps) and better to use for almost everything than PHP. PHP has its place, and part of the reason it still has that place is because a lot of web hosts haven't started hosting Python and Ruby frameworks in a scalable, fast way. But it's not the frameworks' fault. That's just my 2c. On Mon, Nov 8, 2010 at 6:18 PM, Jorge Biquez wrote: > Hello all. > > Newbie question. Sorry. > > Can you mention applications/systems/solutions made with Python that are > well known and used by public in general? ANd that maybe we do not know they > are done with Python? > > I had a talk with a friend, "PHP-Only-Fan", and he said (you know the schema > of those talks) that "his" language is better and that "just to prove it" > there are not too many applications done with Python than the ones done with > PHP and that "that of course is for something". That conversation , that by > the way I guess is useless at all , makes me thing the idea of ask of > applications done with Python. Not for debate the argument of that guy BUT > to learn what can be done with Python. In grphical interface, schemas of > jobs, etc. I know that there are tons of solutions but would like to hear of > possible about the ones you have used most or recommend the most. > > As an example, I love and have used in the last years MAILMAN, never > crashed, always works even on my small and old Intel Pentium III with a 10GB > hard disk and 640KB of RAM. Still working and will work for sure (running > under FreeBsd by the way). > > Thanks in advance for your comments. > > Jorge Biquez > > _______________________________________________ > Tutor maillist ?- ?Tutor at python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > From jason.heeris at gmail.com Mon Nov 8 21:09:39 2010 From: jason.heeris at gmail.com (Jason) Date: Mon, 8 Nov 2010 18:09:39 -0800 (PST) Subject: Define macro when invoking setup.py Message-ID: <43ca24d3-72ac-470a-ab20-798770e7e6d1@29g2000prb.googlegroups.com> I'd like to be able switch between building my C extension with a certain preprocessor macro defined or not defined. I'm using the rudimentary distutils setup.py example given here: http://docs.python.org/extending/building.html Is there a command line option that distutils.core.setup() will interpret for me, like the "-D" option for gcc? Or do I need to do something more complicated? (I had a brief look at the distutils.command.build_* docs... but they're pretty sparse.) From ldo at geek-central.gen.new_zealand Mon Nov 8 21:10:24 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 09 Nov 2010 15:10:24 +1300 Subject: http error 301 for urlopen References: <4cd7987e$0$1674$742ec2ed@news.sonic.net> Message-ID: In message <4cd7987e$0$1674$742ec2ed at news.sonic.net>, John Nagle wrote: > It's the New York Times' paywall. They're trying to set a cookie, > and will redirect the URL until you store and return the cookie. And if they find out you?re acessing them from a script, they?ll probably try to find a way to block that as well. From usenet-nospam at seebs.net Mon Nov 8 21:13:11 2010 From: usenet-nospam at seebs.net (Seebs) Date: 09 Nov 2010 02:13:11 GMT Subject: Pythonic/idiomatic? References: <87y693cpf6.fsf@benfinney.id.au> <87lj53cnar.fsf@benfinney.id.au> Message-ID: On 2010-11-09, Ben Finney wrote: > Seebs writes: >> I think we're stuck with backwards compatibility at least as far as >> 2.4. > Then you don't yet have the ???any??? and ???all??? built-in functions, or the > tuple-of-prefixes feature of ???str.startswith??? either. Bummer. Eww. > At which point, the Pythonic thing to do is to convince your > organisation to use a version of Python that's at least officially > supported by the PSF :-) Unfortunately, we're selling something to people who will explode if we tell them to upgrade their RHEL4 systems, so we have to work on those. (There is some tiny hope that we'll be able to move the baseline to RHEL5 within another two years.) If it were only a matter of internal use, my job would be orders of magnitude easier. (I'm maintaining something that intercepts and wraps large hunks of the standard C library; if you think dealing with Python 2.4 is a burden, you ain't seen *nothing* compared to that.) -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From ldo at geek-central.gen.new_zealand Mon Nov 8 21:15:58 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 09 Nov 2010 15:15:58 +1300 Subject: Silly newbie question - Carrot character (^) References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> Message-ID: In message , Dennis Lee Bieber wrote: > On Sat, 6 Nov 2010 10:22:47 -0400, Philip Semanchuk > declaimed the following in > gmane.comp.python.general: > >> Some people might think the language ref> is a fine place to direct >> newcomers to Python. I don't. It's not awful, but it's dense and >> unfriendly for those just starting out. >> > Have you ever looked at the reference manual for Ada? Or even worse, the annotated reference. I thought annotations were supposed to clarify things; in this case they seemed to have the opposite effect... From ldo at geek-central.gen.new_zealand Mon Nov 8 21:18:31 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 09 Nov 2010 15:18:31 +1300 Subject: subclassing str References: <5dLBo.1024$w8.406@twister2.libero.it> Message-ID: In message <5dLBo.1024$w8.406 at twister2.libero.it>, not1xor1 (Alessandro) wrote: > I'm already using plain functions, but thought that wrapping most of > them in a str subclass would let me save some time and yield cleaner > and more manageable code How exactly does a.f(b, c) save time over f(a, b, c) ? From usenet-nospam at seebs.net Mon Nov 8 21:29:57 2010 From: usenet-nospam at seebs.net (Seebs) Date: 09 Nov 2010 02:29:57 GMT Subject: Silly newbie question - Carrot character (^) References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> Message-ID: On 2010-11-09, Lawrence D'Oliveiro wrote: > In message , Dennis Lee > Bieber wrote: >> Have you ever looked at the reference manual for Ada? > Or even worse, the annotated reference. I thought annotations were supposed > to clarify things; in this case they seemed to have the opposite effect... Clearly, you've never seen Schildt's infamous "Annotated ANSI C Standard". -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From lists at cheimes.de Mon Nov 8 21:48:10 2010 From: lists at cheimes.de (Christian Heimes) Date: Tue, 09 Nov 2010 03:48:10 +0100 Subject: Define macro when invoking setup.py In-Reply-To: <43ca24d3-72ac-470a-ab20-798770e7e6d1@29g2000prb.googlegroups.com> References: <43ca24d3-72ac-470a-ab20-798770e7e6d1@29g2000prb.googlegroups.com> Message-ID: Am 09.11.2010 03:09, schrieb Jason: > I'd like to be able switch between building my C extension with a > certain preprocessor macro defined or not defined. I'm using the > rudimentary distutils setup.py example given here: > > http://docs.python.org/extending/building.html > > Is there a command line option that distutils.core.setup() will > interpret for me, like the "-D" option for gcc? Or do I need to do > something more complicated? (I had a brief look at the > distutils.command.build_* docs... but they're pretty sparse.) You were looking at the wrong manual. Read http://docs.python.org/distutils/setupscript.html#preprocessor-options Extension(..., define_macros=[('NDEBUG', '1'), ('HAVE_STRFTIME', None)], undef_macros=['HAVE_FOO', 'HAVE_BAR']) Note that define_macros requires a list of tuples each having two members. Christian From rantingrick at gmail.com Mon Nov 8 21:55:04 2010 From: rantingrick at gmail.com (rantingrick) Date: Mon, 8 Nov 2010 18:55:04 -0800 (PST) Subject: subclassing str References: <5dLBo.1024$w8.406@twister2.libero.it> Message-ID: <6048c71a-fba9-4244-9a36-a5d19c8a5516@y23g2000yqd.googlegroups.com> On Nov 8, 8:18?pm, Lawrence D'Oliveiro wrote: > In message <5dLBo.1024$w8.... at twister2.libero.it>, not1xor1 (Alessandro) > wrote: > > > I'm already using plain functions, but thought that wrapping most of > > them in a str subclass would let me save some time and yield cleaner > > and more manageable code > > How exactly does > > ? ?a.f(b, c) > > save time over > > ? ? f(a, b, c) > > ? I think if you'll re-read the OP's statements (specifically the ones you quoted!) then you will see it's not an issue of time, its an issue of form and structure. Its an issue of paradigm. The OP wishes to keep his code as true to OOP as possible and what is wrong with that? Nothing in my book! One thing i love about Python is the fact that it can please almost all the "religious paradigm zealots" with it's multiple choice approach to programming. However some of the features that OOP fundamentalists hold dear in their heart are not always achievable in a clean manner with Python. Yes you could use a function but that is not the OOP way. Yes you could use UserString but that also seems too excessive. Ruby allows redefining everything. However this can open a REAL can of worms in group environment greater than one! From jason.heeris at gmail.com Mon Nov 8 21:56:06 2010 From: jason.heeris at gmail.com (Jason) Date: Mon, 8 Nov 2010 18:56:06 -0800 (PST) Subject: Define macro when invoking setup.py References: <43ca24d3-72ac-470a-ab20-798770e7e6d1@29g2000prb.googlegroups.com> Message-ID: On Nov 9, 10:48?am, Christian Heimes wrote: > You were looking at the wrong manual. Readhttp://docs.python.org/distutils/setupscript.html#preprocessor-options > > Extension(..., > ? ? ? ? ? define_macros=[('NDEBUG', '1'), > ? ? ? ? ? ? ? ? ? ? ? ? ?('HAVE_STRFTIME', None)], > ? ? ? ? ? undef_macros=['HAVE_FOO', 'HAVE_BAR']) > > Note that define_macros requires a list of tuples each having two members. But can they be selected or set from the command line, so I can do, say, "setup.py build -DDEBUG=1"? ? Jason From jason.heeris at gmail.com Mon Nov 8 22:04:13 2010 From: jason.heeris at gmail.com (Jason) Date: Mon, 8 Nov 2010 19:04:13 -0800 (PST) Subject: Define macro when invoking setup.py References: <43ca24d3-72ac-470a-ab20-798770e7e6d1@29g2000prb.googlegroups.com> Message-ID: <70efe9e9-96c6-4e3e-863e-f28575a008fe@u25g2000pra.googlegroups.com> On Nov 9, 10:56?am, Jason wrote: > But can they be selected or set from the command line, so I can do, > say, "setup.py build -DDEBUG=1"? Just answered my own question: there's an option for "build_ext" (NOT "build") that allows this. Thanks, Jason From azeynel1 at gmail.com Mon Nov 8 22:17:27 2010 From: azeynel1 at gmail.com (Zeynel) Date: Mon, 8 Nov 2010 19:17:27 -0800 (PST) Subject: Is there a way to pring a list object in Python? References: <88413b8d-e4dc-4eba-a19c-e9911e7eeb82@30g2000yql.googlegroups.com> Message-ID: <6d0b0de1-a66b-4991-85f5-1afb4e5109b8@y23g2000yqd.googlegroups.com> On Oct 31, 2:44?pm, Benjamin Kaplan wrote: > Rep() = Rep object > Rep.all() = Query object > list(Rep.all()) = List of Rep objects. > list(Rep.all())[0] = A single Rep object > list(Rep.all())[0].replist = A list > Thanks! This was very helpful. From lists at asd-group.com Mon Nov 8 23:16:23 2010 From: lists at asd-group.com (John Bond) Date: Tue, 09 Nov 2010 04:16:23 +0000 Subject: Commercial or Famous Applicattions.? In-Reply-To: <201011090026.oA90QP1S095565@krusty.intranet.com.mx> References: <201011090026.oA90QP1S095565@krusty.intranet.com.mx> Message-ID: <4CD8CB17.4060301@asd-group.com> On 9/11/2010 12:18 AM, Jorge Biquez wrote: > Hello all. > > Newbie question. Sorry. > > Can you mention applications/systems/solutions made with Python that > are well known and used by public in general? ANd that maybe we do not > know they are done with Python? > > ... > Jorge Biquez > Keep in mind that Python is also popular in frameworks such as Zope and Twisted, and things based on them are based on Python. It's also been reasonably popular and well supported on Symbian smartphones. The Wing IDE is a good example of a commercial Python app on the desktop. I once got asked to write a list things that I'd make different in the technology world if I could, to make it better for everyone. Number 3 was "everywhere you now see Javascript or PHP, you'd see Python instead". If only... Cheers, JB From etolv.computers.groups at gmail.com Mon Nov 8 23:28:55 2010 From: etolv.computers.groups at gmail.com (mohammed ahmed) Date: Mon, 8 Nov 2010 20:28:55 -0800 (PST) Subject: Send a free SMS to your friends from Gmail Message-ID: <6756c026-a4f2-486a-9d85-ee5fd86e16da@i32g2000pri.googlegroups.com> Send a free SMS to your friends from Gmail Did you know that you can now send free text messages (SMS) to your friends directly from your Gmail account? Try Gmail SMS today and start texting your friends from your computer. http://free-sms-sms-sms.blogspot.com/2010/11/gmail-sms.html send free sms from pc to mobile http://phpforweb.com/askany/sms.php?sms From etolv.computers.groups at gmail.com Mon Nov 8 23:28:56 2010 From: etolv.computers.groups at gmail.com (mohammed ahmed) Date: Mon, 8 Nov 2010 20:28:56 -0800 (PST) Subject: Send a free SMS to your friends from Gmail Message-ID: <96e5f7f8-8932-4123-a705-7aadd32f0ebf@g28g2000pra.googlegroups.com> Send a free SMS to your friends from Gmail Did you know that you can now send free text messages (SMS) to your friends directly from your Gmail account? Try Gmail SMS today and start texting your friends from your computer. http://free-sms-sms-sms.blogspot.com/2010/11/gmail-sms.html send free sms from pc to mobile http://phpforweb.com/askany/sms.php?sms From ldo at geek-central.gen.new_zealand Tue Nov 9 00:54:50 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 09 Nov 2010 18:54:50 +1300 Subject: Commercial or Famous Applicattions.? References: <201011090026.oA90QP1S095565@krusty.intranet.com.mx> Message-ID: In message , John Bond wrote: > I once got asked to write a list things that I'd make different in the > technology world if I could, to make it better for everyone. Number 3 > was "everywhere you now see Javascript or PHP, you'd see Python > instead". If only... PHP yes, JavaScript no. From ldo at geek-central.gen.new_zealand Tue Nov 9 00:57:14 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 09 Nov 2010 18:57:14 +1300 Subject: Commercial or Famous Applicattions.? References: Message-ID: In message , Jorge Biquez wrote: > ... there are not too many applications done with Python > than the ones done with PHP ... PHP is only used for server-side Web applications, nothing else. Python is used for lots of things, on and off the Web. From ldo at geek-central.gen.new_zealand Tue Nov 9 01:04:53 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 09 Nov 2010 19:04:53 +1300 Subject: Silly newbie question - Caret character (^) References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> Message-ID: In message , Seebs wrote: > On 2010-11-09, Lawrence D'Oliveiro > wrote: > >> In message , Dennis >> Lee Bieber wrote: >>> >>> Have you ever looked at the reference manual for Ada? > >> Or even worse, the annotated reference. I thought annotations were >> supposed to clarify things; in this case they seemed to have the opposite >> effect... > > Clearly, you've never seen Schildt's infamous "Annotated ANSI C Standard". There absolutely no chance (or at least no way I can imagine) that anyone could annotate a concise language like C up to the level of turgidity of the Ada spec. Hang on, is this Herb Schildt? I bought a couple of his books, back when I was trying to get to grips with C++ (I have the edition of ?C++ The Complete Reference? which proudly proclaims it ?Covers the New International Standard for C+?). Not as useful as I thought they would be; I ended up referring to the libstdc++ sources to clarify things. From lists at asd-group.com Tue Nov 9 01:31:48 2010 From: lists at asd-group.com (John Bond) Date: Tue, 09 Nov 2010 06:31:48 +0000 Subject: Commercial or Famous Applicattions.? In-Reply-To: References: <201011090026.oA90QP1S095565@krusty.intranet.com.mx> Message-ID: <4CD8EAD4.9080705@asd-group.com> On 9/11/2010 5:54 AM, Lawrence D'Oliveiro wrote: > In message, John Bond > wrote: > >> I once got asked to write a list things that I'd make different in the >> technology world if I could, to make it better for everyone. Number 3 >> was "everywhere you now see Javascript or PHP, you'd see Python >> instead". If only... > PHP yes, JavaScript no. Without wanting to go too far o/t, why? Cheers, JB. From ldo at geek-central.gen.new_zealand Tue Nov 9 01:52:22 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 09 Nov 2010 19:52:22 +1300 Subject: JavaScript vs Python (was Re: Commercial or Famous Applicattions.?) References: <201011090026.oA90QP1S095565@krusty.intranet.com.mx> Message-ID: In message , John Bond wrote: > On 9/11/2010 5:54 AM, Lawrence D'Oliveiro wrote: > >> In message, John Bond >> wrote: >> >>> I once got asked to write a list things that I'd make different in the >>> technology world if I could, to make it better for everyone. Number 3 >>> was "everywhere you now see Javascript or PHP, you'd see Python >>> instead". If only... >> >> PHP yes, JavaScript no. >> > ... why? Because JavaScript is actually a decent language in its own right. From usenet-nospam at seebs.net Tue Nov 9 02:00:00 2010 From: usenet-nospam at seebs.net (Seebs) Date: 09 Nov 2010 07:00:00 GMT Subject: Silly newbie question - Caret character (^) References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> Message-ID: On 2010-11-09, Lawrence D'Oliveiro wrote: > In message , Seebs wrote: >> On 2010-11-09, Lawrence D'Oliveiro >> wrote: >>> Or even worse, the annotated reference. I thought annotations were >>> supposed to clarify things; in this case they seemed to have the opposite >>> effect... >> Clearly, you've never seen Schildt's infamous "Annotated ANSI C Standard". > There absolutely no chance (or at least no way I can imagine) that anyone > could annotate a concise language like C up to the level of turgidity of the > Ada spec. Not so much turgidity as being WRONG. Consistently and often. > Hang on, is this Herb Schildt? I bought a couple of his books, back when I > was trying to get to grips with C++ (I have the edition of ???C++ The Complete > Reference??? which proudly proclaims it ???Covers the New International Standard > for C+???). Not as useful as I thought they would be; I ended up referring to > the libstdc++ sources to clarify things. Yes, Herb Schildt: http://www.seebs.net/c/c_tcn4e.html (I know too little about C++ to criticize is writings about it, but people have told me they're comparable.) -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From arnodel at gmail.com Tue Nov 9 02:08:18 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Tue, 09 Nov 2010 07:08:18 +0000 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jftftFelnU1@mid.individual.net> <87oca1b8ba.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <87pqufx9ct.fsf@gmail.com> Lawrence D'Oliveiro writes: > In message <87oca1b8ba.fsf.mdw at metalzone.distorted.org.uk>, Mark Wooding > wrote: > >> Vertical space is a limiting factor on how much code one can see at a >> time. > > One thing that helps me is that Emacs has commands for quickly jumping > between matching brackets. > > Of course, this only works for languages that have brackets. python-mode has python-beginning-of-block (C-c C-u) and python-end-of-block. -- Arnaud From infodmpcg at gmail.com Tue Nov 9 02:09:01 2010 From: infodmpcg at gmail.com (Karis Lee) Date: Mon, 8 Nov 2010 23:09:01 -0800 (PST) Subject: How to Write a Winning Dissertation Message-ID: <364295c9-ac73-4362-85ef-bfc757b5e542@z17g2000prz.googlegroups.com> Writing a Dissertation requires mastery of research methods for valid and reliable data collection, availability of all the resources and perfection of dissertation format, structure and citation styles. This article offers some guiltiness about how to write a winning dissertation. Dissertation Writing certainly is very challenging and time consuming task. Writing a dissertation requires to set before clear aims and objectives, define the research approach and methods and achieve the objectives with valid and reliable results. Dissertation Writing is the most vital and exigent task for students. It is in fact a real test of their academic learning, mastery of the language, and command of expression. For students, dissertation writing has become an adamant task because of countless reasons. The most obvious reason why students fail in writing a good dissertation is that they don?t give due attention to its format, structure and the citation style. The proper format of masters dissertation is very important and it should be consistent throughout to offer a professional look. Mostly, universities prefer times new roman 12 font size with 1.5? margin on both sides to allow binding. The proper structure of any acceptable dissertation is: 1. Dissertation title 2. Dissertation acknowledgment 3. Dissertation abstract 4. Table of contents 5. Dissertation Introduction 6. Dissertation Literature review 7. Dissertation methodology 8. Dissertation results 9. Dissertation conclusion Some universities prefer to break the dissertation even to six or seven chapters. For this purpose, the results are presented in fourth chapter while a critical analysis of these results is presented in fifth chapter. Then conclusion is offered in chapter six and in the seventh chapter dissertation recommendation and limitations are offered. Finally, the citation style is also very important and if students fail to follow the given citation style by the university they are sure to fail and lose their valuable degree. Citation is must for any academic writing and every reference to any research of the author must be quoted using the required citation style. For example, in UK universities Harvard citation style and APA citation style are mostly used. In order to be familiar with these citation styles, there is a lot of material on internet and APA citation examples as well as Harvard citation examples can be found easily. Besides the format, structure and the citation style, choosing the proper research methodology is very critical for data collection process. There are two kinds of data collected for academic research: primary and the secondary. The secondary data comes from the already written sources like books, articles, journals and information available from web. On the other hand, the primary data is collected personally through interviews, case study, and surveys. Dissertation Master is the best place to get help for writing a perfect dissertation as we have hired masters of dissertation writing who are well aware of the dissertation format, dissertation structure and the dissertation data collection. Besides, our prices are very affordable, competitive and we offer attractive discounts. For more detail, visit http://www.dissertationmaster.com From clp2 at rebertia.com Tue Nov 9 02:30:24 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 8 Nov 2010 23:30:24 -0800 Subject: JavaScript vs Python (was Re: Commercial or Famous Applicattions.?) In-Reply-To: References: <201011090026.oA90QP1S095565@krusty.intranet.com.mx> Message-ID: On Mon, Nov 8, 2010 at 10:52 PM, Lawrence D'Oliveiro wrote: > In message , John Bond > wrote: > >> On 9/11/2010 5:54 AM, Lawrence D'Oliveiro wrote: >>> In message, John Bond >>> wrote: >>> >>>> I once got asked to write a list things that I'd make different in the >>>> technology world if I could, to make it better for everyone. Number 3 >>>> was "everywhere you now see Javascript or PHP, you'd see Python >>>> instead". If only... >>> >>> PHP yes, JavaScript no. >>> >> ... why? > > Because JavaScript is actually a decent language in its own right. "The Good Parts" of it anyway. Cheers, Chris From ldo at geek-central.gen.new_zealand Tue Nov 9 02:34:29 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 09 Nov 2010 20:34:29 +1300 Subject: Silly newbie question - Caret character (^) References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> Message-ID: In message , Seebs wrote: > Not so much turgidity as being WRONG. Consistently and often. Wow. And the guy?s written so many books; how does he get away with it? > (I know too little about C++ to criticize is writings about it, but people > have told me they're comparable.) I suppose seeing that ?Covers the New International Standard for C+? should have set off my alarm bells... From arnodel at gmail.com Tue Nov 9 02:34:36 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Tue, 09 Nov 2010 07:34:36 +0000 Subject: Pythonic/idiomatic? References: Message-ID: <87lj53x84z.fsf@gmail.com> Seebs writes: > I have an existing hunk of Makefile code: > CPPFLAGS = "$(filter -D* -I* -i* -U*,$(TARGET_CFLAGS))" > For those not familiar with GNU makeisms, this means "assemble a string > which consists of all the words in $(TARGET_CFLAGS) which start with one > of -D, -I, -i, or -U". So if you give it > foo -Ibar baz > it'll say > -Ibar > > I have a similar situation in a Python context, and I am wondering > whether this is an idiomatic spelling: > > ' '.join([x for x in target_cflags.split() if re.match('^-[DIiU]', x)]) You can also use the (less favoured) filter: >>> target_cflags="-ifoo -abar -U -Dbaz".split() >>> def matches_flags(flags): ... return re.compile("^-[%s]" % flags).match ... >>> ' '.join(filter(matches_flags("DiIU"), target_cflags)) '-ifoo -U -Dbaz' -- Arnaud From ldo at geek-central.gen.new_zealand Tue Nov 9 02:35:48 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 09 Nov 2010 20:35:48 +1300 Subject: How to test if a module exists? References: Message-ID: In message , Roy Smith wrote: > On the other hand, if your module's bug is that it in turn imports some > other module, which doesn't exist, you'll also get an ImportError. Does it really matter? Either way, the module is unusable. From ian.g.kelly at gmail.com Tue Nov 9 02:50:20 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 9 Nov 2010 00:50:20 -0700 Subject: JavaScript vs Python (was Re: Commercial or Famous Applicattions.?) In-Reply-To: References: <201011090026.oA90QP1S095565@krusty.intranet.com.mx> Message-ID: On Tue, Nov 9, 2010 at 12:30 AM, Chris Rebert wrote: > "The Good Parts" of it anyway. > > All hail William Goldman! Wait, what were talking about? Ian -------------- next part -------------- An HTML attachment was scrubbed... URL: From usenet-nospam at seebs.net Tue Nov 9 02:55:14 2010 From: usenet-nospam at seebs.net (Seebs) Date: 09 Nov 2010 07:55:14 GMT Subject: Silly newbie question - Caret character (^) References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> Message-ID: On 2010-11-09, Lawrence D'Oliveiro wrote: > In message , Seebs wrote: >> Not so much turgidity as being WRONG. Consistently and often. > Wow. And the guy???s written so many books; how does he get away with it? No one knows or cares. I don't mean "no one knows or cares how he gets away with it"; I mean "no one knows or cares that he's awful". The publisher doesn't care whether the books are accurate, as long as they sell, and most reviewers don't read closely enough to realize he's full of crap. In particular, he's very good at making up complications from whole cloth which aren't really problems, and then offering "solutions" which show people a clever trick to work around the problem. (e.g., his elaborate revelations about how to use feof() in C to work around his failure to understand how EOF works.) -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Tue Nov 9 03:27:13 2010 From: usenet-nospam at seebs.net (Seebs) Date: 09 Nov 2010 08:27:13 GMT Subject: Best exercises for beginers to learn? References: Message-ID: On 2010-11-08, brf256 at gmail.com wrote: > I was wondering if there are any good exercises that you > would recommend learning? Yes. *Write something you want to use.* Nothing will teach you programming as fast as programming stuff you care about for the joy of having it. Exercises that you don't care about in their own right will not catch you the same way. If you write something you want to have, you will not stop when it happens to work, but will keep tweaking it and improving it so it does what you want. That will teach you more than *any* prefab exercise that has no particular significance to you. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From michele.simionato at gmail.com Tue Nov 9 03:29:54 2010 From: michele.simionato at gmail.com (Michele Simionato) Date: Tue, 9 Nov 2010 00:29:54 -0800 (PST) Subject: How to get dynamically-created fxn's source? References: Message-ID: <10aaf181-51b1-44f3-b8f8-3a921a729b6c@a9g2000pro.googlegroups.com> On Nov 5, 5:55?pm, gb345 wrote: > For a project I'm working on I need a way to retrieve the source > code of dynamically generated Python functions. ?(These functions > are implemented dynamically in order to simulate "partial application" > in Python.[1]) ?The ultimate goal is to preserve a textual record > of transformations performed on data, along with all the data (both > pre- and post- transformation) itself. > > These transformation functions could be dynamically generated as > closures, but I suspect that this would make it more difficult to > extract source code that could serve as a reasonably self-contained > description of the transformation (because this source code would > refer to variables defined outside of the function). ?An alternative > would be to generate the *source code* for the functions dynamically, > from a template having slots (within the function's definition) > that gets filled in with actual parameter values, and pass this > source code to exec. > > In any case, the problem remains of how to extract the > dynamically-generated function's source code. > > One possibility would be to define a Transformation wrapper class > whose __init__ takes the dynamically-generated source code (a > string) as argument, keeps it around as an instance attribute for > future reference, and exec's it to define its __call__ method. > > Is this overkill/reinventing the wheel? ?IOW, does Python already > have a built-in way to achieve this same effect? > > (Also, the wrapper scheme above is somewhat loose: it's relatively > easy for the source code instance attribute (as described) to fall > out of sync with the function that actually executes when __call__ > runs. ?Maybe a tighter connection between the obtained source code > and the code that actually executes when __call__ runs is possible.) > > I'm aware of the inspect module, but from reading its source code > I gather that it is designed for inspecting source code that is > explicitly written in files, and would not be too good at inspecting > functions that are generated dynamically (i.e. not from source code > explicitly given in a source file--I hope that made sense). > > Your comments and suggestions would be much appreciated. ?Many > thanks in advance! > > G > > [1] For example, given a base function spam that has the signature > (typeT, typeT, typeT, int, int, int) and three specific integer > values X, Y, and Z, dynamically generate a new function spamXYZ > with signature (typeT, typeT, typeT) such that spamXYZ(A, B, C) is > identical to spam(A, B, C, X, Y, Z), for all possible values of A, > B, C. I wondered a lot about this issue when writing my own decorator module. You may look at the source code of the FunctionMaker class which tries to address the problem by storing the source code of the generated function into an attribute. Using inspect.getsource does not work (see http://bugs.python.org/issue1764286). Of course if you functools.partial is enough to solve your problem use it and be done with it. From geoff.bache at gmail.com Tue Nov 9 04:18:55 2010 From: geoff.bache at gmail.com (Geoff Bache) Date: Tue, 9 Nov 2010 01:18:55 -0800 (PST) Subject: A way to get setup.py to create links instead of copy Message-ID: <5ec2edeb-14cf-4c1d-919f-d4246f4af10a@f20g2000yqi.googlegroups.com> Hi all, One of the things I've always loved about Python (having come from compiled languages) was the lack of an extra step between changing my code and running it. On my current project, however, I find that I have to install my Python code with setup.py before it will run. Being used to not having this step, I easily forget to run setup.py install before they will run, and then spend time wondering why my changes didn't work. So I went into the target directory and replaced the copies with symbolic links back to the original code. This felt like a hack but does mean I don't have to install the whole time any more. I wonder if there is some standard way to deal with this situation? Regards, Geoff Bache From ldo at geek-central.gen.new_zealand Tue Nov 9 04:23:47 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 09 Nov 2010 22:23:47 +1300 Subject: Silly newbie question - Caret character (^) References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> Message-ID: In message , Seebs wrote: > The publisher doesn't care whether the books are accurate ... A sad state for the once-proud name ?Osborne? ... From costin.gament at gmail.com Tue Nov 9 04:24:09 2010 From: costin.gament at gmail.com (=?UTF-8?Q?Costin_Gamen=C8=9B?=) Date: Tue, 9 Nov 2010 11:24:09 +0200 Subject: List index out of range, but list has enough elements Message-ID: Hi, I am trying to read a string as csv, but I encountered an odd problem. Here's my code: csvfile = csv.reader(datastr.split('\n'), delimiter=';') r = '' for i in csvfile: for j in i: print j print i[0] the "print j" statement works, but "print i[0]" returns "IndexError: list index out of range". Am I missing something? From ldo at geek-central.gen.new_zealand Tue Nov 9 04:25:11 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 09 Nov 2010 22:25:11 +1300 Subject: How to test if a module exists? References: Message-ID: In message , Roy Smith wrote: > Fail early and often, that's what I say. Good advice that could apply to lots of things. Except maybe procrastination ... :) From ldo at geek-central.gen.new_zealand Tue Nov 9 04:25:54 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 09 Nov 2010 22:25:54 +1300 Subject: JavaScript vs Python References: <201011090026.oA90QP1S095565@krusty.intranet.com.mx> Message-ID: In message , Chris Rebert wrote: > On Mon, Nov 8, 2010 at 10:52 PM, Lawrence D'Oliveiro > wrote: > >> Because JavaScript is actually a decent language in its own right. > > "The Good Parts" of it anyway. Python, too, has its good parts, you have to admit... From ldo at geek-central.gen.new_zealand Tue Nov 9 04:26:52 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 09 Nov 2010 22:26:52 +1300 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: In message , Ethan Furman wrote: > Lawrence D'Oliveiro wrote: > >> In message , Tim Harig wrote: >>> >>> I personally prefer tabs as it lets *me* decide how far the apparent >>> indentations are in the code. >> >> But they don?t. Other people can have different settings, and they will >> see different indentations for your code > > That's exactly the point -- each person can decide what level of > indentation they prefer to look at. But I thought Mr Harig was referring to ?*me*? as in the author of the code, not the reader. From __peter__ at web.de Tue Nov 9 04:31:21 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 09 Nov 2010 10:31:21 +0100 Subject: Pythonic/idiomatic? References: Message-ID: Seebs wrote: > I have an existing hunk of Makefile code: > CPPFLAGS = "$(filter -D* -I* -i* -U*,$(TARGET_CFLAGS))" > For those not familiar with GNU makeisms, this means "assemble a string > which consists of all the words in $(TARGET_CFLAGS) which start with one > of -D, -I, -i, or -U". So if you give it > foo -Ibar baz > it'll say > -Ibar > > I have a similar situation in a Python context, and I am wondering > whether this is an idiomatic spelling: > > ' '.join([x for x in target_cflags.split() if re.match('^-[DIiU]', x)]) > > This appears to do the same thing, but is it an idiomatic use of list > comprehensions, or should I be breaking it out into more bits? You may be able split and match with a single regex, e. g. >>> cflags = "-Dxxx -D zzz -i- -U42-U7 -i -U" >>> re.compile(r"-[DIiU]\S*").findall(cflags) ['-Dxxx', '-D', '-i-', '-U42-U7', '-i', '-U'] >>> re.compile(r"-[DIiU]\s*(?:[^-]\S*)?").findall(cflags) ['-Dxxx', '-D zzz', '-i', '-U42-U7', '-i ', '-U'] Peter From stefan_ml at behnel.de Tue Nov 9 04:33:28 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 09 Nov 2010 10:33:28 +0100 Subject: List index out of range, but list has enough elements In-Reply-To: References: Message-ID: Costin Gamen?, 09.11.2010 10:24: > Hi, I am trying to read a string as csv, but I encountered an odd > problem. Here's my code: > > csvfile = csv.reader(datastr.split('\n'), delimiter=';') > r = '' > for i in csvfile: > for j in i: > print j > print i[0] > > the "print j" statement works, but "print i[0]" returns "IndexError: > list index out of range". Am I missing something? Are you sure the output you get from the "print j" is from the same loop iteration as the "print i[0]"? Try adding "i" to the output. Stefan From __peter__ at web.de Tue Nov 9 04:37:58 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 09 Nov 2010 10:37:58 +0100 Subject: List index out of range, but list has enough elements References: Message-ID: Costin Gamen? wrote: > Hi, I am trying to read a string as csv, but I encountered an odd > problem. Here's my code: > > csvfile = csv.reader(datastr.split('\n'), delimiter=';') > r = '' > for i in csvfile: > for j in i: > print j > print i[0] > > the "print j" statement works, but "print i[0]" returns "IndexError: > list index out of range". Am I missing something? Change print i[0] to print i You'll see that there are empty rows in your data. You cannot detect these rows with for j in i: print j because you get zero iterations, i. e. the print j statement is never executed for these rows. Peter From mdw at distorted.org.uk Tue Nov 9 04:49:32 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 09 Nov 2010 09:49:32 +0000 Subject: Pythonic/idiomatic? References: Message-ID: <8762w6n7wz.fsf.mdw@metalzone.distorted.org.uk> Seebs writes: > ' '.join([x for x in target_cflags.split() if re.match('^-[DIiU]', x)]) > > This appears to do the same thing, but is it an idiomatic use of list > comprehensions, or should I be breaking it out into more bits? It looks OK to me. You say (elsewhere in the thread) that you're stuck with 2.4 compatibility. I'd personally avoid the regexp, though, and write this (actually tested with Python 2.4!): ' '.join(i for i in target_cflags.split() for p in 'DIiU' if i.startswith('-' + p)) > You will note that of course, I have carefully made it a one-liner so I > don't have to worry about indentation*. I failed at that. You have to put up with my indentation. -- [mdw] From costin.gament at gmail.com Tue Nov 9 04:51:56 2010 From: costin.gament at gmail.com (=?UTF-8?Q?Costin_Gamen=C8=9B?=) Date: Tue, 9 Nov 2010 11:51:56 +0200 Subject: List index out of range, but list has enough elements In-Reply-To: References: Message-ID: Thank you for your timely response. Yes, I am sure "i" and "j" are from the same iteration. I should point out that "i" actually has 8 elements and that str(i) gives a nice printout. On Tue, Nov 9, 2010 at 11:33 AM, Stefan Behnel wrote: > Costin Gamen?, 09.11.2010 10:24: >> >> Hi, I am trying to read a string as csv, but I encountered an odd >> problem. Here's my code: >> >> ? ? ? ?csvfile = csv.reader(datastr.split('\n'), delimiter=';') >> ? ? ? ?r = '' >> ? ? ? ?for i in csvfile: >> ? ? ? ? ? ? ? ?for j in i: >> ? ? ? ? ? ? ? ? ? ? ? ?print j >> ? ? ? ? ? ? ? ?print i[0] >> >> the "print j" statement works, but "print i[0]" returns "IndexError: >> list index out of range". Am I missing something? > > Are you sure the output you get from the "print j" is from the same loop > iteration as the "print i[0]"? Try adding "i" to the output. > > Stefan > > -- > http://mail.python.org/mailman/listinfo/python-list > From nitinpawar432 at gmail.com Tue Nov 9 05:02:44 2010 From: nitinpawar432 at gmail.com (Nitin Pawar) Date: Tue, 9 Nov 2010 15:32:44 +0530 Subject: List index out of range, but list has enough elements In-Reply-To: References: Message-ID: You may want to try a spilt if you are getting 8 different elements then it will give you a list of those elements On Tue, Nov 9, 2010 at 3:21 PM, Costin Gamen? wrote: > Thank you for your timely response. Yes, I am sure "i" and "j" are > from the same iteration. I should point out that "i" actually has 8 > elements and that str(i) gives a nice printout. > > On Tue, Nov 9, 2010 at 11:33 AM, Stefan Behnel > wrote: > > Costin Gamen?, 09.11.2010 10:24: > >> > >> Hi, I am trying to read a string as csv, but I encountered an odd > >> problem. Here's my code: > >> > >> csvfile = csv.reader(datastr.split('\n'), delimiter=';') > >> r = '' > >> for i in csvfile: > >> for j in i: > >> print j > >> print i[0] > >> > >> the "print j" statement works, but "print i[0]" returns "IndexError: > >> list index out of range". Am I missing something? > > > > Are you sure the output you get from the "print j" is from the same loop > > iteration as the "print i[0]"? Try adding "i" to the output. > > > > Stefan > > > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -------------- next part -------------- An HTML attachment was scrubbed... URL: From mdw at distorted.org.uk Tue Nov 9 05:12:43 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 09 Nov 2010 10:12:43 +0000 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jftftFelnU1@mid.individual.net> <87oca1b8ba.fsf.mdw@metalzone.distorted.org.uk> <87pqufx9ct.fsf@gmail.com> Message-ID: <871v6un6uc.fsf.mdw@metalzone.distorted.org.uk> Arnaud Delobelle writes: > python-mode has python-beginning-of-block (C-c C-u) and > python-end-of-block. Yes. It was one of my explicit gripes that editing Python requires one to learn entirely new and unfamiliar keystrokes for doing fairly familiar editing tasks. -- [mdw] From costin.gament at gmail.com Tue Nov 9 05:44:45 2010 From: costin.gament at gmail.com (=?UTF-8?Q?Costin_Gamen=C8=9B?=) Date: Tue, 9 Nov 2010 12:44:45 +0200 Subject: List index out of range, but list has enough elements In-Reply-To: References: Message-ID: Thank you all for your interest in my problem. As Peter pointed out, there was one row with zero elements in it and that's where my problem was (of course it was the very last row, hence my confidence I have "good" data). Have a nice one, Costin On Tue, Nov 9, 2010 at 12:02 PM, Nitin Pawar wrote: > You may want to try a spilt if you are getting 8 different elements then it > will give you a list of those elements > > On Tue, Nov 9, 2010 at 3:21 PM, Costin Gamen? > wrote: >> >> Thank you for your timely response. Yes, I am sure "i" and "j" are >> from the same iteration. I should point out that "i" actually has 8 >> elements and that str(i) gives a nice printout. >> >> On Tue, Nov 9, 2010 at 11:33 AM, Stefan Behnel >> wrote: >> > Costin Gamen?, 09.11.2010 10:24: >> >> >> >> Hi, I am trying to read a string as csv, but I encountered an odd >> >> problem. Here's my code: >> >> >> >> ? ? ? ?csvfile = csv.reader(datastr.split('\n'), delimiter=';') >> >> ? ? ? ?r = '' >> >> ? ? ? ?for i in csvfile: >> >> ? ? ? ? ? ? ? ?for j in i: >> >> ? ? ? ? ? ? ? ? ? ? ? ?print j >> >> ? ? ? ? ? ? ? ?print i[0] >> >> >> >> the "print j" statement works, but "print i[0]" returns "IndexError: >> >> list index out of range". Am I missing something? >> > >> > Are you sure the output you get from the "print j" is from the same loop >> > iteration as the "print i[0]"? Try adding "i" to the output. >> > >> > Stefan >> > >> > -- >> > http://mail.python.org/mailman/listinfo/python-list >> > >> -- >> http://mail.python.org/mailman/listinfo/python-list > > > > -- > Nitin Pawar > > From stefan_ml at behnel.de Tue Nov 9 06:00:27 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 09 Nov 2010 12:00:27 +0100 Subject: List index out of range, but list has enough elements In-Reply-To: References: Message-ID: [rearranged the responses in the right order] Costin Gamen?, 09.11.2010 11:44: >> On Tue, Nov 9, 2010 at 3:21 PM, Costin Gamen? wrote: >>> On Tue, Nov 9, 2010 at 11:33 AM, Stefan Behnel wrote: >>>> Costin Gamen?, 09.11.2010 10:24: >>>>> Hi, I am trying to read a string as csv, but I encountered an odd >>>>> problem. Here's my code: >>>>> >>>>> csvfile = csv.reader(datastr.split('\n'), delimiter=';') >>>>> r = '' >>>>> for i in csvfile: >>>>> for j in i: >>>>> print j >>>>> print i[0] >>>>> >>>>> the "print j" statement works, but "print i[0]" returns "IndexError: >>>>> list index out of range". Am I missing something? >>>> >>>> Are you sure the output you get from the "print j" is from the same loop >>>> iteration as the "print i[0]"? Try adding "i" to the output. >>>> >>> Thank you for your timely response. Yes, I am sure "i" and "j" are >>> from the same iteration. I should point out that "i" actually has 8 >>> elements and that str(i) gives a nice printout. >>> > Thank you all for your interest in my problem. As Peter pointed out, > there was one row with zero elements in it and that's where my problem > was (of course it was the very last row, hence my confidence I have > "good" data). A classic "don't be sure before you've tested". ;-) Stefan From jeanmichel at sequans.com Tue Nov 9 06:02:22 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 09 Nov 2010 12:02:22 +0100 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: <4CD92A3E.1010706@sequans.com> Jon Dufresne wrote: > On Sat, Nov 6, 2010 at 1:52 PM, Roy Smith wrote: > >> import sys >> try: >> import xx >> except ImportError: >> tb = sys.exc_traceback >> while tb: >> print tb >> tb = tb.tb_next >> >> > > I went ahead and implemented this and it now works. I even uncovered a > bug I wasn't previously seeing because now the program was failing > early! :) > > I hope there isn't a hidden naivete in using this pattern. > > Thanks, > Jon > try: ....: import xx ....: except ImportError: ....: tb = sys.exc_traceback ....: while tb: ....: print tb ....: tb = tb.tb_next ....: I don't see how it solves your problem. It does not test if a module exists, nor does it handles missing or flawed modules differently. JM From roy at panix.com Tue Nov 9 07:30:45 2010 From: roy at panix.com (Roy Smith) Date: Tue, 09 Nov 2010 07:30:45 -0500 Subject: How to test if a module exists? References: Message-ID: In article , Lawrence D'Oliveiro wrote: > In message , Roy Smith wrote: > > > On the other hand, if your module's bug is that it in turn imports some > > other module, which doesn't exist, you'll also get an ImportError. > > Does it really matter? Either way, the module is unusable. If I understand correctly, he's trying to differentiate between: 1) The module is unusable because it's not installed 2) The module is unusable because it has a bug in it. The later case implies he needs to find and fix the bug. From fred.sells at adventistcare.org Tue Nov 9 07:57:35 2010 From: fred.sells at adventistcare.org (Sells, Fred) Date: Tue, 9 Nov 2010 07:57:35 -0500 Subject: { '0':'c->c->a' ,'1':'a->b->a' .........} In-Reply-To: References: <8961af78-5f7b-46e1-95d7-014534b6e637@s4g2000yql.googlegroups.com> Message-ID: Since your keys are not unique, I would think that you would want a list of values for the object corresponding to each key. Something like Mydict = {} Mydict.setdefault(mykey, []).append(avalue) -----Original Message----- From: python-list-bounces+frsells=adventistcare.org at python.org [mailto:python-list-bounces+frsells=adventistcare.org at python.org] On Behalf Of Peter Otten Sent: Sunday, November 07, 2010 4:01 PM To: python-list at python.org Subject: Re: { '0':'c->c->a' ,'1':'a->b->a' .........} chris wrote: > have anybody a hint , how i get a dict from non unique id's and their > different related values. > > Thanks for advance > Chris > > ###random data # > a=range(10)*3 > def seqelem(): > i=random.randint(0,2) > elem=['a','b','c'][i] > return elem > > s=[seqelem() for t in range(30)] > print zip(a,s) > > ## favored result: > { '0':'c->c->a' ,'1':'a->b->a' .........} >>> import random >>> from collections import defaultdict >>> a = range(10)*3 >>> s = [random.choice("abc") for _ in a] >>> d = defaultdict(list) >>> for k, v in zip(a, s): ... d[k].append(v) ... >>> d defaultdict(, {0: ['b', 'a', 'a'], 1: ['c', 'a', 'c'], 2: ['c', 'c', 'c'], 3: ['c', 'a', 'a'], 4: ['b', 'c', 'a'], 5: ['b', 'c', 'c'], 6: ['c', 'a', 'b'], 7: ['b', 'b', 'a'], 8: ['a', 'c', 'c'], 9: ['b', 'a', 'b']}) >>> dict((k, "->".join(v)) for k, v in d.iteritems()) {0: 'b->a->a', 1: 'c->a->c', 2: 'c->c->c', 3: 'c->a->a', 4: 'b->c->a', 5: 'b->c->c', 6: 'c->a->b', 7: 'b->b->a', 8: 'a->c->c', 9: 'b->a->b'} Peter -- http://mail.python.org/mailman/listinfo/python-list From magawake at gmail.com Tue Nov 9 08:20:45 2010 From: magawake at gmail.com (Mag Gam) Date: Tue, 9 Nov 2010 08:20:45 -0500 Subject: udp sockets with python Message-ID: Hello, When measuring round trip time for the UDP echo client/server the C version is much faster. I was wondering if there is anything I can do to speed up. My current code for client looks like this.... sock=socket(AF_INET,SOCK_DGRAM) for x in range (1000): sock.sendto("foo",(server,port)) a=sock.recv(256) sock.close() The server code looks like this: UDPsock=socket(AF_INET,SOCK_DGRAM) UDPSock.bind(addr) while 1: m,c=UDPsock,recvfrom(1024) UDPsock.sendto('bar',c) UDPsock.close() I am measuring the round trip time using tcpdump. The C version is giving me around 80 microseconds (average) and the python is giving me close to 300 microseconds (average). From neilc at norwich.edu Tue Nov 9 08:24:02 2010 From: neilc at norwich.edu (Neil Cerutti) Date: 9 Nov 2010 13:24:02 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8jt0biFob3U1@mid.individual.net> On 2010-11-07, Ethan Furman wrote: > Lawrence D'Oliveiro wrote: >> In message , Tim Harig wrote: >>> I personally prefer tabs as it lets *me* decide how far the >>> apparent indentations are in the code. >> >> But they don???t. Other people can have different settings, >> and they will see different indentations for your code > > That's exactly the point -- each person can decide what level > of indentation they prefer to look at. That ideal works only if you are disciplined to never mix tabs and spaces. "Wrapped" lines can become ugly when tabstop is changed. -- Neil Cerutti From jeanmichel at sequans.com Tue Nov 9 08:31:59 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 09 Nov 2010 14:31:59 +0100 Subject: Pythonic/idiomatic? In-Reply-To: References: Message-ID: <4CD94D4F.8010508@sequans.com> Seebs wrote: > I have an existing hunk of Makefile code: > CPPFLAGS = "$(filter -D* -I* -i* -U*,$(TARGET_CFLAGS))" > For those not familiar with GNU makeisms, this means "assemble a string > which consists of all the words in $(TARGET_CFLAGS) which start with one > of -D, -I, -i, or -U". So if you give it > foo -Ibar baz > it'll say > -Ibar > > I have a similar situation in a Python context, and I am wondering > whether this is an idiomatic spelling: > > ' '.join([x for x in target_cflags.split() if re.match('^-[DIiU]', x)]) > > This appears to do the same thing, but is it an idiomatic use of list > comprehensions, or should I be breaking it out into more bits? > > You will note that of course, I have carefully made it a one-liner so I > don't have to worry about indentation*. > > -s > [*] Kidding, I just thought this seemed like a pretty clear expression. > One pythonic way to do it, is to use an option parser. optparse (or argparse if python > 2.7) JM From martin at address-in-sig.invalid Tue Nov 9 08:42:11 2010 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Tue, 9 Nov 2010 13:42:11 +0000 (UTC) Subject: Commercial or Famous Applicattions.? References: Message-ID: On Tue, 09 Nov 2010 00:47:08 +0000, brf256 wrote: > Mailman is of course. > ...and don't forget getmail, a better behaved replacement for fetchmail. -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From icanbob at gmail.com Tue Nov 9 09:03:06 2010 From: icanbob at gmail.com (bobicanprogram) Date: Tue, 9 Nov 2010 06:03:06 -0800 (PST) Subject: Cross compiling (i386 from amd64) with distutils References: Message-ID: <347be269-f40d-45a3-a564-874d85ebb288@w38g2000pri.googlegroups.com> On Nov 7, 7:19 pm, Jason wrote: > My situation is this: I have a Diamond Systems single-board computer > with a > matching GPIO board. DS have a library for controlling the GPIO > board... but > it's a static library (libdscud-6.02.a) with an accompanying header > (dscud.h). > I'd like to create a Python extension to use the device. > > The architecture of the SBC is 486, and it runs Debian Squeeze/Grip. > While it > is possible to develop on it directly, I'd rather use my desktop > machine > (Debian Squeeze, amd64). > > If I write a simple C program to control the device, I'd include the > header > file and cross-compile it like so: > > gcc -m32 -march=i386 -lpthread -I/usr/local/dscud-6.02 -o dio > dio.c \ > /usr/local/dscud-6.02/libdscud-6.02.a > > To get myself started with the Python extension, I've basically taken > the > "noddy" demo[1] and thrown in a function call from the DSC library > just to see > if I can get something to build. > > My distutils setup.py looks like: > > ---- > from distutils.core import setup, Extension > > module1 = Extension('noddy', > sources = ['src/noddy.c'], > libraries = ['pthread'], > include_dirs = ['/usr/local/dscud-6.02'], > extra_objects = ['/usr/local/dscud-6.02/libdscud-6.02.a'], > extra_compile_args = ['-m32', '-march=i386']) > > setup(name = 'Noddy', version = '1.0', description = 'This is a demo > package', > ext_modules = [module1]) > ---- > > This works fine on the target machine with "python setup.py build", > but when I > try it on my desktop machine, I get: > > ---- > $ python setup.py build > running build > running build_ext > building 'noddy' extension > creating build > creating build/temp.linux-x86_64-2.6 > creating build/temp.linux-x86_64-2.6/src > gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall > -Wstrict-prototypes -fPIC -I/usr/local/dscud-6.02 -I/usr/include/ > python2.6 -c > src/noddy.c -o build/temp.linux-x86_64-2.6/src/noddy.o -m32 - > march=i386 > In file included from /usr/include/python2.6/Python.h:58, > from src/noddy.c:1: > /usr/include/python2.6/pyport.h:694:2: error: #error "LONG_BIT > definition > appears wrong for platform (bad gcc/glibc config?)." > error: command 'gcc' failed with exit status 1 > > ---- > > So is it possible to get distutils to cross compile something like > this, and > if so, what am I missing? Or am I using the wrong tool for the job? > > Target python ver. is 2.6. GCC is 4.4.5. > > Cheers, > Jason > > [1]http://docs.python.org/extending/newtypes.html Cross compilation might be one solution to Python access. The SIMPL toolkit (http://www.icanprogram.com/simpl; http://www.icanprogram.com/06py/lesson1/lesson1.html) might be easier. If you ultimately want to communicate from a 64bit to a 32bit system, you'll probably want to use a text based tokenized messaging strategy as opposed to the binary one in these examples. bob From franapoli at gmail.com Tue Nov 9 09:14:11 2010 From: franapoli at gmail.com (Ciccio) Date: Tue, 09 Nov 2010 15:14:11 +0100 Subject: Dictionary of lists strange behaviour Message-ID: Hi all, hope you can help me understanding why the following happens: In [213]: g = {'a': ['a1','a2'], 'b':['b1','b2']} In [214]: rg = dict.fromkeys(g.keys(),[]) In [215]: rg Out[215]: {'a': [], 'b': []} In [216]: rg['a'].append('x') In [217]: rg Out[217]: {'a': ['x'], 'b': ['x']} What I meant was appending 'x' to the list pointed by the key 'a' in the dictionary 'rg'. Why rg['b'] is written too? Thanks. From msarro at gmail.com Tue Nov 9 09:16:29 2010 From: msarro at gmail.com (Matty Sarro) Date: Tue, 9 Nov 2010 09:16:29 -0500 Subject: Best exercises for beginers to learn? In-Reply-To: References: Message-ID: I agree completely with Seebs, however I will mention that until you find a project that tickles your fancy there are some good places to find exercises. Pyschools: http://www.pyschools.com Project Euler: http://projecteuler.net/ You can also check out: http://learnpythonthehardway.org/index The exercises are pretty good. On Tue, Nov 9, 2010 at 3:27 AM, Seebs wrote: > On 2010-11-08, brf256 at gmail.com wrote: > > I was wondering if there are any good exercises that you > > would recommend learning? > > Yes. > > *Write something you want to use.* > > Nothing will teach you programming as fast as programming stuff you care > about for the joy of having it. Exercises that you don't care about in > their own right will not catch you the same way. > > If you write something you want to have, you will not stop when it > happens to work, but will keep tweaking it and improving it so it does > what you want. That will teach you more than *any* prefab exercise that > has no particular significance to you. > > -s > -- > Copyright 2010, all wrongs reversed. Peter Seebach / > usenet-nospam at seebs.net > http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures > http://en.wikipedia.org/wiki/Fair_Game_(Scientology)<-- get educated! > I am not speaking for my employer, although they do rent some of my > opinions. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From landimatte at gmail.com Tue Nov 9 09:24:11 2010 From: landimatte at gmail.com (Matteo Landi) Date: Tue, 9 Nov 2010 15:24:11 +0100 Subject: Dictionary of lists strange behaviour In-Reply-To: References: Message-ID: On Tue, Nov 9, 2010 at 3:14 PM, Ciccio wrote: > Hi all, > > hope you can help me understanding why the following happens: > > In [213]: g = {'a': ['a1','a2'], 'b':['b1','b2']} > In [214]: rg = dict.fromkeys(g.keys(),[]) The argument you pass which is used to fill the values of the new dict, is created once; this means that the empty list is shared between all the keys of the dict. I think you need to create the new dict by hand. Regards, Matteo > In [215]: rg > Out[215]: {'a': [], 'b': []} > In [216]: rg['a'].append('x') > In [217]: rg > Out[217]: {'a': ['x'], 'b': ['x']} > > What I meant was appending 'x' to the list pointed by the key 'a' in the > dictionary 'rg'. Why rg['b'] is written too? > > Thanks. > -- > http://mail.python.org/mailman/listinfo/python-list > -- Matteo Landi http://www.matteolandi.net/ From homebuz11 at gmail.com Tue Nov 9 09:28:08 2010 From: homebuz11 at gmail.com (naveed ahmed) Date: Tue, 9 Nov 2010 06:28:08 -0800 (PST) Subject: Free E-Books collection Message-ID: Freeit http://freeit11.blogspot.comis the world's leading online source of ebooks, with a vast range of ebooks from academic, Popular and professional publishers. Freeit http://freeit11.blogspot.com eBook communicates my vision of exploring the whole universe to you. What if you had a plausible method (based on today's science and technology) freeit large selection of eBooks. New eBook releases and bestsellers in over 40 categories including science fiction, romance, mystery, for more e-books visit Freeit From philip at semanchuk.com Tue Nov 9 09:42:47 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 9 Nov 2010 09:42:47 -0500 Subject: Silly newbie question - Caret character (^) In-Reply-To: References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> Message-ID: <666482B8-FFC9-4A0E-B944-5D725C368DE1@semanchuk.com> On Nov 9, 2010, at 1:04 AM, Lawrence D'Oliveiro wrote: > In message , Seebs wrote: > >> On 2010-11-09, Lawrence D'Oliveiro >> wrote: >> >>> In message , Dennis >>> Lee Bieber wrote: >>>> >>>> Have you ever looked at the reference manual for Ada? >> >>> Or even worse, the annotated reference. I thought annotations were >>> supposed to clarify things; in this case they seemed to have the opposite >>> effect... >> >> Clearly, you've never seen Schildt's infamous "Annotated ANSI C Standard". > > There absolutely no chance (or at least no way I can imagine) that anyone > could annotate a concise language like C up to the level of turgidity of the > Ada spec. > > Hang on, is this Herb Schildt? I bought a couple of his books, back when I > was trying to get to grips with C++ (I have the edition of ?C++ The Complete > Reference? which proudly proclaims it ?Covers the New International Standard > for C+?). Not as useful as I thought they would be; I ended up referring to > the libstdc++ sources to clarify things. What's funny is that I went looking for a printed copy of the C standard a few years back and the advice I got was that the cheapest route was to find a used copy of Schildt's "Annotated ANSI C Standard" and ignore the annotations. So it serves at least one useful purpose. Cheers Philip From jeanmichel at sequans.com Tue Nov 9 09:43:05 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 09 Nov 2010 15:43:05 +0100 Subject: Dictionary of lists strange behaviour In-Reply-To: References: Message-ID: <4CD95DF9.50906@sequans.com> Ciccio wrote: > Hi all, > > hope you can help me understanding why the following happens: > > In [213]: g = {'a': ['a1','a2'], 'b':['b1','b2']} > In [214]: rg = dict.fromkeys(g.keys(),[]) > In [215]: rg > Out[215]: {'a': [], 'b': []} > In [216]: rg['a'].append('x') > In [217]: rg > Out[217]: {'a': ['x'], 'b': ['x']} > > What I meant was appending 'x' to the list pointed by the key 'a' in > the dictionary 'rg'. Why rg['b'] is written too? > > Thanks. rg = dict.fromkeys(g.keys(),[]) you are intialising the content with the same object []. write instead for key in g: rg[key] = [] # python create a new list everytime it hits this line For the same reason you never assign an empty list to default parameters value: In [37]: def a(p=[]): ....: return p ....: In [38]: a1 = a() In [39]: a2 = a() In [40]: id(a1) ; id(a2) Out[40]: 161119884 Out[40]: 161119884 Jean-Michel From davea at ieee.org Tue Nov 9 10:05:44 2010 From: davea at ieee.org (Dave Angel) Date: Tue, 09 Nov 2010 10:05:44 -0500 Subject: Dictionary of lists strange behaviour In-Reply-To: References: Message-ID: <4CD96348.3070300@ieee.org> On 2:59 PM, Ciccio wrote: > Hi all, > > hope you can help me understanding why the following happens: > > In [213]: g = {'a': ['a1','a2'], 'b':['b1','b2']} > In [214]: rg = dict.fromkeys(g.keys(),[]) > In [215]: rg > Out[215]: {'a': [], 'b': []} > In [216]: rg['a'].append('x') > In [217]: rg > Out[217]: {'a': ['x'], 'b': ['x']} > > What I meant was appending 'x' to the list pointed by the key 'a' in > the dictionary 'rg'. Why rg['b'] is written too? > > Thanks. > The second argument to the fromkeys() method is an empty list object. So that object is the value for *both* the new dictionary items. It does not make a new object each time, it uses the same one. You can check this for yourself, by doing id(rg["a"]) and id(rg["b"]) I'd do something like : rg = {} for key in g.keys(): rg[key] = [] DaveA From kw at codebykevin.com Tue Nov 9 10:19:10 2010 From: kw at codebykevin.com (Kevin Walzer) Date: Tue, 09 Nov 2010 10:19:10 -0500 Subject: Commercial or Famous Applicattions.? In-Reply-To: References: Message-ID: On 11/8/10 7:18 PM, Jorge Biquez wrote: > Hello all. > > Newbie question. Sorry. > > Can you mention applications/systems/solutions made with Python that are > well known and used by public in general? ANd that maybe we do not know > they are done with Python? There are several on the Mac: Checkout, a POS program: http://checkoutapp.com/ EagleFiler, a file organizer: http://c-command.com/eaglefiler/ Phynchronicity, a GUI for Fink package manager: http://www.codebykevin.com/phynchronicity.html QuickWho, a whois search tool: http://www.codebykevin.com/quickwho.html I'm also sure there are others that I'm not aware of. --Kevin -- Kevin Walzer Code by Kevin http://www.codebykevin.com From rbotting at csusb.edu Tue Nov 9 10:26:39 2010 From: rbotting at csusb.edu (RJB) Date: Tue, 9 Nov 2010 07:26:39 -0800 (PST) Subject: Help Documenting Python Syntax Message-ID: <4d15eca9-20a5-4ad1-bdd6-f66fb386220b@y2g2000prf.googlegroups.com> I have been trying to redevelop a syntax page for Python at http://cse.csusb.edu/dick/samples/python.syntax.html I would appreciate and encouragement or corrections -- because I know there is at least one gross error in there. By the way, this is part of a suite of language definitions... going back to the 1960's RJBotting Who was PAAAAAR in the early 1980's From tjreedy at udel.edu Tue Nov 9 10:47:45 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 09 Nov 2010 10:47:45 -0500 Subject: Dictionary of lists strange behaviour In-Reply-To: References: Message-ID: On 11/9/2010 9:14 AM, Ciccio wrote: > Hi all, > > hope you can help me understanding why the following happens: > > In [213]: g = {'a': ['a1','a2'], 'b':['b1','b2']} > In [214]: rg = dict.fromkeys(g.keys(),[]) If you rewrite this as bl = [] rg = dict.fromkeys(g.keys(),bl) is the answer any more obvious? > In [215]: rg > Out[215]: {'a': [], 'b': []} > In [216]: rg['a'].append('x') > In [217]: rg > Out[217]: {'a': ['x'], 'b': ['x']} > > What I meant was appending 'x' to the list pointed by the key 'a' in the > dictionary 'rg'. Why rg['b'] is written too? -- Terry Jan Reedy From invalid at invalid.invalid Tue Nov 9 10:53:42 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 9 Nov 2010 15:53:42 +0000 (UTC) Subject: Commercial or Famous Applicattions.? References: Message-ID: On 2010-11-09, Jorge Biquez wrote: > Can you mention applications/systems/solutions made with Python that > are well known and used by public in general? ANd that maybe we do > not know they are done with Python? I'm not sure how much the "public in general" knows about it, but one I ran across recently is OpenERP: http://www.openerp.com/ It's a complete CRM/purchasing/HR/Accouting/Inventory/etc. system for businesses. Other programs I've used that I noticed were written in Python: Freevo (PVR/DVR HTPC media center) bittorrent (the original apps) RedHat's installer and some admin utils. Gentoos "emerge" build system. meld (source code diff/merge tool) skencil (vector drafting program) bitpim (cellphone data synch app) PyNeighborhood (network neighborhood browser) I'm sure there are dozens more that I've used and never realized they were written in Python. Last time I checked IBM/Lenovo computers all came with Python installed, since some of the pre-installed admin/maintenance stuff is written in Python. -- Grant Edwards grant.b.edwards Yow! Are we live or on at tape? gmail.com From darragh.ssa at gmail.com Tue Nov 9 11:04:43 2010 From: darragh.ssa at gmail.com (Kruptein) Date: Tue, 9 Nov 2010 08:04:43 -0800 (PST) Subject: Deditor 0.2.2 References: <6cdb5dd1-1868-4a6e-8b59-5b871f8d412e@42g2000prt.googlegroups.com> Message-ID: <613e4abc-329b-4ab3-8349-b3ec047cb747@r14g2000yqa.googlegroups.com> On Nov 8, 3:01?pm, Jean-Michel Pichavant wrote: > TheSeeker wrote: > > On Nov 6, 7:06 am, Kruptein wrote: > > >> Hey, > > >> I released version 0.2.2 of my pythonic text-editor ?Deditor. > >> It adds the use of projects, a project is a set of files which you can > >> open all at once to make development much faster and easier. > > >> For more information visit launchpad:http://launchpad.net/deditor > > >> I also uploaded a video to introduce you to deditor:http://www.youtube.com/watch?v=hS8xBu-39VI > >> (note: youtube is still processing the file so you might have to wait > >> a bit to see it) > > > Hi, > > I might have missed this, but it seems deditor requires Python above > > 2.5? > > > It would be nice to mention the requirements on the home page > > somewhere. > > > Thanks, > > Duane > > I already point that on the last release. You should really just > consider writing the requirements (python & wx). > > JM I'm going todo that right now! I alswyas forget it :p From tjreedy at udel.edu Tue Nov 9 11:06:09 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 09 Nov 2010 11:06:09 -0500 Subject: Help Documenting Python Syntax In-Reply-To: <4d15eca9-20a5-4ad1-bdd6-f66fb386220b@y2g2000prf.googlegroups.com> References: <4d15eca9-20a5-4ad1-bdd6-f66fb386220b@y2g2000prf.googlegroups.com> Message-ID: On 11/9/2010 10:26 AM, RJB wrote: > I have been trying to redevelop a syntax page for Python at > http://cse.csusb.edu/dick/samples/python.syntax.html Page does not load correctly; had to hit refresh to get entire page. It should specify that this is the syntax for Python 2.5. To me "the Python language" is 3.2. > I would appreciate and encouragement or corrections -- because I know > there is at least one gross error in there. -- Terry Jan Reedy From invalid at invalid.invalid Tue Nov 9 11:14:30 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 9 Nov 2010 16:14:30 +0000 (UTC) Subject: Help Documenting Python Syntax References: <4d15eca9-20a5-4ad1-bdd6-f66fb386220b@y2g2000prf.googlegroups.com> Message-ID: On 2010-11-09, Terry Reedy wrote: > On 11/9/2010 10:26 AM, RJB wrote: >> I have been trying to redevelop a syntax page for Python at >> http://cse.csusb.edu/dick/samples/python.syntax.html > > Page does not load correctly; had to hit refresh to get entire page. > It should specify that this is the syntax for Python 2.5. To me "the > Python language" is 3.2. Nope. I just checked, and it's 2.6.5: $ python Python 2.6.5 (release26-maint, Aug 9 2010, 11:06:44) ;) My question is why bother with 2.5? I would think the logical choices would be 3.2 or 2.7 (or maybe 2.6). -- Grant Edwards grant.b.edwards Yow! I have a TINY BOWL in at my HEAD gmail.com From calderone.jeanpaul at gmail.com Tue Nov 9 11:20:40 2010 From: calderone.jeanpaul at gmail.com (Jean-Paul Calderone) Date: Tue, 9 Nov 2010 08:20:40 -0800 (PST) Subject: udp sockets with python References: Message-ID: <34f2de21-0bdf-46b1-9fef-77717fc56239@r4g2000prj.googlegroups.com> On Nov 9, 5:20?am, Mag Gam wrote: > Hello, > > When measuring round trip time for the UDP echo client/server the C > version is much faster. I was wondering if there is anything I can do > to speed up. > > My current code for client looks like this.... > > sock=socket(AF_INET,SOCK_DGRAM) > for x in range (1000): > ? sock.sendto("foo",(server,port)) > ? a=sock.recv(256) > > sock.close() > > The server code looks like this: > UDPsock=socket(AF_INET,SOCK_DGRAM) > UDPSock.bind(addr) > while 1: > ? m,c=UDPsock,recvfrom(1024) > ? UDPsock.sendto('bar',c) > > UDPsock.close() > > I am measuring the round trip time using tcpdump. The C version is > giving me around 80 microseconds (average) and the python is giving me > close to 300 microseconds (average). Try replacing the hostname in your send calls with an IP address. If you're not passing an IP address here, then the Python version has to do a name lookup for each send, I bet your C version is not. Jean-Paul From franapoli at gmail.com Tue Nov 9 12:19:32 2010 From: franapoli at gmail.com (Ciccio) Date: Tue, 09 Nov 2010 18:19:32 +0100 Subject: Dictionary of lists strange behaviour References: Message-ID: Il 09/11/2010 16:47, Terry Reedy ha scritto: > On 11/9/2010 9:14 AM, Ciccio wrote: >> Hi all, >> >> hope you can help me understanding why the following happens: >> >> In [213]: g = {'a': ['a1','a2'], 'b':['b1','b2']} >> In [214]: rg = dict.fromkeys(g.keys(),[]) > > If you rewrite this as > > bl = [] > rg = dict.fromkeys(g.keys(),bl) > > is the answer any more obvious? It isn't since I erroneously assumed that a clone of the object would be made in both cases. Thanks for your help From franapoli at gmail.com Tue Nov 9 12:23:07 2010 From: franapoli at gmail.com (Ciccio) Date: Tue, 09 Nov 2010 18:23:07 +0100 Subject: Dictionary of lists strange behaviour References: Message-ID: Thank you all, this was timely and helpful. francesco From moura.mario at gmail.com Tue Nov 9 12:32:17 2010 From: moura.mario at gmail.com (macm) Date: Tue, 9 Nov 2010 09:32:17 -0800 (PST) Subject: Learning Pyhton - Functional Programming - How intersect/difference two dict with dict/values? fast! Message-ID: <4d71519e-a232-427f-b4e0-5bae90fc4acb@n32g2000prc.googlegroups.com> Hi Folks, dict1 = {'ab':[[1,2,3,'d3','d4',5],12],'ac':[[1,3,'78a','79b'], 54],'ad': [[56,57,58,59],34], 'ax': [[56,57,58,59],34]} dict2 = {'ab':[[22,2,'a0','42s','c4','d3'],12],'ab':[[2,4,50,42,'c4'], 12],'ac':[[1,3,'79b',45,65,'er4'],54],'ae': [[56,57,58,59],34],'ax': [[9],34]} dict3 = {'ac':[[1,3,67,'gf'],12],'at':[[2,4,50,42,'c4'],12],'as': [[1,3,'79b',45,65,'er4'],54],'ae': [[56,57,58,59],34]} intersect = filter(dict1.has_key, dict2.keys()) intersect result: ['ax', 'ac', 'ab'] expect result dict1 intersection with dict2 {'ac':[1,3,'79b'], 'ab':[2,'d3']} # look last key/value 'ax' (dict1, dict2) even intersec a key but not values from list so not valid and difference from dict3 dict3 = {'ac':[[1,3,67,'gf'],12],'at':[[2,4,50,42,'c4'],12],'as': [[1,3,'79b',45,65,'er4'],54],'ae': [[56,57,58,59],34]} result from (intersect - dict3) {'ac':['79b'], 'ab':[2,'d3']} Thanks in advance! Before someone blame me. Yes I am trying learn python Functional Programming! ; ) Best Regards macm From steve at holdenweb.com Tue Nov 9 12:33:09 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 09 Nov 2010 12:33:09 -0500 Subject: A way to get setup.py to create links instead of copy In-Reply-To: <5ec2edeb-14cf-4c1d-919f-d4246f4af10a@f20g2000yqi.googlegroups.com> References: <5ec2edeb-14cf-4c1d-919f-d4246f4af10a@f20g2000yqi.googlegroups.com> Message-ID: On 11/9/2010 4:18 AM, Geoff Bache wrote: > Hi all, > > One of the things I've always loved about Python (having come from > compiled languages) was the lack of an extra step between changing my > code and running it. > > On my current project, however, I find that I have to install my > Python code with setup.py before it will run. Being used to not having > this step, I easily forget to run setup.py install before they will > run, and then spend time wondering why my changes didn't work. > > So I went into the target directory and replaced the copies with > symbolic links back to the original code. This felt like a hack but > does mean I don't have to install the whole time any more. > > I wonder if there is some standard way to deal with this situation? > Yes, there is. It involves (to a first approximation) understanding the role of sys.path, and its relationship with the PYTHONPATH environment variable. In brief, this tells the interpreter where to look for modules when it is importing. Installation with setup.py is normally reserved for a fairly permanent insertion of the code into your Python distribution, which might have added it for all users. If this is an issue you may want to undo the installation manually by removing its additions to your Python's Lib/site-packages directory. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From tjreedy at udel.edu Tue Nov 9 12:57:28 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 09 Nov 2010 12:57:28 -0500 Subject: Silly newbie question - Caret character (^) In-Reply-To: References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> Message-ID: On 11/9/2010 2:00 AM, Seebs wrote: > Yes, Herb Schildt: > http://www.seebs.net/c/c_tcn4e.html I've been wondering why C programmers keep writing code susceptible to buffer overruns ;=). Your two 'nitpicks' about fflush have both come up on this list as real issues causing people problems. So I agree that it needs to be explained properly and completely as you suggest. -- Terry Jan Reedy From jon.dufresne at gmail.com Tue Nov 9 13:06:39 2010 From: jon.dufresne at gmail.com (Jon Dufresne) Date: Tue, 9 Nov 2010 10:06:39 -0800 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: On Tue, Nov 9, 2010 at 4:30 AM, Roy Smith wrote: > In article , > ?Lawrence D'Oliveiro wrote: > >> In message , Roy Smith wrote: >> >> > On the other hand, if your module's bug is that it in turn imports some >> > other module, which doesn't exist, you'll also get an ImportError. >> >> Does it really matter? Either way, the module is unusable. > > If I understand correctly, he's trying to differentiate between: > > 1) The module is unusable because it's not installed > > 2) The module is unusable because it has a bug in it. > Yes. Case 1 is an acceptable case. In case 1, if the extension module (extension as in extension to my core program) does not have magic.py then the extension adds no behavior in the magic1 portion of the program. However, if the extension does have magic.py but it is buggy (case 2), I want my program to fail. Currently I am doing this using the traceback code suggested in an earlier post. From jon.dufresne at gmail.com Tue Nov 9 13:08:05 2010 From: jon.dufresne at gmail.com (Jon Dufresne) Date: Tue, 9 Nov 2010 10:08:05 -0800 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: On Mon, Nov 8, 2010 at 11:35 PM, Lawrence D'Oliveiro wrote: > In message , Roy Smith wrote: > >> On the other hand, if your module's bug is that it in turn imports some >> other module, which doesn't exist, you'll also get an ImportError. > > Does it really matter? Either way, the module is unusable. In my program it matters. If the module exists but is buggy, then I want to be notified immediately to fix it. However if the module does not exist in an extension module (keyword being extension) then the extensions doesn't add behavior to that part of the program. From __peter__ at web.de Tue Nov 9 13:14:15 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 09 Nov 2010 19:14:15 +0100 Subject: Learning Pyhton - Functional Programming - How intersect/difference two dict with dict/values? fast! References: <4d71519e-a232-427f-b4e0-5bae90fc4acb@n32g2000prc.googlegroups.com> Message-ID: macm wrote: > Hi Folks, > > dict1 = {'ab':[[1,2,3,'d3','d4',5],12],'ac':[[1,3,'78a','79b'], > 54],'ad': [[56,57,58,59],34], 'ax': [[56,57,58,59],34]} > dict2 = {'ab':[[22,2,'a0','42s','c4','d3'],12],'ab':[[2,4,50,42,'c4'], > 12],'ac':[[1,3,'79b',45,65,'er4'],54],'ae': [[56,57,58,59],34],'ax': > [[9],34]} > dict3 = {'ac':[[1,3,67,'gf'],12],'at':[[2,4,50,42,'c4'],12],'as': > [[1,3,'79b',45,65,'er4'],54],'ae': [[56,57,58,59],34]} > intersect = filter(dict1.has_key, dict2.keys()) > intersect > result: > ['ax', 'ac', 'ab'] > > expect result dict1 intersection with dict2 > {'ac':[1,3,'79b'], 'ab':[2,'d3']} # look last key/value 'ax' (dict1, > dict2) even intersec a key but not values from list so not valid > > and difference from dict3 > dict3 = {'ac':[[1,3,67,'gf'],12],'at':[[2,4,50,42,'c4'],12],'as': > [[1,3,'79b',45,65,'er4'],54],'ae': [[56,57,58,59],34]} > > result from (intersect - dict3) > {'ac':['79b'], 'ab':[2,'d3']} > > Thanks in advance! > > Before someone blame me. > > Yes I am trying learn python Functional Programming! ; ) >>> dict((k, v) for k, v in ((k, [a for a in v if a in w]) for k, v, w in ((k, v[0], set(dict2[k][0])) for k, v in dict1.iteritems() if k in dict2)) if v) {'ac': [1, 3, '79b'], 'ab': [2]} Replacing the genexps with map/filter/lambda is left as an exercise. > Before someone blame me. I'm trying to set new standards in readability ;) From tjreedy at udel.edu Tue Nov 9 13:43:43 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 09 Nov 2010 13:43:43 -0500 Subject: Dictionary of lists strange behaviour In-Reply-To: References: Message-ID: On 11/9/2010 12:19 PM, Ciccio wrote: > Il 09/11/2010 16:47, Terry Reedy ha scritto: >> On 11/9/2010 9:14 AM, Ciccio wrote: >>> Hi all, >>> >>> hope you can help me understanding why the following happens: >>> >>> In [213]: g = {'a': ['a1','a2'], 'b':['b1','b2']} >>> In [214]: rg = dict.fromkeys(g.keys(),[]) >> >> If you rewrite this as >> >> bl = [] >> rg = dict.fromkeys(g.keys(),bl) >> >> is the answer any more obvious? > > It isn't since I erroneously assumed that a clone of the object would be > made in both cases. I can see how you might think that, especially if you have experience with other languages where that would be usual. In Python, the general policy is to not copy objects unless explicitly requested. None, False, and True cannot be copied. There is essentially never a reason to copy a number or string or tuple. I believe dict.fromkeys is more usually given None or 0 or '' as value initializer. List *is* useful as an initializer for collecitons.defaultdicts. -- Terry Jan Reedy From msarro at gmail.com Tue Nov 9 14:00:17 2010 From: msarro at gmail.com (Matty Sarro) Date: Tue, 9 Nov 2010 14:00:17 -0500 Subject: An easier way to do this? (spoiler if you're using pyschools for fun) Message-ID: Hey everyone, I'm working on one of the puzzles on pyschools.com, and am trying to figure out if I can make my solution a bit more elegant. def getSumOfLastDigit(numList): sumOfDigits=0 for i in range(0, len(numList)): num=str(numList.pop()) sumOfDigits+=int(num[-1:]) return sumOfDigits Below is the problem. Basically you take the last digit of each number in the list, and add them together. Write a function: getSumOfLastDigit(numList) that takes in a list of positive numbers and returns the sum of all the last digit in the list. *Examples* >>> getSumOfLastDigit([12, 23, 34]) 9 >>> getSumOfLastDigit([2, 3, 4]) 9 >>> getSumOfLastDigit([1, 23, 456]) 10 -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Tue Nov 9 14:09:31 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 9 Nov 2010 11:09:31 -0800 Subject: An easier way to do this? (spoiler if you're using pyschools for fun) In-Reply-To: References: Message-ID: On Tue, Nov 9, 2010 at 11:00 AM, Matty Sarro wrote: > Hey everyone, > I'm working on one of the puzzles on pyschools.com, and am trying to figure > out if I can make my solution a bit more elegant. > > def getSumOfLastDigit(numList): > ??? sumOfDigits=0 > ??? for i in range(0, len(numList)): > ??? ??? num=str(numList.pop()) Just loop over the list directly: for num in numList: num = str(num) > ??? ??? sumOfDigits+=int(num[-1:]) No need for the colon: sumOfDigits+= int(num[-1]) > ??? return sumOfDigits And now for the much simpler math-based solution: def getSumOfLastDigit(numList): return sum(num%10 for num in numList) Cheers, Chris -- http://blog.rebertia.com From __peter__ at web.de Tue Nov 9 14:13:47 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 09 Nov 2010 20:13:47 +0100 Subject: An easier way to do this? (spoiler if you're using pyschools for fun) References: Message-ID: Matty Sarro wrote: > Hey everyone, > I'm working on one of the puzzles on pyschools.com, and am trying to > figure out if I can make my solution a bit more elegant. > > def getSumOfLastDigit(numList): > sumOfDigits=0 > for i in range(0, len(numList)): > num=str(numList.pop()) > sumOfDigits+=int(num[-1:]) > return sumOfDigits > > Below is the problem. Basically you take the last digit of each number in > the list, and add them together. > > Write a function: getSumOfLastDigit(numList) that takes in a list of > positive numbers and returns the sum of all the last digit in the list. > > *Examples* > > >>> getSumOfLastDigit([12, 23, 34]) > 9 > >>> getSumOfLastDigit([2, 3, 4]) > 9 > >>> getSumOfLastDigit([1, 23, 456]) > 10 Loop over a list directly: for n in numlist: # ... Use the modulo (%) operator to find the last digit: last_digit = n % 10 There is a built-in sum() function: sum([1,2,3]) # 6 There is an inlined form of the for-loop called "generator expression" sum(i*i for i in [1,2,3]) # 14 Putting it all together: >>> def gsold(numbers): ... return sum(i%10 for i in numbers) ... >>> gsold([12,23,34]) 9 >>> gsold([2,3,4]) 9 >>> gsold([1,23,456]) 10 Peter From tjreedy at udel.edu Tue Nov 9 14:18:34 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 09 Nov 2010 14:18:34 -0500 Subject: An easier way to do this? (spoiler if you're using pyschools for fun) In-Reply-To: References: Message-ID: On 11/9/2010 2:00 PM, Matty Sarro wrote: > I'm working on one of the puzzles on pyschools.com > , and am trying to figure out if I can make my > solution a bit more elegant. Definitely > def getSumOfLastDigit(numList): > sumOfDigits=0 > for i in range(0, len(numList)): > num=str(numList.pop()) This is an awkward way to iterate through a list ;-) > sumOfDigits+=int(num[-1:]) > return sumOfDigits > Write a function: getSumOfLastDigit(numList) that takes in a list of > positive numbers and returns the sum of all the last digit in the list. > > *Examples* > >>> getSumOfLastDigit([12, 23, 34]) > 9 > >>> getSumOfLastDigit([2, 3, 4]) > 9 > >>> getSumOfLastDigit([1, 23, 456]) > 10 # Straightforward version of what you did def getSumOfLastDigit(numList): sumOfDigits=0 for i in numList: sumOfDigits+=int(str(i)[-1:]) return sumOfDigits print(getSumOfLastDigit([12, 23, 34]), getSumOfLastDigit([2, 3, 4]), getSumOfLastDigit([1, 23, 456]) ) # 9 9 10 # Use generator expression with built-in sum function def getSumOfLastDigit(numList): return sum(int(str(i)[-1:]) for i in numList) print(getSumOfLastDigit([12, 23, 34]), getSumOfLastDigit([2, 3, 4]), getSumOfLastDigit([1, 23, 456]) ) # 9 9 10 -- Terry Jan Reedy From nagle at animats.com Tue Nov 9 15:39:07 2010 From: nagle at animats.com (John Nagle) Date: Tue, 09 Nov 2010 12:39:07 -0800 Subject: Learning Pyhton - Functional Programming - How intersect/difference two dict with dict/values? fast! In-Reply-To: <4d71519e-a232-427f-b4e0-5bae90fc4acb@n32g2000prc.googlegroups.com> References: <4d71519e-a232-427f-b4e0-5bae90fc4acb@n32g2000prc.googlegroups.com> Message-ID: <4cd9b16d$0$1640$742ec2ed@news.sonic.net> On 11/9/2010 9:32 AM, macm wrote: > Hi Folks, > > dict1 = {'ab':[[1,2,3,'d3','d4',5],12],'ac':[[1,3,'78a','79b'], > 54],'ad': [[56,57,58,59],34], 'ax': [[56,57,58,59],34]} > dict2 = {'ab':[[22,2,'a0','42s','c4','d3'],12],'ab':[[2,4,50,42,'c4'], > 12],'ac':[[1,3,'79b',45,65,'er4'],54],'ae': [[56,57,58,59],34],'ax': > [[9],34]} > dict3 = {'ac':[[1,3,67,'gf'],12],'at':[[2,4,50,42,'c4'],12],'as': > [[1,3,'79b',45,65,'er4'],54],'ae': [[56,57,58,59],34]} > intersect = filter(dict1.has_key, dict2.keys()) > intersect > result: > ['ax', 'ac', 'ab'] When you've spent a year maintaining and fixing code written by others, come back and we'll talk. John Nagle From greg.ewing at canterbury.ac.nz Tue Nov 9 15:44:29 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 10 Nov 2010 09:44:29 +1300 Subject: Why "flat is better than nested"? In-Reply-To: References: Message-ID: <8jtq5dF67vU1@mid.individual.net> Lawrence D'Oliveiro wrote: > In message > , rustom > wrote: > >>If you take zen seriously you dont get it >>If you dont take zen seriously you dont get it >>That -- seriously -- is zen > > I don?t get it. I get it. Does that mean that I don't get it? -- Greg From tjreedy at udel.edu Tue Nov 9 15:55:16 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 09 Nov 2010 15:55:16 -0500 Subject: Learning Pyhton - Functional Programming - How intersect/difference two dict with dict/values? fast! In-Reply-To: <4cd9b16d$0$1640$742ec2ed@news.sonic.net> References: <4d71519e-a232-427f-b4e0-5bae90fc4acb@n32g2000prc.googlegroups.com> <4cd9b16d$0$1640$742ec2ed@news.sonic.net> Message-ID: > On 11/9/2010 9:32 AM, macm wrote: >> dict1 = {'ab':[[1,2,3,'d3','d4',5],12],'ac':[[1,3,'78a','79b'], >> 54],'ad': [[56,57,58,59],34], 'ax': [[56,57,58,59],34]} To echo John Nagle's point, if you want non-masochist volunteers to read your code, write something readable like: dict1 = {'ab': [[1,2,3,'d3','d4',5], 12], 'ac': [[1,3,'78a','79b'], 54], 'ad': [[56,57,58,59], 34], 'ax': [[56,57,58,59], 34]} -- Terry Jan Reedy From darcy at druid.net Tue Nov 9 16:03:56 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 9 Nov 2010 16:03:56 -0500 Subject: Learning Pyhton - Functional Programming - How intersect/difference two dict with dict/values? fast! In-Reply-To: References: <4d71519e-a232-427f-b4e0-5bae90fc4acb@n32g2000prc.googlegroups.com> <4cd9b16d$0$1640$742ec2ed@news.sonic.net> Message-ID: <20101109160356.c9ea3ab2.darcy@druid.net> On Tue, 09 Nov 2010 15:55:16 -0500 Terry Reedy wrote: > To echo John Nagle's point, if you want non-masochist volunteers to read > your code, write something readable like: > > dict1 = {'ab': [[1,2,3,'d3','d4',5], 12], > 'ac': [[1,3,'78a','79b'], 54], > 'ad': [[56,57,58,59], 34], > 'ax': [[56,57,58,59], 34]} I have been learning to like this form: dict1 = dict( ab = [[1,2,3,'d3','d4',5], 12], ac = [[1,3,'78a','79b'], 54], ad = [[56,57,58,59], 34], ax = [[56,57,58,59], 34], ) Of course, it only works when all the keys are strings. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From stef.mientki at gmail.com Tue Nov 9 16:09:06 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Tue, 09 Nov 2010 22:09:06 +0100 Subject: JavaScript vs Python In-Reply-To: References: <201011090026.oA90QP1S095565@krusty.intranet.com.mx> Message-ID: <4CD9B872.3020905@gmail.com> On 09-11-2010 10:25, Lawrence D'Oliveiro wrote: > In message , Chris > Rebert wrote: > >> On Mon, Nov 8, 2010 at 10:52 PM, Lawrence D'Oliveiro >> wrote: >> >>> Because JavaScript is actually a decent language in its own right. >> "The Good Parts" of it anyway. > Python, too, has its good parts, you have to admit... And there's a (or even more) Python to JS compilers, I never heard of a JS to Python compiler. cheers, Stef From greg.ewing at canterbury.ac.nz Tue Nov 9 16:09:52 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 10 Nov 2010 10:09:52 +1300 Subject: populating a doubly-subscripted array In-Reply-To: <87aaljmm44.fsf.mdw@metalzone.distorted.org.uk> References: <87aaljmm44.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <8jtrl3FgvdU1@mid.individual.net> Mark Wooding wrote: > What [x] * n does is make a list, whose length is n, and all of whose > entries are precisely the value x. If x itself is a list, then you get > an outer list all of whose entries are the /same/ inner list A reasonably elegant way to fix this is to use list comprehensions for all except the innermost list: ff = [[0.0]*5 for i in xrange(5)] If you're computing heavily with arrays, you might also consider using numpy arrays instead of lists. -- Greg From jjposner at optimum.net Tue Nov 9 16:13:07 2010 From: jjposner at optimum.net (John Posner) Date: Tue, 09 Nov 2010 16:13:07 -0500 Subject: Why "flat is better than nested"? In-Reply-To: <8jtq5dF67vU1@mid.individual.net> References: <8jtq5dF67vU1@mid.individual.net> Message-ID: <4CD9B963.6060709@optimum.net> On 11/9/2010 3:44 PM, Gregory Ewing wrote: >> >> I don?t get it. > > I get it. Does that mean that I don't get it? Yes. As Dr. Feynman said about quantum mechanics. -John From mdw at distorted.org.uk Tue Nov 9 16:14:27 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 09 Nov 2010 21:14:27 +0000 Subject: functions, list, default parameters References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <8ivelpFif1U1@mid.individual.net> <4cca88bc$0$29987$c3e8da3$5496439d@news.astraweb.com> <8j1seqFa1eU2@mid.individual.net> Message-ID: <87tyjqkxn0.fsf.mdw@metalzone.distorted.org.uk> Lawrence D'Oliveiro writes: > In message , Robert Kern > wrote: > > So examining LHS "selectors" is not sufficient for determining > > immutability. > > Yes it is. All your attempts at counterexamples showed is that it is not > necessary, not that it is not sufficient. You've got them the wrong way around. A is sufficient for B if and only if B is true whenever A is true; i.e., it is never the case that A is true and B is false. In this case, we also say that B is necessary for A. See also http://en.wikipedia.org/wiki/Necessary_and_sufficient_condition -- [mdw] From mdw at distorted.org.uk Tue Nov 9 16:21:25 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 09 Nov 2010 21:21:25 +0000 Subject: Silly newbie question - Caret character (^) References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> Message-ID: <87pquekxbe.fsf.mdw@metalzone.distorted.org.uk> Philip Semanchuk writes: > What's funny is that I went looking for a printed copy of the C > standard a few years back and the advice I got was that the cheapest > route was to find a used copy of Schildt's "Annotated ANSI C Standard" > and ignore the annotations. So it serves at least one useful purpose. The book was much cheaper than a copy of the C standard from ANSI or ISO even when it was new. It was a common joke (HHOS) at the time that the difference in price reflected the value of the annotations. (It also has two errors in the actual text of the standard. There's a character missing in the syntax summary, and one page was omitted entirely, replaced by a copy of the previous page: my copy came with a corrected page ineptly glued in at the relevant place.) -- [mdw] From jjposner at optimum.net Tue Nov 9 16:25:51 2010 From: jjposner at optimum.net (John Posner) Date: Tue, 09 Nov 2010 16:25:51 -0500 Subject: Dictionary of lists strange behaviour In-Reply-To: References: Message-ID: <4CD9BC5F.9090707@optimum.net> On 11/9/2010 1:43 PM, Terry Reedy wrote: > ... List *is* useful as an initializer for > collecitons.defaultdicts. And it was useful when several members of this forum helped me to develop a prime-number generator. See http://www.mail-archive.com/python-list at python.org/msg288128.html. (I meant to post this to the "functions, list, default parameters" thread, but never got a round tuit.) -John From duane.kaufman at gmail.com Tue Nov 9 16:36:17 2010 From: duane.kaufman at gmail.com (TheSeeker) Date: Tue, 9 Nov 2010 13:36:17 -0800 (PST) Subject: Deditor 0.2.2 References: <6cdb5dd1-1868-4a6e-8b59-5b871f8d412e@42g2000prt.googlegroups.com> <613e4abc-329b-4ab3-8349-b3ec047cb747@r14g2000yqa.googlegroups.com> Message-ID: <8004a3c1-5c08-430a-b42d-11ca8c1e2f1a@v28g2000prn.googlegroups.com> On Nov 9, 10:04?am, Kruptein wrote: > On Nov 8, 3:01?pm, Jean-Michel Pichavant > wrote: > > > > > > > > > > > TheSeeker wrote: > > > On Nov 6, 7:06 am, Kruptein wrote: > > > >> Hey, > > > >> I released version 0.2.2 of my pythonic text-editor ?Deditor. > > >> It adds the use of projects, a project is a set of files which you can > > >> open all at once to make development much faster and easier. > > > >> For more information visit launchpad:http://launchpad.net/deditor > > > >> I also uploaded a video to introduce you to deditor:http://www.youtube.com/watch?v=hS8xBu-39VI > > >> (note: youtube is still processing the file so you might have to wait > > >> a bit to see it) > > > > Hi, > > > I might have missed this, but it seems deditor requires Python above > > > 2.5? > > > > It would be nice to mention the requirements on the home page > > > somewhere. > > > > Thanks, > > > Duane > > > I already point that on the last release. You should really just > > consider writing the requirements (python & wx). > > > JM > > I'm going todo that right now! I alswyas forget it :p Hi, I was wondering if there was any reason deditor will not work under Windows? I tried to run it and got the following (Python 2.6, wxPython 2.8): Traceback (most recent call last): File "C:\junk\deditor-0.2.2\deditor.py", line 910, in deditor = DEDITOR(None, -1, "") File "C:\junk\deditor-0.2.2\deditor.py", line 101, in __init__ self.initialize() File "C:\junk\deditor-0.2.2\deditor.py", line 342, in initialize self.menu.SetLabel(4,self.menu.GetLabel(4).strip("_") +"\t"+"+".join(self.get _base_config("keys", "ctab").split(","))) File "C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 1136 6, in GetLabel return _core_.MenuBar_GetLabel(*args, **kwargs) wx._core.PyAssertionError: C++ assertion "item" failed at ..\..\src \common\menuc mn.cpp(1125) in wxMenuBarBase::GetLabel(): wxMenuBar::GetLabel(): no such item Thanks, Duane From mdw at distorted.org.uk Tue Nov 9 16:36:52 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 09 Nov 2010 21:36:52 +0000 Subject: subclassing str References: <5dLBo.1024$w8.406@twister2.libero.it> <6048c71a-fba9-4244-9a36-a5d19c8a5516@y23g2000yqd.googlegroups.com> Message-ID: <87lj52kwln.fsf.mdw@metalzone.distorted.org.uk> rantingrick writes: > One thing i love about Python is the fact that it can please almost > all the "religious paradigm zealots" with it's multiple choice > approach to programming. However some of the features that OOP > fundamentalists hold dear in their heart are not always achievable in > a clean manner with Python. Yes you could use a function but that is > not the OOP way. It can be more than just an aesthetic difference. Sometimes it can be nice to extend existing classes to understand additional protocols. For example, suppose you're implementing some object serialization format: it'd be really nice if you could add `serialize' methods to `str', `int', `list' and friends. This is certainly the Smalltalk way. Unfortunately, you can't do it in Python. One option is to implement a subclass which implements the additional protocol. This causes fragmentation: now each protocol wants its own subclass: if you want an object which understands both protocols, you need to mess with multiple inheritance[1] (and, in Python, at least, hope that everyone is using `super' properly to implement upwards delegation). Otherwise you have to do the dispatch yourself, either by hand or by using one of the generic function/multimethod frameworks. [1] At least Python gives you a fighting chance of getting this to work. Java and C# won't countenance multiple inheritance at all, and C++ will botch it all by giving you a separate copy of the common superclass's state for each protocol implementation (what are the chances that everyone decided to use a virtual base class?) /and/ hideously breaking upwards delegation. -- [mdw] From muetted at gmail.com Tue Nov 9 16:45:23 2010 From: muetted at gmail.com (Sana Khan) Date: Tue, 9 Nov 2010 13:45:23 -0800 (PST) Subject: Kareena and Saif Kissing I Kurbaan sex scene | Kareena Topless Kiss | Kurbaan Kiss Message-ID: <9b55ec62-3549-4a79-90f1-e4317dbcf34a@n32g2000prc.googlegroups.com> http://groups.google.com/group/hsfun/t/8c6133cfeac2eff0 From mdw at distorted.org.uk Tue Nov 9 17:09:58 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 09 Nov 2010 22:09:58 +0000 Subject: populating a doubly-subscripted array References: <87aaljmm44.fsf.mdw@metalzone.distorted.org.uk> <8jtrl3FgvdU1@mid.individual.net> Message-ID: <87d3qekv2h.fsf.mdw@metalzone.distorted.org.uk> Gregory Ewing writes: > A reasonably elegant way to fix this is to use list comprehensions > for all except the innermost list: > > ff = [[0.0]*5 for i in xrange(5)] Yes, this is a good approach. I should have suggested something like this as a solution myself, rather than merely explaining the problem. > If you're computing heavily with arrays, you might also consider > using numpy arrays instead of lists. Also a good idea. -- [mdw] From ldo at geek-central.gen.new_zealand Tue Nov 9 17:24:45 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 10 Nov 2010 11:24:45 +1300 Subject: Silly newbie question - Caret character (^) References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> <87pquekxbe.fsf.mdw@metalzone.distorted.org.uk> Message-ID: In message <87pquekxbe.fsf.mdw at metalzone.distorted.org.uk>, Mark Wooding wrote: > The book was much cheaper than a copy of the C standard from ANSI or ISO > even when it was new. It was a common joke (HHOS) at the time that the > difference in price reflected the value of the annotations. Crapware in a book! :) From ldo at geek-central.gen.new_zealand Tue Nov 9 17:32:32 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 10 Nov 2010 11:32:32 +1300 Subject: Silly newbie question - Caret character (^) References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> Message-ID: In message , Terry Reedy wrote: > I've been wondering why C programmers keep writing code susceptible to > buffer overruns ;=). I am continually disappointed with the ?do as I say, not as I do? attitude among people offering up sample code. I remember writing to one contributor to a programming magazine many years ago, about his admonition not to simply copy-and-paste sample code, to point out that he had done exactly that (complete with bug). The main sticking point seems to be error checking; for some reason, writers of sample code seem to believe the code is ?clearer? if you leave this out, when in fact all real-world applications of the illustrated techniques would include the error checks. So what do they end up illustrating? Nothing relevant to the real world. Is this why so many real-world programs fail to check for errors in important places, and segfault or behave unpredictably instead of gracefully reporting a problem? From moura.mario at gmail.com Tue Nov 9 17:41:35 2010 From: moura.mario at gmail.com (macm) Date: Tue, 9 Nov 2010 14:41:35 -0800 (PST) Subject: Learning Pyhton - Functional Programming - How intersect/difference two dict with dict/values? fast! References: <4d71519e-a232-427f-b4e0-5bae90fc4acb@n32g2000prc.googlegroups.com> <4cd9b16d$0$1640$742ec2ed@news.sonic.net> Message-ID: Sorry Mr. Nagle and Folks I had a bad day today. I need forward but with fever, a grasp and headache is hard. You are absolute right, I was rude and I ask your pardon. About my code, sorry I thought was the best way to copy and paste in python console. Best Regards macm On Nov 9, 7:03?pm, "D'Arcy J.M. Cain" wrote: > On Tue, 09 Nov 2010 15:55:16 -0500 > > Terry Reedy wrote: > > To echo John Nagle's point, if you want non-masochist volunteers to read > > your code, write something readable like: > > > dict1 = {'ab': [[1,2,3,'d3','d4',5], 12], > > ? ? ? ? ? 'ac': [[1,3,'78a','79b'], 54], > > ? ? ? ? ? 'ad': [[56,57,58,59], 34], > > ? ? ? ? ? 'ax': [[56,57,58,59], 34]} > > I have been learning to like this form: > > dict1 = dict( > ? ab = [[1,2,3,'d3','d4',5], 12], > ? ac = [[1,3,'78a','79b'], 54], > ? ad = [[56,57,58,59], 34], > ? ax = [[56,57,58,59], 34], > ) > > Of course, it only works when all the keys are strings. > > -- > D'Arcy J.M. Cain ? ? ? ? | ?Democracy is three wolveshttp://www.druid.net/darcy/? ? ? ? ? ? ? ?| ?and a sheep voting on > +1 416 425 1212 ? ? (DoD#0082) ? ?(eNTP) ? | ?what's for dinner. From ldo at geek-central.gen.new_zealand Tue Nov 9 17:43:05 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 10 Nov 2010 11:43:05 +1300 Subject: Silly newbie question - Caret character (^) References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> Message-ID: In message , Terry Reedy wrote: > Your two 'nitpicks' about fflush have both come up on this list as real > issues causing people problems. Cache on disk drives is a bug, not a feature. Performance-wise, it?s fast RAM hobbled by being located on the wrong side of a connection to the CPU that isn?t designed to transfer data at RAM speeds. And of course correctness-wise, it?s another complication in implementing the semantics of OS operations that are supposed to guarantee that data has been saved to persistent storage. From macrocoders at gmail.com Tue Nov 9 17:43:59 2010 From: macrocoders at gmail.com (macro coders) Date: Wed, 10 Nov 2010 00:43:59 +0200 Subject: python script installation wizard Message-ID: i want simple "hello world" script. i want python installer. sample image http://img705.imageshack.us/img705/9430/py2exe.png how do python setup wizard? -- *Www.PythonTR.Org* -macrocoders- -------------- next part -------------- An HTML attachment was scrubbed... URL: From mdw at distorted.org.uk Tue Nov 9 17:51:06 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 09 Nov 2010 22:51:06 +0000 Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> <87aalrjkty.fsf@benfinney.id.au> <8jd3m9Fr55U7@mid.individual.net> <87fwvdb69k.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <878w12kt5x.fsf.mdw@metalzone.distorted.org.uk> Lawrence D'Oliveiro writes: > In message <87fwvdb69k.fsf.mdw at metalzone.distorted.org.uk>, Mark Wooding > wrote: > > for descr, attr, colours in [ > > ('normal', 'image', 'Normal'), > > ('highlighted', 'highlight', 'Highlighted'), > > ('selected', 'select', 'Selected')]: > > colourlist = getattr(MainWindow, 'Colors%sList' % colours) > > ## ... > > But then you lose the ability to match up the bracketing symbols. You're right. I do. > That?s why I put them on lines by themselves. But the bracketing symbols are thoroughly uninteresting! All that putting them on their own lines achieves is to draw attention to the scaffolding at the expense of the building. It's great if you like the Pompidou Centre, I suppose... Besides, any editor worth its salt will highlight bracket mismatches for the reader, or at least get its automatic indentation in a twist if you get the brackets wrong. > Maybe you should look at the code in context > , then you can express some > more opinions on how to improve it. 1. class keyval: `are there official symbolic names for these anywhere?' The gtk.keysyms module contains `Return', `KP_Enter', `Left', `Up', `Right', and `Down'. Question: why are `returnkey' and `enterkey' defined in hex and the others in decimal? 2. The MainWindow class only has the `Window' attribute described in its definition. Apparently there are other attributes as well (the ColorMumbleList family for one, also `LayerDisplay'). Similarly, the LoadedImage class has attributes `Contents' and `FileName', but I see attributes `RowStride', `ImageDrawSize' and `SrcDimensions' used immediately below. 3. In SelectSaveMenu, there's a curious `for' loop: for State in (gtk.STATE_NORMAL,) : # no need for gtk.STATE_INSENSITIVE ## blah Firstly, this is obviously equivalent to `state = gtk.STATE_NORMAL' followed by the loop body (YAGNI). Secondly, the loop is followed by an `#end if' comment. If you're going to write the things, at least get them right! 4. Ahh! I've tracked down where the MainWindow is actually populated. Ugh. The code appears to revel in boilerplate. (For those at home, we're now looking at `SetupMainWindow', specifically at the calls to `DefineScrollingList'.) I count six calls, each nearly (but not quite) identical, of about eleven lines each. Of course, being boilerplate, the similarities visually outweigh the differences, when in fact it's the differences that are interesting. It doesn't help that all of the names of the things involved are so wretchedly verbose. How about the following? def make_listview(label, render, colattr, head, bounds, osc, box): setattr(MainWindow, label + 'Display', DefineScrollingList(getattr(MainWindow, label + 'List'), 0, render, colattr, head, bounds, osc, box) def make_listview_l1(label, head, osc): make_listview(label, None, 'text, head, (160, 160), osc, List1Box) make_listview_l1('Button', 'Buttons', None) make_listview_l1('Layer', 'Button Layer', LayerSelectionChanged) MainWindow.colourlist = {} MainWindow.colourview = {} for head in ['Normal', 'Highlight', 'Select']: MainWindow.colourlist[head] = gtk.ListStore(gobject.TYPE_PYOBJECT) MainWindow.colourview[head] = \ DefineScrollingList(MainWindow.colourlist[head], 0, ColorCellRenderer(), None, head, (120, 120), None, List2Box) make_listview('LoadedColors', ColorCellRenderer(), None, '', (120, 240), None, MiddleBox) Looking at some of the rest of the code, it might (or might not) be worthwhile actually making a class to gather together a list's model and view; subclasses can then vary their individual parameters, and the various colour lists can also keep the various captions with them. (Sometimes a strong separation between model and view is a good thing; this doesn't seem to be one of those times.) 5. Much of the indentation and layout is rather unconventional, though not intolerable. But I found (deep in `SelectSaveMenu'): NewRenderPixels = array.array \ ( "B", FillColor * (ImageRowStride // 4 * ImageBounds[1]) ) to be most disconcerting. Also, I couldn't work out why some parens are indented only two spaces and others are indented the full eight. Oh! It's inconsistent tab/space selection. I'm afraid that about this point I had to get on with some other stuff. I've done enough throwing of stones, so I should point at a glass house of my own so that others can return the favour: http://git.distorted.org.uk/~mdw/tripe/tree The Python code is in `py', `svc' and `mon'. Those who believe PEP 8 is carven in stone will be disappointed. It's a bit... tricky in places. -- [mdw] From ian.g.kelly at gmail.com Tue Nov 9 18:30:40 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 9 Nov 2010 16:30:40 -0700 Subject: python script installation wizard In-Reply-To: References: Message-ID: On Tue, Nov 9, 2010 at 3:43 PM, macro coders wrote: > > i want simple "hello world" script. i want python installer. sample image > http://img705.imageshack.us/img705/9430/py2exe.png how do python setup > wizard? > Use the distutils package in the standard library. You'll need to write a setup.py file for your distribution, and the Windows installer will be created using the "setup.py bdist_wininst" command. See the distutils documentation for the details. -------------- next part -------------- An HTML attachment was scrubbed... URL: From robert.kern at gmail.com Tue Nov 9 19:05:26 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 09 Nov 2010 18:05:26 -0600 Subject: Allowing comments after the line continuation backslash In-Reply-To: <878w12kt5x.fsf.mdw@metalzone.distorted.org.uk> References: <4CCE6FF6.2050408@v.loewis.de> <87aalrjkty.fsf@benfinney.id.au> <8jd3m9Fr55U7@mid.individual.net> <87fwvdb69k.fsf.mdw@metalzone.distorted.org.uk> <878w12kt5x.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On 11/9/10 4:51 PM, Mark Wooding wrote: > Lawrence D'Oliveiro writes: > >> In message<87fwvdb69k.fsf.mdw at metalzone.distorted.org.uk>, Mark Wooding >> wrote: >>> for descr, attr, colours in [ >>> ('normal', 'image', 'Normal'), >>> ('highlighted', 'highlight', 'Highlighted'), >>> ('selected', 'select', 'Selected')]: >>> colourlist = getattr(MainWindow, 'Colors%sList' % colours) >>> ## ... >> >> But then you lose the ability to match up the bracketing symbols. > > You're right. I do. > >> That?s why I put them on lines by themselves. > > But the bracketing symbols are thoroughly uninteresting! All that > putting them on their own lines achieves is to draw attention to the > scaffolding at the expense of the building. It's great if you like the > Pompidou Centre, I suppose... For me, putting the brackets on their own lines (and using a trailing comma) has little to do with increasing readability. It's for making editing easier. Keeping all of the items consistent means that in order to add, delete, or move any item is the same operation everywhere in the list whether it is the first item, last item, or any item in between. -- 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 usenet-nospam at seebs.net Tue Nov 9 19:11:23 2010 From: usenet-nospam at seebs.net (Seebs) Date: 10 Nov 2010 00:11:23 GMT Subject: Pythonic/idiomatic? References: Message-ID: On 2010-11-09, Jean-Michel Pichavant wrote: > One pythonic way to do it, is to use an option parser. That seems like massive overkill -- I don't care about any of the other options. It seems like it'd result in doing more work to get and then extract the options, and most of that would be discarded instnatly. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Tue Nov 9 19:13:38 2010 From: usenet-nospam at seebs.net (Seebs) Date: 10 Nov 2010 00:13:38 GMT Subject: Silly newbie question - Caret character (^) References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> Message-ID: On 2010-11-09, Terry Reedy wrote: > I've been wondering why C programmers keep writing code susceptible to > buffer overruns ;=). Because we're dumb! (Actually, in my defense, my code almost never, if ever, has buffer overruns. I do in some rare cases have truncation issues with sufficiently ridiculous input data.) > Your two 'nitpicks' about fflush have both come up on this list as real > issues causing people problems. So I agree that it needs to be explained > properly and completely as you suggest. Huh. Since Schildt fell out of favor, I've almost never seen people trying to fflush(stdin), and the update rules are weird enough that I don't think I've ever seen anyone try to use it. :) -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From martin at address-in-sig.invalid Tue Nov 9 19:28:25 2010 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Wed, 10 Nov 2010 00:28:25 +0000 (UTC) Subject: Pythonic/idiomatic? References: Message-ID: On Wed, 10 Nov 2010 00:11:23 +0000, Seebs wrote: > On 2010-11-09, Jean-Michel Pichavant wrote: >> One pythonic way to do it, is to use an option parser. > > That seems like massive overkill -- I don't care about any of the other > options. It seems like it'd result in doing more work to get and then > extract the options, and most of that would be discarded instnatly. > I've always used an extended version of getopt() in C. I was so surprised to see that there's nothing equivalent in Java that I wrote my own and was consequently was very pleased to find that Python already has the optparse module. Using it is a no-brainer, particularly as it makes quite a good fist of being self-documenting and of spitting out a nicely formatted chunk of help text when asked to do so. -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From robert.kern at gmail.com Tue Nov 9 19:42:06 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 09 Nov 2010 18:42:06 -0600 Subject: Pythonic/idiomatic? In-Reply-To: References: <87y693cpf6.fsf@benfinney.id.au> <87lj53cnar.fsf@benfinney.id.au> Message-ID: On 11/8/10 8:13 PM, Seebs wrote: > On 2010-11-09, Ben Finney wrote: >> Seebs writes: >>> I think we're stuck with backwards compatibility at least as far as >>> 2.4. > >> Then you don't yet have the ???any??? and ???all??? built-in functions, or the >> tuple-of-prefixes feature of ???str.startswith??? either. Bummer. > > Eww. > >> At which point, the Pythonic thing to do is to convince your >> organisation to use a version of Python that's at least officially >> supported by the PSF :-) > > Unfortunately, we're selling something to people who will explode if > we tell them to upgrade their RHEL4 systems, so we have to work on those. > (There is some tiny hope that we'll be able to move the baseline to RHEL5 > within another two years.) When we deal with such people, we also sell them a recent Python interpreter. :-) -- 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 python.list at tim.thechases.com Tue Nov 9 20:02:33 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 09 Nov 2010 19:02:33 -0600 Subject: Allowing comments after the line continuation backslash In-Reply-To: References: <4CCE6FF6.2050408@v.loewis.de> <87aalrjkty.fsf@benfinney.id.au> <8jd3m9Fr55U7@mid.individual.net> <87fwvdb69k.fsf.mdw@metalzone.distorted.org.uk> <878w12kt5x.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <4CD9EF29.5030500@tim.thechases.com> On 11/09/10 18:05, Robert Kern wrote: > For me, putting the brackets on their own lines (and using a trailing comma) has > little to do with increasing readability. It's for making editing easier. It also makes diff's much easier to read (my big impetus for doing the same as Robert) -tkc From mdw at distorted.org.uk Tue Nov 9 20:39:01 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 10 Nov 2010 01:39:01 +0000 Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> <87aalrjkty.fsf@benfinney.id.au> <8jd3m9Fr55U7@mid.individual.net> <87fwvdb69k.fsf.mdw@metalzone.distorted.org.uk> <878w12kt5x.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <877hgmj6tm.fsf.mdw@metalzone.distorted.org.uk> Tim Chase writes: > On 11/09/10 18:05, Robert Kern wrote: > > For me, putting the brackets on their own lines (and using a > > trailing comma) has little to do with increasing readability. It's > > for making editing easier. > > It also makes diff's much easier to read (my big impetus for doing the > same as Robert) Hmm. That's a good point, actually. I'm not overly fussed about the ease of editing: it doesn't seem especially hard either way. But nice diffs are definitely valuable. Food for thought; thanks. -- [mdw] From afriere at yahoo.co.uk Tue Nov 9 21:06:07 2010 From: afriere at yahoo.co.uk (Asun Friere) Date: Tue, 9 Nov 2010 18:06:07 -0800 (PST) Subject: DTD Parsing Message-ID: <4e7a49ec-1816-46e5-bc51-9f7c88f4d025@37g2000prx.googlegroups.com> Now that PyXML (and thus xmlproc) is defunct, does anyone know any handy modules (apart from re :) for parsing DTDs? From python.list at tim.thechases.com Tue Nov 9 21:23:14 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 09 Nov 2010 20:23:14 -0600 Subject: Allowing comments after the line continuation backslash In-Reply-To: <877hgmj6tm.fsf.mdw@metalzone.distorted.org.uk> References: <4CCE6FF6.2050408@v.loewis.de> <87aalrjkty.fsf@benfinney.id.au> <8jd3m9Fr55U7@mid.individual.net> <87fwvdb69k.fsf.mdw@metalzone.distorted.org.uk> <878w12kt5x.fsf.mdw@metalzone.distorted.org.uk> <877hgmj6tm.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <4CDA0212.7000201@tim.thechases.com> On 11/09/10 19:39, Mark Wooding wrote: > Tim Chase writes: >> It also makes diff's much easier to read > > Hmm. That's a good point, actually. I'm not overly fussed > about the ease of editing: it doesn't seem especially hard > either way. But nice diffs are definitely valuable. Food for > thought; thanks. I find that diffs like for row in ( (item_bar, details_bar), (item_foo, details_foo), + (item_baz, details_baz), ): do_something(row) are much easier/faster to understand instead of for row in ( (item_bar, details_bar), - (item_foo, details_foo)): + (item_foo, details_foo), + (item_baz, details_baz)): do_something(row) -tkc From felipe.bastosn at gmail.com Tue Nov 9 21:44:53 2010 From: felipe.bastosn at gmail.com (Felipe Bastos Nunes) Date: Wed, 10 Nov 2010 00:44:53 -0200 Subject: DTD Parsing In-Reply-To: <4e7a49ec-1816-46e5-bc51-9f7c88f4d025@37g2000prx.googlegroups.com> References: <4e7a49ec-1816-46e5-bc51-9f7c88f4d025@37g2000prx.googlegroups.com> Message-ID: I'd like to know too. I work with java and jdom, but I'm doing personal things in python, and plan to go full python in the next 2 years. Xml is my first option for configuration files and simple storages. 2010/11/10, Asun Friere : > Now that PyXML (and thus xmlproc) is defunct, does anyone know any > handy modules (apart from re :) for parsing DTDs? > -- > http://mail.python.org/mailman/listinfo/python-list > -- Felipe Bastos Nunes From lists at cheimes.de Tue Nov 9 22:02:34 2010 From: lists at cheimes.de (Christian Heimes) Date: Wed, 10 Nov 2010 04:02:34 +0100 Subject: DTD Parsing In-Reply-To: References: <4e7a49ec-1816-46e5-bc51-9f7c88f4d025@37g2000prx.googlegroups.com> Message-ID: Am 10.11.2010 03:44, schrieb Felipe Bastos Nunes: > I'd like to know too. I work with java and jdom, but I'm doing > personal things in python, and plan to go full python in the next 2 > years. Xml is my first option for configuration files and simple > storages. Don't repeat the mistakes of others and use XML as a configuration language. XML isn't meant to be edited by humans. It's my strong believe that XML is great for stuff like data exchange and long time data storage, but not for configuration. Python has much more suited ways to deal with configuration. At work we used to have XML for configuration years ago. Today we use configobj [1], a ini style config system with config specs, validation and many more features. You can define a setting as e.g. list of ints and you actually get a list of ints from the resulting config object. Back to the initial question: I highly recommend LXML for any kind of XML processing, validation, XPath etc. It's super fast, extremely powerful and supports all features of libxml2 and libxslt. It also supports DTD, RelaxNG and XML schema. Christian [1] http://pypi.python.org/pypi/configobj [2] http://pypi.python.org/pypi/lxml From robert.kern at gmail.com Tue Nov 9 22:10:00 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 09 Nov 2010 21:10:00 -0600 Subject: Allowing comments after the line continuation backslash In-Reply-To: <877hgmj6tm.fsf.mdw@metalzone.distorted.org.uk> References: <4CCE6FF6.2050408@v.loewis.de> <87aalrjkty.fsf@benfinney.id.au> <8jd3m9Fr55U7@mid.individual.net> <87fwvdb69k.fsf.mdw@metalzone.distorted.org.uk> <878w12kt5x.fsf.mdw@metalzone.distorted.org.uk> <877hgmj6tm.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On 2010-11-09 19:39 , Mark Wooding wrote: > Tim Chase writes: > >> On 11/09/10 18:05, Robert Kern wrote: >>> For me, putting the brackets on their own lines (and using a >>> trailing comma) has little to do with increasing readability. It's >>> for making editing easier. >> >> It also makes diff's much easier to read (my big impetus for doing the >> same as Robert) > > Hmm. That's a good point, actually. I'm not overly fussed about the > ease of editing: it doesn't seem especially hard either way. It might just be my vim bias. Vim has such *very* easy ways to cut and paste whole lines that not taking the opportunity to permit them seems like a waste. -- 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 afriere at yahoo.co.uk Tue Nov 9 22:36:10 2010 From: afriere at yahoo.co.uk (Asun Friere) Date: Tue, 9 Nov 2010 19:36:10 -0800 (PST) Subject: DTD Parsing References: <4e7a49ec-1816-46e5-bc51-9f7c88f4d025@37g2000prx.googlegroups.com> Message-ID: <06071410-4684-4169-b1f8-0783e34f9062@f16g2000prj.googlegroups.com> On Nov 10, 2:02?pm, Christian Heimes wrote: > Am 10.11.2010 03:44, schrieb Felipe Bastos Nunes: > > > I'd like to know too. I work with java and jdom, but I'm doing > > personal things in python, and plan to go full python in the next 2 > > years. Xml is my first option for configuration files and simple > > storages. > > Don't repeat the mistakes of others and use XML as a configuration > language. XML isn't meant to be edited by humans. Yes but configuration files are not necessarily meant to be edited by humans either! Having said that, I'm actually old school and prefer "setting=value" human editable config files which are easily read into a dict via some code something like this: def read_config (file_obj) : """Reads a config file and returns values as a dictionary Config file is a series of lines in the format: #comment name=value name:value name = value #comment Neither name nor value may contain '#', '=', ':' nor any spaces. """ config = {} nameval = re.compile('^\s*([^=:\s]+)\s*(?:=|:)\s*([^=:\s]*) \s*(?:#.*)?\s*$').search comment = re.compile('^\s*($|#)').search for line in file_obj : if comment(line) : continue try : name, value = nameval(line).groups() except AttributeError : sys.stderr.write('WARNING: suspect entry: %s\n' % line) continue config[name]=value file_obj.close() return config Thanks Christian, I might check out 'configobj', but my needs are rarely more complicated than the above will satisfy. In any case Felipe, whether you intend to use XML for config or not (or for any other reason), there are good tools for XML parsing in python including with DTD validation. Try the modules 'libxml2', 'lxml', or even, if your needs are modest, the poorly named 'HTMLParser'. What I'm looking for instead is something to parse a DTD, such as xmlproc's DTDConsumer. It might even exist in the modules I've mentioned, but I can't find it. In the event, I think I'll use a DTD- >xsd conversion script and then simply use HTMLParser. Unless someone can point me in the way of a simple DTD parser, that is. From afriere at yahoo.co.uk Tue Nov 9 22:42:37 2010 From: afriere at yahoo.co.uk (Asun Friere) Date: Tue, 9 Nov 2010 19:42:37 -0800 (PST) Subject: DTD Parsing References: <4e7a49ec-1816-46e5-bc51-9f7c88f4d025@37g2000prx.googlegroups.com> Message-ID: <49f5805b-416a-4942-a17e-2703e5f79f10@g28g2000pra.googlegroups.com> On Nov 10, 2:02?pm, Christian Heimes wrote: > Back to the initial question: I highly recommend LXML for any kind of > XML processing, validation, XPath etc. Sorry Christian, didn't realise at first that that was a response to MY intial question. But does lxml actually have something for parsing DTDs, as opposed parsing XML and validating it against a DTD? From ldo at geek-central.gen.new_zealand Tue Nov 9 23:01:05 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 10 Nov 2010 17:01:05 +1300 Subject: Commercial or Famous Applicattions.? References: Message-ID: In message , Martin Gregorie wrote: > ...and don't forget getmail, a better behaved replacement for fetchmail. I was just looking this up in the Getmail FAQ, since I didn?t know about the issues with Fetchmail. That?s it, ESR is off my Christmas-card list... From ldo at geek-central.gen.new_zealand Tue Nov 9 23:11:29 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 10 Nov 2010 17:11:29 +1300 Subject: Silly newbie question - Caret character (^) References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> Message-ID: In message , Seebs wrote: > In particular, he's very good at making up complications from whole cloth > which aren't really problems, and then offering "solutions" which show > people a clever trick to work around the problem. (e.g., his elaborate > revelations about how to use feof() in C to work around his failure to > understand how EOF works.) What was sad to me to read was this phrase of yours: ... but rather, takes the shortest path to something that won't get those complaints anymore ... To me, this is the sign of someone who doesn?t really enjoy what they do. Because somebody who cares about what they do would take the trouble to get it right. But if he can?t be bothered, why does he keep doing it? There must be more pleasant ways of getting a meal ticket... From usenet-nospam at seebs.net Tue Nov 9 23:12:30 2010 From: usenet-nospam at seebs.net (Seebs) Date: 10 Nov 2010 04:12:30 GMT Subject: Silly newbie question - Caret character (^) References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> Message-ID: On 2010-11-10, Lawrence D'Oliveiro wrote: > What was sad to me to read was this > phrase of yours: > ... but rather, takes the shortest path to something that won't get > those complaints anymore ... > To me, this is the sign of someone who doesn't really enjoy what they do. Yes. I both write and program, and I do them because I love them. If I won the lottery tomorrow (and hey, my chances are only very very slightly lower than everyone else's), I wouldn't stop programming or writing. I might change my focus some, but both of them are things I'd keep doing. > Because somebody who cares about what they do would take the trouble to get > it right. But if he can't be bothered, why does he keep doing it? There must > be more pleasant ways of getting a meal ticket... It's hard to say. I get the feeling sometimes that he's one of the people to whom programming is sort-of-fun, but not fun when you have to get all persnickety about it. Similarly, writing is fun if you're getting praised for it, but dealing with criticism is harder. (Trust me, I know of this; I have gotten a fair number of corrections over the years.) That said, I suspect he's made a fairly large amount of money; multiple bestsellers is a pretty good way to make a decent bit of pocket change. I may have my gripes about Python, but I will say this: The Python community seems full of people who are passionate about writing good code. I would much rather be in a community of people who care a lot about how I should do things, but I think they're wrong, than about people who figure anything that the interpreter accepts is fine. I can learn from people I disagree with, but not from people who don't care. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From drsalists at gmail.com Tue Nov 9 23:41:08 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 9 Nov 2010 20:41:08 -0800 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <87mxpp3u3i.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On Thu, Nov 4, 2010 at 10:45 AM, Tim Harig wrote: > I also looked at F# and Scala; but, neither are really applicable on my > chosen platform. With F# being such a new language, I suspect that it > borrowed its indent practices either from Haskell or from Python. > I'm pretty sure F# gets its whitespace conventions from the ML family of (very interesting) languages. I believe F# is based largely on Objective Caml. http://stromberg.dnsalias.org/~strombrg/significant-whitespace.html -------------- next part -------------- An HTML attachment was scrubbed... URL: From wuwei23 at gmail.com Wed Nov 10 00:08:35 2010 From: wuwei23 at gmail.com (alex23) Date: Tue, 9 Nov 2010 21:08:35 -0800 (PST) Subject: Why "flat is better than nested"? References: <8jtq5dF67vU1@mid.individual.net> Message-ID: <48b37d9f-25de-45e5-864c-90ef7cfb4782@e26g2000vbz.googlegroups.com> Gregory Ewing wrote: > I get it. Does that mean that I don't get it? Mu. From stefan_ml at behnel.de Wed Nov 10 00:11:04 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 10 Nov 2010 06:11:04 +0100 Subject: DTD Parsing In-Reply-To: <49f5805b-416a-4942-a17e-2703e5f79f10@g28g2000pra.googlegroups.com> References: <4e7a49ec-1816-46e5-bc51-9f7c88f4d025@37g2000prx.googlegroups.com> <49f5805b-416a-4942-a17e-2703e5f79f10@g28g2000pra.googlegroups.com> Message-ID: Asun Friere, 10.11.2010 04:42: > On Nov 10, 2:02 pm, Christian Heimes wrote: > >> Back to the initial question: I highly recommend LXML for any kind of >> XML processing, validation, XPath etc. > > Sorry Christian, didn't realise at first that that was a response to > MY intial question. But does lxml actually have something for parsing > DTDs, as opposed parsing XML and validating it against a DTD? What's your interest in parsing a DTD if you're not up to validating XML? Stefan From afriere at yahoo.co.uk Wed Nov 10 00:41:36 2010 From: afriere at yahoo.co.uk (Asun Friere) Date: Tue, 9 Nov 2010 21:41:36 -0800 (PST) Subject: DTD Parsing References: <4e7a49ec-1816-46e5-bc51-9f7c88f4d025@37g2000prx.googlegroups.com> <49f5805b-416a-4942-a17e-2703e5f79f10@g28g2000pra.googlegroups.com> Message-ID: On Nov 10, 4:11?pm, Stefan Behnel wrote: > What's your interest in parsing a DTD if you're not up to validating XML? Spitting out boilerplate code. Just at the moment I'm creating a stub XSLT sheet, which creates a template per element (from a 3rd party DTD with 143 elements, yuk!) containing nothing more than a apply-templates line listing all possible child elements and a comment saying 'NOT IMPLEMENTED: %s' % element_name. This saves not only typing, but helps me work through and guards against any clumsy oversight on my part in writing a translation sheet for an IMO overly large schema. A few years back I used a similar technique to write some boiler plate python code where xml was isomorphically represented on a class per element basis (which will no doubt offend some people's sense of generalisation, but is none the less an interesting way to work with XML). While I'm here and just for the record, (as I don't imagine anyone would want to use the code I posted above), the line "file_obj.close()" has no place in a function which is passed an open file_object. My apologies. From aioe.org at technicalbloke.com Wed Nov 10 00:45:35 2010 From: aioe.org at technicalbloke.com (r0g) Date: Wed, 10 Nov 2010 05:45:35 +0000 Subject: Class extension confusion :( Message-ID: I have a subclass of BaseHHTPRequestHandler which uses a dictonary "paths" and a function "api_call" which are defined in the main namespace of the module. I'd rather I was able to pass these object to the constructor and store them as data attributes "self.paths" and "self.api_call" but I'm not sure how to do that properly. My understanding is that one may extend a constructor by defining it's __init__ method, calling the parents constructor and then adding ones own attributes to taste. What I don't understand is where or how I am supposed to get these extra constructor arguments into the class given that I don't instantiate it myself, it is seemingly instantiated by HTTPServer class that I pass it to e.g. httpd = HTTPServer(server_address, PlainAJAXRequestHandler) I wondered if I ought to instantiate an instance of PlainAJAXRequestHandler, set the attributes (either manually or by extending it's constructor) and pass that to HTTPServer but I figured it expects a class not an instance as it probably wants to spawn one instance for each request so that would be a non starter. Might I need to subclass HTTPServer, find the bit that instantiates the request handler and override that so it passes it's constructor more parameters? Right now I'm pretty confused, can somebody please tell me how I might accomplish this, what I'm failing to grasp or point me to the docs that explain it - I've spent the last hour or two plowing through docs to no avail, I guess it's a case of keyword ignorance on my part! Code follows... Thanks for reading! Roger. class PlainAJAXRequestHandler(BaseHTTPRequestHandler): paths = { "/": pages.main, "/jqtest/": pages.jqtest } def do_GET(self): # Handle JSON api calls if self.path[:6] == "/ajax?": getvars = urlparse.parse_qs( self.path[6:] ) api_key = getvars[ "api" ][0] json_string = getvars[ "qry" ][0] json_object = json.loads( json_string ) response = api_call( api_key, json_object ) if response: self.send_response(200) self.send_header("Content-type", "application/json") self.end_headers() self.wfile.write( response ) else: self.send_response(404) self.end_headers() return # Handle web pages try: page = self.paths[self.path]() except KeyError: self.send_response(404) self.end_headers() self.wfile.write( "404 - Document not found!" ) return self.send_response(200) self.send_header("Content-type", "text/html") self.end_headers() self.wfile.write( page ) return From stefan_ml at behnel.de Wed Nov 10 01:00:54 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 10 Nov 2010 07:00:54 +0100 Subject: DTD Parsing In-Reply-To: References: <4e7a49ec-1816-46e5-bc51-9f7c88f4d025@37g2000prx.googlegroups.com> <49f5805b-416a-4942-a17e-2703e5f79f10@g28g2000pra.googlegroups.com> Message-ID: Asun Friere, 10.11.2010 06:41: > On Nov 10, 4:11 pm, Stefan Behnel wrote: > >> What's your interest in parsing a DTD if you're not up to validating XML? > > Spitting out boilerplate code. >[...] > A few years back I used a similar technique to write some boiler plate > python code where xml was isomorphically represented on a class per > element basis (which will no doubt offend some people's sense of > generalisation, but is none the less an interesting way to work with > XML). Give lxml.objectify a try. It doesn't use DTDs, but does what you want. There are also some other similar tools like gnosis.objectify or Amara. I never benchmarked them in comparison, but I'd be surprised if lxml.objectify wasn't the fastest. I'd be interested in seeing the margin, though, in case anyone wants to give it a try. It's generally a good idea to state what you want to achieve, rather than just describing the failure of an intermediate step of one possible path towards your hidden goal. This list has a huge history of finding shortcuts that the OPs didn't think of. Stefan From aioe.org at technicalbloke.com Wed Nov 10 01:14:56 2010 From: aioe.org at technicalbloke.com (r0g) Date: Wed, 10 Nov 2010 06:14:56 +0000 Subject: DTD Parsing References: <4e7a49ec-1816-46e5-bc51-9f7c88f4d025@37g2000prx.googlegroups.com> <06071410-4684-4169-b1f8-0783e34f9062@f16g2000prj.googlegroups.com> Message-ID: On 10/11/10 03:36, Asun Friere wrote: > On Nov 10, 2:02 pm, Christian Heimes wrote: >> Am 10.11.2010 03:44, schrieb Felipe Bastos Nunes: >> >>> I'd like to know too. I work with java and jdom, but I'm doing >>> personal things in python, and plan to go full python in the next 2 >>> years. Xml is my first option for configuration files and simple >>> storages. >> >> Don't repeat the mistakes of others and use XML as a configuration >> language. XML isn't meant to be edited by humans. > > Yes but configuration files are not necessarily meant to be edited by > humans either! > > Having said that, I'm actually old school and prefer "setting=value" > human editable config files which are easily read into a dict via some > code something like this: > Me too when possible, TBH if I only needed strings and there was no pressing security issue I'd just do this... config = {} for line in (open("config.txt", 'r')): if len(line) > 0 and line[0] <> "#": param, value = line.rstrip().split("=",1) config[param] = value There is a place for XML settings though, they're nice and portable and for some apps you probably don't want end users editing their configurations by hand in a text editor anyway, you would prefer them to use the nice consistency preserving config interface you have lovingly built for them. You have built them a nice GUI config interface haven't you ??? ;) Roger From ldo at geek-central.gen.new_zealand Wed Nov 10 01:20:40 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 10 Nov 2010 19:20:40 +1300 Subject: Silly newbie question - Caret character (^) References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> Message-ID: In message , Seebs wrote: > I may have my gripes about Python, but I will say this: The Python > community seems full of people who are passionate about writing good code. And they know how to write good code in other languages, not just Python. In other words, they know programming, not just Python programming. You see that come through a lot of the time, when a discussion goes off- track like this. :) From ldo at geek-central.gen.new_zealand Wed Nov 10 01:26:50 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 10 Nov 2010 19:26:50 +1300 Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> <87aalrjkty.fsf@benfinney.id.au> <8jd3m9Fr55U7@mid.individual.net> <87fwvdb69k.fsf.mdw@metalzone.distorted.org.uk> <878w12kt5x.fsf.mdw@metalzone.distorted.org.uk> Message-ID: In message , Robert Kern wrote: > For me, putting the brackets on their own lines (and using a trailing > comma) has little to do with increasing readability. It's for making > editing easier. Keeping all of the items consistent means that in order to > add, delete, or move any item is the same operation everywhere in the list > whether it is the first item, last item, or any item in between. Yup, I like to do that when there?s nothing special about the last item in the list. Sometimes there is (e.g. an enumeration entry naming the number of values in the enumeration, or an all-zero sentinel marking the end of a list), in which case I omit the comma to indicate that nothing should come afterwards. I remember an early experience with JavaScript (back in the days of Netscape versus Internet Explorer 5.1 on a Mac), when I found that constructing a list in this way wasn?t working in IE: turned out it was inserting some kind of extra phantom list item after that last comma. Sigh... From ldo at geek-central.gen.new_zealand Wed Nov 10 01:48:49 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 10 Nov 2010 19:48:49 +1300 Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> <87aalrjkty.fsf@benfinney.id.au> <8jd3m9Fr55U7@mid.individual.net> <87fwvdb69k.fsf.mdw@metalzone.distorted.org.uk> <878w12kt5x.fsf.mdw@metalzone.distorted.org.uk> Message-ID: In message <878w12kt5x.fsf.mdw at metalzone.distorted.org.uk>, Mark Wooding wrote: > Lawrence D'Oliveiro writes: > >> Maybe you should look at the code in context >> , then you can express some >> more opinions on how to improve it. > > 1. class keyval: `are there official symbolic names for these > anywhere?' The gtk.keysyms module contains `Return', `KP_Enter', > `Left', `Up', `Right', and `Down'. Thanks, that?s useful. I couldn?t find mention of such in the documentation anywhere. > Question: why are `returnkey' and `enterkey' defined in hex and the > others in decimal? Can?t remember now. Does it matter? > 2. The MainWindow class only has the `Window' attribute described in > its definition. Apparently there are other attributes as well (the > ColorMumbleList family for one, also `LayerDisplay'). Similarly, > the LoadedImage class has attributes `Contents' and `FileName', but > I see attributes `RowStride', `ImageDrawSize' and `SrcDimensions' > used immediately below. These are really just namespaces, one for the GUI context and the other for the image data. > 3. In SelectSaveMenu, there's a curious `for' loop: > > for State in (gtk.STATE_NORMAL,) : # no need for > gtk.STATE_INSENSITIVE > ## blah > > Firstly, this is obviously equivalent to `state = gtk.STATE_NORMAL' > followed by the loop body (YAGNI). It?s a tuple of one element. It used to be a tuple of two, and there is the possibility it might need to become that again (as intimated at in the attached comment). That?s why it stays a tuple. > 4. Ahh! I've tracked down where the MainWindow is actually > populated. Ugh. The code appears to revel in boilerplate. (For > those at home, we're now looking at `SetupMainWindow', specifically > at the calls to `DefineScrollingList'.) I count six calls, each > nearly (but not quite) identical, of about eleven lines each. Could be worse. Imagine if I had written out the 30 lines of that function out each time instead. > Of course, being boilerplate, the similarities visually outweigh the > differences, when in fact it's the differences that are > interesting. That is generally how code reuse works. All the ?boilerplate? is in the function definition, so I just have to call it parameterized by the differences appropriate to each instance. > It doesn't help that all of the names of the things involved are so > wretchedly verbose. Oh please, no. Since when are explanatory names ?wretchedly verbose?? > How about the following? > > def make_listview_l1 ... And what, pray tell, is the significance of the name ?make_listview_l1?? If there is something I would describe as ?wretched?, it is the use of random numerical suffixes like this. > Looking at some of the rest of the code, it might (or might not) be > worthwhile actually making a class to gather together a list's model > and view; subclasses can then vary their individual parameters, and > the various colour lists can also keep the various captions with > them. Most of that variation is already handled without the limitations of thinking in classes. For example, selection of a colour in all three lists is handled through a single EditColor routine. And of course you?ve already seen how a single DefineScrollingList routine can be used to set up all the scrolling lists used in this GUI. > 5. Much of the indentation and layout is rather unconventional, though > not intolerable. But I found (deep in `SelectSaveMenu'): > > NewRenderPixels = array.array \ > ( > "B", > FillColor > * > (ImageRowStride // 4 * ImageBounds[1]) > ) > > to be most disconcerting. Is the structure of the expression not apparent to you? You?d probably need plenty of fresh air after something like this, then: PatternArray = array.array \ ( "I", 16 * (16 * (Light,) + 16 * (Dark,)) + 16 * (16 * (Dark,) + 16 * (Light,)) ) > Also, I couldn't work out why some parens are indented only two > spaces and others are indented the full eight. Eight?? You mean four. See, this is why I should probably stop using tabs... From ldo at geek-central.gen.new_zealand Wed Nov 10 01:53:58 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 10 Nov 2010 19:53:58 +1300 Subject: Am I The Only One Who Keeps Reading =?UTF-8?B?4oCcTnVtcHnigJ0gYXMg4oCcTnVtcHR54oCdPw==?= Message-ID: Sorry... From ian.g.kelly at gmail.com Wed Nov 10 02:36:37 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 10 Nov 2010 00:36:37 -0700 Subject: DTD Parsing In-Reply-To: References: <4e7a49ec-1816-46e5-bc51-9f7c88f4d025@37g2000prx.googlegroups.com> <06071410-4684-4169-b1f8-0783e34f9062@f16g2000prj.googlegroups.com> Message-ID: On 11/9/2010 11:14 PM, r0g wrote: > Me too when possible, TBH if I only needed strings and there was no > pressing security issue I'd just do this... > > config = {} > for line in (open("config.txt", 'r')): > if len(line) > 0 and line[0] <> "#": > param, value = line.rstrip().split("=",1) > config[param] = value That's five whole lines of code. Why go to all that trouble when you can just do this: import config I kid, but only partially. Where this really shines is when you're prototyping something and you need to configure complex object hierarchies. No need to spend time writing parsers to generate the hierarchies; you just construct the objects directly in the config. When the project becomes mature enough that configuration security is a concern, then you can replace the config with XML or whatever, and in the meantime you can focus on more important things, like the actual project. Cheers, Ian From aioe.org at technicalbloke.com Wed Nov 10 03:05:27 2010 From: aioe.org at technicalbloke.com (r0g) Date: Wed, 10 Nov 2010 08:05:27 +0000 Subject: DTD Parsing References: <4e7a49ec-1816-46e5-bc51-9f7c88f4d025@37g2000prx.googlegroups.com> <06071410-4684-4169-b1f8-0783e34f9062@f16g2000prj.googlegroups.com> Message-ID: On 10/11/10 07:36, Ian Kelly wrote: > On 11/9/2010 11:14 PM, r0g wrote: >> Me too when possible, TBH if I only needed strings and there was no >> pressing security issue I'd just do this... >> >> config = {} >> for line in (open("config.txt", 'r')): >> if len(line) > 0 and line[0] <> "#": >> param, value = line.rstrip().split("=",1) >> config[param] = value > > That's five whole lines of code. Why go to all that trouble when you can > just do this: > > import config > Heh, mainly because I figure the config module will have a lot more options than I have use for right now and therefore the docs will take me longer to read than I will save by not just typing in the above ;) Having said that, you've just prompted me to take a look... there goes another 10 minutes of my life! Roger From landimatte at gmail.com Wed Nov 10 03:06:48 2010 From: landimatte at gmail.com (Matteo Landi) Date: Wed, 10 Nov 2010 09:06:48 +0100 Subject: An easier way to do this? (spoiler if you're using pyschools for fun) In-Reply-To: References: Message-ID: I agree with Peter: * iterate over the list directly * use %10 instead of string conversion + slice (*) use genexps Good luck, Matteo On Tue, Nov 9, 2010 at 8:18 PM, Terry Reedy wrote: > On 11/9/2010 2:00 PM, Matty Sarro wrote: > >> I'm working on one of the puzzles on pyschools.com >> , and am trying to figure out if I can make my >> solution a bit more elegant. > > Definitely > >> def getSumOfLastDigit(numList): >> ? ? sumOfDigits=0 >> ? ? for i in range(0, len(numList)): >> ? ? ? ? num=str(numList.pop()) > > This is an awkward way to iterate through a list ;-) > >> ? ? ? ? sumOfDigits+=int(num[-1:]) >> ? ? return sumOfDigits > >> Write a function: getSumOfLastDigit(numList) that takes in a list of >> positive numbers and returns the sum of all the last digit in the list. >> >> *Examples* >> ? ?>>> ?getSumOfLastDigit([12, ?23, ?34]) >> ? ?9 >> ? ?>>> ?getSumOfLastDigit([2, ?3, ?4]) >> ? ?9 >> ? ?>>> ?getSumOfLastDigit([1, ?23, ?456]) >> ? ?10 > > # Straightforward version of what you did > > def getSumOfLastDigit(numList): > ? ?sumOfDigits=0 > ? ?for i in numList: > ? ? ? ?sumOfDigits+=int(str(i)[-1:]) > ? ?return sumOfDigits > > print(getSumOfLastDigit([12, 23, 34]), > ? ? ?getSumOfLastDigit([2, 3, 4]), > ? ? ?getSumOfLastDigit([1, 23, 456]) ) > # 9 9 10 > > # Use generator expression with built-in sum function > > def getSumOfLastDigit(numList): > ? ?return sum(int(str(i)[-1:]) for i in numList) > > print(getSumOfLastDigit([12, 23, 34]), > ? ? ?getSumOfLastDigit([2, 3, 4]), > ? ? ?getSumOfLastDigit([1, 23, 456]) ) > # 9 9 10 > > -- > Terry Jan Reedy > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Matteo Landi http://www.matteolandi.net/ From afriere at yahoo.co.uk Wed Nov 10 03:22:26 2010 From: afriere at yahoo.co.uk (Asun Friere) Date: Wed, 10 Nov 2010 00:22:26 -0800 (PST) Subject: DTD Parsing References: <4e7a49ec-1816-46e5-bc51-9f7c88f4d025@37g2000prx.googlegroups.com> <49f5805b-416a-4942-a17e-2703e5f79f10@g28g2000pra.googlegroups.com> Message-ID: <1a5c04df-be05-4e8e-858a-6124cd911770@29g2000prb.googlegroups.com> On Nov 10, 5:00?pm, Stefan Behnel wrote: > Give lxml.objectify a try. It doesn't use DTDs, but does what you want. Yes I should take the time to familiarise myself with the lxml API in general. I mostly use libxml2 and libxslt nowadays. For simple stuff (like this) I use a StateParser which is your common-or-garden variety State Pattern built on HTMLParser. (For the record it took 3 trivial state definitions and one hackish one :) However, my issue was not with any particular in any particular python technology for XML processing, but with eating a DTD. Once it's in xsd, it's all downhill from there! So the answer to my question turned out to be dtd2xsd.pl :) > It's generally a good idea to state what you want to achieve, rather than > just describing the failure of an intermediate step of one possible path > towards your hidden goal. This list has a huge history of finding shortcuts > that the OPs didn't think of. It's very simple really. I would like to know whether there is some generally used DTD parser around which could function as a replacement for xmlproc's DTDParser/DTDConsumer, the existence of which might have evaded my attention. I would still like to know. Without wanting to appear ungrateful, I'm not after any shortcut to any goal, hidden or otherwise, nor is the reason I want a DTD Parser (I only told you because you asked so nicely) strictly pertinent to my question. I simply meant to ask, precisely what I did ask. From afriere at yahoo.co.uk Wed Nov 10 03:27:51 2010 From: afriere at yahoo.co.uk (Asun Friere) Date: Wed, 10 Nov 2010 00:27:51 -0800 (PST) Subject: DTD Parsing References: <4e7a49ec-1816-46e5-bc51-9f7c88f4d025@37g2000prx.googlegroups.com> <06071410-4684-4169-b1f8-0783e34f9062@f16g2000prj.googlegroups.com> Message-ID: <6e32203f-b4e2-4466-ac05-e02800fc16dd@r31g2000prg.googlegroups.com> On Nov 10, 6:36?pm, Ian Kelly wrote: > That's five whole lines of code. ?Why go to all that trouble when you > can just do this: > > import config > > I kid, but only partially. ? For myself, generally because I only become aware of the module, or the module is only written after I written some stuff myself. I wrote a Date object before the standard one either existed or I knew of it and I'll keep on using it till you pry it from my cold ... on 2nd thoughts don't pry, just let me use it. From geoff.bache at gmail.com Wed Nov 10 03:33:29 2010 From: geoff.bache at gmail.com (Geoff Bache) Date: Wed, 10 Nov 2010 00:33:29 -0800 (PST) Subject: A way to get setup.py to create links instead of copy References: <5ec2edeb-14cf-4c1d-919f-d4246f4af10a@f20g2000yqi.googlegroups.com> Message-ID: <7e132838-91eb-4958-8acf-e305d77b4d03@r14g2000yqa.googlegroups.com> On Nov 9, 6:33?pm, Steve Holden wrote: > On 11/9/2010 4:18 AM, Geoff Bache wrote: > > > Hi all, > > > One of the things I've always loved about Python (having come from > > compiled languages) was the lack of an extra step between changing my > > code and running it. > > > On my current project, however, I find that I have to install my > > Python code with setup.py before it will run. Being used to not having > > this step, I easily forget to run setup.py install before they will > > run, and then spend time wondering why my changes didn't work. > > > So I went into the target directory and replaced the copies with > > symbolic links back to the original code. This felt like a hack but > > does mean I don't have to install the whole time any more. > > > I wonder if there is some standard way to deal with this situation? > > Yes, there is. It involves (to a first approximation) understanding the > role of sys.path, and its relationship with the PYTHONPATH environment > variable. In brief, this tells the interpreter where to look for modules > when it is importing. > > Installation with setup.py is normally reserved for a fairly permanent > insertion of the code into your Python distribution, which might have > added it for all users. If this is an issue you may want to undo the > installation manually by removing its additions to your Python's > Lib/site-packages directory. > Hi Steve, I think I understand this stuff fairly well. I have my own Python installation (using virtualenv) so I'm not affecting anyone else. The problem is that my program runs from the command line, and is tested via other programs that call it as a subprocess, and don't expect to have to invoke Python explicitly. It does not work with the default Python on my system, which is a too old version, so relies on the "#!" line at the top to be correct. As I cannot hardcode this in my source tree, it seems difficult to make it runnable from the source tree. Incidentally, I'm interested that you say setup.py is normally reserved for a permanent installation. I've run into many Python programs, including quite well known ones, which did not appear to be runnable directly from the download or source tree, but required running setup.py before they would work. Regards, Geoff From tjreedy at udel.edu Wed Nov 10 04:24:36 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 10 Nov 2010 04:24:36 -0500 Subject: Silly newbie question - Caret character (^) In-Reply-To: References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> Message-ID: On 11/9/2010 7:13 PM, Seebs wrote: > On 2010-11-09, Terry Reedy wrote: >> I've been wondering why C programmers keep writing code susceptible to >> buffer overruns ;=). > > Because we're dumb! > > (Actually, in my defense, my code almost never, if ever, has buffer > overruns. I do in some rare cases have truncation issues with sufficiently > ridiculous input data.) I was referring to Schildt using gets() all the time and thereby teaching new C generations to do he same. -- Terry Jan Reedy From ldo at geek-central.gen.new_zealand Wed Nov 10 04:47:57 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 10 Nov 2010 22:47:57 +1300 Subject: Learning Pyhton - Functional Programming - How intersect/difference two dict with dict/values? fast! References: <4d71519e-a232-427f-b4e0-5bae90fc4acb@n32g2000prc.googlegroups.com> <4cd9b16d$0$1640$742ec2ed@news.sonic.net> Message-ID: In message , Terry Reedy wrote: > To echo John Nagle's point, if you want non-masochist volunteers to read > your code, write something readable like: > > dict1 = {'ab': [[1,2,3,'d3','d4',5], 12], > 'ac': [[1,3,'78a','79b'], 54], > 'ad': [[56,57,58,59], 34], > 'ax': [[56,57,58,59], 34]} How come Python itself doesn?t display things that way? From ldo at geek-central.gen.new_zealand Wed Nov 10 04:50:02 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 10 Nov 2010 22:50:02 +1300 Subject: How to test if a module exists? References: Message-ID: In message , Jon Dufresne wrote: > On Mon, Nov 8, 2010 at 11:35 PM, Lawrence D'Oliveiro ... I see that you published my unobfuscated e-mail address on USENET for all to see. I obfuscated it for a reason, to keep the spammers away. I'm assuming this was a momentary lapse of judgement, for which I expect an apology. Otherwise, it becomes grounds for an abuse complaint to your ISP. From paul.nospam at rudin.co.uk Wed Nov 10 04:51:16 2010 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Wed, 10 Nov 2010 09:51:16 +0000 Subject: Learning Pyhton - Functional Programming - How intersect/difference two dict with dict/values? fast! References: <4d71519e-a232-427f-b4e0-5bae90fc4acb@n32g2000prc.googlegroups.com> <4cd9b16d$0$1640$742ec2ed@news.sonic.net> Message-ID: <87tyjpy0a3.fsf@rudin.co.uk> Lawrence D'Oliveiro writes: > In message , Terry Reedy > wrote: > >> To echo John Nagle's point, if you want non-masochist volunteers to read >> your code, write something readable like: >> >> dict1 = {'ab': [[1,2,3,'d3','d4',5], 12], >> 'ac': [[1,3,'78a','79b'], 54], >> 'ad': [[56,57,58,59], 34], >> 'ax': [[56,57,58,59], 34]} > > How come Python itself doesn?t display things that way? try: pprint.pprint(dict1) From __peter__ at web.de Wed Nov 10 04:52:40 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 10 Nov 2010 10:52:40 +0100 Subject: Class extension confusion :( References: Message-ID: r0g wrote: > I have a subclass of BaseHHTPRequestHandler which uses a dictonary > "paths" and a function "api_call" which are defined in the main > namespace of the module. I'd rather I was able to pass these object to > the constructor and store them as data attributes "self.paths" and > "self.api_call" but I'm not sure how to do that properly. My > understanding is that one may extend a constructor by defining it's > __init__ method, calling the parents constructor and then adding ones > own attributes to taste. What I don't understand is where or how I am > supposed to get these extra constructor arguments into the class given > that I don't instantiate it myself, it is seemingly instantiated by > HTTPServer class that I pass it to e.g. > > httpd = HTTPServer(server_address, PlainAJAXRequestHandler) > > I wondered if I ought to instantiate an instance of > PlainAJAXRequestHandler, set the attributes (either manually or by > extending it's constructor) and pass that to HTTPServer but I figured it > expects a class not an instance as it probably wants to spawn one > instance for each request so that would be a non starter. Might I need > to subclass HTTPServer, find the bit that instantiates the request > handler and override that so it passes it's constructor more parameters? > Right now I'm pretty confused, can somebody please tell me how I might > accomplish this, what I'm failing to grasp or point me to the docs that > explain it - I've spent the last hour or two plowing through docs to no > avail, I guess it's a case of keyword ignorance on my part! Code > follows... Try passing a factory function instead of a class. Untested: from functools import partial class PlainAJAXRequestHandler(BaseHTTPRequestHandler): def __init__(self, api_call, paths, *args, **kw): BaseHTTPRequestHandler.__init__(self, *args, **kw) self.api_call = api_call self.paths = paths paths = ... api_call = ... httpd = HTTPServer( server_address, partial(PlainAJAXRequestHandler, paths, api_call)) From ldo at geek-central.gen.new_zealand Wed Nov 10 04:52:52 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 10 Nov 2010 22:52:52 +1300 Subject: subclassing str References: <5dLBo.1024$w8.406@twister2.libero.it> <6048c71a-fba9-4244-9a36-a5d19c8a5516@y23g2000yqd.googlegroups.com> <87lj52kwln.fsf.mdw@metalzone.distorted.org.uk> Message-ID: In message <87lj52kwln.fsf.mdw at metalzone.distorted.org.uk>, Mark Wooding wrote: > One option is to implement a subclass which implements the additional > protocol. This is why I think object orientation ruins your ability to think properly. For ?protocol? read ?function?. If you want to implement a new function, then implement a new function, why do you have to go through this ?subclassing? malarkey just to do something so simple. From ldo at geek-central.gen.new_zealand Wed Nov 10 04:53:44 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 10 Nov 2010 22:53:44 +1300 Subject: Help Documenting Python Syntax References: <4d15eca9-20a5-4ad1-bdd6-f66fb386220b@y2g2000prf.googlegroups.com> Message-ID: In message , Grant Edwards wrote: > My question is why bother with 2.5? In mitigation, your honour, let me plead that the latest Debian Stable still ships with that version. From mdw at distorted.org.uk Wed Nov 10 05:56:31 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 10 Nov 2010 10:56:31 +0000 Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> <87aalrjkty.fsf@benfinney.id.au> <8jd3m9Fr55U7@mid.individual.net> <87fwvdb69k.fsf.mdw@metalzone.distorted.org.uk> <878w12kt5x.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <87tyjpih0g.fsf.mdw@metalzone.distorted.org.uk> Lawrence D'Oliveiro writes: > In message <878w12kt5x.fsf.mdw at metalzone.distorted.org.uk>, Mark Wooding > wrote: > > 2. The MainWindow class only has the `Window' attribute described in > > its definition. Apparently there are other attributes as well (the > > ColorMumbleList family for one, also `LayerDisplay'). Similarly, > > the LoadedImage class has attributes `Contents' and `FileName', but > > I see attributes `RowStride', `ImageDrawSize' and `SrcDimensions' > > used immediately below. > > These are really just namespaces, one for the GUI context and the other for > the image data. I think my point was about the rather selective documentation of the namespaces. The trivial-class trick is something I use myself (though usually to simulate a structure rather than just to carve up namespace) so I don't find it objectionable in and of itself. > > 3. In SelectSaveMenu, there's a curious `for' loop: > > > > for State in (gtk.STATE_NORMAL,) : # no need for > > gtk.STATE_INSENSITIVE > > ## blah > > > > Firstly, this is obviously equivalent to `state = gtk.STATE_NORMAL' > > followed by the loop body (YAGNI). > > It?s a tuple of one element. It used to be a tuple of two, and there is the > possibility it might need to become that again (as intimated at in the > attached comment). That?s why it stays a tuple. I guessed the history. I'm in two minds about this sort of thing. I /like/ history: I'm fascinated by the history of old programs and programming languages; but looping over a single thing just seems weird. > > Of course, being boilerplate, the similarities visually outweigh the > > differences, when in fact it's the differences that are > > interesting. > > That is generally how code reuse works. All the ?boilerplate? is in the > function definition, so I just have to call it parameterized by the > differences appropriate to each instance. Except that's not the case. There are extremely close similarities between the six calls which strongly suggest (to me, anyway) that further factoring would be beneficial. I detest writing anything more than once, and don't much enjoy playing spot-the-difference when reading code. The six calls are a screenful of spot-the-difference. > > It doesn't help that all of the names of the things involved are so > > wretchedly verbose. > > Oh please, no. Since when are explanatory names ?wretchedly verbose?? When the start and end bits are the same and the different bits are hidden in the middle. After staring at a screenful of MainWindow.MumbleDisplay my head starts spinning. > > How about the following? > > > > def make_listview_l1 ... > > And what, pray tell, is the significance of the name ?make_listview_l1?? If > there is something I would describe as ?wretched?, it is the use of random > numerical suffixes like this. It's a terse reference to List1Box (your name). Since it was only being used in the following two lines, I figured the name didn't matter much. (In Lisp, I'd have wrapped the two lines in FLET and simply called the function FROB.) > > Looking at some of the rest of the code, it might (or might not) be > > worthwhile actually making a class to gather together a list's model > > and view; subclasses can then vary their individual parameters, and > > the various colour lists can also keep the various captions with > > them. > > Most of that variation is already handled without the limitations of > thinking in classes. For example, selection of a colour in all three lists > is handled through a single EditColor routine. And of course you?ve already > seen how a single DefineScrollingList routine can be used to set up all the > scrolling lists used in this GUI. There's so much commonality in the arguments that I'm not convinced that they're fully factored. Worse, there are several tables involving your various ColorMumbleLists: adding another would require fiddling with all of them, which suggests that things have been sliced up the wrong way. (I'm aware in this instance that the set of such things is externally constrained in this case.) Maybe packaging all of the information about each individual list in one object and having a list of these objects would be better. > > 5. Much of the indentation and layout is rather unconventional, though > > not intolerable. But I found (deep in `SelectSaveMenu'): > > > > NewRenderPixels = array.array \ > > ( > > "B", > > FillColor > > * > > (ImageRowStride // 4 * ImageBounds[1]) > > ) > > > > to be most disconcerting. > > Is the structure of the expression not apparent to you? No, it really isn't. Oddly enough, I'd find (setf new-render-pixels (array:array "B" (* fill-color (floor image-row-stride 4) (aref image-bounds 1)))) much easier to cope with. > You?d probably need plenty of fresh air after something like this, > then: > > PatternArray = array.array \ > ( > "I", > 16 * (16 * (Light,) + 16 * (Dark,)) > + > 16 * (16 * (Dark,) + 16 * (Light,)) > ) That's not noticeably worse. The bizarre thing is the relative indentation of the operands to the * -- the oddness of which is emphasized by the initial argument. > > Also, I couldn't work out why some parens are indented only two > > spaces and others are indented the full eight. > > Eight?? You mean four. No, eight. Text editors are misleading: tab stops for plain text files are not a matter of individual preference. (I read the code straight off GitHub: my browser correctly interpreted tabs as moving to the next multiple of eight columns.) -- [mdw] From preyanthesila at ymail.com Wed Nov 10 06:17:07 2010 From: preyanthesila at ymail.com (preyanthesila at ymail.com) Date: Wed, 10 Nov 2010 03:17:07 -0800 (PST) Subject: Real profiles and real moms are alone Message-ID: <7b431995-efad-4aed-a065-01ee159c9ca5@a9g2000pro.googlegroups.com> Real profiles and real moms are alone http://urlrunt.me?c92 From preyanthesila at ymail.com Wed Nov 10 06:17:47 2010 From: preyanthesila at ymail.com (preyanthesila at ymail.com) Date: Wed, 10 Nov 2010 03:17:47 -0800 (PST) Subject: talk singles dads for make his life better Message-ID: <8652b2a9-a31f-4fa1-bf31-ea50a4e9d363@42g2000prt.googlegroups.com> talk singles dads for make his life better http://urlrunt.me?c92 From fetchinson at googlemail.com Wed Nov 10 06:39:40 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Wed, 10 Nov 2010 12:39:40 +0100 Subject: =?windows-1252?Q?Re=3A_Am_I_The_Only_One_Who_Keeps_Reading_=93Numpy=94_?= =?windows-1252?Q?as_=93Numpty=94=3F?= In-Reply-To: References: Message-ID: As in Numpty Dumpty? > Sorry... -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From duane.kaufman at gmail.com Wed Nov 10 06:49:05 2010 From: duane.kaufman at gmail.com (TheSeeker) Date: Wed, 10 Nov 2010 03:49:05 -0800 (PST) Subject: Deditor 0.2.2 References: <6cdb5dd1-1868-4a6e-8b59-5b871f8d412e@42g2000prt.googlegroups.com> <613e4abc-329b-4ab3-8349-b3ec047cb747@r14g2000yqa.googlegroups.com> Message-ID: <470b7ee0-b109-4bb6-afa0-391baf02033e@35g2000prt.googlegroups.com> On Nov 9, 10:04?am, Kruptein wrote: > On Nov 8, 3:01?pm, Jean-Michel Pichavant > wrote: > > > > > > > > > > > TheSeeker wrote: > > > On Nov 6, 7:06 am, Kruptein wrote: > > > >> Hey, > > > >> I released version 0.2.2 of my pythonic text-editor ?Deditor. > > >> It adds the use of projects, a project is a set of files which you can > > >> open all at once to make development much faster and easier. > > > >> For more information visit launchpad:http://launchpad.net/deditor > > > >> I also uploaded a video to introduce you to deditor:http://www.youtube.com/watch?v=hS8xBu-39VI > > >> (note: youtube is still processing the file so you might have to wait > > >> a bit to see it) > > > > Hi, > > > I might have missed this, but it seems deditor requires Python above > > > 2.5? > > > > It would be nice to mention the requirements on the home page > > > somewhere. > > > > Thanks, > > > Duane > > > I already point that on the last release. You should really just > > consider writing the requirements (python & wx). > > > JM > > I'm going todo that right now! I alswyas forget it :p Hi, In addition, on Debian Lenny, with Python 2.5: deditor.py:429: Warning: 'with' will become a reserved keyword in Python 2.6 Traceback (most recent call last): File "", line 1, in File "deditor.py", line 429 with open(cf,"wb") as configf: ^ SyntaxError: invalid syntax So I don't think Python 2.5 works . Thanks, Duane From mdw at distorted.org.uk Wed Nov 10 06:56:08 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 10 Nov 2010 11:56:08 +0000 Subject: subclassing str References: <5dLBo.1024$w8.406@twister2.libero.it> <6048c71a-fba9-4244-9a36-a5d19c8a5516@y23g2000yqd.googlegroups.com> <87lj52kwln.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <87lj51ie93.fsf.mdw@metalzone.distorted.org.uk> Lawrence D'Oliveiro writes: > In message <87lj52kwln.fsf.mdw at metalzone.distorted.org.uk>, Mark Wooding > wrote: > > > One option is to implement a subclass which implements the additional > > protocol. > > This is why I think object orientation ruins your ability to think > properly. For ?protocol? read ?function?. If you want to implement a > new function, then implement a new function, why do you have to go > through this ?subclassing? malarkey just to do something so simple. Functions don't do type-dependent dispatch, which was, of course, the whole point. A `protocol' is a collection of messages understood by a number of different kinds of objects, causing potentially object-specific behaviour. I gave the explicit example of serialization: string probably serializes differently from an integer or a list. The `__str__' and `__repr__' methods form a simple protocol for object printing, as an additional example. The `str' and `repr' functions provides a potentially useful external entry points into the protocol, but they work by doing a type-dependent dispatch on the argument -- calling the appropriate method. Object orientation isn't useless or an impediment to clear thinking. It does seem to have turned into a bizarre kind of religion by some, and many `mainstream' languages provide very poor object orientation features (yes, Java and C#, I'm looking at you). But OO can be useful. I think the notion of `protocol' is central to coherent OO design, but this seems largely overlooked in much of the literature I've read. This may mean that many people are muddled about what OO is actually for. -- [mdw] From mdw at distorted.org.uk Wed Nov 10 07:04:01 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 10 Nov 2010 12:04:01 +0000 Subject: How to test if a module exists? References: Message-ID: <87hbfpidvy.fsf.mdw@metalzone.distorted.org.uk> Lawrence D'Oliveiro writes: > I see that you published my unobfuscated e-mail address on USENET for all to > see. I obfuscated it for a reason, to keep the spammers away. I'm assuming > this was a momentary lapse of judgement, for which I expect an apology. > Otherwise, it becomes grounds for an abuse complaint to your ISP. Don't be silly! If anything, using forged email addresses in Usenet headers is closer to abuse. Note that there's nothing to stop `new_zealand' from becoming a TLD at some point (the underscore makes it unlikely, I grant). If you'd mangled the local part, or used an explicitly reserved TLD such as `example', then there wouldn't be a problem. -- [mdw] From aioe.org at technicalbloke.com Wed Nov 10 07:21:44 2010 From: aioe.org at technicalbloke.com (r0g) Date: Wed, 10 Nov 2010 12:21:44 +0000 Subject: How to test if a module exists? References: Message-ID: On 10/11/10 09:50, Lawrence D'Oliveiro wrote: > In message, Jon > Dufresne wrote: > >> On Mon, Nov 8, 2010 at 11:35 PM, Lawrence D'Oliveiro ... > > I see that you published my unobfuscated e-mail address on USENET for all to > see. I obfuscated it for a reason, to keep the spammers away. I'm assuming > this was a momentary lapse of judgement, for which I expect an apology. > Otherwise, it becomes grounds for an abuse complaint to your ISP. > You use your main address on USENET rather than a junk one!? Obfuscated or not that's either brave or foolhardy! Roger. From felipe.bastosn at gmail.com Wed Nov 10 07:34:06 2010 From: felipe.bastosn at gmail.com (Felipe Bastos Nunes) Date: Wed, 10 Nov 2010 10:34:06 -0200 Subject: DTD Parsing In-Reply-To: References: <4e7a49ec-1816-46e5-bc51-9f7c88f4d025@37g2000prx.googlegroups.com> <06071410-4684-4169-b1f8-0783e34f9062@f16g2000prj.googlegroups.com> Message-ID: I'll look at the options. But anyway, only to give an example of the configs I told, the ShoX project (at sourceforge.net) has xml as config files. I'm not talking about common users to edit the xmls, it's about the developer edit them :-) I'm working in a python wireless sensor network simulator, some builtin functions at python will greatly increase the ease in doing this. Does any, libxml2 or lxml, collect children like jdom does in java? List children = myRoot.getChildren(); Or just doing a Handler to find the children? 2010/11/10, Ian Kelly : > On 11/9/2010 11:14 PM, r0g wrote: >> Me too when possible, TBH if I only needed strings and there was no >> pressing security issue I'd just do this... >> >> config = {} >> for line in (open("config.txt", 'r')): >> if len(line) > 0 and line[0] <> "#": >> param, value = line.rstrip().split("=",1) >> config[param] = value > > That's five whole lines of code. Why go to all that trouble when you > can just do this: > > import config > > I kid, but only partially. Where this really shines is when you're > prototyping something and you need to configure complex object > hierarchies. No need to spend time writing parsers to generate the > hierarchies; you just construct the objects directly in the config. > When the project becomes mature enough that configuration security is a > concern, then you can replace the config with XML or whatever, and in > the meantime you can focus on more important things, like the actual > project. > > Cheers, > Ian > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Felipe Bastos Nunes From felipe.vinturini at gmail.com Wed Nov 10 07:36:41 2010 From: felipe.vinturini at gmail.com (Felipe Vinturini) Date: Wed, 10 Nov 2010 10:36:41 -0200 Subject: Questions: While And List Comprehension Message-ID: Hi Folks, I am quite new to python and I don't have a lot of experience with it yet. I have two simple questions: 1. Is there a way to limit the number of times a list comprehension will execute? E.g. I want to read from input only 5 values, so I would like something like (the values between # # are what I want): =================================================================================== COUNT = 0 print [ v for v in sys.stdin.readlines() *# *IF COUNT < 5* #* ] ## Increment COUNT somewhere =================================================================================== 2.* *I would like to know another way, a more pythonic way, to write the following: =================================================================================== import sys def Z(iNumber): sum=0 while (iNumber>=5): iNumber=iNumber/5 sum = sum + iNumber print sum def factorialCountZeros2(): sysStdinReadLine = sys.stdin.readline numValues = int(sysStdinReadLine()) [ Z(int(sysStdinReadLine())) for x in xrange(numValues) ] if __name__ == '__main__': factorialCountZeros2() =================================================================================== To be more specific, I would like to know about the Z function, is there a way to rewrite that while with list comprehension? This code is to solve the CodeChef problem: http://www.codechef.com/problems/FCTRL/ (I am still in the easy part) and it executed in 2.5 secs, I would like to know if there is something else I can improve performance. Thanks for your attention! Regards, Felipe. -------------- next part -------------- An HTML attachment was scrubbed... URL: From nomail at thisaddress.com Wed Nov 10 07:44:41 2010 From: nomail at thisaddress.com (Sven) Date: Wed, 10 Nov 2010 07:44:41 -0500 Subject: =?iso-8859-1?Q?Re:_Am_I_The_Only_One_Who_Keeps_Reading_=3FNumpy=3F_as_=3FNumpty=3F=3F?= References: Message-ID: <2010111007444115344-nomail@thisaddresscom> On 2010-11-10 01:53:58 -0500, Lawrence D'Oliveiro said: > Sorry... no. -- ./Sven From mdw at distorted.org.uk Wed Nov 10 07:45:07 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 10 Nov 2010 12:45:07 +0000 Subject: How to test if a module exists? References: Message-ID: <87d3qdibzg.fsf.mdw@metalzone.distorted.org.uk> r0g writes: > You use your main address on USENET rather than a junk one!? Obfuscated or > not that's either brave or foolhardy! I use my real email address. I also have an aggressive spam filter. But I don't think that much of my comes from Usenet harvesters any more, to be honest. -- [mdw] From nomail at thisaddress.com Wed Nov 10 07:49:47 2010 From: nomail at thisaddress.com (Sven) Date: Wed, 10 Nov 2010 07:49:47 -0500 Subject: Development Vs Release Message-ID: <201011100749474192-nomail@thisaddresscom> Hi, When developing tools I often also work on a module that I need to import into that tool. Once the work is complete both (or more) files go to a release location on the network. The question I have is: what is the easiest way to adjust the import path depending on whether it's a release or dev version. Right now I am using a custom env var (PYDEV) that I have to manually set when I work on the project that will insert the development module path into sys.path. This way the released version will not append the path and use the system wide PYTHONPATH Are there any better ways of doing this? I don't like the idea of flags inside the code as they can often get missed when developers release their code, ending up with released versions that import modules from the developer's working directory. Thanks -- ./Sven From martin at address-in-sig.invalid Wed Nov 10 08:07:58 2010 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Wed, 10 Nov 2010 13:07:58 +0000 (UTC) Subject: Commercial or Famous Applicattions.? References: Message-ID: On Wed, 10 Nov 2010 17:01:05 +1300, Lawrence D'Oliveiro wrote: > In message , Martin Gregorie wrote: > >> ...and don't forget getmail, a better behaved replacement for >> fetchmail. > > I was just looking this up in the Getmail FAQ, since I didn?t know about > the issues with Fetchmail. > FWIW the thing that really irritated me about fetchmail is the way it only deletes messages at the end of a session and never cleans up after itself. If a session gets timed out or otherwise interrupted the messages that were read in it are left in the server's mail marked 'read'. Subsequent sessions won't re-read them but won't go expunge them either. This leads to a gradual build-up of read but not expunged messages in the server's mailbox. The only fix I discovered was to go in manually with an MUA just after a fetchmail session so it could read and expunge this junk. getmail doesn't cause this problem. -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From ben+python at benfinney.id.au Wed Nov 10 08:10:10 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 11 Nov 2010 00:10:10 +1100 Subject: [OT] Usenet and email address exposure (was: How to test if a module exists?) References: Message-ID: <87zkthb9zh.fsf_-_@benfinney.id.au> r0g writes: > You use your main address on USENET rather than a junk one!? Yes. The amount of time spent keeping my spam filter well-trained is far smaller than the amount I'd lose faffing around with countless throwaway email addresses. I have to expose my address on the internet anyway for it to be useful. Hiding it from Usenet isn't going to gain me anything useful. > Obfuscated or not that's either brave or foolhardy! I haven't noticed much spam to email addresses I use on Usenet, and the spam filter catches it all. But regardless, a well-trained spam filter allows me to continue using a consistent, working email address. -- \ ?Everything you read in newspapers is absolutely true, except | `\ for that rare story of which you happen to have first-hand | _o__) knowledge.? ?Erwin Knoll | Ben Finney From martin at address-in-sig.invalid Wed Nov 10 08:12:24 2010 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Wed, 10 Nov 2010 13:12:24 +0000 (UTC) Subject: How to test if a module exists? References: <87hbfpidvy.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On Wed, 10 Nov 2010 12:04:01 +0000, Mark Wooding wrote: > Lawrence D'Oliveiro writes: > >> I see that you published my unobfuscated e-mail address on USENET for >> all to see. I obfuscated it for a reason, to keep the spammers away. >> I'm assuming this was a momentary lapse of judgement, for which I >> expect an apology. Otherwise, it becomes grounds for an abuse complaint >> to your ISP. > > Don't be silly! If anything, using forged email addresses in Usenet > headers is closer to abuse. Note that there's nothing to stop > `new_zealand' from becoming a TLD at some point (the underscore makes it > unlikely, I grant). If you'd mangled the local part, or used an > explicitly reserved TLD such as `example', then there wouldn't be a > problem. > Using the .invalid TLD is a generally accepted way of writing an intentionally fake address for use in USENET. -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From lnenov at mm-sol.com Wed Nov 10 08:12:46 2010 From: lnenov at mm-sol.com (lnenov) Date: Wed, 10 Nov 2010 15:12:46 +0200 Subject: Enumeration of strings and export of the constants Message-ID: <4CDA9A4E.1050106@mm-sol.com> Hi, I need to enumerate a couple hundred strings to constants and export them to another module(s) globals. In the mean time I want to keep my module's namespace as clear as I can and I don't want to use "import *" later. Here is the code I intend to use: test.py 1 class Apinamespace(): 2 @staticmethod 3 def import_to(destination): 4 5 for name, number in Apinamespace.__dict__.items(): 6 if (name.startswith('__') and name.endswith('__')) or name == "import_to": # :) 7 pass 8 else: 9 setattr(destination, name, number) 10 11 class Enumerate(): 12 def __init__(self, names, start = 0, step = 1): 13 enumerate_to = Apinamespace 14 15 for number, name in self.enumerate(names, start, step): 16 setattr(enumerate_to, name, number) 17 18 def enumerate(self, names, start = 0, step = 1): 19 for index in range(len(names)): 20 yield (start, names[index]) 21 start += step 22 23 example_names = ['Foo','Bar','Free', 'Beer'] 24 example_names2 = ['Foo_me_too', 'Bar_me_too', 'Free_me_too', 'Beer_me_too'] 25 Enumerate(example_names) 26 Enumerate(example_names2, 4, 2) This works like a charm: >>> import sys, test >>> thismodule = sys.modules[__name__] >>> test.Apinamespace.import_to(thismodule) >>> Beer 3 >>> Beer_me_too 10 Is there a better and more common way to do this? Do you know of a way to see the module in/from which a function was called without using traceback and frames? (I want to remove the argument from Apinamespace.import_me) And can line 6 be replaced by something less evil. Thanks for any suggestions. Lyudmil From darragh.ssa at gmail.com Wed Nov 10 08:51:05 2010 From: darragh.ssa at gmail.com (Kruptein) Date: Wed, 10 Nov 2010 05:51:05 -0800 (PST) Subject: Deditor 0.2.2 References: <6cdb5dd1-1868-4a6e-8b59-5b871f8d412e@42g2000prt.googlegroups.com> <613e4abc-329b-4ab3-8349-b3ec047cb747@r14g2000yqa.googlegroups.com> <470b7ee0-b109-4bb6-afa0-391baf02033e@35g2000prt.googlegroups.com> Message-ID: <84d92b8c-4592-4883-a8c4-929d93ff1138@j2g2000yqf.googlegroups.com> On Nov 10, 12:49?pm, TheSeeker wrote: > On Nov 9, 10:04?am, Kruptein wrote: > > > > > > > On Nov 8, 3:01?pm, Jean-Michel Pichavant > > wrote: > > > > TheSeeker wrote: > > > > On Nov 6, 7:06 am, Kruptein wrote: > > > > >> Hey, > > > > >> I released version 0.2.2 of my pythonic text-editor ?Deditor. > > > >> It adds the use of projects, a project is a set of files which you can > > > >> open all at once to make development much faster and easier. > > > > >> For more information visit launchpad:http://launchpad.net/deditor > > > > >> I also uploaded a video to introduce you to deditor:http://www.youtube.com/watch?v=hS8xBu-39VI > > > >> (note: youtube is still processing the file so you might have to wait > > > >> a bit to see it) > > > > > Hi, > > > > I might have missed this, but it seems deditor requires Python above > > > > 2.5? > > > > > It would be nice to mention the requirements on the home page > > > > somewhere. > > > > > Thanks, > > > > Duane > > > > I already point that on the last release. You should really just > > > consider writing the requirements (python & wx). > > > > JM > > > I'm going todo that right now! I alswyas forget it :p > > Hi, > > In addition, on Debian Lenny, with Python 2.5: > > deditor.py:429: Warning: 'with' will become a reserved keyword in > Python 2.6 > Traceback (most recent call last): > ? File "", line 1, in > ? File "deditor.py", line 429 > ? ? with open(cf,"wb") as configf: > ? ? ? ? ? ? ^ > SyntaxError: invalid syntax > > So I don't think Python 2.5 works . > > Thanks, > Duane that's possible, I was only able to test it with version 2.7, I'm going to change the dependencies then. thanks to point that out, 2.6 should work though? and the windows wxpython version and the linux version are different which causes some stupid bugs... :s From rbotting at csusb.edu Wed Nov 10 08:57:04 2010 From: rbotting at csusb.edu (RJB) Date: Wed, 10 Nov 2010 05:57:04 -0800 (PST) Subject: Help Documenting Python Syntax References: <4d15eca9-20a5-4ad1-bdd6-f66fb386220b@y2g2000prf.googlegroups.com> Message-ID: On Nov 9, 8:14?am, Grant Edwards wrote: > On 2010-11-09, Terry Reedy wrote: > > > On 11/9/2010 10:26 AM, RJB wrote: > >> I have been trying to redevelop a syntax page for Python at > >> ? ? ?http://cse.csusb.edu/dick/samples/python.syntax.html > > > Page does not load correctly; had to hit refresh to get entire page. > > It should specify that this is the syntax for Python 2.5. To me "the > > Python language" is 3.2. > > Nope. ?I just checked, and it's 2.6.5: > > ? $ python > ? Python 2.6.5 (release26-maint, Aug ?9 2010, 11:06:44) > > ;) > > My question is why bother with 2.5? > > I would think the logical choices would be 3.2 or 2.7 (or maybe 2.6). > I'm working from some grammars I've found on the web plus experiments. RJB From nobody at nowhere.com Wed Nov 10 08:59:02 2010 From: nobody at nowhere.com (Nobody) Date: Wed, 10 Nov 2010 13:59:02 +0000 Subject: Commercial or Famous Applicattions.? References: Message-ID: On Wed, 10 Nov 2010 13:07:58 +0000, Martin Gregorie wrote: > FWIW the thing that really irritated me about fetchmail is the way it > only deletes messages at the end of a session and never cleans up after > itself. If a session gets timed out or otherwise interrupted the messages > that were read in it are left in the server's mail marked 'read'. > Subsequent sessions won't re-read them but won't go expunge them either. > This leads to a gradual build-up of read but not expunged messages in the > server's mailbox. The --flush option will delete any "seen" messages before retrieving new messages. The --fetchall option will retrieve both seen and unseen messages. From pecora at anvil.nrl.navy.mil Wed Nov 10 09:10:49 2010 From: pecora at anvil.nrl.navy.mil (Lou Pecora) Date: Wed, 10 Nov 2010 09:10:49 -0500 Subject: Am I The Only One Who Keeps Reading ?Numpy? as ?Numpty?? References: <2010111007444115344-nomail@thisaddresscom> Message-ID: In article <2010111007444115344-nomail at thisaddresscom>, Sven wrote: > On 2010-11-10 01:53:58 -0500, Lawrence D'Oliveiro said: > > > Sorry... > > no. Yes, except for one other, above. :-) Bigger question: How do you pronouce it? Some say "num pee". Not the greatest image to English speakers. I say "num pie". Makes more sense to me since the "pie" sound is already in python a root for the name. This, of course, is a burning issue for us all. -- -- Lou Pecora From t33n4n at gmail.com Wed Nov 10 09:27:40 2010 From: t33n4n at gmail.com (Teenan) Date: Wed, 10 Nov 2010 14:27:40 +0000 Subject: Class extension confusion :( In-Reply-To: References: Message-ID: If memory serves, the following should work fine, as long as your happy for these vars to have the same value for all instances of the RequestHandler (static) MyHandler = PlainAJAXRequestHandler MyHandler.paths = my_paths_var webServer = HTTPServer( server_address, MyHandler) An alternative I've used in the past is to extend the server class in the same way, and store these vars in the server rather than the request handler. You can then use self.server in the requesthandler which holds the server instance. like self.server.my_var I seem to remember the documentation saying something about that the __init__ shouldn't be overriden for the HTTPRequestHandler class, so I wouldn't go down that route. Teenan. On Wed, Nov 10, 2010 at 5:45 AM, r0g wrote: > I have a subclass of BaseHHTPRequestHandler which uses a dictonary "paths" > and a function "api_call" which are defined in the main namespace of the > module. I'd rather I was able to pass these object to the constructor and > store them as data attributes "self.paths" and "self.api_call" but I'm not > sure how to do that properly. My understanding is that one may extend a > constructor by defining it's __init__ method, calling the parents > constructor and then adding ones own attributes to taste. What I don't > understand is where or how I am supposed to get these extra constructor > arguments into the class given that I don't instantiate it myself, it is > seemingly instantiated by HTTPServer class that I pass it to e.g. > > httpd = HTTPServer(server_address, PlainAJAXRequestHandler) > > I wondered if I ought to instantiate an instance of > PlainAJAXRequestHandler, set the attributes (either manually or by extending > it's constructor) and pass that to HTTPServer but I figured it expects a > class not an instance as it probably wants to spawn one instance for each > request so that would be a non starter. Might I need to subclass HTTPServer, > find the bit that instantiates the request handler and override that so it > passes it's constructor more parameters? Right now I'm pretty confused, can > somebody please tell me how I might accomplish this, what I'm failing to > grasp or point me to the docs that explain it - I've spent the last hour or > two plowing through docs to no avail, I guess it's a case of keyword > ignorance on my part! Code follows... > > Thanks for reading! > > Roger. > > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mdw at distorted.org.uk Wed Nov 10 09:28:28 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 10 Nov 2010 14:28:28 +0000 Subject: Am I The Only One Who Keeps Reading ?Numpy? as ?Numpty?? References: <2010111007444115344-nomail@thisaddresscom> Message-ID: <874obpi777.fsf.mdw@metalzone.distorted.org.uk> Lou Pecora writes: > Bigger question: How do you pronouce it? Rhymes with `grumpy'. -- [mdw] From bookredwu at gmail.com Wed Nov 10 09:42:44 2010 From: bookredwu at gmail.com (alexander) Date: Wed, 10 Nov 2010 06:42:44 -0800 (PST) Subject: Curses Programming Message-ID: Hi, all Here is the test. Plz help..... / ***************************************************************************************************************************************************/ If you use the new image search of Google, you will find that the result images are layouted in a way that each row has the same height, but contains different number of images dependents the width-height ratio of each image. The goal is to make each row of images having approximately same total width. Just try search any image inimages.google.com, you will get the idea. If you're the programmer designing this page, what algorithm would you use to select images for each row? Input: The input of the program is a plain text file, each line in the file containg 2 numbers, describing the width and height of an image e.g. 800 600 640 400 720 1280 ... Goal: Design an algorithm to put those images into a number of rows, each row is 150 pixel height and 1200 pixel wide. You could scale images proportionally to the same height. You need make sure the images are aligned as closely as possbile to the row boundary. Output: The indexes of the images you would put on each row followed by blank line. e.g. 0 1 2 According to the input file example, this output means image-0 (800 x 600) and image-1 (640 x 400) is put on the first row and image-2 (720 x 1280) is put on the second row. Constraint: Assuming, the input file contains less than 100 lines. Your algorithm should finish within 5 secs on a standard laptop. / **********************************************************************************************************************************************/ Could any give a hand? Thanks a lot Alex From bookredwu at gmail.com Wed Nov 10 09:49:01 2010 From: bookredwu at gmail.com (alexander) Date: Wed, 10 Nov 2010 06:49:01 -0800 (PST) Subject: Feed subscription IM bot Message-ID: <74b044f0-0188-4adf-af86-635cca338846@o15g2000prh.googlegroups.com> Hi, Can anyone help on this? / ********************************************************************************************************************/ The project should either be hosted online and usable from there, or can be run locally. Complete ource code should be delivered along with a brief readme for features. It should take about about 1-2 hours to complete. Basic requirements: Build a Python driven IM bot with the following features * A user can add the bot to his/her Google talk/jabber friends list. * The user types the words "sub [feed_url]" to the bot to begin subscribing to the feed at the specified feed_url ([feed_url] is the placeholder for the actual feed url. e.g. http://myweb.com/feed) * The user types the words "unsub [feed_url]" to stop subscribing to the feed * The bot scans the feed at a specified time interval, and sends new contents to the subscribing user Additional credits: * Additional bot commands: "ls", "pause [feed_url]", " resume[feed_url]", "grep [feed_url] [keywords]", whatever you think is useful and fun, even not feed subscription related * A web interface for reading/managing subscriptions * Beautiful, extensible and scalable architecture Requirements: * Python 2.5 * Robust and graceful error handling * Robust unicode handling / ************************************************************************************************************/ Thanks From azeynel1 at gmail.com Wed Nov 10 10:13:06 2010 From: azeynel1 at gmail.com (Zeynel) Date: Wed, 10 Nov 2010 07:13:06 -0800 (PST) Subject: How to read the Python tutorial? Message-ID: <59c26dd2-529f-4a4a-8f48-1ee5f35b068f@t7g2000vbj.googlegroups.com> For instance, when the tutorial has http://docs.python.org/release/2.6/library/datetime.html class datetime.datetime A combination of a date and a time. Attributes: year, month, day, hour, minute, second, microsecond, and tzinfo. What does this mean? How do I use it? For instance, I have a DateTimeProperty mDate that I get from a query in Google App Engine. This mDate has value mDATE = 2010-11-10 14:35:22.863000 But when I try datetime.datetime.mDATE.toordinal()) I get AttributeError. If I try something like td = mDATE.seconds in GAE development server I get AttributeError: 'datetime.datetime' object has no attribute 'seconds' What am I doing wrong? And how to understand this stuff so that I can start using the language instead of trying to figure out types. Thanks for your help. From martin at address-in-sig.invalid Wed Nov 10 10:19:16 2010 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Wed, 10 Nov 2010 15:19:16 +0000 (UTC) Subject: Commercial or Famous Applicattions.? References: Message-ID: On Wed, 10 Nov 2010 13:59:02 +0000, Nobody wrote: > On Wed, 10 Nov 2010 13:07:58 +0000, Martin Gregorie wrote: > >> FWIW the thing that really irritated me about fetchmail is the way it >> only deletes messages at the end of a session and never cleans up after >> itself. If a session gets timed out or otherwise interrupted the >> messages that were read in it are left in the server's mail marked >> 'read'. Subsequent sessions won't re-read them but won't go expunge >> them either. This leads to a gradual build-up of read but not expunged >> messages in the server's mailbox. > > The --flush option will delete any "seen" messages before retrieving new > messages. > ...and is described as dangerous, can cause message loss in the man page along with a warning to avoid including it as a permanent option - good enough reasons for not using it IMO. > The --fetchall option will retrieve both seen and unseen > messages. > Again, not useful as a permanent option since I don't want to receive duplicated messages. In both cases using them 'as required' requires: (a) monitoring the source mailbox for 'read' message build up (b) when 'read' messages are seen, executing a sequence of stop fetchmail alter configuration run it for one retrieval session change config back restart using the normal configuration That's far too much hassle to be part of SOP. Now, if ESR had fixed fetchmail to tidy up after itself (if getmail can do that, there's no reason why fetchmail can't) or had even added the ability for a daily or weekly cron job to enquire about 'read' messages and, if any are present, tell it to silently expunge them in a special session, I'd probably still use it. Without equivalent fixes its just a buggy bit of software, making getmail a superior replacement because it 'just works'. -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From invalid at invalid.invalid Wed Nov 10 10:30:26 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 10 Nov 2010 15:30:26 +0000 (UTC) Subject: Am I The Only One Who Keeps Reading ?Numpy? as ?Numpty?? References: <2010111007444115344-nomail@thisaddresscom> <874obpi777.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On 2010-11-10, Mark Wooding wrote: > Lou Pecora writes: >> Bigger question: How do you pronouce it? > > Rhymes with `grumpy'. Num-Pie -- Grant Edwards grant.b.edwards Yow! Boys, you have ALL at been selected to LEAVE th' gmail.com PLANET in 15 minutes!! From azeynel1 at gmail.com Wed Nov 10 10:40:37 2010 From: azeynel1 at gmail.com (Zeynel) Date: Wed, 10 Nov 2010 07:40:37 -0800 (PST) Subject: How to convert the date object 2010-11-10 14:52:35.026000 to integer? Message-ID: mDATE = "2010-11-10 14:52:35.026000" (Not sure if this is string or something else.) I would like to convert mDATE to integer to add, multiply etc. For instance, if I try to convert mDATE to seconds td = mDATE.seconds I get the error td = result.mDATE.seconds AttributeError: 'datetime.datetime' object has no attribute 'seconds' Thanks. From rantingrick at gmail.com Wed Nov 10 10:51:38 2010 From: rantingrick at gmail.com (rantingrick) Date: Wed, 10 Nov 2010 07:51:38 -0800 (PST) Subject: How to read the Python tutorial? References: <59c26dd2-529f-4a4a-8f48-1ee5f35b068f@t7g2000vbj.googlegroups.com> Message-ID: On Nov 10, 9:13?am, Zeynel wrote: > For instance, when the tutorial hashttp://docs.python.org/release/2.6/library/datetime.html > > class datetime.datetime > A combination of a date and a time. Attributes: year, month, day, > hour, minute, second, microsecond, and tzinfo. > > What does this mean? How do I use it? > > For instance, I have a DateTimeProperty mDate that I get from a query > in Google App Engine. This mDate has value > > mDATE = 2010-11-10 14:35:22.863000 Wait a minute i am confused...? Does Python have a "text" object that magically turns into a datetime object? >>> mDATE = 2010-11-10 14:35:22.863000 SyntaxError: invalid syntax hmm, apparently not! Usually in order to use methods of an object, you must create an object first or more specifically an instance. >>> dateobj = datetime.date(2010,11,10) >>> dir(dateobj) ['__add__', '__class__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__ne__', '__new__', '__radd__', '__reduce__', '__reduce_ex__', '__repr__', '__rsub__', '__setattr__', '__sizeof__', '__str__', '__sub__', '__subclasshook__', 'ctime', 'day', 'fromordinal', 'fromtimestamp', 'isocalendar', 'isoformat', 'isoweekday', 'max', 'min', 'month', 'replace', 'resolution', 'strftime', 'timetuple', 'today', 'toordinal', 'weekday', 'year'] From rantingrick at gmail.com Wed Nov 10 10:53:41 2010 From: rantingrick at gmail.com (rantingrick) Date: Wed, 10 Nov 2010 07:53:41 -0800 (PST) Subject: How to convert the date object 2010-11-10 14:52:35.026000 to integer? References: Message-ID: <6e22008f-4c72-4c1a-9722-50b92a96df3d@r14g2000yqa.googlegroups.com> On Nov 10, 9:40?am, Zeynel wrote: > mDATE = "2010-11-10 14:52:35.026000" > > (Not sure if this is string or something else.) > > I would like to convert mDATE to integer to add, multiply etc. > > For instance, if I try to convert mDATE to seconds > > td = mDATE.seconds > > I get the error > > ? ? td = result.mDATE.seconds > AttributeError: 'datetime.datetime' object has no attribute 'seconds' > > Thanks. No group likes when you ask the same question twice in two different threads. faus pas! Go back and check your other thread for enlightenment. From rantingrick at gmail.com Wed Nov 10 10:58:05 2010 From: rantingrick at gmail.com (rantingrick) Date: Wed, 10 Nov 2010 07:58:05 -0800 (PST) Subject: =?windows-1252?Q?Re=3A_Am_I_The_Only_One_Who_Keeps_Reading_=93Numpy=94_?= =?windows-1252?Q?as_=93Numpty=94=3F?= References: Message-ID: <940162c6-b61a-4bb7-9965-6e155716cda8@n30g2000vbb.googlegroups.com> On Nov 10, 12:53?am, Lawrence D'Oliveiro wrote: > Sorry... Was humpty dumpty your favorite nursery rhyme? And it's "Num-pee" for me. If the "py" is appended i use "x-pee" and if it is pre i use "pie- x". From hpj at urpla.net Wed Nov 10 11:03:03 2010 From: hpj at urpla.net (Hans-Peter Jansen) Date: Wed, 10 Nov 2010 17:03:03 +0100 Subject: http error 301 for urlopen In-Reply-To: References: <4cd7987e$0$1674$742ec2ed@news.sonic.net> Message-ID: <201011101703.03524.hpj@urpla.net> On Tuesday 09 November 2010, 03:10:24 Lawrence D'Oliveiro wrote: > In message <4cd7987e$0$1674$742ec2ed at news.sonic.net>, John Nagle wrote: > > It's the New York Times' paywall. They're trying to set a > > cookie, and will redirect the URL until you store and return the > > cookie. > > And if they find out you?re acessing them from a script, they?ll > probably try to find a way to block that as well. ..which could be alleviated by carefully crafting the requests ;-) Luckily, unpleasant related ground work was already done by others, e.g.: http://bugs.python.org/issue2275 Pete From azeynel1 at gmail.com Wed Nov 10 11:05:55 2010 From: azeynel1 at gmail.com (Zeynel) Date: Wed, 10 Nov 2010 08:05:55 -0800 (PST) Subject: How to read the Python tutorial? References: <59c26dd2-529f-4a4a-8f48-1ee5f35b068f@t7g2000vbj.googlegroups.com> Message-ID: <6b2d39f4-c9d9-4e77-9bb7-60e26dc334ee@j9g2000vbl.googlegroups.com> On Nov 10, 10:51?am, rantingrick wrote: > Wait a minute i am confused...? Does Python have a "text" object that > magically turns into a datetime object? > > >>> mDATE = 2010-11-10 14:35:22.863000 > > SyntaxError: invalid syntax This is the reason I am asking the question. I am confused about what mDATE is. It is defined as a DateTimeProperty in Google App Engine in the following model: class Rep(db.Model): mAUTHOR = db.UserProperty(auto_current_user=True) mUNIQUE = db.StringProperty() mCOUNT = db.IntegerProperty() mDATE = db.DateTimeProperty(auto_now=True) mDATE0 = db.DateTimeProperty(auto_now_add=True) mWEIGHT = db.IntegerProperty() When I acces it with this query: QUERY = Rep.all() QUERY.filter("mAUTHOR =", user) QUERY.order("-mCOUNT") RESULTS = QUERY.fetch(10) But when I try to use like this for instance: for result in RESULTS: WEIGHT = (datetime.datetime.result.mDATE.toordinal()) * result.mCOUNT I get AttributeError or if I try to use it like this dt = result.mDATE.seconds I get AttributeError: 'datetime.datetime' object has no attribute 'seconds' From rantingrick at gmail.com Wed Nov 10 11:19:19 2010 From: rantingrick at gmail.com (rantingrick) Date: Wed, 10 Nov 2010 08:19:19 -0800 (PST) Subject: How to read the Python tutorial? References: <59c26dd2-529f-4a4a-8f48-1ee5f35b068f@t7g2000vbj.googlegroups.com> <6b2d39f4-c9d9-4e77-9bb7-60e26dc334ee@j9g2000vbl.googlegroups.com> Message-ID: On Nov 10, 10:05?am, Zeynel wrote: > AttributeError: 'datetime.datetime' object has no attribute 'seconds' First of all put some scaffolding in this code. What is scaffolding. Basically some debug print statements so you can follow the trail of errors. You need to learn how to debug code and be self reliant. A few very important functions are. >>> a = 's' >>> b = 1 >>> a * b 's' >>> a + b Traceback (most recent call last): File "", line 1, in a + b TypeError: cannot concatenate 'str' and 'int' objects >>> type(a), type(b) (, ) >>> id(a), id(b) (26864768, 12844616) >>> print a, b s 1 >>> repr(a), repr(b) ("'s'", '1') >>> isinstance(a, str) True I would start at the loop and figure out what is going on from there with some print statements and the functions i showed you. Debugging is a large part of any programming project. We all do it everyday. So the sooner you learn the better. If you have a specific question feel free to ask, but general debug issues are better solved yourself. A few more indispensable functions are dir() and help() From robert.kern at gmail.com Wed Nov 10 12:02:35 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 10 Nov 2010 11:02:35 -0600 Subject: Allowing comments after the line continuation backslash In-Reply-To: References: <4CCE6FF6.2050408@v.loewis.de> <87aalrjkty.fsf@benfinney.id.au> <8jd3m9Fr55U7@mid.individual.net> <87fwvdb69k.fsf.mdw@metalzone.distorted.org.uk> <878w12kt5x.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On 11/10/10 12:26 AM, Lawrence D'Oliveiro wrote: > In message, Robert Kern > wrote: > >> For me, putting the brackets on their own lines (and using a trailing >> comma) has little to do with increasing readability. It's for making >> editing easier. Keeping all of the items consistent means that in order to >> add, delete, or move any item is the same operation everywhere in the list >> whether it is the first item, last item, or any item in between. > > Yup, I like to do that when there?s nothing special about the last item in > the list. Sometimes there is (e.g. an enumeration entry naming the number of > values in the enumeration, or an all-zero sentinel marking the end of a > list), in which case I omit the comma to indicate that nothing should come > afterwards. > > I remember an early experience with JavaScript (back in the days of Netscape > versus Internet Explorer 5.1 on a Mac), when I found that constructing a > list in this way wasn?t working in IE: turned out it was inserting some kind > of extra phantom list item after that last comma. Sigh... It's one of the things that pains me every time I code JavaScript. That and the lack of tuple unpacking. -- 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 igor.idziejczak at gmail.com Wed Nov 10 12:08:19 2010 From: igor.idziejczak at gmail.com (xoff) Date: Wed, 10 Nov 2010 09:08:19 -0800 (PST) Subject: multiple discontinued ranges Message-ID: I was wondering what the best method was in Python programming for 2 discontinued ranges. e.g. I want to use the range 3 to 7 and 17 to 23. Am I obliged to use 2 for loops defining the 2 ranges like this: for i in range (3,7): do bla for i in range (7,17): do bla or is there a more clever way to do this? From paul.nospam at rudin.co.uk Wed Nov 10 12:13:07 2010 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Wed, 10 Nov 2010 17:13:07 +0000 Subject: multiple discontinued ranges References: Message-ID: <87y691w198.fsf@rudin.co.uk> xoff writes: > I was wondering what the best method was in Python programming for 2 > discontinued ranges. e.g. I want to use the range 3 to 7 and 17 to 23. > Am I obliged to use 2 for loops defining the 2 ranges like this: > > for i in range (3,7): > do bla > for i in range (7,17): > do bla > > or is there a more clever way to do this? for i in itertools.chain(xrange(3,7), xrange(17,23)): print i From janssen at parc.com Wed Nov 10 12:15:18 2010 From: janssen at parc.com (Bill Janssen) Date: Wed, 10 Nov 2010 09:15:18 PST Subject: ANN: PyGUI 2.3 In-Reply-To: <8ivk3kFjhuU1@mid.individual.net> References: <8ivk3kFjhuU1@mid.individual.net> Message-ID: <35473.1289409318@parc.com> Gregory Ewing wrote: > Daniel Fetchinson wrote: > > > Any reason your project is not easy_installable? > > Mainly because I'm not a setuptools user and haven't been > motivated to learn how to do this so far. Applause!! Bill From no.email at nospam.invalid Wed Nov 10 12:15:38 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 10 Nov 2010 09:15:38 -0800 Subject: multiple discontinued ranges References: Message-ID: <7xy691w151.fsf@ruckus.brouhaha.com> xoff writes: > I was wondering what the best method was in Python programming for 2 > discontinued ranges. e.g. I want to use the range 3 to 7 and 17 to 23. you could use itertools.chain: from itertools import chain for i in chain(range(3,7), range(17,23)): ... I'm assuming you're using python 3. In python 2 each of those ranges expands immediately to a list, so on the one hand they're consuming potentially lots of storage (you should use xrange instead). On the other hand you could just concatenate the lists with +, but I wouldn't advise that. From eraserix at gmail.com Wed Nov 10 12:19:13 2010 From: eraserix at gmail.com (eraserix) Date: Wed, 10 Nov 2010 09:19:13 -0800 (PST) Subject: subprocess.Popen deadlocks Message-ID: <2cf9a225-7d1c-4490-8a62-807e79bdd06a@n30g2000vbb.googlegroups.com> Hi >From time to time I observe a deadlock in subprocess.Popen. I see the childprocess beeing and if I attach gdb to the stuck python script, I can see it waiting on line 1128 in subprocess.py ( data = _eintr_retry_call(os.read, errpipe_read, 1048576) ). Any ideas of whats going on? I'm on linux using python 2.6.5. I already found http://bugs.python.org/issue1731717 and stubbed out subprocess._cleanup, but this didn't really help and doesn't seem to be the problem anyway... A bit of information about what I'm trying to do: I try to control several process from a python script. Each process is started from a thread, the threads just wait() for the child to exit and can then be joined. Main waits for SIGINT. After it received the signal, it will send a signal to the processes spawned by the threads and then join() the threads (which should terminate after their process exits) Christoph From igor.idziejczak at gmail.com Wed Nov 10 12:23:06 2010 From: igor.idziejczak at gmail.com (xoff) Date: Wed, 10 Nov 2010 09:23:06 -0800 (PST) Subject: multiple discontinued ranges References: <87y691w198.fsf@rudin.co.uk> Message-ID: <45992bf6-7a5b-4612-9c57-7618a8d33307@t35g2000yqj.googlegroups.com> On 10 nov, 18:13, Paul Rudin wrote: > xoff writes: > > I was wondering what the best method was in Python programming for 2 > > discontinued ranges. e.g. I want to use the range 3 to 7 and 17 to 23. > > Am I obliged to use 2 for loops defining the 2 ranges like this: > > > for i in range (3,7): > > ?do bla > > for i in range (7,17): > > ?do bla > > > or is there a more clever way to do this? > > for i in itertools.chain(xrange(3,7), xrange(17,23)): > ? ? print i Thank you, that was exactly what I needed! From manu3d at gmail.com Wed Nov 10 12:25:45 2010 From: manu3d at gmail.com (Emanuele D'Arrigo) Date: Wed, 10 Nov 2010 09:25:45 -0800 (PST) Subject: A matter of queues, tasks and multiprocessing Message-ID: Greetings everybody, I've tried to come up with this message for a couple of weeks now and it doesn't look like I'm getting any clearer in my thoughts so I decided that it's probably best to take the plunge and ask you guys to kindly throw me a rope... What I'm trying to come up with is some kind of simple, dynamically scalable, domain-agnostic, multi-processor capable, tasking system. Maybe I'm already giving myself too many constraints here, i.e. it might all be possible except... the "simple" part. Clearly a good (the?) starting point is to think in terms of tasks, queues and worker threads. Once synchronization issues are properly attended this methodology feels, at least in theory, neat and intuitive. The problem is of course to put in practice. For example in my context I can think of tasks with very heterogeneous computing requirements, i.e. quick tasks such as UI interactions, slow tasks such as I/O with large files, and pretty much everything in- between. In this context, and given that I cannot know a priory a task's execution time, how can I create a system that is responsive on things like UI, takes its time on things such as I/O but gives the application the opportunity to further customize things? I.e. a user might want to limit the number of processors/core used to a subset of those available. Alternatively an application might want to create more threads than the optimal number simply because interleaving the executions of a few tasks is preferable to simply queuing them. And all this might have to happen at runtime. Currently on one end of the spectrum I'm considering a purely functional approach, with one queue for UI-related tasks, one for I/O- related tasks and one for everything else. On a single processor/core machine they'd simply be serviced by one thread each, all sharing one processor. On a two processors/cores machine UI and I/O queues might be serviced by two separate threads on the same processor while everything else is serviced by a worker thread on the other processor. As the number of cores/processors increases more threads/processor would be attached to each queue, but how to establish what should get more resources first? Alternatively I've read about queues with threads that "steal" from other queues. But that seems to assumes more or less homogeneous task execution or applications where responsiveness might drop to zero, i.e. because slow I/O tasks are being attended by all available threads/processors. In these cases, should the UI-related thread/queue never ever steal from the other queues, to maintain responsiveness at all times, effectively creating an hybrid approach with one purely functional thread/queue and (potentially) many other self-balancing threads/queues? Thoughts, hints, tips, tricks, directions, reading material of any kind will all be appreciated! =) Sincerely, Manu From igor.idziejczak at gmail.com Wed Nov 10 12:34:14 2010 From: igor.idziejczak at gmail.com (xoff) Date: Wed, 10 Nov 2010 09:34:14 -0800 (PST) Subject: multiple discontinued ranges References: <7xy691w151.fsf@ruckus.brouhaha.com> Message-ID: <3250c9df-deeb-4610-93f2-93ba4b1568e4@p1g2000yqm.googlegroups.com> On 10 nov, 18:15, Paul Rubin wrote: > you could use itertools.chain: > > ? from itertools import chain > > ? for i in chain(range(3,7), range(17,23)): > ? ? ... > > I'm assuming you're using python 3. ?In python 2 each of those ranges > expands immediately to a list, so on the one hand they're consuming > potentially lots of storage (you should use xrange instead). ?On the > other hand you could just concatenate the lists with +, but I wouldn't > advise that. I am curious, why wouldn't you advise something like this: for i in chain(range(3,7) + range(17,23)): Thanks again! From simon at mullis.co.uk Wed Nov 10 12:56:42 2010 From: simon at mullis.co.uk (Simon Mullis) Date: Wed, 10 Nov 2010 18:56:42 +0100 Subject: Is Eval *always* Evil? Message-ID: Hi All, I'm writing a Django App to webify a Python script I wrote that parses some big XML docs and summarizes certain data contained within. This app will be used by a closed group of people, all with their own login credentials to the system (backed off to the corp SSO system). I've already got Django, Celery and Rabbitmq working to handle uploads and passing the "offline" parsing / processing task to the backend. One way to do the XML processing is to use a number of XPath queries and a key point is the required output (and therefore the list of queries) is not yet complete (and will always be a little "fluid"). Ultimately, I don't want to be stuck with maintaining this list of XPath queries and want to allow my colleagues to add / change / remove them as they see fit. I didn't know my "xpath from my elbow" when I first started looking into this so I think they'll be able to learn it pretty easily. The only easy way to accomplish this I can think of is create a new table with { "name" : "xpath command" } key, value pairs and allow it to be edited via the browser (using Django's Admin scaffolding) . I plan on making sure that when amending the list of XPath queries, each entry is tested against a known good XML file so the user can see sample results before they're allowed to save it to the database. I'm aware that this will probably slow things down, as there'll be lots of serial XPath queries, but even if the job takes 5 minutes longer then it will still save man-days of manual work. I can live with this as long as it's flexible. # In the meantime - and as a proof of concept - I'm using a dict instead. xpathlib = { "houses" : r'[ y.tag for y in x.xpath("//houses/*") ]', "names" : r'[ y.text for y in x.xpath("//houses/name") ]', "footwear_type" : r'[ y.tag for y in x.xpath("//cupboard/bottom_shelf/*") ]', "shoes" : r'[ y.text for y in x.xpath("//cupboard/bottom_shelf/shoes/*") ]', "interface_types" : r'[ y.text[:2] for y in x.xpath("//interface/name") ]', } # (I left a real one at the bottom so you can see I might want to do some string manipulation on the results within the list comprehension). # Then in my backend task processing scripts I would have something like: def apply_xpath(xpath_command, xml_frag): x = xml_frag if re.findall(r'\[\sy\.\w+(?:\[.+\])?\s+for y in x\.xpath\("/{1,2}[\w+|\/|\*]+"\)\s\]', xml_frag): result = eval(xpath_command, {"__builtins__":[]},{"x": x}) if type(result).__name__ == "list": return result Yes, the regex is pretty unfriendly, but it works for all of the cases above and fails for other non-valid examples I've tried. # Let's try it in ipython: from lxml import etree f = open('/tmp/sample.xml') xml_frag = etree.fromstring(f.read()) print apply_xpath(xpathlib["footwear_type"], xml_frag) ['ballet shoes', 'loafers', 'ballet shoes', 'hiking boots', 'training shoes', 'hiking boots', 'socks'] Is this approach ok? I've been reading about this and know about the following example that bypass the __builtins__ restriction on eval (edited so it won't work). __import__('shutill').rmtreee('/') <===DO NOT TRY AND RUN THIS As the potential audience for this Web App is both known and controlled, am I being too cautious? If "eval" is not the way forward, are there any suggestions for another way to do this? Thanks From mwilson at the-wire.com Wed Nov 10 13:02:48 2010 From: mwilson at the-wire.com (Mel) Date: Wed, 10 Nov 2010 13:02:48 -0500 Subject: multiple discontinued ranges References: Message-ID: xoff wrote: > I was wondering what the best method was in Python programming for 2 > discontinued ranges. e.g. I want to use the range 3 to 7 and 17 to 23. > Am I obliged to use 2 for loops defining the 2 ranges like this: > > for i in range (3,7): > do bla > for i in range (7,17): > do bla > > or is there a more clever way to do this? One horribly clever way is to concoct a 9-th order polynomial to return 3,4,5,6,17,18,19,20,21,22 for input values 0,1,2,3,4,5,6,7,8,9. The reasonable way is to use two loops as you've done. If the pattern of discontinuous ranges is really important in your application, you'd perhaps want to package it up (not tested): def important_range (): for x in xrange (3, 7): yield x for x in xrange (17,23): yield x to be used elsewhere as for v in important_range(): # use v ... Mel. From __peter__ at web.de Wed Nov 10 13:19:03 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 10 Nov 2010 19:19:03 +0100 Subject: multiple discontinued ranges References: Message-ID: xoff wrote: > I was wondering what the best method was in Python programming for 2 > discontinued ranges. e.g. I want to use the range 3 to 7 and 17 to 23. > Am I obliged to use 2 for loops defining the 2 ranges like this: > > for i in range (3,7): > do bla > for i in range (7,17): > do bla > > or is there a more clever way to do this? >>> for r in xrange(3, 7), xrange(17, 23): ... for i in r: ... print i, ... 3 4 5 6 17 18 19 20 21 22 From data.2 at rediff.com Wed Nov 10 14:39:36 2010 From: data.2 at rediff.com (gaurav) Date: Wed, 10 Nov 2010 11:39:36 -0800 (PST) Subject: Big opportunity. Message-ID: <2c749249-3d9a-4c61-8cb1-eca2c0b074a3@j12g2000prm.googlegroups.com> Complete resource for free or paid Work at home jobs online/offline. http://rojgars1.webs.com/gov.htm http://rojgars.webs.com/bankingjobs.htm Get start earning at your Management work. Great career in Management Visit: http://managementjobs.webs.com/pm.htm & http://topcareer.webs.com/humanresourcemgmt.htm From nobody at nowhere.com Wed Nov 10 15:04:15 2010 From: nobody at nowhere.com (Nobody) Date: Wed, 10 Nov 2010 20:04:15 +0000 Subject: multiple discontinued ranges References: <7xy691w151.fsf@ruckus.brouhaha.com> <3250c9df-deeb-4610-93f2-93ba4b1568e4@p1g2000yqm.googlegroups.com> Message-ID: On Wed, 10 Nov 2010 09:34:14 -0800, xoff wrote: > I am curious, why wouldn't you advise something like this: > for i in chain(range(3,7) + range(17,23)): Because it constructs all three lists (both of the individual ranges and their concatenation) in memory. For a trivial example, that isn't a problem; for a real application, it could be. From moura.mario at gmail.com Wed Nov 10 15:14:22 2010 From: moura.mario at gmail.com (macm) Date: Wed, 10 Nov 2010 12:14:22 -0800 (PST) Subject: Learning Pyhton - Functional Programming - How intersect/difference two dict with dict/values? fast! References: <4d71519e-a232-427f-b4e0-5bae90fc4acb@n32g2000prc.googlegroups.com> <4cd9b16d$0$1640$742ec2ed@news.sonic.net> <87tyjpy0a3.fsf@rudin.co.uk> Message-ID: <7158677e-8b26-40ec-83a4-c46143e3ec3d@q18g2000vbm.googlegroups.com> Hi Folks I am studing yet (with fever, grasp and headache). I know I can do better, but first I should learn more about "dictionary comprehension syntax" in python 2.65 >>> dict1 = {'ab':[[1,2,3,'d3','d4',5],12],'ac':[[1,3,'78a','79b'],54],'ad': [[56,57,58,59],34], 'ax': [[56,57,58,59],34]} >>> dict2 = {'ab':[[22,2,'a0','42s','c4','d3'],12],'ab':[[2,4,50,42,'c4'],12],'ac':[[1,3,'79b',45,65,'er4'],54],'ae': [[56,57,58,59],34],'ax':[[9],34]} >>> >>> # Arnaud Delobelle ... def intersectList(iterables): ... nexts = [iter(iterable).next for iterable in iterables] ... v = [next() for next in nexts] ... while True: ... for i in xrange(1, len(v)): ... while v[0] > v[i]: ... v[i] = nexts[i]() ... if v[0] < v[i]: break ... else: ... yield v[0] ... v[0] = nexts[0]() ... >>> def intersect(s1, s2): ... d = {} ... e = {} ... r1 = filter(s1.has_key, s2.keys()) ... for x in r1: ... d[x] = list(intersectList([s1[x][0],s2[x][0]])) ... if len(d[x]) > 0: ... e[x] = d[x] ... return e ... >>> intersect(dict1,dict2) {'ac': [1, 3, '79b'], 'ab': [2]} >>> Best Regards Mario On 10 nov, 07:51, Paul Rudin wrote: > Lawrence D'Oliveiro writes: > > In message , Terry Reedy > > wrote: > > >> To echo John Nagle's point, if you want non-masochist volunteers to read > >> your code, write something readable like: > > >> dict1 = {'ab': [[1,2,3,'d3','d4',5], 12], > >> ? ? ? ? ? 'ac': [[1,3,'78a','79b'], 54], > >> ? ? ? ? ? 'ad': [[56,57,58,59], 34], > >> ? ? ? ? ? 'ax': [[56,57,58,59], 34]} > > > How come Python itself doesn?t display things that way? > > try: pprint.pprint(dict1) From danmcleran at yahoo.com Wed Nov 10 15:19:28 2010 From: danmcleran at yahoo.com (danmcleran at yahoo.com) Date: Wed, 10 Nov 2010 12:19:28 -0800 (PST) Subject: A matter of queues, tasks and multiprocessing References: Message-ID: <9e6f2dcc-7d15-4162-b3e9-9ef77a0b8980@n30g2000vbb.googlegroups.com> If you are using Python 2.6 or greater, look into the multiprocessing module. It may contain 90% of what you need. From clp2 at rebertia.com Wed Nov 10 15:26:20 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 10 Nov 2010 12:26:20 -0800 Subject: Feed subscription IM bot In-Reply-To: <74b044f0-0188-4adf-af86-635cca338846@o15g2000prh.googlegroups.com> References: <74b044f0-0188-4adf-af86-635cca338846@o15g2000prh.googlegroups.com> Message-ID: On Wed, Nov 10, 2010 at 6:49 AM, alexander wrote: > Hi, > > ? Can anyone help on this? http://stackoverflow.com/questions/1901828/best-python-xmpp-jabber-client-library http://www.djangoproject.com/ Come back when you have a much less nebulous question. And try googling first next time. Regards, Chris > ********************************************************************************************************************/ > > > ?The project should either be hosted online and usable from there, or > can be run locally. Complete ource code should be delivered along with > a brief readme for features. It should take about about 1-2 hours to > complete. > ?Basic requirements: Build a Python driven IM bot with the following > features > ?* A user can add the bot to his/her Google talk/jabber friends list. > ?* The user types the words "sub [feed_url]" to the bot to begin > subscribing to the feed at the specified feed_url ([feed_url] is the > placeholder for the actual feed url. e.g. http://myweb.com/feed) > * The user types the words "unsub [feed_url]" to stop subscribing to > the feed > * The bot scans the feed at a specified time interval, and sends new > contents to the subscribing user > Additional credits: > * Additional bot commands: "ls", "pause [feed_url]", " > resume[feed_url]", "grep [feed_url] [keywords]", whatever you think is > useful and fun, even not feed subscription related > * A web interface for reading/managing subscriptions > * Beautiful, extensible and scalable architecture > ?Requirements: > ?* Python 2.5 > ?* Robust and graceful error handling > ?* Robust unicode handling > > / > ************************************************************************************************************/ > > Thanks From robert.kern at gmail.com Wed Nov 10 15:27:50 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 10 Nov 2010 14:27:50 -0600 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: On 11/10/10 3:50 AM, Lawrence D'Oliveiro wrote: > In message, Jon > Dufresne wrote: > >> On Mon, Nov 8, 2010 at 11:35 PM, Lawrence D'Oliveiro ... > > I see that you published my unobfuscated e-mail address on USENET for all to > see. I obfuscated it for a reason, to keep the spammers away. I'm assuming > this was a momentary lapse of judgement, for which I expect an apology. > Otherwise, it becomes grounds for an abuse complaint to your ISP. I don't see any obfuscated email address at all in your own posts. I only see your full, unobfuscated e-mail address that you list on your web page. You are leaking the information, not Jon. -- 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 emile at fenx.com Wed Nov 10 15:33:02 2010 From: emile at fenx.com (Emile van Sebille) Date: Wed, 10 Nov 2010 12:33:02 -0800 Subject: How to read the Python tutorial? In-Reply-To: References: <59c26dd2-529f-4a4a-8f48-1ee5f35b068f@t7g2000vbj.googlegroups.com> <6b2d39f4-c9d9-4e77-9bb7-60e26dc334ee@j9g2000vbl.googlegroups.com> Message-ID: On 11/10/2010 8:19 AM rantingrick said... > I would start at the loop and figure out what is going on from there > with some print statements and the functions i showed you. Debugging > is a large part of any programming project. We all do it everyday. So > the sooner you learn the better. If you have a specific question feel > free to ask, but general debug issues are better solved yourself. > > A few more indispensable functions are dir() and help() All good info -- I'd add that you should learn and become comfortable with: import pdb; pdb.set_trace() to test running code. Emile From emile at fenx.com Wed Nov 10 15:35:51 2010 From: emile at fenx.com (Emile van Sebille) Date: Wed, 10 Nov 2010 12:35:51 -0800 Subject: multiple discontinued ranges In-Reply-To: <3250c9df-deeb-4610-93f2-93ba4b1568e4@p1g2000yqm.googlegroups.com> References: <7xy691w151.fsf@ruckus.brouhaha.com> <3250c9df-deeb-4610-93f2-93ba4b1568e4@p1g2000yqm.googlegroups.com> Message-ID: On 11/10/2010 9:34 AM xoff said... > On 10 nov, 18:15, Paul Rubin wrote: >> potentially lots of storage (you should use xrange instead). On the >> other hand you could just concatenate the lists with +, but I wouldn't >> advise that. > > I am curious, why wouldn't you advise something like this: > for i in chain(range(3,7) + range(17,23)): I'd assume because concatenation is generally considered expensive. If you were to do it, you'd likely drop the chain and write: for i in range(3,7) + range(17,23): Emile From ian.g.kelly at gmail.com Wed Nov 10 15:38:49 2010 From: ian.g.kelly at gmail.com (Ian) Date: Wed, 10 Nov 2010 12:38:49 -0800 (PST) Subject: DTD Parsing References: <4e7a49ec-1816-46e5-bc51-9f7c88f4d025@37g2000prx.googlegroups.com> <06071410-4684-4169-b1f8-0783e34f9062@f16g2000prj.googlegroups.com> Message-ID: On Nov 10, 1:05?am, r0g wrote: > > That's five whole lines of code. Why go to all that trouble when you can > > just do this: > > > import config > > Heh, mainly because I figure the config module will have a lot more > options than I have use for right now and therefore the docs will take > me longer to read than I will save by not just typing in the above ;) I think you misunderstand me. There is no config module and there are no docs to read. It's just the configuration file itself written as a Python script, containing arbitrary settings like: SESSION_TIMEOUT = 900 or: DOMAIN_OBJECTS = [ ObjectType1( option1 = 'foo', option2 = 'bar', ), ObjectType2( option1 = 'foo', option2 = 'baz', option3 = 42, ), ... ] Cheers, Ian From emile at fenx.com Wed Nov 10 15:40:07 2010 From: emile at fenx.com (Emile van Sebille) Date: Wed, 10 Nov 2010 12:40:07 -0800 Subject: Feed subscription IM bot In-Reply-To: <74b044f0-0188-4adf-af86-635cca338846@o15g2000prh.googlegroups.com> References: <74b044f0-0188-4adf-af86-635cca338846@o15g2000prh.googlegroups.com> Message-ID: On 11/10/2010 6:49 AM alexander said... > Hi, > > Can anyone help on this? > > / Probably most of us, but as it's obviously homework, and expected to take you 1-2 hours for the level class you're taking, and that it's now six hours later, why not post where you're at and we can help you wrap things up? Emile From moura.mario at gmail.com Wed Nov 10 15:42:53 2010 From: moura.mario at gmail.com (macm) Date: Wed, 10 Nov 2010 12:42:53 -0800 (PST) Subject: Learning Pyhton - Functional Programming - How intersect/difference two dict with dict/values? fast! References: <4d71519e-a232-427f-b4e0-5bae90fc4acb@n32g2000prc.googlegroups.com> <4cd9b16d$0$1640$742ec2ed@news.sonic.net> <87tyjpy0a3.fsf@rudin.co.uk> <7158677e-8b26-40ec-83a4-c46143e3ec3d@q18g2000vbm.googlegroups.com> Message-ID: <7e450af4-f5c0-406a-af6c-1e1caa224cef@o2g2000vbh.googlegroups.com> ... and this works! >>> def intersect(s1, s2): ... d = {} ... e = {} ... r1 = filter(s1.has_key, s2.keys()) ... for x in r1: ... d[x]= filter(lambda z:z in s1[x][0],s2[x][0]) ... if len(d[x]) > 0: ... e[x] = d[x] ... return e ... >>> intersect(dict1,dict2) {'ac': [1, 3, '79b'], 'ab': [2]} >>> but how I pass d[x] and make the filter? >>> result = [filter(lambda z:z in dict1[x][0],dict2[x][0]) for x in filter(dict1.has_key, dict2.keys())] >>> result [[], [1, 3, '79b'], [2]] >>> but should be {'ac': [1, 3, '79b'], 'ab': [2]} Best Regards Mario On 10 nov, 18:14, macm wrote: > Hi Folks > > I am studing yet (with fever, grasp and headache). > > I know I can do better, but first I should learn more about > "dictionary comprehension syntax" in python 2.65 > > >>> dict1 = {'ab':[[1,2,3,'d3','d4',5],12],'ac':[[1,3,'78a','79b'],54],'ad': [[56,57,58,59],34], 'ax': [[56,57,58,59],34]} > >>> dict2 = {'ab':[[22,2,'a0','42s','c4','d3'],12],'ab':[[2,4,50,42,'c4'],12],'ac':[[1,3,'79b',45,65,'er4'],54],'ae': [[56,57,58,59],34],'ax':[[9],34]} > > >>> # Arnaud Delobelle > > ... def intersectList(iterables): > ... ? ? nexts = [iter(iterable).next for iterable in iterables] > ... ? ? v = [next() for next in nexts] > ... ? ? while True: > ... ? ? ? ? for i in xrange(1, len(v)): > ... ? ? ? ? ? ? while v[0] > v[i]: > ... ? ? ? ? ? ? ? ? v[i] = nexts[i]() > ... ? ? ? ? ? ? if v[0] < v[i]: break > ... ? ? ? ? else: > ... ? ? ? ? ? ? yield v[0] > ... ? ? ? ? v[0] = nexts[0]() > ...>>> defintersect(s1, s2): > > ... ? ? d = {} > ... ? ? e = {} > ... ? ? r1 = filter(s1.has_key, s2.keys()) > ... ? ? for x in r1: > ... ? ? ? ? d[x] = list(intersectList([s1[x][0],s2[x][0]])) > ... ? ? ? ? if len(d[x]) > 0: > ... ? ? ? ? ? ? e[x] = d[x] > ... ? ? return e > ...>>>intersect(dict1,dict2) > > {'ac': [1, 3, '79b'], 'ab': [2]} > > > > Best Regards > > Mario > > On 10 nov, 07:51, Paul Rudin wrote: > > > Lawrence D'Oliveiro writes: > > > In message , Terry Reedy > > > wrote: > > > >> To echo John Nagle's point, if you want non-masochist volunteers to read > > >> your code, write something readable like: > > > >> dict1 = {'ab': [[1,2,3,'d3','d4',5], 12], > > >> ? ? ? ? ? 'ac': [[1,3,'78a','79b'], 54], > > >> ? ? ? ? ? 'ad': [[56,57,58,59], 34], > > >> ? ? ? ? ? 'ax': [[56,57,58,59], 34]} > > > > How come Python itself doesn?t display things that way? > > > try: pprint.pprint(dict1) > > From duane.kaufman at gmail.com Wed Nov 10 15:44:38 2010 From: duane.kaufman at gmail.com (TheSeeker) Date: Wed, 10 Nov 2010 12:44:38 -0800 (PST) Subject: Deditor 0.2.2 References: <6cdb5dd1-1868-4a6e-8b59-5b871f8d412e@42g2000prt.googlegroups.com> <613e4abc-329b-4ab3-8349-b3ec047cb747@r14g2000yqa.googlegroups.com> <470b7ee0-b109-4bb6-afa0-391baf02033e@35g2000prt.googlegroups.com> <84d92b8c-4592-4883-a8c4-929d93ff1138@j2g2000yqf.googlegroups.com> Message-ID: <10b9ba99-b27b-4366-a031-8731e5c095be@k11g2000vbf.googlegroups.com> On Nov 10, 7:51?am, Kruptein wrote: > On Nov 10, 12:49?pm, TheSeeker wrote: > > > > > > > > > > > On Nov 9, 10:04?am, Kruptein wrote: > > > > On Nov 8, 3:01?pm, Jean-Michel Pichavant > > > wrote: > > > > > TheSeeker wrote: > > > > > On Nov 6, 7:06 am, Kruptein wrote: > > > > > >> Hey, > > > > > >> I released version 0.2.2 of my pythonic text-editor ?Deditor. > > > > >> It adds the use of projects, a project is a set of files which you can > > > > >> open all at once to make development much faster and easier. > > > > > >> For more information visit launchpad:http://launchpad.net/deditor > > > > > >> I also uploaded a video to introduce you to deditor:http://www.youtube.com/watch?v=hS8xBu-39VI > > > > >> (note: youtube is still processing the file so you might have to wait > > > > >> a bit to see it) > > > > > > Hi, > > > > > I might have missed this, but it seems deditor requires Python above > > > > > 2.5? > > > > > > It would be nice to mention the requirements on the home page > > > > > somewhere. > > > > > > Thanks, > > > > > Duane > > > > > I already point that on the last release. You should really just > > > > consider writing the requirements (python & wx). > > > > > JM > > > > I'm going todo that right now! I alswyas forget it :p > > > Hi, > > > In addition, on Debian Lenny, with Python 2.5: > > > deditor.py:429: Warning: 'with' will become a reserved keyword in > > Python 2.6 > > Traceback (most recent call last): > > ? File "", line 1, in > > ? File "deditor.py", line 429 > > ? ? with open(cf,"wb") as configf: > > ? ? ? ? ? ? ^ > > SyntaxError: invalid syntax > > > So I don't think Python 2.5 works . > > > Thanks, > > Duane > > that's possible, I was only able to test it with version 2.7, I'm > going to change the dependencies then. thanks to point that out, 2.6 > should work though? > > and the windows wxpython version and the linux version are different > which causes some stupid bugs... :s Hi, Unfortunately, the wxPython bug precludes me seeing if Python 2.6 works (in Windows, at least). Maybe someone else can answer whether Python 2.6 works. Duane From python at mrabarnett.plus.com Wed Nov 10 15:50:00 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 10 Nov 2010 20:50:00 +0000 Subject: How to read the Python tutorial? In-Reply-To: <59c26dd2-529f-4a4a-8f48-1ee5f35b068f@t7g2000vbj.googlegroups.com> References: <59c26dd2-529f-4a4a-8f48-1ee5f35b068f@t7g2000vbj.googlegroups.com> Message-ID: <4CDB0578.1070700@mrabarnett.plus.com> On 10/11/2010 15:13, Zeynel wrote: > For instance, when the tutorial has http://docs.python.org/release/2.6/library/datetime.html > > class datetime.datetime > A combination of a date and a time. Attributes: year, month, day, > hour, minute, second, microsecond, and tzinfo. > > What does this mean? How do I use it? > > For instance, I have a DateTimeProperty mDate that I get from a query > in Google App Engine. This mDate has value > > mDATE = 2010-11-10 14:35:22.863000 > > But when I try > > datetime.datetime.mDATE.toordinal()) > > I get AttributeError. > > If I try something like > > td = mDATE.seconds > > in GAE development server I get > > AttributeError: 'datetime.datetime' object has no attribute 'seconds' > > What am I doing wrong? And how to understand this stuff so that I can > start using the language instead of trying to figure out types. Thanks > for your help. > If you lookup 'datetime' in Python's documentation you'll find that the attribute is called 'second'. From python at mrabarnett.plus.com Wed Nov 10 15:51:21 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 10 Nov 2010 20:51:21 +0000 Subject: multiple discontinued ranges In-Reply-To: <3250c9df-deeb-4610-93f2-93ba4b1568e4@p1g2000yqm.googlegroups.com> References: <7xy691w151.fsf@ruckus.brouhaha.com> <3250c9df-deeb-4610-93f2-93ba4b1568e4@p1g2000yqm.googlegroups.com> Message-ID: <4CDB05C9.6020400@mrabarnett.plus.com> On 10/11/2010 17:34, xoff wrote: > On 10 nov, 18:15, Paul Rubin wrote: >> you could use itertools.chain: >> >> from itertools import chain >> >> for i in chain(range(3,7), range(17,23)): >> ... >> >> I'm assuming you're using python 3. In python 2 each of those ranges >> expands immediately to a list, so on the one hand they're consuming >> potentially lots of storage (you should use xrange instead). On the >> other hand you could just concatenate the lists with +, but I wouldn't >> advise that. > > I am curious, why wouldn't you advise something like this: > for i in chain(range(3,7) + range(17,23)): > In Python 3 'range' is a generator, like 'xrange' in Python 2. From tjreedy at udel.edu Wed Nov 10 15:55:32 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 10 Nov 2010 15:55:32 -0500 Subject: How to read the Python tutorial? In-Reply-To: <59c26dd2-529f-4a4a-8f48-1ee5f35b068f@t7g2000vbj.googlegroups.com> References: <59c26dd2-529f-4a4a-8f48-1ee5f35b068f@t7g2000vbj.googlegroups.com> Message-ID: On 11/10/2010 10:13 AM, Zeynel wrote: > For instance, when the tutorial has http://docs.python.org/release/2.6/library/datetime.html > > class datetime.datetime > A combination of a date and a time. Attributes: year, month, day, > hour, minute, second, microsecond, and tzinfo. Note 'second' singular, as with other attributes. > td = mDATE.seconds You added a 's' to 'second', so > in GAE development server I get > AttributeError: 'datetime.datetime' object has no attribute 'seconds' -- Terry Jan Reedy From ethan at stoneleaf.us Wed Nov 10 15:57:24 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 10 Nov 2010 12:57:24 -0800 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: <4CDB0734.1050503@stoneleaf.us> Lawrence D'Oliveiro wrote: > In message , Jon > Dufresne wrote: > >> On Mon, Nov 8, 2010 at 11:35 PM, Lawrence D'Oliveiro ... > > I see that you published my unobfuscated e-mail address on USENET for all to > see. I obfuscated it for a reason, to keep the spammers away. I'm assuming > this was a momentary lapse of judgement, for which I expect an apology. > Otherwise, it becomes grounds for an abuse complaint to your ISP. Dumb question: Where did you obfuscate it? All I see is (apparently) the real one. Hoping-to-learn-something'ly yours, ~Ethan~ From clp2 at rebertia.com Wed Nov 10 16:04:44 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 10 Nov 2010 13:04:44 -0800 Subject: Curses Programming In-Reply-To: References: Message-ID: On Wed, Nov 10, 2010 at 6:42 AM, alexander wrote: > Subject: Curses Programming This has nothing whatsoever to do with the (n)curses library or even console programming. Lying in your subject line does not help gain you goodwill. > Hi, all > > ? ? Here is the test. Plz help..... If you want homework help, show that you've at least made /some/ sort of attempt, and ask a *specific* question regarding what part is giving you trouble. Otherwise, you're liable to be ignored with prejudice. Usage of expressions like "Plz" doesn't help your case either. Regards, Chris From emile at fenx.com Wed Nov 10 16:19:39 2010 From: emile at fenx.com (Emile van Sebille) Date: Wed, 10 Nov 2010 13:19:39 -0800 Subject: Enumeration of strings and export of the constants In-Reply-To: <4CDA9A4E.1050106@mm-sol.com> References: <4CDA9A4E.1050106@mm-sol.com> Message-ID: On 11/10/2010 5:12 AM lnenov said... > Hi, > > I need to enumerate a couple hundred strings to constants and export > them to another module(s) globals. Do they really need to be globals? Why not a constants in an object/container that would neither pollute the global namespace nor risk being shadowed by subsequent inadvertent name conflict? > In the mean time I want to keep my module's namespace as clear as I can > and I don't want to use "import *" later. > > Here is the code I intend to use: > > test.py > 1 class Apinamespace(): > 2 @staticmethod > 3 def import_to(destination): > 4 > 5 for name, number in Apinamespace.__dict__.items(): > 6 if (name.startswith('__') and name.endswith('__')) or name == > "import_to": # :) > 7 pass > 8 else: > 9 setattr(destination, name, number) > 10 > 11 class Enumerate(): > 12 def __init__(self, names, start = 0, step = 1): > 13 enumerate_to = Apinamespace > 14 > 15 for number, name in self.enumerate(names, start, step): > 16 setattr(enumerate_to, name, number) > 17 > 18 def enumerate(self, names, start = 0, step = 1): > 19 for index in range(len(names)): > 20 yield (start, names[index]) > 21 start += step > 22 > 23 example_names = ['Foo','Bar','Free', 'Beer'] > 24 example_names2 = ['Foo_me_too', 'Bar_me_too', 'Free_me_too', > 'Beer_me_too'] > 25 Enumerate(example_names) > 26 Enumerate(example_names2, 4, 2) > > This works like a charm: > >>> import sys, test > >>> thismodule = sys.modules[__name__] > >>> test.Apinamespace.import_to(thismodule) > >>> Beer > 3 > >>> Beer_me_too > 10 > > Is there a better and more common way to do this? Yes -- don't. It'd generally indicate what's been called 'a bad smell' Emile > Do you know of a way to see the module in/from which a function was > called without using traceback and frames? (I want to remove the > argument from Apinamespace.import_me) > And can line 6 be replaced by something less evil. > > Thanks for any suggestions. > > Lyudmil > > > From hpj at urpla.net Wed Nov 10 16:20:07 2010 From: hpj at urpla.net (Hans-Peter Jansen) Date: Wed, 10 Nov 2010 22:20:07 +0100 Subject: ANN: PyQt v4.8.1 Released In-Reply-To: References: Message-ID: <201011102220.08040.hpj@urpla.net> Am Monday 08 November 2010 02:26:51 schrieb Robert Kern: > On 2010-11-07 18:53 , Lawrence D'Oliveiro wrote: > > In message, Robert > > Kern > > > > wrote: > >> Everyone here knew exactly what he meant. > > > > But if you don?t banana the right tomato, everybody could be grapefruit, > > right? > > > > You know what I mean. > > And as I reiterated in the part that you snipped, he is not using > "commercial" as a synonym for "proprietary". It is the license that he > sells commercially. ..with a pretty affordable price, I may add. I don't understand all the fuzz about some obvious formulation. It it a concern only for those who want to _sell_ their _products_ based on PyQt and consequently don't want to reveal their source code. Pete (Not being afflicted in any way with Riverbankcomputing, other than being a satisfied commercial licencee). From usenet-nospam at seebs.net Wed Nov 10 16:21:06 2010 From: usenet-nospam at seebs.net (Seebs) Date: 10 Nov 2010 21:21:06 GMT Subject: Silly newbie question - Caret character (^) References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> Message-ID: On 2010-11-10, Terry Reedy wrote: > I was referring to Schildt using gets() all the time and thereby > teaching new C generations to do he same. Ahh, yes. I am told that the current plan is to kill it in C1X. I would shed no tears. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From no.email at nospam.invalid Wed Nov 10 16:24:32 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 10 Nov 2010 13:24:32 -0800 Subject: multiple discontinued ranges References: <7xy691w151.fsf@ruckus.brouhaha.com> <3250c9df-deeb-4610-93f2-93ba4b1568e4@p1g2000yqm.googlegroups.com> Message-ID: <7xbp5wx46n.fsf@ruckus.brouhaha.com> xoff writes: > I am curious, why wouldn't you advise something like this: > for i in chain(range(3,7) + range(17,23)): First of all, the outer chain does nothing. Second, concatenating the two lists creates a new list, consuming storage and taking time copying all the elements. Third, if there are n lists instead of two, I think the copying time is O(n**2) in the number of lists because there are n-1 separate copy operations and they keep getting larger. From oly at digitaloctave.com Wed Nov 10 16:38:32 2010 From: oly at digitaloctave.com (Oliver Marks) Date: Wed, 10 Nov 2010 21:38:32 +0000 Subject: Embedded python issue with gtk Message-ID: <1289425112.18057.6.camel@leela> I have already emailed about this issue, but have still not got any where. I have reduced the plugin down to its bare minimum it simple loads the the python interpreter and imports gtk library. If i do this outside the embedded python it imports and i can use the gtk library, so why does it not work when embedded i am on ubuntu 10.10 64bit if its a specific issue on this platform. the code is below or you can get the code with the build system from the link below, obviously to see the error you need to load the plugin into geany. I am guessing this is a linking issue just hoping someone can point me in the right direction. http://ubuntuone.com/p/OhA/ #include /* For Python itself. This MUST come first. */ #include "geany.h" /* for the GeanyApp data type */ #include "geanyplugin.h" /* for the GeanyApp data type */ #include "plugindata.h" /* this defines the plugin API */ #define PLUGIN_NAME _("Geany Python Test") PLUGIN_VERSION_CHECK(GEANY_API_VERSION) /* All plugins must set name, description, version and author. */ PLUGIN_SET_INFO(PLUGIN_NAME, _("Test Python plugin."), _(VERSION), _("Test Author")) /* initialise the plugin */ void plugin_init(GeanyData *data){ printf("Loading the test Python module.\n"); Py_Initialize(); /* Start the Python interpreter. */ PyRun_SimpleString("import gtk"); } /* Cleanup the plugin when required */ void plugin_cleanup(void){ Py_Finalize(); } This is the error i get on loading of the plugin. Traceback (most recent call last): File "", line 1, in File "/usr/lib/pymodules/python2.6/gtk-2.0/gtk/__init__.py", line 30, in import gobject as _gobject File "/usr/lib/pymodules/python2.6/gtk-2.0/gobject/__init__.py", line 26, in from glib import spawn_async, idle_add, timeout_add, timeout_add_seconds, \ File "/usr/lib/pymodules/python2.6/gtk-2.0/glib/__init__.py", line 22, in from glib._glib import * ImportError: /usr/lib/libpyglib-2.0-python2.6.so.0: undefined symbol: PyExc_ImportError From hniksic at xemacs.org Wed Nov 10 16:52:13 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Wed, 10 Nov 2010 22:52:13 +0100 Subject: Is Eval *always* Evil? References: Message-ID: <87wrok4zjm.fsf@xemacs.org> Simon Mullis writes: > If "eval" is not the way forward, are there any suggestions for > another way to do this? ast.literal_eval might be the thing for you. From ian.g.kelly at gmail.com Wed Nov 10 16:54:08 2010 From: ian.g.kelly at gmail.com (Ian) Date: Wed, 10 Nov 2010 13:54:08 -0800 (PST) Subject: How to read the Python tutorial? References: <59c26dd2-529f-4a4a-8f48-1ee5f35b068f@t7g2000vbj.googlegroups.com> Message-ID: <128980d1-283d-4017-a137-1eca4291f806@k30g2000vbn.googlegroups.com> On Nov 10, 8:13?am, Zeynel wrote: > But when I try > > datetime.datetime.mDATE.toordinal()) > > I get AttributeError. Others have already explained why "mDATE.seconds" does not work, but I wanted to touch on this as well. The above fails because "mDATE" is not an attribute of the "datetime.datetime" class, which is to be expected since you've merely defined it as a local variable. If you want to call the "toordinal" method of mDATE, just do this: mDATE.toordinal() or this: datetime.datetime.toordinal(mDATE) But in most cases the first version is preferred. As an aside, your capitalization scheme would drive me insane. I suggest reading PEP 8, the Python style guide, and following the recommendations there. Also, it is not customary in Python to prefix attribute names with the string "m" or "m_" as it is in C++. Because Python does not do implicit attribute lookup, it is always clear from context whether a name refers to an attribute or not, and so the "m" is superfluous. Cheers, Ian From robert.kern at gmail.com Wed Nov 10 17:01:07 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 10 Nov 2010 16:01:07 -0600 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: On 11/10/10 2:27 PM, Robert Kern wrote: > On 11/10/10 3:50 AM, Lawrence D'Oliveiro wrote: >> In message, Jon >> Dufresne wrote: >> >>> On Mon, Nov 8, 2010 at 11:35 PM, Lawrence D'Oliveiro ... >> >> I see that you published my unobfuscated e-mail address on USENET for all to >> see. I obfuscated it for a reason, to keep the spammers away. I'm assuming >> this was a momentary lapse of judgement, for which I expect an apology. >> Otherwise, it becomes grounds for an abuse complaint to your ISP. > > I don't see any obfuscated email address at all in your own posts. I only see > your full, unobfuscated e-mail address that you list on your web page. You are > leaking the information, not Jon. FWIW, I am reading this via GMane using Thunderbird. Perhaps something along the way is unobfuscating your email address. -- 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 msarro at gmail.com Wed Nov 10 17:46:15 2010 From: msarro at gmail.com (Matty Sarro) Date: Wed, 10 Nov 2010 17:46:15 -0500 Subject: Looping through files in a directory Message-ID: Short story - I have a few thousand files in a directory I need to parse through. Is there a simple way to loop through files? I'd like to avoid writing a python script that can parse 1 file, and have to call it a few thousand times from a bash script. Any input or pointers to functions that'd help would be very much appreciated. Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Wed Nov 10 17:53:54 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 10 Nov 2010 23:53:54 +0100 Subject: DTD Parsing In-Reply-To: References: <4e7a49ec-1816-46e5-bc51-9f7c88f4d025@37g2000prx.googlegroups.com> <06071410-4684-4169-b1f8-0783e34f9062@f16g2000prj.googlegroups.com> Message-ID: Felipe Bastos Nunes, 10.11.2010 13:34: > Does any, libxml2 or lxml, collect children like jdom does in java? > List children = myRoot.getChildren(); Bah, that's *so* Java. ;) ElementTree and lxml.etree do it like this: children = list(myRoot) lxml also supports XPath and lots of other helpful stuff. Stefan From emile at fenx.com Wed Nov 10 17:56:45 2010 From: emile at fenx.com (Emile van Sebille) Date: Wed, 10 Nov 2010 14:56:45 -0800 Subject: Questions: While And List Comprehension In-Reply-To: References: Message-ID: On 11/10/2010 4:36 AM Felipe Vinturini said... > Hi Folks, > > I am quite new to python and I don't have a lot of experience with it yet. > > I have two simple questions: > > 1. Is there a way to limit the number of times a list comprehension will > execute? E.g. I want to read from input only 5 values, so I would like > something like (the values between # # are what I want): > =================================================================================== > COUNT = 0 > print [ v for v in sys.stdin.readlines() *# *IF COUNT< 5* #* ] ## Increment > COUNT somewhere Easiest would be print [ v for v in sys.stdin.readlines()[:5] ] but that still reads the entire sys.stdin (whatever it may be...) > =================================================================================== > > 2.* *I would like to know another way, a more pythonic way, to write the > following: > =================================================================================== > import sys > > def Z(iNumber): > sum=0 > while (iNumber>=5): > iNumber=iNumber/5 > sum = sum + iNumber > print sum > > def factorialCountZeros2(): > sysStdinReadLine = sys.stdin.readline > numValues = int(sysStdinReadLine()) > [ Z(int(sysStdinReadLine())) for x in xrange(numValues) ] > > if __name__ == '__main__': > factorialCountZeros2() > =================================================================================== > To be more specific, I would like to know about the Z function, is there a > way to rewrite that while with list comprehension? Well, you could use def X(iNumber): print sum([iNumber/(5**ii) for ii in range(1,2*int(len("%s" % iNumber)))]) but the range selection is rather arbitrary. Emile > > This code is to solve the CodeChef problem: > http://www.codechef.com/problems/FCTRL/ (I am still in the easy part) and it > executed in 2.5 secs, I would like to know if there is something else I can > improve performance. > > Thanks for your attention! > > Regards, > Felipe. > > From prologic at shortcircuit.net.au Wed Nov 10 17:59:25 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 11 Nov 2010 08:59:25 +1000 Subject: Curses Programming In-Reply-To: References: Message-ID: On Thu, Nov 11, 2010 at 12:42 AM, alexander wrote: > Could any give a hand? Assignment ? Homework ? cheers James -- -- James Mills -- -- "Problems are solved by method" From prologic at shortcircuit.net.au Wed Nov 10 18:01:37 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 11 Nov 2010 09:01:37 +1000 Subject: Questions: While And List Comprehension In-Reply-To: References: Message-ID: On Wed, Nov 10, 2010 at 10:36 PM, Felipe Vinturini wrote: > 1. Is there a way to limit the number of times a list comprehension will > execute??E.g. I want to read from input only 5 values, so I would like > something like (the values between # # are what I want): > =================================================================================== > COUNT = 0 > print [ v for v in sys.stdin.readlines() # IF COUNT < 5 # ] ## Increment > COUNT somewhere > =================================================================================== print [v for v in sys.stdin.readlines()[:5]] cheers James -- -- James Mills -- -- "Problems are solved by method" From ldo at geek-central.gen.new_zealand Wed Nov 10 18:07:17 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 11 Nov 2010 12:07:17 +1300 Subject: Development Vs Release References: <201011100749474192-nomail@thisaddresscom> Message-ID: In message <201011100749474192-nomail at thisaddresscom>, Sven wrote: > I don't like the idea of flags inside the code as they can often get > missed when developers release their code, ending up with released > versions that import modules from the developer's working directory. I have used a flag, together with a custom installation script that knows how to edit that flag in each source file depending on whether it?s being installed for testing or production use. From lists at cheimes.de Wed Nov 10 18:14:36 2010 From: lists at cheimes.de (Christian Heimes) Date: Thu, 11 Nov 2010 00:14:36 +0100 Subject: Is Eval *always* Evil? In-Reply-To: References: Message-ID: Am 10.11.2010 18:56, schrieb Simon Mullis: Yes, eval is evil, may lead to security issues and it's unnecessary slow, too. > # In the meantime - and as a proof of concept - I'm using a dict instead. > > xpathlib = { > "houses" : r'[ y.tag for y in x.xpath("//houses/*") ]', > "names" : r'[ y.text for y in x.xpath("//houses/name") ]', > "footwear_type" : r'[ y.tag for y in > x.xpath("//cupboard/bottom_shelf/*") ]', > "shoes" : r'[ y.text for y in > x.xpath("//cupboard/bottom_shelf/shoes/*") ]', > "interface_types" : r'[ y.text[:2] for y in > x.xpath("//interface/name") ]', > } You have two possibilities here: * either learn more XPath. You can do everything with XPath as well, for example "//houses/name/text()" * use lambdas instead, for example "names" : lambda x: [y.text for y in x.xpath("//houses/name")] Christian From lists at cheimes.de Wed Nov 10 18:18:41 2010 From: lists at cheimes.de (Christian Heimes) Date: Thu, 11 Nov 2010 00:18:41 +0100 Subject: DTD Parsing In-Reply-To: <06071410-4684-4169-b1f8-0783e34f9062@f16g2000prj.googlegroups.com> References: <4e7a49ec-1816-46e5-bc51-9f7c88f4d025@37g2000prx.googlegroups.com> <06071410-4684-4169-b1f8-0783e34f9062@f16g2000prj.googlegroups.com> Message-ID: Am 10.11.2010 04:36, schrieb Asun Friere: > Yes but configuration files are not necessarily meant to be edited by > humans either! Yeah, you are right. I'm sorry but every time I read XML and configuration in one sentence, I see the horror of TomCat or Shibboleth XML configs popping up. From ian.g.kelly at gmail.com Wed Nov 10 18:30:01 2010 From: ian.g.kelly at gmail.com (Ian) Date: Wed, 10 Nov 2010 15:30:01 -0800 (PST) Subject: Enumeration of strings and export of the constants References: Message-ID: On Nov 10, 6:12?am, lnenov wrote: > Is there a better and more common way to do this? from itertools import count, izip class APINamespace(object): def __init__(self): self._named_values = [] def enumerate(self, names, start=0, step=1): self._named_values.extend(izip(names, count(start, step))) def import_to(self, destination): for name, number in self._named_values: setattr(destination, name, number) Note the "step" parameter of itertools.count requires Python 2.7 or 3.1. > And can line 6 be replaced by something less evil. Yes, by putting the names to be imported into their own container as I've done above, instead of polluting the class dictionary with them. Cheers, Ian From arnodel at gmail.com Wed Nov 10 18:35:28 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Wed, 10 Nov 2010 23:35:28 +0000 Subject: Am I The Only One Who Keeps Reading =?utf-8?B?4oCcTnVtcHk=?= =?utf-8?B?4oCd?= as =?utf-8?B?4oCcTnVtcHR54oCdPw==?= References: <940162c6-b61a-4bb7-9965-6e155716cda8@n30g2000vbb.googlegroups.com> Message-ID: <87hbfoycov.fsf@gmail.com> rantingrick writes: >[...] it's "Num-pee" for me. If the "py" is appended i use "x-pee" and >if it is pre i use "pie- x". So pypy is "pie-pee", not "pie-pie" or "pee-pee". With that edifying thought, I'm off to bed. -- Arnaud From steve at holdenweb.com Wed Nov 10 18:36:24 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 10 Nov 2010 18:36:24 -0500 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: On 11/10/2010 4:50 AM, Lawrence D'Oliveiro wrote: > In message , Jon > Dufresne wrote: > >> On Mon, Nov 8, 2010 at 11:35 PM, Lawrence D'Oliveiro ... > > I see that you published my unobfuscated e-mail address on USENET for all to > see. I obfuscated it for a reason, to keep the spammers away. I'm assuming > this was a momentary lapse of judgement, for which I expect an apology. > Otherwise, it becomes grounds for an abuse complaint to your ISP. > Lawrence: Please stop making yourself look ridiculous with these requests. Accidents happen, and it does little or no good to draw people's attention to it. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From prologic at shortcircuit.net.au Wed Nov 10 19:14:42 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 11 Nov 2010 10:14:42 +1000 Subject: Looping through files in a directory In-Reply-To: References: Message-ID: On Thu, Nov 11, 2010 at 8:46 AM, Matty Sarro wrote: > Short story - I have a few thousand files in a directory I need to parse > through. Is there a simple way to loop through files? I'd like to avoid > writing a python script that can parse 1 file, and have to call it a few > thousand times from a bash script. Any input or pointers to functions that'd > help would be very much appreciated. Thanks! os.walk or os.listdir cheers James -- -- James Mills -- -- "Problems are solved by method" From steve at holdenweb.com Wed Nov 10 19:17:34 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 10 Nov 2010 19:17:34 -0500 Subject: Looping through files in a directory In-Reply-To: References: Message-ID: On 11/10/2010 5:46 PM, Matty Sarro wrote: > Short story - I have a few thousand files in a directory I need to parse > through. Is there a simple way to loop through files? I'd like to avoid > writing a python script that can parse 1 file, and have to call it a few > thousand times from a bash script. Any input or pointers to functions > that'd help would be very much appreciated. Thanks! > from glob import glob for filename in glob("*"): # do something with filename regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From prologic at shortcircuit.net.au Wed Nov 10 19:29:04 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 11 Nov 2010 10:29:04 +1000 Subject: Questions: While And List Comprehension In-Reply-To: References: Message-ID: On Thu, Nov 11, 2010 at 8:56 AM, Emile van Sebille wrote: > Easiest would be print [ v for v in sys.stdin.readlines()[:5] ] but that > still reads the entire sys.stdin (whatever it may be...) Here's a way of doing the same thing without consuming the entire stream (sys.stdin): #!/usr/bin/env python import sys print [v for v in list(line for line in sys.stdin)[:5]] This uses a generator expression to read from stdin, converts this to a list (only getting the first 5 items). cheers James -- -- James Mills -- -- "Problems are solved by method" From clp2 at rebertia.com Wed Nov 10 19:43:10 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 10 Nov 2010 16:43:10 -0800 Subject: Looping through files in a directory In-Reply-To: References: Message-ID: On Wed, Nov 10, 2010 at 2:46 PM, Matty Sarro wrote: > Short story - I have a few thousand files in a directory I need to parse > through. Is there a simple way to loop through files? I'd like to avoid > writing a python script that can parse 1 file, and have to call it a few > thousand times from a bash script. Any input or pointers to functions that'd > help would be very much appreciated. Thanks! http://docs.python.org/library/os.html#os.listdir http://docs.python.org/library/os.html#os.walk Cheers, Chris -- http://blog.rebertia.com From emile at fenx.com Wed Nov 10 19:46:56 2010 From: emile at fenx.com (Emile van Sebille) Date: Wed, 10 Nov 2010 16:46:56 -0800 Subject: Looping through files in a directory In-Reply-To: References: Message-ID: On 11/10/2010 2:46 PM Matty Sarro said... > Short story - I have a few thousand files in a directory I need to parse > through. Is there a simple way to loop through files? I'd like to avoid > writing a python script that can parse 1 file, and have to call it a few > thousand times from a bash script. Any input or pointers to functions that'd > help would be very much appreciated. Thanks! > > glob works pretty well. Emile From steve at holdenweb.com Wed Nov 10 19:57:29 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 10 Nov 2010 19:57:29 -0500 Subject: Questions: While And List Comprehension In-Reply-To: References: Message-ID: On 11/10/2010 6:01 PM, James Mills wrote: > On Wed, Nov 10, 2010 at 10:36 PM, Felipe Vinturini > wrote: >> 1. Is there a way to limit the number of times a list comprehension will >> execute? E.g. I want to read from input only 5 values, so I would like >> something like (the values between # # are what I want): >> =================================================================================== >> COUNT = 0 >> print [ v for v in sys.stdin.readlines() # IF COUNT < 5 # ] ## Increment >> COUNT somewhere >> =================================================================================== > > print [v for v in sys.stdin.readlines()[:5]] > how about print [sys.stdin.readline() for i in range(5)] At least that won't consume the whole file. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From wuwei23 at gmail.com Wed Nov 10 19:58:06 2010 From: wuwei23 at gmail.com (alex23) Date: Wed, 10 Nov 2010 16:58:06 -0800 (PST) Subject: Commercial or Famous Applicattions.? References: Message-ID: Martin Gregorie wrote: > Now, if ESR had fixed fetchmail [...] Did you try submitting patches? From wuwei23 at gmail.com Wed Nov 10 20:01:52 2010 From: wuwei23 at gmail.com (alex23) Date: Wed, 10 Nov 2010 17:01:52 -0800 (PST) Subject: Questions: While And List Comprehension References: Message-ID: Steve Holden wrote: > how about print [sys.stdin.readline() for i in range(5)] > > At least that won't consume the whole file. +1 on this approach. Clear and obvious and not reliant on any library modules other than sys. itertools, what WAS I thinking? :) From python.list at tim.thechases.com Wed Nov 10 20:24:22 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 10 Nov 2010 19:24:22 -0600 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: <4CDB45C6.7030309@tim.thechases.com> On 11/10/10 03:50, Lawrence D'Oliveiro wrote: > In message, Jon > Dufresne wrote: > >> Lawrence D'Oliveiro wrote: > > I see that you published my unobfuscated e-mail address on USENET for all to > see. I obfuscated it for a reason, to keep the spammers away. I'm assuming > this was a momentary lapse of judgement, for which I expect an apology. > Otherwise, it becomes grounds for an abuse complaint to your ISP. Amusingly, as others have noted, you replied with an unobfuscated email address. However, I suspect that if you file a complaint with Jon's ISP, they'll laugh at your complaint just like my ISP did when you complained to them[1]. My ISP contact's response pretty much boiled down to "yeah, I was pretty certain he was just being a tool, but I wanted to follow up to make sure" and sharing a laugh with me at your expense. Try spending your time learning to really obfuscate or finding a tool to better handle spam, instead of wasting your time (even if it's just firing off the same idiotic email template) being a tool about it. -tkc [1] http://www.mail-archive.com/python-list at python.org/msg287766.html From python.list at tim.thechases.com Wed Nov 10 20:28:15 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 10 Nov 2010 19:28:15 -0600 Subject: Looping through files in a directory In-Reply-To: References: Message-ID: <4CDB46AF.7070405@tim.thechases.com> On 11/10/10 16:46, Matty Sarro wrote: > Short story - I have a few thousand files in a directory I > need to parse through. Is there a simple way to loop through > files? I'd like to avoid writing a python script that can > parse 1 file, and have to call it a few thousand times from a > bash script. Any input or pointers to functions that'd help > would be very much appreciated. Sounds like you're reaching for os.listdir() import os TARGET = '/path/to/wherever' for fname in os.listdir(TARGET): process_file(os.path.join(TARGET, fname)) or possibly glob.glob() from glob import glob for fname in glob(os.path.join(TARGET, '*.txt')): process_file(fname) -tkc From python at mrabarnett.plus.com Wed Nov 10 20:38:49 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 11 Nov 2010 01:38:49 +0000 Subject: Questions: While And List Comprehension In-Reply-To: References: Message-ID: <4CDB4929.4010006@mrabarnett.plus.com> On 11/11/2010 00:29, James Mills wrote: > On Thu, Nov 11, 2010 at 8:56 AM, Emile van Sebille wrote: >> Easiest would be print [ v for v in sys.stdin.readlines()[:5] ] but that >> still reads the entire sys.stdin (whatever it may be...) > > Here's a way of doing the same thing without consuming the entire > stream (sys.stdin): > > #!/usr/bin/env python > > import sys > print [v for v in list(line for line in sys.stdin)[:5]] > > This uses a generator expression to read from stdin, converts this to > a list (only getting the first 5 items). > 'list' will exhaust the input, then the slicing will return at most 5 lines. From clp2 at rebertia.com Wed Nov 10 21:18:09 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 10 Nov 2010 18:18:09 -0800 Subject: Questions: While And List Comprehension In-Reply-To: <4CDB4929.4010006@mrabarnett.plus.com> References: <4CDB4929.4010006@mrabarnett.plus.com> Message-ID: On Wed, Nov 10, 2010 at 5:38 PM, MRAB wrote: > On 11/11/2010 00:29, James Mills wrote: >> On Thu, Nov 11, 2010 at 8:56 AM, Emile van Sebille ?wrote: >>> Easiest would be print [ v for v in sys.stdin.readlines()[:5] ] but that >>> still reads the entire sys.stdin (whatever it may be...) >> >> Here's a way of doing the same thing without consuming the entire >> stream (sys.stdin): >> >> #!/usr/bin/env python >> >> import sys >> print [v for v in list(line for line in sys.stdin)[:5]] >> >> This uses a generator expression to read from stdin, converts this to >> a list (only getting the first 5 items). >> > 'list' will exhaust the input, then the slicing will return at most 5 > lines. Also, the list comprehension and generator expression are both the identity versions thereof, so a shorter equivalent version of the erroneous code would be simply: print list(sys.stdin)[:5] Cheers, Chris From robert.kern at gmail.com Wed Nov 10 21:39:52 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 10 Nov 2010 20:39:52 -0600 Subject: Is Eval *always* Evil? In-Reply-To: References: Message-ID: On 2010-11-10 17:14 , Christian Heimes wrote: > Am 10.11.2010 18:56, schrieb Simon Mullis: > > Yes, eval is evil, may lead to security issues and it's unnecessary > slow, too. > >> # In the meantime - and as a proof of concept - I'm using a dict instead. >> >> xpathlib = { >> "houses" : r'[ y.tag for y in x.xpath("//houses/*") ]', >> "names" : r'[ y.text for y in x.xpath("//houses/name") ]', >> "footwear_type" : r'[ y.tag for y in >> x.xpath("//cupboard/bottom_shelf/*") ]', >> "shoes" : r'[ y.text for y in >> x.xpath("//cupboard/bottom_shelf/shoes/*") ]', >> "interface_types" : r'[ y.text[:2] for y in >> x.xpath("//interface/name") ]', >> } > > You have two possibilities here: > > * either learn more XPath. You can do everything with XPath as well, > for example "//houses/name/text()" > > * use lambdas instead, for example "names" : lambda x: [y.text for y in > x.xpath("//houses/name")] Well, the key reason he is using strings is so that he can easily slap on a Django admin UI to allow certain users to add new expressions. lambdas don't help with that. -- 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 Wed Nov 10 21:40:11 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 10 Nov 2010 20:40:11 -0600 Subject: Is Eval *always* Evil? In-Reply-To: <87wrok4zjm.fsf@xemacs.org> References: <87wrok4zjm.fsf@xemacs.org> Message-ID: On 2010-11-10 15:52 , Hrvoje Niksic wrote: > Simon Mullis writes: > >> If "eval" is not the way forward, are there any suggestions for >> another way to do this? > > ast.literal_eval might be the thing for you. No, that doesn't work since he needs to call methods. -- 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 ldo at geek-central.gen.new_zealand Wed Nov 10 21:54:38 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 11 Nov 2010 15:54:38 +1300 Subject: Silly newbie question - Caret character (^) References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> Message-ID: In message , Seebs wrote: > On 2010-11-10, Terry Reedy wrote: > >> I was referring to Schildt using gets() all the time and thereby >> teaching new C generations to do he same. > > Ahh, yes. > > I am told that the current plan is to kill it in C1X. I would shed no > tears. Another function that should be deprecated is strncat?I myself was caught out misunderstanding it recently. What purpose does it serve? From ldo at geek-central.gen.new_zealand Wed Nov 10 21:55:51 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 11 Nov 2010 15:55:51 +1300 Subject: Is Eval *always* Evil? References: Message-ID: In message , Robert Kern wrote: > Well, the key reason he is using strings is so that he can easily slap on > a Django admin UI to allow certain users to add new expressions. lambdas > don't help with that. Provded you can trust the users who are allowed to add such expressions, it?s probably all right. From ldo at geek-central.gen.new_zealand Wed Nov 10 22:02:31 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 11 Nov 2010 16:02:31 +1300 Subject: DTD Parsing References: <4e7a49ec-1816-46e5-bc51-9f7c88f4d025@37g2000prx.googlegroups.com> Message-ID: In message , Christian Heimes wrote: > Don't repeat the mistakes of others and use XML as a configuration > language. XML isn't meant to be edited by humans. My principle is: anything automatically generated by machine is not fit for viewing or editing by humans. There?s nothing special about XML in this regard. I have successfully got a nontechnical client to put together XML control files to drive some software I wrote for him. He used KXMLEditor (part of KDE 3.x, seems to be defunct nowadays), and of course he always started with an existing example and modified that. But it wasn?t too long before he was regularly doing it without needing to ask me questions. From steve at holdenweb.com Wed Nov 10 22:02:51 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 10 Nov 2010 22:02:51 -0500 Subject: Questions: While And List Comprehension In-Reply-To: References: Message-ID: On 11/10/2010 7:29 PM, James Mills wrote: > On Thu, Nov 11, 2010 at 8:56 AM, Emile van Sebille wrote: >> Easiest would be print [ v for v in sys.stdin.readlines()[:5] ] but that >> still reads the entire sys.stdin (whatever it may be...) > > Here's a way of doing the same thing without consuming the entire > stream (sys.stdin): > > #!/usr/bin/env python > > import sys > print [v for v in list(line for line in sys.stdin)[:5]] > > This uses a generator expression to read from stdin, converts this to > a list (only getting the first 5 items). > A generator expression slicing only accesses as many elements as it needs to? But surely list(line for line in sys.stdin) will be evaluated before the indexing is applied? I'd have thought that would have exhausted the input file. >>> f = open("/tmp/data", "w") >>> for i in 'one two three four five six seven eight nine ten'.split(): ... f.write("%s\n" % i) ... >>> f.close() >>> f = open("/tmp/data") >>> print [v for v in list(line for line in f)[:5]] ['one\n', 'two\n', 'three\n', 'four\n', 'five\n'] >>> f.next() Traceback (most recent call last): File "", line 1, in StopIteration >>> This suggests that you are mistaken about not exhausting the source. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From ldo at geek-central.gen.new_zealand Wed Nov 10 22:04:15 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 11 Nov 2010 16:04:15 +1300 Subject: DTD Parsing References: <4e7a49ec-1816-46e5-bc51-9f7c88f4d025@37g2000prx.googlegroups.com> <06071410-4684-4169-b1f8-0783e34f9062@f16g2000prj.googlegroups.com> Message-ID: In message , Christian Heimes wrote: > I'm sorry but every time I read XML and configuration in one sentence, I > see the horror of TomCat or Shibboleth XML configs popping up. Tomcat I know is written in Java; let me guess?Shibboleth is too? From ldo at geek-central.gen.new_zealand Wed Nov 10 22:07:45 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 11 Nov 2010 16:07:45 +1300 Subject: DTD Parsing References: <4e7a49ec-1816-46e5-bc51-9f7c88f4d025@37g2000prx.googlegroups.com> <06071410-4684-4169-b1f8-0783e34f9062@f16g2000prj.googlegroups.com> Message-ID: In message , Ian Kelly wrote: > On 11/9/2010 11:14 PM, r0g wrote: >> >> config = {} >> for line in (open("config.txt", 'r')): >> if len(line) > 0 and line[0] <> "#": >> param, value = line.rstrip().split("=",1) >> config[param] = value > > That's five whole lines of code. Why go to all that trouble when you > can just do this: > > import config Not a good idea. Because if there any mistakes in the config, you would like to print useful explanatory error messages to help the writer of the config file figure out what they?ve done wrong, rather than relying on them to understand Python exception tracebacks. Also your config validation rules may not map easily to Python language rules. From ian.g.kelly at gmail.com Wed Nov 10 22:10:24 2010 From: ian.g.kelly at gmail.com (Ian) Date: Wed, 10 Nov 2010 19:10:24 -0800 (PST) Subject: Questions: While And List Comprehension References: Message-ID: <4a556852-a1f8-41bf-8df6-56397ef7fd8e@c39g2000yqi.googlegroups.com> On 11/10/2010 4:36 AM Felipe Vinturini said... > 2.* *I would like to know another way, a more pythonic way, to write the > following: > =================================================================================== > import sys > > def Z(iNumber): > ? ? ?sum=0 > ? ? ?while (iNumber>=5): > ? ? ? ? ?iNumber=iNumber/5 > ? ? ? ? ?sum = sum + iNumber > ? ? ?print sum > > def factorialCountZeros2(): > ? ? ?sysStdinReadLine = sys.stdin.readline > ? ? ?numValues = int(sysStdinReadLine()) > ? ? ?[ Z(int(sysStdinReadLine())) for x in xrange(numValues) ] > > if __name__ == '__main__': > ? ? ?factorialCountZeros2() > =================================================================================== > To be more specific, I would like to know about the Z function, is there a > way to rewrite that while with list comprehension? Probably not in a way that's more efficient than what you're already doing. One thing you should do is to use the // operator instead of /. Apart from being more portable (/ no longer does integer division in Python 3), it's also significantly faster: $ python -m timeit "12 / 5" 10000000 loops, best of 3: 0.0711 usec per loop $ python -m timeit "12 // 5" 10000000 loops, best of 3: 0.028 usec per loop Also, don't use a list comprehension for your looping construct in factorialCountZeros2(). The list comprehension has to build up a list containing all the None objects returned by the Z() method, which wastes time and space. Because of that, it would be faster just to write it out the for loop. Besides the speed improvement, it's also bad style to use a list comprehension for a loop where you're only interested in the side effects. Another thing to consider is that function calls are expensive. Your Z() function gets called once for every line of input, which could add up. While it will make the code a bit less readable (CodeChef is definitely not the place to go if you want to learn to write *clear* code), you might see some improvement if you wrap that function into the factorialCountZeros2() function. Finally, one thing that really tends to help a lot in these puzzles is to do all your input at once and all your output at once. I/O is crazy expensive, but you can cut a lot of that out by minimizing the number of reads and writes that you have to do. After the first readline, you can do something like "input = sys.stdin.read().strip().split('\n')" to pull everything into a single list, then iterate over the list instead of stdin. For output, append all your results to a list instead of printing them immediately, then use '\n'.join() to generate something suitable for printing. Cheers, Ian P.S. CodeChef and SPOJ both have the psyco module available. If you just can't seem to get a problem solved in the time limit, you can always turn it on for a major speed boost. It's more fun to try to solve the problems without it, though. From prologic at shortcircuit.net.au Wed Nov 10 22:46:16 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 11 Nov 2010 13:46:16 +1000 Subject: Questions: While And List Comprehension In-Reply-To: <4CDB4929.4010006@mrabarnett.plus.com> References: <4CDB4929.4010006@mrabarnett.plus.com> Message-ID: On Thu, Nov 11, 2010 at 11:38 AM, MRAB wrote: > 'list' will exhaust the input, then the slicing will return at most 5 > lines. Hmm you're right :) -- -- James Mills -- -- "Problems are solved by method" From prologic at shortcircuit.net.au Wed Nov 10 22:48:07 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 11 Nov 2010 13:48:07 +1000 Subject: Questions: While And List Comprehension In-Reply-To: References: Message-ID: On Thu, Nov 11, 2010 at 1:02 PM, Steve Holden wrote: > This suggests that you are mistaken about not exhausting the source. Yeah I was mistaken. Oh well :) I was thinking of a generator-based solution and got lost in the implementation! -- -- James Mills -- -- "Problems are solved by method" From prologic at shortcircuit.net.au Wed Nov 10 22:53:21 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 11 Nov 2010 13:53:21 +1000 Subject: Questions: While And List Comprehension In-Reply-To: References: Message-ID: On Thu, Nov 11, 2010 at 11:01 AM, alex23 wrote: > +1 on this approach. Clear and obvious and not reliant on any library > modules other than sys. > > itertools, what WAS I thinking? :) maybe: import sys from itertools import islice print [v for v in islice((line for line in sys.stdin), 0, 5)] ? -- -- James Mills -- -- "Problems are solved by method" From " " at libero.it Wed Nov 10 23:14:05 2010 From: " " at libero.it (not1xor1 (Alessandro)) Date: Thu, 11 Nov 2010 04:14:05 GMT Subject: subclassing str In-Reply-To: References: <5dLBo.1024$w8.406@twister2.libero.it> Message-ID: Il 09/11/2010 03:18, Lawrence D'Oliveiro ha scritto: > How exactly does > > a.f(b, c) > > save time over > > f(a, b, c) unfortunately in real world you have: objId = objId.method(args) vs. objId = moduleName.method(objId, args) I know you can use "from moduleName import *", but IMHO that produces code much harder to manage and extend -- bye !(!1|1) From jon.dufresne at gmail.com Wed Nov 10 23:18:16 2010 From: jon.dufresne at gmail.com (Jon Dufresne) Date: Wed, 10 Nov 2010 20:18:16 -0800 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: On Wed, Nov 10, 2010 at 1:50 AM, Lawrence D'Oliveiro wrote: > In message , Jon > Dufresne wrote: > >> On Mon, Nov 8, 2010 at 11:35 PM, Lawrence D'Oliveiro ... > > I see that you published my unobfuscated e-mail address on USENET for all to > see. I obfuscated it for a reason, to keep the spammers away. I'm assuming > this was a momentary lapse of judgement, for which I expect an apology. > Otherwise, it becomes grounds for an abuse complaint to your ISP. > Is this for real? I did a "replay all" to respond to your post. What are you suggesting? I don't see anything that looks like an obfuscated email. Jon From aioe.org at technicalbloke.com Wed Nov 10 23:22:38 2010 From: aioe.org at technicalbloke.com (r0g) Date: Thu, 11 Nov 2010 04:22:38 +0000 Subject: Class extension confusion :( References: Message-ID: On 10/11/10 09:52, Peter Otten wrote: > r0g wrote: > >> I have a subclass of BaseHHTPRequestHandler which uses a dictonary >> "paths" and a function "api_call" which are defined in the main >> namespace of the module. I'd rather I was able to pass these object to >> the constructor and store them as data attributes "self.paths" and >> "self.api_call" but I'm not sure how to do that properly. My >> understanding is that one may extend a constructor by defining it's >> __init__ method, calling the parents constructor and then adding ones >> own attributes to taste. What I don't understand is where or how I am >> supposed to get these extra constructor arguments into the class given >> that I don't instantiate it myself, it is seemingly instantiated by >> HTTPServer class that I pass it to e.g. >> >> httpd = HTTPServer(server_address, PlainAJAXRequestHandler) >> >> I wondered if I ought to instantiate an instance of >> PlainAJAXRequestHandler, set the attributes (either manually or by >> extending it's constructor) and pass that to HTTPServer but I figured it >> expects a class not an instance as it probably wants to spawn one >> instance for each request so that would be a non starter. Might I need >> to subclass HTTPServer, find the bit that instantiates the request >> handler and override that so it passes it's constructor more parameters? >> Right now I'm pretty confused, can somebody please tell me how I might >> accomplish this, what I'm failing to grasp or point me to the docs that >> explain it - I've spent the last hour or two plowing through docs to no >> avail, I guess it's a case of keyword ignorance on my part! Code >> follows... > > Try passing a factory function instead of a class. Untested: > > from functools import partial > > class PlainAJAXRequestHandler(BaseHTTPRequestHandler): > def __init__(self, api_call, paths, *args, **kw): > BaseHTTPRequestHandler.__init__(self, *args, **kw) > self.api_call = api_call > self.paths = paths > > paths = ... > api_call = ... > > httpd = HTTPServer( > server_address, > partial(PlainAJAXRequestHandler, paths, api_call)) > Great, that looks ideal Peter, thanks very much :) One more question quick question if you have time... I actually subclass the class in question later on to provide an SSL secured connection, is it possible (or even advisable) to do the following to spare me having to modify the derived classes init (and any subsequent classes' inits) too?... PlainAJAXRequestHandler = partial(PlainAJAXRequestHandler, paths, api_call)) ^??? Remap name to new extended class class SecureAJAXRequestHandler(PlainAJAXRequestHandler): def setup(self): self.connection = self.request self.rfile = socket._fileobject(self.request, "rb", self.rbufsize) self.wfile = socket._fileobject(self.request, "wb", self.wbufsize) ^??? therefore no init needed? Cheers, Roger From clp2 at rebertia.com Wed Nov 10 23:29:59 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 10 Nov 2010 20:29:59 -0800 Subject: subclassing str In-Reply-To: References: <5dLBo.1024$w8.406@twister2.libero.it> Message-ID: On Wed, Nov 10, 2010 at 8:14 PM, not1xor1 (Alessandro) <" "@libero.it> wrote: > Il 09/11/2010 03:18, Lawrence D'Oliveiro ha scritto: > >> How exactly does >> >> ? ?a.f(b, c) >> >> save time over >> >> ? ? f(a, b, c) > > unfortunately in real world you have: > > objId = objId.method(args) > > vs. > > objId = moduleName.method(objId, args) > > I know you can use "from moduleName import *", but IMHO that produces code > much harder to manage and extend So just don't use the form with the asterisk. Explicitly list the members you wish to import from the module (`from moduleName import meth1, meth2`). That way, you don't have to specify the module name on every invocation, but the origin of the functions is still made explicit. Cheers, Chris -- http://blog.rebertia.com From robert.kern at gmail.com Wed Nov 10 23:31:25 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 10 Nov 2010 22:31:25 -0600 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: On 2010-11-10 22:18 , Jon Dufresne wrote: > On Wed, Nov 10, 2010 at 1:50 AM, Lawrence D'Oliveiro > wrote: >> In message, Jon >> Dufresne wrote: >> >>> On Mon, Nov 8, 2010 at 11:35 PM, Lawrence D'Oliveiro ... >> >> I see that you published my unobfuscated e-mail address on USENET for all to >> see. I obfuscated it for a reason, to keep the spammers away. I'm assuming >> this was a momentary lapse of judgement, for which I expect an apology. >> Otherwise, it becomes grounds for an abuse complaint to your ISP. >> > > Is this for real? I did a "replay all" to respond to your post. What > are you suggesting? I don't see anything that looks like an obfuscated > email. To be fair, I think Lawrence is *trying* to obfuscate his email address. You can see it in the python-list archives. http://mail.python.org/pipermail/python-list/2010-November/1260153.html However, somewhere between him and you (and me!), it gets unobfuscated. You did nothing wrong, even if you accept Lawrence's premise that deliberately unobfuscating someone's email address is apology-worthy. Personally, I don't. -- 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 steve at holdenweb.com Wed Nov 10 23:49:56 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 10 Nov 2010 23:49:56 -0500 Subject: DTD Parsing In-Reply-To: References: <4e7a49ec-1816-46e5-bc51-9f7c88f4d025@37g2000prx.googlegroups.com> <06071410-4684-4169-b1f8-0783e34f9062@f16g2000prj.googlegroups.com> Message-ID: On 11/10/2010 10:07 PM, Lawrence D'Oliveiro wrote: > In message , Ian Kelly > wrote: > >> > On 11/9/2010 11:14 PM, r0g wrote: >>> >> >>> >> config = {} >>> >> for line in (open("config.txt", 'r')): >>> >> if len(line) > 0 and line[0] <> "#": >>> >> param, value = line.rstrip().split("=",1) >>> >> config[param] = value >> > >> > That's five whole lines of code. Why go to all that trouble when you >> > can just do this: >> > >> > import config > Not a good idea. [...] Sure, you wouldn't want users editing imported Python files, it would be leaving your program hostage to all the things an ignorant or malevolent user might do. But practical for, for example, experimental work. I seem to remember that the major server project in "Python Web Programming" has all configurable modules importing a common Config module, though in my own defense that *was* almost ten years ago now. (That wasn't intended to be a production server though it ran sporadically on a computer in my basement for several years and produced a traceback occasionally). regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From aioe.org at technicalbloke.com Thu Nov 11 00:02:45 2010 From: aioe.org at technicalbloke.com (r0g) Date: Thu, 11 Nov 2010 05:02:45 +0000 Subject: How to test if a module exists? References: <87d3qdibzg.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On 10/11/10 12:45, Mark Wooding wrote: > r0g writes: > >> You use your main address on USENET rather than a junk one!? Obfuscated or >> not that's either brave or foolhardy! > > I use my real email address. I also have an aggressive spam filter. > But I don't think that much of my comes from Usenet harvesters any more, > to be honest. > > -- [mdw] Really? I get a metric butt-ton of spam every day to this address. Right now it simply filtered by address straight into my recycle bin, I suppose if it ever becomes burdensome or starts to choke my bandwidth I'll tell my mailserver to bounce it :) Roger From rantingrick at gmail.com Thu Nov 11 00:05:41 2010 From: rantingrick at gmail.com (rantingrick) Date: Wed, 10 Nov 2010 21:05:41 -0800 (PST) Subject: Questions: While And List Comprehension References: Message-ID: <54412a44-2321-4e62-96b8-fa08882f8845@k3g2000vbp.googlegroups.com> On Nov 10, 4:56?pm, Emile van Sebille wrote: > On 11/10/2010 4:36 AM Felipe Vinturini said... > > > Hi Folks, > > > I am quite new to python and I don't have a lot of experience with it yet. > > > I have two simple questions: > > > 1. Is there a way to limit the number of times a list comprehension will > > execute? E.g. I want to read from input only 5 values, so I would like > > something like (the values between # # are what I want): Hey all you guys could be mistaken. It looks like the OP is trying to implement some sort of ghetto database. And he may NOT necessarily want the FIRST five lines of the file. He said (and i quote) "the values /between/ # and #". Where # and # are starting and ending of a range -- not necessarily the starting of the input file! However we really need the OP to clear up these questions! From prologic at shortcircuit.net.au Thu Nov 11 00:18:43 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 11 Nov 2010 15:18:43 +1000 Subject: Questions: While And List Comprehension In-Reply-To: <54412a44-2321-4e62-96b8-fa08882f8845@k3g2000vbp.googlegroups.com> References: <54412a44-2321-4e62-96b8-fa08882f8845@k3g2000vbp.googlegroups.com> Message-ID: On Thu, Nov 11, 2010 at 3:05 PM, rantingrick wrote: > Hey all you guys could be mistaken. It looks like the OP is trying to > implement some sort of ghetto database. And he may NOT necessarily > want the FIRST five lines of the file. He said (and i quote) "the > values /between/ # and #". Where # and # are starting and ending of a > range -- not necessarily the starting of the input file! However we > really need the OP to clear up these questions! Valid point Rick. And yes my earlier post was very wrong :/ My follow-up (after realizing my mistake) might be better (using islice). cheers James -- -- James Mills -- -- "Problems are solved by method" From aioe.org at technicalbloke.com Thu Nov 11 00:20:23 2010 From: aioe.org at technicalbloke.com (r0g) Date: Thu, 11 Nov 2010 05:20:23 +0000 Subject: Curses Programming References: Message-ID: On 10/11/10 14:42, alexander wrote: > Hi, all > > Here is the test. Plz help..... > > / > ***************************************************************************************************************************************************/ > If you use the new image search of Google, you will find that the > result images are layouted in a way that each row has the same height, > but contains different number of images dependents the width-height > ratio of each image. The goal is to make each row of images having > approximately same total width. Just try search any image > inimages.google.com, you will get the idea. > If you're the programmer designing this page, what algorithm would you > use to select images for each row? > Input: > The input of the program is a plain text file, each line in the file > containg 2 numbers, describing the width and height of an image > e.g. > 800 600 > 640 400 > 720 1280 > ... > Goal: > Design an algorithm to put those images into a number of rows, each > row is 150 pixel height and 1200 pixel wide. You could scale images > proportionally to the same height. You need make sure the images are > aligned as closely as possbile to the row boundary. > Output: > The indexes of the images you would put on each row followed by blank > line. > e.g. > 0 > 1 > 2 > According to the input file example, this output means image-0 (800 x > 600) and image-1 (640 x 400) is put on the first row and image-2 (720 > x 1280) is put on the second row. > Constraint: > Assuming, the input file contains less than 100 lines. Your algorithm > should finish within 5 secs on a standard laptop. > > / > **********************************************************************************************************************************************/ > > Could any give a hand? > Thanks a lot > Alex Alex, At least try thinking about how you would solve the problem - that is after all the whole point of the exercise i.e. to think up an algorithm, not to code it in python. That part is your homework and nobody here will do it for you. Also, if you don't enjoy solving this kind of problem it's possible you are studying the wrong subject. If you can think of a basic strategy to solve the above problem and can explain it in fairly plain english then I'm sure some people here will be happy to a) improve it and b) Help you if you are struggling to translate your concept into working python code. Even then, it being a homework assignment you can't expect people to just give it to you on a plate. Expect homework assistance to be at least slightly oblique, it's for your own good. If you don't have to do any thinking yourself then you're not going to learn much either and next week you'll be right back where you were, pestering some other poor forum. Good luck with it! Roger. From timr at probo.com Thu Nov 11 00:23:54 2010 From: timr at probo.com (Tim Roberts) Date: Wed, 10 Nov 2010 21:23:54 -0800 Subject: udp sockets with python References: Message-ID: Mag Gam wrote: > >I am measuring the round trip time using tcpdump. The C version is >giving me around 80 microseconds (average) and the python is giving me >close to 300 microseconds (average). If you need the performance of a compiled language, then it's probably not appropriate to use an interpreter. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From aioe.org at technicalbloke.com Thu Nov 11 00:54:10 2010 From: aioe.org at technicalbloke.com (r0g) Date: Thu, 11 Nov 2010 05:54:10 +0000 Subject: DTD Parsing References: <4e7a49ec-1816-46e5-bc51-9f7c88f4d025@37g2000prx.googlegroups.com> <06071410-4684-4169-b1f8-0783e34f9062@f16g2000prj.googlegroups.com> Message-ID: On 10/11/10 20:38, Ian wrote: > On Nov 10, 1:05 am, r0g wrote: >>> That's five whole lines of code. Why go to all that trouble when you can >>> just do this: >> >>> import config >> >> Heh, mainly because I figure the config module will have a lot more >> options than I have use for right now and therefore the docs will take >> me longer to read than I will save by not just typing in the above ;) > > I think you misunderstand me. There is no config module and there are > no docs to read. It's just the configuration file itself written as a > Python script, containing arbitrary settings like: So you're not talking about this then?... http://www.red-dove.com/config-doc/ I see. You're suggesting writing config files IN the language you're already writing in? Indeed that's what I do in many situations, it has the advantage of working in any scripting language (I do the same in PHP fairly often, as do several big projects like Drupal) and of course it spares you a bit of code. However, if your config file it's meant to be distributed / editable by end users you don't necessarily want them to need a full understanding of python syntax to do it. Also, actually parsing config files (rather than just importing namespaces) gives you an opportunity to deal with any syntax errors on a case by case basis i.e. skip, fail, issue warning etc. Just importing code gives you a kind of 100% consistency or death situation and while that might be exactly what you want many times there may be situations where you want a bit more fine grained control! Roger From aioe.org at technicalbloke.com Thu Nov 11 01:04:54 2010 From: aioe.org at technicalbloke.com (r0g) Date: Thu, 11 Nov 2010 06:04:54 +0000 Subject: Questions: While And List Comprehension References: Message-ID: On 10/11/10 22:56, Emile van Sebille wrote: > On 11/10/2010 4:36 AM Felipe Vinturini said... >> Hi Folks, >> >> I am quite new to python and I don't have a lot of experience with it >> yet. >> >> I have two simple questions: >> >> 1. Is there a way to limit the number of times a list comprehension will >> execute? E.g. I want to read from input only 5 values, so I would like >> something like (the values between # # are what I want): >> =================================================================================== >> >> COUNT = 0 >> print [ v for v in sys.stdin.readlines() *# *IF COUNT< 5* #* ] ## >> Increment >> COUNT somewhere > > Easiest would be print [ v for v in sys.stdin.readlines()[:5] ] but that > still reads the entire sys.stdin (whatever it may be...) > Use readline() + a counter instead... print [sys.stdin.readline() for x in xrange(0,5)] Roger From aioe.org at technicalbloke.com Thu Nov 11 01:08:24 2010 From: aioe.org at technicalbloke.com (r0g) Date: Thu, 11 Nov 2010 06:08:24 +0000 Subject: DTD Parsing References: <4e7a49ec-1816-46e5-bc51-9f7c88f4d025@37g2000prx.googlegroups.com> <06071410-4684-4169-b1f8-0783e34f9062@f16g2000prj.googlegroups.com> Message-ID: On 10/11/10 23:18, Christian Heimes wrote: > Am 10.11.2010 04:36, schrieb Asun Friere: >> Yes but configuration files are not necessarily meant to be edited by >> humans either! > > Yeah, you are right. I'm sorry but every time I read XML and > configuration in one sentence, I see the horror of TomCat or Shibboleth > XML configs popping up. > There are XML editors these days you know? I hear some of them even do schema checking :) Roger From aioe.org at technicalbloke.com Thu Nov 11 01:11:17 2010 From: aioe.org at technicalbloke.com (r0g) Date: Thu, 11 Nov 2010 06:11:17 +0000 Subject: Looping through files in a directory References: Message-ID: On 11/11/10 00:17, Steve Holden wrote: > On 11/10/2010 5:46 PM, Matty Sarro wrote: >> Short story - I have a few thousand files in a directory I need to parse >> through. Is there a simple way to loop through files? I'd like to avoid >> writing a python script that can parse 1 file, and have to call it a few >> thousand times from a bash script. Any input or pointers to functions >> that'd help would be very much appreciated. Thanks! >> > from glob import glob > for filename in glob("*"): > # do something with filename > > regards > Steve Ooo, that's nice, would that work on non *nix platforms too? Roger From clp2 at rebertia.com Thu Nov 11 01:23:05 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 10 Nov 2010 22:23:05 -0800 Subject: Looping through files in a directory In-Reply-To: References: Message-ID: On Wed, Nov 10, 2010 at 10:11 PM, r0g wrote: > On 11/11/10 00:17, Steve Holden wrote: >> On 11/10/2010 5:46 PM, Matty Sarro wrote: >>> >>> Short story - I have a few thousand files in a directory I need to parse >>> through. Is there a simple way to loop through files? I'd like to avoid >>> writing a python script that can parse 1 file, and have to call it a few >>> thousand times from a bash script. Any input or pointers to functions >>> that'd help would be very much appreciated. Thanks! >>> >> from glob import glob >> for filename in glob("*"): >> ? # do something with filename >> >> regards >> ?Steve > > Ooo, that's nice, would that work on non *nix platforms too? Well, yeah; note the lack of any "Availability:" restriction note in the module's docs. http://docs.python.org/library/glob.html Cheers, Chris From aioe.org at technicalbloke.com Thu Nov 11 01:25:31 2010 From: aioe.org at technicalbloke.com (r0g) Date: Thu, 11 Nov 2010 06:25:31 +0000 Subject: Looping through files in a directory References: Message-ID: On 11/11/10 06:23, Chris Rebert wrote: > On Wed, Nov 10, 2010 at 10:11 PM, r0g wrote: >> On 11/11/10 00:17, Steve Holden wrote: >>> On 11/10/2010 5:46 PM, Matty Sarro wrote: >>>> >>>> Short story - I have a few thousand files in a directory I need to parse >>>> through. Is there a simple way to loop through files? I'd like to avoid >>>> writing a python script that can parse 1 file, and have to call it a few >>>> thousand times from a bash script. Any input or pointers to functions >>>> that'd help would be very much appreciated. Thanks! >>>> >>> from glob import glob >>> for filename in glob("*"): >>> # do something with filename >>> >>> regards >>> Steve >> >> Ooo, that's nice, would that work on non *nix platforms too? > > Well, yeah; note the lack of any "Availability:" restriction note in > the module's docs. > http://docs.python.org/library/glob.html > > Cheers, > Chris Ahh, I see (or rather I don't). I'm afraid I have a habit of missing things that aren't there, my bad. Roger From hniksic at xemacs.org Thu Nov 11 02:24:54 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Thu, 11 Nov 2010 08:24:54 +0100 Subject: Is Eval *always* Evil? References: <87wrok4zjm.fsf@xemacs.org> Message-ID: <87sjz84915.fsf@xemacs.org> Robert Kern writes: > On 2010-11-10 15:52 , Hrvoje Niksic wrote: >> Simon Mullis writes: >> >>> If "eval" is not the way forward, are there any suggestions for >>> another way to do this? >> >> ast.literal_eval might be the thing for you. > > No, that doesn't work since he needs to call methods. You're right; I misread the post. From __peter__ at web.de Thu Nov 11 03:01:00 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 11 Nov 2010 09:01 +0100 Subject: Class extension confusion :( References: Message-ID: r0g wrote: > On 10/11/10 09:52, Peter Otten wrote: >> r0g wrote: >> >>> I have a subclass of BaseHHTPRequestHandler which uses a dictonary >>> "paths" and a function "api_call" which are defined in the main >>> namespace of the module. I'd rather I was able to pass these object to >>> the constructor and store them as data attributes "self.paths" and >>> "self.api_call" but I'm not sure how to do that properly. My >>> understanding is that one may extend a constructor by defining it's >>> __init__ method, calling the parents constructor and then adding ones >>> own attributes to taste. What I don't understand is where or how I am >>> supposed to get these extra constructor arguments into the class given >>> that I don't instantiate it myself, it is seemingly instantiated by >>> HTTPServer class that I pass it to e.g. >>> >>> httpd = HTTPServer(server_address, PlainAJAXRequestHandler) >>> >>> I wondered if I ought to instantiate an instance of >>> PlainAJAXRequestHandler, set the attributes (either manually or by >>> extending it's constructor) and pass that to HTTPServer but I figured it >>> expects a class not an instance as it probably wants to spawn one >>> instance for each request so that would be a non starter. Might I need >>> to subclass HTTPServer, find the bit that instantiates the request >>> handler and override that so it passes it's constructor more parameters? >>> Right now I'm pretty confused, can somebody please tell me how I might >>> accomplish this, what I'm failing to grasp or point me to the docs that >>> explain it - I've spent the last hour or two plowing through docs to no >>> avail, I guess it's a case of keyword ignorance on my part! Code >>> follows... >> >> Try passing a factory function instead of a class. Untested: >> >> from functools import partial >> >> class PlainAJAXRequestHandler(BaseHTTPRequestHandler): >> def __init__(self, api_call, paths, *args, **kw): >> BaseHTTPRequestHandler.__init__(self, *args, **kw) >> self.api_call = api_call >> self.paths = paths >> >> paths = ... >> api_call = ... >> >> httpd = HTTPServer( >> server_address, >> partial(PlainAJAXRequestHandler, paths, api_call)) >> > > > Great, that looks ideal Peter, thanks very much :) > > One more question quick question if you have time... I actually subclass > the class in question later on to provide an SSL secured connection, is > it possible (or even advisable) to do the following to spare me having > to modify the derived classes init (and any subsequent classes' inits) > too?... > > PlainAJAXRequestHandler = partial(PlainAJAXRequestHandler, paths, > api_call)) > > ^??? Remap name to new extended class > > class SecureAJAXRequestHandler(PlainAJAXRequestHandler): That's not possible; you are trying to subclass a function. What you can do (again untested): def make_handler_class(paths, api_call): class MyHandler(BaseHTTPRequestHandler): paths = paths api_call = staticmethod(api_call) return MyHandler PlainAJAXRequestHandler = make_handler_class(paths, api_call) class SecureAJAXRequestHandler(PlainAJAXRequestHandler): ... Peter From nagle at animats.com Thu Nov 11 03:07:53 2010 From: nagle at animats.com (John Nagle) Date: Thu, 11 Nov 2010 00:07:53 -0800 Subject: Is Eval *always* Evil? In-Reply-To: References: Message-ID: <4cdba45a$0$1599$742ec2ed@news.sonic.net> On 11/10/2010 6:39 PM, Robert Kern wrote: > On 2010-11-10 17:14 , Christian Heimes wrote: >> Am 10.11.2010 18:56, schrieb Simon Mullis: >> >> Yes, eval is evil, may lead to security issues and it's unnecessary >> slow, too. If you have to use "eval", use the 2 or 3 argument form with a "globals" and "locals" dictionary. This lists the variables and functions that "eval" can see and touch. The Python documentation for this is not very good: "If the globals dictionary is present and lacks ?__builtins__?, the current globals are copied into globals before expression is parsed. This means that expression normally has full access to the standard __builtin__ module and restricted environments are propagated." What this means is that you have to put in "__builtins__" to PREVENT all built-ins from being imported. See http://lybniz2.sourceforge.net/safeeval.html for something readable on how to use "eval" safely. John Nagle From __peter__ at web.de Thu Nov 11 03:10:21 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 11 Nov 2010 09:10:21 +0100 Subject: Questions: While And List Comprehension References: Message-ID: James Mills wrote: > On Thu, Nov 11, 2010 at 11:01 AM, alex23 wrote: >> +1 on this approach. Clear and obvious and not reliant on any library >> modules other than sys. >> >> itertools, what WAS I thinking? :) > > maybe: > > import sys > from itertools import islice > > print [v for v in islice((line for line in sys.stdin), 0, 5)] (line for line in sys.stdin) and sys.stdin are equivalent as are [v for v in items] and list(items) So print list(islice(sys.stdin, 5)) Peter From paul.nospam at rudin.co.uk Thu Nov 11 03:11:42 2010 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Thu, 11 Nov 2010 08:11:42 +0000 Subject: Is Eval *always* Evil? References: Message-ID: <87mxpgwa81.fsf@rudin.co.uk> Robert Kern writes: > On 2010-11-10 17:14 , Christian Heimes wrote: >> Am 10.11.2010 18:56, schrieb Simon Mullis: >> >> Yes, eval is evil, may lead to security issues and it's unnecessary >> slow, too. Still - it is used in the standard library... From xrgtn at umc.com.ua Thu Nov 11 03:36:02 2010 From: xrgtn at umc.com.ua (Alexander Gattin) Date: Thu, 11 Nov 2010 10:36:02 +0200 Subject: How convert list to nested dictionary? In-Reply-To: <44817c9a-647b-4bed-9162-faf0fb5313bc@f20g2000yqi.googlegroups.com> References: <940876cd-2546-4673-aef4-ba11b4156287@fv1g2000vbb.googlegroups.com> <44817c9a-647b-4bed-9162-faf0fb5313bc@f20g2000yqi.googlegroups.com> Message-ID: <20101111083602.GA3982@xrgtn-q40> Hello, On Thu, Nov 04, 2010 at 02:10:12PM -0700, macm wrote: > > > How convert list to nested dictionary? > > > > >>>> l > > > ['k1', 'k2', 'k3', 'k4', 'k5'] > > >>>> result > > > {'k1': {'k2': {'k3': {'k4': {'k5': {}}}}}} > > http://www.amk.ca/python/writing/functional so, why didn't you try python's reduce? IMO this is trivial: > >>> l > ['k1', 'k2', 'k3', 'k4', 'k5'] > >>> reduce(lambda x,y: {y:x}, l.__reversed__()) > {'k1': {'k2': {'k3': {'k4': 'k5'}}}} > >>> reduce(lambda x,y: {y:x}, l.__reversed__(), dict()) > {'k1': {'k2': {'k3': {'k4': {'k5': {}}}}}} > >>> second reduce uses empty dict for seed. -- With best regards, xrgtn From aioe.org at technicalbloke.com Thu Nov 11 03:56:58 2010 From: aioe.org at technicalbloke.com (r0g) Date: Thu, 11 Nov 2010 08:56:58 +0000 Subject: Class extension confusion :( References: Message-ID: On 10/11/10 09:52, Peter Otten wrote: > class PlainAJAXRequestHandler(BaseHTTPRequestHandler): > def __init__(self, api_call, paths, *args, **kw): > BaseHTTPRequestHandler.__init__(self, *args, **kw) > self.api_call = api_call > self.paths = paths Hmm, the plot thickens! I always thought you had to call the parent constructor first (as above) when extending a constructor (not that I've had occasion to do that in a long time), but it turns out when I do this the lines below it never get executed and when I move them above that line they seem to work fine so it appears I was wrong about that. I've tried typing many variants of "python class extend constructor" into google over the last few days but I'm damned if I can find the docs explaining this. I'm sure I found them several years back when I first too up python, maybe by google-fu is on the wane! Anyway, that's not my main question, this is... The extra names that I pass to functools.partial seem to be bound permanently into the namespace of my class now i.e. I can reference them as 'api_call' and 'paths' anywhere in the classes' methods as opposed to having to assign them in the constructor and reference them as 'self.api_call' and 'self.paths'. I'm not 100% how that's working but in practical terms it suggests to two lines assigning those names to data attributes are redundant as I can access them anywhere anyway. Indeed, I've commented them out and my app still seems to work fine so... Question A) Are there any good reasons why I shouldn't just do that? (other than B!) Question B) The only reason I can think of so far is that I don't have a clear picture of how those names came to end up in that scope, it seems very convenient but I'm worried it's black magic of some sort! Could anyone explain or point me to the right docs please? Please shout if you would like to see the source. Thanks muchly :) Roger. From simon at mullis.co.uk Thu Nov 11 04:16:30 2010 From: simon at mullis.co.uk (Simon Mullis) Date: Thu, 11 Nov 2010 10:16:30 +0100 Subject: Is Eval *always* Evil? In-Reply-To: <4cdba45a$0$1599$742ec2ed@news.sonic.net> References: <4cdba45a$0$1599$742ec2ed@news.sonic.net> Message-ID: On 11 November 2010 09:07, John Nagle wrote: >>> Am 10.11.2010 18:56, schrieb Simon Mullis: >>> Yes, eval is evil, may lead to security issues and it's unnecessary >>> slow, too. > > ? If you have to use "eval", use the 2 or 3 argument form with a > "globals" and "locals" dictionary. ?This lists the variables > and functions that "eval" can see and touch. > > ? The Python documentation for this is not very good: > "If the globals dictionary is present and lacks ?__builtins__?, the current > globals are copied into globals before expression is parsed. This means that > expression ?normally has full access to the standard __builtin__ ?module and > restricted environments are propagated." > > ? What this means is that you have to put in "__builtins__" to > PREVENT all built-ins from being imported. Aren't I already doing this? >>> result = eval(xpath_command, {"__builtins__":[]},{"x": x}) SM From __peter__ at web.de Thu Nov 11 04:34:22 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 11 Nov 2010 10:34:22 +0100 Subject: Class extension confusion :( References: Message-ID: r0g wrote: > On 10/11/10 09:52, Peter Otten wrote: >> class PlainAJAXRequestHandler(BaseHTTPRequestHandler): >> def __init__(self, api_call, paths, *args, **kw): >> BaseHTTPRequestHandler.__init__(self, *args, **kw) >> self.api_call = api_call >> self.paths = paths > > > Hmm, the plot thickens! I always thought you had to call the parent > constructor first (as above) when extending a constructor (not that I've > had occasion to do that in a long time), but it turns out when I do this > the lines below it never get executed and when I move them above that > line they seem to work fine so it appears I was wrong about that. I've I didn't believe you until I had a look into the source. The meat is in SocketServer.py: class BaseRequestHandler: [snip] def __init__(self, request, client_address, server): self.request = request self.client_address = client_address self.server = server try: self.setup() self.handle() self.finish() finally: sys.exc_traceback = None # Help garbage collection def setup(self): pass def handle(self): pass def finish(self): pass As you can see this doesn't use __init__() just to set up the instance, it makes it the only method that is called by client code. That's an unusual design decision, to say the least. > tried typing many variants of "python class extend constructor" into > google over the last few days but I'm damned if I can find the docs > explaining this. I'm sure I found them several years back when I first > too up python, maybe by google-fu is on the wane! > > Anyway, that's not my main question, this is... The extra names that I > pass to functools.partial seem to be bound permanently into the > namespace of my class now i.e. I can reference them as 'api_call' and > 'paths' anywhere in the classes' methods as opposed to having to assign > them in the constructor and reference them as 'self.api_call' and > 'self.paths'. I'm not 100% how that's working but in practical terms it > suggests to two lines assigning those names to data attributes are > redundant as I can access them anywhere anyway. Indeed, I've commented > them out and my app still seems to work fine so... > > Question A) Are there any good reasons why I shouldn't just do that? > (other than B!) No. Use either class B(A): path = ... or class B(A): def __init__(self, path, *args, **kw): self.path = path A.__init__(self, *args, **kw) not both. > Question B) The only reason I can think of so far is that I don't have a > clear picture of how those names came to end up in that scope, it seems > very convenient but I'm worried it's black magic of some sort! Could > anyone explain or point me to the right docs please? Python looks for attributes in the instance first, and then in the class as a fallback. You only need to put them in the instance if you expect that you want a different value for every instance. Peter From felipe.vinturini at gmail.com Thu Nov 11 04:37:12 2010 From: felipe.vinturini at gmail.com (Felipe Vinturini) Date: Thu, 11 Nov 2010 07:37:12 -0200 Subject: Questions: While And List Comprehension In-Reply-To: References: Message-ID: On Thu, Nov 11, 2010 at 6:10 AM, Peter Otten <__peter__ at web.de> wrote: > James Mills wrote: > > > On Thu, Nov 11, 2010 at 11:01 AM, alex23 wrote: > >> +1 on this approach. Clear and obvious and not reliant on any library > >> modules other than sys. > >> > >> itertools, what WAS I thinking? :) > > > > maybe: > > > > import sys > > from itertools import islice > > > > print [v for v in islice((line for line in sys.stdin), 0, 5)] > > (line for line in sys.stdin) > > and sys.stdin are equivalent as are > > [v for v in items] > > and list(items) > > So > > print list(islice(sys.stdin, 5)) > > Peter > -- > http://mail.python.org/mailman/listinfo/python-list > Hello Folks, You are great! Thanks for the suggestions! With the values between # #, I meant I would like to limit the values sys.stdin.readlines() read (but I think there is no way to do it); instead of reading the entire input, limit it to read only 5 entries. I knew about readline(), but when checking it with cProfile each readline() needs a function call and with readlines() it is only one. I think that depending on input, readline() calls may have a higher cost. Check below: My test file: TestFile.txt ===================================================== 1 2 3 4 5 6 7 8 9 10 ===================================================== My test code: simpleReadLines.py ===================================================== import sys import cProfile def simpleTestLimitRLS(tLimit): sysStdinReadLines = sys.stdin.readlines allValues = [ int(v) for v in sysStdinReadLines() ] print allValues[:tLimit] def simpleTestLimitRL(tLimit): sysStdinReadLine = sys.stdin.readline print [ sysStdinReadLine() for x in xrange(0,5) ] if __name__ == '__main__': cProfile.run("simpleTestLimitRL(5)") cProfile.run("simpleTestLimitRLS(5)") ===================================================== Test result: ===================================================== >type TestFile.txt | python simpleReadLines.py ['1\n', '2\n', '3\n', '4\n', '5\n'] 8 function calls in 0.004 CPU seconds Ordered by: standard name ncalls tottime percall cumtime percall filename:lineno(function) 1 0.000 0.000 0.004 0.004 :1() 1 0.004 0.004 0.004 0.004 simpleReadLines.py:13(simpleTestLimitRL) 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects} 5 0.000 0.000 0.000 0.000 {method 'readline' of 'file' objects} [6, 7, 8, 9, 10] 4 function calls in 0.003 CPU seconds Ordered by: standard name ncalls tottime percall cumtime percall filename:lineno(function) 1 0.000 0.000 0.003 0.003 :1() 1 0.003 0.003 0.003 0.003 simpleReadLines.py:8(simpleTestLimitRLS) 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects} 1 0.000 0.000 0.000 0.000 {method 'readlines' of 'file' objects} ===================================================== If I change the execution order to: 1. simpleTestLimitRLS(5) 2. simpleTestLimitRL(5) Of course, python returns an error because all the input has been consumed by readlines(). Again, thanks for your attention and suggestions. Regards, Felipe. -------------- next part -------------- An HTML attachment was scrubbed... URL: From prologic at shortcircuit.net.au Thu Nov 11 04:49:27 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 11 Nov 2010 19:49:27 +1000 Subject: Questions: While And List Comprehension In-Reply-To: References: Message-ID: On Thu, Nov 11, 2010 at 6:10 PM, Peter Otten <__peter__ at web.de> wrote: > (line for line in sys.stdin) > > and sys.stdin are equivalent as are > > [v for v in items] > > and list(items) > > So > > print list(islice(sys.stdin, 5)) I was being a little verbose ... But I like your simplification :) cheers James -- -- James Mills -- -- "Problems are solved by method" From lnenov at mm-sol.com Thu Nov 11 04:49:50 2010 From: lnenov at mm-sol.com (lnenov) Date: Thu, 11 Nov 2010 11:49:50 +0200 Subject: Enumeration of strings and export of the constants In-Reply-To: References: Message-ID: <4CDBBC3E.5070906@mm-sol.com> On 11/11/2010 01:30 AM, Ian wrote: > On Nov 10, 6:12 am, lnenov wrote: >> Is there a better and more common way to do this? > from itertools import count, izip > > class APINamespace(object): > > def __init__(self): > self._named_values = [] > > def enumerate(self, names, start=0, step=1): > self._named_values.extend(izip(names, count(start, step))) > > def import_to(self, destination): > for name, number in self._named_values: > setattr(destination, name, number) > > Note the "step" parameter of itertools.count requires Python 2.7 or > 3.1. > >> And can line 6 be replaced by something less evil. > Yes, by putting the names to be imported into their own container as > I've done above, instead of polluting the class dictionary with them. Thanks a lot. It was my initial idea to pull something like that but for some mysterious reason i failed miserably. Thanks again. ~Lyudmil > Cheers, > Ian From xrgtn at yandex.ru Thu Nov 11 04:51:33 2010 From: xrgtn at yandex.ru (Alexander Gattin) Date: Thu, 11 Nov 2010 11:51:33 +0200 Subject: Learning Pyhton - Functional Programming - How intersect/difference two dict with dict/values? fast! In-Reply-To: <4d71519e-a232-427f-b4e0-5bae90fc4acb@n32g2000prc.googlegroups.com> References: <4d71519e-a232-427f-b4e0-5bae90fc4acb@n32g2000prc.googlegroups.com> Message-ID: <20101111095133.GA5707@xrgtn-q40> Hello, On Tue, Nov 09, 2010 at 09:32:17AM -0800, macm wrote: > dict1 = {'ab':[[1,2,3,'d3','d4',5],12],'ac':[[1,3,'78a','79b'], > 54],'ad': [[56,57,58,59],34], 'ax': [[56,57,58,59],34]} > dict2 = {'ab':[[22,2,'a0','42s','c4','d3'],12],'ab':[[2,4,50,42,'c4'], > 12],'ac':[[1,3,'79b',45,65,'er4'],54],'ae': [[56,57,58,59],34],'ax': > [[9],34]} You have a problem here: key 'ab' is listed twice in dict2 and only its second value is then visible: [[2,4,50,42,'c4'], 12], so that I couldn't get the desired {'ac':[1,3,'79b'], 'ab':[2,'d3']} intersection. So, after I've found the problem, the desired functional-style code emerges: > >>> dict(filter(lambda t: t[1], > ... map(lambda k: (k, filter(lambda v: v in dict2[k][0], dict1[k][0])), > ... filter(dict2.has_key, dict1.iterkeys())) > ... ) > ... ) > {'ac': [1, 3, '79b'], 'ab': [2, 'd3']} > >>> -- With best regards, xrgtn From lnenov at mm-sol.com Thu Nov 11 04:52:52 2010 From: lnenov at mm-sol.com (lnenov) Date: Thu, 11 Nov 2010 11:52:52 +0200 Subject: Enumeration of strings and export of the constants In-Reply-To: References: <4CDA9A4E.1050106@mm-sol.com> Message-ID: <4CDBBCF4.4010006@mm-sol.com> On 11/10/2010 11:19 PM, Emile van Sebille wrote: > On 11/10/2010 5:12 AM lnenov said... >> Hi, >> >> I need to enumerate a couple hundred strings to constants and export >> them to another module(s) globals. > > Do they really need to be globals? Why not a constants in an > object/container that would neither pollute the global namespace nor > risk being shadowed by subsequent inadvertent name conflict? It is ment for testing purposes and would be used mainly in interactive mode. This would save some typing : ) ~Lyudmil From xrgtn at yandex.ru Thu Nov 11 05:04:12 2010 From: xrgtn at yandex.ru (Alexander Gattin) Date: Thu, 11 Nov 2010 12:04:12 +0200 Subject: Learning Pyhton - Functional Programming - How intersect/difference two dict with dict/values? fast! In-Reply-To: <20101111095133.GA5707@xrgtn-q40> References: <4d71519e-a232-427f-b4e0-5bae90fc4acb@n32g2000prc.googlegroups.com> <20101111095133.GA5707@xrgtn-q40> Message-ID: <20101111100412.GA8627@xrgtn-q40> On Thu, Nov 11, 2010 at 11:51:33AM +0200, Alexander Gattin wrote: > functional-style code emerges: > > > >>> dict(filter(lambda t: t[1], > > ... map(lambda k: (k, filter(lambda v: v in dict2[k][0], dict1[k][0])), > > ... filter(dict2.has_key, dict1.iterkeys())) > > ... ) > > ... ) Sorry, the indentation for the above code is plain wrong. I'm not accustomed to lisp-indenting, and only have managed to produce the next version below: > >>> dict(filter(lambda t: t[1], > ... map(lambda k: (k, filter(lambda v: v in dict2[k][0], > ... dict1[k][0] > ... ) > ... ), > ... filter(dict2.has_key, dict1.iterkeys()) > ... ) > ... ) > ... ) > {'ac': [1, 3, '79b'], 'ab': [2, 'd3']} > >>> -- With best regards, xrgtn From cbrown at cbrownsystems.com Thu Nov 11 05:37:52 2010 From: cbrown at cbrownsystems.com (cbrown at cbrownsystems.com) Date: Thu, 11 Nov 2010 02:37:52 -0800 (PST) Subject: multiple discontinued ranges References: Message-ID: <3627e745-e45e-4b2c-8899-ca09c1d5a84b@n32g2000pre.googlegroups.com> On Nov 10, 10:02 am, Mel wrote: > xoff wrote: > > I was wondering what the best method was in Python programming for 2 > > discontinued ranges. e.g. I want to use the range 3 to 7 and 17 to 23. > > Am I obliged to use 2 for loops defining the 2 ranges like this: > > > for i in range (3,7): > > do bla > > for i in range (7,17): > > do bla > > > or is there a more clever way to do this? > > One horribly clever way is to concoct a 9-th order polynomial to return > 3,4,5,6,17,18,19,20,21,22 for input values 0,1,2,3,4,5,6,7,8,9. > And one would want one with integer coefficients... truly horribly clever! A good example of complex is better than complicated... > The reasonable way is to use two loops as you've done. If the pattern of > discontinuous ranges is really important in your application, you'd perhaps > want to package it up (not tested): > > def important_range (): > for x in xrange (3, 7): > yield x > for x in xrange (17,23): > yield x > Reasonable; but DRY: don't repeat yourself. IMNSHO, better would be: ... def important_range (): ... for x in [xrange (3, 7), xrange (17,23)]: ... for y in x: ... yield y because face it, you're probably going to add to that list of ranges anyway, so you should anticipate it (and there's no cost if you don't end up adding to it). To extend that notion, I would imagine that itertools.chain is already basically defined as: ... def chain(*args): ... for x in args: ... for y in x: ... yield y so important_range() can then be simply defined as: ... def important_range: ... return chain(xrange (3, 7), xrange (17,23)) Cheers - Chas > to be used elsewhere as > > for v in important_range(): > # use v ... > > Mel. From mdw at distorted.org.uk Thu Nov 11 06:28:27 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 11 Nov 2010 11:28:27 +0000 Subject: How to test if a module exists? References: <87d3qdibzg.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <87vd44gkv8.fsf.mdw@metalzone.distorted.org.uk> r0g writes: > Really? I get a metric butt-ton of spam every day to this address. I'm sure I get sent a lot of spam (though I don't know for sure -- see below). But I don't think much of it comes from Usenet harvesters any more. > Right now it simply filtered by address straight into my recycle bin, > I suppose if it ever becomes burdensome or starts to choke my > bandwidth I'll tell my mailserver to bounce it :) Don't do that. Get your mailserver to /reject/ spam during SMTP with a 5xx code. Bouncing spam is really bad because it implicitly assumes that the envelope sender address is good. Spam rarely has a valid envelope sender. If you're lucky, the envelope sender is simply invalid, and you'll end up with a double-bounce when your mailserver finds out. If you're unlucky, the envelope sender is a /valid/ address from the spammer's list and some innocent victim will end up receiving your bounce (this is called `backscatter'). -- [mdw] From moura.mario at gmail.com Thu Nov 11 06:28:45 2010 From: moura.mario at gmail.com (macm) Date: Thu, 11 Nov 2010 03:28:45 -0800 (PST) Subject: Open Multiples Files at same time with multiprocessing - How "declare" dynamically the var? Message-ID: Hi Folks My approach to open multiples files at same time is: def openFiles(self,file,q): fp = open(file, 'rb') fp.seek(0) fcontent = fp.read() fp.close() q.put(fcontent) return def testOpen(self): L = ['file1.txt','file2.txt','file3.txt','file4.txt','file5.txt'] d1 = [] for x in L: z=L.index(x) q = Queue() m = Process(target=self.openFiles, args=(x,q,)) m.start() d1.append(q.get()) # <= This get is locking ? It is mean: "wait m.start(), like m.join()??" print list(d1) return Is the best way? Is q.get() locking the loop? I feel that q.get() is locking so I would like to "declare" dynamically the var q{z} in python? is it possible? How? def testOpen(self): L = ['file1.txt','file2.txt','file3.txt','file4.txt','file5.txt'] d1 = [] for x in L: z=L.index(x) q{z} = Queue() m{z} = Process(target=self.openFiles, args=(x,q{z},)) m{z}.start() for x in L: z=L.index(x) d1.append(q{z}.get()) # <= So now I am sure that q{z}.get() isn't lock print list(d1) return I tried use list but didn't work look below one shot. Best Regards macm I tried : def testOpen(self): L = ['file1.txt','file2.txt', 'file3.txt','file4.txt', 'file5.txt'] d1 = [] q = [] m = [] for x in L: z=L.index(x) q.insert(z, Queue()) m.insert(z,Process(target=self.openFiles, args=(x,q[z]))) m[z].start() # Now I am sure. Isnt lock for x in L: z=L.index(x) d1.append(q[z].get()) print list(d1) return From ndbecker2 at gmail.com Thu Nov 11 06:36:28 2010 From: ndbecker2 at gmail.com (Neal Becker) Date: Thu, 11 Nov 2010 06:36:28 -0500 Subject: strange problem with multiprocessing Message-ID: Any idea what this could be about? Traceback (most recent call last): File "run-tests-10111104.py", line 48, in results = pool.map (run_test, cases) File "/usr/lib64/python2.7/multiprocessing/pool.py", line 199, in map return self.map_async(func, iterable, chunksize).get() File "/usr/lib64/python2.7/multiprocessing/pool.py", line 491, in get raise self._value ValueError: cannot convert float NaN to integer From martin at address-in-sig.invalid Thu Nov 11 07:15:04 2010 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Thu, 11 Nov 2010 12:15:04 +0000 (UTC) Subject: Commercial or Famous Applicattions.? References: Message-ID: On Wed, 10 Nov 2010 16:58:06 -0800, alex23 wrote: > Martin Gregorie wrote: >> Now, if ESR had fixed fetchmail [...] > > Did you try submitting patches? Nope. I'd already seen comments that bug reports etc. are ignored and tried getmail. Since that does the needful, why should I bother? -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From usenet at solar-empire.de Thu Nov 11 07:29:59 2010 From: usenet at solar-empire.de (Marc Christiansen) Date: Thu, 11 Nov 2010 13:29:59 +0100 Subject: strange problem with multiprocessing References: Message-ID: <774tq7-t5j.ln1@pluto.solar-empire.de> Neal Becker wrote: > Any idea what this could be about? > > Traceback (most recent call last): > File "run-tests-10111104.py", line 48, in > results = pool.map (run_test, cases) > File "/usr/lib64/python2.7/multiprocessing/pool.py", line 199, in map > return self.map_async(func, iterable, chunksize).get() > File "/usr/lib64/python2.7/multiprocessing/pool.py", line 491, in get > raise self._value > ValueError: cannot convert float NaN to integer > The ValueError comes from run_test. It contains an int(x), where x == float('nan'). Does cases maybe contain a NaN? Ciao Marc From manu3d at gmail.com Thu Nov 11 09:04:33 2010 From: manu3d at gmail.com (Emanuele D'Arrigo) Date: Thu, 11 Nov 2010 06:04:33 -0800 (PST) Subject: A matter of queues, tasks and multiprocessing References: <9e6f2dcc-7d15-4162-b3e9-9ef77a0b8980@n30g2000vbb.googlegroups.com> Message-ID: <41980a52-5bf3-4212-a0f4-a9968c2eb523@i17g2000vbq.googlegroups.com> On Nov 10, 9:19?pm, "danmcle... at yahoo.com" wrote: > If you are using Python 2.6 or greater, look into the multiprocessing > module. It may contain 90% of what you need. Thank you Dan, indeed the multi-processing module has been my first port of call and indeed it has all the basic ingredients. What I'm looking for is an higher-level architecture built on the multi- processing and the multi-threading modules. Thanks again! Manu From mail at timgolden.me.uk Thu Nov 11 09:13:34 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 11 Nov 2010 14:13:34 +0000 Subject: A matter of queues, tasks and multiprocessing In-Reply-To: <41980a52-5bf3-4212-a0f4-a9968c2eb523@i17g2000vbq.googlegroups.com> References: <9e6f2dcc-7d15-4162-b3e9-9ef77a0b8980@n30g2000vbb.googlegroups.com> <41980a52-5bf3-4212-a0f4-a9968c2eb523@i17g2000vbq.googlegroups.com> Message-ID: <4CDBFA0E.4060001@timgolden.me.uk> On 11/11/2010 14:04, Emanuele D'Arrigo wrote: > On Nov 10, 9:19 pm, "danmcle... at yahoo.com" > wrote: >> If you are using Python 2.6 or greater, look into the multiprocessing >> module. It may contain 90% of what you need. > > Thank you Dan, indeed the multi-processing module has been my first > port of call and indeed it has all the basic ingredients. What I'm > looking for is an higher-level architecture built on the multi- > processing and the multi-threading modules. Try Celery http://ask.github.com/celery/getting-started/introduction.html TJG From stef.mientki at gmail.com Thu Nov 11 09:22:57 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Thu, 11 Nov 2010 15:22:57 +0100 Subject: is there an Python equivalent for the PHP super globals like $_POST, $_COOKIE ? Message-ID: <4CDBFC41.6080404@gmail.com> hello, finally got Python running at my server. Now I would like to replace the PHP server scripts with Python ( for easier maintenance). But I can't find how th get to PHP's equivalent of $_Post and $_Cookie ? Google finds lots of links, but I can't find the answer. thanks, Stef Mientki From cdalten at gmail.com Thu Nov 11 10:07:32 2010 From: cdalten at gmail.com (chad) Date: Thu, 11 Nov 2010 07:07:32 -0800 (PST) Subject: How do I skip over multiple words in a file? Message-ID: Let's say that I have an article. What I want to do is read in this file and have the program skip over ever instance of the words "the", "and", "or", and "but". What would be the general strategy for attacking a problem like this? From tartley at tartley.com Thu Nov 11 10:15:03 2010 From: tartley at tartley.com (Jonathan Hartley) Date: Thu, 11 Nov 2010 07:15:03 -0800 (PST) Subject: Ways of accessing this mailing list? References: <87lj5ahzd9.fsf@benfinney.id.au> Message-ID: On Nov 3, 9:27?pm, Ben Finney wrote: > Grant Edwards writes: > > On 2010-11-02, John Bond wrote: > > > My normal inbox is getting unmanageable, and I think I need to find > > > a new way of following this and other lists. > > > Point an NNTP client at new.gmane.org. > > Ditto, but the correct hostname is ?news.gmane.org?. > Hey. I'm was trying this, and got stuck for a while. I have found 'gmane.comp.python.devel', which looks great for lurking, along with many other entries under gmane.comp.python.*. But I couldn't find *this* list (comp.lang.python) for ages, despite scrutinising possible aliases. For anyone else in the same boat, you are looking for gmane.comp.python.general. Jonathan From python.list at tim.thechases.com Thu Nov 11 10:48:54 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 11 Nov 2010 09:48:54 -0600 Subject: How do I skip over multiple words in a file? In-Reply-To: References: Message-ID: <4CDC1066.9050400@tim.thechases.com> On 11/11/10 09:07, chad wrote: > Let's say that I have an article. What I want to do is read in > this file and have the program skip over ever instance of the > words "the", "and", "or", and "but". What would be the > general strategy for attacking a problem like this? I'd keep a file of "stop words", read them into a set (normalizing case in the process). Then, as I skim over each word in my target file, check if the case-normalized version of the word is in your stop-words and skipping if it is. It might look something like this: def normalize_word(s): return s.strip().upper() stop_words = set( normalize_word(word) for word in file('stop_words.txt') ) for line in file('data.txt'): for word in line.split(): if normalize_word(word) in stop_words: continue process(word) -tkc From calderone.jeanpaul at gmail.com Thu Nov 11 11:03:21 2010 From: calderone.jeanpaul at gmail.com (Jean-Paul Calderone) Date: Thu, 11 Nov 2010 08:03:21 -0800 (PST) Subject: udp sockets with python References: Message-ID: On Nov 10, 9:23?pm, Tim Roberts wrote: > Mag Gam wrote: > > >I am measuring the round trip time using tcpdump. The C version is > >giving me around 80 microseconds (average) and the python is giving me > >close to 300 microseconds (average). > > If you need the performance of a compiled language, then it's probably not > appropriate to use an interpreter. Ridiculous. From fuglyducky at gmail.com Thu Nov 11 11:09:23 2010 From: fuglyducky at gmail.com (fuglyducky) Date: Thu, 11 Nov 2010 08:09:23 -0800 (PST) Subject: Looping through files in a directory References: Message-ID: <636b05ca-5c24-40de-9000-babc0723943f@29g2000prb.googlegroups.com> On Nov 10, 4:14?pm, James Mills wrote: > On Thu, Nov 11, 2010 at 8:46 AM, Matty Sarro wrote: > > Short story - I have a few thousand files in a directory I need to parse > > through. Is there a simple way to loop through files? I'd like to avoid > > writing a python script that can parse 1 file, and have to call it a few > > thousand times from a bash script. Any input or pointers to functions that'd > > help would be very much appreciated. Thanks! > > os.walk or os.listdir > > cheers > James > > -- > -- James Mills > -- > -- "Problems are solved by method" I was able to do something similar like this... ############################ rootPath = 'T:/' pattern = '*.xml' for root, dirs, files in os.walk(rootPath): for filename in fnmatch.filter(files, pattern): full_path = (os.path.join(root, filename)) print(full_path) ############################ From ian.g.kelly at gmail.com Thu Nov 11 11:30:57 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 11 Nov 2010 09:30:57 -0700 Subject: Open Multiples Files at same time with multiprocessing - How "declare" dynamically the var? In-Reply-To: References: Message-ID: On 11/11/2010 4:28 AM, macm wrote: > def openFiles(self,file,q): > fp = open(file, 'rb') > fp.seek(0) The seek is unnecessary; the file will already be at position 0 after it is opened. > def testOpen(self): > L = > ['file1.txt','file2.txt','file3.txt','file4.txt','file5.txt'] > d1 = [] > for x in L: > z=L.index(x) "for z, x in enumerate(L):" > q = Queue() > m = Process(target=self.openFiles, args=(x,q,)) > m.start() > d1.append(q.get()) #<= This get is locking ? It is mean: > "wait m.start(), like m.join()??" It can't get an item from the queue until an item has been put in the queue to get, so it waits for the process m to put something there. It does not do an implicit m.join() however. > I tried use list but didn't work look below one shot. "It didn't work" is not very useful for helping you debug. Be specific. What were you expecting, and what did you get instead? If there was a traceback, copy and paste it. Cheers, Ian From olivier.scalbert at algosyn.com Thu Nov 11 11:58:28 2010 From: olivier.scalbert at algosyn.com (Olivier Scalbert) Date: Thu, 11 Nov 2010 17:58:28 +0100 Subject: Question on using urllib Message-ID: <4cdc20b4$0$14249$ba620e4c@news.skynet.be> Hello all, Sorry if this question is not 100% python related, it is also related to http or html ... Everything takes place in this page: http://www.infometeo.be/klanten/KYC/campage2mega.php With the following program, I can download the 2 small meteo images, without any problem: import urllib urllib.urlretrieve("http://www.infometeo.be/wwweather/currentimage.php?icao=EBFN", "meteo1.jpg") urllib.urlretrieve("http://www.meteokust.be/metstatgr.php?s=zb", "meteo2.jpg") But I would like to download the main background picture. By looking inside the html page, it seems it's url is: http://www.infometeo.be/img.php?iid=1057 ...
... Warning, the iid may vary depending time ... I try to download it with python: urllib.urlretrieve("http://www.infometeo.be/img.php?iid=1057", "picture.jpg") But then I receive only 2 bytes: CR LF I think. If I use this url with my browser (firefox), I also get nothing (a blank page). If I go back to the main page with the firebug plugin activated, I can change the iid directly inside the html code with firebug, and then, even previous pictures can be displayed ... So I am a bit lost ... Any help would be very appreciate !! Thanks, Olivier From fetchinson at googlemail.com Thu Nov 11 12:24:12 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Thu, 11 Nov 2010 18:24:12 +0100 Subject: ANN: PyGUI 2.3 In-Reply-To: <4CCA99F3.4060106@canterbury.ac.nz> References: <4CCA99F3.4060106@canterbury.ac.nz> Message-ID: >> The problem is that some part of the application gets installed to >> >> /home/fetchinson/.local/lib/python2.6/site-packages/GUI >> >> and some other parts get installed to >> >> /home/fetchinson/.local/lib/python/site-packages/GUI > > Which parts get installed in which places, exactly? This gets installed to /home/fetchinson/.local/lib/python/GUI : Generic Gtk __init__.py __init__.pyc Version.py Version.pyc _where.py _where.pyc And this gets installed to /home/fetchinson/.local/lib/python2.6/site-packages/GUI : Resources > I'm puzzled, because I can't see anything in the setup.py > that could result in things getting split up like this. > I'm wondering whether there is some breakage in distutils. I honestly have no idea :) Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From __peter__ at web.de Thu Nov 11 12:37:27 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 11 Nov 2010 18:37:27 +0100 Subject: Question on using urllib References: <4cdc20b4$0$14249$ba620e4c@news.skynet.be> Message-ID: Olivier Scalbert wrote: > Sorry if this question is not 100% python related, it is also related to > http or html ... > > Everything takes place in this page: > http://www.infometeo.be/klanten/KYC/campage2mega.php > > With the following program, I can download the 2 small meteo images, > without any problem: > > import urllib > > urllib.urlretrieve("http://www.infometeo.be/wwweather/currentimage.php?icao=EBFN", > "meteo1.jpg") > urllib.urlretrieve("http://www.meteokust.be/metstatgr.php?s=zb", > "meteo2.jpg") > > But I would like to download the main background picture. > > By looking inside the html page, it seems it's url is: > http://www.infometeo.be/img.php?iid=1057 > I try to download it with python: > urllib.urlretrieve("http://www.infometeo.be/img.php?iid=1057", > "picture.jpg") The problem is indeed not Python-related. The provider of the images doesn't like what you're trying to do and verifies the referer, i. e. that the page you claim to be coming from is acceptable. Here's one way to satisfy that check: >>> from urllib2 import Request, urlopen >>> r = Request("http://www.infometeo.be/img.php?iid=1057", headers=dict(Referer="http://www.infometeo.be/img.php?iid=1057")) >>> img = urlopen(r).read() >>> with open("tmp.jpg", "w") as f: f.write(img) ... >>> Now if you are using that workaround a lot he may come up with more sophisticated techniques. So dont ;) Peter From steve at holdenweb.com Thu Nov 11 13:01:01 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 11 Nov 2010 13:01:01 -0500 Subject: is there an Python equivalent for the PHP super globals like $_POST, $_COOKIE ? In-Reply-To: <4CDBFC41.6080404@gmail.com> References: <4CDBFC41.6080404@gmail.com> Message-ID: On 11/11/2010 9:22 AM, Stef Mientki wrote: > hello, > > finally got Python running at my server. > > Now I would like to replace the PHP server scripts with Python ( for easier maintenance). > > But I can't find how th get to PHP's equivalent of $_Post and $_Cookie ? > Google finds lots of links, but I can't find the answer. > > thanks, > Stef Mientki Stef: Moving from one language to anther is not just a matter of transliterating the code. Of you try that you will end up with a messy code base that looks like PHP written in Python. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From rantingrick at gmail.com Thu Nov 11 13:07:51 2010 From: rantingrick at gmail.com (rantingrick) Date: Thu, 11 Nov 2010 10:07:51 -0800 (PST) Subject: =?windows-1252?Q?Re=3A_Am_I_The_Only_One_Who_Keeps_Reading_=93Numpy=94_?= =?windows-1252?Q?as_=93Numpty=94=3F?= References: <940162c6-b61a-4bb7-9965-6e155716cda8@n30g2000vbb.googlegroups.com> <87hbfoycov.fsf@gmail.com> Message-ID: On Nov 10, 5:35?pm, Arnaud Delobelle wrote: > So pypy is "pie-pee", not "pie-pie" or "pee-pee". ?With that edifying > thought, I'm off to bed. :) Good catch! Actually i've always thought of pypi as pie-pie and Scipy as cy-pie. Num-pie does not work for me. Maybe some linguist could chime in and explain these odd tendencies...? From olivier.scalbert at algosyn.com Thu Nov 11 13:15:19 2010 From: olivier.scalbert at algosyn.com (Olivier Scalbert) Date: Thu, 11 Nov 2010 19:15:19 +0100 Subject: Question on using urllib In-Reply-To: References: <4cdc20b4$0$14249$ba620e4c@news.skynet.be> Message-ID: <4cdc32b8$0$14247$ba620e4c@news.skynet.be> On 11/11/2010 06:37 PM, Peter Otten wrote: > The problem is indeed not Python-related. The provider of the images doesn't > like what you're trying to do and verifies the referer, i. e. that the page > you claim to be coming from is acceptable. Here's one way to satisfy that > check: > >>>> from urllib2 import Request, urlopen >>>> r = Request("http://www.infometeo.be/img.php?iid=1057", > headers=dict(Referer="http://www.infometeo.be/img.php?iid=1057")) >>>> img = urlopen(r).read() >>>> with open("tmp.jpg", "w") as f: f.write(img) > ... >>>> > > Now if you are using that workaround a lot he may come up with more > sophisticated techniques. So dont ;) > > Peter Thanks Peter, it works perfectly ! At 60 fps I can even make a video ... ;-) Olivier From stef.mientki at gmail.com Thu Nov 11 13:20:03 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Thu, 11 Nov 2010 19:20:03 +0100 Subject: is there an Python equivalent for the PHP super globals like $_POST, $_COOKIE ? In-Reply-To: References: <4CDBFC41.6080404@gmail.com> Message-ID: <4CDC33D3.9060308@gmail.com> On 11-11-2010 19:01, Steve Holden wrote: > On 11/11/2010 9:22 AM, Stef Mientki wrote: >> hello, >> >> finally got Python running at my server. >> >> Now I would like to replace the PHP server scripts with Python ( for easier maintenance). >> >> But I can't find how th get to PHP's equivalent of $_Post and $_Cookie ? >> Google finds lots of links, but I can't find the answer. >> >> thanks, >> Stef Mientki > Stef: > > Moving from one language to anther is not just a matter of > transliterating the code. Of you try that you will end up with a messy > code base that looks like PHP written in Python. Steve I agree with you, but replacing a number of 3 to 10 lines of code scripts won't create a mess ;-) cheers, Stef > regards > Steve From usenet-nospam at seebs.net Thu Nov 11 13:22:05 2010 From: usenet-nospam at seebs.net (Seebs) Date: 11 Nov 2010 18:22:05 GMT Subject: Silly newbie question - Caret character (^) References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> Message-ID: (Note followups, this has stopped being very Pythony.) On 2010-11-11, Lawrence D'Oliveiro wrote: > Another function that should be deprecated is strncat???I myself was caught > out misunderstanding it recently. What purpose does it serve? I'm wondering if you're thinking of strncpy(), which is the famously bogus one. strncat() just has a fencepost error -- given a limit N, it will write at most N+1 characters. strncpy(), however, pads with null bytes if the source string isn't long enough, and does not null terminate if there isn't room to. This behavior is nearly always undesireable. However, if you were building a filesystem in which file path names were given exactly sixteen bytes of space in the directory entry, and you didn't want to truncate them to 15 bytes, you might write precisely this behavior. So that's what we got. I don't know whether anyone's gotten buy-in from the standards people for strlcpy()/strlcat(), but I really hope so. Me, I just use snprintf with a %s format instead of str*cpy(). -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From nagle at animats.com Thu Nov 11 13:32:46 2010 From: nagle at animats.com (John Nagle) Date: Thu, 11 Nov 2010 10:32:46 -0800 Subject: os.tmpfile() vs. tempfile.TemporaryFile() Message-ID: <4cdc36cf$0$1665$742ec2ed@news.sonic.net> Is there any reason to prefer "tempfile.TemporaryFile()" over "os.tmpfile()"? Both create a nameless temporary file that will be deleted on close. John Nagle From david_v_wright at yahoo.com Thu Nov 11 13:36:51 2010 From: david_v_wright at yahoo.com (david wright) Date: Thu, 11 Nov 2010 10:36:51 -0800 (PST) Subject: is there an Python equivalent for the PHP super globals like $_POST, $_COOKIE ? In-Reply-To: <4CDC33D3.9060308@gmail.com> References: <4CDBFC41.6080404@gmail.com> <4CDC33D3.9060308@gmail.com> Message-ID: <641264.37067.qm@web31810.mail.mud.yahoo.com> ________________________________ From: Stef Mientki To: python-list at python.org Sent: Thu, November 11, 2010 10:20:03 AM Subject: Re: is there an Python equivalent for the PHP super globals like $_POST, $_COOKIE ? On 11-11-2010 19:01, Steve Holden wrote: > On 11/11/2010 9:22 AM, Stef Mientki wrote: >> hello, >> >> finally got Python running at my server. >> >> Now I would like to replace the PHP server scripts with Python ( for easier >>maintenance). >> >> But I can't find how th get to PHP's equivalent of $_Post and $_Cookie ? >> Google finds lots of links, but I can't find the answer. >> >> thanks, >> Stef Mientki > Stef: > > Moving from one language to anther is not just a matter of > transliterating the code. Of you try that you will end up with a messy > code base that looks like PHP written in Python. - Steve I agree with you, - but replacing a number of 3 to 10 lines of code scripts won't create a mess ;-) So, assuming you want the 'straight ahead' (i.e. no framework, like Django) your looking at vanilla CGI programming. form = cgi.FieldStorage() # parse query string, handles decoding and GET and POST print "

name:", form["name"].value http://docs.python.org/library/cgi.html Enjoy! :) David -------------- next part -------------- An HTML attachment was scrubbed... URL: From danmcleran at yahoo.com Thu Nov 11 13:38:32 2010 From: danmcleran at yahoo.com (danmcleran at yahoo.com) Date: Thu, 11 Nov 2010 10:38:32 -0800 (PST) Subject: os.tmpfile() vs. tempfile.TemporaryFile() References: <4cdc36cf$0$1665$742ec2ed@news.sonic.net> Message-ID: On Nov 11, 11:32?am, John Nagle wrote: > ? ?Is there any reason to prefer "tempfile.TemporaryFile()" > over "os.tmpfile()"? ?Both create a nameless temporary file > that will be deleted on close. > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? John Nagle tempfile.TemporaryFile has more options, e.g. file prefix, suffix, dir location, mode, and buf size. if you don't care about any of that, then it probably makes no difference. From aotto1968 at users.berlios.de Thu Nov 11 13:51:38 2010 From: aotto1968 at users.berlios.de (Andreas Otto) Date: Thu, 11 Nov 2010 19:51:38 +0100 Subject: ANNOUNCE: NHI1-0.9, PLMK-1.7 und libmsgque-4.7 Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Dear User, ANNOUNCE: Major Feature Release ==================================== libmsgque: Application-Server-Toolkit for C, C++, JAVA, C#, TCL, PERL, PHP, PYTHON, RUBY, VB.NET PLMK: Programming-Language-Microkernel NHI1: Non-Human-Intelligence #1 LINKS ===== ChangeLog: > http://nhi1.berlios.de/theLink/changelog.htm libmsgque including PHP documentation: > http://nhi1.berlios.de/theLink/index.htm NHI1: > http://nhi1.berlios.de/ DOWNLOAD: > http://developer.berlios.de/projects/nhi1/ PHP man pages: > reference: msgqueforphpref.n > tutorial: msgqueforphptut.n SUMMARY ======= This version adds the ability to: * PHP language support. * a new interface of the "ProcessEvent" function and the "startAs" configuration option. * terminate an application from a callback with the "ErrorSetEXIT" function. The PHP language is characterized by an extensive but undocumented C API. The number of features combined with a growing and moving language made the extension programming difficult and lengthy. The successful PHP extension shows the flexibility and adaptability of NHI1. mfg Andreas Otto (aotto1968) -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.15 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org/ iQEcBAEBAgAGBQJM3Ds6AAoJEGTcPijNG3/ATywH/iguN1+96sp2RGzIz6N3I8mx tw4YO6ac8NPT+Ztm+IXYbGlkyb2Z/3UwES7aZunYy7DK/kJBh7VBbZNGGWZlRTvm w02uMa4dTCBye8tNkQ8dRAxjshe9taM1+54Z4k1EsFmIXOMi8bbdDuAPk2i8xGRu vJIFC6ubIx93Sjgodcr/AIGRskjutpF29+uoaSMz+8UrTxnSoJxq8VvgWR/+MXfZ UOb8GutVV6bGI/ylE/NgLpxvE1LUMNgMS0QzHgQHSu4E/8tW3Oyzt6FU68k51n8+ OTJaFYC7o1W9VwSoc/HNHPhVmECYONW40pRrf2P0llqiKElBAd23g1/h83iblqo= =5U+w -----END PGP SIGNATURE----- From stef.mientki at gmail.com Thu Nov 11 13:56:07 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Thu, 11 Nov 2010 19:56:07 +0100 Subject: is there an Python equivalent for the PHP super globals like $_POST, $_COOKIE ? In-Reply-To: <641264.37067.qm@web31810.mail.mud.yahoo.com> References: <4CDBFC41.6080404@gmail.com> <4CDC33D3.9060308@gmail.com> <641264.37067.qm@web31810.mail.mud.yahoo.com> Message-ID: <4CDC3C47.3050303@gmail.com> On 11-11-2010 19:36, david wright wrote: > > ---------------------------------------------------------------------------------------------------- > *From:* Stef Mientki > *To:* python-list at python.org > *Sent:* Thu, November 11, 2010 10:20:03 AM > *Subject:* Re: is there an Python equivalent for the PHP super globals like $_POST, $_COOKIE ? > > On 11-11-2010 19:01, Steve Holden wrote: > > On 11/11/2010 9:22 AM, Stef Mientki wrote: > >> hello, > >> > >> finally got Python running at my server. > >> > >> Now I would like to replace the PHP server scripts with Python ( for easier maintenance). > >> > >> But I can't find how th get to PHP's equivalent of $_Post and $_Cookie ? > >> Google finds lots of links, but I can't find the answer. > >> > >> thanks, > >> Stef Mientki > > Stef: > > > > Moving from one language to anther is not just a matter of > > transliterating the code. Of you try that you will end up with a messy > > code base that looks like PHP written in Python. > - Steve I agree with you, > - but replacing a number of 3 to 10 lines of code scripts won't create a mess ;-) > > So, assuming you want the 'straight ahead' (i.e. no framework, like Django) your looking > at vanilla CGI programming. > > form = cgi.FieldStorage() # parse query string, handles decoding and GET and POST > > print "

name:", form["name"].value > > http://docs.python.org/library/cgi.html thanks David, looks that was what I was looking for, I'll investigate all the properties of Fieldstorage. thanks, Stef > Enjoy! :) > David > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From aioe.org at technicalbloke.com Thu Nov 11 14:34:23 2010 From: aioe.org at technicalbloke.com (r0g) Date: Thu, 11 Nov 2010 19:34:23 +0000 Subject: Class extension confusion :( References: Message-ID: On 11/11/10 09:34, Peter Otten wrote: > r0g wrote: > >> Question B) The only reason I can think of so far is that I don't have a >> clear picture of how those names came to end up in that scope, it seems >> very convenient but I'm worried it's black magic of some sort! Could >> anyone explain or point me to the right docs please? > > Python looks for attributes in the instance first, and then in the class as > a fallback. You only need to put them in the instance if you expect that you > want a different value for every instance. > > Peter > Thanks Peter, I think I understand now, I'll quickly explain my picture of things though so you or some other denizens of the mighty comp.lang.python can correct me if I'm wrong!... I can access the parameters I pass to __init__ within the classes' methods without using self. as these methods are run within the constructor itself and are therefore within it's local scope. That also explains why I had to call the constructor _after_ creating the new data attributes to have them be included. My initial belief that one has to call the parent constructor as the first action in the extended constructor is not technically valid, in most cases it can be called at any point but in situations like the above it can mess things up so I ought to put it at the end of my constructors for it to always work. Are there any drawbacks to calling it last or is that how it is supposed to work? The BaseHTTPRequestHandler seemed curiously constructed to me at first too but I think I can see why now... as it's a handler it's only ever meant to be a transient thing and it requires no external parameters (unless you're me!) as it's always called by HTTPServer which has all the info necessary so there's be no sense requiring users to create an instance then call a method to get the servers response, you may as well just bundle it all into one. Also as it might be called hundreds or thousands of times in quick succession it would be important to have it finish and get garbage collected. I also see that I ought to at least assign these extended params to data attributes and access them via self. like I would normally do as I can't guarantee that implementation of BaseHTTPREquestHandler will remain constant over time. If I understand correctly it may also be possible (and more efficient) to use setattr() to inject the parameters I want into the class as class attributes before use, rather than assigning them to data attributes every time I instantiate an new instance. Actually looking at the code from BaseRequestHandler it seems I may have overlooked the proper way of associating a callback function anyway. It looks like I should just define self.handle() in my subclass so that's one less parameter to worry about, although I think I may still need to use the factory function method you showed me to get the "paths" dictionary in there. Thanks so much for all your help, I really appreciate it and, assuming I'm not totally wrong about all of the above, I find it reassuring that I'm not going mad! Cheers, Roger. From aioe.org at technicalbloke.com Thu Nov 11 14:45:28 2010 From: aioe.org at technicalbloke.com (r0g) Date: Thu, 11 Nov 2010 19:45:28 +0000 Subject: How to test if a module exists? References: <87d3qdibzg.fsf.mdw@metalzone.distorted.org.uk> <87vd44gkv8.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On 11/11/10 11:28, Mark Wooding wrote: > r0g writes: > >> Really? I get a metric butt-ton of spam every day to this address. > > I'm sure I get sent a lot of spam (though I don't know for sure -- see > below). But I don't think much of it comes from Usenet harvesters any > more. > >> Right now it simply filtered by address straight into my recycle bin, >> I suppose if it ever becomes burdensome or starts to choke my >> bandwidth I'll tell my mailserver to bounce it :) > > Don't do that. Get your mailserver to /reject/ spam during SMTP with a > 5xx code. Bouncing spam is really bad because it implicitly assumes > that the envelope sender address is good. Spam rarely has a valid > envelope sender. If you're lucky, the envelope sender is simply > invalid, and you'll end up with a double-bounce when your mailserver > finds out. If you're unlucky, the envelope sender is a /valid/ address > from the spammer's list and some innocent victim will end up receiving > your bounce (this is called `backscatter'). > > -- [mdw] Whoops, I forgot 'bounce' has a clear meaning in the world email, I meant reject. Having suffered plenty of backscatter back in the day I wouldn't want to wish that on anyone. Thankfully I haven't had any of that in a few years now. I guess a lot more people are using Domainkeys and SPF these days. Roger From ldo at geek-central.gen.new_zealand Thu Nov 11 14:49:18 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 12 Nov 2010 08:49:18 +1300 Subject: How to test if a module exists? References: Message-ID: In message , Jon Dufresne wrote: > On Wed, Nov 10, 2010 at 1:50 AM, Lawrence D'Oliveiro wrote: > >> In message , Jon >> Dufresne wrote: >> >>> On Mon, Nov 8, 2010 at 11:35 PM, Lawrence D'Oliveiro ... >> >> I see that you published my unobfuscated e-mail address on USENET for all >> to see. I obfuscated it for a reason, to keep the spammers away. I'm >> assuming this was a momentary lapse of judgement, for which I expect an >> apology. Otherwise, it becomes grounds for an abuse complaint to your >> ISP. >> > > Is this for real? I did a "replay all" to respond to your post. What > are you suggesting? I don't see anything that looks like an obfuscated > email. Tell me what you see here, for example . From aioe.org at technicalbloke.com Thu Nov 11 15:02:05 2010 From: aioe.org at technicalbloke.com (r0g) Date: Thu, 11 Nov 2010 20:02:05 +0000 Subject: is there an Python equivalent for the PHP super globals like $_POST, $_COOKIE ? References: Message-ID: On 11/11/10 14:22, Stef Mientki wrote: > hello, > > finally got Python running at my server. > > Now I would like to replace the PHP server scripts with Python ( for easier maintenance). > > But I can't find how th get to PHP's equivalent of $_Post and $_Cookie ? > Google finds lots of links, but I can't find the answer. > > thanks, > Stef Mientki PHP only tends to be run one way, the mod_php Apache module. There's several ways run python in conjunction with a webserver like apache: mod_wsgi, mod_python, CGI and FastCGI. I've never really looked into this way of doing things but I guess the details are going to vary depending on which one you use. It's also not uncommon for python to actually BE the webserver too, there's lots of webserver modules for python, cherrypy is fairly simple and well regarded. Often you can proxy these through Apache to get the benefits of both although again, that's not an approach I've used so I can't really advise you further. Roger. From ryszard.czerminski at gmail.com Thu Nov 11 15:08:55 2010 From: ryszard.czerminski at gmail.com (=?ISO-8859-2?Q?Ryszard_Czermi=F1ski?=) Date: Thu, 11 Nov 2010 15:08:55 -0500 Subject: please subscribe me to the list Message-ID: Thanks! Ryszard From aioe.org at technicalbloke.com Thu Nov 11 15:12:54 2010 From: aioe.org at technicalbloke.com (r0g) Date: Thu, 11 Nov 2010 20:12:54 +0000 Subject: How do I skip over multiple words in a file? References: Message-ID: On 11/11/10 15:07, chad wrote: > Let's say that I have an article. What I want to do is read in this > file and have the program skip over ever instance of the words "the", > "and", "or", and "but". What would be the general strategy for > attacking a problem like this? If your files are not too big I'd simply read them into a string and do a string replace for each word you want to skip. If you want case insensitivity use re.replace() instead of the default string.replace() method. Neither are elegant or all that efficient but both are very easy. If your use case requires something high performance then best keep looking :) Roger. From aioe.org at technicalbloke.com Thu Nov 11 15:14:52 2010 From: aioe.org at technicalbloke.com (r0g) Date: Thu, 11 Nov 2010 20:14:52 +0000 Subject: udp sockets with python References: Message-ID: On 11/11/10 16:03, Jean-Paul Calderone wrote: > On Nov 10, 9:23 pm, Tim Roberts wrote: >> Mag Gam wrote: >> >>> I am measuring the round trip time using tcpdump. The C version is >>> giving me around 80 microseconds (average) and the python is giving me >>> close to 300 microseconds (average). >> >> If you need the performance of a compiled language, then it's probably not >> appropriate to use an interpreter. > > Ridiculous. Terse! From aioe.org at technicalbloke.com Thu Nov 11 15:23:12 2010 From: aioe.org at technicalbloke.com (r0g) Date: Thu, 11 Nov 2010 20:23:12 +0000 Subject: is there an Python equivalent for the PHP super globals like $_POST, $_COOKIE ? References: <4CDBFC41.6080404@gmail.com> Message-ID: On 11/11/10 18:01, Steve Holden wrote: > On 11/11/2010 9:22 AM, Stef Mientki wrote: >> hello, >> >> finally got Python running at my server. >> >> Now I would like to replace the PHP server scripts with Python ( for easier maintenance). >> >> But I can't find how th get to PHP's equivalent of $_Post and $_Cookie ? >> Google finds lots of links, but I can't find the answer. >> >> thanks, >> Stef Mientki > > Stef: > > Moving from one language to anther is not just a matter of > transliterating the code. Of you try that you will end up with a messy > code base that looks like PHP written in Python. > > regards > Steve Come on Steve, I thought your role is to encourage / cheerlead here ;D While you're absolutely right when it comes to complex apps and sites I get the impression he's only talking about your common or garden short admin scripts. I might be wrong though. Roger From paul.watson at tungsten-consulting.com Thu Nov 11 15:24:28 2010 From: paul.watson at tungsten-consulting.com (Paul Watson) Date: Thu, 11 Nov 2010 13:24:28 -0700 Subject: is there an Python equivalent for the PHP super globals like $_POST, $_COOKIE ? In-Reply-To: References: <4CDBFC41.6080404@gmail.com> Message-ID: <4CDC50FC.60702@gmail.com> On 2010-11-11 11:20, Stef Mientki wrote: > On 11-11-2010 19:01, Steve Holden wrote: >> On 11/11/2010 9:22 AM, Stef Mientki wrote: >>> hello, >>> >>> finally got Python running at my server. >>> >>> Now I would like to replace the PHP server scripts with Python ( for easier maintenance). >>> >>> But I can't find how th get to PHP's equivalent of $_Post and $_Cookie ? >>> Google finds lots of links, but I can't find the answer. >>> >>> thanks, >>> Stef Mientki >> Stef: >> >> Moving from one language to anther is not just a matter of >> transliterating the code. Of you try that you will end up with a messy >> code base that looks like PHP written in Python. > Steve I agree with you, > but replacing a number of 3 to 10 lines of code scripts won't create a mess ;-) > > cheers, > Stef >> regards >> Steve > If there is no automated process to do the translation, then it should be avoided. It is an opportunity for chaos to ensue. From paul.hermeneutic at gmail.com Thu Nov 11 15:24:28 2010 From: paul.hermeneutic at gmail.com (Paul Watson) Date: Thu, 11 Nov 2010 13:24:28 -0700 Subject: is there an Python equivalent for the PHP super globals like $_POST, $_COOKIE ? In-Reply-To: References: <4CDBFC41.6080404@gmail.com> Message-ID: <4CDC50FC.60702@gmail.com> On 2010-11-11 11:20, Stef Mientki wrote: > On 11-11-2010 19:01, Steve Holden wrote: >> On 11/11/2010 9:22 AM, Stef Mientki wrote: >>> hello, >>> >>> finally got Python running at my server. >>> >>> Now I would like to replace the PHP server scripts with Python ( for easier maintenance). >>> >>> But I can't find how th get to PHP's equivalent of $_Post and $_Cookie ? >>> Google finds lots of links, but I can't find the answer. >>> >>> thanks, >>> Stef Mientki >> Stef: >> >> Moving from one language to anther is not just a matter of >> transliterating the code. Of you try that you will end up with a messy >> code base that looks like PHP written in Python. > Steve I agree with you, > but replacing a number of 3 to 10 lines of code scripts won't create a mess ;-) > > cheers, > Stef >> regards >> Steve > If there is no automated process to do the translation, then it should be avoided. It is an opportunity for chaos to ensue. From python at mrabarnett.plus.com Thu Nov 11 15:25:46 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 11 Nov 2010 20:25:46 +0000 Subject: please subscribe me to the list In-Reply-To: References: Message-ID: <4CDC514A.8030803@mrabarnett.plus.com> On 11/11/2010 20:08, Ryszard Czermi?ski wrote: > Thanks! > Ryszard What don't you do it yourself? Go to: http://mail.python.org/mailman/listinfo/python-list From ldo at geek-central.gen.new_zealand Thu Nov 11 15:26:51 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 12 Nov 2010 09:26:51 +1300 Subject: How to test if a module exists? References: Message-ID: In message , Tim Chase wrote: > Amusingly, as others have noted, you replied with an unobfuscated > email address. This would seem to be an independent, true record of what members of python-list would see of my posting, would it not? You would agree that it shows my e- mail address as obfuscated, would you not? So if you claim to be seeing an unobfuscated e-mail address for my posting on python-list, you would be lying, would you not? From phd at phd.pp.ru Thu Nov 11 15:26:57 2010 From: phd at phd.pp.ru (Oleg Broytman) Date: Thu, 11 Nov 2010 23:26:57 +0300 Subject: Torrent VFS for Midnight Commander Message-ID: <20101111202657.GA2613@phd.pp.ru> Torrent Virtual FileSystem for Midnight Commander WHAT IS IT View files, directories and meta information from a torrent metafile in Midnight Commander. WHAT'S NEW in version 1.0.0 (2010-11-11) Initial release. WHERE TO GET Master site: http://phd.pp.ru/Software/mc/ Mirrors: http://phd.by.ru/Software/mc/ http://phd.webhost.ru/Software/mc/ AUTHOR Oleg Broytman COPYRIGHT Copyright (C) 2010 PhiloSoft Design LICENSE GPL Oleg. -- Oleg Broytman http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From bnbowman at gmail.com Thu Nov 11 15:28:38 2010 From: bnbowman at gmail.com (Brett Bowman) Date: Thu, 11 Nov 2010 12:28:38 -0800 Subject: Copy Protected PDFs and PIL Message-ID: I'm trying to parse some basic details and a thumbnail from ~12,000 PDFs for my company, but a few hundred of them are copy protected. To make matters worse, I can't seem to trap the error it causes: whenever it happens PIL throws a "FATAL PDF disallows copying" message and dies. An automated way to snap a picture of the PDFs would be ideal, but I'd settle for a way to skip over them without crashing my program. Any tips? Brett Bowman Bioinformatics Associate Cibus LLC -------------- next part -------------- An HTML attachment was scrubbed... URL: From paul.hermeneutic at gmail.com Thu Nov 11 15:33:21 2010 From: paul.hermeneutic at gmail.com (Paul Watson) Date: Thu, 11 Nov 2010 13:33:21 -0700 Subject: How do I skip over multiple words in a file? In-Reply-To: References: Message-ID: <8k328sFjltU1@mid.individual.net> On 2010-11-11 08:07, chad wrote: > Let's say that I have an article. What I want to do is read in this > file and have the program skip over ever instance of the words "the", > "and", "or", and "but". What would be the general strategy for > attacking a problem like this? I realize that you may need or want to do this in Python. This would be trivial in an awk script. From python.list at tim.thechases.com Thu Nov 11 15:38:29 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 11 Nov 2010 14:38:29 -0600 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: <4CDC5445.20000@tim.thechases.com> On 11/11/10 13:49, Lawrence D'Oliveiro wrote: >> Is this for real? I did a "replay all" to respond to your post. What >> are you suggesting? I don't see anything that looks like an obfuscated >> email. > > Tell me what you see here, for example > . How about we look at an excerpt of the message you just sent: =============================== From: Lawrence D'Oliveiro Newsgroups: gmane.comp.python.general Subject: Re: How to test if a module exists? Date: Fri, 12 Nov 2010 08:49:18 +1300 [snip] >>> On Mon, Nov 8, 2010 at 11:35 PM, Lawrence D'Oliveiro ... >> >> I see that you published my unobfuscated e-mail address on >> USENET for all to see. I obfuscated it for a reason, to >> keep the spammers away. I'm assuming this was a momentary >> lapse of judgement, for which I expect anapology. Otherwise, >> it becomes grounds for an abuse complaint to your ISP. ================================ Gee...your unobfuscated email addresses FROM YOU. How about you apologize for blaming your own sins on others and then demanding THEIR apologies? When your own incompetence is at fault, demanding an apology just makes you look like an even bigger fool. And using a pre-authored email just amplifies your numskullery. And besides, your addle-pated folly has now exposed your email address to the big bad intarwebs. Once exposed, it doesn't really matter if anybody else exposes it because you yourself are to blame for letting the horse out of the barn. -tkc From no.email at nospam.invalid Thu Nov 11 15:41:01 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 11 Nov 2010 12:41:01 -0800 Subject: How do I skip over multiple words in a file? References: Message-ID: <7xhbfntwyq.fsf@ruckus.brouhaha.com> chad writes: > Let's say that I have an article. What I want to do is read in this > file and have the program skip over ever instance of the words "the", > "and", "or", and "but". What would be the general strategy for > attacking a problem like this? Something like (untested): stopwords = set (('and', 'or', 'but')) def goodwords(): for line in file: for w in line.split(): if w.lower() not in stopwords: yield w Removing punctuation is left as an exercise. From steve at holdenweb.com Thu Nov 11 15:42:23 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 11 Nov 2010 15:42:23 -0500 Subject: is there an Python equivalent for the PHP super globals like $_POST, $_COOKIE ? In-Reply-To: References: <4CDBFC41.6080404@gmail.com> Message-ID: On 11/11/2010 3:23 PM, r0g wrote: > On 11/11/10 18:01, Steve Holden wrote: >> On 11/11/2010 9:22 AM, Stef Mientki wrote: >>> hello, >>> >>> finally got Python running at my server. >>> >>> Now I would like to replace the PHP server scripts with Python ( for >>> easier maintenance). >>> >>> But I can't find how th get to PHP's equivalent of $_Post and $_Cookie ? >>> Google finds lots of links, but I can't find the answer. >>> >>> thanks, >>> Stef Mientki >> >> Stef: >> >> Moving from one language to anther is not just a matter of >> transliterating the code. Of you try that you will end up with a messy >> code base that looks like PHP written in Python. >> >> regards >> Steve > > Come on Steve, I thought your role is to encourage / cheerlead here ;D > > While you're absolutely right when it comes to complex apps and sites I > get the impression he's only talking about your common or garden short > admin scripts. I might be wrong though. > > Roger I'm quite happy to encourage, but I do find it necessary to interject a warning from time to time. I was pretty sure someone with PHP knowledge would come to the rescue. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From philip at semanchuk.com Thu Nov 11 15:54:36 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Thu, 11 Nov 2010 15:54:36 -0500 Subject: Copy Protected PDFs and PIL In-Reply-To: References: Message-ID: On Nov 11, 2010, at 3:28 PM, Brett Bowman wrote: > I'm trying to parse some basic details and a thumbnail from ~12,000 PDFs for > my company, but a few hundred of them are copy protected. To make matters > worse, I can't seem to trap the error it causes: whenever it happens PIL > throws a "FATAL PDF disallows copying" message and dies. An automated way > to snap a picture of the PDFs would be ideal, but I'd settle for a way to > skip over them without crashing my program. > > Any tips? What operating system? From steve at holdenweb.com Thu Nov 11 16:00:08 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 11 Nov 2010 16:00:08 -0500 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: On 11/11/2010 3:26 PM, Lawrence D'Oliveiro wrote: > In message , Tim Chase > wrote: > >> Amusingly, as others have noted, you replied with an unobfuscated >> email address. > > This > > would seem to be an independent, true record of what members of python-list > would see of my posting, would it not? You would agree that it shows my e- > mail address as obfuscated, would you not? So if you claim to be seeing an > unobfuscated e-mail address for my posting on python-list, you would be > lying, would you not? I still await some insight (which, of course, you are under no obligation to provide) about just why you perceive these innocent mistakes to be great wrongs that need righting. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From ethan at stoneleaf.us Thu Nov 11 16:00:39 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 11 Nov 2010 13:00:39 -0800 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: <4CDC5977.8010306@stoneleaf.us> Lawrence D'Oliveiro wrote: > In message , Tim Chase > wrote: > >> Amusingly, as others have noted, you replied with an unobfuscated >> email address. > > This > > would seem to be an independent, true record of what members of python-list > would see of my posting, would it not? You would agree that it shows my e- > mail address as obfuscated, would you not? So if you claim to be seeing an > unobfuscated e-mail address for my posting on python-list, you would be > lying, would you not? I'm using Thunderbird, and the headers, which I see very plainly while reading postings, says : Lawrence D'Oliveiro . That's what I see. ~Ethan~ From steve at holdenweb.com Thu Nov 11 16:01:19 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 11 Nov 2010 16:01:19 -0500 Subject: Copy Protected PDFs and PIL In-Reply-To: References: Message-ID: On 11/11/2010 3:28 PM, Brett Bowman wrote: > I'm trying to parse some basic details and a thumbnail from ~12,000 PDFs > for my company, but a few hundred of them are copy protected. To make > matters worse, I can't seem to trap the error it causes: whenever it > happens PIL throws a "FATAL PDF disallows copying" message and dies. An > automated way to snap a picture of the PDFs would be ideal, but I'd > settle for a way to skip over them without crashing my program. > > Any tips? > Well, you might consider letting us know whether the program gives a traceback or whether it's a PIL crash, for a start. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From python at mrabarnett.plus.com Thu Nov 11 16:03:44 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 11 Nov 2010 21:03:44 +0000 Subject: Copy Protected PDFs and PIL In-Reply-To: References: Message-ID: <4CDC5A30.8050406@mrabarnett.plus.com> On 11/11/2010 20:28, Brett Bowman wrote: > I'm trying to parse some basic details and a thumbnail from ~12,000 PDFs > for my company, but a few hundred of them are copy protected. To make > matters worse, I can't seem to trap the error it causes: whenever it > happens PIL throws a "FATAL PDF disallows copying" message and dies. An > automated way to snap a picture of the PDFs would be ideal, but I'd > settle for a way to skip over them without crashing my program. > > Any tips? > You could try it in a worker thread; it might kill only the worker. From aioe.org at technicalbloke.com Thu Nov 11 16:07:19 2010 From: aioe.org at technicalbloke.com (r0g) Date: Thu, 11 Nov 2010 21:07:19 +0000 Subject: How to test if a module exists? References: Message-ID: On 11/11/10 20:26, Lawrence D'Oliveiro wrote: > In message, Tim Chase > wrote: > >> Amusingly, as others have noted, you replied with an unobfuscated >> email address. > > This > > would seem to be an independent, true record of what members of python-list > would see of my posting, would it not? You would agree that it shows my e- > mail address as obfuscated, would you not? So if you claim to be seeing an > unobfuscated e-mail address for my posting on python-list, you would be > lying, would you not? Lawrence, this is getting old fast, just suck it up and move along. Roger From ian.g.kelly at gmail.com Thu Nov 11 16:10:37 2010 From: ian.g.kelly at gmail.com (Ian) Date: Thu, 11 Nov 2010 13:10:37 -0800 (PST) Subject: How to test if a module exists? References: Message-ID: <1d28ab93-fcaa-4c42-8bfc-4bc6de967f5d@37g2000prx.googlegroups.com> On Nov 11, 1:26?pm, Lawrence D'Oliveiro wrote: > In message , Tim Chase > wrote: > > > Amusingly, as others have noted, you replied with an unobfuscated > > email address. > > This > > would seem to be an independent, true record of what members of python-list > would see of my posting, would it not? You would agree that it shows my e- > mail address as obfuscated, would you not? Soifyou claim to be seeing an > unobfuscated e-mail address for my posting on python-list, you would be > lying, would you not? I also see the unobfuscated email address when reading your messages from python-list. The only place I see the obfuscated .new_zealand email address is when I click "View profile" in Google Groups -- but in that case the address is already truncated, so it hardly matters. From nberg at atmos.ucla.edu Thu Nov 11 16:16:12 2010 From: nberg at atmos.ucla.edu (Neil Berg) Date: Thu, 11 Nov 2010 13:16:12 -0800 Subject: returning results from function Message-ID: Hi Python community, In a main script, I pass the year (yr), month (mo), day (dy) and hour(hr) into the utc_to_local function (pasted below) which converts that date and time into local standard time. I am passing several dates and times into this function and would like to work with the "returned" loc_y/m/d/h values, but no output is visibly seen when I run the main script. I want the "return" command to just return the values to me in the main script so I can work with them! Any help is appreciated. Thanks in advance, Neil _________ Mac OS X 10.6.4 Python 2.6 _________ from datetime import datetime from pytz import timezone import pytz def utc_to_local(yr,mo,dy,hr): fmt = '%Y-%m-%d %H %Z' utc = pytz.utc local = pytz.timezone("US/Pacific") utc_dt = datetime(yr,mo,dy,hr, tzinfo=utc) loc_dt = utc_dt.astimezone(local) # local date YY-MM-DD HR TZ #print utc_dt.strftime(fmt), " = ", loc_dt.strftime(fmt) loc_y = loc_dt.year # local year loc_m = loc_dt.month # local month loc_d = loc_dt.day # local day loc_h = loc_dt.hour # local hour return loc_y, loc_m, loc_d, loc_h From emile at fenx.com Thu Nov 11 16:17:39 2010 From: emile at fenx.com (Emile van Sebille) Date: Thu, 11 Nov 2010 13:17:39 -0800 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: I'm using thunderbird via gmane and see the sender shown as ldo at geek-central.gen.nz -- so, no lies -- you've been self-outed. Emile From aioe.org at technicalbloke.com Thu Nov 11 16:17:56 2010 From: aioe.org at technicalbloke.com (r0g) Date: Thu, 11 Nov 2010 21:17:56 +0000 Subject: Class extension confusion :( References: Message-ID: On 11/11/10 19:34, r0g wrote: > On 11/11/10 09:34, Peter Otten wrote: >> r0g wrote: > If I understand correctly it may also be possible > (and more efficient) to use setattr() to inject the parameters I want > into the class as class attributes before use, rather than assigning > them to data attributes every time I instantiate an new instance. Ah, it's even simpler than that, turns out I've been significantly overcomplicating things, I can just set the class attributes by calling classname.attributename = whatever once at the start of my script. The one thing I might need to change as the server runs is the paths dictionary but dicts are mutable so that's no problem and I don't need to inject any data into the instances at all. I'm guessing I can subclass that easily now too - happy days! Well, far from wasted time it's been a very educational diversion, cheers :) Roger. From stefan.sonnenberg at pythonmeister.com Thu Nov 11 16:18:14 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Thu, 11 Nov 2010 22:18:14 +0100 Subject: How do I skip over multiple words in a file? In-Reply-To: <8k328sFjltU1@mid.individual.net> References: <8k328sFjltU1@mid.individual.net> Message-ID: <4CDC5D96.60707@pythonmeister.com> Am 11.11.2010 21:33, schrieb Paul Watson: > On 2010-11-11 08:07, chad wrote: >> Let's say that I have an article. What I want to do is read in this >> file and have the program skip over ever instance of the words "the", >> "and", "or", and "but". What would be the general strategy for >> attacking a problem like this? > > I realize that you may need or want to do this in Python. This would > be trivial in an awk script. There are several ways to do this. skip = ('and','or','but') all=[] [[all.append(w) for w in l.split() if w not in skip] for l in open('some.txt').readlines()] print all If some.txt contains your original question, it returns this: ["Let's", 'say', 'that', 'I', 'have', 'an', 'article.', 'What', 'I', 'want', 'to ', 'do', 'is', 'read', 'in', 'this', 'file', 'have', 'the', 'program', 'skip', ' over', 'ever', 'instance', 'of', 'the', 'words', '"the",', '"and",', '"or",', '" but".', 'What', 'would', 'be', 'the', 'general', 'strategy', 'for', 'attacking', 'a', 'problem', 'like', 'this?'] But this _one_ way to get there. Faster solutions could be based on a regex: import re skip = ('and','or','but') all = re.compile('(\w+)') print [w for w in all.findall(open('some.txt').read()) if w not in skip] this gives this result (you loose some punctuation etc): ['Let', 's', 'say', 'that', 'I', 'have', 'an', 'article', 'What', 'I', 'want', ' to', 'do', 'is', 'read', 'in', 'this', 'file', 'have', 'the', 'program', 'skip', 'over', 'ever', 'instance', 'of', 'the', 'words', 'the', 'What', 'would', 'be', 'the', 'general', 'strategy', 'for', 'attacking', 'a', 'problem', 'like', 'this '] But there are some many ways to do it ... -------------- next part -------------- A non-text attachment was scrubbed... Name: stefan_sonnenberg.vcf Type: text/x-vcard Size: 223 bytes Desc: not available URL: From python at mrabarnett.plus.com Thu Nov 11 16:23:08 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 11 Nov 2010 21:23:08 +0000 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: <4CDC5EBC.4030706@mrabarnett.plus.com> On 11/11/2010 20:26, Lawrence D'Oliveiro wrote: > In message, Tim Chase > wrote: > >> Amusingly, as others have noted, you replied with an unobfuscated >> email address. > > This > > would seem to be an independent, true record of what members of python-list > would see of my posting, would it not? You would agree that it shows my e- > mail address as obfuscated, would you not? So if you claim to be seeing an > unobfuscated e-mail address for my posting on python-list, you would be > lying, would you not? Lawrence, I receive posts from this list via email and I can tell you that the post referred to above arrived in my inbox with an unobfuscated email address, so what both you and I see in that webpage is not necessarily the same as what arrives by email. Looking back I can tell you that your post (give or take an hour for DST) at 3 Nov 2010 07:52 "Re: functions, list, default parameters" was the last to arrive with an obfuscated address; the next one at 3 Nov 2010 22:40 "Re: Allowing comments after the line continuation backslash" and _all_ the subsequent ones arrived with an _unobfuscated_ email address. From emile at fenx.com Thu Nov 11 16:24:15 2010 From: emile at fenx.com (Emile van Sebille) Date: Thu, 11 Nov 2010 13:24:15 -0800 Subject: Copy Protected PDFs and PIL In-Reply-To: References: Message-ID: On 11/11/2010 12:28 PM Brett Bowman said... > I'm trying to parse some basic details and a thumbnail from ~12,000 PDFs for > my company, but a few hundred of them are copy protected. To make matters > worse, I can't seem to trap the error it causes: whenever it happens PIL > throws a "FATAL PDF disallows copying" message and dies. An automated way > to snap a picture of the PDFs would be ideal, but I'd settle for a way to > skip over them without crashing my program. > > Any tips? try / except around the relevant code? Emile From bnbowman at gmail.com Thu Nov 11 16:26:03 2010 From: bnbowman at gmail.com (Brett Bowman) Date: Thu, 11 Nov 2010 13:26:03 -0800 Subject: Copy Protected PDFs and PIL In-Reply-To: References: Message-ID: Windows currently, though I also have a Linux box running Ubuntu if need be. On Thu, Nov 11, 2010 at 12:28 PM, Brett Bowman wrote: > I'm trying to parse some basic details and a thumbnail from ~12,000 PDFs > for my company, but a few hundred of them are copy protected. To make > matters worse, I can't seem to trap the error it causes: whenever it happens > PIL throws a "FATAL PDF disallows copying" message and dies. An automated > way to snap a picture of the PDFs would be ideal, but I'd settle for a way > to skip over them without crashing my program. > > Any tips? > > Brett Bowman > Bioinformatics Associate > Cibus LLC > -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Thu Nov 11 16:28:48 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 11 Nov 2010 15:28:48 -0600 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: <4CDC6010.80707@tim.thechases.com> On 11/11/10 14:26, Lawrence D'Oliveiro wrote: > In message, Tim Chase > wrote: > >> Amusingly, as others have noted, you replied with an unobfuscated >> email address. > > This > > would seem to be an independent, true record of what members of python-list > would see of my posting, would it not? You would agree that it shows my e- > mail address as obfuscated, would you not? So if you claim to be seeing an > unobfuscated e-mail address for my posting on python-list, you would be > lying, would you not? You're welcome to point to something on the web that doesn't show all the raw headers as a reason to accuse me of lying. However if you want the raw headers as they show up here (via Gmane's NNTP) see below or go visit Gmane with your NNTP client of choice or see on their web interface[1] that it has .nz as your TLD. Said leakage comes from you. Or perhaps Gmane lies as much as I do... ;-) -tkc [1] http://article.gmane.org/gmane.comp.python.general/678520/ Path: news.gmane.org!not-for-mail From: Lawrence D'Oliveiro Newsgroups: gmane.comp.python.general Subject: Re: How to test if a module exists? Date: Fri, 12 Nov 2010 09:26:51 +1300 Organization: Geek Central Lines: 13 Approved: news at gmane.org Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1289508625 22893 80.91.229.12 (11 Nov 2010 20:50:25 GMT) X-Complaints-To: usenet at dough.gmane.org NNTP-Posting-Date: Thu, 11 Nov 2010 20:50:25 +0000 (UTC) To: python-list at python.org Original-X-From: python-list-bounces+python-python-list=m.gmane.org at python.org Thu Nov 11 21:50:21 2010 Return-path: Envelope-to: python-python-list at m.gmane.org Original-Received: from mail.python.org ([82.94.164.166]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PGe67-0004p0-27 for python-python-list at m.gmane.org; Thu, 11 Nov 2010 21:50:19 +0100 Original-Received: from albatross.python.org (localhost [127.0.0.1]) by mail.python.org (Postfix) with ESMTP id D1573EE991 for ; Thu, 11 Nov 2010 21:50:18 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=python.org; s=200901; t=1289508618; bh=Qq3BZxpd6aw/1Vw+oG675AEz9lJPB9M4gIz6CavHT5U=; h=From:Subject:Date:Message-ID:References:Mime-Version:To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: Content-Type:Content-Transfer-Encoding:Sender; b=sDyLoQWAR3KEW7xHY7kclTb+Tz+2/gsxIIvmxInTSLNkDVQPqkK1nKZIm3tmUxEL8 Y5lcejoI2VRwfUD1CBNHKOpr/yN1bPmohX5pRZh4H0I+WqcLWmFyCIMFG9QfD0NJku gh0+wcaMH6VkD5qHehXP2nf5Lrg0yJ+BbkJ0DDok= Original-Path: news.xs4all.nl!newsspool.news.xs4all.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!feeder.news-service.com!news.glorb.com!newsfeeds.ihug.co.nz!lust.ihug.co.nz!ihug.co.nz!not-for-mail Original-Newsgroups: comp.lang.python Original-Followup-To: comp.lang.python Original-Lines: 13 Original-NNTP-Posting-Host: 118-93-131-51.dsl.dyn.ihug.co.nz Original-X-Trace: lust.ihug.co.nz 1289507211 26631 118.93.131.51 (11 Nov 2010 20:26:51 GMT) Original-X-Complaints-To: abuse at ihug.co.nz Original-NNTP-Posting-Date: Thu, 11 Nov 2010 20:26:51 +0000 (UTC) User-Agent: KNode/4.4.6 Original-Xref: news.xs4all.nl comp.lang.python:648868 X-BeenThere: python-list at python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: python-list-bounces+python-python-list=m.gmane.org at python.org Errors-To: python-list-bounces+python-python-list=m.gmane.org at python.org Xref: news.gmane.org gmane.comp.python.general:678700 Archived-At: In message , Tim Chase wrote: > Amusingly, as others have noted, you replied with an unobfuscated > email address. This would seem to be an independent, true record of what members of python-list would see of my posting, would it not? You would agree that it shows my e- mail address as obfuscated, would you not? So if you claim to be seeing an unobfuscated e-mail address for my posting on python-list, you would be lying, would you not? From ethan at stoneleaf.us Thu Nov 11 16:42:13 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 11 Nov 2010 13:42:13 -0800 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: <4CDC6335.9090301@stoneleaf.us> Lawrence D'Oliveiro wrote: > In message , Tim Chase > wrote: > >> Amusingly, as others have noted, you replied with an unobfuscated >> email address. > > This > > would seem to be an independent, true record of what members of python-list > would see of my posting, would it not? No, I would not -- it is not what I use, and it is not what I see. ~Ethan~ From ldo at geek-central.gen.new_zealand Thu Nov 11 16:53:39 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 12 Nov 2010 10:53:39 +1300 Subject: How to test if a module exists? References: Message-ID: In message , MRAB wrote: > ... the next one at 3 Nov 2010 22:40 "Re: Allowing comments after the line > continuation backslash" and _all_ the subsequent ones arrived with an > _unobfuscated_ email address. You mean from this one on ? From crebert at ucsd.edu Thu Nov 11 16:54:58 2010 From: crebert at ucsd.edu (Chris Rebert) Date: Thu, 11 Nov 2010 13:54:58 -0800 Subject: returning results from function In-Reply-To: References: Message-ID: On Thu, Nov 11, 2010 at 1:16 PM, Neil Berg wrote: > Hi Python community, > > In a main script, I pass the year (yr), month (mo), day (dy) and hour(hr) into the utc_to_local function (pasted below) which converts that date and time into local standard time. ?I am passing several dates and times into this function and would like to work with the "returned" loc_y/m/d/h values, > but no output is visibly seen when I run the main script. Does the main script print() the returned values? Python doesn't output stuff unless you explicitly ask it to (except when you're using the REPL). Show us your main script, or at least the part of it where utc_to_local() is called. >?I want the "return" command to just return the values to me in the main script so I can work with them! It already does that. The problem must lie with the caller (i.e. the main script). Cheers, Chris -- http://blog.rebertia.com From davea at ieee.org Thu Nov 11 17:01:27 2010 From: davea at ieee.org (Dave Angel) Date: Thu, 11 Nov 2010 17:01:27 -0500 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: <4CDC67B7.2030103@ieee.org> On 2:59 PM, Lawrence D'Oliveiro wrote: > In message, Tim Chase > wrote: > >> Amusingly, as others have noted, you replied with an unobfuscated >> email address. > This > > would seem to be an independent, true record of what members of python-list > would see of my posting, would it not? You would agree that it shows my e- > mail address as obfuscated, would you not? So if you claim to be seeing an > unobfuscated e-mail address for my posting on python-list, you would be > lying, would you not? > On the link you specify, your email address has the word 'at' in it. I subscribe to this list by email, in digest form. And your email address here has a real "@" in it. Don't be so free to call people liars when they're reporting what they actually see. If you get this message directly, you can look at the TO: list. I just did a reply-all without editing anything. DaveA From stefan.sonnenberg at pythonmeister.com Thu Nov 11 17:10:28 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Thu, 11 Nov 2010 23:10:28 +0100 Subject: returning results from function In-Reply-To: References: Message-ID: <4CDC69D4.8040105@pythonmeister.com> Am 11.11.2010 22:16, schrieb Neil Berg: > Hi Python community, > > In a main script, I pass the year (yr), month (mo), day (dy) and hour(hr) into the utc_to_local function (pasted below) which converts that date and time into local standard time. I am passing several dates and times into this function and would like to work with the "returned" loc_y/m/d/h values, but no output is visibly seen when I run the main script. I want the "return" command to just return the values to me in the main script so I can work with them! Any help is appreciated. > > Thanks in advance, > Neil > > _________ > Mac OS X 10.6.4 > Python 2.6 > _________ > > from datetime import datetime > from pytz import timezone > import pytz > > def utc_to_local(yr,mo,dy,hr): > fmt = '%Y-%m-%d %H %Z' > utc = pytz.utc > local = pytz.timezone("US/Pacific") > utc_dt = datetime(yr,mo,dy,hr, tzinfo=utc) > loc_dt = utc_dt.astimezone(local) # local date YY-MM-DD HR TZ > #print utc_dt.strftime(fmt), " = ", loc_dt.strftime(fmt) > > loc_y = loc_dt.year # local year > loc_m = loc_dt.month # local month > loc_d = loc_dt.day # local day > loc_h = loc_dt.hour # local hour > > return loc_y, loc_m, loc_d, loc_h > Could you please be so nice and share the relevant parts of your main script with us ? -------------- next part -------------- A non-text attachment was scrubbed... Name: stefan_sonnenberg.vcf Type: text/x-vcard Size: 223 bytes Desc: not available URL: From bmjames at gmail.com Thu Nov 11 17:46:06 2010 From: bmjames at gmail.com (Ben James) Date: Thu, 11 Nov 2010 22:46:06 +0000 Subject: Am I The Only One Who Keeps Reading =?UTF-8?B?4oCcTnVtcHnigJ0=?= =?UTF-8?B?IGFzIOKAnE51bXB0eeKAnT8=?= References: Message-ID: On 10/11/2010 06:53, Lawrence D'Oliveiro wrote: > Sorry... I read it as "numpty" all the time! From python at mrabarnett.plus.com Thu Nov 11 17:54:17 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 11 Nov 2010 22:54:17 +0000 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: <4CDC7419.3010707@mrabarnett.plus.com> On 11/11/2010 21:53, Lawrence D'Oliveiro wrote: > In message, MRAB wrote: > >> ... the next one at 3 Nov 2010 22:40 "Re: Allowing comments after the line >> continuation backslash" and _all_ the subsequent ones arrived with an >> _unobfuscated_ email address. > > You mean from this one on > ? Yes. From ethan at stoneleaf.us Thu Nov 11 17:55:15 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 11 Nov 2010 14:55:15 -0800 Subject: How to test if a module exists? In-Reply-To: <4CDC67B7.2030103@ieee.org> References: <4CDC67B7.2030103@ieee.org> Message-ID: <4CDC7453.5010907@stoneleaf.us> Dave Angel wrote: > On 2:59 PM, Lawrence D'Oliveiro wrote: >> In message, Tim Chase >> wrote: >> >>> Amusingly, as others have noted, you replied with an unobfuscated >>> email address. >> This >> >> would seem to be an independent, true record of what members of >> python-list >> would see of my posting, would it not? You would agree that it shows >> my e- >> mail address as obfuscated, would you not? So if you claim to be >> seeing an >> unobfuscated e-mail address for my posting on python-list, you would be >> lying, would you not? >> > > On the link you specify, your email address has the word 'at' in it. > > I subscribe to this list by email, in digest form. And your email > address here has a real "@" in it. Don't be so free to call people > liars when they're reporting what they actually see. > > If you get this message directly, you can look at the TO: list. I just > did a reply-all without editing anything. > > DaveA > Interesting -- Lawrence's email address is showing the .new_zealand in your To headers, and that's what came up just now when I replied to all; but when I reply to something directly from Lawrence, it has the .nz instead. ~Ethan~ -- For those interested, I'm using Thunderbird on Windows boxen. From mdw at distorted.org.uk Thu Nov 11 17:55:26 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 11 Nov 2010 22:55:26 +0000 Subject: How to test if a module exists? References: Message-ID: <87mxpfjwrl.fsf.mdw@metalzone.distorted.org.uk> Lawrence D'Oliveiro writes: > In message , MRAB wrote: > > > ... the next one at 3 Nov 2010 22:40 "Re: Allowing comments after the line > > continuation backslash" and _all_ the subsequent ones arrived with an > > _unobfuscated_ email address. > > You mean from this one on > ? No. More like http://article.gmane.org/gmane.comp.python.general/677953 We'll accept your apologies now. -- [mdw] From nberg at atmos.ucla.edu Thu Nov 11 17:57:27 2010 From: nberg at atmos.ucla.edu (Neil Berg) Date: Thu, 11 Nov 2010 14:57:27 -0800 Subject: returning results from function In-Reply-To: References: Message-ID: <18BC12D7-80A2-46AD-8DE2-9D4B7C5F7A2E@atmos.ucla.edu> My main script reads in monthly netCDF files that record variables each hour for that month. The length of all time variables is equal to the number of hours per month. Using January 1995, for example, time_y is a 1d array of the integer 1995 repeated 744 times, time_m is a 1d array of the integer 1 repeated 744 times, time_d is a 1d array that ranges from 1 to 31, and time_h is a 1d array that cycles from 0 23. The part that calls upon utc_to_local() is: time_y = ncfile.variables['time_y'][:] # (time,int) [yrs] time_m = ncfile.variables['time_m'][:] # (time,int) [mnths] time_d = ncfile.variables['time_d'][:] # (time,int) [days] time_h = ncfile.variables['time_h'][:] # (time,float) [hrs] ntim =len(time_h) for tim_idx in range(0,ntim): local_date = utc_to_local(time_y[tim_idx],time_m[tim_idx],time_d[tim_idx],int(time_h[tim_idx])) ***Here is where I'd like to see the returned values so I can create new arrays that store them ***** Hope this makes sense. Thanks, Neil On Nov 11, 2010, at 1:54 PM, Chris Rebert wrote: > On Thu, Nov 11, 2010 at 1:16 PM, Neil Berg wrote: >> Hi Python community, >> >> In a main script, I pass the year (yr), month (mo), day (dy) and hour(hr) into the utc_to_local function (pasted below) which converts that date and time into local standard time. I am passing several dates and times into this function and would like to work with the "returned" loc_y/m/d/h values, >> but no output is visibly seen when I run the main script. > > Does the main script print() the returned values? Python doesn't > output stuff unless you explicitly ask it to (except when you're using > the REPL). Show us your main script, or at least the part of it where > utc_to_local() is called. > >> I want the "return" command to just return the values to me in the main script so I can work with them! > > It already does that. The problem must lie with the caller (i.e. the > main script). > > Cheers, > Chris > -- > http://blog.rebertia.com From emile at fenx.com Thu Nov 11 18:00:01 2010 From: emile at fenx.com (Emile van Sebille) Date: Thu, 11 Nov 2010 15:00:01 -0800 Subject: How to test if a module exists? In-Reply-To: <4CDC67B7.2030103@ieee.org> References: <4CDC67B7.2030103@ieee.org> Message-ID: On 11/11/2010 2:01 PM Dave Angel said... > I subscribe to this list by email, in digest form. And your email > address here has a real "@" in it. Don't be so free to call people liars > when they're reporting what they actually see. > > If you get this message directly, you can look at the TO: list. I just > did a reply-all without editing anything. Which I see on my end now as copying to: ldo at geek-central.gen.new_zealand so it didn't go directly as it happens... Emile From steve at holdenweb.com Thu Nov 11 18:00:18 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 11 Nov 2010 15:00:18 -0800 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: On 11/11/2010 1:53 PM, Lawrence D'Oliveiro wrote: > In message , MRAB wrote: > >> ... the next one at 3 Nov 2010 22:40 "Re: Allowing comments after the line >> continuation backslash" and _all_ the subsequent ones arrived with an >> _unobfuscated_ email address. > > You mean from this one on > ? Here's a screen capture from Thunderbird. Anything else you need? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ -------------- next part -------------- A non-text attachment was scrubbed... Name: doliviero.png Type: image/png Size: 7027 bytes Desc: not available URL: From crebert at ucsd.edu Thu Nov 11 18:29:40 2010 From: crebert at ucsd.edu (Chris Rebert) Date: Thu, 11 Nov 2010 15:29:40 -0800 Subject: returning results from function In-Reply-To: <18BC12D7-80A2-46AD-8DE2-9D4B7C5F7A2E@atmos.ucla.edu> References: <18BC12D7-80A2-46AD-8DE2-9D4B7C5F7A2E@atmos.ucla.edu> Message-ID: > On Nov 11, 2010, at 1:54 PM, Chris Rebert wrote: >> On Thu, Nov 11, 2010 at 1:16 PM, Neil Berg wrote: >>> Hi Python community, >>> >>> In a main script, I pass the year (yr), month (mo), day (dy) and hour(hr) into the utc_to_local function (pasted below) which converts that date and time into local standard time. ?I am passing several dates and times into this function and would like to work with the "returned" loc_y/m/d/h values, >>> but no output is visibly seen when I run the main script. >> >> Does the main script print() the returned values? Python doesn't >> output stuff unless you explicitly ask it to (except when you're using >> the REPL). Show us your main script, or at least the part of it where >> utc_to_local() is called. >> >>> ?I want the "return" command to just return the values to me in the main script so I can work with them! >> >> It already does that. The problem must lie with the caller (i.e. the >> main script). On Thu, Nov 11, 2010 at 2:57 PM, Neil Berg wrote: > My main script reads in monthly netCDF files that record variables each hour for that month. ?The length of all time variables is equal to the number of hours per month. ?Using January 1995, for example, time_y is a 1d array of the integer 1995 repeated 744 times, time_m is a 1d array of the integer 1 repeated 744 times, time_d is a 1d array that ranges from 1 to 31, and time_h is a 1d array that cycles from 0 23. ?The part that calls upon utc_to_local() is: > > time_y = ncfile.variables['time_y'][:] # (time,int) [yrs] > time_m = ncfile.variables['time_m'][:] # (time,int) [mnths] > time_d = ncfile.variables['time_d'][:] # (time,int) [days] > time_h = ncfile.variables['time_h'][:] ? ?# (time,float) [hrs] > ntim =len(time_h) > for tim_idx in range(0,ntim): > ? ? ? ?local_date = utc_to_local(time_y[tim_idx],time_m[tim_idx],time_d[tim_idx],int(time_h[tim_idx])) > ? ? ? ?***Here is where I'd like to see the returned values so I can create new arrays that store them ***** Add: print(local_date) Or if you want to be fancy: print("%.4d-%.2d-%.2d %.2d" % local_date) Cheers, Chris -- http://blog.rebertia.com From robert.kern at gmail.com Thu Nov 11 18:35:59 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 11 Nov 2010 17:35:59 -0600 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: On 2010-11-11 14:26 , Lawrence D'Oliveiro wrote: > In message, Tim Chase > wrote: > >> Amusingly, as others have noted, you replied with an unobfuscated >> email address. > > This > > would seem to be an independent, true record of what members of python-list > would see of my posting, would it not? You would agree that it shows my e- > mail address as obfuscated, would you not? So if you claim to be seeing an > unobfuscated e-mail address for my posting on python-list, you would be > lying, would you not? This is what I see, reading from GMane using Thunderbird: http://imgur.com/Dg1Xr Face it: your post gets passed through a variety of systems outside of your control or the other readers here. Somewhere along the line, your email address is getting unobfuscated. The people replying are simply replying with what their email/NNTP clients show them. -- 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 usenet-nospam at seebs.net Thu Nov 11 18:40:00 2010 From: usenet-nospam at seebs.net (Seebs) Date: 11 Nov 2010 23:40:00 GMT Subject: How to test if a module exists? References: Message-ID: On 2010-11-11, Lawrence D'Oliveiro wrote: > In message , Tim Chase > wrote: >> Amusingly, as others have noted, you replied with an unobfuscated >> email address. > This > > would seem to be an independent, true record of what members of python-list > would see of my posting, would it not? It might or might not be. Not all of us are "members of python-list". I'm reading this on Usenet. (Where the only distinction I see is that the country name is spelled out.) > You would agree that it shows my e- > mail address as obfuscated, would you not? I don't know whether that counts as obfuscated. > So if you claim to be seeing an > unobfuscated e-mail address for my posting on python-list, you would be > lying, would you not? I have found that, in general, the chances that someone is lying are very low. The chances are much higher that they are mistaken, or that I have misunderstood their claim. Or for that matter, that there's Something Strange Going On. Say, someone's got a Usenet provider that Helpfully Fixes things, or someone set up an aliasing thing in a Very Clever newsreader some time back so they could reply to your posts and didn't notice it was then performing the same aliasing when displaying the group, or... Usually, with people who aren't obvious frothing kooks, I tend to view "lying" as being an extremely unusual explanation. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Thu Nov 11 18:41:44 2010 From: usenet-nospam at seebs.net (Seebs) Date: 11 Nov 2010 23:41:44 GMT Subject: How to test if a module exists? References: Message-ID: On 2010-11-11, Lawrence D'Oliveiro wrote: > In message , MRAB wrote: >> ... the next one at 3 Nov 2010 22:40 "Re: Allowing comments after the line >> continuation backslash" and _all_ the subsequent ones arrived with an >> _unobfuscated_ email address. > You mean from this one on >? Just as a data point: I'm using comp.lang.python via NNTP from Megabitz, reader is SLRN, and I still see ".gen.new_zealand". Sounds to me like some source may be "helpfully fixing" the address as it forwards things. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From robert.kern at gmail.com Thu Nov 11 18:42:35 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 11 Nov 2010 17:42:35 -0600 Subject: Copy Protected PDFs and PIL In-Reply-To: References: Message-ID: On 2010-11-11 14:28 , Brett Bowman wrote: > I'm trying to parse some basic details and a thumbnail from ~12,000 PDFs for my > company, but a few hundred of them are copy protected. To make matters worse, I > can't seem to trap the error it causes: whenever it happens PIL throws a "FATAL > PDF disallows copying" message and dies. An automated way to snap a picture of > the PDFs would be ideal, but I'd settle for a way to skip over them without > crashing my program. > > Any tips? I don't think PIL reads PDF files at all. Are you sure that the error comes from PIL and not some other piece of software? I would be very surprised if PIL simply crashed with such an error message. That is not a situation where a well-behaved Python library like PIL would abort without a catchable traceback. -- 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 usenet-nospam at seebs.net Thu Nov 11 18:43:49 2010 From: usenet-nospam at seebs.net (Seebs) Date: 11 Nov 2010 23:43:49 GMT Subject: How to test if a module exists? References: Message-ID: On 2010-11-11, Tim Chase wrote: >=============================== > From: Lawrence D'Oliveiro > Newsgroups: gmane.comp.python.general Oh, interesting. > Gee...your unobfuscated email addresses FROM YOU. No, from gmane. Out here in comp.lang.python (no gmane), it's obfuscated. So it sounds like there is an entity other than Lawrence deobfuscating the addresses, but it's not a specific poster here. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From aioe.org at technicalbloke.com Thu Nov 11 18:52:30 2010 From: aioe.org at technicalbloke.com (r0g) Date: Thu, 11 Nov 2010 23:52:30 +0000 Subject: How to test if a module exists? References: Message-ID: On 11/11/10 21:53, Lawrence D'Oliveiro wrote: > In message, MRAB wrote: > >> ... the next one at 3 Nov 2010 22:40 "Re: Allowing comments after the line >> continuation backslash" and _all_ the subsequent ones arrived with an >> _unobfuscated_ email address. > > You mean from this one on > ? Lawrence if you keep this up it won't be long til somebody writes a script to spam your precious bloody email address across every damn message board on the internet. All you are doing now is drawing further attention to it and causing it to be reposted over and over again, it's not a secret, you're being obnoxious and you deserve every shred of spam you get as a result. Roger From ldo at geek-central.gen.new_zealand Thu Nov 11 19:20:47 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 12 Nov 2010 13:20:47 +1300 Subject: How to test if a module exists? References: Message-ID: I have just received an admission from Barry Warsaw that a hack was done on python-list specifically to deal with bounces caused by a list member trying to reply to my obfuscated e-mail address. I have asked him to undo that hack. If he likes, he can filter out that (obfuscated) address of mine completely, I don?t mind, since I can always read replies to my postings here on USENET. The important point, as far as I?m concerned, is that I do NOT want to see my unobfuscated address appear on USENET. As for those who persisted in posting my address after being warned of this, I?m still deciding what to do. From simon at mullis.co.uk Thu Nov 11 19:24:56 2010 From: simon at mullis.co.uk (Simon Mullis) Date: Fri, 12 Nov 2010 01:24:56 +0100 Subject: parse date/time from a log entry with only strftime (and no regexen) In-Reply-To: <23d7e1bb0902050250k60cceb46jf7c1149f0b1e024@mail.gmail.com> References: <23d7e1bb0902030552j6a12dcbcy428c9ede8419fb7b@mail.gmail.com> <7e3602b0-57c0-4d9e-8c8d-fb0a5b00108d@d36g2000prf.googlegroups.com> <23d7e1bb0902050250k60cceb46jf7c1149f0b1e024@mail.gmail.com> Message-ID: This was a long time ago.... But just in case anyone googling ever has the same question, this is what I did (last year). The user just needs to supply a strftime formatted string, such as "%A, %e %b %h:%M" and this Class figures out the regex to use on the log entries... class RegexBuilder(object): """This class is used to create the regex from the strftime string. So, we pass it a strftime string and it returns a regex with capture groups.""" lookup_table = { '%a' : r"(\w{3})", # locale's abbrev day name '%A' : r"(\w{6,8})", # locale's full day name '%b' : r"(\w{3})", # abbrev month name '%B' : r"(\w{4,9})", # full month name '%d' : r"(3[0-1]|[1-2]\d|0[1-9]|[1-9]|[1-9])", # day of month '%e' : r"([1-9]|[1-3][0-9])", # day of month, no leader '%H' : r"(2[0-3]|[0-1]\d|\d)", # Hour (24h clock) '%I' : r"(1[0-2]|0[1-9]|[1-9])", # Hour (12h clock) '%j' : r"(36[0-6]|3[0-5]\d|[1-2]\d\d|0[1-9]\d|00[1-9]\ |[1-9]\d|0[1-9]|[1-9])", # Day of year '%m' : r"(1[0-2]|0[1-9]|[1-9])", # Month as decimal '%M' : r"([0-5]\d|\d)", # Minute '%S' : r"(6[0-1]|[0-5]\d|\d)", # Second '%U' : r"(5[0-3]|[0-4]\d|\d)", # Week of year (Sun = 0) '%w' : r"([0-6])", # Weekday (Sun = 0) '%W' : r"(5[0-3]|[0-5]\d|\d)", # Week of year (Mon = 0) '%y' : r"(\d{2})", # Year (no century) '%Y' : r"(\d{4})", # Year with 4 digits '%p' : r"(AM|PM)", '%P' : r"(am|pm)", '%f' : r"(\d+)", # TODO: microseconds. Only in Py 2.6+ } # Format of the keys in the table above strftime_re = r'%\w' def __init__(self, date_format): r = re.compile(RegexBuilder.strftime_re) self.created_re = r.sub(self._lookup, date_format) def _lookup(self, match): """ Regex lookup...""" return RegexBuilder.lookup_table[match.group()] > 2009/2/3 andrew cooke >> >> > > ValueError: unconverted data remains: ?this is the remainder of the >> > > log >> > > line >> > > that I do not care about >> >> you could catch the ValueError and split at the ':' in the .args >> attribute to find the extra data. ?you could then find the extra data >> in the original string, use the index to remove it, and re-parse the >> time. >> >> ugly, but should work. >> andrew >> -- >> http://mail.python.org/mailman/listinfo/python-list > > > > -- > Simon Mullis > _________________ > simon at mullis.co.uk > From ethan at stoneleaf.us Thu Nov 11 19:51:38 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 11 Nov 2010 16:51:38 -0800 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: <4CDC8F9A.9030603@stoneleaf.us> Lawrence D'Oliveiro wrote: > The important point, as far as > I?m concerned, is that I do NOT want to see my unobfuscated address appear > on USENET. You sure did a lousy job of obfuscating for someone so concerned about it. > As for those who persisted in posting my address after being warned of this, > I?m still deciding what to do. You can be such an ass sometimes. ~Ethan~ From invalid at invalid.invalid Thu Nov 11 19:55:22 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 12 Nov 2010 00:55:22 +0000 (UTC) Subject: How to test if a module exists? References: Message-ID: On 2010-11-12, Lawrence D'Oliveiro wrote: > As for those who persisted in posting my address after being warned of this, > I'm still deciding what to do. Plonk. -- Grant From steve at holdenweb.com Thu Nov 11 20:19:36 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 11 Nov 2010 17:19:36 -0800 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: <4CDC9628.4000500@holdenweb.com> On 11/11/2010 4:55 PM, Grant Edwards wrote: > On 2010-11-12, Lawrence D'Oliveiro wrote: > >> As for those who persisted in posting my address after being warned of this, >> I'm still deciding what to do. > > Plonk. > Don't you mean >> On 2010-11-12, Lawrence D'Oliveiro wrote: ? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From roy at panix.com Thu Nov 11 20:25:19 2010 From: roy at panix.com (Roy Smith) Date: Thu, 11 Nov 2010 20:25:19 -0500 Subject: is there an Python equivalent for the PHP super globals like $_POST, $_COOKIE ? References: Message-ID: In article , r0g wrote: > On 11/11/10 14:22, Stef Mientki wrote: >> I can't find how th get to PHP's equivalent of $_Post and $_Cookie ? PHP is mostly a one-trick pony. It's meant to be run as a web scripting language with Apache (or, I suppose, something else) on the front end. As a result, a lot of web-specific things like $_Post and $_Cookie are built into the language. Python is intended to be more general purpose, so things which are built in to other languages usually can be found in library modules. In this case, you probably want to look at the SimpleHTTPServer module. You may also want to look at any of several web application frameworks such as Django, Pylons, etc. I'm guessing these are overkill for the sorts of things you want to do, but they're worth at least browsing to get some idea of what's out there. For what it's worth, I've pretty much avoided PHP for all these years. My latest gig, however, has had me doing PHP for the past 3 months or so. The more I learn about PHP, the more I want to go running in the other direction. From nberg at atmos.ucla.edu Thu Nov 11 20:26:34 2010 From: nberg at atmos.ucla.edu (Neil Berg) Date: Thu, 11 Nov 2010 17:26:34 -0800 Subject: neglecting daylight savings Message-ID: <29FB1B84-3F33-48F6-AF25-DAF7EE24433D@atmos.ucla.edu> Hi Python community, I am trying to convert UTC to PST and want to neglect daylight savings even for the days that are in PDT, not PST. I simply want every UTC date to be pushed back by 8 hours and not worry about the days when the difference is really -7 due to daylight savings. I have written a function called utc_to_local (pasted below) that reads in the UTC year, month, day, and hour from a main code and returns that value in local standard time. The problem is that I can't figure out how to "turn off" the automatic daylight savings switch that appears be built in to somewhere. Here is some sample output showing the daylight savings switch on April 2, 1995 at 2am local time, which I would like to override. 1995-04-02 08 UTC = 1995-04-02 00 PST 1995-04-02 09 UTC = 1995-04-02 01 PST 1995-04-02 10 UTC = 1995-04-02 03 PDT 1995-04-02 11 UTC = 1995-04-02 04 PDT I want the third line of the output to read "1995-04-02 02" PST, the fourth to read "1995-04-02 03", etc. ___________________________ from datetime import datetime from pytz import timezone import pytz def utc_to_local(yr,mo,dy,hr): fmt = '%Y-%m-%d %H %Z' utc = pytz.utc pacific = pytz.timezone("America/Los_Angeles") utc_dt = datetime(yr,mo,dy,hr, tzinfo=utc) loc_dt = utc_dt.astimezone(pacific) # local date YY-MM-DD HR TZ print utc_dt.strftime(fmt), "=", loc_dt.strftime(fmt) loc_y = loc_dt.year # local year loc_m = loc_dt.month # local month loc_d = loc_dt.day # local day loc_h = loc_dt.hour # local hour return loc_y, loc_m, loc_d, loc_h _____________________________ Python 2.6 Mac OS X 10.6.4 _____________________________ Any help is much appreciated. Thank you in advance, Neil Berg From python.list at tim.thechases.com Thu Nov 11 20:32:19 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 11 Nov 2010 19:32:19 -0600 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: <4CDC9923.2070303@tim.thechases.com> On 11/11/10 18:20, Lawrence D'Oliveiro wrote: > As for those who persisted in posting my address after being > warned of this, I?m still deciding what to do. I've got a hint: 1) You can pursue it with various ISPs. If you choose the latter, I can fairly confidently say that any provider, upon reviewing the emails in question & seeing that your own posts hit the web unobfuscated, will laugh at you and consider your complaints a blathering annoyance spawned by your ineptitude. Mine did when you griped to them. They'll do it again. 2) you can take the advice of just about everybody in this thread and surrender the issue, finding better ways to deal with it than publicly displaying your nincompoopery. Several constructive suggestions have been given, and I'll add a few: find a better spam filter (I use Thunderbird's); use list-specific mailing addresses; use a truly obfuscated email such as "nobody at nowhere.invalid"; read via a spam-filtering source (gmane did a pretty good job until fairly recently); use a white-list for senders you actually care to read (I suspect I won't make the cut...no skin off my back). -tkc From emile at fenx.com Thu Nov 11 20:34:39 2010 From: emile at fenx.com (Emile van Sebille) Date: Thu, 11 Nov 2010 17:34:39 -0800 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: On 11/11/2010 4:20 PM Lawrence D'Oliveiro said... > I have just received an admission from Barry Warsaw that a hack was done on > python-list specifically to deal with bounces caused by a list member trying > to reply to my obfuscated e-mail address. > > I have asked him to undo that hack. If he likes, he can filter out that > (obfuscated) address of mine completely, I don?t mind, since I can always > read replies to my postings here on USENET. The important point, as far as > I?m concerned, is that I do NOT want to see my unobfuscated address appear > on USENET. > > As for those who persisted in posting my address after being warned of this, > I?m still deciding what to do. Well, you got you're work cut out for you. Google says... Results 1 - 10 of about 17,300 for ldo at geek-central.gen.***** Emile From ben+python at benfinney.id.au Thu Nov 11 20:35:21 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 12 Nov 2010 12:35:21 +1100 Subject: neglecting daylight savings References: Message-ID: <87k4kjb9ye.fsf@benfinney.id.au> Neil Berg writes: > I am trying to convert UTC to PST and want to neglect daylight savings > even for the days that are in PDT, not PST. Then you don't want ?PST?. That name entails all the rules of the time zone. If that's not what you want, don't ask timezone libraries for it. Similarly for the timezone named ?America/Los_Angeles?; if you ask for that you are explicitly asking for all the time changes that zone entails. If you don't want it, don't ask for it. If you want exactly the same offset all the time, regardless of government DST silliness, ask for it: ?UTC-8?, for example, or whatever the fixed offset from UTC you want. -- \ ?Outside of a dog, a book is man's best friend. Inside of a | `\ dog, it's too dark to read.? ?Groucho Marx | _o__) | Ben Finney From emile at fenx.com Thu Nov 11 20:41:11 2010 From: emile at fenx.com (Emile van Sebille) Date: Thu, 11 Nov 2010 17:41:11 -0800 Subject: neglecting daylight savings In-Reply-To: <29FB1B84-3F33-48F6-AF25-DAF7EE24433D@atmos.ucla.edu> References: <29FB1B84-3F33-48F6-AF25-DAF7EE24433D@atmos.ucla.edu> Message-ID: On 11/11/2010 5:26 PM Neil Berg said... > Hi Python community, > > I am trying to convert UTC to PST and want to neglect daylight savings even for the days that are in PDT, not PST. IIRC, that what Arizona time is. Why not use it instead of attempting to redefine PST? Emile From martin at address-in-sig.invalid Thu Nov 11 21:38:28 2010 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Fri, 12 Nov 2010 02:38:28 +0000 (UTC) Subject: is there an Python equivalent for the PHP super globals like $_POST, $_COOKIE ? References: <4CDBFC41.6080404@gmail.com> Message-ID: On Thu, 11 Nov 2010 13:01:01 -0500, Steve Holden wrote: > Moving from one language to anther is not just a matter of > transliterating the code. Of you try that you will end up with a messy > code base that looks like PHP written in Python. > "The determined Real Programmer can write Fortran programs in any language." - from "Real Programmers don't use Pascal". -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From usenet-nospam at seebs.net Thu Nov 11 22:03:00 2010 From: usenet-nospam at seebs.net (Seebs) Date: 12 Nov 2010 03:03:00 GMT Subject: How to test if a module exists? References: Message-ID: On 2010-11-12, Lawrence D'Oliveiro wrote: > I have just received an admission from Barry Warsaw that a hack was done on > python-list specifically to deal with bounces caused by a list member trying > to reply to my obfuscated e-mail address. That's... Fascinating. But it does mean that the people who were reporting seeing it were, in fact, merely accurately reporting on what they saw. > As for those who persisted in posting my address after being warned of this, > I???m still deciding what to do. I would suggest, very strongly: Nothing. 1. Genie, bottle, out. 2. At least some were quoting your posts to show what they looked like, which is hardly a great abuse. Look... You're dealing with humans. Walk up to a human holding something. Say "smell this, it smells like ass!". Watch them smell it, and then react with shock if it smells bad. Tell them something is too hot to touch safely, and they will touch it to see whether this is true. You told them that your posts were under an obfuscated address, so they quoted the address they saw and said "you mean this one?" None of the people in question were the ones who decided to de-obfuscate the address. None of them had, prior to your announcement, any way to know that de-obfuscation was even occurring, and from all the evidence available to them, the most reasonable inference would have been that you were mistaken about how your posting software was configured. When I offered the speculative notion that some gateway somewhere was deobfuscating this address, I didn't think it was *likely*, merely "more likely than people lying". As a matter of fact, that you jumped directly to the accusation that other people were lying suggests strongly that you the possibility that this was happening *did not even occur to you*. I put it to you that if the possibility is implausible and unusual enough that it did not even *occur* to you to consider it until multiple people had pointed to multiple citations, it is likely that it *also* did not occur to the various other participants. All they could see was posts by you, showing a particular email address, in which you claimed that it was very rude for people other than you to include that email address in posts. I would also suggest a more general observation: Had you approached this with less hostility, I suspect you would have gotten more cooperative responses, rather than indignation. People accused of doing a thing that they very definitely did not do are not going to be inclined to respond in a helpful manner. Had your post said something like: I notice that in your post, my address is no longer obfuscated. I much prefer that my address be obfuscated on Usenet, and when I send it out, it usually is; see for instance this source (link to python-list) showing that my message had an obfuscated address when it reached python-list. ... I think you would have gotten more helpful responses, and we might have more quickly tracked down that it was apparently specific to some of the many mirrors of this traffic. Finally, last but not least: Since the gmane.* archives have that address, and web crawlers are orders of magnitude more common and more active than usenet crawlers, I would consider the question thoroughly academic at this point. The address is out there. Further use of it on Usenet is unlikely to have a statistically measurable impact. Just as a side note: I have an unobfuscated address in both my signature and my From line. This address is live, it delivers to me, and so on. Yes, I get spam to it. Of the last 26,061 spams I've gotten, it's produced a grand total of 239. So, under 1% of my incoming spam. You can measure the interval during which I cared about that, but if you try to represent it as seconds using 32-bit floating point, it'll turn into 0 because it's under FLOAT_EPSILON. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From lists at asd-group.com Thu Nov 11 23:48:29 2010 From: lists at asd-group.com (John Bond) Date: Fri, 12 Nov 2010 04:48:29 +0000 Subject: Extending Thunderbird mail client with Python Message-ID: <4CDCC71D.6050805@asd-group.com> Anyone have any experience with this, ideally using Python 3? I'd like to sync my Thunderbird contacts with various things including my mobile phone. Of course, I want to do it with Python! I've seen some stuff around, eg. an XPI that provides Python bindings to the Mozilla XPCOM APIs (through which I imagine you can access Thunderbird data like its contacts database), but it doesn't seem maintained or ported to Python 3. Cheers, JB From ldo at geek-central.gen.new_zealand Thu Nov 11 23:53:42 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 12 Nov 2010 17:53:42 +1300 Subject: How to test if a module exists? References: Message-ID: I have asked for my messages to be filtered from being distributed to python-list. As far as I?m concerned, the lot of you can bloody piss off. From iamforufriends at gmail.com Thu Nov 11 23:56:19 2010 From: iamforufriends at gmail.com (fun for u all) Date: Thu, 11 Nov 2010 20:56:19 -0800 (PST) Subject: HAI WANT TO MEET FRIENDS FOR REAL FUN, CLICK FRIENDS-4-FUN Message-ID: <6d2d0754-4eb8-4e9b-9ad1-58d1ab1d595f@j29g2000prf.googlegroups.com> HAI WANT TO MEET FRIENDS FOR REAL FUN, CLICK FRIENDS-4-FUN HAI WANT TO MEET FRIENDS FOR REAL FUN, CLICK FRIENDS-4-FUN http://tinyurl.com/friend-4-fun or http://goo.gl/1bour or http://tinyurl.com/friend-4-fun1 From iamforufriends at gmail.com Thu Nov 11 23:56:23 2010 From: iamforufriends at gmail.com (fun for u all) Date: Thu, 11 Nov 2010 20:56:23 -0800 (PST) Subject: HAI WANT TO MEET FRIENDS FOR REAL FUN, CLICK FRIENDS-4-FUN Message-ID: <32fd9d96-3d73-4a33-8a7d-833722745979@i4g2000pro.googlegroups.com> HAI WANT TO MEET FRIENDS FOR REAL FUN, CLICK FRIENDS-4-FUN HAI WANT TO MEET FRIENDS FOR REAL FUN, CLICK FRIENDS-4-FUN http://tinyurl.com/friend-4-fun or http://goo.gl/1bour or http://tinyurl.com/friend-4-fun1 From ldo at geek-central.gen.new_zealand Fri Nov 12 00:58:11 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 12 Nov 2010 18:58:11 +1300 Subject: subprocess.Popen deadlocks References: <2cf9a225-7d1c-4490-8a62-807e79bdd06a@n30g2000vbb.googlegroups.com> Message-ID: In message <2cf9a225-7d1c-4490-8a62-807e79bdd06a at n30g2000vbb.googlegroups.com>, eraserix wrote: > I try to control several process from a python script. Each process is > started from a thread, the threads just wait() for the child to exit > and can then be joined. Main waits for SIGINT. After it received the > signal, it will send a signal to the processes spawned by the threads > and then join() the threads (which should terminate after their > process exits) Threading is always likely to be a source of bugs, whether in your code or the Python library. In this case, your threads don?t even seem to be doing anything useful. Why not skip all the threads and just spawn all the processes in your main loop? Then after getting the SIGINT, send that signal to all your processes, and then do a bunch of os.waitpid calls to clean them all up. From wuwei23 at gmail.com Fri Nov 12 01:43:31 2010 From: wuwei23 at gmail.com (alex23) Date: Thu, 11 Nov 2010 22:43:31 -0800 (PST) Subject: How to test if a module exists? References: Message-ID: On Nov 12, 2:53?pm, Lawrence D'Oliveiro wrote: > I have asked for my messages to be filtered from being distributed to > python-list. As far as I?m concerned, the lot of you can bloody piss off. Oh Lawrence, the feeling is mutual. At least then we'd be spared your constant indignation at Windows. From pythonisland at gmail.com Fri Nov 12 03:38:04 2010 From: pythonisland at gmail.com (ChunLai Zhu) Date: Fri, 12 Nov 2010 16:38:04 +0800 Subject: What is the information I can get? Message-ID: * Hello,I have knew the python mail list neamed python-list at python.org,I want to know what is the information I can get from the mail list?Thank you!* -- *=:-)* *Keep Stupid,Keep Thirsty!* -------------- next part -------------- An HTML attachment was scrubbed... URL: From pavlovevidence at gmail.com Fri Nov 12 03:46:06 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 12 Nov 2010 00:46:06 -0800 (PST) Subject: os.tmpfile() vs. tempfile.TemporaryFile() References: <4cdc36cf$0$1665$742ec2ed@news.sonic.net> Message-ID: On Nov 11, 10:32?am, John Nagle wrote: > ? ?Is there any reason to prefer "tempfile.TemporaryFile()" > over "os.tmpfile()"? ?Both create a nameless temporary file > that will be deleted on close. os.tmpfile calls your OS's tmpfile system call. tempfile.TemporaryFile creates the temporary file itself. So, if you trust your OS more than Python, use os.tempfile. I-only-use-tempfile-module-ly yr's, Carl Banks From stefan_ml at behnel.de Fri Nov 12 03:47:21 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 12 Nov 2010 09:47:21 +0100 Subject: Am I The Only One Who Keeps Reading =?UTF-8?B?4oCcTnVtcHnigJ0=?= =?UTF-8?B?IGFzIOKAnE51bXB0eeKAnT8=?= In-Reply-To: References: <940162c6-b61a-4bb7-9965-6e155716cda8@n30g2000vbb.googlegroups.com> <87hbfoycov.fsf@gmail.com> Message-ID: rantingrick, 11.11.2010 19:07: > On Nov 10, 5:35 pm, Arnaud Delobelle wrote: > >> So pypy is "pie-pee", not "pie-pie" or "pee-pee". With that edifying >> thought, I'm off to bed. > > > :) Good catch! > > Actually i've always thought of pypi as pie-pie and Scipy as cy-pie. > Num-pie does not work for me. Maybe some linguist could chime in and > explain these odd tendencies...? Ah, that's just English. Never mind. http://www.mipmip.org/tidbits/pronunciation.shtml Stefan From pythonisland at gmail.com Fri Nov 12 03:57:41 2010 From: pythonisland at gmail.com (ChunLai Zhu) Date: Fri, 12 Nov 2010 16:57:41 +0800 Subject: How can I read the information? Message-ID: Hi, I'm learning the python program language.I get someinformation from the python-list,but I felt boring to read a text-information ,so how can I read the python-list's FAQs quickly? Thank you! -- *=:-)* *Keep Stupid,Keep Thirsty!* -------------- next part -------------- An HTML attachment was scrubbed... URL: From research at johnohagan.com Fri Nov 12 04:47:26 2010 From: research at johnohagan.com (John O'Hagan) Date: Fri, 12 Nov 2010 09:47:26 +0000 Subject: Sending changed parameters into nested generators Message-ID: <201011120947.27356.research@johnohagan.com> I have a generator function which takes as arguments another generator and a dictionary of other generators like this: def modgen(gen, gendict): for item in gen(): for k, v in gendict: do_something_called_k(item, v.next()) yield item I want to control the output of this generator by sending in new values to the generators in gendict. I have done this using a list in a simple generator like: def loop(lis): while True: for item in lis: yield item and write: lis[:] = [new_value] to see the output of modgen() change. However, I want to be able to use other modgen() instances as values in gendict, each with a gendict of its own, which in turn may contain modgen() instances, and so on recursively. The recursion stops wherever a simple generator like loop() is encountered. To this end I've made nested dictionaries like this example: {'a':[1,2,3], 'b':{'a':[4,5,6]}, 'c':{'a':{'a':[7,8,9], 'b':{'c':[10]}}}} and used a recursive function to convert them to the gendict I'm after like this: def iterized(dic): itdic = {} for k, v in dic.items(): if isinstance(v, dict): itval = iterized(v) itdic[k] = maingen(itval) else: itdic[k] = loop(v) return itdic Then I can write: recdic = {nested:dictionary} gendict = iterized(recdict) mygen = modgen(gen, gendict) The problem is that the gendict looks like this: {'a': , 'b': , 'c': } so I have no direct access from there to the sub-generators. I have tried using a deep update function on the original nested dictionary, but this only works if I change the contents of a list, not if I want to, say, change a node from a list to a dictionary or vice versa, because in that case I'm not operating on the same object the generator is using. If anyone's still reading :) , how can I send new values to arbitrary sub- generators? Thanks, john From girish.cfc at gmail.com Fri Nov 12 06:15:56 2010 From: girish.cfc at gmail.com (Girish) Date: Fri, 12 Nov 2010 03:15:56 -0800 (PST) Subject: COM ERROR Message-ID: Hello All, I have an issue while accessing COM API of an application. I got following error when I tried to run following command: win32com.client.Dispatch() File "C:\Python25\Lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx) File "C:\Python25\Lib\site-packages\win32com\client\dynamic.py", line 98, in _GetGoodDispatchAndUserName return (_GetGoodDispatch(IDispatch, clsctx), userName) File "C:\Python25\Lib\site-packages\win32com\client\dynamic.py", line 78, in _GetGoodDispatch IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch) com_error: (-2147024882, 'Not enough storage is available to complete this operation.', None, None) Your help would be appreciated. Thanks, Girish. From iamforufriends at gmail.com Fri Nov 12 07:22:01 2010 From: iamforufriends at gmail.com (fun for u all) Date: Fri, 12 Nov 2010 04:22:01 -0800 (PST) Subject: HAI WANT TO MEET FRIENDS FOR REAL FUN, CLICK FRIENDS-4-FUN Message-ID: HAI WANT TO MEET FRIENDS FOR REAL FUN, CLICK FRIENDS-4-FUN http://tinyurl.com/friend-4-fun or http://goo.gl/1bour or http://tinyurl.com/friend-4-fun1 From ndbecker2 at gmail.com Fri Nov 12 08:05:52 2010 From: ndbecker2 at gmail.com (Neal Becker) Date: Fri, 12 Nov 2010 08:05:52 -0500 Subject: argparse '--' not working? Message-ID: It is a 'standard' behaviour that a lone '--' terminates options. argparse says: If you have positional arguments that must begin with '-' and don?t look like negative numbers, you can insert the pseudo-argument '--' which tells parse_args that everything after that is a positional argument: But it doesn't seem to work: import argparse parser = argparse.ArgumentParser() parser.add_argument ('--submit', '-s', action='store_true') parser.add_argument ('--list', '-l', action='store_true') opt = parser.parse_args() ./queue --submit -- test1.py -n usage: queue [-h] [--submit] [--list] queue: error: unrecognized arguments: -- test1.py -n From __peter__ at web.de Fri Nov 12 08:31:51 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 12 Nov 2010 14:31:51 +0100 Subject: argparse '--' not working? References: Message-ID: Neal Becker wrote: > It is a 'standard' behaviour that a lone '--' terminates options. > argparse says: > > If you have positional arguments that must begin with '-' and don?t look > like negative numbers, you can insert the pseudo-argument '--' which tells > parse_args that everything after that is a positional argument: /If/ you have positonal arguments... > But it doesn't seem to work: > > import argparse > > parser = argparse.ArgumentParser() > parser.add_argument ('--submit', '-s', action='store_true') > parser.add_argument ('--list', '-l', action='store_true') > opt = parser.parse_args() > > ./queue --submit -- test1.py -n > usage: queue [-h] [--submit] [--list] > queue: error: unrecognized arguments: -- test1.py -n Unlike optparse in argparse you must declare positional arguments, too: >>> import argparse >>> parser = argparse.ArgumentParser() >>> parser.add_argument("-s", action="store_true") [snip] >>> parser.add_argument("whatever", nargs="*") [snip] >>> parser.parse_args(["-s", "yadda"]) Namespace(s=True, whatever=['yadda']) >>> parser.parse_args(["--", "-s", "yadda"]) Namespace(s=False, whatever=['-s', 'yadda']) Peter From johann.spies at gmail.com Fri Nov 12 08:32:56 2010 From: johann.spies at gmail.com (Johann Spies) Date: Fri, 12 Nov 2010 15:32:56 +0200 Subject: http-headers for soappy Message-ID: How do I pass the following header Header name: Cookie Header value: [SID="the session identifier"] to SOAP.HeaderHandler(): class HeaderHandler: # Initially fail out if there are any problems. def __init__(self, header, attrs): for i in header.__dict__.keys(): if i[0] == "_": continue d = getattr(header, i) try: fault = int(attrs[id(d)][(NS.ENV, 'mustUnderstand')]) except: fault = 0 if fault: raise faultType, ("%s:MustUnderstand" % NS.ENV_T, "Required Header Misunderstood", "%s" % i) Regards Johann -- May grace and peace be yours in abundance through the full knowledge of God and of Jesus our Lord! His divine power has given us everything we need for life and godliness through the full knowledge of the one who called us by his own glory and excellence. 2 Pet. 1:2b,3a -------------- next part -------------- An HTML attachment was scrubbed... URL: From neilc at norwich.edu Fri Nov 12 08:54:39 2010 From: neilc at norwich.edu (Neil Cerutti) Date: 12 Nov 2010 13:54:39 GMT Subject: is there an Python equivalent for the PHP super globals like $_POST, $_COOKIE ? References: <4CDBFC41.6080404@gmail.com> Message-ID: <8k4v8vFhiiU5@mid.individual.net> On 2010-11-12, Martin Gregorie wrote: > On Thu, 11 Nov 2010 13:01:01 -0500, Steve Holden wrote: > >> Moving from one language to anther is not just a matter of >> transliterating the code. Of you try that you will end up with a messy >> code base that looks like PHP written in Python. > > "The determined Real Programmer can write Fortran programs in > any language." They probably won't run quite as as fast, though. -- Neil Cerutti From greentackle at gmail.com Fri Nov 12 09:12:19 2010 From: greentackle at gmail.com (Micah Carrick) Date: Fri, 12 Nov 2010 06:12:19 -0800 Subject: Use company name for module Message-ID: My company is working on releasing some of our code as open-source python modules. I don't want my "foo" module conflicting with other modules called "foo" on PyPi or github or a user's system. Is there anything wrong, from a conventions standpoint, with having modules like company.foo and company.bar even if foo and bar are not necessarily related other than being released by us? I really don't like the cryptic module names or things like foo2 and the like. -- Micah Carrick - http://www.micahcarrick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From manu3d at gmail.com Fri Nov 12 09:18:52 2010 From: manu3d at gmail.com (Emanuele D'Arrigo) Date: Fri, 12 Nov 2010 06:18:52 -0800 (PST) Subject: A matter of queues, tasks and multiprocessing References: <9e6f2dcc-7d15-4162-b3e9-9ef77a0b8980@n30g2000vbb.googlegroups.com> <41980a52-5bf3-4212-a0f4-a9968c2eb523@i17g2000vbq.googlegroups.com> Message-ID: On Nov 11, 3:13?pm, Tim Golden wrote: > Try Celery > > ? ?http://ask.github.com/celery/getting-started/introduction.html Thank you Tim, looks very interesting! Manu From eraserix at gmail.com Fri Nov 12 09:28:45 2010 From: eraserix at gmail.com (eraserix) Date: Fri, 12 Nov 2010 06:28:45 -0800 (PST) Subject: subprocess.Popen deadlocks References: <2cf9a225-7d1c-4490-8a62-807e79bdd06a@n30g2000vbb.googlegroups.com> Message-ID: <165f506f-f5d2-4ae5-b80a-1c445423274c@n24g2000prj.googlegroups.com> On Nov 12, 6:58?am, Lawrence D'Oliveiro wrote: > In message > <2cf9a225-7d1c-4490-8a62-807e79bdd... at n30g2000vbb.googlegroups.com>, > > Why not skip all the threads and just spawn all the processes in your main > loop? Then after getting the SIGINT, send that signal to all your processes, > and then do a bunch of os.waitpid calls to clean them all up. Thanks for the hint. You are right, the problem could be solved singlethreaded by doing some sort of polling (my description simplified things a bit) avoiding the multithreading problems altogether. I had another look at the subprocesses module and discovered the actual bug. I describe it in issue 10394. Christoph From data.2 at rediff.com Fri Nov 12 10:20:41 2010 From: data.2 at rediff.com (gaurav) Date: Fri, 12 Nov 2010 07:20:41 -0800 (PST) Subject: Careers at your place. Message-ID: <707f1f3a-7191-4c11-8cb5-f492bf5f3e95@j29g2000prf.googlegroups.com> Your desirable careers. Railroad employers, opportunities in only on the site for government, banking and data entry. http://rojgars.webs.com/Railwayjobs.htm http://rojgars1.webs.com/gov.htm Local careers in Management work. More careers in Management. http://managementjobs.webs.com/pm.htm & http://topcareer.webs.com/humanresourcemgmt.htm From robert.kern at gmail.com Fri Nov 12 10:50:46 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 12 Nov 2010 09:50:46 -0600 Subject: Use company name for module In-Reply-To: References: Message-ID: On 11/12/10 8:12 AM, Micah Carrick wrote: > My company is working on releasing some of our code as open-source python > modules. I don't want my "foo" module conflicting with other modules called > "foo" on PyPi or github or a user's system. Is there anything wrong, from a > conventions standpoint, with having modules like company.foo and company.bar > even if foo and bar are not necessarily related other than being released by us? > I really don't like the cryptic module names or things like foo2 and the like. Yes, using namespace packages. You need to use `distribute` in your setup.py in order to accomplish this. http://pypi.python.org/pypi/distribute/ http://packages.python.org/distribute/setuptools.html#namespace-packages -- 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 ian.g.kelly at gmail.com Fri Nov 12 11:36:23 2010 From: ian.g.kelly at gmail.com (Ian) Date: Fri, 12 Nov 2010 08:36:23 -0800 (PST) Subject: Sending changed parameters into nested generators References: Message-ID: <44041b0d-e86a-4044-8077-2d8a1af6966c@r31g2000prg.googlegroups.com> On Nov 12, 2:47?am, "John O'Hagan" wrote: > I have tried using a deep update function on the original nested dictionary, > but this only works if I ?change the contents of a list, not if I want to, > say, change a node from a list to a dictionary or vice versa, because in that > case I'm not operating on the same object the generator is using. > > If anyone's still reading :) , how can I send new values to arbitrary sub- > generators? I think you're focusing too heavily on generators. Just because a nifty language construct exists doesn't mean that it's the right thing to use in all situations. It sounds to me that what you really want are objects with .next() methods and externally visible state -- i.e. iterators. Or it might be that coroutines are what you're really after, although I think they would be difficult to manage in the way that you are doing. You can view the docs on the pythonic approach to coroutines at: http://docs.python.org/whatsnew/2.5.html#pep-342-new-generator-features Cheers, Ian From mygogo2011 at gmail.com Fri Nov 12 12:57:29 2010 From: mygogo2011 at gmail.com (PHP.CCC) Date: Fri, 12 Nov 2010 09:57:29 -0800 (PST) Subject: === LOAN AND INTERNSHIP PROGRAM === Message-ID: <0c9b9ae3-ce25-4b70-94d0-bb97aa02e810@i4g2000pro.googlegroups.com> === LOAN AND INTERNSHIP PROGRAM === European Union (EU) allows for the free movement of goods between Italy and other member states: Austria, Belgium, Bulgaria, Cyprus, Czech Republic, Denmark, Estonia, Finland, France, Germany, Greece, Hungary, Ireland, Latvia, Lithuania, Luxembourg, Malta, Netherlands, Poland, Portugal, Romania, Slovakia, Slovenia, Sweden, and United Kingdom. The European Union has numerous bilateral and multilateral agreements, such as the Agreement on Textiles and Clothing (formerly the Multi-Fiber Agreement), PECO countries Agreement, Israel Agreement, Turkey Agreement, Baltic Sea countries Agreement. http://to.ly/81Qj From arnodel at gmail.com Fri Nov 12 13:09:21 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Fri, 12 Nov 2010 18:09:21 +0000 Subject: Sending changed parameters into nested generators References: Message-ID: <87d3qaxvla.fsf@gmail.com> "John O'Hagan" writes: > I have a generator function which takes as arguments another generator and a > dictionary of other generators like this: > > def modgen(gen, gendict): > for item in gen(): > for k, v in gendict: > do_something_called_k(item, v.next()) > yield item > > I want to control the output of this generator by sending in new values to the > generators in gendict. I have done this using a list in a simple generator > like: > > def loop(lis): > while True: > for item in lis: > yield item > > and write: > > lis[:] = [new_value] > > to see the output of modgen() change. > > However, I want to be able to use other modgen() instances as values in > gendict, each with a gendict of its own, which in turn may contain modgen() > instances, and so on recursively. The recursion stops wherever a simple > generator like loop() is encountered. > > To this end I've made nested dictionaries like this example: > > {'a':[1,2,3], 'b':{'a':[4,5,6]}, 'c':{'a':{'a':[7,8,9], 'b':{'c':[10]}}}} > > and used a recursive function to convert them to the gendict I'm after like > this: > > def iterized(dic): > itdic = {} > for k, v in dic.items(): > if isinstance(v, dict): > itval = iterized(v) > itdic[k] = maingen(itval) > else: > itdic[k] = loop(v) > return itdic > > Then I can write: > > recdic = {nested:dictionary} > gendict = iterized(recdict) > mygen = modgen(gen, gendict) > > The problem is that the gendict looks like this: > > {'a': , 'b': 0x8841464>, 'c': } > > so I have no direct access from there to the sub-generators. > > I have tried using a deep update function on the original nested dictionary, > but this only works if I change the contents of a list, not if I want to, > say, change a node from a list to a dictionary or vice versa, because in that > case I'm not operating on the same object the generator is using. > > If anyone's still reading :) , how can I send new values to arbitrary sub- > generators? > > Thanks, > > john Try instead: def loop(d, k): while True: for x in d[k]: yield x def iterized(dic): itdic = {} for k, v in dic.items(): if isinstance(v, dict): itval = iterized(v) itdic[k] = maingen(itval) else: itdic[k] = loop(dic, k) return itdic Untested. -- Arnaud From jarausch at igpm.rwth-aachen.de Fri Nov 12 13:32:24 2010 From: jarausch at igpm.rwth-aachen.de (Helmut Jarausch) Date: 12 Nov 2010 18:32:24 GMT Subject: importing site fails - why? Message-ID: <8k5fhoFd8sU1@mid.dfncis.de> Hi, as often before, I've cloned a working system (GenToo) onto another machine. There, from a livecd and chroot to the cloned root partition python -v import site fails with the following error Python 2.6.6 (r266:84292, Oct 13 2010, 09:06:24) [GCC 4.4.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. dlopen("/usr/lib64/python2.6/lib-dynload/readline.so", 2); import readline # dynamically loaded from /usr/lib64/python2.6/lib- dynload/readline.so >>> import site # /usr/lib64/python2.6/site.pyc matches /usr/lib64/python2.6/site.py import site # precompiled from /usr/lib64/python2.6/site.pyc Traceback (most recent call last): File "", line 1, in File "/usr/lib64/python2.6/site.py", line 526, in main() File "/usr/lib64/python2.6/site.py", line 509, in main known_paths = addsitepackages(known_paths) File "/usr/lib64/python2.6/site.py", line 289, in addsitepackages addsitedir(sitedir, known_paths) File "/usr/lib64/python2.6/site.py", line 185, in addsitedir addpackage(sitedir, name, known_paths) File "/usr/lib64/python2.6/site.py", line 159, in addpackage if not dircase in known_paths and os.path.exists(dir): File "/usr/lib64/python2.6/genericpath.py", line 18, in exists st = os.stat(path) TypeError: stat() argument 1 must be encoded string without NULL bytes, not str >>>? I'm puzzled and I'd appreciate any hints to the reason for this failure. Many thanks, Helmut. From stefan.sonnenberg at pythonmeister.com Fri Nov 12 13:42:46 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Fri, 12 Nov 2010 19:42:46 +0100 Subject: importing site fails - why? In-Reply-To: <8k5fhoFd8sU1@mid.dfncis.de> References: <8k5fhoFd8sU1@mid.dfncis.de> Message-ID: <4CDD8AA6.30704@pythonmeister.com> Am 12.11.2010 19:32, schrieb Helmut Jarausch: > Hi, > > as often before, I've cloned a working system (GenToo) onto another > machine. There, from a livecd and chroot to the cloned root partition > > python -v > import site > > fails with the following error > Python 2.6.6 (r266:84292, Oct 13 2010, 09:06:24) > [GCC 4.4.4] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > dlopen("/usr/lib64/python2.6/lib-dynload/readline.so", 2); > import readline # dynamically loaded from /usr/lib64/python2.6/lib- > dynload/readline.so >>>> import site > # /usr/lib64/python2.6/site.pyc matches /usr/lib64/python2.6/site.py > import site # precompiled from /usr/lib64/python2.6/site.pyc > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib64/python2.6/site.py", line 526, in > main() > File "/usr/lib64/python2.6/site.py", line 509, in main > known_paths = addsitepackages(known_paths) > File "/usr/lib64/python2.6/site.py", line 289, in addsitepackages > addsitedir(sitedir, known_paths) > File "/usr/lib64/python2.6/site.py", line 185, in addsitedir > addpackage(sitedir, name, known_paths) > File "/usr/lib64/python2.6/site.py", line 159, in addpackage > if not dircase in known_paths and os.path.exists(dir): > File "/usr/lib64/python2.6/genericpath.py", line 18, in exists > st = os.stat(path) > TypeError: stat() argument 1 must be encoded string without NULL bytes, > not str >>>> ? > I'm puzzled and I'd appreciate any hints to the reason for this failure. > > Many thanks, > Helmut. You gave the answer yourself. Chrooting does not automatically mean your SO cache is where it should be for the target system. Perhaps your livecd is newer/older than the target system or simply the python in live environment is not (most likely) compiled as the one in the target system. That is _one_ reason I stoped using gentoo and switched to debian/ubuntu. -------------- next part -------------- A non-text attachment was scrubbed... Name: stefan_sonnenberg.vcf Type: text/x-vcard Size: 232 bytes Desc: not available URL: From celiadoug at mchsi.com Fri Nov 12 14:05:38 2010 From: celiadoug at mchsi.com (Doug Stell) Date: Fri, 12 Nov 2010 12:05:38 -0700 Subject: Supporting Python 2.x and 3.x on a PC Message-ID: I support multiple projects, some of which will remain on Python 2.x and some of which want to use Python 3.1.2. While I have installed both on my Windows PC, only the last installed version can be used. I do not have admin rights on the machine, so altering registry settings is not an option. Any guidance on how I can select between the versions? Thanks From stefan.sonnenberg at pythonmeister.com Fri Nov 12 14:23:42 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Fri, 12 Nov 2010 20:23:42 +0100 Subject: Supporting Python 2.x and 3.x on a PC In-Reply-To: References: Message-ID: <4CDD943E.30909@pythonmeister.com> Am 12.11.2010 20:05, schrieb Doug Stell: > I support multiple projects, some of which will remain on Python 2.x > and some of which want to use Python 3.1.2. While I have installed > both on my Windows PC, only the last installed version can be used. I > do not have admin rights on the machine, so altering registry settings > is not an option. Any guidance on how I can select between the > versions? > > Thanks " only the last installed version can be used" What does that mean ? I have several versions installed, and switch between them only by taking the desired interpreter. C:\Python26\python.exe gives a 2.6 python C:\Python27\python.exe gives a 2.7 python If I only start python on windows shell, the latter is run. If I just do this: SET PATH=C:\Python26;%PATH% entering just "python" on the cmd prompt gives me a 2.6 python. Hope this helps. -------------- next part -------------- A non-text attachment was scrubbed... Name: stefan_sonnenberg.vcf Type: text/x-vcard Size: 223 bytes Desc: not available URL: From jarausch at igpm.rwth-aachen.de Fri Nov 12 14:24:26 2010 From: jarausch at igpm.rwth-aachen.de (Helmut Jarausch) Date: 12 Nov 2010 19:24:26 GMT Subject: importing site fails - why? References: <8k5fhoFd8sU1@mid.dfncis.de> Message-ID: <8k5ijaFd8sU2@mid.dfncis.de> On Fri, 12 Nov 2010 19:42:46 +0100, Stefan Sonnenberg-Carstens wrote: > Am 12.11.2010 19:32, schrieb Helmut Jarausch: >> Hi, >> >> as often before, I've cloned a working system (GenToo) onto another >> machine. There, from a livecd and chroot to the cloned root partition >> >> python -v >> import site >> >> fails with the following error >> Python 2.6.6 (r266:84292, Oct 13 2010, 09:06:24) [GCC 4.4.4] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. >> dlopen("/usr/lib64/python2.6/lib-dynload/readline.so", 2); import >> readline # dynamically loaded from /usr/lib64/python2.6/lib- >> dynload/readline.so >>>>> import site >> # /usr/lib64/python2.6/site.pyc matches /usr/lib64/python2.6/site.py >> import site # precompiled from /usr/lib64/python2.6/site.pyc Traceback >> (most recent call last): >> File "", line 1, in >> File "/usr/lib64/python2.6/site.py", line 526, in >> main() >> File "/usr/lib64/python2.6/site.py", line 509, in main >> known_paths = addsitepackages(known_paths) >> File "/usr/lib64/python2.6/site.py", line 289, in addsitepackages >> addsitedir(sitedir, known_paths) >> File "/usr/lib64/python2.6/site.py", line 185, in addsitedir >> addpackage(sitedir, name, known_paths) >> File "/usr/lib64/python2.6/site.py", line 159, in addpackage >> if not dircase in known_paths and os.path.exists(dir): >> File "/usr/lib64/python2.6/genericpath.py", line 18, in exists >> st = os.stat(path) >> TypeError: stat() argument 1 must be encoded string without NULL bytes, >> not str >>>>> ? >> I'm puzzled and I'd appreciate any hints to the reason for this >> failure. >> >> Many thanks, >> Helmut. > You gave the answer yourself. > Chrooting does not automatically mean your SO cache is where it should > be for the target system. > Perhaps your livecd is newer/older than the target system or simply the > python in live environment > is not (most likely) compiled as the one in the target system. > It has been working dozens of time! Are you saying, an ldconfig would rectify the situation? Unfortunately, I can only test it on monday. Thanks, Helmut. -- Helmut Jarausch Lehrstuhl fuer Numerische Mathematik RWTH - Aachen University D 52056 Aachen, Germany From stefan.sonnenberg at pythonmeister.com Fri Nov 12 14:35:11 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Fri, 12 Nov 2010 20:35:11 +0100 Subject: importing site fails - why? In-Reply-To: <8k5ijaFd8sU2@mid.dfncis.de> References: <8k5fhoFd8sU1@mid.dfncis.de> <8k5ijaFd8sU2@mid.dfncis.de> Message-ID: <4CDD96EF.20603@pythonmeister.com> Am 12.11.2010 20:24, schrieb Helmut Jarausch: > On Fri, 12 Nov 2010 19:42:46 +0100, Stefan Sonnenberg-Carstens wrote: > >> Am 12.11.2010 19:32, schrieb Helmut Jarausch: >>> Hi, >>> >>> as often before, I've cloned a working system (GenToo) onto another >>> machine. There, from a livecd and chroot to the cloned root partition >>> >>> python -v >>> import site >>> >>> fails with the following error >>> Python 2.6.6 (r266:84292, Oct 13 2010, 09:06:24) [GCC 4.4.4] on linux2 >>> Type "help", "copyright", "credits" or "license" for more information. >>> dlopen("/usr/lib64/python2.6/lib-dynload/readline.so", 2); import >>> readline # dynamically loaded from /usr/lib64/python2.6/lib- >>> dynload/readline.so >>>>>> import site >>> # /usr/lib64/python2.6/site.pyc matches /usr/lib64/python2.6/site.py >>> import site # precompiled from /usr/lib64/python2.6/site.pyc Traceback >>> (most recent call last): >>> File "", line 1, in >>> File "/usr/lib64/python2.6/site.py", line 526, in >>> main() >>> File "/usr/lib64/python2.6/site.py", line 509, in main >>> known_paths = addsitepackages(known_paths) >>> File "/usr/lib64/python2.6/site.py", line 289, in addsitepackages >>> addsitedir(sitedir, known_paths) >>> File "/usr/lib64/python2.6/site.py", line 185, in addsitedir >>> addpackage(sitedir, name, known_paths) >>> File "/usr/lib64/python2.6/site.py", line 159, in addpackage >>> if not dircase in known_paths and os.path.exists(dir): >>> File "/usr/lib64/python2.6/genericpath.py", line 18, in exists >>> st = os.stat(path) >>> TypeError: stat() argument 1 must be encoded string without NULL bytes, >>> not str >>>>>> ? >>> I'm puzzled and I'd appreciate any hints to the reason for this >>> failure. >>> >>> Many thanks, >>> Helmut. >> You gave the answer yourself. >> Chrooting does not automatically mean your SO cache is where it should >> be for the target system. >> Perhaps your livecd is newer/older than the target system or simply the >> python in live environment >> is not (most likely) compiled as the one in the target system. >> > It has been working dozens of time! > Are you saying, an ldconfig would rectify the situation? > > Unfortunately, I can only test it on monday. > > Thanks, > Helmut. > > > > > It works as long as the so files are close enough in the way they were built, the symbols they expose and the versions they have. calling ldconfig _can_ help, but this is not for sure. You can of course try to call ldd /usr/bin/python (or where it lives) and ldd /usr/lib64/python2.6/lib-dynload/readline.so to see if there is something abviously wrong. -------------- next part -------------- A non-text attachment was scrubbed... Name: stefan_sonnenberg.vcf Type: text/x-vcard Size: 232 bytes Desc: not available URL: From kern.ra at gmail.com Fri Nov 12 14:49:08 2010 From: kern.ra at gmail.com (Becky Kern) Date: Fri, 12 Nov 2010 14:49:08 -0500 Subject: Newbie question about "import arcgisscripting" Message-ID: Hi, I'm a brand new Python 2.7 user, attempting to use it to convert a raster file to an ASCII file. I used ArcGis9.3 to create the raster file. My code begins with the line >>import arcgisscripting However, Python gives an error message "ImportError: DLL load failed: The specified module could not be found." I found arcgisscripting in a list of available modules in the Python help menu. How do I successfully import the module? Thanks, Becky -------------- next part -------------- An HTML attachment was scrubbed... URL: From bnbowman at gmail.com Fri Nov 12 15:00:55 2010 From: bnbowman at gmail.com (Brett Bowman) Date: Fri, 12 Nov 2010 12:00:55 -0800 Subject: Copy Protected PDFs and PIL In-Reply-To: References: Message-ID: To answer various question: MRAB - I've tried worker threads, and it kills the thread only and not the program as a whole. I could use that as a work-around, but I would prefer something more direct, in case other problems arise. Steve Holden - A traceback sounds like a great idea, but I don't know how to go about it, or know what is involved. Could you suggest a tutorial I could follow? Emile van Sebille - a Try/Except block was the first thing I tried, and it still dies with a fatal error, even if I use a generic Except Robert Kern - A whoops, good catch. I meant to say gfx and swftools. I'm using PIL to modify the images once I get a PNG from swftools, and I mis-spoke. The code in question is: import gfx print "1" doc = gfx.open("pdf", MY_FILE) print "2" page1 = doc.getPage(1) print "3" g_img = gfx.ImageList() print "4" g_img.startpage(a_page.width,a_page.height) print "5" a_page.render(g_img) print "6" g_img.endpage() print "7" g_img.save(TEMP_PNG) which prints the following: 1 2 3 4 5 FATAL PDF disallows copying Any help or suggestions would be appreciated. /b/ On Thu, Nov 11, 2010 at 12:28 PM, Brett Bowman wrote: > I'm trying to parse some basic details and a thumbnail from ~12,000 PDFs > for my company, but a few hundred of them are copy protected. To make > matters worse, I can't seem to trap the error it causes: whenever it happens > PIL throws a "FATAL PDF disallows copying" message and dies. An automated > way to snap a picture of the PDFs would be ideal, but I'd settle for a way > to skip over them without crashing my program. > > Any tips? > > Brett Bowman > Bioinformatics Associate > Cibus LLC > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nagle at animats.com Fri Nov 12 15:18:07 2010 From: nagle at animats.com (John Nagle) Date: Fri, 12 Nov 2010 12:18:07 -0800 Subject: A matter of queues, tasks and multiprocessing In-Reply-To: References: Message-ID: <4cdda0fe$0$1609$742ec2ed@news.sonic.net> On 11/10/2010 9:25 AM, Emanuele D'Arrigo wrote: > Greetings everybody, > > I've tried to come up with this message for a couple of weeks now and > it doesn't look like I'm getting any clearer in my thoughts so I > decided that it's probably best to take the plunge and ask you guys to > kindly throw me a rope... > > What I'm trying to come up with is some kind of simple, dynamically > scalable, domain-agnostic, multi-processor capable, tasking system. > Maybe I'm already giving myself too many constraints here, i.e. it > might all be possible except... the "simple" part. No, the problem is vagueness. We can't tell from your description what you want to do. A real-time desktop application? Warehouse-scale computing? Your own "cloud"? Incidentally, bear in mind that once you scale beyond tens of machines, error detection and recovery starts to dominate the problem. John Nagle From nagle at animats.com Fri Nov 12 15:25:21 2010 From: nagle at animats.com (John Nagle) Date: Fri, 12 Nov 2010 12:25:21 -0800 Subject: A matter of queues, tasks and multiprocessing In-Reply-To: <4cdda0fe$0$1609$742ec2ed@news.sonic.net> References: <4cdda0fe$0$1609$742ec2ed@news.sonic.net> Message-ID: <4cdda2b0$0$1656$742ec2ed@news.sonic.net> On 11/12/2010 12:18 PM, John Nagle wrote: > On 11/10/2010 9:25 AM, Emanuele D'Arrigo wrote: >> Greetings everybody, >> >> I've tried to come up with this message for a couple of weeks now and >> it doesn't look like I'm getting any clearer in my thoughts so I >> decided that it's probably best to take the plunge and ask you guys to >> kindly throw me a rope... >> >> What I'm trying to come up with is some kind of simple, dynamically >> scalable, domain-agnostic, multi-processor capable, tasking system. >> Maybe I'm already giving myself too many constraints here, i.e. it >> might all be possible except... the "simple" part. > > No, the problem is vagueness. We can't tell from your description > what you want to do. A real-time desktop application? Warehouse-scale > computing? Your own "cloud"? > > Incidentally, bear in mind that once you scale beyond tens of > machines, error detection and recovery starts to dominate > the problem. > > John Nagle Here's how Google does it: http://www.stanford.edu/class/ee380/Abstracts/101110-slides.pdf John Nagle From robert.kern at gmail.com Fri Nov 12 15:30:06 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 12 Nov 2010 14:30:06 -0600 Subject: Copy Protected PDFs and PIL Message-ID: On 11/12/10 2:00 PM, Brett Bowman wrote: > A whoops, good catch. I meant to say gfx and swftools. I'm using PIL to > modify the images once I get a PNG from swftools, and I mis-spoke. There is nothing you can do to catch the error. swftools is not written to be used as a Python library, so it aborts the process when it runs into problems instead of raising an exception. Tough luck. I recommend using the pyPdf library to attempt to see if the PDF is copy-protected first. Then use gfx to render the PDF to an image. http://pybrary.net/pyPdf/ -- 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 emile at fenx.com Fri Nov 12 15:43:59 2010 From: emile at fenx.com (Emile van Sebille) Date: Fri, 12 Nov 2010 12:43:59 -0800 Subject: Copy Protected PDFs and PIL In-Reply-To: References: Message-ID: On 11/12/2010 12:00 PM Brett Bowman said... > FATAL PDF disallows copying I ran into something like this about six months ago. IIRC, I was able to detect this setting (using reportlab I think), but a quick look to rediscover what I did specifically didn't yield anything useful. I'm pretty sure if I had the time I'd get back to what I found last time. YMMV, Emile From steve at holdenweb.com Fri Nov 12 15:54:01 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 12 Nov 2010 12:54:01 -0800 Subject: Copy Protected PDFs and PIL In-Reply-To: References: Message-ID: On 11/12/2010 12:00 PM, Brett Bowman wrote: > Steve Holden - > A traceback sounds like a great idea, but I don't know how to go about > it, or know what is involved. Could you suggest a tutorial I could follow? > The traceback is the listing of modules and line numbers that you normally get when a Python program fails. But it sounds like you may not be getting a traceback, which could indicate problems arising in some extension module (extension modules are written in compiled languages like C but called from Python in the normal way). So I don't think a tutorial would help in this specific case, and any tutorial worth its salt will tell you what a traceback is. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From python at rcn.com Fri Nov 12 16:24:09 2010 From: python at rcn.com (Raymond Hettinger) Date: Fri, 12 Nov 2010 13:24:09 -0800 (PST) Subject: Is a 32-bit build faster than a 64-bit build Message-ID: <7a628beb-5f36-4cc0-8e38-fa81de268722@s11g2000prs.googlegroups.com> Has anyone here benchmarked a 32-bit Python versus a 64-bit Python for Django or some other webserver? My hypotheses is that for apps not needing the 64-bit address space, the 32-bit version has better memory utilization and hence better cache performance. If so, then switching python versions may enable a single server to handle a greater traffic load. Has anyone here tried that? Raymond From stefan.sonnenberg at pythonmeister.com Fri Nov 12 16:39:34 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Fri, 12 Nov 2010 22:39:34 +0100 Subject: Is a 32-bit build faster than a 64-bit build In-Reply-To: <7a628beb-5f36-4cc0-8e38-fa81de268722@s11g2000prs.googlegroups.com> References: <7a628beb-5f36-4cc0-8e38-fa81de268722@s11g2000prs.googlegroups.com> Message-ID: <4CDDB416.9070507@pythonmeister.com> Am 12.11.2010 22:24, schrieb Raymond Hettinger: > My hypotheses is that for apps not needing the 64-bit address space, > the 32-bit version has better memory utilization and hence better > cache performance. If so, then switching python versions may enable a > single server to handle a greater traffic load. Has anyone here tried > that? In most cases (all?) I have seen did the performance not differ when compared between running python scripts in 32 or 64 bit env. But that is not true for compiled code. Just take your script and do some benchmarking. In germany we say: probieren geht ?ber studieren. Don't study - try it. An ex-post explanation will show at hand, I promise :-) -------------- next part -------------- A non-text attachment was scrubbed... Name: stefan_sonnenberg.vcf Type: text/x-vcard Size: 223 bytes Desc: not available URL: From stefan_ml at behnel.de Fri Nov 12 17:00:25 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 12 Nov 2010 23:00:25 +0100 Subject: Is a 32-bit build faster than a 64-bit build In-Reply-To: <7a628beb-5f36-4cc0-8e38-fa81de268722@s11g2000prs.googlegroups.com> References: <7a628beb-5f36-4cc0-8e38-fa81de268722@s11g2000prs.googlegroups.com> Message-ID: Raymond Hettinger, 12.11.2010 22:24: > Has anyone here benchmarked a 32-bit Python versus a 64-bit Python for > Django or some other webserver? > > My hypotheses is that for apps not needing the 64-bit address space, > the 32-bit version has better memory utilization and hence better > cache performance. OTOH, x86_64 has more registers and allows faster compiler flags for default installations (e.g. there is no x86_64 processor without MMX and SSE). So, if you don't compile your software yourself (including OS kernel and libraries, e.g. OpenSSL), it will likely run faster on 64bits simply due to the better compiler optimisations. There are good reasons for both being able to run faster depending on the specific code, so benchmarking is basically all you can do. Stefan From gburdell1 at gmail.com Fri Nov 12 17:03:33 2010 From: gburdell1 at gmail.com (George Burdell) Date: Fri, 12 Nov 2010 14:03:33 -0800 (PST) Subject: Newbie question about python garbage collection when keeping only a reference to an object's member Message-ID: My understanding is that any object which is not pointed to by any variable will be automatically deleted. What if I create a class object, but only keep a reference to one of its members, and not a reference to the object itself? What goes on internally in Python? Does Python retain the whole object, or does it just keep a copy of the referenced member? For example, if I have def myclass: def __init__(self): self.x = [1,2,3] self.y = [4,5,6] x = myclass().x This works, and I correctly get x = [1,2,3]. But what happened to the myclass() object initially created, and the member "y"? From robert.kern at gmail.com Fri Nov 12 17:12:23 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 12 Nov 2010 16:12:23 -0600 Subject: Newbie question about python garbage collection when keeping only a reference to an object's member In-Reply-To: References: Message-ID: On 11/12/10 4:03 PM, George Burdell wrote: > My understanding is that any object which is not pointed to by any > variable will be automatically deleted. What if I create a class > object, but only keep a reference to one of its members, and not a > reference to the object itself? What goes on internally in Python? > Does Python retain the whole object, or does it just keep a copy of > the referenced member? > > For example, if I have > > def myclass: > def __init__(self): > self.x = [1,2,3] > self.y = [4,5,6] > x = myclass().x > > This works, and I correctly get x = [1,2,3]. But what happened to the > myclass() object initially created, and the member "y"? They get deleted. -- 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 steve at holdenweb.com Fri Nov 12 17:18:44 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 12 Nov 2010 14:18:44 -0800 Subject: Newbie question about python garbage collection when keeping only a reference to an object's member In-Reply-To: References: Message-ID: On 11/12/2010 2:03 PM, George Burdell wrote: > My understanding is that any object which is not pointed to by any > variable will be automatically deleted. What if I create a class > object, but only keep a reference to one of its members, and not a > reference to the object itself? What goes on internally in Python? > Does Python retain the whole object, or does it just keep a copy of > the referenced member? > > For example, if I have > > def myclass: > def __init__(self): > self.x = [1,2,3] > self.y = [4,5,6] > x = myclass().x > > This works, and I correctly get x = [1,2,3]. But what happened to the > myclass() object initially created, and the member "y"? The myclass() call created a myclass instance (which contains a reference to a newly created list, which therefore has a refcount of 1). Attribute access to that instance then returns a second reference to the list, which is bound to the name x in the current local namespace (or the module global namespace if this is top-level code). The binding results in a reference count of two for the list. The instance, having no outstanding references, is then garbage-collected, which means that the objects referenced by its namespace have their reference counts decremented for each reference. So the destruction of the myclass instance reduces the reference count of the list [1, 2, 3] to one, and that of the list [4, 5, 6] to zero (which causes *it* to be garbage collected). And you are left with a local variable x that references a list whose current contents are [1, 2, 3]. Remember, the new values aren't created in local namespace. They are created in a shared area of memory (often referred to as the "heap"), so it's quite easy to "keep objects alive" that were created inside functions - just make sure you hold on to references outside the functions, and you are fine. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From emile at fenx.com Fri Nov 12 17:20:17 2010 From: emile at fenx.com (Emile van Sebille) Date: Fri, 12 Nov 2010 14:20:17 -0800 Subject: Newbie question about python garbage collection when keeping only a reference to an object's member In-Reply-To: References: Message-ID: On 11/12/2010 2:03 PM George Burdell said... > My understanding is that any object which is not pointed to by any > variable will be automatically deleted. What if I create a class > object, but only keep a reference to one of its members, and not a > reference to the object itself? What goes on internally in Python? > Does Python retain the whole object, or does it just keep a copy of > the referenced member? > > For example, if I have > > def myclass: class myclass: > def __init__(self): > self.x = [1,2,3] > self.y = [4,5,6] > x = myclass().x > > This works, and I correctly get x = [1,2,3]. But what happened to the > myclass() object initially created, and the member "y"? Garbage collect(ed|able) It only existed (was referenceable) while instantiated and can be gc'd one no longer referenced. Emile From steve at REMOVE-THIS-cybersource.com.au Fri Nov 12 18:51:44 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 12 Nov 2010 23:51:44 GMT Subject: How to test if a module exists? References: Message-ID: <4cddd310$0$29992$c3e8da3$5496439d@news.astraweb.com> On Thu, 11 Nov 2010 16:51:38 -0800, Ethan Furman wrote: > Lawrence D'Oliveiro wrote: >> As for those who persisted in posting my address after being warned of >> this, I?m still deciding what to do. > > You can be such an ass sometimes. "Sometimes"? -- Steven From bblais at bryant.edu Fri Nov 12 19:24:50 2010 From: bblais at bryant.edu (Brian Blais) Date: Fri, 12 Nov 2010 19:24:50 -0500 Subject: drawing with the mouse with turtle Message-ID: I'd like to draw on a turtle canvas, but use the mouse to direct the turtle. I don't see a good way of getting the mouse coordinates and the button state. I tried to do something like this: import turtle def gothere(event): print event.x print event.y turtle.goto(event.x,event.y) turtle.reset() turtle.speed(0) c=turtle.getcanvas() c.bind("", gothere) turtle.pendown() but this seemed to draw in the wrong place (like the coordinates were wrong). Is there a good way to do this? thanks, bb -- Brian Blais bblais at bryant.edu http://web.bryant.edu/~bblais http://bblais.blogspot.com/ From steve at holdenweb.com Fri Nov 12 19:26:51 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 12 Nov 2010 16:26:51 -0800 Subject: How to test if a module exists? In-Reply-To: <4cddd310$0$29992$c3e8da3$5496439d@news.astraweb.com> References: <4cddd310$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 11/12/2010 3:51 PM, Steven D'Aprano wrote: > On Thu, 11 Nov 2010 16:51:38 -0800, Ethan Furman wrote: > >> Lawrence D'Oliveiro wrote: > >>> As for those who persisted in posting my address after being warned of >>> this, I?m still deciding what to do. >> >> You can be such an ass sometimes. > > "Sometimes"? > OK, that's probably enough. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at REMOVE-THIS-cybersource.com.au Fri Nov 12 20:05:42 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 13 Nov 2010 01:05:42 GMT Subject: drawing with the mouse with turtle References: Message-ID: <4cdde466$0$29992$c3e8da3$5496439d@news.astraweb.com> On Fri, 12 Nov 2010 19:24:50 -0500, Brian Blais wrote: > I'd like to draw on a turtle canvas, but use the mouse to direct the > turtle. I don't see a good way of getting the mouse coordinates and the > button state. I think the right way to do that is by creating an event handler to the turtle. These docs are for Python 2.7 turtle, but they may be applicable to older versions as well: http://docs.python.org/library/turtle.html#turtle.ondrag I quote: >>> turtle.ondrag(turtle.goto) Subsequently, clicking and dragging the Turtle will move it across the screen thereby producing handdrawings (if pen is down). That's probably all you need to do. -- Steven From martin.kaspar at campus-24.com Fri Nov 12 20:21:04 2010 From: martin.kaspar at campus-24.com (Martin Kaspar) Date: Fri, 12 Nov 2010 17:21:04 -0800 (PST) Subject: need some debug-infos on a simple regex Message-ID: hello dear list! i'm very new to programming and self teaching myself. I'm having a problem with a little project. I'm trying to preform an fetch-process, but every time i try it i runs into errors. i have read the Python-documents for more than ten hours now! And i have several books here - but they do not help at the moment. This code runs like a charme!! import urllib import urlparse import re url = "http://search.cpan.org/author/?W" html = urllib.urlopen(url).read() for lk, capname, name in re.findall('(.*?)
(.*?)', html): alk = urlparse.urljoin(url, lk) data = { 'url':alk, 'name':name, 'cname':capname } phtml = urllib.urlopen(alk).read() memail = re.search('', phtml) if memail: data['email'] = memail.group(1) print data Note the above mentioned code runs very very good. All is nice. Now i want to apply it on a new target. I can learn alot with this ...Let us say on this swiss-site:educa.ch: What is aimed: I want to adopt it on a new target to learn mor about regex and to do some homework - (working as a teacher - and collecting some data bout colleagues) How should we fetch the sites - that is the problem..i want to learn while applying the code...What is necessary to apply the example on the target!? the target: http://www.educa.ch/dyn/79362.asp?action=search But the code (see below) does not run - i tried several things to debug - can yozu help me!? BTW - should i fetch the pages and load them into an array or should i loop over the http://www.educa.ch/dyn/79376.asp?id=2635 http://www.educa.ch/dyn/79376.asp?id=3493 and so on... see the code that does not work!? import urllib import urlparse import re url = "http://www.educa.ch/dyn/" html = urllib.urlopen("http://www.educa.ch/dyn/79362.asp? action=search").read() for capname, lk in re.findall('
]+>([^<] +).*?', phtml) if memail: data['email'] = memail.group(1) print data Look forward to get some starting points... thx matze From bblais at bryant.edu Fri Nov 12 20:48:34 2010 From: bblais at bryant.edu (Brian Blais) Date: Fri, 12 Nov 2010 20:48:34 -0500 Subject: drawing with the mouse with turtle In-Reply-To: <4cdde466$0$29992$c3e8da3$5496439d@news.astraweb.com> References: <4cdde466$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Nov 12, 2010, at 8:05 PM, Steven D'Aprano wrote: > On Fri, 12 Nov 2010 19:24:50 -0500, Brian Blais wrote: > >> I'd like to draw on a turtle canvas, but use the mouse to direct the >> turtle. I don't see a good way of getting the mouse coordinates and the >> button state. > > I think the right way to do that is by creating an event handler to the > turtle. These docs are for Python 2.7 turtle, but they may be applicable > to older versions as well: > > http://docs.python.org/library/turtle.html#turtle.ondrag > > I quote: > >>>> turtle.ondrag(turtle.goto) > > Subsequently, clicking and dragging the Turtle will move it > across the screen thereby producing handdrawings (if pen is down). > > > That's probably all you need to do. that's what I tried first, with no luck. I am on 2.6 on Mac OSX (Enthought distribution). The following code: import turtle turtle.reset() turtle.speed(0) turtle.ondrag(turtle.goto) turtle.pendown() running it in ipython brings up a window, but clicking, dragging, or anything like that doesn't move the turtle or draw anything. running it in just plain python brings up the window, but it instantly closes. I added: turtle.mainloop() which keeps the window open, but the clicking or dragging still doesn't move the turtle or update the window in any way. bb -- Brian Blais bblais at bryant.edu http://web.bryant.edu/~bblais http://bblais.blogspot.com/ From martin at address-in-sig.invalid Fri Nov 12 20:51:01 2010 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Sat, 13 Nov 2010 01:51:01 +0000 (UTC) Subject: need some debug-infos on a simple regex References: Message-ID: On Fri, 12 Nov 2010 17:21:04 -0800, Martin Kaspar wrote: > hello dear list! > > i'm very new to programming and self teaching myself. I'm having a > problem with a little project. > This doesn't directly help with your problem, but the tool at this URL: http://www.solmetra.com/scripts/regex/ may be useful when you're experimenting with regexes or testing them. Perl regexes are similar enough to Python regexes for this tool to be useful here. Without examples of text that the regex is intended to match its difficult to say more. -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From research at johnohagan.com Fri Nov 12 21:39:59 2010 From: research at johnohagan.com (John O'Hagan) Date: Sat, 13 Nov 2010 02:39:59 +0000 Subject: Sending changed parameters into nested generators In-Reply-To: <44041b0d-e86a-4044-8077-2d8a1af6966c@r31g2000prg.googlegroups.com> References: <44041b0d-e86a-4044-8077-2d8a1af6966c@r31g2000prg.googlegroups.com> Message-ID: <201011130240.00394.research@johnohagan.com> On Fri, 12 Nov 2010, Ian wrote: > On Nov 12, 2:47 am, "John O'Hagan" wrote: > > I have tried using a deep update function on the original nested > > dictionary, but this only works if I change the contents of a list, not > > if I want to, say, change a node from a list to a dictionary or vice > > versa, because in that case I'm not operating on the same object the > > generator is using. > > > > If anyone's still reading :) , how can I send new values to arbitrary > > sub- generators? > > I think you're focusing too heavily on generators. Just because a > nifty language construct exists doesn't mean that it's the right thing > to use in all situations. It sounds to me that what you really want > are objects with .next() methods and externally visible state -- i.e. > iterators. Oddly enough I had just begun to replace some of the generator routines in the real program with iterator classes, but it didn't occur to me that they could solve the nesting problem. I guess I could access the parameters of nested iterators like: MyIter().param.iterator.param and so on? I'll try it, thanks. Although if it can be done with built-in functionality... > Or it might be that coroutines are what you're really after, although > I think they would be difficult to manage in the way that you are > doing. From the rather slight docs on these features, it seems they are tailor-made for what I'm doing (in fact my exact solution is described there as "hackish"!), but so far I can't see how they could solve my nesting problem. [...] Thanks, John From python at mrabarnett.plus.com Fri Nov 12 21:54:14 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 13 Nov 2010 02:54:14 +0000 Subject: need some debug-infos on a simple regex In-Reply-To: References: Message-ID: <4CDDFDD6.2010809@mrabarnett.plus.com> On 13/11/2010 01:21, Martin Kaspar wrote: > hello dear list! > > i'm very new to programming and self teaching myself. I'm having a > problem with a little project. > > I'm trying to preform an fetch-process, but every time i try it i runs > into errors. > i have read the Python-documents for more than ten hours now! And i > have several books here > - but they do not help at the moment. This code runs like a charme!! > > > import urllib > import urlparse > import re > > url = "http://search.cpan.org/author/?W" > html = urllib.urlopen(url).read() > for lk, capname, name in re.findall(' href="(/~.*?/)">(.*?)
(.*?)', html): > alk = urlparse.urljoin(url, lk) > > data = { 'url':alk, 'name':name, 'cname':capname } > > phtml = urllib.urlopen(alk).read() > memail = re.search('', phtml) > if memail: > data['email'] = memail.group(1) > > print data > > Note the above mentioned code runs very very good. All is nice. Now i > want to apply it on a new target. I can learn alot with this ...Let us > say on this swiss-site:educa.ch: > > What is aimed: I want to adopt it on a new target to learn mor about > regex and to do some homework - (working as a teacher - and > collecting some data bout colleagues) How should we fetch the sites - > that is the problem..i want to learn while applying the > code...What is necessary to apply the example on the target!? > > the target: http://www.educa.ch/dyn/79362.asp?action=search > > But the code (see below) does not run - i tried several things to > debug - can yozu help me!? > BTW - should i fetch the pages and load them into an array or should i > loop over the > > http://www.educa.ch/dyn/79376.asp?id=2635 > http://www.educa.ch/dyn/79376.asp?id=3493 > and so on... > > see the code that does not work!? > > import urllib > import urlparse > import re > > url = "http://www.educa.ch/dyn/" > html = urllib.urlopen("http://www.educa.ch/dyn/79362.asp? > action=search").read() > for capname, lk in re.findall('
]+>([^<] > +).*?', phtml) > if memail: > data['email'] = memail.group(1) > > print data > > Look forward to get some starting points... > Don't just say "does not run" or "does not work". That's not very helpful. It's like saying "My car doesn't work. How should I fix it?". :-) When writing regexes it's recommended that you use raw string literals. Your first regex contains 'asp?', which is saying that 'p' is optional. I think you meant 'asp\?'. Also, '.' will match any character except '\n'. If want to match an actual '.' then use '\.'. Your second regex contains a closing parenthesis ')' but no opening parenthesis '('. From g.rodola at gmail.com Fri Nov 12 22:19:08 2010 From: g.rodola at gmail.com (=?ISO-8859-1?Q?Giampaolo_Rodol=E0?=) Date: Sat, 13 Nov 2010 04:19:08 +0100 Subject: ANN: psutil 0.2.0 released Message-ID: Hi, I'm pleased to announce the 0.2.0 release of psutil: http://code.google.com/p/psutil === About === psutil is a module providing an interface for retrieving information on running processes and system utilization (CPU, memory) in a portable way by using Python, implementing many functionalities offered by command line tools like ps, top, kill, lsof and netstat. It currently supports Linux, Windows, OS X and FreeBSD both 32-bit and 64-bit with Python versions from 2.4 to 3.2 by using a unique code base. === Major enhancements === * per-process open files * per-process TCP/UPD connections * per-process children * per-process executable name * per-process number of threads * per-process send_signal() and terminate() methods * system cached and buffer memory * support for Windows 64-bit (XP, Vista, 7) and Windows 2000 * mingw compiler support === Links === * Home page: http://code.google.com/p/psutil * Mailing list: http://groups.google.com/group/psutil/topics * Source tarball: http://psutil.googlecode.com/files/psutil-0.2.0.tar.gz * Windows Installer (Python 2.7): http://psutil.googlecode.com/files/psutil-0.2.0.win32-py2.7.exe * Api Reference: http://code.google.com/p/psutil/wiki/Documentation --- Giampaolo Rodola' http://code.google.com/p/pyftpdlib http://code.google.com/p/psutil/ From steve at REMOVE-THIS-cybersource.com.au Fri Nov 12 23:43:48 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 13 Nov 2010 04:43:48 GMT Subject: Sending changed parameters into nested generators References: Message-ID: <4cde1784$0$29992$c3e8da3$5496439d@news.astraweb.com> On Fri, 12 Nov 2010 09:47:26 +0000, John O'Hagan wrote: > I have a generator function which takes as arguments another generator > and a dictionary of other generators like this: > > def modgen(gen, gendict): > for item in gen(): > for k, v in gendict: > do_something_called_k(item, v.next()) > yield item [snip] > If anyone's still reading :) , how can I send new values to arbitrary > sub- generators? I have a headache after reading your problem :( I think it's a good time to point you at the Zen, particularly these five maxims: Beautiful is better than ugly. Simple is better than complex. Complex is better than complicated. Flat is better than nested. If the implementation is hard to explain, it's a bad idea. I'm afraid that your nested generators inside another generator idea fails all of those... it's not elegant (beautiful), it's complicated, it's nested, and the implementation is hard to explain. You could probably replace generators with full-blown iterators, but I wonder what you're trying to accomplish that is so complicated that it needs such complexity to solve it. What are you actually trying to accomplish? Can you give a simple example of what practical task you hope to perform? I suspect there's probably a more elegant way to solve the problem. -- Steven From mygogo2011 at gmail.com Sat Nov 13 00:00:50 2010 From: mygogo2011 at gmail.com (PHP.CCC) Date: Fri, 12 Nov 2010 21:00:50 -0800 (PST) Subject: Air Drop Pro iPhone Game Review Message-ID: <3b947859-c66d-49a1-ba37-3ef26c783123@b19g2000prj.googlegroups.com> Air Drop Pro iPhone Game Review AirDrop Pro is is based on the aid delivery service within the third world etc. So we should all know what to expect from this iPhone and iPod Touch game. The format of the games goes like this a plane flies in a straight line through the screen from either left to right or right to left. You have to touch the screen to release the package from the plane which has a parachute attached. click here >>> http://bit.ly/a6575w From steve at holdenweb.com Sat Nov 13 00:50:12 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 12 Nov 2010 21:50:12 -0800 Subject: need some debug-infos on a simple regex In-Reply-To: References: Message-ID: On 11/12/2010 5:51 PM, Martin Gregorie wrote: > On Fri, 12 Nov 2010 17:21:04 -0800, Martin Kaspar wrote: > >> hello dear list! >> >> i'm very new to programming and self teaching myself. I'm having a >> problem with a little project. >> > This doesn't directly help with your problem, but the tool at this URL: > http://www.solmetra.com/scripts/regex/ > > may be useful when you're experimenting with regexes or testing them. > Perl regexes are similar enough to Python regexes for this tool to be > useful here. > > Without examples of text that the regex is intended to match its > difficult to say more. > > Or you could look at the Kodos tool, which is written in Python and will tell you exactly what a Python pattern will and will not match. http://kodos.sourceforge.net/ regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From research at johnohagan.com Sat Nov 13 01:52:00 2010 From: research at johnohagan.com (John O'Hagan) Date: Sat, 13 Nov 2010 06:52:00 +0000 Subject: Sending changed parameters into nested generators In-Reply-To: <4cde1784$0$29992$c3e8da3$5496439d@news.astraweb.com> References: <4cde1784$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: <201011130652.01523.research@johnohagan.com> On Sat, 13 Nov 2010, Steven D'Aprano wrote: > On Fri, 12 Nov 2010 09:47:26 +0000, John O'Hagan wrote: > > I have a generator function which takes as arguments another generator > > and a dictionary of other generators like this: > > > > def modgen(gen, gendict): > > for item in gen(): > > for k, v in gendict: > > do_something_called_k(item, v.next()) > > > > yield item > > [snip] > > > If anyone's still reading :) , how can I send new values to arbitrary > > sub- generators? > > I have a headache after reading your problem :( > > I think it's a good time to point you at the Zen, particularly these five > maxims: > > Beautiful is better than ugly. > Simple is better than complex. > Complex is better than complicated. > Flat is better than nested. > If the implementation is hard to explain, it's a bad idea. > > > I'm afraid that your nested generators inside another generator idea > fails all of those... it's not elegant (beautiful), it's complicated, > it's nested, and the implementation is hard to explain. > > You could probably replace generators with full-blown iterators, but I > wonder what you're trying to accomplish that is so complicated that it > needs such complexity to solve it. What are you actually trying to > accomplish? Can you give a simple example of what practical task you hope > to perform? I suspect there's probably a more elegant way to solve the > problem. I hope there is! The project not practical but artistic; it's a real-time musical composition program. A (simplified) description: one module contains number-list generating functions, others contain functions designed to filter and modify the number lists produced, according to various parameters. Each such stream of number lists is assigned a musical meaning (e.g. pitch, rhythm, volume, etc) and they are combined to produce representations of musical phrases, which are sent to a backend which plays the music as it is produced, and makes PDF scores. Each such "instrument" runs as a separate thread, so several can play together in a coordinated fashion. All the compositional interest lies in the selection of number-list generators and how their output is modified. For example, if I say "Play every third note up an octave" it's not very interesting, compared to "Play every nth note up an interval of m", where n and m vary according to some pattern. It gets even more interesting when that pattern is a function of x and y, which also vary according to another pattern, and so on. To that end, I have each parameter of each modifier set by another generator, such that the value may change with each iteration. This may continue recursively, until at some level we give a parameter a simple value. That's all working, but I also want it to be interactive. Each thread opens a terminal where new options can be entered, but so far it only works, as I mentioned, for changing the values in a top-level mutable object. I agree that as a piece of code this is complicated, nested and hard to explain, but I don't agree that it's ugly. In fact, it was my existing interest in a "patterns within patterns" style of composition that got me learning python in the first place, as the patterns got too hard to keep track of manually. I'm not attached to using nested generators, and would be happy with any solution which enables me to do what I've described. It seems to me that the concept is inherently nested, but I'd be glad to be proved wrong. Regards, John From snehaparitala at gmail.com Sat Nov 13 03:50:27 2010 From: snehaparitala at gmail.com (sms) Date: Sat, 13 Nov 2010 00:50:27 -0800 (PST) Subject: hello Message-ID: http://infoukhotels.blogspot.com/ From nad at acm.org Sat Nov 13 05:03:03 2010 From: nad at acm.org (Ned Deily) Date: Sat, 13 Nov 2010 02:03:03 -0800 Subject: IDLE debugger questions References: <04a3c943-5aee-4248-9cb3-60ea424108cb@j4g2000prm.googlegroups.com> Message-ID: In article , Roger Davis wrote: > Thanks for that info, Ned, I can now get the sys.argv[] list I need, > that's a big help! However, is there any other way to set a breakpoint > in idle that will work on Mac OS X, maybe entering a manual command > somewhere with a specified line number? Inability to set a breakpoint > is an absolute showstopper for me, the code I am trying to debug loops > way too much to be manually steppable in a human time frame. Sorry about the long delay in replying. It turns out that IDLE's breakpoint facility is currently unusable on OS X when Python Tkinter is built with Aqua Tk, the default on OS X. The reason: IDLE implements the Set and Clear Breakpoints menu options through a context popup menu but the popup menus don't work with Aqua Tk. On other systems, the popup menus are bound to the Right mouse button. But on OS X, there's no guarantee that there is more than one button (the Left) and, even if there is, the button bindings are different for Aqua Tk. The net effect is that you can't make the popup menus appear with or without a three-button mouse or equivalent. As far as I can tell, this has been an issue ever since Python started using Aqua Tk on OS X instead of X11 Tk, many releases ago. I've opened an issue for the problem and supplied a patch to have IDLE use Control-Click for popups on OS X as is common in other applications. http://bugs.python.org/issue10404 Thanks for calling this problem to our attention! -- Ned Deily, nad at acm.org From iamforufriends at gmail.com Sat Nov 13 05:41:27 2010 From: iamforufriends at gmail.com (naughty girl) Date: Sat, 13 Nov 2010 02:41:27 -0800 (PST) Subject: NAUGHTY GIRL, WANNA NAUGHTY WITH ME, COME ON... Message-ID: NAUGHTY GIRL, WANNA NAUGHTY WITH ME, COME ON... FREE GOLD MEMBER FOR FEMALE PROFILE http://goo.gl/1bour http://goo.gl/1bour http://goo.gl/1bour http://goo.gl/1bour http://goo.gl/1bour http://goo.gl/1bour http://goo.gl/1bour From bblais at bryant.edu Sat Nov 13 06:22:59 2010 From: bblais at bryant.edu (Brian Blais) Date: Sat, 13 Nov 2010 06:22:59 -0500 Subject: drawing with the mouse with turtle In-Reply-To: References: <4cdde466$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5983D120-1DFA-47C2-8CA1-769A6BDCD5CD@bryant.edu> On Nov 13, 2010, at 1:31 AM, Dennis Lee Bieber wrote: > On Fri, 12 Nov 2010 20:48:34 -0500, Brian Blais > declaimed the following in gmane.comp.python.general: > >> turtle.ondrag(turtle.goto) >> turtle.pendown() >> >> > I'm not familiar with the turtle module but... would it make more > sense to drop the pen before dragging the turtle around? > > """ > Subsequently, clicking and dragging the Turtle will move it across the > screen thereby producing handdrawings (if pen is down). > """ > > "if pen is down" <=== > there is no change by changing the order, but I didn't expect one. since ondrag is binding a callback, which is only called when the event happens, I figure that the pen has to be down when the callback happens, not when the binding occurs. since the pen is down (and never lifted), when I start dragging the mouse around after that it should work...but doesn't seem to. thanks, bb -- Brian Blais bblais at bryant.edu http://web.bryant.edu/~bblais http://bblais.blogspot.com/ From solipsis at pitrou.net Sat Nov 13 07:28:58 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Sat, 13 Nov 2010 13:28:58 +0100 Subject: Is a 32-bit build faster than a 64-bit build References: <7a628beb-5f36-4cc0-8e38-fa81de268722@s11g2000prs.googlegroups.com> Message-ID: <20101113132858.31fc5c35@pitrou.net> On Fri, 12 Nov 2010 13:24:09 -0800 (PST) Raymond Hettinger wrote: > Has anyone here benchmarked a 32-bit Python versus a 64-bit Python for > Django or some other webserver? > > My hypotheses is that for apps not needing the 64-bit address space, > the 32-bit version has better memory utilization and hence better > cache performance. If so, then switching python versions may enable a > single server to handle a greater traffic load. Has anyone here tried > that? On micro-benchmarks, x86-64 is always faster by about 10-30% compared to x86, simply because of the extended register set and other additional niceties. On a benchmark stressing the memory system a little more such as dcbench-py3k.py in http://bugs.python.org/issue9520, the 64-bit build is still faster until the tested data structure (a large dict) overwhelms the 2MB last-level cache in my CPU, after which the 32-bit build becomes 10% faster for the same numbers of elements: To be clear, here are the figures in 64-bit mode: 10000 words ( 9092 keys), 2893621 inserts/s, 13426069 lookups/s, 86 bytes/key (0.8MB) 20000 words ( 17699 keys), 3206654 inserts/s, 12338002 lookups/s, 44 bytes/key (0.8MB) 40000 words ( 34490 keys), 2613517 inserts/s, 7643726 lookups/s, 91 bytes/key (3.0MB) 80000 words ( 67148 keys), 2579562 inserts/s, 4872069 lookups/s, 46 bytes/key (3.0MB) 160000 words ( 130897 keys), 2377487 inserts/s, 5765316 lookups/s, 48 bytes/key (6.0MB) 320000 words ( 254233 keys), 2119978 inserts/s, 5003979 lookups/s, 49 bytes/key (12.0MB) 640000 words ( 493191 keys), 1965413 inserts/s, 4640743 lookups/s, 51 bytes/key (24.0MB) 1280000 words ( 956820 keys), 1854546 inserts/s, 4338543 lookups/s, 52 bytes/key (48.0MB) And here are the figures in 32-bit mode: 10000 words ( 9092 keys), 2250163 inserts/s, 9487229 lookups/s, 43 bytes/key (0.4MB) 20000 words ( 17699 keys), 2543235 inserts/s, 7653839 lookups/s, 22 bytes/key (0.4MB) 40000 words ( 34490 keys), 2360162 inserts/s, 8851543 lookups/s, 45 bytes/key (1.5MB) 80000 words ( 67148 keys), 2415169 inserts/s, 8581037 lookups/s, 23 bytes/key (1.5MB) 160000 words ( 130897 keys), 2203071 inserts/s, 6914732 lookups/s, 24 bytes/key (3.0MB) 320000 words ( 254233 keys), 2005980 inserts/s, 5670133 lookups/s, 24 bytes/key (6.0MB) 640000 words ( 493191 keys), 1856385 inserts/s, 4929790 lookups/s, 25 bytes/key (12.0MB) 1280000 words ( 956820 keys), 1746364 inserts/s, 4530747 lookups/s, 26 bytes/key (24.0MB) However, it's not obvious to me that a program like "Django or some other webserver" would have really bad cache locality. Even if the total working set is larger than the CPU cache, there can still be quite a good cache efficiency if a large fraction of CPU time is spent on small datasets. By the way, I've been experimenting with denser dicts and with linear probing (in the hope that it will improve cache efficiency and spatial locality in real applications), and there doesn't seem to be adverse consequences on micro-benchmarks. Do you think I should upload a patch? Regards Antoine. From affdfsdfdsfsd at b.com Sat Nov 13 08:46:29 2010 From: affdfsdfdsfsd at b.com (Tracubik) Date: 13 Nov 2010 13:46:29 GMT Subject: strange behavor.... Message-ID: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> hi all, i've this on python 2.6.6: >>> def change_integer(int_value): ... int_value = 10 ... ... def change_list(list): ... list[0] = 10 ... ... a = 1 ... l = [1,1,1] ... ... change_integer(a) ... change_list(l) ... ... print a ... print l 1 [10, 1, 1] why the integer value doesn't change while the list value do? in Pascal i can choose the behavour of parametres, how this work on Python? also a link could be appreciated Thanks in advance Nico From wuwei23 at gmail.com Sat Nov 13 08:50:40 2010 From: wuwei23 at gmail.com (alex23) Date: Sat, 13 Nov 2010 05:50:40 -0800 (PST) Subject: strange behavor.... References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> Message-ID: <880c7343-896d-4262-87e6-096dd54f948a@i32g2000pri.googlegroups.com> Tracubik wrote: > why the integer value doesn't change while the list value do? http://effbot.org/pyfaq/why-are-default-values-shared-between-objects.htm From beliavsky at aol.com Sat Nov 13 08:52:26 2010 From: beliavsky at aol.com (Beliavsky) Date: Sat, 13 Nov 2010 05:52:26 -0800 (PST) Subject: scipy code runs in empty directory, not another Message-ID: After installing numpy, scipy, and matplotlib for python 2.6 and running the code from http://www.scipy.org/Cookbook/OptimizationDemo1 (stored as xoptimize.py) in a directory with other python codes, I got the error messages C:\python\code\mycode>python xoptimize.py Traceback (most recent call last): File "xoptimize.py", line 3, in from pylab import * File "c:\python26\lib\site-packages\pylab.py", line 1, in from matplotlib.pylab import * File "c:\python26\lib\site-packages\matplotlib\__init__.py", line 133, in import sys, os, tempfile File "c:\python26\lib\tempfile.py", line 34, in from random import Random as _Random File "C:\python\code\mycode\random.py", line 1, in from RandomArray import standard_normal File "C:\python\code\mycode\RandomArray.py", line 1, in import ranlib ImportError: No module named ranlib When I create a new directory, copy xoptimize.py there, and run, the program works. Can someone explain why other files are "interfering" in the first case? Thanks. From bblais at bryant.edu Sat Nov 13 09:10:41 2010 From: bblais at bryant.edu (Brian Blais) Date: Sat, 13 Nov 2010 09:10:41 -0500 Subject: drawing with the mouse with turtle...solved? In-Reply-To: References: <4cdde466$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: <02F35119-461B-4FE4-B082-A5274B5998A4@bryant.edu> On Nov 12, 2010, at 8:48 PM, Brian Blais wrote: > > On Nov 12, 2010, at 8:05 PM, Steven D'Aprano wrote: > >> On Fri, 12 Nov 2010 19:24:50 -0500, Brian Blais wrote: >> >>> I'd like to draw on a turtle canvas, but use the mouse to direct the >>> turtle. I don't see a good way of getting the mouse coordinates and the >>> button state. >> >> I think the right way to do that is by creating an event handler to the >> turtle. These docs are for Python 2.7 turtle, but they may be applicable >> to older versions as well: >> >> http://docs.python.org/library/turtle.html#turtle.ondrag >> >> I quote: >> >>>>> turtle.ondrag(turtle.goto) >> >> Subsequently, clicking and dragging the Turtle will move it >> across the screen thereby producing handdrawings (if pen is down). >> >> >> That's probably all you need to do. > > > that's what I tried first, with no luck. I am on 2.6 on Mac OSX (Enthought distribution). The following code: > > > import turtle > > turtle.reset() > turtle.speed(0) > turtle.ondrag(turtle.goto) > turtle.pendown() > > running it in ipython brings up a window, but clicking, dragging, or anything like that doesn't move the turtle or draw anything. running it in just plain python brings up the window, but it instantly closes. I added: turtle.mainloop() > > which keeps the window open, but the clicking or dragging still doesn't move the turtle or update the window in any way. > Here is code that "works", with at least one small oddity: import turtle def gothere(event): turtle.penup() turtle.goto(event.x-360,340-event.y) turtle.pendown() def movearound(event): turtle.goto(event.x-360,340-event.y) def release(event): turtle.penup() def reset(event): turtle.clear() turtle.reset() turtle.speed(0) c=turtle.getcanvas() c.bind("", gothere) c.bind("", movearound) c.bind("", release) c.bind("",reset) s=turtle.Screen() s.listen() the oddity is that the coordinate transformations, x-360 and 340-y, are done by eye and do not seem to be related to any of the coordinate values I could find. my screen size is 300x400, the x and y canvas scales are 1 and 1, but if I try to transform with those numbers the mouse is clearly off. any ideas? bb -- Brian Blais bblais at bryant.edu http://web.bryant.edu/~bblais http://bblais.blogspot.com/ From chris.gonnerman at newcenturycomputers.net Sat Nov 13 09:12:05 2010 From: chris.gonnerman at newcenturycomputers.net (Chris Gonnerman) Date: Sat, 13 Nov 2010 08:12:05 -0600 Subject: [Python] scipy code runs in empty directory, not another In-Reply-To: References: Message-ID: <4CDE9CB5.3060208@newcenturycomputers.net> On 11/13/2010 07:52 AM, Beliavsky wrote: > After installing numpy, scipy, and matplotlib for python 2.6 and > running the code from http://www.scipy.org/Cookbook/OptimizationDemo1 > (stored as xoptimize.py) in a directory with other python codes, I got > the error messages > > C:\python\code\mycode>python xoptimize.py > Traceback (most recent call last): > File "xoptimize.py", line 3, in > from pylab import * > File "c:\python26\lib\site-packages\pylab.py", line 1, in > from matplotlib.pylab import * > File "c:\python26\lib\site-packages\matplotlib\__init__.py", line > 133, in > import sys, os, tempfile > File "c:\python26\lib\tempfile.py", line 34, in > from random import Random as _Random > File "C:\python\code\mycode\random.py", line 1, in > from RandomArray import standard_normal > File "C:\python\code\mycode\RandomArray.py", line 1, in > import ranlib > ImportError: No module named ranlib > > When I create a new directory, copy xoptimize.py there, and run, the > program works. Can someone explain why other files are "interfering" > in the first case? Thanks. You'd need to post a list of the files in the directory before we'd have any idea why this is happening. -- Chris. From deets at web.de Sat Nov 13 09:14:12 2010 From: deets at web.de (Diez B. Roggisch) Date: Sat, 13 Nov 2010 15:14:12 +0100 Subject: strange behavor.... References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <880c7343-896d-4262-87e6-096dd54f948a@i32g2000pri.googlegroups.com> Message-ID: alex23 writes: > Tracubik wrote: >> why the integer value doesn't change while the list value do? > > http://effbot.org/pyfaq/why-are-default-values-shared-between-objects.htm Not the issue here. The reason the OP sees a difference that there is only one way to pass parameters in python. There have been wars waged about the right name to call them. What's happening is that in the function, the parameter names are bound to the objects the caller passed in. But these names only exist in the scope of the function. So re-binding that name by doing e.g. a = 2 does not change the binding in the callers context. So because of this, no change happens in change_integer. Because there is no change to the integer itself. Actually, you can't even change an integer in pyhon. They are immutable. a = 2 a += 10 will make a point to the integer-object with the value 12. But the "old" 2 and 10 still exist. And that's where the differency in change_list is in. That gets passed a reference to a _mutable_ object, a list. And if you mutatet that list, you end up with a changed object in the callers context as well. Diez From deets at web.de Sat Nov 13 09:15:51 2010 From: deets at web.de (Diez B. Roggisch) Date: Sat, 13 Nov 2010 15:15:51 +0100 Subject: scipy code runs in empty directory, not another References: Message-ID: Beliavsky writes: > After installing numpy, scipy, and matplotlib for python 2.6 and > running the code from http://www.scipy.org/Cookbook/OptimizationDemo1 > (stored as xoptimize.py) in a directory with other python codes, I got > the error messages > > C:\python\code\mycode>python xoptimize.py > Traceback (most recent call last): > File "xoptimize.py", line 3, in > from pylab import * > File "c:\python26\lib\site-packages\pylab.py", line 1, in > from matplotlib.pylab import * > File "c:\python26\lib\site-packages\matplotlib\__init__.py", line > 133, in > import sys, os, tempfile > File "c:\python26\lib\tempfile.py", line 34, in > from random import Random as _Random > File "C:\python\code\mycode\random.py", line 1, in > from RandomArray import standard_normal > File "C:\python\code\mycode\RandomArray.py", line 1, in > import ranlib > ImportError: No module named ranlib > > When I create a new directory, copy xoptimize.py there, and run, the > program works. Can someone explain why other files are "interfering" > in the first case? Thanks. Because you probably have a file named the same way as some pyhon or matplotlib module, and that shadows the "real" one. Try copying more and more files into your new directory to find the culprit. Diez From benjamin.kaplan at case.edu Sat Nov 13 09:27:37 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sat, 13 Nov 2010 09:27:37 -0500 Subject: [Python] scipy code runs in empty directory, not another In-Reply-To: <4CDE9CB5.3060208@newcenturycomputers.net> References: <4CDE9CB5.3060208@newcenturycomputers.net> Message-ID: On Saturday, November 13, 2010, Chris Gonnerman wrote: > On 11/13/2010 07:52 AM, Beliavsky wrote: > > After installing numpy, scipy, and matplotlib for python 2.6 and > running the code from http://www.scipy.org/Cookbook/OptimizationDemo1 > (stored as xoptimize.py) in a directory with other python codes, I got > the error messages > > C:\python\code\mycode>python xoptimize.py > Traceback (most recent call last): > ? File "xoptimize.py", line 3, in > ? ? from pylab import * > ? File "c:\python26\lib\site-packages\pylab.py", line 1, in > ? ? from matplotlib.pylab import * > ? File "c:\python26\lib\site-packages\matplotlib\__init__.py", line > 133, in > ? ? import sys, os, tempfile > ? File "c:\python26\lib\tempfile.py", line 34, in > ? ? from random import Random as _Random > ? File "C:\python\code\mycode\random.py", line 1, in > ? ? from RandomArray import standard_normal > ? File "C:\python\code\mycode\RandomArray.py", line 1, in > ? ? import ranlib > ImportError: No module named ranlib > > When I create a new directory, copy xoptimize.py there, and run, the > program works. Can someone explain why other files are "interfering" > in the first case? Thanks. > > You'd need to post a list of the files in the directory before we'd have any idea why this is happening. No he doesn't. We can get that from the traceback. Bekiavsky, there's a file called random.py in your folder. Python doesn't treat the standard library fila any differently than it does your own files. It searches the path for the first file called "random" that it sees and it imports that. Since it finds your file first, that's the one it imports. The failure you're seeing is actually in your code-you're trying to import a module that shouldn't exist. In > > -- Chris. > > -- > http://mail.python.org/mailman/listinfo/python-list > From subhakolkata1234 at gmail.com Sat Nov 13 09:39:25 2010 From: subhakolkata1234 at gmail.com (joy99) Date: Sat, 13 Nov 2010 06:39:25 -0800 (PST) Subject: Some Machine Learning related questions Message-ID: <22c10f1d-ded5-46b3-bf7b-74492f12ca64@w38g2000pri.googlegroups.com> Dear Group, Hope every one is fine. I am trying to put some questions. I am developing some tool boxes for support vector machine (SVM) and hidden markov model (HMM). For HMM I was following the tutorial by Leeds University Computer Science Department, available online in HTML format, and for SVM I was following a book on Neural Networks by Simon Haykin. After comprehending them, I thought to cross check my knowledge with the original works. I referred to 1989 Rabiner paper for HMM and SVM society's tutorial for SVM. Here, I am getting some confusions. I am looking for a forum, especially an active forum, like this one (I searched for few in Google, but all seem to be very lazy), where I can post these questions. I felt this room consists of very expert people and I visit it often moreover it is very active -everytime I posed some question people solved it very nicely. If any one can suggest a solution to my queries taking his/her valuable time, I would be grateful enough. Thanks in advance. Apology if it is an unrelated question of the forum. Wishing you all a happy winter. Best Regards, Subhabrata. From mdw at distorted.org.uk Sat Nov 13 11:29:19 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Sat, 13 Nov 2010 16:29:19 +0000 Subject: strange behavor.... References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> Message-ID: <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> Tracubik writes: > >>> def change_integer(int_value): > ... int_value = 10 > ... > ... def change_list(list): > ... list[0] = 10 [...] > why the integer value doesn't change while the list value do? Because in the first case you changed a variable local to the function, and that variable was lost when the function returned; and in the second case, you modified the list value that was passed to the function. > in Pascal i can choose the behavour of parametres, how this work on > Python? You must learn to distinguish two notions to understand how this works in Python: the notions are /assigning a value to a variable/, and /mutating a value/. The former is what simple assignment `foo = ...' does: it makes the variable store a different value. Assigning a value to a function argument /never/ affects the caller in Python. It's simply not possible to write a `swap' function in Python. The latter means that a value itself changes but the relevant variables continue to store the same values. Alas, Python is actually slightly confusing here, since the same notation `=' sometimes means assignment and sometimes means mutation. You can tell which is which by looking at the left hand side: if it's a simple variable name, the variable is assigned a new value; if it's something more complicated (e.g., indexing (`foo[0]'), or attribute selection (`foo.bar') then some mutation is (probably) going to happen: these kinds of assignment are translated into method calls, so what actually happens is up to the object in question. It gets worse: compound assignment -- statements like `foo += ...' -- might either be mutation or assignment. What happens if the current value of `foo' has the an appropriate method is that the method is called, and probably mutates the value of foo; otherwise Python treats the statement as if it had been `foo = foo + (...)'. Returning, sort of, to the point: if you want to write a function which causes side-effects on its caller, then you have[1] to do it by mutating the caller's argument values. So you could write an awful `swap' function like def awful_swap(x, y): x[0], y[0] = y[0], x[0] and then you have to call it as xx = [x] yy = [y] awful_swap(xx, yy) x = xx[0] y = yy[0] but there's no good reason to actually do such a thing in Python when you can write x, y = y, x anyway. In Pascal, one tends to use `var' parameters to work around the fact that Pascal functions can only return a single value. This is true in Python too, but it isn't anywhere near as annoying because Python makes it easy (a) to combine multiple values together into a tuple (`return x, y, z') and (b) to pick tuples apart into their components again at the other end (`a, b, c = some_function()'). If you have a number of values which you find that you're combining and splitting apart repeatedly then maybe you're better off putting them together in a class with some appropriate operations. [1] In general; if the called function happens to be lexically enclosed in its caller, then it can play with its caller's variables directly -- well, in Python 3, anyway. -- [mdw] From davea at ieee.org Sat Nov 13 11:41:59 2010 From: davea at ieee.org (Dave Angel) Date: Sat, 13 Nov 2010 11:41:59 -0500 Subject: scipy code runs in empty directory, not another In-Reply-To: References: Message-ID: <4CDEBFD7.7040902@ieee.org> On 2:59 PM, Beliavsky wrote: > After installing numpy, scipy, and matplotlib for python 2.6 and > running the code from http://www.scipy.org/Cookbook/OptimizationDemo1 > (stored as xoptimize.py) in a directory with other python codes, I got > the error messages > > C:\python\code\mycode>python xoptimize.py > Traceback (most recent call last): > File "xoptimize.py", line 3, in > from pylab import * > File "c:\python26\lib\site-packages\pylab.py", line 1, in > from matplotlib.pylab import * > File "c:\python26\lib\site-packages\matplotlib\__init__.py", line > 133, in > import sys, os, tempfile > File "c:\python26\lib\tempfile.py", line 34, in > from random import Random as _Random > File "C:\python\code\mycode\random.py", line 1, in > from RandomArray import standard_normal > File "C:\python\code\mycode\RandomArray.py", line 1, in > import ranlib > ImportError: No module named ranlib > > When I create a new directory, copy xoptimize.py there, and run, the > program works. Can someone explain why other files are "interfering" > in the first case? Thanks. > You have a file random.py in your code directory, which is shadowing the system random library. DaveA From ra.ravi.rav at gmail.com Sat Nov 13 11:54:54 2010 From: ra.ravi.rav at gmail.com (Ravi) Date: Sat, 13 Nov 2010 08:54:54 -0800 (PST) Subject: sqlite3 doesn't raise exception if database is not present/inaccessible Message-ID: <0bed5b60-1985-4145-b084-346a5428e42d@i4g2000pro.googlegroups.com> try this: import sqlite3 con = sqlite3.connect("any string here") and there is no error reported. You will get an error you do some operations on the database which is confusing. I think sqlite3 should change this behavior. From usernet at ilthio.net Sat Nov 13 12:17:22 2010 From: usernet at ilthio.net (Tim Harig) Date: Sat, 13 Nov 2010 17:17:22 +0000 (UTC) Subject: sqlite3 doesn't raise exception if database is not present/inaccessible References: <0bed5b60-1985-4145-b084-346a5428e42d@i4g2000pro.googlegroups.com> Message-ID: On 2010-11-13, Ravi wrote: > import sqlite3 > con = sqlite3.connect("any string here") That is a property of the sqlite database itself. It always opens the database requested; even if it has to create a new database to do so. > and there is no error reported. You will get an error you do some If you are conserned about it, check that the database contains the schema that you were expecting before trying any other operations on it. > operations on the database which is confusing. I think sqlite3 should > change this behavior. If you believe that, you should talk to the sqlite3 people since this is a property of the database rather then a Python issue. From python at mrabarnett.plus.com Sat Nov 13 12:19:36 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 13 Nov 2010 17:19:36 +0000 Subject: sqlite3 doesn't raise exception if database is not present/inaccessible In-Reply-To: <0bed5b60-1985-4145-b084-346a5428e42d@i4g2000pro.googlegroups.com> References: <0bed5b60-1985-4145-b084-346a5428e42d@i4g2000pro.googlegroups.com> Message-ID: <4CDEC8A8.4090507@mrabarnett.plus.com> On 13/11/2010 16:54, Ravi wrote: > try this: > > import sqlite3 > con = sqlite3.connect("any string here") > > and there is no error reported. You will get an error you do some > operations on the database which is confusing. I think sqlite3 should > change this behavior. That will open an existing database or create a new one. If it raised an exception then how would you create a new database? From vlastimil.brom at gmail.com Sat Nov 13 12:55:35 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sat, 13 Nov 2010 18:55:35 +0100 Subject: regenerating unicodedata for py2.7 using py3 makeunicodedata.py? Message-ID: Hi all, I'd like to ask about a surprising possibility I found while investigating the new unicode 6.0 standard for use in python. As python 2 series won't be updated in this regard ( http://bugs.python.org/issue10400 ), I tried my "poor man's approach" of compiling the needed pyd file with the recent unicode data (cf. the older post http://mail.python.org/pipermail/python-list/2010-March/1240002.html ) While checking the changed format, i found to my big surprise, that it is possible to generate the header files using the py3 makeunicodedata.py which has already been updated for Unicode 6.0; this is even much more comfortable than the previous versions, as the needed data are downloaded automatically. http://svn.python.org/view/python/branches/py3k/Tools/unicode/makeunicodedata.py?view=markup&pathrev=85371 It turned out, that the resulting headers are accepted by MS Visual C++ Express along with the py2.7 source files and that the generated unicodedata.pyd seems to be working work at least in the cases I tested sofar. Is this intended or even guaranteed for these generated files to be compatible across py2.7 and py3, or am I going to be bitten by some less obvious issues later? The newly added ranges and characters are available, only in the CJK Unified Ideographs Extension D the character names are not present (while categories are), but this appears to be the same in the original unicodedadata with 5.2 on CJK Unified Ideographs Extension C. >>> unicodedata.unidata_version '6.0.0' >>> unicodedata.name(u"\U0002B740") # 0x2B740-0x2B81F; CJK Unified Ideographs Extension D # unicode 6.0 addition Traceback (most recent call last): File "", line 1, in ValueError: no such name >>> unicodedata.category(u"\U0002B740") 'Lo' >>> ########################### >>> unicodedata.unidata_version '5.2.0' >>> unicodedata.name(u"\U0002A700") # 0x2A700-0x2B73F; CJK Unified Ideographs Extension C Traceback (most recent call last): File "", line 1, in ValueError: no such name >>> unicodedata.category(u"\U0002A700") 'Lo' >>> Could please anybody confirm, whether this way of updating the unicodedata for 2.7 is generaly viable or point out possible problem this may lead to? Many thanks in advance, Vlastimil Brom From azeynel1 at gmail.com Sat Nov 13 13:53:56 2010 From: azeynel1 at gmail.com (Zeynel) Date: Sat, 13 Nov 2010 10:53:56 -0800 (PST) Subject: Is it possible to break a string literal into multiple lines? Message-ID: <3d0fefad-1152-4740-a164-b3803ce8eea6@29g2000prb.googlegroups.com> I have string formatting line in Google App Engine webframe webapp: self.response.out.write("%s:
mWEIGHT: %s
mDATE0_integer: %s
mCOUNT: %s
" % (result.mUNIQUE, result.mWEIGHT, mDATE0_integer, result.mCOUNT,)) I would like to be able to write it as self.response.out.write("%s:
mWEIGHT: %s
mDATE0_integer: %s
mCOUNT: %s
" % (result.mUNIQUE, result.mWEIGHT, mDATE0_integer, result.mCOUNT,)) But neither \ or enclosing the string in parens let me break the string literal enclosed in "" Is this possible? From jjposner at optimum.net Sat Nov 13 13:55:53 2010 From: jjposner at optimum.net (John Posner) Date: Sat, 13 Nov 2010 13:55:53 -0500 Subject: Question on Django and Django Book Message-ID: <4CDEDF39.1030805@optimum.net> I've started working, as a tech writer, for a Spanish software configuration management company. And I'm investigating the idea of releasing a user manual in the form of a wiki that supports paragraph-by-paragraph commenting. I looked at Django Book [1][2], but it's not clear to me how much of a Django wrangler I'd need to be to create and maintain a book that works the same way. It's not even clear to me if the technology supporting Django Book is available, maintained, etc. Also, maybe there's a non-Django solution that I haven't come across in my Googling. I'd appreciate guidance in any direction! Tx, John [1] http://www.djangobook.com/about/comments/ [2] http://www.djangobook.com/en/2.0/chapter12/ From tjreedy at udel.edu Sat Nov 13 14:00:39 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 13 Nov 2010 14:00:39 -0500 Subject: scipy code runs in empty directory, not another In-Reply-To: <4CDEBFD7.7040902@ieee.org> References: <4CDEBFD7.7040902@ieee.org> Message-ID: On 11/13/2010 11:41 AM, Dave Angel wrote: > On 2:59 PM, Beliavsky wrote: >> After installing numpy, scipy, and matplotlib for python 2.6 and >> running the code from http://www.scipy.org/Cookbook/OptimizationDemo1 >> (stored as xoptimize.py) in a directory with other python codes, I got >> the error messages >> >> C:\python\code\mycode>python xoptimize.py >> Traceback (most recent call last): >> File "xoptimize.py", line 3, in Learn to read tracebacks. They are your debugging friend. >> from pylab import * xoptimize imports pylab >> File "c:\python26\lib\site-packages\pylab.py", line 1, in >> from matplotlib.pylab import * pylab imports matplotlib >> File "c:\python26\lib\site-packages\matplotlib\__init__.py", line >> 133, in >> import sys, os, tempfile matplotlib imports tempfile (to get a plot destination) >> File "c:\python26\lib\tempfile.py", line 34, in >> from random import Random as _Random tempfile import random (to make a 'random' tempfile name) >> File "C:\python\code\mycode\random.py", line 1, in Look carefully at the above line. It should have been: File "C:\python26\lib\random.py ... Ignore the remaining error cascade. >> When I create a new directory, copy xoptimize.py there, and run, the >> program works. Can someone explain why other files are "interfering" >> in the first case? Thanks. >> > You have a file random.py in your code directory, which is shadowing the > system random library. As you can see in the traceback. -- Terry Jan Reedy From python at mrabarnett.plus.com Sat Nov 13 14:08:36 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 13 Nov 2010 19:08:36 +0000 Subject: Is it possible to break a string literal into multiple lines? In-Reply-To: <3d0fefad-1152-4740-a164-b3803ce8eea6@29g2000prb.googlegroups.com> References: <3d0fefad-1152-4740-a164-b3803ce8eea6@29g2000prb.googlegroups.com> Message-ID: <4CDEE234.5000802@mrabarnett.plus.com> On 13/11/2010 18:53, Zeynel wrote: > I have string formatting line in Google App Engine webframe webapp: > > self.response.out.write("%s:
mWEIGHT: %s
> mDATE0_integer: %s
mCOUNT: %s
" % (result.mUNIQUE, > result.mWEIGHT, mDATE0_integer, result.mCOUNT,)) > > I would like to be able to write it as > > self.response.out.write("%s:
> mWEIGHT: %s
> mDATE0_integer: %s
> mCOUNT: %s
" > % > (result.mUNIQUE, > > result.mWEIGHT, > > mDATE0_integer, > > result.mCOUNT,)) > > But neither \ or enclosing the string in parens let me break the > string literal enclosed in "" Is this possible? Use triple-quoted strings: self.response.out.write("""%s:
mWEIGHT: %s
mDATE0_integer: %s
mCOUNT: %s
""" (result.mUNIQUE, result.mWEIGHT, mDATE0_integer, result.mCOUNT,)) From cbrown at cbrownsystems.com Sat Nov 13 14:11:43 2010 From: cbrown at cbrownsystems.com (cbrown at cbrownsystems.com) Date: Sat, 13 Nov 2010 11:11:43 -0800 (PST) Subject: IDLE debugger questions References: <04a3c943-5aee-4248-9cb3-60ea424108cb@j4g2000prm.googlegroups.com> Message-ID: <25e32077-ccb1-488c-89c1-52d81372355e@r31g2000prg.googlegroups.com> On Oct 23, 7:29?am, Roger Davis wrote: > Are there any Python debuggers with a decent GUI out there at all that > will work on a Mac with the following features: (i) ability to pass in > a sys.srgv[] list that the program would otherwise see without the > debugger, (ii) display local variables, (iii) single-step through the > source code, and (iv) set a breakpoint? I think I can live without > anything else for the moment. > I'm very happy using the Eclipse IDE (available for Mac, PC and 'Nix) with the pydev plug-in. It's free, well supported and well behaved, and has all the debugging features you name and then some. It's also a modern code editor with code-hinting, syntax highlighting, etc. The only downside of Eclipse to me is its 'workspace' and 'project' metaphors for file organization; which take a bit of getting used to, particularly if you're used to just editing in a text editor, and then running in Idle or a command line. I still usually also have Idle open as well so I can test little code snippets quickly and easily; but mostly I work in Eclipse. Cheers - Chas From python.list at tim.thechases.com Sat Nov 13 14:14:27 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 13 Nov 2010 13:14:27 -0600 Subject: Is it possible to break a string literal into multiple lines? In-Reply-To: <3d0fefad-1152-4740-a164-b3803ce8eea6@29g2000prb.googlegroups.com> References: <3d0fefad-1152-4740-a164-b3803ce8eea6@29g2000prb.googlegroups.com> Message-ID: <4CDEE393.1000603@tim.thechases.com> On 11/13/2010 12:53 PM, Zeynel wrote: > I have string formatting line in Google App Engine webframe webapp: > > self.response.out.write("%s:
mWEIGHT: %s
> mDATE0_integer: %s
mCOUNT: %s
" % (result.mUNIQUE, > result.mWEIGHT, mDATE0_integer, result.mCOUNT,)) > > I would like to be able to write it as > > self.response.out.write("%s:
> mWEIGHT: %s
> mDATE0_integer: %s
> mCOUNT: %s
" > % > (result.mUNIQUE, > > result.mWEIGHT, > > mDATE0_integer, > > result.mCOUNT,)) > > But neither \ or enclosing the string in parens let me break the > string literal enclosed in "" Is this possible? Use python's triple-quoted strings: self.response.out.write("""%s:
mWEIGHT: %s ... ...
""") Or alternatively, you can do something like self.response.out.write( "%s:br />" "mWEIGHT: %s ..." ... "...
" ) (that excludes newlines and leading whitespace in the string that gets written, but you can modify the string contents to include them if you need/want) -tkc From tjreedy at udel.edu Sat Nov 13 14:19:19 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 13 Nov 2010 14:19:19 -0500 Subject: strange behavor.... In-Reply-To: <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On 11/13/2010 11:29 AM, Mark Wooding wrote: > Alas, Python is actually slightly confusing here, since the same > notation `=' sometimes means assignment and sometimes means mutation. I disagree somewhat. An object is mutated by an internal assignment. "ll[0] = 1" assigns 1 to the 0 slot of ll. "o.a = 1" assigns 1 to the 'a' attribute of o. This which might be implemented by assigning 1 to the 'a' slot of o.__dict__, just as "a=1" might be implemented by assigning 1 to the 'a' slot of a namespace dict. Assignment *always* binds an object to a target. Names are just one possible target. And, of course, assignment always mutates something -- a set of associations -- even if the 'something' is not a Python object itself. So '=' always means assignment/binding by mutation. The question is what gets bound to what in what set of associations. The rest of your post helps clarify that. -- Terry Jan Reedy From azeynel1 at gmail.com Sat Nov 13 14:35:48 2010 From: azeynel1 at gmail.com (Zeynel) Date: Sat, 13 Nov 2010 11:35:48 -0800 (PST) Subject: Is it possible to break a string literal into multiple lines? References: <3d0fefad-1152-4740-a164-b3803ce8eea6@29g2000prb.googlegroups.com> Message-ID: <2250d5a4-57b2-4dc0-bd84-b9cbcd9dab4f@b25g2000vbz.googlegroups.com> Tim Chase and MRAB: Thanks!! On Nov 13, 2:14?pm, Tim Chase wrote: > On 11/13/2010 12:53 PM, Zeynel wrote: > > > > > > > > > > > I have string formatting line in Google App Engine webframe webapp: > > > self.response.out.write("%s:
?mWEIGHT: %s
> > mDATE0_integer: %s
?mCOUNT: %s
" % (result.mUNIQUE, > > result.mWEIGHT, mDATE0_integer, result.mCOUNT,)) > > > I would like to be able to write it as > > > self.response.out.write("%s:
> > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?mWEIGHT: %s
> > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?mDATE0_integer: %s
> > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? mCOUNT: %s
" > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?% > > (result.mUNIQUE, > > > result.mWEIGHT, > > > mDATE0_integer, > > > result.mCOUNT,)) > > > But neither \ or enclosing the string in parens let me break the > > string literal enclosed in "" Is this possible? > > Use python's triple-quoted strings: > > ? ?self.response.out.write("""%s:
> ? ? ? ? mWEIGHT: %s ... > ? ? ? ? ...
""") > > Or alternatively, you can do something like > > ? ?self.response.out.write( > ? ? ?"%s:br />" > ? ? ?"mWEIGHT: %s ..." > ? ? ?... > ? ? ?"...
" > ? ? ?) > > (that excludes newlines and leading whitespace in the string that > gets written, but you can modify the string contents to include > them if you need/want) > > -tkc From dmitrey.kroshko at scipy.org Sat Nov 13 14:41:09 2010 From: dmitrey.kroshko at scipy.org (dmitrey) Date: Sat, 13 Nov 2010 11:41:09 -0800 (PST) Subject: namespace issue, Python vs numpy min/max problem Message-ID: <66c318f3-a659-40ec-ad17-74133639d573@h21g2000vbh.googlegroups.com> hi all, I have the following problem: I have overloaded "max" function in my module (FuncDesigner); it works like following: if some data in arguments is of type "oofun" then my function works, elseware numpy.max() is used. Now the problem: suppose someone writes from FuncDesigner import * ... a = max(0,1) so it calls FuncDesigner, it calls numpy.max and result is 0 (because in numpy it means "max of array with single element 0 along 1st axis"). But if user has not imported numpy then he expected calling ordinary Python max and thus result to be "1". Is there any way to get rid of the problem (somehow automatically determine which func should be used - numpy or Python max)? The same issue with "min", but they are equivalent, of course. From dmitrey.kroshko at scipy.org Sat Nov 13 14:55:21 2010 From: dmitrey.kroshko at scipy.org (dmitrey) Date: Sat, 13 Nov 2010 11:55:21 -0800 (PST) Subject: namespace issue, Python vs numpy min/max problem References: <66c318f3-a659-40ec-ad17-74133639d573@h21g2000vbh.googlegroups.com> Message-ID: <549a97c2-32ac-4b62-87fc-53f19657e293@w18g2000vbe.googlegroups.com> Well, I think I have found an appropriate solution. Regards, D. From mdw at distorted.org.uk Sat Nov 13 15:01:42 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Sat, 13 Nov 2010 20:01:42 +0000 Subject: strange behavor.... References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <87tyjlhu1l.fsf.mdw@metalzone.distorted.org.uk> Terry Reedy writes: > On 11/13/2010 11:29 AM, Mark Wooding wrote: > > > Alas, Python is actually slightly confusing here, since the same > > notation `=' sometimes means assignment and sometimes means mutation. > > I disagree somewhat. An object is mutated by an internal assignment. Some object types are primitive, provided by the runtime system; there are no `internal' variables to be assigned in these cases. (It is possible in principle in Python 3 to implement all of the compound data types using only assignment and closures.) > "ll[0] = 1" assigns 1 to the 0 slot of ll. > "o.a = 1" assigns 1 to the 'a' attribute of o. > This which might be implemented by assigning 1 to the 'a' slot of o.__dict__, > just as "a=1" might be implemented by assigning 1 to the 'a' slot of a > namespace dict. There's a qualitative difference here: simple assignment has semantics defined by the language and provided by the implementation, and can therefore be understood in isolation, using only lexically apparent information; whereas the complex assignments are implemented by invoking methods on the objects mentioned on the left hand side. The objects in question may choose not to implement some other semantics, so the runtime behaviour might not be determinable even in principle without actually executing the program. (Compound assignment has the same problem writ large.) > Assignment *always* binds an object to a target. No! Assignment /never/ binds. There is syntactic confusion here too, since Python interprets a simple assignment in a function body -- in the absence of a declaration such as `global' to the contrary -- as indicating that the variable in question should be bound to a fresh variable on entry to the function. But assignment itself doesn't perform binding. (This is a persistent error in the Python community; or, less charitably, the Python community gratuitously uses the word in a different sense from the wider programming-language-theory community. See Lisp literature passim, for example.) There's a two step mapping: names -> storage locations -> values. Binding affects the left hand part of the mapping; assignment affects the right hand part. -- [mdw] From bmjames at gmail.com Sat Nov 13 15:02:14 2010 From: bmjames at gmail.com (Ben James) Date: Sat, 13 Nov 2010 20:02:14 +0000 Subject: namespace issue, Python vs numpy min/max problem References: <66c318f3-a659-40ec-ad17-74133639d573@h21g2000vbh.googlegroups.com> <549a97c2-32ac-4b62-87fc-53f19657e293@w18g2000vbe.googlegroups.com> Message-ID: On 13/11/2010 19:55, dmitrey wrote: > Well, I think I have found an appropriate solution. > Regards, D. Hi Dmitrey, Would you mind briefly describing your solution? Thanks, Ben From ra.ravi.rav at gmail.com Sat Nov 13 15:07:09 2010 From: ra.ravi.rav at gmail.com (Ravi) Date: Sat, 13 Nov 2010 12:07:09 -0800 (PST) Subject: sqlite3 doesn't raise exception if database is not present/inaccessible References: <0bed5b60-1985-4145-b084-346a5428e42d@i4g2000pro.googlegroups.com> Message-ID: <6415c33b-af1e-48f6-8d9a-efd7b8981ae9@y2g2000prf.googlegroups.com> I understand it now. Thanks for the responses. From clp2 at rebertia.com Sat Nov 13 15:44:58 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 13 Nov 2010 12:44:58 -0800 Subject: strange behavor.... In-Reply-To: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> Message-ID: On Sat, Nov 13, 2010 at 5:46 AM, Tracubik wrote: > hi all, > i've this on python 2.6.6: > >>>> def change_integer(int_value): > ... ? ? int_value = 10 > ... > ... def change_list(list): > ... ? ? list[0] = 10 > ... > ... a = 1 > ... l = [1,1,1] > ... > ... change_integer(a) > ... change_list(l) > ... > ... print a > ... print l > 1 > [10, 1, 1] > > why the integer value doesn't change while the list value do? > in Pascal i can choose the behavour of parametres, how this work on Python? > also a link could be appreciated http://effbot.org/zone/call-by-object.htm Cheers, Chris From tjreedy at udel.edu Sat Nov 13 15:52:46 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 13 Nov 2010 15:52:46 -0500 Subject: namespace issue, Python vs numpy min/max problem In-Reply-To: <66c318f3-a659-40ec-ad17-74133639d573@h21g2000vbh.googlegroups.com> References: <66c318f3-a659-40ec-ad17-74133639d573@h21g2000vbh.googlegroups.com> Message-ID: On 11/13/2010 2:41 PM, dmitrey wrote: > hi all, > I have the following problem: > I have overloaded "max" function in my module (FuncDesigner); it works > like following: > if some data in arguments is of type "oofun" then my function works, > elseware numpy.max() is used. > > Now the problem: > suppose someone writes > from FuncDesigner import * Noone should do that unless your module is **explicitly** designed to be *-imported and you docuement that so that they know it is OK. Now you know why * import is generally discouraged ;-). -- Terry Jan Reedy From davea at ieee.org Sat Nov 13 15:54:31 2010 From: davea at ieee.org (Dave Angel) Date: Sat, 13 Nov 2010 15:54:31 -0500 Subject: strange behavor.... In-Reply-To: <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <4CDEFB07.6070702@ieee.org> On 2:59 PM, Mark Wooding wrote: > Tracubik writes: > >>>>> def change_integer(int_value): >> ... int_value = 10 >> ... >> > > Alas, Python is actually slightly confusing here, since the same > notation `=' sometimes means assignment and sometimes means mutation. > You can tell which is which by looking at the left hand side: if it's a > simple variable name, the variable is assigned a new value; if it's > something more complicated (e.g., indexing (`foo[0]'), or attribute > selection (`foo.bar') then some mutation is (probably) going to happen: No, an (=) assignment is always an assignment. It changes the item on the left hand side to refer to a new object. But if the item on the left hand side is not a simple variable, then generally only part of its contents refers to a new object, rather than the variable itself. For example, mylist[4] = "abc" is assigning a new object to a member of the list, but does not make a new list, replacing the whole list. Your other points, such as about the augmented assignment, are quite useful, however. DaveA From drsalists at gmail.com Sat Nov 13 16:27:36 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Sat, 13 Nov 2010 13:27:36 -0800 Subject: strange behavor.... In-Reply-To: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> Message-ID: On Sat, Nov 13, 2010 at 5:46 AM, Tracubik wrote: > hi all, > i've this on python 2.6.6: > > >>> def change_integer(int_value): > ... int_value = 10 > ... > ... def change_list(list): > ... list[0] = 10 > ... > ... a = 1 > ... l = [1,1,1] > ... > ... change_integer(a) > ... change_list(l) > ... > ... print a > ... print l > 1 > [10, 1, 1] > > why the integer value doesn't change while the list value do? > in Pascal i can choose the behavour of parametres, how this work on Python? > also a link could be appreciated > > Thanks in advance > Nico > -- > http://mail.python.org/mailman/listinfo/python-list > $ cat python-argument-passing #!/usr/bin/python def assign_int(x): print 'id(x) is %d' % id(x) x = 5 # x is now a totally different integer, which won't be reflected in # the caller, because id(x) has changed print 'id(x) is %d' % id(x) def assign_list(list_): # list_ is initially a copy of the reference to list_1 print 'id(list_) is %d' % id(list_) list_ = [ 'a', 'b', 'c' ] # list_ is no a reference to a totally different list, as indicated # by the change in id(). This too won't be reflected in the caller, # because id(list_) has changed print 'id(list_) is %d' % id(list_) def assign_list_element(list_): # list_ is initially a copy of the reference to list_2 print 'id(list_) is %d' % id(list_) list_[1] = 101 # list_ is still a copy of the reference to list_2 - we only changed # one thing in that list, not the list itself. This _will_ be reflected # in the caller, because we're still talking about the same list. print 'id(list_) is %d' % id(list_) x = 1 list_1 = [ 1, 2, 3 ] list_2 = [ 4, 5, 6 ] assign_int(x) print 'x after assign_int(x): %d' % x print assign_list(list_1) print 'list_1 after assign_list(list_1): %s' % list_1 print assign_list_element(list_2) print 'list_1 after assign_list_element(list_2): %s' % list_2 print print 'The author likes to think of all this as pass by value - but' print "when we pass a simple type like an int or float, we're passing" print "the object itself, while for collections of things we're still" print "passing the object itself, but that object _contains_ other things" print "which can easily be changed from the caller's perspective as well." benchbox-dstromberg:~/src/python-var-passing i686-pc-linux-gnu 10388 - above cmd done 2010 Sat Nov 13 01:26 PM $ ./python-argument-passing id(x) is 157519248 id(x) is 157519200 x after assign_int(x): 1 id(list_) is 3077596300 id(list_) is 3077683052 list_1 after assign_list(list_1): [1, 2, 3] id(list_) is 3077682092 id(list_) is 3077682092 list_1 after assign_list_element(list_2): [4, 101, 6] The author likes to think of all this as pass by value - but when we pass a simple type like an int or float, we're passing the object itself, while for collections of things we're still passing the object itself, but that object _contains_ other things which can easily be changed from the caller's perspective as well. benchbox-dstromberg:~/src/python-var-passing i686-pc-linux-gnu 10388 - above cmd done 2010 Sat Nov 13 01:26 PM HTH :) -------------- next part -------------- An HTML attachment was scrubbed... URL: From arnodel at gmail.com Sat Nov 13 16:35:09 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Sat, 13 Nov 2010 21:35:09 +0000 Subject: strange behavor.... References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> <87tyjlhu1l.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <87hbfk29gy.fsf@gmail.com> mdw at distorted.org.uk (Mark Wooding) writes: > Assignment /never/ binds. There is syntactic confusion here too, > since Python interprets a simple assignment in a function body -- in > the absence of a declaration such as `global' to the contrary -- as > indicating that the variable in question should be bound to a fresh > variable on entry to the function. But assignment itself doesn't > perform binding. (This is a persistent error in the Python community; > or, less charitably, the Python community gratuitously uses the word > in a different sense from the wider programming-language-theory > community. See Lisp literature passim, for example.) > > There's a two step mapping: names -> storage locations -> values. > Binding affects the left hand part of the mapping; assignment affects > the right hand part. I'm not sure the notion of "storage location" is useful in Python. I think I understand Python programs correctly using only the notions of "name" and "value" (or object). After execution of the statement: a = 1 The name "a" is bound to the object 1, which means that from then on "a" evaluates to 1. There is no need to know more. As you point out, statements like: a[3] = 1 a.b = 1 are different because they are really function calls, i.e. a.__setitem__(3, 1) a.__setattr__("b", 1) so there is not necessarily any "assigning" or "binding" involved. It is simply a widely followed convention that after the function call: a.__setitem__(3, 1) the function call: a.__getitem__(3) should return 1. Augmented assignment is a different kettle of fish altogether, and IMHO it is the one that confuses things a lot. -- Arnaud From steve at REMOVE-THIS-cybersource.com.au Sat Nov 13 16:38:46 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 13 Nov 2010 21:38:46 GMT Subject: strange behavor.... References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <880c7343-896d-4262-87e6-096dd54f948a@i32g2000pri.googlegroups.com> Message-ID: <4cdf0566$0$29990$c3e8da3$5496439d@news.astraweb.com> On Sat, 13 Nov 2010 05:50:40 -0800, alex23 wrote: > Tracubik wrote: >> why the integer value doesn't change while the list value do? > > http://effbot.org/pyfaq/why-are-default-values-shared-between- objects.htm Right website, wrong page :) http://effbot.org/zone/call-by-object.htm See also Wikipedia's page on parameter passing conventions: http://en.wikipedia.org/wiki/Evaluation_strategy -- Steven From mdw at distorted.org.uk Sat Nov 13 16:42:03 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Sat, 13 Nov 2010 21:42:03 +0000 Subject: strange behavor.... References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <87pqu8j3ys.fsf.mdw@metalzone.distorted.org.uk> Dave Angel writes: > No, an (=) assignment is always an assignment. No. In `foo[0] = bar' it's a method call in disguise. > It changes the item on the left hand side to refer to a new object. Not necessarily. It could do anything at all depending on the type of the recipient object. -- [mdw] From singhvanesa at gmail.com Sat Nov 13 16:52:57 2010 From: singhvanesa at gmail.com (Vanesa Singh) Date: Sat, 13 Nov 2010 13:52:57 -0800 (PST) Subject: want to start your own revenue generation site? Message-ID: <21b74914-5276-4ac3-8d61-3fb243694738@n24g2000prj.googlegroups.com> If you are willing to convert your groups into websites and want to earn huge revenue through your group network- do contact us- we have great service for group owners who has high number of members and messages. Start your own sms, joke, stories, news, jobs website and earn huge from your group user base and articles. We are dedicated php, ajax and open source programmers working in delhi, India. Looking for projects all over the world we can work on any projects in any regional language. We are looking for projects to work upon. If your company, hospital, school, college, non-profits need good interactive website and stores do contact us for services. We have special reduced prices for all non-profits. with warm regards nitin at nitinnaresh.com +91-8800302311 From chris.p.clark at ba.com Sat Nov 13 17:02:21 2010 From: chris.p.clark at ba.com (chris.p.clark at ba.com) Date: Sat, 13 Nov 2010 22:02:21 +0000 Subject: I am away Message-ID: I will be out of the office starting 12/11/2010 and will not return until 16/11/2010. contact Narinder Kumar 0208 738 8871 (narinder.kumar at ba.com) Ian Sherrington (88149) matthew page 0208 738 3519 (matthew.page at ba.com) Greg Lakin 0208 738 3469 (greg.t.lakin at ba.com) Christopher Bristow 208 738 6933 (chris.bristow at ba.com) -- This message is private and confidential and may also be legally privileged. If you have received this message in error, please email it back to the sender and immediately permanently delete it from your computer system. Please do not read, print, re-transmit, store or act in reliance on it or any attachments. British Airways may monitor email traffic data and also the content of emails, where permitted by law, for the purposes of security and staff training and in order to prevent or detect unauthorised use of the British Airways email system. Virus checking of emails (including attachments) is the responsibility of the recipient. British Airways Plc is a public limited company registered in England and Wales. Registered number: 1777777. Registered office: Waterside, PO Box 365, Harmondsworth, West Drayton, Middlesex, England, UB7 0GB. Additional terms and conditions are available on our website: www.ba.com From mdw at distorted.org.uk Sat Nov 13 17:22:00 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Sat, 13 Nov 2010 22:22:00 +0000 Subject: strange behavor.... References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> <87tyjlhu1l.fsf.mdw@metalzone.distorted.org.uk> <87hbfk29gy.fsf@gmail.com> Message-ID: <87hbfkj247.fsf.mdw@metalzone.distorted.org.uk> Arnaud Delobelle writes: > mdw at distorted.org.uk (Mark Wooding) writes: > > > Assignment /never/ binds. There is syntactic confusion here too, > > since Python interprets a simple assignment in a function body -- in > > the absence of a declaration such as `global' to the contrary -- as > > indicating that the variable in question should be bound to a fresh > > variable on entry to the function. But assignment itself doesn't > > perform binding. (This is a persistent error in the Python community; > > or, less charitably, the Python community gratuitously uses the word > > in a different sense from the wider programming-language-theory > > community. See Lisp literature passim, for example.) > > > > There's a two step mapping: names -> storage locations -> values. > > Binding affects the left hand part of the mapping; assignment affects > > the right hand part. > > I'm not sure the notion of "storage location" is useful in Python. We'll see. > I think I understand Python programs correctly using only the notions > of "name" and "value" (or object). Challenge: explain the following code using only those concepts. def foo(): l = [] for i in xrange(10): (lambda j: l.append((lambda: i, lambda: j)))(i) print [(f(), g()) for f, g in l] I explain this as follows. * Python's `for' loop works by assignment. The name `i' remains bound to the same storage location throughout; this binding is established on entry to the function. Since `i' is not rebound in any function lexically enclosed in `foo', every occurrence of `lambda: i' refers to this same storage location. At the end of the loop, this storage location contains the value 9. * The name `j' is rebound repeatedly: in each iteration of the `for' loop, the function `lambda j: ...' is invoked, binding `j' to a fresh storage location into which the value of `i' at the time is stored. Since the function `lambda: j' is lexically enclosed within this function, the name `j' refers to a different storage location in each of these functions, these storage locations are initialized with distinct values 0 up to 9, and they are never changed. * Therefore each `lambda: i' function, when called after the loop, outputs the same value 9; and each `lambda: j' function, when called after the loop, outputs a distinct value. -- [mdw] From steve at REMOVE-THIS-cybersource.com.au Sat Nov 13 17:32:39 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 13 Nov 2010 22:32:39 GMT Subject: strange behavor.... References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> <87tyjlhu1l.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <4cdf1206$0$29990$c3e8da3$5496439d@news.astraweb.com> On Sat, 13 Nov 2010 20:01:42 +0000, Mark Wooding wrote: > Terry Reedy writes: > >> On 11/13/2010 11:29 AM, Mark Wooding wrote: >> >> > Alas, Python is actually slightly confusing here, since the same >> > notation `=' sometimes means assignment and sometimes means mutation. >> >> I disagree somewhat. An object is mutated by an internal assignment. > > Some object types are primitive, provided by the runtime system; there > are no `internal' variables to be assigned in these cases. You seem to be making up your own terminology here, or at least using terminology that isn't normally used in the languages I'm used to. In OO languages such as Python, Java, and (I believe) Ruby, it is conventional to distinguish between objects and "primitives". Primitives are implemented as low-level C-like variables. In that sense, Python has no primitives. Ints, floats, etc. (which are primitives in Java) are full-blown objects in Python. If you mean "primitive" in the sense of "built-in", your conclusion is wrong. Such "primitive" types include dicts and lists, which are sophisticated container objects with internal "variables" to be assigned to: alist[0] = None assigns the value None to the first position in the list. Just because these "variables" aren't *named* variables doesn't mean they don't vary, or that they can't be assigned to. If you mean "primitive" in some other sense, I'm afraid I can't guess what you mean. >> "ll[0] = 1" assigns 1 to the 0 slot of ll. "o.a = 1" assigns 1 to the >> 'a' attribute of o. This which might be implemented by assigning 1 to >> the 'a' slot of o.__dict__, just as "a=1" might be implemented by >> assigning 1 to the 'a' slot of a namespace dict. > > There's a qualitative difference here: simple assignment has semantics > defined by the language and provided by the implementation, and can > therefore be understood in isolation, using only lexically apparent > information; whereas the complex assignments are implemented by invoking > methods on the objects mentioned on the left hand side. Again, you're using unfamiliar terminology. "Simple" and "complex" assignment -- I can guess you mean "name binding" = simple and "any other reference binding" = complex in Python terminology: name = value # simple assignment dict[key] = value # complex assignment obj.attr = value # complex The thing is, the semantics of assigning to built-in components are equally defined by the language as the semantics of name binding. If x is a built-in list or dict, the semantics of: x[something] = value is written in stone and part of the language semantics. Whether that is implemented by a method or not is an irrelevant implementation detail, but for what little it's worth, I believe the CPython implementation is written in a fully procedural fashion, with no methods in sight. One can write: [0, 1, 2, 3, 4][2] = 5 and the language semantics tell you *exactly* what will happen: the value of the list in position 2 will be unbound and the object 5 will be bound in its place. Who cares whether the *implementation* happens to be written as a C function or a Java method, or something else? You are right to point out that for arbitrary types: x[2] = 5 need not be an assignment, since if x is not a built-in x.__setitem__ will be called, and it may do anything it likes. By contrast, name binding: x = 5 *never* calls a method on any object, and therefore is fully defined by the language semantics. The distinction between the two count as an important proviso to the discussion: x[2] = 5 is only an assignment if the type of x is non-pathological and not broken. But putting aside such pathological cases, I don't think you can justify distinguishing between "simple" and "complex" assignment. Names are only one type of reference in Python, not the only one, and assignments other than name-binding can be fully understood from the language semantics *provided you know the type is a built-in*. >> Assignment *always* binds an object to a target. > > No! Assignment /never/ binds. A shocking claim that requires more explanation. If it doesn't bind, what does it do? > There is syntactic confusion here too, > since Python interprets a simple assignment in a function body -- in the > absence of a declaration such as `global' to the contrary -- as > indicating that the variable in question should be bound to a fresh > variable on entry to the function. Well, there seems to be some confusion here, but I don't think it's ours... local variables in functions aren't bound on *entry* to the function. How could they be? They are bound *when the assignment is executed*, which may be never -- hence it is possible to get an UnboundLocalError exception, if you try to retrieve the value of a local which hasn't yet had a value bound to it. > But assignment itself doesn't > perform binding. (This is a persistent error in the Python community; > or, less charitably, the Python community gratuitously uses the word in > a different sense from the wider programming-language-theory community. > See Lisp literature passim, for example.) *Less* charitably? I'm sorry, you think that being *wrong* is better than being *different*? That's not a moral judgment I can agree with. > There's a two step mapping: names -> storage locations -> values. > Binding affects the left hand part of the mapping; assignment affects > the right hand part. That gratuitously conflates the implementation ("storage locations") with the interface. Objects in Python have no storage location, they float in the aether, free to move if the implementation chooses to move them... the CPython implementation doesn't, but some other implementation might do so, but either way *you can't tell the difference* from Python. There is nothing you can write in pure Python that can tell whether the storage location of an object has changed, or even whether "storage location" is a well-defined concept. Nothing in the semantics of Python demand that objects must be implemented as single contiguous blocks of data with a well-defined location. If you can think of an alternative, you're free to write an implementation that uses it. The closest you can come is that CPython exposes the memory location as the id(), but that's not a language promise: Jython and IronPython do not. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Nov 13 17:38:46 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 13 Nov 2010 22:38:46 GMT Subject: namespace issue, Python vs numpy min/max problem References: <66c318f3-a659-40ec-ad17-74133639d573@h21g2000vbh.googlegroups.com> Message-ID: <4cdf1376$0$29990$c3e8da3$5496439d@news.astraweb.com> On Sat, 13 Nov 2010 11:41:09 -0800, dmitrey wrote: > hi all, > I have the following problem: > I have overloaded "max" function in my module (FuncDesigner); it works > like following: > if some data in arguments is of type "oofun" then my function works, > elseware numpy.max() is used. > > Now the problem: > suppose someone writes > from FuncDesigner import * > ... > a = max(0,1) > > so it calls FuncDesigner, it calls numpy.max and result is 0 (because in > numpy it means "max of array with single element 0 along 1st axis"). > But if user has not imported numpy then he expected calling ordinary > Python max and thus result to be "1". That's not your problem, that's the caller's problem. He shouldn't be calling import * unless he wants to import everything in your module directly into his namespace. If the caller said to you: "After executing len = x, I can't access the built-in len function any more, can you change x so that it magically tells when I want the built- in behaviour and does that?" you'd probably tell him to get lost. Doing import * is no different. It only becomes your problem if you have advised people that the right way to use your module is with import *. > Is there any way to get rid of the problem (somehow automatically > determine which func should be used - numpy or Python max)? The same > issue with "min", but they are equivalent, of course. Automatically? No. -- Steven From martin at v.loewis.de Sat Nov 13 17:40:34 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Sat, 13 Nov 2010 23:40:34 +0100 Subject: regenerating unicodedata for py2.7 using py3 makeunicodedata.py? In-Reply-To: References: Message-ID: > Is this intended or even guaranteed for these generated files to be > compatible across py2.7 and py3, or am I going to be bitten by some > less obvious issues later? It works because the generated files are just arrays of structures, and these structures are the same in 2.7 and 3.2. However, there is no guarantee about this property: you will need to check for changes to unicodedata.c to see whether they may affect compatibility. Regards, Martin From steve at REMOVE-THIS-cybersource.com.au Sat Nov 13 17:46:17 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 13 Nov 2010 22:46:17 GMT Subject: strange behavor.... References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> <87pqu8j3ys.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <4cdf1538$0$29990$c3e8da3$5496439d@news.astraweb.com> On Sat, 13 Nov 2010 21:42:03 +0000, Mark Wooding wrote: > Dave Angel writes: > >> No, an (=) assignment is always an assignment. > > No. In `foo[0] = bar' it's a method call in disguise. How does that imply that can't also be an assignment? Of course, you're correct that it's not *necessarily* an assignment, if the type of foo is a pathological or broken class that does weird things on __setitem__. We tend to gloss over that in discussions, in the same way that we gloss over the fact that: len([1,2,3]) does not necessarily return 3, but could in fact do *anything*, depending on whether or not len is still the built-in function or not. I don't think it helps to overload newbies struggling with the basics with such pathological cases though. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Nov 13 17:52:52 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 13 Nov 2010 22:52:52 GMT Subject: strange behavor.... References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <4cdf16c4$0$29990$c3e8da3$5496439d@news.astraweb.com> On Sat, 13 Nov 2010 14:37:44 -0800, Dennis Lee Bieber wrote: > On Sat, 13 Nov 2010 16:29:19 +0000, mdw at distorted.org.uk (Mark Wooding) > declaimed the following in gmane.comp.python.general: > > >> to a function argument /never/ affects the caller in Python. It's >> simply not possible to write a `swap' function in Python. The latter >> means that a value itself changes but the relevant variables continue >> to store the same values. >> > I disagree (borrowing FORTRAN and Ada terms)... > > You can not write a "swap" PROCEDURE in Python... PROCEDUREs do not > return values except via side-effects on the arguments. FUNCTIONs > however, do return values as the function result... Ha, excellent point! But in fairness, in context he was talking about a function that operates purely by side-effects -- what Pascal, Fortran or Ada would call a procedure. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Nov 13 17:55:16 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 13 Nov 2010 22:55:16 GMT Subject: drawing with the mouse with turtle References: <4cdde466$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4cdf1754$0$29990$c3e8da3$5496439d@news.astraweb.com> On Sat, 13 Nov 2010 06:22:59 -0500, Brian Blais wrote: > there is no change by changing the order, but I didn't expect one. > since ondrag is binding a callback, which is only called when the event > happens, I figure that the pen has to be down when the callback happens, > not when the binding occurs. since the pen is down (and never lifted), > when I start dragging the mouse around after that it should work...but > doesn't seem to. Can you tell if your callback is being called at all? In other words, can you distinguish between these? * the callback isn't being called; * the callback is being called, but nothing is being drawn. -- Steven From benjamin at python.org Sat Nov 13 18:08:10 2010 From: benjamin at python.org (Benjamin Peterson) Date: Sat, 13 Nov 2010 17:08:10 -0600 Subject: [RELEASED] Python 3.1.3 release candidate 1 Message-ID: On behalf of the Python development team, I'm gladsome to announce a release candidate of the third bugfix release for the Python 3.1 series, Python 3.1.3. This bug fix release fixes numerous issues found in 3.1.2. Please try it with your packages and report any bugs you find. The final of 3.1.3 is scheduled to be released in two weeks. The Python 3.1 version series focuses on the stabilization and optimization of the features and changes that Python 3.0 introduced. For example, the new I/O system has been rewritten in C for speed. File system APIs that use unicode strings now handle paths with undecodable bytes in them. Other features include an ordered dictionary implementation, a condensed syntax for nested with statements, and support for ttk Tile in Tkinter. For a more extensive list of changes in 3.1, see http://doc.python.org/3.1/whatsnew/3.1.html or Misc/NEWS in the Python distribution. To download Python 3.1.3 visit: http://www.python.org/download/releases/3.1.3/ A list of changes in 3.1.3 can be found here: http://svn.python.org/projects/python/tags/r313rc1/Misc/NEWS The 3.1 documentation can be found at: http://docs.python.org/3.1 Bugs can always be reported to: http://bugs.python.org Enjoy! -- Benjamin Peterson Release Manager benjamin at python.org (on behalf of the entire python-dev team and 3.1.3's contributors) From steve at REMOVE-THIS-cybersource.com.au Sat Nov 13 18:09:18 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 13 Nov 2010 23:09:18 GMT Subject: drawing with the mouse with turtle...solved? References: <4cdde466$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4cdf1a9e$0$29990$c3e8da3$5496439d@news.astraweb.com> On Sat, 13 Nov 2010 09:10:41 -0500, Brian Blais wrote: > Here is code that "works", with at least one small oddity: > > import turtle > > def gothere(event): > turtle.penup() > turtle.goto(event.x-360,340-event.y) > turtle.pendown() > > def movearound(event): > turtle.goto(event.x-360,340-event.y) [...] > the oddity is that the coordinate transformations, x-360 and 340-y, are > done by eye and do not seem to be related to any of the coordinate > values I could find. my screen size is 300x400, the x and y canvas > scales are 1 and 1, but if I try to transform with those numbers the > mouse is clearly off. Have you set the coordinates of the screen? screen.setworldcoordinates What do turtle.window_height() and turtle.window_width() return? -- Steven From benjamin at python.org Sat Nov 13 18:12:22 2010 From: benjamin at python.org (Benjamin Peterson) Date: Sat, 13 Nov 2010 17:12:22 -0600 Subject: [RELEASED] Python 2.7.1 release candidate 1 Message-ID: On behalf of the Python development team, I'm chuffed to announce the a release candidate of Python 2.7.1. Please test the release candidate with your packages and report any bugs you find. 2.7.1 final is scheduled in two weeks. 2.7 includes many features that were first released in Python 3.1. The faster io module, the new nested with statement syntax, improved float repr, set literals, dictionary views, and the memoryview object have been backported from 3.1. Other features include an ordered dictionary implementation, unittests improvements, a new sysconfig module, auto-numbering of fields in the str/unicode format method, and support for ttk Tile in Tkinter. For a more extensive list of changes in 2.7, see http://doc.python.org/dev/whatsnew/2.7.html or Misc/NEWS in the Python distribution. To download Python 2.7.1 visit: http://www.python.org/download/releases/2.7.1/ The 2.7.1 changelog is at: http://svn.python.org/projects/python/tags/r271rc1/Misc/NEWS 2.7 documentation can be found at: http://docs.python.org/2.7/ This is a testing release, so we encourage developers to test it with their applications and libraries. Please report any bugs you find, so they can be fixed in the final release. The bug tracker is at: http://bugs.python.org/ Enjoy! -- Benjamin Peterson Release Manager benjamin at python.org (on behalf of the entire python-dev team and 2.7.1's contributors) From arnodel at gmail.com Sat Nov 13 18:14:22 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Sat, 13 Nov 2010 23:14:22 +0000 Subject: strange behavor.... References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> <87tyjlhu1l.fsf.mdw@metalzone.distorted.org.uk> <87hbfk29gy.fsf@gmail.com> <87hbfkj247.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <87d3q824vl.fsf@gmail.com> mdw at distorted.org.uk (Mark Wooding) writes: > Arnaud Delobelle writes: >> I think I understand Python programs correctly using only the notions >> of "name" and "value" (or object). > > Challenge: explain the following code using only those concepts. > > def foo(): > l = [] > for i in xrange(10): > (lambda j: l.append((lambda: i, lambda: j)))(i) > print [(f(), g()) for f, g in l] > > I explain this as follows. > > * Python's `for' loop works by assignment. The name `i' remains bound > to the same storage location throughout; this binding is established > on entry to the function. Since `i' is not rebound in any function > lexically enclosed in `foo', every occurrence of `lambda: i' refers > to this same storage location. At the end of the loop, this storage > location contains the value 9. I don't need "storage locations". All occurences of the name "i" in the code above belong the the namespace local to the function "foo". > * The name `j' is rebound repeatedly: in each iteration of the `for' > loop, the function `lambda j: ...' is invoked, binding `j' to a > fresh storage location into which the value of `i' at the time is > stored. Since the function `lambda: j' is lexically enclosed within > this function, the name `j' refers to a different storage location > in each of these functions, these storage locations are initialized > with distinct values 0 up to 9, and they are never changed. I don't need "storage locations" to explain this. At each iteration a new lambda function (with a new local namespace) is created and the name "j" belongs to the namespace which is local to the lambda being created. Upon call of the lambda, "j" is bound to the current value of "i". So at each iteration, assignment to "j" is performed in a different namespace. You can argue that I use the notion of "namespace" to explain what you do with "storage locations". However, even with the notion of storage location, you *still* need the notion of namespace to understand Python (see the "lexically enclosed within this function" above). So I still maintain that "storage location" is a superfluous notion in Python. To put it another way, when you say: Two occurences of the name "a" are bound to the same storage location I say: Two occurences of the name "a" belong to the same namespace These are equivalent models (in the sense that they will interpret Python code in the same way), but in order to find out whether two occurences of a name are bound to the same storage location, you need to check whether the names belong to the same namespace! -- Arnaud From mdw at distorted.org.uk Sat Nov 13 18:28:36 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Sat, 13 Nov 2010 23:28:36 +0000 Subject: strange behavor.... References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> <87tyjlhu1l.fsf.mdw@metalzone.distorted.org.uk> <4cdf1206$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: <877hggiz17.fsf.mdw@metalzone.distorted.org.uk> Steven D'Aprano writes: > On Sat, 13 Nov 2010 20:01:42 +0000, Mark Wooding wrote: > > Some object types are primitive, provided by the runtime system; > > there are no `internal' variables to be assigned in these cases. > > You seem to be making up your own terminology here, or at least using > terminology that isn't normally used in the languages I'm used to. I was attempting to define possibly unfamiliar terms as I went along. Did you not notice? > If you mean "primitive" in the sense of "built-in", your conclusion is > wrong. Such "primitive" types include dicts and lists, Yes, those are precisely the ones I was thinking of. > which are sophisticated container objects with internal "variables" to > be assigned to: They have internal state. I don't think that internal state consists of (Python) variables, though. This is why I brought up the possibility of a pure Python implementation, maintaining its state by assigning to variables captured using closures. > > There's a qualitative difference here: simple assignment has semantics > > defined by the language and provided by the implementation, and can > > therefore be understood in isolation, using only lexically apparent > > information; whereas the complex assignments are implemented by invoking > > methods on the objects mentioned on the left hand side. > > Again, you're using unfamiliar terminology. I'm sorry. I thought I defined those terms recently. (It appears not. Sorry.) I meant to refer to assignments in which the target is an identifier (to use the actual terminology from the manual). > "Simple" and "complex" assignment -- I can guess you mean "name > binding" = simple and "any other reference binding" = complex in > Python terminology: Again: assignment is not binding. See the explanation below. > The thing is, the semantics of assigning to built-in components are > equally defined by the language as the semantics of name binding. Did you read what I said? > You are right to point out that for arbitrary types: > > x[2] = 5 > > need not be an assignment, Good. This was /precisely/ what I was pointing out: determining /whether/ the value named by an identifier inhabits one of the built-in types is, in general, hard. > The distinction between the two count as an important proviso to the > discussion: x[2] = 5 is only an assignment if the type of x is > non-pathological and not broken. The latter is not an assignment: it's a disguised method call. > But putting aside such pathological cases, I don't think you can justify > distinguishing between "simple" and "complex" assignment. To conflate them is to confuse two different levels of meaning. Simple assignments occur because the language is hard-wired that way; complex assignments are disguised method calls which often mutate values. > Names are only one type of reference in Python, not the only one, and > assignments other than name-binding can be fully understood from the > language semantics *provided you know the type is a built-in*. > >> Assignment *always* binds an object to a target. > > > > No! Assignment /never/ binds. > > A shocking claim that requires more explanation. If it doesn't bind, > what does it do? Duh! It assigns. You're not usually this slow. Fortunately I explain below. > > There is syntactic confusion here too, since Python interprets a > > simple assignment in a function body -- in the absence of a > > declaration such as `global' to the contrary -- as indicating that > > the variable in question should be bound to a fresh variable on > > entry to the function. > > Well, there seems to be some confusion here, but I don't think it's > ours... local variables in functions aren't bound on *entry* to the > function. How could they be? They are bound *when the assignment is > executed*, which may be never -- hence it is possible to get an > UnboundLocalError exception, if you try to retrieve the value of a local > which hasn't yet had a value bound to it. The exception name perpetuates the misunderstanding, alas; but it's traditional, from Lisp, to say that a variable is `unbound' if it contains no value. > > But assignment itself doesn't perform binding. (This is a > > persistent error in the Python community; or, less charitably, the > > Python community gratuitously uses the word in a different sense > > from the wider programming-language-theory community. See Lisp > > literature passim, for example.) > > *Less* charitably? I'm sorry, you think that being *wrong* is better > than being *different*? That's not a moral judgment I can agree with. Being wrong is perhaps justifiable, and is rectifiable by learning. Being gratuitously different in such a case is to intentionally do a disservice to those coming from or going to other communities where they encounter more conventional uses for the terms in question. > > There's a two step mapping: names -> storage locations -> values. > > Binding affects the left hand part of the mapping; assignment affects > > the right hand part. > > That gratuitously conflates the implementation ("storage locations") There isn't a common term for that concept. I chose `storage location' because it's the term I remember seeing in the denotational semantics for Scheme. The phrase `bound to fresh locations' occurs frequently elsewhere in the Scheme report. It seemed apt. Choose some other term if you please; I merely wanted a term to describe a concept. > with the interface. Objects in Python have no storage location, And now you're confusing `storage locations' (whatever you choose to call them) with values (or `objects'), when my point was precisely that the two are different. > There is nothing you can write in pure Python that can tell whether the > storage location of an object has changed Indeed. Several locations may contain the same value. I remembered that the term `reference' was controversial so I avoided using it. ;-) > or even whether "storage location" is a well-defined concept. I disagree; though it can be a little subtle. Consider: def make_cell(x): def s(y): nonlocal x; x = y return lambda: x, s def copy_cell(c): g, s = c return lambda: g(), lambda y: s(y) Given two such cells (g, s) and (gg, ss), we can determine whether they use the same storage location or not, despite possibly having been constructed using copy_cell, perhaps one from the other, or perhaps (indirectly) from a common proper ancestor. def same_location_p(g, s, gg, ss): fresh = object() old = g() try: s(fresh) return gg() is fresh finally: s(old) Because of `copy_cell' you can't use `id' to solve this problem (at least not without doing serious poking about inside code objects). > Nothing in the semantics of Python demand that objects must be > implemented as single contiguous blocks of data with a well-defined > location. Indeed. I didn't claim otherwise. > The closest you can come is that CPython exposes the memory location > as the id(), but that's not a language promise: Jython and IronPython > do not. No. `id' reveals object identity. The clue is in the name. -- [mdw] From mdw at distorted.org.uk Sat Nov 13 18:32:50 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Sat, 13 Nov 2010 23:32:50 +0000 Subject: strange behavor.... References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <8739r4iyu5.fsf.mdw@metalzone.distorted.org.uk> Dennis Lee Bieber writes: > def swapFunc(a, b): > return b, a That's not what a `swap' function should do. > > Alas, Python is actually slightly confusing here, since the same > > notation `=' sometimes means assignment and sometimes means mutation. > > "=" means just one thing, a rebinding of some identifier to a > different object. Names aren't bound to objects. See elsewhere. > Or, in more general, "=" rebinds the fully qualified name to a > different object, which has the result of mutating a partially qualified > name (a name whose suffix has be removed). Names aren't mutated at all. Values (or, synonymously, objects) are mutated. -- [mdw] From mdw at distorted.org.uk Sat Nov 13 18:40:36 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Sat, 13 Nov 2010 23:40:36 +0000 Subject: strange behavor.... References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> <87pqu8j3ys.fsf.mdw@metalzone.distorted.org.uk> <4cdf1538$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87y68whjwr.fsf.mdw@metalzone.distorted.org.uk> Steven D'Aprano writes: > On Sat, 13 Nov 2010 21:42:03 +0000, Mark Wooding wrote: > > > Dave Angel writes: > > > >> No, an (=) assignment is always an assignment. > > > > No. In `foo[0] = bar' it's a method call in disguise. > > How does that imply that can't also be an assignment? Is `splat(34)' an assignment? If so, I think the term's meaning is grievously diluted. I'd rather say that `splat(34)' might mutate a value, or have side effects, and reserve the term `assignment' for the job of explaining how variables work. That seems pretty tricky, because we're arguing about it a lot, so I think we need sharply defined concepts so that we don't get more confused than we have to be. > Of course, you're correct that it's not *necessarily* an assignment, [...] > I don't think it helps to overload newbies struggling with the basics > with such pathological cases though. I think that we're better off giving `newbies' a conceptual framework which is robust, so that they can understand pathological situations when they occur. -- [mdw] From vlastimil.brom at gmail.com Sat Nov 13 19:10:47 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sun, 14 Nov 2010 01:10:47 +0100 Subject: regenerating unicodedata for py2.7 using py3 makeunicodedata.py? In-Reply-To: References: Message-ID: 2010/11/13 Martin v. Loewis : >> Is this intended or even guaranteed for these generated files to be >> compatible across py2.7 and py3, or am I going to be bitten by some >> less obvious issues later? > > It works because the generated files are just arrays of structures, > and these structures are the same in 2.7 and 3.2. However, there is > no guarantee about this property: you will need to check for changes > to unicodedata.c to see whether they may affect compatibility. > > Regards, > Martin > -- > http://mail.python.org/mailman/listinfo/python-list > Thanks for the confirmation Martin! Do you think, it the mentioned omission of the character names of some CJK ranges in unicodedata intended, or should it be reported to the tracker? Regards, Vlastimil Brom From robert.kern at gmail.com Sat Nov 13 19:13:02 2010 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 13 Nov 2010 18:13:02 -0600 Subject: Some Machine Learning related questions In-Reply-To: <22c10f1d-ded5-46b3-bf7b-74492f12ca64@w38g2000pri.googlegroups.com> References: <22c10f1d-ded5-46b3-bf7b-74492f12ca64@w38g2000pri.googlegroups.com> Message-ID: On 2010-11-13 08:39 , joy99 wrote: > I am looking for a forum, especially an active forum, like this one (I > searched for few in Google, but all seem to be very lazy), where I can > post these questions. http://stats.stackexchange.com/ -- 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 steve at REMOVE-THIS-cybersource.com.au Sat Nov 13 21:07:57 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 14 Nov 2010 02:07:57 GMT Subject: strange behavor.... References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> <87tyjlhu1l.fsf.mdw@metalzone.distorted.org.uk> <87hbfk29gy.fsf@gmail.com> <87hbfkj247.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <4cdf447d$0$29990$c3e8da3$5496439d@news.astraweb.com> On Sat, 13 Nov 2010 22:22:00 +0000, Mark Wooding wrote: > Challenge: explain the following code using only those concepts. ("those concepts" being name and value/object) > def foo(): > l = [] > for i in xrange(10): > (lambda j: l.append((lambda: i, lambda: j)))(i) > print [(f(), g()) for f, g in l] >>> foo() [(9, 0), (9, 1), (9, 2), (9, 3), (9, 4), (9, 5), (9, 6), (9, 7), (9, 8), (9, 9)] Here's a slightly less condensed version that demonstrates the same behaviour, but may be slightly easier to understand: def spam(): a = [] b = [] for i in xrange(5): a.append(lambda: i) b.append(lambda i=i: i) print [f() for f in a] print [f() for f in b] Anyway, here goes... In your function foo, the name "i" is bound to the objects 0, 1, 2, ... 9 sequentially, each time around the for-loop. Inside the loop, a function object is created and then called: (lambda j: l.append((lambda: i, lambda: j)))(i) (Aside: this depends on scoping rules that were introduced quite late in Python's history -- prior to version 2.2, this wouldn't work at all.) The "outer" lambda: lambda j: l.append(...) has a name in the function namespace (a "local variable") called "j". On entry to this function, this j is bound to the same object which is bound to i *at the time that the function is called*. That is, each of the sequence of "outer" lambdas get a distinct j = 0, 1, 2, ... What does these outer lambdas do? They create two more function objects, which I will label "A" and "B": A:: lambda: i B:: lambda: j and places those function objects in a tuple and appends the tuple to the list. What do these "inner" functions do? They have no local variable of their own -- they refer only the i and j of their enclosing scope, namely the "outer" lambda that created them. Note that there isn't actually a single A and a single B, there is a whole series of them... we might label them A0, A1, A2, ... etc. None of the function A0, A1, A2, ... have any local variable i. When you call them, Python looks in the enclosing scopes for a variable i. It doesn't find one in the "outer" lambda, so it next searches the namespace of foo, where it finds the name i bound to the object 9. Hence the inner lambdas Ai always return 9, since 9 is the value of i when the function is called. Functions B0, B1, B2, ... similarly have no local variable j. When you call any of the Bs, Python looks in the enclosing scopes for a variable j. However, in this case it *does* find one, in the "outer" lambda, where the name j has been bound to some object which was determined at the time "outer" was called, namely the value of i *at the time*, and hence 0, 1, 2, ... depending on which specific function you're looking at. Hence the inner lambda Bi returns the value of i *at the time it was defined*. > I explain this as follows. > > * Python's `for' loop works by assignment. The name `i' remains bound > to the same storage location throughout; This is not necessarily true. It's true for CPython, where function locals are implemented as fixed slots in the function object; since the slot doesn't move relative to the function, and the function doesn't move relative to the heap, the name i is in a fixed storage location for the life of foo. But that's not necessarily the case for all implementations -- locals could be stored in a data structure that moves data around (say, a red-black tree), or objects could be free to move in the heap, or both. -- Steven From subhakolkata1234 at gmail.com Sat Nov 13 21:35:52 2010 From: subhakolkata1234 at gmail.com (joy99) Date: Sat, 13 Nov 2010 18:35:52 -0800 (PST) Subject: Some Machine Learning related questions References: <22c10f1d-ded5-46b3-bf7b-74492f12ca64@w38g2000pri.googlegroups.com> Message-ID: <56ce2ba4-00d1-41f7-9d1a-92366703728c@w38g2000pri.googlegroups.com> On Nov 13, 7:39?pm, joy99 wrote: > Dear Group, > > Hope every one is fine. > > I am trying to put some questions. > > I am developing some tool boxes for support vector machine (SVM) and > hidden markov model (HMM). > For HMM I was following the tutorial by Leeds University Computer > Science Department, available online in HTML format, and for SVM I was > following a book on Neural Networks by Simon Haykin. > > After comprehending them, I thought to cross check my knowledge with > the original works. I referred to 1989 Rabiner paper for HMM and SVM > society's tutorial for SVM. > > Here, I am getting some confusions. > > I am looking for a forum, especially an active forum, like this one (I > searched for few in Google, but all seem to be very lazy), where I can > post these questions. > > I felt this room consists of very expert people and I visit it often > moreover it is very active -everytime I posed some question people > solved it very nicely. > > If any one can suggest a solution to my queries taking his/her > valuable time, I would be grateful enough. > > Thanks in advance. > > Apology if it is an unrelated question of the forum. > > Wishing you all a happy winter. > > Best Regards, > Subhabrata. Thanx Robert, It seems a good site. Wishing You A Happy Day Ahead, Best Regards, Subhabrata. From wuwei23 at gmail.com Sat Nov 13 22:20:20 2010 From: wuwei23 at gmail.com (alex23) Date: Sat, 13 Nov 2010 19:20:20 -0800 (PST) Subject: strange behavor.... References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <880c7343-896d-4262-87e6-096dd54f948a@i32g2000pri.googlegroups.com> <4cdf0566$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Right website, wrong page :) > > http://effbot.org/zone/call-by-object.htm D'oh. Thanks for the catch :) From tundra at tundraware.com Sat Nov 13 23:05:57 2010 From: tundra at tundraware.com (Tim Daneliuk) Date: Sat, 13 Nov 2010 22:05:57 -0600 Subject: Looking For Tutorial Comparison Of sh - perl - python Message-ID: <3q34r7-m9s2.ln1@ozzie.tundraware.com> I am putting together a comparison & intro to each of sh, perl, python with a view towards addressing: - What is each language naturally good for - What are their respective strengths and weaknesses - How do they differ paradigmatically Audience is non-programming sysadmins, many of whom are trying to improve their scripting skills. I have written extensive sh and python, considerably less perl. Before I attack this myself, has anyone done something along these lines I could piggyback upon? TIA, -- ---------------------------------------------------------------------------- Tim Daneliuk tundra at tundraware.com PGP Key: http://www.tundraware.com/PGP/ From snehaparitala at gmail.com Sun Nov 14 01:30:51 2010 From: snehaparitala at gmail.com (sms) Date: Sat, 13 Nov 2010 22:30:51 -0800 (PST) Subject: hi Message-ID: <98dfc937-a055-4209-9a5f-e5b42b57beb7@n32g2000pre.googlegroups.com> http://infohivaids.blogspot.com/ From steve at REMOVE-THIS-cybersource.com.au Sun Nov 14 02:35:46 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 14 Nov 2010 07:35:46 GMT Subject: ANN: stats0.1.1a calculator statistics for Python Message-ID: <4cdf9152$0$29990$c3e8da3$5496439d@news.astraweb.com> I am pleased to announce the second public release of stats for Python, and the first targeted at Python 3.x. http://pypi.python.org/pypi/stats stats is a pure-Python module providing basic statistics functions similar to those found on scientific calculators. It has over 40 statistics functions, including: Univariate statistics: * arithmetic, harmonic, geometric and quadratic means * median, mode, midrange, trimean * mean of angular quantities * running and weighted averages * quartiles, hinges and quantiles * variance and standard deviation (sample and population) * average deviation and median average deviation (MAD) * skew and kurtosis * standard error of the mean Multivariate statistics: * Pearson's correlation coefficient * Q-correlation coefficient * covariance (sample and population) * linear regression * sums Sxx, Syy and Sxy and others. This is an unstable alpha release of the software. Feedback and contributions are welcome. -- Steven D'Aprano From arnodel at gmail.com Sun Nov 14 03:15:27 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Sun, 14 Nov 2010 08:15:27 +0000 Subject: strange behavor.... References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> <87tyjlhu1l.fsf.mdw@metalzone.distorted.org.uk> <87hbfk29gy.fsf@gmail.com> <87hbfkj247.fsf.mdw@metalzone.distorted.org.uk> <87d3q824vl.fsf@gmail.com> Message-ID: <878w0w1fts.fsf@gmail.com> Dennis Lee Bieber writes: > On Sat, 13 Nov 2010 23:14:22 +0000, Arnaud Delobelle > declaimed the following in gmane.comp.python.general: > > >> Two occurences of the name "a" belong to the same namespace >> > Pardon? By definition, any given namespace can have only one > occurence of any given name... Well, yes, but I'm talking about occurences *in code*. In the following code: def foo(): a = 1 a = 2 the name "a" occurs twice, both occurences belong to the same namespace. -- Arnaud From franck at ditter.org Sun Nov 14 04:03:56 2010 From: franck at ditter.org (Franck Ditter) Date: Sun, 14 Nov 2010 10:03:56 +0100 Subject: Noob question on 2 vs 3 Python releases Message-ID: Pardon my noobness (?) but why is there a 2.x and 3.x development teams working concurrently in Python ? I hardly saw that in other languages. Which one should I choose to start with, to cope with the future ? Isn't 3.x supposed to extend 2.y ? This situation is very strange... Thanks for your explanations... franck From clp2 at rebertia.com Sun Nov 14 04:11:20 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 14 Nov 2010 01:11:20 -0800 Subject: Noob question on 2 vs 3 Python releases In-Reply-To: References: Message-ID: On Sun, Nov 14, 2010 at 1:03 AM, Franck Ditter wrote: > Pardon my noobness (?) but why is there a 2.x and 3.x development > teams working concurrently in Python ? I hardly saw that in other > languages. You haven't heard of the infamous Perl 6? > Which one should I choose to start with, to cope with > the future ? Read http://wiki.python.org/moin/Python2orPython3 > Isn't 3.x supposed to extend 2.y ? Not just extend. It also makes some *backwards-incompatible* removals and revisions, hence the different major version number. Cheers, Chris -- http://blog.rebertia.com From xrgtn at yandex.ru Sun Nov 14 05:00:48 2010 From: xrgtn at yandex.ru (Alexander Gattin) Date: Sun, 14 Nov 2010 12:00:48 +0200 Subject: Copy Protected PDFs and PIL In-Reply-To: References: Message-ID: <20101114100048.GA3999@xrgtn-q40> Hello, On Fri, Nov 12, 2010 at 12:00:55PM -0800, Brett Bowman wrote: > MRAB - > I've tried worker threads, and it kills the > thread only and not the program as a whole. I > could use that as a work-around, but I would > prefer something more direct, in case other > problems arise. Looks like the gfx module doesn't raise an exception but terminates the thread instead (strange that not the whole process -- I'd use strace/truss/tusc to see what happens). So running gfx's render() tasks in separate threads or processes may be your only workaround. BTW, when your child process dies it's good idea to find out the cause of its death. So you can check its: * exitcode/WTERMSIG/WCOREDUMP * stderr/stdout (if you run it through popen*()) * your own IPS, like e.g. child process sending some short message over the pipe/socket that describes what it's about to do (like in your example below): > import gfx > print "1" > doc = gfx.open("pdf", MY_FILE) > print "2" > page1 = doc.getPage(1) > print "3" > g_img = gfx.ImageList() > print "4" > g_img.startpage(a_page.width,a_page.height) > print "5" > a_page.render(g_img) > print "6" > g_img.endpage() > print "7" > g_img.save(TEMP_PNG) > > which prints the following: > > 1 > 2 > 3 > 4 > 5 This way a parent process can tell that its child most has died during a_page.render(g_img)... -- With best regards, xrgtn From iamforufriends at gmail.com Sun Nov 14 07:34:28 2010 From: iamforufriends at gmail.com (naughty girl) Date: Sun, 14 Nov 2010 04:34:28 -0800 (PST) Subject: NAUGHTY GIRL, WANNA NAUGHTY WITH ME, COME ON...really free... Message-ID: <4f404880-63a3-487c-af90-4e812cb7a7b1@37g2000prx.googlegroups.com> NAUGHTY GIRL, WANNA NAUGHTY WITH ME, COME ON...really free... FREE GOLD MEMBER FOR FEMALE PROFILE, registar with female gender for free access http://goo.gl/1bour http://www.benaughty.com/aff.php?a_aid=27340f40&a_bid=17a6530c From martin at address-in-sig.invalid Sun Nov 14 08:00:47 2010 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Sun, 14 Nov 2010 13:00:47 +0000 (UTC) Subject: Looking For Tutorial Comparison Of sh - perl - python References: <3q34r7-m9s2.ln1@ozzie.tundraware.com> Message-ID: On Sat, 13 Nov 2010 22:05:57 -0600, Tim Daneliuk wrote: > I am putting together a comparison & intro to each of sh, perl, python > with a view towards addressing: > Add awk / gawk to that list. IME its often the easiest and most concise way to process a text file, e.g. a log file, while applying different processing rules depending on line content and/or generating summaries. > Before I attack this myself, has anyone done > something along these lines I could piggyback upon? > I haven't seen such a comparison, but that doesn't meant that they don't exist. -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From news1234 at free.fr Sun Nov 14 08:12:48 2010 From: news1234 at free.fr (News123) Date: Sun, 14 Nov 2010 14:12:48 +0100 Subject: how to identify currently running threads QTHreads Message-ID: <4cdfe050$0$10182$426a34cc@news.free.fr> Hi I'm working with several persons on a PyQT python application. This application is using threads / QThreads in several places. When trying to quit the application it doesn't stop. I assume one thread / QThread did not stop. (wasn't declared as daemon thread) Is there a simple way in Python to identify all active Threads / QThreads when trying, such that I can locate the thread, itls related python code and fix it? Thanks for any suggestions. From ph.ton.sharma at gmail.com Sun Nov 14 09:48:38 2010 From: ph.ton.sharma at gmail.com (ton ph) Date: Sun, 14 Nov 2010 20:18:38 +0530 Subject: Help: Guide needed in trying to delete/flush the content of a fifo file. Message-ID: Hi python geeks, I have problem which i have been trying to find out for the past some days, i have a device which feeds info to my fifo continuosly, and a thread of mine reads the fifo continuosly. Now when i change a parameter in the device, it sends me different values. Now my problem is that , i want to get rid of the contents of my previous info which is present in my buffer of the fifo.So i want to flush the fifo content when my device starts sending different info .... i am implementing writing and reading the fifo using two different threads. Please someone guide me solving my problem. I highly apologise everyone in case my post is not so clear... Thanks everyone in advance. -------------- next part -------------- An HTML attachment was scrubbed... URL: From scott.stephens.j at gmail.com Sun Nov 14 09:51:49 2010 From: scott.stephens.j at gmail.com (otenki) Date: Sun, 14 Nov 2010 06:51:49 -0800 (PST) Subject: another newbie question Message-ID: Hello Pythonistas! I'm trying to get floating point division to work; I'm using Python 2.6.5. When I enter 'from _future_ import division' at the command line, I get the ImportError, no module named _future_. How can I rectify this? Sorry for this basic question, but I don't know where else to turn. Thanks, Scott From nitinpawar432 at gmail.com Sun Nov 14 10:00:09 2010 From: nitinpawar432 at gmail.com (Nitin Pawar) Date: Sun, 14 Nov 2010 20:30:09 +0530 Subject: another newbie question In-Reply-To: References: Message-ID: >From the error, you are importing wrong module which actually does not exists try importing something from maths On Sun, Nov 14, 2010 at 8:21 PM, otenki wrote: > Hello Pythonistas! > I'm trying to get floating point division to work; I'm using Python > 2.6.5. When I enter 'from _future_ import division' at the command > line, I get the ImportError, no module named _future_. How can I > rectify this? > Sorry for this basic question, but I don't know where else to turn. > Thanks, > Scott > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -------------- next part -------------- An HTML attachment was scrubbed... URL: From tim at westpark-club.org.uk Sun Nov 14 10:01:15 2010 From: tim at westpark-club.org.uk (Tim Golden) Date: Sun, 14 Nov 2010 15:01:15 +0000 Subject: another newbie question In-Reply-To: References: Message-ID: <4CDFF9BB.4020504@westpark-club.org.uk> On 14/11/2010 3:00 PM, Nitin Pawar wrote: >> I'm trying to get floating point division to work; I'm using Python >> 2.6.5. When I enter 'from _future_ import division' at the command >> line, I get the ImportError, no module named _future_. How can I >> rectify this? That should be two underscores, not one: from __future__ import division TJG From __peter__ at web.de Sun Nov 14 10:03:23 2010 From: __peter__ at web.de (Peter Otten) Date: Sun, 14 Nov 2010 16:03:23 +0100 Subject: another newbie question References: Message-ID: otenki wrote: > Hello Pythonistas! > I'm trying to get floating point division to work; I'm using Python > 2.6.5. When I enter 'from _future_ import division' at the command > line, I get the ImportError, no module named _future_. How can I > rectify this? You need two leading/trailing underscores, not one: >>> 1/2 0 >>> from __future__ import division >>> 1/2 0.5 From bouncingcats at gmail.com Sun Nov 14 10:09:47 2010 From: bouncingcats at gmail.com (David) Date: Mon, 15 Nov 2010 02:09:47 +1100 Subject: another newbie question In-Reply-To: References: Message-ID: On 15/11/2010, otenki wrote: > When I enter 'from _future_ import division' at the command > line, I get the ImportError, no module named _future_. The module name is "__future__" Notice that there are 2 underscore characters before the word "future" and 2 after it. This is a common convention in python. From scott.stephens.j at gmail.com Sun Nov 14 10:17:11 2010 From: scott.stephens.j at gmail.com (otenki) Date: Sun, 14 Nov 2010 07:17:11 -0800 (PST) Subject: another newbie question References: Message-ID: <42686808-8148-47f3-8cd2-abb553c3df38@o11g2000prf.googlegroups.com> On Nov 14, 10:09?am, David wrote: > On 15/11/2010, otenki wrote: > > > When I enter 'from _future_ import division' at the command > > line, I get the ImportError, no module named _future_. > > The module name is "__future__" > > Notice that there are 2 underscore characters before the word "future" > and 2 after it. This is a common convention in python. Thanks to all for your quick responses to my newbie question. It is much appreciated!!! Scott From gol.sexy.gol7 at gmail.com Sun Nov 14 10:58:43 2010 From: gol.sexy.gol7 at gmail.com (SEXY) Date: Sun, 14 Nov 2010 07:58:43 -0800 (PST) Subject: =?UTF-8?B?2KrYudmA2KLYsdmBICDYqNmE2YrYotix2K/ZiA==?= Message-ID: <2074de3d-64b0-410a-af59-064d6d5bf9b2@z22g2000pri.googlegroups.com> http://gamezer.com.billiards.downbux.net/play-1/?id=1150 From azeynel1 at gmail.com Sun Nov 14 11:14:21 2010 From: azeynel1 at gmail.com (Zeynel) Date: Sun, 14 Nov 2010 08:14:21 -0800 (PST) Subject: Why datetime module is so complicated? Message-ID: <10fb6248-cc3e-433d-89c8-4620ddf673cb@v12g2000vbh.googlegroups.com> It's about a week now I've been trying to convert a datetime object to seconds since epoch; the object is set to current time by class Rep() in Google App Engine: class Rep(db.Model): ... mCOUNT = db.IntegerProperty() mDATE0 = db.DateTimeProperty(auto_now_add=True) mWEIGHT = db.FloatProperty() I want to divide mDATE0 by the integer mCOUNT. I asked the same question here previously and also at stackoverflow. So far, I still cannot make it work. I would greatly appreciate if someone who is an expert in datetime operation in Python could help me understand this issue. Thank you. Latest question in Stackoverlow with link to my original question there: http://stackoverflow.com/questions/4178125/datetime-and-utctimetuple Previous discussions at comp.lang.python: http://groups.google.com/group/comp.lang.python/browse_frm/thread/ac9a2c89bed67869/28c7c7b8d48f3805?hl=en#28c7c7b8d48f3805 http://groups.google.com/group/comp.lang.python/browse_frm/thread/a5aeb6c40ae08450/fd9b42e0c403380e?hl=en#fd9b42e0c403380e From emile at fenx.com Sun Nov 14 11:29:16 2010 From: emile at fenx.com (Emile van Sebille) Date: Sun, 14 Nov 2010 08:29:16 -0800 Subject: strange behavor.... In-Reply-To: <877hggiz17.fsf.mdw@metalzone.distorted.org.uk> References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> <87tyjlhu1l.fsf.mdw@metalzone.distorted.org.uk> <4cdf1206$0$29990$c3e8da3$5496439d@news.astraweb.com> <877hggiz17.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On 11/13/2010 3:28 PM Mark Wooding said... > Steven D'Aprano writes: > >> On Sat, 13 Nov 2010 20:01:42 +0000, Mark Wooding wrote: >>> Some object types are primitive, provided by the runtime system; >>> there are no `internal' variables to be assigned in these cases. >> >> You seem to be making up your own terminology here, or at least using >> terminology that isn't normally used in the languages I'm used to. > > I was attempting to define possibly unfamiliar terms as I went along. > Did you not notice? > You both make valid points when viewed from the specific writer's perspective. I think you're speaking past each other because Steven and others are explaining terms in their common python context in an attempt to have Mark understand and use them similarly, which is of most benefit to our community. Mark on the other hand is attempting to make sense of our common terms in light of similarly termed constructs from his experience, which of course we all have done and do as we continue to learn, but with an apparent effort to change our common usage. Mark says "The latter is not an assignment: it's a disguised method call." We all know that _everything_ is a disguised method call and we call the disguised method call that resembles a statement where the LHS is separated from the RHS by a single equals sign assignment. In the long run, Mark can choose to either further and complete his understanding and adopt python's commonly understood terminology; or continue to point to how in other languages the usage of terms also used in python conflicts with the established meaning of those terms as implemented in python. The difference between "developing contributor" and "trolling" turns on when this acceptance starts. My .02. Emile From aahz at pythoncraft.com Sun Nov 14 11:32:38 2010 From: aahz at pythoncraft.com (Aahz) Date: 14 Nov 2010 08:32:38 -0800 Subject: how to identify currently running threads QTHreads References: <4cdfe050$0$10182$426a34cc@news.free.fr> Message-ID: In article <4cdfe050$0$10182$426a34cc at news.free.fr>, News123 wrote: > >Is there a simple way in Python to identify all active Threads / >QThreads when trying, such that I can locate the thread, itls related >python code and fix it? threading.enumerate() or sys._current_frames() -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Look, it's your affair if you want to play with five people, but don't go calling it doubles." --John Cleese anticipates Usenet From roy at panix.com Sun Nov 14 11:40:56 2010 From: roy at panix.com (Roy Smith) Date: Sun, 14 Nov 2010 11:40:56 -0500 Subject: another newbie question References: Message-ID: In article , David wrote: > On 15/11/2010, otenki wrote: > > When I enter 'from _future_ import division' at the command > > line, I get the ImportError, no module named _future_. > > The module name is "__future__" > > Notice that there are 2 underscore characters before the word "future" > and 2 after it. This is a common convention in python. I suppose the double-underscore convention was a questionable choice, given how many fixed width fonts make it difficult to discern the gap between them. In fact, in most fonts, it's an intentional design goal that they run together (think of it as a sort of recurisive ligature). That being said, it is what it is, and isn't changing. I'm really picky about what font I use for coding. For years, I've stuck to Apple's Monaco, antialised. In the latest version of the OS (Snow Leopard), they added a new font called Menio. When I first looked at it, I couldn't tell the difference, and decided to stick with Monaco. I just opened up TextEdit and tried looking at __ (double underscore) in various fonts. Lo and behold, you can see the gap in Monaco, and the two run completely together in Menio. I'm still searching for as nice a font to use on Linux. Then, there are people who try to program in proportional fonts. The mind boggles. For a (thankfully short) while some years ago, people were publishing programming books with the code samples in proportional fonts. Blech. From deets at web.de Sun Nov 14 11:53:42 2010 From: deets at web.de (Diez B. Roggisch) Date: Sun, 14 Nov 2010 17:53:42 +0100 Subject: Why datetime module is so complicated? References: <10fb6248-cc3e-433d-89c8-4620ddf673cb@v12g2000vbh.googlegroups.com> Message-ID: Zeynel writes: > It's about a week now I've been trying to convert a datetime object to > seconds since epoch; the object is set to current time by class Rep() > in Google App Engine: > > class Rep(db.Model): > ... > mCOUNT = db.IntegerProperty() > mDATE0 = db.DateTimeProperty(auto_now_add=True) > mWEIGHT = db.FloatProperty() > > I want to divide mDATE0 by the integer mCOUNT. I asked the same > question here previously and also at stackoverflow. So far, I still > cannot make it work. I would greatly appreciate if someone who is an > expert in datetime operation in Python could help me understand this > issue. Thank you. >>> from datetime import * >>> d = datetime.now() >>> dir(d) ['__add__', '__class__', '__delattr__', '__doc__', '__eq__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__ne__', '__new__', '__radd__', '__reduce__', '__reduce_ex__', '__repr__', '__rsub__', '__setattr__', '__str__', '__sub__', 'astimezone', 'combine', 'ctime', 'date', 'day', 'dst', 'fromordinal', 'fromtimestamp', 'hour', 'isocalendar', 'isoformat', 'isoweekday', 'max', 'microsecond', 'min', 'minute', 'month', 'now', 'replace', 'resolution', 'second', 'strftime', 'strptime', 'time', 'timetuple', 'timetz', 'today', 'toordinal', 'tzinfo', 'tzname', 'utcfromtimestamp', 'utcnow', 'utcoffset', 'utctimetuple', 'weekday', 'year'] >>> d.time() datetime.time(17, 50, 54, 778159) >>> d.ctime() 'Sun Nov 14 17:50:54 2010' >>> d.time >>> d.timetuple() (2010, 11, 14, 17, 50, 54, 6, 318, -1) >>> import time >>> dir(time) ['__doc__', '__file__', '__name__', 'accept2dyear', 'altzone', 'asctime', 'clock', 'ctime', 'daylight', 'gmtime', 'localtime', 'mktime', 'sleep', 'strftime', 'strptime', 'struct_time', 'time', 'timezone', 'tzname', 'tzset'] >>> help(time.mktime) >>> time.mktime(d.timetuple()) 1289753454.0 >>> Not that hard. Diez From nfdisco at gmail.com Sun Nov 14 11:58:42 2010 From: nfdisco at gmail.com (ernest) Date: Sun, 14 Nov 2010 08:58:42 -0800 (PST) Subject: raise Exception or raise Exception() Message-ID: <1b51a22c-a9ec-4d58-8dc5-ddb62628fc0f@w21g2000vby.googlegroups.com> I have seen both forms and I'm not sure if they're both correct, or one is right and the other wrong. In practical terms, the two of them seem to have the same effect. Cheers, Ernest From vlastimil.brom at gmail.com Sun Nov 14 11:59:50 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sun, 14 Nov 2010 17:59:50 +0100 Subject: Why datetime module is so complicated? In-Reply-To: <10fb6248-cc3e-433d-89c8-4620ddf673cb@v12g2000vbh.googlegroups.com> References: <10fb6248-cc3e-433d-89c8-4620ddf673cb@v12g2000vbh.googlegroups.com> Message-ID: 2010/11/14 Zeynel : > It's about a week now I've been trying to convert a datetime object to > seconds since epoch; the object is set to current time by class Rep() > in Google App Engine: > > class Rep(db.Model): > ? ?... > ? ?mCOUNT = db.IntegerProperty() > ? ?mDATE0 = db.DateTimeProperty(auto_now_add=True) > ? ?mWEIGHT = db.FloatProperty() > > I want to divide mDATE0 by the integer mCOUNT. I asked the same > question here previously and also at stackoverflow. So far, I still > cannot make it work. I would greatly appreciate if someone who is an > expert in datetime operation in Python could help me understand this > issue. Thank you. > > Latest question in Stackoverlow with link to my original question > there: http://stackoverflow.com/questions/4178125/datetime-and-utctimetuple > > Previous discussions at comp.lang.python: > > http://groups.google.com/group/comp.lang.python/browse_frm/thread/ac9a2c89bed67869/28c7c7b8d48f3805?hl=en#28c7c7b8d48f3805 > > http://groups.google.com/group/comp.lang.python/browse_frm/thread/a5aeb6c40ae08450/fd9b42e0c403380e?hl=en#fd9b42e0c403380e > -- > http://mail.python.org/mailman/listinfo/python-list > Hi, just a try, as it is not completely clear to me, what you are trying to achieve, as I don't have experiences with the mentioned framework. It seems to me, that you can only reasonably divide timedeltas, not the absolute timestamps, it might be something like the following: >>> april_1st=datetime.datetime(2010, 4, 1, 11, 55, 00) >>> may_1st=datetime.datetime(2010, 5, 1, 11, 54, 03, 123456) >>> delta_dates = may_1st - april_1st >>> delta_in_secs = delta_dates.total_seconds() >>> delta_in_secs 2591943.123456 >>> delta_in_secs / 5.2 498450.60066461534 >>> hth, vbr From clp2 at rebertia.com Sun Nov 14 13:14:47 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 14 Nov 2010 10:14:47 -0800 Subject: raise Exception or raise Exception() In-Reply-To: <1b51a22c-a9ec-4d58-8dc5-ddb62628fc0f@w21g2000vby.googlegroups.com> References: <1b51a22c-a9ec-4d58-8dc5-ddb62628fc0f@w21g2000vby.googlegroups.com> Message-ID: On Sun, Nov 14, 2010 at 8:58 AM, ernest wrote: > I have seen both forms and I'm not sure if they're > both correct, or one is right and the other wrong. They're both acceptable (although obviously you should always raise a more specific error than Exception). `raise SomeException` is in fact equivalent to `raise SomeException()`. Providing an error message is always advisable though, so really in most cases you ought to `raise SomeException("Informative error message")` Cheers, Chris -- http://blog.rebertia.com From mammique at garbure.org Sun Nov 14 13:50:54 2010 From: mammique at garbure.org (Camille Harang) Date: Sun, 14 Nov 2010 19:50:54 +0100 Subject: subprocess pipe Message-ID: Hi all, I'm having a problem with subprocess.Popen. It seems that its unable to capture the pg_dump's standard inputs & outputs in a non-shell mode: from subprocess import Popen, PIPE # fire pg_dump in order to read data from the file object pgsql.stdout pgsql = Popen(['/usr/bin/pg_dump', '--host', 'localhost', '--password', '--username', 'mammique'], stdin=PIPE, stderr=PIPE, stdout=PIPE, shell=True) # pg_dump prompts for password so I inject it in stdin. pgsql.stdin.write('MY_PASSWORD' + '\n') In the shell mode (shell=True) pipes works but the args (username, etc.) are omitted. If I turn to shell=False the arguments are passed to pg_dump but subprocess.Popen is no longer able to capture the standard inputs & outputs, the password prompt appears on the TTY instead and doesn't take the input written in stdin. It seems that subprocess.Popen has only this problem with pg_dump, other interactive command lines seems to be correctly handled. Any lead? Thanks, Camille. From python at mrabarnett.plus.com Sun Nov 14 13:55:55 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 14 Nov 2010 18:55:55 +0000 Subject: Help: Guide needed in trying to delete/flush the content of a fifo file. In-Reply-To: References: Message-ID: <4CE030BB.20500@mrabarnett.plus.com> On 14/11/2010 14:48, ton ph wrote: > Hi python geeks, > I have problem which i have been trying to find out for the past > some days, i have a device which feeds info to my fifo continuosly, and > a thread of mine reads the > fifo continuosly. Now when i change a parameter in the device, it sends > me different values. Now my problem is that , i want to get rid of the > contents of my previous info which > is present in my buffer of the fifo.So i want to flush the fifo content > when my device starts sending different info .... i am implementing > writing and reading the fifo using two different threads. > Please someone guide me solving my problem. > I highly apologise everyone in case my post is not so clear... > Thanks everyone in advance. > When the info changes, the thread which is putting items into the fifo could flush it just by getting items from it (using a non-blocking get) until it's empty. From python at mrabarnett.plus.com Sun Nov 14 13:59:33 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 14 Nov 2010 18:59:33 +0000 Subject: another newbie question In-Reply-To: References: Message-ID: <4CE03195.9010800@mrabarnett.plus.com> On 14/11/2010 16:40, Roy Smith wrote: > In article, > David wrote: > >> On 15/11/2010, otenki wrote: >>> When I enter 'from _future_ import division' at the command >>> line, I get the ImportError, no module named _future_. >> >> The module name is "__future__" >> >> Notice that there are 2 underscore characters before the word "future" >> and 2 after it. This is a common convention in python. > > I suppose the double-underscore convention was a questionable choice, > given how many fixed width fonts make it difficult to discern the gap > between them. In fact, in most fonts, it's an intentional design goal > that they run together (think of it as a sort of recurisive ligature). > That being said, it is what it is, and isn't changing. > [snip] Guido chose double underscores because CPython is written in C and that's what C uses. It's true that with hindsight it was a mistake... From micah at greentackle.com Sun Nov 14 14:00:18 2010 From: micah at greentackle.com (Micah Carrick) Date: Sun, 14 Nov 2010 11:00:18 -0800 Subject: Objects versus dictionaries Message-ID: I'm writing a little API that other people will use. There are up to 3 "objects" that get passed around. One of them has some validation methods, the other two simply store data and probably won't have any validation or other methods. I only made them objects so that they are syntactically (is that a word?) similar the other object rather than using dictionaries. I figure it also better allows for changes in the future. Any thoughts on the pros/cons of using my own objects over a dictionary objects? # this is what I have now... stuff = Stuff(foo="foo", bar="bar") if stuff.is_valid(): cust = Customer(name="John", email="foo at bar.com") order = Order(order_id=1234, amount=12.99) SomeObject.some_method(stuff, cust, order) # this would also work... stuff = Stuff(foo="foo", bar="bar") if stuff.is_valid(): cust = { 'name': "John", 'email': "foo at bar.com" } order = { 'order_id': 1234, 'amount': 12.99 } SomeObject.some_method(stuff, cust, order) -- Micah Carrick -------------- next part -------------- An HTML attachment was scrubbed... URL: From kern.ra at gmail.com Sun Nov 14 14:07:40 2010 From: kern.ra at gmail.com (Becky Kern) Date: Sun, 14 Nov 2010 14:07:40 -0500 Subject: [Beginner question] Raster to ASCII Message-ID: Hi users, I'm using Python 2.5 (in concert with ArcGIS 9.3) to convert a raster to an ASCII file. I used the code (listed below) several weeks ago to successfully do the conversion, but when I tried to replicate it a few days ago, I got an error message. import arcgisscripting gp = arcgisscripting.create(9.3) InRaster = "C:/data/raster1" OutAsciiFile = "C:/data/raster2ascii.asc" gp.RasterToASCII_conversion(InRaster, OutAsciiFile) The error message: arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid. raster1 does not exist. My file path has not changed so I don't understand why Python can no longer recognize my raster file. Any ideas? -------------- next part -------------- An HTML attachment was scrubbed... URL: From artur.siekielski at gmail.com Sun Nov 14 14:08:08 2010 From: artur.siekielski at gmail.com (Artur Siekielski) Date: Sun, 14 Nov 2010 11:08:08 -0800 (PST) Subject: Getting references to objects without incrementing reference counters Message-ID: <8c98a453-3303-4509-be39-1a26084f573a@o11g2000prf.googlegroups.com> Hi. I'm using CPython 2.7 and Linux. In order to make parallel computations on a large list of objects I want to use multiple processes (by using multiprocessing module). In the first step I fill the list with objects and then I fork() my worker processes that do the job. This should work optimally in the aspect of memory usage because Linux implements copy-on-write in forked processes. So I should have only one physical list of objects (the worker processes don't change the objects on the list). The problem is that after a short time children processes are using more and more memory (they don't create new objects - they only read objects from the list and write computation result to the database). After investigation I concluded the source of this must be incrementing of a reference counter when getting an object from the list. It changes only one int but OS must copy the whole memory page to the child process. I reimplemented the function for getting the element (from the file listobject.c) but omitting the PY_INCREF call and it solved my problems with increasing memory. The questions is: are there any better ways to have a real read-only list (in terms of memory representation of objects)? My solution is of course not safe. I thought about weakrefs but it seems they cannot be used here because getting a real reference from a weakref increases a reference counter. Maybe another option would be to store reference counters not in objects, but in a separate array to minimize number of memory pages they occupy... From clp2 at rebertia.com Sun Nov 14 14:15:53 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 14 Nov 2010 11:15:53 -0800 Subject: subprocess pipe In-Reply-To: References: Message-ID: On Sun, Nov 14, 2010 at 10:50 AM, Camille Harang wrote: > Hi all, > > I'm having a problem with subprocess.Popen. It seems that its unable to > capture the pg_dump's standard inputs & outputs in a non-shell mode: > > from subprocess import Popen, PIPE > > # fire pg_dump in order to read data from the file object pgsql.stdout > pgsql = Popen(['/usr/bin/pg_dump', > ? ? ? ? ? ? ? '--host', 'localhost', > ? ? ? ? ? ? ? '--password', > ? ? ? ? ? ? ? '--username', > ? ? ? ? ? ? ? 'mammique'], > ? ? ? ? ? ? ?stdin=PIPE, > ? ? ? ? ? ? ?stderr=PIPE, > ? ? ? ? ? ? ?stdout=PIPE, > ? ? ? ? ? ? ?shell=True) > > # pg_dump prompts for password so I inject it in stdin. > pgsql.stdin.write('MY_PASSWORD' + '\n') > > In the shell mode (shell=True) pipes works but the args (username, etc.) > are omitted. If I turn to shell=False the arguments are passed to > pg_dump but subprocess.Popen is no longer able to capture the standard > inputs & outputs, the password prompt appears on the TTY instead and > doesn't take the input written in stdin. It seems that subprocess.Popen > has only this problem with pg_dump, other interactive command lines > seems to be correctly handled. > > Any lead? Quoting http://docs.python.org/library/subprocess.html , emphasis mine: """ On Unix, with shell=True: [...] If args is a sequence, ***the first item*** specifies the command string, and any additional items will be treated as additional arguments ***to the shell itself***. """ So if you're using shell=True, pass a single string rather than a tokenized list. That is to say: command = "/usr/bin/pg_dump --host localhost --password --username mammique" pgsql = Popen(command, stdin=PIPE, stderr=PIPE, stdout=PIPE, shell=True) Cheers, Chris -- http://blog.rebertia.com From clp2 at rebertia.com Sun Nov 14 14:20:48 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 14 Nov 2010 11:20:48 -0800 Subject: Objects versus dictionaries In-Reply-To: References: Message-ID: On Sun, Nov 14, 2010 at 11:00 AM, Micah Carrick wrote: > I'm writing a little API that other people will use. There are up to 3 > "objects" that get passed around. One of them has some validation methods, > the other two simply store data and probably won't have any validation or > other methods. I only made them objects so that they are syntactically (is > that a word?) similar the other object rather than using dictionaries. I > figure it also better allows for changes in the future. > > Any thoughts on the pros/cons of using my own objects over a dictionary > objects? Objects are definitely nicer to work with syntactically, and they help make your program's types more explicit. Rather than coding the "data holder" classes manually, consider using namedtuples instead: http://docs.python.org/library/collections.html#collections.namedtuple Cheers, Chris -- http://blog.rebertia.com From mammique at yooook.net Sun Nov 14 14:25:30 2010 From: mammique at yooook.net (Camille Harang) Date: Sun, 14 Nov 2010 20:25:30 +0100 Subject: subprocess pipe In-Reply-To: References: Message-ID: <4CE037AA.1050309@yooook.net> Hi Chris, thanks for your reply. Chris Rebert a ?crit : > Quoting http://docs.python.org/library/subprocess.html , emphasis mine: > """ > On Unix, with shell=True: [...] If args is a sequence, ***the first > item*** specifies the command string, and any additional items will be > treated as additional arguments ***to the shell itself***. > """ Yes, I read that, that's why I'd like to avoid shell=True, but if I do shall=False subprocess.Popen is no longer able to catch the standard inputs & outputs of pg_dump (but it does on other commands that has a prompt, e.g. 'passwd') That's the problem :-/ Regards, Camille. -- The Good, the Bad and the Ugly under Creative Commons! https://yooook.net/r/lp1 From hidura at gmail.com Sun Nov 14 14:34:40 2010 From: hidura at gmail.com (Hidura) Date: Sun, 14 Nov 2010 15:34:40 -0400 Subject: Objects versus dictionaries In-Reply-To: References: Message-ID: Use *kargs to pass all the informatio that you need if u want in the future extended this will be usefull 2010/11/14, Micah Carrick : > I'm writing a little API that other people will use. There are up to 3 > "objects" that get passed around. One of them has some validation methods, > the other two simply store data and probably won't have any validation or > other methods. I only made them objects so that they are syntactically (is > that a word?) similar the other object rather than using dictionaries. I > figure it also better allows for changes in the future. > > Any thoughts on the pros/cons of using my own objects over a dictionary > objects? > > # this is what I have now... > stuff = Stuff(foo="foo", bar="bar") > if stuff.is_valid(): > cust = Customer(name="John", email="foo at bar.com") > order = Order(order_id=1234, amount=12.99) > SomeObject.some_method(stuff, cust, order) > > # this would also work... > stuff = Stuff(foo="foo", bar="bar") > if stuff.is_valid(): > cust = { 'name': "John", 'email': "foo at bar.com" } > order = { 'order_id': 1234, 'amount': 12.99 } > SomeObject.some_method(stuff, cust, order) > > -- > Micah Carrick > -- Enviado desde mi dispositivo m?vil Diego I. Hidalgo D. From python at mrabarnett.plus.com Sun Nov 14 14:38:59 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 14 Nov 2010 19:38:59 +0000 Subject: [Beginner question] Raster to ASCII In-Reply-To: References: Message-ID: <4CE03AD3.9040506@mrabarnett.plus.com> On 14/11/2010 19:07, Becky Kern wrote: > Hi users, > I'm using Python 2.5 (in concert with ArcGIS 9.3) to convert a raster to > an ASCII file. I used the code (listed below) several weeks ago to > successfully do the conversion, but when I tried to replicate it a few > days ago, I got an error message. > import arcgisscripting > gp = arcgisscripting.create(9.3) > InRaster = "C:/data/raster1" > OutAsciiFile = "C:/data/raster2ascii.asc" > gp.RasterToASCII_conversion(InRaster, OutAsciiFile) > The error message: > arcgisscripting.ExecuteError: Failed to execute. Parameters are not > valid. raster1 does not exist. > My file path has not changed so I don't understand why Python can no > longer recognize my raster file. Any ideas? > Just to make sure, does os.path.isfile(InRaster) return True? From python.list at tim.thechases.com Sun Nov 14 14:45:20 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 14 Nov 2010 13:45:20 -0600 Subject: [Beginner question] Raster to ASCII In-Reply-To: References: Message-ID: <4CE03C50.2000900@tim.thechases.com> On 11/14/2010 01:07 PM, Becky Kern wrote: > import arcgisscripting > gp = arcgisscripting.create(9.3) > InRaster = "C:/data/raster1" > OutAsciiFile = "C:/data/raster2ascii.asc" > gp.RasterToASCII_conversion(InRaster, OutAsciiFile) > > The error message: > > arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid. > raster1 does not exist. While I can't speak specifically to arcgisscripting, having no experience with it, the error _sounds_ like the InRaster file isn't found. It's the only reference to "raster1" in your code and the error points directly at "raster1". My suspicion is that you're missing an extension...something like InRaster = "C:/data/raster1.rst" with whatever the corresponding extension is. Alternatively, it's pointing at directory named "raster1" instead of a file. -tkc From usernet at ilthio.net Sun Nov 14 14:47:55 2010 From: usernet at ilthio.net (Tim Harig) Date: Sun, 14 Nov 2010 19:47:55 +0000 (UTC) Subject: subprocess pipe References: Message-ID: On 2010-11-14, Camille Harang wrote: > # pg_dump prompts for password so I inject it in stdin. > pgsql.stdin.write('MY_PASSWORD' + '\n') For security reasons, some programs use direct access to the TTY system for password entry rather then reading from stdin. Most of these programs provide another access mechanism that can be used for authentication (ie public keys or storing the password in a permission restricted configuration file. From usernet at ilthio.net Sun Nov 14 14:51:40 2010 From: usernet at ilthio.net (Tim Harig) Date: Sun, 14 Nov 2010 19:51:40 +0000 (UTC) Subject: subprocess pipe References: Message-ID: On 2010-11-14, Tim Harig wrote: > On 2010-11-14, Camille Harang wrote: >> # pg_dump prompts for password so I inject it in stdin. >> pgsql.stdin.write('MY_PASSWORD' + '\n') > > For security reasons, some programs use direct access to the TTY system > for password entry rather then reading from stdin. Most of these programs > provide another access mechanism that can be used for authentication > (ie public keys or storing the password in a permission restricted > configuration file.[) for scripts. .pgpass ? From roy at panix.com Sun Nov 14 15:14:00 2010 From: roy at panix.com (Roy Smith) Date: Sun, 14 Nov 2010 15:14:00 -0500 Subject: raise Exception or raise Exception() References: <1b51a22c-a9ec-4d58-8dc5-ddb62628fc0f@w21g2000vby.googlegroups.com> Message-ID: In article , Chris Rebert wrote: > On Sun, Nov 14, 2010 at 8:58 AM, ernest wrote: > > I have seen both forms and I'm not sure if they're > > both correct, or one is right and the other wrong. > > They're both acceptable (although obviously you should always raise a > more specific error than Exception). > `raise SomeException` is in fact equivalent to `raise SomeException()`. I've always found this rather disconcerting and unpythonic. Sure, it saves a couple of keystrokes here and there, but it also adds confusion such as Ernest's. It reminds me of Perl's letting you omit the parentheses on function calls. From mammique at garbure.org Sun Nov 14 15:16:22 2010 From: mammique at garbure.org (Camille Harang) Date: Sun, 14 Nov 2010 21:16:22 +0100 Subject: subprocess pipe In-Reply-To: References: Message-ID: <4CE04396.1010108@garbure.org> Tim Harig a ?crit : > On 2010-11-14, Camille Harang wrote: >> # pg_dump prompts for password so I inject it in stdin. >> pgsql.stdin.write('MY_PASSWORD' + '\n') > > For security reasons, some programs use direct access to the TTY system > for password entry rather then reading from stdin. Most of these programs > provide another access mechanism that can be used for authentication > (ie public keys or storing the password in a permission restricted > configuration file. Ha, indeed, I suspected that pg_dump didn't behave normally, security matters might be an explanation, I'll dig in that way, thanks a lot. Regards, Camille. From mammique at garbure.org Sun Nov 14 15:16:37 2010 From: mammique at garbure.org (Camille Harang) Date: Sun, 14 Nov 2010 21:16:37 +0100 Subject: subprocess pipe In-Reply-To: References: Message-ID: <4CE043A5.4070405@garbure.org> Tim Harig a ?crit : > On 2010-11-14, Camille Harang wrote: >> # pg_dump prompts for password so I inject it in stdin. >> pgsql.stdin.write('MY_PASSWORD' + '\n') > > For security reasons, some programs use direct access to the TTY system > for password entry rather then reading from stdin. Most of these programs > provide another access mechanism that can be used for authentication > (ie public keys or storing the password in a permission restricted > configuration file. Ha, indeed, I suspected that pg_dump didn't behave normally, security matters might be an explanation, I'll dig in that way, thanks a lot. Regards, Camille. From mammique at garbure.org Sun Nov 14 15:16:37 2010 From: mammique at garbure.org (Camille Harang) Date: Sun, 14 Nov 2010 21:16:37 +0100 Subject: subprocess pipe In-Reply-To: References: Message-ID: <4CE043A5.4070405@garbure.org> Tim Harig a ?crit : > On 2010-11-14, Camille Harang wrote: >> # pg_dump prompts for password so I inject it in stdin. >> pgsql.stdin.write('MY_PASSWORD' + '\n') > > For security reasons, some programs use direct access to the TTY system > for password entry rather then reading from stdin. Most of these programs > provide another access mechanism that can be used for authentication > (ie public keys or storing the password in a permission restricted > configuration file. Ha, indeed, I suspected that pg_dump didn't behave normally, security matters might be an explanation, I'll dig in that way, thanks a lot. Regards, Camille. From steve at holdenweb.com Sun Nov 14 15:23:03 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 14 Nov 2010 12:23:03 -0800 Subject: strange behavor.... In-Reply-To: References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> <87tyjlhu1l.fsf.mdw@metalzone.distorted.org.uk> <4cdf1206$0$29990$c3e8da3$5496439d@news.astraweb.com> <877hggiz17.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On 11/14/2010 8:29 AM, Emile van Sebille wrote: [...] > We all know that _everything_ is a disguised method call and we call the > disguised method call that resembles a statement where the LHS is > separated from the RHS by a single equals sign assignment. I think your elided attempt to reconcile the opposing viewpoints on this thread is creditworthy. We should not allow our wish to resolve conflicting viewpoints blind us to reality, however. What method of a does the statement a = something call? I ask in genuine ignorance, and in the knowledge that you may indeed be able to point me to such a method. I would prefer to think of a = something and lst[i] = something as in some sense different, because I see names as referencing locations in a namespace. Perhaps you can help to unify my perceptions. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From rschroev_nospam_ml at fastmail.fm Sun Nov 14 15:44:45 2010 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Sun, 14 Nov 2010 21:44:45 +0100 Subject: strange behavor.... In-Reply-To: References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> <87tyjlhu1l.fsf.mdw@metalzone.distorted.org.uk> <4cdf1206$0$29990$c3e8da3$5496439d@news.astraweb.com> <877hggiz17.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <1TXDo.79784$r35.72278@newsfe14.ams2> Op 2010-11-14 21:23, Steve Holden schreef: > What method of a does the statement > > a = something > > call? I ask in genuine ignorance, and in the knowledge that you may > indeed be able to point me to such a method. It wouldn't call a method of a. I'm not an expert in these matters, but I would think it would call a method in a's namespace. For example, if 'a' lives in module 'foo', I would think that a = something # from within module foo and foo.a = something # outside of module foo are equivalent. But chances are my conceptions are wrong. -- The saddest aspect of life right now is that science gathers knowledge faster than society gathers wisdom. -- Isaac Asimov Roel Schroeven From calderone.jeanpaul at gmail.com Sun Nov 14 16:04:17 2010 From: calderone.jeanpaul at gmail.com (Jean-Paul Calderone) Date: Sun, 14 Nov 2010 13:04:17 -0800 (PST) Subject: Getting references to objects without incrementing reference counters References: <8c98a453-3303-4509-be39-1a26084f573a@o11g2000prf.googlegroups.com> Message-ID: <8063c457-98bf-4add-a1c7-38b01848cbe3@w21g2000vby.googlegroups.com> On Nov 14, 11:08?am, Artur Siekielski wrote: > Hi. > I'm using CPython 2.7 and Linux. In order to make parallel > computations on a large list of objects I want to use multiple > processes (by using multiprocessing module). In the first step I fill > the list with objects and then I fork() my worker processes that do > the job. > > This should work optimally in the aspect of memory usage because Linux > implements copy-on-write in forked processes. So I should have only > one physical list of objects (the worker processes don't change the > objects on the list). The problem is that after a short time children > processes are using more and more memory (they don't create new > objects - they only read objects from the list and write computation > result to the database). > > After investigation I concluded the source of this must be > incrementing of a reference counter when getting an object from the > list. It changes only one int but OS must copy the whole memory page > to the child process. I reimplemented the function for getting the > element (from the file listobject.c) but omitting the PY_INCREF call > and it solved my problems with increasing memory. > > The questions is: are there any better ways to have a real read-only > list (in terms of memory representation of objects)? My solution is of > course not safe. I thought about weakrefs but it seems they cannot be > used here because getting a real reference from a weakref increases a > reference counter. Maybe another option would be to store reference > counters not in objects, but in a separate array to minimize number of > memory pages they occupy... It might be interesting to try with Jython or PyPy. Neither of these Python runtimes uses reference counting at all. Jean-Paul From emile at fenx.com Sun Nov 14 16:18:53 2010 From: emile at fenx.com (Emile van Sebille) Date: Sun, 14 Nov 2010 13:18:53 -0800 Subject: strange behavor.... In-Reply-To: References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> <87tyjlhu1l.fsf.mdw@metalzone.distorted.org.uk> <4cdf1206$0$29990$c3e8da3$5496439d@news.astraweb.com> <877hggiz17.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On 11/14/2010 12:23 PM Steve Holden said... > On 11/14/2010 8:29 AM, Emile van Sebille wrote: > [...] >> We all know that _everything_ is a disguised method call and we call the >> disguised method call that resembles a statement where the LHS is >> separated from the RHS by a single equals sign assignment. > > I think your elided attempt to reconcile the opposing viewpoints on this > thread is creditworthy. We should not allow our wish to resolve > conflicting viewpoints blind us to reality, however. What method of a > does the statement > > a = something Contrivance, but all the same: >>> class Test: ... def __del__(self): ... global a ... a = 10 ... >>> a = Test() >>> ... here's your a = something, which also lends credence to Mark's argument that you can't easily tell... >>> a = 9 >>> >>> print a 10 >>> I'd also suggest that long before magic methods like __radd__ and such were added, that the expectation that everything _could_ be a magic method was there, and that those methods of next best benefit were added as time and interest permitted. That _all_ those possible methods are not yet implemented I leave to the developers. :) I was mainly trying to point out that until a common vernacular is accepted by those engaging in a discussion misconceptions are inevitable, and that learning how those terms are applied within a context is necessary for advancement. A numpy matrix is not Neo's Matrix and arguing that it should be or that python's use is "wrong" doesn't really get anyone anywhere. Emile From steve at REMOVE-THIS-cybersource.com.au Sun Nov 14 17:00:28 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 14 Nov 2010 22:00:28 GMT Subject: strange behavor.... References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> <87tyjlhu1l.fsf.mdw@metalzone.distorted.org.uk> <4cdf1206$0$29990$c3e8da3$5496439d@news.astraweb.com> <877hggiz17.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <4ce05bfc$0$29990$c3e8da3$5496439d@news.astraweb.com> On Sun, 14 Nov 2010 12:23:03 -0800, Steve Holden wrote: > What method of a does the statement > > a = something > > call? I ask in genuine ignorance, and in the knowledge that you may > indeed be able to point me to such a method. I know the question wasn't directed at me, but here's my 2 cents worth: It doesn't; Mark has correctly identified that difference between what he calls "simple assignment" (and the rest of us call "name binding"), and "complex assignment" (assignment to something other than a name). This is a design choice of Python -- objects don't know what names (if any) they are bound to, so Python doesn't call a method on the object "something". Nor does it call an method on the object currently bound to the name "a" but about to be unbound -- what would be the point? And of course, the name "a" might not yet be bound to anything, in which case there is nothing on the left hand side to call. On the other hand, in the global scope, "a = something" *may* call globals().__setitem__('a', 'something'), although it's quite possible that Python may optimize that in some fashion and avoid the method call. But even if it did call the method, unless you can replace globals() with a custom dict that did something "interesting" on assignment, that's merely an implementation detail. And CPython, if not other implementations, don't call anything analogous inside functions: locals() is not a real dictionary and no method is called. We (well, I *wink*) agree with Mark that name binding is different; we only disagree whether that difference is *conceptually* important enough to change 15 or 20 years of Python terminology to suit his Lisp sensibilities. > I would prefer to think of > > a = something > > and > > lst[i] = something > > as in some sense different, because I see names as referencing locations > in a namespace. Perhaps you can help to unify my perceptions. Names in namespaces reference *objects* -- that the objects happen to have fixed locations in the heap (their memory location) is an implementation detail. You know, some day in my Copious Spare Time, I'm going to write my own Python implementation using handles to objects instead of pointers, just so I can point to an implementation where objects are free to move in memory and don't have a fixed location :) -- Steven From arnodel at gmail.com Sun Nov 14 17:25:48 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Sun, 14 Nov 2010 22:25:48 +0000 Subject: strange behavor.... References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> <87tyjlhu1l.fsf.mdw@metalzone.distorted.org.uk> <4cdf1206$0$29990$c3e8da3$5496439d@news.astraweb.com> <877hggiz17.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <874obj1r0z.fsf@gmail.com> Steve Holden writes: > On 11/14/2010 8:29 AM, Emile van Sebille wrote: > [...] >> We all know that _everything_ is a disguised method call and we call the >> disguised method call that resembles a statement where the LHS is >> separated from the RHS by a single equals sign assignment. > > I think your elided attempt to reconcile the opposing viewpoints on this > thread is creditworthy. We should not allow our wish to resolve > conflicting viewpoints blind us to reality, however. What method of a > does the statement > > a = something > > call? I ask in genuine ignorance, and in the knowledge that you may > indeed be able to point me to such a method. If "a = something" is compiled to "STORE_NAME" and the statement is executed in a context where locals() is a custom dictionary then it is possible that the statement will call the custom __setitem__ method of the locals: >>> class mydict(dict): ... def __setitem__(self, key, val): ... print "assigning %r to %r" % (val, key) ... super(mydict, self).__setitem__(key, val) ... >>> d = mydict() >>> exec "a=2" in d assigning 2 to 'a' >>> d['a'] 2 But note that: >>> exec "global a; a = 3" in d >>> d['a'] 3 So even if the globals() dictionary is custom, its __setitem__ method is *not* called. Below is a summary of what methods are called depending on the opcode executed: OPCODE Assignment type Method call =============== =============== =============================================== STORE_SLICE a[?:?] = b calls a.__setslice__(...) or a.__setitem__(...) STORE_SUBSCR a[x] = b calls a.__setitem__(x, b) STORE_ATTR a.x = b calls a.__setattr__("x", b) STORE_NAME a = b calls locals().__setitem__("a", b) STORE_GLOBAL a = b calls dict.__setitem__(globals(), "a", b) STORE_FAST a = b doesn't call any method STORE_DEREF a = b doesn't call any method So you can see that a[...] = b and a.x = b *always* call a method that can be overriden, whereas a = b *almost* never does. The only exception is when the opcode "STORE_NAME" is executed. I'm not sure when something gets compiled to "STORE_NAME", but I can't think of many examples apart from when one uses the "exec" statement. Perhaps someone can enlighten me here. > > I would prefer to think of > > a = something > > and > > lst[i] = something > > as in some sense different, because I see names as referencing locations > in a namespace. Perhaps you can help to unify my perceptions. I think that you are correct, with the "STORE_NAME" caveat. -- Arnaud From drsalists at gmail.com Sun Nov 14 17:31:48 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Sun, 14 Nov 2010 14:31:48 -0800 Subject: Looking For Tutorial Comparison Of sh - perl - python In-Reply-To: References: <3q34r7-m9s2.ln1@ozzie.tundraware.com> Message-ID: On Sun, Nov 14, 2010 at 5:00 AM, Martin Gregorie wrote: > On Sat, 13 Nov 2010 22:05:57 -0600, Tim Daneliuk wrote: > > > I am putting together a comparison & intro to each of sh, perl, python > > with a view towards addressing: > > > Add awk / gawk to that list. IME its often the easiest and most concise > way to process a text file, e.g. a log file, while applying different > processing rules depending on line content and/or generating summaries. > > > Before I attack this myself, has anyone done > > something along these lines I could piggyback upon? > > > I haven't seen such a comparison, but that doesn't meant that they don't > exist. > The perl people might not agree (they seem to frown on the idea of exec'ing anything external, at least when you do it from shell), but I see sh/ksh/bash programming as Including awk, sed, tr and grep, among other tools - and I see that as a Good Thing (tm). As I see it, this keeps POSIX shell proper quite a bit leaner, and very interestingly, makes it very naturally parallelisable. Another cool thing about POSIX shell programming, is that with shell functions, you can have internal extensions (shell functions) and external extensions (shell scripts), with exactly the same syntax in the way they are called, and almost exactly the same syntax in the way they are defined; it almost doesn't matter in which way something was implemented (until you involve subshells). POSIX shell does have its issues though - mostly the proliferation of #!$% noise in the builtins. I hope you'll include something about the fact that POSIX shell is white space sensitive - albeit in a different way from Python. Oh, also, the perl people tend to want to slam POSIX shell for not being portable; I think it is, really, you just need a small amount of information about how to do it. The usual example that gets trotted out is that to suppress a newline you have to say "echo -n fred" in BSD-ish shells, and "echo 'fred\c'" in SysV-ish shells - but: 1) Almost all sh/ksh/bash implementations do -n now. 2) Even if that weren't the case, you could always portably say "echo fred | tr -d '\012'". HTH -------------- next part -------------- An HTML attachment was scrubbed... URL: From jbiquez at icsmx.com Sun Nov 14 17:32:24 2010 From: jbiquez at icsmx.com (Jorge Biquez) Date: Sun, 14 Nov 2010 16:32:24 -0600 Subject: What was your strategy? Message-ID: <201011142240.oAEMecu2054270@krusty.intranet.com.mx> Hello all. Quick question. I know some of you are with Python since started, some other maybe later. I was wondering if you can share what was the strategy you followed to master Python (Yes I know I have to work hard study and practice a lot). I mean did you use special books, special sites, a plan to learn each subject in a special way. I would like to know, if possible, comments specially from some of you who in the past had other languages, frameworks and platforms and left (almost) all of them and stayed with Python. Thanks in advance Jorge Biquez From news1234 at free.fr Sun Nov 14 17:50:08 2010 From: news1234 at free.fr (News123) Date: Sun, 14 Nov 2010 23:50:08 +0100 Subject: how to identify currently running threads QTHreads In-Reply-To: References: <4cdfe050$0$10182$426a34cc@news.free.fr> Message-ID: <4ce067a0$0$3692$426a74cc@news.free.fr> On 11/14/2010 05:32 PM, Aahz wrote: > In article <4cdfe050$0$10182$426a34cc at news.free.fr>, > News123 wrote: >> > >> >Is there a simple way in Python to identify all active Threads / >> >QThreads when trying, such that I can locate the thread, itls related >> >python code and fix it? > threading.enumerate() or sys._current_frames() Thanks a lot From usenet-nospam at seebs.net Sun Nov 14 17:59:23 2010 From: usenet-nospam at seebs.net (Seebs) Date: 14 Nov 2010 22:59:23 GMT Subject: What was your strategy? References: Message-ID: On 2010-11-14, Jorge Biquez wrote: > I was wondering if you can share what was the strategy you followed > to master Python (Yes I know I have to work hard study and practice a > lot). I mean did you use special books, special sites, a plan to > learn each subject in a special way. I would like to know, if > possible, comments specially from some of you who in the past had > other languages, frameworks and platforms and left (almost) all of > them and stayed with Python. I've been learning Python the same way I learn any language; get a book, read it over lunch for a few days, start typing, ask people how to improve my code once I have some. This information is almost certainly useless to you, though, unless you've already learned at least six or seven programming languages. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From drsalists at gmail.com Sun Nov 14 18:08:18 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Sun, 14 Nov 2010 15:08:18 -0800 Subject: Objects versus dictionaries In-Reply-To: References: Message-ID: On Sun, Nov 14, 2010 at 11:20 AM, Chris Rebert wrote: > On Sun, Nov 14, 2010 at 11:00 AM, Micah Carrick > wrote: > > I'm writing a little API that other people will use. There are up to 3 > > "objects" that get passed around. One of them has some validation > methods, > > the other two simply store data and probably won't have any validation or > > other methods. I only made them objects so that they are syntactically > (is > > that a word?) similar the other object rather than using dictionaries. I > > figure it also better allows for changes in the future. > > > > Any thoughts on the pros/cons of using my own objects over a dictionary > > objects? > > Objects are definitely nicer to work with syntactically, and they help > make your program's types more explicit. > Rather than coding the "data holder" classes manually, consider using > namedtuples instead: > http://docs.python.org/library/collections.html#collections.namedtuple > namedtuples are nice, but I don't think pylint understands how to look inside them as well as it understands how to look inside class instances. pylint isn't for everyone, but I find it very useful in producing sturdy python code with few surprises at runtime. -------------- next part -------------- An HTML attachment was scrubbed... URL: From james.harris.1 at googlemail.com Sun Nov 14 18:21:02 2010 From: james.harris.1 at googlemail.com (James Harris) Date: Sun, 14 Nov 2010 15:21:02 -0800 (PST) Subject: What was your strategy? References: Message-ID: <0e852728-1c38-40e3-a7b6-356254e4f038@a9g2000pro.googlegroups.com> On Nov 14, 10:32?pm, Jorge Biquez wrote: > Hello all. > Quick question. I know some of you are with Python since started, > some other maybe later. > > I was wondering if you can share what was the strategy you followed > to master Python (Yes I know I have to work hard study and practice a > lot). I mean did you use special books, special sites, a plan to > learn each subject in a special way. I would like to know, if > possible, comments specially from some of you who in the past had > other languages, frameworks and platforms and left (almost) all of > them and stayed with Python. IMHO there's no one solution. What works for a person depends on how that person learns. Options: books, online free course lecture videos, class instruction, preexisting code, supplied documentation, online tutorials etc. I find it useful to have at least two sources, e.g. two books, as each author brings a slightly different approach and often make different assumptions (and make different mistakes). Comparing two or more makes it easier to see through the differences. But make sure each is reputable in its own right. For example, I used: Learning Python, and Python in a Nutshell (and WxPython in action for the GUI stuff). I'd recommend at least the Nutshell book as a reference. If books work for you check Amazon or similar for feedback of others. James From bnbowman at gmail.com Sun Nov 14 18:30:38 2010 From: bnbowman at gmail.com (Brett Bowman) Date: Sun, 14 Nov 2010 15:30:38 -0800 Subject: Fixing PDF EOF Errors with PyPDF Message-ID: Hey all, I'm trying to read a library of my company's PDFs, but about a third of them can't be opened. PyPDF (v1.12) spits out this error: pyPdf.utils.PdfReadError: EOF marker not found I searched for the answer via google, but all I found was this link: http://lindaocta.com/?tag=pypdf. She suggests fixing the problem by appending an EOF marker like so: def fixPdf(pdfFile): try: fileOpen = file(pdfFile, "a") fileOpen.write("%%EOF") fileOpen.close() return "Fixed" except Exception, e: return "Unable to open file: %s with error: %s" % (pdfFile, str(e)) Which appears to successfully append all of the files, as the exception is never triggered and "Fixed" always returned, but subsequent attempts to open the files all failed. Yet all of those files can be open successfully with Adobe Acrobat Reader. Is this code inorrect or is there some other way to correct this error? Or does the code depend on the system? (I'm using Windows XP, but I believe the author was using a *nix) Sincerely, Brett Bowman -------------- next part -------------- An HTML attachment was scrubbed... URL: From greg.ewing at canterbury.ac.nz Sun Nov 14 18:37:09 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 15 Nov 2010 12:37:09 +1300 Subject: namespace issue, Python vs numpy min/max problem In-Reply-To: <4cdf1376$0$29990$c3e8da3$5496439d@news.astraweb.com> References: <66c318f3-a659-40ec-ad17-74133639d573@h21g2000vbh.googlegroups.com> <4cdf1376$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8kba57Flm7U1@mid.individual.net> Steven D'Aprano wrote: > It > only becomes your problem if you have advised people that the right way > to use your module is with import *. And if you're advising people to do that, it would be an extremely good idea to give your functions different names so that they don't conflict with the builtin min and max. -- Greg From drsalists at gmail.com Sun Nov 14 18:41:07 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Sun, 14 Nov 2010 15:41:07 -0800 Subject: Getting references to objects without incrementing reference counters In-Reply-To: <8c98a453-3303-4509-be39-1a26084f573a@o11g2000prf.googlegroups.com> References: <8c98a453-3303-4509-be39-1a26084f573a@o11g2000prf.googlegroups.com> Message-ID: On Sun, Nov 14, 2010 at 11:08 AM, Artur Siekielski < artur.siekielski at gmail.com> wrote: > Hi. > I'm using CPython 2.7 and Linux. In order to make parallel > computations on a large list of objects I want to use multiple > processes (by using multiprocessing module). In the first step I fill > the list with objects and then I fork() my worker processes that do > the job. > You could try http://docs.python.org/library/multiprocessing.html#multiprocessing.Array to put the data in shared memory. Copy on write is great, but not a panacea, and not optimal in any sense of the word I'm accustomed to. Like you said it depends on page boundaries, and also it can kind of fall apart if a shared library wasn't built as position independent code due to all the address fixups. And it's mostly code that gets shared - data tends to diverge. Supposedly at one time Sun was able to drastically reduce the memory requirements of Solaris by grouping related variables (things that were likely to be needed at the same time) into the same pages of memory. Is it possible you're just seeing a heap grow that isn't getting garbage collected as often as you expect? Normal computation in Python creates objects without free'ing them all that often. HTH -------------- next part -------------- An HTML attachment was scrubbed... URL: From stef.mientki at gmail.com Sun Nov 14 18:49:02 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Mon, 15 Nov 2010 00:49:02 +0100 Subject: What was your strategy? In-Reply-To: <201011142240.oAEMecu2054270@krusty.intranet.com.mx> References: <201011142240.oAEMecu2054270@krusty.intranet.com.mx> Message-ID: <4CE0756E.5090502@gmail.com> On 14-11-2010 23:32, Jorge Biquez wrote: > Hello all. > Quick question. I know some of you are with Python since started, some other maybe later. > > I was wondering if you can share what was the strategy you followed to master Python (Yes I know I > have to work hard study and practice a lot). I mean did you use special books, special sites, a > plan to learn each subject in a special way. I would like to know, if possible, comments specially > from some of you who in the past had other languages, frameworks and platforms and left (almost) > all of them and stayed with Python. > > Thanks in advance > > Jorge Biquez > I think you have to start with determining a goal, some kind of application you want or like to create. Learning to program without a goal (which good well be school assignments) is in my opinion fruitless. Secondly you've to decide if the application will be an old fashion desktop application or a modern web application, or maybe even, it should start as a desktop application and should be easily be converted to a webappplication in the future. (btw I mainly write desktop applications ;-) When you've a goal and a global scope, you can find the right tools: language (Python of course), IDE, framework, etc. cheers, Stef Mientki From ben+python at benfinney.id.au Sun Nov 14 18:53:24 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 15 Nov 2010 10:53:24 +1100 Subject: What was your strategy? References: Message-ID: <877hgfbgy3.fsf@benfinney.id.au> Jorge Biquez writes: > I was wondering if you can share what was the strategy you followed to > master Python (Yes I know I have to work hard study and practice a > lot). I mean did you use special books, special sites, a plan to learn > each subject in a special way. I find that my strategy with learning Python was similar to strategies for learning a natural language: * Use it, as often as feasible. Keep practicing. * Use it, as often as feasible, for real problems. The kind of problems that I actually need a solution to will motivate me to learn when a contrived exercise would not. * Additionally, seek out areas of the language I'm not actively using and learn them too. This pretty much means I'll need contrived exercises, but it guards against staying in a rut of the familiar. * Use it, as much as feasible, in public. Put my inevitable errors on display where they can be discovered and suggestions can be made for improvement. This has the not inconsiderable benefit of encouraging humility also. Those all worked well when I learn a natural language, and they work well for learning a programming language. After all, a programming language is a constructed language for human-to-human communication. It happens to have the additional constraint of communicating with computers as a side goal :-) -- \ ?Spam will be a thing of the past in two years' time.? ?Bill | `\ Gates, 2004-01-24 | _o__) | Ben Finney From jdoe at usenetlove.invalid Sun Nov 14 19:00:57 2010 From: jdoe at usenetlove.invalid (John Doe) Date: 15 Nov 2010 00:00:57 GMT Subject: Komodo 6, why "Workspace Restore" after every restart? Message-ID: <4ce07839$0$17214$c3e8da3$eb767761@news.astraweb.com> Does Komodo have to be shut down individually every time I want to restart Windows XP? Is there some way to eliminate the persistent Workspace Restore error after every restart? I have tried setting it to restore files without asking, but that does not seem to work. Thanks. From deets at web.de Sun Nov 14 19:03:02 2010 From: deets at web.de (Diez B. Roggisch) Date: Mon, 15 Nov 2010 01:03:02 +0100 Subject: Getting references to objects without incrementing reference counters References: <8c98a453-3303-4509-be39-1a26084f573a@o11g2000prf.googlegroups.com> Message-ID: Artur Siekielski writes: > Hi. > I'm using CPython 2.7 and Linux. In order to make parallel > computations on a large list of objects I want to use multiple > processes (by using multiprocessing module). In the first step I fill > the list with objects and then I fork() my worker processes that do > the job. > > This should work optimally in the aspect of memory usage because Linux > implements copy-on-write in forked processes. So I should have only > one physical list of objects (the worker processes don't change the > objects on the list). The problem is that after a short time children > processes are using more and more memory (they don't create new > objects - they only read objects from the list and write computation > result to the database). > > After investigation I concluded the source of this must be > incrementing of a reference counter when getting an object from the > list. It changes only one int but OS must copy the whole memory page > to the child process. I reimplemented the function for getting the > element (from the file listobject.c) but omitting the PY_INCREF call > and it solved my problems with increasing memory. > > The questions is: are there any better ways to have a real read-only > list (in terms of memory representation of objects)? My solution is of > course not safe. I thought about weakrefs but it seems they cannot be > used here because getting a real reference from a weakref increases a > reference counter. Maybe another option would be to store reference > counters not in objects, but in a separate array to minimize number of > memory pages they occupy... You don't say what data you share, and if all of it is needed for each child. So it's hard to suggest optimizations. And AFAIK there is no built-in way of doing what you want. It's complex and error-prone. Maybe mmap + (struct|pickle) help, if what you need can be formulated in a way that traversing the whole data piecewise by explicitly marshaling-demarshaling data? Diez From python at mrabarnett.plus.com Sun Nov 14 19:16:36 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 15 Nov 2010 00:16:36 +0000 Subject: What was your strategy? In-Reply-To: <877hgfbgy3.fsf@benfinney.id.au> References: <877hgfbgy3.fsf@benfinney.id.au> Message-ID: <4CE07BE4.7010707@mrabarnett.plus.com> On 14/11/2010 23:53, Ben Finney wrote: > Jorge Biquez writes: > >> I was wondering if you can share what was the strategy you followed to >> master Python (Yes I know I have to work hard study and practice a >> lot). I mean did you use special books, special sites, a plan to learn >> each subject in a special way. > > I find that my strategy with learning Python was similar to strategies > for learning a natural language: > > * Use it, as often as feasible. Keep practicing. > > * Use it, as often as feasible, for real problems. The kind of problems > that I actually need a solution to will motivate me to learn when a > contrived exercise would not. > > * Additionally, seek out areas of the language I'm not actively using > and learn them too. This pretty much means I'll need contrived > exercises, but it guards against staying in a rut of the familiar. > > * Use it, as much as feasible, in public. Put my inevitable errors on > display where they can be discovered and suggestions can be made for > improvement. This has the not inconsiderable benefit of encouraging > humility also. > I'd also say: don't fight the language, but follow its idioms, and listen to advice from those who know it better, because there's usually a good reason why something is done this way and not that way. It will all make sense in the end. :-) > Those all worked well when I learn a natural language, and they work > well for learning a programming language. > > After all, a programming language is a constructed language for > human-to-human communication. It happens to have the additional > constraint of communicating with computers as a side goal :-) > From data.2 at rediff.com Sun Nov 14 19:26:21 2010 From: data.2 at rediff.com (gaurav) Date: Sun, 14 Nov 2010 16:26:21 -0800 (PST) Subject: Cash your skill in Management careers. Message-ID: <326e2393-25eb-42f4-8845-76bb83bd4089@v28g2000prn.googlegroups.com> Careers in Management work. Careers for your future. http://managementjobs.webs.com/hrm.htm http://topcareer.webs.com/businessmanagement.htm Fresh coming up complete government career, computer jobs. http://rojgars1.webs.com/gov.htm http://printmediajobs.webs.com/fl.htm From herrxandor at gmail.com Sun Nov 14 20:04:38 2010 From: herrxandor at gmail.com (Martin Caum) Date: Sun, 14 Nov 2010 17:04:38 -0800 (PST) Subject: QT window closes immediately Message-ID: <141ef269-de70-4ce1-b4ff-bfb0f58ee9d2@k14g2000pre.googlegroups.com> I am attempting to open a window on mouse activity which works, but the window fails to stay open. I set it to terminate when the escape key is pressed even when the program is not currently selected. This works fine. Originally I had it create the window only with a right click, but when I noticed the window closed immediately I set it to any mouse activity for easier debugging. My script is as follows: [code] import pythoncom, pyHook import sys import win32api from PyQt4 import QtGui, QtCore class WindowObject(QtGui.QWidget): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.setWindowTitle('Window') self.resize(50, 250) def OnKeyboardEvent(event): if event.KeyID == 27: win32api.PostQuitMessage() return 1 def OnMouseEvent(event): x = event.Position[0] y = event.Position[1] createWindow(x, y) return 1 def createWindow(x, y): menu = WindowObject() menu.move(x, y) menu.show() hm = pyHook.HookManager() hm.MouseAll = OnMouseEvent hm.KeyDown = OnKeyboardEvent hm.HookMouse() hm.HookKeyboard() app = QtGui.QApplication(sys.argv) pythoncom.PumpMessages()[/code] I'm fairly certain that this is due to my lack of understanding in the PumpMessages command and the HookManager. Any advice? From no.email at nospam.invalid Sun Nov 14 20:37:34 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 14 Nov 2010 17:37:34 -0800 Subject: What was your strategy? References: Message-ID: <7xzktbcqox.fsf@ruckus.brouhaha.com> Jorge Biquez writes: > I was wondering if you can share what was the strategy you followed to > master Python (Yes I know I have to work hard study and practice a lot). 1. Read the tutorial http://docs.python.org/tutorial/ 2. Start writing code, and encounter various issues as usually happens. 3. Refer to the other reference manuals, web search, and ask questions in the newsgroup as you run into issues. 4. After a while you'll have hit most of the usual issues and learned how to deal with them, and how to find resolution for new issues that might come up. That's about as close to mastery as one normally reaches in this world. Python is a pretty easy language if you have a reasonable programming background when you first start with it. I think the way it's currently organized, it may not be so great for self-study if you're not already a programmer. > I mean did you use special books, special sites, Nah. From rustompmody at gmail.com Sun Nov 14 21:24:17 2010 From: rustompmody at gmail.com (rustom) Date: Sun, 14 Nov 2010 18:24:17 -0800 (PST) Subject: What was your strategy? References: <7xzktbcqox.fsf@ruckus.brouhaha.com> Message-ID: <3701a7aa-7bae-440e-b663-a39549de6699@x4g2000pre.googlegroups.com> Jorge Biquez writes: > I was wondering if you can share what was the strategy you followed to > master Python (Yes I know I have to work hard study and practice a lot). One of the basic mistakes that folks (kids?) studying a language do is to study *only* the language. I guess the mistake happens more in the Java, VB type languages than in python but the mistake is pervasive nevertheless. (Its particularly dangerous with C++ which you can study without mastering for a lifetime) Python is obviously simpler/cleaner etc but still the mistake persists of studying past the point of diminishing returns. Specifically, an intelligent person who has a background of other languages can get the minimal,basic hang in a a day (not so intelligent and inexperienced may be a week or two). After that you need to study OTHER things. Here is such a list 1. "python" 2. IDE (emacs+python-mode in my case, but whatever you use, learn to use it) - debugger - introspection - ipython looks promising 3. CS - algorithms - data structures - 'theory:' FSM, complexity, computability limits, O notation etc 4. Operating Systems How python fits into the OS you are using 5. Paradigms - scripting - functional - oo 6. 'Advanced' Stuff - TDD - Profiling - C interfacing ... The difficult part is studying this stuff independent of python and then making the bridge. eg. 75% of (typical) data-structure books deal with things like 'linked-lists' -- useless in python-- but the remaining 25% you need. From wuwei23 at gmail.com Sun Nov 14 23:03:36 2010 From: wuwei23 at gmail.com (alex23) Date: Sun, 14 Nov 2010 20:03:36 -0800 (PST) Subject: Komodo 6, why "Workspace Restore" after every restart? References: <4ce07839$0$17214$c3e8da3$eb767761@news.astraweb.com> Message-ID: <428b98ca-72bf-4e3b-ad8a-dafe2fc4d553@v28g2000prn.googlegroups.com> On Nov 15, 10:00?am, John Doe wrote: > Does Komodo have to be shut down individually every time I want to > restart Windows XP? Is there some way to eliminate the persistent > Workspace Restore error after every restart? I have tried setting it > to restore files without asking, but that does not seem to work. You'd be better served asking this on the Komodo forums: http://community.activestate.com/forums/komodo-support From brf256 at gmail.com Sun Nov 14 23:09:46 2010 From: brf256 at gmail.com (brf256 at gmail.com) Date: Mon, 15 Nov 2010 04:09:46 +0000 Subject: What was your strategy? Message-ID: <118175645-1289794186-cardhu_decombobulator_blackberry.rim.net-1855251157-@bda480.bisx.prod.on.blackberry> I used "a non programmers tutorial to python" by Josh coglatti. Its a free wikibook too. Then I carried on to "the guide to python". Hope this helps and good luck! - Braden Faulkner - Braden Faulkner From robert.kern at gmail.com Sun Nov 14 23:46:47 2010 From: robert.kern at gmail.com (Robert Kern) Date: Sun, 14 Nov 2010 22:46:47 -0600 Subject: namespace issue, Python vs numpy min/max problem In-Reply-To: <8kba57Flm7U1@mid.individual.net> References: <66c318f3-a659-40ec-ad17-74133639d573@h21g2000vbh.googlegroups.com> <4cdf1376$0$29990$c3e8da3$5496439d@news.astraweb.com> <8kba57Flm7U1@mid.individual.net> Message-ID: On 2010-11-14 17:37 , Gregory Ewing wrote: > Steven D'Aprano wrote: >> It only becomes your problem if you have advised people that the right way to >> use your module is with import *. > > And if you're advising people to do that, it would be an > extremely good idea to give your functions different names > so that they don't conflict with the builtin min and max. And we (the numpy devs) explicitly advise people *against* that. -- 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 drsalists at gmail.com Sun Nov 14 23:47:48 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Sun, 14 Nov 2010 20:47:48 -0800 Subject: Noob question on 2 vs 3 Python releases In-Reply-To: References: Message-ID: On Sun, Nov 14, 2010 at 1:03 AM, Franck Ditter wrote: > Pardon my noobness (?) but why is there a 2.x and 3.x development > teams working concurrently in Python ? I hardly saw that in other > languages. Which one should I choose to start with, to cope with > the future ? Isn't 3.x supposed to extend 2.y ? > This situation is very strange... > Thanks for your explanations... > > franck > -- > http://mail.python.org/mailman/listinfo/python-list > Actually, has there ever been a language with a substantial userbase that didn't ever have two (or more) versions at the same time? C has, C++ has, FORTRAN has, perl has, java has... I believe user migrations are just kind of part of being a computer language. That's a significant part of why code doesn't maintain itself. -------------- next part -------------- An HTML attachment was scrubbed... URL: From jdoe at usenetlove.invalid Mon Nov 15 00:08:53 2010 From: jdoe at usenetlove.invalid (John Doe) Date: 15 Nov 2010 05:08:53 GMT Subject: Komodo 6, why "Workspace Restore" after every restart? References: <4ce07839$0$17214$c3e8da3$eb767761@news.astraweb.com> <428b98ca-72bf-4e3b-ad8a-dafe2fc4d553@v28g2000prn.googlegroups.com> Message-ID: <4ce0c065$0$23246$c3e8da3$a9097924@news.astraweb.com> alex23 wrote: > John Doe wrote: >> Does Komodo have to be shut down individually every time I want >> to restart Windows XP? Is there some way to eliminate the >> persistent Workspace Restore error after every restart? I have >> tried setting it to restore files without asking, but that does >> not seem to work. > > You'd be better served asking this on the Komodo forums: UseNet would be better off if Google Groups didn't exist, IMO. -- > http://community.activestate.com/forums/komodo-support > > see also googled groups > Path: news.astraweb.com!border5.newsrouter.astraweb.com!news-out.readnews.com!transit3.readnews.com!postnews.google.com!v28g2000prn.googlegroups.com!not-for-mail > From: alex23 > Newsgroups: comp.lang.python > Subject: Re: Komodo 6, why "Workspace Restore" after every restart? > Date: Sun, 14 Nov 2010 20:03:36 -0800 (PST) > Organization: http://groups.google.com > Lines: 8 > Message-ID: <428b98ca-72bf-4e3b-ad8a-dafe2fc4d553 v28g2000prn.googlegroups.com> > References: <4ce07839$0$17214$c3e8da3$eb767761 news.astraweb.com> > NNTP-Posting-Host: 130.102.44.25 > Mime-Version: 1.0 > Content-Type: text/plain; charset=ISO-8859-1 > Content-Transfer-Encoding: quoted-printable > X-Trace: posting.google.com 1289793817 25517 127.0.0.1 (15 Nov 2010 04:03:37 GMT) > X-Complaints-To: groups-abuse google.com > NNTP-Posting-Date: Mon, 15 Nov 2010 04:03:37 +0000 (UTC) > Complaints-To: groups-abuse google.com > Injection-Info: v28g2000prn.googlegroups.com; posting-host=130.102.44.25; posting-account=rYyWJQoAAACVJO77HvcyJfa3TnGYCqK_ > User-Agent: G2/1.0 > X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.2.4) Gecko/20100611 Firefox/3.6.4,gzip(gfe) > From wuwei23 at gmail.com Mon Nov 15 00:44:35 2010 From: wuwei23 at gmail.com (alex23) Date: Sun, 14 Nov 2010 21:44:35 -0800 (PST) Subject: Komodo 6, why "Workspace Restore" after every restart? References: <4ce07839$0$17214$c3e8da3$eb767761@news.astraweb.com> <428b98ca-72bf-4e3b-ad8a-dafe2fc4d553@v28g2000prn.googlegroups.com> <4ce0c065$0$23246$c3e8da3$a9097924@news.astraweb.com> Message-ID: <6ae54329-c652-4a59-b0e2-4c2038f58d5a@x4g2000pre.googlegroups.com> John Doe wrote: > UseNet would be better off if Google Groups didn't exist, IMO. I'm sorry, are you cranky because you didn't get the answer you wanted when you posted in a less relevant forum? Why do you think comp.lang.python is more appropriate than the Komodo forums? What does Google Groups have to do with this issue? From lambdadmitry at gmail.com Mon Nov 15 01:39:05 2010 From: lambdadmitry at gmail.com (Dmitry Groshev) Date: Sun, 14 Nov 2010 22:39:05 -0800 (PST) Subject: Some syntactic sugar proposals Message-ID: Here are some proposals. They are quite useful at my opinion and I'm interested for suggestions. It's all about some common patterns. First of all: how many times do you write something like t = foo() t = t if pred(t) else default_value ? Of course we can write it as t = foo() if pred(foo()) else default_value but here we have 2 foo() calls instead of one. Why can't we write just something like this: t = foo() if pred(it) else default_value where "it" means "foo() value"? Second, I saw a lot of questions about using dot notation for a "object-like" dictionaries and a lot of solutions like this: class dotdict(dict): def __getattr__(self, attr): return self.get(attr, None) __setattr__= dict.__setitem__ __delattr__= dict.__delitem__ why there isn't something like this in a standart library? And the third. The more I use python the more I see how "natural" it can be. By "natural" I mean the statements like this: [x.strip() for x in reversed(foo)] which looks almost like a natural language. But there is some pitfalls: if x in range(a, b): #wrong! it feels so natural to check it that way, but we have to write if a <= x <= b I understand that it's not a big deal, but it would be awesome to have some optimisations - it's clearly possible to detect things like that "wrong" one and fix it in a bytecode. x in range optimisation dot dict access foo() if foo() else bar() From lambdadmitry at gmail.com Mon Nov 15 01:40:42 2010 From: lambdadmitry at gmail.com (Dmitry Groshev) Date: Sun, 14 Nov 2010 22:40:42 -0800 (PST) Subject: Some syntactic sugar proposals References: Message-ID: On Nov 15, 9:39?am, Dmitry Groshev wrote: > Here are some proposals. They are quite useful at my opinion and I'm > interested for suggestions. It's all about some common patterns. > First of all: how many times do you write something like > ? ? t = foo() > ? ? t = t if pred(t) else default_value > ? Of course we can write it as > ? ? t = foo() if pred(foo()) else default_value > but here we have 2 foo() calls instead of one. Why can't we write just > something like this: > ? ? t = foo() if pred(it) else default_value > where "it" means "foo() value"? > Second, I saw a lot of questions about using dot notation for a > "object-like" dictionaries and a lot of solutions like this: > ? ? class dotdict(dict): > ? ? ? ? def __getattr__(self, attr): > ? ? ? ? ? ? return self.get(attr, None) > ? ? ? ? __setattr__= dict.__setitem__ > ? ? ? ? __delattr__= dict.__delitem__ > why there isn't something like this in a standart library? > And the third. The more I use python the more I see how "natural" it > can be. By "natural" I mean the statements like this: > ? ? [x.strip() for x in reversed(foo)] > which looks almost like a natural language. But there is some > pitfalls: > ? ? if x in range(a, b): #wrong! > it feels so natural to check it that way, but we have to write > ? ? if a <= x <= b > I understand that it's not a big deal, but it would be awesome to have > some optimisations - it's clearly possible to detect things like that > "wrong" one and fix it in a bytecode. > > x in range optimisation > dot dict access > foo() if foo() else bar() Oh, I'm sorry. I forgot to delete my little notes at the bottom of message. From clp2 at rebertia.com Mon Nov 15 01:48:04 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 14 Nov 2010 22:48:04 -0800 Subject: Some syntactic sugar proposals In-Reply-To: References: Message-ID: On Sun, Nov 14, 2010 at 10:39 PM, Dmitry Groshev wrote: > Here are some proposals. They are quite useful at my opinion and I'm > interested for suggestions. It's all about some common patterns. > Second, I saw a lot of questions about using dot notation for a > "object-like" dictionaries and a lot of solutions like this: > ? ?class dotdict(dict): > ? ? ? ?def __getattr__(self, attr): > ? ? ? ? ? ?return self.get(attr, None) > ? ? ? ?__setattr__= dict.__setitem__ > ? ? ? ?__delattr__= dict.__delitem__ > why there isn't something like this in a standart library? There is: http://docs.python.org/library/collections.html#collections.namedtuple The "bunch" recipe is also fairly well-known; I suppose one could argue whether it's std-lib-worthy: http://code.activestate.com/recipes/52308-the-simple-but-handy-collector-of-a-bunch-of-named/ Cheers, Chris From lambdadmitry at gmail.com Mon Nov 15 01:53:33 2010 From: lambdadmitry at gmail.com (Dmitry Groshev) Date: Sun, 14 Nov 2010 22:53:33 -0800 (PST) Subject: Some syntactic sugar proposals References: Message-ID: On Nov 15, 9:48?am, Chris Rebert wrote: > On Sun, Nov 14, 2010 at 10:39 PM, Dmitry Groshev wrote: > > Here are some proposals. They are quite useful at my opinion and I'm > > interested for suggestions. It's all about some common patterns. > > > Second, I saw a lot of questions about using dot notation for a > > "object-like" dictionaries and a lot of solutions like this: > > ? ?class dotdict(dict): > > ? ? ? ?def __getattr__(self, attr): > > ? ? ? ? ? ?return self.get(attr, None) > > ? ? ? ?__setattr__= dict.__setitem__ > > ? ? ? ?__delattr__= dict.__delitem__ > > why there isn't something like this in a standart library? > > There is:http://docs.python.org/library/collections.html#collections.namedtuple > > The "bunch" recipe is also fairly well-known; I suppose one could > argue whether it's std-lib-worthy:http://code.activestate.com/recipes/52308-the-simple-but-handy-collec... > > Cheers, > Chris namedtuple is not a "drop-in" replacement like this "dotdict" thing - you first need to create a new namedtuple instance. As for me it's a bit too complicated. From wuwei23 at gmail.com Mon Nov 15 02:30:30 2010 From: wuwei23 at gmail.com (alex23) Date: Sun, 14 Nov 2010 23:30:30 -0800 (PST) Subject: Some syntactic sugar proposals References: Message-ID: <4ac1734d-fffb-4fdc-be42-27812a174b97@i32g2000pri.googlegroups.com> On Nov 15, 4:39?pm, Dmitry Groshev wrote: > First of all: how many times do you write something like > ? ? t = foo() > ? ? t = t if pred(t) else default_value > ? Of course we can write it as > ? ? t = foo() if pred(foo()) else default_value > but here we have 2 foo() calls instead of one. Why can't we write just > something like this: > ? ? t = foo() if pred(it) else default_value > where "it" means "foo() value"? Could you provide an actual use case for this. This seems weird to me: you're creating an object, testing the object, then possibly throwing it away and using a default instead. Are you sure you can't restructure your code as such: t = foo(x) if else default > Second, I saw a lot of questions about using dot notation for a > "object-like" dictionaries and a lot of solutions like this: > ? ? class dotdict(dict): > ? ? ? ? def __getattr__(self, attr): > ? ? ? ? ? ? return self.get(attr, None) > ? ? ? ? __setattr__= dict.__setitem__ > ? ? ? ? __delattr__= dict.__delitem__ > why there isn't something like this in a standart library? Personally, I like keeping object attribute references separate from dictionary item references. If you're someone who doesn't mind muddying that distinction, then - as you've discovered - it's a simple addition to your own code. > ? ? if x in range(a, b): #wrong! Only in Python 3.x, it's perfectly valid in Python 2.x. To achieve the same in Python 3.x, try: if x in list(range(a, b,)): # BUT SEE MY COMMENT BELOW > it feels so natural to check it that way, but we have to write > ? ? if a <= x <= b > I understand that it's not a big deal, but it would be awesome to have > some optimisations - it's clearly possible to detect things like that > "wrong" one and fix it in a bytecode. This seems more like a pessimisation to me: your range version constructs a list just to do a single container check. That's a _lot_ more cumbersome than two simple comparisons chained together. From wuwei23 at gmail.com Mon Nov 15 02:31:45 2010 From: wuwei23 at gmail.com (alex23) Date: Sun, 14 Nov 2010 23:31:45 -0800 (PST) Subject: Some syntactic sugar proposals References: <4ac1734d-fffb-4fdc-be42-27812a174b97@i32g2000pri.googlegroups.com> Message-ID: <62c29144-d2bf-4f30-88c9-e726f62b5dc2@k14g2000pre.googlegroups.com> On Nov 15, 5:30?pm, alex23 wrote: > ? ?t = foo(x) if else default This should read 'test' instead of 'text', sorry. From lambdadmitry at gmail.com Mon Nov 15 02:50:33 2010 From: lambdadmitry at gmail.com (Dmitry Groshev) Date: Sun, 14 Nov 2010 23:50:33 -0800 (PST) Subject: Some syntactic sugar proposals References: <4ac1734d-fffb-4fdc-be42-27812a174b97@i32g2000pri.googlegroups.com> Message-ID: On Nov 15, 10:30?am, alex23 wrote: > On Nov 15, 4:39?pm, Dmitry Groshev wrote: > > > First of all: how many times do you write something like > > ? ? t = foo() > > ? ? t = t if pred(t) else default_value > > ? Of course we can write it as > > ? ? t = foo() if pred(foo()) else default_value > > but here we have 2 foo() calls instead of one. Why can't we write just > > something like this: > > ? ? t = foo() if pred(it) else default_value > > where "it" means "foo() value"? > > Could you provide an actual use case for this. This seems weird to me: > you're creating an object, testing the object, then possibly throwing > it away and using a default instead. Are you sure you can't > restructure your code as such: > > ? ?t = foo(x) if else default Sure. Let's pretend you have some string foo and compiled regular expression bar. Naive code: t = bar.findall(foo) if len(t) < 3: t = [] Code with proposed syntactic sugar: t = bar.findall(foo) if len(it) > 2 else [] > > Second, I saw a lot of questions about using dot notation for a > > "object-like" dictionaries and a lot of solutions like this: > > ? ? class dotdict(dict): > > ? ? ? ? def __getattr__(self, attr): > > ? ? ? ? ? ? return self.get(attr, None) > > ? ? ? ? __setattr__= dict.__setitem__ > > ? ? ? ? __delattr__= dict.__delitem__ > > why there isn't something like this in a standart library? > > Personally, I like keeping object attribute references separate from > dictionary item references. Your Python doesn't - dot notation is just a sugar for __dict__ lookup with default metaclass. > This seems more like a pessimisation to me: your range version > constructs a list just to do a single container check. That's a _lot_ > more cumbersome than two simple comparisons chained together. By "wrong" I meant exactly this. I told about "compiler" optimisation of statements like this so it would not construct a list. From jdoe at usenetlove.invalid Mon Nov 15 03:08:25 2010 From: jdoe at usenetlove.invalid (John Doe) Date: 15 Nov 2010 08:08:25 GMT Subject: Komodo 6, why "Workspace Restore" after every restart? References: <4ce07839$0$17214$c3e8da3$eb767761@news.astraweb.com> <428b98ca-72bf-4e3b-ad8a-dafe2fc4d553@v28g2000prn.googlegroups.com> <4ce0c065$0$23246$c3e8da3$a9097924@news.astraweb.com> <6ae54329-c652-4a59-b0e2-4c2038f58d5a@x4g2000pre.googlegroups.com> Message-ID: <4ce0ea79$0$29271$c3e8da3$88b277c5@news.astraweb.com> alex23 wrote: > John Doe wrote: >> UseNet would be better off if Google Groups didn't exist, IMO. > > I'm sorry, are you cranky because you didn't get the answer you > wanted when you posted in a less relevant forum? Do you realize the harm your filthy news server is doing to UseNet? Many regulars here block all of those who post through Google Groups. That is because your stinking news server spams UseNet like no other ever has. > Why do you think comp.lang.python is more appropriate than the > Komodo forums? Because I prefer posting to UseNet. Komodo is a popular subject here. > What does Google Groups have to do with this issue? Google Groups spews a massive amount of sewage onto UseNet everyday. Google Groups is your news server. You should be ashamed, and I want to help. From nobody at nowhere.com Mon Nov 15 03:08:26 2010 From: nobody at nowhere.com (Nobody) Date: Mon, 15 Nov 2010 08:08:26 +0000 Subject: subprocess pipe References: Message-ID: On Sun, 14 Nov 2010 19:47:55 +0000, Tim Harig wrote: > On 2010-11-14, Camille Harang wrote: >> # pg_dump prompts for password so I inject it in stdin. >> pgsql.stdin.write('MY_PASSWORD' + '\n') > > For security reasons, some programs use direct access to the TTY system > for password entry rather then reading from stdin. Indeed, the getpass() function exists[1] for this purpose: The getpass() function opens /dev/tty (the controlling terminal of the process), outputs the string prompt, turns off echoing, reads one line (the "password"), restores the terminal state and closes /dev/tty again. [1] Or existed. It was dropped from the Unix standard in POSIX.1-2001, but most systems still provide it. From wuwei23 at gmail.com Mon Nov 15 03:42:36 2010 From: wuwei23 at gmail.com (alex23) Date: Mon, 15 Nov 2010 00:42:36 -0800 (PST) Subject: Komodo 6, why "Workspace Restore" after every restart? References: <4ce07839$0$17214$c3e8da3$eb767761@news.astraweb.com> <428b98ca-72bf-4e3b-ad8a-dafe2fc4d553@v28g2000prn.googlegroups.com> <4ce0c065$0$23246$c3e8da3$a9097924@news.astraweb.com> <6ae54329-c652-4a59-b0e2-4c2038f58d5a@x4g2000pre.googlegroups.com> <4ce0ea79$0$29271$c3e8da3$88b277c5@news.astraweb.com> Message-ID: <15016ae4-b341-4f4e-ac84-62fe7f93f217@g20g2000prg.googlegroups.com> John Doe wrote: > Google Groups spews a massive amount of sewage onto UseNet > everyday. Google Groups is your news server. You should be > ashamed, and I want to help. Get over yourself. From jarausch at igpm.rwth-aachen.de Mon Nov 15 03:46:17 2010 From: jarausch at igpm.rwth-aachen.de (Helmut Jarausch) Date: 15 Nov 2010 08:46:17 GMT Subject: import site fails - Please Help Message-ID: <8kcaapF44bU1@mid.dfncis.de> Hi, I'm completely puzzled and I hope someone can shed some light on it. After cloning a running system, booting the new machine from a rescue CD, chroot to the new root partition, I get the following strange error from python upon startup python -v > import site failed .... st= os.stat(path) stat() argument 1 must be encoded string without NULL bytes, not str So, what's broken? How can I get out what 'path' contained at this moment? Many thanks for your help, Helmut. From wuwei23 at gmail.com Mon Nov 15 04:03:55 2010 From: wuwei23 at gmail.com (alex23) Date: Mon, 15 Nov 2010 01:03:55 -0800 (PST) Subject: Some syntactic sugar proposals References: <4ac1734d-fffb-4fdc-be42-27812a174b97@i32g2000pri.googlegroups.com> Message-ID: On Nov 15, 5:50?pm, Dmitry Groshev wrote: > On Nov 15, 10:30?am, alex23 wrote: > > Personally, I like keeping object attribute references separate from > > dictionary item references. > > Your Python doesn't - dot notation is just a sugar for __dict__ lookup > with default metaclass. That's a gross oversimplification that tends towards wrong: >>> class C(object): ... def __init__(self): ... self._x = None ... @property ... def x(self): return self._x ... @x.setter ... def x(self, val): self._x = val ... >>> c = C() >>> c.x = 1 >>> c.x 1 >>> c.__dict__['x'] Traceback (most recent call last): File "", line 1, in KeyError: 'x' But my concern has _nothing_ to do with the implementation detail of how objects hold attributes, it's solely over the clarity that comes from being able to visually tell that something is an object vs a dictionary. > > This seems more like a pessimisation to me: your range version > > constructs a list just to do a single container check. That's a _lot_ > > more cumbersome than two simple comparisons chained together. > > By "wrong" I meant exactly this. I told about "compiler" optimisation > of statements like this so it would not construct a list. So you want this: if x in range(1,10): ...to effectively emit the same bytecode as a chained comparison while this: for x in range(1,10): ...produces a list/generator? Never going to happen. "Special cases aren't special enough to break the rules." The standard form for chained comparisons can handle far more complex expressions which your 'in' version could not: 0 <= min <= max <= 100 From jdoe at usenetlove.invalid Mon Nov 15 04:04:08 2010 From: jdoe at usenetlove.invalid (John Doe) Date: 15 Nov 2010 09:04:08 GMT Subject: Komodo 6, why "Workspace Restore" after every restart? References: <4ce07839$0$17214$c3e8da3$eb767761@news.astraweb.com> <428b98ca-72bf-4e3b-ad8a-dafe2fc4d553@v28g2000prn.googlegroups.com> <4ce0c065$0$23246$c3e8da3$a9097924@news.astraweb.com> <6ae54329-c652-4a59-b0e2-4c2038f58d5a@x4g2000pre.googlegroups.com> <4ce0ea79$0$29271$c3e8da3$88b277c5@news.astraweb.com> <15016ae4-b341-4f4e-ac84-62fe7f93f217@g20g2000prg.googlegroups.com> Message-ID: <4ce0f788$0$30018$c3e8da3$76a7c58f@news.astraweb.com> alex23 wrote: > John Doe wrote: >> Google Groups spews a massive amount of sewage onto UseNet >> everyday. Google Groups is your news server. You should be >> ashamed > > Get over yourself. You too, and stop using the spammers den while you are at it. -- See also googled groups > Path: news.astraweb.com!border5.newsrouter.astraweb.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!postnews.google.com!g20g2000prg.googlegroups.com!not-for-mail > From: alex23 > Newsgroups: comp.lang.python > Subject: Re: Komodo 6, why "Workspace Restore" after every restart? > Date: Mon, 15 Nov 2010 00:42:36 -0800 (PST) > Organization: http://groups.google.com > Lines: 6 > Message-ID: <15016ae4-b341-4f4e-ac84-62fe7f93f217 g20g2000prg.googlegroups.com> > References: <4ce07839$0$17214$c3e8da3$eb767761 news.astraweb.com> <428b98ca-72bf-4e3b-ad8a-dafe2fc4d553 v28g2000prn.googlegroups.com> <4ce0c065$0$23246$c3e8da3$a9097924 news.astraweb.com> <6ae54329-c652-4a59-b0e2-4c2038f58d5a x4g2000pre.googlegroups.com> <4ce0ea79$0$29271$c3e8da3$88b277c5 news.astraweb.com> > NNTP-Posting-Host: 115.64.196.128 > Mime-Version: 1.0 > Content-Type: text/plain; charset=ISO-8859-1 > X-Trace: posting.google.com 1289810556 23916 127.0.0.1 (15 Nov 2010 08:42:36 GMT) > X-Complaints-To: groups-abuse google.com > NNTP-Posting-Date: Mon, 15 Nov 2010 08:42:36 +0000 (UTC) > Complaints-To: groups-abuse google.com > Injection-Info: g20g2000prg.googlegroups.com; posting-host=115.64.196.128; posting-account=rYyWJQoAAACVJO77HvcyJfa3TnGYCqK_ > User-Agent: G2/1.0 > X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.12 (KHTML, like Gecko) Chrome/9.0.576.0 Safari/534.12,gzip(gfe) > From lambdadmitry at gmail.com Mon Nov 15 04:27:02 2010 From: lambdadmitry at gmail.com (Dmitry Groshev) Date: Mon, 15 Nov 2010 01:27:02 -0800 (PST) Subject: Some syntactic sugar proposals References: <4ac1734d-fffb-4fdc-be42-27812a174b97@i32g2000pri.googlegroups.com> Message-ID: <3f1c77d1-b3b4-4f34-b61c-1598dba3517a@e20g2000vbn.googlegroups.com> On Nov 15, 12:03?pm, alex23 wrote: > On Nov 15, 5:50?pm, Dmitry Groshev wrote: > > > On Nov 15, 10:30?am, alex23 wrote: > > > Personally, I like keeping object attribute references separate from > > > dictionary item references. > > > Your Python doesn't - dot notation is just a sugar for __dict__ lookup > > with default metaclass. > > That's a gross oversimplification that tends towards wrong: > > >>> class C(object): > > ... ? def __init__(self): > ... ? ? self._x = None > ... ? @property > ... ? def x(self): return self._x > ... ? @x.setter > ... ? def x(self, val): self._x = val > ...>>> c = C() > >>> c.x = 1 > >>> c.x > 1 > >>> c.__dict__['x'] > > Traceback (most recent call last): > ? File "", line 1, in > KeyError: 'x' > > But my concern has _nothing_ to do with the implementation detail of > how objects hold attributes, it's solely over the clarity that comes > from being able to visually tell that something is an object vs a > dictionary. Oh, now I understand you. But this "dotdict" (or "bunch") things don't break anything. You still need to use it explicitly and it is very useful if you need to serialize some JSON data about some entities. s = """[{"name": "Jhon Doe", "age": "12"}, {"name": "Alice", "age": "23"}]""" t = map(dotdict, json.loads(s)) t[0] #{'age': '12', 'name': 'Jhon Doe'} t[0].age #'12' Of course you can do this with namedtuple, but in fact this isn't a tuple at all. It's a list of entities. > > > This seems more like a pessimisation to me: your range version > > > constructs a list just to do a single container check. That's a _lot_ > > > more cumbersome than two simple comparisons chained together. > > > By "wrong" I meant exactly this. I told about "compiler" optimisation > > of statements like this so it would not construct a list. > > So you want this: > > ? if x in range(1,10): > > ...to effectively emit the same bytecode as a chained comparison while > this: > > ? for x in range(1,10): > > ...produces a list/generator? > > Never going to happen. "Special cases aren't special enough to break > the rules." The standard form for chained comparisons can handle far > more complex expressions which your 'in' version could not: 0 <= min > <= max <= 100 I know about chained comparisons, thanks. It's not about them. It's about bytecode optimisation. But maybe you are right about "Special cases aren't special enough to break the rules". I kinda forgot that :) From aioe.org at technicalbloke.com Mon Nov 15 05:09:31 2010 From: aioe.org at technicalbloke.com (r0g) Date: Mon, 15 Nov 2010 10:09:31 +0000 Subject: is there an Python equivalent for the PHP super globals like $_POST, $_COOKIE ? References: Message-ID: On 12/11/10 01:25, Roy Smith wrote: > In article, > r0g wrote: > >> On 11/11/10 14:22, Stef Mientki wrote: >>> I can't find how th get to PHP's equivalent of $_Post and $_Cookie ? > > PHP is mostly a one-trick pony. It's meant to be run as a web scripting > language with Apache (or, I suppose, something else) on the front end. > As a result, a lot of web-specific things like $_Post and $_Cookie are > built into the language. > > Python is intended to be more general purpose, so things which are built > in to other languages usually can be found in library modules. In this > case, you probably want to look at the SimpleHTTPServer module. > Actually when they say "Simple" they really mean it. The the SimpleHTTPServer module doesn't parse form data at all. It's pretty easy to get that using the urlparse module though... def do_GET(self): getvars = urlparse.parse_qs( self.path ) field1 = getvars[ "username" ][0] field2 = getvars[ "password" ][0] if authenticate( field1, filed2 ): self.send_response(200) self.send_header("Content-type", "text/html") self.end_headers() self.wfile.write( "welcome" ) else: self.send_response(404) self.end_headers() return This may be lower level than you want really and does involve permanently running a daemon on your server as opposed to the PHP way of doing things (having Apache interpret PHP on a page by page basis). > My latest gig, however, has had me doing PHP for the past 3 months or > so. That's terrible, you have my fullest sympathy in these difficult times. Roger From mdw at distorted.org.uk Mon Nov 15 05:52:31 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Mon, 15 Nov 2010 10:52:31 +0000 Subject: strange behavor.... References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> <87tyjlhu1l.fsf.mdw@metalzone.distorted.org.uk> <87hbfk29gy.fsf@gmail.com> <87hbfkj247.fsf.mdw@metalzone.distorted.org.uk> <4cdf447d$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87lj4uhn9s.fsf.mdw@metalzone.distorted.org.uk> Steven D'Aprano writes: > > def foo(): > > l = [] > > for i in xrange(10): > > (lambda j: l.append((lambda: i, lambda: j)))(i) > > print [(f(), g()) for f, g in l] > > Here's a slightly less condensed version that demonstrates the same > behaviour, but may be slightly easier to understand: The output is the same but the reasons for it are different: > def spam(): > a = [] > b = [] > for i in xrange(5): > a.append(lambda: i) > b.append(lambda i=i: i) Here, you've replaced lambda-binding by a default argument value. > print [f() for f in a] > print [f() for f in b] > > In your function foo, the name "i" is bound to the objects 0, 1, 2, ... 9 > sequentially, each time around the for-loop. Inside the loop, a function > object is created and then called: > > (lambda j: l.append((lambda: i, lambda: j)))(i) > > (Aside: this depends on scoping rules that were introduced quite late in > Python's history -- prior to version 2.2, this wouldn't work at all.) Indeed. The default-argument trick above was used to simulate it. Not coincidentally, it was around version 2.2 that Python became interesting to me... > The "outer" lambda: > > lambda j: l.append(...) > > has a name in the function namespace (a "local variable") called "j". On > entry to this function, this j is bound to the same object which is bound > to i *at the time that the function is called*. That is, each of the > sequence of "outer" lambdas get a distinct j = 0, 1, 2, ... Ahh. You've invented a new concept of localness instead, which is equivalent to the usual notion of binding. > None of the function A0, A1, A2, ... have any local variable i. i.e., i is free in the An functions and in the outer lambda... > Functions B0, B1, B2, ... similarly have no local variable j. When you > call any of the Bs, Python looks in the enclosing scopes for a variable > j. However, in this case it *does* find one, in the "outer" lambda, ... but j is bound in the outer lambda. This is not new terminology: it goes back to lambda calculus: a variable x occurs free in a term T if * T is x; * T is U V where x occurs free in U or V; or * T is lambda y.U where y is not x and x occurs free in U. If x occurs free in T then it occurs bound in lambda x.T. See also SICP. > > * Python's `for' loop works by assignment. The name `i' remains bound > > to the same storage location throughout; > > This is not necessarily true. It's true for CPython, where function > locals are implemented as fixed slots in the function object; since the > slot doesn't move relative to the function, and the function doesn't move > relative to the heap, the name i is in a fixed storage location for the > life of foo. But that's not necessarily the case for all implementations > -- locals could be stored in a data structure that moves data around > (say, a red-black tree), or objects could be free to move in the heap, or > both. Don't be silly. In a tree, the `location' would be the tree node containing the corresponding key. You're working at the wrong level of abstraction. -- [mdw] From ph.ton.sharma at gmail.com Mon Nov 15 06:03:57 2010 From: ph.ton.sharma at gmail.com (Ton) Date: Mon, 15 Nov 2010 03:03:57 -0800 (PST) Subject: Help: Guide needed in trying to delete/flush the content of a fifo file. References: Message-ID: <1c7f7feb-ff95-404b-9628-458922360908@j12g2000prm.googlegroups.com> On Nov 14, 11:55?pm, MRAB wrote: > On 14/11/2010 14:48, ton ph wrote:> Hi python geeks, > > ? ?I have ?problem which i have been trying to find out for the past > > some days, i have a device which feeds info to my fifo continuosly, and > > a thread of mine reads the > > fifo continuosly. Now when i change a parameter in the device, it sends > > me different values. Now my problem is that , i want to get rid of the > > contents of my previous info which > > is present in my buffer of the fifo.So i want to flush the fifo content > > when my device starts sending different info .... i am implementing > > writing and reading the fifo ?using two different threads. > > Please someone guide me solving my problem. > > I highly apologise everyone in case my post is not so clear... > > Thanks everyone in advance. > > When the info changes, the thread which is putting items into the fifo > could flush it just by getting items from it (using a non-blocking get) > until it's empty. Hi Mrab, Thanks for your immediate reply , can you please guide me with any tool or library function which i can flush my fifo content .. i use os.mkfifo() to make the fifo. Or is there any other way i could do this ... Thanks From mdw at distorted.org.uk Mon Nov 15 06:07:12 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Mon, 15 Nov 2010 11:07:12 +0000 Subject: strange behavor.... References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> <87tyjlhu1l.fsf.mdw@metalzone.distorted.org.uk> <4cdf1206$0$29990$c3e8da3$5496439d@news.astraweb.com> <877hggiz17.fsf.mdw@metalzone.distorted.org.uk> <874obj1r0z.fsf@gmail.com> Message-ID: <87hbfihmlb.fsf.mdw@metalzone.distorted.org.uk> Arnaud Delobelle writes: > >>> exec "a=2" in d > assigning 2 to 'a' > >>> d['a'] > 2 > > >>> exec "global a; a = 3" in d > >>> d['a'] > 3 Oooh, now isn't that an interesting wrinkle? I've been careful (without drawing attention) to restrict my arguments to variables inside functions, largely because Python's global scopes work completely differently. (Python's global scopes work similarly to traditional Lisp and Scheme, which isn't at all objectionable, but it's not the only way of managing global scopes. Queinnec's Lisp In Small Pieces describes others.) > So even if the globals() dictionary is custom, its __setitem__ method is > *not* called. Fascinating. Thank you. -- [mdw] From hniksic at xemacs.org Mon Nov 15 06:10:29 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Mon, 15 Nov 2010 12:10:29 +0100 Subject: Some syntactic sugar proposals References: Message-ID: <87oc9q266y.fsf@xemacs.org> Dmitry Groshev writes: > which looks almost like a natural language. But there is some > pitfalls: > if x in range(a, b): #wrong! > it feels so natural to check it that way, but we have to write > if a <= x <= b For the record, you have to write: if a <= x < b: Ranges are open on the ending side. From chrmic at gmx.de Mon Nov 15 06:24:40 2010 From: chrmic at gmx.de (Christoph Michalke) Date: Mon, 15 Nov 2010 12:24:40 +0100 Subject: distutils, cygwin, ' not a regular file Message-ID: <20101115112440.193500@gmx.net> In-Reply-To: <8faqj0FnoeU1 at mid.individual.net> References: <8faqj0FnoeU1 at mid.individual.net> In message <8faqj0FnoeU1 at mid.individual.net>, on Tue, 14 Sep 2010 20:50:04 -0600, Wed Sep 15 04:50:04 2010, Paul Watson wrote: > $ python setup.py sdist > [...] > reading manifest file 'MANIFEST' > [...] > ' not a regular file -- skipping > ' not a regular file -- skipping > ' not a regular file -- skipping In distutils/command/sdist.py in make_release_tree() I find log.warn("'%s' not a regular file -- skipping" % file) Therefore 2 apostrophes should appear in your setup.py sdist output. But you are seeing only one, therefore the file names in your file list probably contain a "\r" (carriage return). You seem to get your file list from a MANIFEST file, and probably this MANIFEST file was checked in on Windows with CR LF line endings and now you are reading it in cygwin (or in any Unix like environment) and you are getting a file name "sample.py\r" instead of "sample.py". The file "sample.py" exists and is a regular file. But the file "sample.py\r" does not exist and is therefore especially not a regular file. HTH, regards Christoph -- GMX DSL Doppel-Flat ab 19,99 €/mtl.! Jetzt auch mit gratis Notebook-Flat! http://portal.gmx.net/de/go/dsl From mdw at distorted.org.uk Mon Nov 15 07:28:46 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Mon, 15 Nov 2010 12:28:46 +0000 Subject: Some syntactic sugar proposals References: Message-ID: <87zktag48x.fsf.mdw@metalzone.distorted.org.uk> Dmitry Groshev writes: > First of all: how many times do you write something like > t = foo() > t = t if pred(t) else default_value > ? Of course we can write it as > t = foo() if pred(foo()) else default_value > but here we have 2 foo() calls instead of one. Why can't we write just > something like this: > t = foo() if pred(it) else default_value > where "it" means "foo() value"? How about t = (lambda y: y if pred(y) else default_value)(foo(x)) You could even package the lambda into a named function if you get bored of typing or your aesthetic senses are offended. > And the third. The more I use python the more I see how "natural" it > can be. By "natural" I mean the statements like this: > [x.strip() for x in reversed(foo)] > which looks almost like a natural language. But there is some > pitfalls: > if x in range(a, b): #wrong! > it feels so natural to check it that way, but we have to write > if a <= x <= b This, I think, is your error. The test `x in range(a, b)' means the same as `a <= x < b' (only in Python 2 it builds a list and then throws it away again). Such half-open intervals turn out to be what you want most of the time, and I think you'll avoid many bugs if you embrace them rather than trying to cling to the fully-closed intervals above. Python very definitely made the right decision to use half-open intervals pervasively, e.g., for `rangeand 'in sequence slicing. It's a bad idea to fight against it. Advantages of half-open intervals [a, b): * The number of elements is exactly b - a; closed intervals contain an extra element which is often forgotten. * They compose and split nicely: if a <= c <= b then [a, b) is exactly the disjoint union of [a, c) and [c, b). * Sums over these intervals are often better behaved; indeed, there's a rather pretty analogy between sums on half-open intervals and definite integrals which is lost if you use closed intervals. (The above two observations are special cases of this one.) See Concrete Mathematics (Graham, Knuth, Patashnik) for more on this. * It's easy to express an empty interval. You can't do that if you work entirely with closed intervals, but empty sets are an important boundary case and it's annoying to have to handle them separately. -- [mdw] From santosh.srinivas at gmail.com Mon Nov 15 07:38:25 2010 From: santosh.srinivas at gmail.com (Santosh Srinivas) Date: Mon, 15 Nov 2010 12:38:25 -0000 Subject: DDE using Python Message-ID: <4ce129b9.1c988e0a.4142.5ae0@mx.google.com> Hello Group, I want to connect to an application on my desktop that I understand provides access to few topics and data via DDE. But, I don't know the topic names. Is there any way that I can connect and find out what the available options are? Thanks. S From python.list at tim.thechases.com Mon Nov 15 07:46:59 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 15 Nov 2010 06:46:59 -0600 Subject: Some syntactic sugar proposals In-Reply-To: References: Message-ID: <4CE12BC3.80404@tim.thechases.com> On 11/15/2010 12:39 AM, Dmitry Groshev wrote: > x in range optimisation I've often thought this would make a nice O(1)-test lookup on an xrange() generator. I don't have strong use-cases for it, but a bit of well-tested code in the standard library would save me from doing the math (along with its potential fenceposting and sign errors) the couple times I've reached for it. Using the x in list(xrange(...)) # or "range()" depending your version ends up with an O(n) lookup, though I suppose one could create a set() for O(1) lookups, but that still requires O(N) storage (where a mathematical lookup would involve O(1) storage *and* time) > foo() if foo() else bar() This is usually indicative that you need to cache the object...something like etcc = expensive_to_calculate_constructor() result = foo(etcc) if test(etcc) else bar() That way, you cache the potentially-expensive calculation, indicate to other readers-of-your-code that it's potentially-expensive, and enforce the use of that cache to ensure that you don't duplicate the expensive op. -tkc From neilc at norwich.edu Mon Nov 15 08:14:28 2010 From: neilc at norwich.edu (Neil Cerutti) Date: 15 Nov 2010 13:14:28 GMT Subject: another newbie question References: Message-ID: <8kcq1kFo4gU8@mid.individual.net> On 2010-11-14, Roy Smith wrote: > Then, there are people who try to program in proportional > fonts. The mind boggles. For a (thankfully short) while some > years ago, people were publishing programming books with the > code samples in proportional fonts. Blech. I kinda like it, but as a Vim user I can't partake. -- Neil Cerutti From artur.siekielski at gmail.com Mon Nov 15 08:54:56 2010 From: artur.siekielski at gmail.com (Artur Siekielski) Date: Mon, 15 Nov 2010 05:54:56 -0800 (PST) Subject: Getting references to objects without incrementing reference counters References: <8c98a453-3303-4509-be39-1a26084f573a@o11g2000prf.googlegroups.com> <8063c457-98bf-4add-a1c7-38b01848cbe3@w21g2000vby.googlegroups.com> Message-ID: <4feaf76f-2533-4776-95a3-d312be76ddb0@d20g2000yqg.googlegroups.com> On Nov 14, 10:04?pm, Jean-Paul Calderone wrote: > It might be interesting to try with Jython or PyPy. ?Neither of these > Python runtimes uses reference counting at all. I have to use CPython because of C extensions I use (and because I use Python 2.7 features). From roy at panix.com Mon Nov 15 09:00:05 2010 From: roy at panix.com (Roy Smith) Date: Mon, 15 Nov 2010 09:00:05 -0500 Subject: is there an Python equivalent for the PHP super globals like $_POST, $_COOKIE ? References: Message-ID: In article , r0g wrote: > > My latest gig, however, has had me doing PHP for the past 3 months or > > so. > > That's terrible, you have my fullest sympathy in these difficult times. Actually, in a sick sort of way, it's fun. We regularly have PHP bashing sessions in the office when somebody discovers yet another depraved piece of language mis-design and we all get a good laugh out of it. No all languages afford you the opportunity for this kind of entertainment. It's also quite educational. You can learn a lot about language design by observing the mistakes that can be made. From artur.siekielski at gmail.com Mon Nov 15 09:13:15 2010 From: artur.siekielski at gmail.com (Artur Siekielski) Date: Mon, 15 Nov 2010 06:13:15 -0800 (PST) Subject: Getting references to objects without incrementing reference counters References: <8c98a453-3303-4509-be39-1a26084f573a@o11g2000prf.googlegroups.com> Message-ID: <0afcca4a-13b7-42ab-aea5-86b4324708e3@p1g2000yqm.googlegroups.com> On Nov 15, 1:03?am, de... at web.de (Diez B. Roggisch) wrote: > You don't say what data you share, and if all of it is needed for each > child. So it's hard to suggest optimizations. Here is an example of such a problem I'm dealing with now: I'm building large index of words in memory, it takes 50% of RAM. After building it I want to enable querying it using multiple processors enabling fast handling of multiple clients at once (communication is done with sockets). So I create the index in the parent process and than fork children that handle client queries. But after a short time only traversing the index by children makes them use much memory, resulting shortly in Out Of Memory Errors. > And AFAIK there is no > built-in way of doing what you want. It's complex and error-prone. Having read-only objects is complex and error-prone? > Maybe mmap + (struct|pickle) help, if what you need can be formulated in a way > that traversing the whole data piecewise by explicitly > marshaling-demarshaling data? In case of this word index it is impossible... And probably would be too slow. Using mmap and mapping the object structure into structs should probably work... From michele.simionato at gmail.com Mon Nov 15 09:36:12 2010 From: michele.simionato at gmail.com (Michele Simionato) Date: Mon, 15 Nov 2010 06:36:12 -0800 (PST) Subject: STARTTLS extension not supported by server Message-ID: <6e4c8009-7d17-4d04-91dd-75e834b9cde0@o14g2000yqe.googlegroups.com> I have a CentOS machine with Python 2.4 and I wanted to install Python 2.7 on it. The installation went fine but now I have a problem with a script sending email via TLS authentication. If I do something like import smtplib smtpO = smtplib.SMTP() smtpO.ehlo() smtpO.starttls() I get the following error: Traceback (most recent call last): File "y.py", line 5, in smtpO.starttls() File "/home/rcare/lib/python2.7/smtplib.py", line 614, in starttls raise SMTPException("STARTTLS extension not supported by server.") smtplib.SMTPException: STARTTLS extension not supported by server. Notice that this not a problem of the SMTP server, since with Python 2.4 the script is connecting to the SMTP server just fine. At first I thought the problem was with the ssl support, I recompiled the module, but I still get the same error. Do you have any suggestion to be debug the issue and to figure out where the problem is? TIA, Michele Simionato From a_jtim at bellsouth.net Mon Nov 15 10:20:52 2010 From: a_jtim at bellsouth.net (Tim Arnold) Date: Mon, 15 Nov 2010 07:20:52 -0800 (PST) Subject: remote server and effective uid Message-ID: Hi, I have a remote server on a FreeBSD box with clients connecting from linux, all running python2.7. I've setup the remote server as an inetd service (currently running as 'nobody'). Both client and server have access to the same file systems. How can I enable the server process to write into the client's directories? If I change the inetd service to run as 'root', I guess that would work, but then the client couldn't remove the files put there after the request. I could ditch the whole server process and wrap client requests with rsh calls, but is there a way I can switch the effective uid of the server process without asking clients to login? Or is there a better way to solve the problem? thanks, --Tim Arnold From invalid at invalid.invalid Mon Nov 15 10:24:43 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 15 Nov 2010 15:24:43 +0000 (UTC) Subject: What was your strategy? References: <7xzktbcqox.fsf@ruckus.brouhaha.com> Message-ID: On 2010-11-15, Paul Rubin wrote: > Python is a pretty easy language if you have a reasonable programming > background when you first start with it. I think the way it's currently > organized, it may not be so great for self-study if you're not already a > programmer. The way what is organized? You think the language itself is organized poorly for self-study? -- Grant Edwards grant.b.edwards Yow! I wonder if I could at ever get started in the gmail.com credit world? From usernet at ilthio.net Mon Nov 15 10:41:01 2010 From: usernet at ilthio.net (Tim Harig) Date: Mon, 15 Nov 2010 15:41:01 +0000 (UTC) Subject: remote server and effective uid References: Message-ID: On 2010-11-15, Tim Arnold wrote: > How can I enable the server process to write into the client's > directories? > If I change the inetd service to run as 'root', I guess that would > work, but then the client couldn't remove the files put there after > the request. Python provides os.setuid() and os.seteuid() which wrap the system functions. See you systems man pages for these functions for more information. From deets at web.de Mon Nov 15 10:42:56 2010 From: deets at web.de (Diez B. Roggisch) Date: Mon, 15 Nov 2010 16:42:56 +0100 Subject: Getting references to objects without incrementing reference counters References: <8c98a453-3303-4509-be39-1a26084f573a@o11g2000prf.googlegroups.com> <0afcca4a-13b7-42ab-aea5-86b4324708e3@p1g2000yqm.googlegroups.com> Message-ID: <87pqu6zj7j.fsf@web.de> Artur Siekielski writes: > On Nov 15, 1:03?am, de... at web.de (Diez B. Roggisch) wrote: >> You don't say what data you share, and if all of it is needed for each >> child. So it's hard to suggest optimizations. > > Here is an example of such a problem I'm dealing with now: I'm > building large index of words in memory, it takes 50% of RAM. After > building it I want to enable querying it using multiple processors > enabling fast handling of multiple clients at once (communication is > done with sockets). So I create the index in the parent process and > than fork children that handle client queries. But after a short time > only traversing the index by children makes them use much memory, > resulting shortly in Out Of Memory Errors. > >> And AFAIK there is no >> built-in way of doing what you want. It's complex and error-prone. > > Having read-only objects is complex and error-prone? Yes. Python has no built-in semantics for that. You can't declare an object to be read-only. And if one wanted to implement that, you'd have to make sure the object consists only of read-only attributes itself. And circumvene a great deal of the dynamic features in python (which you don't need for this usecase, but still are there) Diez From kern.ra at gmail.com Mon Nov 15 11:06:45 2010 From: kern.ra at gmail.com (Becky Kern) Date: Mon, 15 Nov 2010 11:06:45 -0500 Subject: [Beginner question] Error when converting raster to ASCII Message-ID: Hi again users, This is in response to my post from 11/14/2010 (see below) >* Hi users, *>* I'm using Python 2.5 (in concert with ArcGIS 9.3) to convert a raster to *>* an ASCII file. I used the code (listed below) several weeks ago to *>* successfully do the conversion, but when I tried to replicate it a few *>* days ago, I got an error message. *>* import arcgisscripting *>* gp = arcgisscripting.create(9.3) *>* InRaster = "C:/data/raster1" *>* OutAsciiFile = "C:/data/raster2ascii.asc" *>* gp.RasterToASCII_conversion(InRaster, OutAsciiFile) *>* The error message: *>* arcgisscripting.ExecuteError: Failed to execute. Parameters are not *>* valid. raster1 does not exist. *>* My file path has not changed so I don't understand why Python can no *>* longer recognize my raster file. Any ideas? *>* * MRAB responded: Just to make sure, does os.path.isfile(InRaster) return True? When I tried os.path.isfile(InRaster), I received the following error message: "NameError: name 'os' is not defined" Does this shed any light on why my raster to ASCII conversion isn't working? Thanks again. -------------- next part -------------- An HTML attachment was scrubbed... URL: From calderone.jeanpaul at gmail.com Mon Nov 15 11:28:52 2010 From: calderone.jeanpaul at gmail.com (Jean-Paul Calderone) Date: Mon, 15 Nov 2010 08:28:52 -0800 (PST) Subject: Getting references to objects without incrementing reference counters References: <8c98a453-3303-4509-be39-1a26084f573a@o11g2000prf.googlegroups.com> <0afcca4a-13b7-42ab-aea5-86b4324708e3@p1g2000yqm.googlegroups.com> <87pqu6zj7j.fsf@web.de> Message-ID: On Nov 15, 10:42?am, de... at web.de (Diez B. Roggisch) wrote: > And circumvene a great deal of the dynamic features in python > (which you don't need for this usecase, but still are there) > Great as the features might be, when you don't need them, it's clearly a bad thing to have them drag you down. Fortunately the PyPy team is making great progress in implementing a runtime that transparently sheds those dynamic features when running a program that doesn't take advantage of them. Jean-Paul From old_road_farm at verizon.net Mon Nov 15 11:31:52 2010 From: old_road_farm at verizon.net (octopusgrabbus) Date: Mon, 15 Nov 2010 08:31:52 -0800 (PST) Subject: Modifying Element In For List Message-ID: <01e04b27-c523-40b7-b9cb-8288823de8fa@p11g2000vbn.googlegroups.com> My question concerns elementary list and pass by reference: I've written a function which is passed a list that contains rows read from a csv file. The function traverses csv_rows, row by row, and inspects the first element in each row. The function tests for '', and if true, replaces that with a 0. I've used the standard Python for syntax for this. def cleanMeterID(csv_rows, bad_meter_id_count): d = drIdx() row_number = 0 for row in csv_rows: if False == is_number(row[d.MeterID]): csv_rows[row_number][d.MeterID] = 0 row_number = row_number + 1 bad_meter_id_count[0]= bad_meter_id_count[0] + 1 print("Received ", bad_meter_id_count[0], " bad meter ids") I believe the logic show above is flawed, because I am not modifying elements in the original csv_rows list. I would modify this to use an index to traverse the list like idx=None for idx in range(0, len(csv_rows), 1): if False == is_number(row[d.MeterID]): csv_rows[row_number][d.MeterID] = 0 row_number = row_number + 1 bad_meter_id_count[0]= bad_meter_id_count[0] + 1 Is this correct? Thank you. From benjamin.kaplan at case.edu Mon Nov 15 11:36:46 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 15 Nov 2010 11:36:46 -0500 Subject: [Beginner question] Error when converting raster to ASCII In-Reply-To: References: Message-ID: On Monday, November 15, 2010, Becky Kern wrote: > Hi again users, > > This is in response to my post from 11/14/2010 (see below) > >> Hi users, >> I'm using Python 2.5 (in concert with ArcGIS 9.3) to convert a raster to >> an ASCII file. I used the code (listed below) several weeks ago to >> successfully do the conversion, but when I tried to replicate it a few >> days ago, I got an error message. >> import arcgisscripting >> gp = arcgisscripting.create(9.3) >> InRaster = "C:/data/raster1" >> OutAsciiFile = "C:/data/raster2ascii.asc" >> gp.RasterToASCII_conversion(InRaster, OutAsciiFile) >> The error message: >> arcgisscripting.ExecuteError: Failed to execute. Parameters are not >> valid. raster1 does not exist. >> My file path has not changed so I don't understand why Python can no >> longer recognize my raster file. Any ideas? >> > > MRAB responded: > Just to make sure, does os.path.isfile(InRaster) return True? > > When I tried os.path.isfile(InRaster), I received the following error message: > "NameError: name 'os' is not defined" you need to import os.path > > Does this shed any light on why my raster to ASCII conversion isn't working? > > Thanks again. > > From edreamleo at gmail.com Mon Nov 15 12:06:01 2010 From: edreamleo at gmail.com (Edward K. Ream) Date: Mon, 15 Nov 2010 09:06:01 -0800 (PST) Subject: Leo 4.8 rc1 released Message-ID: <330ee46d-4894-409d-ab4b-af517fb95dec@k30g2000vbn.googlegroups.com> Leo 4.8 release candidate 1 is now available at: http://sourceforge.net/project/showfiles.php?group_id=3458&package_id=29106 Leo is a text editor, data organizer, project manager and much more. See: http://webpages.charter.net/edreamleo/intro.html The highlights of Leo 4.8: -------------------------- - Leo now uses the simplest possible sentinel lines in external files. External files with sentinels now look like Emacs org-mode files. - Leo Qt gui now supports Drag and Drop. This was one of the most frequently requested features. - Improved abbreviation commands. You now define abbreviations in Leo settings nodes, not external files. - @url nodes may contain url's in body text. This allows headlines to contain summaries: very useful. - Leo now uses PyEnchant to check spelling. - Leo can now open multiple files from the command line. - Leo's ancient Tangle and Untangle commands are now deprecated. This will help newbies how to learn Leo. - Leo now shows "Resurrected" and "Recovered" nodes. These protect data and show how data have changed. These fix several long-standing data-related problems. - A new "screenshots" plugin for creating slide shows with Leo. I used this plugin to create Leo's introductory slide shows. - Improved autocompletion: Ctrl-space starts a one-time completion. - A better installer. - Many bug fixes. Links: ------ Leo: http://webpages.charter.net/edreamleo/front.html Forum: http://groups.google.com/group/leo-editor Download: http://sourceforge.net/project/showfiles.php?group_id=3458 Bzr: http://code.launchpad.net/leo-editor/ Quotes: http://webpages.charter.net/edreamleo/testimonials.html Edward K. Ream November 15, 2010 From duncan.booth at invalid.invalid Mon Nov 15 12:27:46 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 15 Nov 2010 17:27:46 GMT Subject: Modifying Element In For List References: <01e04b27-c523-40b7-b9cb-8288823de8fa@p11g2000vbn.googlegroups.com> Message-ID: octopusgrabbus wrote: > I've written a function which is passed a list that contains rows read > from a csv file. The function traverses csv_rows, row by row, and > inspects the first element in each row. The function tests for '', and > if true, replaces that with a 0. > > I've used the standard Python for syntax for this. > > def cleanMeterID(csv_rows, bad_meter_id_count): > d = drIdx() > > row_number = 0 > > for row in csv_rows: > if False == is_number(row[d.MeterID]): > csv_rows[row_number][d.MeterID] = 0 > row_number = row_number + 1 > bad_meter_id_count[0]= bad_meter_id_count[0] + 1 > > print("Received ", bad_meter_id_count[0], " bad meter ids") > > I believe the logic show above is flawed, because I am not modifying > elements in the original csv_rows list. You have a reference to the row, so just modify it directly. Other points: bad_meter_id_count should just be a return value: that messing about with a list is just plain nasty. Comparing directly against True or False is error prone: a value in Python can be false without actually being equal to False. def cleanMeterID(csv_rows): d = drIdx() count = 0 for row in csv_rows: if not is_number(row[d.MeterID]): # or even: if row[d.MeterID]=='': row[d.MeterID] = 0 count += 1 print("Received {} bad meter ids".format(count)) return count -- Duncan Booth http://kupuguy.blogspot.com From artur.siekielski at gmail.com Mon Nov 15 12:30:16 2010 From: artur.siekielski at gmail.com (Artur Siekielski) Date: Mon, 15 Nov 2010 09:30:16 -0800 (PST) Subject: Getting references to objects without incrementing reference counters References: <8c98a453-3303-4509-be39-1a26084f573a@o11g2000prf.googlegroups.com> <0afcca4a-13b7-42ab-aea5-86b4324708e3@p1g2000yqm.googlegroups.com> <87pqu6zj7j.fsf@web.de> Message-ID: On Nov 15, 5:28?pm, Jean-Paul Calderone wrote: > On Nov 15, 10:42?am, de... at web.de (Diez B. Roggisch) wrote: > > > And circumvene a great deal of the dynamic features in python > > (which you don't need for this usecase, but still are there) > > Great as the features might be, when you don't need them, it's clearly > a bad thing to have them drag you down. ?Fortunately the PyPy team is > making great progress in implementing a runtime that transparently > sheds > those dynamic features when running a program that doesn't take > advantage > of them. In case of PyPy such design - forks() + relying on copy-on-write - I think will not work at all, because PyPy GC moves objects so they will not stay in the same memory pages. Or if they are not modified they will stay at the same memory address? CPython's simple runtime (no real GC) makes reasoning about memory- level structures easy, so I was hoping that copy-on-write will work here. Anyway for my usecase using unsafe_listget (implemented by me - doesn't increment reference count) does the job. From tjreedy at udel.edu Mon Nov 15 13:17:45 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 15 Nov 2010 13:17:45 -0500 Subject: Some syntactic sugar proposals In-Reply-To: References: Message-ID: On 11/15/2010 1:39 AM, Dmitry Groshev wrote: > Here are some proposals. They are quite useful at my opinion and I'm > interested for suggestions. It's all about some common patterns. > First of all: how many times do you write something like > t = foo() > t = t if pred(t) else default_value Never. t=t unbinds and rebinds 't' to the same object. A waste. Only rebind if needed. if not pred(t): t = default_value > ? Of course we can write it as > t = foo() if pred(foo()) else default_value > but here we have 2 foo() calls instead of one. Why can't we write just > something like this: > t = foo() if pred(it) else default_value > where "it" means "foo() value"? Too magical. I agree with most other comments. -- Terry Jan Reedy From bblais at bryant.edu Mon Nov 15 13:49:34 2010 From: bblais at bryant.edu (Brian Blais) Date: Mon, 15 Nov 2010 13:49:34 -0500 Subject: Some syntactic sugar proposals In-Reply-To: References: Message-ID: <7BD5C86C-CDFD-4FBE-8AB7-A6C30AF9587F@bryant.edu> On Nov 15, 2010, at 1:39 AM, Dmitry Groshev wrote: > if x in range(a, b): #wrong! > it feels so natural to check it that way, but we have to write > if a <= x <= b > I understand that it's not a big deal, but it would be awesome to have > some optimisations - it's clearly possible to detect things like that > "wrong" one and fix it in a bytecode. I don't think anyone has pointed this out, but these are *not* the same thing. observe: x=3 if x in range(1,10): print "yay!" if 1<=x<10: print "yay too!" x=3.2 if x in range(1,10): print "yay!" if 1<=x<10: print "yay too!" output: yay! yay too! yay too! bb -- Brian Blais bblais at bryant.edu http://web.bryant.edu/~bblais http://bblais.blogspot.com/ From a_jtim at bellsouth.net Mon Nov 15 14:19:37 2010 From: a_jtim at bellsouth.net (Tim Arnold) Date: Mon, 15 Nov 2010 11:19:37 -0800 (PST) Subject: remote server and effective uid References: Message-ID: On Nov 15, 10:41?am, Tim Harig wrote: > On 2010-11-15, Tim Arnold wrote: > > > How can I enable the server process to write into the client's > > directories? > > If I change the inetd service to run as 'root', I guess that would > > work, but then the client couldn't remove the files put there after > > the request. > > Python provides os.setuid() and os.seteuid() which wrap the system > functions. ?See you systems man pages for these functions for more > information. Thanks -- that was a lot easier than I thought it was going to be. pass the client's uid in the message to the server like so argstring, local_dir, uid = message.split(':') os.seteuid(int(uid)) thanks again, --Tim From no.email at nospam.invalid Mon Nov 15 14:25:12 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 15 Nov 2010 11:25:12 -0800 Subject: STARTTLS extension not supported by server References: <6e4c8009-7d17-4d04-91dd-75e834b9cde0@o14g2000yqe.googlegroups.com> Message-ID: <7xtyjie6ef.fsf@ruckus.brouhaha.com> Michele Simionato writes: > Notice that this not a problem of the SMTP server, since with Python > 2.4 the script is connecting to the SMTP server Um, my guess is that 2.4 didn't attempt to use TLS at all, and your 2.7 installation doesn't have the TLS libraries installed or they're not configured where Python can find them. From bostjan.mejak at gmail.com Mon Nov 15 14:53:07 2010 From: bostjan.mejak at gmail.com (=?UTF-8?Q?Bo=C5=A1tjan_Mejak?=) Date: Mon, 15 Nov 2010 20:53:07 +0100 Subject: HTMLWindow or HtmlWindow or perhaps HTMLwindo Message-ID: Hello, I am wondering which of the 3 class names are prefered by PEP-8? class HTMLWindow(...) class HtmlWindow(...) class HTMLwindow(...) Thank you for your answer in advance. From krister.svanlund at gmail.com Mon Nov 15 15:09:41 2010 From: krister.svanlund at gmail.com (Krister Svanlund) Date: Mon, 15 Nov 2010 21:09:41 +0100 Subject: HTMLWindow or HtmlWindow or perhaps HTMLwindo In-Reply-To: References: Message-ID: """ CapitalizedWords (or CapWords, or CamelCase -- so named because of the bumpy look of its letters[4]). This is also sometimes known as StudlyCaps. Note: When using abbreviations in CapWords, capitalize all the letters of the abbreviation. Thus HTTPServerError is better than HttpServerError. """ On Mon, Nov 15, 2010 at 8:53 PM, Bo?tjan Mejak wrote: > Hello, I am wondering which of the 3 class names are prefered by PEP-8? > > class HTMLWindow(...) > > class HtmlWindow(...) > > class HTMLwindow(...) > > > Thank you for your answer in advance. > -- > http://mail.python.org/mailman/listinfo/python-list > From bmjames at gmail.com Mon Nov 15 15:09:58 2010 From: bmjames at gmail.com (Ben James) Date: Mon, 15 Nov 2010 20:09:58 +0000 Subject: HTMLWindow or HtmlWindow or perhaps HTMLwindo References: Message-ID: On 15/11/2010 19:53, Bo?tjan Mejak wrote: > Hello, I am wondering which of the 3 class names are prefered by PEP-8? > > class HTMLWindow(...) > > class HtmlWindow(...) > > class HTMLwindow(...) > > > Thank you for your answer in advance. PEP 8 says: Note: When using abbreviations in CapWords, capitalize all the letters of the abbreviation. Thus HTTPServerError is better than HttpServerError. So, to apply that to your example, PEP 8 recommends HTMLWindow. From kern.ra at gmail.com Mon Nov 15 15:14:56 2010 From: kern.ra at gmail.com (Becky Kern) Date: Mon, 15 Nov 2010 15:14:56 -0500 Subject: Solution to: [Beginner question] Raster to ASCII conversion Message-ID: Hi users, Found a solution to my Raster to ASCII conversion problem, so I thought I'd post. My raster was created in ArcGIS 9.3 as an ESRI GRID (folder with associated info folder). I needed to use the ListRasters method (see http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?id=958&pid=905&topicname=ListRasters_method) to get Python to recognize it as a raster. My functioning code is posted below. >>import arcgisscripting >>gp = arcgisscripting.create(9.3) >>gp.workspace = "C:\Users\Lab User\Desktop\BKern\Blackwater\PVA\Scenario 1\Nov 15" >>rasters = gp.ListRasters("","ALL") >>for raster in rasters: print raster ... scen1_11_15 >>InRaster = "scen1_11_15" >>OutasciiFile = "C:\Users\Lab User\Desktop\BKern\Blackwater\PVA\Scenario 1\Nov 15\scen1.asc" >>gp.RasterToASCII_conversion(InRaster, OutasciiFile) -------------- next part -------------- An HTML attachment was scrubbed... URL: From ndbecker2 at gmail.com Mon Nov 15 15:15:08 2010 From: ndbecker2 at gmail.com (Neal Becker) Date: Mon, 15 Nov 2010 15:15:08 -0500 Subject: question on ConfigParser defaults Message-ID: import ConfigParser # New instance with 'bar' and 'baz' defaulting to 'Life' and 'hard' each config = ConfigParser.SafeConfigParser({'bar': 'Life', 'baz': 'hard'}) config.read('example.cfg') print config.get('Section1', 'foo') # -> "Python is fun!" config.remove_option('Section1', 'bar') config.remove_option('Section1', 'baz') print config.get('Section1', 'foo') # -> "Life is hard!" -------------- I'm confused. ConfigParser insists that all settings live in some 'section'. At least, settings read from a config file have to have some [section]. What section is associated with the defaults set by the constructor? In the above example, there is no reference to 'Section1' in the constructor, yet we refer to 'Section1' later to retrieve the values? From krister.svanlund at gmail.com Mon Nov 15 15:22:23 2010 From: krister.svanlund at gmail.com (Krister Svanlund) Date: Mon, 15 Nov 2010 21:22:23 +0100 Subject: HTMLWindow or HtmlWindow or perhaps HTMLwindo In-Reply-To: References: Message-ID: On Mon, Nov 15, 2010 at 9:09 PM, Ben James wrote: > On 15/11/2010 19:53, Bo?tjan Mejak wrote: >> >> Hello, I am wondering which of the 3 class names are prefered by PEP-8? >> >> class HTMLWindow(...) >> >> class HtmlWindow(...) >> >> class HTMLwindow(...) >> >> >> Thank you for your answer in advance. > > PEP 8 says: > > ? ?Note: When using abbreviations in CapWords, capitalize all the > ? ?letters of the abbreviation. ?Thus HTTPServerError is better than > ? ?HttpServerError. > > So, to apply that to your example, PEP 8 recommends HTMLWindow. > -- > http://mail.python.org/mailman/listinfo/python-list > Yeah, since HTML is an abbreviation it's the exact recommendation to use... :) From python at mrabarnett.plus.com Mon Nov 15 15:37:00 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 15 Nov 2010 20:37:00 +0000 Subject: Solution to: [Beginner question] Raster to ASCII conversion In-Reply-To: References: Message-ID: <4CE199EC.6080001@mrabarnett.plus.com> On 15/11/2010 20:14, Becky Kern wrote: > Hi users, > Found a solution to my Raster to ASCII conversion problem, so I thought > I'd post. > My raster was created in ArcGIS 9.3 as an ESRI GRID (folder with > associated info folder). I needed to use the ListRasters method (see > http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?id=958&pid=905&topicname=ListRasters_method > ) to > get Python to recognize it as a raster. My functioning code is posted below. > >>import arcgisscripting > >>gp = arcgisscripting.create(9.3) > >>gp.workspace = "C:\Users\Lab > User\Desktop\BKern\Blackwater\PVA\Scenario 1\Nov 15" > >>rasters = gp.ListRasters("","ALL") > >>for raster in rasters: print raster > ... > scen1_11_15 > >>InRaster = "scen1_11_15" > >>OutasciiFile = "C:\Users\Lab > User\Desktop\BKern\Blackwater\PVA\Scenario 1\Nov 15\scen1.asc" > >>gp.RasterToASCII_conversion(InRaster, OutasciiFile) > Be careful when using string literals containing backslashes. It's recommended that you use raw strings: gp.workspace = r"C:\Users\Lab User\Desktop\BKern\Blackwater\PVA\Scenario 1\Nov 15" OutasciiFile = r"C:\Users\Lab User\Desktop\BKern\Blackwater\PVA\Scenario 1\Nov 15\scen1.asc" You were lucky that none of the backslashes started an escape sequence. If you were using Python 3 then it would've complained about \U and \N. From nagle at animats.com Mon Nov 15 15:44:05 2010 From: nagle at animats.com (John Nagle) Date: Mon, 15 Nov 2010 12:44:05 -0800 Subject: Some syntactic sugar proposals In-Reply-To: <4ac1734d-fffb-4fdc-be42-27812a174b97@i32g2000pri.googlegroups.com> References: <4ac1734d-fffb-4fdc-be42-27812a174b97@i32g2000pri.googlegroups.com> Message-ID: <4ce19ba5$0$1676$742ec2ed@news.sonic.net> On 11/14/2010 11:30 PM, alex23 wrote: > On Nov 15, 4:39 pm, Dmitry Groshev wrote: >> First of all: how many times do you write something like > >> Second, I saw a lot of questions about using dot notation for a >> "object-like" dictionaries and a lot of solutions like this: >> class dotdict(dict): >> def __getattr__(self, attr): >> return self.get(attr, None) >> __setattr__= dict.__setitem__ >> __delattr__= dict.__delitem__ >> why there isn't something like this in a standart library? > > Personally, I like keeping object attribute references separate from > dictionary item references. Right. This isn't JavaScript. If you need a "dict", use a "dict". Don't use attributes as named storage. It leads to problems. Functions and various built-in objects are in the attribute namespace, and this can lead to name clashes. Maybe security holes, if the attribute keys come from external input. There are also some restrictions on the syntax of attribute names, restrictions "dict" does not have. Remember, you can inherit from "dict", which allows you to write obj['abc'] which is almost as short as obj.abc but safer. John Nagle From python at mrabarnett.plus.com Mon Nov 15 15:47:09 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 15 Nov 2010 20:47:09 +0000 Subject: Help: Guide needed in trying to delete/flush the content of a fifo file. In-Reply-To: <1c7f7feb-ff95-404b-9628-458922360908@j12g2000prm.googlegroups.com> References: <1c7f7feb-ff95-404b-9628-458922360908@j12g2000prm.googlegroups.com> Message-ID: <4CE19C4D.2030403@mrabarnett.plus.com> On 15/11/2010 11:03, Ton wrote: > On Nov 14, 11:55 pm, MRAB wrote: >> On 14/11/2010 14:48, ton ph wrote:> Hi python geeks, >>> I have problem which i have been trying to find out for the past >>> some days, i have a device which feeds info to my fifo continuosly, and >>> a thread of mine reads the >>> fifo continuosly. Now when i change a parameter in the device, it sends >>> me different values. Now my problem is that , i want to get rid of the >>> contents of my previous info which >>> is present in my buffer of the fifo.So i want to flush the fifo content >>> when my device starts sending different info .... i am implementing >>> writing and reading the fifo using two different threads. >>> Please someone guide me solving my problem. >>> I highly apologise everyone in case my post is not so clear... >>> Thanks everyone in advance. >> >> When the info changes, the thread which is putting items into the fifo >> could flush it just by getting items from it (using a non-blocking get) >> until it's empty. > > Hi Mrab, > Thanks for your immediate reply , can you please guide me with any > tool or library function which i can flush my fifo content .. i use > os.mkfifo() to make the fifo. Or is there any other way i could do > this ... > Thanks Ah, you're using pipes; I thought you might've been using a queue. I don't know of a way of flushing a pipe. I wonder whether it's a good idea for the producer to keep filling the fifo, because the consumer know how 'old' the info is when it arrives, and there's your problem of discarding stale info. Perhaps the producer should wait until the consumer has sent an acknowledgement before sending more info. From nagle at animats.com Mon Nov 15 16:06:45 2010 From: nagle at animats.com (John Nagle) Date: Mon, 15 Nov 2010 13:06:45 -0800 Subject: Getting references to objects without incrementing reference counters In-Reply-To: <8c98a453-3303-4509-be39-1a26084f573a@o11g2000prf.googlegroups.com> References: <8c98a453-3303-4509-be39-1a26084f573a@o11g2000prf.googlegroups.com> Message-ID: <4ce1a0f5$0$1633$742ec2ed@news.sonic.net> On 11/14/2010 11:08 AM, Artur Siekielski wrote: > Hi. > I'm using CPython 2.7 and Linux. In order to make parallel > computations on a large list of objects I want to use multiple > processes (by using multiprocessing module). In the first step I fill > the list with objects and then I fork() my worker processes that do > the job. > > This should work optimally in the aspect of memory usage because Linux > implements copy-on-write in forked processes. There used to be a memory leak when using Pickle to talk to subprocesses. See what I wrote at "http://groups.google.com/group/comp.lang.python/browse_thread/thread/3f8b999c25af263a%22" The Pickle module has an optimization scheme and cache which requires that both sender and receiver keep a reference to each object transmitted. Cache clearing wasn't well worked out for Pickle object reuse, and the receive end had a memory leak. Did that get fixed? John Nagle From eric.promislow at gmail.com Mon Nov 15 16:15:48 2010 From: eric.promislow at gmail.com (Eric Promislow) Date: Mon, 15 Nov 2010 13:15:48 -0800 (PST) Subject: Komodo 6, why "Workspace Restore" after every restart? References: <4ce07839$0$17214$c3e8da3$eb767761@news.astraweb.com> <428b98ca-72bf-4e3b-ad8a-dafe2fc4d553@v28g2000prn.googlegroups.com> <4ce0c065$0$23246$c3e8da3$a9097924@news.astraweb.com> <6ae54329-c652-4a59-b0e2-4c2038f58d5a@x4g2000pre.googlegroups.com> <4ce0ea79$0$29271$c3e8da3$88b277c5@news.astraweb.com> <15016ae4-b341-4f4e-ac84-62fe7f93f217@g20g2000prg.googlegroups.com> <4ce0f788$0$30018$c3e8da3$76a7c58f@news.astraweb.com> Message-ID: <2f84eafd-f7fb-48a5-bd23-3e6a311ae99d@37g2000prx.googlegroups.com> Komodo always asks you if you want to restore the last workspace when it wasn't shut down cleanly the previous time. The reason for this is that it's possible Komodo ended up in a state where it's hung due to a particular workspace configuration. This question lets you bring up Komodo in a possibly sane configuration instead. Is this the best thing to do? Wouldn't it be better to manually remove a couple of config files, and restart Komodo in a basic but sane configuration? You could make a good case for that, and may I suggest that http://community.activestate.com/forums/komodo-discussion would be a better place to continue this particular discussion? Thanks for bringing up the issue though. Eric Promislow Komodo Developer From usernet at ilthio.net Mon Nov 15 16:26:02 2010 From: usernet at ilthio.net (Tim Harig) Date: Mon, 15 Nov 2010 21:26:02 +0000 (UTC) Subject: remote server and effective uid References: Message-ID: On 2010-11-15, Tim Arnold wrote: > On Nov 15, 10:41?am, Tim Harig wrote: >> On 2010-11-15, Tim Arnold wrote: >> >> > How can I enable the server process to write into the client's >> > directories? >> > If I change the inetd service to run as 'root', I guess that would >> > work, but then the client couldn't remove the files put there after >> > the request. >> >> Python provides os.setuid() and os.seteuid() which wrap the system >> functions. ?See you systems man pages for these functions for more >> information. > > Thanks -- that was a lot easier than I thought it was going to be. > pass the client's uid in the message to the server like so > > argstring, local_dir, uid = message.split(':') > os.seteuid(int(uid)) I am not sure exactly what you are doing; but, I would advise great caution as messing this up could easily open your system to exploitation. Be very sure that you know what you are doing. From nagle at animats.com Mon Nov 15 17:42:43 2010 From: nagle at animats.com (John Nagle) Date: Mon, 15 Nov 2010 14:42:43 -0800 Subject: What was your strategy? In-Reply-To: References: Message-ID: <4ce1b772$0$1663$742ec2ed@news.sonic.net> On 11/14/2010 2:59 PM, Seebs wrote: > On 2010-11-14, Jorge Biquez wrote: >> I was wondering if you can share what was the strategy you followed >> to master Python (Yes I know I have to work hard study and practice a >> lot). I mean did you use special books, special sites, a plan to >> learn each subject in a special way. I would like to know, if >> possible, comments specially from some of you who in the past had >> other languages, frameworks and platforms and left (almost) all of >> them and stayed with Python. > > I've been learning Python the same way I learn any language; get a > book, read it over lunch for a few days, start typing, ask people > how to improve my code once I have some. > > This information is almost certainly useless to you, though, unless > you've already learned at least six or seven programming languages. Right. I just read over the language description and the reference manual. Python is a memory-safe late-binding declaration-free naive interpreter with classes that uses indentation for nesting level and reference counting for allocation. If those are all familiar concepts from other languages, Python is trivial. Python is actually rather easy to learn. It doesn't have the storage management problems of C and C++, the awful syntax of Perl, the object-as-copy semantics of Javascript, or the mess of stacked libraries of Java. John Nagle From aahz at pythoncraft.com Mon Nov 15 17:52:52 2010 From: aahz at pythoncraft.com (Aahz) Date: 15 Nov 2010 14:52:52 -0800 Subject: OO and game design questions References: <2630c899-96b2-4f83-9081-764b80d76650@h7g2000yqn.googlegroups.com> Message-ID: In article , Martin Gregorie wrote: >On Tue, 19 Oct 2010 19:49:20 -0400, Dave Angel wrote: >> >> Thanks, that is what I was trying to say. In the same sense that >> emptying a list makes it quite small, if it's a general purpose object, >> you just want to remove all the attributes. > >I think a 'place' (to generalise it) is quite a small object in any case. >All it needs to contain is a few lists: >- a list of exits, which in some implementations might be simply > references to other places, but might usefully be objects with > two sides, each having an appearance and a link to the place > where that side appears. >- a list of fixed objects which only serve to describe the place. >- a list of mobile objects that actors can pick up and move >- a list of actors who happen to be there. > >plus a describePlace() method and add(), remove() and getItem() methods >for each list. It may be possible to use a single list for all types of >object, in which case the object itself would be very small indeed. Maybe you want a rule-based approach: http://eblong.com/zarf/essays/rule-based-if/ -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Look, it's your affair if you want to play with five people, but don't go calling it doubles." --John Cleese anticipates Usenet From cs at zip.com.au Mon Nov 15 20:30:06 2010 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 16 Nov 2010 12:30:06 +1100 Subject: Help: Guide needed in trying to delete/flush the content of a fifo file. In-Reply-To: <4CE19C4D.2030403@mrabarnett.plus.com> References: <4CE19C4D.2030403@mrabarnett.plus.com> Message-ID: <20101116013006.GA15879@cskk.homeip.net> On 15Nov2010 20:47, MRAB wrote: | On 15/11/2010 11:03, Ton wrote: | >Hi Mrab, | > Thanks for your immediate reply , can you please guide me with any | >tool or library function which i can flush my fifo content .. i use | >os.mkfifo() to make the fifo. Or is there any other way i could do | >this ... | >Thanks | | Ah, you're using pipes; I thought you might've been using a queue. I | don't know of a way of flushing a pipe. I think the nearest thing you can do is empty it with a read(). On many systems (AFAIR) a stat of a pipe returns the amount of buffered data, so you could go (untested - some of the following method names will probably be wrong, too) something like: buffered = os.fstat(fifo.fileno()) if buffered > 0: fifo.read(buffered) Of course it is all a bit racy, as data may arrive after the stat, but arbitrarily "flush"ing the pipe has equivalent problems. | I wonder whether it's a good idea for the producer to keep filling the | fifo, because the consumer know how 'old' the info is when it arrives, | and there's your problem of discarding stale info. Perhaps the producer | should wait until the consumer has sent an acknowledgement before | sending more info. I agree with this statement. -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ In the end, winning is the only safety. - Kerr Avon From jdoe at usenetlove.invalid Mon Nov 15 21:31:23 2010 From: jdoe at usenetlove.invalid (John Doe) Date: 16 Nov 2010 02:31:23 GMT Subject: Komodo 6, why "Workspace Restore" after every restart? References: <4ce07839$0$17214$c3e8da3$eb767761@news.astraweb.com> <428b98ca-72bf-4e3b-ad8a-dafe2fc4d553@v28g2000prn.googlegroups.com> <4ce0c065$0$23246$c3e8da3$a9097924@news.astraweb.com> <6ae54329-c652-4a59-b0e2-4c2038f58d5a@x4g2000pre.googlegroups.com> <4ce0ea79$0$29271$c3e8da3$88b277c5@news.astraweb.com> <15016ae4-b341-4f4e-ac84-62fe7f93f217@g20g2000prg.googlegroups.com> <4ce0f788$0$30018$c3e8da3$76a7c58f@news.astraweb.com> <2f84eafd-f7fb-48a5-bd23-3e6a311ae99d@37g2000prx.googlegroups.com> Message-ID: <4ce1ecfa$0$30001$c3e8da3$76a7c58f@news.astraweb.com> Eric Promislow wrote: > Komodo always asks you if you want to restore the last workspace > when it wasn't shut down cleanly the previous time. Why is shutting down in Windows XP more difficult for version 6? The only thing I have open is a single small Python file. Apparently version 6 is unable to handle the ordinary shutdown command it gets from Windows. Or maybe there is some setting that can correct the problem. Version 5 shutdown just fine when Windows was restarted. -- > > The reason for this is that it's possible Komodo ended up in a state > where > it's hung due to a particular workspace configuration. This question > lets > you bring up Komodo in a possibly sane configuration instead. > > Is this the best thing to do? Wouldn't it be better to manually > remove a > couple of config files, and restart Komodo in a basic but sane > configuration? > You could make a good case for that, and may I suggest that > http://community.activestate.com/forums/komodo-discussion would be a > better place to continue this particular discussion? > > Thanks for bringing up the issue though. > > Eric Promislow > Komodo Developer > > see also googled groups > Path: news.astraweb.com!border1.newsrouter.astraweb.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!postnews.google.com!37g2000prx.googlegroups.com!not-for-mail > From: Eric Promislow > Newsgroups: comp.lang.python > Subject: Re: Komodo 6, why "Workspace Restore" after every restart? > Date: Mon, 15 Nov 2010 13:15:48 -0800 (PST) > Organization: http://groups.google.com > Lines: 22 > Message-ID: <2f84eafd-f7fb-48a5-bd23-3e6a311ae99d 37g2000prx.googlegroups.com> > References: <4ce07839$0$17214$c3e8da3$eb767761 news.astraweb.com> <428b98ca-72bf-4e3b-ad8a-dafe2fc4d553 v28g2000prn.googlegroups.com> <4ce0c065$0$23246$c3e8da3$a9097924 news.astraweb.com> <6ae54329-c652-4a59-b0e2-4c2038f58d5a x4g2000pre.googlegroups.com> <4ce0ea79$0$29271$c3e8da3$88b277c5 news.astraweb.com> <15016ae4-b341-4f4e-ac84-62fe7f93f217 g20g2000prg.googlegroups.com> <4ce0f788$0$30018$c3e8da3$76a7c58f news.astraweb.com> > NNTP-Posting-Host: 204.244.102.2 > Mime-Version: 1.0 > Content-Type: text/plain; charset=ISO-8859-1 > X-Trace: posting.google.com 1289855748 13278 127.0.0.1 (15 Nov 2010 21:15:48 GMT) > X-Complaints-To: groups-abuse google.com > NNTP-Posting-Date: Mon, 15 Nov 2010 21:15:48 +0000 (UTC) > Complaints-To: groups-abuse google.com > Injection-Info: 37g2000prx.googlegroups.com; posting-host=204.244.102.2; posting-account=AeH9QwoAAABhC1IaTOmk_lG2sf4IeBZX > User-Agent: G2/1.0 > X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2.11) Gecko/20101012 Firefox/3.6.11 (.NET CLR 3.5.30729),gzip(gfe) > From steve-REMOVE-THIS at cybersource.com.au Tue Nov 16 00:17:37 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 16 Nov 2010 05:17:37 GMT Subject: Modifying Element In For List References: <01e04b27-c523-40b7-b9cb-8288823de8fa@p11g2000vbn.googlegroups.com> Message-ID: <4ce213f0$0$29983$c3e8da3$5496439d@news.astraweb.com> On Mon, 15 Nov 2010 08:31:52 -0800, octopusgrabbus wrote: > My question concerns elementary list and pass by reference: What does pass-by-reference have to do with Python? Python doesn't use pass-by-reference... if you think it does, you have misunderstood something. Hint: if you think Python has pass-by-reference, please write a procedure that takes two generic arguments, and swaps their values, like so: a = 1 b = 2 swap(a, b) assert a == 2 assert b == 1 This is the canonical test for pass by reference semantics. > I've written a function which is passed a list that contains rows read > from a csv file. What are the rows? Lists? Tuples? Something else? > The function traverses csv_rows, row by row, and > inspects the first element in each row. The function tests for '', and > if true, replaces that with a 0. > > I've used the standard Python for syntax for this. As opposed to C++ syntax or Lisp syntax? You can't write Python code without using Python syntax, so I'm not sure what you mean here. > def cleanMeterID(csv_rows, bad_meter_id_count): > d = drIdx() > > row_number = 0 > > for row in csv_rows: > if False == is_number(row[d.MeterID]): > csv_rows[row_number][d.MeterID] = 0 > row_number = row_number + 1 > bad_meter_id_count[0]= bad_meter_id_count[0] + 1 > > print("Received ", bad_meter_id_count[0], " bad meter ids") > > I believe the logic show above is flawed, because I am not modifying > elements in the original csv_rows list. Are you sure about that? What happens when you try it? > I would modify this to use an > index to traverse the list like This is nearly always the wrong solution in Python. -- Steven From steve-REMOVE-THIS at cybersource.com.au Tue Nov 16 00:26:08 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 16 Nov 2010 05:26:08 GMT Subject: Some syntactic sugar proposals References: Message-ID: <4ce215f0$0$29983$c3e8da3$5496439d@news.astraweb.com> On Sun, 14 Nov 2010 22:39:05 -0800, Dmitry Groshev wrote: > Here are some proposals. They are quite useful at my opinion and I'm > interested for suggestions. It's all about some common patterns. First > of all: how many times do you write something like > t = foo() > t = t if pred(t) else default_value > ? Hardly ever. Not often enough to need special syntax for it. Of course we can write it as > t = foo() if pred(foo()) else default_value > but here we have 2 foo() calls instead of one. Why can't we write just > something like this: > t = foo() if pred(it) else default_value > where "it" means "foo() value"? t = foo()+bar()+baz() if pred(it) else baz()-foo()-bar() What does "it" mean here? > Second, I saw a lot of questions about using dot notation for a > "object-like" dictionaries and a lot of solutions like this: > class dotdict(dict): > def __getattr__(self, attr): > return self.get(attr, None) > __setattr__= dict.__setitem__ > __delattr__= dict.__delitem__ > why there isn't something like this in a standart library? Because dot notation for dictionaries is not something we should encourage. > And the > third. The more I use python the more I see how "natural" it can be. By > "natural" I mean the statements like this: > [x.strip() for x in reversed(foo)] > which looks almost like a natural language. But there is some pitfalls: > if x in range(a, b): #wrong! Why do you say it's wrong? It's perfectly correct: 1 in range(1, 10) => returns True 1.5 in range(1, 10) => returns False 5 in range(1, 10) => returns True 10 in range(1, 10) => returns False exactly as I expect for element testing in a half-open interval. So where's the problem? If you want interval testing, you need to perform an interval test, not an element test. > it feels so natural to check it that way, but we have to write > if a <= x <= b > I understand that it's not a big deal, but it would be awesome to have > some optimisations - it's clearly possible to detect things like that > "wrong" one and fix it in a bytecode. If I write: x in range(1, 10) how do you expect the compiler to read my mind and know if I want the half-open interval or the closed interval? -- Steven From ian.g.kelly at gmail.com Tue Nov 16 00:40:00 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 15 Nov 2010 22:40:00 -0700 Subject: Some syntactic sugar proposals In-Reply-To: <4ce215f0$0$29983$c3e8da3$5496439d@news.astraweb.com> References: <4ce215f0$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 11/15/2010 10:26 PM, Steven D'Aprano wrote: > t = foo()+bar()+baz() if pred(it) else baz()-foo()-bar() > > What does "it" mean here? "it" would mean the result of the expression foo()+bar()+baz(). What else could it mean? There are valid objections to the proposal, but the intended semantics seem perfectly clear. Cheers, Ian From mback1 at live.se Tue Nov 16 00:45:38 2010 From: mback1 at live.se (Mikael B) Date: Tue, 16 Nov 2010 06:45:38 +0100 Subject: Leo 4.8 rc1 released In-Reply-To: <330ee46d-4894-409d-ab4b-af517fb95dec@k30g2000vbn.googlegroups.com> References: <330ee46d-4894-409d-ab4b-af517fb95dec@k30g2000vbn.googlegroups.com> Message-ID: > From: edreamleo at gmail.com > Subject: Leo 4.8 rc1 released > Date: Mon, 15 Nov 2010 09:06:01 -0800 > To: python-list at python.org > > Leo 4.8 release candidate 1 is now available at: > http://sourceforge.net/project/showfiles.php?group_id=3458&package_id=29106 > > Leo is a text editor, data organizer, project manager and much more. > See: > http://webpages.charter.net/edreamleo/intro.html I tried to install Leo on ubuntu 10.10 with python 2.6.6 prax at prax-MS-7327:~/H?mtningar/Leo-4.8-rc1/leo/scripts$ sudo python LinixInstall.py ***** Installing Leo to /usr/lib/leo... ***** Creating Leo startup script -> /usr/bin/leo ***** Leo installed successfully - type 'leo filename.leo' to use it. prax at prax-MS-7327:~$ leo test.leo python: can't open file '/usr/lib/leo/leo.py': [Errno 2] No such file or directory What to do now? /Mikael -------------- next part -------------- An HTML attachment was scrubbed... URL: From ph.ton.sharma at gmail.com Tue Nov 16 01:52:02 2010 From: ph.ton.sharma at gmail.com (Ton) Date: Mon, 15 Nov 2010 22:52:02 -0800 (PST) Subject: Help: Guide needed in trying to delete/flush the content of a fifo file. References: <1c7f7feb-ff95-404b-9628-458922360908@j12g2000prm.googlegroups.com> Message-ID: On Nov 16, 1:47?am, MRAB wrote: > On 15/11/2010 11:03, Ton wrote: > > > > > On Nov 14, 11:55 pm, MRAB ?wrote: > >> On 14/11/2010 14:48, ton ph wrote:> ?Hi python geeks, > >>> ? ? I have ?problem which i have been trying to find out for the past > >>> some days, i have a device which feeds info to my fifo continuosly, and > >>> a thread of mine reads the > >>> fifo continuosly. Now when i change a parameter in the device, it sends > >>> me different values. Now my problem is that , i want to get rid of the > >>> contents of my previous info which > >>> is present in my buffer of the fifo.So i want to flush the fifo content > >>> when my device starts sending different info .... i am implementing > >>> writing and reading the fifo ?using two different threads. > >>> Please someone guide me solving my problem. > >>> I highly apologise everyone in case my post is not so clear... > >>> Thanks everyone in advance. > > >> When the info changes, the thread which is putting items into the fifo > >> could flush it just by getting items from it (using a non-blocking get) > >> until it's empty. > > > Hi Mrab, > > ? Thanks for your immediate reply , can you please guide me with any > > tool or library function which i can flush my fifo content .. i use > > os.mkfifo() to make the fifo. Or is there any other way i could do > > this ... > > Thanks > > Ah, you're using pipes; I thought you might've been using a queue. I > don't know of a way of flushing a pipe. > > I wonder whether it's a good idea for the producer to keep filling the > fifo, because the consumer know how 'old' the info is when it arrives, > and there's your problem of discarding stale info. Perhaps the producer > should wait until the consumer has sent an acknowledgement before > sending more info. Thanks Mrab, the problem now is that the producer continously dumps the information and since i am implementing the producer using the subprocess as like this cmd = ['my files'] proc = subprocess.Popen(cmd, shell=True, bufsize=0, stdout=subprocess.PIPE, stderr=subprocess.STDOUT ) while flag == True: line = proc.stdout.read() Now what i want is to synchronise the problem of actual info the device is sending and the proper reading as the device is sending and not about reading the previous old info in the fifo... hope i have made clearer my prob. even i have tried proc.stdout.flush(), to flush the previous old info in the fifo. Thnks From hniksic at xemacs.org Tue Nov 16 04:03:44 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Tue, 16 Nov 2010 10:03:44 +0100 Subject: strange behavor.... References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> <87tyjlhu1l.fsf.mdw@metalzone.distorted.org.uk> <4cdf1206$0$29990$c3e8da3$5496439d@news.astraweb.com> <877hggiz17.fsf.mdw@metalzone.distorted.org.uk> <874obj1r0z.fsf@gmail.com> <87hbfihmlb.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <878w0t1vyn.fsf@xemacs.org> mdw at distorted.org.uk (Mark Wooding) writes: >> So even if the globals() dictionary is custom, its __setitem__ method is >> *not* called. > > Fascinating. Thank you. In case it's not obvious, that is because CPython assumes the type for many of its internal or semi-internal structures, and calls the appropriate functions, such as dict.__setitem__ (PyDict_SetItem in C) directly. So python doesn't break the encapsulation of dict itself, it just takes the liberty to assume that globals() is a non-subclassed dict, at least as far as __setitem__ is concerned. From steve at REMOVE-THIS-cybersource.com.au Tue Nov 16 05:42:39 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 16 Nov 2010 10:42:39 GMT Subject: Some syntactic sugar proposals References: <4ce215f0$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4ce2601e$0$30001$c3e8da3$5496439d@news.astraweb.com> On Mon, 15 Nov 2010 22:40:00 -0700, Ian Kelly wrote: > On 11/15/2010 10:26 PM, Steven D'Aprano wrote: >> t = foo()+bar()+baz() if pred(it) else baz()-foo()-bar() >> >> What does "it" mean here? > > "it" would mean the result of the expression foo()+bar()+baz(). What > else could it mean? It could mean the last expression, baz(). Or the entire compound expression, foo()+bar()+baz(). > There are valid objections to the proposal, but the > intended semantics seem perfectly clear. Fair point, my example was terrible and didn't show the point that was clear in my head. Mea culpa. How about this instead? t = foo()+it if pred(it) else bar() Should that be a SyntaxError, or is `it` a variable that holds its value from statement to statement? t = it t = (foo() if pred(it) else bar()) if cond(it) else baz() For what it's worth, Apple's defunct Hypertalk language had a couple of syntax elements very much like that. Hypertalk had a special variable, "it", which you used like this: get the number of cards put it into field "Card number" I trust I don't have to explain this? :) Hypertalk also had a special function, "the result", which worked something like this: ask "This is a dialog box. Please type your answer here:" put the result into field "Your answer" (or you could use "result()" instead). Both of these worked quite well with Hypertalk, particularly with it's focus on non-programmers, but they were designed into the language from the beginning. In Python they would be the proverbial round peg in a square hole. BTW, I frequently use "it" for iterators, and making "it" a reserved word would break a lot of my code. This would make me quite peeved. -- Steven From artur.siekielski at gmail.com Tue Nov 16 06:44:14 2010 From: artur.siekielski at gmail.com (Artur Siekielski) Date: Tue, 16 Nov 2010 03:44:14 -0800 (PST) Subject: Getting references to objects without incrementing reference counters References: <8c98a453-3303-4509-be39-1a26084f573a@o11g2000prf.googlegroups.com> <4ce1a0f5$0$1633$742ec2ed@news.sonic.net> Message-ID: On Nov 15, 10:06?pm, John Nagle wrote: > On 11/14/2010 11:08 AM, Artur Siekielski wrote: > > > Hi. > > I'm using CPython 2.7 and Linux. In order to make parallel > > computations on a large list of objects I want to use multiple > > processes (by using multiprocessing module). In the first step I fill > > the list with objects and then I fork() my worker processes that do > > the job. > > > This should work optimally in the aspect of memory usage because Linux > > implements copy-on-write in forked processes. > > ? ? There used to be a memory leak when using Pickle to talk > to subprocesses. ?See what I wrote at It's something different - I'm not using serialization at all - I have full Python objects "copied" into child processes :). From georg at python.org Tue Nov 16 09:05:51 2010 From: georg at python.org (Georg Brandl) Date: Tue, 16 Nov 2010 15:05:51 +0100 Subject: [RELEASED] Python 3.2 alpha 4 Message-ID: <4CE28FBF.9020200@python.org> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On behalf of the Python development team, I'm happy to announce the fourth and (this time really) final alpha preview release of Python 3.2. Python 3.2 is a continuation of the efforts to improve and stabilize the Python 3.x line. Since the final release of Python 2.7, the 2.x line will only receive bugfixes, and new features are developed for 3.x only. Since PEP 3003, the Moratorium on Language Changes, is in effect, there are no changes in Python's syntax and built-in types in Python 3.2. Development efforts concentrated on the standard library and support for porting code to Python 3. Highlights are: * numerous improvements to the unittest module * PEP 3147, support for .pyc repository directories * PEP 3149, support for version tagged dynamic libraries * an overhauled GIL implementation that reduces contention * many consistency and behavior fixes for numeric operations * countless fixes regarding string/unicode issues; among them full support for a bytes environment (filenames, environment variables) * a sysconfig module to access configuration information * a pure-Python implementation of the datetime module * additions to the shutil module, among them archive file support * improvements to pdb, the Python debugger For an extensive list of changes in 3.2, see Misc/NEWS in the Python distribution. To download Python 3.2 visit: http://www.python.org/download/releases/3.2/ 3.2 documentation can be found at: http://docs.python.org/3.2/ Please consider trying Python 3.2 with your code and reporting any bugs you may notice to: http://bugs.python.org/ Enjoy! - -- Georg Brandl, Release Manager georg at python.org (on behalf of the entire python-dev team and 3.2's contributors) -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.16 (GNU/Linux) iEYEARECAAYFAkzij74ACgkQN9GcIYhpnLCbtwCgi4whRruM0Oi6yfgjVclYErFa OJcAn0U8UBBsQBFyGcnKJRbls6B+guQ2 =Vuqf -----END PGP SIGNATURE----- From arnodel at gmail.com Tue Nov 16 09:12:52 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Tue, 16 Nov 2010 14:12:52 +0000 Subject: strange behavor.... References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> <87tyjlhu1l.fsf.mdw@metalzone.distorted.org.uk> <4cdf1206$0$29990$c3e8da3$5496439d@news.astraweb.com> <877hggiz17.fsf.mdw@metalzone.distorted.org.uk> <874obj1r0z.fsf@gmail.com> <87hbfihmlb.fsf.mdw@metalzone.distorted.org.uk> <878w0t1vyn.fsf@xemacs.org> Message-ID: <87tyjhxspn.fsf@gmail.com> Hrvoje Niksic writes: > mdw at distorted.org.uk (Mark Wooding) writes: > >>> So even if the globals() dictionary is custom, its __setitem__ method is >>> *not* called. >> >> Fascinating. Thank you. > > In case it's not obvious, that is because CPython assumes the type for > many of its internal or semi-internal structures, and calls the > appropriate functions, such as dict.__setitem__ (PyDict_SetItem in C) > directly. So python doesn't break the encapsulation of dict itself, it > just takes the liberty to assume that globals() is a non-subclassed > dict, at least as far as __setitem__ is concerned. But it doesn't make this assumption for locals(). -- Arnaud From steve at holdenweb.com Tue Nov 16 09:29:06 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 16 Nov 2010 09:29:06 -0500 Subject: strange behavor.... In-Reply-To: <87tyjhxspn.fsf@gmail.com> References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> <87tyjlhu1l.fsf.mdw@metalzone.distorted.org.uk> <4cdf1206$0$29990$c3e8da3$5496439d@news.astraweb.com> <877hggiz17.fsf.mdw@metalzone.distorted.org.uk> <874obj1r0z.fsf@gmail.com> <87hbfihmlb.fsf.mdw@metalzone.distorted.org.uk> <878w0t1vyn.fsf@xemacs.org> <87tyjhxspn.fsf@gmail.com> Message-ID: On 11/16/2010 9:12 AM, Arnaud Delobelle wrote: > Hrvoje Niksic writes: > >> mdw at distorted.org.uk (Mark Wooding) writes: >> >>>> So even if the globals() dictionary is custom, its __setitem__ method is >>>> *not* called. >>> >>> Fascinating. Thank you. >> >> In case it's not obvious, that is because CPython assumes the type for >> many of its internal or semi-internal structures, and calls the >> appropriate functions, such as dict.__setitem__ (PyDict_SetItem in C) >> directly. So python doesn't break the encapsulation of dict itself, it >> just takes the liberty to assume that globals() is a non-subclassed >> dict, at least as far as __setitem__ is concerned. > > But it doesn't make this assumption for locals(). > That's because it reserves the right to optimize local storage without extending the mapping to allowing item setting. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From ian.g.kelly at gmail.com Tue Nov 16 11:16:52 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 16 Nov 2010 09:16:52 -0700 Subject: Some syntactic sugar proposals In-Reply-To: <4ce2601e$0$30001$c3e8da3$5496439d@news.astraweb.com> References: <4ce215f0$0$29983$c3e8da3$5496439d@news.astraweb.com> <4ce2601e$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 11/16/2010 3:42 AM, Steven D'Aprano wrote: > On Mon, 15 Nov 2010 22:40:00 -0700, Ian Kelly wrote: > >> On 11/15/2010 10:26 PM, Steven D'Aprano wrote: >>> t = foo()+bar()+baz() if pred(it) else baz()-foo()-bar() >>> >>> What does "it" mean here? >> >> "it" would mean the result of the expression foo()+bar()+baz(). What >> else could it mean? > > It could mean the last expression, baz(). Or the entire compound > expression, foo()+bar()+baz(). Unless the precedence rules were to change, the three expressions in the example that are operated on by the ternary are these: 1. foo()+bar()+baz() 2. pred(it) 3. baz()-foo()-bar() So the antecedent would have to be one of those in order to make any sense at all, and obviously the only choice of those that would be useful is the first one. >> There are valid objections to the proposal, but the >> intended semantics seem perfectly clear. > > Fair point, my example was terrible and didn't show the point that was > clear in my head. Mea culpa. How about this instead? > > t = foo()+it if pred(it) else bar() > > Should that be a SyntaxError, or is `it` a variable that holds its value > from statement to statement? SyntaxError. Implementing this without making 'it' a keyword would be very sloppy, IMO. Another option would be to use a special variable named '__', similar to the variable '_' that the REPL uses to store the result of the last command. This might break some existing code, but probably not very much. Mostly it would just be confusing. > t = (foo() if pred(it) else bar()) if cond(it) else baz() More problematic: t = foo() if pred(bar() if pred2(it) else str(it)) else bar() Does the first 'it' belong to the inner or outer ternary? Probably the inner one. What about the second 'it'? > BTW, I frequently use "it" for iterators, and making "it" a reserved word > would break a lot of my code. This would make me quite peeved. I do the same, and yes, it would make upgrading a real pain. Cheers, Ian From gelonida at gmail.com Tue Nov 16 11:39:05 2010 From: gelonida at gmail.com (gelonida) Date: Tue, 16 Nov 2010 08:39:05 -0800 (PST) Subject: first attempt with pybluez on XP fail Message-ID: <5bc1ca02-c2c0-432e-acaf-9da9fc99054b@v20g2000yqb.googlegroups.com> Hi, Wanted to write a first simple example with pybluez and offer a serial connection service with a given name. What I tried (being inspired by http://people.csail.mit.edu/albert/bluez-intro/x290.html ) is: server_sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM ) port = bluetooth.PORT_ANY # original example used get_available_port() # buy this seems obsolete server_sock.bind(("",port)) server_sock.listen(1) print "listening on port %d" % port loc_host, loc_port = server_sock.getsockname() print "HOST", loc_host, "PORT??", loc_port uuid = "1e0ca4ea-299d-4335-93eb-27fcfe7fa848" bluetooth.advertise_service( server_sock, "FooBar Service", uuid ) The error message, that I get is: listening on port 0 HOST XX:XX:XX:XX:XX:XX PORT?? 1 Traceback (most recent call last): File "XXX\bt_01.py", line 94, in cmd(args) File "XXX\bt_01.py", line 71, in srvr srvr = BTSerService() File "XXX\bt_01.py", line 51, in __init__ bluetooth.advertise_service( server_sock, "FooBar Service", uuid ) File "C:\Python26\lib\site-packages\bluetooth\msbt.py", line 173, in advertise _service sock._sdp_handle = bt.set_service_raw (sock._raw_sdp_record, True) IOError: An invalid argument was supplied. What might I be doing wrong? I got rid of the obsolete get_available_port() and wonder what else might have changed? Thanks a lot for your help. From rde at audaxis.com Tue Nov 16 11:47:21 2010 From: rde at audaxis.com (Romaric DEFAUX) Date: Tue, 16 Nov 2010 17:47:21 +0100 Subject: Pickle in a POST/GET request give EOFError Message-ID: <4CE2B599.7050504@audaxis.com> Hi everybody ! First time I write to this mailing list :) I started writing in python last week, that's probably why I can't understand the following problem... I create a list called web_site_list. This list contain dictionaries called web_site. And some values in this dictionaries are list too. I do that in a function and I return this : return pickle.dumps(web_site_list) This is working fine :) If I do : print "%s" % pickle.loads(system.get_web_site_list()) I've got the right stuffs. For example it returns : [{'documentroot_size': '120', 'servername': '---default---', 'client': 'undefined', 'documentroot': '/var/www/', 'client_contact': 'undefined', 'serveralias': []}] I send this to a web service. I send it like that : #I put it in params def system_updateweb_site(server, login, password): params = {} params['login'] = login params['password'] = password params['action'] = 'updateweb_site' params['servername'] = get_servername() params['hosted_web_site'] = get_web_site_list() return call_system_ws(server, params) #Here's how I send it (I tried in GET and POST) def call_system_ws(host, params): query_string = urllib.urlencode(params) #GET # f = urllib.urlopen("http://%s/ws?%s" % (host, query_string)) #POST f = urllib.urlopen("http://%s/ws" % (host), query_string) result = f.readline().strip() if result == 'ERROR': msg = f.readline().strip() return (False, msg) return (True, result) On the server side : if action == 'updateweb_site': if not (fields.has_key('servername') and fields.has_key('hosted_web_site')): raise WSError('missing parameter : servername or hosted_web_site') log ('ERROR : missing parameter : servername or hosted_web_site') else: servername=g.db.escape_string(fields['servername']) hosted_web_site=g.db.escape_string(fields['hosted_web_site']) output = systemserver.updateweb_site(cursor, servername, hosted_web_site) In systemserver.py : def updateweb_site(cursor, host, hosted_web_site): web_site_list = pickle.loads(hosted_web_site) return "%s" % (web_site_list) I catch this error :* *: args = () message = '' Why ? If I just print hosted_web_site, I get this on my web page : (lp0\n(dp1\nS\'documentroot_size\'\np2\nS\'120\'\np3\nsS\'servername\'\np4\nS\'default\'\np5\nsS\'client\'\np6\nS\'undefined\'\np7\nsS\'documentroot\'\np8\nS\'/var/www/\'\np9\nsS\'client_contact\'\np10\ng7\nsS\'serveralias\'\np11\n(lp12\nsa. It's the "pickled view" of [{'documentroot_size': '120', 'servername': '---default---', 'client': 'undefined', 'documentroot': '/var/www/', 'client_contact': 'undefined', 'serveralias': []}] Can someone help me please ? I spend my afternoon to google to try to find a solution... Thanks in advance !!! Romaric Defaux -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 5361 bytes Desc: S/MIME Cryptographic Signature URL: From list at qtrac.plus.com Tue Nov 16 12:23:51 2010 From: list at qtrac.plus.com (Mark Summerfield) Date: Tue, 16 Nov 2010 17:23:51 +0000 Subject: [Python-Dev] [RELEASED] Python 3.2 alpha 3 In-Reply-To: <4CB45754.10600@python.org> References: <4CB45754.10600@python.org> Message-ID: <20101116172351.38238f15@dino> Hi Georg, On Tue, 12 Oct 2010 14:40:52 +0200 Georg Brandl wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On behalf of the Python development team, I'm happy to announce the > third and final alpha preview release of Python 3.2. [snip] I built & ran Py3.2a4's tests & they were fine for me on Debian testing 64-bit. I also tested all the Python 3 book's examples and with one exception---due to (3) below---they all work fine:-) I think it might be worth mentioning in What's New: (1) In "Other Language Changes", the second item about str() might benefit from a note; perhaps: "This change may break doctests that compare floats. (For example, in older Python 3's str(math.pi) produces '3.14159265359'.) (2) In "New, Improved, and Deprecated Modules", it still has "XXX mention argparse". Maybe replace with: "A new option parsing module, argparse, has been added. This module is more flexible and pragmatic than the deprecated optparse module it supercedes." After all, the module's own documentation is sufficient for the details and "argparse" is a link to it. (3) There is no mention of a subtle change in ElementTree. In older Python 3's xml.etree.ElementTree.parse() would raise an xml.parsers.expat.ExpatError if the parse failed; in 3.2a4 it seems to raise xml.etree.ElementTree.ParseError instead. This is much nicer but could probably do with a mention since it can break things (with an "During handling of the above exception, another exception occurred" error). Perhaps in the "New, Improved, and Deprecated Modules" you might add: "The xml.etree.ElementTree now raises an xml.etree.ElementTree.ParseError when a parse fails; previously it raised a xml.parsers.expat.ExpatError." It would also be nice to mention this in the ElementTree module's documentation for the parse() function. -- Mark Summerfield, Qtrac Ltd, www.qtrac.eu C++, Python, Qt, PyQt - training and consultancy "Programming in Python 3" - ISBN 0321680561 http://www.qtrac.eu/py3book.html From tim.arnold at sas.com Tue Nov 16 12:37:37 2010 From: tim.arnold at sas.com (Tim Arnold) Date: Tue, 16 Nov 2010 12:37:37 -0500 Subject: remote server and effective uid References: Message-ID: "Tim Harig" wrote in message news:ibs8h9$jmq$1 at speranza.aioe.org... > On 2010-11-15, Tim Arnold wrote: >> On Nov 15, 10:41 am, Tim Harig wrote: >>> On 2010-11-15, Tim Arnold wrote: >>> >>> > How can I enable the server process to write into the client's >>> > directories? >>> > If I change the inetd service to run as 'root', I guess that would >>> > work, but then the client couldn't remove the files put there after >>> > the request. >>> >>> Python provides os.setuid() and os.seteuid() which wrap the system >>> functions. See you systems man pages for these functions for more >>> information. >> >> Thanks -- that was a lot easier than I thought it was going to be. >> pass the client's uid in the message to the server like so >> >> argstring, local_dir, uid = message.split(':') >> os.seteuid(int(uid)) > > I am not sure exactly what you are doing; but, I would advise great > caution as messing this up could easily open your system to exploitation. > Be very sure that you know what you are doing. I can see how that looks dangerous, but I think it's okay. I have inetd listening on a port and whatever it receives, it passes on to that line above "argstring, local_dir, uid message.split(':'). The argstring is parsed using 'argparse' the resulting list of args is passed to a Python class that can only do work for a specific set of args. I can't think of a way someone could pass in an evil argstring that could do anything but fail. Thanks for your reply, and if you still think it's dangerous please let me know. --Tim From iamforufriends at gmail.com Tue Nov 16 13:26:52 2010 From: iamforufriends at gmail.com (real dating with hot girl) Date: Tue, 16 Nov 2010 10:26:52 -0800 (PST) Subject: ***REAL DATING WITH HOT REAL GIRL FOR FREE...*** Message-ID: ***REAL DATING WITH HOT REAL GIRL FOR FREE...*** http://is.gd/he5WZ OR http://x2c.eu/4z OR http://tinyurl.com/friend-4-fun1 From Marc-Andre.Belzile at autodesk.com Tue Nov 16 13:36:24 2010 From: Marc-Andre.Belzile at autodesk.com (Marc-Andre Belzile) Date: Tue, 16 Nov 2010 18:36:24 +0000 Subject: Python OGL package Message-ID: Hi list, could someone recommend a good python ogl package (open source is preferred) ? I found these ones so far: http://pyopengl.sourceforge.net/ http://wiki.wxpython.org/wxOGL thanks -mab -------------- next part -------------- An HTML attachment was scrubbed... URL: From andre.roberge at gmail.com Tue Nov 16 13:45:00 2010 From: andre.roberge at gmail.com (=?ISO-8859-1?Q?Andr=E9?=) Date: Tue, 16 Nov 2010 10:45:00 -0800 (PST) Subject: Some syntactic sugar proposals References: Message-ID: <2e60b1d0-d95e-47ad-b251-58a417931487@o2g2000vbh.googlegroups.com> On Nov 15, 2:39?am, Dmitry Groshev wrote: > Here are some proposals. They are quite useful at my opinion and I'm > interested for suggestions. It's all about some common patterns. > First of all: how many times do you write something like > ? ? t = foo() > ? ? t = t if pred(t) else default_value Never! [snip] > And the third. The more I use python the more I see how "natural" it > can be. By "natural" I mean the statements like this: > ? ? [x.strip() for x in reversed(foo)] > which looks almost like a natural language. But there is some > pitfalls: > ? ? if x in range(a, b): #wrong! This is true only if x is an integer such that a <= x < b > it feels so natural to check it that way, but we have to write > ? ? if a <= x <= b This is true if x is an integer OR a float. Two very different cases, deserving of different notation. Andr? From raymond.activestate at gmail.com Tue Nov 16 14:09:49 2010 From: raymond.activestate at gmail.com (Raymond Hettinger) Date: Tue, 16 Nov 2010 11:09:49 -0800 (PST) Subject: [RELEASED] Python 3.2 alpha 3 References: <4CB45754.10600@python.org> Message-ID: <1510ba5f-a2ff-422d-9a69-23c9ba523bcb@v12g2000vbh.googlegroups.com> On Nov 16, 9:23?am, Mark Summerfield wrote: > I think it might be worth mentioning in What's New: FWIW, I'll be updating the What's New document for the Beta. Raymond From python at mrabarnett.plus.com Tue Nov 16 14:13:23 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 16 Nov 2010 19:13:23 +0000 Subject: Help: Guide needed in trying to delete/flush the content of a fifo file. In-Reply-To: References: <1c7f7feb-ff95-404b-9628-458922360908@j12g2000prm.googlegroups.com> Message-ID: <4CE2D7D3.8040203@mrabarnett.plus.com> On 16/11/2010 06:52, Ton wrote: > On Nov 16, 1:47 am, MRAB wrote: >> On 15/11/2010 11:03, Ton wrote: >> >> >> >>> On Nov 14, 11:55 pm, MRAB wrote: >>>> On 14/11/2010 14:48, ton ph wrote:> Hi python geeks, >>>>> I have problem which i have been trying to find out for the past >>>>> some days, i have a device which feeds info to my fifo continuosly, and >>>>> a thread of mine reads the >>>>> fifo continuosly. Now when i change a parameter in the device, it sends >>>>> me different values. Now my problem is that , i want to get rid of the >>>>> contents of my previous info which >>>>> is present in my buffer of the fifo.So i want to flush the fifo content >>>>> when my device starts sending different info .... i am implementing >>>>> writing and reading the fifo using two different threads. >>>>> Please someone guide me solving my problem. >>>>> I highly apologise everyone in case my post is not so clear... >>>>> Thanks everyone in advance. >> >>>> When the info changes, the thread which is putting items into the fifo >>>> could flush it just by getting items from it (using a non-blocking get) >>>> until it's empty. >> >>> Hi Mrab, >>> Thanks for your immediate reply , can you please guide me with any >>> tool or library function which i can flush my fifo content .. i use >>> os.mkfifo() to make the fifo. Or is there any other way i could do >>> this ... >>> Thanks >> >> Ah, you're using pipes; I thought you might've been using a queue. I >> don't know of a way of flushing a pipe. >> >> I wonder whether it's a good idea for the producer to keep filling the >> fifo, because the consumer know how 'old' the info is when it arrives, >> and there's your problem of discarding stale info. Perhaps the producer >> should wait until the consumer has sent an acknowledgement before >> sending more info. > > Thanks Mrab, > the problem now is that the producer continously dumps the > information and since i am implementing the producer using the > subprocess as like this > > cmd = ['my files'] > proc = subprocess.Popen(cmd, shell=True, bufsize=0, > stdout=subprocess.PIPE, stderr=subprocess.STDOUT ) > > while flag == True: > line = proc.stdout.read() > > Now what i want is to synchronise the problem of actual info the > device is sending and the proper reading as the device is sending and > not about reading the previous old info in the fifo... hope i have > made clearer my prob. even i have tried proc.stdout.flush(), to flush > the previous old info in the fifo. Thnks Use two pipes, one each way. The consumer could use send a message to the producer requesting an update, which the producer could send back via the other pipe. From pecora at anvil.nrl.navy.mil Tue Nov 16 14:22:08 2010 From: pecora at anvil.nrl.navy.mil (Lou Pecora) Date: Tue, 16 Nov 2010 14:22:08 -0500 Subject: What was your strategy? References: <201011142240.oAEMecu2054270@krusty.intranet.com.mx> Message-ID: In article , Dennis Lee Bieber wrote: > On Sun, 14 Nov 2010 16:32:24 -0600, Jorge Biquez > declaimed the following in gmane.comp.python.general: > > > I was wondering if you can share what was the strategy you followed > > to master Python (Yes I know I have to work hard study and practice a > > lot). I mean did you use special books, special sites, a plan to > > I picked up the first edition "Programming Python" (and a now > forgotten competitor book) since the Amiga was mentioned... I'll jump in and recommend the book "Python in a Nutshell" by Martelli. It may be a little dated now, but it covers many Python topics in good detail without becoming a bloated reference. Nicely written. It's still the first book I reach for after 6 years of Python coding and it rarely disappoints. -- -- Lou Pecora From ndbecker2 at gmail.com Tue Nov 16 14:35:01 2010 From: ndbecker2 at gmail.com (Neal Becker) Date: Tue, 16 Nov 2010 14:35:01 -0500 Subject: argparse subparser problem Message-ID: I want to have subparsers, but I also want to be able to say: myprogram --version and get the version # --------------------------- import argparse def stop(): pass parser = argparse.ArgumentParser() parser.add_argument ('--version', action='store_true') subparsers = parser.add_subparsers() parser_stop = subparsers.add_parser ('stop') parser_stop.add_argument ('stop', action='store_true') parser_stop.set_defaults (func=stop) opt = parser.parse_args (['--version']) ------------------------------ python test_p1.py usage: test_p1.py [-h] [--version] {stop} ... test_p1.py: error: too few arguments From steve at holdenweb.com Tue Nov 16 14:37:16 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 16 Nov 2010 14:37:16 -0500 Subject: What was your strategy? In-Reply-To: References: <201011142240.oAEMecu2054270@krusty.intranet.com.mx> Message-ID: On 11/16/2010 2:22 PM, Lou Pecora wrote: > I'll jump in and recommend the book "Python in a Nutshell" by Martelli. > It may be a little dated now, but it covers many Python topics in good > detail without becoming a bloated reference. Nicely written. It's still > the first book I reach for after 6 years of Python coding and it rarely > disappoints. +1 It's encyclopedic. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From fuglyducky at gmail.com Tue Nov 16 15:00:12 2010 From: fuglyducky at gmail.com (fuglyducky) Date: Tue, 16 Nov 2010 12:00:12 -0800 (PST) Subject: SQLite3 and lastrowid Message-ID: <2d87112c-e776-41ea-838a-5e165e478052@e20g2000vbn.googlegroups.com> I am fairly new to Python (no development experience) and brand new to using sqlite through Python. With that said, I created a database with two tables. The first has about 30,000 rows of static data. The second has 9 rows of static data. Before I added the second table I could simply run 'print(cursor.lastrowid)' and it would give me the id number. However, with two tables I am unable to do this. Does anyone know if there is a way to reference one table or another to get lastrowid? Thanks!!! From gelonida at gmail.com Tue Nov 16 15:31:15 2010 From: gelonida at gmail.com (Gelonida) Date: Tue, 16 Nov 2010 21:31:15 +0100 Subject: first attempts with pybluez on Win XP fail Message-ID: Hi, My post from Google groups doesn't sem to get through. SO here once more posted from gmane. Wanted to write a first simple example with pybluez and offer a serial connection service with a given name. What I tried (being inspired by http://people.csail.mit.edu/albert/bluez-intro/x290.html ) is: server_sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM ) port = bluetooth.PORT_ANY # original example used get_available_port() # buy this seems obsolete server_sock.bind(("",port)) server_sock.listen(1) print "listening on port %d" % port loc_host, loc_port = server_sock.getsockname() print "HOST", loc_host, "PORT??", loc_port uuid = "1e0ca4ea-299d-4335-93eb-27fcfe7fa848" bluetooth.advertise_service( server_sock, "FooBar Service", uuid ) The error message, that I get is: listening on port 0 HOST XX:XX:XX:XX:XX:XX PORT?? 1 Traceback (most recent call last): File "XXX\bt_01.py", line 94, in cmd(args) File "XXX\bt_01.py", line 71, in srvr srvr = BTSerService() File "XXX\bt_01.py", line 51, in __init__ bluetooth.advertise_service( server_sock, "FooBar Service", uuid ) File "C:\Python26\lib\site-packages\bluetooth\msbt.py", line 173, in advertise _service sock._sdp_handle = bt.set_service_raw (sock._raw_sdp_record, True) IOError: An invalid argument was supplied. What might I be doing wrong? I got rid of the obsolete get_available_port() and wonder what else might have changed? Thanks a lot for your help. From hansyin at gmail.com Tue Nov 16 15:38:56 2010 From: hansyin at gmail.com (Hans) Date: Tue, 16 Nov 2010 12:38:56 -0800 (PST) Subject: how to use socket to get packet which destination ip is not local? Message-ID: <21df438f-9869-4818-bc59-752702e2a203@j1g2000vbl.googlegroups.com> Hi, Maybe it's a very simple question. I'm trying to write a dhcpclient code with python. The dhcpclient does not have ip address at the very beginning, it sends out dhcpdiscover and then server sends back dhcpoffer. the dhcpoffer will use assigned ip as destination ip, but that ip is not client's local ip yet. How can I make my socket to receive that packet? I tried socket bind to 0.0.0.0, but it only binds to any local ip, not any ip which may not be local. therefore the socket cannot get that dhcp offer packet even I can use wireshark to see that packet did come to this pc. How to solve it? Thanks in advance. Rgds, Hans From pedroigor91 at gmail.com Tue Nov 16 15:51:07 2010 From: pedroigor91 at gmail.com (pedro igor sampaio avelino) Date: Tue, 16 Nov 2010 12:51:07 -0800 (PST) Subject: Help in language development Message-ID: <6fb7a013-cee1-4c77-9b96-d5494a5dda98@j25g2000yqa.googlegroups.com> Hello, my name Pedro Igor, I am a student and develop applications in python for 1 year. I enrolled in the group to contribute in developing this wonderful language that helps me both in day-to-day, but I'm going through some difficulties because they do not know where to start, can someone please give me some steps so that I can contribute at once development for all, where do I start, if the documentation or a book. I know that most people have more important issues to address in other posts but assistance does not cost anything. Graciously From ian.g.kelly at gmail.com Tue Nov 16 15:54:37 2010 From: ian.g.kelly at gmail.com (Ian) Date: Tue, 16 Nov 2010 12:54:37 -0800 (PST) Subject: SQLite3 and lastrowid References: <2d87112c-e776-41ea-838a-5e165e478052@e20g2000vbn.googlegroups.com> Message-ID: <713377d1-b9e2-4da1-a56a-c4f042f6e3e4@g2g2000vbe.googlegroups.com> On Nov 16, 1:00?pm, fuglyducky wrote: > Before I added the second table I could simply run > 'print(cursor.lastrowid)' and it would give me the id number. However, > with two tables I am unable to do this. It would help if you would show the code where you're trying to do this. Without your actual code to look at, we can't tell you why it doesn't work. > Does anyone know if there is a way to reference one table or another > to get lastrowid? cursor.lastrowid is always in reference to the last query executed by the cursor, not in reference to a table. If you don't capture the value, and then you execute another query on the same cursor, the previous value of cursor.lastrowid no longer exists. If you need it now, then either you should have captured it when you had the chance, or you should not have executed another query on the same cursor. But perhaps this is not what you're actually trying to do. I can't tell, because I haven't seen the code. Cheers, Ian From m.g.bode at web.de Tue Nov 16 15:55:25 2010 From: m.g.bode at web.de (Michael Bode) Date: Tue, 16 Nov 2010 21:55:25 +0100 Subject: How to implement a callback COM object in Python Message-ID: Hi, I'm trying to write a COM client to a COM server which controls a power meter. The COM server fires events that should be handled by the client. The docs state that I have to supply a class which implements the IFM2DeviceEvents interface. I need some instructions on how to translate the VB sample code to Python: Option Explicit Implements IFM2DeviceEvents Private m_CallbackEvent As String Private m_CallbackMessage As String Private m_DeviceIndex As Integer Private m_SerialNumber As String Private m_ZeroDeviceTimeoutCounter As Integer ' Methods Private Sub IFM2DeviceEvents_DisplayErrorToClient() frmTest.DisplayErrorMessage m_CallbackMessage End Sub Private Sub IFM2DeviceEvents_NotifyData(ByVal CallbackData As IFM2DeviceEvents) frmTest.NotifyData CallbackData End Sub Private Sub IFM2DeviceEvents_NotifyDeviceStatus(ByVal CallbackData As IFM2DeviceEvents, ByVal DevicesList As cFM2Devices) frmTest.NotifyDeviceStatus CallbackData, DevicesList End Sub Private Sub IFM2DeviceEvents_DisplayZeroDeviceProgressToClient() frmTest.DisplayZeroDeviceProgress m_CallbackMessage, m_ZeroDeviceTimeoutCounter End Sub ' Read/write properties Private Property Let IFM2DeviceEvents_CallbackEvent(ByVal RHS As String) m_CallbackEvent = RHS End Property Private Property Get IFM2DeviceEvents_CallbackEvent() As String IFM2DeviceEvents_CallbackEvent = m_CallbackEvent End Property ... From python at mrabarnett.plus.com Tue Nov 16 15:57:55 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 16 Nov 2010 20:57:55 +0000 Subject: how to use socket to get packet which destination ip is not local? In-Reply-To: <21df438f-9869-4818-bc59-752702e2a203@j1g2000vbl.googlegroups.com> References: <21df438f-9869-4818-bc59-752702e2a203@j1g2000vbl.googlegroups.com> Message-ID: <4CE2F053.7010509@mrabarnett.plus.com> On 16/11/2010 20:38, Hans wrote: > Hi, > > Maybe it's a very simple question. I'm trying to write a dhcpclient > code with python. The dhcpclient does not have ip address at the very > beginning, it sends out dhcpdiscover and then server sends back > dhcpoffer. the dhcpoffer will use assigned ip as destination ip, but > that ip is not client's local ip yet. How can I make my socket to > receive that packet? > > I tried socket bind to 0.0.0.0, but it only binds to any local ip, not > any ip which may not be local. therefore the socket cannot get that > dhcp offer packet even I can use wireshark to see that packet did come > to this pc. > > How to solve it? Thanks in advance. > Have you read this: http://en.wikipedia.org/wiki/Dynamic_Host_Configuration_Protocol From felipe.bastosn at gmail.com Tue Nov 16 16:02:02 2010 From: felipe.bastosn at gmail.com (Felipe Bastos Nunes) Date: Tue, 16 Nov 2010 19:02:02 -0200 Subject: Help in language development In-Reply-To: <6fb7a013-cee1-4c77-9b96-d5494a5dda98@j25g2000yqa.googlegroups.com> References: <6fb7a013-cee1-4c77-9b96-d5494a5dda98@j25g2000yqa.googlegroups.com> Message-ID: [Portuguese talking, excuse me guys] Pedro, voc?s podem dar um olhada no bug tracking, e estudar os c?digos pra encontrar solu??es. 2010/11/16 pedro igor sampaio avelino > Hello, my name Pedro Igor, I am a student and develop applications in > python for 1 year. I enrolled in the group to contribute in developing > this wonderful language that helps me both in day-to-day, but I'm > going through some difficulties because they do not know where to > start, can someone please give me some steps so that I can contribute > at once development for all, where do I start, if the documentation or > a book. I know that most people have more important issues to address > in other posts but assistance does not cost anything. > > Graciously > -- > http://mail.python.org/mailman/listinfo/python-list > -- Felipe Bastos Nunes -------------- next part -------------- An HTML attachment was scrubbed... URL: From fuglyducky at gmail.com Tue Nov 16 16:08:15 2010 From: fuglyducky at gmail.com (fuglyducky) Date: Tue, 16 Nov 2010 13:08:15 -0800 (PST) Subject: SQLite3 and lastrowid References: <2d87112c-e776-41ea-838a-5e165e478052@e20g2000vbn.googlegroups.com> <713377d1-b9e2-4da1-a56a-c4f042f6e3e4@g2g2000vbe.googlegroups.com> Message-ID: On Nov 16, 12:54?pm, Ian wrote: > On Nov 16, 1:00?pm, fuglyducky wrote: > > > Before I added the second table I could simply run > > 'print(cursor.lastrowid)' and it would give me the id number. However, > > with two tables I am unable to do this. > > It would help if you would show the code where you're trying to do > this. ?Without your actual code to look at, we can't tell you why it > doesn't work. > > > Does anyone know if there is a way to reference one table or another > > to get lastrowid? > > cursor.lastrowid is always in reference to the last query executed by > the cursor, not in reference to a table. ?If you don't capture the > value, and then you execute another query on the same cursor, the > previous value of cursor.lastrowid no longer exists. ?If you need it > now, then either you should have captured it when you had the chance, > or you should not have executed another query on the same cursor. > > But perhaps this is not what you're actually trying to do. ?I can't > tell, because I haven't seen the code. > > Cheers, > Ian Thanks for the input. Sorry...I should have included the code...it's just a simple query... ##################################################### import sqlite3 import random db_connect = sqlite3.connect('test.db') cursor = db_connect.cursor() print(cursor.lastrowid) # Choose random index from DB - need to understand lastrowid #row_count = cursor.lastrowid #random_row = random.randrange(0, row_count) cursor.execute("SELECT * FROM table1 WHERE id = 2002") print(cursor.fetchmany()) #for row in cursor: # print(row) db_connect.commit() cursor.close() ##################################################### From dan at catfolks.net Tue Nov 16 16:12:14 2010 From: dan at catfolks.net (Dan M) Date: Tue, 16 Nov 2010 15:12:14 -0600 Subject: SQLite3 and lastrowid References: <2d87112c-e776-41ea-838a-5e165e478052@e20g2000vbn.googlegroups.com> <713377d1-b9e2-4da1-a56a-c4f042f6e3e4@g2g2000vbe.googlegroups.com> Message-ID: On Tue, 16 Nov 2010 13:08:15 -0800, fuglyducky wrote: > On Nov 16, 12:54?pm, Ian wrote: >> On Nov 16, 1:00?pm, fuglyducky wrote: >> >> > Before I added the second table I could simply run >> > 'print(cursor.lastrowid)' and it would give me the id number. >> > However, with two tables I am unable to do this. >> >> It would help if you would show the code where you're trying to do >> this. ?Without your actual code to look at, we can't tell you why it >> doesn't work. >> >> > Does anyone know if there is a way to reference one table or another >> > to get lastrowid? >> >> cursor.lastrowid is always in reference to the last query executed by >> the cursor, not in reference to a table. ?If you don't capture the >> value, and then you execute another query on the same cursor, the >> previous value of cursor.lastrowid no longer exists. ?If you need it >> now, then either you should have captured it when you had the chance, >> or you should not have executed another query on the same cursor. >> >> But perhaps this is not what you're actually trying to do. ?I can't >> tell, because I haven't seen the code. >> >> Cheers, >> Ian > > Thanks for the input. Sorry...I should have included the code...it's > just a simple query... > > ##################################################### > > import sqlite3 > import random > > db_connect = sqlite3.connect('test.db') cursor = db_connect.cursor() > > print(cursor.lastrowid) > > # Choose random index from DB - need to understand lastrowid #row_count > = cursor.lastrowid > #random_row = random.randrange(0, row_count) > > cursor.execute("SELECT * FROM table1 WHERE id = 2002") > print(cursor.fetchmany()) Perhaps insert here: cursor.execute("SELECT count() from table2") table2lastRow = cursor.lastrowid() > > #for row in cursor: > # print(row) > > > db_connect.commit() > cursor.close() > > ##################################################### From fred.sells at adventistcare.org Tue Nov 16 16:48:02 2010 From: fred.sells at adventistcare.org (Sells, Fred) Date: Tue, 16 Nov 2010 16:48:02 -0500 Subject: What was your strategy? In-Reply-To: <201011142240.oAEMecu2054270@krusty.intranet.com.mx> References: <201011142240.oAEMecu2054270@krusty.intranet.com.mx> Message-ID: It helps to try to solve a real (to you) problem, that way you discover what you don't know. If your code ends up nested 3 levels or your methods are more than 10 lines, ask for help. -----Original Message----- From: python-list-bounces+frsells=adventistcare.org at python.org [mailto:python-list-bounces+frsells=adventistcare.org at python.org] On Behalf Of Jorge Biquez Sent: Sunday, November 14, 2010 5:32 PM To: python-list at python.org Subject: What was your strategy? Hello all. Quick question. I know some of you are with Python since started, some other maybe later. I was wondering if you can share what was the strategy you followed to master Python (Yes I know I have to work hard study and practice a lot). I mean did you use special books, special sites, a plan to learn each subject in a special way. I would like to know, if possible, comments specially from some of you who in the past had other languages, frameworks and platforms and left (almost) all of them and stayed with Python. Thanks in advance Jorge Biquez -- http://mail.python.org/mailman/listinfo/python-list From ian.g.kelly at gmail.com Tue Nov 16 16:52:42 2010 From: ian.g.kelly at gmail.com (Ian) Date: Tue, 16 Nov 2010 13:52:42 -0800 (PST) Subject: SQLite3 and lastrowid References: <2d87112c-e776-41ea-838a-5e165e478052@e20g2000vbn.googlegroups.com> <713377d1-b9e2-4da1-a56a-c4f042f6e3e4@g2g2000vbe.googlegroups.com> Message-ID: <2ec7c0d8-4105-452d-88e3-01050c4c567f@v12g2000vbh.googlegroups.com> On Nov 16, 2:08?pm, fuglyducky wrote: > db_connect = sqlite3.connect('test.db') > cursor = db_connect.cursor() > > print(cursor.lastrowid) At this point you haven't executed a query yet, so there is no meaningful value that cursor.lastrowid can take. > # Choose random index from DB - need to understand lastrowid > #row_count = cursor.lastrowid > #random_row = random.randrange(0, row_count) This is wrong. The lastrowid is not the number of rows in the table. It's the row-id of the row that was inserted (if any) by the last query executed by the cursor. In the case of sqlite3, I think the row- id is just the primary key if it's an integer (but in general the row- id is database-dependent), so you *might* be able to get away with it if you always let it autoincrement when inserting, never delete any rows, and never change their primary keys. But it's unreliable and only available immediately after an insert, so don't do it that way. The proper way to get the number of rows is to use the COUNT aggregate function, e.g., "SELECT COUNT(*) FROM TABLE1", which will return a single row with a single column containing the number of rows in table1. Cheers, Ian From bostjan.mejak at gmail.com Tue Nov 16 16:56:05 2010 From: bostjan.mejak at gmail.com (=?UTF-8?Q?Bo=C5=A1tjan_Mejak?=) Date: Tue, 16 Nov 2010 22:56:05 +0100 Subject: Raw Unicode docstring Message-ID: Hello, how does one write a raw unicode docstring? If I have backslashes in the docstring, I must tuck an 'r' in front of it, like this: r"""This is a raw docstring.""" If I have foreign letters in the docstring, I must tuck a 'u' in front of it, like this: u"""This is a Unicode docstring.""" What if I have foreign characters *and* backslashes in my docstring? How to write the docstring then? ru"""My raw unicode docstring.""" or ur"""My unicode docstring.""" Please answer my question, although it may sound like a noobish one. Thanks. From contact at xavierho.com Tue Nov 16 17:02:59 2010 From: contact at xavierho.com (Xavier Ho) Date: Wed, 17 Nov 2010 08:02:59 +1000 Subject: Python OGL package In-Reply-To: References: Message-ID: Also try Pyglet, in combination of PyOpenGL. Cheers, Xav On 17 November 2010 04:36, Marc-Andre Belzile < Marc-Andre.Belzile at autodesk.com> wrote: > Hi list, > > > > could someone recommend a good python ogl package (open source is > preferred) ? I found these ones so far: > > > > http://pyopengl.sourceforge.net/ > > http://wiki.wxpython.org/wxOGL > > > > thanks > > > > -mab > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From aahz at pythoncraft.com Tue Nov 16 17:16:10 2010 From: aahz at pythoncraft.com (Aahz) Date: 16 Nov 2010 14:16:10 -0800 Subject: Komodo 6, why "Workspace Restore" after every restart? References: <4ce07839$0$17214$c3e8da3$eb767761@news.astraweb.com> <4ce0ea79$0$29271$c3e8da3$88b277c5@news.astraweb.com> <15016ae4-b341-4f4e-ac84-62fe7f93f217@g20g2000prg.googlegroups.com> <4ce0f788$0$30018$c3e8da3$76a7c58f@news.astraweb.com> Message-ID: [overquoting follows to prove my point] Someone who claims to care as much as you do about Usenet ought to have better quoting habits. You should be ashamed of yourself. In article <4ce0f788$0$30018$c3e8da3$76a7c58f at news.astraweb.com>, John Doe wrote: >alex23 wrote: > >> John Doe wrote: > >>> Google Groups spews a massive amount of sewage onto UseNet >>> everyday. Google Groups is your news server. You should be >>> ashamed >> >> Get over yourself. > >You too, and stop using the spammers den while you are at it. >-- > > > > > > > > > > > > > > > > >See also googled groups >> Path: news.astraweb.com!border5.newsrouter.astraweb.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!postnews.google.com!g20g2000prg.googlegroups.com!not-for-mail >> From: alex23 >> Newsgroups: comp.lang.python >> Subject: Re: Komodo 6, why "Workspace Restore" after every restart? >> Date: Mon, 15 Nov 2010 00:42:36 -0800 (PST) >> Organization: http://groups.google.com >> Lines: 6 >> Message-ID: <15016ae4-b341-4f4e-ac84-62fe7f93f217 g20g2000prg.googlegroups.com> >> References: <4ce07839$0$17214$c3e8da3$eb767761 news.astraweb.com> <428b98ca-72bf-4e3b-ad8a-dafe2fc4d553 v28g2000prn.googlegroups.com> <4ce0c065$0$23246$c3e8da3$a9097924 news.astraweb.com> <6ae54329-c652-4a59-b0e2-4c2038f58d5a x4g2000pre.googlegroups.com> <4ce0ea79$0$29271$c3e8da3$88b277c5 news.astraweb.com> >> NNTP-Posting-Host: 115.64.196.128 >> Mime-Version: 1.0 >> Content-Type: text/plain; charset=ISO-8859-1 >> X-Trace: posting.google.com 1289810556 23916 127.0.0.1 (15 Nov 2010 08:42:36 GMT) >> X-Complaints-To: groups-abuse google.com >> NNTP-Posting-Date: Mon, 15 Nov 2010 08:42:36 +0000 (UTC) >> Complaints-To: groups-abuse google.com >> Injection-Info: g20g2000prg.googlegroups.com; posting-host=115.64.196.128; posting-account=rYyWJQoAAACVJO77HvcyJfa3TnGYCqK_ >> User-Agent: G2/1.0 >> X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.12 (KHTML, like Gecko) Chrome/9.0.576.0 Safari/534.12,gzip(gfe) >> -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Look, it's your affair if you want to play with five people, but don't go calling it doubles." --John Cleese anticipates Usenet From python at mrabarnett.plus.com Tue Nov 16 17:22:40 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 16 Nov 2010 22:22:40 +0000 Subject: Raw Unicode docstring In-Reply-To: References: Message-ID: <4CE30430.3020909@mrabarnett.plus.com> On 16/11/2010 21:56, Bo?tjan Mejak wrote: > Hello, > > how does one write a raw unicode docstring? If I have backslashes in > the docstring, I must tuck an 'r' in front of it, like this: > r"""This is a raw docstring.""" > > If I have foreign letters in the docstring, I must tuck a 'u' in front > of it, like this: > u"""This is a Unicode docstring.""" > > What if I have foreign characters *and* backslashes in my docstring? > How to write the docstring then? > ru"""My raw unicode docstring.""" > or > ur"""My unicode docstring.""" > > Please answer my question, although it may sound like a noobish one. Thanks. Why not try them both and see what happens? From robert.kern at gmail.com Tue Nov 16 17:26:18 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 16 Nov 2010 16:26:18 -0600 Subject: Raw Unicode docstring In-Reply-To: References: Message-ID: On 11/16/10 3:56 PM, Bo?tjan Mejak wrote: > Hello, > > how does one write a raw unicode docstring? If I have backslashes in > the docstring, I must tuck an 'r' in front of it, like this: > r"""This is a raw docstring.""" > > If I have foreign letters in the docstring, I must tuck a 'u' in front > of it, like this: > u"""This is a Unicode docstring.""" > > What if I have foreign characters *and* backslashes in my docstring? I would just use a double-backslash u'\\' for each backslash that is supposed to be in the actual string. -- 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 lorena.aspiroz at gmail.com Tue Nov 16 17:30:58 2010 From: lorena.aspiroz at gmail.com (laspi) Date: Tue, 16 Nov 2010 14:30:58 -0800 (PST) Subject: Is Unladen Swallow dead? Message-ID: <2e1a4d02-1e8a-4d31-95da-f33aaf90578c@30g2000yql.googlegroups.com> There has been little or no activity at all in this project in the last months, and the last comments on their mailing list seem to conrfim that it's future is uncertain. It's also very strange the lack of updates, news or discussions, specially considering that the merging plan has been approved. Or it hasn't? From ladasky at my-deja.com Tue Nov 16 17:32:19 2010 From: ladasky at my-deja.com (John Ladasky) Date: Tue, 16 Nov 2010 14:32:19 -0800 (PST) Subject: Some syntactic sugar proposals References: <4ac1734d-fffb-4fdc-be42-27812a174b97@i32g2000pri.googlegroups.com> Message-ID: <3a859762-8123-44f9-8ce8-0997746de19e@o34g2000vbi.googlegroups.com> On Nov 14, 11:30?pm, alex23 wrote: > On Nov 15, 4:39?pm, Dmitry Groshev wrote: > > > ? ? if x in range(a, b): #wrong! > > Only in Python 3.x, it's perfectly valid in Python 2.x. To achieve the > same in Python 3.x, try: > > ? ? if x in list(range(a, b,)): # BUT SEE MY COMMENT BELOW > > > it feels so natural to check it that way, but we have to write > > ? ? if a <= x <= b > > I understand that it's not a big deal, but it would be awesome to have > > some optimisations - it's clearly possible to detect things like that > > "wrong" one and fix it in a bytecode. > > This seems more like a pessimisation to me: your range version > constructs a list just to do a single container check. That's a _lot_ > more cumbersome than two simple comparisons chained together. Also: testing for the membership of x in a set is NOT the same thing as testing using inequality operators. The inequality operators will return True for any FLOATING-POINT value within the range (a...b), but the set test will only return True for set members. From tjreedy at udel.edu Tue Nov 16 17:33:14 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 16 Nov 2010 17:33:14 -0500 Subject: Raw Unicode docstring In-Reply-To: References: Message-ID: On 11/16/2010 4:56 PM, Bo?tjan Mejak wrote: > Hello, > > how does one write a raw unicode docstring? If I have backslashes in > the docstring, I must tuck an 'r' in front of it, like this: > r"""This is a raw docstring.""" You only need (and want that) if you want '\' to be taken literally. And even if you do, '\\' will put one '\' in the string, so raw mode is never needed; it is only a convenience when one needs lots of literal backslashes. > If I have foreign letters in the docstring, I must tuck a 'u' in front > of it, like this: > u"""This is a Unicode docstring.""" > > What if I have foreign characters *and* backslashes in my docstring? > How to write the docstring then? > ru"""My raw unicode docstring.""" > or > ur"""My unicode docstring.""" > > Please answer my question, although it may sound like a noobish one. Thanks. You could look in the manual, which has been improved in this regard for 2.7.1. Or you could try both and see which gives a syntax error ;=). That would have been faster than posting this. -- Terry Jan Reedy From alex.kapps at web.de Tue Nov 16 17:34:09 2010 From: alex.kapps at web.de (Alexander Kapps) Date: Tue, 16 Nov 2010 23:34:09 +0100 Subject: Raw Unicode docstring In-Reply-To: References: Message-ID: <4CE306E1.7050000@web.de> On 16.11.2010 22:56, Bo?tjan Mejak wrote: > Hello, > > how does one write a raw unicode docstring? If I have backslashes in > the docstring, I must tuck an 'r' in front of it, like this: > r"""This is a raw docstring.""" > > If I have foreign letters in the docstring, I must tuck a 'u' in front > of it, like this: > u"""This is a Unicode docstring.""" > > What if I have foreign characters *and* backslashes in my docstring? > How to write the docstring then? > ru"""My raw unicode docstring.""" > or > ur"""My unicode docstring.""" > > Please answer my question, although it may sound like a noobish one. Thanks. One of Python's main strength is it's brilliant interactive mode, where you can easily try things out (Hint: Try ipython for an even better interactive experience) 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. >>> ru"Schei?t\nderB?r\nim Wald?" File "", line 1 ru"Schei?t\nderB?r\nim Wald?" ^ SyntaxError: invalid syntax >>> ur"Schei?t\nderB?r\nim Wald?" u'Schei\xdft\\nderB\xe4r\\nim Wald?' >>> Looks like ur"" works fine. From drsalists at gmail.com Tue Nov 16 18:40:50 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 16 Nov 2010 15:40:50 -0800 Subject: Is Unladen Swallow dead? In-Reply-To: <2e1a4d02-1e8a-4d31-95da-f33aaf90578c@30g2000yql.googlegroups.com> References: <2e1a4d02-1e8a-4d31-95da-f33aaf90578c@30g2000yql.googlegroups.com> Message-ID: I'm not a contributor to the U-S project, but I have been monitoring alternative python implementations' progress some, and seem to be adding something to pypy all of a sudden. I think unladen swallow has produced performance improvements, and they are likely to be merged into cpython 3.3. However, the improvements are not quite as substantial as were hoped for, and pypy seems to be getting some steam behind it. With pypy looking likely to even be able to provide source-level compatibility with C extension modules, the need for unladen swallow is perhaps somewhat lessened. At the outset, the U-S people looked at pypy and got the impression it was years from being a fast alternative to cpython for production code, but it sounds like pypy's coming along nicely now. Then again, the pypy people don't seem to feel that C extensions are going to perform that well in pypy (it sounds like an issue of initialization overhead and infeasibility of JIT compiling C extensions). I've been testing some of my own code in cpython 2.6, cpython 3.1 and pypy 1.3; with this specific program pypy seems to be about 4x faster than cpython 2.6, and almost that much faster than cpython 3.1 (I have the same - albeit unfinished - code running on all 3). This code is I/O intensive and somewhat math-intensive. On Tue, Nov 16, 2010 at 2:30 PM, laspi wrote: > There has been little or no activity at all in this project in the > last months, and the last comments on their mailing list seem to > conrfim that it's future is uncertain. > It's also very strange the lack of updates, news or discussions, > specially considering that the merging plan has been approved. Or it > hasn't? > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From fuglyducky at gmail.com Tue Nov 16 18:48:33 2010 From: fuglyducky at gmail.com (fuglyducky) Date: Tue, 16 Nov 2010 15:48:33 -0800 (PST) Subject: SQLite3 and lastrowid References: <2d87112c-e776-41ea-838a-5e165e478052@e20g2000vbn.googlegroups.com> <713377d1-b9e2-4da1-a56a-c4f042f6e3e4@g2g2000vbe.googlegroups.com> <2ec7c0d8-4105-452d-88e3-01050c4c567f@v12g2000vbh.googlegroups.com> Message-ID: <3c741e3a-ba55-4401-9cf0-9fc1e730dc4e@g2g2000vbe.googlegroups.com> On Nov 16, 1:52?pm, Ian wrote: > On Nov 16, 2:08?pm, fuglyducky wrote: > > > db_connect = sqlite3.connect('test.db') > > cursor = db_connect.cursor() > > > print(cursor.lastrowid) > > At this point you haven't executed a query yet, so there is no > meaningful value that cursor.lastrowid can take. > > > # Choose random index from DB - need to understand lastrowid > > #row_count = cursor.lastrowid > > #random_row = random.randrange(0, row_count) > > This is wrong. ?The lastrowid is not the number of rows in the table. > It's the row-id of the row that was inserted (if any) by the last > query executed by the cursor. ?In the case of sqlite3, I think the row- > id is just the primary key if it's an integer (but in general the row- > id is database-dependent), so you *might* be able to get away with it > if you always let it autoincrement when inserting, never delete any > rows, and never change their primary keys. ?But it's unreliable and > only available immediately after an insert, so don't do it that way. > > The proper way to get the number of rows is to use the COUNT aggregate > function, e.g., "SELECT COUNT(*) FROM TABLE1", which will return a > single row with a single column containing the number of rows in > table1. > > Cheers, > Ian Ahhh...great...thanks for the info! I'll do the row count then!!! From research at johnohagan.com Tue Nov 16 19:33:19 2010 From: research at johnohagan.com (John O'Hagan) Date: Wed, 17 Nov 2010 00:33:19 +0000 Subject: argparse subparser problem In-Reply-To: References: Message-ID: <201011170033.20177.research@johnohagan.com> On Tue, 16 Nov 2010, Neal Becker wrote: > I want to have subparsers, but I also want to be able to say: > > myprogram --version > and get the version # > > --------------------------- [...] AFAIK, it is not possible ATM to have optional subparsers with argparse: http://code.google.com/p/argparse/issues/detail?id=47 To do something like what you want, I've done my own pre-parsing of the command-line to separate out sub-options, and then sent them to multiple separate top-level ArgumentParser instances. Regards, john From bill at kingofmarketing.net Tue Nov 16 19:45:26 2010 From: bill at kingofmarketing.net (Bill Fishbaugher) Date: Tue, 16 Nov 2010 18:45:26 -0600 Subject: I have a question about JavaFit Message-ID: Hello, I was searching online to find more info about JavaFit and I came across your information. Can you tell me, are you still involved with JavaFit? If you are, how are things going for you? Please let me know. Sincerely, Bill From deets at web.de Tue Nov 16 19:54:16 2010 From: deets at web.de (Diez B. Roggisch) Date: Wed, 17 Nov 2010 01:54:16 +0100 Subject: QT window closes immediately References: <141ef269-de70-4ce1-b4ff-bfb0f58ee9d2@k14g2000pre.googlegroups.com> Message-ID: Martin Caum writes: > I am attempting to open a window on mouse activity which works, but > the window fails to stay open. > I set it to terminate when the escape key is pressed even when the > program is not currently selected. This works fine. Originally I had > it create the window only with a right click, but when I noticed the > window closed immediately I set it to any mouse activity for easier > debugging. My script is as follows: > [code] > import pythoncom, pyHook > import sys > import win32api > from PyQt4 import QtGui, QtCore > > class WindowObject(QtGui.QWidget): > def __init__(self, parent=None): > QtGui.QWidget.__init__(self, parent) > self.setWindowTitle('Window') > self.resize(50, 250) > > def OnKeyboardEvent(event): > if event.KeyID == 27: > win32api.PostQuitMessage() > return 1 > > def OnMouseEvent(event): > x = event.Position[0] > y = event.Position[1] > createWindow(x, y) > return 1 > > def createWindow(x, y): > menu = WindowObject() > menu.move(x, y) > menu.show() > > hm = pyHook.HookManager() > hm.MouseAll = OnMouseEvent > hm.KeyDown = OnKeyboardEvent > hm.HookMouse() > hm.HookKeyboard() > > app = QtGui.QApplication(sys.argv) > pythoncom.PumpMessages()[/code] > I'm fairly certain that this is due to my lack of understanding in the > PumpMessages command and the HookManager. Any advice? 1) Keep a reference to your window-object. I can only guess (PyQt not being a regular topic when hacking for me.. .sadly), but GC can interfere with these kind of things. 2) what is the win32 stuff about? Qt should abstract from that. 3) if in doubt, as on the PyQt mailing list. Diez From news1234 at free.fr Tue Nov 16 20:19:53 2010 From: news1234 at free.fr (News123) Date: Wed, 17 Nov 2010 02:19:53 +0100 Subject: QT window closes immediately In-Reply-To: <141ef269-de70-4ce1-b4ff-bfb0f58ee9d2@k14g2000pre.googlegroups.com> References: <141ef269-de70-4ce1-b4ff-bfb0f58ee9d2@k14g2000pre.googlegroups.com> Message-ID: <4ce32db9$0$22875$426a74cc@news.free.fr> On 11/15/2010 02:04 AM, Martin Caum wrote: > I am attempting to open a window on mouse activity which works, but > the window fails to stay open. > I set it to terminate when the escape key is pressed even when the > program is not currently selected. This works fine. Originally I had > it create the window only with a right click, but when I noticed the > window closed immediately I set it to any mouse activity for easier > debugging. My script is as follows: > [code] > import pythoncom, pyHook > import sys > import win32api > from PyQt4 import QtGui, QtCore > > class WindowObject(QtGui.QWidget): > def __init__(self, parent=None): > QtGui.QWidget.__init__(self, parent) > self.setWindowTitle('Window') > self.resize(50, 250) > > def OnKeyboardEvent(event): > if event.KeyID == 27: > win32api.PostQuitMessage() > return 1 > > def OnMouseEvent(event): > x = event.Position[0] > y = event.Position[1] > createWindow(x, y) > return 1 > > def createWindow(x, y): > menu = WindowObject() > menu.move(x, y) > menu.show() > > hm = pyHook.HookManager() > hm.MouseAll = OnMouseEvent > hm.KeyDown = OnKeyboardEvent > hm.HookMouse() > hm.HookKeyboard() > > app = QtGui.QApplication(sys.argv) > pythoncom.PumpMessages()[/code] > I'm fairly certain that this is due to my lack of understanding in the > PumpMessages command and the HookManager. Any advice? Shouldn't every QT application have an event loop. I would have expecte a call to app._exec() as you need already pumpMessages() fro the COM interface, I assume you had to use the threading or multiprocessing module as well. From bnbowman at gmail.com Tue Nov 16 20:37:10 2010 From: bnbowman at gmail.com (Brett Bowman) Date: Tue, 16 Nov 2010 17:37:10 -0800 Subject: Cannot Remove File: Device or resource busy Message-ID: I'm spawning a subprocess to fix some formating errors with a library of PDFs with pdftk: try: sp = subprocess.Popen('pdftk.exe "%s" output %s' % (pdfFile, outputFile)) sp.wait() del sp except Exception, e: return "Unable to open file: %s with error: %s" % (pdfFile, str(e)) And then I test the result: try: pdf_handle = open(outputFile, "rb") pdf_pypdf = PdfFileReader(pdf_handle) del pdf_pypdf del pdf_handle except Exception, e: return "Unable to open file: %s with error: %s" % (outputFile, str(e)) Both of which appear to work. But when I try to delete the original pdfFile, I get an error message saying that the file is still in use. if I use: sp = subprocess.Popen('rm "%s"' % pdfFile) sp.wait() I get the message - the standard error message from rm and if I use: cwd = os.getcwd() os.remove(cwd + "\\" + pdfFile) I get "WindowsError: [Error 32]" saying much the same thing. What am I missing? Any suggestions would be appreciated. Details: Python 2.6 Windows XP Sincerely, Brett Bowman -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Tue Nov 16 21:25:34 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 17 Nov 2010 02:25:34 +0000 Subject: Cannot Remove File: Device or resource busy In-Reply-To: References: Message-ID: <4CE33D1E.2040108@mrabarnett.plus.com> On 17/11/2010 01:37, Brett Bowman wrote: > I'm spawning a subprocess to fix some formating errors with a library of > PDFs with pdftk: > try: > sp = subprocess.Popen('pdftk.exe "%s" output %s' % (pdfFile, > outputFile)) > sp.wait() > del sp > except Exception, e: > return "Unable to open file: %s with error: %s" % (pdfFile, str(e)) > > And then I test the result: > try: > pdf_handle = open(outputFile, "rb") > pdf_pypdf = PdfFileReader(pdf_handle) > del pdf_pypdf > del pdf_handle > except Exception, e: > return "Unable to open file: %s with error: %s" % (outputFile, > str(e)) > > Both of which appear to work. But when I try to delete the original > pdfFile, I get an error message saying that the file is still in use. > > if I use: > sp = subprocess.Popen('rm "%s"' % pdfFile) > sp.wait() > I get the message - the standard error message from rm > > and if I use: > cwd = os.getcwd() > os.remove(cwd + "\\" + pdfFile) > I get "WindowsError: [Error 32]" saying much the same thing. > > What am I missing? Any suggestions would be appreciated. > > Details: > Python 2.6 > Windows XP > Try Process Explorer, available from Microsoft at: http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx and use Find. That will tell you what has it open. From rbd at hawaii.edu Tue Nov 16 21:33:52 2010 From: rbd at hawaii.edu (Roger Davis) Date: Tue, 16 Nov 2010 18:33:52 -0800 (PST) Subject: strange subprocess behavior when calling ps Message-ID: <55f26d5c-aba9-4892-9e2c-1caa9988e7fe@v23g2000vbi.googlegroups.com> Hi all, I have encountered a strange problem with some code I am writing to search the system process list for certain running processes. I am using subprocess.Popen() to call '/bin/ps -e'. When I save my code to the file pid.py (whose first line is #!/usr/bin/python) and run it with the command % ./pid.py it works perfectly fine, retrieving lines from my pipe to the /bin/ps output which look exactly as if I had typed the command '/bin/ps -e' myself into a shell window. Here is a sample line from that output: 1891 ttys000 0:00.12 -tcsh Now for the weird part -- when I run this code using the command % python pid.py I get entirely different output. It only prints out a very few processes instead of the entire table, and each line also has lots of environment variable values displayed. Here is the line from that output which corresponds to the line immediately above: 1891 s000 S+ 0:00.12 -tcsh PATH=/usr/bin:/bin:/usr/sbin:/sbin TMPDIR=/var/folders/3e/3e-TyTQIG-aOa4x37pbTbk++-H6/-Tmp-/ SHELL=/bin/ tcsh HOME=/Users/hmrgsoft USER=hmrgsoft LOGNAME=hmrgsoft DISPLAY=/tmp/ launch-c1YZNr/org.x:0 SSH_AUTH_SOCK=/tmp/launch-AJ9xbl/Listeners Apple_PubSub_Socket_Render=/tmp/launch-BsRx5Y/Render COMMAND_MODE=unix2003 __CF_USER_TEXT_ENCODING=0x532:0:0 TERM_PROGRAM=Apple_Terminal TERM_PROGRAM_VERSION=273 LANG=en_US.UTF-8 TERM=xterm-color It's like it's calling up an entirely different ps, or passing it different command arguments. In both cases, however, I am explicitly calling /bin/ps with the same -e argument, and there appear to be no other ps commands on my system, neither do I appear to have any ps builtin command in any shell. I am running 2.6.6 under MacOS 10.6.4 on a MacBook Pro Intel. I have appended the code below. I am running both commands directly in a Terminal window running tcsh. Can anyone explain this? Thanks! Roger Davis ##### code follows #!/usr/bin/python import sys import subprocess def main(): psargs= ["/bin/ps", "-e"] try: ps= subprocess.Popen(psargs, stdout=subprocess.PIPE, close_fds=True) psout= ps.communicate()[0] pslines= psout.splitlines() for line in pslines: print "%s" % line except KeyboardInterrupt: print "Keyboard interrupt received -- terminating." sys.stdout.flush() sys.exit(-1) except: print "%s: unexpected error in generation of system process list" % prognm sys.stdout.flush() sys.exit(-1) main() From prologic at shortcircuit.net.au Tue Nov 16 21:44:57 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 17 Nov 2010 12:44:57 +1000 Subject: strange subprocess behavior when calling ps In-Reply-To: <55f26d5c-aba9-4892-9e2c-1caa9988e7fe@v23g2000vbi.googlegroups.com> References: <55f26d5c-aba9-4892-9e2c-1caa9988e7fe@v23g2000vbi.googlegroups.com> Message-ID: On Wed, Nov 17, 2010 at 12:33 PM, Roger Davis wrote: > Hi all, > > I have encountered a strange problem with some code I am writing to > search the system process list for certain running processes. I am > using subprocess.Popen() to call '/bin/ps -e'. When I save my code to > the file pid.py (whose first line is #!/usr/bin/python) and run it > with the command > > % ./pid.py > > it works perfectly fine, retrieving lines from my pipe to the /bin/ps > output which look exactly as if I had typed the command '/bin/ps -e' > myself into a shell window. Here is a sample line from that output: > > ?1891 ttys000 ? ?0:00.12 -tcsh > > Now for the weird part -- when I run this code using the command > > % python pid.py > > I get entirely different output. It only prints out a very few > processes instead of the entire table, and each line also has lots of > environment variable values displayed. Here is the line from that > output which corresponds to the line immediately above: > > ?1891 s000 ?S+ ? ? 0:00.12 -tcsh PATH=/usr/bin:/bin:/usr/sbin:/sbin > TMPDIR=/var/folders/3e/3e-TyTQIG-aOa4x37pbTbk++-H6/-Tmp-/ SHELL=/bin/ > tcsh HOME=/Users/hmrgsoft USER=hmrgsoft LOGNAME=hmrgsoft DISPLAY=/tmp/ > launch-c1YZNr/org.x:0 SSH_AUTH_SOCK=/tmp/launch-AJ9xbl/Listeners > Apple_PubSub_Socket_Render=/tmp/launch-BsRx5Y/Render > COMMAND_MODE=unix2003 __CF_USER_TEXT_ENCODING=0x532:0:0 > TERM_PROGRAM=Apple_Terminal TERM_PROGRAM_VERSION=273 LANG=en_US.UTF-8 > TERM=xterm-color > > It's like it's calling up an entirely different ps, or passing it > different command arguments. In both cases, however, I am explicitly > calling /bin/ps with the same -e argument, and there appear to be no > other ps commands on my system, neither do I appear to have any ps > builtin command in any shell. > > I am running 2.6.6 under MacOS 10.6.4 on a MacBook Pro Intel. I have > appended the code below. I am running both commands directly in a > Terminal window running tcsh. > > Can anyone explain this? Thanks! > > Roger Davis > > ##### code follows > > #!/usr/bin/python > import sys > import subprocess > > def main(): > > ? ? ? ?psargs= ["/bin/ps", "-e"] > ? ? ? ?try: > ? ? ? ? ? ? ? ?ps= subprocess.Popen(psargs, stdout=subprocess.PIPE, close_fds=True) > ? ? ? ? ? ? ? ?psout= ps.communicate()[0] > ? ? ? ? ? ? ? ?pslines= psout.splitlines() > ? ? ? ? ? ? ? ?for line in pslines: > ? ? ? ? ? ? ? ? ? ? ? ?print "%s" % line > ? ? ? ?except KeyboardInterrupt: > ? ? ? ? ? ? ? ?print "Keyboard interrupt received -- terminating." > ? ? ? ? ? ? ? ?sys.stdout.flush() > ? ? ? ? ? ? ? ?sys.exit(-1) > ? ? ? ?except: > ? ? ? ? ? ? ? ?print "%s: unexpected error in generation of system process list" % > prognm > ? ? ? ? ? ? ? ?sys.stdout.flush() > ? ? ? ? ? ? ? ?sys.exit(-1) > > main() Roger, why not use the nicely written and documented psutil module ? http://pypi.python.org/pypi/psutil/0.2.0 http://code.google.com/p/psutil/ cheers James -- -- James Mills -- -- "Problems are solved by method" From crebert at ucsd.edu Tue Nov 16 22:13:16 2010 From: crebert at ucsd.edu (Chris Rebert) Date: Tue, 16 Nov 2010 19:13:16 -0800 Subject: strange subprocess behavior when calling ps In-Reply-To: <55f26d5c-aba9-4892-9e2c-1caa9988e7fe@v23g2000vbi.googlegroups.com> References: <55f26d5c-aba9-4892-9e2c-1caa9988e7fe@v23g2000vbi.googlegroups.com> Message-ID: On Tue, Nov 16, 2010 at 6:33 PM, Roger Davis wrote: > Hi all, > > I have encountered a strange problem with some code I am writing to > search the system process list for certain running processes. I am > using subprocess.Popen() to call '/bin/ps -e'. When I save my code to > the file pid.py (whose first line is #!/usr/bin/python) and run it > with the command > > % ./pid.py > > it works perfectly fine, retrieving lines from my pipe to the /bin/ps > output which look exactly as if I had typed the command '/bin/ps -e' > myself into a shell window. Here is a sample line from that output: > > ?1891 ttys000 ? ?0:00.12 -tcsh > > Now for the weird part -- when I run this code using the command > > % python pid.py > > I get entirely different output. It only prints out a very few > processes instead of the entire table, and each line also has lots of > environment variable values displayed. > It's like it's calling up an entirely different ps, or passing it > different command arguments. In both cases, however, I am explicitly > calling /bin/ps with the same -e argument, and there appear to be no > other ps commands on my system, neither do I appear to have any ps > builtin command in any shell. > > I am running 2.6.6 under MacOS 10.6.4 on a MacBook Pro Intel. I have > appended the code below. I am running both commands directly in a > Terminal window running tcsh. > > Can anyone explain this? Thanks! > ##### code follows > > #!/usr/bin/python Have you checked whether those commands are running under the same Python? What output do you get from tcsh for the following?: which python python -V /usr/bin/python -V ls -l /usr/bin/python Also, did you upgrade your system Python or something? I'm running Mac OS 10.6.5 and the built-in /usr/bin/python is v2.6.1, so I find the implied claim that your /usr/bin/python is v2.6.6 to be rather bizarre. I am unable to reproduce your problem with either my v2.6.1 system Python or my v2.6.6 Python from Fink. Cheers, Chris -- http://blog.rebertia.com From rbd at hawaii.edu Tue Nov 16 23:05:17 2010 From: rbd at hawaii.edu (Roger Davis) Date: Tue, 16 Nov 2010 20:05:17 -0800 (PST) Subject: strange subprocess behavior when calling ps References: <55f26d5c-aba9-4892-9e2c-1caa9988e7fe@v23g2000vbi.googlegroups.com> Message-ID: <7bca95cc-5213-4a54-960c-de12d1e308fe@a30g2000vbt.googlegroups.com> Thanks, Chris, you're at least on the right track. I did upgrade from python.org and the python in my shell PATH is /Library/Frameworks/ Python.framework/Versions/2.6/bin/python: % python Python 2.6.6 (r266:84374, Aug 31 2010, 11:00:51) [GCC 4.0.1 (Apple Inc. build 5493)] on darwin /usr/bin/python is the Apple-distributed 2.6.1: % /usr/bin/python Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29) [GCC 4.2.1 (Apple Inc. build 5646)] on darwin This still doesn't explain the behavior to me, however. In either case python is supposed to be forking a child process with a specific executable (/bin/ps) and a specific argument list (-e) and reading that command's output lines. Why should those output lines be different whether I use 2.6.1, 2.6.6 or 8.9.10 for that matter? In fact, this makes the problem that much worse -- the newer python 2.6.6 is the one producing the incorrect output. Changing the first line of the script to read #!/Library/Frameworks/Python.framework/Versions/2.6/bin/python does not help, it still prints out the wrong output whether I do % ./pid.py or % /Library/Frameworks/Python.framework/Versions/2.6/bin/python ./ pid.py Any ideas? Thanks! From hansyin at gmail.com Tue Nov 16 23:14:51 2010 From: hansyin at gmail.com (Hans) Date: Tue, 16 Nov 2010 20:14:51 -0800 (PST) Subject: how to use socket to get packet which destination ip is not local? References: <21df438f-9869-4818-bc59-752702e2a203@j1g2000vbl.googlegroups.com> Message-ID: <52c44aed-6810-40da-82fe-a5d3da800c7d@w18g2000vbe.googlegroups.com> On Nov 16, 12:57?pm, MRAB wrote: > On 16/11/2010 20:38, Hans wrote: > > > Hi, > > > Maybe it's a very simple question. I'm trying to write a dhcpclient > > code with python. The dhcpclient does not have ip address at the very > > beginning, it sends out dhcpdiscover and then server sends back > > dhcpoffer. the dhcpoffer will use assigned ip as destination ip, but > > that ip is not client's local ip yet. How can I make my socket to > > receive that packet? > > > I tried socket bind to 0.0.0.0, but it only binds to any local ip, not > > any ip which may not be local. therefore the socket cannot get that > > dhcp offer packet even I can use wireshark to see that packet did come > > to this pc. > > > How to solve it? Thanks in advance. > > Have you read this: > > ? ? ?http://en.wikipedia.org/wiki/Dynamic_Host_Configuration_Protocol Thanks for the response. Yes, I read it. it tells me how dhcp works. But I cannot find answer for my question, dhcp response may be unicast or broadcast depends on the flag in request. my question is how to use socket to read that response. In my test, sniffer already shows server sends back an offer response(unicast in my case), but because the dst- ip in response is not local ip, then my socket cannot read it. Can you help? thank you very much! From rbd at hawaii.edu Tue Nov 16 23:15:16 2010 From: rbd at hawaii.edu (Roger Davis) Date: Tue, 16 Nov 2010 20:15:16 -0800 (PST) Subject: strange subprocess behavior when calling ps References: <55f26d5c-aba9-4892-9e2c-1caa9988e7fe@v23g2000vbi.googlegroups.com> <7bca95cc-5213-4a54-960c-de12d1e308fe@a30g2000vbt.googlegroups.com> Message-ID: Hi James, Thanks for the pointer to psutil. I actually did look around on python.org before coding this up to see if there was such a package available but there is not, at least not where I'm looking -- on the other hand, I can't find my car keys most of the time. I would really like to restrict my code dependencies to the standard Python distribution (if there actually is such a thing, I'm new to the language). Of course, that's assuming that I can actually get my code to work in that fashion. If I can't get to the bottom of this issue and figure out why my existing code does not work I will investigate psutil further. Thanks! Roger From nad at acm.org Tue Nov 16 23:18:02 2010 From: nad at acm.org (Ned Deily) Date: Tue, 16 Nov 2010 20:18:02 -0800 Subject: strange subprocess behavior when calling ps References: <55f26d5c-aba9-4892-9e2c-1caa9988e7fe@v23g2000vbi.googlegroups.com> Message-ID: In article <55f26d5c-aba9-4892-9e2c-1caa9988e7fe at v23g2000vbi.googlegroups.com>, Roger Davis wrote: > I have encountered a strange problem with some code I am writing to > search the system process list for certain running processes. I am > using subprocess.Popen() to call '/bin/ps -e'. When I save my code to > the file pid.py (whose first line is #!/usr/bin/python) and run it > with the command > > % ./pid.py > > it works perfectly fine, retrieving lines from my pipe to the /bin/ps > output which look exactly as if I had typed the command '/bin/ps -e' > myself into a shell window. Here is a sample line from that output: > > 1891 ttys000 0:00.12 -tcsh > > Now for the weird part -- when I run this code using the command > > % python pid.py > > I get entirely different output. It only prints out a very few > processes instead of the entire table, and each line also has lots of > environment variable values displayed. Here is the line from that > output which corresponds to the line immediately above: > > 1891 s000 S+ 0:00.12 -tcsh PATH=/usr/bin:/bin:/usr/sbin:/sbin > TMPDIR=/var/folders/3e/3e-TyTQIG-aOa4x37pbTbk++-H6/-Tmp-/ SHELL=/bin/ > tcsh HOME=/Users/hmrgsoft USER=hmrgsoft LOGNAME=hmrgsoft DISPLAY=/tmp/ > launch-c1YZNr/org.x:0 SSH_AUTH_SOCK=/tmp/launch-AJ9xbl/Listeners > Apple_PubSub_Socket_Render=/tmp/launch-BsRx5Y/Render > COMMAND_MODE=unix2003 __CF_USER_TEXT_ENCODING=0x532:0:0 > TERM_PROGRAM=Apple_Terminal TERM_PROGRAM_VERSION=273 LANG=en_US.UTF-8 > TERM=xterm-color > > It's like it's calling up an entirely different ps, or passing it > different command arguments. In both cases, however, I am explicitly > calling /bin/ps with the same -e argument, and there appear to be no > other ps commands on my system, neither do I appear to have any ps > builtin command in any shell. > > I am running 2.6.6 under MacOS 10.6.4 on a MacBook Pro Intel. I have > appended the code below. I am running both commands directly in a > Terminal window running tcsh. See "man compat". What you are seeing is the difference between ps(1) output in "legacy" mode, attempting to duplicate the old, non-POSIX behavior from 10.3 days, or "unix2003" mode. Terminal login sessions are normally automatically started with the COMMAND_MODE environment variable set: $ echo $COMMAND_MODE unix2003 Adding an "env={"COMMAND_MODE": "unix2003"}" argument to your subprocess Popen call should do the trick. -- Ned Deily, nad at acm.org From midnacc at gmail.com Tue Nov 16 23:36:06 2010 From: midnacc at gmail.com (c_c) Date: Wed, 17 Nov 2010 12:36:06 +0800 Subject: how to use socket to get packet which destination ip is not local? In-Reply-To: <4CE2F053.7010509@mrabarnett.plus.com> References: <21df438f-9869-4818-bc59-752702e2a203@j1g2000vbl.googlegroups.com> <4CE2F053.7010509@mrabarnett.plus.com> Message-ID: libpcap On Wed, Nov 17, 2010 at 4:57 AM, MRAB wrote: > On 16/11/2010 20:38, Hans wrote: > >> Hi, >> >> Maybe it's a very simple question. I'm trying to write a dhcpclient >> code with python. The dhcpclient does not have ip address at the very >> beginning, it sends out dhcpdiscover and then server sends back >> dhcpoffer. the dhcpoffer will use assigned ip as destination ip, but >> that ip is not client's local ip yet. How can I make my socket to >> receive that packet? >> >> I tried socket bind to 0.0.0.0, but it only binds to any local ip, not >> any ip which may not be local. therefore the socket cannot get that >> dhcp offer packet even I can use wireshark to see that packet did come >> to this pc. >> >> How to solve it? Thanks in advance. >> >> Have you read this: > > http://en.wikipedia.org/wiki/Dynamic_Host_Configuration_Protocol > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From sjmachin at lexicon.net Wed Nov 17 00:14:33 2010 From: sjmachin at lexicon.net (John Machin) Date: Tue, 16 Nov 2010 21:14:33 -0800 (PST) Subject: Raw Unicode docstring References: Message-ID: <4a1c5b98-8bf2-4525-b26f-a30b3dcbd6e1@e20g2000vbn.googlegroups.com> On Nov 17, 9:34?am, Alexander Kapps wrote: > ?>>> ur"Schei?t\nderB?r\nim Wald?" Nicht ohne eine Genehmigung von der Umwelt Erhaltung Abteilung. From justpark78 at gmail.com Wed Nov 17 00:26:19 2010 From: justpark78 at gmail.com (justin) Date: Tue, 16 Nov 2010 21:26:19 -0800 (PST) Subject: How can I catch segmentation fault in python? Message-ID: Hi all, I am calling a program written in C inside Python using ctypes, and it seems that sometimes the program in C crashes while it's being used in Python. Even under the circumstances, I want to get the Python program going by handling the segmentation fault. I've already searched the Internet, but couldn't get the right answer to catch them. Could any of you please let me know how to deal with this and catch the segmentation fault in Python? Thanks, Justin. From drsalists at gmail.com Wed Nov 17 00:59:27 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 16 Nov 2010 21:59:27 -0800 Subject: remote server and effective uid In-Reply-To: References: Message-ID: On Tue, Nov 16, 2010 at 9:37 AM, Tim Arnold wrote: > "Tim Harig" wrote in message > news:ibs8h9$jmq$1 at speranza.aioe.org... > > On 2010-11-15, Tim Arnold wrote: > >> On Nov 15, 10:41 am, Tim Harig wrote: > >>> On 2010-11-15, Tim Arnold wrote: > >>> > >>> > How can I enable the server process to write into the client's > >>> > directories? > >>> > If I change the inetd service to run as 'root', I guess that would > >>> > work, but then the client couldn't remove the files put there after > >>> > the request. > >>> > >>> Python provides os.setuid() and os.seteuid() which wrap the system > >>> functions. See you systems man pages for these functions for more > >>> information. > >> > >> Thanks -- that was a lot easier than I thought it was going to be. > >> pass the client's uid in the message to the server like so > >> > >> argstring, local_dir, uid = message.split(':') > >> os.seteuid(int(uid)) > > > > I am not sure exactly what you are doing; but, I would advise great > > caution as messing this up could easily open your system to exploitation. > > Be very sure that you know what you are doing. > > I can see how that looks dangerous, but I think it's okay. I have inetd > listening on a port and whatever it receives, it passes on to that line > above "argstring, local_dir, uid message.split(':'). The argstring is > parsed using 'argparse' the resulting list of args is passed to a Python > class that can only do work for a specific set of args. I can't think of a > way someone could pass in an evil argstring that could do anything but > fail. > > Thanks for your reply, and if you still think it's dangerous please let me > know. > What if an attacker passes something other than their own uid across a socket to your inetd-launched process? EG, what if they pass a 0 (for root) instead of getuid()? It might be fine in your case, but in many cases, it's a problem. -------------- next part -------------- An HTML attachment was scrubbed... URL: From swapnil.st at gmail.com Wed Nov 17 01:15:14 2010 From: swapnil.st at gmail.com (swapnil) Date: Tue, 16 Nov 2010 22:15:14 -0800 (PST) Subject: How can I catch segmentation fault in python? References: Message-ID: On Nov 17, 10:26?am, justin wrote: > Hi all, > > I am calling a program written in C inside Python using ctypes, > and it seems that sometimes the program in C crashes while it's being > used in Python. > Even under the circumstances, I want to get the Python program going > by handling the segmentation fault. > > I've already searched the Internet, but couldn't get the right answer > to catch them. > Could any of you please let me know how to deal with this and catch > the segmentation fault in Python? > > Thanks, > Justin. Segmentation fault isn't exactly an exception that you can catch. It usually means something has gone horribly wrong, like dereferencing invalid pointer, trying to access memory out of process's range. Since if you run out of memory Python simply raises MemoryError exception, which you can catch. So that is not the case for segmentation fault. From swapnil.st at gmail.com Wed Nov 17 01:24:51 2010 From: swapnil.st at gmail.com (swapnil) Date: Tue, 16 Nov 2010 22:24:51 -0800 (PST) Subject: Is Unladen Swallow dead? References: <2e1a4d02-1e8a-4d31-95da-f33aaf90578c@30g2000yql.googlegroups.com> Message-ID: <8b0b044c-34a8-4747-b68f-f4cb56882f6f@e26g2000vbz.googlegroups.com> On Nov 17, 3:30?am, laspi wrote: > There has been little or no activity at all in this project in the > last months, and the last comments on their mailing list seem to > conrfim that it's future is uncertain. > It's also very strange the lack of updates, news or discussions, > specially considering that the merging plan has been approved. Or it > hasn't? AFAIK, the merging plan was approved by Guido early this year. I guess Google is expecting the community to drive the project from here on. That was the whole idea for merging it to mainline. From my last conversation with Collin, they are targeting Python 3.3 From rbd at hawaii.edu Wed Nov 17 01:47:09 2010 From: rbd at hawaii.edu (Roger Davis) Date: Tue, 16 Nov 2010 22:47:09 -0800 (PST) Subject: strange subprocess behavior when calling ps References: <55f26d5c-aba9-4892-9e2c-1caa9988e7fe@v23g2000vbi.googlegroups.com> Message-ID: <61496525-afab-4d19-a7e9-e61fb46e03ef@n30g2000vbb.googlegroups.com> Thanks, Ned! That really helps to explain what is going on. Now, just a couple more questions and I think I will know all I need to know. First, I *still* don't quite understand why this happens with my 2.6.6 interpreter but not my 2.6.1, and why another of the respondents to this thread (Chris) could not duplicate this problem with his own 2.6.6 environment. Is there something defective with my Python environment having to do with the 2.6.6 upgrade I installed directly from python.org? (Chris used Fink, apparently.) If so, how can I clean it up? I do have an easier time believing that this is a mangled installation issue now that the problem has essentially been reduced to the handling of an environment variable which I can well imagine could be easily garbled somewhere in a version mismatch scenario. Second, I do need to make this work on multiple platforms, primarily Linux in addition to the Mac but also with a potential variety of Python releases on both MacOS and Linux. I'm not sure if Linux will object to this COMMAND_MODE business, I guess I'll just have to try and see what happens. Any thoughts on that? Finally, to split hairs a bit concerning your suggested solution, I have a question about the additional env={'COMMAND_MODE': 'unix2003'} argument. This works for me, but my reading of the subprocess documentation leads me to believe that this will actually wipe out the entire environment that would otherwise be inherited from the parent and replace it with that single setting. I don't think this has any ill effects here with regard to ps, at least none I can detect at the moment, but wouldn't a perhaps safer solution be to do os.environ['COMMAND_MODE']= 'unix2003' prior to the Popen() to instead augment/correct the existing environment which will then later be inherited by the child, assuming no explicit env= optional argument is used? This also works for me, and I think I'm more inclined to go this route unless you can think of a good reason not to do so. Thanks very much for your help! From clp2 at rebertia.com Wed Nov 17 02:01:05 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 16 Nov 2010 23:01:05 -0800 Subject: How can I catch segmentation fault in python? In-Reply-To: References: Message-ID: On Tue, Nov 16, 2010 at 9:26 PM, justin wrote: > Hi all, > > I am calling a program written in C inside Python using ctypes, > and it seems that sometimes the program in C crashes while it's being > used in Python. > Even under the circumstances, I want to get the Python program going > by handling the segmentation fault. > > I've already searched the Internet, but couldn't get the right answer > to catch them. > Could any of you please let me know how to deal with this and catch > the segmentation fault in Python? You can't "catch" it. It's not a mere Exception, it's a fatal error that effectively crashes the interpreter itself. At best, you could perhaps use the `multiprocessing` or `subprocess` modules to segregate the part of your program that uses ctypes and then try and recover when you detect that the subprocess has crashed. Instead, if possible, fix the C program and/or ensure that there's not an error in your ctypes interfacing code. Cheers, Chris -- http://blog.rebertia.com From nagle at animats.com Wed Nov 17 02:02:11 2010 From: nagle at animats.com (John Nagle) Date: Tue, 16 Nov 2010 23:02:11 -0800 Subject: Is Unladen Swallow dead? In-Reply-To: <8b0b044c-34a8-4747-b68f-f4cb56882f6f@e26g2000vbz.googlegroups.com> References: <2e1a4d02-1e8a-4d31-95da-f33aaf90578c@30g2000yql.googlegroups.com> <8b0b044c-34a8-4747-b68f-f4cb56882f6f@e26g2000vbz.googlegroups.com> Message-ID: <4ce37e01$0$1666$742ec2ed@news.sonic.net> On 11/16/2010 10:24 PM, swapnil wrote: > On Nov 17, 3:30 am, laspi wrote: >> There has been little or no activity at all in this project in the >> last months, and the last comments on their mailing list seem to >> conrfim that it's future is uncertain. >> It's also very strange the lack of updates, news or discussions, >> specially considering that the merging plan has been approved. Or it >> hasn't? > > AFAIK, the merging plan was approved by Guido early this year. I guess > Google is expecting the community to drive the project from here on. > That was the whole idea for merging it to mainline. From my last > conversation with Collin, they are targeting Python 3.3 I think it's dead. They're a year behind on quarterly releases. The last release was Q3 2009. The project failed to achieve its stated goal of a 5x speedup. Not even close. More like 1.5x (http://www.python.org/dev/peps/pep-3146) The Google blog at "http://groups.google.com/group/unladen-swallow/browse_thread/thread/f2011129c4414d04" says, as of November 8, 2010: "Jeffrey and I have been pulled on to other projects of higher importance to Google. Unfortunately, no-one from the Python open-source community has been interested in picking up the merger work, and since none of the original team is still full-time on the project, it's moving very slowly. Finishing up the merger into the py3k-jit branch is a high priority for me this quarter, but what happens then is an open question." So Google has pulled the plug on Unladen Swallow. It looks like they underestimated the difficulty of speeding up the CPython model. The performance improvement achieved was so low that cluttering up CPython with a JIT system and LLVM probably is a lose. John Nagle From nagle at animats.com Wed Nov 17 02:06:01 2010 From: nagle at animats.com (John Nagle) Date: Tue, 16 Nov 2010 23:06:01 -0800 Subject: How can I catch segmentation fault in python? In-Reply-To: References: Message-ID: <4ce37ee7$0$1666$742ec2ed@news.sonic.net> On 11/16/2010 10:15 PM, swapnil wrote: > On Nov 17, 10:26 am, justin wrote: >> Hi all, >> >> I am calling a program written in C inside Python using ctypes, >> and it seems that sometimes the program in C crashes while it's being >> used in Python. >> Even under the circumstances, I want to get the Python program going >> by handling the segmentation fault. >> >> I've already searched the Internet, but couldn't get the right answer >> to catch them. >> Could any of you please let me know how to deal with this and catch >> the segmentation fault in Python? >> >> Thanks, >> Justin. > > Segmentation fault isn't exactly an exception that you can catch. It > usually means something has gone horribly wrong, like dereferencing > invalid pointer, trying to access memory out of process's range. Since > if you run out of memory Python simply raises MemoryError exception, > which you can catch. So that is not the case for segmentation fault. Either fix the program so it doesn't crash,or run the offending module and the C code in a subprocess. John Nagle From matlab.dude at mbnet.fi Wed Nov 17 03:04:11 2010 From: matlab.dude at mbnet.fi (MATLABdude) Date: Wed, 17 Nov 2010 00:04:11 -0800 (PST) Subject: MATLAB to Python? Message-ID: <74f276c3-38a4-4df0-af39-7b1f2a81472e@c39g2000yqi.googlegroups.com> Hi! Can you, please, try to help me with Python? I try to convert a MATLAB program to Python. Here are the MATLAB codes: http://pastebin.com/eJetYizv http://pastebin.com/0eXTVfyN Here is my Python code: http://pastebin.com/jCPdLHx7 What is wrong with my Python code? The program doesn't produce quite the same lambdas as the MATLAB program does. My code probably has lots of errors because I'm just learning the basics about Python. Thanks for all the help! From bnbowman at gmail.com Wed Nov 17 03:16:29 2010 From: bnbowman at gmail.com (Brett Bowman) Date: Wed, 17 Nov 2010 00:16:29 -0800 Subject: Cannot Remove File: Device or resource busy In-Reply-To: References: Message-ID: Good ideas, but I've tried them already: -No del command, or replacing it with a set-to-null, neither solve my file access problem. -PdfFileReader has no close() function, and causes an error. Weird, but true. -pdf_handle.close() on the other hand, fails to solve the problem. On Tue, Nov 16, 2010 at 11:25 PM, Dennis Lee Bieber wrote: > On Tue, 16 Nov 2010 17:37:10 -0800, Brett Bowman > declaimed the following in gmane.comp.python.general: > > > > > And then I test the result: > > try: > > pdf_handle = open(outputFile, "rb") > > pdf_pypdf = PdfFileReader(pdf_handle) > > del pdf_pypdf > > del pdf_handle > > except Exception, e: > > return "Unable to open file: %s with error: %s" % (outputFile, > > str(e)) > > > You seem enamored of "del", which is something I've only used for > special purposes, and even then rarely -- binding a null object to the > name is just as effective for most uses. > > While the common Python does garbage collect objects when the > reference count goes to zero, there is no real guarantee of this. > > I'd replace that > del pdf_handle > whit > pdf_handle.close() > > -- > Wulfraed Dennis Lee Bieber AF6VN > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Wed Nov 17 03:38:49 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 17 Nov 2010 09:38:49 +0100 Subject: MATLAB to Python? References: <74f276c3-38a4-4df0-af39-7b1f2a81472e@c39g2000yqi.googlegroups.com> Message-ID: MATLABdude wrote: > Can you, please, try to help me with Python? I try to convert a MATLAB > program to Python. > > Here are the MATLAB codes: > http://pastebin.com/eJetYizv > http://pastebin.com/0eXTVfyN > > Here is my Python code: > http://pastebin.com/jCPdLHx7 That is too much code for me, in a problem domain I'm not familiar with. > What is wrong with my Python code? The program doesn't produce quite > the same lambdas as the MATLAB program does. My code probably has lots > of errors because I'm just learning the basics about Python. If no-one fixes it for you I suggest that you break the code in smaller functions (at most ten lines) that you can test separately. That should make it easier to spot the misbehaving parts of your calculation. If you come back then with one of these, the matlab equivalent, sample input and expected output a significantly larger number of people can and may be willing to help. Peter From pavlovevidence at gmail.com Wed Nov 17 03:46:47 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 17 Nov 2010 00:46:47 -0800 (PST) Subject: MATLAB to Python? References: <74f276c3-38a4-4df0-af39-7b1f2a81472e@c39g2000yqi.googlegroups.com> Message-ID: <9c9107ca-2727-4389-b939-edae6a2e03ca@26g2000yqv.googlegroups.com> On Nov 17, 12:04?am, MATLABdude wrote: > Hi! > > Can you, please, try to help me with Python? I try to convert a MATLAB > program to Python. > > Here are the MATLAB codes:http://pastebin.com/eJetYizvhttp://pastebin.com/0eXTVfyN > > Here is my Python code:http://pastebin.com/jCPdLHx7 > > What is wrong with my Python code? The program doesn't produce quite > the same lambdas as the MATLAB program does. My code probably has lots > of errors because I'm just learning the basics about Python. > > Thanks for all the help! I was about to say it was a pretty good looking piece of code, and probably if anything is wrong it's a typo somewhere. But then my eye caught something at the last minute: xx = range(-kappa, h, kappa+1) Looks like you're treating range arguments as (start,step,stop), same order as in Matlab. In Python it's (start,stop,step), so you should be using this: xx = range(-kappa,kappa+1,h) Other than that, you might jus have to pepper your scripts with prints and disps to catch the exact point where the discrepancy occurs. Carl Banks From arnodel at gmail.com Wed Nov 17 03:53:20 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Wed, 17 Nov 2010 08:53:20 +0000 Subject: MATLAB to Python? References: <74f276c3-38a4-4df0-af39-7b1f2a81472e@c39g2000yqi.googlegroups.com> Message-ID: <878w0s2uwv.fsf@gmail.com> MATLABdude writes: > Hi! > > Can you, please, try to help me with Python? I try to convert a MATLAB > program to Python. > > Here are the MATLAB codes: > http://pastebin.com/eJetYizv > http://pastebin.com/0eXTVfyN > > Here is my Python code: > http://pastebin.com/jCPdLHx7 > > What is wrong with my Python code? The program doesn't produce quite > the same lambdas as the MATLAB program does. My code probably has lots > of errors because I'm just learning the basics about Python. > > Thanks for all the help! I don't understand what's going on in your code, but line 81 you have: xx = range(-kappa, h, kappa+1) I guess that the step is supposed to be h, so you should write: xx = range(-kappa, kappa+1, h) -- Arnaud From swapnil.st at gmail.com Wed Nov 17 03:53:56 2010 From: swapnil.st at gmail.com (swapnil) Date: Wed, 17 Nov 2010 00:53:56 -0800 (PST) Subject: import site fails - Please Help References: <8kcaapF44bU1@mid.dfncis.de> Message-ID: <8c8b2bf7-9fd8-466c-9306-06aa56448772@j2g2000yqf.googlegroups.com> On Nov 15, 1:46?pm, Helmut Jarausch wrote: > Hi, I'm completely puzzled and I hope someone > can shed some light on it. > > After cloning a running system, booting the new machine from a rescue CD, > chroot to the new root partition, I get the following strange error > from python upon startup > > python -v> import site failed > > .... > st= os.stat(path) > stat() argument 1 must be encoded string without NULL bytes, not str > > So, what's broken? How can I get out what 'path' contained at this > moment? > > Many thanks for your help, > Helmut. Perhaps its not able to locate the libraries. Try using http://docs.python.org/using/cmdline.html#envvar-PYTHONPATH and http://docs.python.org/using/cmdline.html#envvar-PYTHONHOME From nad at acm.org Wed Nov 17 04:19:09 2010 From: nad at acm.org (Ned Deily) Date: Wed, 17 Nov 2010 01:19:09 -0800 Subject: strange subprocess behavior when calling ps References: <55f26d5c-aba9-4892-9e2c-1caa9988e7fe@v23g2000vbi.googlegroups.com> <61496525-afab-4d19-a7e9-e61fb46e03ef@n30g2000vbb.googlegroups.com> Message-ID: In article <61496525-afab-4d19-a7e9-e61fb46e03ef at n30g2000vbb.googlegroups.com>, Roger Davis wrote: > First, I *still* don't quite understand why this happens with my 2.6.6 > interpreter but not my 2.6.1, and why another of the respondents to > this thread (Chris) could not duplicate this problem with his own > 2.6.6 environment. Is there something defective with my Python > environment having to do with the 2.6.6 upgrade I installed directly > from python.org? (Chris used Fink, apparently.) If so, how can I clean > it up? I do have an easier time believing that this is a mangled > installation issue now that the problem has essentially been reduced > to the handling of an environment variable which I can well imagine > could be easily garbled somewhere in a version mismatch scenario. Interesting. It appears that OS X 10.6 takes into account the deployment target of the executable. Prior to 2.7, all recent python.org installed Pythons have been built with MACOSX_DEPLOYMENT_TARGET = 10.3, allowing the same build to work on all releases from 10.3.9 on. So, when you launch a script with the python.org interpreter (with a 10.3 deployment target), OS X automatically sets COMMAND_MODE to 'legacy'. The Apple-supplied Python 2.6.1 in OS X 10.6 is built with a deployment target of 10.6, so it gets a COMMAND_MODE of 'unix2003'. And, as far as I can tell, OS X 10.5 honors COMMAND_MODE but does not automatically set it or tailor it like 10.6 does. Live and learn! > Second, I do need to make this work on multiple platforms, primarily > Linux in addition to the Mac but also with a potential variety of > Python releases on both MacOS and Linux. I'm not sure if Linux will > object to this COMMAND_MODE business, I guess I'll just have to try > and see what happens. Any thoughts on that? As far as I know, COMMAND_MODE has no special meaning on other platforms so it should be ignored anywhere but on OS X. If you want to be extra cautious, you could test for 'sys.platform == 'darwin'. > Finally, to split hairs a bit concerning your suggested solution, I > have a question about the additional env={'COMMAND_MODE': 'unix2003'} > argument. This works for me, but my reading of the subprocess > documentation leads me to believe that this will actually wipe out the > entire environment that would otherwise be inherited from the parent > and replace it with that single setting. I don't think this has any > ill effects here with regard to ps, at least none I can detect at the > moment, but wouldn't a perhaps safer solution be to do > > os.environ['COMMAND_MODE']= 'unix2003' > > prior to the Popen() to instead augment/correct the existing > environment which will then later be inherited by the child, assuming > no explicit env= optional argument is used? This also works for me, > and I think I'm more inclined to go this route unless you can think of > a good reason not to do so. That analysis seems correct. So it comes down to whether there are any environment variable settings the user could make that would positively or negatively affect the operation of your script. -- Ned Deily, nad at acm.org From swapnil.st at gmail.com Wed Nov 17 04:39:08 2010 From: swapnil.st at gmail.com (swapnil) Date: Wed, 17 Nov 2010 01:39:08 -0800 (PST) Subject: In-process interpreters Message-ID: <7091619d-f6a4-4cd7-bd0d-4d10a1daf03f@y37g2000vbl.googlegroups.com> Hi, Please refer my post on Python-ideas list http://mail.python.org/pipermail/python-ideas/2010-November/008666.html and provide feedback if any. From jeanmichel at sequans.com Wed Nov 17 05:34:42 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 17 Nov 2010 11:34:42 +0100 Subject: strange subprocess behavior when calling ps In-Reply-To: <55f26d5c-aba9-4892-9e2c-1caa9988e7fe@v23g2000vbi.googlegroups.com> References: <55f26d5c-aba9-4892-9e2c-1caa9988e7fe@v23g2000vbi.googlegroups.com> Message-ID: <4CE3AFC2.4020209@sequans.com> Roger Davis wrote: > Hi all, > [snip] > Roger Davis > > ##### code follows > > #!/usr/bin/python > import sys > import subprocess > > def main(): > > psargs= ["/bin/ps", "-e"] > try: > ps= subprocess.Popen(psargs, stdout=subprocess.PIPE, close_fds=True) > psout= ps.communicate()[0] > pslines= psout.splitlines() > for line in pslines: > print "%s" % line > except KeyboardInterrupt: > print "Keyboard interrupt received -- terminating." > sys.stdout.flush() > sys.exit(-1) > except: > print "%s: unexpected error in generation of system process list" % > prognm > sys.stdout.flush() > sys.exit(-1) > > main() > Completely off topic but I think the try clause could be rewritten that way: try: ps= subprocess.Popen(psargs, stdout=subprocess.PIPE, close_fds=True) psout= ps.communicate()[0] pslines= psout.splitlines() for line in pslines: print "%s" % line except KeyboardInterrupt: print "Keyboard interrupt received -- terminating." finally: sys.stdout.flush() Don't use bare except clause, you're masking syntax errors for instance, which will be flagged as 'unexpected error in generation ...". In a more general manner, if something unexpected happens it's better to just let the exception raise uncought. If you want to handle some errors, meaning you're kindof expecting them then add a explicit clause (like you did with KeyboardInterrupt). JM PS : "except Exception :" will catch most of the exceptions (all inheriting from that class). It's better than using a bare "except :" clause. (Exception won't catch SyntaxError) From lipun4u at gmail.com Wed Nov 17 06:48:39 2010 From: lipun4u at gmail.com (asit) Date: Wed, 17 Nov 2010 03:48:39 -0800 (PST) Subject: urllib2 error Message-ID: <17eed640-7375-4b15-b124-5e012af33e79@y23g2000yqd.googlegroups.com> I have this piece of code import urllib2 proc_url = 'http://www.nse-india.com/content/historical/EQUITIES/2001/ JAN/cm01JAN2001bhav.csv.zip' print 'processing....', proc_url req = urllib2.Request(proc_url) res = urllib2.urlopen(req) when i run this...following error comes Traceback (most recent call last): File "C:/Python26/reqnse.py", line 92, in res = urllib2.urlopen(req) File "C:\Python26\lib\urllib2.py", line 124, in urlopen return _opener.open(url, data, timeout) File "C:\Python26\lib\urllib2.py", line 395, in open response = meth(req, response) File "C:\Python26\lib\urllib2.py", line 508, in http_response 'http', request, response, code, msg, hdrs) File "C:\Python26\lib\urllib2.py", line 433, in error return self._call_chain(*args) File "C:\Python26\lib\urllib2.py", line 367, in _call_chain result = func(*args) File "C:\Python26\lib\urllib2.py", line 516, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) HTTPError: HTTP Error 403: Forbidden would anyone help me why ?? From kushal.kumaran+python at gmail.com Wed Nov 17 07:01:26 2010 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Wed, 17 Nov 2010 17:31:26 +0530 Subject: urllib2 error In-Reply-To: <17eed640-7375-4b15-b124-5e012af33e79@y23g2000yqd.googlegroups.com> References: <17eed640-7375-4b15-b124-5e012af33e79@y23g2000yqd.googlegroups.com> Message-ID: On Wed, Nov 17, 2010 at 5:18 PM, asit wrote: > I have this piece of code > > import urllib2 > > proc_url = 'http://www.nse-india.com/content/historical/EQUITIES/2001/ > JAN/cm01JAN2001bhav.csv.zip' > print 'processing....', proc_url > req = urllib2.Request(proc_url) > res = urllib2.urlopen(req) > > when i run this...following error comes > > Traceback (most recent call last): > > HTTPError: HTTP Error 403: Forbidden > The web server is probably trying to forbid downloads using automated tools by examining the user agent header (downloading using wget also fails, for example). You can work around that by setting the User-Agent header to the same value as a browser that works. The urllib2 documentation covers how to set headers in requests. -- regards, kushal From lipun4u at gmail.com Wed Nov 17 07:18:53 2010 From: lipun4u at gmail.com (asit dhal) Date: Wed, 17 Nov 2010 17:48:53 +0530 Subject: urllib2 error In-Reply-To: References: <17eed640-7375-4b15-b124-5e012af33e79@y23g2000yqd.googlegroups.com> Message-ID: On Wed, Nov 17, 2010 at 5:31 PM, Kushal Kumaran wrote: > On Wed, Nov 17, 2010 at 5:18 PM, asit wrote: >> I have this piece of code >> >> import urllib2 >> >> proc_url = 'http://www.nse-india.com/content/historical/EQUITIES/2001/ >> JAN/cm01JAN2001bhav.csv.zip' >> print 'processing....', proc_url >> req = urllib2.Request(proc_url) >> res = urllib2.urlopen(req) >> >> when i run this...following error comes >> >> Traceback (most recent call last): >> >> HTTPError: HTTP Error 403: Forbidden >> > > The web server is probably trying to forbid downloads using automated > tools by examining the user agent header (downloading using wget also > fails, for example). ?You can work around that by setting the > User-Agent header to the same value as a browser that works. > > The urllib2 documentation covers how to set headers in requests. > > -- > regards, > kushal > -- Regards, Asit Kumar Dhal TCS, Mumbai blog: http://asitdhal.blogspot.com/ Thanx...it worked From lists at cheimes.de Wed Nov 17 08:17:24 2010 From: lists at cheimes.de (Christian Heimes) Date: Wed, 17 Nov 2010 14:17:24 +0100 Subject: Cannot Remove File: Device or resource busy In-Reply-To: References: Message-ID: Am 17.11.2010 09:16, schrieb Brett Bowman: > Good ideas, but I've tried them already: > -No del command, or replacing it with a set-to-null, neither solve my file > access problem. > -PdfFileReader has no close() function, and causes an error. Weird, but > true. > -pdf_handle.close() on the other hand, fails to solve the problem. You have to close the file explicitly, for example with a proper with block. with open(outputFile, "rb") as fh: pdf_pypdf = PdfFileReader(fh) # process the PDF file here Christian From nadiasvertex at gmail.com Wed Nov 17 09:01:58 2010 From: nadiasvertex at gmail.com (Christopher) Date: Wed, 17 Nov 2010 06:01:58 -0800 (PST) Subject: Some syntactic sugar proposals References: Message-ID: > ? Of course we can write it as > ? ? t = foo() if pred(foo()) else default_value > but here we have 2 foo() calls instead of one. Why can't we write just > something like this: > ? ? t = foo() if pred(it) else default_value > where "it" means "foo() value"? i don't like magic names. what about: t = foo() as v if pred(v) else default_value From justpark78 at gmail.com Wed Nov 17 09:28:36 2010 From: justpark78 at gmail.com (justin) Date: Wed, 17 Nov 2010 06:28:36 -0800 (PST) Subject: How can I catch segmentation fault in python? References: <4ce37ee7$0$1666$742ec2ed@news.sonic.net> Message-ID: <45ccbf6c-5cc7-422e-88ba-bb4615fe31d5@k5g2000vbn.googlegroups.com> On Nov 17, 1:06?am, John Nagle wrote: > On 11/16/2010 10:15 PM, swapnil wrote: > > > > > > > On Nov 17, 10:26 am, justin ?wrote: > >> Hi all, > > >> I am calling a program written in C inside Python using ctypes, > >> and it seems that sometimes the program in C crashes while it's being > >> used in Python. > >> Even under the circumstances, I want to get the Python program going > >> by handling the segmentation fault. > > >> I've already searched the Internet, but couldn't get the right answer > >> to catch them. > >> Could any of you please let me know how to deal with this and catch > >> the segmentation fault in Python? > > >> Thanks, > >> Justin. > > > Segmentation fault isn't exactly an exception that you can catch. It > > usually means something has gone horribly wrong, like dereferencing > > invalid pointer, trying to access memory out of process's range. Since > > if you run out of memory Python simply raises MemoryError exception, > > which you can catch. So that is not the case for segmentation fault. > > ? ? Either fix the program so it doesn't crash,or run the offending > module and the C code in a subprocess. > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? John Nagle Thanks guys for this fast replies, Turns out that it is a fact that segmentation fault is not what I can deal with in programming level. But the problem is that the code is not mine, and it takes over a day for me to get the point where the segmentation fault occurred. Plus, it seems that the point is not deterministic Still, I think I should at least try to figure out exactly at which point the segmentation fault occurs, and think where to go from there according to your kind advice. Again many thanks, Justin. From rde at audaxis.com Wed Nov 17 09:44:49 2010 From: rde at audaxis.com (Romaric DEFAUX) Date: Wed, 17 Nov 2010 15:44:49 +0100 Subject: Pickle in a POST/GET request give EOFError In-Reply-To: <4CE2B599.7050504@audaxis.com> References: <4CE2B599.7050504@audaxis.com> Message-ID: <4CE3EA61.2090707@audaxis.com> Le 16/11/2010 17:47, Romaric DEFAUX a ?crit : > Hi everybody ! > > First time I write to this mailing list :) > I started writing in python last week, that's probably why I can't > understand the following problem... > > > I create a list called web_site_list. > This list contain dictionaries called web_site. > And some values in this dictionaries are list too. > > I do that in a function and I return this : > return pickle.dumps(web_site_list) > > This is working fine :) > > If I do : > print "%s" % pickle.loads(system.get_web_site_list()) > > I've got the right stuffs. For example it returns : > [{'documentroot_size': '120', 'servername': '---default---', 'client': > 'undefined', 'documentroot': '/var/www/', 'client_contact': > 'undefined', 'serveralias': []}] > > I send this to a web service. I send it like that : > #I put it in params > def system_updateweb_site(server, login, password): > params = {} > params['login'] = login > params['password'] = password > params['action'] = 'updateweb_site' > params['servername'] = get_servername() > params['hosted_web_site'] = get_web_site_list() > return call_system_ws(server, params) > > #Here's how I send it (I tried in GET and POST) > def call_system_ws(host, params): > query_string = urllib.urlencode(params) > #GET > # f = urllib.urlopen("http://%s/ws?%s" % (host, query_string)) > #POST > f = urllib.urlopen("http://%s/ws" % (host), query_string) > result = f.readline().strip() > if result == 'ERROR': > msg = f.readline().strip() > return (False, msg) > return (True, result) > > > On the server side : > if action == 'updateweb_site': > if not (fields.has_key('servername') > and fields.has_key('hosted_web_site')): > raise WSError('missing > parameter : servername or hosted_web_site') > log ('ERROR : missing > parameter : servername or hosted_web_site') > else: > > servername=g.db.escape_string(fields['servername']) > > hosted_web_site=g.db.escape_string(fields['hosted_web_site']) > output = > systemserver.updateweb_site(cursor, servername, hosted_web_site) > > In systemserver.py : > def updateweb_site(cursor, host, hosted_web_site): > web_site_list = pickle.loads(hosted_web_site) > return "%s" % (web_site_list) > > I catch this error :* > > *: > > args = () > message = '' > > Why ? > > If I just print hosted_web_site, I get this on my web page : > > (lp0\n(dp1\nS\'documentroot_size\'\np2\nS\'120\'\np3\nsS\'servername\'\np4\nS\'default\'\np5\nsS\'client\'\np6\nS\'undefined\'\np7\nsS\'documentroot\'\np8\nS\'/var/www/\'\np9\nsS\'client_contact\'\np10\ng7\nsS\'serveralias\'\np11\n(lp12\nsa. > > > It's the "pickled view" of > [{'documentroot_size': '120', 'servername': '---default---', 'client': > 'undefined', 'documentroot': '/var/www/', 'client_contact': > 'undefined', 'serveralias': []}] > > Can someone help me please ? I spend my afternoon to google to try to > find a solution... > > > Thanks in advance !!! > > Romaric Defaux > After entirely rewrite my code to not use Web service but socket (a real client/server program) I finally found the problem... And it's not linked to the POST or GET method... It's because of that : g.db.escape_string(fields['hosted_web_site']) (escape_string is the function in MySQLdb library) It escapes the simple quote of the pickled object, and break it... It's good to know, NEVER escape a pickled object :) Romaric Defaux -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 5361 bytes Desc: S/MIME Cryptographic Signature URL: From mwilson at the-wire.com Wed Nov 17 10:18:51 2010 From: mwilson at the-wire.com (Mel) Date: Wed, 17 Nov 2010 10:18:51 -0500 Subject: Some syntactic sugar proposals References: Message-ID: Christopher wrote: >> ? Of course we can write it as >> t = foo() if pred(foo()) else default_value >> but here we have 2 foo() calls instead of one. Why can't we write just >> something like this: >> t = foo() if pred(it) else default_value >> where "it" means "foo() value"? > > i don't like magic names. what about: > > t = foo() as v if pred(v) else default_value !! so: assignment inside an expression. Mel. From usenot at geekmail.INVALID Wed Nov 17 10:24:33 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Wed, 17 Nov 2010 10:24:33 -0500 Subject: Some syntactic sugar proposals References: Message-ID: <20101117102433.28926da4@geekmail.INVALID> On Wed, 17 Nov 2010 10:18:51 -0500 Mel wrote: > Christopher wrote: > > >> ? Of course we can write it as > >> t = foo() if pred(foo()) else default_value > >> but here we have 2 foo() calls instead of one. Why can't we write > >> just something like this: > >> t = foo() if pred(it) else default_value > >> where "it" means "foo() value"? > > > > i don't like magic names. what about: > > > > t = foo() as v if pred(v) else default_value > > !! so: assignment inside an expression. > I like the idea of having an "as ... if" construct, though. :) /W -- To reach me via email, replace INVALID with the country code of my home country. But if you spam me, I'll be one sour Kraut. From wolfgang at rohdewald.de Wed Nov 17 10:37:45 2010 From: wolfgang at rohdewald.de (Wolfgang Rohdewald) Date: Wed, 17 Nov 2010 16:37:45 +0100 Subject: How can I catch segmentation fault in python? In-Reply-To: <45ccbf6c-5cc7-422e-88ba-bb4615fe31d5@k5g2000vbn.googlegroups.com> References: <4ce37ee7$0$1666$742ec2ed@news.sonic.net> <45ccbf6c-5cc7-422e-88ba-bb4615fe31d5@k5g2000vbn.googlegroups.com> Message-ID: <201011171637.45610.wolfgang@rohdewald.de> On Mittwoch 17 November 2010, justin wrote: > But the problem is that the code is not mine, and it takes > over a day for me to get the point where the segmentation > fault occurred. Plus, it seems that the point is not > deterministic > > Still, I think I should at least try to figure out exactly at > which point the segmentation fault occurs, and think where to > go from there according to your kind advice. try valgrind -- mit freundlichen Gr?ssen with my best greetings Wolfgang Rohdewald dipl. Informatik Ing. ETH Rohdewald Systemberatung Karauschenstieg 4 D 21640 Horneburg Tel.: 04163 826 819 Fax: 04163 826 828 Internet: http://www.rohdewald.de From jldunn2000 at gmail.com Wed Nov 17 10:41:54 2010 From: jldunn2000 at gmail.com (loial) Date: Wed, 17 Nov 2010 07:41:54 -0800 (PST) Subject: Oracle jdbc sql select for update in python Message-ID: <8048ca20-914a-4ea4-8f9f-7c516cea962a@z19g2000yqb.googlegroups.com> I want to do a select from...for update in python, update the selected row and then commit; However cannot seem to get it to work...the update statement seems to be waiting because the row is locked. Presumably oracle thinks the update is another transaction. How can I get this to work? What statements do I need to ensure Oracle treats this as one transaction? From wolfgang at rohdewald.de Wed Nov 17 10:47:16 2010 From: wolfgang at rohdewald.de (Wolfgang Rohdewald) Date: Wed, 17 Nov 2010 16:47:16 +0100 Subject: How can I catch segmentation fault in python? In-Reply-To: <201011171637.45610.wolfgang@rohdewald.de> References: <45ccbf6c-5cc7-422e-88ba-bb4615fe31d5@k5g2000vbn.googlegroups.com> <201011171637.45610.wolfgang@rohdewald.de> Message-ID: <201011171647.16464.wolfgang@rohdewald.de> On Mittwoch 17 November 2010, Wolfgang Rohdewald wrote: > On Mittwoch 17 November 2010, justin wrote: > > But the problem is that the code is not mine, and it takes > > over a day for me to get the point where the segmentation > > fault occurred. Plus, it seems that the point is not > > deterministic > > > > Still, I think I should at least try to figure out exactly > > at which point the segmentation fault occurs, and think > > where to go from there according to your kind advice. > > try valgrind hit the send button too fast... even if the segmentation fault only happens after a long time valgrind might find problems much sooner, and fixing them might remove the segmentation fault. -- Wolfgang From justpark78 at gmail.com Wed Nov 17 11:00:28 2010 From: justpark78 at gmail.com (justin) Date: Wed, 17 Nov 2010 08:00:28 -0800 (PST) Subject: How can I catch segmentation fault in python? References: <45ccbf6c-5cc7-422e-88ba-bb4615fe31d5@k5g2000vbn.googlegroups.com> <201011171637.45610.wolfgang@rohdewald.de> Message-ID: Just checked what is valgrind, sounds promising. Let me try that. Thanks a lot, Justin. On Nov 17, 9:47?am, Wolfgang Rohdewald wrote: > On Mittwoch 17 November 2010, Wolfgang Rohdewald wrote: > > > On Mittwoch 17 November 2010, justin wrote: > > > But the problem is that the code is not mine, and it takes > > > over a day for me to get the point where the segmentation > > > fault occurred. Plus, it seems that the point is not > > > deterministic > > > > Still, I think I should at least try to figure out exactly > > > at which point the segmentation fault occurs, and think > > > where to go from there according to your kind advice. > > > try valgrind > > hit the send button too fast... > > even if the segmentation fault only happens after a long time > valgrind might find problems much sooner, and fixing them > might remove the segmentation fault. > > -- > Wolfgang From mdw at distorted.org.uk Wed Nov 17 11:08:04 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 17 Nov 2010 16:08:04 +0000 Subject: how to use socket to get packet which destination ip is not local? References: <21df438f-9869-4818-bc59-752702e2a203@j1g2000vbl.googlegroups.com> Message-ID: <87r5ekexwb.fsf.mdw@metalzone.distorted.org.uk> Hans writes: > I tried socket bind to 0.0.0.0, but it only binds to any local ip, not > any ip which may not be local. therefore the socket cannot get that > dhcp offer packet even I can use wireshark to see that packet did come > to this pc. You must use a raw socket for this. Raw sockets are fiddly, not very portable, and require privilege. Sorry. -- [mdw] From virbento at gmail.com Wed Nov 17 11:20:34 2010 From: virbento at gmail.com (=?ISO-8859-1?Q?Virg=EDlio_Bento?=) Date: Wed, 17 Nov 2010 16:20:34 +0000 Subject: pySerial Vs 2 Serial Ports Message-ID: Dear all, I Have two modules communicating by Bluetooth. Basically I want to rotate two vector using the accelerometer data. I read the data using pyserial like this: ############################################### ser1 = serial.Serial(port='COM6',baudrate=19200) if ser1.isOpen(): print "Comm 1 is open" ser2 = serial.Serial(port='COM43',baudrate=19200) if ser2.isOpen(): print "Comm 2 is open" ############################################### And then retirieve the raw data in a while loop like this: while True: line1 = ser2.readline() line2 = ser1.readline() ... My problem is the following... when I read from only one module, all goes smooth, but when i try to read from the two modules, the second one that i read retrieves the data with a huge delay. In terms of debug, I tried to run two independent scripts, each one opening and retrieving data from one COM port and there isn't any delay, only when i read the two COM's in the same script i get the delay. Any Clue? Thanks in Advance. Best Regards. -------------- next part -------------- An HTML attachment was scrubbed... URL: From mdw at distorted.org.uk Wed Nov 17 11:31:40 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 17 Nov 2010 16:31:40 +0000 Subject: Some syntactic sugar proposals References: Message-ID: <87mxp7gbdf.fsf.mdw@metalzone.distorted.org.uk> Christopher writes: > i don't like magic names. what about: > > t = foo() as v if pred(v) else default_value This is an improvement on `it'; anaphorics are useful in their place, but they don't seem to fit well with Python. But I don't think that's the big problem with this proposal. The real problem is that it completely changes the evaluation rule for the conditional expression. (The evaluation rule is already pretty screwy: Python is consistently left-to-right -- except here.) Evaluating a conditional expression starts in the middle, by evaluating the condition. If the condition is true, then it evaluates the consequent (to the left); otherwise it evaluates the alternative (to the right). Screwy, but tolerable. The proposal is to evaluate the /consequent/, stash it somewhere, evaluate the condition, and then either output the consequent which we evaluated earlier or the alternative which we must evaluate now. Of course, the implementation must be able to tell which of these evaluation rules to apply. The marker to look for is either `it' (original anaphoric proposal -- this is the real reason why `it' should be a reserved word: its presence radically alters the evaluation rule, so it ought to be a clear syntactic marker) or `as' (as suggested above). Elsewhere in the language, `as' is pretty consistent in what it does: it provides a name for a thing described elsewhere (a `with' context object, or an imported thing) -- but nothing else. It certainly doesn't suggest a change in the way anything else is evaluated. 1/x if x != 0 else None works for any numeric x; it'd be really surprising to me if 1/x as hunoz if x != 0 else None didn't. -1 on this one. -- [mdw] From rbotting at csusb.edu Wed Nov 17 11:32:16 2010 From: rbotting at csusb.edu (RJB) Date: Wed, 17 Nov 2010 08:32:16 -0800 (PST) Subject: Raw Unicode docstring References: Message-ID: <731150d2-929e-4683-8241-fe001e5aaeed@k13g2000vbq.googlegroups.com> On Nov 16, 1:56?pm, Bo?tjan Mejak wrote: > Hello, > > how does one write a raw unicode docstring? If I have backslashes in > the docstring, I must tuck an 'r' in front of it, like this: > r"""This is a raw docstring.""" > > If I have foreign letters in the docstring, I must tuck a 'u' in front > of it, like this: > u"""This is a Unicode docstring.""" > > What if I have foreign characters *and* backslashes in my docstring? > How to write the docstring then? > ru"""My raw unicode docstring.""" > or > ur"""My unicode docstring.""" > > Please answer my question, although it may sound like a noobish one. Thanks. Check out http://cse.csusb.edu/dick/samples/python.syntax.html#stringprefix which lists alternate string prefixes. Does any bodyy know if "ur" and "UR" mean the same thing? From ktenney at gmail.com Wed Nov 17 12:46:11 2010 From: ktenney at gmail.com (Kent Tenney) Date: Wed, 17 Nov 2010 11:46:11 -0600 Subject: Sqlalchemy access to Firefox's places.sqlite Message-ID: Howdy, Lazy, wanting to access Firefox's places.sqlite via Sqlalchemy. How about this: Sqlite Manager -> places.sqlite -> Export Wizard -> table name sqlite_manager this produces file sqlite_manager.sql which looks like: BEGIN TRANSACTION; INSERT INTO "sqlite_master" VALUES('table','moz_bookmarks','moz_bookmarks', 2,'CREATE TABLE moz_bookmarks (id INTEGER PRIMARY KEY,type INTEGER, fk INTEGER DEFAULT NULL, parent INTEGER, position INTEGER, title LONGVARCHAR, keyword_id INTEGER, folder_type TEXT, dateAdded INTEGER, lastModified INTEGER)'); INSERT INTO "sqlite_master" VALUES('index','moz_bookmarks_itemindex', 'moz_bookmarks',3,'CREATE INDEX moz_bookmarks_itemindex ON moz_bookmarks (fk, type)'); ... Is there an easy way to go from this sql to Sqlalchemy code? Thanks, Kent From steve at holdenweb.com Wed Nov 17 13:07:42 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 17 Nov 2010 13:07:42 -0500 Subject: Raw Unicode docstring In-Reply-To: <731150d2-929e-4683-8241-fe001e5aaeed@k13g2000vbq.googlegroups.com> References: <731150d2-929e-4683-8241-fe001e5aaeed@k13g2000vbq.googlegroups.com> Message-ID: On 11/17/2010 11:32 AM, RJB wrote: > On Nov 16, 1:56 pm, Bo?tjan Mejak wrote: >> Hello, >> >> how does one write a raw unicode docstring? If I have backslashes in >> the docstring, I must tuck an 'r' in front of it, like this: >> r"""This is a raw docstring.""" >> >> If I have foreign letters in the docstring, I must tuck a 'u' in front >> of it, like this: >> u"""This is a Unicode docstring.""" >> >> What if I have foreign characters *and* backslashes in my docstring? >> How to write the docstring then? >> ru"""My raw unicode docstring.""" >> or >> ur"""My unicode docstring.""" >> >> Please answer my question, although it may sound like a noobish one. Thanks. > > Check out > http://cse.csusb.edu/dick/samples/python.syntax.html#stringprefix > which lists alternate string prefixes. > > Does any bodyy know if "ur" and "UR" mean the same thing? Yes, they do. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From python at mrabarnett.plus.com Wed Nov 17 13:15:28 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 17 Nov 2010 18:15:28 +0000 Subject: Raw Unicode docstring In-Reply-To: <731150d2-929e-4683-8241-fe001e5aaeed@k13g2000vbq.googlegroups.com> References: <731150d2-929e-4683-8241-fe001e5aaeed@k13g2000vbq.googlegroups.com> Message-ID: <4CE41BC0.2060702@mrabarnett.plus.com> On 17/11/2010 16:32, RJB wrote: > On Nov 16, 1:56 pm, Bo?tjan Mejak wrote: >> Hello, >> >> how does one write a raw unicode docstring? If I have backslashes in >> the docstring, I must tuck an 'r' in front of it, like this: >> r"""This is a raw docstring.""" >> >> If I have foreign letters in the docstring, I must tuck a 'u' in front >> of it, like this: >> u"""This is a Unicode docstring.""" >> >> What if I have foreign characters *and* backslashes in my docstring? >> How to write the docstring then? >> ru"""My raw unicode docstring.""" >> or >> ur"""My unicode docstring.""" >> >> Please answer my question, although it may sound like a noobish one. Thanks. > > Check out > http://cse.csusb.edu/dick/samples/python.syntax.html#stringprefix > which lists alternate string prefixes. > > Does any bodyy know if "ur" and "UR" mean the same thing? I've tried them. It looks like the answer is yes. From awilliam at whitemice.org Wed Nov 17 13:16:43 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Wed, 17 Nov 2010 13:16:43 -0500 Subject: Pickle in a POST/GET request give EOFError In-Reply-To: <4CE3EA61.2090707@audaxis.com> References: <4CE2B599.7050504@audaxis.com> <4CE3EA61.2090707@audaxis.com> Message-ID: <1290017803.3934.0.camel@linux-yu4c.site> On Wed, 2010-11-17 at 15:44 +0100, Romaric DEFAUX wrote: > After entirely rewrite my code to not use Web service but socket (a real > client/server program) I finally found the problem... And it's not > linked to the POST or GET method... > It's because of that : > g.db.escape_string(fields['hosted_web_site']) > (escape_string is the function in MySQLdb library) > It escapes the simple quote of the pickled object, and break it... > It's good to know, NEVER escape a pickled object :) If you are worried about the binary-ness of the pickle string you can base64 encode it (using the base64 module). -- Adam Tauno Williams From bostjan.mejak at gmail.com Wed Nov 17 13:38:18 2010 From: bostjan.mejak at gmail.com (=?UTF-8?Q?Bo=C5=A1tjan_Mejak?=) Date: Wed, 17 Nov 2010 19:38:18 +0100 Subject: Program, Application, and Software Message-ID: What is the difference between a program, an application, and software? From clp2 at rebertia.com Wed Nov 17 13:45:04 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 17 Nov 2010 10:45:04 -0800 Subject: Program, Application, and Software In-Reply-To: References: Message-ID: On Wed, Nov 17, 2010 at 10:38 AM, Bo?tjan Mejak wrote: > What is the difference between a program, an application, and software? (1) This has nothing at all to do with (wx)Python specifically. (2) Did you try consulting Wikipedia?: http://en.wikipedia.org/wiki/Computer_program http://en.wikipedia.org/wiki/Application_software http://en.wikipedia.org/wiki/Computer_software Or did you find the articles somehow lacking or something? Regards, Chris From rbd at hawaii.edu Wed Nov 17 14:29:34 2010 From: rbd at hawaii.edu (Roger Davis) Date: Wed, 17 Nov 2010 11:29:34 -0800 (PST) Subject: strange subprocess behavior when calling ps References: <55f26d5c-aba9-4892-9e2c-1caa9988e7fe@v23g2000vbi.googlegroups.com> Message-ID: <1ed38051-9c8b-4ae8-9a88-9833209d2775@h21g2000vbh.googlegroups.com> > Completely off topic but I think the try clause could be rewritten that way: > ... > Don't use bare except clause, you're masking syntax errors for instance, > which will be flagged as 'unexpected error in generation ...". > In a more general manner, if something unexpected happens it's better to > just let the exception raise uncought. If you want to handle some > errors, meaning you're kindof expecting them then add a explicit clause > (like you did with KeyboardInterrupt). > > JM > > PS : "except Exception :" will catch most of the exceptions (all > inheriting from that class). It's better than using a bare "except :" > clause. (Exception won't catch SyntaxError) Thanks for the suggestion JM, it is off-topic and, although I will first just say that the exception mechanism is *not* one of the reasons I use Python (and stop there with regard to the whole exception mechanism and various usage strategies in general), I do have a few specific questions about a couple of your statements if you don't mind following up. First, inserting a syntax error into my existing code does not hide a SyntaxError exception as you have stated: % cat pid.py #!/usr/bin/python import os import sys import subprocess def main(): psargs= ["/bin/ps", "-e"] try: ps= subprocess.Popen(psargs, stdout=subprocess.PIPE, close_fds=True) psout= ps.communicate()[0] pslines= psout.splitlines() if pslines not good Python talky-talk for line in pslines: print "%s" % line except KeyboardInterrupt: print "Keyboard interrupt received -- terminating." sys.stdout.flush() sys.exit(-1) except: print "%s: unexpected error in generation of system process list" % prognm sys.stdout.flush() sys.exit(-1) main() % ./pid.py File "./pid.py", line 14 if pslines not good Python talky-talk ^ SyntaxError: invalid syntax It appears that the interpreter is catching the syntax error before the code is even executed. Second, python.org's exception hierarchy documentation (Section 6.1 at http://docs.python.org/library/exceptions.html) shows all exception types except SystemExit, KeyboardInterrupt and GeneratorExit as being descendants of Exception. This includes SyntaxError, a child of StandardError which is itself a child of Exception. So, if I say 'except Exception:' then isn't that clause going to process any child exception type of Exception (including SyntaxError) that I haven't already covered in a separate except clause? (Except of course that my interpreter doesn't seem to treat a syntax error as any kind of exception at all!) Finally, and this does not apply to your comments in particular, in researching around about exception handling I often see the usage except Exception, e: suggested, but can't for the life of me figure out what the heck the ', e' part does. Can anybody explain what this means and why it might be desirable (or not)? Thanks! From ph.ton.sharma at gmail.com Wed Nov 17 14:29:54 2010 From: ph.ton.sharma at gmail.com (Ton) Date: Wed, 17 Nov 2010 11:29:54 -0800 (PST) Subject: Help: Guide needed in trying to delete/flush the content of a fifo file. References: <1c7f7feb-ff95-404b-9628-458922360908@j12g2000prm.googlegroups.com> Message-ID: Thanks Mrab ... the way of how to use the pipe for the producer as well as the consumer is a bit confusing to me. As i am using the subprocess for both the producer and the consumer as above. Can you please explain me further using a bit of pseudocode. Thanks for ur concern. In Nov 17, 12:13?am, MRAB wrote: > On 16/11/2010 06:52, Ton wrote: > > > > > On Nov 16, 1:47 am, MRAB ?wrote: > >> On 15/11/2010 11:03, Ton wrote: > > >>> On Nov 14, 11:55 pm, MRAB ? ?wrote: > >>>> On 14/11/2010 14:48, ton ph wrote:> ? ?Hi python geeks, > >>>>> ? ? ?I have ?problem which i have been trying to find out for the past > >>>>> some days, i have a device which feeds info to my fifo continuosly, and > >>>>> a thread of mine reads the > >>>>> fifo continuosly. Now when i change a parameter in the device, it sends > >>>>> me different values. Now my problem is that , i want to get rid of the > >>>>> contents of my previous info which > >>>>> is present in my buffer of the fifo.So i want to flush the fifo content > >>>>> when my device starts sending different info .... i am implementing > >>>>> writing and reading the fifo ?using two different threads. > >>>>> Please someone guide me solving my problem. > >>>>> I highly apologise everyone in case my post is not so clear... > >>>>> Thanks everyone in advance. > > >>>> When the info changes, the thread which is putting items into the fifo > >>>> could flush it just by getting items from it (using a non-blocking get) > >>>> until it's empty. > > >>> Hi Mrab, > >>> ? ?Thanks for your immediate reply , can you please guide me with any > >>> tool or library function which i can flush my fifo content .. i use > >>> os.mkfifo() to make the fifo. Or is there any other way i could do > >>> this ... > >>> Thanks > > >> Ah, you're using pipes; I thought you might've been using a queue. I > >> don't know of a way of flushing a pipe. > > >> I wonder whether it's a good idea for the producer to keep filling the > >> fifo, because the consumer know how 'old' the info is when it arrives, > >> and there's your problem of discarding stale info. Perhaps the producer > >> should wait until the consumer has sent an acknowledgement before > >> sending more info. > > > Thanks Mrab, > > ? ?the problem now is that the producer continously dumps the > > information and since i am implementing the producer using the > > subprocess as like this > > > cmd = ['my files'] > > proc = subprocess.Popen(cmd, shell=True, bufsize=0, > > stdout=subprocess.PIPE, stderr=subprocess.STDOUT ) > > > while flag == True: > > ? ? ? line = proc.stdout.read() > > > Now what i want is to synchronise the problem of actual info the > > device is sending and the proper reading as the device is sending and > > not about reading the previous old info in the fifo... hope i have > > made clearer my prob. even i have tried proc.stdout.flush(), to flush > > the previous old info in the fifo. Thnks > > Use two pipes, one each way. The consumer could use send a message to > the producer requesting an update, which the producer could send back > via the other pipe. Thanks marab for your immediate reply. But how actually i go for using pipes in the producer and consumer is a bit doubtful . can you please explain with a pseudocode ... as in my case both producer and consumer are executed using the subprocess as my previous post.... Thanks From rbd at hawaii.edu Wed Nov 17 14:31:49 2010 From: rbd at hawaii.edu (Roger Davis) Date: Wed, 17 Nov 2010 11:31:49 -0800 (PST) Subject: strange subprocess behavior when calling ps References: <55f26d5c-aba9-4892-9e2c-1caa9988e7fe@v23g2000vbi.googlegroups.com> <61496525-afab-4d19-a7e9-e61fb46e03ef@n30g2000vbb.googlegroups.com> Message-ID: <858e1965-1f27-4d36-9f54-271e9ad8dca3@a12g2000vbc.googlegroups.com> On Nov 16, 11:19?pm, Ned Deily wrote: > Interesting. ?It appears that OS X 10.6 takes into account the ... Thanks very much for your thorough explanation, Ned! I think I've got what I need now. Roger From crebert at ucsd.edu Wed Nov 17 14:43:14 2010 From: crebert at ucsd.edu (Chris Rebert) Date: Wed, 17 Nov 2010 11:43:14 -0800 Subject: strange subprocess behavior when calling ps In-Reply-To: <1ed38051-9c8b-4ae8-9a88-9833209d2775@h21g2000vbh.googlegroups.com> References: <55f26d5c-aba9-4892-9e2c-1caa9988e7fe@v23g2000vbi.googlegroups.com> <1ed38051-9c8b-4ae8-9a88-9833209d2775@h21g2000vbh.googlegroups.com> Message-ID: On Wed, Nov 17, 2010 at 11:29 AM, Roger Davis wrote: >> Completely off topic but I think the try clause could be rewritten that way: >> ... >> Don't use bare except clause, you're masking syntax errors for instance, >> which will be flagged as 'unexpected error in generation ...". >> In a more general manner, if something unexpected happens it's better to >> just let the exception raise uncought. If you want to handle some >> errors, meaning you're kindof expecting them then add a explicit clause >> (like you did with KeyboardInterrupt). >> >> JM >> >> PS : "except Exception :" will catch most of the exceptions (all >> inheriting from that class). It's better than using a bare "except :" >> clause. (Exception won't catch SyntaxError) > > Thanks for the suggestion JM, it is off-topic and, although I will > first just say that the exception mechanism is *not* one of the > reasons I use Python (and stop there with regard to the whole > exception mechanism and various usage strategies in general), I do > have a few specific questions about a couple of your statements if you > don't mind following up. > > First, inserting a syntax error into my existing code does not hide a > SyntaxError exception as you have stated: > % ./pid.py > ?File "./pid.py", line 14 > ? ?if pslines not good Python talky-talk > ? ? ? ? ? ? ? ? ? ? ?^ > SyntaxError: invalid syntax > > It appears that the interpreter is catching the syntax error before > the code is even executed. Now try: # junk.py @#$%^& gibberish @#$%^ # main.py import junk You'll get a run-time SyntaxError. > Finally, and this does not apply to your comments in particular, in > researching around about exception handling I often see the usage > > ? except Exception, e: > > suggested, but can't for the life of me figure out what the heck the > ', e' part does. Can anybody explain what this means and why it might > be desirable (or not)? That's how `except Exception as e` used to be spelled. The exception object will be bound to the variable `e`, allowing you to inspect it further. For example, one might use that form of `except` with an I/O-related exception to be able to check its `errno` attribute in order to handle the error properly. If you're just catching a generic Exception, said form of `except` is less useful. Cheers, Chris -- http://blog.rebertia.com From ladasky at my-deja.com Wed Nov 17 15:49:17 2010 From: ladasky at my-deja.com (John Ladasky) Date: Wed, 17 Nov 2010 12:49:17 -0800 (PST) Subject: Is Unladen Swallow dead? References: <2e1a4d02-1e8a-4d31-95da-f33aaf90578c@30g2000yql.googlegroups.com> Message-ID: On Nov 16, 2:30?pm, laspi wrote: >Is Unladen Swallow dead? No, it's just resting. From rbd at hawaii.edu Wed Nov 17 16:19:50 2010 From: rbd at hawaii.edu (Roger Davis) Date: Wed, 17 Nov 2010 13:19:50 -0800 (PST) Subject: strange subprocess behavior when calling ps References: <55f26d5c-aba9-4892-9e2c-1caa9988e7fe@v23g2000vbi.googlegroups.com> <1ed38051-9c8b-4ae8-9a88-9833209d2775@h21g2000vbh.googlegroups.com> Message-ID: <34b1ad2e-eb79-43dd-b2f5-59f220edd902@j9g2000vbl.googlegroups.com> Thanks for the clarification on exceptions, Chris! Roger From huisky at gmail.com Wed Nov 17 16:45:58 2010 From: huisky at gmail.com (huisky) Date: Wed, 17 Nov 2010 13:45:58 -0800 (PST) Subject: How to read such file and sumarize the data? Message-ID: Say I have following log file, which records the code usage. I want to read this file and do the summarize how much total CPU time consumed for each user. Is Python able to do so or say easy to achieve this?, anybody can give me some hints, appricate very much! Example log file. ************************************************************************************** LSTC license server version 224 started at Sun Dec 6 18:56:48 2009 using configuration file /usr/local/lstc/server_data xyz 15424 at trofast3.marin.ntnu.no LS-DYNA_971 NCPU=1 started Sun Dec 6 18:57:40 15424 at trofast3.marin.ntnu.no completed Sun Dec 6 19:42:55 xyz 15500 at trofast3.marin.ntnu.no LS-DYNA_971 NCPU=2 started Sun Dec 6 20:17:02 15500 at trofast3.marin.ntnu.no completed Sun Dec 6 20:26:03 xyz 18291 at trofast2.marin.ntnu.no LS-DYNA_971 NCPU=1 started Sun Dec 6 21:01:17 18291 at trofast2.marin.ntnu.no completed Sun Dec 6 21:01:28 tanhoi 552 at iimt-tanhoi-w.ivt.ntnu.no LS-DYNA_971 NCPU=1 started Mon Dec 7 09:31:00 552 at iimt-tanhoi-w.ivt.ntnu.no presumed dead Mon Dec 7 10:36:48 sabril 18863 at trofast2.marin.ntnu.no LS-DYNA_971 NCPU=2 started Mon Dec 7 13:14:47 18863 at trofast2.marin.ntnu.no completed Mon Dec 7 13:24:07 sabril 18937 at trofast2.marin.ntnu.no LS-DYNA_971 NCPU=2 started Mon Dec 7 14:21:34 sabril 18969 at trofast2.marin.ntnu.no LS-DYNA_971 NCPU=2 started Mon Dec 7 14:28:42 18969 at trofast2.marin.ntnu.no killed Mon Dec 7 14:31:48 18937 at trofast2.marin.ntnu.no killed Mon Dec 7 14:32:06 From nagle at animats.com Wed Nov 17 17:09:59 2010 From: nagle at animats.com (John Nagle) Date: Wed, 17 Nov 2010 14:09:59 -0800 Subject: Is Unladen Swallow dead? In-Reply-To: References: <2e1a4d02-1e8a-4d31-95da-f33aaf90578c@30g2000yql.googlegroups.com> Message-ID: <4ce452c5$0$1638$742ec2ed@news.sonic.net> On 11/17/2010 12:49 PM, John Ladasky wrote: > On Nov 16, 2:30 pm, laspi wrote: >> Is Unladen Swallow dead? > > No, it's just resting. For those who don't get that, The Monty Python reference: "http://www.mtholyoke.edu/~ebarnes/python/dead-parrot.htm" Owner: Oh yes, the, uh, the Norwegian Blue...What's,uh...What's wrong with it? Mr. Praline: I'll tell you what's wrong with it, my lad. 'E's dead, that's what's wrong with it! Owner: No, no, 'e's uh,...he's resting. Mr. Praline: Look, matey, I know a dead parrot when I see one, and I'm looking at one right now. Owner: No no he's not dead, he's, he's restin'! Remarkable bird, the Norwegian Blue, idn'it, ay? Beautiful plumage! Mr. Praline: The plumage don't enter into it. It's stone dead. Owner: Nononono, no, no! 'E's resting! Mr. Praline: All right then, if he's restin', I'll wake him up! (shouting at the cage) 'Ello, Mister Polly Parrot! I've got a lovely fresh cuttle fish for you if you show... (owner hits the cage) Owner: There, he moved! Mr. Praline: No, he didn't, that was you hitting the cage! Owner: I never!! Mr. Praline: Yes, you did! Owner: I never, never did anything... Mr. Praline: (yelling and hitting the cage repeatedly) 'ELLO POLLY!!!!! Testing! Testing! Testing! Testing! This is your nine o'clock alarm call! (Takes parrot out of the cage and thumps its head on the counter. Throws it up in the air and watches it plummet to the floor.) Mr. Praline: Now that's what I call a dead parrot. (There's more, but you get the idea.) John Nagle From philip at semanchuk.com Wed Nov 17 17:30:21 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 17 Nov 2010 17:30:21 -0500 Subject: Is Unladen Swallow dead? In-Reply-To: <4ce452c5$0$1638$742ec2ed@news.sonic.net> References: <2e1a4d02-1e8a-4d31-95da-f33aaf90578c@30g2000yql.googlegroups.com> <4ce452c5$0$1638$742ec2ed@news.sonic.net> Message-ID: <6843D43E-3586-4D9D-9C70-8B1452734323@semanchuk.com> On Nov 17, 2010, at 5:09 PM, John Nagle wrote: > On 11/17/2010 12:49 PM, John Ladasky wrote: >> On Nov 16, 2:30 pm, laspi wrote: >>> Is Unladen Swallow dead? >> >> No, it's just resting. > > For those who don't get that, The Monty Python reference: > "http://www.mtholyoke.edu/~ebarnes/python/dead-parrot.htm" A link to the source material: http://www.youtube.com/user/montypython?blend=1&ob=4#p/c/6FD5A97331C1B802/0/npjOSLCR2hE -- Cheers Philip From python at mrabarnett.plus.com Wed Nov 17 17:32:38 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 17 Nov 2010 22:32:38 +0000 Subject: How to read such file and sumarize the data? In-Reply-To: References: Message-ID: <4CE45806.7080803@mrabarnett.plus.com> On 17/11/2010 21:45, huisky wrote: > Say I have following log file, which records the code usage. > I want to read this file and do the summarize how much total CPU time > consumed for each user. > Is Python able to do so or say easy to achieve this?, anybody can give > me some hints, appricate very much! > > > Example log file. > ************************************************************************************** > LSTC license server version 224 started at Sun Dec 6 18:56:48 2009 > using configuration file /usr/local/lstc/server_data > xyz 15424 at trofast3.marin.ntnu.no LS-DYNA_971 NCPU=1 started Sun Dec 6 > 18:57:40 > 15424 at trofast3.marin.ntnu.no completed Sun Dec 6 19:42:55 > xyz 15500 at trofast3.marin.ntnu.no LS-DYNA_971 NCPU=2 started Sun Dec 6 > 20:17:02 > 15500 at trofast3.marin.ntnu.no completed Sun Dec 6 20:26:03 > xyz 18291 at trofast2.marin.ntnu.no LS-DYNA_971 NCPU=1 started Sun Dec 6 > 21:01:17 > 18291 at trofast2.marin.ntnu.no completed Sun Dec 6 21:01:28 > tanhoi 552 at iimt-tanhoi-w.ivt.ntnu.no LS-DYNA_971 NCPU=1 started Mon > Dec 7 09:31:00 > 552 at iimt-tanhoi-w.ivt.ntnu.no presumed dead Mon Dec 7 10:36:48 > sabril 18863 at trofast2.marin.ntnu.no LS-DYNA_971 NCPU=2 started Mon > Dec 7 13:14:47 > 18863 at trofast2.marin.ntnu.no completed Mon Dec 7 13:24:07 > sabril 18937 at trofast2.marin.ntnu.no LS-DYNA_971 NCPU=2 started Mon > Dec 7 14:21:34 > sabril 18969 at trofast2.marin.ntnu.no LS-DYNA_971 NCPU=2 started Mon > Dec 7 14:28:42 > 18969 at trofast2.marin.ntnu.no killed Mon Dec 7 14:31:48 > 18937 at trofast2.marin.ntnu.no killed Mon Dec 7 14:32:06 Here's how I would probably do it: Use 2 dicts, one for the start time of each user, and the other for the total elapsed time of each user. For each line extract the user name, date/time and whether the user is starting, finishing, etc. When a user starts, save the info in the first dict, and when a user finishes, calculate the elapsed time and add it to the total for that user. The date/time can be parsed by the time or datetime module. From usernet at ilthio.net Wed Nov 17 17:38:53 2010 From: usernet at ilthio.net (Tim Harig) Date: Wed, 17 Nov 2010 22:38:53 +0000 (UTC) Subject: How to read such file and sumarize the data? References: Message-ID: On 2010-11-17, huisky wrote: > I want to read this file and do the summarize how much total CPU time > consumed for each user. > Is Python able to do so or say easy to achieve this?, anybody can give > me some hints, appricate very much! The question is, is the information you want available in the data. > Example log file. > ************************************************************************************** > LSTC license server version 224 started at Sun Dec 6 18:56:48 2009 > using configuration file /usr/local/lstc/server_data > xyz 15424 at trofast3.marin.ntnu.no LS-DYNA_971 NCPU=1 started Sun Dec 6 > 18:57:40 > 15424 at trofast3.marin.ntnu.no completed Sun Dec 6 19:42:55 > xyz 15500 at trofast3.marin.ntnu.no LS-DYNA_971 NCPU=2 started Sun Dec 6 > 20:17:02 > 15500 at trofast3.marin.ntnu.no completed Sun Dec 6 20:26:03 > xyz 18291 at trofast2.marin.ntnu.no LS-DYNA_971 NCPU=1 started Sun Dec 6 > 21:01:17 > 18291 at trofast2.marin.ntnu.no completed Sun Dec 6 21:01:28 > tanhoi 552 at iimt-tanhoi-w.ivt.ntnu.no LS-DYNA_971 NCPU=1 started Mon > Dec 7 09:31:00 > 552 at iimt-tanhoi-w.ivt.ntnu.no presumed dead Mon Dec 7 10:36:48 > sabril 18863 at trofast2.marin.ntnu.no LS-DYNA_971 NCPU=2 started Mon > Dec 7 13:14:47 > 18863 at trofast2.marin.ntnu.no completed Mon Dec 7 13:24:07 > sabril 18937 at trofast2.marin.ntnu.no LS-DYNA_971 NCPU=2 started Mon > Dec 7 14:21:34 > sabril 18969 at trofast2.marin.ntnu.no LS-DYNA_971 NCPU=2 started Mon > Dec 7 14:28:42 > 18969 at trofast2.marin.ntnu.no killed Mon Dec 7 14:31:48 > 18937 at trofast2.marin.ntnu.no killed Mon Dec 7 14:32:06 I see starts, completes, kills, and presumed deads. The question is can the starts be matched to the completes and kills either from the numbers before @ or from a combination of the address and NCPU. You will need to figure out whether or not you want to count the presumed deads in your calculations. Assuming that the starts and stops can be corrilated, it is a simple matter of finding the pairs and using the datetime module to find the difference in time between them. From usernet at ilthio.net Wed Nov 17 17:49:43 2010 From: usernet at ilthio.net (Tim Harig) Date: Wed, 17 Nov 2010 22:49:43 +0000 (UTC) Subject: How to read such file and sumarize the data? References: Message-ID: On 2010-11-17, MRAB wrote: > When a user starts, save the info in the first dict, and when a user > finishes, calculate the elapsed time and add it to the total for that > user. Perhaps you know more about the structure of this data. It seems to me that a user might have more then a single job(?) running at once. I therefore made the assumption that each start must be matched to its coorisponding stop. From alex.kapps at web.de Wed Nov 17 17:51:01 2010 From: alex.kapps at web.de (Alexander Kapps) Date: Wed, 17 Nov 2010 23:51:01 +0100 Subject: Is Unladen Swallow dead? In-Reply-To: <4ce452c5$0$1638$742ec2ed@news.sonic.net> References: <2e1a4d02-1e8a-4d31-95da-f33aaf90578c@30g2000yql.googlegroups.com> <4ce452c5$0$1638$742ec2ed@news.sonic.net> Message-ID: <4CE45C55.2030802@web.de> On 17.11.2010 23:09, John Nagle wrote: > On 11/17/2010 12:49 PM, John Ladasky wrote: >> On Nov 16, 2:30 pm, laspi wrote: >>> Is Unladen Swallow dead? >> >> No, it's just resting. > > For those who don't get that, The Monty Python reference: > "http://www.mtholyoke.edu/~ebarnes/python/dead-parrot.htm" Thank you John for making my light enough Wallet even lighter, now I have to go and buy the original English version. Seems the German translation sucks (misses a lot) and my copy lacks the original dub. Damned. :-) From steve at holdenweb.com Wed Nov 17 18:10:23 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 17 Nov 2010 18:10:23 -0500 Subject: How to read such file and sumarize the data? In-Reply-To: References: Message-ID: On 11/17/2010 4:45 PM, huisky wrote: > Say I have following log file, which records the code usage. > I want to read this file and do the summarize how much total CPU time > consumed for each user. > Is Python able to do so or say easy to achieve this?, anybody can give > me some hints, appricate very much! > > > Example log file. > ************************************************************************************** I'm assuming the following (unquoted) data is in file "data.txt": > LSTC license server version 224 started at Sun Dec 6 18:56:48 2009 > using configuration file /usr/local/lstc/server_data > xyz 15424 at trofast3.marin.ntnu.no LS-DYNA_971 NCPU=1 started Sun Dec 6 > 18:57:40 > 15424 at trofast3.marin.ntnu.no completed Sun Dec 6 19:42:55 > xyz 15500 at trofast3.marin.ntnu.no LS-DYNA_971 NCPU=2 started Sun Dec 6 > 20:17:02 > 15500 at trofast3.marin.ntnu.no completed Sun Dec 6 20:26:03 > xyz 18291 at trofast2.marin.ntnu.no LS-DYNA_971 NCPU=1 started Sun Dec 6 > 21:01:17 > 18291 at trofast2.marin.ntnu.no completed Sun Dec 6 21:01:28 > tanhoi 552 at iimt-tanhoi-w.ivt.ntnu.no LS-DYNA_971 NCPU=1 started Mon > Dec 7 09:31:00 > 552 at iimt-tanhoi-w.ivt.ntnu.no presumed dead Mon Dec 7 10:36:48 > sabril 18863 at trofast2.marin.ntnu.no LS-DYNA_971 NCPU=2 started Mon > Dec 7 13:14:47 > 18863 at trofast2.marin.ntnu.no completed Mon Dec 7 13:24:07 > sabril 18937 at trofast2.marin.ntnu.no LS-DYNA_971 NCPU=2 started Mon > Dec 7 14:21:34 > sabril 18969 at trofast2.marin.ntnu.no LS-DYNA_971 NCPU=2 started Mon > Dec 7 14:28:42 > 18969 at trofast2.marin.ntnu.no killed Mon Dec 7 14:31:48 > 18937 at trofast2.marin.ntnu.no killed Mon Dec 7 14:32:06 The line wrapping being wrong shouldn't affect the logic. $ cat data.py lines = open("data.txt").readlines() from collections import defaultdict c = defaultdict(int) for line in lines: ls = line.split() if len(ls) > 3 and ls[3].startswith("NCPU="): amt = int(ls[3][5:]) c[ls[0]] += amt for key, value in c.items(): print key, ":", value $ python data.py xyz : 4 tanhoi : 1 sabril : 6 regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From alex.kapps at web.de Wed Nov 17 18:10:56 2010 From: alex.kapps at web.de (Alexander Kapps) Date: Thu, 18 Nov 2010 00:10:56 +0100 Subject: Program, Application, and Software In-Reply-To: References: Message-ID: <4CE46100.4040402@web.de> On 17.11.2010 19:38, Bo?tjan Mejak wrote: > What is the difference between a program, an application, and software? Program: A sequence of one or more instructions (even 'print "hello"' is a valid Python program) Application: Usually a large(er), complex program Software: The parts of a computer that you *can't* kick. From alex.kapps at web.de Wed Nov 17 18:14:46 2010 From: alex.kapps at web.de (Alexander Kapps) Date: Thu, 18 Nov 2010 00:14:46 +0100 Subject: Raw Unicode docstring In-Reply-To: <4a1c5b98-8bf2-4525-b26f-a30b3dcbd6e1@e20g2000vbn.googlegroups.com> References: <4a1c5b98-8bf2-4525-b26f-a30b3dcbd6e1@e20g2000vbn.googlegroups.com> Message-ID: <4CE461E6.8060305@web.de> On 17.11.2010 06:14, John Machin wrote: > On Nov 17, 9:34 am, Alexander Kapps wrote: > >> >>> ur"Schei?t\nderB?r\nim Wald?" > > Nicht ohne eine Genehmigung von der Umwelt Erhaltung Abteilung. The typical response around here is "Ja, aber nur wenn er Klopapier dabei hat." :-D From cs at zip.com.au Wed Nov 17 18:16:28 2010 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 18 Nov 2010 10:16:28 +1100 Subject: strange subprocess behavior when calling ps In-Reply-To: References: Message-ID: <20101117231628.GA12910@cskk.homeip.net> On 16Nov2010 20:18, Ned Deily wrote: | In article | <55f26d5c-aba9-4892-9e2c-1caa9988e7fe at v23g2000vbi.googlegroups.com>, | Roger Davis wrote: | > I am running 2.6.6 under MacOS 10.6.4 on a MacBook Pro Intel. I have | > appended the code below. I am running both commands directly in a | > Terminal window running tcsh. | | See "man compat". What you are seeing is the difference between ps(1) | output in "legacy" mode, attempting to duplicate the old, non-POSIX | behavior from 10.3 days, or "unix2003" mode. Terminal login sessions | are normally automatically started with the COMMAND_MODE environment | variable set: | | $ echo $COMMAND_MODE | unix2003 | | Adding an "env={"COMMAND_MODE": "unix2003"}" argument to your subprocess | Popen call should do the trick. For an added datum, my machine (MacOSX 10.6.5 Intel Macbook Air) says "legacy" instead of "unix2003". -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ I understand a fury in your words, but not your words. - William Shakespeare From nospam at panda.com Wed Nov 17 18:18:44 2010 From: nospam at panda.com (Mark Crispin) Date: Wed, 17 Nov 2010 15:18:44 -0800 Subject: simple(?) Python C module question Message-ID: This is something that ought to be simple, but going through the documentation hasn't come up with the answer. Hopefully someone can answer it faster than I can figure it out from the documentation. I am using Python 2.6 for a project. I do not have a choice in the matter, so telling me to use Python 3.1 is not helpful. [I already wasted a while learning that Python 2.x and Python 3.x are very different, and documentation for the one is lies for the other........] I know relatively little about Python, but am experienced in other OO languages. The OO jargon I'll use in this question is as is used in SmallTalk or perhaps Objective-C (just in case Python uses other jargon). I have a Python module written in C that interfaces with an external C library. Basically, the project is to make it possible to use that library from Python scripts. If you know who I am, you can guess which library. :) I have gotten as far as writing the module, and I can call methods in the module that call the library and do the intended thing. So far, so good. However, I now need to write a method that creates what the library calls a "stream", and I need method calls to work on that stream. The obvious way to do this in any other OO language is to have an object that holds the stream from the library in an instance variable (which actually will be constant for that object instance), and has various object methods for operating on that stream. I assume that the object methods are defined by a PyMethodDef table, just as they are for the module. But how do I: [1] define the object [2] create an instance of the object with the stream and methods [3] hook the object's destruction to a library stream-close function Python does NOT need to look at the stream in any way. Ideally, the object is just a blob that only has method calls. This ought to be simple, and not even require me to know much Python since basically the task is just this module and a few very basic Python scripts to use it. Other people will be writing the real scripts. Of course, I could just have the open method return the stream pointer as a big int, and have module methods that take the stream pointer as their first argument, just as in C code. If I did that, the project would have been done by now. But the result wouldn't be very OO or Pythonish; and more to the point other people will have to use it. I hate when people inflict quick, dirty, stupid, ugly, lazy programmer abominations on me; and so I feel obligated to do it right rather than inflict an abomination on others... :) Thanks in advance for any pointers and/or help. -- Mark -- http://panda.com/mrc Democracy is two wolves and a sheep deciding what to eat for lunch. Liberty is a well-armed sheep contesting the vote. From invalid at invalid.invalid Wed Nov 17 18:35:54 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 17 Nov 2010 23:35:54 +0000 (UTC) Subject: simple(?) Python C module question References: Message-ID: On 2010-11-17, Mark Crispin wrote: Hey, it's the IMAP guy! Get 'im! > I have a Python module written in C that interfaces with an external > C library. Basically, the project is to make it possible to use that > library from Python scripts. If you know who I am, you can guess > which library. :) Have you looked at ctypes? It's not suitable for all libraries, but it can often obviate the need to write any C code: http://docs.python.org/release/2.6.6/library/ctypes.html#module-ctypes -- Grant Edwards grant.b.edwards Yow! I wonder if I should at put myself in ESCROW!! gmail.com From python at mrabarnett.plus.com Wed Nov 17 18:37:23 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 17 Nov 2010 23:37:23 +0000 Subject: How to read such file and sumarize the data? In-Reply-To: References: Message-ID: <4CE46733.6010008@mrabarnett.plus.com> On 17/11/2010 22:49, Tim Harig wrote: > On 2010-11-17, MRAB wrote: >> When a user starts, save the info in the first dict, and when a user >> finishes, calculate the elapsed time and add it to the total for that >> user. > > Perhaps you know more about the structure of this data. It seems to me > that a user might have more then a single job(?) running at once. I > therefore made the assumption that each start must be matched to its > coorisponding stop. I did make certain assumptions. It's up to the OP to adapt it to the actual problem accordingly. :-) From martin at address-in-sig.invalid Wed Nov 17 18:38:58 2010 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Wed, 17 Nov 2010 23:38:58 +0000 (UTC) Subject: How to read such file and sumarize the data? References: Message-ID: On Wed, 17 Nov 2010 13:45:58 -0800, huisky wrote: > Say I have following log file, which records the code usage. I want to > read this file and do the summarize how much total CPU time consumed for > each user. > Two points you should think about: - I don't think you can extract CPU time from this log: you can get the process elapsed time and the number of CPUs each run has used, but you can't calculate CPU time from those values since you don't know how the process spent waiting for i/o etc. - is the first (numeric) part of the first field on the line a process id? If it is, you can match start and stop messages on the value of the first field provided that this value can never be shared by two processes that are both running. If you can get simultaneous duplicates, then you're out of luck because you'll never be able to match up start and stop lines. > Is Python able to do so or say easy to achieve this?, anybody can give > me some hints, appricate very much! > Sure. There are two approaches possible: - sort the log on the first two fields and then process it with Python knowing that start and stop lines will be adjacent - use the first field as the key to an array and put the start time and CPU count in that element. When a matching stop line is found you, retrieve the array element, calculate and output or total the usage figure for that run and delete the array element. -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From robert.kern at gmail.com Wed Nov 17 18:39:43 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 17 Nov 2010 17:39:43 -0600 Subject: Is Unladen Swallow dead? In-Reply-To: <4CE45C55.2030802@web.de> References: <2e1a4d02-1e8a-4d31-95da-f33aaf90578c@30g2000yql.googlegroups.com> <4ce452c5$0$1638$742ec2ed@news.sonic.net> <4CE45C55.2030802@web.de> Message-ID: On 11/17/10 4:51 PM, Alexander Kapps wrote: > On 17.11.2010 23:09, John Nagle wrote: >> On 11/17/2010 12:49 PM, John Ladasky wrote: >>> On Nov 16, 2:30 pm, laspi wrote: >>>> Is Unladen Swallow dead? >>> >>> No, it's just resting. >> >> For those who don't get that, The Monty Python reference: >> "http://www.mtholyoke.edu/~ebarnes/python/dead-parrot.htm" > > Thank you John for making my light enough Wallet even lighter, now I have to go > and buy the original English version. Seems the German translation sucks (misses > a lot) and my copy lacks the original dub. They're all (legitimately) on Youtube now. http://www.youtube.com/watch?v=npjOSLCR2hE -- 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 martin at address-in-sig.invalid Wed Nov 17 18:43:27 2010 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Wed, 17 Nov 2010 23:43:27 +0000 (UTC) Subject: Is Unladen Swallow dead? References: <2e1a4d02-1e8a-4d31-95da-f33aaf90578c@30g2000yql.googlegroups.com> <4ce452c5$0$1638$742ec2ed@news.sonic.net> Message-ID: On Wed, 17 Nov 2010 23:51:01 +0100, Alexander Kapps wrote: > On 17.11.2010 23:09, John Nagle wrote: >> On 11/17/2010 12:49 PM, John Ladasky wrote: >>> On Nov 16, 2:30 pm, laspi wrote: >>>> Is Unladen Swallow dead? >>> >>> No, it's just resting. >> >> For those who don't get that, The Monty Python reference: >> "http://www.mtholyoke.edu/~ebarnes/python/dead-parrot.htm" > > Thank you John for making my light enough Wallet even lighter, now I > have to go and buy the original English version. Seems the German > translation sucks (misses a lot) and my copy lacks the original dub. > While you're at it, pick up the video of "Monty Python and the Holy Grail". the project name, Unladen Swallow, is a reference to the film. -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From gelonida at gmail.com Wed Nov 17 18:50:06 2010 From: gelonida at gmail.com (Gelonida) Date: Thu, 18 Nov 2010 00:50:06 +0100 Subject: first attempts with pybluez on Linux fail as well Message-ID: Hi, Wanted to write a first simple example with pybluez and offer a serial connection service with a given name. What I tried (being inspired by http://people.csail.mit.edu/albert/bluez-intro/x290.html ) is: server_sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM ) port = bluetooth.PORT_ANY # original example used get_available_port() # buy this seems obsolete server_sock.bind(("",port)) server_sock.listen(1) print "listening on port %d" % port loc_host, loc_port = server_sock.getsockname() print "HOST", loc_host, "PORT??", loc_port uuid = "1e0ca4ea-299d-4335-93eb-27fcfe7fa848" bluetooth.advertise_service( server_sock, "FooBar Service", uuid ) Unde Linux the file does not produce an error message, but When I use another PC to look for services I do NOT see the service "FooBar Service" What might I be doing wrong? Are there any special requirements on the buetooth dongle / bluetooth stack to make abov example work? Thanks a lot for your help. From clp2 at rebertia.com Wed Nov 17 18:57:21 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 17 Nov 2010 15:57:21 -0800 Subject: simple(?) Python C module question In-Reply-To: References: Message-ID: On Wed, Nov 17, 2010 at 3:18 PM, Mark Crispin wrote: > I have a Python module written in C that interfaces with an external C > library. ?Basically, the project is to make it possible to use that library > from Python scripts. ?If you know who I am, you can guess which library. ?:) > > I have gotten as far as writing the module, and I can call methods in the > module that call the library and do the intended thing. ?So far, so good. > > However, I now need to write a method that creates what the library calls a > "stream", and I need method calls to work on that stream. > > The obvious way to do this in any other OO language is to have an object > that holds the stream from the library in an instance variable (which > actually will be constant for that object instance), and has various object > methods for operating on that stream. > > I assume that the object methods are defined by a PyMethodDef table, just as > they are for the module. ?But how do I: > ?[1] define the object > ?[2] create an instance of the object with the stream and methods > ?[3] hook the object's destruction to a library stream-close function > > Python does NOT need to look at the stream in any way. ?Ideally, the object > is just a blob that only has method calls. > Of course, I could just have the open method return the stream pointer as a > big int, and have module methods that take the stream pointer as their first > argument, just as in C code. ?If I did that, the project would have been > done by now. ?But the result wouldn't be very OO or Pythonish; and more to > the point other people will have to use it. ?I hate when people inflict > quick, dirty, stupid, ugly, lazy programmer abominations on me; and so I > feel obligated to do it right rather than inflict an abomination on > others... ?:) > > Thanks in advance for any pointers and/or help. Definitely not a direct answer to your questions, but you might consider using SWIG (http://www.swig.org/Doc1.3/Python.html ); haven't used it myself, but I've generally heard good things about it. Ironically, from the docs, it seems the C modules it generates approximately use your "abomination" approach (except the pointer is at least stored as an opaque object rather than an int); however, importantly, it also generates a .py module with appropriate nice wrapper classes to wrap the function calls as much more natural method calls. So, directly using your "abomination" approach and then manually writing a wrapper class in Python itself is also another option. Cheers, Chris -- http://blog.rebertia.com From davidreynon at gmail.com Wed Nov 17 19:02:05 2010 From: davidreynon at gmail.com (dave) Date: Wed, 17 Nov 2010 16:02:05 -0800 (PST) Subject: Using Python and Connecting to MySQL remotely WITHOUT MySQL installed on local computer Message-ID: http://sourceforge.net/projects/mysql-python/ Using this package, WITHOUT having MySQL installed on my Mac OS X, how can I use python to connect to a remote MySQL server? All of the tutorials mention having to download MySQL! From mdw at distorted.org.uk Wed Nov 17 19:18:44 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 18 Nov 2010 00:18:44 +0000 Subject: simple(?) Python C module question References: Message-ID: <87tyjfeb6j.fsf.mdw@metalzone.distorted.org.uk> Mark Crispin writes: > I have a Python module written in C that interfaces with an external C > library. Basically, the project is to make it possible to use that > library from Python scripts. If you know who I am, you can guess > which library. :) You have your very own Wikipedia page, so others probably needn't guess. > However, I now need to write a method that creates what the library calls a > "stream", and I need method calls to work on that stream. > > The obvious way to do this in any other OO language is to have an > object that holds the stream from the library in an instance variable > (which actually will be constant for that object instance), and has > various object methods for operating on that stream. Yeah, that's pretty much the way it works in Python, though it's a bit more tedious. (I suppose it's too late to suggest using Cython now. It makes this sort of thing much less unpleasant.) > I assume that the object methods are defined by a PyMethodDef table, > just as they are for the module. But how do I: > [1] define the object You need two things here: a C structure to represent the innards of your custom Python type, and a Python type block (a PyTypeObject) providing everything the Python interpreter needs to know about it. The C structure can be pretty much whatever you like, as long as it begins with the macro PyObject_HEAD: typedef struct thingy { PyObject_HEAD /* your stuff here; maybe: */ stream *s; } thingy; The PyTypeObject is big and boring to fill in but you can probably leave most of it null. The structure is described in the Python API manual, but I think you'll need to fill in: * a name for the type (qualified by your module's name; tp_name); * the object size (sizeof(thingy); tp_basicsize); * a deallocation function (tp_dealloc); * some flags (you probably want Py_TPFLAGS_DEFAULT and maybe Py_TPFLAGS_BASETYPE if you don't mind people making subclasses; tp_flags); * a string to be shown to the user if he asks for help about your type (tp_doc); * a pointer to a methods table (tp_methods); * a pointer to a table of attribute getters and setters (if you want to expose stuff as attributes rather than methods; tp_getset); * an allocator (probably PyType_GenericAlloc; tp_alloc); and * a function to construct a new instance (to be called when Python tries to construct an object by calling the type -- leave it null if you construct instances in some other way; tp_new). You might also want to implement the tp_str function to provide useful information about your object's state (e.g., for debugging scripts). There are some standard protocols which might be useful to implement; it doesn't sound like your streams would benefit from behaving like numbers or sequences, but maybe they might be iterable. You attach methods on the type by mentioning them in the PyMethodDef table you set in tp_methods; they get a pointer to the recipient object (a `thingy' as above) so they can find the underlying stream if they want. Getters and setters are pretty similar, but have a simpler interface because they don't need to mess with argument parsing.. > [2] create an instance of the object with the stream and methods If you want Python programs to be able to make streams by saying stream = mumble.stream(...) or whatever then you'll need to implement tp_new: this is pretty much like a standard method, except it gets a pointer to a PyTypeObject to tell it what kind of type to make. (The constructor may be called to construct a subclass of your type.) Parse the arguments and check that they're plausible; then make a new skeleton instance by t = (thingy *)ty->tp_alloc(ty, 0); (where ty is the type pointer you received), fill in your bits, and return (PyObject *)t. Otherwise, well, you go through the same procedure with tp_alloc, only you know which type you want statically. > [3] hook the object's destruction to a library stream-close function This is the tp_dealloc function. It should free up any of your resources, and then say obj->ob_type->tp_free(obj); Python will have arranged for this function to exist if you left tp_free as a null pointer. > Python does NOT need to look at the stream in any way. Ideally, the > object is just a blob that only has method calls. That's what you get anyway, if you use the C API. If you want Python programs to be able to poke about inside your objects, you have to let them explicitly, and that means writing code. > This ought to be simple, and not even require me to know much Python > since basically the task is just this module and a few very basic > Python scripts to use it. Other people will be writing the real > scripts. It doesn't require you to know any Python at all. It /does/ require a certain familiarity with the implementation, though. > Of course, I could just have the open method return the stream pointer > as a big int, and have module methods that take the stream pointer as > their first argument, just as in C code. I don't think Python programmers would thank you for this kind of obviously unsafe implementation; so you already have my gratitude for trying to do the job properly. I know that it's somewhat tedious. And consider giving Cython a look. -- [mdw] From usernet at ilthio.net Wed Nov 17 19:21:54 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 18 Nov 2010 00:21:54 +0000 (UTC) Subject: Using Python and Connecting to MySQL remotely WITHOUT MySQL installed on local computer References: Message-ID: On 2010-11-18, dave wrote: > http://sourceforge.net/projects/mysql-python/ > > Using this package, WITHOUT having MySQL installed on my Mac OS X, how > can I use python to connect to a remote MySQL server? > > All of the tutorials mention having to download MySQL! You don't have to install all of MySQL, just the client libraries. I would assume that almost every MySQL connector uses these libraries; but, you might see if the MySQL-ODBC connector will work without them. It is a long shot. Your last option would be to recreate your own connector without using the MySQL client libraries. I am not really sure what the purpose of reinventing this wheel would be. From nospam at panda.com Wed Nov 17 19:25:54 2010 From: nospam at panda.com (Mark Crispin) Date: Wed, 17 Nov 2010 16:25:54 -0800 Subject: simple(?) Python C module question In-Reply-To: References: Message-ID: On Wed, 17 Nov 2010, Grant Edwards posted: > Hey, it's the IMAP guy! Get 'im! Busted! :p Alright, here's the full story. As may be obvious to some, the module is to be a Python interface into c-client. What may not be obvious is that this is for QA automation. The consumers of this module will know Python but not necessarily C and certainly not c-client. Right now the module is called cclient but that will certainly change. So, I have methods such as cclient.create that in my module look like: static PyObject *cclient_create(PyObject *self, PyObject *args) { char *mailbox; PyObject *ret = NULL; if(PyArg_ParseTuple(args, "s", &mailbox)) ret = Py_BuildValue("i", mail_create(NULL, mailbox)); return ret; } and indeed within Python cclient.create("testbox") creates "testbox" as expected. A bunch of other methods are the same. Now, however, I need cclient.open, and expect to do something like: static PyObject *cclient_create(PyObject *self, PyObject *args) { char *mailbox; MAILSTREAM *stream; PyObject *ret = NULL; if(PyArg_ParseTuple(args, "s", &mailbox) && (stream = mail_open(NULL, mailbox, 0))) { ret = ???; // set ret to a "cclient stream" object that has "stream" as // an instance variable, and a method table, presumably via // PyMethodDef, for this "cclient stream" object. } return ret; } So, if in Python, I do something like: stream = cclient.open("testbox") print stream.uid(1) I expect that to call an method like static PyObject *cclient_create(PyObject *self, PyObject *args) { long sequence; MAILSTREAM *stream = ???; // get stream from self PyObject *ret = NULL; if(PyArg_ParseTuple(args, "l", &sequence)) ret = Py_BuildValue("i", mail_uid(stream, sequence)); return ret; } So, basically, what I'm missing are the two "???" things above, plus how to make this "cclient stream" object call mail_close(stream). In SmallTalk or Objective C, the method table would be defined as part of a factory object that has a "new" factory method that in my case would take "stream" as an argument and set it as the instance method. Then to get the stream, I'd do something like stream = [self getStream]; > Have you looked at ctypes? It's not suitable for all libraries, but > it can often obviate the need to write any C code: > http://docs.python.org/release/2.6.6/library/ctypes.html#module-ctypes Hmm. I don't think that it helps, especially as I don't really want to make the consumers of this module know anything about c-client or its calling conventions. Thanks for any clues... -- Mark -- http://panda.com/mrc Democracy is two wolves and a sheep deciding what to eat for lunch. Liberty is a well-armed sheep contesting the vote. From debatem1 at gmail.com Wed Nov 17 19:28:39 2010 From: debatem1 at gmail.com (geremy condra) Date: Wed, 17 Nov 2010 16:28:39 -0800 Subject: simple(?) Python C module question In-Reply-To: References: Message-ID: On Wed, Nov 17, 2010 at 3:35 PM, Grant Edwards wrote: > On 2010-11-17, Mark Crispin wrote: > > Hey, it's the IMAP guy! ?Get 'im! > >> I have a Python module written in C that interfaces with an external >> C library. ?Basically, the project is to make it possible to use that >> library from Python scripts. ?If you know who I am, you can guess >> which library. ?:) > > Have you looked at ctypes? ?It's not suitable for all libraries, but > it can often obviate the need to write any C code: > > ?http://docs.python.org/release/2.6.6/library/ctypes.html#module-ctypes This. You may also want to check out [0] and [1], which use ctypes and generally make short work of writing C bindings. For a more complete example, see [2]. Geremy Condra [0]: http://code.activestate.com/recipes/576731-c-function-decorator/ [1]: http://code.activestate.com/recipes/576734-c-struct-decorator/ [2]: http://gitorious.org/evpy From ben+python at benfinney.id.au Wed Nov 17 19:28:50 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 18 Nov 2010 11:28:50 +1100 Subject: Program, Application, and Software References: Message-ID: <87hbffa30d.fsf@benfinney.id.au> Alexander Kapps writes: > On 17.11.2010 19:38, Bo?tjan Mejak wrote: > > What is the difference between a program, an application, and > > software? Alexander's guide is good. Some notes from a native speaker of English: > Program: A sequence of one or more instructions (even 'print "hello"' > is a valid Python program) Some like to sub-divide ?script? as a type of program; I don't see the point, and refer to such things as programs. > Application: Usually a large(er), complex program An application might also be several programs working together, along with the non-program software they use to do their jobs: e.g. ?LibreOffice is an application consisting of many programs, data sets, libraries, images, document templates, and other software?. > Software: The parts of a computer that you *can't* kick. It's worth noting a common error of non-native English users: ?software? is an uncountable noun, like ?hardware?. This is unlike ?program? and ?application?, both of which are countable. So it makes no more sense to speak of ?a software? than ?a clothing?; both are wrong. If you want to refer to countable items, ?a software work? is acceptable if you want to refer generically to a work of digitally-stored information. Otherwise be more precise: a software work might be ?a document?, ?an image?, ?an audio recording?, ?a program?, ?a database?, et cetera. Hope that helps. -- \ ?It's my belief we developed language because of our deep inner | `\ need to complain.? ?Jane Wagner, via Lily Tomlin | _o__) | Ben Finney From mdw at distorted.org.uk Wed Nov 17 19:39:33 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 18 Nov 2010 00:39:33 +0000 Subject: Program, Application, and Software References: Message-ID: <87pqu3ea7u.fsf.mdw@metalzone.distorted.org.uk> Alexander Kapps writes: > Application: Usually a large(er), complex program I'd say that an `application' is specifically a program intended for direct human use. Other things are servers, daemons and utilities. But I might just be weird. -- [mdw] From nospam at panda.com Wed Nov 17 19:45:38 2010 From: nospam at panda.com (Mark Crispin) Date: Wed, 17 Nov 2010 16:45:38 -0800 Subject: simple(?) Python C module question In-Reply-To: <87tyjfeb6j.fsf.mdw@metalzone.distorted.org.uk> References: <87tyjfeb6j.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On Thu, 18 Nov 2010, Mark Wooding posted: > [snip] Whoo-hoo! That's exactly what I was looking for. If we ever meet in person, I owe you a beer, sir. And by that I mean real beer (from what we call a "microbrew"), not Budweiser... :) -- Mark -- http://panda.com/mrc Democracy is two wolves and a sheep deciding what to eat for lunch. Liberty is a well-armed sheep contesting the vote. From python.list at tim.thechases.com Wed Nov 17 19:49:56 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 17 Nov 2010 18:49:56 -0600 Subject: Program, Application, and Software In-Reply-To: <4CE46100.4040402@web.de> References: <4CE46100.4040402@web.de> Message-ID: <4CE47834.2030702@tim.thechases.com> On 11/17/2010 05:10 PM, Alexander Kapps wrote: > On 17.11.2010 19:38, Bo?tjan Mejak wrote: >> What is the difference between a program, an application, and software? > > Software: The parts of a computer that you *can't* kick. Programmer: the part that usually gets kicked... -tkc From tjreedy at udel.edu Wed Nov 17 19:51:56 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 17 Nov 2010 19:51:56 -0500 Subject: How to read such file and sumarize the data? In-Reply-To: References: Message-ID: On 11/17/2010 6:10 PM, Steve Holden wrote: > $ cat data.py > lines = open("data.txt").readlines() Since you iterate through the file just once, there is no reason I can think of to make a complete in-memory copy. That would be a problem with a multi-gigabyte log file ;=). In 3.x at least, open files are line iterators and one would just need lines = open("data.txt") > from collections import defaultdict > c = defaultdict(int) > for line in lines: > ls = line.split() > if len(ls)> 3 and ls[3].startswith("NCPU="): > amt = int(ls[3][5:]) > c[ls[0]] += amt > for key, value in c.items(): > print key, ":", value > > > $ python data.py > xyz : 4 > tanhoi : 1 > sabril : 6 > > regards > Steve -- Terry Jan Reedy From python at mrabarnett.plus.com Wed Nov 17 20:16:34 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 18 Nov 2010 01:16:34 +0000 Subject: Program, Application, and Software In-Reply-To: <87hbffa30d.fsf@benfinney.id.au> References: <87hbffa30d.fsf@benfinney.id.au> Message-ID: <4CE47E72.7070802@mrabarnett.plus.com> On 18/11/2010 00:28, Ben Finney wrote: > Alexander Kapps writes: > >> On 17.11.2010 19:38, Bo?tjan Mejak wrote: >>> What is the difference between a program, an application, and >>> software? > > Alexander's guide is good. Some notes from a native speaker of English: > >> Program: A sequence of one or more instructions (even 'print "hello"' >> is a valid Python program) > > Some like to sub-divide ?script? as a type of program; I don't see the > point, and refer to such things as programs. > [snip] I'd probably say that a "script" is a program which is normally not interactive: you just set it up, start it, and let it do its work (a "batch script", for example). It's also written in a language primarily designed for convenience rather than speed (Want to manipulate large chunks of text? Fine! :-)). From steve at holdenweb.com Wed Nov 17 21:14:03 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 17 Nov 2010 21:14:03 -0500 Subject: How to read such file and sumarize the data? In-Reply-To: References: Message-ID: On 11/17/2010 7:51 PM, Terry Reedy wrote: > On 11/17/2010 6:10 PM, Steve Holden wrote: > >> $ cat data.py >> lines = open("data.txt").readlines() > > Since you iterate through the file just once, there is no reason I can > think of to make a complete in-memory copy. That would be a problem with > a multi-gigabyte log file ;=). In 3.x at least, open files are line > iterators and one would just need > You are indeed perfectly correct. Thank you. Probably old-ingrained habits showing through. Open files have been line iterators since 2.2, I believe. regards Steve > lines = open("data.txt") > >> from collections import defaultdict >> c = defaultdict(int) >> for line in lines: >> ls = line.split() >> if len(ls)> 3 and ls[3].startswith("NCPU="): >> amt = int(ls[3][5:]) >> c[ls[0]] += amt >> for key, value in c.items(): >> print key, ":", value >> >> >> $ python data.py >> xyz : 4 >> tanhoi : 1 >> sabril : 6 >> >> regards >> Steve > > -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Wed Nov 17 21:24:22 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 17 Nov 2010 21:24:22 -0500 Subject: Using Python and Connecting to MySQL remotely WITHOUT MySQL installed on local computer In-Reply-To: References: Message-ID: On 11/17/2010 7:21 PM, Tim Harig wrote: > On 2010-11-18, dave wrote: >> http://sourceforge.net/projects/mysql-python/ >> >> Using this package, WITHOUT having MySQL installed on my Mac OS X, how >> can I use python to connect to a remote MySQL server? >> >> All of the tutorials mention having to download MySQL! > > You don't have to install all of MySQL, just the client libraries. I would > assume that almost every MySQL connector uses these libraries; but, you > might see if the MySQL-ODBC connector will work without them. It is a long > shot. Your last option would be to recreate your own connector without > using the MySQL client libraries. I am not really sure what the purpose of > reinventing this wheel would be. I believe that the coming trend is to implement the MySQL client protocol directly in Python, thereby obviating the need for any MySQL client installation on the machine hosting the Python code. The pymysql project at http://code.google.com/p/pymysql/ is one such solution, aimed at satisfying Python 3 users without the need to port existing low-level client code. As an irrelevance might I also add that the trend for built-in extension modules is to require a reference implementation in Python to ease the task of those wishing to port the language and get as much functionality (albeit at some performance in cost) available as early in the porting cycle as possible. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From cs at zip.com.au Wed Nov 17 21:58:49 2010 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 18 Nov 2010 13:58:49 +1100 Subject: returning results from function In-Reply-To: References: Message-ID: <20101118025849.GA17150@cskk.homeip.net> On 11Nov2010 15:29, Chris Rebert wrote: | > On Nov 11, 2010, at 1:54 PM, Chris Rebert wrote: | >> On Thu, Nov 11, 2010 at 1:16 PM, Neil Berg wrote: | >> time_y = ncfile.variables['time_y'][:] # (time,int) [yrs] | >> time_m = ncfile.variables['time_m'][:] # (time,int) [mnths] | >> time_d = ncfile.variables['time_d'][:] # (time,int) [days] | >> time_h = ncfile.variables['time_h'][:] ? ?# (time,float) [hrs] | >> ntim =len(time_h) | >> for tim_idx in range(0,ntim): | >> ? ? ? ?local_date = utc_to_local(time_y[tim_idx],time_m[tim_idx],time_d[tim_idx],int(time_h[tim_idx])) | >> ? ? ? ?***Here is where I'd like to see the returned values so I can create new arrays that store them ***** | | Add: | print(local_date) | Or if you want to be fancy: | print("%.4d-%.2d-%.2d %.2d" % local_date) It's worth noting that if you know the number of return arguments you can do this: locyr, locmm, locdd, lochh = itc_to_local(.......) and then easily use the individual values. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Admit Nothing. Blame Everyone. Be Bitter. - Matt Hopkins, DoD #1197, From usernet at ilthio.net Wed Nov 17 22:19:16 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 18 Nov 2010 03:19:16 +0000 (UTC) Subject: Using Python and Connecting to MySQL remotely WITHOUT MySQL installed on local computer References: Message-ID: On 2010-11-18, Steve Holden wrote: > On 11/17/2010 7:21 PM, Tim Harig wrote: >> On 2010-11-18, dave wrote: >>> http://sourceforge.net/projects/mysql-python/ >>> >>> Using this package, WITHOUT having MySQL installed on my Mac OS X, how >>> can I use python to connect to a remote MySQL server? >>> >>> All of the tutorials mention having to download MySQL! >> >> You don't have to install all of MySQL, just the client libraries. I would >> assume that almost every MySQL connector uses these libraries; but, you >> might see if the MySQL-ODBC connector will work without them. It is a long >> shot. Your last option would be to recreate your own connector without >> using the MySQL client libraries. I am not really sure what the purpose of >> reinventing this wheel would be. > > I believe that the coming trend is to implement the MySQL client > protocol directly in Python, thereby obviating the need for any MySQL > client installation on the machine hosting the Python code. One of the advantages to using the MySQL supplied library is that if the line protocol changes the connector automatically inherits the work already done by MySQL for the price of a stable API (yes, I am aware that the MySQL API *has* changed through the years). That could be very relevant in the near future as the probject settles its stable forks. > The pymysql project at http://code.google.com/p/pymysql/ is one such > solution, aimed at satisfying Python 3 users without the need to port > existing low-level client code. That still looks like alpha code. Would you be willing to make a statement as to its stability? From tundra at tundraware.com Wed Nov 17 22:39:44 2010 From: tundra at tundraware.com (Tim Daneliuk) Date: Wed, 17 Nov 2010 21:39:44 -0600 Subject: [ANN]: 'tren' Cross-Platform Batch Renaming Tool, Version 1.239 Released Message-ID: <0pjer7-5ag1.ln1@ozzie.tundraware.com> 'tren' Version 1.239 is now released and available for download at: http://www.tundraware.com/Software/tren The last public release was 1.217. --------------------------------------------------------------------- What's New In This Release? --------------------------- This release fixes several critical bugs and adds a number of new features. Existing users are urged to upgrade at their earliest opportunity: FIXED: Backups weren't being improperly named. FIXED: Changed TREN envvar processing to properly parse quoting. FIXED: Each renaming target must either be something that exists or a wildcard that expands to something that exists. Formerly, nonexistent renaming targets were silently ignored. NEW: Debug now shows the incremental change to each file name as each renaming request is applied left-to-right. Use -dq to see this more clearly. NEW: The environment variable TRENINCL is now supported. This allows you to specify a path to search when looking for include files. NEW: Implemented /NAMESOFAR/ renaming token. NEW: Added -e type case conversion option - new kind of renaming request. c - Capitalize l - Lower s - Swap case t - Title -> Char's followiing non-alpha are capitalized u - Upper NEW: Added -T option to allow user to "target" a substring of the full filename for renaming OTHER: Documentation additions and updates including clarification of old features, description of new features, and improved table-of-contents for PDF and PS document formats. What Is 'tren'? ------------------ 'tren' is a general purpose file and directory renaming tool. Unlike commands like 'mv', 'tren' is particularly well suited for renaming *batches* of files and/or directories with a single command line invocation. 'tren' eliminates the tedium of having to script simpler tools to provide higher-level renaming capabilities. 'tren' is also adept at renaming only *part of an existing file or directory name* either based on a literal string or a regular expression pattern. You can replace any single, group, or all instances of a given string in a file or directory name. 'tren' implements the idea of a *renaming token*. These are special names you can embed in your renaming requests that represent things like the file's original name, its length, date of creation, and so on. There are even renaming tokens that will substitute the content of any environment variable or the results of running a program from a shell back into the new file name. 'tren' can automatically generate *sequences* of file names based on their dates, lengths, times within a given date, and so on. In fact, sequences can be generated on the basis of any of the file's 'stat' information. Sequence "numbers" can be ascending or descending and the count can start at any initial value. Counting can take place in one of several internally defined counting "alphabets" (decimal, hex, octal, alpha, etc.) OR you can define your own counting alphabet. This allows you to create sequences in any base (2 or higher please :) using any symbol set for the count. 'tren' is written in pure Python and requires Python version 2.6.x or later. It is known to run on various Unix-like variants (FreeBSD, Linux, MacOS X) as well as Windows. It will also take advantage of 'win32all' Python extensions on a Windows system, if they are present. --------------------------------------------------------------------- Complete details of all fixes, changes, and new features can be found in the WHATSNEW.txt and documentation files included in the distribution. A FreeBSD port has been submitted as well. From tjreedy at udel.edu Wed Nov 17 22:42:06 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 17 Nov 2010 22:42:06 -0500 Subject: simple(?) Python C module question In-Reply-To: References: Message-ID: On 11/17/2010 7:25 PM, Mark Crispin wrote: >> Have you looked at ctypes? It's not suitable for all libraries, but >> it can often obviate the need to write any C code: >> http://docs.python.org/release/2.6.6/library/ctypes.html#module-ctypes > > Hmm. I don't think that it helps, especially as I don't really want to > make the consumers of this module know anything about c-client or its > calling conventions. For the record, a C library wrapper written in Python with cytpes is nearly indistinguishable to users from an equivalent wrapper written in C. However, given that you are more comfortable with C than Python and have gotten the info you need, stick with that. -- Terry Jan Reedy From noydb00 at gmail.com Wed Nov 17 22:47:58 2010 From: noydb00 at gmail.com (noydb) Date: Wed, 17 Nov 2010 19:47:58 -0800 (PST) Subject: How to run an EXE, with argument, capture output value Message-ID: <37037d15-63da-4f37-9508-bdcfff034670@s4g2000yql.googlegroups.com> Hello All, I would appreciate some guidance on this. I'm a newbe, sorry if I sound dumb - I kind of am on this stuff! I have an executable that I want to run within python code. The exe requires an input text file, the user to click a 'compute' button, and then the exe calculates several output values, one of which I want to capture into a variable. Can I use Python to supply the input file, execute the exe and capture the output value, like such that the exe really doesn't need to be 'seen'? Or, would the user still have to click the 'compute' button? Any code snippets or guidance would be very much appreciated. I have found that import os os.system('C:\xTool\stats_hall.exe') will run the exe. And, maybe these execl/execle/execlp/etc functions might be what I need for adding in the argument, but documentation seems to indicate that these do not return output. ?? Thanks much. From steve at holdenweb.com Wed Nov 17 23:19:49 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 17 Nov 2010 23:19:49 -0500 Subject: Using Python and Connecting to MySQL remotely WITHOUT MySQL installed on local computer In-Reply-To: References: Message-ID: On 11/17/2010 10:19 PM, Tim Harig wrote: > On 2010-11-18, Steve Holden wrote: >> On 11/17/2010 7:21 PM, Tim Harig wrote: >>> On 2010-11-18, dave wrote: >>>> http://sourceforge.net/projects/mysql-python/ >>>> >>>> Using this package, WITHOUT having MySQL installed on my Mac OS X, how >>>> can I use python to connect to a remote MySQL server? >>>> >>>> All of the tutorials mention having to download MySQL! >>> >>> You don't have to install all of MySQL, just the client libraries. I would >>> assume that almost every MySQL connector uses these libraries; but, you >>> might see if the MySQL-ODBC connector will work without them. It is a long >>> shot. Your last option would be to recreate your own connector without >>> using the MySQL client libraries. I am not really sure what the purpose of >>> reinventing this wheel would be. >> >> I believe that the coming trend is to implement the MySQL client >> protocol directly in Python, thereby obviating the need for any MySQL >> client installation on the machine hosting the Python code. > > One of the advantages to using the MySQL supplied library is that if the > line protocol changes the connector automatically inherits the work already > done by MySQL for the price of a stable API (yes, I am aware that the MySQL > API *has* changed through the years). That could be very relevant in the > near future as the probject settles its stable forks. > >> The pymysql project at http://code.google.com/p/pymysql/ is one such >> solution, aimed at satisfying Python 3 users without the need to port >> existing low-level client code. > > That still looks like alpha code. Would you be willing to make a statement > as to its stability? No, that was purely an example. I am, however, using MySQL Connector/Python https://launchpad.net/myconnpy in a series of commercial Python 3 classes. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From sxn02 at yahoo.com Wed Nov 17 23:21:06 2010 From: sxn02 at yahoo.com (Sorin Schwimmer) Date: Wed, 17 Nov 2010 20:21:06 -0800 (PST) Subject: String multi-replace Message-ID: <114148.34295.qm@web56007.mail.re3.yahoo.com> Hi All, I have to eliminate diacritics in a fairly large file. Inspired by http://code.activestate.com/recipes/81330/, I came up with the following code: #! /usr/bin/env python import re nodia={chr(196)+chr(130):'A', # mamaliga chr(195)+chr(130):'A', # A^ chr(195)+chr(142):'I', # I^ chr(195)+chr(150):'O', # OE chr(195)+chr(156):'U', # UE chr(195)+chr(139):'A', # AE chr(197)+chr(158):'S', chr(197)+chr(162):'T', chr(196)+chr(131):'a', # mamaliga chr(195)+chr(162):'a', # a^ chr(195)+chr(174):'i', # i^ chr(195)+chr(182):'o', # oe chr(195)+chr(188):'u', # ue chr(195)+chr(164):'a', # ae chr(197)+chr(159):'s', chr(197)+chr(163):'t' } name="R\xc3\xa2\xc5\x9fca" regex = re.compile("(%s)" % "|".join(map(re.escape, nodia.keys()))) print regex.sub(lambda mo: dict[mo.string[mo.start():mo.end()]], name) But it won't work; I end up with: Traceback (most recent call last): File "multirep.py", line 25, in print regex.sub(lambda mo: dict[mo.string[mo.start():mo.end()]], name) File "multirep.py", line 25, in print regex.sub(lambda mo: dict[mo.string[mo.start():mo.end()]], name) TypeError: 'type' object is not subscriptable What am I doing wrong? Thanks for your advice, SxN From benjamin.kaplan at case.edu Wed Nov 17 23:30:12 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 17 Nov 2010 23:30:12 -0500 Subject: String multi-replace In-Reply-To: <114148.34295.qm@web56007.mail.re3.yahoo.com> References: <114148.34295.qm@web56007.mail.re3.yahoo.com> Message-ID: On Wed, Nov 17, 2010 at 11:21 PM, Sorin Schwimmer wrote: > Hi All, > > I have to eliminate diacritics in a fairly large file. > > Inspired by http://code.activestate.com/recipes/81330/, I came up with the following code: > > #! /usr/bin/env python > > import re > > nodia={chr(196)+chr(130):'A', # mamaliga > ? ? ? chr(195)+chr(130):'A', # A^ > ? ? ? chr(195)+chr(142):'I', # I^ > ? ? ? chr(195)+chr(150):'O', # OE > ? ? ? chr(195)+chr(156):'U', # UE > ? ? ? chr(195)+chr(139):'A', # AE > ? ? ? chr(197)+chr(158):'S', > ? ? ? chr(197)+chr(162):'T', > ? ? ? chr(196)+chr(131):'a', # mamaliga > ? ? ? chr(195)+chr(162):'a', # a^ > ? ? ? chr(195)+chr(174):'i', # i^ > ? ? ? chr(195)+chr(182):'o', # oe > ? ? ? chr(195)+chr(188):'u', # ue > ? ? ? chr(195)+chr(164):'a', # ae > ? ? ? chr(197)+chr(159):'s', > ? ? ? chr(197)+chr(163):'t' > ? ? ?} > name="R\xc3\xa2\xc5\x9fca" > > regex = re.compile("(%s)" % "|".join(map(re.escape, nodia.keys()))) > print regex.sub(lambda mo: dict[mo.string[mo.start():mo.end()]], name) > > But it won't work; I end up with: > > Traceback (most recent call last): > ?File "multirep.py", line 25, in > ? ?print regex.sub(lambda mo: dict[mo.string[mo.start():mo.end()]], name) > ?File "multirep.py", line 25, in > ? ?print regex.sub(lambda mo: dict[mo.string[mo.start():mo.end()]], name) > TypeError: 'type' object is not subscriptable > > What am I doing wrong? > > Thanks for your advice, > SxN > dict is a type, not a dict. Your dict is called nodia. I'm guess that's what you meant to use. > > -- > http://mail.python.org/mailman/listinfo/python-list > From drsalists at gmail.com Wed Nov 17 23:37:47 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 17 Nov 2010 20:37:47 -0800 Subject: simple(?) Python C module question In-Reply-To: References: Message-ID: On Wed, Nov 17, 2010 at 7:42 PM, Terry Reedy wrote: > On 11/17/2010 7:25 PM, Mark Crispin wrote: > > Have you looked at ctypes? It's not suitable for all libraries, but >>> it can often obviate the need to write any C code: >>> http://docs.python.org/release/2.6.6/library/ctypes.html#module-ctypes >>> >> >> Hmm. I don't think that it helps, especially as I don't really want to >> make the consumers of this module know anything about c-client or its >> calling conventions. >> > > For the record, a C library wrapper written in Python with cytpes is nearly > indistinguishable to users from an equivalent wrapper written in C. However, > given that you are more comfortable with C than Python and have gotten the > info you need, stick with that. > ...except when you go to recompile a C extension module, if a dependency has changed its API, the C compiler will at least output a warning at the relevant spot. ctypes code is likely to be rather less friendly about it - the word "segfault" comes to mind. I'd say that the 3 main options for C <-> Python interop are: 1) ctypes (nice for light use and if you only need python, not that well type checked, probably the best bet if you're targeting python implementations other than CPython alone) 2) swig (nice if you plan to expose your C API to lots of languages) 3) cython (nice if you only need python, and want to more or less freely intermix normal python with C symbols using a very python-like syntax and with speed near that of C) -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve-REMOVE-THIS at cybersource.com.au Wed Nov 17 23:39:11 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 18 Nov 2010 04:39:11 GMT Subject: Help in language development References: <6fb7a013-cee1-4c77-9b96-d5494a5dda98@j25g2000yqa.googlegroups.com> Message-ID: <4ce4adef$0$29981$c3e8da3$5496439d@news.astraweb.com> Hello Pedro Igor, On Tue, 16 Nov 2010 12:51:07 -0800, pedro igor sampaio avelino wrote: > Hello, my name Pedro Igor, I am a student and develop applications in > python for 1 year. I enrolled in the group to contribute in developing > this wonderful language that helps me both in day-to-day, but I'm going > through some difficulties because they do not know where to start, can > someone please give me some steps so that I can contribute at once > development for all, where do I start, if the documentation or a book. I > know that most people have more important issues to address in other > posts but assistance does not cost anything. If you are interested in helping others, you can start here, on this newsgroup or mailing list. When other people ask questions, try to give the answer yourself. Or you could go to the Python wiki and contribute: http://wiki.python.org/moin/ Or go to the bug tracker, and look for bugs you can work on. Be aware though that the standard for having patches accepted is quite high. http://bugs.python.org/ -- Steven From clp2 at rebertia.com Wed Nov 17 23:45:49 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 17 Nov 2010 20:45:49 -0800 Subject: String multi-replace In-Reply-To: <114148.34295.qm@web56007.mail.re3.yahoo.com> References: <114148.34295.qm@web56007.mail.re3.yahoo.com> Message-ID: On Wed, Nov 17, 2010 at 8:21 PM, Sorin Schwimmer wrote: > Hi All, > > I have to eliminate diacritics in a fairly large file. > > Inspired by http://code.activestate.com/recipes/81330/, I came up with the following code: > > #! /usr/bin/env python > > import re > > nodia={chr(196)+chr(130):'A', # mamaliga > ? ? ? chr(195)+chr(130):'A', # A^ > ? ? ? chr(195)+chr(142):'I', # I^ > ? ? ? chr(195)+chr(150):'O', # OE > ? ? ? chr(195)+chr(156):'U', # UE > ? ? ? chr(195)+chr(139):'A', # AE > ? ? ? chr(197)+chr(158):'S', > ? ? ? chr(197)+chr(162):'T', > ? ? ? chr(196)+chr(131):'a', # mamaliga > ? ? ? chr(195)+chr(162):'a', # a^ > ? ? ? chr(195)+chr(174):'i', # i^ > ? ? ? chr(195)+chr(182):'o', # oe > ? ? ? chr(195)+chr(188):'u', # ue > ? ? ? chr(195)+chr(164):'a', # ae > ? ? ? chr(197)+chr(159):'s', > ? ? ? chr(197)+chr(163):'t' > ? ? ?} > name="R\xc3\xa2\xc5\x9fca" > > regex = re.compile("(%s)" % "|".join(map(re.escape, nodia.keys()))) > print regex.sub(lambda mo: dict[mo.string[mo.start():mo.end()]], name) Have you considered using string.maketrans() and str.translate() instead? It's simpler and likely faster than generating+using regexes like that. http://docs.python.org/library/string.html#string.maketrans Cheers, Chris -- Cue someone quoting Zawinski. http://blog.rebertia.com From steve-REMOVE-THIS at cybersource.com.au Wed Nov 17 23:49:07 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 18 Nov 2010 04:49:07 GMT Subject: Some syntactic sugar proposals References: <87mxp7gbdf.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <4ce4b043$0$29981$c3e8da3$5496439d@news.astraweb.com> On Wed, 17 Nov 2010 16:31:40 +0000, Mark Wooding wrote: > But I don't think that's the big problem with this proposal. The real > problem is that it completely changes the evaluation rule for the > conditional expression. (The evaluation rule is already pretty screwy: > Python is consistently left-to-right -- except here.) Not quite... >>> 1+2*3 7 >>> (1+2)*3 9 But other than that, I agree with your analysis for why Python should not be changed to allow: t = foo() as v if pred(v) else default_value Not everything needs to be a one liner. If you need this, do it the old- fashioned way: t = foo() if not pred(t): t = default_value -- Steven From steve-REMOVE-THIS at cybersource.com.au Thu Nov 18 00:10:03 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 18 Nov 2010 05:10:03 GMT Subject: String multi-replace References: Message-ID: <4ce4b52b$0$29981$c3e8da3$5496439d@news.astraweb.com> On Wed, 17 Nov 2010 20:21:06 -0800, Sorin Schwimmer wrote: > Hi All, > > I have to eliminate diacritics in a fairly large file. What's "fairly large"? Large to you is probably not large to your computer. Anything less than a few dozen megabytes is small enough to be read entirely into memory. > Inspired by http://code.activestate.com/recipes/81330/, I came up with > the following code: If all you are doing is replacing single characters, then there's no need for the 80lb sledgehammer of regular expressions when all you need is a delicate tack hammer. Instead of this: * read the file as bytes * search for pairs of bytes like chr(195)+chr(130) using a regex * replace them with single bytes like 'A' do this: * read the file as a Unicode * search for characters like ? * replace them with single characters like A using unicode.translate() (or str.translate() in Python 3.x) The only gotcha is that you need to know (or guess) the encoding to read the file correctly. -- Steven From sxn02 at yahoo.com Thu Nov 18 00:12:31 2010 From: sxn02 at yahoo.com (Sorin Schwimmer) Date: Wed, 17 Nov 2010 21:12:31 -0800 (PST) Subject: String multi-replace Message-ID: <912885.5637.qm@web56006.mail.re3.yahoo.com> Thanks for your answers. Benjamin Kaplan: of course dict is a type... silly me! I'll blame it on the time (it's midnight here). Chris Rebert: I'll have a look. Thank you both, SxN From usernet at ilthio.net Thu Nov 18 00:24:45 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 18 Nov 2010 05:24:45 +0000 (UTC) Subject: How to run an EXE, with argument, capture output value References: <37037d15-63da-4f37-9508-bdcfff034670@s4g2000yql.googlegroups.com> Message-ID: On 2010-11-18, noydb wrote: > I have an executable that I want to run within python code. The exe > requires an input text file, the user to click a 'compute' button, and > then the exe calculates several output values, one of which I want to > capture into a variable. Can I use Python to supply the input file, > execute the exe and capture the output value, like such that the exe > really doesn't need to be 'seen'? Or, would the user still have to > click the 'compute' button? > > Any code snippets or guidance would be very much appreciated. I have > found that > > import os > os.system('C:\xTool\stats_hall.exe') > > will run the exe. And, maybe these execl/execle/execlp/etc functions > might be what I need for adding in the argument, but documentation > seems to indicate that these do not return output. ?? If you are not already, I would highly suggest using Python3 with the subprocess module: http://docs.python.org/py3k/library/subprocess.html It puts everything in one place and supercedes the exec* functions which where a PITA. You can 95% of what you need simply using subprocess.Popen(). There are several examples from this group in the past few days; but, the process looks something like this: Python 3.1.2 (r312:79147, Oct 9 2010, 00:16:06) [GCC 4.4.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import subprocess >>> pig = subprocess.Popen(["/usr/games/pig"], stdin=subprocess.PIPE) >>> result = pig.communicate(input=b"This is sample text.\n") Isthay isway amplesay exttay. >>> From sxn02 at yahoo.com Thu Nov 18 00:29:33 2010 From: sxn02 at yahoo.com (Sorin Schwimmer) Date: Wed, 17 Nov 2010 21:29:33 -0800 (PST) Subject: String multi-replace Message-ID: <379297.48105.qm@web56003.mail.re3.yahoo.com> Steven D'Aprano: the original file is 139MB (that's the typical size for it). Eliminating diacritics is just a little toping on the cake; the processing is something else. Thanks anyway for your suggestion, SxN PS Perhaps I should have mention that I'm on Python 2.7 From usernet at ilthio.net Thu Nov 18 00:36:59 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 18 Nov 2010 05:36:59 +0000 (UTC) Subject: How to run an EXE, with argument, capture output value References: <37037d15-63da-4f37-9508-bdcfff034670@s4g2000yql.googlegroups.com> Message-ID: On 2010-11-18, Tim Harig wrote: > On 2010-11-18, noydb wrote: >> I have an executable that I want to run within python code. The exe >> requires an input text file, the user to click a 'compute' button, and >> then the exe calculates several output values, one of which I want to >> capture into a variable. Can I use Python to supply the input file, >> execute the exe and capture the output value, like such that the exe ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Sorry, I missed the second part, it's time for me to go to bed. >> really doesn't need to be 'seen'? Or, would the user still have to >> click the 'compute' button? > > Python 3.1.2 (r312:79147, Oct 9 2010, 00:16:06) > [GCC 4.4.4] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import subprocess > >>> pig = subprocess.Popen(["/usr/games/pig"], stdin=subprocess.PIPE) > >>> result = pig.communicate(input=b"This is sample text.\n") > Isthay isway amplesay exttay. > >>> With capturing the output, it looks like: >>> pig = subprocess.Popen(["/usr/games/pig"], stdin=subprocess.PIPE, >>> stdout=subprocess.PIPE) >>> result = pig.communicate(input=b"This is sample text.\n")[0] >>> result b'Isthay isway amplesay exttay.\n' >>> You can also get the return code if you need it: >>> pig.returncode 0 From pmilin at gmail.com Thu Nov 18 02:54:08 2010 From: pmilin at gmail.com (neocortex) Date: Wed, 17 Nov 2010 23:54:08 -0800 (PST) Subject: Does Pygoogle allows for advanced search options? Message-ID: Hello All, Can anyone help me with the Pygoogle: from pygoogle import pygoogle word = u'something' request_word = word.encode('utf-8') request = ('%s+site:.edu' % request_word) g = pygoogle(request) g.get_result_count() Now, I realized that domain restriction works (site:.edu etc.), but I would like to be able to control for language too. Is that possible with the Pygoogle? If not, how can I make that happen? Thanks! PM From cbrown at cbrownsystems.com Thu Nov 18 03:03:05 2010 From: cbrown at cbrownsystems.com (cbrown at cbrownsystems.com) Date: Thu, 18 Nov 2010 00:03:05 -0800 (PST) Subject: Sending changed parameters into nested generators References: <4cde1784$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Nov 12, 10:52 pm, "John O'Hagan" wrote: > On Sat, 13 Nov 2010, Steven D'Aprano wrote: > > On Fri, 12 Nov 2010 09:47:26 +0000, John O'Hagan wrote: > > > I have a generator function which takes as arguments another generator > > > and a dictionary of other generators like this: > > > > def modgen(gen, gendict): > > > for item in gen(): > > > for k, v in gendict: > > > do_something_called_k(item, v.next()) > > > > yield item > > > [snip] > > > > If anyone's still reading :) , how can I send new values to arbitrary > > > sub- generators? > > > I have a headache after reading your problem :( > > > I think it's a good time to point you at the Zen, particularly these five > > maxims: > > > Beautiful is better than ugly. > > Simple is better than complex. > > Complex is better than complicated. > > Flat is better than nested. > > If the implementation is hard to explain, it's a bad idea. > > > I'm afraid that your nested generators inside another generator idea > > fails all of those... it's not elegant (beautiful), it's complicated, > > it's nested, and the implementation is hard to explain. > > > You could probably replace generators with full-blown iterators, but I > > wonder what you're trying to accomplish that is so complicated that it > > needs such complexity to solve it. What are you actually trying to > > accomplish? Can you give a simple example of what practical task you hope > > to perform? I suspect there's probably a more elegant way to solve the > > problem. > > I hope there is! > > The project not practical but artistic; it's a real-time musical composition > program. > > A (simplified) description: one module contains number-list generating > functions, others contain functions designed to filter and modify the number > lists produced, according to various parameters. Each such stream of number > lists is assigned a musical meaning (e.g. pitch, rhythm, volume, etc) and they > are combined to produce representations of musical phrases, which are sent to > a backend which plays the music as it is produced, and makes PDF scores. Each > such "instrument" runs as a separate thread, so several can play together in a > coordinated fashion. > > All the compositional interest lies in the selection of number-list generators > and how their output is modified. For example, if I say "Play every third note > up an octave" it's not very interesting, compared to "Play every nth note up > an interval of m", where n and m vary according to some pattern. It gets even > more interesting when that pattern is a function of x and y, which also vary > according to another pattern, and so on. > > To that end, I have each parameter of each modifier set by another generator, > such that the value may change with each iteration. This may continue > recursively, until at some level we give a parameter a simple value. > > That's all working, but I also want it to be interactive. Each thread opens a > terminal where new options can be entered, but so far it only works, as I > mentioned, for changing the values in a top-level mutable object. > I might first suggest this, although I have some caveats to add: def genfilter(evaluator, **param_sources): while True: params = {} for param, gen in param_sources.iteritems(): params[param] = gen.next() yield evaluator(**params) You can then do things like: >>> def concat(in1, in2): >>> return str(in1)+"|"+str(in2) >>> a = (i for i in range(1,5)) # generator based on a list >>> b = (2*i for i in xrange(1,5)) # 'pure' generator >>> c = genfilter(concat, in1=a, in2=b) >>> for x in c: >>> print x 1|2 2|4 3}6 4|8 or, more relevant to your original question regarding modifying things mid-stream: >>> class Mult(): >>> def __init__(self, multiplier): >>> self.mulitplier = multiplier >>> def multi(self, val): >>> return val*self.multiplier >>> >>> m = Mult(2) >>> a = (i for i in range(1,10)) >>> b = (i for i in range(1,10)) >>> c = genfilter(m.multi, val=b) >>> d = genfilter(concat, in1=a, in2=c) >>> d.next() 1|2 >>> d.next() 2|4 >>> m.multiplier = 3 >>> d.next() 3|9 Obviously more complex and useful examples could be made, but hopefully you get the idea: don't focus on modifying the generators, instead modify the action of the functions which take the generators as inputs. But a real problem with this whole strategy is that a generator's next() function is called every time it is evaluated. If the relationship between your various generators forms a rooted tree, that's not a problem, but I would think the relationships form a directed acyclic graph, and in that case, you end up 'double incrementing' nodes in a way you don't want: >>> m = Mult(2) >>> a = (i for i in range(1,10)) >>> b = genfilter(m.multi, val=a) >>> c = genfilter(concat, in1=a, in2=b) >>> for x in c: >>> print x 1|4 3|8 5|12 7|16 And that's not an unnatural situation for your application: you might have a generator that produces a note, and then three other distinct genfilters that you want to use to create three instruments which form a chord based on that note. With the above pattern (and also your original pattern) you would end up invoking the note generator three times; and I think you don't really want that. To solve that problem, you need a somewhat more complex solution: a class that ensures that each previous stage is only invoked once per 'pass'. I've got an idea for that, if that is of interest. Cheers - Chas From clp2 at rebertia.com Thu Nov 18 03:28:03 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 18 Nov 2010 00:28:03 -0800 Subject: Does Pygoogle allows for advanced search options? In-Reply-To: References: Message-ID: On Wed, Nov 17, 2010 at 11:54 PM, neocortex wrote: > Hello All, > Can anyone help me with the Pygoogle: > from pygoogle import pygoogle You're apparently talking about http://code.google.com/p/pygoogle/ rather than http://pygoogle.sourceforge.net/ ; the former appears to have "borrowed" the latter's name without permission. Oi! > word = u'something' > request_word = word.encode('utf-8') > request = ('%s+site:.edu' % request_word) > g = pygoogle(request) > g.get_result_count() > > Now, I realized that domain restriction works (site:.edu etc.), but I > would like to be able to control for language too. Is that possible > with the Pygoogle? If not, how can I make that happen? The library doesn't seem to have built-in support for filtering by language (and Google lacks a search query-string-based operator for that), but it looks like you could implement that feature by adding an "lr" parameter with an appropriate value to the query `args` dictionary. See the "lr?" entry under "Web Search Specific Arguments" on http://code.google.com/apis/websearch/docs/reference.html , and lines 68 & 102 of pygoogle.py. Cheers, Chris -- Research for random person => too much idle time http://blog.rebertia.com From rde at audaxis.com Thu Nov 18 03:29:00 2010 From: rde at audaxis.com (Romaric DEFAUX) Date: Thu, 18 Nov 2010 09:29:00 +0100 Subject: Pickle in a POST/GET request give EOFError In-Reply-To: References: <4CE2B599.7050504@audaxis.com> <4CE3EA61.2090707@audaxis.com> Message-ID: <4CE4E3CC.8080801@audaxis.com> Le 17/11/2010 18:52, geremy condra a ?crit : > On Wed, Nov 17, 2010 at 6:44 AM, Romaric DEFAUX wrote: > >> Le 16/11/2010 17:47, Romaric DEFAUX a ?crit : >> >>> Hi everybody ! >>> >>> First time I write to this mailing list :) >>> I started writing in python last week, that's probably why I can't >>> understand the following problem... >>> >>> >>> I create a list called web_site_list. >>> This list contain dictionaries called web_site. >>> And some values in this dictionaries are list too. >>> >>> I do that in a function and I return this : >>> return pickle.dumps(web_site_list) >>> >>> This is working fine :) >>> >>> If I do : >>> print "%s" % pickle.loads(system.get_web_site_list()) >>> >>> I've got the right stuffs. For example it returns : >>> [{'documentroot_size': '120', 'servername': '---default---', 'client': >>> 'undefined', 'documentroot': '/var/www/', 'client_contact': 'undefined', >>> 'serveralias': []}] >>> >>> I send this to a web service. I send it like that : >>> #I put it in params >>> def system_updateweb_site(server, login, password): >>> params = {} >>> params['login'] = login >>> params['password'] = password >>> params['action'] = 'updateweb_site' >>> params['servername'] = get_servername() >>> params['hosted_web_site'] = get_web_site_list() >>> return call_system_ws(server, params) >>> >>> #Here's how I send it (I tried in GET and POST) >>> def call_system_ws(host, params): >>> query_string = urllib.urlencode(params) >>> #GET >>> # f = urllib.urlopen("http://%s/ws?%s" % (host, query_string)) >>> #POST >>> f = urllib.urlopen("http://%s/ws" % (host), query_string) >>> result = f.readline().strip() >>> if result == 'ERROR': >>> msg = f.readline().strip() >>> return (False, msg) >>> return (True, result) >>> >>> >>> On the server side : >>> if action == 'updateweb_site': >>> if not (fields.has_key('servername') and >>> fields.has_key('hosted_web_site')): >>> raise WSError('missing parameter : >>> servername or hosted_web_site') >>> log ('ERROR : missing parameter : >>> servername or hosted_web_site') >>> else: >>> >>> servername=g.db.escape_string(fields['servername']) >>> >>> hosted_web_site=g.db.escape_string(fields['hosted_web_site']) >>> output = >>> systemserver.updateweb_site(cursor, servername, hosted_web_site) >>> >>> In systemserver.py : >>> def updateweb_site(cursor, host, hosted_web_site): >>> web_site_list = pickle.loads(hosted_web_site) >>> return "%s" % (web_site_list) >>> >>> I catch this error :* >>> >>> *: >>> >>> args = () >>> message = '' >>> >>> Why ? >>> >>> If I just print hosted_web_site, I get this on my web page : >>> >>> >>> (lp0\n(dp1\nS\'documentroot_size\'\np2\nS\'120\'\np3\nsS\'servername\'\np4\nS\'default\'\np5\nsS\'client\'\np6\nS\'undefined\'\np7\nsS\'documentroot\'\np8\nS\'/var/www/\'\np9\nsS\'client_contact\'\np10\ng7\nsS\'serveralias\'\np11\n(lp12\nsa. >>> >>> It's the "pickled view" of >>> [{'documentroot_size': '120', 'servername': '---default---', 'client': >>> 'undefined', 'documentroot': '/var/www/', 'client_contact': 'undefined', >>> 'serveralias': []}] >>> >>> Can someone help me please ? I spend my afternoon to google to try to find >>> a solution... >>> >>> >>> Thanks in advance !!! >>> >>> Romaric Defaux >>> >>> >> After entirely rewrite my code to not use Web service but socket (a real >> client/server program) I finally found the problem... And it's not linked to >> the POST or GET method... >> It's because of that : >> g.db.escape_string(fields['hosted_web_site']) >> (escape_string is the function in MySQLdb library) >> It escapes the simple quote of the pickled object, and break it... >> >> It's good to know, NEVER escape a pickled object :) >> >> Romaric Defaux >> > I'm not sure I understand what you're doing here, but I trust you've > read about and understand the security problems with pickle? > > Geremy Condra > I read quickly the security problems with pickle. But I don't feel concern about that because I run my program in a private network, not over internet. And now I use socket to communicate on a non-standard port, not anymore web service on the 80 port. If I plan to run it through wan, I will encrypt datas for sure with SSL or something like that :) Romaric Defaux -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 5361 bytes Desc: S/MIME Cryptographic Signature URL: From michael.ricordeau at gmail.com Thu Nov 18 03:43:47 2010 From: michael.ricordeau at gmail.com (Michael Ricordeau) Date: Thu, 18 Nov 2010 09:43:47 +0100 Subject: Pickle in a POST/GET request give EOFError In-Reply-To: <4CE4E3CC.8080801@audaxis.com> References: <4CE2B599.7050504@audaxis.com> <4CE3EA61.2090707@audaxis.com> <4CE4E3CC.8080801@audaxis.com> Message-ID: <20101118094347.53a0980a@moriz.interne> Hi, you can use json for passing list and dict . Pickle is dangerous . Instead of pickle.loads/pickle.dumps use json.loads and json.dumps (using stdlib json in python >= 2.6 or simplejson in python < 2.6) Regards Le Thu, 18 Nov 2010 09:29:00 +0100, Romaric DEFAUX a ?crit : > Le 17/11/2010 18:52, geremy condra a ?crit : > > On Wed, Nov 17, 2010 at 6:44 AM, Romaric DEFAUX wrote: > > > >> Le 16/11/2010 17:47, Romaric DEFAUX a ?crit : > >> > >>> Hi everybody ! > >>> > >>> First time I write to this mailing list :) > >>> I started writing in python last week, that's probably why I can't > >>> understand the following problem... > >>> > >>> > >>> I create a list called web_site_list. > >>> This list contain dictionaries called web_site. > >>> And some values in this dictionaries are list too. > >>> > >>> I do that in a function and I return this : > >>> return pickle.dumps(web_site_list) > >>> > >>> This is working fine :) > >>> > >>> If I do : > >>> print "%s" % pickle.loads(system.get_web_site_list()) > >>> > >>> I've got the right stuffs. For example it returns : > >>> [{'documentroot_size': '120', 'servername': '---default---', 'client': > >>> 'undefined', 'documentroot': '/var/www/', 'client_contact': 'undefined', > >>> 'serveralias': []}] > >>> > >>> I send this to a web service. I send it like that : > >>> #I put it in params > >>> def system_updateweb_site(server, login, password): > >>> params = {} > >>> params['login'] = login > >>> params['password'] = password > >>> params['action'] = 'updateweb_site' > >>> params['servername'] = get_servername() > >>> params['hosted_web_site'] = get_web_site_list() > >>> return call_system_ws(server, params) > >>> > >>> #Here's how I send it (I tried in GET and POST) > >>> def call_system_ws(host, params): > >>> query_string = urllib.urlencode(params) > >>> #GET > >>> # f = urllib.urlopen("http://%s/ws?%s" % (host, query_string)) > >>> #POST > >>> f = urllib.urlopen("http://%s/ws" % (host), query_string) > >>> result = f.readline().strip() > >>> if result == 'ERROR': > >>> msg = f.readline().strip() > >>> return (False, msg) > >>> return (True, result) > >>> > >>> > >>> On the server side : > >>> if action == 'updateweb_site': > >>> if not (fields.has_key('servername') and > >>> fields.has_key('hosted_web_site')): > >>> raise WSError('missing parameter : > >>> servername or hosted_web_site') > >>> log ('ERROR : missing parameter : > >>> servername or hosted_web_site') > >>> else: > >>> > >>> servername=g.db.escape_string(fields['servername']) > >>> > >>> hosted_web_site=g.db.escape_string(fields['hosted_web_site']) > >>> output = > >>> systemserver.updateweb_site(cursor, servername, hosted_web_site) > >>> > >>> In systemserver.py : > >>> def updateweb_site(cursor, host, hosted_web_site): > >>> web_site_list = pickle.loads(hosted_web_site) > >>> return "%s" % (web_site_list) > >>> > >>> I catch this error :* > >>> > >>> *: > >>> > >>> args = () > >>> message = '' > >>> > >>> Why ? > >>> > >>> If I just print hosted_web_site, I get this on my web page : > >>> > >>> > >>> (lp0\n(dp1\nS\'documentroot_size\'\np2\nS\'120\'\np3\nsS\'servername\'\np4\nS\'default\'\np5\nsS\'client\'\np6\nS\'undefined\'\np7\nsS\'documentroot\'\np8\nS\'/var/www/\'\np9\nsS\'client_contact\'\np10\ng7\nsS\'serveralias\'\np11\n(lp12\nsa. > >>> > >>> It's the "pickled view" of > >>> [{'documentroot_size': '120', 'servername': '---default---', 'client': > >>> 'undefined', 'documentroot': '/var/www/', 'client_contact': 'undefined', > >>> 'serveralias': []}] > >>> > >>> Can someone help me please ? I spend my afternoon to google to try to find > >>> a solution... > >>> > >>> > >>> Thanks in advance !!! > >>> > >>> Romaric Defaux > >>> > >>> > >> After entirely rewrite my code to not use Web service but socket (a real > >> client/server program) I finally found the problem... And it's not linked to > >> the POST or GET method... > >> It's because of that : > >> g.db.escape_string(fields['hosted_web_site']) > >> (escape_string is the function in MySQLdb library) > >> It escapes the simple quote of the pickled object, and break it... > >> > >> It's good to know, NEVER escape a pickled object :) > >> > >> Romaric Defaux > >> > > I'm not sure I understand what you're doing here, but I trust you've > > read about and understand the security problems with pickle? > > > > Geremy Condra > > > I read quickly the security problems with pickle. But I don't feel > concern about that because I run my program in a private network, not > over internet. And now I use socket to communicate on a non-standard > port, not anymore web service on the 80 port. If I plan to run it > through wan, I will encrypt datas for sure with SSL or something like > that :) > > Romaric Defaux > From huisky at gmail.com Thu Nov 18 03:54:06 2010 From: huisky at gmail.com (huisky) Date: Thu, 18 Nov 2010 00:54:06 -0800 (PST) Subject: How to read such file and sumarize the data? References: Message-ID: thank you Martin. You are right. But the elapsed time is also okay for me. And i would like to assume that the total CPU time equals to the number of CPUs multiply the elapsed time. As to the number you mentioned, it is the 'process id', so it will be no problem to identify each job. Huiksy On Nov 18, 12:38?am, Martin Gregorie wrote: > On Wed, 17 Nov 2010 13:45:58 -0800, huisky wrote: > > Say I have following log file, which records the code usage. I want to > > read this file and do the summarize how much total CPU time consumed for > > each user. > > Two points you should think about: > > - I don't think you can extract CPU time from this log: you can get > ? the process elapsed time and the number of CPUs each run has used, > ? but you can't calculate CPU time from those values since you don't > ? know how the process spent waiting for i/o etc. > > - is the first (numeric) part of the first field on the line a process id? > ? If it is, you can match start and stop messages on the value of the > ? first field provided that this value can never be shared by two > ? processes that are both running. If you can get simultaneous > ? duplicates, then you're out of luck because you'll never be able to > ? match up start and stop lines. > > > Is Python able to do so or say easy to achieve this?, anybody can give > > me some hints, appricate very much! > > Sure. There are two approaches possible: > - sort the log on the first two fields and then process it with Python > ? knowing that start and stop lines will be adjacent > > - use the first field as the key to an array and put the start time > ? and CPU count in that element. When a matching stop line is found > ? you, retrieve the array element, calculate and output or total the > ? usage figure for that run and delete the array element. > > -- > martin@ ? | Martin Gregorie > gregorie. | Essex, UK > org ? ? ? | From casevh at gmail.com Thu Nov 18 03:55:51 2010 From: casevh at gmail.com (casevh) Date: Thu, 18 Nov 2010 00:55:51 -0800 (PST) Subject: ANN: GMPY 1.14 and GMPY2 alpha1 released Message-ID: Everyone, I'm pleased to annouce the release of both a new production and experimental release of GMPY. GMPY is a wrapper for the MPIR or GMP multiple-precision arithmetic library. The experimental release (GMPY2) now includes support for the MPFR floating-point library. GMPY is available for download from: http://code.google.com/p/gmpy/ Production release ------------------ GMPY 1.14 is the updated stable release. A memory leak was fixed so it is highly recommended that all user upgrade to this version. In addition to a few other bug fixes, GMPY 1.14 is compatible with the changes to the hashing code in Python 3.2a4. The 64-bit Windows installer for Python 3.2 should only be used with 3.2a4 and later. Even though my primary development focus has shifted to GMPY2 (see below), GMPY 1.X will continue to receive bug and compatibility fixes. Experimental release -------------------- To simplify the codebase, allow for changes in the API, and support simultaneous installation, the development version has been renamed to GMPY2. The following is list of changes in GMPY2: In 2.0.0a0 ---------- * support for a mutable integer type "xmpz" * removal of random number functions * "xmpz" supports slices for setting/clearing bits * some methods have been renamed (scan1 -> bit_scan1) * support for Python prior to 2.6 has been removed * support for all division modes has been added * ceiling - round to +Infinity * floor - round to -Infinity * truncate - round to zero * 2exp - division by a power of 2 * support is_even() and is_odd() In 2.0.0a1 ---------- * support for the MPFR floating point library If you use GMPY regularly, please test GMPY2. There have been several requests asking for a mutable integer and I am curious if there are real-world performance improvements. Please report any issues! casevh From huisky at gmail.com Thu Nov 18 03:56:08 2010 From: huisky at gmail.com (huisky) Date: Thu, 18 Nov 2010 00:56:08 -0800 (PST) Subject: How to read such file and sumarize the data? References: Message-ID: the number before @ is the process id in the linux server and it is identical. So i do NOT think distinguish each job's starting and ending time is difficult in this case. Huisky On Nov 17, 11:38?pm, Tim Harig wrote: > On 2010-11-17, huisky wrote: > > > I want to read this file and do the summarize how much total CPU time > > consumed for each user. > > Is Python able to do so or say easy to achieve this?, anybody can give > > me some hints, appricate very much! > > The question is, is the information you want available in the data. > > > > > Example log file. > > ************************************************************************************** > > LSTC license server version 224 started at Sun Dec ?6 18:56:48 2009 > > using configuration file /usr/local/lstc/server_data > > xyz 15... at trofast3.marin.ntnu.no LS-DYNA_971 NCPU=1 started Sun Dec ?6 > > 18:57:40 > > 15... at trofast3.marin.ntnu.no completed Sun Dec ?6 19:42:55 > > xyz 15... at trofast3.marin.ntnu.no LS-DYNA_971 NCPU=2 started Sun Dec ?6 > > 20:17:02 > > 15... at trofast3.marin.ntnu.no completed Sun Dec ?6 20:26:03 > > xyz 18... at trofast2.marin.ntnu.no LS-DYNA_971 NCPU=1 started Sun Dec ?6 > > 21:01:17 > > 18... at trofast2.marin.ntnu.no completed Sun Dec ?6 21:01:28 > > tanhoi 5... at iimt-tanhoi-w.ivt.ntnu.no LS-DYNA_971 NCPU=1 started Mon > > Dec ?7 09:31:00 > > 5... at iimt-tanhoi-w.ivt.ntnu.no presumed dead Mon Dec ?7 10:36:48 > > sabril 18... at trofast2.marin.ntnu.no LS-DYNA_971 NCPU=2 started Mon > > Dec ?7 13:14:47 > > 18... at trofast2.marin.ntnu.no completed Mon Dec ?7 13:24:07 > > sabril 18... at trofast2.marin.ntnu.no LS-DYNA_971 NCPU=2 started Mon > > Dec ?7 14:21:34 > > sabril 18... at trofast2.marin.ntnu.no LS-DYNA_971 NCPU=2 started Mon > > Dec ?7 14:28:42 > > 18... at trofast2.marin.ntnu.no killed Mon Dec ?7 14:31:48 > > 18... at trofast2.marin.ntnu.no killed Mon Dec ?7 14:32:06 > > I see starts, completes, kills, and presumed deads. ?The question is can > the starts be matched to the completes and kills either from the numbers > before @ or from a combination of the address and NCPU. ?You will need to > figure out whether or not you want to count the presumed deads in your > calculations. > > Assuming that the starts and stops can be corrilated, it is a simple matter > of finding the pairs and using the datetime module to find the difference > in time between them. From huisky at gmail.com Thu Nov 18 04:13:47 2010 From: huisky at gmail.com (huisky) Date: Thu, 18 Nov 2010 01:13:47 -0800 (PST) Subject: How to read such file and sumarize the data? References: Message-ID: <16e5b5e2-9b5c-4533-ac17-5e828367df9b@r29g2000yqj.googlegroups.com> Thank you very much for your reply. I think you just count the total number of NCPU used for each user. And it does NOT show how much time used for each user. Huisky On Nov 18, 12:10?am, Steve Holden wrote: > On 11/17/2010 4:45 PM, huisky wrote:> Say I have following log file, which records the code usage. > > I want to read this file and do the summarize how much total CPU time > > consumed for each user. > > Is Python able to do so or say easy to achieve this?, anybody can give > > me some hints, appricate very much! > > > Example log file. > > ************************************************************************************** > > I'm assuming the following (unquoted) data is in file "data.txt": > > > > > LSTC license server version 224 started at Sun Dec ?6 18:56:48 2009 > > using configuration file /usr/local/lstc/server_data > > xyz 15... at trofast3.marin.ntnu.no LS-DYNA_971 NCPU=1 started Sun Dec ?6 > > 18:57:40 > > 15... at trofast3.marin.ntnu.no completed Sun Dec ?6 19:42:55 > > xyz 15... at trofast3.marin.ntnu.no LS-DYNA_971 NCPU=2 started Sun Dec ?6 > > 20:17:02 > > 15... at trofast3.marin.ntnu.no completed Sun Dec ?6 20:26:03 > > xyz 18... at trofast2.marin.ntnu.no LS-DYNA_971 NCPU=1 started Sun Dec ?6 > > 21:01:17 > > 18... at trofast2.marin.ntnu.no completed Sun Dec ?6 21:01:28 > > tanhoi 5... at iimt-tanhoi-w.ivt.ntnu.no LS-DYNA_971 NCPU=1 started Mon > > Dec ?7 09:31:00 > > 5... at iimt-tanhoi-w.ivt.ntnu.no presumed dead Mon Dec ?7 10:36:48 > > sabril 18... at trofast2.marin.ntnu.no LS-DYNA_971 NCPU=2 started Mon > > Dec ?7 13:14:47 > > 18... at trofast2.marin.ntnu.no completed Mon Dec ?7 13:24:07 > > sabril 18... at trofast2.marin.ntnu.no LS-DYNA_971 NCPU=2 started Mon > > Dec ?7 14:21:34 > > sabril 18... at trofast2.marin.ntnu.no LS-DYNA_971 NCPU=2 started Mon > > Dec ?7 14:28:42 > > 18... at trofast2.marin.ntnu.no killed Mon Dec ?7 14:31:48 > > 18... at trofast2.marin.ntnu.no killed Mon Dec ?7 14:32:06 > > The line wrapping being wrong shouldn't affect the logic. > > $ cat data.py > lines = open("data.txt").readlines() > from collections import defaultdict > c = defaultdict(int) > for line in lines: > ? ? ls = line.split() > ? ? if len(ls) > 3 and ls[3].startswith("NCPU="): > ? ? ? ? amt = int(ls[3][5:]) > ? ? ? ? c[ls[0]] += amt > for key, value in c.items(): > ? ? print key, ":", value > > $ python data.py > xyz : 4 > tanhoi : 1 > sabril : 6 > > regards > ?Steve > -- > Steve Holden ? ? ? ? ? +1 571 484 6266 ? +1 800 494 3119 > PyCon 2011 Atlanta March 9-17 ? ? ?http://us.pycon.org/ > See Python Video! ? ? ?http://python.mirocommunity.org/ > Holden Web LLC ? ? ? ? ? ? ? ?http://www.holdenweb.com/ From rde at audaxis.com Thu Nov 18 04:19:27 2010 From: rde at audaxis.com (Romaric DEFAUX) Date: Thu, 18 Nov 2010 10:19:27 +0100 Subject: Pickle in a POST/GET request give EOFError In-Reply-To: <20101118094347.53a0980a@moriz.interne> References: <4CE2B599.7050504@audaxis.com> <4CE3EA61.2090707@audaxis.com> <4CE4E3CC.8080801@audaxis.com> <20101118094347.53a0980a@moriz.interne> Message-ID: <4CE4EF9F.2050803@audaxis.com> Thanks for the tip, I'll do that :) Le 18/11/2010 09:43, Michael Ricordeau a ?crit : > Hi, > > you can use json for passing list and dict . > Pickle is dangerous . > > Instead of pickle.loads/pickle.dumps use json.loads and json.dumps > (using stdlib json in python>= 2.6 or simplejson in python< 2.6) > > Regards > > > > Le Thu, 18 Nov 2010 09:29:00 +0100, > Romaric DEFAUX a ?crit : > > >> Le 17/11/2010 18:52, geremy condra a ?crit : >> >>> On Wed, Nov 17, 2010 at 6:44 AM, Romaric DEFAUX wrote: >>> >>> >>>> Le 16/11/2010 17:47, Romaric DEFAUX a ?crit : >>>> >>>> >>>>> Hi everybody ! >>>>> >>>>> First time I write to this mailing list :) >>>>> I started writing in python last week, that's probably why I can't >>>>> understand the following problem... >>>>> >>>>> >>>>> I create a list called web_site_list. >>>>> This list contain dictionaries called web_site. >>>>> And some values in this dictionaries are list too. >>>>> >>>>> I do that in a function and I return this : >>>>> return pickle.dumps(web_site_list) >>>>> >>>>> This is working fine :) >>>>> >>>>> If I do : >>>>> print "%s" % pickle.loads(system.get_web_site_list()) >>>>> >>>>> I've got the right stuffs. For example it returns : >>>>> [{'documentroot_size': '120', 'servername': '---default---', 'client': >>>>> 'undefined', 'documentroot': '/var/www/', 'client_contact': 'undefined', >>>>> 'serveralias': []}] >>>>> >>>>> I send this to a web service. I send it like that : >>>>> #I put it in params >>>>> def system_updateweb_site(server, login, password): >>>>> params = {} >>>>> params['login'] = login >>>>> params['password'] = password >>>>> params['action'] = 'updateweb_site' >>>>> params['servername'] = get_servername() >>>>> params['hosted_web_site'] = get_web_site_list() >>>>> return call_system_ws(server, params) >>>>> >>>>> #Here's how I send it (I tried in GET and POST) >>>>> def call_system_ws(host, params): >>>>> query_string = urllib.urlencode(params) >>>>> #GET >>>>> # f = urllib.urlopen("http://%s/ws?%s" % (host, query_string)) >>>>> #POST >>>>> f = urllib.urlopen("http://%s/ws" % (host), query_string) >>>>> result = f.readline().strip() >>>>> if result == 'ERROR': >>>>> msg = f.readline().strip() >>>>> return (False, msg) >>>>> return (True, result) >>>>> >>>>> >>>>> On the server side : >>>>> if action == 'updateweb_site': >>>>> if not (fields.has_key('servername') and >>>>> fields.has_key('hosted_web_site')): >>>>> raise WSError('missing parameter : >>>>> servername or hosted_web_site') >>>>> log ('ERROR : missing parameter : >>>>> servername or hosted_web_site') >>>>> else: >>>>> >>>>> servername=g.db.escape_string(fields['servername']) >>>>> >>>>> hosted_web_site=g.db.escape_string(fields['hosted_web_site']) >>>>> output = >>>>> systemserver.updateweb_site(cursor, servername, hosted_web_site) >>>>> >>>>> In systemserver.py : >>>>> def updateweb_site(cursor, host, hosted_web_site): >>>>> web_site_list = pickle.loads(hosted_web_site) >>>>> return "%s" % (web_site_list) >>>>> >>>>> I catch this error :* >>>>> >>>>> *: >>>>> >>>>> args = () >>>>> message = '' >>>>> >>>>> Why ? >>>>> >>>>> If I just print hosted_web_site, I get this on my web page : >>>>> >>>>> >>>>> (lp0\n(dp1\nS\'documentroot_size\'\np2\nS\'120\'\np3\nsS\'servername\'\np4\nS\'default\'\np5\nsS\'client\'\np6\nS\'undefined\'\np7\nsS\'documentroot\'\np8\nS\'/var/www/\'\np9\nsS\'client_contact\'\np10\ng7\nsS\'serveralias\'\np11\n(lp12\nsa. >>>>> >>>>> It's the "pickled view" of >>>>> [{'documentroot_size': '120', 'servername': '---default---', 'client': >>>>> 'undefined', 'documentroot': '/var/www/', 'client_contact': 'undefined', >>>>> 'serveralias': []}] >>>>> >>>>> Can someone help me please ? I spend my afternoon to google to try to find >>>>> a solution... >>>>> >>>>> >>>>> Thanks in advance !!! >>>>> >>>>> Romaric Defaux >>>>> >>>>> >>>>> >>>> After entirely rewrite my code to not use Web service but socket (a real >>>> client/server program) I finally found the problem... And it's not linked to >>>> the POST or GET method... >>>> It's because of that : >>>> g.db.escape_string(fields['hosted_web_site']) >>>> (escape_string is the function in MySQLdb library) >>>> It escapes the simple quote of the pickled object, and break it... >>>> >>>> It's good to know, NEVER escape a pickled object :) >>>> >>>> Romaric Defaux >>>> >>>> >>> I'm not sure I understand what you're doing here, but I trust you've >>> read about and understand the security problems with pickle? >>> >>> Geremy Condra >>> >>> >> I read quickly the security problems with pickle. But I don't feel >> concern about that because I run my program in a private network, not >> over internet. And now I use socket to communicate on a non-standard >> port, not anymore web service on the 80 port. If I plan to run it >> through wan, I will encrypt datas for sure with SSL or something like >> that :) >> >> Romaric Defaux >> >> -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 5361 bytes Desc: S/MIME Cryptographic Signature URL: From mdw at distorted.org.uk Thu Nov 18 04:32:23 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 18 Nov 2010 09:32:23 +0000 Subject: Some syntactic sugar proposals References: <87mxp7gbdf.fsf.mdw@metalzone.distorted.org.uk> <4ce4b043$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87d3q3dljs.fsf.mdw@metalzone.distorted.org.uk> Steven D'Aprano writes: > On Wed, 17 Nov 2010 16:31:40 +0000, Mark Wooding wrote: > > > But I don't think that's the big problem with this proposal. The real > > problem is that it completely changes the evaluation rule for the > > conditional expression. (The evaluation rule is already pretty screwy: > > Python is consistently left-to-right -- except here.) > > Not quite... > > >>> 1+2*3 > 7 > >>> (1+2)*3 > 9 You're wrong. Python evaluates these left-to-right, as I said. Parentheses override operator associativity; they don't affect evaluation order at all. Consider: def say(x): print 'seen %s' % x return x print say(1) + say(2) * say(3) print (say(1) + say(2)) * say(3) Run this program and you get seen 1 seen 2 seen 3 7 seen 1 seen 2 seen 3 9 So definitely left-to-right. Translating into reverse-Polish, say with Dijkstra's shunting-yard algorithm, is enlightening: you get 1 2 3 * + for the first and 1 2 + 3 * for the second. This preserves evaluation order; indeed, this is a general property of the shunting-yard algorithm. Finally, I quote from the language reference (5.13 of the 2.5 version), just to show that (this time, at least) I'm not trying to impose unfamiliar terminology, and that Python is defined to behave like this and I'm not relying on implementation-specific details. Alas, it also highlights a genuine inconsistency, but one which might be considered tolerable. : 5.13 Evaluation order : ===================== : : Python evaluates expressions from left to right. Notice that while : evaluating an assignment, the right-hand side is evaluated before the : left-hand side. : : In the following lines, expressions will be evaluated in the : arithmetic order of their suffixes: : : expr1, expr2, expr3, expr4 : (expr1, expr2, expr3, expr4) : {expr1: expr2, expr3: expr4} : expr1 + expr2 * (expr3 - expr4) : func(expr1, expr2, *expr3, **expr4) : expr3, expr4 = expr1, expr2 So the above example is /explicitly/ dealt with in the language reference, if only you'd cared to look. > Not everything needs to be a one liner. If you need this, do it the old- > fashioned way: > > t = foo() > if not pred(t): t = default_value I already explained how to write it as a one-liner: t = (lambda y: y if pred(y) else default_value)(foo()) -- [mdw] From __peter__ at web.de Thu Nov 18 04:39:23 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 18 Nov 2010 10:39:23 +0100 Subject: String multi-replace References: Message-ID: Sorin Schwimmer wrote: > I have to eliminate diacritics in a fairly large file. > > Inspired by http://code.activestate.com/recipes/81330/, I came up with the > following code: Here's the unicode.translate()-based approach spelt out: http://effbot.org/zone/unicode-convert.htm Peter From clp2 at rebertia.com Thu Nov 18 05:05:13 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 18 Nov 2010 02:05:13 -0800 Subject: I have a question about JavaFit In-Reply-To: References: Message-ID: "We" are a technical discussion maillinglist. About a computer programming language. Named Python. An unrelated computer programming language which happens to be named "Java" also exists, but is not this mailinglist's topic of discussion. Some computer programmers personally consume a lot of coffee, but aside from that, as a group, this maillinglist's members have nothing to do with "Javalution Coffee Company" or their "JavaFit" coffee products. To put it simply, you're barking up entirely the wrong tree. How exactly were you led to believe that python-list at python.org had anything to do with JavaFit in the first place? Regards, Chris, random maillinglist subscriber On Tue, Nov 16, 2010 at 4:45 PM, Bill Fishbaugher wrote: > Hello, > > I was searching online to find more info about JavaFit and I came across your information. > > Can you tell me, are you still involved with JavaFit? If you are, how are things going for you? > > Please let me know. > > Sincerely, > Bill From rde at audaxis.com Thu Nov 18 05:22:30 2010 From: rde at audaxis.com (Romaric DEFAUX) Date: Thu, 18 Nov 2010 11:22:30 +0100 Subject: Pickle in a POST/GET request give EOFError In-Reply-To: <20101118094347.53a0980a@moriz.interne> References: <4CE2B599.7050504@audaxis.com> <4CE3EA61.2090707@audaxis.com> <4CE4E3CC.8080801@audaxis.com> <20101118094347.53a0980a@moriz.interne> Message-ID: <4CE4FE66.20904@audaxis.com> Hi again, I try simplejson, but I have a problem. (I just replace pickle everywhere by simplejson) Here's a test I did : # python Python 2.5.2 (r252:60911, Jan 20 2010, 21:48:48) [GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu3)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import simplejson >>> disk_list = [] >>> disk = {} >>> disk['name'] = "disk1" >>> disk['size'] = "52428800" >>> disk_list.append(disk) >>> print disk_list [{'name': 'disk1', 'size': '52428800'}] >>> disk = {} >>> disk['name'] = "disk2" >>> disk['size'] = "647648" >>> disk_list.append(disk) >>> print disk_list [{'name': 'disk1', 'size': '52428800'}, {'name': 'disk2', 'size': '647648'}] >>> disk_list_json = simplejson.dumps(disk_list) >>> print disk_list_json [{"name": "disk1", "size": "52428800"}, {"name": "disk2", "size": "647648"}] >>> disk_list2 = simplejson.loads(disk_list_json) >>> print disk_list2 [{u'name': u'disk1', u'size': u'52428800'}, {u'name': u'disk2', u'size': u'647648'}] >>> print repr(disk_list_json) '[{"name": "disk1", "size": "52428800"}, {"name": "disk2", "size": "647648"}]' Explanation : I "dumps" with json a list of dictionnaries into disk_list_json. When I "loads" it, I don't get my list of dictionnaries like before (see disk_list2). It adds "u" letter everywhere. Why ? Thanks for help ! Romaric Defaux Le 18/11/2010 09:43, Michael Ricordeau a ?crit : > Hi, > > you can use json for passing list and dict . > Pickle is dangerous . > > Instead of pickle.loads/pickle.dumps use json.loads and json.dumps > (using stdlib json in python>= 2.6 or simplejson in python< 2.6) > > Regards > > > > Le Thu, 18 Nov 2010 09:29:00 +0100, > Romaric DEFAUX a ?crit : > > >> Le 17/11/2010 18:52, geremy condra a ?crit : >> >>> On Wed, Nov 17, 2010 at 6:44 AM, Romaric DEFAUX wrote: >>> >>> >>>> Le 16/11/2010 17:47, Romaric DEFAUX a ?crit : >>>> >>>> >>>>> Hi everybody ! >>>>> >>>>> First time I write to this mailing list :) >>>>> I started writing in python last week, that's probably why I can't >>>>> understand the following problem... >>>>> >>>>> >>>>> I create a list called web_site_list. >>>>> This list contain dictionaries called web_site. >>>>> And some values in this dictionaries are list too. >>>>> >>>>> I do that in a function and I return this : >>>>> return pickle.dumps(web_site_list) >>>>> >>>>> This is working fine :) >>>>> >>>>> If I do : >>>>> print "%s" % pickle.loads(system.get_web_site_list()) >>>>> >>>>> I've got the right stuffs. For example it returns : >>>>> [{'documentroot_size': '120', 'servername': '---default---', 'client': >>>>> 'undefined', 'documentroot': '/var/www/', 'client_contact': 'undefined', >>>>> 'serveralias': []}] >>>>> >>>>> I send this to a web service. I send it like that : >>>>> #I put it in params >>>>> def system_updateweb_site(server, login, password): >>>>> params = {} >>>>> params['login'] = login >>>>> params['password'] = password >>>>> params['action'] = 'updateweb_site' >>>>> params['servername'] = get_servername() >>>>> params['hosted_web_site'] = get_web_site_list() >>>>> return call_system_ws(server, params) >>>>> >>>>> #Here's how I send it (I tried in GET and POST) >>>>> def call_system_ws(host, params): >>>>> query_string = urllib.urlencode(params) >>>>> #GET >>>>> # f = urllib.urlopen("http://%s/ws?%s" % (host, query_string)) >>>>> #POST >>>>> f = urllib.urlopen("http://%s/ws" % (host), query_string) >>>>> result = f.readline().strip() >>>>> if result == 'ERROR': >>>>> msg = f.readline().strip() >>>>> return (False, msg) >>>>> return (True, result) >>>>> >>>>> >>>>> On the server side : >>>>> if action == 'updateweb_site': >>>>> if not (fields.has_key('servername') and >>>>> fields.has_key('hosted_web_site')): >>>>> raise WSError('missing parameter : >>>>> servername or hosted_web_site') >>>>> log ('ERROR : missing parameter : >>>>> servername or hosted_web_site') >>>>> else: >>>>> >>>>> servername=g.db.escape_string(fields['servername']) >>>>> >>>>> hosted_web_site=g.db.escape_string(fields['hosted_web_site']) >>>>> output = >>>>> systemserver.updateweb_site(cursor, servername, hosted_web_site) >>>>> >>>>> In systemserver.py : >>>>> def updateweb_site(cursor, host, hosted_web_site): >>>>> web_site_list = pickle.loads(hosted_web_site) >>>>> return "%s" % (web_site_list) >>>>> >>>>> I catch this error :* >>>>> >>>>> *: >>>>> >>>>> args = () >>>>> message = '' >>>>> >>>>> Why ? >>>>> >>>>> If I just print hosted_web_site, I get this on my web page : >>>>> >>>>> >>>>> (lp0\n(dp1\nS\'documentroot_size\'\np2\nS\'120\'\np3\nsS\'servername\'\np4\nS\'default\'\np5\nsS\'client\'\np6\nS\'undefined\'\np7\nsS\'documentroot\'\np8\nS\'/var/www/\'\np9\nsS\'client_contact\'\np10\ng7\nsS\'serveralias\'\np11\n(lp12\nsa. >>>>> >>>>> It's the "pickled view" of >>>>> [{'documentroot_size': '120', 'servername': '---default---', 'client': >>>>> 'undefined', 'documentroot': '/var/www/', 'client_contact': 'undefined', >>>>> 'serveralias': []}] >>>>> >>>>> Can someone help me please ? I spend my afternoon to google to try to find >>>>> a solution... >>>>> >>>>> >>>>> Thanks in advance !!! >>>>> >>>>> Romaric Defaux >>>>> >>>>> >>>>> >>>> After entirely rewrite my code to not use Web service but socket (a real >>>> client/server program) I finally found the problem... And it's not linked to >>>> the POST or GET method... >>>> It's because of that : >>>> g.db.escape_string(fields['hosted_web_site']) >>>> (escape_string is the function in MySQLdb library) >>>> It escapes the simple quote of the pickled object, and break it... >>>> >>>> It's good to know, NEVER escape a pickled object :) >>>> >>>> Romaric Defaux >>>> >>>> >>> I'm not sure I understand what you're doing here, but I trust you've >>> read about and understand the security problems with pickle? >>> >>> Geremy Condra >>> >>> >> I read quickly the security problems with pickle. But I don't feel >> concern about that because I run my program in a private network, not >> over internet. And now I use socket to communicate on a non-standard >> port, not anymore web service on the 80 port. If I plan to run it >> through wan, I will encrypt datas for sure with SSL or something like >> that :) >> >> Romaric Defaux >> >> -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 5361 bytes Desc: S/MIME Cryptographic Signature URL: From michael.ricordeau at gmail.com Thu Nov 18 05:26:00 2010 From: michael.ricordeau at gmail.com (Michael Ricordeau) Date: Thu, 18 Nov 2010 11:26:00 +0100 Subject: Pickle in a POST/GET request give EOFError In-Reply-To: <4CE4FE66.20904@audaxis.com> References: <4CE2B599.7050504@audaxis.com> <4CE3EA61.2090707@audaxis.com> <4CE4E3CC.8080801@audaxis.com> <20101118094347.53a0980a@moriz.interne> <4CE4FE66.20904@audaxis.com> Message-ID: <20101118112600.4ea01146@moriz.interne> When loading from json datas with simplejson, strings are unicode . Le Thu, 18 Nov 2010 11:22:30 +0100, Romaric DEFAUX a ?crit : > Hi again, > > I try simplejson, but I have a problem. (I just replace pickle > everywhere by simplejson) > > Here's a test I did : > # python > Python 2.5.2 (r252:60911, Jan 20 2010, 21:48:48) > [GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu3)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import simplejson > >>> disk_list = [] > >>> disk = {} > >>> disk['name'] = "disk1" > >>> disk['size'] = "52428800" > >>> disk_list.append(disk) > >>> print disk_list > [{'name': 'disk1', 'size': '52428800'}] > >>> disk = {} > >>> disk['name'] = "disk2" > >>> disk['size'] = "647648" > >>> disk_list.append(disk) > >>> print disk_list > [{'name': 'disk1', 'size': '52428800'}, {'name': 'disk2', 'size': '647648'}] > >>> disk_list_json = simplejson.dumps(disk_list) > >>> print disk_list_json > [{"name": "disk1", "size": "52428800"}, {"name": "disk2", "size": "647648"}] > >>> disk_list2 = simplejson.loads(disk_list_json) > >>> print disk_list2 > [{u'name': u'disk1', u'size': u'52428800'}, {u'name': u'disk2', u'size': > u'647648'}] > >>> print repr(disk_list_json) > '[{"name": "disk1", "size": "52428800"}, {"name": "disk2", "size": > "647648"}]' > > Explanation : > I "dumps" with json a list of dictionnaries into disk_list_json. > When I "loads" it, I don't get my list of dictionnaries like before (see > disk_list2). It adds "u" letter everywhere. > Why ? > Thanks for help ! > > Romaric Defaux > > Le 18/11/2010 09:43, Michael Ricordeau a ?crit : > > Hi, > > > > you can use json for passing list and dict . > > Pickle is dangerous . > > > > Instead of pickle.loads/pickle.dumps use json.loads and json.dumps > > (using stdlib json in python>= 2.6 or simplejson in python< 2.6) > > > > Regards > > > > > > > > Le Thu, 18 Nov 2010 09:29:00 +0100, > > Romaric DEFAUX a ?crit : > > > > > >> Le 17/11/2010 18:52, geremy condra a ?crit : > >> > >>> On Wed, Nov 17, 2010 at 6:44 AM, Romaric DEFAUX wrote: > >>> > >>> > >>>> Le 16/11/2010 17:47, Romaric DEFAUX a ?crit : > >>>> > >>>> > >>>>> Hi everybody ! > >>>>> > >>>>> First time I write to this mailing list :) > >>>>> I started writing in python last week, that's probably why I can't > >>>>> understand the following problem... > >>>>> > >>>>> > >>>>> I create a list called web_site_list. > >>>>> This list contain dictionaries called web_site. > >>>>> And some values in this dictionaries are list too. > >>>>> > >>>>> I do that in a function and I return this : > >>>>> return pickle.dumps(web_site_list) > >>>>> > >>>>> This is working fine :) > >>>>> > >>>>> If I do : > >>>>> print "%s" % pickle.loads(system.get_web_site_list()) > >>>>> > >>>>> I've got the right stuffs. For example it returns : > >>>>> [{'documentroot_size': '120', 'servername': '---default---', 'client': > >>>>> 'undefined', 'documentroot': '/var/www/', 'client_contact': 'undefined', > >>>>> 'serveralias': []}] > >>>>> > >>>>> I send this to a web service. I send it like that : > >>>>> #I put it in params > >>>>> def system_updateweb_site(server, login, password): > >>>>> params = {} > >>>>> params['login'] = login > >>>>> params['password'] = password > >>>>> params['action'] = 'updateweb_site' > >>>>> params['servername'] = get_servername() > >>>>> params['hosted_web_site'] = get_web_site_list() > >>>>> return call_system_ws(server, params) > >>>>> > >>>>> #Here's how I send it (I tried in GET and POST) > >>>>> def call_system_ws(host, params): > >>>>> query_string = urllib.urlencode(params) > >>>>> #GET > >>>>> # f = urllib.urlopen("http://%s/ws?%s" % (host, query_string)) > >>>>> #POST > >>>>> f = urllib.urlopen("http://%s/ws" % (host), query_string) > >>>>> result = f.readline().strip() > >>>>> if result == 'ERROR': > >>>>> msg = f.readline().strip() > >>>>> return (False, msg) > >>>>> return (True, result) > >>>>> > >>>>> > >>>>> On the server side : > >>>>> if action == 'updateweb_site': > >>>>> if not (fields.has_key('servername') and > >>>>> fields.has_key('hosted_web_site')): > >>>>> raise WSError('missing parameter : > >>>>> servername or hosted_web_site') > >>>>> log ('ERROR : missing parameter : > >>>>> servername or hosted_web_site') > >>>>> else: > >>>>> > >>>>> servername=g.db.escape_string(fields['servername']) > >>>>> > >>>>> hosted_web_site=g.db.escape_string(fields['hosted_web_site']) > >>>>> output = > >>>>> systemserver.updateweb_site(cursor, servername, hosted_web_site) > >>>>> > >>>>> In systemserver.py : > >>>>> def updateweb_site(cursor, host, hosted_web_site): > >>>>> web_site_list = pickle.loads(hosted_web_site) > >>>>> return "%s" % (web_site_list) > >>>>> > >>>>> I catch this error :* > >>>>> > >>>>> *: > >>>>> > >>>>> args = () > >>>>> message = '' > >>>>> > >>>>> Why ? > >>>>> > >>>>> If I just print hosted_web_site, I get this on my web page : > >>>>> > >>>>> > >>>>> (lp0\n(dp1\nS\'documentroot_size\'\np2\nS\'120\'\np3\nsS\'servername\'\np4\nS\'default\'\np5\nsS\'client\'\np6\nS\'undefined\'\np7\nsS\'documentroot\'\np8\nS\'/var/www/\'\np9\nsS\'client_contact\'\np10\ng7\nsS\'serveralias\'\np11\n(lp12\nsa. > >>>>> > >>>>> It's the "pickled view" of > >>>>> [{'documentroot_size': '120', 'servername': '---default---', 'client': > >>>>> 'undefined', 'documentroot': '/var/www/', 'client_contact': 'undefined', > >>>>> 'serveralias': []}] > >>>>> > >>>>> Can someone help me please ? I spend my afternoon to google to try to find > >>>>> a solution... > >>>>> > >>>>> > >>>>> Thanks in advance !!! > >>>>> > >>>>> Romaric Defaux > >>>>> > >>>>> > >>>>> > >>>> After entirely rewrite my code to not use Web service but socket (a real > >>>> client/server program) I finally found the problem... And it's not linked to > >>>> the POST or GET method... > >>>> It's because of that : > >>>> g.db.escape_string(fields['hosted_web_site']) > >>>> (escape_string is the function in MySQLdb library) > >>>> It escapes the simple quote of the pickled object, and break it... > >>>> > >>>> It's good to know, NEVER escape a pickled object :) > >>>> > >>>> Romaric Defaux > >>>> > >>>> > >>> I'm not sure I understand what you're doing here, but I trust you've > >>> read about and understand the security problems with pickle? > >>> > >>> Geremy Condra > >>> > >>> > >> I read quickly the security problems with pickle. But I don't feel > >> concern about that because I run my program in a private network, not > >> over internet. And now I use socket to communicate on a non-standard > >> port, not anymore web service on the 80 port. If I plan to run it > >> through wan, I will encrypt datas for sure with SSL or something like > >> that :) > >> > >> Romaric Defaux > >> > >> > > From jeanmichel at sequans.com Thu Nov 18 05:50:39 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 18 Nov 2010 11:50:39 +0100 Subject: strange subprocess behavior when calling ps In-Reply-To: <1ed38051-9c8b-4ae8-9a88-9833209d2775@h21g2000vbh.googlegroups.com> References: <55f26d5c-aba9-4892-9e2c-1caa9988e7fe@v23g2000vbi.googlegroups.com> <1ed38051-9c8b-4ae8-9a88-9833209d2775@h21g2000vbh.googlegroups.com> Message-ID: <4CE504FF.2080709@sequans.com> Roger Davis wrote: >> Completely off topic but I think the try clause could be rewritten that way: >> ... >> Don't use bare except clause, you're masking syntax errors for instance, >> which will be flagged as 'unexpected error in generation ...". >> In a more general manner, if something unexpected happens it's better to >> just let the exception raise uncought. If you want to handle some >> errors, meaning you're kindof expecting them then add a explicit clause >> (like you did with KeyboardInterrupt). >> >> JM >> >> PS : "except Exception :" will catch most of the exceptions (all >> inheriting from that class). It's better than using a bare "except :" >> clause. (Exception won't catch SyntaxError) >> > > Thanks for the suggestion JM, it is off-topic and, although I will > first just say that the exception mechanism is *not* one of the > reasons I use Python (and stop there with regard to the whole > exception mechanism and various usage strategies in general), I do > have a few specific questions about a couple of your statements if you > don't mind following up. > > First, inserting a syntax error into my existing code does not hide a > SyntaxError exception as you have stated: > > % cat pid.py > #!/usr/bin/python > import os > import sys > import subprocess > > def main(): > > psargs= ["/bin/ps", "-e"] > try: > ps= subprocess.Popen(psargs, stdout=subprocess.PIPE, close_fds=True) > psout= ps.communicate()[0] > pslines= psout.splitlines() > if pslines not good Python talky-talk > for line in pslines: > print "%s" % line > except KeyboardInterrupt: > print "Keyboard interrupt received -- terminating." > sys.stdout.flush() > sys.exit(-1) > except: > print "%s: unexpected error in generation of system process list" % > prognm > sys.stdout.flush() > sys.exit(-1) > > main() > > % ./pid.py > File "./pid.py", line 14 > if pslines not good Python talky-talk > ^ > SyntaxError: invalid syntax > > It appears that the interpreter is catching the syntax error before > the code is even executed. > > That's right, 'cause my example is approximative. You would need to import that file. A better example would be to fire a NameError exception. In the above code of fix the syntax error, but replace "for line in pslines" by "for line in psLines". note the typo, very common mistake. Then see how the error is hidden by your handler. > Second, python.org's exception hierarchy documentation (Section 6.1 at > http://docs.python.org/library/exceptions.html) shows all exception > types except SystemExit, KeyboardInterrupt and GeneratorExit as being > descendants of Exception. This includes SyntaxError, a child of > StandardError which is itself a child of Exception. So, if I say > 'except Exception:' then isn't that clause going to process any child > exception type of Exception (including SyntaxError) that I haven't > already covered in a separate except clause? You're absolutely right. Using Exception is bad, using bare except is even worse. Exception is slightly better than except because you can at least get the exception instance that has been raised, print it in your handler, so you don't loose information (well, with a bare except you can still inspect some sys objects to get info about the last exception but it's a bit hackish). > (Except of course that my > interpreter doesn't seem to treat a syntax error as any kind of > exception at all!) > > Finally, and this does not apply to your comments in particular, in > researching around about exception handling I often see the usage > > except Exception, e: > > suggested, but can't for the life of me figure out what the heck the > ', e' part does. Can anybody explain what this means and why it might > be desirable (or not)? > > Thanks! > > > Exception is the class, e is an instance of that class that has been actually fired, it contains informations, most of the time a message. This syntax has changed in python 3 I think, that would mean that you're right to be confused, this python 2 syntax is ... strange... import sys # what if someone writes sys.hihi ? try: raise AttributeError("sys object has no attribute 'hihi'") except Exception, e: print e.args print e.__class__ print e.message print e.__doc__ output: ("sys object has no attribute 'hihi'",) sys object has no attribute 'hihi' Attribute not found. Apart from all these details, just keep in mind this golden rule: - Don't use bare except clause. And you'll be fine. JM From jeanmichel at sequans.com Thu Nov 18 06:02:04 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 18 Nov 2010 12:02:04 +0100 Subject: How to run an EXE, with argument, capture output value In-Reply-To: References: <37037d15-63da-4f37-9508-bdcfff034670@s4g2000yql.googlegroups.com> Message-ID: <4CE507AC.1030006@sequans.com> Tim Harig wrote: > On 2010-11-18, noydb wrote: > >> I have an executable that I want to run within python code. The exe >> requires an input text file, the user to click a 'compute' button, and >> then the exe calculates several output values, one of which I want to >> capture into a variable. Can I use Python to supply the input file, >> execute the exe and capture the output value, like such that the exe >> really doesn't need to be 'seen'? Or, would the user still have to >> click the 'compute' button? >> >> Any code snippets or guidance would be very much appreciated. I have >> found that >> >> import os >> os.system('C:\xTool\stats_hall.exe') >> >> will run the exe. And, maybe these execl/execle/execlp/etc functions >> might be what I need for adding in the argument, but documentation >> seems to indicate that these do not return output. ?? >> > > If you are not already, I would highly suggest using Python3 with the > subprocess module: > > http://docs.python.org/py3k/library/subprocess.html > > It puts everything in one place and supercedes the exec* functions which > where a PITA. You can 95% of what you need simply using > subprocess.Popen(). There are several examples from this group in the past > few days; but, the process looks something like this: > > Python 3.1.2 (r312:79147, Oct 9 2010, 00:16:06) > [GCC 4.4.4] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import subprocess > >>> pig = subprocess.Popen(["/usr/games/pig"], stdin=subprocess.PIPE) > >>> result = pig.communicate(input=b"This is sample text.\n") > Isthay isway amplesay exttay. > >>> > Suggesting subprocess is a good idea, *highly* suggesting python3 is questionable. The above code works in python 2. Many libraries (those included batteries) have not been ported yet to python 3. Py3 is a better core language than py2, but for now, less featured. JM From rde at audaxis.com Thu Nov 18 06:23:01 2010 From: rde at audaxis.com (Romaric DEFAUX) Date: Thu, 18 Nov 2010 12:23:01 +0100 Subject: Pickle in a POST/GET request give EOFError In-Reply-To: <20101118112600.4ea01146@moriz.interne> References: <4CE2B599.7050504@audaxis.com> <4CE3EA61.2090707@audaxis.com> <4CE4E3CC.8080801@audaxis.com> <20101118094347.53a0980a@moriz.interne> <4CE4FE66.20904@audaxis.com> <20101118112600.4ea01146@moriz.interne> Message-ID: <4CE50C95.4090407@audaxis.com> Sorry for this stupid question, but how can I convert unicode to string. I ask that because I hit an error (perhaps a bug) in mod_wsgi, and that crash the apache process : TypeError: sequence of string values expected, value of type unicode found RuntimeError: generator ignored GeneratorExit child pid 16211 exit signal Segmentation fault (11) Romaric Defaux Le 18/11/2010 11:26, Michael Ricordeau a ?crit : > When loading from json datas with simplejson, strings are unicode . > > > Le Thu, 18 Nov 2010 11:22:30 +0100, > Romaric DEFAUX a ?crit : > > >> Hi again, >> >> I try simplejson, but I have a problem. (I just replace pickle >> everywhere by simplejson) >> >> Here's a test I did : >> # python >> Python 2.5.2 (r252:60911, Jan 20 2010, 21:48:48) >> [GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu3)] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. >> >>> import simplejson >> >>> disk_list = [] >> >>> disk = {} >> >>> disk['name'] = "disk1" >> >>> disk['size'] = "52428800" >> >>> disk_list.append(disk) >> >>> print disk_list >> [{'name': 'disk1', 'size': '52428800'}] >> >>> disk = {} >> >>> disk['name'] = "disk2" >> >>> disk['size'] = "647648" >> >>> disk_list.append(disk) >> >>> print disk_list >> [{'name': 'disk1', 'size': '52428800'}, {'name': 'disk2', 'size': '647648'}] >> >>> disk_list_json = simplejson.dumps(disk_list) >> >>> print disk_list_json >> [{"name": "disk1", "size": "52428800"}, {"name": "disk2", "size": "647648"}] >> >>> disk_list2 = simplejson.loads(disk_list_json) >> >>> print disk_list2 >> [{u'name': u'disk1', u'size': u'52428800'}, {u'name': u'disk2', u'size': >> u'647648'}] >> >>> print repr(disk_list_json) >> '[{"name": "disk1", "size": "52428800"}, {"name": "disk2", "size": >> "647648"}]' >> >> Explanation : >> I "dumps" with json a list of dictionnaries into disk_list_json. >> When I "loads" it, I don't get my list of dictionnaries like before (see >> disk_list2). It adds "u" letter everywhere. >> Why ? >> Thanks for help ! >> >> Romaric Defaux >> >> Le 18/11/2010 09:43, Michael Ricordeau a ?crit : >> >>> Hi, >>> >>> you can use json for passing list and dict . >>> Pickle is dangerous . >>> >>> Instead of pickle.loads/pickle.dumps use json.loads and json.dumps >>> (using stdlib json in python>= 2.6 or simplejson in python< 2.6) >>> >>> Regards >>> >>> >>> >>> Le Thu, 18 Nov 2010 09:29:00 +0100, >>> Romaric DEFAUX a ?crit : >>> >>> >>> >>>> Le 17/11/2010 18:52, geremy condra a ?crit : >>>> >>>> >>>>> On Wed, Nov 17, 2010 at 6:44 AM, Romaric DEFAUX wrote: >>>>> >>>>> >>>>> >>>>>> Le 16/11/2010 17:47, Romaric DEFAUX a ?crit : >>>>>> >>>>>> >>>>>> >>>>>>> Hi everybody ! >>>>>>> >>>>>>> First time I write to this mailing list :) >>>>>>> I started writing in python last week, that's probably why I can't >>>>>>> understand the following problem... >>>>>>> >>>>>>> >>>>>>> I create a list called web_site_list. >>>>>>> This list contain dictionaries called web_site. >>>>>>> And some values in this dictionaries are list too. >>>>>>> >>>>>>> I do that in a function and I return this : >>>>>>> return pickle.dumps(web_site_list) >>>>>>> >>>>>>> This is working fine :) >>>>>>> >>>>>>> If I do : >>>>>>> print "%s" % pickle.loads(system.get_web_site_list()) >>>>>>> >>>>>>> I've got the right stuffs. For example it returns : >>>>>>> [{'documentroot_size': '120', 'servername': '---default---', 'client': >>>>>>> 'undefined', 'documentroot': '/var/www/', 'client_contact': 'undefined', >>>>>>> 'serveralias': []}] >>>>>>> >>>>>>> I send this to a web service. I send it like that : >>>>>>> #I put it in params >>>>>>> def system_updateweb_site(server, login, password): >>>>>>> params = {} >>>>>>> params['login'] = login >>>>>>> params['password'] = password >>>>>>> params['action'] = 'updateweb_site' >>>>>>> params['servername'] = get_servername() >>>>>>> params['hosted_web_site'] = get_web_site_list() >>>>>>> return call_system_ws(server, params) >>>>>>> >>>>>>> #Here's how I send it (I tried in GET and POST) >>>>>>> def call_system_ws(host, params): >>>>>>> query_string = urllib.urlencode(params) >>>>>>> #GET >>>>>>> # f = urllib.urlopen("http://%s/ws?%s" % (host, query_string)) >>>>>>> #POST >>>>>>> f = urllib.urlopen("http://%s/ws" % (host), query_string) >>>>>>> result = f.readline().strip() >>>>>>> if result == 'ERROR': >>>>>>> msg = f.readline().strip() >>>>>>> return (False, msg) >>>>>>> return (True, result) >>>>>>> >>>>>>> >>>>>>> On the server side : >>>>>>> if action == 'updateweb_site': >>>>>>> if not (fields.has_key('servername') and >>>>>>> fields.has_key('hosted_web_site')): >>>>>>> raise WSError('missing parameter : >>>>>>> servername or hosted_web_site') >>>>>>> log ('ERROR : missing parameter : >>>>>>> servername or hosted_web_site') >>>>>>> else: >>>>>>> >>>>>>> servername=g.db.escape_string(fields['servername']) >>>>>>> >>>>>>> hosted_web_site=g.db.escape_string(fields['hosted_web_site']) >>>>>>> output = >>>>>>> systemserver.updateweb_site(cursor, servername, hosted_web_site) >>>>>>> >>>>>>> In systemserver.py : >>>>>>> def updateweb_site(cursor, host, hosted_web_site): >>>>>>> web_site_list = pickle.loads(hosted_web_site) >>>>>>> return "%s" % (web_site_list) >>>>>>> >>>>>>> I catch this error :* >>>>>>> >>>>>>> *: >>>>>>> >>>>>>> args = () >>>>>>> message = '' >>>>>>> >>>>>>> Why ? >>>>>>> >>>>>>> If I just print hosted_web_site, I get this on my web page : >>>>>>> >>>>>>> >>>>>>> (lp0\n(dp1\nS\'documentroot_size\'\np2\nS\'120\'\np3\nsS\'servername\'\np4\nS\'default\'\np5\nsS\'client\'\np6\nS\'undefined\'\np7\nsS\'documentroot\'\np8\nS\'/var/www/\'\np9\nsS\'client_contact\'\np10\ng7\nsS\'serveralias\'\np11\n(lp12\nsa. >>>>>>> >>>>>>> It's the "pickled view" of >>>>>>> [{'documentroot_size': '120', 'servername': '---default---', 'client': >>>>>>> 'undefined', 'documentroot': '/var/www/', 'client_contact': 'undefined', >>>>>>> 'serveralias': []}] >>>>>>> >>>>>>> Can someone help me please ? I spend my afternoon to google to try to find >>>>>>> a solution... >>>>>>> >>>>>>> >>>>>>> Thanks in advance !!! >>>>>>> >>>>>>> Romaric Defaux >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>> After entirely rewrite my code to not use Web service but socket (a real >>>>>> client/server program) I finally found the problem... And it's not linked to >>>>>> the POST or GET method... >>>>>> It's because of that : >>>>>> g.db.escape_string(fields['hosted_web_site']) >>>>>> (escape_string is the function in MySQLdb library) >>>>>> It escapes the simple quote of the pickled object, and break it... >>>>>> >>>>>> It's good to know, NEVER escape a pickled object :) >>>>>> >>>>>> Romaric Defaux >>>>>> >>>>>> >>>>>> >>>>> I'm not sure I understand what you're doing here, but I trust you've >>>>> read about and understand the security problems with pickle? >>>>> >>>>> Geremy Condra >>>>> >>>>> >>>>> >>>> I read quickly the security problems with pickle. But I don't feel >>>> concern about that because I run my program in a private network, not >>>> over internet. And now I use socket to communicate on a non-standard >>>> port, not anymore web service on the 80 port. If I plan to run it >>>> through wan, I will encrypt datas for sure with SSL or something like >>>> that :) >>>> >>>> Romaric Defaux >>>> >>>> >>>> >> >> -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 5361 bytes Desc: S/MIME Cryptographic Signature URL: From pmilin at gmail.com Thu Nov 18 06:26:14 2010 From: pmilin at gmail.com (neocortex) Date: Thu, 18 Nov 2010 03:26:14 -0800 (PST) Subject: Does Pygoogle allows for advanced search options? References: Message-ID: <706ff3ad-66b4-4cdb-a68f-bf0a079c2dc1@32g2000yqz.googlegroups.com> > The library doesn't seem to have built-in support for filtering by > language (and Google lacks a search query-string-based operator for > that), but it looks like you could implement that feature by adding an > "lr" parameter with an appropriate value to the query `args` > dictionary. See the "lr?" entry under "Web Search Specific Arguments" > onhttp://code.google.com/apis/websearch/docs/reference.html, and > lines 68 & 102 of pygoogle.py. >From those lines, it can be concluded that lr=lang_?? is not supported, unfortunately. And, when I execute, I get an error. Is there any other way to get Google search from Python? I really need only number of hits. Best, PM From rde at audaxis.com Thu Nov 18 06:27:32 2010 From: rde at audaxis.com (Romaric DEFAUX) Date: Thu, 18 Nov 2010 12:27:32 +0100 Subject: Pickle in a POST/GET request give EOFError In-Reply-To: <4CE50C95.4090407@audaxis.com> References: <4CE2B599.7050504@audaxis.com> <4CE3EA61.2090707@audaxis.com> <4CE4E3CC.8080801@audaxis.com> <20101118094347.53a0980a@moriz.interne> <4CE4FE66.20904@audaxis.com> <20101118112600.4ea01146@moriz.interne> <4CE50C95.4090407@audaxis.com> Message-ID: <4CE50DA4.50806@audaxis.com> Hi answer to myself :) With str(unicode_string) ! Le 18/11/2010 12:23, Romaric DEFAUX a ?crit : > Sorry for this stupid question, but how can I convert unicode to string. > I ask that because I hit an error (perhaps a bug) in mod_wsgi, and > that crash the apache process : > > TypeError: sequence of string values expected, value of type unicode > found > RuntimeError: generator ignored GeneratorExit > child pid 16211 exit signal Segmentation fault (11) > > Romaric Defaux > > Le 18/11/2010 11:26, Michael Ricordeau a ?crit : >> When loading from json datas with simplejson, strings are unicode . >> >> >> Le Thu, 18 Nov 2010 11:22:30 +0100, >> Romaric DEFAUX a ?crit : >> >>> Hi again, >>> >>> I try simplejson, but I have a problem. (I just replace pickle >>> everywhere by simplejson) >>> >>> Here's a test I did : >>> # python >>> Python 2.5.2 (r252:60911, Jan 20 2010, 21:48:48) >>> [GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu3)] on linux2 >>> Type "help", "copyright", "credits" or "license" for more information. >>> >>> import simplejson >>> >>> disk_list = [] >>> >>> disk = {} >>> >>> disk['name'] = "disk1" >>> >>> disk['size'] = "52428800" >>> >>> disk_list.append(disk) >>> >>> print disk_list >>> [{'name': 'disk1', 'size': '52428800'}] >>> >>> disk = {} >>> >>> disk['name'] = "disk2" >>> >>> disk['size'] = "647648" >>> >>> disk_list.append(disk) >>> >>> print disk_list >>> [{'name': 'disk1', 'size': '52428800'}, {'name': 'disk2', 'size': >>> '647648'}] >>> >>> disk_list_json = simplejson.dumps(disk_list) >>> >>> print disk_list_json >>> [{"name": "disk1", "size": "52428800"}, {"name": "disk2", "size": >>> "647648"}] >>> >>> disk_list2 = simplejson.loads(disk_list_json) >>> >>> print disk_list2 >>> [{u'name': u'disk1', u'size': u'52428800'}, {u'name': u'disk2', >>> u'size': >>> u'647648'}] >>> >>> print repr(disk_list_json) >>> '[{"name": "disk1", "size": "52428800"}, {"name": "disk2", "size": >>> "647648"}]' >>> >>> Explanation : >>> I "dumps" with json a list of dictionnaries into disk_list_json. >>> When I "loads" it, I don't get my list of dictionnaries like before >>> (see >>> disk_list2). It adds "u" letter everywhere. >>> Why ? >>> Thanks for help ! >>> >>> Romaric Defaux >>> >>> Le 18/11/2010 09:43, Michael Ricordeau a ?crit : >>>> Hi, >>>> >>>> you can use json for passing list and dict . >>>> Pickle is dangerous . >>>> >>>> Instead of pickle.loads/pickle.dumps use json.loads and json.dumps >>>> (using stdlib json in python>= 2.6 or simplejson in python< 2.6) >>>> >>>> Regards >>>> >>>> >>>> >>>> Le Thu, 18 Nov 2010 09:29:00 +0100, >>>> Romaric DEFAUX a ?crit : >>>> >>>> >>>>> Le 17/11/2010 18:52, geremy condra a ?crit : >>>>> >>>>>> On Wed, Nov 17, 2010 at 6:44 AM, Romaric >>>>>> DEFAUX wrote: >>>>>> >>>>>> >>>>>>> Le 16/11/2010 17:47, Romaric DEFAUX a ?crit : >>>>>>> >>>>>>> >>>>>>>> Hi everybody ! >>>>>>>> >>>>>>>> First time I write to this mailing list :) >>>>>>>> I started writing in python last week, that's probably why I can't >>>>>>>> understand the following problem... >>>>>>>> >>>>>>>> >>>>>>>> I create a list called web_site_list. >>>>>>>> This list contain dictionaries called web_site. >>>>>>>> And some values in this dictionaries are list too. >>>>>>>> >>>>>>>> I do that in a function and I return this : >>>>>>>> return pickle.dumps(web_site_list) >>>>>>>> >>>>>>>> This is working fine :) >>>>>>>> >>>>>>>> If I do : >>>>>>>> print "%s" % pickle.loads(system.get_web_site_list()) >>>>>>>> >>>>>>>> I've got the right stuffs. For example it returns : >>>>>>>> [{'documentroot_size': '120', 'servername': '---default---', >>>>>>>> 'client': >>>>>>>> 'undefined', 'documentroot': '/var/www/', 'client_contact': >>>>>>>> 'undefined', >>>>>>>> 'serveralias': []}] >>>>>>>> >>>>>>>> I send this to a web service. I send it like that : >>>>>>>> #I put it in params >>>>>>>> def system_updateweb_site(server, login, password): >>>>>>>> params = {} >>>>>>>> params['login'] = login >>>>>>>> params['password'] = password >>>>>>>> params['action'] = 'updateweb_site' >>>>>>>> params['servername'] = get_servername() >>>>>>>> params['hosted_web_site'] = get_web_site_list() >>>>>>>> return call_system_ws(server, params) >>>>>>>> >>>>>>>> #Here's how I send it (I tried in GET and POST) >>>>>>>> def call_system_ws(host, params): >>>>>>>> query_string = urllib.urlencode(params) >>>>>>>> #GET >>>>>>>> # f = urllib.urlopen("http://%s/ws?%s" % (host, >>>>>>>> query_string)) >>>>>>>> #POST >>>>>>>> f = urllib.urlopen("http://%s/ws" % (host), >>>>>>>> query_string) >>>>>>>> result = f.readline().strip() >>>>>>>> if result == 'ERROR': >>>>>>>> msg = f.readline().strip() >>>>>>>> return (False, msg) >>>>>>>> return (True, result) >>>>>>>> >>>>>>>> >>>>>>>> On the server side : >>>>>>>> if action == 'updateweb_site': >>>>>>>> if not >>>>>>>> (fields.has_key('servername') and >>>>>>>> fields.has_key('hosted_web_site')): >>>>>>>> raise >>>>>>>> WSError('missing parameter : >>>>>>>> servername or hosted_web_site') >>>>>>>> log ('ERROR : missing >>>>>>>> parameter : >>>>>>>> servername or hosted_web_site') >>>>>>>> else: >>>>>>>> >>>>>>>> servername=g.db.escape_string(fields['servername']) >>>>>>>> >>>>>>>> hosted_web_site=g.db.escape_string(fields['hosted_web_site']) >>>>>>>> output = >>>>>>>> systemserver.updateweb_site(cursor, servername, hosted_web_site) >>>>>>>> >>>>>>>> In systemserver.py : >>>>>>>> def updateweb_site(cursor, host, hosted_web_site): >>>>>>>> web_site_list = pickle.loads(hosted_web_site) >>>>>>>> return "%s" % (web_site_list) >>>>>>>> >>>>>>>> I catch this error :* >>>>>>>> >>>>>>>> *: >>>>>>>> >>>>>>>> args = () >>>>>>>> message = '' >>>>>>>> >>>>>>>> Why ? >>>>>>>> >>>>>>>> If I just print hosted_web_site, I get this on my web page : >>>>>>>> >>>>>>>> >>>>>>>> (lp0\n(dp1\nS\'documentroot_size\'\np2\nS\'120\'\np3\nsS\'servername\'\np4\nS\'default\'\np5\nsS\'client\'\np6\nS\'undefined\'\np7\nsS\'documentroot\'\np8\nS\'/var/www/\'\np9\nsS\'client_contact\'\np10\ng7\nsS\'serveralias\'\np11\n(lp12\nsa. >>>>>>>> >>>>>>>> >>>>>>>> It's the "pickled view" of >>>>>>>> [{'documentroot_size': '120', 'servername': '---default---', >>>>>>>> 'client': >>>>>>>> 'undefined', 'documentroot': '/var/www/', 'client_contact': >>>>>>>> 'undefined', >>>>>>>> 'serveralias': []}] >>>>>>>> >>>>>>>> Can someone help me please ? I spend my afternoon to google to >>>>>>>> try to find >>>>>>>> a solution... >>>>>>>> >>>>>>>> >>>>>>>> Thanks in advance !!! >>>>>>>> >>>>>>>> Romaric Defaux >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>> After entirely rewrite my code to not use Web service but socket >>>>>>> (a real >>>>>>> client/server program) I finally found the problem... And it's >>>>>>> not linked to >>>>>>> the POST or GET method... >>>>>>> It's because of that : >>>>>>> g.db.escape_string(fields['hosted_web_site']) >>>>>>> (escape_string is the function in MySQLdb library) >>>>>>> It escapes the simple quote of the pickled object, and break it... >>>>>>> >>>>>>> It's good to know, NEVER escape a pickled object :) >>>>>>> >>>>>>> Romaric Defaux >>>>>>> >>>>>>> >>>>>> I'm not sure I understand what you're doing here, but I trust you've >>>>>> read about and understand the security problems with pickle? >>>>>> >>>>>> Geremy Condra >>>>>> >>>>>> >>>>> I read quickly the security problems with pickle. But I don't feel >>>>> concern about that because I run my program in a private network, not >>>>> over internet. And now I use socket to communicate on a non-standard >>>>> port, not anymore web service on the 80 port. If I plan to run it >>>>> through wan, I will encrypt datas for sure with SSL or something like >>>>> that :) >>>>> >>>>> Romaric Defaux >>>>> >>>>> >>> > -- Romaric Defaux Administrateur Syst?mes et R?seaux Audaxis +33.820 00 70 70 -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 5361 bytes Desc: S/MIME Cryptographic Signature URL: From python at mrabarnett.plus.com Thu Nov 18 06:41:40 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 18 Nov 2010 11:41:40 +0000 Subject: String multi-replace In-Reply-To: References: <114148.34295.qm@web56007.mail.re3.yahoo.com> Message-ID: <4CE510F4.9020209@mrabarnett.plus.com> On 18/11/2010 04:30, Benjamin Kaplan wrote: > On Wed, Nov 17, 2010 at 11:21 PM, Sorin Schwimmer wrote: >> Hi All, >> >> I have to eliminate diacritics in a fairly large file. >> >> Inspired by http://code.activestate.com/recipes/81330/, I came up with the following code: >> >> #! /usr/bin/env python >> >> import re >> >> nodia={chr(196)+chr(130):'A', # mamaliga >> chr(195)+chr(130):'A', # A^ >> chr(195)+chr(142):'I', # I^ >> chr(195)+chr(150):'O', # OE >> chr(195)+chr(156):'U', # UE >> chr(195)+chr(139):'A', # AE >> chr(197)+chr(158):'S', >> chr(197)+chr(162):'T', >> chr(196)+chr(131):'a', # mamaliga >> chr(195)+chr(162):'a', # a^ >> chr(195)+chr(174):'i', # i^ >> chr(195)+chr(182):'o', # oe >> chr(195)+chr(188):'u', # ue >> chr(195)+chr(164):'a', # ae >> chr(197)+chr(159):'s', >> chr(197)+chr(163):'t' >> } >> name="R\xc3\xa2\xc5\x9fca" >> >> regex = re.compile("(%s)" % "|".join(map(re.escape, nodia.keys()))) >> print regex.sub(lambda mo: dict[mo.string[mo.start():mo.end()]], name) >> >> But it won't work; I end up with: >> >> Traceback (most recent call last): >> File "multirep.py", line 25, in >> print regex.sub(lambda mo: dict[mo.string[mo.start():mo.end()]], name) >> File "multirep.py", line 25, in >> print regex.sub(lambda mo: dict[mo.string[mo.start():mo.end()]], name) >> TypeError: 'type' object is not subscriptable >> >> What am I doing wrong? >> >> Thanks for your advice, >> SxN >> > > dict is a type, not a dict. Your dict is called nodia. I'm guess > that's what you meant to use. > Could I also suggest that you use: mo.group() instead of: mo.string[mo.start():mo.end()] From trylks at gmail.com Thu Nov 18 06:46:07 2010 From: trylks at gmail.com (trylks) Date: Thu, 18 Nov 2010 12:46:07 +0100 Subject: with HTTPConnection as conn: Message-ID: Hi! Would it be possible to use a with statement with an HTTPConnection object? I know it is not possible at this moment, it doesn't implement an __exit__ method, at least in version 3.1.1. I was wondering if the __exit__ method should do something more than conn.close(), something really hard or impossible, or if there are more requisites to use the with statement beside of implementing that method. So far it seems easy, useful and not done yet, so I'm probably mistaken about something, and wondering what may that be. Thank you. From clp2 at rebertia.com Thu Nov 18 06:53:31 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 18 Nov 2010 03:53:31 -0800 Subject: with HTTPConnection as conn: In-Reply-To: References: Message-ID: On Thu, Nov 18, 2010 at 3:46 AM, trylks wrote: > Hi! > > Would it be possible to use a with statement with an HTTPConnection object? Yes, via http://docs.python.org/library/contextlib.html#contextlib.closing from httplib import HTTPConnection from contextlib import closing with closing(HTTPConnection(...)) as conn: # do whatever # connection now closed Cheers, Chris -- http://blog.rebertia.com From grigory.v.p at gmail.com Thu Nov 18 07:03:57 2010 From: grigory.v.p at gmail.com (Grigory Petrov) Date: Thu, 18 Nov 2010 15:03:57 +0300 Subject: =?windows-1252?Q?How_to_correctly_pass_=93pointer=2Dto=2Dpointer=94_into_?= =?windows-1252?Q?DLL_via_ctypes=3F?= Message-ID: Hello. I have a DLL that allocates memory and returns it. Function in DLL is like this: void Foo( unsigned char** ppMem, int* pSize ) { ? * pSize = 4; ? * ppMem = malloc( * pSize ); ? for( int i = 0; i < * pSize; i ++ ) (* pMem)[ i ] = i; } Also, i have a python code that access this function from my DLL: from ctypes import * Foo = windll.mydll.Foo Foo.argtypes = [ POINTER( POINTER( c_ubyte ) ), POINTER( c_int ) ] mem = POINTER( c_ubyte )() size = c_int( 0 ) Foo( byref( mem ), byref( size ) ] print size, mem[ 0 ], mem[ 1 ], mem[ 2 ], mem[ 3 ] I'm expecting that?print?will show "4 0 1 2 3" but it shows "4 221 221 221 221" O_O. Any hints what i'm doing wrong? From matlab.dude at mbnet.fi Thu Nov 18 07:16:57 2010 From: matlab.dude at mbnet.fi (MATLABdude) Date: Thu, 18 Nov 2010 04:16:57 -0800 (PST) Subject: MATLAB to Python? References: <74f276c3-38a4-4df0-af39-7b1f2a81472e@c39g2000yqi.googlegroups.com> Message-ID: <40274408-8ae7-4500-983c-54714cf674d6@y23g2000yqd.googlegroups.com> On Nov 17, 10:04?am, MATLABdude wrote: Thanks guys! I still have some problems. I made the code somewhat simpler by dropping off some parts of it (xx, f). Now my Python code calculates 8 different values for lambda. The problem is that I don't know where the minus sign comes from. Also the values themselves are not identical compared to the values of the MATLAB program. nonhomog.py | nonhomog.m -0.774244159818 | 0.9976 -0.823595831818 | 0.9969 -0.774374006419 | 0.5464 -1.0 | -54.3440 -0.774244172803 | 0.9976 -0.774244289666 | 0.9976 -0.823595831818 | 0.9969 -1.0 | 0.9674 The new Python code can be found here: http://pastebin.com/c1UvtXxu From bc at freeuk.com Thu Nov 18 07:24:22 2010 From: bc at freeuk.com (BartC) Date: Thu, 18 Nov 2010 12:24:22 -0000 Subject: Is Unladen Swallow dead? In-Reply-To: <4ce37e01$0$1666$742ec2ed@news.sonic.net> References: <2e1a4d02-1e8a-4d31-95da-f33aaf90578c@30g2000yql.googlegroups.com> <8b0b044c-34a8-4747-b68f-f4cb56882f6f@e26g2000vbz.googlegroups.com> <4ce37e01$0$1666$742ec2ed@news.sonic.net> Message-ID: "John Nagle" wrote in message news:4ce37e01$0$1666$742ec2ed at news.sonic.net... > On 11/16/2010 10:24 PM, swapnil wrote: >> AFAIK, the merging plan was approved by Guido early this year. I guess >> Google is expecting the community to drive the project from here on. >> That was the whole idea for merging it to mainline. From my last >> conversation with Collin, they are targeting Python 3.3 > > I think it's dead. They're a year behind on quarterly releases. > The last release was Q3 2009. The project failed to achieve its > stated goal of a 5x speedup. Not even close. More like 1.5x > (http://www.python.org/dev/peps/pep-3146) There must have been good reasons to predict a 5x increase. But why did it take so long to find out the approach wasn't going anywhere? Assuming the 5x speedup was shown to be viable (ie. performing the same benchmarks, on the same data, can be done that quickly in any other language, and allowing for the overheads associated with Python's dynamic nature), then what went wrong? (I've had a look at the benchmarks, with a view to trying some on other languages, and they seem an extraordinarily difficult bunch to work with.) > The Google blog at > "http://groups.google.com/group/unladen-swallow/browse_thread/thread/f2011129c4414d04" > says, as of November 8, 2010: > So Google has pulled the plug on Unladen Swallow. It looks > like they underestimated the difficulty of speeding up the CPython > model. The performance improvement achieved was so low > that cluttering up CPython with a JIT system and LLVM probably is > a lose. LLVM. Ok, that explains a lot. (LLVM is a huge, complex system). -- Bartc From nomail at thisaddress.com Thu Nov 18 08:02:06 2010 From: nomail at thisaddress.com (Sven) Date: Thu, 18 Nov 2010 08:02:06 -0500 Subject: argparse subparser problem References: Message-ID: <2010111808020643145-nomail@thisaddresscom> On 2010-11-16 14:35:01 -0500, Neal Becker said: > I want to have subparsers, but I also want to be able to say: > > myprogram --version > and get the version # Would it not be possible to print the version number and then exit the program before building the subparser? > --------------------------- > > import argparse > > def stop(): > pass > > parser = argparse.ArgumentParser() > parser.add_argument ('--version', action='store_true') # if --version print version # sys.exit(0) > subparsers = parser.add_subparsers() > > parser_stop = subparsers.add_parser ('stop') > parser_stop.add_argument ('stop', action='store_true') > parser_stop.set_defaults (func=stop) > > > opt = parser.parse_args (['--version']) > ------------------------------ -- ./Sven From python at mrabarnett.plus.com Thu Nov 18 08:07:13 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 18 Nov 2010 13:07:13 +0000 Subject: MATLAB to Python? In-Reply-To: <40274408-8ae7-4500-983c-54714cf674d6@y23g2000yqd.googlegroups.com> References: <74f276c3-38a4-4df0-af39-7b1f2a81472e@c39g2000yqi.googlegroups.com> <40274408-8ae7-4500-983c-54714cf674d6@y23g2000yqd.googlegroups.com> Message-ID: <4CE52501.1080208@mrabarnett.plus.com> On 18/11/2010 12:16, MATLABdude wrote: > On Nov 17, 10:04 am, MATLABdude wrote: > > Thanks guys! > > I still have some problems. I made the code somewhat simpler by > dropping off some parts of it (xx, f). > > Now my Python code calculates 8 different values for lambda. The > problem is that I don't know where the minus sign comes from. Also the > values themselves are not identical compared to the values of the > MATLAB program. > nonhomog.py | nonhomog.m > -0.774244159818 | 0.9976 > -0.823595831818 | 0.9969 > -0.774374006419 | 0.5464 > -1.0 | -54.3440 > -0.774244172803 | 0.9976 > -0.774244289666 | 0.9976 > -0.823595831818 | 0.9969 > -1.0 | 0.9674 > > The new Python code can be found here: http://pastebin.com/c1UvtXxu Don't use: from math import * from numpy import * from scipy import * because you'll never be sure where a name comes from! Also, check for accidental integer division. (In Python 2 integer / integer returns integer.) From awilliam at whitemice.org Thu Nov 18 08:24:37 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Thu, 18 Nov 2010 08:24:37 -0500 Subject: Pickle in a POST/GET request give EOFError In-Reply-To: <4CE4FE66.20904@audaxis.com> References: <4CE2B599.7050504@audaxis.com> <4CE3EA61.2090707@audaxis.com> <4CE4E3CC.8080801@audaxis.com> <20101118094347.53a0980a@moriz.interne> <4CE4FE66.20904@audaxis.com> Message-ID: <1290086677.8819.2.camel@linux-yu4c.site> On Thu, 2010-11-18 at 11:22 +0100, Romaric DEFAUX wrote: > Hi again, > I try simplejson, but I have a problem. (I just replace pickle > everywhere by simplejson) > Explanation : > I "dumps" with json a list of dictionnaries into disk_list_json. > When I "loads" it, I don't get my list of dictionnaries like before (see > disk_list2). It adds "u" letter everywhere. Correct; I strongly disagree with the assertion to use JSON over Pickle. Pickle is superior for serialization - JSON does not preserve type. Use Pickle when possible. JSON is best for communicating simple data to stupid clients [web browsers]. JSON doesn't know about dates, it doesn't know about string vs. unicode, etc... -- Adam Tauno Williams From pecora at anvil.nrl.navy.mil Thu Nov 18 09:05:59 2010 From: pecora at anvil.nrl.navy.mil (Lou Pecora) Date: Thu, 18 Nov 2010 09:05:59 -0500 Subject: What was your strategy? References: <201011142240.oAEMecu2054270@krusty.intranet.com.mx> Message-ID: In article , Steve Holden wrote: > On 11/16/2010 2:22 PM, Lou Pecora wrote: > > I'll jump in and recommend the book "Python in a Nutshell" by Martelli. > > It may be a little dated now, but it covers many Python topics in good > > detail without becoming a bloated reference. Nicely written. It's still > > the first book I reach for after 6 years of Python coding and it rarely > > disappoints. > > +1 > > It's encyclopedic. Indeed. I hope Martelli updates it. I'd buy another copy right away. -- -- Lou Pecora From davea at ieee.org Thu Nov 18 09:19:22 2010 From: davea at ieee.org (Dave Angel) Date: Thu, 18 Nov 2010 09:19:22 -0500 Subject: String multi-replace In-Reply-To: <379297.48105.qm@web56003.mail.re3.yahoo.com> References: <379297.48105.qm@web56003.mail.re3.yahoo.com> Message-ID: <4CE535EA.7040309@ieee.org> On 2:59 PM, Sorin Schwimmer wrote: > Steven D'Aprano: the original file is 139MB (that's the typical size for it). Eliminating diacritics is just a little toping on the cake; the processing is something else. > > Thanks anyway for your suggestion, > SxN > > PS Perhaps I should have mention that I'm on Python 2.7 > > In the message you were replying to, Steven had a much more important suggestion to make than the size one, and you apparently didn't notice it. Chris made a similar implication. I'll try a third time. The file is obviously encoded, and you know the encoding. Judging from the first entry in your table, it's in utf-8. If so, then your approach is all wrong. Treating it as a pile of bytes, and replacing pairs is likely to get you in trouble, since it's quite possible that you may get a match with the last byte of one character and the first byte of another one. If you substitute such a match, you'll make a hash of the whole region, and quite likely end up with a byte stream that is no longer even utf-8. Fortunately, you can solve that problem, and simplify your code greatly in the bargain, by doing something like what was suggested by Steven. Change your map of encoded bytes into unicode_nodia, using decode("utf-8") on the keys, and u"" on the values Read in each line of the file, decode it to the unicode it represents, and do a simple translate once it's valid unicode. Assuming the line is in utf-8, use uni = line.decode("utf-8") newuni = uni.trans(unicode_nodia) newutf8 = newuni.encode("utf-8") incidentally, to see what a given byte pair in your table is, you can do something like: import unicodedata a = chr(196)+chr(130) unicodedata.name(a.decode("utf-8")) 'LATIN CAPITAL LETTER A WITH BREVE' DaveA From martin at address-in-sig.invalid Thu Nov 18 09:21:47 2010 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Thu, 18 Nov 2010 14:21:47 +0000 (UTC) Subject: Program, Application, and Software References: <87hbffa30d.fsf@benfinney.id.au> Message-ID: On Thu, 18 Nov 2010 01:16:34 +0000, MRAB wrote: > I'd probably say that a "script" is a program which is normally not > interactive: you just set it up, start it, and let it do its work (a > "batch script", for example). It's also written in a language primarily > designed for convenience rather than speed (Want to manipulate large > chunks of text? Fine! :-)). > I use 'script' to refer to programs written in languages that don't have a separate compile phase which must be run before the program can be executed. IOW Python and Perl programs are scripts aloing with programs written as awk, Javascript and bash scripts. -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From brf256 at gmail.com Thu Nov 18 09:25:40 2010 From: brf256 at gmail.com (brf256 at gmail.com) Date: Thu, 18 Nov 2010 14:25:40 +0000 Subject: What was your strategy? In-Reply-To: References: <201011142240.oAEMecu2054270@krusty.intranet.com.mx> Message-ID: <1011767245-1290090337-cardhu_decombobulator_blackberry.rim.net-1654248048-@bda480.bisx.prod.on.blackberry> +2 I also agree. - Braden Faulkner -----Original Message----- From: Lou Pecora Sender: python-list-bounces+brf256=gmail.com at python.org Date: Thu, 18 Nov 2010 09:05:59 To: Subject: Re: What was your strategy? In article , Steve Holden wrote: > On 11/16/2010 2:22 PM, Lou Pecora wrote: > > I'll jump in and recommend the book "Python in a Nutshell" by Martelli. > > It may be a little dated now, but it covers many Python topics in good > > detail without becoming a bloated reference. Nicely written. It's still > > the first book I reach for after 6 years of Python coding and it rarely > > disappoints. > > +1 > > It's encyclopedic. Indeed. I hope Martelli updates it. I'd buy another copy right away. -- -- Lou Pecora -- http://mail.python.org/mailman/listinfo/python-list From btricha at gmail.com Thu Nov 18 09:58:21 2010 From: btricha at gmail.com (Bryan Richardson) Date: Thu, 18 Nov 2010 07:58:21 -0700 Subject: Twisted on Windows Message-ID: Hello All, First off I must say that Twisted is a very nice event driven I/O package indeed. Thanks to all the developers who have contributed to it, as it's made my life much easier. Now for my question... I have a custom server application, and I have it structured as such: MyServerApp/ <-- root directory ? ?server.py foo/ __init__.py factory.py In my server.py file, which is a Twistd config file that can be executed with twistd -ny server.py, I have the following import line: from foo.factory import MyServerFactory When I run 'twistd -ny server.py' on my Linux machine from within the root MyServerApp directory, all works as expected. However, when I try to do the same thing on a Windows machine using the twistd script that gets installed, I get an error saying that foo.factory cannot be found. However, if I modify my server.py file on Windows to just create the factory and start the reactor, I can run it just fine with 'python server.py' even though it still has the import line for MyServerFactory. Bottom line is, on Windows, the python executable can find my custom module in a sub directory but the twistd script cannot. Any ideas why this is? -- Thanks! Bryan From solipsis at pitrou.net Thu Nov 18 10:01:25 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Thu, 18 Nov 2010 16:01:25 +0100 Subject: with HTTPConnection as conn: References: Message-ID: <20101118160125.3de403aa@pitrou.net> On Thu, 18 Nov 2010 12:46:07 +0100 trylks wrote: > Hi! > > Would it be possible to use a with statement with an HTTPConnection object? > > I know it is not possible at this moment, it doesn't implement an > __exit__ method, at least in version 3.1.1. I was wondering if the > __exit__ method should do something more than conn.close(), something > really hard or impossible, or if there are more requisites to use the > with statement beside of implementing that method. So far it seems > easy, useful and not done yet, so I'm probably mistaken about > something, and wondering what may that be. It's possibly one of those things that haven't been implemented simply because no one thought about it yet, or bothered enough to do it. In other words, you can open a feature request at http://bugs.python.org, and even provide a patch. Regards Antoine. From rbd at soest.hawaii.edu Thu Nov 18 10:35:42 2010 From: rbd at soest.hawaii.edu (Roger Davis) Date: Thu, 18 Nov 2010 05:35:42 -1000 (HST) Subject: strange subprocess behavior when calling ps In-Reply-To: <801_1290077447_4CE50505_801_399_1_4CE504FF.2080709@sequans.com> References: <55f26d5c-aba9-4892-9e2c-1caa9988e7fe@v23g2000vbi.googlegroups.com> <1ed38051-9c8b-4ae8-9a88-9833209d2775@h21g2000vbh.googlegroups.com> <801_1290077447_4CE50505_801_399_1_4CE504FF.2080709@sequans.com> Message-ID: Hi JM, Thank you very much for your followup explanation! Roger From invalid at invalid.invalid Thu Nov 18 10:41:51 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 18 Nov 2010 15:41:51 +0000 (UTC) Subject: Program, Application, and Software References: <87hbffa30d.fsf@benfinney.id.au> Message-ID: On 2010-11-18, Martin Gregorie wrote: > On Thu, 18 Nov 2010 01:16:34 +0000, MRAB wrote: > >> I'd probably say that a "script" is a program which is normally not >> interactive: you just set it up, start it, and let it do its work (a >> "batch script", for example). It's also written in a language primarily >> designed for convenience rather than speed (Want to manipulate large >> chunks of text? Fine! :-)). >> > I use 'script' to refer to programs written in languages that don't have > a separate compile phase which must be run before the program can be > executed. IOW Python and Perl programs are scripts aloing with programs > written as awk, Javascript and bash scripts. I use 'script' to refer to programs that are used to automate things that would otherwise be done by a person typing commands. IOW, what I write using Python aren't scripts. They're programs. -- Grant Edwards grant.b.edwards Yow! All of life is a blur at of Republicans and meat! gmail.com From hniksic at xemacs.org Thu Nov 18 10:55:00 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Thu, 18 Nov 2010 16:55:00 +0100 Subject: with HTTPConnection as conn: References: Message-ID: <87hbfebp9n.fsf@xemacs.org> Antoine Pitrou writes: > On Thu, 18 Nov 2010 12:46:07 +0100 > trylks wrote: >> Hi! >> >> Would it be possible to use a with statement with an HTTPConnection object? >> >> I know it is not possible at this moment, it doesn't implement an >> __exit__ method, at least in version 3.1.1. I was wondering if the >> __exit__ method should do something more than conn.close(), something >> really hard or impossible, or if there are more requisites to use the >> with statement beside of implementing that method. So far it seems >> easy, useful and not done yet, so I'm probably mistaken about >> something, and wondering what may that be. > > It's possibly one of those things that haven't been implemented simply > because no one thought about it yet, or bothered enough to do it. Also, contextlib.closing is readily available: with contextlib.closing(HTTPConnection(...)) as conn: ... From martin at address-in-sig.invalid Thu Nov 18 11:05:51 2010 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Thu, 18 Nov 2010 16:05:51 +0000 (UTC) Subject: Program, Application, and Software References: <87hbffa30d.fsf@benfinney.id.au> Message-ID: On Thu, 18 Nov 2010 15:41:51 +0000, Grant Edwards wrote: > On 2010-11-18, Martin Gregorie wrote: >> On Thu, 18 Nov 2010 01:16:34 +0000, MRAB wrote: >> >>> I'd probably say that a "script" is a program which is normally not >>> interactive: you just set it up, start it, and let it do its work (a >>> "batch script", for example). It's also written in a language >>> primarily designed for convenience rather than speed (Want to >>> manipulate large chunks of text? Fine! :-)). >>> >> I use 'script' to refer to programs written in languages that don't >> have a separate compile phase which must be run before the program can >> be executed. IOW Python and Perl programs are scripts aloing with >> programs written as awk, Javascript and bash scripts. > > I use 'script' to refer to programs that are used to automate things > that would otherwise be done by a person typing commands. > Its a long-standing UNIXism - it applies to any language implementation where you can add "#!/path/to/interpreter" as the first line of the source file, make the file executable with chmod and run it by treating the file name as a command. > IOW, what I write using Python aren't scripts. They're programs. > Anything with one or more executable lines is a program: #!/usr/bin/python print "\nHello, Python World\n" -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From fetchinson at googlemail.com Thu Nov 18 11:27:43 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Thu, 18 Nov 2010 17:27:43 +0100 Subject: what's the precision of fractions.Fraction? Message-ID: I do a recursive evaluation of an expression involving fractions and unsurprisingly the numerator and denominator grows pretty quickly. After 10-20 iterations the number of digits in the numerator and denominator (as integers) reaches 80-100. And I'm wondering until what point I can trust the result since I'm using fractions.Fraction for the whole procedure. Are Fraction's infinite precision? Or will I get some sort of an exception if python is not able to represent the numerator and/or denominator as integers? http://www.python.org/dev/peps/pep-3141/ was not very helpful in this regard nor was http://docs.python.org/library/fractions.html Any ideas? Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From ben at wbpsystems.com Thu Nov 18 11:48:11 2010 From: ben at wbpsystems.com (tazz_ben) Date: Thu, 18 Nov 2010 08:48:11 -0800 (PST) Subject: Distribution of Python Scripts Message-ID: Hi Folks - I'm an experienced programmer, but this is my first app with python, so I apologize for any stupidity on my part. So I've written/still working on a command line tool written in Python. It talks to a web service, so there really isn't anything in it that is dependent on a particular os. My goal is to distribute the script as a tool to my users so they can use it (they are on multiple platforms), the vast majority are not programmers. So, I'm looking for a way to distribute the app that takes care of details like them having python installed, or having an older version etc. From reading some docs it sounds like "Squeeze" did exactly this back in the day, but it is ancient and I'm writing in 2.7. Just to be clear I could care less if they see the source code, my goal is all around ease of use. I would love to have one distribution file for all platforms, but I can live with making three if that's the only option. So, what's my options. From calderone.jeanpaul at gmail.com Thu Nov 18 11:52:39 2010 From: calderone.jeanpaul at gmail.com (Jean-Paul Calderone) Date: Thu, 18 Nov 2010 08:52:39 -0800 (PST) Subject: Twisted on Windows References: Message-ID: <1463cdde-3095-426b-af2f-efa2c556e8f0@i41g2000vbn.googlegroups.com> On Nov 18, 9:58?am, Bryan Richardson wrote: > Hello All, > > First off I must say that Twisted is a very nice event driven I/O > package indeed. Thanks to all the developers who have contributed to > it, as it's made my life much easier. > > Now for my question... > > I have a custom server application, and I have it structured as such: > > MyServerApp/ <-- root directory > ? ?server.py > ? ?foo/ > ? ? ? __init__.py > ? ? ? factory.py > > In my server.py file, which is a Twistd config file that can be > executed with twistd -ny server.py, I have the following import line: > > from foo.factory import MyServerFactory > > When I run 'twistd -ny server.py' on my Linux machine from within the > root MyServerApp directory, all works as expected. However, when I try > to do the same thing on a Windows machine using the twistd script that > gets installed, I get an error saying that foo.factory cannot be > found. However, if I modify my server.py file on Windows to just > create the factory and start the reactor, I can run it just fine with > 'python server.py' even though it still has the import line for > MyServerFactory. > > Bottom line is, on Windows, the python executable can find my custom > module in a sub directory but the twistd script cannot. Any ideas why > this is? > When you run a .py file, python adds the directory containing that .py file to the front of sys.path. So when you run server.py, MyServerApp/ is added to sys.path and the foo package can be found. This happens on Linux and Windows. When you run twistd, the ".py file" you're running is /usr/bin/twistd or C:\Python26\Scripts\twistd or something else along those lines. So Python adds /usr/bin or C:\Python26\Scripts to sys.path. This doesn't help you find the foo package at all. On Linux, when not running as root, twistd adds the current working directory to sys.path. So if your working directory is MyServerApp, then the foo package can be found. When running as root, or when running on Windows, twistd does not add the working directory to sys.path. So with all that in mind, the solution should be pretty clear - just set PYTHONPATH to include MyServerApp. This variation of twistd behavior is pretty confusing, and I think a future version may drop the sys.path manipulation entirely, so that it behaves consistently in all configurations. Jean-Paul From ian.g.kelly at gmail.com Thu Nov 18 12:13:25 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 18 Nov 2010 10:13:25 -0700 Subject: what's the precision of fractions.Fraction? In-Reply-To: References: Message-ID: On Thu, Nov 18, 2010 at 9:27 AM, Daniel Fetchinson < fetchinson at googlemail.com> wrote: > I do a recursive evaluation of an expression involving fractions and > unsurprisingly the numerator and denominator grows pretty quickly. > After 10-20 iterations the number of digits in the numerator and > denominator (as integers) reaches 80-100. And I'm wondering until what > point I can trust the result since I'm using fractions.Fraction for > the whole procedure. Are Fraction's infinite precision? Or will I get > some sort of an exception if python is not able to represent the > numerator and/or denominator as integers? > Since fractions are represented as a pair of integers, and since python integers have unlimited precision, I would guess that fractions also have unlimited precision. You could check the code if you want to be absolutely sure. Cheers, Ian -------------- next part -------------- An HTML attachment was scrubbed... URL: From drsalists at gmail.com Thu Nov 18 12:45:08 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Thu, 18 Nov 2010 09:45:08 -0800 Subject: Is Unladen Swallow dead? In-Reply-To: References: <2e1a4d02-1e8a-4d31-95da-f33aaf90578c@30g2000yql.googlegroups.com> <8b0b044c-34a8-4747-b68f-f4cb56882f6f@e26g2000vbz.googlegroups.com> <4ce37e01$0$1666$742ec2ed@news.sonic.net> Message-ID: On Thu, Nov 18, 2010 at 4:24 AM, BartC wrote: > "John Nagle" wrote in message > news:4ce37e01$0$1666$742ec2ed at news.sonic.net... > > On 11/16/2010 10:24 PM, swapnil wrote: >> > > AFAIK, the merging plan was approved by Guido early this year. I guess >>> Google is expecting the community to drive the project from here on. >>> That was the whole idea for merging it to mainline. From my last >>> conversation with Collin, they are targeting Python 3.3 >>> >> >> I think it's dead. They're a year behind on quarterly releases. >> The last release was Q3 2009. The project failed to achieve its >> stated goal of a 5x speedup. Not even close. More like 1.5x >> (http://www.python.org/dev/peps/pep-3146) >> > > There must have been good reasons to predict a 5x increase. But why did it > take so long to find out the approach wasn't going anywhere? > It's not that it wasn't going anywhere. Improvements were accomplished. Also, LLVM needed to be modified more than a little bit for the purpose. Also, the developers were constrained a bit by the need to preserve compatibility with some pretty weird code - like methods being replaced mid-loop. It's not a small project. -------------- next part -------------- An HTML attachment was scrubbed... URL: From martin at v.loewis.de Thu Nov 18 12:45:55 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Thu, 18 Nov 2010 18:45:55 +0100 Subject: regenerating unicodedata for py2.7 using py3 makeunicodedata.py? In-Reply-To: References: Message-ID: <4CE56653.8020201@v.loewis.de> > Thanks for the confirmation Martin! > > Do you think, it the mentioned omission of the character names of some > CJK ranges in unicodedata intended, or should it be reported to the > tracker? It's certainly a bug. So a bug report would be appreciated, but much more so a patch. Ideally, the patch would either be completely forward-compatible (should the CJK ranges change in future Unicode versions), or at least have a safe-guard to detect that the data file is getting out of sync with the C implementation. Regards, Martin From martin at v.loewis.de Thu Nov 18 12:45:55 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Thu, 18 Nov 2010 18:45:55 +0100 Subject: regenerating unicodedata for py2.7 using py3 makeunicodedata.py? In-Reply-To: References: Message-ID: <4CE56653.8020201@v.loewis.de> > Thanks for the confirmation Martin! > > Do you think, it the mentioned omission of the character names of some > CJK ranges in unicodedata intended, or should it be reported to the > tracker? It's certainly a bug. So a bug report would be appreciated, but much more so a patch. Ideally, the patch would either be completely forward-compatible (should the CJK ranges change in future Unicode versions), or at least have a safe-guard to detect that the data file is getting out of sync with the C implementation. Regards, Martin From brf256 at gmail.com Thu Nov 18 12:50:58 2010 From: brf256 at gmail.com (brf256 at gmail.com) Date: Thu, 18 Nov 2010 17:50:58 +0000 Subject: Is Unladen Swallow dead? Message-ID: <1778189007-1290102660-cardhu_decombobulator_blackberry.rim.net-1230079009-@bda480.bisx.prod.on.blackberry> I do hope that it isn't dead but it unfortunately seems that way? - Braden Faulkner From no.email at nospam.invalid Thu Nov 18 13:09:24 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 18 Nov 2010 10:09:24 -0800 Subject: What was your strategy? References: <201011142240.oAEMecu2054270@krusty.intranet.com.mx> Message-ID: <7xr5ei1p2j.fsf@ruckus.brouhaha.com> Lou Pecora writes: >> > I'll jump in and recommend the book "Python in a Nutshell" by Martelli. >> It's encyclopedic. > Indeed. I hope Martelli updates it. I'd buy another copy right away. It's a great book but not a starting point for beginners. It's definitely worth having for more advanced users. From fetchinson at googlemail.com Thu Nov 18 13:17:51 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Thu, 18 Nov 2010 19:17:51 +0100 Subject: what's the precision of fractions.Fraction? In-Reply-To: References: Message-ID: >> I do a recursive evaluation of an expression involving fractions and >> unsurprisingly the numerator and denominator grows pretty quickly. >> After 10-20 iterations the number of digits in the numerator and >> denominator (as integers) reaches 80-100. And I'm wondering until what >> point I can trust the result since I'm using fractions.Fraction for >> the whole procedure. Are Fraction's infinite precision? Or will I get >> some sort of an exception if python is not able to represent the >> numerator and/or denominator as integers? > > Since fractions are represented as a pair of integers, and since python > integers have unlimited precision, I would guess that fractions also have > unlimited precision. You could check the code if you want to be absolutely > sure. Sounds reasonable, thanks a lot, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From nagle at animats.com Thu Nov 18 13:31:15 2010 From: nagle at animats.com (John Nagle) Date: Thu, 18 Nov 2010 10:31:15 -0800 Subject: Is Unladen Swallow dead? In-Reply-To: References: <2e1a4d02-1e8a-4d31-95da-f33aaf90578c@30g2000yql.googlegroups.com> <8b0b044c-34a8-4747-b68f-f4cb56882f6f@e26g2000vbz.googlegroups.com> <4ce37e01$0$1666$742ec2ed@news.sonic.net> Message-ID: <4ce570ff$0$1617$742ec2ed@news.sonic.net> On 11/18/2010 4:24 AM, BartC wrote: > "John Nagle" wrote in message > news:4ce37e01$0$1666$742ec2ed at news.sonic.net... >> On 11/16/2010 10:24 PM, swapnil wrote: > >>> AFAIK, the merging plan was approved by Guido early this year. I >>> guess Google is expecting the community to drive the project >>> from here on. That was the whole idea for merging it to mainline. >>> From my last conversation with Collin, they are targeting Python >>> 3.3 >> >> I think it's dead. They're a year behind on quarterly releases. >> The last release was Q3 2009. The project failed to achieve its >> stated goal of a 5x speedup. Not even close. More like 1.5x >> (http://www.python.org/dev/peps/pep-3146) > > There must have been good reasons to predict a 5x increase. For Java, adding a JIT improved performance by much more than that. Hard-code compilers for LISP have done much better than 5x. The best Java and LISP compilers approach the speed of C, while CPython is generally considered to be roughly 60 times slower than C. So 5x probably looked like a conservative goal. For Google, a company which buys servers by the acre, a 5x speedup would have a big payoff. > Assuming the 5x speedup was shown to be viable (ie. performing the > same benchmarks, on the same data, can be done that quickly in any > other language, and allowing for the overheads associated with > Python's dynamic nature), then what went wrong? Python is defined by what a naive interpreter with late binding and dynamic name lookups, like CPython, can easily implement. Simply emulating the semantics of CPython with generated code doesn't help all that much. Because you can "monkey patch" Python objects from outside the class, a local compiler, like a JIT, can't turn name lookups into hard bindings. Nor can it make reliable decisions about the types of objects. That adds a sizable performance penalty. Short of global program analysis, the compiler can't tell when code for the hard cases needs to be generated. So the hard-case code, where you figure out at run-time, for ever use of "+", whether "+" is addition or concatenation, has to be generated every time. Making that decision is far slower than doing an add. Shed Skin, which analyzes the entire program, including libraries, on every compilation, can figure out the types of objects and generate much faster code. Shed Skin has some heavy restrictions, many of which could be lifted if more work went into that effort. That's one approach that might work. I've referred to this problem as "gratuitous hidden dynamism". Most things which could be changed dynamically in a Python program usually aren't. This has been pointed out many times by many people. There's even a PhD thesis on the topic. Without a few restrictions, so that a compiler can at least tell when support for the hard cases is needed, Python cannot be compiled well. John Nagle From stefan.sonnenberg at pythonmeister.com Thu Nov 18 14:08:00 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Thu, 18 Nov 2010 20:08:00 +0100 Subject: what's the precision of fractions.Fraction? In-Reply-To: References: Message-ID: <4CE57990.2020706@pythonmeister.com> Am 18.11.2010 17:27, schrieb Daniel Fetchinson: > I do a recursive evaluation of an expression involving fractions and > unsurprisingly the numerator and denominator grows pretty quickly. > After 10-20 iterations the number of digits in the numerator and > denominator (as integers) reaches 80-100. And I'm wondering until what > point I can trust the result since I'm using fractions.Fraction for > the whole procedure. Are Fraction's infinite precision? Or will I get > some sort of an exception if python is not able to represent the > numerator and/or denominator as integers? > > http://www.python.org/dev/peps/pep-3141/ was not very helpful in this > regard nor was http://docs.python.org/library/fractions.html > > Any ideas? > > Cheers, > Daniel > I'm not sure what you really want to know. Fractions are, by their math definition, of unlimited precision. For example, PI/2 is accurate (with endless precision as PI is a trancendent number), but 3.1415926/2 (the decimal representation) is not. So is fraction.Fraction(1,3) of unlimited precision, thus giving this: from fractions import Fraction >>> one_tenth=Fraction(1,10) >>> a = one_tenth+one_tenth >>> a Fraction(1, 5) >>> a = one_tenth+one_tenth+one_tenth >>> a Fraction(3, 10) now compare to standard floats: >>> one_tenth=1.0/10 >>> a = one_tenth+one_tenth >>> a 0.2 >>> a = one_tenth+one_tenth+one_tenth >>> a 0.30000000000000004 (this error is caused by the internal representation of floats as binary numbers, see No. 14 in Python tut). I think you really want to know, how large numerator/denominator can be. As python has bignum support (type=long), the only limit is the one your virtual memory system offers, which is almost always approx. the amount of ram. If you need it really *precise*, cast your Fractions into type Decimal: >>> from decimal import Decimal >>> one_tenth=Fraction(1,10) >>> three_tenth = one_tenth*3 >>> d = Decimal(three_tenth.numerator)/Decimal(three_tenth.denominator) >>> d Decimal('0.3') The operator '/' (__div__) is properly over-written. You can even tweak the precision getcontext().prec by setting it to a higher value. Cheers -------------- next part -------------- A non-text attachment was scrubbed... Name: stefan_sonnenberg.vcf Type: text/x-vcard Size: 223 bytes Desc: not available URL: From bmjames at gmail.com Thu Nov 18 14:13:10 2010 From: bmjames at gmail.com (Ben James) Date: Thu, 18 Nov 2010 19:13:10 +0000 Subject: Is Unladen Swallow dead? References: Message-ID: On 18/11/2010 17:50, brf256 at gmail.com wrote: > I do hope that it isn't dead but it unfortunately seems that way? > > - Braden Faulkner > It looks like we'll have to get used to a laden one. Maybe if we had two, and a strand of creeper... From bmjames at gmail.com Thu Nov 18 14:17:07 2010 From: bmjames at gmail.com (Ben James) Date: Thu, 18 Nov 2010 19:17:07 +0000 Subject: I have a question about JavaFit References: Message-ID: On 18/11/2010 10:05, Chris Rebert wrote: > "We" are a technical discussion maillinglist. About a computer > programming language. Named Python. > An unrelated computer programming language which happens to be named > "Java" also exists, but is not this mailinglist's topic of discussion. > Some computer programmers personally consume a lot of coffee, but > aside from that, as a group, this maillinglist's members have nothing > to do with "Javalution Coffee Company" or their "JavaFit" coffee > products. > To put it simply, you're barking up entirely the wrong tree. > How exactly were you led to believe that python-list at python.org had > anything to do with JavaFit in the first place? > > Regards, > Chris, random maillinglist subscriber > > On Tue, Nov 16, 2010 at 4:45 PM, Bill Fishbaugher > wrote: >> Hello, >> >> I was searching online to find more info about JavaFit and I came across your information. >> >> Can you tell me, are you still involved with JavaFit? If you are, how are things going for you? >> >> Please let me know. >> >> Sincerely, >> Bill Is a JavaFit what you have when you drink waaaaaay too much coffee? From stefan.sonnenberg at pythonmeister.com Thu Nov 18 14:40:47 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Thu, 18 Nov 2010 20:40:47 +0100 Subject: I have a question about JavaFit In-Reply-To: References: Message-ID: <4CE5813F.8080001@pythonmeister.com> Am 18.11.2010 20:17, schrieb Ben James: > On 18/11/2010 10:05, Chris Rebert wrote: >> "We" are a technical discussion maillinglist. About a computer >> programming language. Named Python. >> An unrelated computer programming language which happens to be named >> "Java" also exists, but is not this mailinglist's topic of discussion. >> Some computer programmers personally consume a lot of coffee, but >> aside from that, as a group, this maillinglist's members have nothing >> to do with "Javalution Coffee Company" or their "JavaFit" coffee >> products. >> To put it simply, you're barking up entirely the wrong tree. >> How exactly were you led to believe that python-list at python.org had >> anything to do with JavaFit in the first place? >> >> Regards, >> Chris, random maillinglist subscriber >> >> On Tue, Nov 16, 2010 at 4:45 PM, Bill Fishbaugher >> wrote: >>> Hello, >>> >>> I was searching online to find more info about JavaFit and I came >>> across your information. >>> >>> Can you tell me, are you still involved with JavaFit? If you are, >>> how are things going for you? >>> >>> Please let me know. >>> >>> Sincerely, >>> Bill > > Is a JavaFit what you have when you drink waaaaaay too much coffee? Java FIT : Java Framework for integrated testing http://fit.c2.com/ Last update to site Oct 2007 There seems (ed) to be a python port. Status unknown. I guess what bill is looking for is test driven development. This thingy seems really strange. -------------- next part -------------- A non-text attachment was scrubbed... Name: stefan_sonnenberg.vcf Type: text/x-vcard Size: 223 bytes Desc: not available URL: From jenn.duerr at gmail.com Thu Nov 18 15:15:03 2010 From: jenn.duerr at gmail.com (noydb) Date: Thu, 18 Nov 2010 12:15:03 -0800 (PST) Subject: How to run an EXE, with argument, capture output value References: <37037d15-63da-4f37-9508-bdcfff034670@s4g2000yql.googlegroups.com> Message-ID: <70d6c9a7-8ba9-420d-822a-0ba71888e4f4@v20g2000yqb.googlegroups.com> I will use 2.5. I tried your suggestion, with this code import subprocess pig = subprocess.Popen(["C:\Halls\hallbig2.exe"], stdin=subprocess.PIPE, stdout=subprocess.PIPE) result = pig.communicate(input='C:\Halls\Input\Ea39j.txt')[-1] #I need to capture the, what I think is the, last output print result print pig.returncode >> None >> 0 So the tuple is empty. ?? The exe executes fine and returns output in th exe tool itself. The python script seems to execute fine, no errors, '...returned exit code 0'. Any ideas/suggestions? From dutche at gmail.com Thu Nov 18 15:20:44 2010 From: dutche at gmail.com (dutche) Date: Thu, 18 Nov 2010 12:20:44 -0800 (PST) Subject: Changing the EAX register with Python Message-ID: Hi folks, I have a unusual question here. How can I change the value of EAX register under python under Linux?? As paimei does under Windows. My project is to have a python program that loads a C program and sets a breakpoint at some address, and then with this breakpoint I change the EAX register and then continue the program execution. With Windows and paimei I did that, but under Linux I don't know yet. Any ideas? Thank you From btricha at gmail.com Thu Nov 18 15:55:47 2010 From: btricha at gmail.com (Bryan Richardson) Date: Thu, 18 Nov 2010 13:55:47 -0700 Subject: Twisted on Windows In-Reply-To: <1463cdde-3095-426b-af2f-efa2c556e8f0@i41g2000vbn.googlegroups.com> References: <1463cdde-3095-426b-af2f-efa2c556e8f0@i41g2000vbn.googlegroups.com> Message-ID: Thanks Jean-Paul, I added the following to my server.py file and things work perfectly on both Windows and Linux now. sys.path.insert(0, os.getcwd()) On Thu, Nov 18, 2010 at 9:52 AM, Jean-Paul Calderone wrote: > On Nov 18, 9:58?am, Bryan Richardson wrote: >> Hello All, >> >> First off I must say that Twisted is a very nice event driven I/O >> package indeed. Thanks to all the developers who have contributed to >> it, as it's made my life much easier. >> >> Now for my question... >> >> I have a custom server application, and I have it structured as such: >> >> MyServerApp/ <-- root directory >> ? ?server.py >> ? ?foo/ >> ? ? ? __init__.py >> ? ? ? factory.py >> >> In my server.py file, which is a Twistd config file that can be >> executed with twistd -ny server.py, I have the following import line: >> >> from foo.factory import MyServerFactory >> >> When I run 'twistd -ny server.py' on my Linux machine from within the >> root MyServerApp directory, all works as expected. However, when I try >> to do the same thing on a Windows machine using the twistd script that >> gets installed, I get an error saying that foo.factory cannot be >> found. However, if I modify my server.py file on Windows to just >> create the factory and start the reactor, I can run it just fine with >> 'python server.py' even though it still has the import line for >> MyServerFactory. >> >> Bottom line is, on Windows, the python executable can find my custom >> module in a sub directory but the twistd script cannot. Any ideas why >> this is? >> > > When you run a .py file, python adds the directory containing that .py > file to the front of sys.path. ?So when you run server.py, > MyServerApp/ > is added to sys.path and the foo package can be found. ?This happens > on > Linux and Windows. > > When you run twistd, the ".py file" you're running is /usr/bin/twistd > or C:\Python26\Scripts\twistd or something else along those lines. ?So > Python adds /usr/bin or C:\Python26\Scripts to sys.path. ?This doesn't > help you find the foo package at all. > > On Linux, when not running as root, twistd adds the current working > directory to sys.path. ?So if your working directory is MyServerApp, > then the foo package can be found. > > When running as root, or when running on Windows, twistd does not add > the working directory to sys.path. > > So with all that in mind, the solution should be pretty clear - just > set PYTHONPATH to include MyServerApp. > > This variation of twistd behavior is pretty confusing, and I think a > future version may drop the sys.path manipulation entirely, so that > it behaves consistently in all configurations. > > Jean-Paul > -- > http://mail.python.org/mailman/listinfo/python-list > From tjreedy at udel.edu Thu Nov 18 16:31:40 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 18 Nov 2010 16:31:40 -0500 Subject: what's the precision of fractions.Fraction? In-Reply-To: References: Message-ID: On 11/18/2010 11:27 AM, Daniel Fetchinson wrote: > I do a recursive evaluation of an expression involving fractions and > unsurprisingly the numerator and denominator grows pretty quickly. > After 10-20 iterations the number of digits in the numerator and > denominator (as integers) reaches 80-100. And I'm wondering until what > point I can trust the result since I'm using fractions.Fraction for > the whole procedure. Are Fraction's infinite precision? 'Unbounded' (except by memory) would be be more accurate. > Or will I get > some sort of an exception if python is not able to represent the > numerator and/or denominator as integers? I believe you could eventually get MemoryError. But you might get tired of waiting first. I tried i=0 n=2 while True: print(i) n *= n i += 1 The 30th doubling (I believe to a billion bit or 128 megabyte number, on a gigabyte machine) took a few minutes and I killed the program after that as it tried to page everything else out to disk. -- Terry Jan Reedy From anthra.norell at bluewin.ch Thu Nov 18 16:38:09 2010 From: anthra.norell at bluewin.ch (Frederic Rentsch) Date: Thu, 18 Nov 2010 22:38:09 +0100 Subject: String multi-replace In-Reply-To: <912885.5637.qm@web56006.mail.re3.yahoo.com> References: <912885.5637.qm@web56006.mail.re3.yahoo.com> Message-ID: <1290116289.2902.81.camel@hatchbox-one> On Wed, 2010-11-17 at 21:12 -0800, Sorin Schwimmer wrote: > Thanks for your answers. > > Benjamin Kaplan: of course dict is a type... silly me! I'll blame it on the time (it's midnight here). > > Chris Rebert: I'll have a look. > > Thank you both, > SxN > > Forgive me if this is off the track. I haven't followed the thread. I do have a little module that I believe does what you attempted to do: multiple substitutions using a regular expression that joins a bunch of targets with '|' in between. Whether or not you risk unintended translations as Dave Angel pointed out where the two characters or one of your targets join coincidentally you will have to determine. If so you can't use this approach. If, on the other hand, your format is safe it'll work just fine. Use like this: >>> import translator >>> t = translator.Translator (nodia.items ()) >>> t (name) # Your example 'Rasca' Frederic -------------- next part -------------- A non-text attachment was scrubbed... Name: translator.py Type: text/x-python Size: 4276 bytes Desc: not available URL: From usernet at ilthio.net Thu Nov 18 17:22:35 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 18 Nov 2010 22:22:35 +0000 (UTC) Subject: How to run an EXE, with argument, capture output value References: <37037d15-63da-4f37-9508-bdcfff034670@s4g2000yql.googlegroups.com> <70d6c9a7-8ba9-420d-822a-0ba71888e4f4@v20g2000yqb.googlegroups.com> Message-ID: On 2010-11-18, noydb wrote: > import subprocess > pig = subprocess.Popen(["C:\Halls\hallbig2.exe"], > stdin=subprocess.PIPE, stdout=subprocess.PIPE) > result = pig.communicate(input='C:\Halls\Input\Ea39j.txt')[-1] #I need > to capture the, what I think is the, last output >From the subprocess documentation: [62]communicate() returns a tuple (stdoutdata, stderrdata). Note that if you want to send data to the process's stdin, you need to create the Popen object with stdin=PIPE. Similarly, to get anything other than None in the result tuple, you need to give stdout=PIPE and/or stderr=PIPE too. By using index [-1] you are accessing the processes stderr stream. I am not really sure why you changed it. It doesn't give you the last output. Index 0 gives you *all* of stdout and index 1 gives you *all* of stderr, period. If you wish to further disect the output to get say the last line, then you will need to parse it separately. > print result > print pig.returncode >>> None >>> 0 > > So the tuple is empty. ?? The exe executes fine and returns output in > th exe tool itself. The python script seems to execute fine, no > errors, '...returned exit code 0'. Any ideas/suggestions? No the tuple contains two items (stdout, stderr). The first is what the program printed to its stdout stream (which is most likely the output you see if you run the command at a terminal/console). The second is what it printed to its stderr stream which is a channel used for out of band data such as error or status messages. In this case, it is None, because you did open stderr as a subprocess.PIPE. From stefan.sonnenberg at pythonmeister.com Thu Nov 18 17:24:10 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Thu, 18 Nov 2010 23:24:10 +0100 Subject: Changing the EAX register with Python In-Reply-To: References: Message-ID: <4CE5A78A.1010809@pythonmeister.com> Am 18.11.2010 21:20, schrieb dutche: > Hi folks, I have a unusual question here. > > How can I change the value of EAX register under python under Linux?? > As paimei does under Windows. > > My project is to have a python program that loads a C program and sets > a breakpoint at some address, and then with this breakpoint I change > the EAX register and then continue the program execution. > > With Windows and paimei I did that, but under Linux I don't know yet. > > Any ideas? > > Thank you You asked for it: from ctypes import * import time import os cdll.LoadLibrary('libc.so.6') libc = CDLL('libc.so.6') PTRACE_TRACEME = 0 PTRACE_GETREGS = 12 PTRACE_SETREGS = 13 PTRACE_SYSCALL = 24 SYS_WRITE = 4 SYS_IOCTL = 54 class user_regs_struct(Structure): _fields_ = [ ('ebx',c_ulong), ('ecx',c_ulong), ('edx',c_ulong), ('esi',c_ulong), ('edi',c_ulong), ('ebp',c_ulong), ('eax',c_ulong), ('xds',c_ulong), ('xes',c_ulong), ('xfs',c_ulong), ('xgs',c_ulong), ('orig_eax',c_ulong), ('eip',c_ulong), ('xcs',c_ulong), ('eflags',c_ulong), ('esp',c_ulong), ('xss',c_ulong), ] child = os.fork() if child == 0: libc.ptrace(PTRACE_TRACEME,0,None,None) os.execl('/bin/ls','ls') else: while True: pid,status = os.wait() if status != 0: reg = pointer(user_regs_struct()) libc.ptrace(PTRACE_GETREGS,pid,None,reg) if reg.contents.orig_eax == SYS_IOCTL: print 'IOCTL ebx,ecx = 0x%0x,0x%0x' % (reg.contents.ebx,reg.contents.ecx) # replace IOCTL with SYS_WRITE reg.contents.orig_eax = SYS_WRITE libc.ptrace(PTRACE_SETREGS,pid,None,reg) libc.ptrace(PTRACE_SYSCALL,pid,None,None) else: os._exit(0) -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: debug.py URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: stefan_sonnenberg.vcf Type: text/x-vcard Size: 223 bytes Desc: not available URL: From bryan.wheelock at gmail.com Thu Nov 18 17:31:19 2010 From: bryan.wheelock at gmail.com (Bryan Wheelock) Date: Thu, 18 Nov 2010 17:31:19 -0500 Subject: Why is pdb messing with STDIN? I can't step through my code, or enter any data accurately. Message-ID: I'm baffled by the behavior of pdb as I attempt to debug a Twill test. I'm trying to step through socket.get_fqdn() and my key entries are garbled. I prefer to use ipdb, but the STDOUT gets messed up and printed at the end of the ipdb session. That defeats the purpose of a debugger. So I'm using pdb. Here is the code: def v1endpoint(self, port): """Return an OpenID 1.1 OpenIDServiceEndpoint for the server.""" import pdb; pdb.set_trace() base = "http://%s:%s" % (socket.getfqdn('127.0.0.1'), port) ep = OpenIDServiceEndpoint() ep.claimed_id = base + "/id/bob" ep.server_url = base + "/openidserver" ep.type_uris = [OPENID_1_1_TYPE] return ep Here is the behavior: ---------------------------------------------------------------------- Ran 2 tests in 0.029s FAILED (errors=2) Destroying test database 'default'... > /Users/Bryan/work/osqa/forum/tests.py(96)v1endpoint() -> base = "http://%s:%s" % (socket.getfqdn('127.0.0.1'), port) (Pdb) > /Users/Bryan/work/osqa/forum/tests.py(96)v1endpoint() -> base = "http://%s:%s" % (socket.getfqdn('127.0.0.1'), port) ######################################## # I enter 's' + return no character is displayed (Pdb) --Call-- > /usr/local/lib/python2.7/socket.py(124)getfqdn() -> def getfqdn(name=''): ######################################## # I enter 's' + return no character is displayed (Pdb) > /usr/local/lib/python2.7/socket.py(133)getfqdn() -> name = name.strip() ######################################## # I enter 's' + return no character is displayed (Pdb) ######################################## # I enter 's' + return no character is displayed (Pdb) *** NameError: name 'ss' is not defined ######################################## # I enter 'l' + return ; it's displayed but not the inputed data aparently (Pdb) l*** NameError: name 'ss' is not defined ######################################## # I enter 'l' + return ; it's displayed but not the inputed data aparently (Pdb) s *** NameError: name 'ls' is not defined ######################################## # I enter 'name' + return ; it's displayed but not the inputed data aparently (Pdb) ne None of the pdb commands work. Characters are added or not added. It's driving me nuts. I'm using Python 2.7 on osX-10.5.8 What is going on? I've never seen anything like this. thanks, Bryan -------------- next part -------------- An HTML attachment was scrubbed... URL: From drsalists at gmail.com Thu Nov 18 17:33:12 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Thu, 18 Nov 2010 14:33:12 -0800 Subject: Changing the EAX register with Python In-Reply-To: References: Message-ID: Here's -a- way to try - not necessarily the best way: 1) Write a little gcc .c with inline assembler, to make your EAX change 2) Call it from CPython using ctypes However, by the time you return from the code that makes your change and resume execution in the CPython interpreter, EAX may well have been changed to something new. Accumulators don't often hold the same value for very long. On Thu, Nov 18, 2010 at 12:20 PM, dutche wrote: > Hi folks, I have a unusual question here. > > How can I change the value of EAX register under python under Linux?? > As paimei does under Windows. > > My project is to have a python program that loads a C program and sets > a breakpoint at some address, and then with this breakpoint I change > the EAX register and then continue the program execution. > > With Windows and paimei I did that, but under Linux I don't know yet. > > Any ideas? > > Thank you > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From usernet at ilthio.net Thu Nov 18 17:36:51 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 18 Nov 2010 22:36:51 +0000 (UTC) Subject: How to run an EXE, with argument, capture output value References: <37037d15-63da-4f37-9508-bdcfff034670@s4g2000yql.googlegroups.com> Message-ID: On 2010-11-18, Jean-Michel Pichavant wrote: > Tim Harig wrote: >> If you are not already, I would highly suggest using Python3 with the ^^^^ >> subprocess module: > Suggesting subprocess is a good idea, *highly* suggesting python3 is > questionable. The above code works in python 2. Many libraries (those > included batteries) have not been ported yet to python 3. > Py3 is a better core language than py2, but for now, less featured. I didn't, and I don't, recommend Python3 over Python2 for just any purpose.I recommended Python3's subprocess module over the Python2's subprocess module if that is indeed possible. I happen to be one of those that feels this transition was terribly mis-handled and that there should have been provisions to allow both versions to either be maintained together or to allow modules from both versions to work together. I don't really have a huge preference for either version; but, having to deal with both of them has given the project a black eye. From noydb00 at gmail.com Thu Nov 18 17:54:23 2010 From: noydb00 at gmail.com (noydb) Date: Thu, 18 Nov 2010 14:54:23 -0800 (PST) Subject: How to run an EXE, with argument, capture output value References: <37037d15-63da-4f37-9508-bdcfff034670@s4g2000yql.googlegroups.com> <70d6c9a7-8ba9-420d-822a-0ba71888e4f4@v20g2000yqb.googlegroups.com> Message-ID: <71e489bd-429d-4814-9a0c-6b5f875b3780@30g2000yql.googlegroups.com> On Nov 18, 5:22?pm, Tim Harig wrote: > On 2010-11-18, noydb wrote: > > > import subprocess > > pig = subprocess.Popen(["C:\Halls\hallbig2.exe"], > > stdin=subprocess.PIPE, stdout=subprocess.PIPE) > > result = pig.communicate(input='C:\Halls\Input\Ea39j.txt')[-1] #I need > > to capture the, what I think is the, last output > > From the subprocess documentation: > > ? ? ? ? ? ?[62]communicate() returns a tuple (stdoutdata, stderrdata). > ? ? ? ? ? ?Note that if you want to send data to the process's stdin, > ? ? ? ? ? ?you need to create the Popen object with stdin=PIPE. Similarly, > ? ? ? ? ? ?to get anything other than None in the result tuple, you need > ? ? ? ? ? ?to give stdout=PIPE and/or stderr=PIPE too. > > By using index [-1] you are accessing the processes stderr stream. ?I am > not really sure why you changed it. ?It doesn't give you the last output. > Index 0 gives you *all* of stdout and index 1 gives you *all* of stderr, > period. ?If you wish to further disect the output to get say the last line, > then you will need to parse it separately. Okay, I see now. I did run it to start with 0 -- still same result no matter if 0 or -1. So, what is result (stdout, using [0]) in this case? (yes, i know I sound dumb - programming is not my background, obviously). A list, tuple??? How do you access stdout (or is it stdoutdata?) results? I have tried, get errors with all attempts. The exe gui returns several statistical values uopn inputing a text file (containing numerous lines of ) and clicking compute - I want just one of the values. > > > print result > > print pig.returncode > >>> None > >>> 0 > > > So the tuple is empty. ?? ?The exe executes fine and returns output in > > th exe tool itself. ?The python script seems to execute fine, no > > errors, '...returned exit code 0'. ?Any ideas/suggestions? > > No the tuple contains two items (stdout, stderr). ?The first is what the > program printed to its stdout stream (which is most likely the output you > see if you run the command at a terminal/console). ?The second is what it printed to its > stderr stream which is a channel used for out of band data such as error or > status messages. ?In this case, it is None, because you did open stderr as a > subprocess.PIPE. From calderone.jeanpaul at gmail.com Thu Nov 18 17:59:49 2010 From: calderone.jeanpaul at gmail.com (Jean-Paul Calderone) Date: Thu, 18 Nov 2010 14:59:49 -0800 (PST) Subject: Is Unladen Swallow dead? References: <2e1a4d02-1e8a-4d31-95da-f33aaf90578c@30g2000yql.googlegroups.com> <8b0b044c-34a8-4747-b68f-f4cb56882f6f@e26g2000vbz.googlegroups.com> <4ce37e01$0$1666$742ec2ed@news.sonic.net> <4ce570ff$0$1617$742ec2ed@news.sonic.net> Message-ID: <3c722259-f8f0-49af-b62a-4ee1f8c5e7cc@d8g2000yqf.googlegroups.com> On Nov 18, 1:31?pm, John Nagle wrote: > On 11/18/2010 4:24 AM, BartC wrote: > > > > > > > > > > > "John Nagle" wrote in message > >news:4ce37e01$0$1666$742ec2ed at news.sonic.net... > >> On 11/16/2010 10:24 PM, swapnil wrote: > > >>> AFAIK, the merging plan was approved by Guido early this year. I > >>> guess Google is expecting the community to drive the project > >>> from here on. That was the whole idea for merging it to mainline. > >>> From my last conversation with Collin, they are targeting Python > >>> 3.3 > > >> I think it's dead. They're a year behind on quarterly releases. > >> The last release was Q3 2009. The project failed to achieve its > >> stated goal of a 5x speedup. Not even close. More like 1.5x > >> (http://www.python.org/dev/peps/pep-3146) > > > There must have been good reasons to predict a 5x increase. > > ? ? ?For Java, adding a JIT improved performance by much more than that. > Hard-code compilers for LISP have done much better than 5x. ?The > best Java and LISP compilers approach the speed of C, while CPython > is generally considered to be roughly 60 times slower than C. ?So > 5x probably looked like a conservative goal. ?For Google, a company > which buys servers by the acre, a 5x speedup would have a big payoff. > > > Assuming the 5x speedup was shown to be viable (ie. performing the > > same benchmarks, on the same data, can be done that quickly in any > > other language, and allowing for the overheads associated with > > Python's dynamic nature), then what went wrong? > > ? ? ? Python is defined by what a naive interpreter with late binding > and dynamic name lookups, like CPython, can easily implement. ?Simply > emulating the semantics of CPython with generated code doesn't help > all that much. > > ? ? ? Because you can "monkey patch" Python objects from outside the > class, a local compiler, like a JIT, can't turn name lookups into hard > bindings. ?Nor can it make reliable decisions about the types of > objects. ?That adds a sizable performance penalty. Short of global > program analysis, the compiler can't tell when code for the hard cases > needs to be generated. ?So the hard-case code, where you figure out at > run-time, for ever use of "+", whether "+" is addition or concatenation, > has to be generated every time. ?Making that decision is far slower > than doing an add. > This isn't completely accurate. It *is* possible to write a JIT compiler for a Python runtime which has fast path code for the common case, the case where the meaning of "+" doesn't change between every opcode. PyPy has produced some pretty good results with this approach. For those who haven't seen it yet, http://speed.pypy.org/ has some graphs which reflect fairly well on PyPy's performance for benchmarks that are not entirely dissimilar to real world code. Jean-Paul From eric.frederich at gmail.com Thu Nov 18 18:12:30 2010 From: eric.frederich at gmail.com (Eric Frederich) Date: Thu, 18 Nov 2010 18:12:30 -0500 Subject: Extension on Windows Message-ID: Hello, I am trying to create an extension on Windows and I may be over my head but I have made it pretty far. I am trying to create bindings for some libraries which require me to use Visual Studio 2005. I set up the spammodule example and in VS set the output file to be a .pyd file. When I copy that .pyd file into site-packages I can use it just fine and call system('dir'). Now when I created a 2nd function to wrap a library function I get the following. ImportError: DLL load failed: The specified module could not be found. I added the correct additional include directories and specified the correct .lib file to get it to compile fine without any errors. What is going on here? I tried running python with -vvv and got no meaningful info... it just fails. What else do I need to do? Thanks, ~Eric From usernet at ilthio.net Thu Nov 18 18:16:05 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 18 Nov 2010 23:16:05 +0000 (UTC) Subject: How to run an EXE, with argument, capture output value References: <37037d15-63da-4f37-9508-bdcfff034670@s4g2000yql.googlegroups.com> <70d6c9a7-8ba9-420d-822a-0ba71888e4f4@v20g2000yqb.googlegroups.com> <71e489bd-429d-4814-9a0c-6b5f875b3780@30g2000yql.googlegroups.com> Message-ID: On 2010-11-18, noydb wrote: > On Nov 18, 5:22?pm, Tim Harig wrote: >> On 2010-11-18, noydb wrote: > Okay, I see now. I did run it to start with 0 -- still same result no > matter if 0 or -1. > So, what is result (stdout, using [0]) in this case? (yes, i know I > sound dumb - programming is not my background, obviously). A list, Nope, this one is my fault, I never should have posted being so tired. I was reading posts after being unable to sleep and missed something important about what you said. Sorry about the confusion. > tuple??? How do you access stdout (or is it stdoutdata?) results? I > have tried, get errors with all attempts. The exe gui returns several GUI!!!! Ewwwww. I missed that part. GUIs, on Windows, do not have the standard streams. GUIs are in general, ugly to automate through the GUI itself. I would be much better if the program can be run with command line options, text interface, or if provides an automation object through COM or .Net. As workaround, if you run Python through Windows Script Host, you can open the program with WshShell and automate it, by sending it the keystrokes as you perform the action by typing, with SendKeys() From noydb00 at gmail.com Thu Nov 18 18:20:57 2010 From: noydb00 at gmail.com (noydb) Date: Thu, 18 Nov 2010 15:20:57 -0800 (PST) Subject: How to run an EXE, with argument, capture output value References: <37037d15-63da-4f37-9508-bdcfff034670@s4g2000yql.googlegroups.com> <70d6c9a7-8ba9-420d-822a-0ba71888e4f4@v20g2000yqb.googlegroups.com> <71e489bd-429d-4814-9a0c-6b5f875b3780@30g2000yql.googlegroups.com> Message-ID: <850908d0-26d4-45a5-86bc-855445fde0bf@a37g2000yqi.googlegroups.com> On Nov 18, 5:54?pm, noydb wrote: > On Nov 18, 5:22?pm, Tim Harig wrote: > > > > > > > On 2010-11-18, noydb wrote: > > > > import subprocess > > > pig = subprocess.Popen(["C:\Halls\hallbig2.exe"], > > > stdin=subprocess.PIPE, stdout=subprocess.PIPE) > > > result = pig.communicate(input='C:\Halls\Input\Ea39j.txt')[-1] #I need > > > to capture the, what I think is the, last output > > > From the subprocess documentation: > > > ? ? ? ? ? ?[62]communicate() returns a tuple (stdoutdata, stderrdata). > > ? ? ? ? ? ?Note that if you want to send data to the process's stdin, > > ? ? ? ? ? ?you need to create the Popen object with stdin=PIPE. Similarly, > > ? ? ? ? ? ?to get anything other than None in the result tuple, you need > > ? ? ? ? ? ?to give stdout=PIPE and/or stderr=PIPE too. > > > By using index [-1] you are accessing the processes stderr stream. ?I am > > not really sure why you changed it. ?It doesn't give you the last output. > > Index 0 gives you *all* of stdout and index 1 gives you *all* of stderr, > > period. ?If you wish to further disect the output to get say the last line, > > then you will need to parse it separately. > > Okay, I see now. ?I did run it to start with 0 -- still same result no > matter if 0 or -1. > So, what is result (stdout, using [0]) in this case? ?(yes, i know I > sound dumb - programming is not my background, obviously). ?A list, > tuple??? ?How do you access stdout (or is it stdoutdata?) results? ?I > have tried, get errors with all attempts. ?The exe gui returns several > statistical values uopn inputing a text file (containing numerous > lines of ) and clicking compute - I want just one > of the values. > > > > > > > > print result > > > print pig.returncode > > >>> None > > >>> 0 > > > > So the tuple is empty. ?? ?The exe executes fine and returns output in > > > th exe tool itself. ?The python script seems to execute fine, no > > > errors, '...returned exit code 0'. ?Any ideas/suggestions? > > > No the tuple contains two items (stdout, stderr). ?The first is what the > > program printed to its stdout stream (which is most likely the output you > > see if you run the command at a terminal/console). ?The second is what it printed to its > > stderr stream which is a channel used for out of band data such as error or > > status messages. ?In this case, it is None, because you did open stderr as a > > subprocess.PIPE.- Hide quoted text - > > - Show quoted text -- Hide quoted text - > > - Show quoted text - stdout is a file object From noydb00 at gmail.com Thu Nov 18 18:28:18 2010 From: noydb00 at gmail.com (noydb) Date: Thu, 18 Nov 2010 15:28:18 -0800 (PST) Subject: How to run an EXE, with argument, capture output value References: <37037d15-63da-4f37-9508-bdcfff034670@s4g2000yql.googlegroups.com> <70d6c9a7-8ba9-420d-822a-0ba71888e4f4@v20g2000yqb.googlegroups.com> <71e489bd-429d-4814-9a0c-6b5f875b3780@30g2000yql.googlegroups.com> <850908d0-26d4-45a5-86bc-855445fde0bf@a37g2000yqi.googlegroups.com> Message-ID: <0594c8c1-e13c-4057-9ff5-783ad97fd0a2@l17g2000yqe.googlegroups.com> On Nov 18, 6:20?pm, noydb wrote: > On Nov 18, 5:54?pm, noydb wrote: > > > > > > > On Nov 18, 5:22?pm, Tim Harig wrote: > > > > On 2010-11-18, noydb wrote: > > > > > import subprocess > > > > pig = subprocess.Popen(["C:\Halls\hallbig2.exe"], > > > > stdin=subprocess.PIPE, stdout=subprocess.PIPE) > > > > result = pig.communicate(input='C:\Halls\Input\Ea39j.txt')[-1] #I need > > > > to capture the, what I think is the, last output > > > > From the subprocess documentation: > > > > ? ? ? ? ? ?[62]communicate() returns a tuple (stdoutdata, stderrdata). > > > ? ? ? ? ? ?Note that if you want to send data to the process's stdin, > > > ? ? ? ? ? ?you need to create the Popen object with stdin=PIPE. Similarly, > > > ? ? ? ? ? ?to get anything other than None in the result tuple, you need > > > ? ? ? ? ? ?to give stdout=PIPE and/or stderr=PIPE too. > > > > By using index [-1] you are accessing the processes stderr stream. ?I am > > > not really sure why you changed it. ?It doesn't give you the last output. > > > Index 0 gives you *all* of stdout and index 1 gives you *all* of stderr, > > > period. ?If you wish to further disect the output to get say the last line, > > > then you will need to parse it separately. > > > Okay, I see now. ?I did run it to start with 0 -- still same result no > > matter if 0 or -1. > > So, what is result (stdout, using [0]) in this case? ?(yes, i know I > > sound dumb - programming is not my background, obviously). ?A list, > > tuple??? ?How do you access stdout (or is it stdoutdata?) results? ?I > > have tried, get errors with all attempts. ?The exe gui returns several > > statistical values uopn inputing a text file (containing numerous > > lines of ) and clicking compute - I want just one > > of the values. > > > > > print result > > > > print pig.returncode > > > >>> None > > > >>> 0 > > > > > So the tuple is empty. ?? ?The exe executes fine and returns output in > > > > th exe tool itself. ?The python script seems to execute fine, no > > > > errors, '...returned exit code 0'. ?Any ideas/suggestions? > > > > No the tuple contains two items (stdout, stderr). ?The first is what the > > > program printed to its stdout stream (which is most likely the output you > > > see if you run the command at a terminal/console). ?The second is what it printed to its > > > stderr stream which is a channel used for out of band data such as error or > > > status messages. ?In this case, it is None, because you did open stderr as a > > > subprocess.PIPE.- Hide quoted text - > > > - Show quoted text -- Hide quoted text - > > > - Show quoted text - > > stdout is a file object- Hide quoted text - > > - Show quoted text - if I do >>> print pig.communicate() ('', None) Doesn't that mean it is empty? From steve at REMOVE-THIS-cybersource.com.au Thu Nov 18 19:07:05 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Nov 2010 00:07:05 GMT Subject: Program, Application, and Software References: <87hbffa30d.fsf@benfinney.id.au> Message-ID: <4ce5bfa9$0$29966$c3e8da3$5496439d@news.astraweb.com> On Thu, 18 Nov 2010 14:21:47 +0000, Martin Gregorie wrote: > I use 'script' to refer to programs written in languages that don't have > a separate compile phase which must be run before the program can be > executed. IOW Python and Perl programs are scripts aloing with programs > written as awk, Javascript and bash scripts. You're mistaken then about Python, because it does have a separate compilation phase that runs before the program can be executed. Where do you think the .pyc files come from, and what did you think the compile() function did? It just happens automatically, rather than manually. For that matter, what about languages with JIT compilers, like Java or, yes, Python? CPython itself has no built-in JIT, but PyPy does, and Psyco is an optimizing JIT compiler for CPython on some hardware. I think the difference between "scripts" and "programs" is about as meaningful as the difference between "mountains" and "hills" -- there clearly is a difference between *this specific* hill and *that specific* mountain, but any general distinction between hills and mountains is arbitrary and artificial. Maybe, once upon a time, there was a meaningful distinction to be made between purely interpreted languages and purely compiled languages. But today, when "interpreted" languages have a compilation phase, and "compiled" languages have the equivalent of eval() and do their compilation at runtime, such a distinction is now fairly arbitrary. Better questions are: * Does the program compile to native machine code or byte code? * How efficient is the machine code, or the virtual machine that executes the byte code? What do you mean by "efficient"? * Is there an integrated parse-compile-execute cycle, or does the developer have to perform them individually? * To what degree is the syntax of the language aimed at rapid development and/or runtime efficiency? Harder questions to ask, and answer, than "Is that language for writing scripts or programs or applications?", but the answers are far more meaningful. -- Steven From steve at REMOVE-THIS-cybersource.com.au Thu Nov 18 19:09:37 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Nov 2010 00:09:37 GMT Subject: Some syntactic sugar proposals References: <87mxp7gbdf.fsf.mdw@metalzone.distorted.org.uk> <4ce4b043$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d3q3dljs.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <4ce5c041$0$29966$c3e8da3$5496439d@news.astraweb.com> On Thu, 18 Nov 2010 09:32:23 +0000, Mark Wooding wrote: [...] > You're wrong. Python evaluates these left-to-right, as I said. > Parentheses override operator associativity; they don't affect > evaluation order at all. Fair enough. I concede your point. [...] >> Not everything needs to be a one liner. If you need this, do it the >> old- fashioned way: >> >> t = foo() >> if not pred(t): t = default_value > > I already explained how to write it as a one-liner: > > t = (lambda y: y if pred(y) else default_value)(foo()) I didn't say it couldn't be written as a one-liner. I suggested that it was better not to. The costs of the one-liner are: * reduced readability; * requires an increased level of knowledge of the reader ("what's lambda do?"); * runtime inefficiency (you create a function object, only to use it once then throw it away). The advantages? * one fewer line of code. In my experience, the obsessiveness in which some people look for one- liners is far from helpful, and goes against the spirit of Python. This isn't Perl :) -- Steven From python at mrabarnett.plus.com Thu Nov 18 19:26:41 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 19 Nov 2010 00:26:41 +0000 Subject: Program, Application, and Software In-Reply-To: <4ce5bfa9$0$29966$c3e8da3$5496439d@news.astraweb.com> References: <87hbffa30d.fsf@benfinney.id.au> <4ce5bfa9$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4CE5C441.1020209@mrabarnett.plus.com> On 19/11/2010 00:07, Steven D'Aprano wrote: > On Thu, 18 Nov 2010 14:21:47 +0000, Martin Gregorie wrote: > >> I use 'script' to refer to programs written in languages that don't have >> a separate compile phase which must be run before the program can be >> executed. IOW Python and Perl programs are scripts aloing with programs >> written as awk, Javascript and bash scripts. > > You're mistaken then about Python, because it does have a separate > compilation phase that runs before the program can be executed. Where do > you think the .pyc files come from, and what did you think the compile() > function did? It just happens automatically, rather than manually. > [snip] I think what he means is that you don't need explicitly to compile and then run. From alex.kapps at web.de Thu Nov 18 19:43:28 2010 From: alex.kapps at web.de (Alexander Kapps) Date: Fri, 19 Nov 2010 01:43:28 +0100 Subject: Program, Application, and Software In-Reply-To: <4CE5C441.1020209@mrabarnett.plus.com> References: <87hbffa30d.fsf@benfinney.id.au> <4ce5bfa9$0$29966$c3e8da3$5496439d@news.astraweb.com> <4CE5C441.1020209@mrabarnett.plus.com> Message-ID: <4CE5C830.4000700@web.de> On 19.11.2010 01:26, MRAB wrote: > On 19/11/2010 00:07, Steven D'Aprano wrote: >> On Thu, 18 Nov 2010 14:21:47 +0000, Martin Gregorie wrote: >> >>> I use 'script' to refer to programs written in languages that don't have >>> a separate compile phase which must be run before the program can be >>> executed. IOW Python and Perl programs are scripts aloing with programs >>> written as awk, Javascript and bash scripts. >> >> You're mistaken then about Python, because it does have a separate >> compilation phase that runs before the program can be executed. Where do >> you think the .pyc files come from, and what did you think the compile() >> function did? It just happens automatically, rather than manually. >> > [snip] > I think what he means is that you don't need explicitly to compile and > then run. What difference does it make? Is 'print "Hello"' a program or a script? Are you saying, that it depends on whether you have to manually call some compiler? From martin at address-in-sig.invalid Thu Nov 18 19:57:42 2010 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Fri, 19 Nov 2010 00:57:42 +0000 (UTC) Subject: Program, Application, and Software References: <87hbffa30d.fsf@benfinney.id.au> <4ce5bfa9$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, 19 Nov 2010 00:07:05 +0000, Steven D'Aprano wrote: > On Thu, 18 Nov 2010 14:21:47 +0000, Martin Gregorie wrote: > >> I use 'script' to refer to programs written in languages that don't >> have a separate compile phase which must be run before the program can >> be executed. IOW Python and Perl programs are scripts aloing with >> programs written as awk, Javascript and bash scripts. > > > You're mistaken then about Python, because it does have a separate > compilation phase that runs before the program can be executed. Where do > you think the .pyc files come from, and what did you think the compile() > function did? It just happens automatically, rather than manually. > Notice my mention of the hash-bang line? That makes it quite clear that I did not mean what you're reading into "separate compile phase which must be run" because hash-bang means you can feed source into the run-time execution system, and also means that by definition the source contains or references everything a program needs to run and that the source code translation step, if there is one, is fast enough for the time it takes to be negligible. Those aren't necessarily the case with a separate compilation step. .pyc files are an optional extra: in a *nix environment they are not produced if you use a hash-bang line to execute the source file: they only appear if you run the source with a "python file.py" command. -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From SSharma84 at slb.com Thu Nov 18 20:30:21 2010 From: SSharma84 at slb.com (Sachin Kumar Sharma) Date: Fri, 19 Nov 2010 01:30:21 +0000 Subject: Advise for numerical programming content (New python user) Message-ID: <75C2FED246299A478280FA1470EDA4430A966005@NL0230MBX06N2.DIR.slb.com> Python Users, I am an average Fortran user. I am new to python and I am currently evaluating options and functionalities of numerical programming and related 2d and 3d graphic outputs with python. Kindly share your experience in scientific programming with python like how do you like it, comparison with Fortran and C++. Which version of python + numpy+scipy are compatible with each other or if any other numerical analysis package is available (I am working on windows environment.) Does graphic output like maps, histogram, crossplot, tornado charts is good enough with basic installation or needs some additional packages? Your feedback is valuable for me to start. Thanks & Regards Sachin ************************************************************************ Sachin Kumar Sharma Senior Geoscientist -------------- next part -------------- An HTML attachment was scrubbed... URL: From mdw at distorted.org.uk Thu Nov 18 20:35:55 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Fri, 19 Nov 2010 01:35:55 +0000 Subject: Is Unladen Swallow dead? References: <2e1a4d02-1e8a-4d31-95da-f33aaf90578c@30g2000yql.googlegroups.com> <8b0b044c-34a8-4747-b68f-f4cb56882f6f@e26g2000vbz.googlegroups.com> <4ce37e01$0$1666$742ec2ed@news.sonic.net> <4ce570ff$0$1617$742ec2ed@news.sonic.net> Message-ID: <87vd3uccxw.fsf.mdw@metalzone.distorted.org.uk> John Nagle writes: > Python is defined by what a naive interpreter with late binding > and dynamic name lookups, like CPython, can easily implement. Simply > emulating the semantics of CPython with generated code doesn't help > all that much. Indeed. > Because you can "monkey patch" Python objects from outside the > class, a local compiler, like a JIT, can't turn name lookups into hard > bindings. Nor can it make reliable decisions about the types of > objects. But it /can/ make guesses. A dynamic runtime doesn't have to predict everything right in advance; it only has to predict most things sort of well enough, and fix up the things it got wrong before anyone notices. For example, A Python compiler could inline a function call if it makes a note to recompile the calling function if the called function is modified. Most functions aren't redefined, so this is probably a pretty good guess. > That adds a sizable performance penalty. Short of global program > analysis, the compiler can't tell when code for the hard cases needs > to be generated. The right approach is to guess that things are going to be done the easy way, and then detect when the guess is wrong. > So the hard-case code, where you figure out at run-time, for ever use > of "+", whether "+" is addition or concatenation, has to be generated > every time. Making that decision is far slower than doing an add. There's an old trick here called `inline caching'. The first time a function is called, compile it so as to assume that types of things are as you found this time: inline simple methods, and so on. Insert some quick type checks at the top: is this going to work next time? If not, take a trap back into the compiler. The traditional approach is to replace the mispredictions with full dispatches (`monomorphic inline caching'); the clever approach tolerates a few different types, dispatching to optimized code for each (`polymorphic inline caching'), unless there are just too many decision points and you give up. There are time/space tradeoffs to be made here too. Fortunately, you don't have to compile everything super-optimized from the get-go: you can dynamically identify the inner loops which need special attention, and get the compiler to really stare hard at them. The rest of the program might plausibly be left interpreted much of the time for all anyone will care. > I've referred to this problem as "gratuitous hidden dynamism". > Most things which could be changed dynamically in a Python program > usually aren't. This is one of the crucial observations for making a dynamic language go fast; the other is that you still have the compiler around if you guessed wrong. An aggressively dynamic runtime has two enormous advantages over batch compilers such as are traditionally used for C: it gets the entire program in one go, and it gets to see the real live data that the program's meant to run against. Given that, I'd expect it to be able to /beat/ a batch compiler in terms of performance. > This has been pointed out many times by many people. There's > even a PhD thesis on the topic. Without a few restrictions, so > that a compiler can at least tell when support for the hard cases > is needed, Python cannot be compiled well. This assumes static compilation. It's the wrong approach for a dynamic language like Python. -- [mdw] From phlip2005 at gmail.com Thu Nov 18 20:45:04 2010 From: phlip2005 at gmail.com (Phlip) Date: Thu, 18 Nov 2010 17:45:04 -0800 (PST) Subject: Bunch 2.0 - a dict with a default Message-ID: <58298828-d882-45f8-a396-b8f164d49570@g7g2000vbl.googlegroups.com> Pythonistas: If everyone likes this post, then the code is a "snippet" for community edification. Otherwise, it's a question: How to do this kind of thing better? I want a dict() variant that passes these test cases: map = Map() assert not(map.has_key('_default')) map = Map(yo='dude') assert map['yo'] == 'dude' assert map.yo == 'dude' assert None == map['whatever'] assert not(map.has_key('_default')) map = Map(yo='dude', _default='q') assert 'q' == map['whatever'] assert not(map.has_key('_default')) That's like Bunch, but with a default value. (That makes code with excess if statements less likely.) So here's the implementation: def Map(*args, **kwargs): value = kwargs.get('_default', None) if kwargs.has_key('_default'): del kwargs['_default'] class _DefMap(dict): def __init__(self, *a, **kw): dict.__init__(self, *a, **kw) self.__dict__ = self def __getitem__(self, key): if not self.has_key(key): self[key] = value return dict.__getitem__(self, key) return _DefMap(*args, **kwargs) -- Phlip http://bit.ly/ZeekLand From mdw at distorted.org.uk Thu Nov 18 20:53:13 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Fri, 19 Nov 2010 01:53:13 +0000 Subject: Some syntactic sugar proposals References: <87mxp7gbdf.fsf.mdw@metalzone.distorted.org.uk> <4ce4b043$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d3q3dljs.fsf.mdw@metalzone.distorted.org.uk> <4ce5c041$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87r5eicc52.fsf.mdw@metalzone.distorted.org.uk> Steven D'Aprano writes: > >> Not everything needs to be a one liner. If you need this, do it the > >> old- fashioned way: > >> > >> t = foo() > >> if not pred(t): t = default_value > > > > I already explained how to write it as a one-liner: > > > > t = (lambda y: y if pred(y) else default_value)(foo()) > > I didn't say it couldn't be written as a one-liner. I suggested that it > was better not to. Ahh. I misunderstood the first sentence above as dismissing the possibility. Sorry. I agree that it's not a /nice/ one-liner. ;-) > The costs of the one-liner are: > > * reduced readability; > * requires an increased level of knowledge of the reader ("what's lambda > do?"); > * runtime inefficiency (you create a function object, only to use it once > then throw it away). This last can be obviated by a clever compiler (which, in our case, we have not got). The second could be considered an advantage: it's educational! > The advantages? > > * one fewer line of code. > > In my experience, the obsessiveness in which some people look for one- > liners is far from helpful, and goes against the spirit of Python. This > isn't Perl :) Oh, I agree completely. On the other hand, it's just /fun/. Python is a fun language and using its features in playfully unusual ways is enjoyable; like a good pun in a natural language. Just as puns aren't always appropriate in written language, playful code isn't always appropriate either; but that doesn't mean it's never appropriate. (Java has no sense of humour. C++ does have, but it's a bit weird.) -- [mdw] From ckaynor at zindagigames.com Thu Nov 18 20:55:39 2010 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Thu, 18 Nov 2010 17:55:39 -0800 Subject: Bunch 2.0 - a dict with a default In-Reply-To: <58298828-d882-45f8-a396-b8f164d49570@g7g2000vbl.googlegroups.com> References: <58298828-d882-45f8-a396-b8f164d49570@g7g2000vbl.googlegroups.com> Message-ID: You may want to look at the collections.defaultdict class. It takes in a factory function for default values. You can also implement your class by overriding the __missing__ method of the dict class, rather than overriding the __getitem__. Both were added in Python 2.5 according to the documentation. Chris On Thu, Nov 18, 2010 at 5:45 PM, Phlip wrote: > Pythonistas: > > If everyone likes this post, then the code is a "snippet" for > community edification. Otherwise, it's a question: How to do this kind > of thing better? > > I want a dict() variant that passes these test cases: > > map = Map() > assert not(map.has_key('_default')) > > map = Map(yo='dude') > assert map['yo'] == 'dude' > assert map.yo == 'dude' > assert None == map['whatever'] > assert not(map.has_key('_default')) > > map = Map(yo='dude', _default='q') > assert 'q' == map['whatever'] > assert not(map.has_key('_default')) > > That's like Bunch, but with a default value. (That makes code with > excess if statements less likely.) > > So here's the implementation: > > def Map(*args, **kwargs): > value = kwargs.get('_default', None) > if kwargs.has_key('_default'): del kwargs['_default'] > > class _DefMap(dict): > def __init__(self, *a, **kw): > dict.__init__(self, *a, **kw) > self.__dict__ = self > > def __getitem__(self, key): > if not self.has_key(key): self[key] = value > return dict.__getitem__(self, key) > > return _DefMap(*args, **kwargs) > > -- > Phlip > http://bit.ly/ZeekLand > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mdw at distorted.org.uk Thu Nov 18 21:05:10 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Fri, 19 Nov 2010 02:05:10 +0000 Subject: Program, Application, and Software References: <87hbffa30d.fsf@benfinney.id.au> <4ce5bfa9$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87mxp6cbl5.fsf.mdw@metalzone.distorted.org.uk> Steven D'Aprano writes: > On Thu, 18 Nov 2010 14:21:47 +0000, Martin Gregorie wrote: > > > I use 'script' to refer to programs written in languages that don't have > > a separate compile phase which must be run before the program can be > > executed. IOW Python and Perl programs are scripts aloing with programs > > written as awk, Javascript and bash scripts. > > You're mistaken then about Python, because it does have a separate > compilation phase that runs before the program can be executed. Where do > you think the .pyc files come from, and what did you think the compile() > function did? It just happens automatically, rather than manually. I think Martin meant that there's no /explicit/ compilation phase. As a case in point, tcc is an optimizing native-code compiler for C which is so fast at generating code that it has a mode which accepts an initial `#!' line in its input; the documentation refers to C `scripts'. Awk, Javascript and Perl have full compilation phases too, but they're hidden from the user; bash certainly builds a parse tree but I don't know whether it just walks that or has some other kind of internal representation. > Maybe, once upon a time, there was a meaningful distinction to be made > between purely interpreted languages and purely compiled languages. No, there never was; only between interpreting and compiling implementations. > But today, when "interpreted" languages have a compilation phase, and > "compiled" languages have the equivalent of eval() and do their > compilation at runtime, such a distinction is now fairly arbitrary. > Better questions are: > > * Does the program compile to native machine code or byte code? > > * How efficient is the machine code, or the virtual machine that executes > the byte code? What do you mean by "efficient"? > > * Is there an integrated parse-compile-execute cycle, or does the > developer have to perform them individually? > > * To what degree is the syntax of the language aimed at rapid development > and/or runtime efficiency? > > Harder questions to ask, and answer, than "Is that language for writing > scripts or programs or applications?", but the answers are far more > meaningful. Maybe. I note that there are Lisp systems (plural!) which compile to native code (only -- with no interpreter at all), but fully support runtime `eval', batch compilation of source files, aggressive optimization for speed and/or space, and so on. So I think that some of the above questions, at least, present false dichotomies: one doesn't have to choose one or the other; one can have cake and eat it too. Also some of the questions are about the language and some are about the implementation. It's important not to get the two confused. -- [mdw] From pavlovevidence at gmail.com Thu Nov 18 21:23:24 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 18 Nov 2010 18:23:24 -0800 (PST) Subject: Is Unladen Swallow dead? References: <2e1a4d02-1e8a-4d31-95da-f33aaf90578c@30g2000yql.googlegroups.com> <8b0b044c-34a8-4747-b68f-f4cb56882f6f@e26g2000vbz.googlegroups.com> <4ce37e01$0$1666$742ec2ed@news.sonic.net> <4ce570ff$0$1617$742ec2ed@news.sonic.net> <3c722259-f8f0-49af-b62a-4ee1f8c5e7cc@d8g2000yqf.googlegroups.com> Message-ID: <4f5a7118-bfbe-4a44-9cd2-94c8dbaa8169@e26g2000vbz.googlegroups.com> On Nov 18, 2:59?pm, Jean-Paul Calderone wrote: > On Nov 18, 1:31?pm, John Nagle wrote: > > > > > > > On 11/18/2010 4:24 AM, BartC wrote: > > > > "John Nagle" wrote in message > > >news:4ce37e01$0$1666$742ec2ed at news.sonic.net... > > >> On 11/16/2010 10:24 PM, swapnil wrote: > > > >>> AFAIK, the merging plan was approved by Guido early this year. I > > >>> guess Google is expecting the community to drive the project > > >>> from here on. That was the whole idea for merging it to mainline. > > >>> From my last conversation with Collin, they are targeting Python > > >>> 3.3 > > > >> I think it's dead. They're a year behind on quarterly releases. > > >> The last release was Q3 2009. The project failed to achieve its > > >> stated goal of a 5x speedup. Not even close. More like 1.5x > > >> (http://www.python.org/dev/peps/pep-3146) > > > > There must have been good reasons to predict a 5x increase. > > > ? ? ?For Java, adding a JIT improved performance by much more than that. > > Hard-code compilers for LISP have done much better than 5x. ?The > > best Java and LISP compilers approach the speed of C, while CPython > > is generally considered to be roughly 60 times slower than C. ?So > > 5x probably looked like a conservative goal. ?For Google, a company > > which buys servers by the acre, a 5x speedup would have a big payoff. > > > > Assuming the 5x speedup was shown to be viable (ie. performing the > > > same benchmarks, on the same data, can be done that quickly in any > > > other language, and allowing for the overheads associated with > > > Python's dynamic nature), then what went wrong? > > > ? ? ? Python is defined by what a naive interpreter with late binding > > and dynamic name lookups, like CPython, can easily implement. ?Simply > > emulating the semantics of CPython with generated code doesn't help > > all that much. > > > ? ? ? Because you can "monkey patch" Python objects from outside the > > class, a local compiler, like a JIT, can't turn name lookups into hard > > bindings. ?Nor can it make reliable decisions about the types of > > objects. ?That adds a sizable performance penalty. Short of global > > program analysis, the compiler can't tell when code for the hard cases > > needs to be generated. ?So the hard-case code, where you figure out at > > run-time, for ever use of "+", whether "+" is addition or concatenation, > > has to be generated every time. ?Making that decision is far slower > > than doing an add. > > This isn't completely accurate. ?It *is* possible to write a JIT > compiler > for a Python runtime which has fast path code for the common case, the > case > where the meaning of "+" doesn't change between every opcode. ?PyPy > has > produced some pretty good results with this approach. Right. The key is to be able to dispatch on the type of object once for a given chunk of code, which is possible if you do some kind of flow path analysis on the function/chunk. PyPy is starting to look much better of late, I kind of thought their first approach was wrong (or at least too much) but they seem to have pushed though it. Carl Banks From tjreedy at udel.edu Thu Nov 18 21:54:42 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 18 Nov 2010 21:54:42 -0500 Subject: Program, Application, and Software In-Reply-To: <87mxp6cbl5.fsf.mdw@metalzone.distorted.org.uk> References: <87hbffa30d.fsf@benfinney.id.au> <4ce5bfa9$0$29966$c3e8da3$5496439d@news.astraweb.com> <87mxp6cbl5.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On 11/18/2010 9:05 PM, Mark Wooding wrote: >> Maybe, once upon a time, there was a meaningful distinction to be made >> between purely interpreted languages and purely compiled languages. > > No, there never was; only between interpreting and compiling > implementations. Right. I remember using a C *interpreter* about 25 years ago on Unix. And on Windows, as I remember, the Borland TurboC system let one compile, link, and run with one command. A language is just a language, not an implementation. -- Terry Jan Reedy From steve at holdenweb.com Thu Nov 18 21:55:49 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 18 Nov 2010 21:55:49 -0500 Subject: Distribution of Python Scripts In-Reply-To: References: Message-ID: On 11/18/2010 11:48 AM, tazz_ben wrote: > Hi Folks - > > I'm an experienced programmer, but this is my first app with python, > so I apologize for any stupidity on my part. So I've written/still > working on a command line tool written in Python. It talks to a web > service, so there really isn't anything in it that is dependent on a > particular os. My goal is to distribute the script as a tool to my > users so they can use it (they are on multiple platforms), the vast > majority are not programmers. > > So, I'm looking for a way to distribute the app that takes care of > details like them having python installed, or having an older version > etc. From reading some docs it sounds like "Squeeze" did exactly this > back in the day, but it is ancient and I'm writing in 2.7. Just to > be clear I could care less if they see the source code, my goal is all > around ease of use. I would love to have one distribution file for > all platforms, but I can live with making three if that's the only > option. > > So, what's my options. The only one I could find was cxFreeze: http://cx-freeze.sourceforge.net/ regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From nagle at animats.com Thu Nov 18 22:57:44 2010 From: nagle at animats.com (John Nagle) Date: Thu, 18 Nov 2010 19:57:44 -0800 Subject: Is Unladen Swallow dead? In-Reply-To: <87vd3uccxw.fsf.mdw@metalzone.distorted.org.uk> References: <2e1a4d02-1e8a-4d31-95da-f33aaf90578c@30g2000yql.googlegroups.com> <8b0b044c-34a8-4747-b68f-f4cb56882f6f@e26g2000vbz.googlegroups.com> <4ce37e01$0$1666$742ec2ed@news.sonic.net> <4ce570ff$0$1617$742ec2ed@news.sonic.net> <87vd3uccxw.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <4ce5f5c4$0$1592$742ec2ed@news.sonic.net> On 11/18/2010 5:35 PM, Mark Wooding wrote: > John Nagle writes: > >> Python is defined by what a naive interpreter with late binding >> and dynamic name lookups, like CPython, can easily implement. Simply >> emulating the semantics of CPython with generated code doesn't help >> all that much. > > Indeed. > >> Because you can "monkey patch" Python objects from outside the >> class, a local compiler, like a JIT, can't turn name lookups into hard >> bindings. Nor can it make reliable decisions about the types of >> objects. > > But it /can/ make guesses. A dynamic runtime doesn't have to predict > everything right in advance; it only has to predict most things sort of > well enough, and fix up the things it got wrong before anyone notices. > For example, A Python compiler could inline a function call if it makes > a note to recompile the calling function if the called function is > modified. Most functions aren't redefined, so this is probably a pretty > good guess. > >> That adds a sizable performance penalty. Short of global program >> analysis, the compiler can't tell when code for the hard cases needs >> to be generated. > > The right approach is to guess that things are going to be done the easy > way, and then detect when the guess is wrong. That's been done successfully for Self and JavaScript. It's not easy. See this talk on JaegerMonkey: http://blog.cdleary.com/2010/09/picing-on-javascript-for-fun-and-profit/ The effort needed to do that for Javascript is justified by the size of the installed base. The Unladen Swallow people had plans to go in that direction, but they underestimated the size of the job. John Nagle From aahz at pythoncraft.com Thu Nov 18 23:04:28 2010 From: aahz at pythoncraft.com (Aahz) Date: 18 Nov 2010 20:04:28 -0800 Subject: Python has a "really hidden encapsulation"? References: <87iq0vpaw3.fsf@gmail.com> <5286c48b-0567-4e13-bfbc-aaaeab0a6438@v20g2000yqb.googlegroups.com> <87fwvw214g.fsf@gmail.com> Message-ID: In article <87fwvw214g.fsf at gmail.com>, Arnaud Delobelle wrote: > >Are you referring to the fact that in Python, if an attribute is a >property, the __dict__ lookup on the instance is not performed? As in: > >>>> class A: >... @property >... def x(self): return 42 >... >>>> a = A() >>>> a.__dict__['x'] = 24 >>>> a.x >42 >>>> a.__dict__['x'] >24 > >This is documented, but I actually don't know the reason for it. Because otherwise you would be able to overwrite the property with a value. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Look, it's your affair if you want to play with five people, but don't go calling it doubles." --John Cleese anticipates Usenet From steve at holdenweb.com Thu Nov 18 23:19:19 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 18 Nov 2010 23:19:19 -0500 Subject: Program, Application, and Software In-Reply-To: References: <87hbffa30d.fsf@benfinney.id.au> <4ce5bfa9$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 11/18/2010 7:57 PM, Martin Gregorie wrote: [...] > .pyc files are an optional extra: in a *nix environment they are not > produced if you use a hash-bang line to execute the source file: they > only appear if you run the source with a "python file.py" command. > Close, but no cigar. They are only created (assuming file permissions permit) when the module is *imported*. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From rtomek at ceti.com.pl Thu Nov 18 23:23:29 2010 From: rtomek at ceti.com.pl (Tomasz Rola) Date: Fri, 19 Nov 2010 05:23:29 +0100 Subject: What was your strategy? In-Reply-To: <7xzktbcqox.fsf@ruckus.brouhaha.com> References: <7xzktbcqox.fsf@ruckus.brouhaha.com> Message-ID: On Sun, 14 Nov 2010, Paul Rubin wrote: > Jorge Biquez writes: > > I was wondering if you can share what was the strategy you followed to > > master Python (Yes I know I have to work hard study and practice a lot). > > 1. Read the tutorial http://docs.python.org/tutorial/ > 2. Start writing code, and encounter various issues as usually happens. > 3. Refer to the other reference manuals, web search, and ask questions > in the newsgroup as you run into issues. > 4. After a while you'll have hit most of the usual issues and learned > how to deal with them, and how to find resolution for new issues that > might come up. That's about as close to mastery as one normally > reaches in this world. > > Python is a pretty easy language if you have a reasonable programming > background when you first start with it. I think the way it's currently > organized, it may not be so great for self-study if you're not already a > programmer. > > > I mean did you use special books, special sites, > > Nah. Wow, exactly same strategy by me. Do you think it should be GPLed, by chance ;-) ? I find this way of learning to be a bit hard (it must have helped that I was no beginner), but somehow none other option came to my head when I was approaching Python some years ago. I guess I'm not a good follower of various written "rules of engagement". So, after tutorial I jumped over the standard Python docs (module index, plus library & language references) until I found whatever was needed at the moment. So choice of strategy depends on choice maker. BTW, I think it was very important in my case to have specific program in mind, begging me to write it in Python. So learning was more exciting thanks to this. I came to Python from some other languages, of which only C retains it's value to me nowadays. I consider myself kind of departed from Pythonland, in search of some other, maybe better alternatives - but it is quite possible Python will join C. I'm undecided, as I've not tried 3.x yet. As a side note, I'm not quite sure Python is good for beginners. Yes, it is very simple and easy to grasp. And yes, it is a bit too simple, maybe? So a beginner learns to think in terms of nails and hammers, but may never hear of screwdrivers in his programing life. I may be wrong but, thinking of it, I feel it was good I have been exposed to Pascal and C (and few other things) long before Python. I would advise Python to casual/Sunday programers, knowing there is big chance they will never learn more than this, so Python is their best option IMHO. But in case of "serious"/"serial" ;-) programing, I would save Python for second or third language. I mean, I perceive it as rather "one way to do it" language and forcing this "one way" on unformed programer doesn't look good. No offence. See? I'm still here. 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 steve at REMOVE-THIS-cybersource.com.au Thu Nov 18 23:26:28 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Nov 2010 04:26:28 GMT Subject: what's the precision of fractions.Fraction? References: Message-ID: <4ce5fc73$0$29966$c3e8da3$5496439d@news.astraweb.com> On Thu, 18 Nov 2010 20:08:00 +0100, Stefan Sonnenberg-Carstens wrote: > If you need it really *precise*, cast your Fractions into type Decimal: It's actually the opposite. Decimal has many advantages, but being "really precise" is not one of them. It suffers the exact same issues re precision and round-off as binary floating point. It is easy to demonstrate that there are numbers which cannot be represented precisely as Decimals no matter how many decimal places you use, but can be represented exactly as Fractions. Fraction can exactly represent every Decimal, but Decimal cannot represent exactly every Fraction. We're not talking about weird edge cases either, but simple numbers that you're likely to come across every day: >>> from decimal import Decimal >>> one_ninth = Decimal(1)/Decimal(9) >>> two_thirds = Decimal(2)/Decimal(3) >>> one_ninth*6 == two_thirds False >>> from fractions import Fraction >>> one_ninth = Fraction(1, 9) >>> two_thirds = Fraction(2, 3) >>> one_ninth*6 == two_thirds True Still not convinced? >>> f = Fraction(1) + Fraction(1, 10**100000) >>> f != 1 True (which is virtually instantaneous, by the way) compared to the *much* slower: >>> d = Decimal(1) + Decimal(1)/Decimal(10**100000) >>> d != 1 False Yes, I could try to set the Decimal context to 100,000 decimal places -- and just as easily defeat it again by adding one more to the exponent. In my opinion, the Fraction module is one of the least appreciated and underused modules in the standard library -- and I include myself in that. It really is a joy, and I don't use it anywhere near enough. -- Steven From steve at REMOVE-THIS-cybersource.com.au Thu Nov 18 23:30:30 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Nov 2010 04:30:30 GMT Subject: Program, Application, and Software References: <87hbffa30d.fsf@benfinney.id.au> <4ce5bfa9$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4ce5fd65$0$29966$c3e8da3$5496439d@news.astraweb.com> On Fri, 19 Nov 2010 00:26:41 +0000, MRAB wrote: > On 19/11/2010 00:07, Steven D'Aprano wrote: >> On Thu, 18 Nov 2010 14:21:47 +0000, Martin Gregorie wrote: >> >>> I use 'script' to refer to programs written in languages that don't >>> have a separate compile phase which must be run before the program can >>> be executed. IOW Python and Perl programs are scripts aloing with >>> programs written as awk, Javascript and bash scripts. >> >> You're mistaken then about Python, because it does have a separate >> compilation phase that runs before the program can be executed. Where >> do you think the .pyc files come from, and what did you think the >> compile() function did? It just happens automatically, rather than >> manually. >> > [snip] > I think what he means is that you don't need explicitly to compile and > then run. So if I write a small shell script to act as a wrapper around the usual compile/execute cycle of (say) C, my C programs turn into scripts, but if I ignore the wrapper and run the compile/execute commands manually, they turn back into not-scripts? -- Steven From tdldev at gmail.com Fri Nov 19 00:39:23 2010 From: tdldev at gmail.com (Verde Denim) Date: Fri, 19 Nov 2010 00:39:23 -0500 Subject: dpkt Message-ID: Hi I'm looking to find some help working with dpkt. As you probably know, there really isn't any documentation, and not being astute at Python as of yet leaves me with a lot of gaps. Is there anyone here that can point me in a direction toward writing some test code for parsing gre packets? Thanks for the input; I appreciate the help. Jack -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan.sonnenberg at pythonmeister.com Fri Nov 19 01:26:25 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Fri, 19 Nov 2010 07:26:25 +0100 Subject: dpkt In-Reply-To: References: Message-ID: <4CE61891.2070601@pythonmeister.com> Am 19.11.2010 06:39, schrieb Verde Denim: > Hi > I'm looking to find some help working with dpkt. As you probably know, > there really isn't any documentation, and not being astute at Python > as of yet leaves me with a lot of gaps. > Is there anyone here that can point me in a direction toward writing > some test code for parsing gre packets? > > Thanks for the input; I appreciate the help. > > Jack There is. It is inside the code (not the obvious way). http://www.monkey.org/~dugsong/dpkt/pydoc/public/dpkt-module.html (May be outdated) -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: stefan_sonnenberg.vcf Type: text/x-vcard Size: 223 bytes Desc: not available URL: From timr at probo.com Fri Nov 19 02:17:00 2010 From: timr at probo.com (Tim Roberts) Date: Thu, 18 Nov 2010 23:17:00 -0800 Subject: Changing the EAX register with Python References: Message-ID: dutche wrote: > >Hi folks, I have a unusual question here. > >How can I change the value of EAX register under python under Linux?? >As paimei does under Windows. > >My project is to have a python program that loads a C program and sets >a breakpoint at some address, and then with this breakpoint I change >the EAX register and then continue the program execution. > >With Windows and paimei I did that, but under Linux I don't know yet. You will need to find a Linux application equivalent to PaiMei. Your question is not "how can I change EAX", your question is "where can I find a Linux debugger that can be controlled from Python?" I don't know the answer to that. gdb is quite powerful, and you can certainly control it by connecting to its stdin and stdout connections. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From stefan.sonnenberg at pythonmeister.com Fri Nov 19 03:28:48 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Fri, 19 Nov 2010 09:28:48 +0100 Subject: Changing the EAX register with Python In-Reply-To: References: Message-ID: Hi, just read my mail :-) You can just build an debugger in python yourself. The script I posted should give you an idea. Am Fr, 19.11.2010, 08:17 schrieb Tim Roberts: > dutche wrote: >> >>Hi folks, I have a unusual question here. >> >>How can I change the value of EAX register under python under Linux?? >>As paimei does under Windows. >> >>My project is to have a python program that loads a C program and sets >>a breakpoint at some address, and then with this breakpoint I change >>the EAX register and then continue the program execution. >> >>With Windows and paimei I did that, but under Linux I don't know yet. > > You will need to find a Linux application equivalent to PaiMei. Your > question is not "how can I change EAX", your question is "where can I find > a Linux debugger that can be controlled from Python?" > > I don't know the answer to that. gdb is quite powerful, and you can > certainly control it by connecting to its stdin and stdout connections. > -- > Tim Roberts, timr at probo.com > Providenza & Boekelheide, Inc. > -- > http://mail.python.org/mailman/listinfo/python-list > > -- MfG, Stefan Sonnenberg-Carstens IT Architect From greg.ewing at canterbury.ac.nz Fri Nov 19 03:48:58 2010 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Fri, 19 Nov 2010 21:48:58 +1300 Subject: ANN: PyGUI 2.3.1 Message-ID: PyGUI 2.3.1 is available: http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/ This version incorporates a modification that I hope will improve the behaviour of ScrollableViews on Windows with pywin32 builds later than 212. (There are still problems with it, though. If the Scrollable View doesn't fill all of its containing window, the scroll bars get repositioned incorrectly when the window is resized. This appears to be entirely MFC's doing. I really will have to get away from using CView altogether.) This version also fixes a problem on Windows whereby dismissing a modal dialog with the Return key could spuriously activate a button in another window. What is PyGUI? -------------- PyGUI is a cross-platform GUI toolkit designed to be lightweight and have a highly Pythonic API. -- Gregory Ewing greg.ewing at canterbury.ac.nz http://www.cosc.canterbury.ac.nz/greg.ewing/ From jeanmichel at sequans.com Fri Nov 19 05:43:26 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 19 Nov 2010 11:43:26 +0100 Subject: Distribution of Python Scripts In-Reply-To: References: Message-ID: <4CE654CE.6030705@sequans.com> tazz_ben wrote: > Hi Folks - > > I'm an experienced programmer, but this is my first app with python, > so I apologize for any stupidity on my part. So I've written/still > working on a command line tool written in Python. It talks to a web > service, so there really isn't anything in it that is dependent on a > particular os. My goal is to distribute the script as a tool to my > users so they can use it (they are on multiple platforms), the vast > majority are not programmers. > > So, I'm looking for a way to distribute the app that takes care of > details like them having python installed, or having an older version > etc. From reading some docs it sounds like "Squeeze" did exactly this > back in the day, but it is ancient and I'm writing in 2.7. Just to > be clear I could care less if they see the source code, my goal is all > around ease of use. I would love to have one distribution file for > all platforms, but I can live with making three if that's the only > option. > > So, what's my options. > I've never done that before. So maybe I will give you a very bad idea, but if so, I'm confident that ppl in this list will scream about it :) You can ship your app with python (the executable) and the module you're using as local modules. Let's assume you are importing sys and os: myApp/python.exe myApp/myScript.py myApp/os/__init__.py -> actually the whole package myApp/sys/__init__.py If you see what I mean. by running python.exe myScript.py ... That should work. You'll have to include every single module you are using. Only python.exe would required to be platform specific. Maybe that's a terrible thing to do... :D JM From xrgtn at yandex.ru Fri Nov 19 06:14:34 2010 From: xrgtn at yandex.ru (Alexander Gattin) Date: Fri, 19 Nov 2010 13:14:34 +0200 Subject: SQLite3 and lastrowid In-Reply-To: <2ec7c0d8-4105-452d-88e3-01050c4c567f@v12g2000vbh.googlegroups.com> References: <2d87112c-e776-41ea-838a-5e165e478052@e20g2000vbn.googlegroups.com> <713377d1-b9e2-4da1-a56a-c4f042f6e3e4@g2g2000vbe.googlegroups.com> <2ec7c0d8-4105-452d-88e3-01050c4c567f@v12g2000vbh.googlegroups.com> Message-ID: <20101119111434.GF31233@xrgtn-q40> Hello, On Tue, Nov 16, 2010 at 01:52:42PM -0800, Ian wrote: > The proper way to get the number of rows is to > use the COUNT aggregate function, e.g., "SELECT > COUNT(*) FROM TABLE1", which will return a > single row with a single column containing the > number of rows in table1. It's better to select count(1) instead of count(*). The latter may skip rows consisting entirely of NULLs IIRC. -- With best regards, xrgtn From iamforufriends at gmail.com Fri Nov 19 06:24:44 2010 From: iamforufriends at gmail.com (DATE@COUPLES) Date: Fri, 19 Nov 2010 03:24:44 -0800 (PST) Subject: HI ALL, COUPLE R INVITING U FOR HOT DATING FOR FREE.... PLZ WELCOME(ABOVE 18YEARS ONLY) Message-ID: HI ALL, COUPLE R INVITING U FOR HOT DATING FOR FREE.... PLZ WELCOME(ABOVE 18YEARS ONLY) http://x2c.eu/58 http://x2c.eu/58 http://x2c.eu/58 http://x2c.eu/58 http://x2c.eu/58 http://x2c.eu/58 http://x2c.eu/58 http://x2c.eu/58 From xrgtn at yandex.ru Fri Nov 19 06:28:53 2010 From: xrgtn at yandex.ru (Alexander Gattin) Date: Fri, 19 Nov 2010 13:28:53 +0200 Subject: SQLite3 and lastrowid In-Reply-To: <20101119111434.GF31233@xrgtn-q40> References: <2d87112c-e776-41ea-838a-5e165e478052@e20g2000vbn.googlegroups.com> <713377d1-b9e2-4da1-a56a-c4f042f6e3e4@g2g2000vbe.googlegroups.com> <2ec7c0d8-4105-452d-88e3-01050c4c567f@v12g2000vbh.googlegroups.com> <20101119111434.GF31233@xrgtn-q40> Message-ID: <20101119112853.GG31233@xrgtn-q40> On Fri, Nov 19, 2010 at 01:14:34PM +0200, Alexander Gattin wrote: > On Tue, Nov 16, 2010 at 01:52:42PM -0800, Ian > wrote: > > The proper way to get the number of rows is to > > use the COUNT aggregate function, e.g., "SELECT > > COUNT(*) FROM TABLE1", which will return a > > single row with a single column containing the > > number of rows in table1. > > It's better to select count(1) instead of > count(*). The latter may skip rows consisting > entirely of NULLs IIRC. sorry, I'm wrong -- count(*) behaves the same way as count(1) does: sqlite> create table t (x number, y char); sqlite> insert into t(x,y) values(1,'a'); sqlite> insert into t(x,y) values(2,NULL); sqlite> insert into t(x,y) values(NULL,'c'); sqlite> insert into t(x,y) values(NULL,NULL); sqlite> insert into t(x,y) values(NULL,NULL); sqlite> select count(1),count(*),count(x),count(y) from t; 5|5|2|2 sqlite> P.S. Surprise -- it's true even for Oracle SQL... -- With best regards, xrgtn (+380501102966/+380636177128/xrgtn at jabber.kiev.ua) From alain at dpt-info.u-strasbg.fr Fri Nov 19 06:32:19 2010 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Fri, 19 Nov 2010 12:32:19 +0100 Subject: SQLite3 and lastrowid References: <2d87112c-e776-41ea-838a-5e165e478052@e20g2000vbn.googlegroups.com> <713377d1-b9e2-4da1-a56a-c4f042f6e3e4@g2g2000vbe.googlegroups.com> <2ec7c0d8-4105-452d-88e3-01050c4c567f@v12g2000vbh.googlegroups.com> Message-ID: <87r5ehblbw.fsf@dpt-info.u-strasbg.fr> Alexander Gattin writes: >> The proper way to get the number of rows is to >> use the COUNT aggregate function, e.g., "SELECT >> COUNT(*) FROM TABLE1", which will return a >> single row with a single column containing the >> number of rows in table1. > > It's better to select count(1) instead of > count(*). The latter may skip rows consisting > entirely of NULLs IIRC. Wrong: count(anyname) ignores NULL, whereas count(*) does not. -- Alain. From xrgtn at yandex.ru Fri Nov 19 06:47:49 2010 From: xrgtn at yandex.ru (Alexander Gattin) Date: Fri, 19 Nov 2010 13:47:49 +0200 Subject: strange subprocess behavior when calling ps In-Reply-To: References: <55f26d5c-aba9-4892-9e2c-1caa9988e7fe@v23g2000vbi.googlegroups.com> <61496525-afab-4d19-a7e9-e61fb46e03ef@n30g2000vbb.googlegroups.com> Message-ID: <20101119114748.GH31233@xrgtn-q40> Hello, On Wed, Nov 17, 2010 at 01:19:09AM -0800, Ned Deily wrote: > As far as I know, COMMAND_MODE has no special > meaning on other platforms UNIX_STD=2003 on HP-UX if anyone's interested... -- With best regards, xrgtn From xrgtn at umc.com.ua Fri Nov 19 07:00:44 2010 From: xrgtn at umc.com.ua (Alexander Gattin) Date: Fri, 19 Nov 2010 14:00:44 +0200 Subject: SQLite3 and lastrowid In-Reply-To: <87r5ehblbw.fsf@dpt-info.u-strasbg.fr> References: <2d87112c-e776-41ea-838a-5e165e478052@e20g2000vbn.googlegroups.com> <713377d1-b9e2-4da1-a56a-c4f042f6e3e4@g2g2000vbe.googlegroups.com> <2ec7c0d8-4105-452d-88e3-01050c4c567f@v12g2000vbh.googlegroups.com> <87r5ehblbw.fsf@dpt-info.u-strasbg.fr> Message-ID: <20101119120044.GI31233@xrgtn-q40> Hello, On Fri, Nov 19, 2010 at 12:32:19PM +0100, Alain Ketterlin wrote: > Alexander Gattin writes: > > It's better to select count(1) instead of > > count(*). The latter may skip rows consisting > > entirely of NULLs IIRC. > > Wrong: count(anyname) ignores NULL, whereas count(*) does not. I'm using count(1), which is a count over constant non-NULL expression (1). It doesn't ignore NULLs or duplicate rows, as my attempts with Oracle 10g, 8g and sqlite3 show. -- With best regards, xrgtn From wolfgang at rohdewald.de Fri Nov 19 07:03:14 2010 From: wolfgang at rohdewald.de (Wolfgang Rohdewald) Date: Fri, 19 Nov 2010 13:03:14 +0100 Subject: SQLite3 and lastrowid In-Reply-To: <20101119111434.GF31233@xrgtn-q40> References: <2d87112c-e776-41ea-838a-5e165e478052@e20g2000vbn.googlegroups.com> <2ec7c0d8-4105-452d-88e3-01050c4c567f@v12g2000vbh.googlegroups.com> <20101119111434.GF31233@xrgtn-q40> Message-ID: <201011191303.14984.wolfgang@rohdewald.de> On Freitag 19 November 2010, Alexander Gattin wrote: > It's better to select count(1) instead of > count(*). The latter may skip rows consisting > entirely of NULLs IIRC. in some data bases count(1) is said to be faster than count(*), I believe -- Wolfgang From alain at dpt-info.u-strasbg.fr Fri Nov 19 07:23:40 2010 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Fri, 19 Nov 2010 13:23:40 +0100 Subject: SQLite3 and lastrowid References: <2d87112c-e776-41ea-838a-5e165e478052@e20g2000vbn.googlegroups.com> <713377d1-b9e2-4da1-a56a-c4f042f6e3e4@g2g2000vbe.googlegroups.com> <2ec7c0d8-4105-452d-88e3-01050c4c567f@v12g2000vbh.googlegroups.com> <87r5ehblbw.fsf@dpt-info.u-strasbg.fr> Message-ID: <87k4k9biyb.fsf@dpt-info.u-strasbg.fr> Alexander Gattin writes: > On Fri, Nov 19, 2010 at 12:32:19PM +0100, Alain > Ketterlin wrote: >> Alexander Gattin writes: >> > It's better to select count(1) instead of >> > count(*). The latter may skip rows consisting >> > entirely of NULLs IIRC. >> >> Wrong: count(anyname) ignores NULL, whereas count(*) does not. > > I'm using count(1), which is a count over constant > non-NULL expression (1). It doesn't ignore NULLs > or duplicate rows, as my attempts with Oracle 10g, > 8g and sqlite3 show. I'm not saying anything about count(1) (which works like count(*) as you explain, even though I see no point in using 1, since *'s hehavior is well-defined). What was wrong in your first message is that count(*) ignores NULL (granted, you've corrected your mistake in a later message, which I didn't see before posting). -- Alain. From ulrich.eckhardt at dominolaser.com Fri Nov 19 07:28:37 2010 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Fri, 19 Nov 2010 13:28:37 +0100 Subject: Extension on Windows References: Message-ID: Eric Frederich wrote: > I am trying to create an extension on Windows and I may be over my > head but I have made it pretty far. > > I am trying to create bindings for some libraries which require me to > use Visual Studio 2005. > > I set up the spammodule example and in VS set the output file to be a .pyd > file. When I copy that .pyd file into site-packages I can use it just fine > and call system('dir'). A ".pyd" is a ".dll", just with a different extension. That means that you can use all tools for DLLs on those, too, like e.g. dependencywalker[1] in order to check for missing dependent DLLs. If the name of the PYD is "foo.pyd", Python looks for a function "foo_init" (or "init_foo") which it calls in order to register the contained code. If this is missing or has the wrong name, Python won't load it. That means that you can't rename the file without touching its content! > Now when I created a 2nd function to wrap a library function I get the > following. > > ImportError: DLL load failed: The specified module could not be found. This can mean that the module itself couldn't be loaded or that one of the DLLs it depends on couldn't be found. Use dependencywalker to check. > I added the correct additional include directories and specified the > correct .lib file to get it to compile fine without any errors. That may be so, but it won't make the system pick up the DLL from whichever location you installed it to. > What is going on here? I tried running python with -vvv and got no > meaningful info... it just fails. Python tries to load the DLL and only gets told by the system that "the DLL failed to load", but not which one. I'm afraid Python can't do any better, since it doesn't have any better info itself. Uli [1] http://dependencywalker.com -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From deets at web.de Fri Nov 19 07:39:14 2010 From: deets at web.de (Diez B. Roggisch) Date: Fri, 19 Nov 2010 13:39:14 +0100 Subject: How to correctly pass =?utf-8?Q?=E2=80=9Cpointer-to-pointer?= =?utf-8?Q?=E2=80=9D?= into DLL via ctypes? References: Message-ID: Grigory Petrov writes: > Hello. > > I have a DLL that allocates memory and returns it. Function in DLL is like this: > > void Foo( unsigned char** ppMem, int* pSize ) > { > ? * pSize = 4; > ? * ppMem = malloc( * pSize ); > ? for( int i = 0; i < * pSize; i ++ ) (* pMem)[ i ] = i; > } > > Also, i have a python code that access this function from my DLL: > > from ctypes import * > Foo = windll.mydll.Foo > Foo.argtypes = [ POINTER( POINTER( c_ubyte ) ), POINTER( c_int ) ] > mem = POINTER( c_ubyte )() > size = c_int( 0 ) > Foo( byref( mem ), byref( size ) ] > print size, mem[ 0 ], mem[ 1 ], mem[ 2 ], mem[ 3 ] > > I'm expecting that?print?will show "4 0 1 2 3" but it shows "4 221 221 > 221 221" O_O. Any hints what i'm doing wrong? After correcting quite a few obvious errors in your code, it worked just fine for me. So I guess what you think you test is not what you test. --- test.py from ctypes import * foo = cdll.LoadLibrary("/Users/deets/projects/GH28/kinect/kinect/c/foo/libtest.dylib").foo foo.argtypes = [ POINTER( POINTER( c_ubyte ) ), POINTER( c_int ) ] mem = POINTER( c_ubyte )() size = c_int( 0 ) foo( byref( mem ), byref( size ) ) print size, mem[ 0 ], mem[ 1 ], mem[ 2 ], mem[ 3 ] --- --- test.c void foo( unsigned char** ppMem, int* pSize ) { int i; * pSize = 4; * ppMem = malloc( * pSize ); for( i = 0; i < * pSize; i ++ ) (* ppMem)[ i ] = i; } --- --- CMakeLists.txt cmake_minimum_required (VERSION 2.6) project (Test) add_library(test SHARED test.c) --- -- Diez From xrgtn at yandex.ru Fri Nov 19 07:39:54 2010 From: xrgtn at yandex.ru (Alexander Gattin) Date: Fri, 19 Nov 2010 14:39:54 +0200 Subject: SQLite3 and lastrowid In-Reply-To: <201011191303.14984.wolfgang@rohdewald.de> References: <2d87112c-e776-41ea-838a-5e165e478052@e20g2000vbn.googlegroups.com> <2ec7c0d8-4105-452d-88e3-01050c4c567f@v12g2000vbh.googlegroups.com> <20101119111434.GF31233@xrgtn-q40> <201011191303.14984.wolfgang@rohdewald.de> Message-ID: <20101119123954.GA3078@xrgtn-q40> Hello, On Fri, Nov 19, 2010 at 01:03:14PM +0100, Wolfgang Rohdewald wrote: > On Freitag 19 November 2010, Alexander Gattin wrote: > > It's better to select count(1) instead of > > count(*). not true, > > The latter may skip rows consisting > > entirely of NULLs IIRC. not true either. I've heard that count(1) is preferred to count(*) but forgot why. Your post reveals the truth about my belief: > in some data bases count(1) is said to be faster > than count(*), I believe And as it turns out this isn't true anymore on modern databases (count(1) and count(*) behave exactly the same). And quite surprisingly, on old ones count(*) was faster than count(1): > 'Oracle Performance Tuning', second edition, > O'Reilly & Associates, Inc, page 175. It says: > > "Contrary to popular belief COUNT(*) is faster > than COUNT(1). If the rows are returned via an > index, counting the indexed column - for example, > COUNT(EMP_NO) is faster still. The optimizer > realizes from the existence of the index that the > column must also exist (non-null). We tested the > following statements on several different > computers and found that COUNT(*) consistently > runs between 15% and 20% faster than COUNT(1) and > that COUNT(INDEXED_COLUMN) is 5% faster again." // http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1156151916789 P.S. sorry for starting this discussion. -- With best regards, xrgtn From eric.frederich at gmail.com Fri Nov 19 07:42:20 2010 From: eric.frederich at gmail.com (Eric Frederich) Date: Fri, 19 Nov 2010 07:42:20 -0500 Subject: Extension on Windows In-Reply-To: References: Message-ID: On Fri, Nov 19, 2010 at 7:28 AM, Ulrich Eckhardt wrote: >> Now when I created a 2nd function to wrap a library function I get the >> following. >> >> ImportError: DLL load failed: The specified module could not be found. > > This can mean that the module itself couldn't be loaded or that one of the > DLLs it depends on couldn't be found. Use dependencywalker to check. What do I do when I find these dependencies? Do I put them in some environment variable? Do I put them in site-packages along with the .pyd file, or in some other directory? From cournape at gmail.com Fri Nov 19 07:43:44 2010 From: cournape at gmail.com (David Cournapeau) Date: Fri, 19 Nov 2010 21:43:44 +0900 Subject: Changing the EAX register with Python In-Reply-To: References: Message-ID: On Fri, Nov 19, 2010 at 4:17 PM, Tim Roberts wrote: > dutche wrote: >> >>Hi folks, I have a unusual question here. >> >>How can I change the value of EAX register under python under Linux?? >>As paimei does under Windows. >> >>My project is to have a python program that loads a C program and sets >>a breakpoint at some address, and then with this breakpoint I change >>the EAX register and then continue the program execution. >> >>With Windows and paimei I did that, but under Linux I don't know yet. > > You will need to find a Linux application equivalent to PaiMei. ?Your > question is not "how can I change EAX", your question is "where can I find > a Linux debugger that can be controlled from Python?" Well, gdb may just be the tool you are looking for: since version 7.0 at least, you can script gdb using python, http://sourceware.org/gdb/wiki/PythonGdb cheers, David From grigory.v.p at gmail.com Fri Nov 19 07:57:03 2010 From: grigory.v.p at gmail.com (Grigory Petrov) Date: Fri, 19 Nov 2010 15:57:03 +0300 Subject: =?windows-1252?Q?Re=3A_How_to_correctly_pass_=93pointer=2Dto=2Dpointer=94_i?= =?windows-1252?Q?nto_DLL_via_ctypes=3F?= In-Reply-To: References: Message-ID: Thank you a lot! I have stripped down my production code to the sample - and it worked. Bug was in another part of my code where free() was called for the memory in question. On Fri, Nov 19, 2010 at 3:39 PM, Diez B. Roggisch wrote: > Grigory Petrov writes: > >> Hello. >> >> I have a DLL that allocates memory and returns it. Function in DLL is like this: >> >> void Foo( unsigned char** ppMem, int* pSize ) >> { >> ? * pSize = 4; >> ? * ppMem = malloc( * pSize ); >> ? for( int i = 0; i < * pSize; i ++ ) (* pMem)[ i ] = i; >> } >> >> Also, i have a python code that access this function from my DLL: >> >> from ctypes import * >> Foo = windll.mydll.Foo >> Foo.argtypes = [ POINTER( POINTER( c_ubyte ) ), POINTER( c_int ) ] >> mem = POINTER( c_ubyte )() >> size = c_int( 0 ) >> Foo( byref( mem ), byref( size ) ] >> print size, mem[ 0 ], mem[ 1 ], mem[ 2 ], mem[ 3 ] >> >> I'm expecting that?print?will show "4 0 1 2 3" but it shows "4 221 221 >> 221 221" O_O. Any hints what i'm doing wrong? > > After correcting quite a few obvious errors in your code, it worked just > fine for me. So I guess what you think you test is not what you test. > > --- test.py > from ctypes import * > > foo = cdll.LoadLibrary("/Users/deets/projects/GH28/kinect/kinect/c/foo/libtest.dylib").foo > foo.argtypes = [ POINTER( POINTER( c_ubyte ) ), POINTER( c_int ) ] > mem = POINTER( c_ubyte )() > size = c_int( 0 ) > foo( byref( mem ), byref( size ) ) > print size, mem[ 0 ], mem[ 1 ], mem[ 2 ], mem[ 3 ] > --- > > --- test.c > void foo( unsigned char** ppMem, int* pSize ) > { > ?int i; > ?* pSize = 4; > ?* ppMem = malloc( * pSize ); > ?for( i = 0; i < * pSize; i ++ ) (* ppMem)[ i ] = i; > } > --- > > --- CMakeLists.txt > cmake_minimum_required (VERSION 2.6) > project (Test) > add_library(test SHARED test.c) > --- > > -- > Diez > -- > http://mail.python.org/mailman/listinfo/python-list > From dutche at gmail.com Fri Nov 19 08:08:37 2010 From: dutche at gmail.com (dutche) Date: Fri, 19 Nov 2010 05:08:37 -0800 (PST) Subject: Changing the EAX register with Python References: Message-ID: <2b1e6b5d-b8da-4892-8d47-60751540cfb2@a12g2000vbc.googlegroups.com> Well, I think using ptrace is really the best way, at least what I have found on Google told me that. Stefan, your answer will fit perfectlly for me, it was what I'm searching. Thank you On Nov 19, 10:43?am, David Cournapeau wrote: > On Fri, Nov 19, 2010 at 4:17 PM, Tim Roberts wrote: > > dutche wrote: > > >>Hi folks, I have a unusual question here. > > >>How can I change the value of EAX register under python under Linux?? > >>As paimei does under Windows. > > >>My project is to have a python program that loads a C program and sets > >>a breakpoint at some address, and then with this breakpoint I change > >>the EAX register and then continue the program execution. > > >>With Windows and paimei I did that, but under Linux I don't know yet. > > > You will need to find a Linux application equivalent to PaiMei. ?Your > > question is not "how can I change EAX", your question is "where can I find > > a Linux debugger that can be controlled from Python?" > > Well, gdb may just be the tool you are looking for: since version 7.0 > at least, you can script gdb using python, > > http://sourceware.org/gdb/wiki/PythonGdb > > cheers, > > David From ulrich.eckhardt at dominolaser.com Fri Nov 19 08:12:49 2010 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Fri, 19 Nov 2010 14:12:49 +0100 Subject: Extension on Windows References: Message-ID: Eric Frederich wrote: > Do I put them [DLL dependencies] in some environment variable? > Do I put them in site-packages along with the .pyd file, or in some > other directory? Take a look at the LoadLibrary() docs: http://msdn.microsoft.com/en-us/library/ms684175(VS.85).aspx These further lead on to: http://msdn.microsoft.com/en-us/library/ms682586(v=VS.85).aspx which details in what order different places are searched for DLLs. If you put the DLL in the same directory as your PYD, it should work. This is not the most elegant solution though, see above for more info. Cheers! Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From martin at address-in-sig.invalid Fri Nov 19 09:22:32 2010 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Fri, 19 Nov 2010 14:22:32 +0000 (UTC) Subject: Program, Application, and Software References: <87hbffa30d.fsf@benfinney.id.au> <4ce5bfa9$0$29966$c3e8da3$5496439d@news.astraweb.com> <4CE5C441.1020209@mrabarnett.plus.com> Message-ID: On Fri, 19 Nov 2010 01:43:28 +0100, Alexander Kapps wrote: > What difference does it make? Is 'print "Hello"' a program or a script? > Are you saying, that it depends on whether you have to manually call > some compiler? Thats the way the term 'script' is usually used in the UNIX/Linux world. In that environment you'd call awk and Perl scripting languages but C and Java are known as compiled languages. The size of the source isn't relevant: if you can mark a source file as executable and simply run it its a 'script' while if it needs a separate preparatory step to generate a separate executable its just a source file for a compiled language. The distinction doesn't seem to be used in a Windows environment. Indeed, it doesn't make sense there since executables are limited to .BAR or .CMD files, which are directly interpreted by the command processor, and .EXE or .COM files, which must be compiled before they can be run. AFAIK there's no way you can mark anything else, such as an awk, Perl or Python source file, as executable since there is no 'executable' attribute in any Windows filing system. -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From pruebauno at latinmail.com Fri Nov 19 09:25:12 2010 From: pruebauno at latinmail.com (nn) Date: Fri, 19 Nov 2010 06:25:12 -0800 (PST) Subject: Bunch 2.0 - a dict with a default References: <58298828-d882-45f8-a396-b8f164d49570@g7g2000vbl.googlegroups.com> Message-ID: <26dfa5db-de55-46fd-95d9-5cc3f5ea6b94@d20g2000yqg.googlegroups.com> On Nov 18, 8:45?pm, Phlip wrote: > Pythonistas: > > If everyone likes this post, then the code is a "snippet" for > community edification. Otherwise, it's a question: How to do this kind > of thing better? > > I want a dict() variant that passes these test cases: > > ? ? ? ? map = Map() > ? ? ? ? assert not(map.has_key('_default')) > > ? ? ? ? map = Map(yo='dude') > ? ? ? ? assert map['yo'] == 'dude' > ? ? ? ? assert map.yo == 'dude' > ? ? ? ? assert None == map['whatever'] > ? ? ? ? assert not(map.has_key('_default')) > > ? ? ? ? map = Map(yo='dude', _default='q') > ? ? ? ? assert 'q' == map['whatever'] > ? ? ? ? assert not(map.has_key('_default')) > > That's like Bunch, but with a default value. (That makes code with > excess if statements less likely.) > > So here's the implementation: > > def Map(*args, **kwargs): > ? ? value = kwargs.get('_default', None) > ? ? if kwargs.has_key('_default'): ?del kwargs['_default'] > > ? ? class _DefMap(dict): > ? ? ? ? def __init__(self, *a, **kw): > ? ? ? ? ? ? dict.__init__(self, *a, **kw) > ? ? ? ? ? ? self.__dict__ = self > > ? ? ? ? def __getitem__(self, key): > ? ? ? ? ? ? if not self.has_key(key): ?self[key] = value > ? ? ? ? ? ? return dict.__getitem__(self, key) > > ? ? return _DefMap(*args, **kwargs) > > -- > ? Phlip > ?http://bit.ly/ZeekLand Looks like some combination of defaultdict and namedtuple. From vlastimil.brom at gmail.com Fri Nov 19 09:49:21 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Fri, 19 Nov 2010 15:49:21 +0100 Subject: regenerating unicodedata for py2.7 using py3 makeunicodedata.py? In-Reply-To: <4CE56653.8020201@v.loewis.de> References: <4CE56653.8020201@v.loewis.de> Message-ID: 2010/11/18 Martin v. Loewis : > >> Thanks for the confirmation Martin! >> >> Do you think, it the mentioned omission of the character names of some >> CJK ranges in unicodedata intended, or should it be reported to the >> tracker? > > It's certainly a bug. So a bug report would be appreciated, but much > more so a patch. Ideally, the patch would either be completely > forward-compatible (should the CJK ranges change in future Unicode > versions), > or at least have a safe-guard to detect that the data file is getting > out of sync with the C implementation. > > Regards, > Martin > Thanks, I just created a bug ticket: http://bugs.python.org/issue10459 The omissions of character names seem to be: ? (0x9fbc) - ? (0x9fcb) (CJK Unified Ideographs [19968-40959] [0x4e00-0x9fff]) ? (0x2a700) - ? (0x2b734) (CJK Unified Ideographs Extension C [173824-177983] [0x2a700-0x2b73f]) ? (0x2b740) - ? (0x2b81d) (CJK Unified Ideographs Extension D [177984-178207] [0x2b740-0x2b81f]) (Also the unprintable ASCII controls, Surrogates and Private use area, where the missing names are probably ok.) Unfortunately, I am not able to provide a patch, mainly because of unicodadate being C code. A while ago I considered writing some unicodedata enhancements in python, which would support the ranges and script names, full category names etc., but sofar the direct programatic lookups in the online unicode docs and with some simple processing also do work sufficiently... Regards, Vlastimil Brom From noydb00 at gmail.com Fri Nov 19 09:52:01 2010 From: noydb00 at gmail.com (noydb) Date: Fri, 19 Nov 2010 06:52:01 -0800 (PST) Subject: How to run an EXE, with argument, capture output value References: <37037d15-63da-4f37-9508-bdcfff034670@s4g2000yql.googlegroups.com> <70d6c9a7-8ba9-420d-822a-0ba71888e4f4@v20g2000yqb.googlegroups.com> <71e489bd-429d-4814-9a0c-6b5f875b3780@30g2000yql.googlegroups.com> <850908d0-26d4-45a5-86bc-855445fde0bf@a37g2000yqi.googlegroups.com> <0594c8c1-e13c-4057-9ff5-783ad97fd0a2@l17g2000yqe.googlegroups.com> Message-ID: <47c956e0-8739-4f30-aa63-8ca5b9549afa@s5g2000yqm.googlegroups.com> Any other help? I am guessing not, just wanted to try one more time. Could really use help, please!! From eric.frederich at gmail.com Fri Nov 19 10:15:53 2010 From: eric.frederich at gmail.com (Eric Frederich) Date: Fri, 19 Nov 2010 10:15:53 -0500 Subject: Extension on Windows In-Reply-To: References: Message-ID: On Fri, Nov 19, 2010 at 8:12 AM, Ulrich Eckhardt wrote: > Eric Frederich wrote: >> Do I put them [DLL dependencies] in some environment variable? >> Do I put them in site-packages along with the .pyd file, or in some >> other directory? > > Take a look at the LoadLibrary() docs: > ?http://msdn.microsoft.com/en-us/library/ms684175(VS.85).aspx > > These further lead on to: > ?http://msdn.microsoft.com/en-us/library/ms682586(v=VS.85).aspx > which details in what order different places are searched for DLLs. > > If you put the DLL in the same directory as your PYD, it should work. This > is not the most elegant solution though, see above for more info. > Well... I used the tool and found missing dependencies and just copied them into site-packages. There were two. Then when I put those two in there and ran dependencywalker again, I had 6 more missing. I found all of these dependencies in a "bin" directory of the program which I'm trying to create bindings for. The one I couldn't find was MSVCR80.DLL but my python module imported fine so maybe its not a big deal (actually, if I throw one of their dll files into dependency walker it shows the same thing). This was just with me wrapping one (very basic) routine. I would imagine as I wrap more and more, I'd need more and more dll files. I think rather than copying .dll files around, I'll just put my .pyd file in their 'bin' directory and set PYTHONPATH environment variable. Things are starting to look promising. I now have to deal with other issues (coming up in a new python-list thread). Thanks a bunch Ulri. From dimos_anastasiou at yahoo.com Fri Nov 19 10:21:32 2010 From: dimos_anastasiou at yahoo.com (Dimos) Date: Fri, 19 Nov 2010 07:21:32 -0800 (PST) Subject: Weibull distr. random number generation Message-ID: <614418.61927.qm@web111714.mail.gq1.yahoo.com> Dear Python list subscribers, Sorry of this has been covered already...This is a newbie question about actual scripting/syntax. I would like to use the random module, and if I understand well the Random class, to create 1300 decimal numbers in python, by providing the 2 Weibull parameters (b,c). How this can be done??? import random print random random.weibullvariate(b,c) How can I set the population size n=1300 in decimals? Best, Dimos From josef.frank at gmx.li Fri Nov 19 10:29:12 2010 From: josef.frank at gmx.li (Josef Frank) Date: Fri, 19 Nov 2010 16:29:12 +0100 Subject: Program, Application, and Software In-Reply-To: References: <87hbffa30d.fsf@benfinney.id.au> <4ce5bfa9$0$29966$c3e8da3$5496439d@news.astraweb.com> <4CE5C441.1020209@mrabarnett.plus.com> Message-ID: Am 19.11.2010 15:22, schrieb Martin Gregorie: > On Fri, 19 Nov 2010 01:43:28 +0100, Alexander Kapps wrote: > >> What difference does it make? Is 'print "Hello"' a program or a script? >> Are you saying, that it depends on whether you have to manually call >> some compiler? > > Thats the way the term 'script' is usually used in the UNIX/Linux world. > > In that environment you'd call awk and Perl scripting languages but C and > Java are known as compiled languages. The size of the source isn't > relevant: if you can mark a source file as executable and simply run it > its a 'script' while if it needs a separate preparatory step to generate > a separate executable its just a source file for a compiled language. > > The distinction doesn't seem to be used in a Windows environment. Indeed, > it doesn't make sense there since executables are limited to .BAR or .CMD > files, which are directly interpreted by the command processor, and .EXE > or .COM files, which must be compiled before they can be run. AFAIK > there's no way you can mark anything else, such as an awk, Perl or Python > source file, as executable since there is no 'executable' attribute in > any Windows filing system. > Not in the file system, but in the environment it is definitely possible. One might try http://www.google.de/search?q=pathext or just have a look at http://wiki.tcl.tk/1785 (the respective filetype has to be associated with it's interpreter however for this method to work.) Josef From rbotting at csusb.edu Fri Nov 19 10:29:59 2010 From: rbotting at csusb.edu (RJB) Date: Fri, 19 Nov 2010 07:29:59 -0800 (PST) Subject: what's the precision of fractions.Fraction? References: <4ce5fc73$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: Does Fractions remove common factors the way it should? If it does and you want to find the closest fraction with a smaller denominator i think tou'll need some number theory and continued fractions. RJB On Nov 18, 8:26?pm, Steven D'Aprano wrote: > On Thu, 18 Nov 2010 20:08:00 +0100, Stefan Sonnenberg-Carstens wrote: > > If you need it really *precise*, cast your Fractions into type Decimal: > > It's actually the opposite. Decimal has many advantages, but being > "really precise" is not one of them. It suffers the exact same issues re > precision and round-off as binary floating point. > > It is easy to demonstrate that there are numbers which cannot be > represented precisely as Decimals no matter how many decimal places you > use, but can be represented exactly as Fractions. Fraction can exactly > represent every Decimal, but Decimal cannot represent exactly every > Fraction. > > We're not talking about weird edge cases either, but simple numbers that > you're likely to come across every day: > > >>> from decimal import Decimal > >>> one_ninth = Decimal(1)/Decimal(9) > >>> two_thirds = Decimal(2)/Decimal(3) > >>> one_ninth*6 == two_thirds > > False > > >>> from fractions import Fraction > >>> one_ninth = Fraction(1, 9) > >>> two_thirds = Fraction(2, 3) > >>> one_ninth*6 == two_thirds > > True > > Still not convinced? > > >>> f = Fraction(1) + Fraction(1, 10**100000) > >>> f != 1 > > True > > (which is virtually instantaneous, by the way) > > compared to the *much* slower: > > >>> d = Decimal(1) + Decimal(1)/Decimal(10**100000) > >>> d != 1 > > False > > Yes, I could try to set the Decimal context to 100,000 decimal places -- > and just as easily defeat it again by adding one more to the exponent. > > In my opinion, the Fraction module is one of the least appreciated and > underused modules in the standard library -- and I include myself in > that. It really is a joy, and I don't use it anywhere near enough. > > -- > Steven From robert.kern at gmail.com Fri Nov 19 10:42:50 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 19 Nov 2010 09:42:50 -0600 Subject: Changing the EAX register with Python In-Reply-To: <2b1e6b5d-b8da-4892-8d47-60751540cfb2@a12g2000vbc.googlegroups.com> References: <2b1e6b5d-b8da-4892-8d47-60751540cfb2@a12g2000vbc.googlegroups.com> Message-ID: On 11/19/10 7:08 AM, dutche wrote: > Well, I think using ptrace is really the best way, at least what I > have found on Google told me that. You may also want to look into pinktrace for another wrapper around ptrace. I haven't used it myself, but it's worth looking into. http://dev.exherbo.org/~alip/pinktrace/ -- 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 pecora at anvil.nrl.navy.mil Fri Nov 19 10:55:28 2010 From: pecora at anvil.nrl.navy.mil (Lou Pecora) Date: Fri, 19 Nov 2010 10:55:28 -0500 Subject: What was your strategy? References: <201011142240.oAEMecu2054270@krusty.intranet.com.mx> <7xr5ei1p2j.fsf@ruckus.brouhaha.com> Message-ID: In article <7xr5ei1p2j.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > Lou Pecora writes: > >> > I'll jump in and recommend the book "Python in a Nutshell" by Martelli. > >> It's encyclopedic. > > Indeed. I hope Martelli updates it. I'd buy another copy right away. > > It's a great book but not a starting point for beginners. It's > definitely worth having for more advanced users. I would beg to differ. I used it from the start of my Python learning curve and was greatly helped by it. For me it gave explanations at just the right level with paths to more detail if you wanted. I found it helpful from the beginning. I would recommended others to at least look at it. You might be helped right away and it's a good addition to any Python programmer's library. -- -- Lou Pecora From eric.frederich at gmail.com Fri Nov 19 11:05:10 2010 From: eric.frederich at gmail.com (Eric Frederich) Date: Fri, 19 Nov 2010 11:05:10 -0500 Subject: Round Trip: C to Python to C Module Message-ID: I have a proprietary software PropSoft that I need to extend. They support extensions written in C that can link against PropLib to interact with the system. I have a Python C module that wraps a couple PropLib functions that I call PyProp. >From an interactive Python shell I can import PyProp and call a function. None of these functions really do anything outside the context of being logged into the PropSoft software; so all the functions fail when running from Python alone. To my amazement, I was able to run PyRun_SimpleString("import PyProp\nPyProp.some_function()") without setting PYTHONPATH or anything. How this works, I don't know and I don't really care (at the moment anyway). The problem I'm having now is how do I return things from my Python script back to C? Ultimately I won't be hard coding python inside of PyRun_SimpleString but loading the script from a file. So, how do I return values back to C? Python functions return values but running a python script?... doesn't that just have an exit status? Is there a mechanism for doing this? Thanks in advance, ~Eric From invalid at invalid.invalid Fri Nov 19 11:32:21 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 19 Nov 2010 16:32:21 +0000 (UTC) Subject: Changing the EAX register with Python References: Message-ID: On 2010-11-19, Tim Roberts wrote: > dutche wrote: >> My project is to have a python program that loads a C program and >> sets a breakpoint at some address, and then with this breakpoint I >> change the EAX register and then continue the program execution. > You will need to find a Linux application equivalent to PaiMei. Your > question is not "how can I change EAX", your question is "where can I > find a Linux debugger that can be controlled from Python?" > > I don't know the answer to that. gdb is quite powerful, and you can > certainly control it by connecting to its stdin and stdout > connections. If you're going to do that, you want to run gdb in "machine interface" mode, which makes it a lot easier to talk to programatically. I've not done it in Python, but it's easy enough in C, so in Python it ought to be trivial: http://sourceware.org/gdb/current/onlinedocs/gdb/GDB_002fMI.html#GDB_002fMI If you don't want to write code to talk the gdb/mi "command language", then another option is to use a library like libmigdb: http://sourceforge.net/projects/libmigdb/ You can probably call the library functions using cytpes: http://docs.python.org/library/ctypes.html -- Grant Edwards grant.b.edwards Yow! Psychoanalysis?? at I thought this was a nude gmail.com rap session!!! From steve at holdenweb.com Fri Nov 19 11:46:32 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 19 Nov 2010 11:46:32 -0500 Subject: What was your strategy? In-Reply-To: References: <201011142240.oAEMecu2054270@krusty.intranet.com.mx> <7xr5ei1p2j.fsf@ruckus.brouhaha.com> Message-ID: On 11/19/2010 10:55 AM, Lou Pecora wrote: > In article <7xr5ei1p2j.fsf at ruckus.brouhaha.com>, > Paul Rubin wrote: > >> Lou Pecora writes: >>>>> I'll jump in and recommend the book "Python in a Nutshell" by Martelli. >>>> It's encyclopedic. >>> Indeed. I hope Martelli updates it. I'd buy another copy right away. >> >> It's a great book but not a starting point for beginners. It's >> definitely worth having for more advanced users. > > I would beg to differ. I used it from the start of my Python learning > curve and was greatly helped by it. For me it gave explanations at just > the right level with paths to more detail if you wanted. I found it > helpful from the beginning. I would recommended others to at least look > at it. You might be helped right away and it's a good addition to any > Python programmer's library. > I'd say "Nushell" is a great book for experienced programmers, whether in Python or other languages. It's definitely not something I would recommend for a programming noob. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From malaclypse2 at gmail.com Fri Nov 19 11:52:21 2010 From: malaclypse2 at gmail.com (Jerry Hill) Date: Fri, 19 Nov 2010 11:52:21 -0500 Subject: How to run an EXE, with argument, capture output value In-Reply-To: <47c956e0-8739-4f30-aa63-8ca5b9549afa@s5g2000yqm.googlegroups.com> References: <37037d15-63da-4f37-9508-bdcfff034670@s4g2000yql.googlegroups.com> <70d6c9a7-8ba9-420d-822a-0ba71888e4f4@v20g2000yqb.googlegroups.com> <71e489bd-429d-4814-9a0c-6b5f875b3780@30g2000yql.googlegroups.com> <850908d0-26d4-45a5-86bc-855445fde0bf@a37g2000yqi.googlegroups.com> <0594c8c1-e13c-4057-9ff5-783ad97fd0a2@l17g2000yqe.googlegroups.com> <47c956e0-8739-4f30-aa63-8ca5b9549afa@s5g2000yqm.googlegroups.com> Message-ID: On Fri, Nov 19, 2010 at 9:52 AM, noydb wrote: > Any other help? ?I am guessing not, just wanted to try one more time. > Could really use help, please!! You'll need to give us more information about the program you're trying to automate. It originally sounded like you just needed to run a console program, where it's usually fairly easy to run and capture the output with the subprocess module. Now it sounds like you're trying to automate a GUI that requires user interaction. That's quite a bit more complicated. When you run "stats_hall.exe", what do you get on the screen? What, exactly, are the steps a normal user would need to perform to do what you want to automate? After the values you're interested in are computed, where do they show up? Is this program publically available someplace? I've generally had good luck doing simple GUI automation with pywinauto. The homepage appears to be: http://pywinauto.pbworks.com which has installation instructions and a FAQ. You might also find this demo useful: http://showmedo.com/videotutorials/video?name=UsingpyWinAutoToControlAWindowsApplication -- Jerry From steve at holdenweb.com Fri Nov 19 11:53:01 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 19 Nov 2010 11:53:01 -0500 Subject: Program, Application, and Software In-Reply-To: References: <87hbffa30d.fsf@benfinney.id.au> <4ce5bfa9$0$29966$c3e8da3$5496439d@news.astraweb.com> <4CE5C441.1020209@mrabarnett.plus.com> Message-ID: On 11/19/2010 9:22 AM, Martin Gregorie wrote: [...] > Indeed, > it doesn't make sense there since executables are limited to .BAR or .CMD > files, which are directly interpreted by the command processor, and .EXE > or .COM files, which must be compiled before they can be run. AFAIK > there's no way you can mark anything else, such as an awk, Perl or Python > source file, as executable since there is no 'executable' attribute in > any Windows filing system. Under Windows you use the PATHEXT mechanism to mark an extension as executable. Then finding a file with that extension on the PATH will trigger it to be run by the registered interpreter. As far as I know, anyway. By default on my Vista system I see PATHEXT contains C:\Users\sholden\workspace\Python3_Lesson3\src>echo %PATHEXT% .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From dfnsonfsduifb at gmx.de Fri Nov 19 12:17:43 2010 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Fri, 19 Nov 2010 18:17:43 +0100 Subject: Modifying Element In For List In-Reply-To: References: <01e04b27-c523-40b7-b9cb-8288823de8fa@p11g2000vbn.googlegroups.com> Message-ID: <8knpmqFda9U1@mid.dfncis.de> Am 15.11.2010 18:27, schrieb Duncan Booth: > Comparing directly against True or False is error prone: a value in > Python can be false without actually being equal to False. Well, you can always use "is" instead of "==", which makes a comparison to True or False perfectly safe. 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 steve at holdenweb.com Fri Nov 19 12:31:47 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 19 Nov 2010 12:31:47 -0500 Subject: Modifying Element In For List In-Reply-To: <8knpmqFda9U1@mid.dfncis.de> References: <01e04b27-c523-40b7-b9cb-8288823de8fa@p11g2000vbn.googlegroups.com> <8knpmqFda9U1@mid.dfncis.de> Message-ID: On 11/19/2010 12:17 PM, Johannes Bauer wrote: > Am 15.11.2010 18:27, schrieb Duncan Booth: > >> Comparing directly against True or False is error prone: a value in >> Python can be false without actually being equal to False. > > Well, you can always use "is" instead of "==", which makes a comparison > to True or False perfectly safe. > But it's still the wrong thing to do. if condition==True: and if condition is True: should both be replaced (under most circumstances) by if condition: regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From ppearson at nowhere.invalid Fri Nov 19 13:20:47 2010 From: ppearson at nowhere.invalid (Peter Pearson) Date: 19 Nov 2010 18:20:47 GMT Subject: what's the precision of fractions.Fraction? References: <4ce5fc73$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8kntfvFr8aU1@mid.individual.net> On Fri, 19 Nov 2010 07:29:59 -0800 (PST), RJB wrote: > Does Fractions remove common factors the way it should? > > If it does and you want to find the closest fraction with a smaller > denominator i think tou'll need some number theory and continued > fractions. No heroics required, finding the greatest common divisor is fast. And if this simple test is indicative, the fractions module reduces: >>> x = fractions.Fraction( 2**100, 3 ) >>> y = fractions.Fraction( 7, 2**101 ) >>> z = x * y >>> print x._numerator, x._denominator 1267650600228229401496703205376 3 >>> print y._numerator, y._denominator 7 2535301200456458802993406410752 >>> print z._numerator, z._denominator 7 6 -- To email me, substitute nowhere->spamcop, invalid->net. From usernet at ilthio.net Fri Nov 19 13:27:23 2010 From: usernet at ilthio.net (Tim Harig) Date: Fri, 19 Nov 2010 18:27:23 +0000 (UTC) Subject: How to run an EXE, with argument, capture output value References: <37037d15-63da-4f37-9508-bdcfff034670@s4g2000yql.googlegroups.com> Message-ID: C:\Documents and Settings\Tim Harig\My Documents\autoCalc>dir Volume in drive C has no label. Volume Serial Number is 30D9-35E0 Directory of C:\Documents and Settings\Tim Harig\My Documents\autoCalc 11/19/2010 12:20 PM

. 11/19/2010 12:20 PM .. 11/19/2010 12:19 PM 686 autoCalc.pys 1 File(s) 686 bytes 2 Dir(s) 16,343,552,000 bytes free C:\Documents and Settings\Tim Harig\My Documents\autoCalc>type autoCalc.pys # autoCalc.pys: The "pys" extension indicates that it should be run under # Windows Script Host # perform the calculation using Windows calculator keySequence = ['2', '{+}', '2', '=', '^c', '%{F4}'] WshShell = WScript.CreateObject("WScript.Shell") calculator = WshShell.Run("calc") WshShell.AppActivate("calc") WScript.Sleep(1000) for currentKey in keySequence: WshShell.SendKeys(currentKey) WScript.Sleep(100) # write the results to notepad and same as demo.txt keySequence = ['result: ', '^v', '^s', 'c:\\Documents and Settings\\Tim Harig\\My Documents\\autoCalc\\demo.txt', '~', '%{F4}'] notepad = WshShell.Run("notepad") WshShell.AppActivate("notepad") WScript.Sleep(1000) for currentKey in keySequence: WshShell.SendKeys(currentKey) WScript.Sleep(100) C:\Documents and Settings\Tim Harig\My Documents\autoCalc>cscript.exe autoCalc.pys Microsoft (R) Windows Script Host Version 5.7 Copyright (C) Microsoft Corporation. All rights reserved. Debugging extensions (axdebug) module does not exist - debugging is disabled.. C:\Documents and Settings\Tim Harig\My Documents\autoCalc>type demo.txt result: 4 C:\Documents and Settings\Tim Harig\My Documents\autoCalc> From deets at web.de Fri Nov 19 14:25:49 2010 From: deets at web.de (Diez B. Roggisch) Date: Fri, 19 Nov 2010 20:25:49 +0100 Subject: Round Trip: C to Python to C Module References: Message-ID: Eric Frederich writes: > I have a proprietary software PropSoft that I need to extend. > They support extensions written in C that can link against PropLib to > interact with the system. > > I have a Python C module that wraps a couple PropLib functions that I > call PyProp. >>From an interactive Python shell I can import PyProp and call a function. > None of these functions really do anything outside the context of > being logged into the PropSoft software; so all the functions fail > when running from Python alone. > > To my amazement, I was able to run PyRun_SimpleString("import > PyProp\nPyProp.some_function()") without setting PYTHONPATH or > anything. How this works, I don't know and I don't really care (at > the moment anyway). > > The problem I'm having now is how do I return things from my Python > script back to C? > Ultimately I won't be hard coding python inside of PyRun_SimpleString > but loading the script from a file. > So, how do I return values back to C? Python functions return values > but running a python script?... doesn't that just have an exit status? > Is there a mechanism for doing this? You write an extension in C that embeds a Python-interpreter. That interpreter then loads your script, and executes it. Let's say the PropSoft offers you three functions for a custom extension. void init(); int do_something(int); void cleanup(); Then you write a C-extension that contains these three function calls, and in init, you create a Python-interpreter and load your script. It should offer a "do_something_in_python" method that takes an int and returns one. In do_something, you invoke the aforementioned do_something_in_python function through the Python C-API as described. In cleanup, you do what the function name says. Possibly the use of elmer[1] makes the whole process easier. [1]: http://wiki.python.org/moin/elmer -- Diez From nulla.epistola at web.de Fri Nov 19 14:58:17 2010 From: nulla.epistola at web.de (Sibylle Koczian) Date: Fri, 19 Nov 2010 20:58:17 +0100 Subject: Module locale throws exception: unsupported locale setting Message-ID: Hello, on a german Windows installation I get problems with locale. If I run that module as a script from a command window this is the output: C:\Python31\Lib>locale.py Locale aliasing: Locale defaults as determined by getdefaultlocale(): ------------------------------------------------------------------------ Language: de_DE Encoding: cp1252 Locale settings on startup: ------------------------------------------------------------------------ LC_NUMERIC ... Language: (undefined) Encoding: (undefined) LC_MONETARY ... Language: (undefined) Encoding: (undefined) LC_COLLATE ... Language: (undefined) Encoding: (undefined) LC_CTYPE ... Language: (undefined) Encoding: (undefined) LC_TIME ... Language: (undefined) Encoding: (undefined) Locale settings after calling resetlocale(): ------------------------------------------------------------------------ Traceback (most recent call last): File "C:\Python31\Lib\locale.py", line 1798, in _print_locale() File "C:\Python31\Lib\locale.py", line 1761, in _print_locale resetlocale() File "C:\Python31\Lib\locale.py", line 537, in resetlocale _setlocale(category, _build_localename(getdefaultlocale())) locale.Error: unsupported locale setting C:\Python31\Lib> This is Windows 7, 64 bit, Python 3.1.2. Same behavior on another Windows machine with Python 2.7 (Windows XP, 32 bit). On Linux, using UTF-8 as system character set and Python 2.6, 2.6.5 or 3.1.2, no problems using locale, running the module as a script gives no exception but the expected output. So I suppose it's either an OS problem or connected with the encoding. I've looked into bugs.python.org, but found only vaguely similar issues. Should I open a new one? Thank you for help, Sibylle From nad at acm.org Fri Nov 19 15:27:49 2010 From: nad at acm.org (Ned Deily) Date: Fri, 19 Nov 2010 12:27:49 -0800 Subject: Module locale throws exception: unsupported locale setting References: Message-ID: In article , Sibylle Koczian wrote: > on a german Windows installation I get problems with locale. If I run > that module as a script from a command window this is the output: > > C:\Python31\Lib>locale.py > Locale aliasing: > > Locale defaults as determined by getdefaultlocale(): > ------------------------------------------------------------------------ > Language: de_DE > Encoding: cp1252 > > Locale settings on startup: > ------------------------------------------------------------------------ > LC_NUMERIC ... > Language: (undefined) > Encoding: (undefined) > > LC_MONETARY ... > Language: (undefined) > Encoding: (undefined) > > LC_COLLATE ... > Language: (undefined) > Encoding: (undefined) > > LC_CTYPE ... > Language: (undefined) > Encoding: (undefined) > > LC_TIME ... > Language: (undefined) > Encoding: (undefined) > > > Locale settings after calling resetlocale(): > ------------------------------------------------------------------------ > Traceback (most recent call last): > File "C:\Python31\Lib\locale.py", line 1798, in > _print_locale() > File "C:\Python31\Lib\locale.py", line 1761, in _print_locale > resetlocale() > File "C:\Python31\Lib\locale.py", line 537, in resetlocale > _setlocale(category, _build_localename(getdefaultlocale())) > locale.Error: unsupported locale setting > > C:\Python31\Lib> > > This is Windows 7, 64 bit, Python 3.1.2. Same behavior on another > Windows machine with Python 2.7 (Windows XP, 32 bit). > > On Linux, using UTF-8 as system character set and Python 2.6, 2.6.5 or > 3.1.2, no problems using locale, running the module as a script gives no > exception but the expected output. So I suppose it's either an OS > problem or connected with the encoding. > > I've looked into bugs.python.org, but found only vaguely similar issues. > Should I open a new one? There have been a lot of changes going into Python 3.2, currently in alpha testing, in the areas of encodings and how they affect the interfaces to/from the various platform operating systems Python 3 runs on. It would be very useful if you could try the same test with the most recent Python 3.2 alpha (http://www.python.org/download/releases/3.2/) and, if the problem persists there, open an issue about it. -- Ned Deily, nad at acm.org From stefaan.himpe at gmail.com Fri Nov 19 20:07:35 2010 From: stefaan.himpe at gmail.com (Stefaan Himpe) Date: Sat, 20 Nov 2010 02:07:35 +0100 Subject: Distribution of Python Scripts In-Reply-To: References: Message-ID: > So, what's my options. Maybe this page can give some inspiration? http://wiki.python.org/moin/deployment From data.2 at rediff.com Fri Nov 19 20:08:06 2010 From: data.2 at rediff.com (gaurav) Date: Fri, 19 Nov 2010 17:08:06 -0800 (PST) Subject: Earn in Management careers. Message-ID: <7e19c68f-792a-482a-ac9c-7d8fe85f1eb8@a30g2000vbt.googlegroups.com> On Management careers base, Earn monthly. Supporting Management careers. http://managementjobs.webs.com/pm.htm & http://topcareer.webs.com/humanresourcemgmt.htm Offers for job seekers Opportunities for you Make your career. http://rojgars1.webs.com/gov.htm http://rojgars.webs.com/bankingjobs.htm From razamatan_retral_net_ignore_com at mustafa.retral.net Fri Nov 19 20:58:19 2010 From: razamatan_retral_net_ignore_com at mustafa.retral.net (Jin Yi) Date: Fri, 19 Nov 2010 17:58:19 -0800 Subject: dict diff Message-ID: <20101120015819.GA1254@mustafa.retral.net> so i came up with a diff method to compare 2 dicts. i found it pretty useful so i thought i'd share it with everyone. you can see the doctest to check out suggested uses. since we can't modify built-ins, i demonstrated adding a diff method to OrderedDict to show how one could add it to your own mapping objects. the core logic is compatible with python2 and 3 (i've only tested using 2.6.5 and 3.1.2). the doctest is suited for python3 though. the interface is pretty straightforward. it would be awesome to have this sucker as a method on the builtin dict, but that'd take a pep, no? -- Jin Yi -------------- next part -------------- A non-text attachment was scrubbed... Name: diffdict.py Type: text/x-python Size: 2062 bytes Desc: not available URL: From razamatan_retral_net at nospam.com Fri Nov 19 20:58:19 2010 From: razamatan_retral_net at nospam.com (Jin Yi) Date: Fri, 19 Nov 2010 17:58:19 -0800 Subject: dict diff Message-ID: <20101120015819.GA1254@mustafa.retral.net> so i came up with a diff method to compare 2 dicts. i found it pretty useful so i thought i'd share it with everyone. you can see the doctest to check out suggested uses. since we can't modify built-ins, i demonstrated adding a diff method to OrderedDict to show how one could add it to your own mapping objects. the core logic is compatible with python2 and 3 (i've only tested using 2.6.5 and 3.1.2). the doctest is suited for python3 though. the interface is pretty straightforward. it would be awesome to have this sucker as a method on the builtin dict, but that'd take a pep, no? -- Jin Yi -------------- next part -------------- A non-text attachment was scrubbed... Name: diffdict.py Type: text/x-python Size: 2062 bytes Desc: not available URL: From noydb00 at gmail.com Fri Nov 19 21:39:29 2010 From: noydb00 at gmail.com (noydb) Date: Fri, 19 Nov 2010 18:39:29 -0800 (PST) Subject: How to run an EXE, with argument, capture output value References: <37037d15-63da-4f37-9508-bdcfff034670@s4g2000yql.googlegroups.com> Message-ID: <0ae3b271-9161-4b94-b11b-0d26e68d2596@j18g2000yqd.googlegroups.com> Thanks to Jerry Hill above who helped. This worked: from pywinauto.application import Application app = Application() app.start_(r'C:\temp\hallbig2.exe') app.Form1.Edit6.TypeKeys(r'C:\temp\input\Ea39j.txt') E_Value = "" while (E_Value == ""): app.Form1.Compute.Click() E_Value = app.Form1.Edit8.WindowText() print repr(E_Value) app.Kill_() From k.sahithi2862 at gmail.com Sat Nov 20 00:30:41 2010 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Fri, 19 Nov 2010 21:30:41 -0800 (PST) Subject: ONLY FOR YOUTH Message-ID: <511902d0-5674-4d11-bffa-bacfc5cb436f@s5g2000yqm.googlegroups.com> TRISHA IN A SPICY DRESS http://youth-shilpa.blogspot.com/2010/11/trisha.html SAKSHI IN A SEXY LOOK http://youth-shilpa.blogspot.com/2010/11/sakshi.html SEXY STUNNIG BEAUTY http://youth-shilpa.blogspot.com/2010/11/beauty.html NAMITHA IN A BEACH http://youth-shilpa.blogspot.com/2010/11/namitha.html HOT LIPKISSES BOLLYWOOD http://youth-shilpa.blogspot.com/2010/11/lipkiss.html SALMA HOT BOOBS SHOW http://youth-shilpa.blogspot.com/2010/11/salma-sexy-photo.html ANJELINA JOLIE SPICY PHOTO http://youth-shilpa.blogspot.com/2010/11/anjelinajolie.html From mback1 at live.se Sat Nov 20 00:53:57 2010 From: mback1 at live.se (Mikael B) Date: Sat, 20 Nov 2010 06:53:57 +0100 Subject: try to use unicode Message-ID: Hi. I'm learning python. python 2.6.6 on ubuntu 10.10 I'm swedish so I try to use unicode to get swedish characters. I've checked wikipedia. utf-8 is said to be an unicode encoding.. this is the test program: # -*- coding: utf-8 -*- import readline s=raw_input(u'M?nadsl?n:') and this is the output: Traceback (most recent call last): File "test_uni.py", line 5, in s=raw_input(u'M?nadsl?n:') UnicodeEncodeError: 'ascii' codec can't encode character u'\xe5' in position 1: ordinal not in range(128) I'm doing something wrong... Mikael -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Sat Nov 20 01:11:53 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 20 Nov 2010 01:11:53 -0500 Subject: dict diff In-Reply-To: <20101120015819.GA1254@mustafa.retral.net> References: <20101120015819.GA1254@mustafa.retral.net> Message-ID: On 11/19/2010 8:58 PM, Jin Yi wrote: > so i came up with a diff method to compare 2 dicts. i found it pretty > useful so i thought i'd share it with everyone. you can see the doctest > to check out suggested uses. since we can't modify built-ins, i > demonstrated adding a diff method to OrderedDict to show how one could > add it to your own mapping objects. > > the core logic is compatible with python2 and 3 (i've only tested using > 2.6.5 and 3.1.2). the doctest is suited for python3 though. > > > the interface is pretty straightforward. it would be awesome to have > this sucker as a method on the builtin dict, but that'd take a pep, no? > > > A PEP *and* some explanation of why you would want such an obscure piece of code built in to the dict object, yes. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From razamatan_retral_net at nospam.com Sat Nov 20 02:15:11 2010 From: razamatan_retral_net at nospam.com (Jin Yi) Date: Fri, 19 Nov 2010 23:15:11 -0800 Subject: dict diff In-Reply-To: References: <20101120015819.GA1254@mustafa.retral.net> Message-ID: <20101120071511.GA3207@mustafa.retral.net> i don't think this piece of code is obscure. i think the use case is there when you know that dicta != dictb, but you need to know where they're different. i wouldn't really care to have it on the dict since it's useful as an unbound method anyway. On Sat, Nov 20, 2010 at 01:11:53AM -0500, Steve Holden wrote: > On 11/19/2010 8:58 PM, Jin Yi wrote: > > so i came up with a diff method to compare 2 dicts. i found it pretty > > useful so i thought i'd share it with everyone. you can see the doctest > > to check out suggested uses. since we can't modify built-ins, i > > demonstrated adding a diff method to OrderedDict to show how one could > > add it to your own mapping objects. > > > > the core logic is compatible with python2 and 3 (i've only tested using > > 2.6.5 and 3.1.2). the doctest is suited for python3 though. > > > > > > the interface is pretty straightforward. it would be awesome to have > > this sucker as a method on the builtin dict, but that'd take a pep, no? > > > > > > > A PEP *and* some explanation of why you would want such an obscure piece > of code built in to the dict object, yes. > > regards > Steve > -- > Steve Holden +1 571 484 6266 +1 800 494 3119 > PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ > See Python Video! http://python.mirocommunity.org/ > Holden Web LLC http://www.holdenweb.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list From stefan.sonnenberg at pythonmeister.com Sat Nov 20 02:47:18 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Sat, 20 Nov 2010 08:47:18 +0100 Subject: try to use unicode In-Reply-To: References: Message-ID: <4CE77D06.1080108@pythonmeister.com> Am 20.11.2010 06:53, schrieb Mikael B: > Hi. > > I'm learning python. python 2.6.6 on ubuntu 10.10 I'm swedish so I try > to use > unicode to get swedish characters. I've checked wikipedia. > utf-8 is said to be an unicode encoding.. > > this is the test program: > > # -*- coding: utf-8 -*- > > import readline > > s=raw_input(u'M?nadsl?n:') > > and this is the output: > > Traceback (most recent call last): > File "test_uni.py", line 5, in > s=raw_input(u'M?nadsl?n:') > UnicodeEncodeError: 'ascii' codec can't encode character u'\xe5' in > position 1: ordinal not in range(128) > > I'm doing something wrong... > > Mikael > Your console is not unicode ready. Please take a look at the locale command and vars like LC_ALL, LC_LANG etc. -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: stefan_sonnenberg.vcf Type: text/x-vcard Size: 223 bytes Desc: not available URL: From mback1 at live.se Sat Nov 20 02:49:59 2010 From: mback1 at live.se (Mikael B) Date: Sat, 20 Nov 2010 08:49:59 +0100 Subject: try to use unicode In-Reply-To: <4CE77D06.1080108@pythonmeister.com> References: , <4CE77D06.1080108@pythonmeister.com> Message-ID: Date: Sat, 20 Nov 2010 08:47:18 +0100 From: stefan.sonnenberg at pythonmeister.com To: mback1 at live.se CC: python-list at python.org Subject: Re: try to use unicode Meddelandetext Am 20.11.2010 06:53, schrieb Mikael B: Hi. I'm learning python. python 2.6.6 on ubuntu 10.10 I'm swedish so I try to use unicode to get swedish characters. I've checked wikipedia. utf-8 is said to be an unicode encoding.. this is the test program: # -*- coding: utf-8 -*- import readline s=raw_input(u'M?nadsl?n:') and this is the output: Traceback (most recent call last): File "test_uni.py", line 5, in s=raw_input(u'M?nadsl?n:') UnicodeEncodeError: 'ascii' codec can't encode character u'\xe5' in position 1: ordinal not in range(128) I'm doing something wrong... Mikael Your console is not unicode ready. Please take a look at the locale command and vars like LC_ALL, LC_LANG etc. Aha... Ok,thank you -------------- next part -------------- An HTML attachment was scrubbed... URL: From maxim.mercury at gmail.com Sat Nov 20 03:28:08 2010 From: maxim.mercury at gmail.com (Maxim Mercury) Date: Sat, 20 Nov 2010 00:28:08 -0800 (PST) Subject: constructin trees in python Message-ID: <3c926050-5e27-4efb-bf76-dbd1f2412810@o14g2000yqe.googlegroups.com> Hi , Iam very much new to python. Iam trying to construct a xml dom tree using the builtin HTMLParser class (on data event callbacks). Iam maintaining the childs as a list of elements and whenver the sax parser encounters a tag i push it to a local stack, my basic logic is below. ************** def handle_starttag(self, tag, attrs): curElement=HTMLElement(tag.lower(), attrs); <------ (1) if(self.elementRoot == None): self.elementRoot = curElement else: self.elementStack[-1].childs.append(curElement) <------ (2) self.elementStack.append(curElement) ************** here is the definintion of htmlelement class HTMLElement: tag=None attrs={} data='' childs=[] the issue is the though new elements are pushed in the stack (1), whenever i append the child to the stack top all other elements in the stack is getting affected, i assume the same reference is used but is there a way to overcome this ? From __peter__ at web.de Sat Nov 20 04:03:49 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 20 Nov 2010 10:03:49 +0100 Subject: constructin trees in python References: <3c926050-5e27-4efb-bf76-dbd1f2412810@o14g2000yqe.googlegroups.com> Message-ID: Maxim Mercury wrote: > here is the definintion of htmlelement > > class HTMLElement: > tag=None > attrs={} > data='' > childs=[] > > the issue is the though new elements are pushed in the stack (1), > whenever i append the child to the stack top all other elements in the > stack is getting affected, i assume the same reference is used but is > there a way to overcome this ? In class A: some_list = [] defines a class attribute shared by all instances of A. To turn some_list into an instance attribute move the definition into the initializer: class A: def __init__(self): self.some_list = [] Note that this holds for every attribute, but you usually see it only for mutables like lists or dicts because in class A: x = "yadda" y = [] a = A() print a.x # yadda a.x = 42 print a.x # 42 del a.x print a.x # can you guess what happens? the class attribute is shadowed by the instance attribute whereas a.y.append(42) modifies the class attribute in place. # two more to check that you've understood the mechanism: a.y += ["ham"] # ? a.y = ["spam"] # ? Peter From arnodel at gmail.com Sat Nov 20 04:17:15 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Sat, 20 Nov 2010 09:17:15 +0000 Subject: what's the precision of fractions.Fraction? References: <4ce5fc73$0$29966$c3e8da3$5496439d@news.astraweb.com> <8kntfvFr8aU1@mid.individual.net> Message-ID: <87k4k88ick.fsf@gmail.com> Peter Pearson writes: > On Fri, 19 Nov 2010 07:29:59 -0800 (PST), RJB wrote: >> Does Fractions remove common factors the way it should? >> >> If it does and you want to find the closest fraction with a smaller >> denominator i think tou'll need some number theory and continued >> fractions. > > No heroics required, finding the greatest common divisor is fast. I think RJB was referring to e.g. finding the closest fraction to a certain fraction with a bounded denominator. -- Arnaud From pmilin at ff.uns.ac.rs Sat Nov 20 04:37:26 2010 From: pmilin at ff.uns.ac.rs (Petar Milin) Date: Sat, 20 Nov 2010 10:37:26 +0100 Subject: Is it possible to use Google's advanced search options? Message-ID: <4CE796D6.5070802@ff.uns.ac.rs> Hello! Can anyone help me with getting number of hits from Google, but with restricton on domain (e.g., .edu) and language (e.g., lang_de)? I have tried with the Pygoogle (from: http://code.google.com/p/pygoogle/ ): from pygoogle import pygoogle word = u'something' request_word = word.encode('utf-8') request = ('%s+site:.edu' % request_word) g = pygoogle(request) g.get_result_count() Now, I realized that domain restriction works, but language does not, since it cannot be specified in request like domain in example above. Please, help! Is this possible with the Pygoogle? If not, how can I make that happen? Thanks! PM -------------- next part -------------- An HTML attachment was scrubbed... URL: From dickinsm at gmail.com Sat Nov 20 04:46:33 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Sat, 20 Nov 2010 01:46:33 -0800 (PST) Subject: what's the precision of fractions.Fraction? References: <4ce5fc73$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <12372eb4-0c12-46fd-99d7-ee9b7b0ebde1@b25g2000vbz.googlegroups.com> On Nov 19, 3:29?pm, RJB wrote: > Does Fractions remove common factors the way it should? > > If it does and you want to find the closest fraction with a smaller > denominator i think tou'll need some number theory and continued > fractions. Or perhaps just use the existing Fraction.limit_denominator method (which does indeed use some number theory and continued fractions): >>> from fractions import Fraction >>> from math import pi >>> Fraction.from_float(pi).limit_denominator(1000) Fraction(355, 113) -- Mark From stefan.sonnenberg at pythonmeister.com Sat Nov 20 05:30:44 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Sat, 20 Nov 2010 11:30:44 +0100 Subject: Is it possible to use Google's advanced search options? In-Reply-To: <4CE796D6.5070802@ff.uns.ac.rs> References: <4CE796D6.5070802@ff.uns.ac.rs> Message-ID: <4CE7A354.8040908@pythonmeister.com> Am 20.11.2010 10:37, schrieb Petar Milin: > Hello! > Can anyone help me with getting number of hits from Google, but with > restricton on domain (e.g., .edu) and language (e.g., lang_de)? I have > tried with the Pygoogle (from: http://code.google.com/p/pygoogle/ > ): > > from pygoogle import pygoogle > word = u'something' > request_word = word.encode('utf-8') > request = ('%s+site:.edu' % request_word) > g = pygoogle(request) > g.get_result_count() > > > Now, I realized that domain restriction works, but language does not, > since it cannot be specified in request like domain in example above. > Please, help! Is this possible with the Pygoogle? If not, how can I > make that happen? > > Thanks! > PM > > See below word = u'something' request_word = word.encode('utf-8') request = ('%s site:.edu options lang:de' % request_word) g = pygoogle(request) g.get_result_count() -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: stefan_sonnenberg.vcf Type: text/x-vcard Size: 232 bytes Desc: not available URL: From as at sci.fi Sat Nov 20 06:04:51 2010 From: as at sci.fi (Anssi Saari) Date: Sat, 20 Nov 2010 13:04:51 +0200 Subject: another newbie question References: Message-ID: Roy Smith writes: > I'm still searching for as nice a font to use on Linux. Envy Code R is a lookalike, so maybe worth considering. I haven't tried actual Monaco on Linux, but apparently it's possible. Personally, I use -lfp-gamow-medium-r-*-*-7-*-*-*-*-*-*-* in Linux (Emacs). From hniksic at xemacs.org Sat Nov 20 06:53:25 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Sat, 20 Nov 2010 12:53:25 +0100 Subject: what's the precision of fractions.Fraction? References: <4ce5fc73$0$29966$c3e8da3$5496439d@news.astraweb.com> <12372eb4-0c12-46fd-99d7-ee9b7b0ebde1@b25g2000vbz.googlegroups.com> Message-ID: <87zkt41aa2.fsf@xemacs.org> Mark Dickinson writes: > On Nov 19, 3:29?pm, RJB wrote: >> Does Fractions remove common factors the way it should? >> >> If it does and you want to find the closest fraction with a smaller >> denominator i think tou'll need some number theory and continued >> fractions. > > Or perhaps just use the existing Fraction.limit_denominator method > (which does indeed use some number theory and continued fractions): > >>>> from fractions import Fraction >>>> from math import pi >>>> Fraction.from_float(pi).limit_denominator(1000) > Fraction(355, 113) People, this is exactly what http://xkcd.com/353/ is about. From steve at REMOVE-THIS-cybersource.com.au Sat Nov 20 07:00:16 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Nov 2010 12:00:16 GMT Subject: dict diff References: <20101120015819.GA1254@mustafa.retral.net> Message-ID: <4ce7b850$0$29991$c3e8da3$5496439d@news.astraweb.com> On Sat, 20 Nov 2010 01:11:53 -0500, Steve Holden wrote: > On 11/19/2010 8:58 PM, Jin Yi wrote: >> so i came up with a diff method to compare 2 dicts. [...] > A PEP *and* some explanation of why you would want such an obscure piece > of code built in to the dict object, yes. You've never wanted to see how two dicts differ, as well as the fact that they do? I frequently find myself wanting to see why two dicts that should be equal aren't, especially for testing and debugging. I use this function: def dict_diffs(a, b): """dict_diffs(adict, bdict) -> (amissing, bmissing, different) Returns sets (amissing, bmissing, different) such that: amissing = keys missing from adict compared to bdict bmissing = keys missing from bdict compared to adict different = keys in both adict and bdict but with different values >>> dict_diffs({1:0, 2:0, 3:0}, {1:1, 2:0, 4:0}) (set([4]), set([3]), set([1])) """ from collections import Mapping if not isinstance(a, Mapping) and isinstance(b, Mapping): raise TypeError('arguments must both be mappings') amissing, bmissing, different = set(), set(), set() for key, value in a.items(): if key not in b: bmissing.add(key) elif value != b[key]: different.add(key) for key, value in b.items(): if key not in a: amissing.add(key) return (amissing, bmissing, different) -- Steven From nulla.epistola at web.de Sat Nov 20 07:52:05 2010 From: nulla.epistola at web.de (Sibylle Koczian) Date: Sat, 20 Nov 2010 13:52:05 +0100 Subject: Module locale throws exception: unsupported locale setting In-Reply-To: References: Message-ID: Am 19.11.2010 21:27, schrieb Ned Deily: > > There have been a lot of changes going into Python 3.2, currently in > alpha testing, in the areas of encodings and how they affect the > interfaces to/from the various platform operating systems Python 3 runs > on. It would be very useful if you could try the same test with the > most recent Python 3.2 alpha > (http://www.python.org/download/releases/3.2/) and, if the problem > persists there, open an issue about it. > Done. No change with 3.2a4, so I opened issue 10466. Thank you, Sibylle From __peter__ at web.de Sat Nov 20 07:59:27 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 20 Nov 2010 13:59:27 +0100 Subject: what's the precision of fractions.Fraction? References: <4ce5fc73$0$29966$c3e8da3$5496439d@news.astraweb.com> <12372eb4-0c12-46fd-99d7-ee9b7b0ebde1@b25g2000vbz.googlegroups.com> <87zkt41aa2.fsf@xemacs.org> Message-ID: Hrvoje Niksic wrote: > Mark Dickinson writes: > >> On Nov 19, 3:29 pm, RJB wrote: >>> Does Fractions remove common factors the way it should? >>> >>> If it does and you want to find the closest fraction with a smaller >>> denominator i think tou'll need some number theory and continued >>> fractions. >> >> Or perhaps just use the existing Fraction.limit_denominator method >> (which does indeed use some number theory and continued fractions): >> >>>>> from fractions import Fraction >>>>> from math import pi >>>>> Fraction.from_float(pi).limit_denominator(1000) >> Fraction(355, 113) > > People, this is exactly what http://xkcd.com/353/ is about. I can't help thinking of http://xkcd.com/378/ with the punch line changed to "'course there's a python library function to do that" It's all butterflies from here on... Peter From maxim.mercury at gmail.com Sat Nov 20 08:05:17 2010 From: maxim.mercury at gmail.com (Maxim Mercury) Date: Sat, 20 Nov 2010 05:05:17 -0800 (PST) Subject: constructin trees in python References: <3c926050-5e27-4efb-bf76-dbd1f2412810@o14g2000yqe.googlegroups.com> Message-ID: On Nov 20, 2:03?pm, Peter Otten <__pete... at web.de> wrote: > Maxim Mercury wrote: > > here is the definintion of htmlelement > > > class HTMLElement: > > ? ? tag=None > > ? ? attrs={} > > ? ? data='' > > ? ? childs=[] > > > the issue is the though new elements are pushed in the stack (1), > > whenever i append the child to the stack top all other elements in the > > stack is getting affected, i assume the same reference is used but is > > there a way to overcome this ? > > In > > class A: > ? ?some_list = [] > > defines a class attribute shared by all instances of A. To turn some_list > into an instance attribute move the definition into the initializer: > > class A: > ? ? def __init__(self): > ? ? ? ? self.some_list = [] > > Note that this holds for every attribute, but you usually see it only for > mutables like lists or dicts because in > > class A: > ? ?x = "yadda" > ? ?y = [] > a = A() > print a.x # yadda > a.x = 42 > print a.x # 42 > del a.x > print a.x # can you guess what happens? > > the class attribute is shadowed by the instance attribute whereas > > a.y.append(42) > > modifies the class attribute in place. > > # two more to check that you've understood the mechanism: > a.y += ["ham"] # ? > a.y = ["spam"] # ? > > Peter Thanks a lot peter, that worked as i needed. Where can i find some good documentation which explains such behavior. From iamforufriends at gmail.com Sat Nov 20 09:54:19 2010 From: iamforufriends at gmail.com (DATE@COUPLES) Date: Sat, 20 Nov 2010 06:54:19 -0800 (PST) Subject: R U READY TO DATE WITH HOT COMMITED COUPLES.... Message-ID: <767035c6-bd6b-451a-9e00-124bb306c3db@d20g2000yqg.googlegroups.com> R U READY TO DATE WITH HOT COMMITED COUPLES.... JUST FOLLOW THE LINK... WE R WAITING.... http://adultfriendfinder.com/go/g1271112-ppc http://adultfriendfinder.com/go/g1271112-ppc http://adultfriendfinder.com/go/g1271112-ppc http://adultfriendfinder.com/go/g1271112-ppc From steve at REMOVE-THIS-cybersource.com.au Sat Nov 20 09:59:53 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Nov 2010 14:59:53 GMT Subject: Inserting class namespace into method scope Message-ID: <4ce7e269$0$29991$c3e8da3$5496439d@news.astraweb.com> I find myself having need of a class where the class scope is included in the scope of methods in the class. A simple example from Python 3.1: x = "outside" class Magic: x = "inside" def method(self): return x I would like Magic().method() to return "inside" rather than "outside". Now, I understand why this is not Python's usual behaviour, and I agree with those reasons -- this is NOT a complaint that Python's normal behaviour is to exclude the class namespace from the method's scope. I also understand that the usual way of getting this would be to return self.x or self.__class__.x from method, instead of x. Again, normally I would do this. But in this specific case I have reasons for wanting to avoid both of the normal behaviours. Do not judge me, please accept that I have a good reason for wanting this, or at least allow me to shoot myself in the foot this way *wink*. In Python 3, is there some way to get this unusual behaviour? -- Steven From mback1 at live.se Sat Nov 20 10:10:49 2010 From: mback1 at live.se (Mikael B) Date: Sat, 20 Nov 2010 16:10:49 +0100 Subject: try to use unicode In-Reply-To: References: , , <4CE77D06.1080108@pythonmeister.com>, Message-ID: From: mback1 at live.se To: python-list at python.org Subject: RE: try to use unicode Date: Sat, 20 Nov 2010 08:49:59 +0100 Date: Sat, 20 Nov 2010 08:47:18 +0100 From: stefan.sonnenberg at pythonmeister.com To: mback1 at live.se CC: python-list at python.org Subject: Re: try to use unicode Meddelandetext Am 20.11.2010 06:53, schrieb Mikael B: Hi. I'm learning python. python 2.6.6 on ubuntu 10.10 I'm swedish so I try to use unicode to get swedish characters. I've checked wikipedia. utf-8 is said to be an unicode encoding.. this is the test program: # -*- coding: utf-8 -*- import readline s=raw_input(u'M?nadsl?n:') and this is the output: Traceback (most recent call last): File "test_uni.py", line 5, in s=raw_input(u'M?nadsl?n:') UnicodeEncodeError: 'ascii' codec can't encode character u'\xe5' in position 1: ordinal not in range(128) I'm doing something wrong... Mikael Your console is not unicode ready. Please take a look at the locale command and vars like LC_ALL, LC_LANG etc. Aha... Ok,thank you ---------------- But I checked this out.. Gnome terminal is set to 'unicode utf-8 encoding' and locale command returns LANG=sv_SE.utf8 LC_CTYPE="sv_SE.utf8" LC_NUMERIC="sv_SE.utf8" LC_TIME="sv_SE.utf8" LC_COLLATE="sv_SE.utf8" LC_MONETARY="sv_SE.utf8" LC_MESSAGES="sv_SE.utf8" LC_PAPER="sv_SE.utf8" LC_NAME="sv_SE.utf8" LC_ADDRESS="sv_SE.utf8" LC_TELEPHONE="sv_SE.utf8" LC_MEASUREMENT="sv_SE.utf8" LC_IDENTIFICATION="sv_SE.utf8" LC_ALL= if I remove the u before strings its works.. it must be a 8-bit subset of utf-8? -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From duncan.booth at invalid.invalid Sat Nov 20 11:24:45 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 20 Nov 2010 16:24:45 GMT Subject: Inserting class namespace into method scope References: <4ce7e269$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > But in this specific case I have reasons for wanting to avoid both of > the normal behaviours. Do not judge me, please accept that I have a > good reason for wanting this, or at least allow me to shoot myself in > the foot this way *wink*. In Python 3, is there some way to get this > unusual behaviour? > Sounds more like you want a mercy killing rather than just shooting in the foot. However, if I had taken sufficient illegal substances to want to do this, I would decorate the function with an attribute to indicate that I want it messed up, and then use a metaclass to create a new function from the original one but with the class namespace in place of the __globals__ attribute. I think you need to do it in a metaclass because once the class is created you just have a dictproxy and you need a real dict as the globals argument to the function constructor. The limitations will be that the resulting method cannot access any globals and also any changes to the class namespace won't be visible inside the function (since the class's dictproxy is a copy of the dict). from types import FunctionType class WeirdClass(type): def __new__(cls, name, bases, classdict): for attrname, attribute in classdict.items(): if getattr(attribute, '_useclassglobals', False): classdict[attrname] = FunctionType(attribute.__code__, classdict, attribute.__name__, attribute.__defaults__, attribute.__closure__) result = type.__new__(cls, name, bases, classdict) return result def classglobals(f): f._useclassglobals = True return f x = "outside" class Magic(metaclass=WeirdClass): x = "inside" @classglobals def method(self): return x m = Magic() print(m.method()) # prints 'inside' Magic.x = "new value" print(m.method()) # still prints 'inside' -- Duncan Booth http://kupuguy.blogspot.com From gd.usenet at spamfence.net Sat Nov 20 11:45:32 2010 From: gd.usenet at spamfence.net (=?UTF-8?Q?G=C3=BCnther?= Dietrich) Date: Sat, 20 Nov 2010 17:45:32 +0100 Subject: Inserting class namespace into method scope References: <4ce7e269$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: >I find myself having need of a class where the class scope is included in >the scope of methods in the class. A simple example from Python 3.1: > >x = "outside" > >class Magic: > x = "inside" > def method(self): > return x > > >I would like Magic().method() to return "inside" rather than "outside". Try this instead: return self.x Best regards, G?nther From dickinsm at gmail.com Sat Nov 20 12:09:33 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Sat, 20 Nov 2010 09:09:33 -0800 (PST) Subject: Weibull distr. random number generation References: Message-ID: <71b9f476-087f-455e-a587-69cd812feea8@j9g2000vbl.googlegroups.com> On Nov 19, 3:21?pm, Dimos wrote: > I would like to use the random module, and if I understand well the Random class, to create ?1300 decimal numbers in python, by providing the 2 Weibull parameters (b,c). How this can be done??? > > import random > print random > random.weibullvariate(b,c) > How can I set the population size n=1300 in decimals? random.weibullvariate(b, c) generates a single sample from the specified Weibull distribution. If you want 1300 samples, you'd use this within a loop. For example, here's code to put 10 Weibull variates with scale parameter 12345.0 and shape parameter 6.0 into a list: >>> import random >>> samples = [] >>> for i in xrange(10): ... samples.append(random.weibullvariate(12345.0, 6.0)) ... >>> print samples [15553.186762792948, 14304.175032317309, 9015.5053691933044, 12585.469181732506, 9436.2677219460638, 13350.89758791281, 5687.4330250037565, 12172.747202474553, 9687.8685933610814, 11699.040541029028] A more experienced Python programmer might use a list comprehension to achieve the same effect in a single line: >>> samples = [random.weibullvariate(12345.0, 6.0) for _ in xrange(10)] >>> print samples [10355.396846416865, 14689.507803932587, 11491.850991569485, 14128.56397290655, 12592.739991974759, 9076.7752548878998, 11868.012238422616, 12016.784656753523, 14724.818462506191, 13253.477389116439] Is this the sort of thing you were looking for? -- Mark From emile at fenx.com Sat Nov 20 12:12:18 2010 From: emile at fenx.com (Emile van Sebille) Date: Sat, 20 Nov 2010 09:12:18 -0800 Subject: Inserting class namespace into method scope In-Reply-To: <4ce7e269$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4ce7e269$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 11/20/2010 6:59 AM Steven D'Aprano said... > I find myself having need of a class where the class scope is included in > the scope of methods in the class. A simple example from Python 3.1: > > x = "outside" > > class Magic: > x = "inside" > def method(self): > return x > > > I would like Magic().method() to return "inside" rather than "outside". > > Now, I understand why this is not Python's usual behaviour, and I agree > with those reasons -- this is NOT a complaint that Python's normal > behaviour is to exclude the class namespace from the method's scope. > > I also understand that the usual way of getting this would be to return > self.x or self.__class__.x from method, instead of x. Again, normally I > would do this. > > But in this specific case I have reasons for wanting to avoid both of the > normal behaviours. Do not judge me, please accept that I have a good > reason for wanting this, or at least allow me to shoot myself in the foot > this way *wink*. In Python 3, is there some way to get this unusual > behaviour? > As it's easy to return self.x but you're restricting that option, what kind of change options must you work within? Emile From stackslip at gmail.com Sat Nov 20 12:23:51 2010 From: stackslip at gmail.com (Slie) Date: Sat, 20 Nov 2010 08:23:51 -0900 Subject: another newbie question Message-ID: I really enjoyed it when I put the MacOsx font on my Ubuntu or any other. Anssi Saari wrote: >Roy Smith writes: > >> I'm still searching for as nice a font to use on Linux. > >Envy Code R is a lookalike, so maybe worth considering. I haven't >tried actual Monaco on Linux, but apparently it's possible. >Personally, I use -lfp-gamow-medium-r-*-*-7-*-*-*-*-*-*-* in Linux >(Emacs). >-- >http://mail.python.org/mailman/listinfo/python-list From parvini_navid at yahoo.com Sat Nov 20 12:37:38 2010 From: parvini_navid at yahoo.com (Navid Parvini) Date: Sat, 20 Nov 2010 09:37:38 -0800 (PST) Subject: Installing pysqlite on Win64 Message-ID: <903873.61971.qm@web51007.mail.re2.yahoo.com> Dear All, I want to install pysqlite on my Windows 64 bit machine. I have python 2.4.3 on it. Would you please let me know how can I do it? That is, I need to use the source file (i.e pysqlite-2.5.6.tar.gz) or there is an executable file to install. Thank you in advance. Regards, Navid -------------- next part -------------- An HTML attachment was scrubbed... URL: From victorsubervi at gmail.com Sat Nov 20 14:23:22 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Sat, 20 Nov 2010 15:23:22 -0400 Subject: Printing from Web Page Message-ID: Hi; I need to be able to print something from a Web page: not the entire page but what I specify. I am writing the page and the client is surfing to it. How do I do this? TIA, beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From pmilin at ff.uns.ac.rs Sat Nov 20 14:24:39 2010 From: pmilin at ff.uns.ac.rs (Petar Milin) Date: Sat, 20 Nov 2010 20:24:39 +0100 Subject: Python-list Digest, Vol 86, Issue 176 In-Reply-To: References: Message-ID: Thanks so much! However, 'options lang:de' does not exactly the same as would 'lr=lang_de'? Am I right? Since I need number of hits, I would like to have the best, most correct values! :-) Sincerely, PM On Sat, Nov 20, 2010 at 12:00 PM, wrote: > Send Python-list mailing list submissions to > ? ? ? ?python-list at python.org > > To subscribe or unsubscribe via the World Wide Web, visit > ? ? ? ?http://mail.python.org/mailman/listinfo/python-list > or, via email, send a message with subject or body 'help' to > ? ? ? ?python-list-request at python.org > > You can reach the person managing the list at > ? ? ? ?python-list-owner at python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Python-list digest..." > > Today's Topics: > > ? 1. Re: what's the precision of fractions.Fraction? (Mark Dickinson) > ? 2. Re: Is it possible to use Google's advanced search options? > ? ? ?(Stefan Sonnenberg-Carstens) > > > ---------- Forwarded message ---------- > From:?Mark Dickinson > To:?python-list at python.org > Date:?Sat, 20 Nov 2010 01:46:33 -0800 (PST) > Subject:?Re: what's the precision of fractions.Fraction? > On Nov 19, 3:29?pm, RJB wrote: >> Does Fractions remove common factors the way it should? >> >> If it does and you want to find the closest fraction with a smaller >> denominator i think tou'll need some number theory and continued >> fractions. > > Or perhaps just use the existing Fraction.limit_denominator method > (which does indeed use some number theory and continued fractions): > >>>> from fractions import Fraction >>>> from math import pi >>>> Fraction.from_float(pi).limit_denominator(1000) > Fraction(355, 113) > > -- > Mark > > > > ---------- Forwarded message ---------- > From:?Stefan Sonnenberg-Carstens > To:?python-list at python.org > Date:?Sat, 20 Nov 2010 11:30:44 +0100 > Subject:?Re: Is it possible to use Google's advanced search options? > Am 20.11.2010 10:37, schrieb Petar Milin: > > Hello! > Can anyone help me with getting number of hits from Google, but with restricton on domain (e.g., .edu) and language (e.g., lang_de)? I have tried with the Pygoogle (from: http://code.google.com/p/pygoogle/): > from pygoogle import pygoogle > word = u'something' > request_word = word.encode('utf-8') > request = ('%s+site:.edu' % request_word) > g = pygoogle(request) > g.get_result_count() > > Now, I realized that domain restriction works, but language does not, since it cannot be specified in request like domain in example above. > Please, help! Is this possible with the Pygoogle? If not, how can I make that happen? > > Thanks! > PM > > See below > > word = u'something' > request_word = word.encode('utf-8') > request = ('%s site:.edu options lang:de' % request_word) > g = pygoogle(request) > g.get_result_count() > -- > http://mail.python.org/mailman/listinfo/python-list > From stefan_ml at behnel.de Sat Nov 20 15:02:47 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 20 Nov 2010 21:02:47 +0100 Subject: Is Unladen Swallow dead? In-Reply-To: <87vd3uccxw.fsf.mdw@metalzone.distorted.org.uk> References: <2e1a4d02-1e8a-4d31-95da-f33aaf90578c@30g2000yql.googlegroups.com> <8b0b044c-34a8-4747-b68f-f4cb56882f6f@e26g2000vbz.googlegroups.com> <4ce37e01$0$1666$742ec2ed@news.sonic.net> <4ce570ff$0$1617$742ec2ed@news.sonic.net> <87vd3uccxw.fsf.mdw@metalzone.distorted.org.uk> Message-ID: Mark Wooding, 19.11.2010 02:35: > John Nagle writes: >> This has been pointed out many times by many people. There's >> even a PhD thesis on the topic. Without a few restrictions, so >> that a compiler can at least tell when support for the hard cases >> is needed, Python cannot be compiled well. > > This assumes static compilation. It's the wrong approach for a dynamic > language like Python. Cython does a pretty good job in that, though. It also optimistically optimises a couple of things even during static compilation, e.g. "x.append(y)" likely hints on "x" being a list, even if static analysis can't prove that. Stefan From razamatan_retral_net at nospam.com Sat Nov 20 15:33:55 2010 From: razamatan_retral_net at nospam.com (Jin Yi) Date: Sat, 20 Nov 2010 12:33:55 -0800 Subject: dict diff In-Reply-To: <4ce7b850$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <20101120015819.GA1254@mustafa.retral.net> <4ce7b850$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20101120203355.GA5403@mustafa.retral.net> right. i moved to a 2-value tuple return value basically to illustrate exactly where each dict is providing a different value. it turns out to be much easier to grok than the 3-value one since it's all there and lines up correctly with the inputs... On Sat, Nov 20, 2010 at 12:00:16PM +0000, Steven D'Aprano wrote: > On Sat, 20 Nov 2010 01:11:53 -0500, Steve Holden wrote: > > > On 11/19/2010 8:58 PM, Jin Yi wrote: > >> so i came up with a diff method to compare 2 dicts. > [...] > > A PEP *and* some explanation of why you would want such an obscure piece > > of code built in to the dict object, yes. > > You've never wanted to see how two dicts differ, as well as the fact that > they do? I frequently find myself wanting to see why two dicts that > should be equal aren't, especially for testing and debugging. > > I use this function: > > def dict_diffs(a, b): > """dict_diffs(adict, bdict) -> (amissing, bmissing, different) > > Returns sets (amissing, bmissing, different) such that: > > amissing = keys missing from adict compared to bdict > bmissing = keys missing from bdict compared to adict > different = keys in both adict and bdict but with different values > > >>> dict_diffs({1:0, 2:0, 3:0}, {1:1, 2:0, 4:0}) > (set([4]), set([3]), set([1])) > > """ > from collections import Mapping > if not isinstance(a, Mapping) and isinstance(b, Mapping): > raise TypeError('arguments must both be mappings') > amissing, bmissing, different = set(), set(), set() > for key, value in a.items(): > if key not in b: > bmissing.add(key) > elif value != b[key]: > different.add(key) > for key, value in b.items(): > if key not in a: > amissing.add(key) > return (amissing, bmissing, different) > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list -- I pops mah collah. (Busta Rhymes) Jin Yi -- http://www.retral.net/razamatan From clp2 at rebertia.com Sat Nov 20 16:34:55 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 20 Nov 2010 13:34:55 -0800 Subject: Does Pygoogle allows for advanced search options? In-Reply-To: <706ff3ad-66b4-4cdb-a68f-bf0a079c2dc1@32g2000yqz.googlegroups.com> References: <706ff3ad-66b4-4cdb-a68f-bf0a079c2dc1@32g2000yqz.googlegroups.com> Message-ID: On Thu, Nov 18, 2010 at 3:26 AM, neocortex wrote: >> The library doesn't seem to have built-in support for filtering by >> language (and Google lacks a search query-string-based operator for >> that), but it looks like you could implement that feature by adding an >> "lr" parameter with an appropriate value to the query `args` >> dictionary. See the "lr?" entry under "Web Search Specific Arguments" >> onhttp://code.google.com/apis/websearch/docs/reference.html, and >> lines 68 & 102 of pygoogle.py. > > From those lines, it can be concluded that lr=lang_?? is not > supported, unfortunately. Right; that's why I said "you could implement that feature". Pretty easily it would seem. > And, when I execute, I get an error. What exactly are you executing, and what's the exact error? Vagueness is the enemy of debugging. Regards, Chris -- http://blog.rebertia.com From ben+python at benfinney.id.au Sat Nov 20 16:59:30 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 21 Nov 2010 08:59:30 +1100 Subject: Inserting class namespace into method scope References: <4ce7e269$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87wro78xml.fsf@benfinney.id.au> Steven D'Aprano writes: > I also understand that the usual way of getting this would be to > return self.x or self.__class__.x from method, instead of x. Again, > normally I would do this. > > But in this specific case I have reasons for wanting to avoid both of > the normal behaviours. Do not judge me, please accept that I have a > good reason for wanting this [?] C'mon, Steven, you know the drill. If you want us to help you solve a problem, don't start with ?I want to use this behaviour that seems loony, and I won't say why?. Instead, help us by telling us what problem you're trying to solve. It's not good enough to simply say ?I can't do it the right way?, you need to let us in on what the problem actually is, otherwise we have to play twenty questions with ?okay, how about this? ?no, that's no good either for other unspecified reasons?. So: what problem are you trying to solve, and what are the constraints? -- \ ?The double standard that exempts religious activities from | `\ almost all standards of accountability should be dismantled | _o__) once and for all.? ?Daniel Dennett, 2010-01-12 | Ben Finney From aahz at pythoncraft.com Sat Nov 20 17:11:30 2010 From: aahz at pythoncraft.com (Aahz) Date: 20 Nov 2010 14:11:30 -0800 Subject: Where's the bug? (cPickle/thread edition) (was Re: How to optimize and monitor garbage collection?) References: Message-ID: In article , Steve Holden wrote: > >[aside: in general, if you think your program is not working because of >a bug in Python, look harder at your program]. Good advice, I certainly agree with you. But sometimes it's not so simple. Right now, my company is running up against a problem with CherryPy because cPickle.dumps() doesn't release the GIL. You could argue that it's our fault for using threads, and you could also argue that we're having problems because our server has heavy memory contention (a dumps() that takes a couple of seconds on a laptop takes more than thirty seconds on the server). Nevertheless, I think it's also arguably a bug that dumps() doesn't release the GIL. (cPickle.dump() *does* release the GIL.) (Fortunately, we're savvy enough that it's easy for us to just make a local copy of cPickle that releases the GIL. Much easier than finding the problem in the first place...) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Look, it's your affair if you want to play with five people, but don't go calling it doubles." --John Cleese anticipates Usenet From joralemonshelly at gmail.com Sat Nov 20 17:40:16 2010 From: joralemonshelly at gmail.com (Shel) Date: Sat, 20 Nov 2010 14:40:16 -0800 (PST) Subject: building a web interface Message-ID: Hello, I am pretty new to all this. I have some coding experience, and am currently most comfortable with Python. I also have database design experience with MS Access, and have just created my first mySQL db. So right now I have a mySQL db structure and some Python code. My end goal is to create a browser-based interactive fiction/game thing. My code is currently just using dummy data rather than pulling in data from the db, but I think/hope it won't be too big of a deal to interact with the db through Python (famous last words...). My main problem right now is how to do the web interface. I don't know much about web architecture, unfortunately. I think I need a CGI script? What I would really like is to find a GUI tool to design the interface that would have customizable templates or drag-and-drop elements or something, so I wouldn't have to code much by hand. Something easy, if such a tool exists. Also would prefer something that I would be able to install/use without having much access to the server where the site will be hosted (on a university server that I don't have control over). I don't fully understand how a lot of the tools I have been looking at work, but it seems like they're often things where you'd have to get an administrator to do stuff on the server (is that right?), which I would prefer to avoid. It looks like Django has some sort of standalone implementation, but I'm not clear on how that would work or how much of a learning curve there would be for using it. If anyone has any thoughts or suggestions, I would really appreciate it. Hope my questions make sense. I don't really know what I'm doing, so could be they're a bit silly. I apologize if that's the case, and please let me know if you need any additional informmation. Thanks, Shel From philip at semanchuk.com Sat Nov 20 17:57:45 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Sat, 20 Nov 2010 17:57:45 -0500 Subject: Installing pysqlite on Win64 In-Reply-To: <903873.61971.qm@web51007.mail.re2.yahoo.com> References: <903873.61971.qm@web51007.mail.re2.yahoo.com> Message-ID: On Nov 20, 2010, at 12:37 PM, Navid Parvini wrote: > Dear All, > > I want to install pysqlite on my Windows 64 bit machine. I have python 2.4.3 on it. > Would you please let me know how can I do it? > > That is, I need to use the source file (i.e pysqlite-2.5.6.tar.gz) or there is an executable file to install. Hi Navid, I'm not a Windows guy so I really can't recommend how to proceed with the specific question you asked. But if there's any way you could upgrade the machine to Python >= 2.5, your problem will go away because those versions of Python come with a built-in sqlite interface. That might be an easier approach for you. Good luck Philip From debatem1 at gmail.com Sat Nov 20 18:14:59 2010 From: debatem1 at gmail.com (geremy condra) Date: Sat, 20 Nov 2010 15:14:59 -0800 Subject: dict diff In-Reply-To: <4ce7b850$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <20101120015819.GA1254@mustafa.retral.net> <4ce7b850$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Nov 20, 2010 at 4:00 AM, Steven D'Aprano wrote: > On Sat, 20 Nov 2010 01:11:53 -0500, Steve Holden wrote: > >> On 11/19/2010 8:58 PM, Jin Yi wrote: >>> so i came up with a diff method to compare 2 dicts. > [...] >> A PEP *and* some explanation of why you would want such an obscure piece >> of code built in to the dict object, yes. > > You've never wanted to see how two dicts differ, as well as the fact that > they do? I frequently find myself wanting to see why two dicts that > should be equal aren't, especially for testing and debugging. > > I use this function: > > def dict_diffs(a, b): > ? ?"""dict_diffs(adict, bdict) -> (amissing, bmissing, different) > > ? ?Returns sets (amissing, bmissing, different) such that: > > ? ?amissing = keys missing from adict compared to bdict > ? ?bmissing = keys missing from bdict compared to adict > ? ?different = keys in both adict and bdict but with different values > > ? ?>>> dict_diffs({1:0, 2:0, 3:0}, {1:1, 2:0, 4:0}) > ? ?(set([4]), set([3]), set([1])) > > ? ?""" > ? ?from collections import Mapping > ? ?if not isinstance(a, Mapping) and isinstance(b, Mapping): > ? ? ? ?raise TypeError('arguments must both be mappings') > ? ?amissing, bmissing, different = set(), set(), set() > ? ?for key, value in a.items(): > ? ? ? ?if key not in b: > ? ? ? ? ? ?bmissing.add(key) > ? ? ? ?elif value != b[key]: > ? ? ? ? ? ?different.add(key) > ? ?for key, value in b.items(): > ? ? ? ?if key not in a: > ? ? ? ? ? ?amissing.add(key) > ? ?return (amissing, bmissing, different) Add me to this group. I frequently use some homebrew set operations on dictionaries. My (stupid) implementation: #! /usr/bin/env python3 class AugmentedDict(dict): def __and__(self, other): """Dictionary intersection operation""" return AugmentedDict(self.items() & other.items()) def __or__(self, other): """Dictionary union operation""" union = self.items() | other.items() merged_union = AugmentedDict(union) if len(union) != len(merged_union): err = 'Cannot take union of non-pairwise disjoint dictionaries' raise Exception(err) return merged_union def __sub__(self, other): """Dictionary difference operation""" return AugmentedDict(self.items() - other.items()) def __xor__(self, other): """Dictionary symmetric difference operation""" return AugmentedDict(self.items() ^ other.items()) if __name__ == "__main__": # demonstrate the behavior of AugmentedDict a = AugmentedDict({'a': 1, 'b': 2, 'c': 3}) b = AugmentedDict({'b': 2, 'c': 3}) c = AugmentedDict({'a': 1}) assert( (a|(b|c)) == (b|(a|c))) assert( (a&(b&c)) == (b&(a&c))) assert( (b&c) == (c&b)) assert( (a - b) == c) assert( (a ^ b) == ((a-b) | (b-a))) Truth be told, I was under the impression that this was actually going to be a part of dictionary behavior at some point, maybe I was thinking of the .items() behavior. Geremy Condra From navkirats at gmail.com Sat Nov 20 18:23:06 2010 From: navkirats at gmail.com (Navkirat Singh) Date: Sun, 21 Nov 2010 04:53:06 +0530 Subject: Persistent Database Cursors Message-ID: Hi Guys, I am having trouble with database cursors. I am using py-postgresql cursors to fetch data over HTTP. I want to be able to refer to the cursor over multiple HTTP requests. Any light on this matter would be of great help. Regards, Nav From goldtech at worldpost.com Sat Nov 20 19:08:51 2010 From: goldtech at worldpost.com (goldtech) Date: Sat, 20 Nov 2010 16:08:51 -0800 (PST) Subject: Installed modules from Synaptic in Ubuntu problem Message-ID: <6d4a1c46-fc21-40a2-84f9-0aff8ed1048c@a37g2000yqi.googlegroups.com> Hi, Using Ubuntu linux 9.04 and have python 2.6. I'm trying to add a module from the synaptic installer. It's ?Tidylib a wrapper for HTML Tidy. It installed with out a problem, when I do a $ help ('modules') I see a module called "tidy". But when I do an import tidy in a script I get an error... import tidy ImportError: No module named tidy How do I get this module working? Any help appreciated. also do I need a special path?: ~$ locate utidylib /usr/share/doc/python-utidylib /usr/share/doc/python-utidylib/README.Debian /usr/share/doc/python-utidylib/README.Debian-source /usr/share/doc/python-utidylib/README.txt /usr/share/doc/python-utidylib/changelog.Debian.gz /usr/share/doc/python-utidylib/copyright /usr/share/python-support/python-utidylib /usr/share/python-support/python-utidylib/tidy /usr/share/python-support/python-utidylib/uTidylib-0.2.egg-info /usr/share/python-support/python-utidylib/tidy/__init__.py /usr/share/python-support/python-utidylib/tidy/error.py /usr/share/python-support/python-utidylib/tidy/lib.py /usr/share/python-support/python-utidylib/tidy/test_tidy.py /var/cache/apt/archives/python-utidylib_0.2-3.2ubuntu1_all.deb /var/lib/dpkg/info/python-utidylib.list /var/lib/dpkg/info/python-utidylib.md5sums /var/lib/dpkg/info/python-utidylib.postinst /var/lib/dpkg/info/python-utidylib.prerm -- From martin at address-in-sig.invalid Sat Nov 20 19:10:19 2010 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Sun, 21 Nov 2010 00:10:19 +0000 (UTC) Subject: building a web interface References: Message-ID: On Sat, 20 Nov 2010 14:40:16 -0800, Shel wrote: > Hello, > > I am pretty new to all this. I have some coding experience, and am > currently most comfortable with Python. I also have database design > experience with MS Access, and have just created my first mySQL db. > > So right now I have a mySQL db structure and some Python code. My end > goal is to create a browser-based interactive fiction/game thing. My > code is currently just using dummy data rather than pulling in data from > the db, but I think/hope it won't be too big of a deal to interact with > the db through Python (famous last words...). > Wrong approach. If you're going to use a database, start with writing a program that puts your data into it alongside the program that reads and uses the data. Do it incrementally: if you are writing an adventure game a good place to start would be the 'place' table and the part of the game builder that adds/amends/removes a place from the database as well as enough of the game program to show the place description and use the doors to move from place to place. This way you'll have that working before you start adding weapons, monsters, etc. or try to implement fights. You'll also learn that writing place descriptions isn't as easy as it sounds: if there are several doors into a room the description must make sense no matter which way you come into it. Its quite hard at first to avoid descriptions like "Further into the forest. Its getting darker" which may be OK coming from a road but is pretty stupid if you're on your way out of the forest toward the road. http://www.kitebird.com/articles/pydbapi.html which tells you what you need to know about accessing SQL databases. > My main problem right now is how to do the web interface. I don't know > much about web architecture, unfortunately. I think I need a CGI script? > You're biting off quite a lot at once. It may be easier to first write a command line Python program and get it working in that form. Once you have the game/application logic working you can adapt it to run as a CGI script. Development and debugging will be easier that way. If you're not familiar with this style of adventure game, look here: http://www.rickadams.org/adventure/ You'll find various downloadable examples on the downloads page as DOS executables and in C or Fortran source code. Have a play with it to see what even this very basic user interaction can do - you'll have fun and learn useful stuff. > What I would really like is to find a GUI tool to design the interface > that would have customizable templates or drag-and-drop elements or > something, so I wouldn't have to code much by hand. Something easy, if > such a tool exists. > If you're doing a textual adventure of something like it a tool won't gain you much, since you only need a few skeleton web pages than your program can select and drop text or images into. > Also would prefer something that I would be able to install/use without > having much access to the server where the site will be hosted (on a > university server that I don't have control over). I don't fully > understand how a lot of the tools I have been looking at work, but it > seems like they're often things where you'd have to get an administrator > to do stuff on the server (is that right?), which I would prefer to > avoid. > CGI and Python should be OK providing the server has Python available and the admins will let you use CGI, but that's not a good development platform. You really need a web server you can start, stop and fiddle with once you get to the point of putting your code in a server. Running a simple local web server on your computer would be a better place to start: once its running you simply point your browser at localhost:80 and send it the URL of the initial page of your application. Search on "Python web server" for details of building or downloading a simple one. You'll also find stuff about interfacing Python programs to a web server. -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From stef.mientki at gmail.com Sat Nov 20 19:36:56 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Sun, 21 Nov 2010 01:36:56 +0100 Subject: building a web interface In-Reply-To: References: Message-ID: <4CE869A8.90209@gmail.com> On 20-11-2010 23:40, Shel wrote: > Hello, > > I am pretty new to all this. I have some coding experience, and am > currently most comfortable with Python. I also have database design > experience with MS Access, and have just created my first mySQL db. > > So right now I have a mySQL db structure and some Python code. My end > goal is to create a browser-based interactive fiction/game thing. My > code is currently just using dummy data rather than pulling in data > from the db, but I think/hope it won't be too big of a deal to > interact with the db through Python (famous last words...). > > My main problem right now is how to do the web interface. I don't know > much about web architecture, unfortunately. I think I need a CGI > script? > > What I would really like is to find a GUI tool to design the interface > that would have customizable templates or drag-and-drop elements or > something, so I wouldn't have to code much by hand. Something easy, if > such a tool exists. > > Also would prefer something that I would be able to install/use > without having much access to the server where the site will be hosted > (on a university server that I don't have control over). I don't fully > understand how a lot of the tools I have been looking at work, but it > seems like they're often things where you'd have to get an > administrator to do stuff on the server (is that right?), which I > would prefer to avoid. > > It looks like Django has some sort of standalone implementation, but > I'm not clear on how that would work or how much of a learning curve > there would be for using it. > > If anyone has any thoughts or suggestions, I would really appreciate > it. > > Hope my questions make sense. I don't really know what I'm doing, so > could be they're a bit silly. I apologize if that's the case, and > please let me know if you need any additional informmation. > > Thanks, > Shel you might take a look at web2py, it can be handled quit low level, runs perfectly on a the build python server, and you switch to almost any database at any time cheers, Stef From steve at REMOVE-THIS-cybersource.com.au Sat Nov 20 19:59:40 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 21 Nov 2010 00:59:40 GMT Subject: Inserting class namespace into method scope References: <4ce7e269$0$29991$c3e8da3$5496439d@news.astraweb.com> <87wro78xml.fsf@benfinney.id.au> Message-ID: <4ce86efc$0$29991$c3e8da3$5496439d@news.astraweb.com> On Sun, 21 Nov 2010 08:59:30 +1100, Ben Finney wrote: > C'mon, Steven, you know the drill. If you want us to help you solve a > problem, don't start with ?I want to use this behaviour that seems > loony, and I won't say why?. Instead, help us by telling us what problem > you're trying to solve. Well, I tried the TL;DR version. Now you have to read the full version. Inspired by the last maxim of the Zen: "Namespaces are one honking great idea -- let's do more of those!" I'm looking to apply this to my code. I have a bunch of related functions and objects which are private to a module, with a single public function that acts as the API to those functions. I'd like to have these private functions in a namespace, separate from the rest of the module. Ignore the fact that they are private functions -- I can deal with that by the usual naming convention. Focus on the "separate namespace" aspect. What I want is the ability to write this: create Namespace: def function(x): return x def func(y): return function("spam") + "'n'" + y dispatch = {1: func, 2: function} def another_func(z): return len(dispatch[2](z)) func("eggs") # raises NameError Namespace.func("eggs") # returns "spam'n'eggs" Namespace.dispatch[1]("cheese") # returns "spam'n'cheese" etc. But of course we can't do that. So other options include: (1) Give up the dream and just place the private functions in the global namespace like everyone else does. So much for the Zen. (2) Place them in a separate module, and import the module, similar to the way that the os module imports path. This is certainly possible, and it works well, but it splits code into two files when it should be in one. It pollutes the module namespace, and Guido has recently expressed mild objection to new code doing what os does. Or at least he suggested that we shouldn't *encourage* doing what os does. (3) Redesign my module to use a full package structure, and place the functions in a separate module in the package. It's overkill to have a package for just two namespaces (modules). (4) Use a class to hold the functions, instantiate the class to get an instance, and deal with the fact that functions in such an instance are automatically turned into methods. There are various ways of dealing with it, including the obvious: write the functions as methods. But this is too Java-like for my liking... I don't need the ability to make multiple instances with independent state, nor do I want to waste time turning it into a singleton or borg class. Worse, it complicates the dispatch table, because I have to deal with bound methods versus unbound methods, or staticmethod/classmethod descriptors... it gets *messy* and *ugly* real fast. (5) Use a class to hold the functions, but avoid instantiating it, so that the functions remain functions. I've done this, and it works great unless the functions need to refer to each other. So in the above example, Namespace.function("spam") is fine, but Namespace.func("eggs") is not. Simple solution: Namespace.func could internally call Namespace.function instead of just function. That's doable now, without any magic, but it feels less than ideal. (6) Do something with nested functions, although I'm not entirely sure what yet. See below. (7) Create a module on the fly, then populate it with the functions: Namespace = type(sys)('Namespace') def function(x): return x def func(y): return function("spam") + "'n'" + y dispatch = {1: func, 2: function} Namespace.function = function Namespace.func = func Namespace.dispatch = dispatch del function, func, dispatch (8) Something else. There's always something else. I've tried (1) through (5), with varying levels of success. (6) is next on my list to try. I haven't tried (7), and I don't think I will bother. It seriously breaks "Don't repeat yourself", and fails to visually set the Namespace functions apart from the global namespace. While I expect it will work, it's too ugly to consider. So I have considered many options, and will look at others, but right now I've set myself the task of exploring (5) and finding out whether or not there is any way to hammer the class namespace into what I want. Duncan suggested a way, but it's messy and fragile. TL;DR. See my first post :-P -- Steven From gnarlodious at gmail.com Sat Nov 20 20:19:06 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Sat, 20 Nov 2010 17:19:06 -0800 (PST) Subject: CGI FieldStorage instances? Message-ID: <1ec25d72-a99e-4fd9-9d50-1ac8c65812e9@z19g2000yqb.googlegroups.com> I'm having a hard time understanding this, can someone explain? Running a CGI with query string: ?action=Find&page=Data Script includes these lines: form=cgi.FieldStorage(keep_blank_values=1) print("Content-type:text/html\n\n") print(cgi.print_form(form)) Output: Form Contents: action: MiniFieldStorage('action', 'Find') page: MiniFieldStorage('page', 'Data') It looks like every variable in the query string instantiates a MiniFieldStorage with that value, is that the case? And if so, what sort of cool tricks could I do with that feature? Because so far I am doing CGI and it is a big old mess. Intercepting every variable is complicated and confusing. Is there an easier way? -- Gnarlie From joralemonshelly at gmail.com Sat Nov 20 20:20:53 2010 From: joralemonshelly at gmail.com (Shel) Date: Sat, 20 Nov 2010 17:20:53 -0800 (PST) Subject: building a web interface References: Message-ID: X-No-Archive:Thanks for your advice. Will take a look at rickadamsadventure.org. Although I am not actually creating an adventure game, I'm sure it will be helpful. Sorry I wasn't clear about the db part. Most of the data has already been written and/or generated and tested with the code. I do plan to finish all the database stuff before going to the front end, but am just thinking ahead about how to do the interface. On Nov 20, 4:10?pm, Martin Gregorie wrote: > On Sat, 20 Nov 2010 14:40:16 -0800, Shel wrote: > > Hello, > > > I am pretty new to all this. I have some coding experience, and am > > currently most comfortable with Python. ?I also have database design > > experience with MS Access, and have just created my first mySQL db. > > > So right now I have a mySQL db structure and some Python code. My end > > goal is to create a browser-based interactive fiction/game thing. My > > code is currently just using dummy data rather than pulling in data from > > the db, but I think/hope it won't be too big of a deal to interact with > > the db through Python (famous last words...). > > Wrong approach. If you're going to use a database, start with writing a > program that puts your data into it alongside the program that reads and > uses the data. Do it incrementally: if you are writing an adventure game > a good place to start would be the 'place' table and the part of the game > builder that adds/amends/removes a place from the database as well as > enough of the game program to show the place description and use the > doors to move from place to place. This way you'll have that working > before you start adding weapons, monsters, etc. or try to implement > fights. You'll also learn that writing place descriptions isn't as easy > as it sounds: if there are several doors into a room the description must > make sense no matter which way you come into it. Its quite hard at first > to avoid descriptions like "Further into the forest. Its getting darker" > which may be OK coming from a road but is pretty stupid if you're on your > way out of the forest toward the road. > > http://www.kitebird.com/articles/pydbapi.htmlwhich tells you what you > need to know about accessing SQL databases. > > > My main problem right now is how to do the web interface. I don't know > > much about web architecture, unfortunately. I think I need a CGI script? > > You're biting off quite a lot at once. It may be easier to first write a > command line Python program and get it working in that form. Once you > have the game/application logic working you can adapt it to run as a CGI > script. Development and debugging will be easier that way. > > If you're not familiar with this style of adventure game, look here:http://www.rickadams.org/adventure/You'll find various downloadable > examples on the downloads page as DOS executables and in C or Fortran > source code. Have a play with it to see what even this very basic user > interaction can do - you'll have fun and learn useful stuff. > > > What I would really like is to find a GUI tool to design the interface > > that would have customizable templates or drag-and-drop elements or > > something, so I wouldn't have to code much by hand. Something easy, if > > such a tool exists. > > If you're doing a textual adventure of something like it a tool won't > gain you much, since you only need a few skeleton web pages than your > program can select and drop text or images into. > > > Also would prefer something that I would be able to install/use without > > having much access to the server where the site will be hosted (on a > > university server that I don't have control over). I don't fully > > understand how a lot of the tools I have been looking at work, but it > > seems like they're often things where you'd have to get an administrator > > to do stuff on the server (is that right?), which I would prefer to > > avoid. > > CGI and Python should be OK providing the server has Python available and > the admins will let you use CGI, but that's not a good development > platform. > > You really need a web server you can start, stop and fiddle with once you > get to the point of putting your code in a server. Running a simple local > web server on your computer would be a better place to start: once its > running you simply point your browser at localhost:80 and send it the URL > of the initial page of your application. > > Search on "Python web server" for details of building or downloading a > simple one. You'll also find stuff about interfacing Python programs to a > web server. > > -- > martin@ ? | Martin Gregorie > gregorie. | Essex, UK > org ? ? ? | From ben+python at benfinney.id.au Sat Nov 20 20:33:09 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 21 Nov 2010 12:33:09 +1100 Subject: Inserting class namespace into method scope References: <4ce7e269$0$29991$c3e8da3$5496439d@news.astraweb.com> <87wro78xml.fsf@benfinney.id.au> <4ce86efc$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87sjyv8nqi.fsf@benfinney.id.au> Steven D'Aprano writes: > I have a bunch of related functions and objects which are private to a > module, with a single public function that acts as the API to those > functions. I'd like to have these private functions in a namespace, > separate from the rest of the module. Ignore the fact that they are > private functions -- I can deal with that by the usual naming > convention. Focus on the "separate namespace" aspect. > > What I want is the ability to write this: > > create Namespace: > def function(x): > return x > > def func(y): > return function("spam") + "'n'" + y > > dispatch = {1: func, 2: function} > > def another_func(z): > return len(dispatch[2](z)) Can you make it concrete, by naming the namespace something meaningful or arbitrary? It's as though you wanted to discuss a function, and named it ?function?. (Oh, you did that too :-) I'll assume an example of a namespace for the storage backends of a library, and that you want a namespace of ?storage?. If you can provide the actual use case that presents this problem to you, that would be best. Running with my contrived example, I take your option (2) below: use a private module as a private namespace. In the file ?_storage?: def backend_foo(x): return x def backend_bar(x): return backend_foo("spam") + "'n'" + x dispatch = {1: backend_bar, 2: backend_foo} > func("eggs") # raises NameError > Namespace.func("eggs") # returns "spam'n'eggs" > > Namespace.dispatch[1]("cheese") # returns "spam'n'cheese" import _storage backend_bar("eggs") # raises NameError _storage.backend_bar("eggs") # returns "spam'n'eggs" _storage.dispatch[1]("cheese") # returns "spam'n'cheese" > (2) Place them in a separate module, and import the module, similar to > the way that the os module imports path. This is certainly possible, > and it works well, but it splits code into two files when it should be > in one. Why should it be in one? If a separate module works well, there needs to be a good reason not to do it. > It pollutes the module namespace, and Guido has recently expressed > mild objection to new code doing what os does. Or at least he > suggested that we shouldn't *encourage* doing what os does. The single-leading-underscore naming convention makes it clear that the module is a private implementation detail, and signals to the reader that the module is not advisable for import except as part of that implementation. That refutes the charge of polluting the module namespace. As for Guido's opinion on the matter, for whatever it's worth, those interested are invited to read recent ?python-dev? discussions on APIs . In short, I think he agrees with my position above. > (3) Redesign my module to use a full package structure, and place the > functions in a separate module in the package. It's overkill to have a > package for just two namespaces (modules). I disagree strongly. Two modules is not too few for a package; it certainly isn't ?overkill?. Packages are quite lightweight for what they do. If they solve a problem well, I don't see why to discard them without a better reason. For all the other options you enumerated I am in agreement with your position. Thanks for making it more concrete so we know what problem we're supposed to be grappling. -- \ ?Nothing is more sacred than the facts.? ?Sam Harris, _The End | `\ of Faith_, 2004 | _o__) | Ben Finney From joralemonshelly at gmail.com Sat Nov 20 20:34:16 2010 From: joralemonshelly at gmail.com (Shel) Date: Sat, 20 Nov 2010 17:34:16 -0800 (PST) Subject: building a web interface References: Message-ID: Thanks for your help. I know that they have Python and mySQL. They have mySQL set up so that they just have to create the db, which they've already done and I've defined the tables and modified the data and whatnot, so that seems good. Not sure about mod-python v. mod-wsgi. Ah, the Django thing makes more sense to me now. I couldn't quite figure out what the heck they were talking about in the description of it. Shel On Nov 20, 4:19?pm, Dennis Lee Bieber wrote: > On Sat, 20 Nov 2010 14:40:16 -0800 (PST), Shel > declaimed the following in > gmane.comp.python.general: > > > What I would really like is to find a GUI tool to design the interface > > that would have customizable templates or drag-and-drop elements or > > something, so I wouldn't have to code much by hand. Something easy, if > > such a tool exists. > > ? ? ? ? In original pure HTML, such would be rather meaningless... Pure HTML > leaves the presentation (the rendering) of the page up to the user's > browser. Layout of one item against another is only relative (form field > 2 comes after form field 1). And I've seen some rather ugly pages > produced using so-called graphical design tools (like layers of > text because the tool isn't smart enough > to find and remove prior tag pairs when one changes intent... I've also > seen text ). > > ? ? ? ? Frames were one attempt at dividing a browser into regions in which > some stuff could stay constant while others are scrolled. > > ? ? ? ? Then you get the hoard that creates things like transparent GIF > files with a few pixels to create "spacing" elements... > > ? ? ? ? I tend to use an ancient copy of HomeSite 5 for HTML editing -- > though I don't do enough such to justify taking the time to define > things like Django's templating tags as standard types. I prefer to edit > in the original intent of HTML -- as a mark-up language which identifies > WHAT a construct is, but does not bother with HOW/WHERE that construct > is rendered. If I really need something looking more like a newspaper > layout I'd define a table and use combinations of row and column span to > "grid" the contents as desired -- and even that would still use > proportional spacing (90% of browser width, say) rather than absolute > pixels (845 pixels wide). > > > Also would prefer something that I would be able to install/use > > without having much access to the server where the site will be hosted > > (on a university server that I don't have control over). I don't fully > > understand how a lot of the tools I have been looking at work, but it > > seems like they're often things where you'd have to get an > > administrator to do stuff on the server (is that right?), which I > > would prefer to avoid. > > ? ? ? ? First step -- find out what toolset the server uses; Apache with > mod-python? mod-WSGI? Do they even have Python available? and if so, > what version (do they have MySQL available AND MySQLdb, and how much > control will they give you -- MySQL administration could be set up to > where they have to create the database AND table definitions, and all > you get is read/update/delete data privileges... Or they create the > database with no contents but your account has table manipulation > privileges within that database... Can you administer your database vie > direct login to the MySQL server, or do you have to go through some > web-based interface?). > > > It looks like Django has some sort of standalone implementation, but > > I'm not clear on how that would work or how much of a learning curve > > there would be for using it. > > ? ? ? ? The "standalone" is a development/debug server mode running on a > non-standard port number (HTTP is privileged port 80, these types of > development servers often run on ports 8080, 8081, etc. as one does not > need to be superuser to bind to the port number). It is not meant as a > production server. Instead one has the real server configured to run the > application (Django and similar are not simple stand-alone CGI scripts; > pages are _methods/functions_ within the application which generate the > page contents and return them to the server for delivery). > > -- > ? ? ? ? Wulfraed ? ? ? ? ? ? ? ? Dennis Lee Bieber ? ? ? ? AF6VN > ? ? ? ? wlfr... at ix.netcom.com ? ?HTTP://wlfraed.home.netcom.com/ From joralemonshelly at gmail.com Sat Nov 20 20:39:21 2010 From: joralemonshelly at gmail.com (Shel) Date: Sat, 20 Nov 2010 17:39:21 -0800 (PST) Subject: building a web interface References: Message-ID: Thanks for your help. I know that they have Python and mySQL. They have mySQL set up so that they just have to create the db, which they've already done and I've defined the tables and modified the data and whatnot, so that seems good. Not sure about mod-python v. mod-wsgi. Ah, the Django thing makes more sense to me now. I couldn't quite figure out what the heck they were talking about in the description of it. Shel On Nov 20, 4:19?pm, Dennis Lee Bieber wrote: > On Sat, 20 Nov 2010 14:40:16 -0800 (PST), Shel > declaimed the following in > gmane.comp.python.general: > > > What I would really like is to find a GUI tool to design the interface > > that would have customizable templates or drag-and-drop elements or > > something, so I wouldn't have to code much by hand. Something easy, if > > such a tool exists. > > ? ? ? ? In original pure HTML, such would be rather meaningless... Pure HTML > leaves the presentation (the rendering) of the page up to the user's > browser. Layout of one item against another is only relative (form field > 2 comes after form field 1). And I've seen some rather ugly pages > produced using so-called graphical design tools (like layers of > text because the tool isn't smart enough > to find and remove prior tag pairs when one changes intent... I've also > seen text ). > > ? ? ? ? Frames were one attempt at dividing a browser into regions in which > some stuff could stay constant while others are scrolled. > > ? ? ? ? Then you get the hoard that creates things like transparent GIF > files with a few pixels to create "spacing" elements... > > ? ? ? ? I tend to use an ancient copy of HomeSite 5 for HTML editing -- > though I don't do enough such to justify taking the time to define > things like Django's templating tags as standard types. I prefer to edit > in the original intent of HTML -- as a mark-up language which identifies > WHAT a construct is, but does not bother with HOW/WHERE that construct > is rendered. If I really need something looking more like a newspaper > layout I'd define a table and use combinations of row and column span to > "grid" the contents as desired -- and even that would still use > proportional spacing (90% of browser width, say) rather than absolute > pixels (845 pixels wide). > > > Also would prefer something that I would be able to install/use > > without having much access to the server where the site will be hosted > > (on a university server that I don't have control over). I don't fully > > understand how a lot of the tools I have been looking at work, but it > > seems like they're often things where you'd have to get an > > administrator to do stuff on the server (is that right?), which I > > would prefer to avoid. > > ? ? ? ? First step -- find out what toolset the server uses; Apache with > mod-python? mod-WSGI? Do they even have Python available? and if so, > what version (do they have MySQL available AND MySQLdb, and how much > control will they give you -- MySQL administration could be set up to > where they have to create the database AND table definitions, and all > you get is read/update/delete data privileges... Or they create the > database with no contents but your account has table manipulation > privileges within that database... Can you administer your database vie > direct login to the MySQL server, or do you have to go through some > web-based interface?). > > > It looks like Django has some sort of standalone implementation, but > > I'm not clear on how that would work or how much of a learning curve > > there would be for using it. > > ? ? ? ? The "standalone" is a development/debug server mode running on a > non-standard port number (HTTP is privileged port 80, these types of > development servers often run on ports 8080, 8081, etc. as one does not > need to be superuser to bind to the port number). It is not meant as a > production server. Instead one has the real server configured to run the > application (Django and similar are not simple stand-alone CGI scripts; > pages are _methods/functions_ within the application which generate the > page contents and return them to the server for delivery). > > -- > ? ? ? ? Wulfraed ? ? ? ? ? ? ? ? Dennis Lee Bieber ? ? ? ? AF6VN > ? ? ? ? wlfr... at ix.netcom.com ? ?HTTP://wlfraed.home.netcom.com/ From joralemonshelly at gmail.com Sat Nov 20 20:41:18 2010 From: joralemonshelly at gmail.com (Shel) Date: Sat, 20 Nov 2010 17:41:18 -0800 (PST) Subject: building a web interface References: Message-ID: <3313becc-6d5b-4cbc-8bfb-bc8252e6d2af@l8g2000yqh.googlegroups.com> This looks very promising. Thanks so much! Shel On Nov 20, 4:36?pm, Stef Mientki wrote: > On 20-11-2010 23:40, Shel wrote: > > > Hello, > > > I am pretty new to all this. I have some coding experience, and am > > currently most comfortable with Python. ?I also have database design > > experience with MS Access, and have just created my first mySQL db. > > > So right now I have a mySQL db structure and some Python code. My end > > goal is to create a browser-based interactive fiction/game thing. My > > code is currently just using dummy data rather than pulling in data > > from the db, but I think/hope it won't be too big of a deal to > > interact with the db through Python (famous last words...). > > > My main problem right now is how to do the web interface. I don't know > > much about web architecture, unfortunately. I think I need a CGI > > script? > > > What I would really like is to find a GUI tool to design the interface > > that would have customizable templates or drag-and-drop elements or > > something, so I wouldn't have to code much by hand. Something easy, if > > such a tool exists. > > > Also would prefer something that I would be able to install/use > > without having much access to the server where the site will be hosted > > (on a university server that I don't have control over). I don't fully > > understand how a lot of the tools I have been looking at work, but it > > seems like they're often things where you'd have to get an > > administrator to do stuff on the server (is that right?), which I > > would prefer to avoid. > > > It looks like Django has some sort of standalone implementation, but > > I'm not clear on how that would work or how much of a learning curve > > there would be for using it. > > > If anyone has any thoughts or suggestions, I would really appreciate > > it. > > > Hope my questions make sense. I don't really know what I'm doing, so > > could be they're a bit silly. I apologize if that's the case, and > > please let me know if you need any additional informmation. > > > Thanks, > > Shel > > you might take a look at web2py, > it can be handled quit low level, > runs perfectly on a the build python server, > and you switch to almost any database at any time > > cheers, > Stef From hidura at gmail.com Sat Nov 20 21:35:47 2010 From: hidura at gmail.com (Hidura) Date: Sat, 20 Nov 2010 22:35:47 -0400 Subject: Printing from Web Page In-Reply-To: References: Message-ID: Explain better what you try to do. 2010/11/20, Victor Subervi : > Hi; > I need to be able to print something from a Web page: not the entire page > but what I specify. I am writing the page and the client is surfing to it. > How do I do this? > TIA, > beno > -- Enviado desde mi dispositivo m?vil Diego I. Hidalgo D. From ian.g.kelly at gmail.com Sun Nov 21 00:50:14 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 20 Nov 2010 22:50:14 -0700 Subject: building a web interface In-Reply-To: References: Message-ID: On 11/20/2010 3:40 PM, Shel wrote: > So right now I have a mySQL db structure and some Python code. My end > goal is to create a browser-based interactive fiction/game thing. My > code is currently just using dummy data rather than pulling in data > from the db, but I think/hope it won't be too big of a deal to > interact with the db through Python (famous last words...). Suggestion: unless you're intent on reinventing the wheel, why not just set up your web interface as a thin front-end for an existing IF engine? An excellent starting point for this would be digging up the source for InfocomBot [1], an AIM bot that acts as a simple wrapper around Frotz [2]. My recollection of seeing the source once is that it was only around 50 or so lines of code. Doing it this way, 1) You don't have to write an IF engine from scratch. 2) If you wrap Frotz specifically, you can serve any Z-code game ever written, including (I think) all of the Infocom games. 3) You can create your game using powerful existing development tools, such as Inform [3]. Cheers, Ian [1] http://waxy.org/2004/03/infocombot_for/ [2] http://frotz.sourceforge.net/ [3] http://inform7.com/ From navkirats at gmail.com Sun Nov 21 01:08:09 2010 From: navkirats at gmail.com (Navkirat Singh) Date: Sun, 21 Nov 2010 11:38:09 +0530 Subject: Pickling a database cursor? Message-ID: <736F0BEA-6FCC-4BA0-954B-15D4556A40BA@gmail.com> Hi Guys, Is there any way to pickle a database cursor? I would like a persistent cursor over multiple HTTP requests. Any help would be awesome ! Nav From clp2 at rebertia.com Sun Nov 21 01:30:26 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 20 Nov 2010 22:30:26 -0800 Subject: Pickling a database cursor? In-Reply-To: <736F0BEA-6FCC-4BA0-954B-15D4556A40BA@gmail.com> References: <736F0BEA-6FCC-4BA0-954B-15D4556A40BA@gmail.com> Message-ID: On Sat, Nov 20, 2010 at 10:08 PM, Navkirat Singh wrote: > Hi Guys, > > Is there any way to pickle a database cursor? I would like a persistent cursor over multiple HTTP requests. Any help would be awesome ! You can't. It's like a file handle in that respect. Cheers, Chris -- http://blog.rebertia.com From lothiraldan at gmail.com Sun Nov 21 04:35:10 2010 From: lothiraldan at gmail.com (FELD Boris) Date: Sun, 21 Nov 2010 10:35:10 +0100 Subject: Printing from Web Page In-Reply-To: References: Message-ID: <911E277A512742F4A8C0CC8A4336505D@gmail.com> I think the best way to do this is using css with specific media type.Take a look at :?http://martybugs.net/articles/print.cgi --?FELD BorisSent with Sparrow On dimanche 21 novembre 2010 at 03:35, Hidura wrote: Explain better what you try to do.2010/11/20, Victor Subervi : Hi; I need to be able to print something from a Web page: not the entire page but what I specify. I am writing the page and the client is surfing to it. How do I do this? TIA, beno-- Enviado desde mi dispositivo m?vilDiego I. Hidalgo D.-- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From pmilin at ff.uns.ac.rs Sun Nov 21 04:57:29 2010 From: pmilin at ff.uns.ac.rs (Petar Milin) Date: Sun, 21 Nov 2010 10:57:29 +0100 Subject: Is it possible to use Google's advanced search options? In-Reply-To: <4CE82F25.3000805@pythonmeister.com> References: <4CE82F25.3000805@pythonmeister.com> Message-ID: <4CE8ED09.6070706@ff.uns.ac.rs> Hello! Thanks so much for the patched Pygoogle! Also, please, can you give me some more information about how to use google search api? I am a newbie in Python, and I still try to cope with it. Thanks to some experience in other programing languages, I think I progress well, but I am not a professional user/programer; quite far from that. Best, Petar On 20/11/10 21:27, Stefan Sonnenberg-Carstens wrote: > Am 20.11.2010 20:24, schrieb Petar Milin: >> Thanks so much! However, 'options lang:de' does not exactly the same >> as would 'lr=lang_de'? Am I right? > You're right. >> Since I need number of hits, I would like to have the best, most >> correct values! :-) >> >> Sincerely, >> PM >> >> On Sat, Nov 20, 2010 at 12:00 PM, >> wrote: > I took a look into pygoogle source code. > It does not send the 'lr' parameter to google.de (as it does not with > many more ...). > I patched it to enable the following (what you needed): > > >>> from pygoogle import pygoogle > >>> g = pygoogle('linux site:.edu') > >>> g.lr = 'lang_de' > >>> g.pages = 2 > >>> print 'German',g.get_result_count() > German 3910 > >>> g.lr = 'lang_en' > >>> print 'English',g.get_result_count() > English 1140000 > >>> g.lr = 'lang_cn' > >>> print 'Chinese',g.get_result_count() > Chinese 1210000 > >>> > > I have attached my patched version of pygoogle. > BTW: the google search api is very straight forware. > Perhaps it is easier to create a custom bot to do your queries. > Cheers, From pmilin at ff.uns.ac.rs Sun Nov 21 05:01:45 2010 From: pmilin at ff.uns.ac.rs (Petar Milin) Date: Sun, 21 Nov 2010 11:01:45 +0100 Subject: Does Pygoogle allows for advanced search options? In-Reply-To: References: <706ff3ad-66b4-4cdb-a68f-bf0a079c2dc1@32g2000yqz.googlegroups.com> Message-ID: <4CE8EE09.20202@ff.uns.ac.rs> On 20/11/10 22:34, Chris Rebert wrote: > On Thu, Nov 18, 2010 at 3:26 AM, neocortex wrote: > >>> The library doesn't seem to have built-in support for filtering by >>> language (and Google lacks a search query-string-based operator for >>> that), but it looks like you could implement that feature by adding an >>> "lr" parameter with an appropriate value to the query `args` >>> dictionary. See the "lr?" entry under "Web Search Specific Arguments" >>> onhttp://code.google.com/apis/websearch/docs/reference.html, and >>> lines 68& 102 of pygoogle.py. >>> >> From those lines, it can be concluded that lr=lang_?? is not >> supported, unfortunately. >> > Right; that's why I said "you could implement that feature". Pretty > easily it would seem. > Thanks for believing in me ( ;-) ), but I am a newbie in Python world, although with some experience in other prog. languages. So, if I read pygoogle.py well, I sould add lr parameter in init and then after lines 68 and 102? Thanks again! You guys here are very kind and helpful! Best, Petar From stefan.sonnenberg at pythonmeister.com Sun Nov 21 05:51:11 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Sun, 21 Nov 2010 11:51:11 +0100 Subject: Does Pygoogle allows for advanced search options? In-Reply-To: <4CE8EE09.20202@ff.uns.ac.rs> References: <706ff3ad-66b4-4cdb-a68f-bf0a079c2dc1@32g2000yqz.googlegroups.com> <4CE8EE09.20202@ff.uns.ac.rs> Message-ID: <4CE8F99F.9010806@pythonmeister.com> Am 21.11.2010 11:01, schrieb Petar Milin: > > On 20/11/10 22:34, Chris Rebert wrote: >> On Thu, Nov 18, 2010 at 3:26 AM, neocortex wrote: >>>> The library doesn't seem to have built-in support for filtering by >>>> language (and Google lacks a search query-string-based operator for >>>> that), but it looks like you could implement that feature by adding an >>>> "lr" parameter with an appropriate value to the query `args` >>>> dictionary. See the "lr?" entry under "Web Search Specific Arguments" >>>> onhttp://code.google.com/apis/websearch/docs/reference.html, and >>>> lines 68& 102 of pygoogle.py. >>> From those lines, it can be concluded that lr=lang_?? is not >>> supported, unfortunately. >> Right; that's why I said "you could implement that feature". Pretty >> easily it would seem. > Thanks for believing in me ( ;-) ), but I am a newbie in Python world, > although with some experience in other prog. languages. > So, if I read pygoogle.py well, I sould add lr parameter in init and > then after lines 68 and 102? Correct. I just did not read source code enough to realize the parameter is needed twice. You just could hack that out, too :-) Normally (what is normal, anyway ?) it's good practice to create an contructor (__init__) in python which has the most common options as keyword arguments and default values assigned, like so: class Foo: def __init__(self,lr='lang_en',url='http://some.of.this'): self.lr = lr self.url = url ... > > Thanks again! You guys here are very kind and helpful! > Best, > Petar > -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: pygoogle.py URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: stefan_sonnenberg.vcf Type: text/x-vcard Size: 223 bytes Desc: not available URL: From kokososo56 at yahoo.com Sun Nov 21 07:18:03 2010 From: kokososo56 at yahoo.com (soso) Date: Sun, 21 Nov 2010 04:18:03 -0800 (PST) Subject: Download the free and exclusive involvement of Bandon the world's first Internet Security Nod32 Antivirus 4.2.67.10 version of Business Edition Topics Encyclopedia Internet Security / Antivirus**** Message-ID: <2fba81c5-2b34-4064-8310-71e13c67ecce@f20g2000yqi.googlegroups.com> Download the free and exclusive involvement of Bandon the world's first Internet Security Nod32 Antivirus 4.2.67.10 version of Business Edition Topics Encyclopedia Internet Security / Antivirus Download from here http://prosoftantivirus.blogspot.com/2010/11/nod32-antivirus-426710-business-edition.html From martin at address-in-sig.invalid Sun Nov 21 07:51:01 2010 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Sun, 21 Nov 2010 12:51:01 +0000 (UTC) Subject: building a web interface References: Message-ID: On Sat, 20 Nov 2010 17:20:53 -0800, Shel wrote: > Sorry I wasn't clear about the db part. Most of the data has already > been written and/or generated and tested with the code. I do plan to > finish all the database stuff before going to the front end, but am just > thinking ahead about how to do the interface. > That sounds good. Sorry if I was repeating stuff you already know, but it wasn't obvious what you knew about care & feeding of an RDBMS. I'll just add two comments on databases: - Decompose the database design to 3NF form and make sure all prime and foreign keys have indexes. This is stuff that previous experience shows self-taught Access users don't do. Not doing it will bite you hard on performance as soon as the tables exceed a few rows in size. Fixing it later can force major changes to the programs as well. - If you haven't looked at it yet, find out about the EXPLAIN verb and what its output means. Use it on all queries that your online program issues and take notice of how rearranging the query and/or adding/changing indexes affects the cost of the query. Lower cost queries mean higher performance and hence faster response times. What I meant to add last night is that, if your application is to be used by more than a single user at a time a prime consideration is how you will recognise input received from each user and how you'll store their context between interactions with them in the same session and keep each session's context separate. The web server doesn't do this, so this managing session context is the application's responsibility. Common methods are to use a session cookie and/or to store session context in the database. -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From victorsubervi at gmail.com Sun Nov 21 09:03:45 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Sun, 21 Nov 2010 10:03:45 -0400 Subject: Printing from Web Page In-Reply-To: <911E277A512742F4A8C0CC8A4336505D@gmail.com> References: <911E277A512742F4A8C0CC8A4336505D@gmail.com> Message-ID: On Sun, Nov 21, 2010 at 5:35 AM, FELD Boris wrote: > I think the best way to do this is using css with specific media type. > Take a look at : http://martybugs.net/articles/print.cgi > Oh, man, this is perfect! Thanks! beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From ayaafarag at gmail.com Sun Nov 21 10:06:04 2010 From: ayaafarag at gmail.com (ayaa) Date: Sun, 21 Nov 2010 07:06:04 -0800 (PST) Subject: Questions about optmodel constraints Message-ID: <46188e2b-ff0f-41cd-a071-57c1eb4bbb52@k3g2000vbp.googlegroups.com> I have three questions: 1. If I have a variable that is stored in a data set and I want to formulate only one constraint (under optmodel) that is a function of all the data set's observations of this variable and a decision variable. Suppose the variable is a and x is the decision variable. My constraint is: [(maximum value of a) +x ] / [(minimum value of a) +x ] < maximum value of (a) / minimum value of (a), can you help me to include this constraint under optmodel? 2. If there is one scalar number that is a result of certain calculations and the it is stored in a dataset and I want to equate a constraint with this scalar, can you help me to do this? 3. If there is one scalar number that is a result of certain calculations and it is stored in a dataset and I want to include this scalar in "sum" operator. Suppose there are also two stored variables that are a and b, and x is a decision variable and the scalar is c, I want c to appear as in the following constraint: sum over i for [ c*(ai)^2 * bi/ (ai+x)] = 0.5 , can you help me to do this under optmodel? Thanks Ayaa From usenet at ffconsultancy.com Sun Nov 21 10:25:08 2010 From: usenet at ffconsultancy.com (Jon Harrop) Date: Sun, 21 Nov 2010 15:25:08 -0000 Subject: Scheme as a virtual machine? In-Reply-To: <20101014052650.510e8833@tritium.streitmacht.eu> References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com><20101014020136.6e85d70b@tritium.streitmacht.eu> <20101014052650.510e8833@tritium.streitmacht.eu> Message-ID: "Ertugrul S?ylemez" wrote in message news:20101014052650.510e8833 at tritium.streitmacht.eu... > That's nonsense. Actually namekuseijin is right. You really need to persevere and familiarize yourself with some of the other languages out there. Haskell is many things but simple is not one of them. If Haskell were half of the things you think it is, it would have more credible success stories. Cheers, Jon. From emile at fenx.com Sun Nov 21 12:16:14 2010 From: emile at fenx.com (Emile van Sebille) Date: Sun, 21 Nov 2010 09:16:14 -0800 Subject: Inserting class namespace into method scope In-Reply-To: <4ce86efc$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4ce7e269$0$29991$c3e8da3$5496439d@news.astraweb.com> <87wro78xml.fsf@benfinney.id.au> <4ce86efc$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 11/20/2010 4:59 PM Steven D'Aprano said... > On Sun, 21 Nov 2010 08:59:30 +1100, Ben Finney wrote: > >> C'mon, Steven, you know the drill. If you want us to help you solve a >> problem, don't start with ?I want to use this behaviour that seems >> loony, and I won't say why?. Instead, help us by telling us what problem >> you're trying to solve. > > Well, I tried the TL;DR version. Now you have to read the full version. > > Inspired by the last maxim of the Zen: > > "Namespaces are one honking great idea -- let's do more of those!" Hmm... while playing with various takes on globals and code blocks I came across this that may be of interest. http://www.voidspace.org.uk/python/articles/code_blocks.shtml Emile From aahz at pythoncraft.com Sun Nov 21 13:30:06 2010 From: aahz at pythoncraft.com (Aahz) Date: 21 Nov 2010 10:30:06 -0800 Subject: is list comprehension necessary? References: <4cc701e7$0$1606$742ec2ed@news.sonic.net> Message-ID: In article <4cc701e7$0$1606$742ec2ed at news.sonic.net>, John Nagle wrote: > >Python isn't a functional language. It has some minimal functional >capabilities, and there's a lobby that would like more. So far, that's >mostly been resisted. Attempts to allow multiline lambdas have been >averted. The weird "functional if" syntax additions were a cave-in to >the functional crowd, and may have been a mistake. Did you actually read the PEP explanation for *why* Guido decided to add conditional expressions? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Look, it's your affair if you want to play with five people, but don't go calling it doubles." --John Cleese anticipates Usenet From pmilin at ff.uns.ac.rs Sun Nov 21 14:35:03 2010 From: pmilin at ff.uns.ac.rs (Petar Milin) Date: Sun, 21 Nov 2010 20:35:03 +0100 Subject: Does Pygoogle allows for advanced search options? Message-ID: <4CE97467.7090308@ff.uns.ac.rs> Hello ALL! I am playing with the modified version of the Pygoogle (by Stefan). Interesting thing is that get_result_count() gives numbers/results different from those in Google. Has anyone checked this? Does anyone know why? Best, Petar From jakub.vysoky at gmail.com Sun Nov 21 14:39:33 2010 From: jakub.vysoky at gmail.com (kvbik) Date: Sun, 21 Nov 2010 11:39:33 -0800 (PST) Subject: multiple times subprocess fails on windows Message-ID: Hello, in a test suite in my project (called rvirtualenv [1]) I discovered a strange behaviour when calling from python a batch file which calles another python and this calles a shell command. [1] http://github.com/kvbik/rvirtualenv I know it sounds pretty strange, but I do this only because I am testing such specific tool (that has similar functionality like original virtualenv and there are things like activate.bat commands). I've uploaded some code snippet here: https://gist.github.com/709004/6ccc44d6aed5fe694bb2adbef2400bbea92998a1 If anyone could explain me this behaviour I would be more than happy, because right now it is the only failing test in my project ;). Thanks in advance, Jakub.. From nagle at animats.com Sun Nov 21 14:43:11 2010 From: nagle at animats.com (John Nagle) Date: Sun, 21 Nov 2010 11:43:11 -0800 Subject: Pickling a database cursor? In-Reply-To: References: <736F0BEA-6FCC-4BA0-954B-15D4556A40BA@gmail.com> Message-ID: <4ce97658$0$1669$742ec2ed@news.sonic.net> On 11/20/2010 10:30 PM, Chris Rebert wrote: > On Sat, Nov 20, 2010 at 10:08 PM, Navkirat Singh > wrote: >> Hi Guys, >> >> Is there any way to pickle a database cursor? I would like a >> persistent cursor over multiple HTTP requests. Any help would be >> awesome ! > > You can't. It's like a file handle in that respect. > > Cheers, Chris -- http://blog.rebertia.com I've seen several related questions on this from the same person. A few hints: I suspect that what you're trying to do is to display a sequence of records from a database in page-sized groups. There's a way to do that. In SQL, look into the OFFSET and LIMIT clauses. The idea is that if you want the first 10 entries, your SQL statement has OFFSET 0 and LIMIT 10. For the next 10, you use OFFSET 10 and LIMIT 10, and so on. For this to work, your SQL statement needs a ORDER BY clause, so the records come out in the same order each time. And you need to define an INDEX on the fields used in the ORDER BY clause, or the database engine has to sort the file every time, which is really slow. The usual way to do this with web pages is to use REST-type parameters in the URL. So you'll have a URL like http://www.example.com/cgi/getrecords.cgi?q=customerid&offset=0&limit=10 On the pages you return, you put URLs for "next page" (with a bigger offset) and "previous page" (with a smaller offset). That way, the user can move forwards and backwards through the pages. You have to read those parameters from the URL and put them into the SQL. (For OFFSET and LIMIT, you have to edit those parameters into the SQL string itself, because those numbers aren't placed in quotes. You can't use the second parameter to cursor.execute for this. So, when you fetch those parameters, convert them to numbers with "int(s)" before putting them into the SQL statement. Otherwise, you'll have an SQL injection vulnerability.) Page through some Google search results and watch how the URLs change. That's how Google does it. Don't use cookies for position information. The browser's "Back" button won't do what users expect if you do that. John Nagle From gtmacdonald at gmail.com Sun Nov 21 15:43:33 2010 From: gtmacdonald at gmail.com (Greg MacDonald) Date: Sun, 21 Nov 2010 12:43:33 -0800 Subject: Strange affinity side effect with multiprocessing. Message-ID: Hi Everyone, I'm having a strange problem with the multiprocessing package and Panda3D. Importing panda modules causes multiprocessing to only use one of my cores. I've created an example test case. It uses an infinite loop to ping the cores so you'll have to manually kill the python processes. So if I run the following I can see in my task manager that both cores are at 100%. Code: #from pandac.PandaModules import Point2 from multiprocessing import Pool def dummyWorker(a): while True: continue class DummyTester(object): def __init__(self): self.pool = Pool(2) def go(self): result = self.pool.map_async(dummyWorker, range(2)) result.get() if __name__ == "__main__": DummyTester().go() But if I uncomment out that one line there it only uses one of my cores. This is with a fresh download of panda 1.7.0 on windows xp, python 2.6, and intel core2 duo. I'm completely at a loss so any thoughts would be greatly appreciated. Thx. -Greg From stefan.sonnenberg at pythonmeister.com Sun Nov 21 15:45:26 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Sun, 21 Nov 2010 21:45:26 +0100 Subject: Does Pygoogle allows for advanced search options? In-Reply-To: <4CE97467.7090308@ff.uns.ac.rs> References: <4CE97467.7090308@ff.uns.ac.rs> Message-ID: <4CE984E6.1050605@pythonmeister.com> Am 21.11.2010 20:35, schrieb Petar Milin: > Hello ALL! > I am playing with the modified version of the Pygoogle (by Stefan). > Interesting thing is that get_result_count() gives numbers/results > different from those in Google. Has anyone checked this? Does anyone > know why? > > Best, > Petar > AFAIK there are several reports which point to the same observation; even time & location (requesting IP) seem to generate different results. -------------- next part -------------- A non-text attachment was scrubbed... Name: stefan_sonnenberg.vcf Type: text/x-vcard Size: 232 bytes Desc: not available URL: From pmilin at gmail.com Sun Nov 21 16:07:50 2010 From: pmilin at gmail.com (Petar Milin) Date: Sun, 21 Nov 2010 22:07:50 +0100 Subject: Does Pygoogle allows for advanced search options? In-Reply-To: <4CE984E6.1050605@pythonmeister.com> References: <4CE97467.7090308@ff.uns.ac.rs> <4CE984E6.1050605@pythonmeister.com> Message-ID: <1290373670.22702.6.camel@Nokia-N900-51-1> So, what can one do about this? There seems to be at least two aspects: (a) difference between browser-based and script-based (pygoogle in this case) query, and (b) difference in time and place, but possibly within the same query type. If so, how can we be sure? It would be interesting (at least to me) to check for the correlations between numbers. That would answer whether there is some/any consistency. Best, Petar ----- Original message ----- > Am 21.11.2010 20:35, schrieb Petar Milin: > > Hello ALL! > > I am playing with the modified version of the Pygoogle (by Stefan). > > Interesting thing is that get_result_count() gives numbers/results > > different from those in Google. Has anyone checked this? Does anyone > > know why? > > > > Best, > > Petar > > > AFAIK there are several reports which point to the same observation; > even time & location (requesting IP) seem to generate different results. > > ? stefan_sonnenberg.vcf -------------- next part -------------- An HTML attachment was scrubbed... URL: From joralemonshelly at gmail.com Sun Nov 21 18:03:49 2010 From: joralemonshelly at gmail.com (Shel) Date: Sun, 21 Nov 2010 15:03:49 -0800 (PST) Subject: building a web interface References: Message-ID: Definitely not looking to reinvent the wheel. Will check these out, thanks! Shel On Nov 20, 9:50?pm, Ian Kelly wrote: > On 11/20/2010 3:40 PM, Shel wrote: > > > So right now I have a mySQL db structure and some Python code. My end > > goal is to create a browser-based interactive fiction/game thing. My > > code is currently just using dummy data rather than pulling in data > > from the db, but I think/hope it won't be too big of a deal to > > interact with the db through Python (famous last words...). > > Suggestion: unless you're intent on reinventing the wheel, why not just > set up your web interface as a thin front-end for an existing IF engine? > ? An excellent starting point for this would be digging up the source > for InfocomBot [1], an AIM bot that acts as a simple wrapper around > Frotz [2]. ?My recollection of seeing the source once is that it was > only around 50 or so lines of code. ?Doing it this way, > > 1) You don't have to write an IF engine from scratch. > > 2) If you wrap Frotz specifically, you can serve any Z-code game ever > written, including (I think) all of the Infocom games. > > 3) You can create your game using powerful existing development tools, > such as Inform [3]. > > Cheers, > Ian > > [1]http://waxy.org/2004/03/infocombot_for/ > [2]http://frotz.sourceforge.net/ > [3]http://inform7.com/ From aaronasterling at gmail.com Sun Nov 21 18:04:55 2010 From: aaronasterling at gmail.com (Aaron Sterling) Date: Sun, 21 Nov 2010 15:04:55 -0800 (PST) Subject: constructin trees in python References: <3c926050-5e27-4efb-bf76-dbd1f2412810@o14g2000yqe.googlegroups.com> Message-ID: <973d6837-e84e-40c0-94a3-205efbe30a0f@g25g2000yqn.googlegroups.com> > Thanks a lot peter, that worked as i needed. Where can i find some > good documentation which explains such behavior. The reason for this behavior is the way python stores attributes. Both a class and an instance of a class have a __dict__ attribute which is a dictionary which stores attributes in name value pairs. Consider the following class. class A(object): a = 1 def __init__(self, b): self.b = b Inspecting A.__dict__, one will see that it looks like {'a': 1} with no reference to b. Instantiating with a = A(2), one will see that a.__dict__ is {'b': 2} with no reference to a. If one accesses a.b, then Python will first look in a.__dict__ and find 'b'. It will then return that value for a.b If one instead accesses a.a then Python will first look in a.__dict__ and not find an entry for 'a'. It will then look in type(a).__dict__ == A.__dict__, find 'a' and return it for a.a One can in fact use this behavior to shadow class attributes. If the __init__ function is changed to def __init__(self, a, b): self.a = a self.b = b then all instances of A will have their own instance attribute named a with whatever value is passed to __init__. They will still have a class level attribute named a with value 1 but Python will never see it because it will find an entry for a in some_instance.__dict__. If one executes del some_instance.a Then on that one instance, visibility for the class level a will be restored. In fact, one can always get the class level instance as type(some_instance).__dict__['a'] but that's a little awkward. The reason that this matters with mutable attributes and not with (often) with immutable attributes is that a statement of the form some_instance.some_mutable_attribute.append(foo) will reference the same class level attribute regardless of the instance it's called with. There's no assignment going on here. An existing binding is being looked up, and the resulting value (a list in this case) is having an attribute called on it. No new bindings are being created. A statement of the form some_instance.some_mutable_attribute = some_new_list Will not affect the class level attribute at all but will simply shadow it in the same manner as describe above. Once a name is bound to an immutable value, the only way to change the value that it points to is to rebind it. This means that any 'change' to a class level immutable value (accessed through attribute lookup on an instance) will simply shadow it on the instance upon which it is accessed. HTH From joralemonshelly at gmail.com Sun Nov 21 18:40:10 2010 From: joralemonshelly at gmail.com (Shel) Date: Sun, 21 Nov 2010 15:40:10 -0800 (PST) Subject: building a web interface References: Message-ID: <16bc6e60-ad98-4d81-9f20-23e9b52eea21@n30g2000vbb.googlegroups.com> No worries at all about repeating things. I wasn't clear, and I appreciate your going to the trouble of teaching me just about anything. Even things I think I know, I might not really know :-) Let's see... am okay with the relational design stuff. Thanks for the "EXPLAIN" verb. I am confused about multiple simultaneous users, which I would like to be able to accommodate. On the db side, I have a structure to store data for each user, and know a bit about selectively locking data, although I have not implemented that yet, so will see what happens. I don't really get how multiple users work in terms of pretty much everything else, like if the Python code is running on the server, then... well, I just don't know. Maybe I should try to get it running for multiple discrete users first, and then think about simultaneous users, or is that a bad way to go about things? Or maybe it will start to make more sense when I get into building the interface? Any info/suggestions are very welcome. Thanks again! Shel On Nov 21, 4:51?am, Martin Gregorie wrote: > On Sat, 20 Nov 2010 17:20:53 -0800, Shel wrote: > > Sorry I wasn't clear about the db part. ?Most of the data has already > > been written and/or generated and tested with the code. ?I do plan to > > finish all the database stuff before going to the front end, but am just > > thinking ahead about how to do the interface. > > That sounds good. Sorry if I was repeating stuff you already know, but it > wasn't obvious what you knew about care & feeding of an RDBMS. I'll just > add two comments on databases: > - Decompose the database design to 3NF form and make sure all prime > ? and foreign keys have indexes. This is stuff that previous experience > ? shows self-taught Access users don't do. Not doing it will bite you > ? hard on performance as soon as the tables exceed a few rows in size. > ? Fixing it later can force major changes to the programs as well. > > - If you haven't looked at it yet, find out about the EXPLAIN verb > ? and what its output means. Use it on all queries that your online > ? program issues and take notice of how rearranging the query and/or > ? adding/changing indexes affects the cost of the query. Lower cost > ? queries mean higher performance and hence faster response times. > > What I meant to add last night is that, if your application is to be used > by more than a single user at a time a prime consideration is how you > will recognise input received from each user and how you'll store their > context between interactions with them in the same session and keep each > session's context separate. The web server doesn't do this, so this > managing session context is the application's responsibility. Common > methods are to use a session cookie and/or to store session context in > the database. > > -- > martin@ ? | Martin Gregorie > gregorie. | Essex, UK > org ? ? ? | From joralemonshelly at gmail.com Sun Nov 21 18:42:09 2010 From: joralemonshelly at gmail.com (Shel) Date: Sun, 21 Nov 2010 15:42:09 -0800 (PST) Subject: building a web interface References: Message-ID: <6ae91df9-7a93-4d70-a60d-82973d7d6295@v23g2000vbi.googlegroups.com> Just want to say thanks again to everyone who responded to this post. You have all been really helpful. From irmen.NOSPAM at xs4all.nl Sun Nov 21 18:54:30 2010 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Mon, 22 Nov 2010 00:54:30 +0100 Subject: [ANN] Pyro 3.11 released Message-ID: <4ce9b13a$0$81485$e4fe514c@news.xs4all.nl> Hi, Pyro 3.11 has been released! Pyro is a an advanced and powerful Distributed Object Technology system written entirely in Python, that is designed to be very easy to use. Have a look at http://www.xs4all.nl/~irmen/pyro3/ for more information. Highlights of this release are: - improved compatibility with Jython - fixed some threading problems regarding proxy connections - fixed a threading issue that could break COM calls - persistent mode nameserver improved As always the detailed changes are in the change log chapter in the manual. More info and download link available in PyPI: http://pypi.python.org/pypi/Pyro/ Enjoy, Irmen de Jong From martin at address-in-sig.invalid Sun Nov 21 21:10:26 2010 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Mon, 22 Nov 2010 02:10:26 +0000 (UTC) Subject: building a web interface References: <16bc6e60-ad98-4d81-9f20-23e9b52eea21@n30g2000vbb.googlegroups.com> Message-ID: On Sun, 21 Nov 2010 15:40:10 -0800, Shel wrote: > I am confused about multiple simultaneous users, which I would like to > be able to accommodate. On the db side, I have a structure to store > data for each user, and know a bit about selectively locking data, > although I have not implemented that yet, so will see what happens. > I realise what I wrote last night wasn't all that clear. Terms: 'transaction' and 'session'. A web server 'transaction' consists of a request from a user that results in a page being sent to the user. That's it. It is an isolated action that does not depend in the web server knowing anything about the user because all the information it needs to decide which page to send was supplied when the user sent in the URL of the page. Now if the user clicks on a link on that page, his browser sends the URL in the link to the server, which in turn fishes out another page and sends it back to the user. As far as the server is concerned, there is no connection whatever between the two requests: either or both URLs could have been copied from a piece of paper for all it knows or cares. There is no concept of context or a session involved. A 'session' involves context. Think of what happens when you login to a computer. That starts a login session that has context: the computer now knows who you are and provides context by connecting you to your login directory and opening some work space which is used to remember which directory you're in, what commands you issued (so you can look at the history), etc. The session and its context persists until you log out. In what you're intending to do, a user will start a session by starting to use your program and that session will last until the user disconnects from the session. All the web server knows is that instead of finding a page on disk some place it passes your user's request to your program and sends its output, in the form of a web page, back to the user. It does this each time it receives a request from the user because all the user's requests contain the same URL - that of your program. The server does this without knowing there is such a thing as a session or that there is any context belonging to the user. The upshot is that your program has to keep track of all the active sessions and maintain context for each active session. It also needs a way to recognise and get rid of dead sessions because sessions don't always end cleanly: the line may go down or the user may forget he was using your program and turn his PC off. For instance, if the session context has a timestamp, you might delete it after, say, 20 hours of inactivity, or when the user logs on again. If the data is sensitive, you might also force a new logon after 10 minutes of inactivity. The database is as good a place as any for keeping session and context data - if its well structured the context may well form a single (large) row on one table, but you do need a unique key for it. That could even be the login name provided you're able to include it in every page you send to the user and can guarantee that the browser will send it back as part of the next request. A hidden field on the page will do this automatically. The basic program cycle will be: - receive a request - read the context for the session - use data in the request to carry out the requested action - write the updated context back to the database - create the output page and send it to the user though of course you need additional dialogue to deal with both valid and invalid logons and logoffs. > I don't really get how multiple users work in terms of pretty much > everything else, like if the Python code is running on the server, > then... well, I just don't know. > Hopefully the above made it a bit clearer. > Maybe I should try to get it running > for multiple discrete users first, and then think about simultaneous > users, or is that a bad way to go about things? Or maybe it will start > to make more sense when I get into building the interface? Any > info/suggestions are very welcome. > For bare desktop development I would split the program into three parts: 1) the program itself, written to run a single transaction each time its called. Inputs would be the bits of the users message it needs to act on and the current session context record. 2) a testing harness that accepts user input from the console, sends output back to the console and maintains a single session context record in memory: IOW it runs your program in single user mode. 3)the web server interface which retrieves the session context record, passes it and the input to your program and, after that has run, saves the session context record and passes the output to the web server for delivery to the user. This way both 2 and 3 can be developed against a really simple 'do almost nothing' version of 1 while that in turn can be developed and tested on your desktop using 2 and later be dropped into the web server with 3 as its interface. I have an in-house copy of Apache that I'd use to develop your type of program. Its used for all my website development so that nothing gets loaded onto my public sites until its been properly checked out here. You can do the same if you can find and install a really simple web server that would run on your PC together with a local copy of MySQL - of course! Given this setup you can use your usual web browser to talk to the local web server. If you can run all that you won't need 2 because you can have your simple web server and program running in a console window on your desktop PC while you hammer it from your web browser. -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From navasia at gmail.com Sun Nov 21 21:35:57 2010 From: navasia at gmail.com (navasia at gmail.com) Date: Sun, 21 Nov 2010 18:35:57 -0800 (PST) Subject: How to open html page in python resource file? ActiveX and Java script addEventListener? Options Message-ID: <615b0ae8-3350-4940-a79d-a3c5ff388362@k5g2000vbn.googlegroups.com> Hi friends, I have an interesting question. Is it possible to open HTML page from python resources (Sorry, I don't know how to use the resources) like we can open using Win32 from .rc files. Can that page contain references to scrips in the resource file? Another question is reagrding ActiveX on win32. ActiveX usually calls Java Script function to notify. In webpage we can add it using document.addeventlistener but those are not available using CallFunction method of ActiveX. But if we decided to use it directly (without web browser) then how can we register Listeners? There must be some way to specify the listeners. Thanks in Advance. From maxim.mercury at gmail.com Sun Nov 21 22:12:43 2010 From: maxim.mercury at gmail.com (Maxim Mercury) Date: Sun, 21 Nov 2010 19:12:43 -0800 (PST) Subject: strings getting unnecessarily cut in lstrip Message-ID: I was using the lstrip to trim the left occurance of a string, and it didnt seem to work for some cases. but when i investigated there does seem to be an issue with some combination of strings here is one case p1 = "abcd" p2 = 'def' # $abc sym = '_' str1 = p1 + sym + p2 str1 = str1.lstrip(p1+sym) print str1 # this prints ef instead of def can someone explain why this is happening ? From steve at holdenweb.com Sun Nov 21 22:26:49 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 21 Nov 2010 22:26:49 -0500 Subject: strings getting unnecessarily cut in lstrip In-Reply-To: References: Message-ID: On 11/21/2010 10:12 PM, Maxim Mercury wrote: > I was using the lstrip to trim the left occurance of a string, and it > didnt seem to work for some cases. but when i investigated there does > seem to be an issue with some combination of strings > here is one case > p1 = "abcd" > p2 = 'def' # $abc > sym = '_' > str1 = p1 + sym + p2 > str1 = str1.lstrip(p1+sym) > print str1 # this prints ef instead of > def > > can someone explain why this is happening ? It's happening because the argument specifies a set of characters, not a string. So the "d" of "def" is removed because there's a "d" in "abcd_". If you want to remove a string, try testing is with its .startswith() method and them removing the right number of characters. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From timr at probo.com Sun Nov 21 23:25:52 2010 From: timr at probo.com (Tim Roberts) Date: Sun, 21 Nov 2010 20:25:52 -0800 Subject: CGI FieldStorage instances? References: <1ec25d72-a99e-4fd9-9d50-1ac8c65812e9@z19g2000yqb.googlegroups.com> Message-ID: <6trje65kt71v00339psntb6srgr5qtls5c@4ax.com> Gnarlodious wrote: > >I'm having a hard time understanding this, can someone explain? > >Running a CGI with query string: > >?action=Find&page=Data > >Script includes these lines: > >form=cgi.FieldStorage(keep_blank_values=1) >print("Content-type:text/html\n\n") >print(cgi.print_form(form)) > >Output: > >Form Contents: > >action: >MiniFieldStorage('action', 'Find') >page: >MiniFieldStorage('page', 'Data') > >It looks like every variable in the query string instantiates a >MiniFieldStorage with that value, is that the case? Yes, unless it's a "file" type, then it is a full FieldStorage. >And if so, what >sort of cool tricks could I do with that feature? Because so far I am >doing CGI and it is a big old mess. Intercepting every variable is >complicated and confusing. Is there an easier way? Have you looked at the source code? That's the beauty of Python. It's all exposed for you. MiniFieldStorage has a .name attribute and a .value attribute. So, for example: print form['action'].value print form['page'].value If you're not sure whether the value will be specified: if 'action' in form: action = form['action'].value -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From es at ertes.de Sun Nov 21 23:38:53 2010 From: es at ertes.de (Ertugrul =?UTF-8?B?U8O2eWxlbWV6?=) Date: Mon, 22 Nov 2010 05:38:53 +0100 Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014020136.6e85d70b@tritium.streitmacht.eu> <20101014052650.510e8833@tritium.streitmacht.eu> Message-ID: <20101122053853.6ec5be33@tritium.streitmacht.eu> "Jon Harrop" wrote: > "Ertugrul S?ylemez" wrote in message > news:20101014052650.510e8833 at tritium.streitmacht.eu... > > > That's nonsense. > > Actually namekuseijin is right. You really need to persevere and > familiarize yourself with some of the other languages out > there. Haskell is many things but simple is not one of them. If > Haskell were half of the things you think it is, it would have more > credible success stories. Jon, I don't care about your opinion, because it's biased. If you were to advocate Haskell in any way, you would lose money. So you must fight it where possible. This makes all your postings about Haskell (and many other languages) meaningless and reading them a waste of time. Haskell is a simple language with a comparably small specification. It's not as simple as Common Lisp, but it's simple. Note that simple doesn't mean easy. Haskell is certainly more difficult to learn than other languages, which explains the low number of success stories. On the other hand, I'm doing rapid web development in it. After all there aren't many CL success stories either, but Paul Graham's story [1] speaks for itself. [1] http://www.paulgraham.com/avg.html Greets, Ertugrul -- nightmare = unsafePerformIO (getWrongWife >>= sex) http://ertes.de/ From steve at holdenweb.com Sun Nov 21 23:57:21 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 21 Nov 2010 23:57:21 -0500 Subject: Scheme as a virtual machine? In-Reply-To: <20101122053853.6ec5be33@tritium.streitmacht.eu> References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014020136.6e85d70b@tritium.streitmacht.eu> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> Message-ID: On 11/21/2010 11:38 PM, Ertugrul S?ylemez wrote: > "Jon Harrop" wrote: > >> "Ertugrul S?ylemez" wrote in message >> news:20101014052650.510e8833 at tritium.streitmacht.eu... >> >>> That's nonsense. >> >> Actually namekuseijin is right. You really need to persevere and >> familiarize yourself with some of the other languages out >> there. Haskell is many things but simple is not one of them. If >> Haskell were half of the things you think it is, it would have more >> credible success stories. > > Jon, I don't care about your opinion, because it's biased. If you were > to advocate Haskell in any way, you would lose money. So you must fight > it where possible. This makes all your postings about Haskell (and many > other languages) meaningless and reading them a waste of time. > > Haskell is a simple language with a comparably small specification. > It's not as simple as Common Lisp, but it's simple. Note that simple > doesn't mean easy. Haskell is certainly more difficult to learn than > other languages, which explains the low number of success stories. On > the other hand, I'm doing rapid web development in it. > > After all there aren't many CL success stories either, but Paul Graham's > story [1] speaks for itself. > > [1] http://www.paulgraham.com/avg.html > Perhaps we could take this thread to alt.small.minded.bickering now? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at REMOVE-THIS-cybersource.com.au Mon Nov 22 01:26:34 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 22 Nov 2010 06:26:34 GMT Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014020136.6e85d70b@tritium.streitmacht.eu> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> Message-ID: <4cea0d1a$0$29991$c3e8da3$5496439d@news.astraweb.com> On Sun, 21 Nov 2010 23:57:21 -0500, Steve Holden wrote: > Perhaps we could take this thread to alt.small.minded.bickering now? Alas, my ISP doesn't carry that newsgroup. Where else can I get my mindless off-topic bitching if not for cross-posts from comp.lang.scheme and comp.lang.functional? *wink* -- Steven From enleverLesX_XXmcX at XmclavXeauX.com.invalid Mon Nov 22 01:27:04 2010 From: enleverLesX_XXmcX at XmclavXeauX.com.invalid (Michel Claveau - MVP) Date: Mon, 22 Nov 2010 07:27:04 +0100 Subject: How to open html page in python resource file? ActiveX and Javascript addEventListener? Options References: <615b0ae8-3350-4940-a79d-a3c5ff388362@k5g2000vbn.googlegroups.com> Message-ID: <4cea0d39$0$7719$ba4acef3@reader.news.orange.fr> Hello! You will find (positive) answers in PyWin32 and his examples. @-salutations -- Michel Claveau From torriem at gmail.com Mon Nov 22 01:57:15 2010 From: torriem at gmail.com (Michael Torrie) Date: Sun, 21 Nov 2010 23:57:15 -0700 Subject: is list comprehension necessary? In-Reply-To: References: <2e4594a9-d39c-4bad-bf45-6204350f249d@k22g2000yqh.googlegroups.com> Message-ID: <4CEA144B.8070604@gmail.com> On 10/27/2010 05:37 AM, Roy Smith wrote: > I agree. I resisted LCs when they first came out, passing them off as > unnecessary, confusing, etc. Eventually, I came to be comfortable with > them and use them often. I do use LCs fairly often, but only then a for loop would be ugly or inefficient. In many cases, I find a normal for loop often is clearer. Basically I'm saying that you can over-use LCs. And sometimes LCs only serve to make code harder to read. Just because you can use an LC doesn't always mean you should. But of course that's just my opinion. From brian.mingus at Colorado.EDU Mon Nov 22 02:19:17 2010 From: brian.mingus at Colorado.EDU (Brian J Mingus) Date: Mon, 22 Nov 2010 00:19:17 -0700 Subject: is list comprehension necessary? In-Reply-To: References: Message-ID: On Tue, Oct 26, 2010 at 3:31 AM, Xah Lee wrote: > ... No, list comprehensions are not "nececessary", just like the plethora of expletives in the majority of your OPs on this list are not necessary. The question is are they useful, and the answer is the case of list comprehensions is obviously yes, whereas in the case of the expletives you love to spew everywhere the answer is no. Framing, young grasshopper. Framing. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dimos_anastasiou at yahoo.com Mon Nov 22 03:20:34 2010 From: dimos_anastasiou at yahoo.com (Dimos) Date: Mon, 22 Nov 2010 00:20:34 -0800 (PST) Subject: Weibull distr. random number generation In-Reply-To: <71b9f476-087f-455e-a587-69cd812feea8@j9g2000vbl.googlegroups.com> Message-ID: <504343.18748.qm@web111717.mail.gq1.yahoo.com> Hello Mark, Exactly, thanks very much! Dimos --- On Sat, 11/20/10, Mark Dickinson wrote: > From: Mark Dickinson > Subject: Re: Weibull distr. random number generation > To: python-list at python.org > Date: Saturday, November 20, 2010, 7:09 PM > On Nov 19, 3:21?pm, Dimos > wrote: > > I would like to use the random module, and if I > understand well the Random class, to create ?1300 decimal > numbers in python, by providing the 2 Weibull parameters > (b,c). How this can be done??? > > > > import random > > print random > > random.weibullvariate(b,c) > > How can I set the population size n=1300 in decimals? > > random.weibullvariate(b, c) generates a single sample from > the > specified Weibull distribution.? If you want 1300 > samples, you'd use > this within a loop.? For example, here's code to put > 10 Weibull > variates with scale parameter 12345.0 and shape parameter > 6.0 into a > list: > > >>> import random > >>> samples = [] > >>> for i in xrange(10): > ...? > ???samples.append(random.weibullvariate(12345.0, > 6.0)) > ... > >>> print samples > [15553.186762792948, 14304.175032317309, > 9015.5053691933044, > 12585.469181732506, 9436.2677219460638, 13350.89758791281, > 5687.4330250037565, 12172.747202474553, > 9687.8685933610814, > 11699.040541029028] > > A more experienced Python programmer might use a list > comprehension to > achieve the same effect in a single line: > > >>> samples = [random.weibullvariate(12345.0, 6.0) > for _ in xrange(10)] > >>> print samples > [10355.396846416865, 14689.507803932587, > 11491.850991569485, > 14128.56397290655, 12592.739991974759, 9076.7752548878998, > 11868.012238422616, 12016.784656753523, > 14724.818462506191, > 13253.477389116439] > > Is this the sort of thing you were looking for? > > -- > Mark > -- > http://mail.python.org/mailman/listinfo/python-list > From matlab.dude at mbnet.fi Mon Nov 22 03:47:50 2010 From: matlab.dude at mbnet.fi (MATLABdude) Date: Mon, 22 Nov 2010 00:47:50 -0800 (PST) Subject: MATLAB to Python? References: <74f276c3-38a4-4df0-af39-7b1f2a81472e@c39g2000yqi.googlegroups.com> <878w0s2uwv.fsf@gmail.com> Message-ID: <525ad586-d4fe-484a-9f9e-74b0e0fd78d4@s4g2000yql.googlegroups.com> On Nov 17, 10:53?am, Arnaud Delobelle wrote: > I guess that the step is supposed to be h, so you should write: > ? ? xx = range(-kappa, kappa+1, h) This is what I have in the source code: ---8<---8<---8<---8<--- h = 0.105069988414 xx = range(-kappa, kappa+1, h) ---8<---8<---8<---8<--- This is what Python says: ValueError: range() step argument must not be zero Can step not be a float value? From clp2 at rebertia.com Mon Nov 22 04:05:21 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 22 Nov 2010 01:05:21 -0800 Subject: MATLAB to Python? In-Reply-To: <525ad586-d4fe-484a-9f9e-74b0e0fd78d4@s4g2000yql.googlegroups.com> References: <74f276c3-38a4-4df0-af39-7b1f2a81472e@c39g2000yqi.googlegroups.com> <878w0s2uwv.fsf@gmail.com> <525ad586-d4fe-484a-9f9e-74b0e0fd78d4@s4g2000yql.googlegroups.com> Message-ID: On Mon, Nov 22, 2010 at 12:47 AM, MATLABdude wrote: > On Nov 17, 10:53?am, Arnaud Delobelle wrote: >> I guess that the step is supposed to be h, so you should write: >> ? ? xx = range(-kappa, kappa+1, h) > > This is what I have in the source code: > ---8<---8<---8<---8<--- > h = ?0.105069988414 > xx = range(-kappa, kappa+1, h) > ---8<---8<---8<---8<--- > > This is what Python says: ValueError: range() step argument must not > be zero > > Can step not be a float value? Correct. Note the DeprecationWarning which is also shown: __main__:1: DeprecationWarning: integer argument expected, got float There are too many subtleties with floating-point, so range() doesn't handle it; that way, you deal with the subtleties yourself, explicitly. Cheers, Chris -- http://blog.rebertia.com From __peter__ at web.de Mon Nov 22 04:11:27 2010 From: __peter__ at web.de (Peter Otten) Date: Mon, 22 Nov 2010 10:11:27 +0100 Subject: MATLAB to Python? References: <74f276c3-38a4-4df0-af39-7b1f2a81472e@c39g2000yqi.googlegroups.com> <878w0s2uwv.fsf@gmail.com> <525ad586-d4fe-484a-9f9e-74b0e0fd78d4@s4g2000yql.googlegroups.com> Message-ID: MATLABdude wrote: > On Nov 17, 10:53 am, Arnaud Delobelle wrote: >> I guess that the step is supposed to be h, so you should write: >> xx = range(-kappa, kappa+1, h) > > This is what I have in the source code: > ---8<---8<---8<---8<--- > h = 0.105069988414 > xx = range(-kappa, kappa+1, h) > ---8<---8<---8<---8<--- > > This is what Python says: ValueError: range() step argument must not > be zero > > Can step not be a float value? Indeed. Older Pythons will warn you and then try to convert the arguments to integers >>> range(1.0) __main__:1: DeprecationWarning: integer argument expected, got float [0] and in 2.7 or 3.x you'll get a type error: >>> range(1.0) Traceback (most recent call last): File "", line 1, in TypeError: range() integer end argument expected, got float. Try numpy.arange() instead: >>> numpy.arange(0, 1, .1) array([ 0. , 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]) From korn at freisingnet.de Mon Nov 22 04:54:46 2010 From: korn at freisingnet.de (Johannes Korn) Date: Mon, 22 Nov 2010 10:54:46 +0100 Subject: Reading bz2 file into numpy array Message-ID: <4cea3de7$0$6769$9b4e6d93@newsspool3.arcor-online.net> Hi, is there a convenient way to read bz2 files into a numpy array? I tried: from bz2 import * from numpy import * fd = BZ2File(filename, 'rb') read_data = fromfile(fd, float32) but BZ2File doesn't seem to produce a transparent filehandle. Kind regards! Johannes From __peter__ at web.de Mon Nov 22 05:37:22 2010 From: __peter__ at web.de (Peter Otten) Date: Mon, 22 Nov 2010 11:37:22 +0100 Subject: Reading bz2 file into numpy array References: <4cea3de7$0$6769$9b4e6d93@newsspool3.arcor-online.net> Message-ID: Johannes Korn wrote: > I tried: > > from bz2 import * > from numpy import * > fd = BZ2File(filename, 'rb') > read_data = fromfile(fd, float32) > > but BZ2File doesn't seem to produce a transparent filehandle. > is there a convenient way to read bz2 files into a numpy array? Try import numpy import bz2 filename = ... f = bz2.BZ2File(filename) data = numpy.fromstring(f.read(), numpy.float32) print data From jeanmichel at sequans.com Mon Nov 22 06:14:27 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 22 Nov 2010 12:14:27 +0100 Subject: building a web interface In-Reply-To: References: Message-ID: <4CEA5093.2070604@sequans.com> Shel wrote: > Hello, > > I am pretty new to all this. I have some coding experience, and am > currently most comfortable with Python. I also have database design > experience with MS Access, and have just created my first mySQL db. > > So right now I have a mySQL db structure and some Python code. My end > goal is to create a browser-based interactive fiction/game thing. My > code is currently just using dummy data rather than pulling in data > from the db, but I think/hope it won't be too big of a deal to > interact with the db through Python (famous last words...). > > My main problem right now is how to do the web interface. I don't know > much about web architecture, unfortunately. I think I need a CGI > script? > > What I would really like is to find a GUI tool to design the interface > that would have customizable templates or drag-and-drop elements or > something, so I wouldn't have to code much by hand. Something easy, if > such a tool exists. > > Also would prefer something that I would be able to install/use > without having much access to the server where the site will be hosted > (on a university server that I don't have control over). I don't fully > understand how a lot of the tools I have been looking at work, but it > seems like they're often things where you'd have to get an > administrator to do stuff on the server (is that right?), which I > would prefer to avoid. > > It looks like Django has some sort of standalone implementation, but > I'm not clear on how that would work or how much of a learning curve > there would be for using it. > > If anyone has any thoughts or suggestions, I would really appreciate > it. > > Hope my questions make sense. I don't really know what I'm doing, so > could be they're a bit silly. I apologize if that's the case, and > please let me know if you need any additional informmation. > > Thanks, > Shel > Django is quite popular, they claim to be easy to learn/use. That's for the web framework. You could use pyjamas for the web interface, looks like it works well with django. Hmm, writing python code only, sounds like a dream come true :D Note that I never used one of these, it just happened I had to look for possible solutions for a web application. JM From andreas.loescher at s2005.tu-chemnitz.de Mon Nov 22 06:21:42 2010 From: andreas.loescher at s2005.tu-chemnitz.de (Andreas =?ISO-8859-1?Q?L=F6scher?=) Date: Mon, 22 Nov 2010 12:21:42 +0100 Subject: Some syntactic sugar proposals In-Reply-To: Message-ID: <1290424902.6446.5.camel@laptop> > if x in range(a, b): #wrong! > it feels so natural to check it that way, but we have to write > if a <= x <= b > I understand that it's not a big deal, but it would be awesome to have > some optimisations - it's clearly possible to detect things like that > "wrong" one and fix it in a bytecode. You can implement it yourself: class between(object): def __init__(self, a,b): super(crang, self).__init__() self.a=a self.b=b def __contains__(self, value): return self.a <= value <= self.b >>> 12.45 in between(-100,100) true But do you need a < x < b a <= x < b a <= x <= b or a < x <= b ? Sure, you could set a new parameter for this, but the normal way is not broken at all. Best From bgraghu1987 at gmail.com Mon Nov 22 06:24:33 2010 From: bgraghu1987 at gmail.com (raghu bg) Date: Mon, 22 Nov 2010 16:54:33 +0530 Subject: Accepting a SAML 2 Assertion Message-ID: Hello, I am working on providing a SSO solution to a customer who acts as an identity provider. He already has IDP on his side to generate SAML 2 assertions with user first name , last name and time stamp as parameters. Our task is to accept this assertion which is signed, decrypt it and send it to the authenticator we already have. The authenticator validates the info and gives access to our application which is written using Python. Here we act as the *service provider.* I am new to SAML and have no idea how to integrate SAML to our current Python application. Can you help me on how to accept these assertion requests from the Idp and decrypt it at Service Provider end using Python. Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From jakub.vysoky at gmail.com Mon Nov 22 06:24:56 2010 From: jakub.vysoky at gmail.com (kvbik) Date: Mon, 22 Nov 2010 03:24:56 -0800 (PST) Subject: multiple times subprocess fails on windows References: Message-ID: <185efeee-71c3-4772-aa78-834208aedf59@k5g2000vbn.googlegroups.com> To be more specific, I have something like this in rvirtualenv itself (that's the pokus.py file): import os os.system("echo 128") I generate a batch file like this (that's the pokus.bat file): @echo off pokus.py And after that, I run the pokus.bat file from a test (that's the run.py file): from subprocess import Popen, PIPE p = Popen('pokus.bat', stdout=PIPE, stderr=PIPE, shell=True) stdout, stderr = p.communicate() print stdout.strip() And the problem is, that I don't receive the output of the os.system to the PIPE. Probable there is something different on windows stdout redirection, because similar stuff works on linux.. Thanks, Jakub. On Nov 21, 8:39?pm, kvbik wrote: > Hello, > > in a test suite in my project (called rvirtualenv [1]) I discovered a > strange behaviour when calling from python a batch file which calles > another python and this calles a shell command. > > [1]http://github.com/kvbik/rvirtualenv > > I know it sounds pretty strange, but I do this only because I am > testing such specific tool (that has similar functionality like > original virtualenv and there are things like activate.bat commands). > > I've uploaded some code snippet here: > > https://gist.github.com/709004/6ccc44d6aed5fe694bb2adbef2400bbea92998a1 > > If anyone could explain me this behaviour I would be more than happy, > because right now it is the only failing test in my project ;). > > Thanks in advance, Jakub.. From ulrich.eckhardt at dominolaser.com Mon Nov 22 06:38:10 2010 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Mon, 22 Nov 2010 12:38:10 +0100 Subject: unittests with different parameters Message-ID: Hi! I'm writing tests and I'm wondering how to achieve a few things most elegantly with Python's unittest module. Let's say I have two flags invert X and invert Y. Now, for testing these, I would write one test for each combination. What I have in the test case is something like this: def test_invert_flags(self): """test flags to invert coordinates""" tests = [((10, 20), INVERT_NONE, (10, 20)), ((10, 20), INVERT_X, (-10, 20)), ((10, 20), INVERT_Y, (10, -20))] for input, flags, expected in tests: res = do_invert(input, flags) self.assertEqual(res, expected, "%s caused wrong results" % (flags,)) So, what I do that I test the function 'do_invert' for different input combinations and verify the result. The ugly thing is that this will abort the whole test if one of the tests in the loop fails. So, my question is how do I avoid this? I know that I could write a common test function instead: def _test_invert_flags(self, input, flags, expected): res = do_invert(input, flags) self.assertEqual(res, expected) def test_invert_flags_non(self): """test not inverting coordinates""" self._test_invert_flags((10, 20), INVERT_NONE, (10, 20)) def test_invert_flags_x(self): """test inverting X coordinates""" self._test_invert_flags((10, 20), INVERT_X, (-10, 20)) def test_invert_flags_y(self): """test inverting Y coordinates""" self._test_invert_flags((10, 20), INVERT_Y, (10, -20)) What I don't like here is that this is unnecessarily verbose and that it basically repeats information. Also, I'd rather construct the error message from the data instead of maintaining it in different places, because manually keeping those in sync is another, errorprone burden. Any suggestions? Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From markhaniford at gmail.com Mon Nov 22 08:12:27 2010 From: markhaniford at gmail.com (MarkHaniford@gmail.com) Date: Mon, 22 Nov 2010 05:12:27 -0800 (PST) Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014020136.6e85d70b@tritium.streitmacht.eu> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> Message-ID: <08823dd4-588a-4729-a660-711e266c96b0@y23g2000yqd.googlegroups.com> On Nov 21, 10:38?pm, Ertugrul S?ylemez wrote: > "Jon Harrop" wrote: > > "Ertugrul S?ylemez" wrote in message > >news:20101014052650.510e8833 at tritium.streitmacht.eu... > > > > That's nonsense. > > > Actually namekuseijin is right. You really need to persevere and > > familiarize yourself with some of the other languages out > > there. Haskell is many things but simple is not one of them. If > > Haskell were half of the things you think it is, it would have more > > credible success stories. > > Jon, I don't care about your opinion, because it's biased. All opinions are biased. From chardster at gmail.com Mon Nov 22 08:43:35 2010 From: chardster at gmail.com (Richard Thomas) Date: Mon, 22 Nov 2010 05:43:35 -0800 (PST) Subject: unittests with different parameters References: Message-ID: On Nov 22, 11:38?am, Ulrich Eckhardt wrote: > Hi! > > I'm writing tests and I'm wondering how to achieve a few things most > elegantly with Python's unittest module. > > Let's say I have two flags invert X and invert Y. Now, for testing these, I > would write one test for each combination. What I have in the test case is > something like this: > > ? def test_invert_flags(self): > ? ? ? """test flags to invert coordinates""" > ? ? ? tests = [((10, 20), INVERT_NONE, (10, 20)), > ? ? ? ? ? ? ? ?((10, 20), INVERT_X, (-10, 20)), > ? ? ? ? ? ? ? ?((10, 20), INVERT_Y, (10, -20))] > ? ? ? for input, flags, expected in tests: > ? ? ? ? ? res = do_invert(input, flags) > ? ? ? ? ? self.assertEqual(res, expected, > ? ? ? ? ? ? ? ? ? ? ? ? ? ?"%s caused wrong results" % (flags,)) > > So, what I do that I test the function 'do_invert' for different input > combinations and verify the result. The ugly thing is that this will abort > the whole test if one of the tests in the loop fails. So, my question is > how do I avoid this? > > I know that I could write a common test function instead: > > ? def _test_invert_flags(self, input, flags, expected): > ? ? ? res = do_invert(input, flags) > ? ? ? self.assertEqual(res, expected) > > ? def test_invert_flags_non(self): > ? ? ? """test not inverting coordinates""" > ? ? ? self._test_invert_flags((10, 20), INVERT_NONE, (10, 20)) > > ? def test_invert_flags_x(self): > ? ? ? """test inverting X coordinates""" > ? ? ? self._test_invert_flags((10, 20), INVERT_X, (-10, 20)) > > ? def test_invert_flags_y(self): > ? ? ? """test inverting Y coordinates""" > ? ? ? self._test_invert_flags((10, 20), INVERT_Y, (10, -20)) > > What I don't like here is that this is unnecessarily verbose and that it > basically repeats information. Also, I'd rather construct the error message > from the data instead of maintaining it in different places, because > manually keeping those in sync is another, errorprone burden. > > Any suggestions? > > Uli > > -- > Domino Laser GmbH > Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 You could have a parameter to the test method and some custom TestLoader that knows what to do with it. See http://docs.python.org/library/unittest.html. I would venture that unit tests are verbose by their very nature; they are 100% redundant. The usual argument against unnecessary redundancy, that of ease of maintenance, really doesn't apply to unit tests. Anyway, good luck with your efforts. Chard. From roy at panix.com Mon Nov 22 09:11:12 2010 From: roy at panix.com (Roy Smith) Date: Mon, 22 Nov 2010 09:11:12 -0500 Subject: unittests with different parameters References: Message-ID: In article , Ulrich Eckhardt wrote: > def test_invert_flags(self): > """test flags to invert coordinates""" > tests = [((10, 20), INVERT_NONE, (10, 20)), > ((10, 20), INVERT_X, (-10, 20)), > ((10, 20), INVERT_Y, (10, -20))] > for input, flags, expected in tests: > res = do_invert(input, flags) > self.assertEqual(res, expected, > "%s caused wrong results" % (flags,)) > > So, what I do that I test the function 'do_invert' for different input > combinations and verify the result. The ugly thing is that this will abort > the whole test if one of the tests in the loop fails. So, my question is > how do I avoid this? Writing one test method per parameter combination, as you suggested, is a reasonable approach, especially if the number of combinations is reasonably small. Another might be to make your loop: failCount = 0 for input, flags, expected in tests: res = do_invert(input, flags) if res != expected: print "%s caused wrong results" % (flags,) failCount += 1 self.assertEqual(failCount, 0, "%d of them failed" % failCount) Yet another possibility is to leave it the way you originally wrote it and not worry about the fact that the loop aborts on the first failure. Let it fail, fix it, then re-run the test to find the next failure. Perhaps not as efficient as finding them all at once, but you're going to fix them one at a time anyway, so what does it matter? It may also turn out that all the failures are due to a single bug, so fixing one fixes them all. From anurag.chourasia at gmail.com Mon Nov 22 09:25:30 2010 From: anurag.chourasia at gmail.com (Anurag Chourasia) Date: Mon, 22 Nov 2010 19:55:30 +0530 Subject: Error Starting Python(Django) App using Apache+Mod_Wsgi Message-ID: All, I have a problem in starting my Python(Django) App using Apache and Mod_Wsgi I am using Django 1.2.3 and Python 2.6.6 running on Apache 2.2.17 with Mod_Wsgi 3.3 When I try to access the app from Web Browser, I am getting these errors. [Mon Nov 22 09:45:25 2010] [notice] Apache/2.2.17 (Unix) mod_wsgi/3.3 Python/2.6.6 configured -- resuming normal operations [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] mod_wsgi (pid=1273874): Target WSGI script '/u01/home/apli/wm/app/gdd/pyserver/ apache/django.wsgi' cannot be loaded as Python module. [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] mod_wsgi (pid=1273874): Exception occurred processing WSGI script '/u01/home/ apli/wm/app/gdd/pyserver/apache/django.wsgi'. [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] Traceback (most recent call last): [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] File "/u01/ home/apli/wm/app/gdd/pyserver/apache/django.wsgi", line 19, in [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] import django.core.handlers.wsgi [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] File "/usr/ local/lib/python2.6/site-packages/django/core/handlers/wsgi.py", line 1, in [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] from threading import Lock [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] File "/usr/ local/lib/python2.6/threading.py", line 13, in [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] from functools import wraps [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] File "/usr/ local/lib/python2.6/functools.py", line 10, in [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] from _functools import partial, reduce [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] ImportError: rtld: 0712-001 Symbol PyArg_UnpackTuple was referenced [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] from module /usr/local/lib/python2.6/lib-dynload/_functools.so(), but a runtime definition [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] of the symbol was not found. [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] rtld: 0712-001 Symbol PyCallable_Check was referenced [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] from module /usr/local/lib/python2.6/lib-dynload/_functools.so(), but a runtime definition [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] of the symbol was not found. [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] rtld: 0712-001 Symbol PyDict_Copy was referenced [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] from module /usr/local/lib/python2.6/lib-dynload/_functools.so(), but a runtime definition [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] of the symbol was not found. [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] rtld: 0712-001 Symbol PyDict_Merge was referenced [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] from module /usr/local/lib/python2.6/lib-dynload/_functools.so(), but a runtime definition [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] of the symbol was not found. [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] rtld: 0712-001 Symbol PyDict_New was referenced [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] from module /usr/local/lib/python2.6/lib-dynload/_functools.so(), but a runtime definition [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] of the symbol was not found. [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] rtld: 0712-001 Symbol PyErr_Occurred was referenced [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] from module /usr/local/lib/python2.6/lib-dynload/_functools.so(), but a runtime definition [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] of the symbol was not found. [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] rtld: 0712-001 Symbol PyErr_SetString was referenced [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] from module /usr/local/lib/python2.6/lib-dynload/_functools.so(), but a runtime definition [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] of the symbol was not found. [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] \t0509-021 Additional errors occurred but are not reported. I assume that those missing runtime definitions are supposed to be in the Python executable. Doing an nm on the first missing symbol reveals that it does exist. root [zibal]% nm /usr/local/bin/python | grep -i PyArg_UnpackTuple .PyArg_UnpackTuple T 268683204 524 PyArg_UnpackTuple D 537073500 PyArg_UnpackTuple d 537073500 12 PyArg_UnpackTuple:F-1 - 224 Please guide. Regards, Guddu -------------- next part -------------- An HTML attachment was scrubbed... URL: From ulrich.eckhardt at dominolaser.com Mon Nov 22 09:30:46 2010 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Mon, 22 Nov 2010 15:30:46 +0100 Subject: unittests with different parameters References: Message-ID: Roy Smith wrote: > Writing one test method per parameter combination, as you suggested, is > a reasonable approach, especially if the number of combinations is > reasonably small. The number of parameters and thus combinations are unfortunately rather large. Also, sometimes that data is not static but rather computed from a loop instead. There are a few optimised computations, where I compute the expected result with the slow but simple version, in those cases I want to check a whole range of inputs using a loop. I'm wondering, classes aren't as static as I'm still used to from C++, so creating the test functions dynamically with a loop outside the class declaration should be another possibility... > Yet another possibility is to leave it the way you originally wrote it > and not worry about the fact that the loop aborts on the first failure. > Let it fail, fix it, then re-run the test to find the next failure. > Perhaps not as efficient as finding them all at once, but you're going > to fix them one at a time anyway, so what does it matter? Imagine all tests that use INVERT_X fail, all others pass. What would your educated guess be where the code is wrong? ;) Thanks Roy! Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From ulrich.eckhardt at dominolaser.com Mon Nov 22 09:32:13 2010 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Mon, 22 Nov 2010 15:32:13 +0100 Subject: unittests with different parameters References: Message-ID: <4gbqr7-5rj.ln1@satorlaser.homedns.org> Richard Thomas wrote: [batch-programming different unit tests] > You could have a parameter to the test method and some custom > TestLoader that knows what to do with it. Interesting, thanks for this suggestion, I'll look into it! Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From raffaelcavallaro at pas.despam.s.il.vous.plait.mac.com Mon Nov 22 09:45:23 2010 From: raffaelcavallaro at pas.despam.s.il.vous.plait.mac.com (Raffael Cavallaro) Date: Mon, 22 Nov 2010 09:45:23 -0500 Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014020136.6e85d70b@tritium.streitmacht.eu> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> <08823dd4-588a-4729-a660-711e266c96b0@y23g2000yqd.googlegroups.com> Message-ID: On 2010-11-22 08:12:27 -0500, MarkHaniford at gmail.com said: > All opinions are biased. All opinions show some bias. Not all opinions represent what is usually called a "conflict of interest." Since JH makes his living selling tools and training for certain languages, he has a severe conflict of interest wrt asessing the value of various other languages. If these other languages are just as good or better than those he makes his living from, it would be very damaging to his livlihood for him to admit this fact. As a result, he is a completely unreliable source on the question. This is why judges must recuse themselves from both civil and criminal trials if they have some significant conflict of interest. The law recognizes that we cannot expect a fair judgement from someone who stands to profit significantly if the judgement goes one way or the other. Similarly, we cannot expect a fair judgement on the relative value of various language tools from a person whose livlihood depends on the audience choosing only those certain language tools that he sells services and training for. warmest regards, Ralph -- Raffael Cavallaro From roy at panix.com Mon Nov 22 09:47:44 2010 From: roy at panix.com (Roy Smith) Date: Mon, 22 Nov 2010 09:47:44 -0500 Subject: unittests with different parameters References: Message-ID: In article , Ulrich Eckhardt wrote: > > Yet another possibility is to leave it the way you originally wrote it > > and not worry about the fact that the loop aborts on the first failure. > > Let it fail, fix it, then re-run the test to find the next failure. > > Perhaps not as efficient as finding them all at once, but you're going > > to fix them one at a time anyway, so what does it matter? > > Imagine all tests that use INVERT_X fail, all others pass. What would your > educated guess be where the code is wrong? ;) Well, let me leave you with one last thought. There's really two kinds of tests -- acceptance tests, and diagnostic tests. I tend to write acceptance tests first. The idea is that if all the tests pass, I know my code works. When some test fails, that's when I start digging deeper and writing diagnostic tests, to help me figure out what went wrong. The worst test is a test which is never written because it's too hard to write. If it's easy to write a bunch of tests which verify correct operation but don't give a lot of clues about what went wrong, it might be worth doing that first and seeing what happens. If some of the tests fail, then invest the time to write more detailed tests which give you more information about each failure. From usenot at geekmail.INVALID Mon Nov 22 10:25:14 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Mon, 22 Nov 2010 10:25:14 -0500 Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014020136.6e85d70b@tritium.streitmacht.eu> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> <4cea0d1a$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20101122102514.59ec96d7@geekmail.INVALID> On 22 Nov 2010 06:26:34 GMT Steven D'Aprano wrote: > On Sun, 21 Nov 2010 23:57:21 -0500, Steve Holden wrote: > > > Perhaps we could take this thread to alt.small.minded.bickering now? > > Alas, my ISP doesn't carry that newsgroup. Where else can I get my > mindless off-topic bitching if not for cross-posts from > comp.lang.scheme and comp.lang.functional? > > *wink* > alt.off-topic *wink* /W -- To reach me via email, replace INVALID with the country code of my home country. But if you spam me, I'll be one sour Kraut. From tosters at gmail.com Mon Nov 22 10:46:47 2010 From: tosters at gmail.com (Roman Dolgiy) Date: Mon, 22 Nov 2010 07:46:47 -0800 (PST) Subject: Python recursively __getattribute__ Message-ID: Hello, I need to implement such behavior: obj.attr1.attr2.attr3 --> obj.attr1__attr2__attr3 It looks like I have to override obj's class __getattribute__ and also use python descriptors somehow. Any help will be much appreciated. http://stackoverflow.com/questions/4247036/python-recursively-getattribute From howard at brazee.net Mon Nov 22 10:57:41 2010 From: howard at brazee.net (Howard Brazee) Date: Mon, 22 Nov 2010 08:57:41 -0700 Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014020136.6e85d70b@tritium.streitmacht.eu> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> Message-ID: On Mon, 22 Nov 2010 05:38:53 +0100, Ertugrul S?ylemez wrote: >Haskell is a simple language with a comparably small specification. >It's not as simple as Common Lisp, but it's simple. Note that simple >doesn't mean easy. Haskell is certainly more difficult to learn than >other languages, which explains the low number of success stories. On >the other hand, I'm doing rapid web development in it. I wonder how much that difficulty is innate, and how much is due to learning other languages first. I'm an old time CoBOL programmer, and know of quite a few people who tried to learn OO-CoBOL without much luck. The way to learn it was to forget it - learn OO with some other language, then come back to it later. We had to divorce ourselves from the old paradigm first. -- "In no part of the constitution is more wisdom to be found, than in the clause which confides the question of war or peace to the legislature, and not to the executive department." - James Madison From usenot at geekmail.INVALID Mon Nov 22 11:04:41 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Mon, 22 Nov 2010 11:04:41 -0500 Subject: Python recursively __getattribute__ References: Message-ID: <20101122110441.267eb032@geekmail.INVALID> On Mon, 22 Nov 2010 07:46:47 -0800 (PST) Roman Dolgiy wrote: > Hello, > > I need to implement such behavior: > > obj.attr1.attr2.attr3 --> obj.attr1__attr2__attr3 > It looks like I have to override obj's class __getattribute__ and also > use python descriptors somehow. > > Any help will be much appreciated. > http://stackoverflow.com/questions/4247036/python-recursively-getattribute Why? No, really: Why? In that link you say that you need to do this to support legacy code. I still don't see how this would be necessary. If you need to support legacy code, doesn't that mean that the solution you're asking for already exists? I really think you should go into detail about why you need this. I'm certain that there's a better solution to your problem. ("Better" being one that is reasonably easy to implement and maintain.) /W -- To reach me via email, replace INVALID with the country code of my home country. But if you spam me, I'll be one sour Kraut. From toby at telegraphics.com.au Mon Nov 22 11:14:40 2010 From: toby at telegraphics.com.au (toby) Date: Mon, 22 Nov 2010 08:14:40 -0800 (PST) Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014020136.6e85d70b@tritium.streitmacht.eu> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> Message-ID: On Nov 22, 10:57?am, Howard Brazee wrote: > On Mon, 22 Nov 2010 05:38:53 +0100, Ertugrul S ylemez > wrote: > > >Haskell is a simple language with a comparably small specification. > >It's not as simple as Common Lisp, but it's simple. ?Note that simple > >doesn't mean easy. ?Haskell is certainly more difficult to learn than > >other languages, which explains the low number of success stories. ?On > >the other hand, I'm doing rapid web development in it. > > I wonder how much that difficulty is innate, and how much is due to > learning other languages first. This is a good (if familiar) observation. Teaching children (or young people with little exposure to computers) how to program in various paradigms could produce interesting primary evidence. Pity that this isn't examined widely and systematically. We could learn something about how to teach programming and design languages this way, don't you agree? The OLPC might do some interesting things in this area but it is still one set of tools. More interesting might be to compare outcomes across a range of different tools, paradigms, syntaxes, and teaching strategies. > I'm an old time CoBOL programmer, and know of quite a few people who > tried to learn OO-CoBOL without much luck. ? The way to learn it was > to forget it - learn OO with some other language, then come back to it > later. ? ?We had to divorce ourselves from the old paradigm first. ? ? > > -- > "In no part of the constitution is more wisdom to be found, > than in the clause which confides the question of war or peace > to the legislature, and not to the executive department." > > - James Madison From sunwei415 at gmail.com Mon Nov 22 11:23:05 2010 From: sunwei415 at gmail.com (Wei Sun) Date: Mon, 22 Nov 2010 16:23:05 GMT Subject: print line number and source filename References: Message-ID: <20101122112250usenet@eggheadcafe.com> Here is what you want for printing python source filename: print __file__ > On Tuesday, June 22, 2010 12:44 PM Peng Yu wrote: > I want to print filename and line number for debugging purpose. So far > I only find how to print the line number but not how to print > filename. > > import inspect > print inspect.currentframe().f_lineno > > I found inspect.getsourcefile(), but I have to supply a class name to > it. I have searched online, but I do not find how to print the source > filename. Would you please let me know? > > Also, always importing the inspect module and getting the frame and > accessing the lineno from the frame is not very convenient to type. Is > there a shorter way to access the line number (for example, in C++ and > perl, __LINE__ can be used to access line number, which is much more > convenient than the way that I found in python). > > -- > Regards, > Peng > Submitted via EggHeadCafe > Merging SharePoint List Data into Word Documents > http://www.eggheadcafe.com/tutorials/aspnet/6054abc5-c5fb-4e86-a352-afd0e8c4a7c6/merging-sharepoint-list-data-into-word-documents.aspx From tooscattered at gmail.com Mon Nov 22 11:25:34 2010 From: tooscattered at gmail.com (scattered) Date: Mon, 22 Nov 2010 08:25:34 -0800 (PST) Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014020136.6e85d70b@tritium.streitmacht.eu> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> <08823dd4-588a-4729-a660-711e266c96b0@y23g2000yqd.googlegroups.com> Message-ID: On Nov 22, 9:45?am, Raffael Cavallaro wrote: > On 2010-11-22 08:12:27 -0500, MarkHanif... at gmail.com said: > > > All opinions are biased. > > All opinions show some bias. Not all opinions represent what is usually > called a "conflict of interest." Since JH makes his living selling > tools and training for certain languages, he has a severe conflict of > interest wrt asessing the value of various other languages. If these > other languages are just as good or better than those he makes his > living from, it would be very damaging to his livlihood for him to > admit this fact. As a result, he is a completely unreliable source on > the question. > And you don't think that Jon Harrop could write a book about Haskell if he honestly came to think that it were a superior all-aroung language? The fact that he *didn't* mindlessly reject F# in favor of O'Caml when F# came out (despite the fact that at the time his company was deeply (exclusively?) invested in O'Caml and arguably had a vested interest in having F# fail to gain support) suggests that he is able to fairly evaluate the merits of other languages. Doubtless he has biases, but there is no reason to think that they are any greater than the bias of any programmer who has invested substantial amounts of time in becoming fluent in a particular language. > This is why judges must recuse themselves from both civil and criminal > trials if they have some significant conflict of interest. But an advocate isn't a judge. Nobody is handing down binding decisions here - they are just advocating their positions. It would be better to compare JH to a defense lawyer. You can't reject the defense's arguments just because the lawyer has a vested interest in the outcome of the trial. > the law recognizes that we cannot expect a fair judgement from someone who > stands to profit significantly if the judgement goes one way or the > other. Similarly, we cannot expect a fair judgement on the relative > value of various language tools from a person whose livlihood depends > on the audience choosing only those certain language tools that he > sells services and training for. > > warmest regards, > > Ralph > > -- > Raffael Cavallaro From tosters at gmail.com Mon Nov 22 11:41:49 2010 From: tosters at gmail.com (Roman Dolgiy) Date: Mon, 22 Nov 2010 08:41:49 -0800 (PST) Subject: Python recursively __getattribute__ References: <20101122110441.267eb032@geekmail.INVALID> Message-ID: <3f980023-665c-47fe-8bb6-78d24c8388e7@k30g2000vbn.googlegroups.com> On Nov 22, 6:04?pm, Andreas Waldenburger wrote: > On Mon, 22 Nov 2010 07:46:47 -0800 (PST) Roman Dolgiy wrote: > > > Hello, > > > I need to implement such behavior: > > > obj.attr1.attr2.attr3 --> obj.attr1__attr2__attr3 > > It looks like I have to override obj's class __getattribute__ and also > > use python descriptors somehow. > > > Any help will be much appreciated. > >http://stackoverflow.com/questions/4247036/python-recursively-getattr... > > Why? No, really: Why? > > In that link you say that you need to do this to support legacy code. I still don't see how this would be necessary. If you need to support legacy code, doesn't that mean that the solution you're asking for already exists? > > I really think you should go into detail about why you need this. I'm certain that there's a better solution to your problem. ("Better" being one that is reasonably easy to implement and maintain.) > > /W > > -- > To reach me via email, replace INVALID with the country code of my home > country. ?But if you spam me, I'll be one sour Kraut. I have a django project. obj is django-haystack's SearchResult instance, it contains a lot of de-normalized data (user__name, user__address) from django model, and I need to access it as result.user.name for compability reasons. From howard at brazee.net Mon Nov 22 11:47:37 2010 From: howard at brazee.net (Howard Brazee) Date: Mon, 22 Nov 2010 09:47:37 -0700 Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014020136.6e85d70b@tritium.streitmacht.eu> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> Message-ID: On Mon, 22 Nov 2010 08:14:40 -0800 (PST), toby wrote: >This is a good (if familiar) observation. Teaching children (or young >people with little exposure to computers) how to program in various >paradigms could produce interesting primary evidence. Pity that this >isn't examined widely and systematically. We could learn something >about how to teach programming and design languages this way, don't >you agree? I do. A study such as that would be more useful than how to teach languages - it could be useful in teaching other stuff as well. -- "In no part of the constitution is more wisdom to be found, than in the clause which confides the question of war or peace to the legislature, and not to the executive department." - James Madison From tkpapp at gmail.com Mon Nov 22 11:51:58 2010 From: tkpapp at gmail.com (Tamas K Papp) Date: 22 Nov 2010 16:51:58 GMT Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014020136.6e85d70b@tritium.streitmacht.eu> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> <08823dd4-588a-4729-a660-711e266c96b0@y23g2000yqd.googlegroups.com> Message-ID: <8kvldeF2e6U1@mid.individual.net> On Mon, 22 Nov 2010 08:25:34 -0800, scattered wrote: > On Nov 22, 9:45?am, Raffael Cavallaro > wrote: >> On 2010-11-22 08:12:27 -0500, MarkHanif... at gmail.com said: >> >> > All opinions are biased. >> >> All opinions show some bias. Not all opinions represent what is usually >> called a "conflict of interest." Since JH makes his living selling >> tools and training for certain languages, he has a severe conflict of >> interest wrt asessing the value of various other languages. If these >> other languages are just as good or better than those he makes his >> living from, it would be very damaging to his livlihood for him to >> admit this fact. As a result, he is a completely unreliable source on >> the question. >> >> > And you don't think that Jon Harrop could write a book about Haskell if > he honestly came to think that it were a superior all-aroung language? Until he writes one, it is useless to speculate about what he could or could not do. There are some pretty good books on Haskell, lots of excellent resources online, and the online community is very supportive. Writing a book which adds significant value to that would not be a trivial undertaking. Best, Tamas From usenot at geekmail.INVALID Mon Nov 22 12:00:42 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Mon, 22 Nov 2010 12:00:42 -0500 Subject: Python recursively __getattribute__ References: <20101122110441.267eb032@geekmail.INVALID> <3f980023-665c-47fe-8bb6-78d24c8388e7@k30g2000vbn.googlegroups.com> Message-ID: <20101122120042.706a2964@geekmail.INVALID> On Mon, 22 Nov 2010 08:41:49 -0800 (PST) Roman Dolgiy wrote: > On Nov 22, 6:04?pm, Andreas Waldenburger > wrote: > > On Mon, 22 Nov 2010 07:46:47 -0800 (PST) Roman Dolgiy > > wrote: > > > > > Hello, > > > > > I need to implement such behavior: > > > > > obj.attr1.attr2.attr3 --> obj.attr1__attr2__attr3 > > > It looks like I have to override obj's class __getattribute__ and > > > also use python descriptors somehow. > > > > > Any help will be much appreciated. > > >http://stackoverflow.com/questions/4247036/python-recursively-getattr... > > > > Why? No, really: Why? > > > > [...] > > I have a django project. > > obj is django-haystack's SearchResult instance, it contains a lot of > de-normalized data (user__name, user__address) from django model, and > I need to access it as result.user.name for compability reasons. I don't know anything about django, so I may be babbling nonsense. Caveat emptor. How about taking your "user__whatever" thingies and have a function emit customized result instances. For this you can just create a plain object subclass, say ResultElement. If these "user__whatever" thingies are strings (you haven't told), split them by "__" and create a new plain object for every level of attributes, attaching it to the previous level. You can probably make your life easier if you use defaultdicts first and then translate these to your object hierarchy. That's how I'd do it. I don't know if that helps you. If not, please provide more info. /W -- To reach me via email, replace INVALID with the country code of my home country. But if you spam me, I'll be one sour Kraut. From ian.g.kelly at gmail.com Mon Nov 22 12:08:34 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 22 Nov 2010 10:08:34 -0700 Subject: unittests with different parameters In-Reply-To: References: Message-ID: On 11/22/2010 4:38 AM, Ulrich Eckhardt wrote: > Let's say I have two flags invert X and invert Y. Now, for testing these, I > would write one test for each combination. What I have in the test case is > something like this: > > def test_invert_flags(self): > """test flags to invert coordinates""" > tests = [((10, 20), INVERT_NONE, (10, 20)), > ((10, 20), INVERT_X, (-10, 20)), > ((10, 20), INVERT_Y, (10, -20))] > for input, flags, expected in tests: > res = do_invert(input, flags) > self.assertEqual(res, expected, > "%s caused wrong results" % (flags,)) > > So, what I do that I test the function 'do_invert' for different input > combinations and verify the result. The ugly thing is that this will abort > the whole test if one of the tests in the loop fails. So, my question is > how do I avoid this? > > I know that I could write a common test function instead: > > def _test_invert_flags(self, input, flags, expected): > res = do_invert(input, flags) > self.assertEqual(res, expected) > > def test_invert_flags_non(self): > """test not inverting coordinates""" > self._test_invert_flags((10, 20), INVERT_NONE, (10, 20)) > > def test_invert_flags_x(self): > """test inverting X coordinates""" > self._test_invert_flags((10, 20), INVERT_X, (-10, 20)) > > def test_invert_flags_y(self): > """test inverting Y coordinates""" > self._test_invert_flags((10, 20), INVERT_Y, (10, -20)) > > What I don't like here is that this is unnecessarily verbose and that it > basically repeats information. The above code looks perfectly fine to me for testing. I think the question you should ask yourself is whether the different combinations you are testing represent tests of distinct behaviors, or tests of the same behavior on a variety of data. If the former case, as in the sample code you posted, then these should probably have separate tests anyway, so that you can easily see that both INVERT_X and INVERT_BOTH are failing, but INVERT_Y is not, which may be valuable diagnostic data. On the other hand, if your test is trying the INVERT_X behavior on nine different points, you probably don't need or want to see every individual point that fails. It's enough to know that INVERT_X is failing and to have a sample point where it fails. In that case I would say just run them in a loop and don't worry that it might exit early. > Also, I'd rather construct the error message > from the data instead of maintaining it in different places, because > manually keeping those in sync is another, errorprone burden. I'm not sure I follow the problem you're describing. If the factored out workhorse function receives the data to test, what prevents it from constructing an error message from that data? Cheers, Ian From namekuseijin at gmail.com Mon Nov 22 12:28:33 2010 From: namekuseijin at gmail.com (namekuseijin) Date: Mon, 22 Nov 2010 09:28:33 -0800 (PST) Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014020136.6e85d70b@tritium.streitmacht.eu> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> Message-ID: <9b520f64-0266-4977-b32a-5f089f7d189b@k13g2000vbq.googlegroups.com> On 22 nov, 14:47, Howard Brazee wrote: > On Mon, 22 Nov 2010 08:14:40 -0800 (PST), toby > > wrote: > >This is a good (if familiar) observation. Teaching children (or young > >people with little exposure to computers) how to program in various > >paradigms could produce interesting primary evidence. Pity that this > >isn't examined widely and systematically. We could learn something > >about how to teach programming and design languages this way, don't > >you agree? > > I do. > > A study such as that would be more useful than how to teach languages > - it could be useful in teaching other stuff as well. yes, pity most children are (used to be) taught Basic first. Also, with a study like this, it's likely some children would be taught some lame language and others would be taught some "industrial strength" language and still others would be taught some esoteric language. I'm not sure it'd prove as much as we are hoping for -- as they are all Turing equivalent and the kids would be able to eventually do the task asked for in any of them -- but I'm sure some of those children would be mentally hurt for all their life. Poor pioneers :p JH, nice to have you back! :) From markhaniford at gmail.com Mon Nov 22 12:32:08 2010 From: markhaniford at gmail.com (MarkHaniford@gmail.com) Date: Mon, 22 Nov 2010 09:32:08 -0800 (PST) Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014020136.6e85d70b@tritium.streitmacht.eu> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> <08823dd4-588a-4729-a660-711e266c96b0@y23g2000yqd.googlegroups.com> Message-ID: On Nov 22, 8:45?am, Raffael Cavallaro wrote: > On 2010-11-22 08:12:27 -0500, MarkHanif... at gmail.com said: > > > All opinions are biased. > > All opinions show some bias. Not all opinions represent what is usually > called a "conflict of interest." > Maybe, but in the case of regulars on newsgroups like c.l.l, there are "conflicts of interest" that either don't or don't indirectly have to do with profiting off the popularity or perception of a particular programming language. Harrop is annoying is the same way that "MatzLisp" guy is annoying on c.l.l. > warmest regards, > > Ralph > > -- > Raffael Cavallaro From toby at telegraphics.com.au Mon Nov 22 12:42:14 2010 From: toby at telegraphics.com.au (toby) Date: Mon, 22 Nov 2010 09:42:14 -0800 (PST) Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014020136.6e85d70b@tritium.streitmacht.eu> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> <9b520f64-0266-4977-b32a-5f089f7d189b@k13g2000vbq.googlegroups.com> Message-ID: <6ca96ca0-cacf-4f82-9c57-0331eae14e57@b25g2000vbz.googlegroups.com> On Nov 22, 12:28?pm, namekuseijin wrote: > On 22 nov, 14:47, Howard Brazee wrote: > > > On Mon, 22 Nov 2010 08:14:40 -0800 (PST), toby > > > wrote: > > >This is a good (if familiar) observation. Teaching children (or young > > >people with little exposure to computers) how to program in various > > >paradigms could produce interesting primary evidence. Pity that this > > >isn't examined widely and systematically. We could learn something > > >about how to teach programming and design languages this way, don't > > >you agree? > > > I do. > > > A study such as that would be more useful than how to teach languages > > - it could be useful in teaching other stuff as well. > > yes, pity most children are (used to be) taught Basic first. > > Also, with a study like this, it's likely some children would be > taught some lame language and others would be taught some "industrial > strength" language and still others would be taught some esoteric > language. This is not worse than the status quo, which does exactly that, but without paying attention to outcomes. What I am proposing is doing it systematically, with observation. Then we can learn something. >?I'm not sure it'd prove as much as we are hoping for -- as > they are all Turing equivalent and the kids would be able to > eventually do the task asked for in any of them -- but I'm sure some > of those children would be mentally hurt for all their life. ?Poor > pioneers :p > > JH, nice to have you back! :) From ulrich.eckhardt at dominolaser.com Mon Nov 22 12:56:14 2010 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Mon, 22 Nov 2010 18:56:14 +0100 Subject: unittests with different parameters References: Message-ID: Ian Kelly wrote: > On 11/22/2010 4:38 AM, Ulrich Eckhardt wrote: >> Also, I'd rather construct the error message from the data >> instead of maintaining it in different places, because >> manually keeping those in sync is another, errorprone burden. > > I'm not sure I follow the problem you're describing. If the factored > out workhorse function receives the data to test, what prevents it from > constructing an error message from that data? Sorry, unprecise description of what I want. If you define a test function and run the tests with "-v", the framework prints the first line of the docstring of that function followed by okay/fail/error, which is much friendlier to the reader than the exception dump afterwards. Using multiple very similar functions requires equally similar docstrings that repeat themselves. I'd prefer creating these from the input data. Thanks for your suggestion, Ian! Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From tjreedy at udel.edu Mon Nov 22 12:57:18 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 22 Nov 2010 12:57:18 -0500 Subject: Python recursively __getattribute__ In-Reply-To: References: Message-ID: On 11/22/2010 10:46 AM, Roman Dolgiy wrote: > Hello, > > I need to implement such behavior: > > obj.attr1.attr2.attr3 --> obj.attr1__attr2__attr3 obj.attr1.attr2.attr3 is parsed as ((obj.attr1).attr2).attr3, so this cannot work in general but only if attr1 and attr2 are known to not be 'final' names. > It looks like I have to override obj's class __getattribute__ and also > use python descriptors somehow. > > Any help will be much appreciated. > http://stackoverflow.com/questions/4247036/python-recursively-getattribute The code posted there by THC4k depened on such knowledge, which you gave there but not here. -- Terry Jan Reedy From ben+python at benfinney.id.au Mon Nov 22 15:15:41 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 23 Nov 2010 07:15:41 +1100 Subject: unittests with different parameters References: Message-ID: <87hbf9868i.fsf@benfinney.id.au> Ulrich Eckhardt writes: > Let's say I have two flags invert X and invert Y. Now, for testing these, I > would write one test for each combination. What I have in the test case is > something like this: > > def test_invert_flags(self): > """test flags to invert coordinates""" > tests = [((10, 20), INVERT_NONE, (10, 20)), > ((10, 20), INVERT_X, (-10, 20)), > ((10, 20), INVERT_Y, (10, -20))] > for input, flags, expected in tests: > res = do_invert(input, flags) > self.assertEqual(res, expected, > "%s caused wrong results" % (flags,)) The ?testscenarios? library is designed for just this reason . It takes a sequence of scenarios, each of which is a tuple just like in your example, and causes a separate test run and report for each one. -- \ ?If we listen only to those who are like us, we will squander | `\ the great opportunity before us: To live together peacefully in | _o__) a world of unresolved differences.? ?David Weinberger | Ben Finney From wxjmfauth at gmail.com Mon Nov 22 15:25:12 2010 From: wxjmfauth at gmail.com (jmfauth) Date: Mon, 22 Nov 2010 12:25:12 -0800 (PST) Subject: Need advices regarding the strings (str, unicode, coding) used as interface for an external library. Message-ID: <62db9e18-a62f-403f-ae49-cb1eb6a22599@k5g2000vbn.googlegroups.com> I'm planning to build an external lib. This lib will exchange a lot of strings between the lib and the "core Python code" of applications. I wish this lib to be modern, 100% unicode compliant. It will be developped for Python 2.7 and for Python 3. In an early phase, technically, it will be developed on Python 2.7 before Python 3, probably 3.2. Two options for the strings interface. a) Pure unicode, that means only type 'unicode' in Python 2.7 and only type 'str' in Python 3. Similar to the Python io module. b) Like a) plus ascii and utf-8 encoded type 'str' to keep some kind of retro compatibility. This lib will anyway work in a "unicode mode", so the ascii and the encoded utf-8 str's have to be converted into "unicode". I'm very comfortable with all this coding stuff and aware of the pros and cons of each solutions. My favourite solution is clearly on the a) side. Advices and comments are welcome. Thanks in advance. From tosters at gmail.com Mon Nov 22 15:44:15 2010 From: tosters at gmail.com (Roman Dolgiy) Date: Mon, 22 Nov 2010 12:44:15 -0800 (PST) Subject: Python recursively __getattribute__ References: Message-ID: On Nov 22, 7:57?pm, Terry Reedy wrote: > On 11/22/2010 10:46 AM, Roman Dolgiy wrote: > > > Hello, > > > I need to implement such behavior: > > > obj.attr1.attr2.attr3 --> ?obj.attr1__attr2__attr3 > > obj.attr1.attr2.attr3 is parsed as ((obj.attr1).attr2).attr3, > so this cannot work in general but only if attr1 and attr2 are known to > not be 'final' names. > > > It looks like I have to override obj's class __getattribute__ and also > > use python descriptors somehow. > > > Any help will be much appreciated. > >http://stackoverflow.com/questions/4247036/python-recursively-getattr... > > The code posted there by THC4k depened on such knowledge, which you gave > there but not here. > > -- > Terry Jan Reedy I need to support a lot of legacy code, with THC4k's approach I'll have to modify project's existing code to use obj.attr1.val instead of obj.attr1 but this is not suitable. From martin.lundberg at gmail.com Mon Nov 22 16:43:34 2010 From: martin.lundberg at gmail.com (Martin Lundberg) Date: Mon, 22 Nov 2010 13:43:34 -0800 (PST) Subject: Glob in python which supports the ** wildcard Message-ID: <0cc11320-1f8c-4063-857e-52c16f0bb688@j18g2000yqd.googlegroups.com> Hi, I want to be able to let the user enter paths like this: apps/name/**/*.js and then find all the matching files in apps/name and all its subdirectories. However I found out that Python's glob function doesn't support the recursive ** wildcard. Is there any 3rd party glob function which do support **? Regards, Martin Lundberg From stefan.sonnenberg at pythonmeister.com Mon Nov 22 17:05:16 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Mon, 22 Nov 2010 23:05:16 +0100 Subject: Glob in python which supports the ** wildcard In-Reply-To: <0cc11320-1f8c-4063-857e-52c16f0bb688@j18g2000yqd.googlegroups.com> References: <0cc11320-1f8c-4063-857e-52c16f0bb688@j18g2000yqd.googlegroups.com> Message-ID: <4CEAE91C.4060003@pythonmeister.com> Am 22.11.2010 22:43, schrieb Martin Lundberg: > Hi, > > I want to be able to let the user enter paths like this: > > apps/name/**/*.js > > and then find all the matching files in apps/name and all its > subdirectories. However I found out that Python's glob function > doesn't support the recursive ** wildcard. Is there any 3rd party glob > function which do support **? > > Regards, > > Martin Lundberg > os.walk() or os.path.walk() can be used. You need to traverse the file system. AFAIK there is no support for this. -------------- next part -------------- A non-text attachment was scrubbed... Name: stefan_sonnenberg.vcf Type: text/x-vcard Size: 223 bytes Desc: not available URL: From raffaelcavallaro at pas.despam.s.il.vous.plait.mac.com Mon Nov 22 17:12:21 2010 From: raffaelcavallaro at pas.despam.s.il.vous.plait.mac.com (Raffael Cavallaro) Date: Mon, 22 Nov 2010 17:12:21 -0500 Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014020136.6e85d70b@tritium.streitmacht.eu> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> <08823dd4-588a-4729-a660-711e266c96b0@y23g2000yqd.googlegroups.com> Message-ID: On 2010-11-22 11:25:34 -0500, scattered said: > And you don't think that [JH] could write a book about Haskell > if he honestly came to think that it were a superior all-aroung > language? Until he actually does, he has a financial interest in trash-talking Haskell. This makes anything he says about Haskell suspect. > The fact that he *didn't* mindlessly reject [musical note lang] in favor of > [Irish Ship Of The Desert] when [musical note lang] came out (despite > the fact that at the time his company > was deeply (exclusively?) invested in [Irish Ship Of The Desert] and > arguably had a vested > interest in having [musical note lang] fail to gain support) suggests > that he is able > to fairly evaluate the merits of other languages. No, it suggests that he saw that supporting the Irish Ship Of The Desert meant going up against Microsoft, so he jumped to the MS supported variant of the Donut Dromedary. You miss the fundamental point; having a financial interest in the outcome of a debate makes anything that person says an advertisement for his financial interests, not a fair assessment. > Doubtless he has > biases, but there is no reason to think that they are any greater than > the bias of any programmer who has invested substantial amounts of > time in becoming fluent in a particular language. Just the opposite. A person who makes his living by being paid to program in a language he has developed some expertise in (rather than selling books on it and training for it) has no financial interest in seeing others develop expertise in it - they would just represent competition. By contrast, one who sells training and books for a language profits directly when others take an interest in that language. Their financial interests are in fact opposite. JH profits when people take an interest in languages he sells training for; a working lisp programmer sees additional *competition* when someone else develops expertise in common lisp. > But an advocate isn't a judge. Nobody is handing down binding > decisions here - they are just advocating their positions. Now you're arguing our point; JH is an *advocate* with a clear conflict of interest which prevents him from presenting anything but the most one sided, and therefore largely useless, assessment. His writing should be seen as a paid advertisement, not as a fair treatment of programming languages. warmest regards, Ralph -- Raffael Cavallaro From kurt.alfred.mueller at sunrise.ch Mon Nov 22 17:54:14 2010 From: kurt.alfred.mueller at sunrise.ch (Kurt Mueller) Date: Mon, 22 Nov 2010 23:54:14 +0100 Subject: Glob in python which supports the ** wildcard In-Reply-To: <4CEAE91C.4060003@pythonmeister.com> References: <0cc11320-1f8c-4063-857e-52c16f0bb688@j18g2000yqd.googlegroups.com> <4CEAE91C.4060003@pythonmeister.com> Message-ID: <4F740F20-CEE1-4726-834D-7CB550243C15@gmail.com> Hi, Am 22.11.2010 um 23:05 schrieb Stefan Sonnenberg-Carstens: > Am 22.11.2010 22:43, schrieb Martin Lundberg: >> I want to be able to let the user enter paths like this: >> apps/name/**/*.js >> and then find all the matching files in apps/name and all its >> subdirectories. However I found out that Python's glob function >> doesn't support the recursive ** wildcard. Is there any 3rd party glob >> function which do support **? > os.walk() or os.path.walk() can be used. > You need to traverse the file system. > AFAIK there is no support for this. If you are a lucky Unix/Linux/MacOS user: --------------------------------------------------------------------------- #!/usr/bin/env python # find files import os cmd = 'find apps/name/ -type f -name "*.js" -print' # find is a standard Unix tool for filename in os.popen(cmd).readlines(): # run find command # do something with filename --------------------------------------------------------------------------- find is very powerful, really. Have anice day -- kurt.alfred.mueller at gmail.com From kurt.alfred.mueller at sunrise.ch Mon Nov 22 18:04:08 2010 From: kurt.alfred.mueller at sunrise.ch (Kurt Mueller) Date: Tue, 23 Nov 2010 00:04:08 +0100 Subject: Glob in python which supports the ** wildcard In-Reply-To: <4CEAE91C.4060003@pythonmeister.com> References: <0cc11320-1f8c-4063-857e-52c16f0bb688@j18g2000yqd.googlegroups.com> <4CEAE91C.4060003@pythonmeister.com> Message-ID: <0AF04369-15B2-4F65-8F79-89F3038DFE5F@gmail.com> HI, Am 22.11.2010 um 23:05 schrieb Stefan Sonnenberg-Carstens: > Am 22.11.2010 22:43, schrieb Martin Lundberg; >> >> I want to be able to let the user enter paths like this: >> apps/name/**/*.js >> and then find all the matching files in apps/name and all its >> subdirectories. However I found out that Python's glob function >> doesn't support the recursive ** wildcard. Is there any 3rd party glob >> function which do support **? >> > os.walk() or os.path.walk() can be used. > You need to traverse the file system. > AFAIK there is no support for this. Or python only: ---------------------------------------------------------- #!/usr/bin/env python import os, fnmatch # generator: def find_files(directory, pattern): for root, dirs, files in os.walk(directory): for basename in files: if fnmatch.fnmatch(basename, pattern): filename = os.path.join(root, basename) yield filename # process each file as it is found: for filename in find_files('apps/name', '*.js'): print 'found java source:', filename ---------------------------------------------------------- Found at http://stackoverflow.com/questions/2186525/use-a-glob-to-find-files-recursively-in-python Have a nice day -- kurt.alfred.mueller at gmail.com From tjreedy at udel.edu Mon Nov 22 19:11:40 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 22 Nov 2010 19:11:40 -0500 Subject: Need advices regarding the strings (str, unicode, coding) used as interface for an external library. In-Reply-To: <62db9e18-a62f-403f-ae49-cb1eb6a22599@k5g2000vbn.googlegroups.com> References: <62db9e18-a62f-403f-ae49-cb1eb6a22599@k5g2000vbn.googlegroups.com> Message-ID: On 11/22/2010 3:25 PM, jmfauth wrote: > I'm planning to build an external lib. This lib will exchange > a lot of strings between the lib and the "core Python code" > of applications. Are you planning to exchange indirectly via disk files or directly via memory buffers? This pretty much amounts to whether the library will interface with Python-only or with anything. Also, what OSes? If 'all', you need to be able to work with both 2 and 4 byte unicodes. -- Terry Jan Reedy From goldtech at worldpost.com Mon Nov 22 19:22:32 2010 From: goldtech at worldpost.com (goldtech) Date: Mon, 22 Nov 2010 16:22:32 -0800 (PST) Subject: How to install uTidylib, easy_install problem Message-ID: I'm using activepython 2.6 on XP. I am trying to install uTidylib 0.2 with easy_install. I like uTidylib more vs. newer modules.and want to use it. I get output below. How do I install it? I do see it in http://pypi.python.org/simple/uTidylib/ Thanks. C:\Documents and Settings\user1>easy_install uTidylib install_dir C:\Python26\Lib\site-packages\ Searching for uTidylib Reading http://pypi.python.org/simple/uTidylib/ Reading http://utidylib.sf.net No local packages or download links found for uTidylib error: Could not find suitable distribution for Requirement.parse('uTidylib') From martin at v.loewis.de Mon Nov 22 19:42:50 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Tue, 23 Nov 2010 01:42:50 +0100 Subject: Glob in python which supports the ** wildcard In-Reply-To: <0cc11320-1f8c-4063-857e-52c16f0bb688@j18g2000yqd.googlegroups.com> References: <0cc11320-1f8c-4063-857e-52c16f0bb688@j18g2000yqd.googlegroups.com> Message-ID: <4CEB0E0A.4030105@v.loewis.de> Am 22.11.2010 22:43, schrieb Martin Lundberg: > Hi, > > I want to be able to let the user enter paths like this: > > apps/name/**/*.js > > and then find all the matching files in apps/name and all its > subdirectories. However I found out that Python's glob function > doesn't support the recursive ** wildcard. Is there any 3rd party glob > function which do support **? mercurial.match supports apps/name/**.js (IIUC). mglob supports rec:*.js. Regards, Martin From sridharr at activestate.com Mon Nov 22 19:43:58 2010 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Mon, 22 Nov 2010 16:43:58 -0800 Subject: How to install uTidylib, easy_install problem In-Reply-To: References: Message-ID: On 2010-11-22, at 4:22 PM, goldtech wrote: > I'm using activepython 2.6 on XP. I am trying to install uTidylib 0.2 > with easy_install. I like uTidylib more vs. newer modules.and want to > use it. I get output below. How do I install it? I do see it in > http://pypi.python.org/simple/uTidylib/ > > Thanks. > > C:\Documents and Settings\user1>easy_install uTidylib > install_dir C:\Python26\Lib\site-packages\ > Searching for uTidylib > Reading http://pypi.python.org/simple/uTidylib/ > Reading http://utidylib.sf.net > No local packages or download links found for uTidylib > error: Could not find suitable distribution for > Requirement.parse('uTidylib') You could try using the Windows installer (uTidylib-0.2.1.win32.exe) from: http://developer.berlios.de/project/showfiles.php?group_id=1810 And perhaps also let Cory Dodt know that his 6-year old package entry has broken download link in it http://pypi.python.org/pypi/uTidylib/ There is not even a source release for 0.2.1. I'd be more than happy to make this available in PyPM once I can find at least the source release of 0.2.1 -srid From dilip1984me at gmail.com Mon Nov 22 20:26:00 2010 From: dilip1984me at gmail.com (dilip raghavan) Date: Mon, 22 Nov 2010 17:26:00 -0800 (PST) Subject: File Reading In Mac Message-ID: <66e4164c-e81d-4a65-b847-c5ef900fa14c@a37g2000yqi.googlegroups.com> Hello , I have been trying to read contents from a file in MAC. I wrote the code filename = "test.rtf" FileHandle = open(filename,'r') fileStr = FileHandle.read() print fileStr FileHandle.close() When I see the output I see a lot of junk. The junk is like a lot of question marks, the font information and other details of the file. The actual content is lost in the junk. I have tried other methods like readline but still I see the junk. I tried the asme code in windows and it worked correctly. Can any one tell me the reason and the solution for this. Thanks In advance. From ndbecker2 at gmail.com Mon Nov 22 20:33:08 2010 From: ndbecker2 at gmail.com (Neal Becker) Date: Mon, 22 Nov 2010 20:33:08 -0500 Subject: bug? mmap doesn't like 0-length files Message-ID: mmap.mmap (f.fileno(), 0, prot=mmap.PROT_READ) error: [Errno 22] Invalid argument According to http://docs.python.org/library/mmap.html, mmap on _windows_ doesn't accept 0-length file. But this was tested on linux. Is this a bug? I don't see anything in linux man-page about the underlying C mmap function not accepting 0-length files. From nad at acm.org Mon Nov 22 20:50:07 2010 From: nad at acm.org (Ned Deily) Date: Mon, 22 Nov 2010 17:50:07 -0800 Subject: File Reading In Mac References: <66e4164c-e81d-4a65-b847-c5ef900fa14c@a37g2000yqi.googlegroups.com> Message-ID: In article <66e4164c-e81d-4a65-b847-c5ef900fa14c at a37g2000yqi.googlegroups.com>, dilip raghavan wrote: > I have been trying to read contents from a file in MAC. > I wrote the code > > filename = "test.rtf" > FileHandle = open(filename,'r') > > fileStr = FileHandle.read() > print fileStr > FileHandle.close() > > When I see the output I see a lot of junk. The junk is like a lot of > question marks, the font information and other details of the file. > The actual content is lost in the junk. > > I have tried other methods like readline but still I see the junk. > I tried the asme code in windows and it worked correctly. > Can any one tell me the reason and the solution for this. With an extension of "rtf", the file is presumably a "Rich Text Format" file. http://en.wikipedia.org/wiki/Rich_Text_Format There are some Python packages out there for dealing with rtf format files. You might try rtf2xml to convert the file, preserving style attributes: http://pypi.python.org/pypi/rtf2xml/ Or look at the Mac OS X command line utility textutil (man 1 textutil) to convert the file to another format. Or use the OS X TextEdit.app. -- Ned Deily, nad at acm.org From icanbob at gmail.com Mon Nov 22 20:52:10 2010 From: icanbob at gmail.com (bobicanprogram) Date: Mon, 22 Nov 2010 17:52:10 -0800 (PST) Subject: Round Trip: C to Python to C Module References: Message-ID: <37aedfc0-f943-4401-b9f7-91fdeef9fe7e@j18g2000yqd.googlegroups.com> On Nov 19, 11:05 am, Eric Frederich wrote: > I have a proprietary software PropSoft that I need to extend. > They support extensions written in C that can link against PropLib to > interact with the system. > > I have a Python C module that wraps a couple PropLib functions that I > call PyProp.>From an interactive Python shell I can import PyProp and call a function. > > None of these functions really do anything outside the context of > being logged into the PropSoft software; so all the functions fail > when running from Python alone. > > To my amazement, I was able to run PyRun_SimpleString("import > PyProp\nPyProp.some_function()") without setting PYTHONPATH or > anything. How this works, I don't know and I don't really care (at > the moment anyway). > > The problem I'm having now is how do I return things from my Python > script back to C? > Ultimately I won't be hard coding python inside of PyRun_SimpleString > but loading the script from a file. > So, how do I return values back to C? Python functions return values > but running a python script?... doesn't that just have an exit status? > Is there a mechanism for doing this? > > Thanks in advance, > ~Eric If you find you can't make this work as planned, you might want to check out the SIMPL toolkit (http://www.icanprogram.com/06py/lesson1/ lesson1.html) for an alternative way to connect C programs to Python modules. bob From cs at zip.com.au Mon Nov 22 21:59:29 2010 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 23 Nov 2010 13:59:29 +1100 Subject: bug? mmap doesn't like 0-length files In-Reply-To: References: Message-ID: <20101123025929.GA27420@cskk.homeip.net> On 22Nov2010 20:33, Neal Becker wrote: | mmap.mmap (f.fileno(), 0, prot=mmap.PROT_READ) | error: [Errno 22] Invalid argument | | According to http://docs.python.org/library/mmap.html, mmap on _windows_ | doesn't accept 0-length file. But this was tested on linux. Is this a bug? | | I don't see anything in linux man-page about the underlying C mmap function | not accepting 0-length files. On a local Gentoo Linux box mmap(2) says in the ERRORS section: EINVAL We don't like addr, length, or offset (e.g., they are too large, or not aligned on a page boundary). EINVAL (since Linux 2.6.12) length was 0. EINVAL flags contained neither MAP_PRIVATE or MAP_SHARED, or contained both of these values. Sure looks like a length of 0 is disliked. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Carpe Daemon - Seize the Background Process - Paul Tomblin From cs at zip.com.au Mon Nov 22 22:00:59 2010 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 23 Nov 2010 14:00:59 +1100 Subject: bug? mmap doesn't like 0-length files In-Reply-To: <20101123025929.GA27420@cskk.homeip.net> References: <20101123025929.GA27420@cskk.homeip.net> Message-ID: <20101123030059.GA27628@cskk.homeip.net> On 23Nov2010 13:59, I wrote: | On 22Nov2010 20:33, Neal Becker wrote: | | mmap.mmap (f.fileno(), 0, prot=mmap.PROT_READ) | | error: [Errno 22] Invalid argument [...] | | I don't see anything in linux man-page about the underlying C mmap function | | not accepting 0-length files. It's worth noting that any time you get an errno error/exception then it is almost certainly the underlying OS interface that has rejected your request, not the python library. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Don't have awk? Use this simple sh emulation: #!/bin/sh echo 'Awk bailing out!' >&2 exit 2 - Tom Horsley From nobody at nowhere.com Mon Nov 22 22:39:02 2010 From: nobody at nowhere.com (Nobody) Date: Tue, 23 Nov 2010 03:39:02 +0000 Subject: Reading bz2 file into numpy array References: <4cea3de7$0$6769$9b4e6d93@newsspool3.arcor-online.net> Message-ID: On Mon, 22 Nov 2010 11:37:22 +0100, Peter Otten wrote: >> is there a convenient way to read bz2 files into a numpy array? > > Try > f = bz2.BZ2File(filename) > data = numpy.fromstring(f.read(), numpy.float32) That's going to hurt if the file is large. You might be better off either extracting to a temporary file, or creating a pipe with numpy.fromfile() reading the pipe and either a thread or subprocess decompressing the data into the pipe. E.g.: import os import threading class Pipe(threading.Thread): def __init__(self, f, blocksize = 65536): super(Pipe, self).__init__() self.f = f self.blocksize = blocksize rd, wr = os.pipe() self.rd = rd self.wr = wr self.daemon = True self.start() def run(self): while True: s = self.f.read(self.blocksize) if not s: break os.write(self.wr, s) os.close(self.wr) def make_real(f): return os.fdopen(Pipe(f).rd, 'rb') Given the number of situations where you need a "real" (OS-level) file handle or descriptor rather than a Python "file-like object", something like this should really be part of the standard library. From nobody at nowhere.com Mon Nov 22 22:42:55 2010 From: nobody at nowhere.com (Nobody) Date: Tue, 23 Nov 2010 03:42:55 +0000 Subject: bug? mmap doesn't like 0-length files References: Message-ID: On Mon, 22 Nov 2010 20:33:08 -0500, Neal Becker wrote: > I don't see anything in linux man-page about the underlying C mmap function > not accepting 0-length files. My mmap(2) manpage says: ERRORS ... EINVAL (since Linux 2.6.12) length was 0. From gnarlodious at gmail.com Mon Nov 22 23:40:44 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Mon, 22 Nov 2010 20:40:44 -0800 (PST) Subject: CGI FieldStorage instances? References: <1ec25d72-a99e-4fd9-9d50-1ac8c65812e9@z19g2000yqb.googlegroups.com> <6trje65kt71v00339psntb6srgr5qtls5c@4ax.com> Message-ID: <8b8a7842-6249-4c0f-ac97-61bd646b52af@k3g2000vbp.googlegroups.com> Let me rephrase the question. Say I have a query string like this: ?view=Data&item=9875 What I want to do is simply invoke process "view" with variable "Data". This would replace my existing query string mess which looks like this: if 'view' in form and 'item' in form: HTML=view(Data, item(9875)) so it just seems like it would be easier to encode the process in the query rather than filtering the query string. -- Gnarlie From matlab.dude at mbnet.fi Tue Nov 23 02:24:39 2010 From: matlab.dude at mbnet.fi (MATLABdude) Date: Mon, 22 Nov 2010 23:24:39 -0800 (PST) Subject: MATLAB to Python? References: <74f276c3-38a4-4df0-af39-7b1f2a81472e@c39g2000yqi.googlegroups.com> <878w0s2uwv.fsf@gmail.com> <525ad586-d4fe-484a-9f9e-74b0e0fd78d4@s4g2000yql.googlegroups.com> Message-ID: On Nov 22, 11:11?am, Peter Otten <__pete... at web.de> wrote: > Try numpy.arange() instead: > >>> numpy.arange(0, 1, .1) > array([ 0. , ?0.1, ?0.2, ?0.3, ?0.4, ?0.5, ?0.6, ?0.7, ?0.8, ?0.9]) Thanks! It worked. What's wrong with the following code? ---8<---8<---8<--- T0_orig = [5, 50, 500, 5000] for counter in T0_orig: T0 = (L**2)/(D*pi**2)*counter amax = T0/kappa alpha = (10**-6)*amax lambda_, xx, f = nonhomog_solver(kappa, alpha, nu, nx) V0 = sqrt( T0_orig*(m**-1) + pi**2 * D/(m*L**2)*lambda_ ) print "V0 = ", V0 print "" ---8<---8<---8<--- Python says: ---8<---8<---8<--- Traceback (most recent call last): File "nonhomog.py", line 159, in main() File "nonhomog.py", line 157, in main nonhomog(0.2) File "nonhomog.py", line 152, in nonhomog V0 = sqrt( T0_orig*(m**-1) + pi**2 * D/(m*L**2)*lambda_ ) TypeError: can't multiply sequence by non-int of type 'float' ---8<---8<---8<--- From arnodel at gmail.com Tue Nov 23 02:43:20 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Tue, 23 Nov 2010 07:43:20 +0000 Subject: MATLAB to Python? References: <74f276c3-38a4-4df0-af39-7b1f2a81472e@c39g2000yqi.googlegroups.com> <878w0s2uwv.fsf@gmail.com> <525ad586-d4fe-484a-9f9e-74b0e0fd78d4@s4g2000yql.googlegroups.com> Message-ID: <87fwus8oyv.fsf@gmail.com> MATLABdude writes: > On Nov 22, 11:11?am, Peter Otten <__pete... at web.de> wrote: >> Try numpy.arange() instead: >> >>> numpy.arange(0, 1, .1) >> array([ 0. , ?0.1, ?0.2, ?0.3, ?0.4, ?0.5, ?0.6, ?0.7, ?0.8, ?0.9]) > > Thanks! It worked. > > What's wrong with the following code? > ---8<---8<---8<--- > T0_orig = [5, 50, 500, 5000] > for counter in T0_orig: > T0 = (L**2)/(D*pi**2)*counter > amax = T0/kappa > alpha = (10**-6)*amax > lambda_, xx, f = nonhomog_solver(kappa, alpha, nu, nx) > V0 = sqrt( T0_orig*(m**-1) + pi**2 * D/(m*L**2)*lambda_ ) > print "V0 = ", V0 > print "" > ---8<---8<---8<--- > > Python says: > ---8<---8<---8<--- > Traceback (most recent call last): > File "nonhomog.py", line 159, in > main() > File "nonhomog.py", line 157, in main > nonhomog(0.2) > File "nonhomog.py", line 152, in nonhomog > V0 = sqrt( T0_orig*(m**-1) + pi**2 * D/(m*L**2)*lambda_ ) > TypeError: can't multiply sequence by non-int of type 'float' > ---8<---8<---8<--- T0_orig is a list and you are trying to multiply this list by a float (m**-1) -- Arnaud From matlab.dude at mbnet.fi Tue Nov 23 02:49:19 2010 From: matlab.dude at mbnet.fi (MATLABdude) Date: Mon, 22 Nov 2010 23:49:19 -0800 (PST) Subject: MATLAB to Python? References: <74f276c3-38a4-4df0-af39-7b1f2a81472e@c39g2000yqi.googlegroups.com> <878w0s2uwv.fsf@gmail.com> <525ad586-d4fe-484a-9f9e-74b0e0fd78d4@s4g2000yql.googlegroups.com> <87fwus8oyv.fsf@gmail.com> Message-ID: <0b801c71-3ccd-49ea-b281-90ab93a80d9d@l17g2000yqe.googlegroups.com> On Nov 23, 9:43?am, Arnaud Delobelle wrote: > T0_orig is a list and you are trying to multiply this list by a float > (m**-1) Yes, yes of course. Thanks! :) This works: ---8<---8<---8<--- T0_orig = [5, 50, 500, 5000] for counter in T0_orig: T0 = (L**2)/(D*pi**2)*counter amax = T0/kappa alpha = (10**-6)*amax lambda_, xx, f = nonhomog_solver(kappa, alpha, nu, nx) V0 = sqrt( counter*(m**-1) + pi**2 * D/(m*L**2)*lambda_ ) print "V0 = ", V0 print "" ---8<---8<---8<--- From simon at brunningonline.net Tue Nov 23 04:08:59 2010 From: simon at brunningonline.net (Simon Brunning) Date: Tue, 23 Nov 2010 09:08:59 +0000 Subject: Glob in python which supports the ** wildcard In-Reply-To: <0cc11320-1f8c-4063-857e-52c16f0bb688@j18g2000yqd.googlegroups.com> References: <0cc11320-1f8c-4063-857e-52c16f0bb688@j18g2000yqd.googlegroups.com> Message-ID: On 22 November 2010 21:43, Martin Lundberg wrote: > Hi, > > I want to be able to let the user enter paths like this: > > apps/name/**/*.js > > and then find all the matching files in apps/name and all its > subdirectories. However I found out that Python's glob function > doesn't support the recursive ** wildcard. Is there any 3rd party glob > function which do support **? This does roughly what you want: http://code.activestate.com/recipes/499305-locating-files-throughout-a-directory-tree/ -- Cheers, Simon B. From simon at brunningonline.net Tue Nov 23 04:40:00 2010 From: simon at brunningonline.net (Simon Brunning) Date: Tue, 23 Nov 2010 09:40:00 +0000 Subject: Glob in python which supports the ** wildcard In-Reply-To: References: <0cc11320-1f8c-4063-857e-52c16f0bb688@j18g2000yqd.googlegroups.com> Message-ID: On 23 November 2010 09:26, Martin Lundberg wrote: > It does not seem to support the ** wildcard? It will recursively seek > for files matching a pattern like *.js but it won't support > /var/name/**/*.js as root, will it? I did say roughly. ;-) You'd need to do: for filename in locate("*.js", "/var/name/"): print filename Adding support for ** is left as an exercise for the reader. -- Cheers, Simon B. From __peter__ at web.de Tue Nov 23 05:18:52 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 23 Nov 2010 11:18:52 +0100 Subject: Reading bz2 file into numpy array References: <4cea3de7$0$6769$9b4e6d93@newsspool3.arcor-online.net> Message-ID: Nobody wrote: > On Mon, 22 Nov 2010 11:37:22 +0100, Peter Otten wrote: > >>> is there a convenient way to read bz2 files into a numpy array? >> >> Try > >> f = bz2.BZ2File(filename) >> data = numpy.fromstring(f.read(), numpy.float32) > > That's going to hurt if the file is large. Yes, but memory usage will peak at about 2*sizeof(data), and most scripts need more data than just a single numpy.array. In short: the OP is unlikely to run into the problem. > You might be better off either extracting to a temporary file, or creating > a pipe with numpy.fromfile() reading the pipe and either a thread or > subprocess decompressing the data into the pipe. I like to keep it simple, so if available RAM turns out to be the limiting factor I think extracting the data into a temporary file is a good backup plan. Peter From ulrich.eckhardt at dominolaser.com Tue Nov 23 05:36:05 2010 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Tue, 23 Nov 2010 11:36:05 +0100 Subject: Making module content available in parent module Message-ID: Hi! Note up front: I'm using Python2.6 still, I guess with 2.7 test discovery, I could get better results easier, right? Now, my problem is I have a directory containing test scripts which I all want to run. I used to run them individually and manually, but want to avoid this overhead in the future. tests/ foo.py # defines TestFoo1 and TestFoo2 bar.py # defines TestBar1 and TestBar2 What I would like to do now is this: from tests import * unittest.main() In other words, import all test files and run them. This does import them, but it turns out that I end up with modules foo and bar, and the unittests inside those are not found. Am I approaching the test loading the wrong way? Cheers! Uli PS: I've been trying a few things here, and stumbled across another thing that could provide a solution. I can "from tests import *", but then all these modules will pollute my namespace. I can "import tests", but then neither of the submodules will be in "tests". I tried "import tests.*", but that doesn't work. Is there no way to import a whole package but with its namespace? -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From bruno.desthuilliers at gmail.com Tue Nov 23 05:40:39 2010 From: bruno.desthuilliers at gmail.com (bruno.desthuilliers at gmail.com) Date: Tue, 23 Nov 2010 02:40:39 -0800 (PST) Subject: Python recursively __getattribute__ References: Message-ID: <2e563fac-88e9-47d0-b44d-1b40f4572f70@i17g2000vbq.googlegroups.com> On 22 nov, 21:44, Roman Dolgiy wrote: >> http://stackoverflow.com/questions/4247036/python-recursively-getattr... > > I need to support a lot of legacy code, with THC4k's approach I'll > have to modify project's existing code to use obj.attr1.val instead of > obj.attr1 but this is not suitable. You should probably re-read THC4k's answer. His code works just fine AFAICT: """ # the proxy maps attribute access to another object class GetattrProxy(object): def __init__(self, proxied, prefix=None): self.proxied = proxied self.prefix = prefix def __getattr__(self, key): attr = (key if self.prefix is None else self.prefix + '__' + key) try: # if the proxied object has the attr return it return getattr(self.proxied, attr) except AttributeError: # else just return another proxy return GetattrProxy(self.proxied, attr) # the thing you want to wrap class Target(object): attr1__attr2__attr3 = 5 attr2 = "attr2" t = Target() proxy = GetattrProxy(t) print "proxy.attr1.attr2.attr3 : '%s'" % proxy.attr1.attr2.attr3 print "proxy.attr2 : '%s'" % proxy.attr2 """ From gh at gregor-horvath.com Tue Nov 23 05:58:06 2010 From: gh at gregor-horvath.com (Gregor Horvath) Date: Tue, 23 Nov 2010 11:58:06 +0100 Subject: Making module content available in parent module References: Message-ID: <20101123115806.21fca7b4@valun> Hi, On Tue, 23 Nov 2010 11:36:05 +0100 Ulrich Eckhardt wrote: > Now, my problem is I have a directory containing test scripts which I > all want to run. I used to run them individually and manually, but > want to avoid this overhead in the future. > > tests/ > foo.py # defines TestFoo1 and TestFoo2 > bar.py # defines TestBar1 and TestBar2 Nose does what you want: http://packages.python.org/nose/ -- Gregor From steve+comp.lang.python at pearwood.info Tue Nov 23 07:35:02 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 Nov 2010 12:35:02 GMT Subject: Making module content available in parent module References: Message-ID: <4cebb4f6$0$29966$c3e8da3$5496439d@news.astraweb.com> On Tue, 23 Nov 2010 11:36:05 +0100, Ulrich Eckhardt wrote: > tests/ > foo.py # defines TestFoo1 and TestFoo2 > bar.py # defines TestBar1 and TestBar2 > > What I would like to do now is this: > > from tests import * > unittest.main() > > In other words, import all test files and run them. This does import > them, but it turns out that I end up with modules foo and bar, and the > unittests inside those are not found. Given the directory structure you show, I find that hard to believe. You should get an ImportError, as there is no module or package called "tests". But suppose you turn tests into a proper package: tests/ __init__.py foo.py bar.py You could have __init__.py include these lines: from foo import * from bar import * Then later, when you do this: from tests import * it will pick up everything from foo and bar, and unittest.main() should run those tests as well. I think. Or you could just do: for module in (foo, bar): try: unittest.main(module) except SystemExit: pass > PS: I've been trying a few things here, and stumbled across another > thing that could provide a solution. I can "from tests import *", but > then all these modules will pollute my namespace. I can "import tests", > but then neither of the submodules will be in "tests". I tried "import > tests.*", but that doesn't work. Is there no way to import a whole > package but with its namespace? The package needs to know what submodules to make available. Put inside __init__.py: import foo import bar and then from outside the package, do this: import tests Now tests.foo and tests.bar will exist. -- Steven From tartley at tartley.com Tue Nov 23 09:00:43 2010 From: tartley at tartley.com (Jonathan Hartley) Date: Tue, 23 Nov 2010 06:00:43 -0800 (PST) Subject: unittests with different parameters References: Message-ID: <846d4dd9-1f6e-424b-b85a-0c497bba434e@c39g2000yqi.googlegroups.com> On Nov 22, 11:38?am, Ulrich Eckhardt wrote: > Hi! > > I'm writing tests and I'm wondering how to achieve a few things most > elegantly with Python's unittest module. > > Let's say I have two flags invert X and invert Y. Now, for testing these, I > would write one test for each combination. What I have in the test case is > something like this: > > ? def test_invert_flags(self): > ? ? ? """test flags to invert coordinates""" > ? ? ? tests = [((10, 20), INVERT_NONE, (10, 20)), > ? ? ? ? ? ? ? ?((10, 20), INVERT_X, (-10, 20)), > ? ? ? ? ? ? ? ?((10, 20), INVERT_Y, (10, -20))] > ? ? ? for input, flags, expected in tests: > ? ? ? ? ? res = do_invert(input, flags) > ? ? ? ? ? self.assertEqual(res, expected, > ? ? ? ? ? ? ? ? ? ? ? ? ? ?"%s caused wrong results" % (flags,)) > > So, what I do that I test the function 'do_invert' for different input > combinations and verify the result. The ugly thing is that this will abort > the whole test if one of the tests in the loop fails. So, my question is > how do I avoid this? > > I know that I could write a common test function instead: > > ? def _test_invert_flags(self, input, flags, expected): > ? ? ? res = do_invert(input, flags) > ? ? ? self.assertEqual(res, expected) > > ? def test_invert_flags_non(self): > ? ? ? """test not inverting coordinates""" > ? ? ? self._test_invert_flags((10, 20), INVERT_NONE, (10, 20)) > > ? def test_invert_flags_x(self): > ? ? ? """test inverting X coordinates""" > ? ? ? self._test_invert_flags((10, 20), INVERT_X, (-10, 20)) > > ? def test_invert_flags_y(self): > ? ? ? """test inverting Y coordinates""" > ? ? ? self._test_invert_flags((10, 20), INVERT_Y, (10, -20)) > > What I don't like here is that this is unnecessarily verbose and that it > basically repeats information. Also, I'd rather construct the error message > from the data instead of maintaining it in different places, because > manually keeping those in sync is another, errorprone burden. > > Any suggestions? > > Uli > > -- > Domino Laser GmbH > Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 The following is a bit ghastly, I'm not sure I'd recommend it, but if you are determined, you could try dynamically adding test methods to the test class. The following is untested - I suspect I have made a schoolboy error in attempting to make methods out of functions - but something like it might work: class MyTestClass(unittest.TestCase): pass testdata = [ (INPUTS, EXPECTED), (INPUTS, EXPECTED), (INPUTS, EXPECTED), ] for index, (input, expected) in enumerate(testdata): # the following sets an attribute on MyTestClass # the names of the attributes are 'test_1', 'test_2', etc # the value of the attributes is a test method that performs the assert setattr( MyTestClass, 'test_%d' % (index,), lambda s: s.assertEquals(METHOD_UNDER_TEST(*input), expected) ) From wxjmfauth at gmail.com Tue Nov 23 09:02:16 2010 From: wxjmfauth at gmail.com (jmfauth) Date: Tue, 23 Nov 2010 06:02:16 -0800 (PST) Subject: Need advices regarding the strings (str, unicode, coding) used as interface for an external library. References: <62db9e18-a62f-403f-ae49-cb1eb6a22599@k5g2000vbn.googlegroups.com> Message-ID: <7b910f46-2b26-443a-96a9-aa84c36ea502@a30g2000vbt.googlegroups.com> Thanks for the reply. Subject closed. From tosters at gmail.com Tue Nov 23 09:54:34 2010 From: tosters at gmail.com (Roman Dolgiy) Date: Tue, 23 Nov 2010 06:54:34 -0800 (PST) Subject: Python recursively __getattribute__ References: <2e563fac-88e9-47d0-b44d-1b40f4572f70@i17g2000vbq.googlegroups.com> Message-ID: <7f33b8a4-7246-476e-a524-e32cf7b09a96@w29g2000vba.googlegroups.com> Thanks to Andreas Waldenburger, THC4k (http://stackoverflow.com/ questions/4247036/python-recursively-getattribute) and others for their tips. I was able to find solution: class Null(object): def __repr__(self): return "" def __str__(self): return '' def __nonzero__(self): return False class ResultAttrFactory(type): _cache = {} @classmethod def prepare(cls, base, result): dict_ = ResultAttr.__dict__.copy() dict_.update({ '_ResultAttr__base': base, '_ResultAttr__result': result}) return ('ResultAttr', (base,), dict_) def __new__(cls, base, result): if (base, result) in cls._cache: type_ = cls._cache[(base, result)] else: type_ = super(ResultAttrFactory, cls).__new__( cls, *cls.prepare(base, result)) cls._cache[(base, result)] = type_ return type_ def __init__(cls, base, result): pass class ResultAttr: """Should be used only with ResultAttrFactory""" @staticmethod def __new__(cls, arg1, name): return cls.__base.__new__(cls, arg1) def __init__(self, arg1, name): self.__name = name super(self.__class__, self).__init__(arg1) def get_result_attr(self, name): if self.__result.is_denorm_attr(name): attr = getattr(self.__result, name, None) else: attr = getattr(self.__result, name) return attr def __getattr__(self, name): lookup_name = "%s__%s" % (self.__name, name) attr = self.get_result_attr(lookup_name) if type(attr).__name__ == 'ResultAttr': type_ = attr.__base elif attr is None: type_ = Null else: type_ = type(attr) result_attr = ResultAttrFactory( type_, self.__result)(attr, lookup_name) return result_attr class BaseResult(object): """ >>> class Result(BaseResult): ... def __init__(self, *args, **kwargs): ... self.x = 35 ... self.y = 5 ... self.y__a = 3 ... self.y__b = 'hello' ... self.y__c__x = [1, 2, 3] ... super(Result, self, *args, **kwargs) >>> r = Result() >>> r.x 35 >>> type(r.x) >>> r.y 5 >>> type(r.y) # doctest:+ELLIPSIS >>> r.y.a 3 >>> r.y.b 'hello' >>> r.y.c # Is there any way to raise AtrributeError here? >>> r.y.d Traceback (most recent call last): AttributeError: 'Result' object has no attribute 'y__d' >>> r.y.c.x [1, 2, 3] """ def is_denorm_attr(self, name): return bool([k for k in self.__dict__.keys() if "%s__" % name in k]) def __getattribute__(self, name): attr = super(BaseResult, self).__getattribute__(name) if name in ('__dict__', 'is_denorm_attr'): return attr if self.is_denorm_attr(name): return ResultAttrFactory(type(attr), self)(attr, name) else: return attr if __name__ == '__main__': import doctest doctest.testmod() https://gist.github.com/710977 The only problem is: >>> r.y.c Is there any way to raise AtrributeError here? Also is there any negative side effects of such method? From duggar at alum.mit.edu Tue Nov 23 10:08:12 2010 From: duggar at alum.mit.edu (Keith H Duggar) Date: Tue, 23 Nov 2010 07:08:12 -0800 (PST) Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014020136.6e85d70b@tritium.streitmacht.eu> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> <08823dd4-588a-4729-a660-711e266c96b0@y23g2000yqd.googlegroups.com> Message-ID: <396f8de7-ece5-4e9c-919b-886eb65ae14a@a30g2000vbt.googlegroups.com> On Nov 22, 5:12?pm, Raffael Cavallaro wrote: > On 2010-11-22 11:25:34 -0500, scattered said: > > > And you don't think that [JH] could write a book about Haskell > > if he honestly came to think that it were a superior all-aroung > > language? > > Until he actually does, he has a financial interest in trash-talking > Haskell. This makes anything he says about Haskell suspect. > > > ?The fact that he *didn't* mindlessly reject [musical note lang] in favor of > > [Irish Ship Of The Desert] when [musical note lang] came out (despite > > the fact that at the time his company > > was deeply (exclusively?) invested in [Irish Ship Of The Desert] and > > arguably had a vested > > interest in having [musical note lang] fail to gain support) suggests > > that he is able > > to fairly evaluate the merits of other languages. > > No, it suggests that he saw that supporting the Irish Ship Of The > Desert meant going up against Microsoft, so he jumped to the MS > supported variant of the Donut Dromedary. > > You miss the fundamental point; having a financial interest in the > outcome of a debate makes anything that person says an advertisement > for his financial interests, not a fair assessment. There is a well-known name for such illogical reasoning: ad hominem. When a person poses an /argument/, nothing personal outside of the /argument/ is relevant. Thus, your claim that "anything that person says ..." is not only obvious hyperbole it is also illogical. It is a common refuge of those who cannot support their position with fact and logic. On more than one occasion Jon Harrop has all but crushed Ertugrul in this very forum with /source code/; that is as objective as it gets. KHD From raffaelcavallaro at pas.despam.s.il.vous.plait.mac.com Tue Nov 23 10:34:22 2010 From: raffaelcavallaro at pas.despam.s.il.vous.plait.mac.com (Raffael Cavallaro) Date: Tue, 23 Nov 2010 10:34:22 -0500 Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014020136.6e85d70b@tritium.streitmacht.eu> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> <08823dd4-588a-4729-a660-711e266c96b0@y23g2000yqd.googlegroups.com> <396f8de7-ece5-4e9c-919b-886eb65ae14a@a30g2000vbt.googlegroups.com> Message-ID: On 2010-11-23 10:08:12 -0500, Keith H Duggar said: > There is a well-known name for such illogical reasoning: ad hominem. You don't understand ad hominem: "The ad hominem is a classic logical fallacy,[2] but it is not always fallacious. For in some instances, questions of personal conduct, character, motives, etc., are legitimate and relevant to the issue.[3]" Source: Sometimes the person's conduct and motives *are relevant* to the point under discussion. Financial conflict of interest is a perfect example where it *is* legitimate and relevant to explore a person's motives and conduct outside of the debate. In this case, JH's conduct outside of the debate (i.e., the fact that he earns his living by selling tools and training for a particular set of languages) and his motives (i.e., he is therefore financially motivated to present these languages in the best possible light and to trash-talk other languages), render his arguments in the debate inherently suspect. warmest regards, Ralph -- Raffael Cavallaro From ulrich.eckhardt at dominolaser.com Tue Nov 23 10:42:00 2010 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Tue, 23 Nov 2010 16:42:00 +0100 Subject: Making module content available in parent module References: <4cebb4f6$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Tue, 23 Nov 2010 11:36:05 +0100, Ulrich Eckhardt wrote: >> PS: I've been trying a few things here, and stumbled across another >> thing that could provide a solution. I can "from tests import *", but >> then all these modules will pollute my namespace. I can "import tests", >> but then neither of the submodules will be in "tests". I tried "import >> tests.*", but that doesn't work. Is there no way to import a whole >> package but with its namespace? > > The package needs to know what submodules to make available. Put inside > __init__.py: > > > import foo > import bar > > and then from outside the package, do this: > > import tests > > Now tests.foo and tests.bar will exist. I've been reading up on packages, but I didn't find anything like that in the documentation, all I found was the meaning of __all__. If I import the modules explicitly there, there's no need to define __all__, unless there are some I don't want to import there, right? Well, I'll try it and see. ;) Steven, thank you for this explanation! Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From duggar at alum.mit.edu Tue Nov 23 11:34:14 2010 From: duggar at alum.mit.edu (Keith H Duggar) Date: Tue, 23 Nov 2010 08:34:14 -0800 (PST) Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014020136.6e85d70b@tritium.streitmacht.eu> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> <08823dd4-588a-4729-a660-711e266c96b0@y23g2000yqd.googlegroups.com> <396f8de7-ece5-4e9c-919b-886eb65ae14a@a30g2000vbt.googlegroups.com> Message-ID: <967678a1-fc5d-4b61-86c5-79a298999582@p1g2000vbo.googlegroups.com> On Nov 23, 10:34?am, Raffael Cavallaro wrote: > On 2010-11-23 10:08:12 -0500, Keith H Duggar said: > > On Nov 22, 5:12?pm, Raffael Cavallaro wrote: > > > On 2010-11-22 11:25:34 -0500, scattered said: > > > > > > > And you don't think that [JH] could write a book about Haskell > > > > if he honestly came to think that it were a superior all-aroung > > > > language? > > > > > > Until he actually does, he has a financial interest in trash-talking > > > Haskell. This makes anything he says about Haskell suspect. > > > > > > > ?The fact that he *didn't* mindlessly reject [musical note lang] in favor of > > > > [Irish Ship Of The Desert] when [musical note lang] came out (despite > > > > the fact that at the time his company > > > > was deeply (exclusively?) invested in [Irish Ship Of The Desert] and > > > > arguably had a vested > > > > interest in having [musical note lang] fail to gain support) suggests > > > > that he is able > > > > to fairly evaluate the merits of other languages. > > > > > > No, it suggests that he saw that supporting the Irish Ship Of The > > > Desert meant going up against Microsoft, so he jumped to the MS > > > supported variant of the Donut Dromedary. > > > > > > You miss the fundamental point; having a financial interest in the > > > outcome of a debate makes anything that person says an advertisement > > > for his financial interests, not a fair assessment. > > > > There is a well-known name for such illogical reasoning: ad hominem. > > When a person poses an /argument/, nothing personal outside of the > > /argument/ is relevant. Thus, your claim that "anything that person > > says ..." is not only obvious hyperbole it is also illogical. > > > > It is a common refuge of those who cannot support their position > > with fact and logic. On more than one occasion Jon Harrop has all > > but crushed Ertugrul in this very forum with /source code/; that > > is as objective as it gets. > > You don't understand ad hominem: > > "The ad hominem is a classic logical fallacy,[2] but it is not always > fallacious. For in some instances, questions of personal conduct, > character, motives, etc., are legitimate and relevant to the issue.[3]" > > Source: > > Sometimes the person's conduct and motives *are relevant* to the point > under discussion. Financial conflict of interest is a perfect example > where it *is* legitimate and relevant to explore a person's motives and > conduct outside of the debate. > > In this case, JH's conduct outside of the debate (i.e., the fact that > he earns his living by selling tools and training for a particular set > of languages) and his motives (i.e., he is therefore financially > motivated to present these languages in the best possible light and to > trash-talk other languages), render his arguments in the debate > inherently suspect. You don't understand the implications of your own words: "having a financial interest in the outcome of a debate makes anything that person says an advertisement for his financial interests, not a fair assessment." is substantially different from "render his arguments in the debate inherently suspect." Do you understand how? Hint, see my comment regarding "hyperbole" and also consider the relationship between the qualifier "anything" and universal quantification. I think if you think a bit more carefully you will come to see how your original statement was indeed fallacious ad hominem. (And that specific example remains so regardless of which common approach to informal logic you take ie whether you choose one that is more or less sympathetic to ad hominem in general.) KHD From darcy at druid.net Tue Nov 23 11:42:29 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 23 Nov 2010 11:42:29 -0500 Subject: Scheme as a virtual machine? In-Reply-To: References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014020136.6e85d70b@tritium.streitmacht.eu> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> <08823dd4-588a-4729-a660-711e266c96b0@y23g2000yqd.googlegroups.com> <396f8de7-ece5-4e9c-919b-886eb65ae14a@a30g2000vbt.googlegroups.com> Message-ID: <20101123114229.69c6609e.darcy@druid.net> On Tue, 23 Nov 2010 10:34:22 -0500 Raffael Cavallaro wrote: > On 2010-11-23 10:08:12 -0500, Keith H Duggar said: > > There is a well-known name for such illogical reasoning: ad hominem. > You don't understand ad hominem: Perhaps you don't understand it. > "The ad hominem is a classic logical fallacy,[2] but it is not always > fallacious. For in some instances, questions of personal conduct, > character, motives, etc., are legitimate and relevant to the issue.[3]" So, explain how motive makes the logic wrong in this case then. > In this case, JH's conduct outside of the debate (i.e., the fact that > he earns his living by selling tools and training for a particular set > of languages) and his motives (i.e., he is therefore financially > motivated to present these languages in the best possible light and to > trash-talk other languages), render his arguments in the debate > inherently suspect. Fine. Suspect his arguments to the point that you examine them closely and then explain what you found erroneous in them. Don't just claim that we should dismiss them because of who made them. You know, it's just possible that Jon actually investigated Haskell before choosing to focus on CL. That would make his opinion carry more weight, not less. Remind me, how is this relevant to Python? -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From huisky at gmail.com Tue Nov 23 12:47:30 2010 From: huisky at gmail.com (huisky) Date: Tue, 23 Nov 2010 09:47:30 -0800 (PST) Subject: Time and date operation Message-ID: <1550b9d2-b8c4-48f1-be27-a3df3ad2eb3e@32g2000yqz.googlegroups.com> Hi everyone, Could you anybody shed lights to me? Say I have two dics. >>> cstart defaultdict(, {15424: ['Dec', '6', '18:57:40'], 552: ['Dec', '7', '09:31:00'], 15500: ['Dec', '6', '20:17:02'], 18863: ['Dec', '7', '13:14:47'], 18291: ['Dec', '6', '21:01:17'], 18969: ['Dec', '7', '14:28:42'], 18937: ['Dec', '7', '14:21:34']}) >>> ccompl defaultdict(, {15424: ['Dec', '6', '19:42:55'], 18291: ['Dec', '6', '21:01:28'], 15500: ['Dec', '6', '20:26:03'], 18863: ['Dec', '7', '13:24:07']}) and I need to calculate the difference time if the key value is the same in both dics. thanks in advance Huisky From clp2 at rebertia.com Tue Nov 23 13:11:33 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 23 Nov 2010 10:11:33 -0800 Subject: Time and date operation In-Reply-To: <1550b9d2-b8c4-48f1-be27-a3df3ad2eb3e@32g2000yqz.googlegroups.com> References: <1550b9d2-b8c4-48f1-be27-a3df3ad2eb3e@32g2000yqz.googlegroups.com> Message-ID: On Tue, Nov 23, 2010 at 9:47 AM, huisky wrote: > Hi everyone, > > Could you anybody shed lights to me? Say I have two dics. >>>> cstart > defaultdict(, {15424: ['Dec', '6', '18:57:40'], 552: > ['Dec', '7', '09:31:00'], 15500: ['Dec', '6', '20:17:02'], 18863: > ['Dec', '7', '13:14:47'], 18291: ['Dec', '6', '21:01:17'], 18969: > ['Dec', '7', '14:28:42'], 18937: ['Dec', '7', '14:21:34']}) >>>> ccompl > defaultdict(, {15424: ['Dec', '6', '19:42:55'], 18291: > ['Dec', '6', '21:01:28'], 15500: ['Dec', '6', '20:26:03'], 18863: > ['Dec', '7', '13:24:07']}) > > and I need to calculate the difference time if the key value is the > same in both dics. Create datetime.datetime objects. Subtract one from another and you'll get a datetime.timedelta object representing the difference between them. The fine manual: http://docs.python.org/library/datetime.html#datetime-objects Cheers, Chris -- http://blog.rebertia.com From clp2 at rebertia.com Tue Nov 23 13:50:19 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 23 Nov 2010 10:50:19 -0800 Subject: Time and date operation In-Reply-To: <002701cb8b3e$3c7c6690$b57533b0$@com> References: <1550b9d2-b8c4-48f1-be27-a3df3ad2eb3e@32g2000yqz.googlegroups.com> <002701cb8b3e$3c7c6690$b57533b0$@com> Message-ID: > -----Original Message----- > From: clp2 at rebertia.com [mailto: clp2 at rebertia.com] > Sent: 2010?11?23? 19:12 > To: huisky > Cc: python-list at python.org > Subject: Re: Time and date operation > > On Tue, Nov 23, 2010 at 9:47 AM, huisky wrote: >> Hi everyone, >> >> Could you anybody shed lights to me? Say I have two dics. >>>>> cstart >> defaultdict(, {15424: ['Dec', '6', '18:57:40'], 552: >> ['Dec', '7', '09:31:00'], 15500: ['Dec', '6', '20:17:02'], 18863: >> ['Dec', '7', '13:14:47'], 18291: ['Dec', '6', '21:01:17'], 18969: >> ['Dec', '7', '14:28:42'], 18937: ['Dec', '7', '14:21:34']}) >>>>> ccompl >> defaultdict(, {15424: ['Dec', '6', '19:42:55'], 18291: >> ['Dec', '6', '21:01:28'], 15500: ['Dec', '6', '20:26:03'], 18863: >> ['Dec', '7', '13:24:07']}) >> >> and I need to calculate the difference time if the key value is the >> same in both dics. > > Create datetime.datetime objects. Subtract one from another and you'll > get a datetime.timedelta object representing the difference between > them. > The fine manual: http://docs.python.org/library/datetime.html#datetime-objects > On Tue, Nov 23, 2010 at 10:42 AM, Huisky wrote: > Hi, > > Thanks. I'm wondering is datetime.datetime objects able to read 'Dec', for example? Yes. Use the %b format directive when calling datetime.datetime.strptime(). http://docs.python.org/library/datetime.html#datetime.datetime.strptime http://docs.python.org/library/time.html#time.strftime Cheers, Chris -- http://blog.rebertia.com From bnbowman at gmail.com Tue Nov 23 14:28:56 2010 From: bnbowman at gmail.com (Brett Bowman) Date: Tue, 23 Nov 2010 11:28:56 -0800 Subject: Subprocess Call works on Windows, but not Ubuntu Message-ID: I ran into an interesting problem trying to spawn a subprocess, so I thought I'd ask if the experts could explain it to me. I'm spawning a subprocess to run "pdf2txt.py", which is a tool that is distributed with PDFminer to do moderately advanced text-dumps of PDFs. Yet when I run the same code on my two dev machines - one Win XP, the other Ubuntu 10.04 or 10.10 - it only works on the former and not the later. And its not terribly complicated code. # Code Start sp_line = 'python pdf2txt.py -p 1 -o %s "%s"' % ('temp.out', pdf_filename) print sp_line sp = subprocess.Popen(sp_line) sp.wait() with open('temp.out', 'r') as pdf_handle: #Do stuff to read the file The output from the print statements reads: python pdf2txt.py -p 1 -o temp.out "Aarts et al (2009).pdf" That command works on both systems when copied directly to the command-line, and the python script it is a part of works on the Windows machine, but I can't the script to work on Ubuntu for the life of me. What am I missing? /b/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Tue Nov 23 14:37:05 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 23 Nov 2010 11:37:05 -0800 Subject: Subprocess Call works on Windows, but not Ubuntu In-Reply-To: References: Message-ID: On Tue, Nov 23, 2010 at 11:28 AM, Brett Bowman wrote: > I ran into an interesting problem trying to spawn a subprocess, so I thought > I'd ask if the experts could explain it to me. ?I'm spawning a subprocess to > run "pdf2txt.py", which is a tool that is distributed with PDFminer to do > moderately advanced text-dumps of PDFs. ?Yet when I run the same code on my > two dev machines - one Win XP, the other Ubuntu 10.04 or 10.10 - it only > works on the former and not the later. And its not terribly complicated > code. > # Code Start > sp_line = 'python pdf2txt.py -p 1 -o %s "%s"' % ('temp.out', pdf_filename) > print sp_line > sp = subprocess.Popen(sp_line) > python pdf2txt.py -p 1 -o temp.out "Aarts et al (2009).pdf" > That command works on both systems when copied directly to the command-line, > and the python script it is a part of works on the Windows machine, but I > can't the script to work on Ubuntu for the life of me. ?What am I missing? Quoting the docs (for the Nth time; emphasis added): """ On Unix, with shell=False (default): args should normally be a sequence. ***If a string is specified for args***, it will be used as the name or path of the program to execute; ***this will only work if the program is being given no arguments.*** """ http://docs.python.org/library/subprocess.html#subprocess.Popen Fixed version: sp_args = ['python', 'pdf2txt.py', '-p', '1', '-o', 'temp.out', pdf_filename] sp = subprocess.Popen(sp_args) Cheers, Chris -- http://blog.rebertia.com From burton at userful.com Tue Nov 23 14:53:25 2010 From: burton at userful.com (Burton Samograd) Date: Tue, 23 Nov 2010 12:53:25 -0700 Subject: Collect output to string Message-ID: Hello, I was wondering if there is any way in python to 'collect output to string' as in some lisps/schemes. Output being, printed output to the console using print. Thanks. -- Burton Samograd From clp2 at rebertia.com Tue Nov 23 15:02:47 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 23 Nov 2010 12:02:47 -0800 Subject: Collect output to string In-Reply-To: References: Message-ID: On Tue, Nov 23, 2010 at 11:53 AM, Burton Samograd wrote: > Hello, > > I was wondering if there is any way in python to 'collect output to > string' as in some lisps/schemes. ?Output being, printed output to the > console using print. Rebind sys.stdout to a StringIO object. http://docs.python.org/library/sys.html#sys.stdout http://docs.python.org/library/stringio.html Cheers, Chris -- http://blog.rebertia.com From bnbowman at gmail.com Tue Nov 23 15:31:25 2010 From: bnbowman at gmail.com (Brett Bowman) Date: Tue, 23 Nov 2010 12:31:25 -0800 Subject: Subprocess Call works on Windows, but not Ubuntu In-Reply-To: References: Message-ID: Ah, that fixed it. Thank you. On Tue, Nov 23, 2010 at 11:37 AM, Chris Rebert wrote: > On Tue, Nov 23, 2010 at 11:28 AM, Brett Bowman wrote: > > I ran into an interesting problem trying to spawn a subprocess, so I > thought > > I'd ask if the experts could explain it to me. I'm spawning a subprocess > to > > run "pdf2txt.py", which is a tool that is distributed with PDFminer to do > > moderately advanced text-dumps of PDFs. Yet when I run the same code on > my > > two dev machines - one Win XP, the other Ubuntu 10.04 or 10.10 - it only > > works on the former and not the later. And its not terribly complicated > > code. > > # Code Start > > sp_line = 'python pdf2txt.py -p 1 -o %s "%s"' % ('temp.out', > pdf_filename) > > print sp_line > > sp = subprocess.Popen(sp_line) > > > python pdf2txt.py -p 1 -o temp.out "Aarts et al (2009).pdf" > > That command works on both systems when copied directly to the > command-line, > > and the python script it is a part of works on the Windows machine, but I > > can't the script to work on Ubuntu for the life of me. What am I > missing? > > Quoting the docs (for the Nth time; emphasis added): > """ > On Unix, with shell=False (default): args should normally be a > sequence. ***If a string is specified for args***, it will be used as > the name or path of the program to execute; ***this will only work if > the program is being given no arguments.*** > """ http://docs.python.org/library/subprocess.html#subprocess.Popen > > Fixed version: > sp_args = ['python', 'pdf2txt.py', '-p', '1', '-o', 'temp.out', > pdf_filename] > sp = subprocess.Popen(sp_args) > > Cheers, > Chris > -- > http://blog.rebertia.com > -------------- next part -------------- An HTML attachment was scrubbed... URL: From burton at userful.com Tue Nov 23 15:59:02 2010 From: burton at userful.com (Burton Samograd) Date: Tue, 23 Nov 2010 13:59:02 -0700 Subject: Collect output to string References: Message-ID: Chris Rebert writes: > On Tue, Nov 23, 2010 at 11:53 AM, Burton Samograd wrote: >> Hello, >> >> I was wondering if there is any way in python to 'collect output to >> string' as in some lisps/schemes. ?Output being, printed output to the >> console using print. > > Rebind sys.stdout to a StringIO object. > http://docs.python.org/library/sys.html#sys.stdout > http://docs.python.org/library/stringio.html Thanks for the tip. Here's my function: def with_output_to_string(f, args): oldstdout = sys.stdout buffer = StringIO.StringIO() sys.stdout = buffer apply(f, args) sys.stdout = oldstdout return buffer.getvalue() Any way I could improve it? -- Burton Samograd From astar at spamcop.net Tue Nov 23 16:13:32 2010 From: astar at spamcop.net (astar) Date: Tue, 23 Nov 2010 13:13:32 -0800 (PST) Subject: progamming approach review, child processes Message-ID: <9bf2b0b6-1c34-40c6-b85f-27836d3b5f2d@o23g2000prh.googlegroups.com> So I have not done much with child processes before. I have an input of programs to be updated, a child process that does the compiles and links (with a log output to an individual file), and a process wait at the end. Except the child process can hang (at the moment, the problem that might show up is: waiting for input). At which point a convenience becomes a hinderance. As it happens the idea of doing the compiles in parallel is supported by the ports system I am working with. So I thought I could avoid the wait syntax, do a lot of children, save all the process hmm I am not sure what to call the pointers, and after a while interrogate the process information to see if all the children got done. At some point, I could think a child is hung and maybe do some useful reporting. Realize that this might be the next day because the compiles might take a while. Is this a reasonable approach? Thank you for your consideration. Possibly pointless information: openbsd 4.8 workstation, packages, but using the port system, want only to compile packages I have installed. There is a utility to tell me which packages are out of date. And I really know I could use pkg_add -u. I did some attachments of the programs, but I suppose they will get scrubbed.. python is I think 2.6.5? From ian.g.kelly at gmail.com Tue Nov 23 16:15:46 2010 From: ian.g.kelly at gmail.com (Ian) Date: Tue, 23 Nov 2010 13:15:46 -0800 (PST) Subject: Collect output to string References: Message-ID: <22e3a2c0-a85b-4d2a-8a4f-ebb719807467@y19g2000prb.googlegroups.com> On Nov 23, 1:59?pm, Burton Samograd wrote: > Thanks for the tip. ?Here's my function: > > def with_output_to_string(f, args): > ? ? ?oldstdout = sys.stdout > ? ? ?buffer = StringIO.StringIO() > ? ? ?sys.stdout = buffer > ? ? ?apply(f, args) > ? ? ?sys.stdout = oldstdout > ? ? ?return buffer.getvalue() > > Any way I could improve it? You should wrap the inner function call in a try-finally call to ensure that the old stdout gets restored even if f raises an exception. Also, the `apply` function is deprecated. Use `f(*args)` instead. The function as a whole would be a bit more Pythonic if written as a decorator IMO, but that's your call. Cheers, Ian From python at mrabarnett.plus.com Tue Nov 23 16:17:53 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 23 Nov 2010 21:17:53 +0000 Subject: Collect output to string In-Reply-To: References: Message-ID: <4CEC2F81.4030106@mrabarnett.plus.com> On 23/11/2010 20:59, Burton Samograd wrote: > Chris Rebert writes: > >> On Tue, Nov 23, 2010 at 11:53 AM, Burton Samograd wrote: >>> Hello, >>> >>> I was wondering if there is any way in python to 'collect output to >>> string' as in some lisps/schemes. Output being, printed output to the >>> console using print. >> >> Rebind sys.stdout to a StringIO object. >> http://docs.python.org/library/sys.html#sys.stdout >> http://docs.python.org/library/stringio.html > > Thanks for the tip. Here's my function: > > def with_output_to_string(f, args): > oldstdout = sys.stdout > buffer = StringIO.StringIO() > sys.stdout = buffer > apply(f, args) > sys.stdout = oldstdout > return buffer.getvalue() > > Any way I could improve it? > Use a try...finally block in an exception occurs: try: apply(f, args) finally: sys.stdout = oldstdout and possibly also replace the older: apply(f, args) with the newer: f(*args) You might also want to handle keyword arguments. From clp2 at rebertia.com Tue Nov 23 16:42:10 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 23 Nov 2010 13:42:10 -0800 Subject: Collect output to string In-Reply-To: <22e3a2c0-a85b-4d2a-8a4f-ebb719807467@y19g2000prb.googlegroups.com> References: <22e3a2c0-a85b-4d2a-8a4f-ebb719807467@y19g2000prb.googlegroups.com> Message-ID: On Tue, Nov 23, 2010 at 1:15 PM, Ian wrote: > On Nov 23, 1:59?pm, Burton Samograd wrote: >> Thanks for the tip. ?Here's my function: >> >> def with_output_to_string(f, args): >> ? ? ?oldstdout = sys.stdout >> ? ? ?buffer = StringIO.StringIO() >> ? ? ?sys.stdout = buffer >> ? ? ?apply(f, args) >> ? ? ?sys.stdout = oldstdout >> ? ? ?return buffer.getvalue() >> >> Any way I could improve it? > > You should wrap the inner function call in a try-finally call to > ensure that the old stdout gets restored even if f raises an > exception. > > Also, the `apply` function is deprecated. ?Use `f(*args)` instead. > > The function as a whole would be a bit more Pythonic if written as a > decorator IMO, but that's your call. A context manager could also be worth considering. http://docs.python.org/library/stdtypes.html#context-manager-types Cheers, Chris From tjreedy at udel.edu Tue Nov 23 18:22:41 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 23 Nov 2010 18:22:41 -0500 Subject: Collect output to string In-Reply-To: References: Message-ID: On 11/23/2010 3:02 PM, Chris Rebert wrote: > On Tue, Nov 23, 2010 at 11:53 AM, Burton Samograd wrote: >> Hello, >> >> I was wondering if there is any way in python to 'collect output to >> string' as in some lisps/schemes. Output being, printed output to the >> console using print. > > Rebind sys.stdout to a StringIO object. > http://docs.python.org/library/sys.html#sys.stdout > http://docs.python.org/library/stringio.html If you are using print or print(), you can redirect output to the StringIO object with >>sfile or file=sfile. I use the latter in a custom test function where I normally want output to the screen but occasionally want to capture test reports. -- Terry Jan Reedy From es at ertes.de Tue Nov 23 18:48:24 2010 From: es at ertes.de (Ertugrul =?UTF-8?B?U8O2eWxlbWV6?=) Date: Wed, 24 Nov 2010 00:48:24 +0100 Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014020136.6e85d70b@tritium.streitmacht.eu> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> <08823dd4-588a-4729-a660-711e266c96b0@y23g2000yqd.googlegroups.com> <396f8de7-ece5-4e9c-919b-886eb65ae14a@a30g2000vbt.googlegroups.com> Message-ID: <20101124004824.7ec98977@tritium.streitmacht.eu> Keith H Duggar wrote: > It is a common refuge of those who cannot support their position with > fact and logic. On more than one occasion Jon Harrop has all but > crushed Ertugrul in this very forum with /source code/; that is as > objective as it gets. Since Jon has financial reasons to invest time doing this and I don't, this is nowhere near "crushing" or "objective". It's simply meaningless. If someone pays me for writing proof code or coming up with challenges, then I will, and I assure you, I would give him a hard time, since I'm an experienced Haskell programmer, who uses it for many different, practical purposes in the real world outside of academia. And I stated explicitly many times that (without being paid) I don't feel like wasting time proving my point to Jon, who would just come up with new arbitrary arguments and challenges anyway, as he does all the time. Jon doesn't and cannot acknowledge valid arguments, so it would be an ongoing, pointless cycle. After all, he was the only one posing stupid challenges on me at all, deliberately constructing problems to be easy to solve in his languages. When I would challenge him, the picture would change, but I think, this is stupid and infantile enough not to do it. In fact, I've even done it once and proved my point that way (which, as always, he didn't acknowledge, but I don't care anymore). Greets, Ertugrul -- nightmare = unsafePerformIO (getWrongWife >>= sex) http://ertes.de/ From gnarlodious at gmail.com Tue Nov 23 21:01:49 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Tue, 23 Nov 2010 18:01:49 -0800 (PST) Subject: CGI FieldStorage instances? References: <1ec25d72-a99e-4fd9-9d50-1ac8c65812e9@z19g2000yqb.googlegroups.com> <6trje65kt71v00339psntb6srgr5qtls5c@4ax.com> <8b8a7842-6249-4c0f-ac97-61bd646b52af@k3g2000vbp.googlegroups.com> Message-ID: On Nov 22, 11:32?pm, Dennis Lee Bieber wrote: > ? ? ? ? Or upgrade to some modernistic framework wherein the application is > a monolithic program and the "name/" portion maps to methods/functions > within the application... Yes, that describes what I am looking for! Is there such a modernistic framework? Links? -- Gnarlie, K5ZN From ian.g.kelly at gmail.com Tue Nov 23 21:22:00 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 23 Nov 2010 19:22:00 -0700 Subject: CGI FieldStorage instances? In-Reply-To: References: <1ec25d72-a99e-4fd9-9d50-1ac8c65812e9@z19g2000yqb.googlegroups.com> <6trje65kt71v00339psntb6srgr5qtls5c@4ax.com> <8b8a7842-6249-4c0f-ac97-61bd646b52af@k3g2000vbp.googlegroups.com> Message-ID: On 11/23/2010 7:01 PM, Gnarlodious wrote: > On Nov 22, 11:32 pm, Dennis Lee Bieber wrote: > >> Or upgrade to some modernistic framework wherein the application is >> a monolithic program and the "name/" portion maps to methods/functions >> within the application... > > Yes, that describes what I am looking for! Is there such a modernistic > framework? Links? Try Django[1] or TurboGears[2]. [1] http://www.djangoproject.com/ [2] http://www.turbogears.org/ Cheers, Ian From stackslip at gmail.com Wed Nov 24 00:55:07 2010 From: stackslip at gmail.com (Garland Fulton) Date: Tue, 23 Nov 2010 20:55:07 -0900 Subject: Arrays Message-ID: Is there a way I can define an Array of and unknown size so I can add and remove to or from it? Are arrays immutable? -------------- next part -------------- An HTML attachment was scrubbed... URL: From iamforufriends at gmail.com Wed Nov 24 01:05:15 2010 From: iamforufriends at gmail.com (DATE@COUPLES) Date: Tue, 23 Nov 2010 22:05:15 -0800 (PST) Subject: BUEATYFUL CHEATING HOUSE WIVES FOR FREE DATING.... Message-ID: <5407e135-6073-4f99-a89e-49eed73ae344@n32g2000pre.googlegroups.com> BUEATYFUL CHEATING HOUSE WIVES FOR FREE DATING.... http://u3.co.za/m3 http://u3.co.za/m3 http://u3.co.za/m3 http://u3.co.za/m3 From ian.g.kelly at gmail.com Wed Nov 24 02:02:14 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 24 Nov 2010 00:02:14 -0700 Subject: Arrays In-Reply-To: References: Message-ID: On 11/23/2010 10:55 PM, Garland Fulton wrote: > Is there a way I can define an Array of and unknown size so I can add > and remove to or from it? Do you mean the arrays of the array module, or NumPy arrays, or something else entirely? In the first case, yes; arrays behave more or less like lists, but more efficiently and with type constraints. In the second case, I believe you have to explicitly resize the array in order to add new elements to it. > Are arrays immutable? No in either case. Cheers, Ian From gallium.arsenide at gmail.com Wed Nov 24 02:45:18 2010 From: gallium.arsenide at gmail.com (John Yeung) Date: Tue, 23 Nov 2010 23:45:18 -0800 (PST) Subject: Ensuring symmetry in difflib.SequenceMatcher Message-ID: <135c0dfc-c382-4dd3-bfaf-8d508e5e648b@j21g2000vba.googlegroups.com> I'm generally pleased with difflib.SequenceMatcher: It's probably not the best available string matcher out there, but it's in the standard library and I've seen worse in the wild. One thing that kind of bothers me is that it's sensitive to which argument you pick as "seq1" and which you pick as "seq2": Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import difflib >>> difflib.SequenceMatcher(None, 'BYRD', 'BRADY').ratio() 0.44444444444444442 >>> difflib.SequenceMatcher(None, 'BRADY', 'BYRD').ratio() 0.66666666666666663 >>> Is this a bug? I am guessing the algorithm is implemented correctly, and that it's just an inherent property of the algorithm used. It's certainly not what I'd call a desirably property. Are there any simple adjustments that can be made without sacrificing (too much) performance? John From caseyalice at adam.com.au Wed Nov 24 03:22:09 2010 From: caseyalice at adam.com.au (Adrian Casey) Date: Wed, 24 Nov 2010 17:52:09 +0930 Subject: pyqt4: multi-threaded database access Message-ID: <38ydnblHjISvVnHRnZ2dnUVZ_rydnZ2d@adnap.net.au> I have a PyQt4 multi-threaded application which accesses many hosts concurrently via ssh. I would like each thread to have access to a database so that it can look up details about the particular system it is connected to. The easy way is to have each thread create a connection to the database. However, this is wasteful and likely to exhaust the maximum number of connections the database (postgresql) allows. Instead, I would like to share a single database connection between all threads. In PyQt4, this is not possible since the database connection can only be used by the thread which created it. So, I'm thinking I'll create a thread to just handle database queries. The worker threads will communicate with the database thread using signals and slots. My question is, if I have 20 worker threads who have emitted a signal which results in a database query, how do I ensure that the query results are sent back to the originating thread? Ideas, examples anyone? Thanks. Adrian. From wolfgang at rohdewald.de Wed Nov 24 03:49:50 2010 From: wolfgang at rohdewald.de (Wolfgang Rohdewald) Date: Wed, 24 Nov 2010 09:49:50 +0100 Subject: Ensuring symmetry in difflib.SequenceMatcher In-Reply-To: <135c0dfc-c382-4dd3-bfaf-8d508e5e648b@j21g2000vba.googlegroups.com> References: <135c0dfc-c382-4dd3-bfaf-8d508e5e648b@j21g2000vba.googlegroups.com> Message-ID: <201011240949.50519.wolfgang@rohdewald.de> On Mittwoch 24 November 2010, John Yeung wrote: > Are there any > simple adjustments that can be made without sacrificing (too > much) performance? >>> difflib.SequenceMatcher(None,*sorted(('BYRD','BRADY'))).ratio() 0.66666666666666663 -- Wolfgang From whitequill.bj at gmail.com Wed Nov 24 04:02:37 2010 From: whitequill.bj at gmail.com (Bj Raz) Date: Wed, 24 Nov 2010 04:02:37 -0500 Subject: factorial of negative one (-1) In-Reply-To: References: <87r5f55qj5.fsf@xemacs.org> <87vd4gm3vb.fsf@xemacs.org> Message-ID: On Tue, Nov 2, 2010 at 12:57 PM, Terry Reedy wrote: > On 11/2/2010 6:11 AM, Hrvoje Niksic wrote: > > 1.1 .hex() >>>>> >>>> '0x1.199999999999ap+0' >> >> Here it is immediately obvious that the final digit of the infinite >> sequence "1.1999..." is rounded from 9 to a. Printing the number with >> any more digits would just reveal zeros, as expected. >> >> Does anyone know why Python doesn't accept hex float literals in source >> code? >> > > Assuming that the parser would have no problem with them: > 1. the format is relatively recent > 2. you can write float.fromhex('') > 3. it never occurred to anyone to do so > 4. literals are values supplied by the programmer; hex float values are > rare and when they do occur, they are usually the stored output of a > previous .hex() in Python or similar in other languages. > 5. too easy to confuse in quick reading with normal float literals > 6. the format is a bit weird and too esoteric for most programmers; they > should not be part of the basic syntax that everyone has to learn; someone > who reads float.fromhex(something) can look it up. > > -- > Terry Jan Reedy > > > -- > http://mail.python.org/mailman/listinfo/python-list > I have just realized that there is a program called PyNum that would be of great help to me, but I can't seem to figure out how to use it after installing, or how to build it with Python 2.7 -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Wed Nov 24 04:43:41 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 24 Nov 2010 10:43:41 +0100 Subject: Ensuring symmetry in difflib.SequenceMatcher References: <135c0dfc-c382-4dd3-bfaf-8d508e5e648b@j21g2000vba.googlegroups.com> Message-ID: John Yeung wrote: > I'm generally pleased with difflib.SequenceMatcher: It's probably not > the best available string matcher out there, but it's in the standard > library and I've seen worse in the wild. One thing that kind of > bothers me is that it's sensitive to which argument you pick as "seq1" > and which you pick as "seq2": > > Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit > (Intel)] on > win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> import difflib >>>> difflib.SequenceMatcher(None, 'BYRD', 'BRADY').ratio() > 0.44444444444444442 >>>> difflib.SequenceMatcher(None, 'BRADY', 'BYRD').ratio() > 0.66666666666666663 >>>> > > Is this a bug? I am guessing the algorithm is implemented correctly, > and that it's just an inherent property of the algorithm used. It's > certainly not what I'd call a desirably property. Are there any > simple adjustments that can be made without sacrificing (too much) > performance? def symmetric_ratio(a, b, S=difflib.SequenceMatcher): return (S(None, a, b).ratio() + S(None, b, a).ratio())/2.0 I'm expecting 50% performance loss ;) Seriously, have you tried to calculate the ratio with realistic data? Without looking into the source I would expect the two ratios to get more similar. Peter From xlizzard at 163.com Wed Nov 24 05:59:26 2010 From: xlizzard at 163.com (xlizzard) Date: Wed, 24 Nov 2010 18:59:26 +0800 (CST) Subject: I got a ImportError,help~! Message-ID: HI, I am a newer to python(my version is 3.1.2),recently I got a IDE named Eric(http://eric-ide.python-projects.org/index.html) to study and on this main page I downloaded a tutorial named "minibrowser". http://eric-ide.python-projects.org/tutorials/MiniBrowser/index.html But when I run this source ,I got the follow Error: Traceback (most recent call last): File "C:\minibrowser\minibrowser\minibrowser.py", line 3, in from ui.mainwindow import MainWindow File "C:\minibrowser\minibrowser\ui\mainwindow.py", line 10, in from Ui_mainwindow import Ui_MainWindow ImportError: No module named Ui_mainwindow I don't understand what's wrong?! The folder structure of the source just like this A.py+ -B.py -C.py A call B,B call C in the same folder ,and "not found"? Can anyone help me,thanks a lot~! -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: minibrowser.zip Type: application/x-zip-compressed Size: 3501 bytes Desc: not available URL: From stefan_ml at behnel.de Wed Nov 24 06:18:38 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 24 Nov 2010 12:18:38 +0100 Subject: Arrays In-Reply-To: References: Message-ID: Garland Fulton, 24.11.2010 06:55: > Is there a way I can define an Array of and unknown size so I can add and > remove to or from it? > > Are arrays immutable? Python has lists and tuples as basic data structures. Tuples are completely immutable, lists are completely mutable. If you want a container that has a fixed size but allows changing items, use a list and avoid calling .append() and .remove() to change items in favour of direct item assignments. If you want a completely mutable container, use a list and use it as you see fit. If you want a stack, a list will do. If you want a queue, a deque is a better option. In any case, if you tell us more about what you actually want to do, we can give better suggestions. Stefan From huisky at gmail.com Wed Nov 24 07:45:54 2010 From: huisky at gmail.com (huisky) Date: Wed, 24 Nov 2010 04:45:54 -0800 (PST) Subject: Read time and date from a text file Message-ID: <0a483e70-619d-4cb7-8fef-bf81b31295e5@j25g2000yqa.googlegroups.com> Hi, As a newbie, I posted my question here again. say i have two dics read from a text file by 'split'. >>> cstart defaultdict(, {15424: ['Dec', '6', '18:57:40'], 552: ['Dec', '7', '09:31:00'], 15500: ['Dec', '6', '20:17:02'], 18863: ['Dec', '7', '13:14:47'], 18291: ['Dec', '6', '21:01:17'], 18969: ['Dec', '7', '14:28:42'], 18937: ['Dec', '7', '14:21:34']}) >>> ccompl defaultdict(, {15424: ['Dec', '6', '19:42:55'], 18291: ['Dec', '6', '21:01:28'], 15500: ['Dec', '6', '20:26:03'], 18863: ['Dec', '7', '13:24:07']}) and I need to calculate the difference time if the key value is the same in both dics. Someone suggested me to use the module 'datetime', but I'm still wondering how to make it work. I mean how to assign ['Dec','6','21:01:17'] to a 'datetime' object and then do the datetime operation. >>>time=datetime.datetime(cstart[18291]) does NOT work. thanks in advance Huisky From fetchinson at googlemail.com Wed Nov 24 08:02:21 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Wed, 24 Nov 2010 14:02:21 +0100 Subject: inverse of a matrix with Fraction entries Message-ID: I guess this is a question to folks with some numpy background (but not necessarily). I'm using fractions.Fraction as entries in a matrix because I need to have very high precision and fractions.Fraction provides infinite precision (as I've learned from advice from this list). Now I need to calculate its inverse. Can numpy help in this regard? Can I tell numpy that the inverse matrix should also have entries in fractions.Fraction? Or numpy can only do floating point calculations? Probably it doesn't matter but the matrix has all components non-zero and is about a thousand by thousand in size. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From tjandacw at cox.net Wed Nov 24 08:05:23 2010 From: tjandacw at cox.net (Tim Williams) Date: Wed, 24 Nov 2010 05:05:23 -0800 (PST) Subject: Read time and date from a text file References: <0a483e70-619d-4cb7-8fef-bf81b31295e5@j25g2000yqa.googlegroups.com> Message-ID: <87f52439-6615-4be7-8f99-5820b41c0e09@s4g2000yql.googlegroups.com> On Nov 24, 7:45?am, huisky wrote: > Hi, > > As a newbie, I posted my question here again. > say i have two dics read from a text file by 'split'. > > >>> cstart > > defaultdict(, {15424: ['Dec', '6', '18:57:40'], 552: > ['Dec', '7', '09:31:00'], 15500: ['Dec', '6', '20:17:02'], 18863: > ['Dec', '7', '13:14:47'], 18291: ['Dec', '6', '21:01:17'], 18969: > ['Dec', '7', '14:28:42'], 18937: ['Dec', '7', '14:21:34']}) > > >>> ccompl > > defaultdict(, {15424: ['Dec', '6', '19:42:55'], 18291: > ['Dec', '6', '21:01:28'], 15500: ['Dec', '6', '20:26:03'], 18863: > ['Dec', '7', '13:24:07']}) > > and I need to calculate the difference time if the key value is the > same in both dics. > > Someone suggested me to use the module 'datetime', but I'm still > wondering how to make it work. > I mean how to assign ['Dec','6','21:01:17'] to a 'datetime' object and > then do the datetime operation. > > >>>time=datetime.datetime(cstart[18291]) ? ? ? does NOT work. > > thanks in advance > Huisky You can use datetime.datetime.strptime() to create a datetime object from a string representing a date >>> import datetime >>> datetime.datetime.strptime('Dec 7 13:24:07','%b %d %H:%M:%S') datetime.datetime(1900, 12, 7, 13, 24, 7) Of course, you need to put in the correct year. datetime.strptime(date_string, format) Return a datetime corresponding to date_string, parsed according to format. This is equivalent to datetime(*(time.strptime(date_string, format)[0:6])). ValueError is raised if the date_string and format can?t be parsed by time.strptime() or if it returns a value which isn?t a time tuple. From __peter__ at web.de Wed Nov 24 08:09:31 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 24 Nov 2010 14:09:31 +0100 Subject: Read time and date from a text file References: <0a483e70-619d-4cb7-8fef-bf81b31295e5@j25g2000yqa.googlegroups.com> Message-ID: huisky wrote: > As a newbie, I posted my question here again. > say i have two dics read from a text file by 'split'. Please don't start a new thread when you are still asking about the same topic. >>>> cstart > > defaultdict(, {15424: ['Dec', '6', '18:57:40'], 552: > ['Dec', '7', '09:31:00'], 15500: ['Dec', '6', '20:17:02'], 18863: > ['Dec', '7', '13:14:47'], 18291: ['Dec', '6', '21:01:17'], 18969: > ['Dec', '7', '14:28:42'], 18937: ['Dec', '7', '14:21:34']}) >>>> ccompl > > defaultdict(, {15424: ['Dec', '6', '19:42:55'], 18291: > ['Dec', '6', '21:01:28'], 15500: ['Dec', '6', '20:26:03'], 18863: > ['Dec', '7', '13:24:07']}) I think you should use a normal dict. A default value of 0 doesn't make much sense here. > and I need to calculate the difference time if the key value is the > same in both dics. > > Someone suggested me to use the module 'datetime', but I'm still > wondering how to make it work. > I mean how to assign ['Dec','6','21:01:17'] to a 'datetime' object and > then do the datetime operation. >>>>time=datetime.datetime(cstart[18291]) does NOT work. Chris Rebert also suggested that you use the strptime() method. To spell it out a bit: >>> s = " ".join(cstart[18291]) >>> s 'Dec 6 21:01:17' >>> datetime.datetime.strptime(s, "%b %d %H:%M:%S") datetime.datetime(1900, 12, 6, 21, 1, 17) You can learn about the format codes here: http://docs.python.org/library/time.html#time.strftime Note that strptime() assumes 1900 as the year which may lead to errors in leapyears and when start and completion time are in different years. Peter From huisky at gmail.com Wed Nov 24 08:17:11 2010 From: huisky at gmail.com (huisky) Date: Wed, 24 Nov 2010 05:17:11 -0800 (PST) Subject: Read time and date from a text file References: <0a483e70-619d-4cb7-8fef-bf81b31295e5@j25g2000yqa.googlegroups.com> Message-ID: <8b2ad59a-1bbb-4e15-b585-7d9900e60dbb@32g2000yqz.googlegroups.com> On Nov 24, 2:09?pm, Peter Otten <__pete... at web.de> wrote: > huisky wrote: > > As a newbie, I posted my question here again. > > say i have two dics read from a text file by 'split'. > > Please don't start a new thread when you are still asking about the same > topic. > > >>>> cstart > > > defaultdict(, {15424: ['Dec', '6', '18:57:40'], 552: > > ['Dec', '7', '09:31:00'], 15500: ['Dec', '6', '20:17:02'], 18863: > > ['Dec', '7', '13:14:47'], 18291: ['Dec', '6', '21:01:17'], 18969: > > ['Dec', '7', '14:28:42'], 18937: ['Dec', '7', '14:21:34']}) > >>>> ccompl > > > defaultdict(, {15424: ['Dec', '6', '19:42:55'], 18291: > > ['Dec', '6', '21:01:28'], 15500: ['Dec', '6', '20:26:03'], 18863: > > ['Dec', '7', '13:24:07']}) > > I think you should use a normal dict. A default value of 0 doesn't make much > sense here. > > > and I need to calculate the difference time if the key value is the > > same in both dics. > > > Someone suggested me to use the module 'datetime', but I'm still > > wondering how to make it work. > > I mean how to assign ['Dec','6','21:01:17'] to a 'datetime' object and > > then do the datetime operation. > >>>>time=datetime.datetime(cstart[18291]) ? ? ? does NOT work. > > Chris Rebert also suggested that you use the strptime() method. To spell it > out a bit: > > >>> s = " ".join(cstart[18291]) > >>> s > 'Dec 6 21:01:17' > >>> datetime.datetime.strptime(s, "%b %d %H:%M:%S") > > datetime.datetime(1900, 12, 6, 21, 1, 17) > > You can learn about the format codes here: > > http://docs.python.org/library/time.html#time.strftime > > Note that strptime() assumes 1900 as the year which may lead to errors in > leapyears and when start and completion time are in different years. > > Peter Thanks a lot, Peter. It helps a lot! I see the problem of year. But the question is the source file does NOT provide the year information. for instance if i have one record as ['Dec','6','21:01:17'], and the other as ['Jan','6','21:01:17'] these two records may be in different year. Will it be a problem to use the 'datetime' do the time difference calculation? regards Huisky Huisky From __peter__ at web.de Wed Nov 24 08:45:13 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 24 Nov 2010 14:45:13 +0100 Subject: Read time and date from a text file References: <0a483e70-619d-4cb7-8fef-bf81b31295e5@j25g2000yqa.googlegroups.com> <8b2ad59a-1bbb-4e15-b585-7d9900e60dbb@32g2000yqz.googlegroups.com> Message-ID: huisky wrote: > I see the problem of year. But the question is the source file does > NOT provide the year information. > for instance if i have one record as ['Dec','6','21:01:17'], and the > other as ['Jan','6','21:01:17'] > these two records may be in different year. Will it be a problem to > use the 'datetime' do the time difference calculation? You have a problem that is independent of Python. You have to guess the correct year to get the correct time interval. One approach would be to use the year from the file's timestamp, then calculate the differences, and whenever you get a negative interval add one year to the end date. This will still result in rare ValueErrors (Feb 29 in non-leapyears) and some silent miscalculations; I fear you'll have to live with that. Peter From ulrich.eckhardt at dominolaser.com Wed Nov 24 09:10:03 2010 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Wed, 24 Nov 2010 15:10:03 +0100 Subject: unittests with different parameters References: Message-ID: Short update on what I've settled for generating test functions for various input data: # test case with common test function class MyTest(unittest.TestCase): def _test_invert_flags(self, input, flags, expected): ? ? ? res = do_invert(input, flags) ? ? ? self.assertEqual(res, expected) # test definitions for the various invert flags tests = [((10, 20), INVERT_NONE, (10, 20)), ? ? ? ? ?((10, 20), INVERT_X, (-10, 20)), ? ? ? ? ?((10, 20), INVERT_Y, (10, -20))] # add test to the test case class for input, flags, expected in tests: def test(self): self._test_invert_flags(input, flags, expected) test.__doc__ = "testing invert flags %s" % flags setattr(MyTest, "test_invert_flags_%s" % flags, test) Yes, the names of the test functions would clash if I tested the same flags twice, in the real code that doesn't happen (enumerate is my friend!). Thanks all! Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From __peter__ at web.de Wed Nov 24 09:12:44 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 24 Nov 2010 15:12:44 +0100 Subject: inverse of a matrix with Fraction entries References: Message-ID: Daniel Fetchinson wrote: > I guess this is a question to folks with some numpy background (but > not necessarily). > > I'm using fractions.Fraction as entries in a matrix because I need to > have very high precision and fractions.Fraction provides infinite > precision (as I've learned from advice from this list). "Infinite" precision only for values that can be expressed as a fraction: >>> Fraction(2)**Fraction(1, 2) 1.4142135623730951 >>> type(_) > Now I need to > calculate its inverse. Can numpy help in this regard? Can I tell numpy > that the inverse matrix should also have entries in > fractions.Fraction? Or numpy can only do floating point calculations? I tried it, and numpy.linalg.inv() converted the Fraction values to float. If you aren't concerned about efficiency it should be easy to do it yourself, in pure python. You could also ask on the numpy mailing list. > Probably it doesn't matter but the matrix has all components non-zero > and is about a thousand by thousand in size. Hmm, where did you get that million of exact fractions from? If some real world data is involved the error introduced by the floating point calculation may be negligable in comparison with the initial measurement uncertainty. Peter From deets at web.de Wed Nov 24 09:25:46 2010 From: deets at web.de (Diez B. Roggisch) Date: Wed, 24 Nov 2010 15:25:46 +0100 Subject: pyqt4: multi-threaded database access References: <38ydnblHjISvVnHRnZ2dnUVZ_rydnZ2d@adnap.net.au> Message-ID: <87fwuqre6t.fsf@web.de> Adrian Casey writes: > I have a PyQt4 multi-threaded application which accesses many hosts > concurrently via ssh. I would like each thread to have access to a > database so that it can look up details about the particular system it > is connected to. > > The easy way is to have each thread create a connection to the database. > However, this is wasteful and likely to exhaust the maximum number of > connections the database (postgresql) allows. Instead, I would like to > share a single database connection between all threads. In PyQt4, this > is not possible since the database connection can only be used by the > thread which created it. > > So, I'm thinking I'll create a thread to just handle database queries. > The worker threads will communicate with the database thread using > signals and slots. > > My question is, if I have 20 worker threads who have emitted a signal > which results in a database query, how do I ensure that the query > results are sent back to the originating thread? > > Ideas, examples anyone? First of all, do you *know* it will exhaust the connections, or is that just some gut feeling? Because postgres can easily handle a few hundered connections, and unless you really are exhausting these, it's the easiest solution. The next advice would be to create a pool of connections (pure python, not Qt). Then you lose the "can only be used by the thread which created it" restriction. Of course you should only use a connection from within one thread at a time, but that shouldn't be an issue. So all you have to make sure is that you fetch & return the connections properly. I would use a context-manager for that: with connection_pooll as connection: do_some_queries(connection) HTH, Diez From gnarlodious at gmail.com Wed Nov 24 09:27:44 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Wed, 24 Nov 2010 06:27:44 -0800 (PST) Subject: CGI FieldStorage instances? References: <1ec25d72-a99e-4fd9-9d50-1ac8c65812e9@z19g2000yqb.googlegroups.com> <6trje65kt71v00339psntb6srgr5qtls5c@4ax.com> <8b8a7842-6249-4c0f-ac97-61bd646b52af@k3g2000vbp.googlegroups.com> Message-ID: <5e2d6196-7667-4bf4-b945-db1464c17453@p7g2000prb.googlegroups.com> On Nov 23, 7:22?pm, Ian Kelly wrote: > Try Django[1] or TurboGears[2]. > > [1]http://www.djangoproject.com/ > [2]http://www.turbogears.org/ Thanks, never understood what those programs were for. -- Gnarlie From benjamin.kaplan at case.edu Wed Nov 24 09:53:05 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 24 Nov 2010 09:53:05 -0500 Subject: I got a ImportError,help~! In-Reply-To: References: Message-ID: 2010/11/24 xlizzard : > HI, > I am a newer to python(my version is 3.1.2),recently I got a IDE named > Eric(http://eric-ide.python-projects.org/index.html) to study > and on this main page I downloaded a tutorial named "minibrowser". > http://eric-ide.python-projects.org/tutorials/MiniBrowser/index.html > But when I run this source ,I got the follow Error: > Traceback (most recent call last): > File "C:\minibrowser\minibrowser\minibrowser.py", line 3, in > from ui.mainwindow import MainWindow > File "C:\minibrowser\minibrowser\ui\mainwindow.py", line 10, in > from Ui_mainwindow import Ui_MainWindow > ImportError: No module named Ui_mainwindow > > I don't understand what's wrong?! > The folder structure of the source just like this > A.py+ > -B.py > -C.py > A call B,B call C in the same folder ,and "not found"? > Can anyone help me,thanks a lot~! > How is that a folder structure? Is A.py a folder? Also, you didn't give us enough information to help. If your files are called A.py, B.py, and C.py, then of course it can't find the Ui_MainWindow module (aside: modules are usually lowercase) > > ________________________________ > ??163/126???????iphone ipad???? > -- > http://mail.python.org/mailman/listinfo/python-list > > From ian.g.kelly at gmail.com Wed Nov 24 09:59:33 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 24 Nov 2010 07:59:33 -0700 Subject: I got a ImportError,help~! In-Reply-To: References: Message-ID: On 11/24/2010 3:59 AM, xlizzard wrote: > HI, > I am a newer to python(my version is 3.1.2),recently I got a IDE named > Eric(http://eric-ide.python-projects.org/index.html) to study > and on this main page I downloaded a tutorial named "**minibrowser". > http://eric-ide.python-projects.org/tutorials/MiniBrowser/index.html > But when I run this source ,I got the follow Error: > Traceback (most recent call last): > File "C:\minibrowser\minibrowser\minibrowser.py", line 3, in > from ui.mainwindow import MainWindow > File "C:\minibrowser\minibrowser\ui\mainwindow.py", line 10, in > from Ui_mainwindow import Ui_MainWindow > ImportError: No module named Ui_mainwindow > I don't understand what's wrong?! > The folder structure of the source just like this > A.py+ > -B.py > -C.py > A call B,B call C in the same folder ,and "not found"? > Can anyone help me,thanks a lot~! That tutorial was probably written for Python 2.X. In Python 3, it is no longer possible to do relative imports using that syntax. If you change the import line to read: from .Ui_mainwindow import Ui_MainWindow or better (making it an absolute import, which is preferred): from ui.mainwindow.Ui_mainwindow import Ui_MainWindow then Python will interpret it as a relative import, and it should work. There could still be other incompatibilities due to the version difference, however. Cheers, Ian From huisky at gmail.com Wed Nov 24 10:02:16 2010 From: huisky at gmail.com (huisky) Date: Wed, 24 Nov 2010 07:02:16 -0800 (PST) Subject: Read time and date from a text file References: <0a483e70-619d-4cb7-8fef-bf81b31295e5@j25g2000yqa.googlegroups.com> <8b2ad59a-1bbb-4e15-b585-7d9900e60dbb@32g2000yqz.googlegroups.com> Message-ID: On Nov 24, 2:45?pm, Peter Otten <__pete... at web.de> wrote: > huisky wrote: > > I see the problem of year. But the question is the source file does > > NOT provide the year information. > > for instance if i have one record as ['Dec','6','21:01:17'], and the > > other as ['Jan','6','21:01:17'] > > these two records may be in different year. Will it be a problem to > > use the 'datetime' do the time difference calculation? > > You have a problem that is independent of Python. You have to guess the > correct year to get the correct time interval. One approach would be to use > the year from the file's timestamp, then calculate the differences, and > whenever you get a negative interval add one year to the end date. > > This will still result in rare ValueErrors (Feb 29 in non-leapyears) and > some silent miscalculations; I fear you'll have to live with that. > > Peter I see, what i'm doing is only for personal usage. should be no problem at all. thanks a lot, Peter! From fetchinson at googlemail.com Wed Nov 24 10:10:54 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Wed, 24 Nov 2010 16:10:54 +0100 Subject: inverse of a matrix with Fraction entries In-Reply-To: References: Message-ID: >> I guess this is a question to folks with some numpy background (but >> not necessarily). >> >> I'm using fractions.Fraction as entries in a matrix because I need to >> have very high precision and fractions.Fraction provides infinite >> precision (as I've learned from advice from this list). > > "Infinite" precision only for values that can be expressed as a fraction: > >>>> Fraction(2)**Fraction(1, 2) > 1.4142135623730951 >>>> type(_) > True, but I only need to add, multiply and divide my fractions in order to end up with the entries in the matrix. >> Now I need to >> calculate its inverse. Can numpy help in this regard? Can I tell numpy >> that the inverse matrix should also have entries in >> fractions.Fraction? Or numpy can only do floating point calculations? > > I tried it, and numpy.linalg.inv() converted the Fraction values to float. > If you aren't concerned about efficiency it should be easy to do it > yourself, in pure python. If there is no other way, that's what I'll try to do. > You could also ask on the numpy mailing list. > >> Probably it doesn't matter but the matrix has all components non-zero >> and is about a thousand by thousand in size. > > Hmm, where did you get that million of exact fractions from? The million of exact fractions are coming from a recursion relation. This recursion relation only adds, multiplies and divides numbers so the end result is always a rational number. > If some real > world data is involved the error introduced by the floating point > calculation may be negligable in comparison with the initial measurement > uncertainty. It's a mathematical problem so no uncertainty is present in the initial values. And even if there was, if there are many orders of magnitude differences between the entries in the matrix floating point does not suffice for various things like eigenvalue calculation and stuff like that. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From korn at freisingnet.de Wed Nov 24 10:12:15 2010 From: korn at freisingnet.de (Johannes Korn) Date: Wed, 24 Nov 2010 16:12:15 +0100 Subject: extensive scatter plot Message-ID: <4ced2b4f$0$6771$9b4e6d93@newsspool3.arcor-online.net> Hi, I would like to produce a scatter plot with roughly 200 mio points. Because the points are so numerous I rather need a point density plot. I use numpy. Right now I loop over the individual data points and make a where query on a meshgrid. ind = where((x_grid == x_points[i]) & (y_grid == y_points[i]) ) counter_grid[ind] += 1 This is really slow. I'm sure there's a better solution already out there. Kind regards! From tom at t0mb.net Wed Nov 24 10:34:52 2010 From: tom at t0mb.net (Tom Boland) Date: Wed, 24 Nov 2010 15:34:52 +0000 Subject: efficient way of splitting a list in to lists where the sum of the values in each does not exceed n Message-ID: <4CED309C.8060500@t0mb.net> I'm trying to find a _nice_ way of taking a list of integers, and splitting them in to lists where the sum of the values does not exceed a threshold. for instance: l = [1, 2, 3, 4, 5, 6] n = 6 nl = [1,2,3], [4], [5], [6] I don't mind if it's done like playing blackjack/pontoon (the card game where you try not to exceed a total of 21), ie. going through the list sequentially, and splitting off the list as soon as the running total would exceed n. A way of efficiently making all lists as close to n as possible would be nice however. I have an algorithm, but it's very ugly. I don't want to paste it, as it's a bit more complicated than I have made out, and wouldn't make too much sense out of context. It's a very ugly blight on my code as well! I wonder if anyone out there has some crazy one-line list comprehension or idiomatic way of doing this beautifully :) Many thanks. Tom. -------------- next part -------------- An HTML attachment was scrubbed... URL: From robert.kern at gmail.com Wed Nov 24 11:02:29 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 24 Nov 2010 10:02:29 -0600 Subject: extensive scatter plot In-Reply-To: <4ced2b4f$0$6771$9b4e6d93@newsspool3.arcor-online.net> References: <4ced2b4f$0$6771$9b4e6d93@newsspool3.arcor-online.net> Message-ID: On 11/24/10 9:12 AM, Johannes Korn wrote: > Hi, > > I would like to produce a scatter plot with roughly 200 mio points. > Because the points are so numerous I rather need a point density plot. > > I use numpy. Right now I loop over the individual data points and make a > where query on a meshgrid. > > ind = where((x_grid == x_points[i])& (y_grid == y_points[i]) ) > counter_grid[ind] += 1 > > This is really slow. I'm sure there's a better solution already out there. > > Kind regards! You will want to ask numpy questions on the numpy mailing list: http://www.scipy.org/Mailing_Lists If you are using a particular plotting package like matplotlib, you will want to ask your plotting questions on their mailing lists. E.g. https://lists.sourceforge.net/lists/listinfo/matplotlib-users If you are doing your own plotting, you will want to use the numpy.histogram2d() function to make a 2D histogram that can be plotted using a colormapped image. If you are using matplotlib, try matplotlib.pyplot.hexbin(). http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.hexbin -- 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 ian.g.kelly at gmail.com Wed Nov 24 11:16:42 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 24 Nov 2010 09:16:42 -0700 Subject: efficient way of splitting a list in to lists where the sum of the values in each does not exceed n In-Reply-To: <4CED309C.8060500@t0mb.net> References: <4CED309C.8060500@t0mb.net> Message-ID: On Wed, Nov 24, 2010 at 8:34 AM, Tom Boland wrote: > I'm trying to find a _nice_ way of taking a list of integers, and splitting > them in to lists where the sum of the values does not exceed a threshold. > > for instance: > > l = [1, 2, 3, 4, 5, 6] > n = 6 > > nl = [1,2,3], [4], [5], [6] > > > I don't mind if it's done like playing blackjack/pontoon (the card game > where you try not to exceed a total of 21), ie. going through the list > sequentially, and splitting off the list as soon as the running total would > exceed n.? A way of efficiently making all lists as close to n as possible > would be nice however. You've described the bin-packing problem [1]. It's known to be NP-hard, so you won't find a solution that is both efficient and optimal, although the Wikipedia page mentions some polynomial-time approximate algorithms that you might want to take a look at. Cheers, Ian [1] http://en.wikipedia.org/wiki/Bin_packing_problem From __peter__ at web.de Wed Nov 24 11:27:53 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 24 Nov 2010 17:27:53 +0100 Subject: inverse of a matrix with Fraction entries References: Message-ID: Daniel Fetchinson wrote: >>> I guess this is a question to folks with some numpy background (but >>> not necessarily). >>> >>> I'm using fractions.Fraction as entries in a matrix because I need to >>> have very high precision and fractions.Fraction provides infinite >>> precision (as I've learned from advice from this list). >> >> "Infinite" precision only for values that can be expressed as a fraction: >> >>>>> Fraction(2)**Fraction(1, 2) >> 1.4142135623730951 >>>>> type(_) >> > > True, but I only need to add, multiply and divide my fractions in > order to end up with the entries in the matrix. > >>> Now I need to >>> calculate its inverse. Can numpy help in this regard? Can I tell numpy >>> that the inverse matrix should also have entries in >>> fractions.Fraction? Or numpy can only do floating point calculations? >> >> I tried it, and numpy.linalg.inv() converted the Fraction values to >> float. If you aren't concerned about efficiency it should be easy to do >> it yourself, in pure python. > > If there is no other way, that's what I'll try to do. > >> You could also ask on the numpy mailing list. >> >>> Probably it doesn't matter but the matrix has all components non-zero >>> and is about a thousand by thousand in size. >> >> Hmm, where did you get that million of exact fractions from? > > The million of exact fractions are coming from a recursion relation. > This recursion relation only adds, multiplies and divides numbers so > the end result is always a rational number. > >> If some real >> world data is involved the error introduced by the floating point >> calculation may be negligable in comparison with the initial measurement >> uncertainty. > > It's a mathematical problem so no uncertainty is present in the > initial values. And even if there was, if there are many orders of > magnitude differences between the entries in the matrix floating point > does not suffice for various things like eigenvalue calculation and > stuff like that. It may be worthwhile to have a look at http://www.sagemath.org/ sage: Matrix([[1,2],[3,4]])**-1 [ -2 1] [ 3/2 -1/2] sage: a = Matrix([[1,2],[3,4]]) sage: b = Matrix([[1,2],[3,4]])**-1 sage: a*b [1 0] [0 1] sage: type(b[1,1]) Peter From tom at t0mb.net Wed Nov 24 11:52:59 2010 From: tom at t0mb.net (Tom Boland) Date: Wed, 24 Nov 2010 16:52:59 +0000 Subject: efficient way of splitting a list in to lists where the sum of the values in each does not exceed n In-Reply-To: References: <4CED309C.8060500@t0mb.net> Message-ID: <4CED42EB.3010600@t0mb.net> Thanks for the reply Ian, I've looked in to the bin-packing problem in a general sense now, and I think my ugly algorithm is actually not too bad (although not too efficient either!) :) It was only for a quick job any how. Thanks again. Tom. On 24/11/10 16:16, Ian Kelly wrote: > On Wed, Nov 24, 2010 at 8:34 AM, Tom Boland wrote: > >> I'm trying to find a _nice_ way of taking a list of integers, and splitting >> them in to lists where the sum of the values does not exceed a threshold. >> >> for instance: >> >> l = [1, 2, 3, 4, 5, 6] >> n = 6 >> >> nl = [1,2,3], [4], [5], [6] >> >> >> I don't mind if it's done like playing blackjack/pontoon (the card game >> where you try not to exceed a total of 21), ie. going through the list >> sequentially, and splitting off the list as soon as the running total would >> exceed n. A way of efficiently making all lists as close to n as possible >> would be nice however. >> > You've described the bin-packing problem [1]. It's known to be > NP-hard, so you won't find a solution that is both efficient and > optimal, although the Wikipedia page mentions some polynomial-time > approximate algorithms that you might want to take a look at. > > Cheers, > Ian > > [1] http://en.wikipedia.org/wiki/Bin_packing_problem > From ppearson at nowhere.invalid Wed Nov 24 12:39:34 2010 From: ppearson at nowhere.invalid (Peter Pearson) Date: 24 Nov 2010 17:39:34 GMT Subject: inverse of a matrix with Fraction entries References: Message-ID: <8l50ulFhb4U1@mid.individual.net> On Wed, 24 Nov 2010 14:02:21 +0100, Daniel Fetchinson wrote: [snip] > I'm using fractions.Fraction as entries in a matrix because I need to > have very high precision and fractions.Fraction provides infinite > precision . . . [snip] > > Probably it doesn't matter but the matrix has all components non-zero > and is about a thousand by thousand in size. I wonder how big the numerators and denominators in those fractions are going to get during the matrix inversion. Would it be surprising if the elements of the inverse matrix had numerators and denominators a million times longer than the original matrix? -- To email me, substitute nowhere->spamcop, invalid->net. From robert.kern at gmail.com Wed Nov 24 12:58:07 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 24 Nov 2010 11:58:07 -0600 Subject: inverse of a matrix with Fraction entries In-Reply-To: References: Message-ID: On 11/24/10 9:10 AM, Daniel Fetchinson wrote: > It's a mathematical problem so no uncertainty is present in the > initial values. And even if there was, if there are many orders of > magnitude differences between the entries in the matrix floating point > does not suffice for various things like eigenvalue calculation and > stuff like that. Well, if you want to do eigenvalue calculations, you are going to have to start doing numerical approximations anyways. There is no analytical solution for matrices larger than 4x4. Sympy will do inverses of matrices over rationals for you, though: |4> from sympy import * |6> m = Matrix([[S(1)/2, S(1)/3], [S(1)/4, S(1)/5]]) |7> m [1/2, 1/3] [1/4, 1/5] |8> m.inv() [ 12, -20] [-15, 30] -- 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 fetchinson at googlemail.com Wed Nov 24 13:02:01 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Wed, 24 Nov 2010 19:02:01 +0100 Subject: inverse of a matrix with Fraction entries In-Reply-To: References: Message-ID: >>>> I guess this is a question to folks with some numpy background (but >>>> not necessarily). >>>> >>>> I'm using fractions.Fraction as entries in a matrix because I need to >>>> have very high precision and fractions.Fraction provides infinite >>>> precision (as I've learned from advice from this list). >>> >>> "Infinite" precision only for values that can be expressed as a fraction: >>> >>>>>> Fraction(2)**Fraction(1, 2) >>> 1.4142135623730951 >>>>>> type(_) >>> >> >> True, but I only need to add, multiply and divide my fractions in >> order to end up with the entries in the matrix. >> >>>> Now I need to >>>> calculate its inverse. Can numpy help in this regard? Can I tell numpy >>>> that the inverse matrix should also have entries in >>>> fractions.Fraction? Or numpy can only do floating point calculations? >>> >>> I tried it, and numpy.linalg.inv() converted the Fraction values to >>> float. If you aren't concerned about efficiency it should be easy to do >>> it yourself, in pure python. >> >> If there is no other way, that's what I'll try to do. >> >>> You could also ask on the numpy mailing list. >>> >>>> Probably it doesn't matter but the matrix has all components non-zero >>>> and is about a thousand by thousand in size. >>> >>> Hmm, where did you get that million of exact fractions from? >> >> The million of exact fractions are coming from a recursion relation. >> This recursion relation only adds, multiplies and divides numbers so >> the end result is always a rational number. >> >>> If some real >>> world data is involved the error introduced by the floating point >>> calculation may be negligable in comparison with the initial measurement >>> uncertainty. >> >> It's a mathematical problem so no uncertainty is present in the >> initial values. And even if there was, if there are many orders of >> magnitude differences between the entries in the matrix floating point >> does not suffice for various things like eigenvalue calculation and >> stuff like that. > > It may be worthwhile to have a look at http://www.sagemath.org/ > > sage: Matrix([[1,2],[3,4]])**-1 > > [ -2 1] > [ 3/2 -1/2] > sage: a = Matrix([[1,2],[3,4]]) > sage: b = Matrix([[1,2],[3,4]])**-1 > sage: a*b > > [1 0] > [0 1] > sage: type(b[1,1]) > This sounds like a good idea! Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From fetchinson at googlemail.com Wed Nov 24 13:07:32 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Wed, 24 Nov 2010 19:07:32 +0100 Subject: inverse of a matrix with Fraction entries In-Reply-To: <8l50ulFhb4U1@mid.individual.net> References: <8l50ulFhb4U1@mid.individual.net> Message-ID: >> I'm using fractions.Fraction as entries in a matrix because I need to >> have very high precision and fractions.Fraction provides infinite >> precision . . . >> >> Probably it doesn't matter but the matrix has all components non-zero >> and is about a thousand by thousand in size. > > I wonder how big the numerators and denominators in those > fractions are going to get during the matrix inversion. Would > it be surprising if the elements of the inverse matrix had > numerators and denominators a million times longer than the > original matrix? I've checked this with Maple for matrix size 150 x 150 and the numerators and denominators do get pretty long. But that's okay as long as it is kept exact. The whole story is that I have a matrix A and matrix B both of which have rational entries and they both have pretty crazy entries too. Their magnitude spans many orders of magnitude, but inverse(A)*B is an okay matrix and I can deal with it using floating point numbers. I only need this exact fraction business for inverse(A)*B (yes, a preconditioner would be useful :)) And I wouldn't want to write the whole matrix into a file, call Maple on it, parse the result, etc. So after all I might just code the inversion via Gauss elimination myself in a way that can deal with fractions, shouldn't be that hard. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From fetchinson at googlemail.com Wed Nov 24 13:10:10 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Wed, 24 Nov 2010 19:10:10 +0100 Subject: inverse of a matrix with Fraction entries In-Reply-To: References: Message-ID: >> It's a mathematical problem so no uncertainty is present in the >> initial values. And even if there was, if there are many orders of >> magnitude differences between the entries in the matrix floating point >> does not suffice for various things like eigenvalue calculation and >> stuff like that. > > Well, if you want to do eigenvalue calculations, you are going to have to > start > doing numerical approximations anyways. There is no analytical solution for > matrices larger than 4x4. Sure! (I didn't explain the whole thing yet, see the other reply where I actually do.) > Sympy will do inverses of matrices over rationals for you, though: > > |4> from sympy import * > > |6> m = Matrix([[S(1)/2, S(1)/3], [S(1)/4, S(1)/5]]) > > |7> m > [1/2, 1/3] > [1/4, 1/5] > > |8> m.inv() > [ 12, -20] > [-15, 30] Thanks a lot! This sounds like the simplest solution so far. I don't need to call Maple after all :) Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From raffaelcavallaro at pas.despam.s.il.vous.plait.mac.com Wed Nov 24 13:10:33 2010 From: raffaelcavallaro at pas.despam.s.il.vous.plait.mac.com (Raffael Cavallaro) Date: Wed, 24 Nov 2010 13:10:33 -0500 Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014020136.6e85d70b@tritium.streitmacht.eu> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> <08823dd4-588a-4729-a660-711e266c96b0@y23g2000yqd.googlegroups.com> <396f8de7-ece5-4e9c-919b-886eb65ae14a@a30g2000vbt.googlegroups.com> <967678a1-fc5d-4b61-86c5-79a298999582@p1g2000vbo.googlegroups.com> Message-ID: On 2010-11-23 11:34:14 -0500, Keith H Duggar said: > You don't understand the implications of your own words: > > "having a financial interest in the outcome of a debate makes > anything that person says an advertisement for his financial > interests, not a fair assessment." > > is substantially different from > > "render his arguments in the debate inherently suspect." They are substantially the same, your jesuitical nit-picking notwithstanding; JH is an untrustworthy source on matters relating to the languages he sells training for. warmest regards, Ralph -- Raffael Cavallaro From tinnews at isbd.co.uk Wed Nov 24 13:13:55 2010 From: tinnews at isbd.co.uk (tinnews at isbd.co.uk) Date: Wed, 24 Nov 2010 18:13:55 +0000 Subject: Problem with module 'evolution' after moving system Message-ID: <3810s7-bu5.ln1@chris.zbmc.eu> I have just moved my desktop system (running xubuntu 10.04) to new hardware. I have an almost trivial python program that uses the evolution module which no longer works and I'm having trouble working out why. The program is:- #!/usr/bin/python # # # # import evolution import sys addrs = evolution.ebook.open_addressbook('default') result = addrs.search(sys.argv[1]) print "Found ", len(result), " matches" if len(result) > 0: for nm in result: print nm.get_property('email-1'), "\t", nm.get_property('full-name') exit(0) else: exit(1) When I run it I get the error:- chris$ getEvoAddress.py zelma Traceback (most recent call last): File "/home/chris/bin/getEvoAddress.py", line 10, in addrs = evolution.ebook.open_addressbook('default') AttributeError: 'NoneType' object has no attribute 'open_addressbook' Using 'help' reveals basic information for evolution but reports "no documentation ...." for evolution.ebook. On the old system (exactly the same version of python, same OS, same everything just about) "help(evolution.ebook)" shows the expected documentation. So, what's wrong, is some python module missing that the evolution module needs? (It's quite likely that there are far more modules installed on the old system than the new one) -- Chris Green From whatsjacksemail at gmail.com Wed Nov 24 13:17:32 2010 From: whatsjacksemail at gmail.com (Jack Keegan) Date: Wed, 24 Nov 2010 18:17:32 +0000 Subject: unittests with different parameters In-Reply-To: References: Message-ID: Apologies if this is a bit off the wall but I've only just started getting into unit testing (in Python) this morning. Would generators help you in any way? You might be able to have a generator which would yield an attribute set combination each time it is called. I'm not sure if it would still stop at the first fail but I was reading this morning that the Py.test framework utilises generators, and is apparently compatible with the python unittest module. I could be wrong though... -------------- next part -------------- An HTML attachment was scrubbed... URL: From burton at userful.com Wed Nov 24 13:25:52 2010 From: burton at userful.com (Burton Samograd) Date: Wed, 24 Nov 2010 11:25:52 -0700 Subject: Collect output to string References: Message-ID: Terry Reedy writes: > On 11/23/2010 3:02 PM, Chris Rebert wrote: > If you are using print or print(), you can redirect output to the > StringIO object with >>sfile or file=sfile. I use the latter in a > custom test function where I normally want output to the screen but > occasionally want to capture test reports. Thanks for the info, but I was looking for a way to collect output without modifying the original function, similar to with-output-to-string in some schemes. -- Burton Samograd From robert.kern at gmail.com Wed Nov 24 13:30:44 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 24 Nov 2010 12:30:44 -0600 Subject: inverse of a matrix with Fraction entries In-Reply-To: References: <8l50ulFhb4U1@mid.individual.net> Message-ID: On 11/24/10 12:07 PM, Daniel Fetchinson wrote: > The whole story is that I have a matrix A and matrix B both of which > have rational entries and they both have pretty crazy entries too. > Their magnitude spans many orders of magnitude, but inverse(A)*B is an > okay matrix and I can deal with it using floating point numbers. I > only need this exact fraction business for inverse(A)*B (yes, a > preconditioner would be useful :)) > > And I wouldn't want to write the whole matrix into a file, call Maple > on it, parse the result, etc. > > So after all I might just code the inversion via Gauss elimination > myself in a way that can deal with fractions, shouldn't be that hard. +1000. This is almost always the right thing to do whether you have floats or rationals. -- 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 gerald.britton at gmail.com Wed Nov 24 13:46:35 2010 From: gerald.britton at gmail.com (Gerald Britton) Date: Wed, 24 Nov 2010 13:46:35 -0500 Subject: Style question for conditional execution Message-ID: Writing in Python gives me the luxury of choosing different paradigms for similar operations. Lately I've been thinking about a minor detail that peaked my interest and am curious what others think: Say that I have some function "f" that I will execute if some variable "v" evaluates true. Using a classical procedural approach, I might write: if v: f() I might, however, think more in a functional-programming direction. Then I might write: v and f() Interestingly, this second expression compiles smaller (though only by a little) in both Python 2.6 and 3.1, which I currently have installed. If I had thousands of such expressions, I could boast about a measurable difference but practically speaking, it is not significant. What I _am_ interested in, however, is feedback from a style perspective. What do the rest of you think about this? Have you used the second approach and, if so, what was your motivation? Is there a good/bad reason to choose one over the other? -- Gerald Britton From ed at leafe.com Wed Nov 24 14:10:23 2010 From: ed at leafe.com (Ed Leafe) Date: Wed, 24 Nov 2010 14:10:23 -0500 Subject: Style question for conditional execution In-Reply-To: References: Message-ID: On Nov 24, 2010, at 1:46 PM, Gerald Britton wrote: > Say that I have some function "f" that I will execute if some variable > "v" evaluates true. Using a classical procedural approach, I might > write: > > if v: > f() > > I might, however, think more in a functional-programming direction. > Then I might write: > > v and f() > > Interestingly, this second expression compiles smaller (though only by > a little) in both Python 2.6 and 3.1, which I currently have > installed. If I had thousands of such expressions, I could boast > about a measurable difference but practically speaking, it is not > significant. > > What I _am_ interested in, however, is feedback from a style perspective. > > What do the rest of you think about this? Readability is key. The first is instantly understandable; the second only if you are familiar with that particular programming construct. Explicit is better than implicit, so I'd go with the first form. -- Ed Leafe From ian.g.kelly at gmail.com Wed Nov 24 14:14:04 2010 From: ian.g.kelly at gmail.com (Ian) Date: Wed, 24 Nov 2010 11:14:04 -0800 (PST) Subject: Style question for conditional execution References: Message-ID: <98effb64-68a1-4532-a3e4-4629a555f8df@y31g2000vbt.googlegroups.com> On Nov 24, 11:46?am, Gerald Britton wrote: > Say that I have some function "f" that I will execute if some variable > "v" evaluates true. ?Using a classical procedural approach, I might > write: > > ? ? if v: > ? ? ? ? f() > > I might, however, think more in a functional-programming direction. > Then I might write: > > ? ? v and f() The idea that "if" is inherently procedural is mistaken. Functional programming emphasizes the use of functions (in the mathematical sense) over changes in state. Assuming that f has no side effects, either of the above could equally be viewed as functional. (Of course, the fact that the return value is simply discarded in both of the above cases suggests that f *does* have side effects, in which case neither of the above should be viewed as functional.) That said, the 'if' version is clearer, so I would nearly always go with that. The rare exception would be if I were genuinely interested in capturing the value of "v" if it evaluated false. I can't remember the last time that was the case. Cheers, Ian From howe.steven at gmail.com Wed Nov 24 14:40:41 2010 From: howe.steven at gmail.com (Steven Howe) Date: Wed, 24 Nov 2010 11:40:41 -0800 Subject: Style question for conditional execution In-Reply-To: References: Message-ID: <4CED6A39.8010607@gmail.com> Both paradigms are in the bash shell. Using a test switch (like -x for executiable) mixed with an && or ||. Example: [-x /usr/bin/firefox ] || exit I think it's very clear, to old hands, but not so much for a new or intermediate users. It certainly is the 'cleaner' form. Like the C style increment " x++ " or the insidious " x += 4 ". However I often found myself looking for places to use "x += 4" instead of just using the clear: "x = x + 4 ". Unless there is a significant compiler/executable improvement it just there to amuse yourself. The if v: f() structure is clearer. Which is the only reason to use indents, braces and the like. I suppose that's my vote/opinion. Given a choice between clean or clear, take clear. sph On 11/24/2010 10:46 AM, Gerald Britton wrote: > Writing in Python gives me the luxury of choosing different paradigms > for similar operations. Lately I've been thinking about a minor > detail that peaked my interest and am curious what others think: > > Say that I have some function "f" that I will execute if some variable > "v" evaluates true. Using a classical procedural approach, I might > write: > > if v: > f() > > I might, however, think more in a functional-programming direction. > Then I might write: > > v and f() > > Interestingly, this second expression compiles smaller (though only by > a little) in both Python 2.6 and 3.1, which I currently have > installed. If I had thousands of such expressions, I could boast > about a measurable difference but practically speaking, it is not > significant. > > What I _am_ interested in, however, is feedback from a style perspective. > > What do the rest of you think about this? > > Have you used the second approach and, if so, what was your motivation? > > Is there a good/bad reason to choose one over the other? > From python at rcn.com Wed Nov 24 15:08:04 2010 From: python at rcn.com (Raymond Hettinger) Date: Wed, 24 Nov 2010 12:08:04 -0800 (PST) Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance Message-ID: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> I'm writing-up more guidance on how to use super() and would like to point at some real-world Python examples of cooperative multiple inheritance. Google searches take me to old papers for C++ and Eiffel, but that don't seem to be relevant to most Python programmers (i.e. a WalkingMenu example where a submenu is both a Entry in a Menu and a Menu itself). Another published example is in a graphic library where some widgets inherit GraphicalFeature methods such as location, size and NestingGroupingFeatures such as finding parents, siblings, and children. I don't find either of those examples compelling because there is no particular reason that they would have to have overlapping method names. So far, the only situation I can find where method names necessarily overlap is for the basics like __init__(), close(), flush(), and save() where multiple parents need to have their own initialization and finalization. If you guys know of good examples, I would appreciate a link or a recap. Thanks, Raymond From mdw at distorted.org.uk Wed Nov 24 15:10:10 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 24 Nov 2010 20:10:10 +0000 Subject: inverse of a matrix with Fraction entries References: <8l50ulFhb4U1@mid.individual.net> Message-ID: <87y68izdnh.fsf.mdw@metalzone.distorted.org.uk> Daniel Fetchinson writes: > So after all I might just code the inversion via Gauss elimination > myself in a way that can deal with fractions, shouldn't be that hard. I wouldn't do it that way. Let M be your matrix. Work out the LCM l of the denominators, and multiply the matrix by that to make it an integer matrix N = l M. Then work out the determinant d of that integer matrix. Next, the big step: use Gaussian elimination to find a matrix A (the `adjugate matrix') such that A N = d I. This should be doable entirely using integer arithmetic, and I think without needing any divisions. Finally, we have l A M = d I, so (l/d A) M = I and l/d A is the inverse you seek. Does that make sense? -- [mdw] From arnodel at gmail.com Wed Nov 24 15:25:19 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Wed, 24 Nov 2010 20:25:19 +0000 Subject: Style question for conditional execution References: Message-ID: <87eiaafp00.fsf@gmail.com> Gerald Britton writes: > Writing in Python gives me the luxury of choosing different paradigms > for similar operations. Lately I've been thinking about a minor > detail that peaked my interest and am curious what others think: > > Say that I have some function "f" that I will execute if some variable > "v" evaluates true. Using a classical procedural approach, I might > write: > > if v: > f() > > I might, however, think more in a functional-programming direction. > Then I might write: > > v and f() > > Interestingly, this second expression compiles smaller (though only by > a little) in both Python 2.6 and 3.1, which I currently have > installed. If I had thousands of such expressions, I could boast > about a measurable difference but practically speaking, it is not > significant. > > What I _am_ interested in, however, is feedback from a style perspective. > > What do the rest of you think about this? > > Have you used the second approach and, if so, what was your motivation? > > Is there a good/bad reason to choose one over the other? I would use the if: form every time but it's interesting that the "JUMP_FORWARD 0" instruction below doesn't get optimised away. If it did, both forms would be the same compiled lengths. >>> def g(): ... if v: f() ... >>> dis.dis(g2) 2 0 LOAD_GLOBAL 0 (v) 3 POP_JUMP_IF_FALSE 16 6 LOAD_GLOBAL 1 (f) 9 CALL_FUNCTION 0 12 POP_TOP 13 JUMP_FORWARD 0 (to 16) >> 16 LOAD_CONST 0 (None) 19 RETURN_VALUE -- Arnaud From no.email at nospam.invalid Wed Nov 24 15:43:18 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 24 Nov 2010 12:43:18 -0800 Subject: Style question for conditional execution References: Message-ID: <7xtyj6o3kp.fsf@ruckus.brouhaha.com> Gerald Britton writes: > if v: > f() > > I might, however, think more in a functional-programming direction. > Then I might write: > > v and f() Python has conditional expressions. The above would be: f() if v else None using "and" is bug-prone. From anurag.chourasia at gmail.com Wed Nov 24 16:01:32 2010 From: anurag.chourasia at gmail.com (Anurag Chourasia) Date: Thu, 25 Nov 2010 02:31:32 +0530 Subject: collect2: library libpython2.6 not found while building extensions (--enable-shared) Message-ID: All, When I configure python to enable shared libraries, none of the extensions are getting built during the make step due to this error. building 'cStringIO' extension gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I. -I/u01/home/apli/wm/GDD/Python-2.6.6/./Include -I. -IInclude -I./Include -I/opt/freeware/include -I/opt/freeware/include/readline -I/opt/freeware/include/ncurses -I/usr/local/include -I/u01/home/apli/wm/GDD/Python-2.6.6/Include -I/u01/home/apli/wm/GDD/Python-2.6.6 -c /u01/home/apli/wm/GDD/Python-2.6.6/Modules/cStringIO.c -o build/temp.aix-5.3-2.6/u01/home/apli/wm/GDD/Python-2.6.6/Modules/cStringIO.o ./Modules/ld_so_aix gcc -pthread -bI:Modules/python.exp build/temp.aix-5.3-2.6/u01/home/apli/wm/GDD/Python-2.6.6/Modules/cStringIO.o -L/usr/local/lib *-lpython2.6* -o build/lib.aix-5.3-2.6/cStringIO.so *collect2: library libpython2.6 not found* building 'cPickle' extension gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I. -I/u01/home/apli/wm/GDD/Python-2.6.6/./Include -I. -IInclude -I./Include -I/opt/freeware/include -I/opt/freeware/include/readline -I/opt/freeware/include/ncurses -I/usr/local/include -I/u01/home/apli/wm/GDD/Python-2.6.6/Include -I/u01/home/apli/wm/GDD/Python-2.6.6 -c /u01/home/apli/wm/GDD/Python-2.6.6/Modules/cPickle.c -o build/temp.aix-5.3-2.6/u01/home/apli/wm/GDD/Python-2.6.6/Modules/cPickle.o ./Modules/ld_so_aix gcc -pthread -bI:Modules/python.exp build/temp.aix-5.3-2.6/u01/home/apli/wm/GDD/Python-2.6.6/Modules/cPickle.o -L/usr/local/lib *-lpython2.6* -o build/lib.aix-5.3-2.6/cPickle.so *collect2: library libpython2.6 not found* This is on AIX 5.3, GCC 4.2, Python 2.6.6 I can confirm that there is a libpython2.6.a file in the top level directory from where I am doing the configure/make etc Here are the options supplied to the configure command ./configure --enable-shared --disable-ipv6 --with-gcc=gcc CPPFLAGS="-I /opt/freeware/include -I /opt/freeware/include/readline -I /opt/freeware/include/ncurses" Please guide me in getting past this error. Thanks for your help on this. Regards, Anurag -------------- next part -------------- An HTML attachment was scrubbed... URL: From toby at telegraphics.com.au Wed Nov 24 16:19:49 2010 From: toby at telegraphics.com.au (toby) Date: Wed, 24 Nov 2010 13:19:49 -0800 (PST) Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014020136.6e85d70b@tritium.streitmacht.eu> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> <08823dd4-588a-4729-a660-711e266c96b0@y23g2000yqd.googlegroups.com> <396f8de7-ece5-4e9c-919b-886eb65ae14a@a30g2000vbt.googlegroups.com> <967678a1-fc5d-4b61-86c5-79a298999582@p1g2000vbo.googlegroups.com> Message-ID: <18cd9337-736b-427c-9cac-14c99056750a@p1g2000yqm.googlegroups.com> On Nov 24, 1:10?pm, Raffael Cavallaro wrote: > On 2010-11-23 11:34:14 -0500, Keith H Duggar said: > > > You don't understand the implications of your own words: > > > ? ?"having a financial interest in the outcome of a debate makes > > ? ?anything that person says an advertisement for his financial > > ? ?interests, not a fair assessment." > > > is substantially different from > > > ? ?"render his arguments in the debate inherently suspect." > > They are substantially the same, your jesuitical nit-picking > notwithstanding; JH is an untrustworthy source on matters relating to > the languages he sells training for. > And furthermore, he has cooties. --T > warmest regards, > > Ralph > > -- > Raffael Cavallaro From tinnews at isbd.co.uk Wed Nov 24 16:33:13 2010 From: tinnews at isbd.co.uk (tinnews at isbd.co.uk) Date: Wed, 24 Nov 2010 21:33:13 +0000 Subject: Problem with module 'evolution' after moving system References: <3810s7-bu5.ln1@chris.zbmc.eu> Message-ID: tinnews at isbd.co.uk wrote: [snip] > Using 'help' reveals basic information for evolution but reports "no > documentation ...." for evolution.ebook. On the old system (exactly > the same version of python, same OS, same everything just about) > "help(evolution.ebook)" shows the expected documentation. > > So, what's wrong, is some python module missing that the evolution > module needs? (It's quite likely that there are far more modules > installed on the old system than the new one) > A bit further trying to see what's wrong it seems that Python is failing to load .so libraries for some reason on the system where it doesn't work. The initialisation code in the evolution module has:- import ebook So, obviously this works on the old system but not on the new system. The ebook.so file is present on both systems in exactly the same place. -- Chris Green From agarwal1975 at gmail.com Wed Nov 24 16:41:56 2010 From: agarwal1975 at gmail.com (ashish) Date: Wed, 24 Nov 2010 13:41:56 -0800 (PST) Subject: No rule to make target `Parser/printgrammar.o' Message-ID: I'm trying to compile Python from source and get the same error on RedHat and Mac OS X. I did not pass any options to configure. The error occurs immediately. Redhat:~/Downloads/Python-2.7$ make gcc -pthread -c -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 - Wall -Wstrict-prototypes -I. -IInclude -I./Include -DPy_BUILD_CORE - o Modules/python.o ./Modules/python.c make: *** No rule to make target `Parser/printgrammar.o', needed by `Parser/pgen'. Stop. MacOSX:Python-2.7$ make gcc -c -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall - Wstrict-prototypes -I. -IInclude -I./Include -DPy_BUILD_CORE -o Modules/python.o ./Modules/python.c make: *** No rule to make target `Parser/printgrammar.o', needed by `Parser/pgen'. Stop. From tinnews at isbd.co.uk Wed Nov 24 16:54:18 2010 From: tinnews at isbd.co.uk (tinnews at isbd.co.uk) Date: Wed, 24 Nov 2010 21:54:18 +0000 Subject: Problem with module 'evolution' after moving system References: <3810s7-bu5.ln1@chris.zbmc.eu> Message-ID: tinnews at isbd.co.uk wrote: > tinnews at isbd.co.uk wrote: > [snip] > > > Using 'help' reveals basic information for evolution but reports "no > > documentation ...." for evolution.ebook. On the old system (exactly > > the same version of python, same OS, same everything just about) > > "help(evolution.ebook)" shows the expected documentation. > > > > So, what's wrong, is some python module missing that the evolution > > module needs? (It's quite likely that there are far more modules > > installed on the old system than the new one) > > > A bit further trying to see what's wrong it seems that Python is > failing to load .so libraries for some reason on the system where it > doesn't work. > > The initialisation code in the evolution module has:- > > import ebook > > So, obviously this works on the old system but not on the new system. > The ebook.so file is present on both systems in exactly the same place. > .... and I've finally found what was missing, I tried:- import evolution.ebook and it told me that 'import bonobo' was failing. A little searching and I found that python-gnome2 (which includes bonobo) was installed on the old system but not on the new one. Installing it has fixed my problem. -- Chris Green From sjmachin at lexicon.net Wed Nov 24 17:01:06 2010 From: sjmachin at lexicon.net (John Machin) Date: Wed, 24 Nov 2010 14:01:06 -0800 (PST) Subject: Ensuring symmetry in difflib.SequenceMatcher References: <135c0dfc-c382-4dd3-bfaf-8d508e5e648b@j21g2000vba.googlegroups.com> Message-ID: <89545b9a-8c97-41cd-a1f6-6b4439deda5c@y19g2000prb.googlegroups.com> On Nov 24, 8:43?pm, Peter Otten <__pete... at web.de> wrote: > John Yeung wrote: > > I'm generally pleased with difflib.SequenceMatcher: ?It's probably not > > the best available string matcher out there, but it's in the standard > > library and I've seen worse in the wild. ?One thing that kind of > > bothers me is that it's sensitive to which argument you pick as "seq1" > > and which you pick as "seq2": > > > Python 2.6.1 (r261:67517, Dec ?4 2008, 16:51:00) [MSC v.1500 32 bit > > (Intel)] on > > win32 > > Type "help", "copyright", "credits" or "license" for more information. > >>>> import difflib > >>>> difflib.SequenceMatcher(None, 'BYRD', 'BRADY').ratio() > > 0.44444444444444442 > >>>> difflib.SequenceMatcher(None, 'BRADY', 'BYRD').ratio() > > 0.66666666666666663 > > > Is this a bug? ?I am guessing the algorithm is implemented correctly, > > and that it's just an inherent property of the algorithm used. ?It's > > certainly not what I'd call a desirably property. ?Are there any > > simple adjustments that can be made without sacrificing (too much) > > performance? > > def symmetric_ratio(a, b, S=difflib.SequenceMatcher): > ? ? return (S(None, a, b).ratio() + S(None, b, a).ratio())/2.0 > > I'm expecting 50% performance loss ;) > > Seriously, have you tried to calculate the ratio with realistic data? > Without looking into the source I would expect the two ratios to get more > similar. > > Peter Surnames are extremely realistic data. The OP should consider using Levenshtein distance, which is "symmetric". A good (non-naive) implementation should be much faster than difflib. ratio = 1.0 - levenshtein(a, b) / float(max(len(a), len(b))) From saul.spatz at gmail.com Wed Nov 24 17:03:14 2010 From: saul.spatz at gmail.com (Saul Spatz) Date: Wed, 24 Nov 2010 14:03:14 -0800 (PST) Subject: PyQt Installation Problem on Windows Message-ID: <22cf97c9-ac22-4af1-8834-7ccb1828cc47@p1g2000yqm.googlegroups.com> Hi, I've been trying to install PyQt on Windows XP Pro so that I can try out eric ide. I used the binary windows installer for PyQt. I can run eric as administrator, but not with my ordinary user account. By running eric.bat with the --debug flag, I found that he crux of the problem is that if I type import PyQt4 in the python shell, it works for both users, but if I type import PyQt4.QtCore it works for the administrator, but the non-privileged account gets the message ImportError: DLL load failed: The specified module could not be found. In the file the file pyqtconfig.py from Python26\Lib\site-packages \PyQt4 I have the line 'pyqt_config_args': '--confirm-license -b C:\\Python26\\Lib\\site- packages\\PyQt4\\bin', I checked with a friend who uses eric, and his file does not have the --confirm-license parameter. As far as we can tell, we followed the same installation procedures. By the way, I have tried this with python 3.1 on the same machine with similar results. I've blown a whole day playing with this, so I'd really appreciate any help you can give me. From fetchinson at googlemail.com Wed Nov 24 17:08:32 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Wed, 24 Nov 2010 23:08:32 +0100 Subject: inverse of a matrix with Fraction entries In-Reply-To: <87y68izdnh.fsf.mdw@metalzone.distorted.org.uk> References: <8l50ulFhb4U1@mid.individual.net> <87y68izdnh.fsf.mdw@metalzone.distorted.org.uk> Message-ID: >> So after all I might just code the inversion via Gauss elimination >> myself in a way that can deal with fractions, shouldn't be that hard. > > I wouldn't do it that way. Let M be your matrix. Work out the LCM l of > the denominators, and multiply the matrix by that to make it an integer > matrix N = l M. Then work out the determinant d of that integer matrix. > Next, the big step: use Gaussian elimination to find a matrix A (the > `adjugate matrix') such that A N = d I. This should be doable entirely > using integer arithmetic, and I think without needing any divisions. > Finally, we have l A M = d I, so (l/d A) M = I and l/d A is the inverse > you seek. > > Does that make sense? Absolutely! But there is nothing wrong with working out the inverse directly using fractions.Fraction arithmetic, I'd think. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From hniksic at xemacs.org Wed Nov 24 17:09:25 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Wed, 24 Nov 2010 23:09:25 +0100 Subject: Collect output to string References: Message-ID: <87wro2gyqy.fsf@xemacs.org> Burton Samograd writes: > Terry Reedy writes: > >> On 11/23/2010 3:02 PM, Chris Rebert wrote: >> If you are using print or print(), you can redirect output to the >> StringIO object with >>sfile or file=sfile. I use the latter in a >> custom test function where I normally want output to the screen but >> occasionally want to capture test reports. > > Thanks for the info, but I was looking for a way to collect output > without modifying the original function, similar to > with-output-to-string in some schemes. Redirecting output like with-output-to-string does is achieved by assigning to sys.stdout. Using contextlib you can make it even closer to with-output-to-string by deploying the actual with statement. Unfortunately python's with cannot return a value, so you must expose the StringIO to the caller. The result is still quite nice: import sys, contextlib, cStringIO @contextlib.contextmanager def output_to_string(): oldout = sys.stdout sys.stdout = cStringIO.StringIO() try: yield sys.stdout finally: sys.stdout = oldout >>> with output_to_string() as out: ... print 'foo' ... print 'bar' ... >>> out.getvalue() 'foo\nbar\n' From robert.kern at gmail.com Wed Nov 24 17:54:56 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 24 Nov 2010 16:54:56 -0600 Subject: inverse of a matrix with Fraction entries In-Reply-To: References: <8l50ulFhb4U1@mid.individual.net> Message-ID: On 11/24/10 12:30 PM, Robert Kern wrote: > On 11/24/10 12:07 PM, Daniel Fetchinson wrote: > >> The whole story is that I have a matrix A and matrix B both of which >> have rational entries and they both have pretty crazy entries too. >> Their magnitude spans many orders of magnitude, but inverse(A)*B is an >> okay matrix and I can deal with it using floating point numbers. I >> only need this exact fraction business for inverse(A)*B (yes, a >> preconditioner would be useful :)) >> >> And I wouldn't want to write the whole matrix into a file, call Maple >> on it, parse the result, etc. >> >> So after all I might just code the inversion via Gauss elimination >> myself in a way that can deal with fractions, shouldn't be that hard. > > +1000. This is almost always the right thing to do whether you have floats or > rationals. By this I meant that you should using Gaussian elimination to *solve* the problem A^-1*B is the right thing to do rather than explicitly forming the inverse of A (no matter which algorithm you use). I hope that's what you meant too. -- 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 brendon.j.costa at gmail.com Wed Nov 24 17:58:56 2010 From: brendon.j.costa at gmail.com (Brendon) Date: Wed, 24 Nov 2010 14:58:56 -0800 (PST) Subject: Python dict as unicode Message-ID: <1045bf31-29f3-4886-bad0-c6025a74aca4@m20g2000prc.googlegroups.com> Hi all, I am trying to convert a dictionary to a unicode string and it fails with an exception. I am awfully surprised but searching the web has not turned up anything useful. I understand why the exception ocurrs, but am not sure why this is the default behaviour of python and if there is anything I can do to fix the problem. I have a python dictionary: d = { ......} It contains both primitive and complex objects. I want a unicode representation of that dict: s = unicode(d) Doing this I get an exception: UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 71: ordinal not in range(128) Now, it seems that unicode(d) is the same as unicode(str(d)). I was expecting there to be a __unicode__ method in the dictionary that in turn calls unicode() on each of the keys/values in the dict, but apparently not. Instead it seems to call the equivalent of str() on each key/value and then after adding them together, calls unicode() on the resulting string. Is this really the default behaviour? If so is there any way around it? I am using python 2.6.6 on a Linux system. From sohel807 at gmail.com Wed Nov 24 18:44:19 2010 From: sohel807 at gmail.com (Akand Islam) Date: Wed, 24 Nov 2010 15:44:19 -0800 (PST) Subject: Matlab equivalent syntax in Python Message-ID: <8317f18c-f2b2-4150-9bc0-e84d75e80de2@n32g2000pre.googlegroups.com> Can anyone please suggest me what will be the good way to use matlab equivalent of "profile clear, profile on, profile off, profile resume and profile viewer" in Python? Thanks in advance. From solipsis at pitrou.net Wed Nov 24 18:46:51 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Thu, 25 Nov 2010 00:46:51 +0100 Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> Message-ID: <20101125004651.3d6221a3@pitrou.net> On Wed, 24 Nov 2010 12:08:04 -0800 (PST) Raymond Hettinger wrote: > I'm writing-up more guidance on how to use super() and would like to > point at some real-world Python examples of cooperative multiple > inheritance. > > Google searches take me to old papers for C++ and Eiffel, but that > don't seem to be relevant to most Python programmers (i.e. a > WalkingMenu example where a submenu is both a Entry in a Menu and a > Menu itself). Another published example is in a graphic library where > some widgets inherit GraphicalFeature methods such as location, size > and NestingGroupingFeatures such as finding parents, siblings, and > children. I don't find either of those examples compelling because > there is no particular reason that they would have to have overlapping > method names. > > So far, the only situation I can find where method names necessarily > overlap is for the basics like __init__(), close(), flush(), and > save() where multiple parents need to have their own initialization > and finalization. > > If you guys know of good examples, I would appreciate a link or a > recap. I have never seen a good use of cooperative multiple inheritance in Python. My own experience trying to use it suggests me that I would have been better with independent "handler" classes (urllib2-style). Regards Antoine. From alan at baselinedata.co.uk Wed Nov 24 19:45:41 2010 From: alan at baselinedata.co.uk (Alan Harris-Reid) Date: Thu, 25 Nov 2010 00:45:41 +0000 Subject: SQLite date fields Message-ID: <4CEDB1B5.4040008@baselinedata.co.uk> Hi, I am having design problems with date storage/retrieval using Python and SQLite. I understand that a SQLite date column stores dates as text in ISO format (ie. '2010-05-25'). So when I display a British date (eg. on a web-page) I convert the date using datetime.datetime.strptime(mydate,'%Y-%m-%d').strftime('%d/%m/%Y'). However, when it comes to writing-back data to the table, SQLite is very forgiving and is quite happy to store '25/06/2003' in a date field, but this is not ideal because a) I could be left with a mixture of date formats in the same column, b) SQLite's date functions only work with ISO format. Therefore I need to convert the date string back to ISO format before committing, but then I would need a generic function which checks data about to be written in all date fields and converts to ISO if necessary. That sounds a bit tedious to me, but maybe it is inevitable. Are there simpler solutions? Would it be easier to change the date field to a 10-character field and store 'dd/mm/yyyy' throughout the table? This way no conversion is required when reading or writing from the table, and I could use datetime() functions if I needed to perform any date-arithmetic. How have other developers overcome this problem? Any help would be appreciated. For the record, I am using SQLite3 with Python 3.1. Alan From afriere at yahoo.co.uk Wed Nov 24 19:45:52 2010 From: afriere at yahoo.co.uk (Asun Friere) Date: Wed, 24 Nov 2010 16:45:52 -0800 (PST) Subject: Style question for conditional execution References: <7xtyj6o3kp.fsf@ruckus.brouhaha.com> Message-ID: On Nov 25, 7:43?am, Paul Rubin wrote: > Gerald Britton writes: > > ? ? if v: > > ? ? ? ? f() > > > I might, however, think more in a functional-programming direction. > > Then I might write: > > > ? ? v and f() > > Python has conditional expressions. ?The above would be: > > ? ? f() if v else None > > using "and" is bug-prone. Using 'and' is indeed bug-prone when used in combination with 'or' to achieve a ternary conditional op, as was done the pre PEP308 days, eg "val = cond and a or b" because of the possibility that 'a' was itself not true, (thus requiring the ugly 'val = (cond and [a] or [b])[0]'). But no such bug could occur with this particular idiom. What could possibly go wrong here? :) That being said, I agree with previous posters that "if cond : fn()" wins in terms of readability. From shearichard at gmail.com Wed Nov 24 20:57:56 2010 From: shearichard at gmail.com (shearichard) Date: Wed, 24 Nov 2010 17:57:56 -0800 (PST) Subject: Pypi (Cheeseshop) Score - derivation of ? Message-ID: <86979c80-0955-4ee8-b645-10097d45dd58@z9g2000pri.googlegroups.com> Hi - Anyone know how the score offered by Pypi is derived ? For instance in ... http://pypi.python.org/pypi?%3Aaction=search&term=spam&submit=search ... 'bud.nospam 1.0.1' has a score of 9 but 'pydspam 1.1.9' has a score of 7. Where are those numbers from and what do they mean ? Thanks R. From ben+python at benfinney.id.au Wed Nov 24 21:54:14 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 25 Nov 2010 13:54:14 +1100 Subject: Pypi (Cheeseshop) Score - derivation of ? References: <86979c80-0955-4ee8-b645-10097d45dd58@z9g2000pri.googlegroups.com> Message-ID: <87zksy6rl5.fsf@benfinney.id.au> shearichard writes: > Hi - Anyone know how the score offered by Pypi is derived ? Specifically, the score offered in response to a search query. > For instance in ... > > http://pypi.python.org/pypi?%3Aaction=search&term=spam&submit=search > > ... 'bud.nospam 1.0.1' has a score of 9 but 'pydspam 1.1.9' has a > score of 7. > > Where are those numbers from and what do they mean ? They are the relevance of the result to that particular search query. I don't know the scale of the score or how it's derived, but that's the intended meaning AFAIK. I think a better term than ?score? could be chosen; perhaps you could submit a bug report against PyPI. -- \ ?One of the most important things you learn from the internet | `\ is that there is no ?them? out there. It's just an awful lot of | _o__) ?us?.? ?Douglas Adams | Ben Finney From shearichard at gmail.com Wed Nov 24 22:46:47 2010 From: shearichard at gmail.com (shearichard) Date: Wed, 24 Nov 2010 19:46:47 -0800 (PST) Subject: Pypi (Cheeseshop) Score - derivation of ? References: <86979c80-0955-4ee8-b645-10097d45dd58@z9g2000pri.googlegroups.com> <87zksy6rl5.fsf@benfinney.id.au> Message-ID: <7528b863-2f10-491d-bf4a-a916eb72a6ad@t8g2000prh.googlegroups.com> On Nov 25, 3:54?pm, Ben Finney wrote: > shearichard writes: > > Hi - Anyone know how the score offered by Pypi is derived ? > > Specifically, the score offered in response to a search query. > > > For instance in ... > > >http://pypi.python.org/pypi?%3Aaction=search&term=spam&submit=search > > > ... 'bud.nospam 1.0.1' has a score of 9 but 'pydspam 1.1.9' has a > > score of 7. > > > Where are those numbers from and what do they mean ? > > They are the relevance of the result to that particular search query. I > don't know the scale of the score or how it's derived, but that's the > intended meaning AFAIK. > > I think a better term than ?score? could be chosen; perhaps you could > submit a bug report against PyPI. > OK that makes sense. I thought it was some comment on how 'good' the package in question was ! I will do as you say and submit a bug report to get the literal altered to something a little more self-explanatory. From wuwei23 at gmail.com Wed Nov 24 23:03:06 2010 From: wuwei23 at gmail.com (alex23) Date: Wed, 24 Nov 2010 20:03:06 -0800 (PST) Subject: Pypi (Cheeseshop) Score - derivation of ? References: <86979c80-0955-4ee8-b645-10097d45dd58@z9g2000pri.googlegroups.com> Message-ID: <30d136fe-5fc3-49aa-904d-c63b228e5d2c@n2g2000pre.googlegroups.com> On Nov 25, 11:57?am, shearichard wrote: > Hi - Anyone know how the score offered by Pypi is derived ? > > For instance in ... > > http://pypi.python.org/pypi?%3Aaction=search&term=spam&submit=search > > ... 'bud.nospam 1.0.1' has a score of 9 but 'pydspam 1.1.9' has a > score of 7. If you hover over the Score header in the results list, it says: Occurrence of search term weighted by field (name, summary, keywords, description, author, maintainer) I thought PyPI used to offer a 'kwality' score for packages, based on the presence of installers, doc files, tests etc. Does anyone know what happened to that? From phlip2005 at gmail.com Wed Nov 24 23:46:18 2010 From: phlip2005 at gmail.com (Phlip) Date: Wed, 24 Nov 2010 20:46:18 -0800 (PST) Subject: a regexp riddle: re.search(r'(?:(\w+), |and (\w+))+', 'whatever a, bbb, and c') =? ('a', 'bbb', 'c') Message-ID: <00a69232-7703-48ce-8a42-b28f24946680@i32g2000pri.googlegroups.com> HypoNt: I need to turn a human-readable list into a list(): print re.search(r'(?:(\w+), |and (\w+))+', 'whatever a, bbb, and c').groups() That currently returns ('c',). I'm trying to match "any word \w+ followed by a comma, or a final word preceded by and." The match returns 'a, bbb, and c', but the groups return ('bbb', 'c'). What do I type for .groups() to also get the 'a'? Please go easy on me (and no RTFM!), because I have only been using regular expressions for about 20 years... -- Phlip http://bit.ly/ZeekLand From alice at gothcandy.com Thu Nov 25 00:16:14 2010 From: alice at gothcandy.com (=?utf-8?Q?Alice_Bevan=E2=80=93McGregor?=) Date: Wed, 24 Nov 2010 21:16:14 -0800 Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> Message-ID: <201011242116145773-alice@gothcandycom> On 2010-11-24 12:08:04 -0800, Raymond Hettinger said: > I'm writing-up more guidance on how to use super() and would like to > point at some real-world Python examples of cooperative multiple > inheritance. The SocketServer module (http://docs.python.org/library/socketserver.html) uses cooperative multiple inheritance to implement threading / async using a ThreadingMixIn class and multi-processing using a ForkingMixIn class, which may not be as complicated a use case as you are looking for. One thing that caught me up was the attribute resolution order; it's a FIFO, with the first superclass being examined preferentially over later superclasses in the declaration. (Mixins go before the class they extend.) ? Alice. From tjreedy at udel.edu Thu Nov 25 00:42:55 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 25 Nov 2010 00:42:55 -0500 Subject: Python dict as unicode In-Reply-To: <1045bf31-29f3-4886-bad0-c6025a74aca4@m20g2000prc.googlegroups.com> References: <1045bf31-29f3-4886-bad0-c6025a74aca4@m20g2000prc.googlegroups.com> Message-ID: On 11/24/2010 5:58 PM, Brendon wrote: > Hi all, > > I am trying to convert a dictionary to a unicode string and it fails > with an exception. I am awfully surprised but searching the web has > not turned up anything useful. I understand why the exception ocurrs, > but am not sure why this is the default behaviour of python and if > there is anything I can do to fix the problem. > > I have a python dictionary: > d = { ......} > > It contains both primitive and complex objects. I want a unicode > representation of that dict: > s = unicode(d) > > Doing this I get an exception: > UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position > 71: ordinal not in range(128) > > Now, it seems that unicode(d) is the same as unicode(str(d)). I was > expecting there to be a __unicode__ method in the dictionary that in > turn calls unicode() on each of the keys/values in the dict, but > apparently not. Instead it seems to call the equivalent of str() on > each key/value and then after adding them together, calls unicode() on > the resulting string. > > Is this really the default behaviour? If so is there any way around > it? Use 3.x > I am using python 2.6.6 on a Linux system. -- Terry Jan Reedy From lkcl at lkcl.net Thu Nov 25 03:09:09 2010 From: lkcl at lkcl.net (Luke Kenneth Casson Leighton) Date: Thu, 25 Nov 2010 08:09:09 +0000 Subject: [ANN] PythonWebkit bindings for WebkitDFB Message-ID: WebkitDFB is an experimental port to allow the webkit web browser engine to use DirectFB (http://directfb.org). It is lightning-quick to start up (no large widget set to load), yet has the potential to provide full HTML5 functionality. The PythonWebkit project, http://www.gnu.org/software/pythonwebkit brings 300+ DOM objects and 2,000+ fully W3C-compliant python-based DOM functions to webkit, making python effectively a peer of javascript (doc.body.style, getElementsByTagName, appendChild, setTimeout, XMLHttpRequest, onclick etc.) These two projects have been brought together in the same source repository. If startup time and CPU usage is important (as it is on embedded systems) then please do consider helping with WebkitDFB by funding its ongoing development and/or helping Denis out. If startup time and CPU usage and _python_ are important... :) in this rather short announcement, it's easy to miss the significance: yes, webkit the web browser engine, directfb the direct framebuffer engine, and python the utterly cool and beautiful programming language have been combined into the same package and sentence. more information at http://www.gnu.org/software/pythonwebkit. l. From joralemonshelly at gmail.com Thu Nov 25 03:12:40 2010 From: joralemonshelly at gmail.com (Shel) Date: Thu, 25 Nov 2010 00:12:40 -0800 (PST) Subject: building a web interface References: <16bc6e60-ad98-4d81-9f20-23e9b52eea21@n30g2000vbb.googlegroups.com> Message-ID: <90335766-af85-4a9d-8a13-518b88014b5a@r31g2000prg.googlegroups.com> This is really great. I wish I could come up with some creative new ways to say thank you, but... thank you :-) Shel On Nov 21, 6:10?pm, Martin Gregorie wrote: > On Sun, 21 Nov 2010 15:40:10 -0800, Shel wrote: > > I am confused about multiple simultaneous users, which I would like to > > be able to accommodate. ?On the db side, I have a structure to store > > data for each user, and know a bit about selectively locking data, > > although I have not implemented that yet, so will see what happens. > > I realise what I wrote last night wasn't all that clear. Terms: > 'transaction' and 'session'. > > A web server 'transaction' consists of a request from a user that results > in a page being sent to the user. That's it. It is an isolated action > that does not depend in the web server knowing anything about the user > because all the information it needs to decide which page to send was > supplied when the user sent in the URL of the page. Now if the user > clicks on a link on that page, his browser sends the URL in the link to > the server, which in turn fishes out another page and sends it back to > the user. As far as the server is concerned, there is no connection > whatever between the two requests: either or both URLs could have been > copied from a piece of paper for all it knows or cares. There is no > concept of context or a session involved. > > A 'session' involves context. Think of what happens when you login to a > computer. That starts a login session that has context: the computer now > knows who you are and provides context by connecting you to your login > directory and opening some work space which is used to remember which > directory you're in, what commands you issued (so you can look at the > history), etc. The session and its context persists until you log out. > > In what you're intending to do, a user will start a session by starting > to use your program and that session will last until the user disconnects > from the session. All the web server knows is that instead of finding a > page on disk some place it passes your user's request to your program and > sends its output, in the form of a web page, back to the user. It does > this each time it receives a request from the user because all the user's > requests contain the same URL - that of your program. The server does > this without knowing there is such a thing as a session or that there is > any context belonging to the user. > > The upshot is that your program has to keep track of all the active > sessions and maintain context for each active session. It also needs a > way to recognise and get rid of dead sessions because sessions don't > always end cleanly: the line may go down or the user may forget he was > using your program and turn his PC off. For instance, if the session > context has a timestamp, you might delete it after, say, 20 hours of > inactivity, or when the user logs on again. If the data is sensitive, you > might also force a new logon after 10 minutes of inactivity. > > The database is as good a place as any for keeping session and context > data - if its well structured the context may well form a single (large) > row on one table, but you do need a unique key for it. That could even be > the login name provided you're able to include it in every page you send > to the user and can guarantee that the browser will send it back as part > of the next request. A hidden field on the page will do this > automatically. > > The basic program cycle will be: > > - receive a request > - read the context for the session > - use data in the request to carry out the requested action > - write the updated context back to the database > - create the output page and send it to the user > > though of course you need additional dialogue to deal with both valid and > invalid logons and logoffs. > > > I don't really get how multiple users work in terms of pretty much > > everything else, like if the Python code is running on the server, > > then... well, I just don't know. > > Hopefully the above made it a bit clearer. > > > ?Maybe I should try to get it running > > for multiple discrete users first, and then think about simultaneous > > users, or is that a bad way to go about things? ?Or maybe it will start > > to make more sense when I get into building the interface? ?Any > > info/suggestions are very welcome. > > For bare desktop development I would split the program into three parts: > > 1) the program itself, written to run a single transaction each time its > called. Inputs would be the bits of the users message it needs to act on > and the current session context record. > > 2) a testing harness that accepts user input from the console, sends > output back to the console and maintains a single session context record > in memory: IOW it runs your program in single user mode. > > 3)the web server interface which retrieves the session context record, > passes it and the input to your program and, after that has run, saves > the session context record and passes the output to the web server for > delivery to the user. > > This way both 2 and 3 can be developed against a really simple 'do almost > nothing' version of 1 while that in turn can be developed and tested on > your desktop using 2 and later be dropped into the web server with 3 as > its interface. > > I have an in-house copy of Apache that I'd use to develop your type of > program. Its used for all my website development so that nothing gets > loaded onto my public sites until its been properly checked out here. > You can do the same if you can find and install a really simple web > server that would run on your PC together with a local copy of MySQL - of > course! Given this setup you can use your usual web browser to talk to > the local web server. If you can run all that you won't need 2 because > you can have your simple web server and program running in a console > window on your desktop PC while you hammer it from your web browser. > > -- > martin@ ? | Martin Gregorie > gregorie. | Essex, UK > org ? ? ? | From alice at gothcandy.com Thu Nov 25 03:36:49 2010 From: alice at gothcandy.com (=?utf-8?Q?Alice_Bevan=E2=80=93McGregor?=) Date: Thu, 25 Nov 2010 00:36:49 -0800 Subject: building a web interface References: Message-ID: <2010112500364975026-alice@gothcandycom> Howdy! I'm mildly biased, being the author of the framework, but I can highly recommend WebCore for rapid prototyping of web applications; it has templating via numerous template engines, excellent JSON (AJAJ) support, and support for database back-ends via SQLAlchemy. It also has session support baked-in via a project called Beaker. Documentation is fairly complete, and I can be found camping in the #webcore IRC channel on irc.freenode.net at strange hours. If you can write a class, you can have a fully operational web application in a single file of ~8 lines or so. (Or you can create a complete easy-installable Python package with multiple modules.) For information, see: http://www.web-core.org/ As an interactive-fiction example: class RootController(web.core.Controller): def index(self): """This returns a template that uses JavaScript to call execute(). The JavaScript adds the result of execute() to the display.""" session = db.Session().save() return './templates/main.html', dict(session=session.id) def execute(self, session, statement): """Load our session and pass the input off to our interactive fiction library of choice. Return the result if all went well.""" session = db.Session.get(session) try: result = myiflib.execute(session, statement) except myiflib.ParseError: return 'json:', dict(status="failure", message="Error...") return 'json:', dict(status="success", message=result) ? Alice. From lanyjie at yahoo.com Thu Nov 25 04:12:38 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Thu, 25 Nov 2010 01:12:38 -0800 (PST) Subject: what a cheap rule Message-ID: <478343.25019.qm@web54204.mail.re2.yahoo.com> Sometimes the golden rule in Python of "explicit is better than implicit" is so cheap that it can be thrown away for the trouble of typing an empty tuple. Today when I am explaining that in Python 3, there are two ways to raise exceptions: raise Exception raise Exception() and that the first one is the same as the second one, as Python will add the missing pair of parenthesis. I felt their pain as they gasped. Before that, I have already explained to them this piece of code: try: raise SomeException() except SomeException: print('Got an exception here') by saying that the except-clause will match anything that belong to the SomeException class. Without knowing this secrete piece of information (that a pair of parenthesis is automatically provided), the following code would be hard to understand: try: raise SomeException except SomeException: print('Got an exception here') because the class object SomeException is not an instance of itself, so a not-so-crooked coder will not consider a match here. So, the explicit is better than implicit rule is thrown out of the window so cheaply, that it literally worth less than an empty tuple! Regards, Yingjie From martin at v.loewis.de Thu Nov 25 04:17:05 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Thu, 25 Nov 2010 10:17:05 +0100 Subject: Pypi (Cheeseshop) Score - derivation of ? In-Reply-To: <30d136fe-5fc3-49aa-904d-c63b228e5d2c@n2g2000pre.googlegroups.com> References: <86979c80-0955-4ee8-b645-10097d45dd58@z9g2000pri.googlegroups.com> <30d136fe-5fc3-49aa-904d-c63b228e5d2c@n2g2000pre.googlegroups.com> Message-ID: <4CEE2991.4050303@v.loewis.de> > Occurrence of search term weighted by field (name, summary, keywords, > description, author, maintainer) > > I thought PyPI used to offer a 'kwality' score for packages, based on > the presence of installers, doc files, tests etc. Does anyone know > what happened to that? There was indeed a kwalitee computation (cheesecake); it is unmaintained. It is a urban myth that this had any impact on search results. It never did. Regards, Martin From anurag.chourasia at gmail.com Thu Nov 25 04:24:15 2010 From: anurag.chourasia at gmail.com (Anurag Chourasia) Date: Thu, 25 Nov 2010 14:54:15 +0530 Subject: AIX 5.3 - Enabling Shared Library Support Vs Extensions Message-ID: All, When I configure python to enable shared libraries, none of the extensions are getting built during the make step due to this error. building 'cStringIO' extension gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I. -I/u01/home/apli/wm/GDD/Python-2.6.6/./Include -I. -IInclude -I./Include -I/opt/freeware/include -I/opt/freeware/include/readline -I/opt/freeware/include/ncurses -I/usr/local/include -I/u01/home/apli/wm/GDD/Python-2.6.6/Include -I/u01/home/apli/wm/GDD/Python-2.6.6 -c /u01/home/apli/wm/GDD/Python-2.6.6/Modules/cStringIO.c -o build/temp.aix-5.3-2.6/u01/home/apli/wm/GDD/Python-2.6.6/Modules/cStringIO.o ./Modules/ld_so_aix gcc -pthread -bI:Modules/python.exp build/temp.aix-5.3-2.6/u01/home/apli/wm/GDD/Python-2.6.6/Modules/cStringIO.o -L/usr/local/lib *-lpython2.6* -o build/lib.aix-5.3-2.6/cStringIO.so *collect2: library libpython2.6 not found* building 'cPickle' extension gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I. -I/u01/home/apli/wm/GDD/Python-2.6.6/./Include -I. -IInclude -I./Include -I/opt/freeware/include -I/opt/freeware/include/readline -I/opt/freeware/include/ncurses -I/usr/local/include -I/u01/home/apli/wm/GDD/Python-2.6.6/Include -I/u01/home/apli/wm/GDD/Python-2.6.6 -c /u01/home/apli/wm/GDD/Python-2.6.6/Modules/cPickle.c -o build/temp.aix-5.3-2.6/u01/home/apli/wm/GDD/Python-2.6.6/Modules/cPickle.o ./Modules/ld_so_aix gcc -pthread -bI:Modules/python.exp build/temp.aix-5.3-2.6/u01/home/apli/wm/GDD/Python-2.6.6/Modules/cPickle.o -L/usr/local/lib *-lpython2.6* -o build/lib.aix-5.3-2.6/cPickle.so *collect2: library libpython2.6 not found* This is on AIX 5.3, GCC 4.2, Python 2.6.6 I can confirm that there is a libpython2.6.a file in the top level directory from where I am doing the configure/make etc Here are the options supplied to the configure command ./configure --enable-shared --disable-ipv6 --with-gcc=gcc CPPFLAGS="-I /opt/freeware/include -I /opt/freeware/include/readline -I /opt/freeware/include/ncurses" Please guide me in getting past this error. Thanks for your help on this. Regards, Anurag -------------- next part -------------- An HTML attachment was scrubbed... URL: From a1chandan at gmail.com Thu Nov 25 04:43:21 2010 From: a1chandan at gmail.com (Geobird) Date: Thu, 25 Nov 2010 01:43:21 -0800 (PST) Subject: Processing file with lists. Message-ID: <93ec74ea-7cf1-4671-81f0-d71313d8736f@29g2000prb.googlegroups.com> I have a text file , having fields delimited by ; in the first line and all the way down is the data taken for those fields . Say FAMILY NAME;SPECIES/SUBSPECIES;GENUS NAME;SUBGENUS NAME;SPECIES NAME;SUBSPECIES NAME;AUTHORSHIP Acrididae;Acanthacris ruficornis (Fabricius, 1787);Acanthacris;;ruficornis;;(Fabricius, 1787) Acrididae;Acrida bicolor (Thunberg, 1815);Acrida;;bicolor;;(Thunberg, 1815) Acrididae;Acrida oxycephala (Pallas, 1771);Acrida;;oxycephala;; (Pallas, 1771) Acrididae;Acrida turrita (Linnaeus, 1758);Acrida;;turrita;;(Linnaeus, 1758) I want to know how could I process this file using ' lists ' , that could answer questions like . How many ? , Who did .. ? etc. I am a newbie , and would appreciate your help From lanyjie at yahoo.com Thu Nov 25 04:44:44 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Thu, 25 Nov 2010 01:44:44 -0800 (PST) Subject: a regexp riddle: re.search(r' In-Reply-To: <00a69232-7703-48ce-8a42-b28f24946680@i32g2000pri.googlegroups.com> Message-ID: <933864.19427.qm@web54204.mail.re2.yahoo.com> --- On Thu, 11/25/10, Phlip wrote: > From: Phlip > Subject: a regexp riddle: re.search(r' > To: python-list at python.org > Date: Thursday, November 25, 2010, 8:46 AM > HypoNt: > > I need to turn a human-readable list into a list(): > > ???print re.search(r'(?:(\w+), |and > (\w+))+', 'whatever a, bbb, and > c').groups() > > That currently returns ('c',). I'm trying to match "any > word \w+ > followed by a comma, or a final word preceded by and." > > The match returns 'a, bbb, and c', but the groups return > ('bbb', 'c'). > What do I type for .groups() to also get the 'a'? > First of all, the 'bbb' coresponds to the first capturing group and 'c' the second. But 'a' is forgotten be cause it was the first match of the first group, but there is a second match 'bbb'. Generally, a capturing group only remembers the last match. It also seems that your re may match this: 'and c', which does not seem to be your intention. So it may be more intuitively written as: r'(?:(\w+), )+and (\w+)' I'm not sure how to get it done in one step, but it would be easy to first get the whole match, then process it with: re.findall(r'(\w+)(?:,|$)', the_whole_match) cheers, Yingjie From alice at gothcandy.com Thu Nov 25 04:52:32 2010 From: alice at gothcandy.com (=?utf-8?Q?Alice_Bevan=E2=80=93McGregor?=) Date: Thu, 25 Nov 2010 01:52:32 -0800 Subject: Processing file with lists. References: <93ec74ea-7cf1-4671-81f0-d71313d8736f@29g2000prb.googlegroups.com> Message-ID: <2010112501523211833-alice@gothcandycom> You describe a two-part problem. The first, loading the data, is easily accomplished with the Python CSV module: http://docs.python.org/library/csv.html e.g.: reader = csv.reader(open('filename', 'rb'), delimiter=';', quotechar=None) In the above example, you can iterate over 'reader' in a for loop to read out each row. The values will be returned in a list. You could also use a DictReader to make the data more naturally accessible using name=value pairs. > I want to know how could I process this file using ' lists ' , > that could answer questions like . How many ? , Who did .. ? > etc. This isn't very clear, but if your dataset is small (< 1000 rows or so) you can fairly quickly read the data into RAM then run through the data with loops designed to pull out certain data, though it seems your data would need additional processing. (The authorship information should be split into two separate columns, for example.) An alternative would be to load the data into a relational database like MySQL or even SQLite (which offers in-memory databases), or an object database such as MongoDB which supports advanced querying using map/reduce. You'd have to examine the documentation on these different systems to see which would best fit your use case. I prefer Mongo as it is very easy to get data into and out of, supports SQL-like queries, and map/reduce is extremely powerful. ? Alice. From alice at gothcandy.com Thu Nov 25 05:00:11 2010 From: alice at gothcandy.com (=?utf-8?Q?Alice_Bevan=E2=80=93McGregor?=) Date: Thu, 25 Nov 2010 02:00:11 -0800 Subject: a regexp riddle: re.search(r'(?:(\w+), |and (\w+))+', 'whatever a, bbb, and c') =? ('a', 'bbb', 'c') References: <00a69232-7703-48ce-8a42-b28f24946680@i32g2000pri.googlegroups.com> Message-ID: <2010112502001129201-alice@gothcandycom> Accepting input from a human is frought with dangers and edge cases. ;) Some time ago I wrote a regular expression generator that creates regexen that can parse arbitrarily delimited text, supports quoting (to avoid accidentally separating two elements that should be treated as one), and works in both directions (text<->native). The code that generates the regex is heavily commented: https://github.com/pulp/marrow.util/blob/master/marrow/util/convert.py#L123-234 You should be able to use this as-is and simply handle the optional 'and' on the last element yourself. You can even create an instance of the class with the options you want then get the generated regular expression by running print(parser.pattern). Note that I have friends who use 'and' multiple times when describing lists of things. :P ? Alice. From alice at gothcandy.com Thu Nov 25 05:04:56 2010 From: alice at gothcandy.com (=?utf-8?Q?Alice_Bevan=E2=80=93McGregor?=) Date: Thu, 25 Nov 2010 02:04:56 -0800 Subject: a regexp riddle: re.search(r'(?:(\w+), |and (\w+))+', 'whatever a, bbb, and c') =? ('a', 'bbb', 'c') References: <00a69232-7703-48ce-8a42-b28f24946680@i32g2000pri.googlegroups.com> Message-ID: <2010112502045628565-alice@gothcandycom> Now that I think about it, and can be stripped using a callback function as the 'normalize' argument to my KeywordProcessor class: def normalize(value): value = value.strip() if value.startswith("and"): value = value[3:] return value parser = KeywordProcessor(',', normalize=normalize, result=list) ? Alice. From stefan-usenet at bytereef.org Thu Nov 25 05:11:17 2010 From: stefan-usenet at bytereef.org (Stefan Krah) Date: Thu, 25 Nov 2010 11:11:17 +0100 Subject: AIX 5.3 - Enabling Shared Library Support Vs Extensions In-Reply-To: References: Message-ID: <20101125101117.GA3437@yoda.bytereef.org> Anurag Chourasia wrote: > When I configure python to enable shared libraries, none of the extensions are getting built during the make step due to this error. > > building 'cStringIO' extension > gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall > -Wstrict-prototypes -I. -I/u01/home/apli/wm/GDD/Python-2.6.6/./Include -I. > -IInclude -I./Include -I/opt/freeware/include > -I/opt/freeware/include/readline -I/opt/freeware/include/ncurses > -I/usr/local/include -I/u01/home/apli/wm/GDD/Python-2.6.6/Include > -I/u01/home/apli/wm/GDD/Python-2.6.6 -c > /u01/home/apli/wm/GDD/Python-2.6.6/Modules/cStringIO.c -o > build/temp.aix-5.3-2.6/u01/home/apli/wm/GDD/Python-2.6.6/Modules/cStringIO.o > ./Modules/ld_so_aix gcc -pthread -bI:Modules/python.exp > build/temp.aix-5.3-2.6/u01/home/apli/wm/GDD/Python-2.6.6/Modules/cStringIO.o > -L/usr/local/lib *-lpython2.6* -o build/lib.aix-5.3-2.6/cStringIO.so ^^^^^^^^^^^^^^^^ Try these flags: -L. -L/usr/local/lib If this solves the problem and the issue is also present in Python-2.7, you should report a bug at http://bugs.python.org/ . Stefan Krah From lanyjie at yahoo.com Thu Nov 25 06:06:03 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Thu, 25 Nov 2010 03:06:03 -0800 (PST) Subject: tilted text in the turtle module Message-ID: <709508.49315.qm@web54207.mail.re2.yahoo.com> First of all, I'd like to express my deep gratidute to the author of this module, it is such a fun module to work with and to teach python as a first programming language. Secondly, I would like to request a feature if it is not too hard to achieve. Currently, you can only write texts horizontally, no matter what is the current orientation of the turtle pen. I wonder if it is possible to write text in any direction when we control the heading of the turtle? For example, the following code would write a vertically oriented text: setheading(90) #turtle facing up write("vertical text!") Thanks a lot! Yingjie From egarrulo at gmail.com Thu Nov 25 06:23:33 2010 From: egarrulo at gmail.com (Elena) Date: Thu, 25 Nov 2010 03:23:33 -0800 (PST) Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> Message-ID: <9059b217-e3a4-4e82-a9a1-a84aafef942d@s9g2000vby.googlegroups.com> On Oct 13, 9:09?pm, namekuseijin wrote: > On 11 out, 08:49, Oleg ?Parashchenko wrote: > > > > > Hello, > > > I'd like to try the idea that Scheme can be considered as a new > > portable assembler. We could code something in Scheme and then compile > > it to PHP or Python or Java or whatever. > > > Any suggestions and pointers to existing and related work are welcome. > > Thanks! > > > My current approach is to take an existing Scheme implementation and > > hijack into its backend. At this moment Scheme code is converted to > > some representation with a minimal set of bytecodes, and it should be > > quite easy to compile this representation to a target language. After > > some research, the main candidates are Gambit, Chicken and CPSCM: > > >http://uucode.com/blog/2010/09/28/r5rs-scheme-as-a-virtual-machine-i/... > > > If there is an interest in this work, I could publish progress > > reports. > > > -- > > Oleg Parashchenko ?olpa at http://uucode.com/http://uucode.com/blog/?XML, TeX, Python, Mac, Chess > > it may be assembler, too bad scheme libs are scattered around written > in far too many different flavors of assembler... > > It warms my heart though to realize that Scheme's usual small size and > footprint has allowed for many quality implementations targetting many > different backends, be it x86 assembly, C, javascript or .NET. ?Take > python and you have a slow c bytecode interpreter and a slow > bytecode .NET compiler. ?Take haskell and its so friggin' huge and > complex that its got its very own scary monolithic gcc. ?When you > think of it, Scheme is the one true high-level language with many > quality perfomant backends -- CL has a few scary compilers for native > code, but not one to java, .NET or javascript that I know of... Take R5RS Scheme and you get a language which doesn't allow you to get things done. Scheme is as far from Assembly as one language can be. Assembly exists to get things done, R5RS Scheme does not even allows you load native libraries of the underlying operating-system, does it? It's easy to stay small and clean when you don't have to dirty your hands with such crap as real-world applications development. From lanyjie at yahoo.com Thu Nov 25 06:32:54 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Thu, 25 Nov 2010 03:32:54 -0800 (PST) Subject: the buggy regex in Python Message-ID: <297677.64235.qm@web54207.mail.re2.yahoo.com> I know many experts will say I don't have understanding...but let me pay this up front as my tuition. Here are some puzzling results I have got (I am using Python 3, I suppose similar results for python 2). When I do the following, I got an exception: >>> re.findall('(d*)*', 'adb') >>> re.findall('((d)*)*', 'adb') When I do this, I am fine but the result is wrong: >>> re.findall('((.d.)*)*', 'adb') [('', 'adb'), ('', '')] Why is it wrong? The first mactch of groups: ('', 'adb') indicates the outer group ((.d.)*) captured the empty string, while the inner group (.d.) captured 'adb', so the outer group must have captured the empty string at the end of the provided string 'adb'. Once we have matched the final empty string '', there should be no more matches, but we got another match ('', '')!!! So, findall matched the empty string in the end of the string twice!!! Isn't this a bug? Yingjie From santiago.caracol at gmail.com Thu Nov 25 07:38:45 2010 From: santiago.caracol at gmail.com (Santiago Caracol) Date: Thu, 25 Nov 2010 04:38:45 -0800 (PST) Subject: do something every n seconds Message-ID: <1a7afe44-b320-4135-9b9d-6b99b6c809b6@p38g2000vbn.googlegroups.com> Hello, how can I do something (e.g. check if new files are in the working directory) every n seconds in Python? Santiago From alice at gothcandy.com Thu Nov 25 07:51:52 2010 From: alice at gothcandy.com (=?utf-8?Q?Alice_Bevan=E2=80=93McGregor?=) Date: Thu, 25 Nov 2010 04:51:52 -0800 Subject: do something every n seconds References: <1a7afe44-b320-4135-9b9d-6b99b6c809b6@p38g2000vbn.googlegroups.com> Message-ID: <2010112504515230363-alice@gothcandycom> > how can I do something (e.g. check if new files are in the working > directory) every n seconds in Python? The simplest method is executing time.sleep(n) within an infinite while loop. There are more elegant solutions: using coroutine frameworks, threaded task schedulers, etc. ? Alice. From no.email at nospam.invalid Thu Nov 25 07:57:44 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 25 Nov 2010 04:57:44 -0800 Subject: do something every n seconds References: <1a7afe44-b320-4135-9b9d-6b99b6c809b6@p38g2000vbn.googlegroups.com> Message-ID: <7x1v698ss7.fsf@ruckus.brouhaha.com> Santiago Caracol writes: > how can I do something (e.g. check if new files are in the working > directory) every n seconds in Python? Don't do it that way if you can help it. Use inotify or the equivalent instead. From stefan.sonnenberg at pythonmeister.com Thu Nov 25 08:20:35 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Thu, 25 Nov 2010 14:20:35 +0100 Subject: do something every n seconds In-Reply-To: <1a7afe44-b320-4135-9b9d-6b99b6c809b6@p38g2000vbn.googlegroups.com> References: <1a7afe44-b320-4135-9b9d-6b99b6c809b6@p38g2000vbn.googlegroups.com> Message-ID: <3b6743bee362727aeaed621874f54f01-EhVcX1lJRApWRxoDCzpQCEFddQZLVF5dQUBFCzBYWENGU1kWXlpwH1RcWzBeQ0wCWVNYQltQ-webmailer1@server05.webmailer.hosteurope.de> Windows or UNIX ? Am Do, 25.11.2010, 13:38 schrieb Santiago Caracol: > Hello, > > how can I do something (e.g. check if new files are in the working > directory) every n seconds in Python? > > Santiago > -- > http://mail.python.org/mailman/listinfo/python-list > > -- MfG, Stefan Sonnenberg-Carstens IT Architect From awilliam at whitemice.org Thu Nov 25 08:37:32 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Thu, 25 Nov 2010 08:37:32 -0500 Subject: do something every n seconds In-Reply-To: <1a7afe44-b320-4135-9b9d-6b99b6c809b6@p38g2000vbn.googlegroups.com> References: <1a7afe44-b320-4135-9b9d-6b99b6c809b6@p38g2000vbn.googlegroups.com> Message-ID: <1290692252.7849.0.camel@linux-yu4c.site> On Thu, 2010-11-25 at 04:38 -0800, Santiago Caracol wrote: > how can I do something (e.g. check if new files are in the working > directory) every n seconds in Python? Use the Python Advanced Scheduler in your application - it is a great little module. Then you've solved every 'scheduler' issue your application will ever have. -- Adam Tauno Williams LPIC-1, Novell CLA OpenGroupware, Cyrus IMAPd, Postfix, OpenLDAP, Samba From python at bdurham.com Thu Nov 25 09:21:16 2010 From: python at bdurham.com (python at bdurham.com) Date: Thu, 25 Nov 2010 09:21:16 -0500 Subject: a regexp riddle: re.search(r'(?:(\w+), |and (\w+))+', 'whatever a, bbb, and c') =? ('a', 'bbb', 'c') In-Reply-To: <00a69232-7703-48ce-8a42-b28f24946680@i32g2000pri.googlegroups.com> References: <00a69232-7703-48ce-8a42-b28f24946680@i32g2000pri.googlegroups.com> Message-ID: <1290694876.8561.1407151613@webmail.messagingengine.com> Phlip, > I'm trying to match "any word \w+ followed by a comma, or a final word preceded by and." Here's a non-regex solution that handles multi-word values and multiple instances of 'and' (as pointed out by Alice). The posted code could be simplified via list comprehension - I chose the more verbose method to illustrate the logic. def to_list( text ): text = text.replace( ' and ', ',' ) output = list() for item in text.split( ',' ): if item: output.append( item.strip() ) return output test = 'cat, dog, big fish, goat and puppy and horse' print to_list( test ) Outputs: ['cat', 'dog', 'big fish', 'goat', 'puppy', 'horse'] Malcolm From jeanmichel at sequans.com Thu Nov 25 09:40:49 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 25 Nov 2010 15:40:49 +0100 Subject: regexp matching end of line or comma Message-ID: <4CEE7571.2010401@sequans.com> Hy guys, I'm struggling matching patterns ending with a comma ',' or an end of line '$'. import re ex1 = 'sumthin,' ex2 = 'sumthin' m1 = re.match('(?P\S+),', ex1) m2 = re.match('(?P\S+)$', ex2) m3 = re.match('(?P\S+)[,$]', ex1) m4 = re.match('(?P\S+)[,$]', ex2) print m1, m2 print m3 print m4 <_sre.SRE_Match object at 0x8834de0> <_sre.SRE_Match object at 0x8834e20> <_sre.SRE_Match object at 0x8834e60> None My problem is that m4 is None while I'd like it to match ex2. Any clue ? JM From steve at holdenweb.com Thu Nov 25 09:54:36 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 25 Nov 2010 08:54:36 -0600 Subject: what a cheap rule In-Reply-To: <478343.25019.qm@web54204.mail.re2.yahoo.com> References: <478343.25019.qm@web54204.mail.re2.yahoo.com> Message-ID: On 11/25/2010 3:12 AM, Yingjie Lan wrote: > Sometimes the golden rule in Python of > "explicit is better than implicit" is > so cheap that it can be thrown away > for the trouble of typing an empty tuple. > I'm not sure that there *are* any golden rules. The "Zen of Python" is intended to be guidelines, not rigid rules intended to constrain your behavior but advice to help you write better code. > Today when I am explaining that in Python 3, > there are two ways to raise exceptions: > > raise Exception > > raise Exception() > > and that the first one is the same > as the second one, as Python will add the > missing pair of parenthesis. > In fact this is noting to do with Python 3 - the same is true of Python 2, so this isn't new: Python 2.6.5 (r265:79063, Jun 12 2010, 17:07:01) [GCC 4.3.4 20090804 (release) 1] on cygwin Type "help", "copyright", "credits" or "license" for more information. >>> raise KeyError Traceback (most recent call last): File "", line 1, in KeyError >>> raise KeyError("Here is the message") Traceback (most recent call last): File "", line 1, in KeyError: 'Here is the message' >>> > I felt their pain as they gasped. > Before that, I have already explained > to them this piece of code: > > try: raise SomeException() > except SomeException: > print('Got an exception here') > > by saying that the except-clause > will match anything > that belong to the SomeException class. > Or any of its subclasses ... > Without knowing this secrete > piece of information (that a > pair of parenthesis is automatically > provided), the following code > would be hard to understand: > > try: raise SomeException > except SomeException: > print('Got an exception here') > > because the class object SomeException > is not an instance of itself, so > a not-so-crooked coder will not > consider a match here. > It's a matter of understanding correctly how the interpreter operates (and the interactive interpreter session is the ideal place to investigate this). The 2.7 documentation for the raise statement says (and this is not new): """ If the first object is an instance, the type of the exception is the class of the instance, the instance itself is the value, and the second object must be None. If the first object is a class, it becomes the type of the exception. The second object is used to determine the exception value: If it is an instance of the class, the instance becomes the exception value. If the second object is a tuple, it is used as the argument list for the class constructor; if it is None, an empty argument list is used, and any other object is treated as a single argument to the constructor. The instance so created by calling the constructor is used as the exception value. """ So the interpreter doesn't really "automatically provide a pair of parentheses", but examines the exception object and instantiates it if it is a class. > So, the explicit is better than > implicit rule is thrown out of > the window so cheaply, > that it literally worth less > than an empty tuple! > Surely an exaggeration. In fact current best practice (which you should inform yourself of as best you can to help you in your teaching work - so you are to be congratulated for bringing this question to the list) is to always use explicit calls, with arguments specifying a tailored message. > Regards, > > Yingjie > > regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Thu Nov 25 10:00:59 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 25 Nov 2010 09:00:59 -0600 Subject: tilted text in the turtle module In-Reply-To: <709508.49315.qm@web54207.mail.re2.yahoo.com> References: <709508.49315.qm@web54207.mail.re2.yahoo.com> Message-ID: On 11/25/2010 5:06 AM, Yingjie Lan wrote: > First of all, I'd like to express my deep gratidute to the author of this module, it is such a fun module to work with and to teach python as a first programming language. > > Secondly, I would like to request a feature if it is not too hard to achieve. Currently, you can only write texts horizontally, no matter what is the current orientation of the turtle pen. I wonder if it is possible to write text in any direction when we control the heading of the turtle? For example, the following code would write a vertically oriented text: > > setheading(90) #turtle facing up > write("vertical text!") > > Thanks a lot! > Yingjie: This sounds like a good idea. To request a feature you should create an account (if you do not already have one) on bugs.python.org and create a new issue (assuming a search reveals that there is not already such an issue). You may find if you look at the module's code that you can imagine how to make the change. If not, the request will wait until some maintainer sees it and has time. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Thu Nov 25 10:05:49 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 25 Nov 2010 09:05:49 -0600 Subject: do something every n seconds In-Reply-To: <1a7afe44-b320-4135-9b9d-6b99b6c809b6@p38g2000vbn.googlegroups.com> References: <1a7afe44-b320-4135-9b9d-6b99b6c809b6@p38g2000vbn.googlegroups.com> Message-ID: On 11/25/2010 6:38 AM, Santiago Caracol wrote: > Hello, > > how can I do something (e.g. check if new files are in the working > directory) every n seconds in Python? > Look at the sched library, which was written to take care of requirements like this. Use time.sleep() as your delay function and time.time() as your time function. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Thu Nov 25 10:25:52 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 25 Nov 2010 09:25:52 -0600 Subject: a regexp riddle: re.search(r'(?:(\w+), |and (\w+))+', 'whatever a, bbb, and c') =? ('a', 'bbb', 'c') In-Reply-To: <00a69232-7703-48ce-8a42-b28f24946680@i32g2000pri.googlegroups.com> References: <00a69232-7703-48ce-8a42-b28f24946680@i32g2000pri.googlegroups.com> Message-ID: On 11/24/2010 10:46 PM, Phlip wrote: > HypoNt: > > I need to turn a human-readable list into a list(): > > print re.search(r'(?:(\w+), |and (\w+))+', 'whatever a, bbb, and > c').groups() > > That currently returns ('c',). I'm trying to match "any word \w+ > followed by a comma, or a final word preceded by and." > > The match returns 'a, bbb, and c', but the groups return ('bbb', 'c'). > What do I type for .groups() to also get the 'a'? > > Please go easy on me (and no RTFM!), because I have only been using > regular expressions for about 20 years... A kind of lazy way just uses a pattern for the separators to fuel a call to re.split(). I assume that " and " and " , " are both acceptable in any position: The best I've been able to do so far (due to split's annoying habit of including the matches of any groups in the pattern I have to throw away every second element) is: >>> re.split("\s*(,|and)?\s*", 'whatever a, bbb, and c')[::2] ['whatever', 'a', 'bbb', '', 'c'] That empty string is because of the ", and" which isn't recognise as a single delimiter. A parsing package might give you better results. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From python at mrabarnett.plus.com Thu Nov 25 10:54:55 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 25 Nov 2010 15:54:55 +0000 Subject: SQLite date fields In-Reply-To: <4CEDB1B5.4040008@baselinedata.co.uk> References: <4CEDB1B5.4040008@baselinedata.co.uk> Message-ID: <4CEE86CF.3010202@mrabarnett.plus.com> On 25/11/2010 00:45, Alan Harris-Reid wrote: > > Hi, > > I am having design problems with date storage/retrieval using Python and > SQLite. > > I understand that a SQLite date column stores dates as text in ISO > format (ie. '2010-05-25'). So when I display a British date (eg. on a > web-page) I convert the date using > datetime.datetime.strptime(mydate,'%Y-%m-%d').strftime('%d/%m/%Y'). > > However, when it comes to writing-back data to the table, SQLite is very > forgiving and is quite happy to store '25/06/2003' in a date field, but > this is not ideal because a) I could be left with a mixture of date > formats in the same column, b) SQLite's date functions only work with > ISO format. > Therefore I need to convert the date string back to ISO format before > committing, but then I would need a generic function which checks data > about to be written in all date fields and converts to ISO if necessary. > That sounds a bit tedious to me, but maybe it is inevitable. > > Are there simpler solutions? Would it be easier to change the date field > to a 10-character field and store 'dd/mm/yyyy' throughout the table? > This way no conversion is required when reading or writing from the > table, and I could use datetime() functions if I needed to perform any > date-arithmetic. > > How have other developers overcome this problem? Any help would be > appreciated. For the record, I am using SQLite3 with Python 3.1. > Even when storing a date as text, I always prefer to use ISO format because it makes sorting by date easier and there's less chance of confusion over UK vs US date format. From raffaelcavallaro at pas.despam.s.il.vous.plait.mac.com Thu Nov 25 10:56:09 2010 From: raffaelcavallaro at pas.despam.s.il.vous.plait.mac.com (Raffael Cavallaro) Date: Thu, 25 Nov 2010 10:56:09 -0500 Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014020136.6e85d70b@tritium.streitmacht.eu> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> <08823dd4-588a-4729-a660-711e266c96b0@y23g2000yqd.googlegroups.com> <396f8de7-ece5-4e9c-919b-886eb65ae14a@a30g2000vbt.googlegroups.com> <967678a1-fc5d-4b61-86c5-79a298999582@p1g2000vbo.googlegroups.com> <18cd9337-736b-427c-9cac-14c99056750a@p1g2000yqm.googlegroups.com> Message-ID: On 2010-11-24 16:19:49 -0500, toby said: > And furthermore, he has cooties. Once again, not all ad hominem arguments are ad hominem fallacies. Financial conflict of interest is a prime example of a perfectly valid ad hominem argument. People who parse patterns but not semantics are apt to fall into the error of believing that "ad hominem" automatically means "logically invalid." This is not the case. warmest regards, Ralph -- Raffael Cavallaro From sol2ray at gmail.com Thu Nov 25 11:02:49 2010 From: sol2ray at gmail.com (Sol Toure) Date: Thu, 25 Nov 2010 11:02:49 -0500 Subject: regexp matching end of line or comma In-Reply-To: <4CEE7571.2010401@sequans.com> References: <4CEE7571.2010401@sequans.com> Message-ID: Try this: '(?P\S+)(,|$)' On Thu, Nov 25, 2010 at 9:40 AM, Jean-Michel Pichavant < jeanmichel at sequans.com> wrote: > Hy guys, > > I'm struggling matching patterns ending with a comma ',' or an end of line > '$'. > > import re > > ex1 = 'sumthin,' > ex2 = 'sumthin' > m1 = re.match('(?P\S+),', ex1) > m2 = re.match('(?P\S+)$', ex2) > m3 = re.match('(?P\S+)[,$]', ex1) > m4 = re.match('(?P\S+)[,$]', ex2) > > print m1, m2 > print m3 > print m4 > > <_sre.SRE_Match object at 0x8834de0> <_sre.SRE_Match object at 0x8834e20> > <_sre.SRE_Match object at 0x8834e60> > None > > My problem is that m4 is None while I'd like it to match ex2. > > Any clue ? > > JM > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://www.afroblend.com African news as it happens. -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Thu Nov 25 11:06:45 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 25 Nov 2010 16:06:45 +0000 Subject: regexp matching end of line or comma In-Reply-To: <4CEE7571.2010401@sequans.com> References: <4CEE7571.2010401@sequans.com> Message-ID: <4CEE8995.9070305@mrabarnett.plus.com> On 25/11/2010 14:40, Jean-Michel Pichavant wrote: > Hy guys, > > I'm struggling matching patterns ending with a comma ',' or an end of > line '$'. > > import re > > ex1 = 'sumthin,' > ex2 = 'sumthin' > m1 = re.match('(?P\S+),', ex1) > m2 = re.match('(?P\S+)$', ex2) > m3 = re.match('(?P\S+)[,$]', ex1) > m4 = re.match('(?P\S+)[,$]', ex2) > > print m1, m2 > print m3 > print m4 > > <_sre.SRE_Match object at 0x8834de0> <_sre.SRE_Match object at 0x8834e20> > <_sre.SRE_Match object at 0x8834e60> > None > > My problem is that m4 is None while I'd like it to match ex2. > > Any clue ? > Within a character set '$' is a literal '$' and not end-of-string, just as '\b' is '\x08' and not word-boundary. Use a lookahead instead: >>> re.match('(?P\S+)(?=,|$)', ex1) <_sre.SRE_Match object at 0x01719FA0> >>> re.match('(?P\S+)(?=,|$)', ex2) <_sre.SRE_Match object at 0x016937E0> From namekuseijin at gmail.com Thu Nov 25 11:11:19 2010 From: namekuseijin at gmail.com (namekuseijin) Date: Thu, 25 Nov 2010 08:11:19 -0800 (PST) Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <9059b217-e3a4-4e82-a9a1-a84aafef942d@s9g2000vby.googlegroups.com> Message-ID: <518ff093-af28-4c09-b692-9e3b6e936ef7@i10g2000prd.googlegroups.com> On 25 nov, 09:23, Elena wrote: > On Oct 13, 9:09?pm, namekuseijin wrote: > > > > > > > On 11 out, 08:49, Oleg ?Parashchenko wrote: > > > > Hello, > > > > I'd like to try the idea that Scheme can be considered as a new > > > portable assembler. We could code something in Scheme and then compile > > > it to PHP or Python or Java or whatever. > > > > Any suggestions and pointers to existing and related work are welcome. > > > Thanks! > > > > My current approach is to take an existing Scheme implementation and > > > hijack into its backend. At this moment Scheme code is converted to > > > some representation with a minimal set of bytecodes, and it should be > > > quite easy to compile this representation to a target language. After > > > some research, the main candidates are Gambit, Chicken and CPSCM: > > > >http://uucode.com/blog/2010/09/28/r5rs-scheme-as-a-virtual-machine-i/... > > > > If there is an interest in this work, I could publish progress > > > reports. > > > > -- > > > Oleg Parashchenko ?olpa at http://uucode.com/http://uucode.com/blog/?XML, TeX, Python, Mac, Chess > > > it may be assembler, too bad scheme libs are scattered around written > > in far too many different flavors of assembler... > > > It warms my heart though to realize that Scheme's usual small size and > > footprint has allowed for many quality implementations targetting many > > different backends, be it x86 assembly, C, javascript or .NET. ?Take > > python and you have a slow c bytecode interpreter and a slow > > bytecode .NET compiler. ?Take haskell and its so friggin' huge and > > complex that its got its very own scary monolithic gcc. ?When you > > think of it, Scheme is the one true high-level language with many > > quality perfomant backends -- CL has a few scary compilers for native > > code, but not one to java, .NET or javascript that I know of... > > Take R5RS Scheme and you get a language which doesn't allow you to get > things done. > > Scheme is as far from Assembly as one language can be. ?Assembly > exists to get things done, R5RS Scheme does not even allows you load > native libraries of the underlying operating-system, does it? ?It's > easy to stay small and clean when you don't have to dirty your hands > with such crap as real-world applications development.- Ocultar texto das mensagens anteriores - assembly in the sense that it's what other languages could compile to. Like many are targetting javascript, the de facto assembly of the web... In any case, the original poster was advocating the opposite: to code in Scheme and compile it to more common backends, such as PHP or javascript... I misunderstood his point. But the flamewars that followed were far more entertaining anyway... :) From lanyjie at yahoo.com Thu Nov 25 11:15:21 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Thu, 25 Nov 2010 08:15:21 -0800 (PST) Subject: what a cheap rule In-Reply-To: Message-ID: <146414.53554.qm@web54206.mail.re2.yahoo.com> --- On Thu, 11/25/10, Steve Holden wrote: > > Sometimes the golden rule in Python of > > "explicit is better than implicit" is > > so cheap that it can be thrown away > > for the trouble of typing an empty tuple. > > > I'm not sure that there *are* any golden rules. The "Zen of > Python" is > intended to be guidelines, not rigid rules intended to > constrain your > behavior but advice to help you write better code. > > > Surely an exaggeration. In fact current best practice > (which you should > inform yourself of as best you can to help you in your > teaching work - > so you are to be congratulated for bringing this question > to the list) > is to always use explicit calls, with arguments specifying > a tailored > message. > > regards > Steve A very cogent message -- the end echos the start. :) I must say that I learned from you a new angle to think about this issue. On the other hand, I still feel that when allowing both ways colliding into the simpleness and bueaty of the language, we should consider to make a decision. Sure, this introduced quite a lot of complexity when the doc has to give a very long explanation of what is happening in order to justify it. As I am thinking about it, it seems two conflicting intuition of code comprehension are at work here: Intuition #1: as if you raise an exception type, and then match that type. It seems that no instances are involved here (Intuitively). See an example code here: try: raise KeyError except KeyError: pass Intuition #2: you raise an exception instance, and then match an instance by its type. See an example code here: try: raise KeyError() except KeyError as ke: pass Those two comprehensions are not compatible, and thus the one that promotes correct understanding should be encouraged, while the other should be discouraged, and maybe even be made iliegal. Regards, Yingjie From python at mrabarnett.plus.com Thu Nov 25 11:16:15 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 25 Nov 2010 16:16:15 +0000 Subject: a regexp riddle: re.search(r'(?:(\w+), |and (\w+))+', 'whatever a, bbb, and c') =? ('a', 'bbb', 'c') In-Reply-To: <00a69232-7703-48ce-8a42-b28f24946680@i32g2000pri.googlegroups.com> References: <00a69232-7703-48ce-8a42-b28f24946680@i32g2000pri.googlegroups.com> Message-ID: <4CEE8BCF.6030103@mrabarnett.plus.com> On 25/11/2010 04:46, Phlip wrote: > HypoNt: > > I need to turn a human-readable list into a list(): > > print re.search(r'(?:(\w+), |and (\w+))+', 'whatever a, bbb, and > c').groups() > > That currently returns ('c',). I'm trying to match "any word \w+ > followed by a comma, or a final word preceded by and." > > The match returns 'a, bbb, and c', but the groups return ('bbb', 'c'). > What do I type for .groups() to also get the 'a'? > > Please go easy on me (and no RTFM!), because I have only been using > regular expressions for about 20 years... > Try re.findall: >>> re.findall(r'(\w+), |and (\w+)', 'whatever a, bbb, and c') [('a', ''), ('bbb', ''), ('', 'c')] You can get a list of strings like this: >>> [x or y for x, y in re.findall(r'(\w+), |and (\w+)', 'whatever a, bbb, and c')] ['a', 'bbb', 'c'] From jeanmichel at sequans.com Thu Nov 25 11:26:34 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 25 Nov 2010 17:26:34 +0100 Subject: regexp matching end of line or comma In-Reply-To: <4CEE8995.9070305@mrabarnett.plus.com> References: <4CEE7571.2010401@sequans.com> <4CEE8995.9070305@mrabarnett.plus.com> Message-ID: <4CEE8E3A.3040707@sequans.com> MRAB wrote: > On 25/11/2010 14:40, Jean-Michel Pichavant wrote: >> Hy guys, >> >> I'm struggling matching patterns ending with a comma ',' or an end of >> line '$'. >> >> import re >> >> ex1 = 'sumthin,' >> ex2 = 'sumthin' >> m1 = re.match('(?P\S+),', ex1) >> m2 = re.match('(?P\S+)$', ex2) >> m3 = re.match('(?P\S+)[,$]', ex1) >> m4 = re.match('(?P\S+)[,$]', ex2) >> >> print m1, m2 >> print m3 >> print m4 >> >> <_sre.SRE_Match object at 0x8834de0> <_sre.SRE_Match object at >> 0x8834e20> >> <_sre.SRE_Match object at 0x8834e60> >> None >> >> My problem is that m4 is None while I'd like it to match ex2. >> >> Any clue ? >> > Within a character set '$' is a literal '$' and not end-of-string, just > as '\b' is '\x08' and not word-boundary. > > Use a lookahead instead: > > >>> re.match('(?P\S+)(?=,|$)', ex1) > <_sre.SRE_Match object at 0x01719FA0> > >>> re.match('(?P\S+)(?=,|$)', ex2) > <_sre.SRE_Match object at 0x016937E0> thanks, it works that way. By the way I don't get the difference between non capturing parentesis (?:) and lookahead parenthesis (?=): re.match('(?P\S+)(?:,|$)', ex2).groups() ('sumthin',) re.match('(?P\S+)(?=,|$)', ex2).groups() ('sumthin',) JM From python at mrabarnett.plus.com Thu Nov 25 11:30:12 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 25 Nov 2010 16:30:12 +0000 Subject: the buggy regex in Python In-Reply-To: <297677.64235.qm@web54207.mail.re2.yahoo.com> References: <297677.64235.qm@web54207.mail.re2.yahoo.com> Message-ID: <4CEE8F14.4030704@mrabarnett.plus.com> On 25/11/2010 11:32, Yingjie Lan wrote: > I know many experts will say I don't have understanding...but let me pay this up front as my tuition. > > Here are some puzzling results I have got (I am using Python 3, I suppose similar results for python 2). > > When I do the following, I got an exception: >>>> re.findall('(d*)*', 'adb') >>>> re.findall('((d)*)*', 'adb') > A repeated repeat can cause problems if what is repeated can match an empty string. The "re" module tries to protect itself by forbidding such a regex. The "regex" module (available from PyPI) accepts that regex and returns a result. > When I do this, I am fine but the result is wrong: >>>> re.findall('((.d.)*)*', 'adb') > [('', 'adb'), ('', '')] > > Why is it wrong? > > The first mactch of groups: > ('', 'adb') > indicates the outer group ((.d.)*) captured > the empty string, while the inner group (.d.) > captured 'adb', so the outer group must have > captured the empty string at the end of the > provided string 'adb'. > > Once we have matched the final empty string '', > there should be no more matches, but we got > another match ('', '')!!! > > So, findall matched the empty string in > the end of the string twice!!! > re.findall performs multiple searches, each starting where the previous one finished. The first match started at the start of the string and finished at its end. The second match started at that point (the end of the string) and found another match, ending at the end of the string. It tried to match a third time, but that failed because it would have matched an empty string again (it's not allowed to return 2 contiguous empty strings). > Isn't this a bug? > No, but it can be confusing at times! :-) From m_mommer at yahoo.com Thu Nov 25 11:30:12 2010 From: m_mommer at yahoo.com (Mario S. Mommer) Date: Thu, 25 Nov 2010 17:30:12 +0100 Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014020136.6e85d70b@tritium.streitmacht.eu> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> <08823dd4-588a-4729-a660-711e266c96b0@y23g2000yqd.googlegroups.com> <396f8de7-ece5-4e9c-919b-886eb65ae14a@a30g2000vbt.googlegroups.com> <967678a1-fc5d-4b61-86c5-79a298999582@p1g2000vbo.googlegroups.com> <18cd9337-736b-427c-9cac-14c99056750a@p1g2000yqm.googlegroups.com> Message-ID: <87vd3l8iy3.fsf@padme.localdomain> Raffael Cavallaro writes: > On 2010-11-24 16:19:49 -0500, toby said: > >> And furthermore, he has cooties. > > Once again, not all ad hominem arguments are ad hominem > fallacies. Financial conflict of interest is a prime example of a > perfectly valid ad hominem argument. It has limited validity. People are way more complicated than the simplistic "follow your own selfish egoistic interests to the letter without taking prisoners" model of human behavior that seems (unfortunately) so prevalent nowadays. > People who parse patterns but not semantics are apt to fall into the > error of believing that "ad hominem" automatically means "logically > invalid." This is not the case. In the realm of pure logic, ad hominems are logically invalid, period. However, if the question cannot be resolved by its own merits, simple logic has little to say, and you may include additional information in a sort-of Bayesian fashion. Saying that a conflict of interest means that nothing this person says makes any sense at all is in a way an admission that the subject of discussion is not very amenable to rational argument. From lanyjie at yahoo.com Thu Nov 25 11:44:51 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Thu, 25 Nov 2010 08:44:51 -0800 (PST) Subject: the buggy regex in Python In-Reply-To: <4CEE8F14.4030704@mrabarnett.plus.com> Message-ID: <120830.69127.qm@web54206.mail.re2.yahoo.com> --- On Thu, 11/25/10, MRAB wrote: > re.findall performs multiple searches, each starting where > the previous > one finished. The first match started at the start of the > string and > finished at its end. The second match started at that point > (the end of > the string) and found another match, ending at the end of > the string. > It tried to match a third time, but that failed because it > would have > matched an empty string again (it's not allowed to return 2 > contiguous > empty strings). > > > Isn't this a bug? > > > No, but it can be confusing at times! :-) > -- But the last empty string is matched twice -- so it is an overlapping. But findall is supposed not to return overlapping matches. So I think this does not live up to the documentation -- thus I still consider it a bug. Yingjie From lanyjie at yahoo.com Thu Nov 25 11:49:53 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Thu, 25 Nov 2010 08:49:53 -0800 (PST) Subject: tilted text in the turtle module In-Reply-To: Message-ID: <933894.81836.qm@web54207.mail.re2.yahoo.com> --- On Thu, 11/25/10, Steve Holden wrote: > From: Steve Holden > Subject: Re: tilted text in the turtle module > To: python-list at python.org > Date: Thursday, November 25, 2010, 7:00 PM > On 11/25/2010 5:06 AM, Yingjie Lan > wrote: > This sounds like a good idea. To request a feature you > should create an > account (if you do not already have one) on bugs.python.org > and create a > new issue (assuming a search reveals that there is not > already such an > issue). > Thanks I just did that. > You may find if you look at the module's code that you can > imagine how > to? make the change. If not, the request will wait > until some maintainer > sees it and has time. > I don't know much about tkinter, not sure if I can contribute. And even if I made a patch, then how to publish it? Regards, Yingjie From python at mrabarnett.plus.com Thu Nov 25 12:07:53 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 25 Nov 2010 17:07:53 +0000 Subject: regexp matching end of line or comma In-Reply-To: <4CEE8E3A.3040707@sequans.com> References: <4CEE7571.2010401@sequans.com> <4CEE8995.9070305@mrabarnett.plus.com> <4CEE8E3A.3040707@sequans.com> Message-ID: <4CEE97E9.5020508@mrabarnett.plus.com> On 25/11/2010 16:26, Jean-Michel Pichavant wrote: > MRAB wrote: >> On 25/11/2010 14:40, Jean-Michel Pichavant wrote: >>> Hy guys, >>> >>> I'm struggling matching patterns ending with a comma ',' or an end of >>> line '$'. >>> >>> import re >>> >>> ex1 = 'sumthin,' >>> ex2 = 'sumthin' >>> m1 = re.match('(?P\S+),', ex1) >>> m2 = re.match('(?P\S+)$', ex2) >>> m3 = re.match('(?P\S+)[,$]', ex1) >>> m4 = re.match('(?P\S+)[,$]', ex2) >>> >>> print m1, m2 >>> print m3 >>> print m4 >>> >>> <_sre.SRE_Match object at 0x8834de0> <_sre.SRE_Match object at >>> 0x8834e20> >>> <_sre.SRE_Match object at 0x8834e60> >>> None >>> >>> My problem is that m4 is None while I'd like it to match ex2. >>> >>> Any clue ? >>> >> Within a character set '$' is a literal '$' and not end-of-string, just >> as '\b' is '\x08' and not word-boundary. >> >> Use a lookahead instead: >> >> >>> re.match('(?P\S+)(?=,|$)', ex1) >> <_sre.SRE_Match object at 0x01719FA0> >> >>> re.match('(?P\S+)(?=,|$)', ex2) >> <_sre.SRE_Match object at 0x016937E0> > thanks, it works that way. > By the way I don't get the difference between non capturing parentesis > (?:) and lookahead parenthesis (?=): > > re.match('(?P\S+)(?:,|$)', ex2).groups() > ('sumthin',) > > re.match('(?P\S+)(?=,|$)', ex2).groups() > ('sumthin',) > A non-capturing parenthesis 'consumes' characters; a lookahead parenthesis doesn't, so another part of the regex can match it again. I suppose that in this instance it doesn't matter! From python at mrabarnett.plus.com Thu Nov 25 12:18:24 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 25 Nov 2010 17:18:24 +0000 Subject: the buggy regex in Python In-Reply-To: <120830.69127.qm@web54206.mail.re2.yahoo.com> References: <120830.69127.qm@web54206.mail.re2.yahoo.com> Message-ID: <4CEE9A60.1030807@mrabarnett.plus.com> On 25/11/2010 16:44, Yingjie Lan wrote: > --- On Thu, 11/25/10, MRAB wrote: >> re.findall performs multiple searches, each starting where >> the previous >> one finished. The first match started at the start of the >> string and >> finished at its end. The second match started at that point >> (the end of >> the string) and found another match, ending at the end of >> the string. >> It tried to match a third time, but that failed because it >> would have >> matched an empty string again (it's not allowed to return 2 >> contiguous >> empty strings). >> >>> Isn't this a bug? >>> >> No, but it can be confusing at times! :-) >> -- > > But the last empty string is matched twice -- so it is > an overlapping. But findall is supposed not to return > overlapping matches. So I think this does not live up > to the documentation -- thus I still consider it a bug. > Look at the spans: >>> for m in re.finditer('((.d.)*)*', 'adb'): print(m.span()) (0, 3) (3, 3) There's an non-empty match followed by an empty match. From steve at holdenweb.com Thu Nov 25 13:04:09 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 25 Nov 2010 12:04:09 -0600 Subject: what a cheap rule In-Reply-To: <146414.53554.qm@web54206.mail.re2.yahoo.com> References: <146414.53554.qm@web54206.mail.re2.yahoo.com> Message-ID: On 11/25/2010 10:15 AM, Yingjie Lan wrote: > As I am thinking about it, it seems two > conflicting intuition of code comprehension > are at work here: > > Intuition #1: as if you raise an exception > type, and then match that type. > It seems that no instances > are involved here (Intuitively). > See an example code here: > > try: raise KeyError > except KeyError: pass > > > Intuition #2: you raise an exception > instance, and then match an instance by > its type. See an example code here: > > try: raise KeyError() > except KeyError as ke: pass > > Those two comprehensions are not compatible, > and thus the one that promotes correct > understanding should be encouraged, > while the other should be discouraged, > and maybe even be made iliegal. I prefer to treat those two cases as unified, by observing that if what is raised in an exception class than an instance is created by calling it with no arguments. So matching is always by the instance's type - it's just that the instance creation can be implicit. I agree with you that explicit is better. Most of the syntactic variation you dislike is to allow existing code to continue to work. Some of it is removed in Python 3, when backwards compatibility could be ignored. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From srikrishnamohan at gmail.com Thu Nov 25 13:06:32 2010 From: srikrishnamohan at gmail.com (km) Date: Thu, 25 Nov 2010 23:36:32 +0530 Subject: do something every n seconds In-Reply-To: References: <1a7afe44-b320-4135-9b9d-6b99b6c809b6@p38g2000vbn.googlegroups.com> Message-ID: while True: time.sleep(10) print('hello python!') HTH, KM On Thu, Nov 25, 2010 at 8:35 PM, Steve Holden wrote: > On 11/25/2010 6:38 AM, Santiago Caracol wrote >> Hello, >> >> how can I do something (e.g. check if new files are in the working >> directory) every n seconds in Python? >> > Look at the sched library, which was written to take care of > requirements like this. Use time.sleep() as your delay function and > time.time() as your time function. > > regards > ?Steve > -- > Steve Holden ? ? ? ? ? +1 571 484 6266 ? +1 800 494 3119 > PyCon 2011 Atlanta March 9-17 ? ? ? http://us.pycon.org/ > See Python Video! ? ? ? http://python.mirocommunity.org/ > Holden Web LLC ? ? ? ? ? ? ? ? http://www.holdenweb.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > From steve at holdenweb.com Thu Nov 25 13:10:26 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 25 Nov 2010 12:10:26 -0600 Subject: tilted text in the turtle module In-Reply-To: <933894.81836.qm@web54207.mail.re2.yahoo.com> References: <933894.81836.qm@web54207.mail.re2.yahoo.com> Message-ID: On 11/25/2010 10:49 AM, Yingjie Lan wrote: > --- On Thu, 11/25/10, Steve Holden wrote: >> From: Steve Holden >> Subject: Re: tilted text in the turtle module >> To: python-list at python.org >> Date: Thursday, November 25, 2010, 7:00 PM >> On 11/25/2010 5:06 AM, Yingjie Lan >> wrote: >> This sounds like a good idea. To request a feature you >> should create an >> account (if you do not already have one) on bugs.python.org >> and create a >> new issue (assuming a search reveals that there is not >> already such an >> issue). >> > > Thanks I just did that. > >> You may find if you look at the module's code that you can >> imagine how >> to make the change. If not, the request will wait >> until some maintainer >> sees it and has time. >> > > I don't know much about tkinter, > not sure if I can contribute. > And even if I made a patch, > then how to publish it? > Once you have a patch, attach it to the issue as a file and try and get it reviewed by a developer for incorporation into a future release. Note that no Python 2.8 release is planned, so you would best concentrate your effort on the 3.x series. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From saul.spatz at gmail.com Thu Nov 25 13:32:17 2010 From: saul.spatz at gmail.com (Saul Spatz) Date: Thu, 25 Nov 2010 10:32:17 -0800 (PST) Subject: regexp matching end of line or comma References: Message-ID: <9293d6eb-7ea8-447f-999a-97d0a190a275@k30g2000vbn.googlegroups.com> On Nov 25, 8:40?am, Jean-Michel Pichavant wrote: > Hy guys, > > I'm struggling matching patterns ending with a comma ',' or an end of > line '$'. > > import re > > ex1 = 'sumthin,' > ex2 = 'sumthin' > m1 = re.match('(?P\S+),', ex1) > m2 = re.match('(?P\S+)$', ex2) > m3 = re.match('(?P\S+)[,$]', ex1) > m4 = re.match('(?P\S+)[,$]', ex2) > > print m1, m2 > print m3 > print m4 > > <_sre.SRE_Match object at 0x8834de0> <_sre.SRE_Match object at 0x8834e20> > <_sre.SRE_Match object at 0x8834e60> > None > > My problem is that m4 is None while I'd like it to match ex2. > > Any clue ? > > JM >From the Regular Expression Syntax documentation: Special characters are not active inside sets. For example, [akm$] will match any of the characters 'a', 'k', 'm', or '$'; so in m4, [,$] matches a comma or a literal dollar sign. From cmpython at gmail.com Thu Nov 25 13:35:12 2010 From: cmpython at gmail.com (CM) Date: Thu, 25 Nov 2010 10:35:12 -0800 (PST) Subject: SQLite date fields References: Message-ID: > However, when it comes to writing-back data to the table, SQLite is very > forgiving and is quite happy to store '25/06/2003' in a date field, but > this is not ideal because a) I could be left with a mixture of date > formats in the same column, ?b) SQLite's date functions only work with > ISO format. > Therefore I need to convert the date string back to ISO format before > committing, but then I would need a generic function which checks data > about to be written in all date fields and converts to ISO if > necessary. ?That sounds a bit tedious to me, but maybe it is inevitable. It doesn't strike me as particularly tedious if it is just the line: datetime.datetime.strptime(mydate,'%Y-%m-%d').strftime('%d/%m/%Y') > Are there simpler solutions? ?Would it be easier to change the date > field to a 10-character field and store 'dd/mm/yyyy' throughout the > table? ?This way no conversion is required when reading or writing from > the table, and I could use datetime() functions if I needed to perform > any date-arithmetic. Maybe I've misunderstood, but wouldn't you have to do the conversion to display the date anyway? It seems to me like, whichever approach you take, you will have to do a conversion. For that reason, isn't it better to leave the date fields in ISO so that you can take advantage of SQLite's date functions? Che > > How have other developers overcome this problem? ?Any help would be > appreciated. ?For the record, I am using SQLite3 with Python 3.1. > > Alan From namekuseijin at gmail.com Thu Nov 25 13:39:24 2010 From: namekuseijin at gmail.com (namekuseijin) Date: Thu, 25 Nov 2010 10:39:24 -0800 (PST) Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> <08823dd4-588a-4729-a660-711e266c96b0@y23g2000yqd.googlegroups.com> <396f8de7-ece5-4e9c-919b-886eb65ae14a@a30g2000vbt.googlegroups.com> <967678a1-fc5d-4b61-86c5-79a298999582@p1g2000vbo.googlegroups.com> <18cd9337-736b-427c-9cac-14c99056750a@p1g2000yqm.googlegroups.com> <87vd3l8iy3.fsf@padme.localdomain> Message-ID: On 25 nov, 14:30, m_mom... at yahoo.com (Mario S. Mommer) wrote: > Raffael Cavallaro > writes: > > > On 2010-11-24 16:19:49 -0500, toby said: > > >> And furthermore, he has cooties. > > > Once again, not all ad hominem arguments are ad hominem > > fallacies. Financial conflict of interest is a prime example of a > > perfectly valid ad hominem argument. > > It has limited validity. People are way more complicated than the > simplistic "follow your own selfish egoistic interests to the letter > without taking prisoners" model of human behavior that seems > (unfortunately) so prevalent nowadays. > > > People who parse patterns but not semantics are apt to fall into the > > error of believing that "ad hominem" automatically means "logically > > invalid." This is not the case. > > In the realm of pure logic, ad hominems are logically invalid, > period. However, if the question cannot be resolved by its own merits, > simple logic has little to say, and you may include additional > information in a sort-of Bayesian fashion. > > Saying that a conflict of interest means that nothing this person says > makes any sense at all is in a way an admission that the subject of > discussion is not very amenable to rational argument. I have to say I'm always amazed how ad hominens can generate quite strong responses to the point of making a lot of new faces (or mail accounts) suddenly appear... ;) From moura.mario at gmail.com Thu Nov 25 13:53:40 2010 From: moura.mario at gmail.com (macm) Date: Thu, 25 Nov 2010 10:53:40 -0800 (PST) Subject: Automatic Distutils generator Message-ID: Hi Folks I am trying run Distutils setup inside a script. The Docs dont tell me much and I cant find any examples. This script will generate shared libraries recursive to all files in a dir. ----------------------------- import os import sys from distutils.core import setup as d from distutils.extension import Extension from Cython.Distutils import build_ext fileList = [] rootdir = sys.argv[1] fileType = '.pyx' for root, subFolders, files in os.walk(rootdir): for file in files: if file[-4:] == fileType: fileList.append(os.path.join(root,file)) # But Here I want automatic Distutils generator # I want replace manual entry like this: # python setup.py build_ext --inplace d.setup(name = str(file) + '_Cython', ext_modules=[ Extension(file[:-4], [file]) ], cmdclass = {'build_ext': build_ext}) d.run_setup() print 'Files convert: \n' print fileList ---------------------------- Who can help me fix it? Best Regards Mario From phlip2005 at gmail.com Thu Nov 25 14:57:33 2010 From: phlip2005 at gmail.com (Phlip) Date: Thu, 25 Nov 2010 11:57:33 -0800 (PST) Subject: a regexp riddle: re.search(r'(?:(\w+), |and (\w+))+', 'whatever a, bbb, and c') =? ('a', 'bbb', 'c') References: <00a69232-7703-48ce-8a42-b28f24946680@i32g2000pri.googlegroups.com> Message-ID: > Accepting input from a human is fraught with dangers and edge cases. > Here's a non-regex solution Thanks all for playing! And as usual I forgot a critical detail: I'm writing a matcher for a Morelia /viridis/ Scenario step, so the matcher must be a single regexp. http://c2.com/cgi/wiki?MoreliaViridis I'm avoiding the current situation, where Morelia pulls out (.*), and the step handler "manually" splits that up with: flags = re.split(r', (?:and )?', flags) That means I already had a brute-force version. A regexp version is always better because, especially in Morelia, it validates input. (.*) is less specific than (\w+). So if the step says: Alice has crypto keys apple, barley, and flax Then the step handler could say (if this worked): def step_user_has_crypto_keys_(self, user, *keys): r'(\w+) has crypto keys (?:(\w+), )+and (\w+)' # assert that user with those keys here That does not work because "a capturing group only remembers the last match". This would appear to be an irritating 'feature' in Regexp. The total match is 'apple, barley, and flax', but the stored groups behave as if each () were a slot, so (\w+)+ would not store "more than one group". Unless there's a Regexp workaround to mean "arbitrary number of slots for each ()", then I /might/ go with this: got = re.findall(r'(?:(\w+), )?(?:(\w+), )?(?:(\w+), )?(?:(\w+), )? (?:(\w+), and )?(\w+)$', 'whatever a, bbb, and c') print got # [('a', '', '', '', 'bbb', 'c')] The trick is to simply paste in a high number of (?:(\w+), )? segments, assuming that nobody should plug in too many. Behavior Driven Development scenarios should be readable and not run-on. (Morelia has a table feature for when you actually need lots of arguments.) Next question: Does re.search() return a match object that I can get ('a', '', '', '', 'bbb', 'c') out of? The calls to groups() and such always return this crazy ('a', 2, 'bbb', 'c') thing that would disturb my user-programmers. -- Phlip From joralemonshelly at gmail.com Thu Nov 25 15:18:33 2010 From: joralemonshelly at gmail.com (Shel) Date: Thu, 25 Nov 2010 12:18:33 -0800 (PST) Subject: building a web interface References: <2010112500364975026-alice@gothcandycom> Message-ID: <487ba202-034e-4ebf-aed7-e248413bd90f@c17g2000prm.googlegroups.com> Will take a look after stuffing myself with turkey today (am in the US, where we give thanks by eating everything in sight). Thanks, Alice. Wait, did I just say "thanks"? Must go eat pie. On Nov 25, 12:36?am, Alice Bevan?McGregor wrote: > Howdy! > > I'm mildly biased, being the author of the framework, but I can highly > recommend WebCore for rapid prototyping of web applications; it has > templating via numerous template engines, excellent JSON (AJAJ) > support, and support for database back-ends via SQLAlchemy. ?It also > has session support baked-in via a project called Beaker. ? > Documentation is fairly complete, and I can be found camping in the > #webcore IRC channel on irc.freenode.net at strange hours. > > If you can write a class, you can have a fully operational web > application in a single file of ~8 lines or so. ?(Or you can create a > complete easy-installable Python package with multiple modules.) > > For information, see:http://www.web-core.org/ > > As an interactive-fiction example: > > class RootController(web.core.Controller): > ? ? def index(self): > ? ? ? ? """This returns a template that uses JavaScript to call execute(). > ? ? ? ? The JavaScript adds the result of execute() to the display.""" > ? ? ? ? session = db.Session().save() > ? ? ? ? return './templates/main.html', dict(session=session.id) > > ? ? def execute(self, session, statement): > ? ? ? ? """Load our session and pass the input off to our interactive > ? ? ? ? fiction library of choice. ?Return the result if all went well.""" > ? ? ? ? session = db.Session.get(session) > > ? ? ? ? try: > ? ? ? ? ? ? result = myiflib.execute(session, statement) > > ? ? ? ? except myiflib.ParseError: > ? ? ? ? ? ? return 'json:', dict(status="failure", message="Error...") > > ? ? ? ? return 'json:', dict(status="success", message=result) > > ?? Alice. From python at mrabarnett.plus.com Thu Nov 25 15:45:02 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 25 Nov 2010 20:45:02 +0000 Subject: a regexp riddle: re.search(r'(?:(\w+), |and (\w+))+', 'whatever a, bbb, and c') =? ('a', 'bbb', 'c') In-Reply-To: References: <00a69232-7703-48ce-8a42-b28f24946680@i32g2000pri.googlegroups.com> Message-ID: <4CEECACE.3000903@mrabarnett.plus.com> On 25/11/2010 19:57, Phlip wrote: >> Accepting input from a human is fraught with dangers and edge cases. > >> Here's a non-regex solution > > Thanks all for playing! And as usual I forgot a critical detail: > > I'm writing a matcher for a Morelia /viridis/ Scenario step, so the > matcher must be a single regexp. > > http://c2.com/cgi/wiki?MoreliaViridis > > I'm avoiding the current situation, where Morelia pulls out (.*), and > the step handler "manually" splits that up with: > > flags = re.split(r', (?:and )?', flags) > > That means I already had a brute-force version. A regexp version is > always better because, especially in Morelia, it validates input. (.*) > is less specific than (\w+). > > So if the step says: > > Alice has crypto keys apple, barley, and flax > > Then the step handler could say (if this worked): > > def step_user_has_crypto_keys_(self, user, *keys): > r'(\w+) has crypto keys (?:(\w+), )+and (\w+)' > > # assert that user with those keys here > [snip] You could do: def step_user_has_crypto_keys_(self, user, keys): r'(\w+) has crypto keys ((?:\w+, )+and \w+)' to validate and capture, and then split the keys string. From smallpox911 at gmail.com Thu Nov 25 15:56:47 2010 From: smallpox911 at gmail.com (small Pox) Date: Thu, 25 Nov 2010 12:56:47 -0800 (PST) Subject: a story of a top expert of Mathematica: Robby Villegas References: <67344004-75e9-478b-af99-e8188f799848@z9g2000pri.googlegroups.com> Message-ID: On Nov 25, 2:10?am, Xah Lee wrote: > On Nov 24, 2:02?pm, Xah Lee wrote: > > > just learned that one of my best friend, one of world's top expert of > > the Mathematica language, died, last month. > > > ? ?Robby Villegas Died (1968-2010)?http://xahlee.org/math/Robby_Villegas.html > > so, apparantly, he killed himself. > > not lisp related, but i thought it is interetsing to many here, > becuase Robby is very interested in computer languages, and share with > many of us being ubberly socially inept and frustrated. (he's not a > emacs users. Occationally uses vi. I think he's main editor is NEdit > (if he hasn't changed since 1990s). Yes he's a linux user. Became a > Redhat linux user as his main machine in late 1990s. You could find > many of his writings in comp.soft-sys.math.mathematica, but i believ > they all dates in the mid 1990s. He's a extremely keep-to-himself > guy.) He's also the first computer programer that i got to know in > real meat space, who hates Windows and Microsoft. > > ----------------------------------------------- > Robby's Goodbye Notes > > Apparantly, Robby killed himself. There's this memorial page posted by > Robby's friends on his site at: Source. Reading it, i came across > several Wolfram employees i remember having met, some i recognize as > Robby's good friends. In it, there's this post, apparantly Robby's > goodbye note. > > ? ? Robby via Christina Szabo Says: > ? ? October 7th, 2010 at 9:54 pm > > ? ? Robby wanted to ?give some explanation to people in general? and > asked > ? ? me to post this, which he wrote. -Christina > > ? ? Subject: the end is important in all things > > ? ? Robby Villegas October 2 at 7:17am > > ? ? Depression, and even more so, physical exhaustion, continues to > claim more and more of my life, to render a larger percentage of each > day either unusable, or a sloggin, dragging fight to keep myself > upright just to get through the basics of my day. On top of fatigue, a > few years ago I began to develop a tendency toward anxiety, which > gradually became more frequent and of faster onset, throwing a specter > of borderline panic attacks over many of my activities. Eventually, I > was taking partial doses of my prescription sleep medication > *preemptively* before simple activities like skating class, meeting > friends at a bar, going to a theater, or spending an evening studying > at a cafe. > > ? ? The sleep and exhaustion problems that forced me to suddenly quit > working in January 2007 have gradually worsened, and I have run out of > means at this point. > > ? ? More important than financial means, though: the ratio of quality > of life to pained struggling has passed a threshold. Eventually, I?ll > forget what it even felt like to be happy, the memories of what I was > will fade further, I won?t be able to appreciate any of the good parts > of life, and I?ll be bitter, not even a shadow of my self. > > ? ? This must not happen. For many years, I have felt that some day > I?d have to make that call that it?s time to go; that most of the good > stuff was past, and the proportion of hope and new joy to the pain and > effort that goes into rallying would fall too low I want to go out > while I can still reflect on the good things, and go out really > feeling and believing ?I lived.? > > ? ? Worse than the death of the body is the death of pieces of the > self while still alive, and the memories that provide conviction that > there was a lot worth being here for, while it lasted. > > ? ? In retrospect, I probably should have made this call last winter, > or at the very latest, early summer, given that the last few months > have had a marked dulling effect on me. But, two decades of fighting > depression, rallying through many dozens of life-hating and self- > hating episodes ranging from bad patches to truly close calls, and > being thankful I did each time I got a ?new lease on life? that was > followed by more of the worthwhile stuff of life ? two decades of that > makes it *intensely* difficult to make that final call. > > ? ? Albeit more weary and dull than I?ve ever been, I am thankful that > there?s enough left of me to look back (even with difficulty) and > appreciate all the good people, activities, and interests that made My > Life worth living during that time. So it is perhaps not too late to > exit while there?s a reasonable amount left of Me. > > ? ? Yours in truth, > ? ? Robby ?R. Scott? > > Not sure what to say. > > Robby has told me in around 2004 to 2005, our last big exchange, that > he has serious insomnia problems. But i don't recall any serious > depression. Actually, i remember now he has told me that he had > depression episodes, which i did too, and we chatted our experiences. > But i recall it's all past tense, and this chat was in 1995. > (depression is hard to define) But i didn't know it was getting to the > point of killing himself, but again, for certain type of persons who > are not emotionally responsive (i.e. cold, lone, type, who hide their > emotions or unable to express it), it could happen on any seemingly > good day. Robby is extremely sensitive to stress and pressure. He's > the type of nice guy who find it hard to say no, and when he actually > had to, it's after huge mental struggle. > > So i guess, for a personality as lone as me and Robby, i can't say i > feel particular regret or inappropriateness on Robby's act of killing > himself. He didn't feel worthwhile to live on, so he had to go. I > certainly wished things could be different, and wished that we'd have > communicated about his situation. I believe, if i told him of my > personal situation, he'd feel better. We certainly would have great > conversations about the pros and cons on methods of suicide, in fact i > believe we had such a conversation before. I missed a friend, who is > one of the greatest unsung expert of Mathematica, of which, i could > certainly use some help, and as a alley in the war on computer > languages. > > In the future, i'll dig up some of Robby's emails and post here. > > The world has 6.5 billions of people. Due to the incredible advances > of communication tech, especially the internet, we the masses get to > see all sort of weirdos and behaviors directly. (e.g. shown in shock > sites, 4chan, etc.) And, in the past 5 years, we greatly see many > suicides (on facebook et al), and in many cases, literally watched > thru online video someone killing himself. > > Am not sure where am going with this, but i guess let's open even more > communication. Legalize suicide. Stop censorship of all sorts except > things like how to make nuclear bomb. We don't like pain, and we don't > want to see our friends to choose to end their life. But we don't want > whatever problems that leads to that path. Hiding and banning is not > going to help. More open info, more communication, we can have more > understanding of us the human animals, and more happiness with us and > our friends. Maybe Robby had biologically rooted psychogical problems. > But am sure, whatever his suffering of depression, can be helped > better if whatever caused his stress, socially induced self-loathing, > closet inhibitions (such as gay people), parental or family problems, > can be reduced. Tolerate, and appreciate, your friends, co-workers, or > strangers, while they are alive. > > It's kinda sad that many of my math friends, died in recent years. > Perhaps it just means am getting old. > > ?Xah I find it COMPASSIONATE that WOLF RAM Research Incorporated after milking such a smart person did not give him safety cushion in his time of difficulty. This is in line with the corporate operational policy of bernard madoffs, roman polanskys, wolf rams, larry ellis islanders, and neocons. Even stalin cried and led the funerals of his comrades whom he had used his jewish doctors to kill. I urge everyone to read the great ebook, the sale and manufacture of saint einstein. postings like mine are needed to get the google censhorship crew to wake up and remove the porn postings barraged by CIA criminals. It is well known that they are targetting minorities with drugs and various marijuana and porn. Mathematica is LISP IN DISGUISE. Wolf Ram stole the idea from lisp. Its R-LISP. The guy who came up with R-LISP was also doing some physics calculations at Stanford. Wolf Ram was doing at Caltech. The fundamental object of Lisp is the cons cell or pair or list and with nesting. The fundamental object of Mathematica is table - really a cheap attempt to pretend NOVELTY. A table is atleast a pair. A symbol-value table of one row is a pair. THE GREATEST TRIBUTE THAT CAN BE GIVEN TO THIS PERSON IS TO MAKE SURE THAT HIS IDEAS DO NOT BECOME LOST AND BECOME THE MONOPOLY OF A SNAKEs OF A CORPORATIONs BUT BENEFIT THE HUMANITY AT LARGE. THE GREATEST TRIBUTE THAT CAN BE GIVEN TO THIS PERSON IS TO MAKE SURE THAT HIS IDEAS DO NOT BECOME LOST AND BECOME THE MONOPOLY OF A SNAKEs OF A CORPORATIONs BUT BENEFIT THE HUMANITY AT LARGE. THE GREATEST TRIBUTE THAT CAN BE GIVEN TO THIS PERSON IS TO MAKE SURE THAT HIS IDEAS DO NOT BECOME LOST AND BECOME THE MONOPOLY OF A SNAKEs OF A CORPORATIONs BUT BENEFIT THE HUMANITY AT LARGE. THE GREATEST TRIBUTE THAT CAN BE GIVEN TO THIS PERSON IS TO MAKE SURE THAT HIS IDEAS DO NOT BECOME LOST AND BECOME THE MONOPOLY OF A SNAKEs OF A CORPORATIONs BUT BENEFIT THE HUMANITY AT LARGE. publish them in the clearest manner in an accumulation for free. if they are clear then they wont take many pages, lot of effort. If they are published openly, they will get refined automatically and get added. Maybe a wikipedia article saying the fundamental ideas or an anonymous pdf posted on forums. or a wikileak doc. THE MANUFACTURE AND SALE OF SAINT EINSTEIN By Christopher Jon Bjerknes 2,825 page treatise on Einstein's plagiarism, Einstein's Zionism, history of Zionism, racism, Judaism, and more. The complete book The Manufacture and Sale of Saint Einstein in one 17 Mb. PDF file can be downloaded by clicking on this link: http://www.jewishracism.com/SaintEinstein.pdf From mdw at distorted.org.uk Thu Nov 25 15:56:54 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 25 Nov 2010 20:56:54 +0000 Subject: inverse of a matrix with Fraction entries References: <8l50ulFhb4U1@mid.individual.net> <87y68izdnh.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <878w0hyve1.fsf.mdw@metalzone.distorted.org.uk> Daniel Fetchinson writes: > > I wouldn't do it that way. Let M be your matrix. Work out the LCM l of > > the denominators, and multiply the matrix by that to make it an integer > > matrix N = l M. Then work out the determinant d of that integer matrix. > > Next, the big step: use Gaussian elimination to find a matrix A (the > > `adjugate matrix') such that A N = d I. This should be doable entirely > > using integer arithmetic, and I think without needing any divisions. > > Finally, we have l A M = d I, so (l/d A) M = I and l/d A is the inverse > > you seek. > > > > Does that make sense? > > Absolutely! But there is nothing wrong with working out the inverse > directly using fractions.Fraction arithmetic, I'd think. It'll work, certainly; but the Fraction implementation will have to do a buttload of GCD computations that it wouldn't need to do if you worked with plain integers. And GCDs are relatively hard, as arithmetical computations go: the usual algorithms require either a number of divisions (which are themselves rather costly) or a bitwise traversal of one of the operands. A million entries seems nontrivial for a matrix, and Gaussian elimination has cubic running time if I remember rightly; I suspect that the transformations I describe would reduce the running time by a fair amount. Of course, I might be drastically underestimating the performance of modern hardware -- I often do -- so this may not be especially relevant. Anyway, the possibility's there. -- [mdw] From fetchinson at googlemail.com Thu Nov 25 16:28:29 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Thu, 25 Nov 2010 22:28:29 +0100 Subject: inverse of a matrix with Fraction entries In-Reply-To: <878w0hyve1.fsf.mdw@metalzone.distorted.org.uk> References: <8l50ulFhb4U1@mid.individual.net> <87y68izdnh.fsf.mdw@metalzone.distorted.org.uk> <878w0hyve1.fsf.mdw@metalzone.distorted.org.uk> Message-ID: >> > I wouldn't do it that way. Let M be your matrix. Work out the LCM l of >> > the denominators, and multiply the matrix by that to make it an integer >> > matrix N = l M. Then work out the determinant d of that integer matrix. >> > Next, the big step: use Gaussian elimination to find a matrix A (the >> > `adjugate matrix') such that A N = d I. This should be doable entirely >> > using integer arithmetic, and I think without needing any divisions. >> > Finally, we have l A M = d I, so (l/d A) M = I and l/d A is the inverse >> > you seek. >> > >> > Does that make sense? >> >> Absolutely! But there is nothing wrong with working out the inverse >> directly using fractions.Fraction arithmetic, I'd think. > > It'll work, certainly; but the Fraction implementation will have to do a > buttload of GCD computations that it wouldn't need to do if you worked > with plain integers. And GCDs are relatively hard, as arithmetical > computations go: the usual algorithms require either a number of > divisions (which are themselves rather costly) or a bitwise traversal of > one of the operands. > > A million entries seems nontrivial for a matrix, and Gaussian > elimination has cubic running time if I remember rightly; I suspect that > the transformations I describe would reduce the running time by a fair > amount. Of course, I might be drastically underestimating the > performance of modern hardware -- I often do -- so this may not be > especially relevant. Anyway, the possibility's there. Okay, I see your point and I completely agree. Surely it will be faster to do it with integers, will give it a shot. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From raymond.activestate at gmail.com Thu Nov 25 17:40:41 2010 From: raymond.activestate at gmail.com (Raymond Hettinger) Date: Thu, 25 Nov 2010 14:40:41 -0800 (PST) Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> <201011242116145773-alice@gothcandycom> Message-ID: <52560c8d-bad6-422f-9c61-2c51e88006a2@z17g2000prz.googlegroups.com> On Nov 24, 9:16?pm, Alice Bevan?McGregor wrote: > On 2010-11-24 12:08:04 -0800, Raymond Hettinger said: > > > I'm writing-up more guidance on how to use super() and would like to > > point at some real-world Python examples of cooperative multiple > > inheritance. > > The SocketServer module > (http://docs.python.org/library/socketserver.html) uses cooperative > multiple inheritance to implement threading / async using a > ThreadingMixIn class and multi-processing using a ForkingMixIn class, > which may not be as complicated a use case as you are looking for. It is a great example of a style of using mixins, but isn't actually an example of Python's cooperative multiple inheritance. The code doesn't use super() and doesn't have a diamond problem. It's hard to write a best practices document for super() when the doesn't appear to be any practice at all :-) Raymond From hugol at fastmail.net Thu Nov 25 17:56:59 2010 From: hugol at fastmail.net (=?ISO-8859-1?Q?Hugo=20L=E9veill=E9?=) Date: Thu, 25 Nov 2010 17:56:59 -0500 Subject: Newbie subprocess question Message-ID: <1290725819.21008.1407210497@webmail.messagingengine.com> I'm starting various application using subprocess.Popen without any problem. The problem is with application inside "Program Files". It looks like subprocess is stopping the application string after "Program". I tried puting the programe name inside double quote like '"Program File*..."'. No luck. How can I start a app inside this folder ? Thanks -- Hugo L?veill? TD Compositing, Vision Globale hugol at fastmail.net From steve at holdenweb.com Thu Nov 25 18:08:02 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 25 Nov 2010 17:08:02 -0600 Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance In-Reply-To: <52560c8d-bad6-422f-9c61-2c51e88006a2@z17g2000prz.googlegroups.com> References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> <201011242116145773-alice@gothcandycom> <52560c8d-bad6-422f-9c61-2c51e88006a2@z17g2000prz.googlegroups.com> Message-ID: On 11/25/2010 4:40 PM, Raymond Hettinger wrote: > It's hard to write a best practices document for super() when > the doesn't appear to be any practice at all :-) > Sounds like the Python community have voted with their feet. I seem to remember that Alex Martelli's "Python in a Nutshell" contains a very thorough description of the new-style class system with an example showing the resolution of the diamond pattern. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From aahz at pythoncraft.com Thu Nov 25 18:13:16 2010 From: aahz at pythoncraft.com (Aahz) Date: 25 Nov 2010 15:13:16 -0800 Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> Message-ID: In article <89b6d53f-dcdc-4442-957f-1f4d29115a26 at n32g2000pre.googlegroups.com>, Raymond Hettinger wrote: > >I'm writing-up more guidance on how to use super() and would like to >point at some real-world Python examples of cooperative multiple >inheritance. My previous job used this rather heavily, but I can't provide you with code. I suspect we weren't the only people, but I have no clue how to locate samples. Were you searching code.google.com or something else? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Look, it's your affair if you want to play with five people, but don't go calling it doubles." --John Cleese anticipates Usenet From usernet at ilthio.net Thu Nov 25 18:18:38 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 25 Nov 2010 23:18:38 +0000 (UTC) Subject: Newbie subprocess question References: Message-ID: On 2010-11-25, Hugo L?veill? wrote: > I'm starting various application using subprocess.Popen without any > problem. The problem is with application inside "Program Files". It > looks like subprocess is stopping the application string after > "Program". I tried puting the programe name inside double quote like > '"Program File*..."'. No luck. Not sure you you are having issues. subprocess.Popen("C:\\Program Files\\Vim\\vim73\\gvim.exe") From coolaj86 at gmail.com Thu Nov 25 18:21:54 2010 From: coolaj86 at gmail.com (AJ ONeal) Date: Thu, 25 Nov 2010 16:21:54 -0700 Subject: MediaTags - exporting m4a, id3, exiv, etc as JSON (YAML) Message-ID: I'm sponsoring the development of cross-platform (C/C++) utilities for extracting a variety of media meta-data as JSON, including stream checksums and stream meta-data. git://github.com/coolaj86/mtags.git I'd like to get support for developing this, and I'm interested in the opinions of others who would use these tools. http://pledgie.com/campaigns/14039 The m4atags utility is now complete. Here's an example of the usage / output: http://coolaj86.info/articles/example-of-verbose-output-from-mediatags.html AJ ONeal -------------- next part -------------- An HTML attachment was scrubbed... URL: From stackslip at gmail.com Thu Nov 25 18:32:57 2010 From: stackslip at gmail.com (Slie) Date: Thu, 25 Nov 2010 14:32:57 -0900 Subject: =?utf-8?B?UmU6IEFycmF5cw==?= Message-ID: <4ceef22b.1a1c640a.442c.2e69@mx.google.com> I have an exercise im working on. I have an array of strings, and I would like to take each peace of the array and assign it to a new array so I can iterate over each of those pieces and replace the sting I want then put it back together. I hope that is not too confusing. This is how im trying to solve the problem. I have a program that takes in integers and it prints out the integers in bigger ones made up of asterisks. Im supposed to alter the program so so that instead of asterisks it prints them in bigger ones made up of the number itself. I am given arrays built to look like the numbers, already. ----- Reply message ----- From: "Stefan Behnel" Date: Wed, Nov 24, 2010 2:18 am Subject: Arrays To: Garland Fulton, 24.11.2010 06:55: > Is there a way I can define an Array of and unknown size so I can add and > remove to or from it? > > Are arrays immutable? Python has lists and tuples as basic data structures. Tuples are completely immutable, lists are completely mutable. If you want a container that has a fixed size but allows changing items, use a list and avoid calling .append() and .remove() to change items in favour of direct item assignments. If you want a completely mutable container, use a list and use it as you see fit. If you want a stack, a list will do. If you want a queue, a deque is a better option. In any case, if you tell us more about what you actually want to do, we can give better suggestions. Stefan -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From no.email at nospam.invalid Thu Nov 25 18:34:33 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 25 Nov 2010 15:34:33 -0800 Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> Message-ID: <7xsjyp2d12.fsf@ruckus.brouhaha.com> Raymond Hettinger writes: > I'm writing-up more guidance on how to use super() and would like to > point at some real-world Python examples of cooperative multiple > inheritance. I'd mention the SocketServer library, except I'm not sure what you mean by "cooperative", so I don't know if that counts. The few times I've tried to use multiple inheritance, I think it wasn't the right idea for what I was doing. It turns into a big mess quite easily. The classic example though is a window system, where you have a "window" class, and a "scroll bar" class, and a "drop-down menu" class, etc. and if you want a window with a scroll bar and a drop-down menu, you inherit from all three of those classes. They each have to support (e.g.) a "redraw" operation, so automatic method combination figures out what to call. I''ve mostly seen this stuff in connection with Lisp. If you look at a CLOS manual you can probably find examples. There are also some examples in the old CADR manual, using the MIT Flavors system which predated CLOS. That manual is online now: http://common-lisp.net/project/bknr/static/lmman/frontpage.html The object system is documented in this chapter: http://common-lisp.net/project/bknr/static/lmman/flavor.xml The paragraph about "defwrapper" gives a clear view into the machinery. From coolaj86 at gmail.com Thu Nov 25 18:34:49 2010 From: coolaj86 at gmail.com (AJ ONeal) Date: Thu, 25 Nov 2010 16:34:49 -0700 Subject: MediaTags - exporting m4a, id3, exiv, etc as JSON Message-ID: I'm sponsoring the development of cross-platform (C/C++) utilities for extracting a variety of media meta-data as JSON, including stream checksums and stream meta-data. git://github.com/coolaj86/mtags.git I'd like to get support for developing this, and I'm interested in the opinions of others who would use these tools. http://pledgie.com/campaigns/14039 The m4atags utility is now complete. Here's an example of the usage / output: http://coolaj86.info/articles/example-of-verbose-output-from-mediatags.html AJ ONeal -------------- next part -------------- An HTML attachment was scrubbed... URL: From nagle at animats.com Thu Nov 25 18:38:36 2010 From: nagle at animats.com (John Nagle) Date: Thu, 25 Nov 2010 15:38:36 -0800 Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance In-Reply-To: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> Message-ID: <4ceef381$0$1659$742ec2ed@news.sonic.net> On 11/24/2010 12:08 PM, Raymond Hettinger wrote: > I'm writing-up more guidance on how to use super() and would like to > point at some real-world Python examples of cooperative multiple > inheritance. > > Google searches take me to old papers for C++ and Eiffel, but that > don't seem to be relevant to most Python programmers (i.e. a > WalkingMenu example where a submenu is both a Entry in a Menu and a > Menu itself). Another published example is in a graphic library where > some widgets inherit GraphicalFeature methods such as location, size > and NestingGroupingFeatures such as finding parents, siblings, and > children. I don't find either of those examples compelling because > there is no particular reason that they would have to have overlapping > method names. > > So far, the only situation I can find where method names necessarily > overlap is for the basics like __init__(), close(), flush(), and > save() where multiple parents need to have their own initialization > and finalization. > > If you guys know of good examples, I would appreciate a link or a > recap. Multiple inheritance in Python is basically what fell out of CPython's internals, not a design. It's one of those areas where order of execution matters, and that wasn't well worked out. Allowing classes to form a directed acyclic graph isn't very useful. It just fell out of the semantics of a naive interpreter. Read "C3 method resolution order": http://www.python.org/download/releases/2.3/mro/ which is what you have to understand to use the awful cases properly. Originally, the semantics were just wrong. Now the awful cases have well-defined semantics, but aren't very useful. Part of the problem is the notion that if a base class is duplicated in the hierarchy, there's only one copy. So if you inherit from two classes, both of which inherit from "dict", there will be only one "dict" at the bottom. (I think.) This probably won't do what the authors of any of the classes involved expected. The author of the class which does the multiple inheritance might not even be aware that there's a clash further up in the hierarchy. This is one of those areas where all the code looks right locally, but it's wrong globally. Best practice for this is "don't do it." Some name clashes ought to simply be detected as errors, rather than being given such complex semantics. John Nagle From tjreedy at udel.edu Thu Nov 25 18:39:57 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 25 Nov 2010 18:39:57 -0500 Subject: what a cheap rule In-Reply-To: <478343.25019.qm@web54204.mail.re2.yahoo.com> References: <478343.25019.qm@web54204.mail.re2.yahoo.com> Message-ID: On 11/25/2010 4:12 AM, Yingjie Lan wrote: > Sometimes the golden rule in Python of > "explicit is better than implicit" is > so cheap that it can be thrown away > for the trouble of typing an empty tuple. > > Today when I am explaining that in Python 3, > there are two ways to raise exceptions: > > raise Exception > raise Exception() I agree with you that this is annoying. I think it is a holdover from the past. In Python 1/2, raise 'some string' also works, but that was disallowed in Py 3. A lot of things were cleaned up in Py 3, but not everything. -- Terry Jan Reedy From lanyjie at yahoo.com Thu Nov 25 18:58:41 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Thu, 25 Nov 2010 15:58:41 -0800 (PST) Subject: tilted text in the turtle module In-Reply-To: Message-ID: <892332.24723.qm@web54207.mail.re2.yahoo.com> --- On Thu, 11/25/10, Steve Holden wrote: > > And even if I made a patch, > > then how to publish it? > > > Once you have a patch, attach it to the issue as a file and > try and get > it reviewed by a developer for incorporation into a future > release. > > Note that no Python 2.8 release is planned, so you would > best > concentrate your effort on the 3.x series. > I see. I suppose one could post a message somewhere to get the attention? Thanks for the pointer. Regards, Yingjie From lanyjie at yahoo.com Thu Nov 25 19:05:46 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Thu, 25 Nov 2010 16:05:46 -0800 (PST) Subject: the buggy regex in Python In-Reply-To: <4CEE9A60.1030807@mrabarnett.plus.com> Message-ID: <100685.62538.qm@web54203.mail.re2.yahoo.com> --- On Thu, 11/25/10, MRAB wrote: > > > Look at the spans: > > >>> for m in re.finditer('((.d.)*)*', 'adb'): > ??? print(m.span()) > > ??? > (0, 3) > (3, 3) > > There's an non-empty match followed by an empty match. If you read my first post, it should be apparent that that the empty string in the end of the string is used twice -- thus an overlap. Yingjie From steve at holdenweb.com Thu Nov 25 19:16:51 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 25 Nov 2010 18:16:51 -0600 Subject: tilted text in the turtle module In-Reply-To: <892332.24723.qm@web54207.mail.re2.yahoo.com> References: <892332.24723.qm@web54207.mail.re2.yahoo.com> Message-ID: On 11/25/2010 5:58 PM, Yingjie Lan wrote: > --- On Thu, 11/25/10, Steve Holden wrote: >>> And even if I made a patch, >>> then how to publish it? >>> >> Once you have a patch, attach it to the issue as a file and >> try and get >> it reviewed by a developer for incorporation into a future >> release. >> >> Note that no Python 2.8 release is planned, so you would >> best >> concentrate your effort on the 3.x series. >> > > I see. I suppose one could post a message somewhere > to get the attention? > > Thanks for the pointer. > One would normally make a post on the python-dev list to get the attention of developers. If you want to *guarantee* that your issue gets attention then you can review five existing issues and advance them a little to help the development team. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From python at mrabarnett.plus.com Thu Nov 25 19:27:59 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 26 Nov 2010 00:27:59 +0000 Subject: Newbie subprocess question In-Reply-To: <1290725819.21008.1407210497@webmail.messagingengine.com> References: <1290725819.21008.1407210497@webmail.messagingengine.com> Message-ID: <4CEEFF0F.6020005@mrabarnett.plus.com> On 25/11/2010 22:56, Hugo L?veill? wrote: > I'm starting various application using subprocess.Popen without any > problem. The problem is with application inside "Program Files". It > looks like subprocess is stopping the application string after > "Program". I tried puting the programe name inside double quote like > '"Program File*..."'. No luck. > > How can I start a app inside this folder ? > Try passing the application path and its arguments (if any) as a list like this: subprocess.Popen([app_path, arg1, arg2]) From lanyjie at yahoo.com Thu Nov 25 19:50:54 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Thu, 25 Nov 2010 16:50:54 -0800 (PST) Subject: tilted text in the turtle module In-Reply-To: Message-ID: <924269.82196.qm@web54208.mail.re2.yahoo.com> --- On Fri, 11/26/10, Steve Holden wrote: > From: Steve Holden > Subject: Re: tilted text in the turtle module > To: python-list at python.org > Date: Friday, November 26, 2010, 4:16 AM > On 11/25/2010 5:58 PM, Yingjie Lan > wrote: > > --- On Thu, 11/25/10, Steve Holden > wrote: > >>> And even if I made a patch, > >>> then how to publish it? > >>> > >> Once you have a patch, attach it to the issue as a > file and > >> try and get > >> it reviewed by a developer for incorporation into > a future > >> release. > >> > >> Note that no Python 2.8 release is planned, so you > would > >> best > >> concentrate your effort on the 3.x series. > >> > > > > I see. I suppose one could post a message somewhere > > to get the attention? > > > > Thanks for the pointer. > > > One would normally make a post on the python-dev list to > get the > attention of developers. If you want to *guarantee* that > your issue gets > attention then you can review five existing issues and > advance them a > little to help the development team. > Sound advices. Many thanks! Yingjie From mdw at distorted.org.uk Thu Nov 25 20:00:44 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Fri, 26 Nov 2010 01:00:44 +0000 Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> <4ceef381$0$1659$742ec2ed@news.sonic.net> Message-ID: <87k4k0yk3n.fsf.mdw@metalzone.distorted.org.uk> John Nagle writes: > Multiple inheritance in Python is basically what fell out of > CPython's internals, not a design. It's one of those areas where > order of execution matters, and that wasn't well worked out. I'm not sure about the history, but this doesn't sound right to me. > Allowing classes to form a directed acyclic graph isn't very > useful. This is simply wrong. > It just fell out of the semantics of a naive interpreter. No: there's some essential work needed to make it happen. > Originally, the semantics were just wrong. Agreed. > Now the awful cases have well-defined semantics, but aren't very > useful. Disagree strongly. I think linearization is the only coherent approach to multiple inheritance, and the C3 linearization seems to have almost all of the necessary properties. I'm not quite sure what you mean by `awful' here: the old Python linearization rules were wrong even for very simple graphs (they failed to respect the superclass ordering properly). The CLOS, Dylan and C3 linearizations agree on most commonly occurring class graphs, including many graphs for which the old Python orderings disagreed; the exceptions are where CLOS or Dylan failed to be monotonic or to obey the extended precedence graph. The semantics are extremely useful in the hands of a careful designer. > Part of the problem is the notion that if a base class is duplicated > in the hierarchy, there's only one copy. This is a problem? No! Duplicating superclass state (as is done in C++ and, I believe, Eiffel) is incoherent. > So if you inherit from two classes, both of which inherit from "dict", > there will be only one "dict" at the bottom. (I think.) Yes. You end up (probably) with an enhanced dictionary which supports both protocols. This happens frequently, and is very useful. > This probably won't do what the authors of any of the classes involved > expected. The author of the class which does the multiple inheritance > might not even be aware that there's a clash further up in the > hierarchy. This is one of those areas where all the code looks right > locally, but it's wrong globally. This is only likely if there's a misdesign -- probably using inheritance where containership is required. > Best practice for this is "don't do it." Some name clashes ought > to simply be detected as errors, rather than being given such > complex semantics. It sounds like you've been scarred by experiences with C++'s dementedly inadequate object system, with its bizarre `repeated inheritance' rules and hopelessly primitive manual (static!) method combination -- possibly even to the extent of believing that they're in some way `right' or `necessary'. I'm sorry. You have my pity. Python's object system is different, and doesn't have those problems. You probably need a viewpoint shift to be able to think about it properly, but that won't happen if you continue to cling to the idea that C++'s approach is anything like a model of how to do it right. -- [mdw] From steve+comp.lang.python at pearwood.info Thu Nov 25 20:10:09 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Nov 2010 01:10:09 GMT Subject: what a cheap rule References: Message-ID: <4cef08f0$0$29974$c3e8da3$5496439d@news.astraweb.com> On Thu, 25 Nov 2010 08:15:21 -0800, Yingjie Lan wrote: > Intuition #1: as if you raise an exception type, and then match that > type. > It seems that no instances > are involved here (Intuitively). Your intuition is not my intuition, nor does it match what Python actually does. You can only go so far on *guessing* what a programming statement does, sometimes you need to actually read the Fine Manual. > See an example code here: > > try: raise KeyError > except KeyError: pass As the documentation states, this creates an instance of KeyError. raise evaluates the first expression as the exception object. It must be either a subclass or an instance of BaseException. If it is a class, the exception instance will be obtained when needed by instantiating the class with no arguments. http://docs.python.org/py3k/reference/simple_stmts.html#the-raise-statement So there is no semantic difference between "raise KeyError" and "raise KeyError()". Why should there be? What practical difference would you expect? If you do this: try: raise KeyError except KeyError as ke: print(ke) you will see that the value caught is an instance, not the class. > Intuition #2: you raise an exception > instance, and then match an instance by its type. See an example code > here: > > try: raise KeyError() > except KeyError as ke: pass Your intuition is wrong. Exceptions aren't matched by type, they are *always* matched by an isinstance() check, and that includes subclasses. >>> try: raise KeyError # with or without parentheses makes no difference ... except Exception as e: print(type(e)) ... > Those two comprehensions are not compatible, and thus the one that > promotes correct understanding should be encouraged, > while the other should be discouraged, and maybe even be made iliegal. You seem to have misunderstood both forms of the raise statement. Should we make exceptions illegal because you can't correctly guess what they do? -- Steven From lanyjie at yahoo.com Thu Nov 25 20:29:00 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Thu, 25 Nov 2010 17:29:00 -0800 (PST) Subject: what a cheap rule In-Reply-To: <4cef08f0$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: <420169.50181.qm@web54201.mail.re2.yahoo.com> --- On Fri, 11/26/10, Steven D'Aprano wrote: > From: Steven D'Aprano > Subject: Re: what a cheap rule > To: python-list at python.org > Date: Friday, November 26, 2010, 5:10 AM > On Thu, 25 Nov 2010 08:15:21 -0800, > Yingjie Lan wrote: > > You seem to have misunderstood both forms of the raise > statement. Should > we make exceptions illegal because you can't correctly > guess what they do? > > Though what you said about Python is right, I think somehow you missed my point a bit. Ideally, the language could be so 'natural' that it means what meets the eyes. Yingjie From steve+comp.lang.python at pearwood.info Thu Nov 25 20:30:23 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Nov 2010 01:30:23 GMT Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> <4ceef381$0$1659$742ec2ed@news.sonic.net> Message-ID: <4cef0daf$0$29974$c3e8da3$5496439d@news.astraweb.com> On Thu, 25 Nov 2010 15:38:36 -0800, John Nagle wrote: > Part of the problem is the notion that if a base class is duplicated in > the hierarchy, there's only one copy. Why is that a problem? I would expect it to be a problem if it showed up twice. > So if you inherit from two > classes, both of which inherit from "dict", there will be only one > "dict" at the bottom. (I think.) This probably won't do what the > authors of any of the classes involved expected. The author of the > class which does the multiple inheritance might not even be aware that > there's a clash further up in the hierarchy. This is one of those areas > where all the code looks right locally, but it's wrong globally. Why do you assume it is "wrong"? The whole point of the "complex semantics" that you are complaining about is to ensure that multiple inheritance does the right thing, rather than the wrong thing. You simply can't safely inherit from arbitrary classes without understanding them. This is equally true for single and multiple inheritance, but in multiple inheritance there are more places for things to go wrong. That is simply because the semantics of "inherit from classes A and B" are more complex than the semantics of "inherit from class A". The problem is that people expect multiple inheritance to "just work" mechanically, without giving any thought to the process. That it does often just work is a credit to the "complex semantics" that you are complaining about, but this lulls people into a false sense of security and makes it more surprising when it doesn't work. > Best practice for this is "don't do it." Some name clashes ought > to simply be detected as errors, rather than being given such complex > semantics. If that's the case, you would have to prohibit ALL multiple inheritance from new-style classes, because all new-style classes inherit from object. -- Steven From raymond.activestate at gmail.com Thu Nov 25 20:36:43 2010 From: raymond.activestate at gmail.com (Raymond Hettinger) Date: Thu, 25 Nov 2010 17:36:43 -0800 (PST) Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> <4ceef381$0$1659$742ec2ed@news.sonic.net> Message-ID: <5c92a83e-9de1-4a03-828c-2cce79ce5a30@v17g2000prc.googlegroups.com> On Nov 25, 3:38?pm, John Nagle wrote: > ? ? Multiple inheritance in Python is basically what fell out of > CPython's internals, not a design. ? Sorry to disagree. That is historically inaccurate. Guido designed super() on purpose. He took his cues from "Putting Metaclasses to Work" by Ira Forman and Scott Danforth. The method resolution order was based on yet another paper which showed the defects in the two earlier designs for multiple inheritance. It may not be great, but it sure wasn't an accident. > ? ? Best practice for this is "don't do it." ?Some name clashes ought > to simply be detected as errors, rather than being given such > complex semantics. That may well be true. If a coder has enough control over the classes to be make sure they use super() in a way that supports cooperative multiple inheritance, then they have enough control to just rename the methods to prevent name diamond shaped name clashes. OTOH, sometimes you don't have control over the names if they are magic methods or standard names like close(), save(), flush(), __init__(), etc. Raymond From raymond.activestate at gmail.com Thu Nov 25 20:41:50 2010 From: raymond.activestate at gmail.com (Raymond Hettinger) Date: Thu, 25 Nov 2010 17:41:50 -0800 (PST) Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> <7xsjyp2d12.fsf@ruckus.brouhaha.com> Message-ID: <2d8b3612-531c-467c-9ffd-9e5ff7ac2e1a@h17g2000pre.googlegroups.com> [Paul Rubin] > I'd mention the SocketServer library, except I'm not sure what you > mean by "cooperative", so I don't know if that counts. Cooperative multiple inheritance is a specific problem when there is a diamond diagram with the same method name needing to be called on multiple paths and each name should only be called exactly once. http://www.python.org/download/releases/2.2.3/descrintro/#cooperation Raymond From piadmin at nowhereland.invalid Thu Nov 25 20:58:03 2010 From: piadmin at nowhereland.invalid (piadmin) Date: Fri, 26 Nov 2010 01:58:03 GMT Subject: Preciseinfo collections updated http://preciseinfo.org Message-ID: All preciseinfo.org collections are updated. (Java, Javascript, C++ VC ATL STL, MFC VC, Python, Php) About collections: ------------------ Collections include two types of information: 1) Code examples (guaranteed to have articles with code on the subject of selected chapter, guaranteed to be relevant to that topic with > 90% certainty) 2) Expert articles Contain articles by writers with above average competence level. Internal search engine: ----------------------- All collections may be searched with a very powerfule internal search engine. It supports all standard search engine operations, including "OR" and a literal match (if you include multiple search words surrounded by quote chars (")). Also, phrase search is fully supported. Synonyms are supported. Except in programming languages synonyms are not that straightforward issue. Do not underestimate the power of INTERNAL search engine. It is a very powerful search engine. It will allow you to drill down the issue to the most precise degree. You can search on some language (Java, MFC, C++, etc.) Or you can search on a single chapter from some language. Or, you can search on ALL the languages and ALL the chapters. If and when you perform a search from some article, the default search condition is to search the chapter that article belongs to. But the search result box will show you what was found and will give you an option to change the scope of search. That is, to select some specific chapter from some collection, or to select ALL the chapters in that collection. If you click on Index link in the navbar, you will be shown the list of articles in that chapter. If you perform a search from the search box in the chapter index, the default search scope is to search that chapter. It is best to search using the internal search engine vs. standard search engines, such as Google. Because Google only has a small part of the collections indexed for whatever reason. But the internal search engine has every single article available in the collection indexed. So you have the "full scoop". Enjoy. From joe at goldthwaites.com Thu Nov 25 22:28:17 2010 From: joe at goldthwaites.com (Joe Goldthwaite) Date: Thu, 25 Nov 2010 20:28:17 -0700 Subject: Parsing markup. Message-ID: I'm attempting to parse some basic tagged markup. The output of the TinyMCE editor returns a string that looks something like this;

This is a paragraph with bold and italic elements in it

It can be made up of multiple lines separated by pagagraph tags.

I'm trying to render the paragraph into a bit mapped image. I need to parse it out into the various paragraph and bold/italic pieces. I'm not sure the best way to approach it. Elementree and lxml seem to want a full formatted page, not a small segment like this one. When I tried to feed a line similar to the above to lxml I got an error; "XMLSyntaxError: Extra content at the end of the document". -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Thu Nov 25 23:03:27 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 26 Nov 2010 04:03:27 +0000 Subject: Parsing markup. In-Reply-To: References: Message-ID: <4CEF318F.2090308@mrabarnett.plus.com> On 26/11/2010 03:28, Joe Goldthwaite wrote: > I?m attempting to parse some basic tagged markup. The output of the > TinyMCE editor returns a string that looks something like this; > >

This is a paragraph with bold and italic elements in > it

It can be made up of multiple lines separated by pagagraph > tags.

> > I?m trying to render the paragraph into a bit mapped image. I need > to parse it out into the various paragraph and bold/italic pieces. > I?m not sure the best way to approach it. Elementree and lxml seem > to want a full formatted page, not a small segment like this one. > When I tried to feed a line similar to the above to lxml I got an > error; ?XMLSyntaxError: Extra content at the end of the document?. > I'd probably use a regex: >>> import re >>> text = "

This is a paragraph with bold and italic elements in it

It can be made up of multiple lines separated by pagagraph tags.

" >>> re.findall(r"|[^<>]+", text) ['

', 'This is a paragraph with ', '', 'bold', '', ' and ', '', 'italic', '', ' elements in it', '

', '

', 'It can be made up of multiple lines separated by pagagraph tags.', '

'] From wuwei23 at gmail.com Thu Nov 25 23:31:19 2010 From: wuwei23 at gmail.com (alex23) Date: Thu, 25 Nov 2010 20:31:19 -0800 (PST) Subject: Pypi (Cheeseshop) Score - derivation of ? References: <86979c80-0955-4ee8-b645-10097d45dd58@z9g2000pri.googlegroups.com> <30d136fe-5fc3-49aa-904d-c63b228e5d2c@n2g2000pre.googlegroups.com> <4CEE2991.4050303@v.loewis.de> Message-ID: "Martin v. Loewis" wrote: > There was indeed a kwalitee computation (cheesecake); it is unmaintained. Ah yes, I couldn't remember the particular mispelling the project used :) From agoretoy at gmail.com Thu Nov 25 23:56:33 2010 From: agoretoy at gmail.com (alex goretoy) Date: Thu, 25 Nov 2010 22:56:33 -0600 Subject: class in c subclasses python classes, called in python Message-ID: I'm looking to create an application that uses c++ and python together. Currently my application is all python. But need to obfuscate some of the code. I am wanting to have c++ code so I can handle encryption with it and other tasks. But first I need it to subclass some python class objects. One task that I need to do is create a class in c++ that subclasses 3 python classes and calls the base class constructor as super would call in python. I need this in c++. How can I do this please? class ABC(a,b,c): def __init__(self, *args, **kwargs): super(ABC, self).__init__(*args, **kwargs) What I would like to know is how would I create a class in C or C++ that would: 1. create a class that subclasses 2 or more python classes 2. initializes the subclassed classes by calling the contructors like python's super would 3. import the class in python and call this class constructor with ABC(*args, **kwargs) is there a way to do this? Thanks in advance :) Thank you, -Alex Goretoy -------------- next part -------------- An HTML attachment was scrubbed... URL: From davea at ieee.org Fri Nov 26 00:06:19 2010 From: davea at ieee.org (Dave Angel) Date: Fri, 26 Nov 2010 00:06:19 -0500 Subject: Newbie subprocess question In-Reply-To: <1290725819.21008.1407210497@webmail.messagingengine.com> References: <1290725819.21008.1407210497@webmail.messagingengine.com> Message-ID: <4CEF404B.4040603@ieee.org> On 01/-10/-28163 02:59 PM, Hugo L?veill? wrote: > I'm starting various application using subprocess.Popen without any > problem. The problem is with application inside "Program Files". It > looks like subprocess is stopping the application string after > "Program". I tried puting the programe name inside double quote like > '"Program File*..."'. No luck. > > How can I start a app inside this folder ? > > Thanks > > How about you show us exactly what you are doing, and just what you mean by "no luck" ? You also should tell us what version of Python you're running, and mention that you're on Windows (presumably, but not necessarily). Perhaps you're using shell=True, perhaps you have an executable in the root directory called c:\program.exe, Perhaps you're passing arguments, but not putting them in separate list items. Who knows? DaveA From javier.collado at gmail.com Fri Nov 26 00:11:07 2010 From: javier.collado at gmail.com (Javier Collado) Date: Fri, 26 Nov 2010 06:11:07 +0100 Subject: Parsing markup. In-Reply-To: References: Message-ID: Hello, 2010/11/26 Joe Goldthwaite : > I?m attempting to parse some basic tagged markup. > >? Elementree and lxml seem to want a full formatted > page, not a small segment like this one. BeautifulSoup (http://www.crummy.com/software/BeautifulSoup/) could help in the parsing: >>> from BeautifulSoup import BeautifulSoup as Soup >>> s = Soup(text) >>> print s.prettify()

This is a paragraph with bold and italic elements in it

It can be made up of multiple lines separated by pagagraph tags.

>>> s.findAll('b') [bold] >>> s.findAll('i') [italic] >>> s.findAll('p') [

This is a paragraph with bold and italic elements in it

,

It can be made up of multiple lines separated by pagagraph tags.

] Best regards, Javier From timr at probo.com Fri Nov 26 01:37:33 2010 From: timr at probo.com (Tim Roberts) Date: Thu, 25 Nov 2010 22:37:33 -0800 Subject: Matlab equivalent syntax in Python References: <8317f18c-f2b2-4150-9bc0-e84d75e80de2@n32g2000pre.googlegroups.com> Message-ID: Akand Islam wrote: > >Can anyone please suggest me what will be the good way to use matlab >equivalent of "profile clear, profile on, profile off, profile resume >and profile viewer" in Python? Python has a number of ways of measuring elapsed time, including the "timeit" module and the "trace" module. There's nothing that will display the results in a pretty graph, so the answer depends on what you are after. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Fri Nov 26 01:45:05 2010 From: timr at probo.com (Tim Roberts) Date: Thu, 25 Nov 2010 22:45:05 -0800 Subject: SQLite date fields References: Message-ID: Alan Harris-Reid wrote: > >I am having design problems with date storage/retrieval using Python and >SQLite. > >I understand that a SQLite date column stores dates as text in ISO >format (ie. '2010-05-25'). Only if you store it that way. >So when I display a British date (eg. on a web-page) I convert the date >using datetime.datetime.strptime(mydate,'%Y-%m-%d').strftime('%d/%m/%Y'). > >However, when it comes to writing-back data to the table, SQLite is very >forgiving and is quite happy to store '25/06/2003' in a date field, SQLite is essentially typeless. ALL fields are stored as strings, with no interpretation. You can store whatever you want in any column. The column types are basically there to remind YOU how to handle the data. >How have other developers overcome this problem? By converting. SQLite's flexibility is cool, but it means you have to be smart about how you store the data. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From mftian at gmail.com Fri Nov 26 03:41:25 2010 From: mftian at gmail.com (Xie&Tian) Date: Fri, 26 Nov 2010 16:41:25 +0800 Subject: berkeley db in concurrent environment Message-ID: Hi list, I'm using bsddb.dbshelve in a conservative and concurrent environment (python version 2.4). I'm wondering if the dbshelve class methods are atomic. That is, if one process keeps writing data to one database file and another process keeps reading from it, will the reading process get incomplete(corrupted) data? Many thanks. Regards -- Luyun Xie ??? http://magefromhell.blogspot.com/ (http://blog.hellmage.info/) -------------- next part -------------- An HTML attachment was scrubbed... URL: From news1234 at free.fr Fri Nov 26 05:11:10 2010 From: news1234 at free.fr (News123) Date: Fri, 26 Nov 2010 11:11:10 +0100 Subject: Newbie subprocess question In-Reply-To: References: Message-ID: <4cef87be$0$20686$426a34cc@news.free.fr> On 11/26/2010 12:18 AM, Tim Harig wrote: > On 2010-11-25, Hugo L?veill? wrote: >> I'm starting various application using subprocess.Popen without any >> problem. The problem is with application inside "Program Files". It >> looks like subprocess is stopping the application string after >> "Program". I tried puting the programe name inside double quote like >> '"Program File*..."'. No luck. > > Not sure you you are having issues. > > subprocess.Popen("C:\\Program Files\\Vim\\vim73\\gvim.exe") Above line should work. In order to avoid the double backslashes (such, that you can just copy paste from the windows explorer or from a command line shell you could additionally prefix the string with r. subprocess.Popen(r"C:\Program Files\Vim\vim73\gvim.exe") copying and pasting reduces the risk of typos From DekuDekuplex at Yahoo.com Fri Nov 26 07:01:37 2010 From: DekuDekuplex at Yahoo.com (Benjamin L. Russell) Date: Fri, 26 Nov 2010 21:01:37 +0900 Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> <08823dd4-588a-4729-a660-711e266c96b0@y23g2000yqd.googlegroups.com> <396f8de7-ece5-4e9c-919b-886eb65ae14a@a30g2000vbt.googlegroups.com> <967678a1-fc5d-4b61-86c5-79a298999582@p1g2000vbo.googlegroups.com> <18cd9337-736b-427c-9cac-14c99056750a@p1g2000yqm.googlegroups.com> <87vd3l8iy3.fsf@padme.localdomain> Message-ID: namekuseijin writes: > I have to say I'm always amazed how ad hominens can generate quite > strong responses to the point of making a lot of new faces (or mail > accounts) suddenly appear... ;) Actually, I had just noticed that aspect as well. Is it just me, or does anybody else also think it rather curious how some of the new accounts all seem to share the same style of argument? Granted, I don't have anything the issue of arguing a point itself. However, it just seems rather unusual that many of the new faces all seem to share the same style of reasoning.... When I was a student at my college, one of the students once told me a secret about how a computer program ran by a professor for a course in introduction to systems programming checked to ensure that the students who were submitting homework assignments worked independently: the program counted the number of occurrences of each type of structure (for-loop, while-loop, if-then statement,etc.), and compared the counts for the types of structures among assignments between different students. The method was so effective that it was able to pinpoint one program among approximately thirty that was handed in by a student who had based his assignment on another program for the same assignment two years earlier, also among approximately thirty. A style of reasoning is like a fingerprint; it identifies the person making the argument. Of course, two people could have a very similar style of argument. However, the odds of this happening are less likely in a single thread. The odds of this happening are even less likely for three people in the thread. The odds of this happening are even less likely for three *new* people in the same thread at the same time.... -- Benjamin L. Russell -- Benjamin L. Russell / DekuDekuplex at Yahoo dot com http://dekudekuplex.wordpress.com/ Translator/Interpreter / Mobile: +011 81 80-3603-6725 "Furuike ya, kawazu tobikomu mizu no oto." -- Matsuo Basho^ From DekuDekuplex at Yahoo.com Fri Nov 26 07:14:15 2010 From: DekuDekuplex at Yahoo.com (Benjamin L. Russell) Date: Fri, 26 Nov 2010 21:14:15 +0900 Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> <08823dd4-588a-4729-a660-711e266c96b0@y23g2000yqd.googlegroups.com> <396f8de7-ece5-4e9c-919b-886eb65ae14a@a30g2000vbt.googlegroups.com> <967678a1-fc5d-4b61-86c5-79a298999582@p1g2000vbo.googlegroups.com> <18cd9337-736b-427c-9cac-14c99056750a@p1g2000yqm.googlegroups.com> <87vd3l8iy3.fsf@padme.localdomain> Message-ID: DekuDekuplex at Yahoo.com (Benjamin L. Russell) writes: > When I was a student at my college, one of the students once told me a > secret about how a computer program ran by a professor for a course in > introduction to systems programming checked to ensure that the students > who were submitting homework assignments worked independently: the > program counted the number of occurrences of each type of structure > (for-loop, while-loop, if-then statement,etc.), and compared the counts > for the types of structures among assignments between different > students. Minor typo corrections: 1) "computer program ran by" -> "computer program run by" 2) "if-then statement,etc." -> "if-then statement, etc." (missing period) Incidentally, regarding the programming assignment, the student who was caught by the structural similarity checking program reportedly received an e-mail message from the professor asking to explain the similarity. He never replied to that message, and subsequently received a grade of 0 for that assignment. -- Benjamin L. Russell -- Benjamin L. Russell / DekuDekuplex at Yahoo dot com http://dekudekuplex.wordpress.com/ Translator/Interpreter / Mobile: +011 81 80-3603-6725 "Furuike ya, kawazu tobikomu mizu no oto." -- Matsuo Basho^ From joncle at googlemail.com Fri Nov 26 07:58:29 2010 From: joncle at googlemail.com (Jon Clements) Date: Fri, 26 Nov 2010 04:58:29 -0800 (PST) Subject: Parsing markup. References: Message-ID: <9cb996fe-39b0-4780-bd56-5323b7269b0f@t8g2000prh.googlegroups.com> On Nov 26, 4:03?am, MRAB wrote: > On 26/11/2010 03:28, Joe Goldthwaite wrote: > ?> I?m attempting to parse some basic tagged markup. ?The output of the > ?> TinyMCE editor returns a string that looks something like this; > ?> > ?>

This is a paragraph with bold and italic elements in > ?> it

It can be made up of multiple lines separated by pagagraph > ?> tags.

> ?> > ?> I?m trying to render the paragraph into a bit mapped image. ?I need > ?> to parse it out into the various paragraph and bold/italic pieces. > ?> I?m not sure the best way to approach it. ?Elementree and lxml seem > ?> to want a full formatted page, not a small segment like this one. > ?> When I tried to feed a line similar to the above to lxml I got an > ?> error; ?XMLSyntaxError: Extra content at the end of the document?. > ?> lxml works fine for me - have you tried: from lxml import html text = "

This is a paragraph with bold and italic elements in it

It can be made up of multiple lines separated by pagagraph tags.

" tree = html.fromstring(text) print tree.findall('p') # should print [, ] hth Jon From smirnoffs at gmail.com Fri Nov 26 08:06:35 2010 From: smirnoffs at gmail.com (Sergey Smirnov) Date: Fri, 26 Nov 2010 15:06:35 +0200 Subject: How to parse a text block? Message-ID: Hi all. I have a lot of text blocks that looks like this one *** Layer 3 Message type: CP-Data Device: MS1 Time: 19:57:44.71 CP-User data length : 37 RPDU Message type indicator (MTI) : (1) RP-DATA The question is how to parse given text block into a dictionary that looks like the dictionary given below? {'Device':'MS1','Time':'Time: 19:57:44.71','CP-User data':{'length':'37','RPDU':{'Message type indicator (MTI)':'(1) RP-DATA'}}} Any other thoughts about reading that kind of text? Thanks, Sergey -------------- next part -------------- An HTML attachment was scrubbed... URL: From duncan.booth at invalid.invalid Fri Nov 26 08:20:01 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 26 Nov 2010 13:20:01 GMT Subject: SQLite date fields References: Message-ID: Tim Roberts wrote: >>However, when it comes to writing-back data to the table, SQLite is >>very forgiving and is quite happy to store '25/06/2003' in a date >>field, > > SQLite is essentially typeless. ALL fields are stored as strings, > with no interpretation. You can store whatever you want in any > column. The column types are basically there to remind YOU how to > handle the data. > Not all fields are stored as strings; they may also be stored as integer, floating point values or binary data. If you create a table with a column of type DATE or DATETIME then the column affinity is NUMERIC. See http://www.sqlite.org/datatype3.html It happens that Python stores datetime values in sqlite databases as text strings by default, but that means if you actually declare the column as DATE or DATETIME you are overriding the default type for each column. Not that it is normally noticeable but: >>> import sqlite3 >>> conn = sqlite3.connect('test.db') >>> c = conn.cursor() >>> c.execute('''CREATE TABLE t1 (d DATE, t TEXT);''') >>> from datetime import datetime >>> d = datetime.now() >>> c.execute('INSERT INTO t1 (d,t) VALUES (julianday(?),julianday(?))', (d, d)) >>> for row in c.execute('SELECT * FROM t1'): print(row) (2455527.0482040276, '2455527.04820403') >>> for row in c.execute("SELECT datetime(d), datetime(t) FROM t1"): print(row) ('2010-11-26 13:09:24', '2010-11-26 13:09:24') -- Duncan Booth http://kupuguy.blogspot.com From greywine at gmail.com Fri Nov 26 08:38:59 2010 From: greywine at gmail.com (greywine at gmail.com) Date: Fri, 26 Nov 2010 05:38:59 -0800 (PST) Subject: passing a tuple into a class function as a single argument Message-ID: <5c738442-e6f6-44b2-9442-f181ff512112@30g2000yql.googlegroups.com> Hi everyone, The following program doesn't work as expected: #Python 2.7 & wxPython 2.9 import wx class MyFrame(wx.Frame): """ We simply derive a new class of Frame. """ def __init__(self, parent, title): wx.Frame.__init__(self, parent, title=title, size=(200,100)) self.control = wx.TextCtrl(self, style=wx.TE_MULTILINE) self.Show(True) app = wx.App(False) size=(600,400) frame = MyFrame(None, 'Small editor') #frame = MyFrame(None, 'Small editor', (600,400)) app.MainLoop() If I use the default size=(200,100) it's just fine. But if I try it pass it a new size (600,400), I get the following error: Traceback (most recent call last): File "C:\Python27\wxpythoneasy1.py", line 13, in frame = MyFrame(None, 'Small editor',((600,400))) TypeError: __init__() takes exactly 3 arguments (4 given) It seems like it's begging to have it pass a different size than the default, but there doesn't seem to be a way to pass a tuple as a single argument. Any help would be appreciate. Thanks, John R. From mwilson at the-wire.com Fri Nov 26 08:53:21 2010 From: mwilson at the-wire.com (Mel) Date: Fri, 26 Nov 2010 08:53:21 -0500 Subject: passing a tuple into a class function as a single argument References: <5c738442-e6f6-44b2-9442-f181ff512112@30g2000yql.googlegroups.com> Message-ID: greywine at gmail.com wrote: > Hi everyone, > > The following program doesn't work as expected: > > > #Python 2.7 & wxPython 2.9 > > import wx > > class MyFrame(wx.Frame): > """ We simply derive a new class of Frame. """ > def __init__(self, parent, title): > wx.Frame.__init__(self, parent, title=title, size=(200,100)) > self.control = wx.TextCtrl(self, style=wx.TE_MULTILINE) > self.Show(True) > > app = wx.App(False) > size=(600,400) > frame = MyFrame(None, 'Small editor') > #frame = MyFrame(None, 'Small editor', (600,400)) > app.MainLoop() > > If I use the default size=(200,100) it's just fine. But if I try it > pass it a new size (600,400), I get the following error: > Traceback (most recent call last): > File "C:\Python27\wxpythoneasy1.py", line 13, in > frame = MyFrame(None, 'Small editor',((600,400))) > TypeError: __init__() takes exactly 3 arguments (4 given) > > It seems like it's begging to have it pass a different size than the > default, but there doesn't seem to be a way to pass a tuple as a > single argument. > > Any help would be appreciate. You have to tell __init__ what's coming. def __init__(self, parent, title, size): wx.Frame.__init__(self, parent, title=title, size=size) and so on. Mel. From fuzzyman at gmail.com Fri Nov 26 09:16:01 2010 From: fuzzyman at gmail.com (Fuzzyman) Date: Fri, 26 Nov 2010 06:16:01 -0800 (PST) Subject: what a cheap rule References: <4cef08f0$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: <71457b9a-2299-498d-bd5b-aef361011c5f@i10g2000prd.googlegroups.com> On Nov 26, 1:10?am, Steven D'Aprano wrote: > On Thu, 25 Nov 2010 08:15:21 -0800, Yingjie Lan wrote: > > Intuition #1: as if you raise an exception type, and then match that > > type. > > It seems that no instances > > are involved here (Intuitively). > > Your intuition is not my intuition, nor does it match what Python > actually does. You can only go so far on *guessing* what a programming > statement does, sometimes you need to actually read the Fine Manual. > > > See an example code here: > > > try: raise KeyError > > except KeyError: pass > > As the documentation states, this creates an instance of KeyError. > > ? ? raise evaluates the first expression as the exception object. > ? ? It must be either a subclass or an instance of BaseException. > ? ? If it is a class, the exception instance will be obtained when > ? ? needed by instantiating the class with no arguments. > > http://docs.python.org/py3k/reference/simple_stmts.html#the-raise-sta... > > So there is no semantic difference between "raise KeyError" and > "raise KeyError()". Why should there be? What practical difference would > you expect? > There *can* be a difference though. >>> raise UnicodeDecodeError Traceback (most recent call last): File "", line 1, in TypeError: function takes exactly 5 arguments (0 given) :-) > > You seem to have misunderstood both forms of the raise statement. Should > we make exceptions illegal because you can't correctly guess what they do? Sometimes people not being able to understand them is a good reason for making things illegal (or rather for not making them legal in the first place). I don't think it applies to this particular case though. All the best, Michael Foord -- http://www.voidspace.org.uk/ From python.list at tim.thechases.com Fri Nov 26 09:49:33 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 26 Nov 2010 08:49:33 -0600 Subject: SQLite date fields In-Reply-To: References: Message-ID: <4CEFC8FD.2050802@tim.thechases.com> On 11/26/2010 07:20 AM, Duncan Booth wrote: > Tim Roberts wrote: >> SQLite is essentially typeless. ALL fields are stored as >> strings, with no interpretation. You can store whatever you >> want in any column. The column types are basically there to >> remind YOU how to handle the data. >> > > Not all fields are stored as strings; they may also be stored > as integer, floating point values or binary data. Where the test gets funky: >>> import sqlite3 >>> conn = sqlite3.connect(':memory:') >>> c = conn.cursor() >>> c.execute('''CREATE TABLE t1 (d DATE, t TEXT, i INTEGER)''') >>> c.execute('''INSERT INTO t1 (d, t, i) VALUES ('foo', 'bar', 'baz')''') >>> c.execute('SELECT * FROM t1') >>> c.fetchall() [(u'foo', u'bar', u'baz')] Reminds me a bit of this [1] thread. -tkc [1] http://www.mail-archive.com/python-list at python.org/msg108200.html From michele.simionato at gmail.com Fri Nov 26 10:02:33 2010 From: michele.simionato at gmail.com (Michele Simionato) Date: Fri, 26 Nov 2010 07:02:33 -0800 (PST) Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> Message-ID: <926a28bb-8cab-4be7-b27b-00cfa76537f3@n2g2000pre.googlegroups.com> On Nov 24, 9:08?pm, Raymond Hettinger wrote: > So far, the only situation I can find where method names necessarily > overlap is for the basics like __init__(), close(), flush(), and > save() where multiple parents need to have their own initialization > and finalization. I do not know of other use cases either. Michele Simionato From user at compgroups.net/ Fri Nov 26 10:27:59 2010 From: user at compgroups.net/ (Oskar) Date: Fri, 26 Nov 2010 09:27:59 -0600 Subject: Help with suds: HTTP Error 401 References: Message-ID: I was having the same issue until I updated suds to the newest version. From edreamleo at gmail.com Fri Nov 26 11:04:19 2010 From: edreamleo at gmail.com (Edward K. Ream) Date: Fri, 26 Nov 2010 08:04:19 -0800 (PST) Subject: ANN: Leo 4.8 final Message-ID: Leo 4.8 final is now available at: http://sourceforge.net/project/showfiles.php?group_id=3458&package_id=29106 Leo is a text editor, data organizer, project manager and much more. See: http://webpages.charter.net/edreamleo/intro.html The highlights of Leo 4.8: -------------------------- - Leo now uses the simplest possible sentinel lines in external files. External files with sentinels now look like Emacs org-mode files. - Leo Qt gui now supports Drag and Drop. This was one of the most frequently requested features. - Improved abbreviation commands. You now define abbreviations in Leo settings nodes, not external files. - @url nodes may contain url's in body text. This allows headlines to contain summaries: very useful. - Leo now uses PyEnchant to check spelling. - Leo can now open multiple files from the command line. - Leo's ancient Tangle and Untangle commands are now deprecated. This will help newbies how to learn Leo. - Leo now shows "Resurrected" and "Recovered" nodes. These protect data and show how data have changed. These fix several long-standing data-related problems. - A new "screenshots" plugin for creating slide shows with Leo. I used this plugin to create Leo's introductory slide shows. - Improved autocompletion: Ctrl-space starts a one-time completion. - A better installer. - Many bug fixes. Links: ------ Leo: http://webpages.charter.net/edreamleo/front.html Forum: http://groups.google.com/group/leo-editor Download: http://sourceforge.net/project/showfiles.php?group_id=3458 Bzr: http://code.launchpad.net/leo-editor/ Quotes: http://webpages.charter.net/edreamleo/testimonials.html Edward K. Ream November 26, 2010 From hpj at urpla.net Fri Nov 26 11:52:26 2010 From: hpj at urpla.net (Hans-Peter Jansen) Date: Fri, 26 Nov 2010 17:52:26 +0100 Subject: PyQt Installation Problem on Windows In-Reply-To: <22cf97c9-ac22-4af1-8834-7ccb1828cc47@p1g2000yqm.googlegroups.com> References: <22cf97c9-ac22-4af1-8834-7ccb1828cc47@p1g2000yqm.googlegroups.com> Message-ID: <201011261752.26972.hpj@urpla.net> On Wednesday 24 November 2010, 23:03:14 Saul Spatz wrote: > Hi, > > I've been trying to install PyQt on Windows XP Pro so that I can try > out eric ide. I used the binary windows installer for PyQt. I can > run eric as administrator, but not with my ordinary user account. By > running eric.bat with the --debug flag, I found that he crux of the > problem is that if I type > > import PyQt4 > > in the python shell, it works for both users, but if I type > > import PyQt4.QtCore > > it works for the administrator, but the non-privileged account gets > the message > > ImportError: DLL load failed: The specified module could not be > found. My WinXP installations are always a bit lacking, since I do work 97% of my time in Linux (and 2% on MacOSX), but Python 2.6.6 and PyQt 4.7.7 do work fine here as a user win XP SP3/i586. Things like what you describe usually point to broken installations (remaining manual build artefacts, unfinished installs, incomplete deinstallations, ...). Just uninstall Python and PyQt, remove everything below your Python base path, and start over (a registry check/cleanup might be worth, too). > In the file the file pyqtconfig.py from Python26\Lib\site-packages > \PyQt4 I have the line > > 'pyqt_config_args': '--confirm-license -b C:\\Python26\\Lib\\site- > packages\\PyQt4\\bin', > > I checked with a friend who uses eric, and his file does not have the > --confirm-license parameter. As far as we can tell, we followed the > same installation procedures. This is unrelated, since it is only a detail in the build process, but points to differing versions. > By the way, I have tried this with python 3.1 on the same machine > with similar results. > > I've blown a whole day playing with this, so I'd really appreciate > any help you can give me. Pete From aahz at pythoncraft.com Fri Nov 26 11:58:31 2010 From: aahz at pythoncraft.com (Aahz) Date: 26 Nov 2010 08:58:31 -0800 Subject: playful coding problems for 10 year olds References: Message-ID: In article , Daniel Fetchinson wrote: > >My niece is interested in programming and python looks like a good >choice (she already wrote a couple of lines :)) She is 10 and I thought >it would be good to have a bunch of playful coding problems for her, >stuff that she could code herself maybe after some initial help. What other interests does she have? Might Python play a role? http://micheinnz.livejournal.com/1080735.html (Agent Weasel ended up making a presentation at the NZ PyCon.) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Think of it as evolution in action." --Tony Rand From gpodevij at gmail.com Fri Nov 26 12:46:01 2010 From: gpodevij at gmail.com (=?ISO-8859-1?Q?Ga=EBtan_Podevijn?=) Date: Fri, 26 Nov 2010 18:46:01 +0100 Subject: Kind of plugin system Message-ID: Hello, Here is my problem. I need to get some informations from files stored on my filesystem, Flickr and Picasa. So the idea is to create a class (for instance, "InformationsProvider") that provides common methods for those three sources, then, for each source, I create a class that inherits from "InformationsProvider" such as "InformationsLocalProvider", "InformationsFlickrProvider" and "InformationPicasaProvider". It is clearly needed because the method to get the informations is totally different for each source (the connection with flickr or picasa for exemple). However, I'd like, in the future, to be able to add new source and thus, just add a new class that implements the methods from Provider. The thing is, I'd like to add only one class, and that the rest of the application is able to use that class without really knowing how many class there are. I'd have something like : for each provider that exists: get the informations file and if I add a new .py that implements a new provider (say Delicious of GMail), the code above takes account of the new class. It must be "dynamic". Could you help me with that ? I hope I was clear enough. Thanks a lot, Ga?tan -------------- next part -------------- An HTML attachment was scrubbed... URL: From gslindstrom at gmail.com Fri Nov 26 13:13:25 2010 From: gslindstrom at gmail.com (Greg Lindstrom) Date: Fri, 26 Nov 2010 12:13:25 -0600 Subject: Dictionaries inside out Message-ID: I am working on a project where I'm using dictionaries to hold the translations to codes (i.e., {'1':'Cheddar','2':'Ice Hockey','IL':'Thermostat Broken'}). The bulk of the application requires me to translate codes to their meaning, but it would be nice to be able to translate a meaning back to the original code as well. This seems to me like it must be a common situation that has been addresses/solved by those smarter than me. Is there, dare I say, a design pattern for this problem? Is there a better way of approaching it other than making a set of dictionaries which "mirror" the originals? FWIW, I have approximately 50 tables ranging from 2 entries to over 100. Thanks, --greg -------------- next part -------------- An HTML attachment was scrubbed... URL: From burton at userful.com Fri Nov 26 13:15:11 2010 From: burton at userful.com (Burton Samograd) Date: Fri, 26 Nov 2010 11:15:11 -0700 Subject: Dictionaries inside out References: Message-ID: Greg Lindstrom writes: > I am working on a project where I'm using dictionaries to hold the > translations to codes (i.e., {'1':'Cheddar','2':'Ice > Hockey','IL':'Thermostat Broken'}).? The bulk of the application > requires me to translate codes to their meaning, but it would be nice > to be able to translate a meaning back to the original code as well.? > This seems to me like it must be a common situation that has been > addresses/solved by those smarter than me.? Is there, dare I say, a > design pattern for this problem?? Is there a better way of approaching > it other than making a set of dictionaries which "mirror" the > originals?? FWIW, I have approximately 50 tables ranging from 2 > entries to over 100. Looks like there might be some solutions here: http://stackoverflow.com/questions/483666/python-reverse-inverse-a-mapping -- Burton Samograd From casevh at gmail.com Fri Nov 26 13:31:32 2010 From: casevh at gmail.com (casevh) Date: Fri, 26 Nov 2010 10:31:32 -0800 (PST) Subject: inverse of a matrix with Fraction entries References: <8l50ulFhb4U1@mid.individual.net> <87y68izdnh.fsf.mdw@metalzone.distorted.org.uk> <878w0hyve1.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On Nov 25, 1:28?pm, Daniel Fetchinson wrote: > Okay, I see your point and I completely agree. > Surely it will be faster to do it with integers, will give it a shot. > > Cheers, > Daniel > > -- > Psss, psss, put it down! -http://www.cafepress.com/putitdown You may want to look at using GMPY. GMPY wraps the Gnu Multiple- precision library and includes support for rational arithmetic. I just tested a few calculations involving rational numbers with hundreds to thousands of digits and GMPY's mpq type was between 10x and 100x faster than fractions.Fractions. GMPY is availabe at http://code.google.com/p/gmpy/ casevh Disclaimer: I'm the current maintainer of GMPY. From iamforufriends at gmail.com Fri Nov 26 13:39:48 2010 From: iamforufriends at gmail.com (READY 4 DATE(WIFE WITH HUSBAND)) Date: Fri, 26 Nov 2010 10:39:48 -0800 (PST) Subject: WIFE WITH HUSBEND HERE FOR DATING... ANYBODY THERE..... Message-ID: WIFE WITH HUSBEND HERE FOR DATING... ANYBODY THERE..... http://u3.co.za/m8 http://u3.co.za/m8 http://u3.co.za/m8 http://u3.co.za/m8 From gpodevij at gmail.com Fri Nov 26 13:49:48 2010 From: gpodevij at gmail.com (=?ISO-8859-1?Q?Ga=EBtan_Podevijn?=) Date: Fri, 26 Nov 2010 19:49:48 +0100 Subject: Dictionaries inside out In-Reply-To: References: Message-ID: Found in Dive in Python 3 : >>> a_dict = {'a': 1, 'b': 2, 'c': 3} >>> {value:key for key, value in a_dict.items()} {1: 'a', 2: 'b', 3: 'c'} 2010/11/26 Burton Samograd > Greg Lindstrom writes: > > > I am working on a project where I'm using dictionaries to hold the > > translations to codes (i.e., {'1':'Cheddar','2':'Ice > > Hockey','IL':'Thermostat Broken'}). The bulk of the application > > requires me to translate codes to their meaning, but it would be nice > > to be able to translate a meaning back to the original code as well. > > This seems to me like it must be a common situation that has been > > addresses/solved by those smarter than me. Is there, dare I say, a > > design pattern for this problem? Is there a better way of approaching > > it other than making a set of dictionaries which "mirror" the > > originals? FWIW, I have approximately 50 tables ranging from 2 > > entries to over 100. > > Looks like there might be some solutions here: > > http://stackoverflow.com/questions/483666/python-reverse-inverse-a-mapping > > -- > Burton Samograd > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From aahz at pythoncraft.com Fri Nov 26 14:57:03 2010 From: aahz at pythoncraft.com (Aahz) Date: 26 Nov 2010 11:57:03 -0800 Subject: a regexp riddle: re.search(r'(?:(\w+), |and (\w+))+', 'whatever a, bbb, and c') =? ('a', 'bbb', 'c') References: <00a69232-7703-48ce-8a42-b28f24946680@i32g2000pri.googlegroups.com> Message-ID: In article , Phlip wrote: > >Thanks all for playing! And as usual I forgot a critical detail: > >I'm writing a matcher for a Morelia /viridis/ Scenario step, so the >matcher must be a single regexp. Why? (You're apparently the author of Morelia, but I don't really understand it.) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Think of it as evolution in action." --Tony Rand From nagle at animats.com Fri Nov 26 14:59:49 2010 From: nagle at animats.com (John Nagle) Date: Fri, 26 Nov 2010 11:59:49 -0800 Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance In-Reply-To: <5c92a83e-9de1-4a03-828c-2cce79ce5a30@v17g2000prc.googlegroups.com> References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> <4ceef381$0$1659$742ec2ed@news.sonic.net> <5c92a83e-9de1-4a03-828c-2cce79ce5a30@v17g2000prc.googlegroups.com> Message-ID: <4cf011b9$0$1619$742ec2ed@news.sonic.net> On 11/25/2010 5:36 PM, Raymond Hettinger wrote: > On Nov 25, 3:38 pm, John Nagle wrote: > >> Best practice for this is "don't do it." Some name clashes ought >> to simply be detected as errors, rather than being given such >> complex semantics. > > That may well be true. If a coder has enough control over the classes > to be make sure they use super() in a way that supports cooperative > multiple inheritance, then they have enough control to just > rename the methods to prevent name diamond shaped name clashes. > > OTOH, sometimes you don't have control over the names if they > are magic methods or standard names like close(), save(), flush(), > __init__(), etc. I'd argue that a better implementation would require that when there's a name clash, you have to specify the class containing the name. In other words, if A is a subclass of B, then B.foo() overrides A.foo(). But if C is a subclass of A and B, and there's an A.foo() and a B.foo(), calling self.foo() in C should be an error, because it's ambiguous. You should have to specify the parent class, using "super". The same issue applies in the other direction. If A and B are subclasses of D, and A.foo() and B.foo() are defined, and D calls self.foo(), that's an ambiguity and should be reported. This catches the case where two classed both inherit from, say "threading.thread", each expecting to have a private thread. Someone then inherits from both classes, getting totally unexpected results when one of the "run" methods is chosen somewhat arbitrarily. Detecting a clash requires machinery CPython's lookup machinery currently lacks. That's why I wrote that the current semantics fell out of the implementation. Again, this is a form of global bug - each class can appear internally correct, but the combination of them won't work as expected. This is the sort of thing which produces obscure bugs when the components come from different sources. Python has relatively few dark corners like this, but this is one of them. (Although, in practice, nobody seems to use this stuff, so it may not matter.) John Nagle From nagle at animats.com Fri Nov 26 15:54:12 2010 From: nagle at animats.com (John Nagle) Date: Fri, 26 Nov 2010 12:54:12 -0800 Subject: inverse of a matrix with Fraction entries In-Reply-To: References: <8l50ulFhb4U1@mid.individual.net> Message-ID: <4cf01e79$0$1592$742ec2ed@news.sonic.net> On 11/24/2010 10:30 AM, Robert Kern wrote: > On 11/24/10 12:07 PM, Daniel Fetchinson wrote: > >> The whole story is that I have a matrix A and matrix B both of which >> have rational entries and they both have pretty crazy entries too. >> Their magnitude spans many orders of magnitude, but inverse(A)*B is an >> okay matrix and I can deal with it using floating point numbers. I >> only need this exact fraction business for inverse(A)*B (yes, a >> preconditioner would be useful :)) >> >> And I wouldn't want to write the whole matrix into a file, call Maple >> on it, parse the result, etc. >> >> So after all I might just code the inversion via Gauss elimination >> myself in a way that can deal with fractions, shouldn't be that hard. > > +1000. This is almost always the right thing to do whether you have > floats or rationals. Right. Inverting a matrix of rationals works fine. There's even a standard use for that, in theorem proving. See G. Nelson and D. C. Oppen. Simplification by cooperating decision procedures. ACM Transactions on Programming Languages and Systems, 1(2):245?257, 1979. It turns out that theorem proving for problems in rational arithmetic which use only addition, subtraction, multiplication by constants, comparisons for equal, greater and less, and the boolean operators is completely decidable. (This covers most of what programs do, especially in the parts that affect control flow.) There's a neat algorithm for solving such problems; you either get "True" or a counterexample. The algorithm uses the simplex method from linear programming, but with rational arithmetic. But that's an exotic application. For ordinary number crunching, rational arithmetic is completely inappropriate. John Nagle From sohel807 at gmail.com Fri Nov 26 16:15:50 2010 From: sohel807 at gmail.com (Akand Islam) Date: Fri, 26 Nov 2010 13:15:50 -0800 (PST) Subject: Matlab equivalent syntax in Python References: <8317f18c-f2b2-4150-9bc0-e84d75e80de2@n32g2000pre.googlegroups.com> Message-ID: <99f8ef31-646e-4e9c-912d-e607389d5191@r31g2000prg.googlegroups.com> On Nov 26, 12:37?am, Tim Roberts wrote: > Akand Islam wrote: > > >Can anyone please suggest me what will be the good way to use matlab > >equivalent of "profile clear, profile on, profile off, profile resume > >and profile viewer" in Python? > > Python has a number of ways of measuring elapsed time, including the > "timeit" module and the "trace" module. ?There's nothing that will display > the results in a pretty graph, so the answer depends on what you are after. > -- > Tim Roberts, t... at probo.com > Providenza & Boekelheide, Inc. Dear Tim Roberts, Thanks for your posting. Like, here is the following Matlab codes which I am trying to transform into Python. Here you will find "profile clear, profile on, profile off, profile resume, profile viewer, and drawnow" syntaxes. So, what will be these equivalents in Python? Regards, Akand =============================================================================================================== function x = amg_solve(GUI_HANDLES); amg_globals; str=get(GUI_HANDLES.panelText,'String'); %Check the source of the problem specification if PROB_SRC==USER_SPEC_FD %if the user finite difference matrix is to be used str=strcat(str,sprintf('\n Initializing Problem to User Specifications ')); str=strcat(str,sprintf('\n USER: Please enter your input file name at the console...')); set(GUI_HANDLES.panelText,'String',str); drawnow; amg_usersetFD; %set up globals as the user has specified them elseif PROB_SRC==USER_SPEC_FEM %if the user finite element matrix is to be used str=strcat(str,sprintf('\n Initializing Problem to User Specifications ')); str=strcat(str,sprintf('\n USER: Please enter your input file name at the console...')); set(GUI_HANDLES.panelText,'String',str); drawnow; amg_usersetFEM; %set up globals as the user has specified them elseif PROB_SRC==EXAMPLE1 %if example 1 is called for str=strcat(str,sprintf('\n Initializing Problem to Poisson Example ')); set(GUI_HANDLES.panelText,'String',str); drawnow; amg_example1; %set up globals for example 1 end profile clear; if SETUP_OPT==AT_ONCE %if user wishes to find all coarse grids up front % see "restrict.m" for what happens otherwise str=strcat(str,sprintf('\n Calling Setup Algorithm to Determine Coarse Grids ')); set(GUI_HANDLES.panelText,'String',str); drawnow; if SHOW_PROFILE==YES profile on; end amg_setup(1); %call setup algorithm if SHOW_PROFILE==YES profile off; end end INIT_RESID = norm(RHS - (A(1).matrix * X_Guess)); %get initial residual str=strcat(str,sprintf('\n 2-Norm of Initial Residual is %d ', INIT_RESID)); set(GUI_HANDLES.panelText,'String',str); drawnow; x = X_Guess; cycleCount = 1; %count the number of AMG cycles executed while (cycleCount<=CYCLES) str=strcat(str,sprintf('\n Starting AMG Cycle Number %i... ', cycleCount)); set(GUI_HANDLES.panelText,'String',str); drawnow; if SHOW_PROFILE==YES profile resume; end x = amg_cycle(cycleCount,1,RHS,x); %execute as many AMG cycles if necessary if SHOW_PROFILE==YES profile off; end str=strcat(str,sprintf('\n 2-Norm of Residual after AMG Cycle Number %i is %d ', cycleCount, norm(RH2(cycleCount,1)))); set(GUI_HANDLES.panelText,'String',str); drawnow; cycleCount=cycleCount+1; %incriment cycle count end FINAL_RESID = norm(RHS - (A(1).matrix * x)); %get initial residual str=strcat(str,sprintf('\nFinished... ')); set(GUI_HANDLES.panelText,'String',str); drawnow; if SHOW_PROFILE==YES profile viewer; end ================================================================================================================================== From tjreedy at udel.edu Fri Nov 26 16:43:28 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 26 Nov 2010 16:43:28 -0500 Subject: Dictionaries inside out In-Reply-To: References: Message-ID: On 11/26/2010 1:13 PM, Greg Lindstrom wrote: > I am working on a project where I'm using dictionaries to hold the > translations to codes (i.e., {'1':'Cheddar','2':'Ice > Hockey','IL':'Thermostat Broken'}). The bulk of the application > requires me to translate codes to their meaning, but it would be nice to > be able to translate a meaning back to the original code as well. This > seems to me like it must be a common situation that has been > addresses/solved by those smarter than me. Is there, dare I say, a > design pattern for this problem? Is there a better way of approaching > it other than making a set of dictionaries which "mirror" the > originals? FWIW, I have approximately 50 tables ranging from 2 entries > to over 100. Making 50 inverse dictionaries is trivial. Depending on your need, you might instead consider one inverse dict that maps 'meaning' to (table,code) pairs (assuming that meanings are not unique across the 50 original tables. -- Terry Jan Reedy From cs at zip.com.au Fri Nov 26 16:50:33 2010 From: cs at zip.com.au (Cameron Simpson) Date: Sat, 27 Nov 2010 08:50:33 +1100 Subject: Matlab equivalent syntax in Python In-Reply-To: <99f8ef31-646e-4e9c-912d-e607389d5191@r31g2000prg.googlegroups.com> References: <99f8ef31-646e-4e9c-912d-e607389d5191@r31g2000prg.googlegroups.com> Message-ID: <20101126215033.GA26585@cskk.homeip.net> On 26Nov2010 13:15, Akand Islam wrote: | Thanks for your posting. Like, here is the following Matlab codes | which I am trying to transform into Python. Here you | will find "profile clear, profile on, profile off, profile resume, | profile viewer, and drawnow" syntaxes. So, what will be these | equivalents | in Python? I would start by looking at the "profile" python module: http://docs.python.org/library/profile.html#module-profile Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Their are thre mistakes in this sentence. - Rob Ray DoD#33333 From steve+comp.lang.python at pearwood.info Fri Nov 26 17:11:01 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Nov 2010 22:11:01 GMT Subject: inverse of a matrix with Fraction entries References: <8l50ulFhb4U1@mid.individual.net> <4cf01e79$0$1592$742ec2ed@news.sonic.net> Message-ID: <4cf03075$0$29994$c3e8da3$5496439d@news.astraweb.com> On Fri, 26 Nov 2010 12:54:12 -0800, John Nagle wrote: > For ordinary number crunching, > rational arithmetic is completely inappropriate. Why? -- Steven From ben+python at benfinney.id.au Fri Nov 26 17:18:21 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 27 Nov 2010 09:18:21 +1100 Subject: Dictionaries inside out References: Message-ID: <87ipzj7mqa.fsf@benfinney.id.au> (Replying to Greg, though his original message doesn't appear at Gmane.) > Greg Lindstrom writes: > > > I am working on a project where I'm using dictionaries to hold the > > translations to codes (i.e., {'1':'Cheddar','2':'Ice > > Hockey','IL':'Thermostat Broken'}).? The bulk of the application > > requires me to translate codes to their meaning, but it would be nice > > to be able to translate a meaning back to the original code as > > well.? If the dict is small and static, and you are sure that each value is unique, I would say simply create the reverse mapping:: desc_by_code = { '1': "Cheddar", '2': "Ice Hockey", 'IL': "Thermostat Broken", } code_by_desc = dict( (desc, code) for (code, desc) in codes_to_messages.items()) > > This seems to me like it must be a common situation that has been > > addresses/solved by those smarter than me.? Is there, dare I say, a > > design pattern for this problem? Yes, a relational database. That might be too much overhead though. > > Is there a better way of approaching > > it other than making a set of dictionaries which "mirror" the > > originals?? FWIW, I have approximately 50 tables ranging from 2 > > entries to over 100. You may have crossed the threshold where a relational database becomes more useful than a bunch of dicts. SQLite is built into Python, and can store its database in memory or in a single file. If the overhead of a database layer is too much, then creating the reverse mappings automatically (as above) is simple enough and works fine. -- \ ?The double standard that exempts religious activities from | `\ almost all standards of accountability should be dismantled | _o__) once and for all.? ?Daniel Dennett, 2010-01-12 | Ben Finney From tavares at fe.up.pt Fri Nov 26 17:54:30 2010 From: tavares at fe.up.pt (tavares at fe.up.pt) Date: Fri, 26 Nov 2010 14:54:30 -0800 (PST) Subject: =?windows-1252?Q?Symposium_=93Computational_Methods_in_Image_Analysis?= =?windows-1252?Q?=94_within_the_USNCCM_11_Congress_=96_Announce_=26_Call_for_Pa?= =?windows-1252?Q?pers?= Message-ID: <57aaabd1-5654-4915-86b9-fe73e0120989@q18g2000vbk.googlegroups.com> Dear Colleague, Within the 11th U.S. National Congress on Computational Mechanics (USNCCM 11 - www.usnccm.org), to be held in Minnesota, USA, in July 25-29, 2011, we are organizing the Symposium ?Computational methods in image analysis?. Examples of some topics that will be considered in the symposium ?Computational methods in image analysis? are: Image Analysis, Objects Modeling, Image Segmentation, Matching, Shape Reconstruction, Motion and Deformation Analysis, Objects Description and Registration, Medical imaging, Software Development for Image Analysis and Grid and High Performance Computing in Image Analysis. Due to your research activities in those fields, we would like to invite you to submit your work and participate in the Symposium ?Computational methods in image analysis?. For instructions and submission, please access to the conference website at: www.usnccm.org Please note that, when submitting your work you should select the Symposium ?2.1 - Computational Methods in Image Analysis?. Important dates: - Abstract submission: November 1, 2010 - January 31, 2011; - Student poster presentation submission: December 15, 2010 - January 31, 2011; - Notifications of abstract acceptance/rejection: February 28, 2011. Kind regards, Jo?o Manuel R. S. Tavares (University of Porto, Portugal, tavares at fe.up.pt) Renato Natal Jorge (University of Porto, Portugal, rnatal at fe.up.pt) Yongjie Zhang (Carnegie Mellon University, USA, jessicaz at andrew.cmu.edu) Dinggang Shen (UNC-CH School of Medicine, USA, dgshen at med.unc.edu) (Symposium organizers) From ben+python at benfinney.id.au Fri Nov 26 18:29:15 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 27 Nov 2010 10:29:15 +1100 Subject: Dictionaries inside out References: <87ipzj7mqa.fsf@benfinney.id.au> Message-ID: <87eia77jg4.fsf@benfinney.id.au> Ben Finney writes: > code_by_desc = dict( > (desc, code) for (code, desc) in codes_to_messages.items()) Bah, I fumbled an edit. Try this:: code_by_desc = dict( (desc, code) for (code, desc) in desc_by_code.items()) -- \ ?The reason we come up with new versions is not to fix bugs. | `\ It's absolutely not.? ?Bill Gates, 1995-10-23 | _o__) | Ben Finney From mdw at distorted.org.uk Fri Nov 26 19:21:58 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Sat, 27 Nov 2010 00:21:58 +0000 Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> <4ceef381$0$1659$742ec2ed@news.sonic.net> <5c92a83e-9de1-4a03-828c-2cce79ce5a30@v17g2000prc.googlegroups.com> <4cf011b9$0$1619$742ec2ed@news.sonic.net> Message-ID: <87y68fwr89.fsf.mdw@metalzone.distorted.org.uk> John Nagle writes: > I'd argue that a better implementation would require that when there's > a name clash, you have to specify the class containing the name. In > other words, if A is a subclass of B, then B.foo() overrides > A.foo(). But if C is a subclass of A and B, and there's an A.foo() and > a B.foo(), calling self.foo() in C should be an error, because it's > ambiguous. You should have to specify the parent class, using "super". How peculiar. `super' is /specifically/ for working out dynamically which superclass to delegate behaviour to, because working it out statically isn't possible in general. > The same issue applies in the other direction. If A and B are > subclasses of D, and A.foo() and B.foo() are defined, and D calls > self.foo(), that's an ambiguity and should be reported. No it isn't. It's downward delegation, which is an essential feature of object oriented design. > @This catches the case where two classed both inherit from, say > "threading.thread", each expecting to have a private thread. Why on earth would anyone do such a bizarre thing? If you want a private thread, then attach one as an attribute. Inheriting is simply madness. > Someone then inherits from both classes, getting totally unexpected > results when one of the "run" methods is chosen somewhat arbitrarily. But only because the original design was crazy. If you make a subclass of `thread' it's because you wanted a more specific kind of thread. If you subclass two other subclasses of `thread', it's because you wanted a very specific kind of thread which included the behaviour of those other two subclasses. > Detecting a clash requires machinery CPython's lookup machinery > currently lacks. What you see as a `clash' is more likely deliberate factoring of behaviour. Again, you seem to think that C++ is, for some reason, the `one true way'. It really isn't. Actually, it's a pretty poor way. But that's not the point: the point is that there are other ways, and if you stopped whining about how Python's object system might theoretically go wrong if you try to use it like it was C++ and started thinking about how to actually make effective use of the features it offers -- features which long predate Python, and have been thought about over many years, in languages such as Zetalisp, Common Lisp, Dylan, Scheme, and variants of Smalltalk -- you might got on much better. -- [mdw] From sohel807 at gmail.com Fri Nov 26 19:23:44 2010 From: sohel807 at gmail.com (Akand Islam) Date: Fri, 26 Nov 2010 16:23:44 -0800 (PST) Subject: Matlab equivalent syntax in Python References: <99f8ef31-646e-4e9c-912d-e607389d5191@r31g2000prg.googlegroups.com> Message-ID: <42086c34-43bd-44d8-a1e3-f220f62826b0@g19g2000yqg.googlegroups.com> On Nov 26, 3:50?pm, Cameron Simpson wrote: > On 26Nov2010 13:15, Akand Islam wrote: > | Thanks for your posting. Like, here is the following Matlab codes > | which I am trying to transform into Python. Here you > | will find "profile clear, profile on, profile off, profile resume, > | profile viewer, and drawnow" syntaxes. So, what will be these > | equivalents > | in Python? > > I would start by looking at the "profile" python module: > > ?http://docs.python.org/library/profile.html#module-profile > > Cheers, > -- > Cameron Simpson DoD#743http://www.cskk.ezoshosting.com/cs/ > > Their are thre mistakes in this sentence. > ? ? ? ? - Rob Ray DoD#33333 Dear Cameron Simpson, Thanks for co-operation. I have gone through the link, however, I am not much clear. Can you please show me some python syntaxes which contain Matlab like "profile on.., drawnow.." and so forth? Regards, Akand From alan at baselinedata.co.uk Fri Nov 26 20:39:02 2010 From: alan at baselinedata.co.uk (Alan Harris-Reid) Date: Sat, 27 Nov 2010 01:39:02 +0000 Subject: SQLite date fields In-Reply-To: References: Message-ID: <4CF06136.4020400@baselinedata.co.uk> To all those who have replied on this thread - many thanks. It looks as though I've got to look further into date objects, SQLite's native date functions, detect_types, etc.. Regards, Alan From casevh at gmail.com Fri Nov 26 22:21:47 2010 From: casevh at gmail.com (casevh) Date: Fri, 26 Nov 2010 19:21:47 -0800 (PST) Subject: inverse of a matrix with Fraction entries References: <8l50ulFhb4U1@mid.individual.net> <4cf01e79$0$1592$742ec2ed@news.sonic.net> <4cf03075$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4b430ffd-8184-46ac-981d-1f25c6b4d375@w29g2000vba.googlegroups.com> On Nov 26, 2:11?pm, Steven D'Aprano wrote: > On Fri, 26 Nov 2010 12:54:12 -0800, John Nagle wrote: > > For ordinary number crunching, > > rational arithmetic is completely inappropriate. > > Why? > > -- > Steven As you perform repeated calculations with rationals, the size of the values (usually) keep growing. (Where size is measured as the length of numerator and denominator.) The speed and memory requirements are no longer constant. I coded a quick matrix inversion function and measured running times using GMPY2 rational and floating point types. For the floating point tests, I used a precision of 1000 bits. With floating point values, the running time grew as n^3. With rational values, the running time grew as n^4*ln(n). On my system, inverting a 1000x1000 matrix with 1000-bit precision floating point would take about 30 minutes. Inverting the same matrix using rationals would take a month or longer and require much more memory. But the rational solution would be exact. casevh From bloom.dax at gmail.com Fri Nov 26 23:54:06 2010 From: bloom.dax at gmail.com (Dax Bloom) Date: Fri, 26 Nov 2010 20:54:06 -0800 (PST) Subject: Using Python for a demonstration in historical linguistics References: <5a85f233-d463-4ef5-a045-342b83873b13@32g2000yqz.googlegroups.com> Message-ID: <99bd3100-0782-4e44-b8f6-4de8b23c693f@c39g2000yqi.googlegroups.com> On Nov 6, 6:41?am, Vlastimil Brom wrote: > 2010/11/6 Dax Bloom : > > > > > > > Hello, > > > In the framework of a project on evolutionary linguistics I wish to > > have a program to process words and simulate the effect of sound > > shift, for instance following the Rask's-Grimm's rule. I look to have > > python take a dictionary file or a string input and replace the > > consonants in it with the Grimm rule equivalent. For example: > > b? ? b ? p ? f > > d? ? d ? t ? ? > > g? ? g ? k ? x > > g?? ? g? ? k? ? x? > > If the dictionary file has the word "Abe" I want the program to > > replace the letter b with f forming the word "Afe" and write the > > result in a tabular file. How easy is it to find the python functions > > to do that? > > > Best regards, > > > Dax Bloom > > -- > >http://mail.python.org/mailman/listinfo/python-list > > Hi, > I guess, the most difficult part would be, to select appropriate > words, to apply the simple rules on (in order not to get "problems" > with Verner's Law or other special rules). > You also normally wouldn't want to chain the changes like the above, > but to keep them separated > b? ? b; p ? f (ie. *b?r?ter- > ... brother and not *p-... (at least > without the High German consonant shift)). > of course, there are also vowel changes to be dealt with and many more > peculiarities ... > > As for implementation, I guess, the simplest way might be to use > regular expression replacements - re.sub(...) with a replace function > looking up the appropriate results in a dictionary. > maybe something along the lines: > > ######################################## > > Rask_Grimm_re = ur"[bdgptk]??" > Rask_Grimm_dct = {u"b":u"p", u"b?": u"b", u"t": u"?", } # ... > > def repl_fn(m): > ? ? return Rask_Grimm_dct.get(m.group(), m.group()) > > ie_txt = u" b?r?ter ... " > almost_germ_txt = re.sub(Rask_Grimm_re, repl_fn, ie_txt) > print u"%s >> %s" % (ie_txt, almost_germ_txt) # vowel changes etc. TBD > > ######################################## > > ?b?r?ter ... ?>> ?br??er ... > > hth, > ? vbr Hello, Thx to every one of you for the prompt response. Resuming the thread of November 5 on evolutionary linguistics, is there a way to refer to a sub-category of text like vowels or consonants? If not, is there a way to optimize the code by creating these sub-categories? I would need to arrange substitution rules into groups because there might be a whole lot more than the ones I mentioned in the example on Rask-Grimm rule; I would like each substitution to produce a new entry and not all substitutions to result in a single entry. I want to do things in two steps (or ?passes?) and apply to the results of the group 1 of rules the rules of group 2. I understand that it could be particularly useful for the study of phonology to have a dynamic analysis system with adjustable rules; in this branch of linguistics parts of a word like the nucleus or the codas are tagged with abbreviatory notations explaining ?phonological processes? with schemas; such historical mutations of language as the metathesis, the prothesis, the anaptyxis or fusional assimilation could be included among the rules that we mentioned for the substitution. It might require the replacing of certain letters with Greek notation in applying phonological processes. What function could tag syllables, the word nucleus and the codas? How easy is it to bridge this with a more visual environment where schematic analysis can be displayed with highlights and notations such as in the phonology textbooks? To outline the goals of the program: 1) Arranging rules for substitution into groups of rules 2) Applying substitutions to string input in logic of ?Multiple pass multiple replace? 3) Returning a string for each substitution 4) Making program environment visual When quoting parts of code can you please precise where to insert them in the code and what the variables mean? Best wishes, Dax Bloom From bloom.dax at gmail.com Sat Nov 27 01:58:04 2010 From: bloom.dax at gmail.com (Dax Bloom) Date: Fri, 26 Nov 2010 22:58:04 -0800 (PST) Subject: Using Python for a demonstration in historical linguistics References: <5a85f233-d463-4ef5-a045-342b83873b13@32g2000yqz.googlegroups.com> Message-ID: On Nov 6, 6:18?am, Peter Otten <__pete... at web.de> wrote: > Peter Otten wrote: > >>>> s = """ > > ... In the framework of a project onevolutionarylinguisticsI wish to > > ... have a program to process words and simulate the effect of sound > > ... shift, for instance following the Rask's-Grimm's rule. I look to have > > ... python take a dictionary file or a string input and replace the > > ... consonants in it with the Grimm rule equivalent. For example: > > ... """ > >>>> rules = ["bpf", ("d", "t", "th"), "gkx"] > >>>> for rule in rules: > > ... ? ? rule = rule[::-1] # go back in time > > ... ? ? for i in range(len(rule)-1): > > ... ? ? ? ? ? ? s = s.replace(rule[i], rule[i+1]) > > ... > > Warning: this simple-minded approach somewhat limits the possible rules. > E. g. it fails for > > a --> b > b --> a > > >>> "abba".replace("a", "b").replace("b", "a") > > 'aaaa' > > while unicode.translate() can deal with it: > > >>> u"abba".translate({ord(u"a"): u"b", ord(u"b"): u"a"}) > > u'baab' > > Or, if you are using Python 3.x as Steven suggested: > > >>> "abba".translate({ord("a"): "b", ord("b"): "a"}) > > 'baab' > > Peter Hi Peter, I read your interesting replies 20 days ago and after several exams and a university semester, I would like to address more fully your answers to my post. However could you please clarify some of the code inputs that you suggested and in what order to insert them in the script? >>>> s = """ > > ... In the framework of a project onevolutionarylinguisticsI wish to > > ... have a program to process words and simulate the effect of sound > > ... shift, for instance following the Rask's-Grimm's rule. I look to have > > ... python take a dictionary file or a string input and replace the > > ... consonants in it with the Grimm rule equivalent. For example: > > ... """ > >>>> rules = ["bpf", ("d", "t", "th"), "gkx"] > >>>> for rule in rules: > > ... ? ? rule = rule[::-1] # go back in time > > ... ? ? for i in range(len(rule)-1): > > ... ? ? ? ? ? ? s = s.replace(rule[i], rule[i+1]) > > ... Best regards, Dax Bloom From nagle at animats.com Sat Nov 27 02:24:30 2010 From: nagle at animats.com (John Nagle) Date: Fri, 26 Nov 2010 23:24:30 -0800 Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance In-Reply-To: <87y68fwr89.fsf.mdw@metalzone.distorted.org.uk> References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> <4ceef381$0$1659$742ec2ed@news.sonic.net> <5c92a83e-9de1-4a03-828c-2cce79ce5a30@v17g2000prc.googlegroups.com> <4cf011b9$0$1619$742ec2ed@news.sonic.net> <87y68fwr89.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <4cf0b232$0$1651$742ec2ed@news.sonic.net> On 11/26/2010 4:21 PM, Mark Wooding wrote: > John Nagle writes: > >> I'd argue that a better implementation would require that when there's >> a name clash, you have to specify the class containing the name. In >> other words, if A is a subclass of B, then B.foo() overrides >> A.foo(). But if C is a subclass of A and B, and there's an A.foo() and >> a B.foo(), calling self.foo() in C should be an error, because it's >> ambiguous. You should have to specify the parent class, using "super". > > How peculiar. `super' is /specifically/ for working out dynamically > which superclass to delegate behaviour to, because working it out > statically isn't possible in general. > >> The same issue applies in the other direction. If A and B are >> subclasses of D, and A.foo() and B.foo() are defined, and D calls >> self.foo(), that's an ambiguity and should be reported. > > No it isn't. It's downward delegation, which is an essential feature of > object oriented design. > >> @This catches the case where two classed both inherit from, say >> "threading.thread", each expecting to have a private thread. > > Why on earth would anyone do such a bizarre thing? If you want a > private thread, then attach one as an attribute. Inheriting is simply > madness. This must be from someone who hasn't used threads in Python. The usual way to write a thread in Python is to subclass "threading.thread". The subclass provides a "run" function, which will be called from the new thread. > If you > stopped whining about how Python's object system might theoretically go > wrong if you try to use it like it was C++ and started thinking about > how to actually make effective use of the features it offers -- features > which long predate Python, and have been thought about over many years, > in languages such as Zetalisp, Common Lisp, Dylan, Scheme, and variants > of Smalltalk -- you might got on much better. Ah, fanboys. Of those, I've written code in Common Lisp, Scheme, and Smalltalk. Most of the LISP variants really did objects very well; objects were an afterthought. Smalltalk went a bit too far in the other direction; the "everything is an object" mindset was overdoing it. Python is reasonably well balanced in the object area. Everything isn't an object. There are explicit classes, unlike the instance-copying model of Self and Javascript. However, multiple inheritance is something of a mess, as the original starter of this thread found when he tried to document how to use it. If you have real trouble writing documentation for a feature, it's usually because the feature is badly designed. John Nagle From user at compgroups.net/ Sat Nov 27 04:00:35 2010 From: user at compgroups.net/ (TuckerTherese) Date: Sat, 27 Nov 2010 03:00:35 -0600 Subject: Newbie question about python garbage collection when keeping only a reference to an object's member References: Message-ID: Some specialists tell that
loan help people to live their own way, because they are able to feel free to buy necessary things. Moreover, various banks offer small business loan for young and old people. From rainer.mansfeld at gmail.com Sat Nov 27 04:37:52 2010 From: rainer.mansfeld at gmail.com (Rainer Mansfeld) Date: Sat, 27 Nov 2010 10:37:52 +0100 Subject: Kind of plugin system In-Reply-To: References: Message-ID: <4CF0D170.9000504@gmail.com> Am 26.11.2010 18:46, schrieb Ga??tan Podevijn: > I need to get some informations from files stored on my filesystem, Flickr > and Picasa. So the idea is to create a class (for instance, > "InformationsProvider") that provides common methods for those three > sources, then, for each source, I create a class that inherits from > "InformationsProvider" such as "InformationsLocalProvider", > "InformationsFlickrProvider" and "InformationPicasaProvider". It is clearly > needed because the method to get the informations is totally different for > each source (the connection with flickr or picasa for exemple). > > However, I'd like, in the future, to be able to add new source and thus, > just add a new class that implements the methods from Provider. The thing > is, I'd like to add only one class, and that the rest of the application is > able to use that class without really knowing how many class there are. > > I'd have something like : > for each provider that exists: get the informations file > > and if I add a new .py that implements a new provider (say Delicious of > GMail), the code above takes account of the new class. It must be "dynamic". Hello Ga?tan, if all your classes are direct descendants of InformationsProvider you might get away with looping over InformationsProvider.__subclasses__(). See http://docs.python.org/library/stdtypes.html#class.__subclasses__ Greetings Rainer From iamforufriends at gmail.com Sat Nov 27 05:24:47 2010 From: iamforufriends at gmail.com (stella(adu^lt girl 4 ad^ults only)) Date: Sat, 27 Nov 2010 02:24:47 -0800 (PST) Subject: ad^ult girl is ready for fu^ck for free... Message-ID: <73c1390e-bce0-4760-922a-6306867fed2c@u9g2000pra.googlegroups.com> ad^ult girl is ready for fu^ck for free... http://x2c.eu/5c http://x2c.eu/5c http://x2c.eu/5c http://x2c.eu/5c http://x2c.eu/5c From mdw at distorted.org.uk Sat Nov 27 06:59:17 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Sat, 27 Nov 2010 11:59:17 +0000 Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> <4ceef381$0$1659$742ec2ed@news.sonic.net> <5c92a83e-9de1-4a03-828c-2cce79ce5a30@v17g2000prc.googlegroups.com> <4cf011b9$0$1619$742ec2ed@news.sonic.net> <87y68fwr89.fsf.mdw@metalzone.distorted.org.uk> <4cf0b232$0$1651$742ec2ed@news.sonic.net> Message-ID: <87d3prvuy2.fsf.mdw@metalzone.distorted.org.uk> John Nagle writes: > On 11/26/2010 4:21 PM, Mark Wooding wrote: > > John Nagle writes: > >> @This catches the case where two classed both inherit from, say > >> "threading.thread", each expecting to have a private thread. > > > > Why on earth would anyone do such a bizarre thing? If you want a > > private thread, then attach one as an attribute. Inheriting is simply > > madness. > > This must be from someone who hasn't used threads in Python. Wrong again. > The usual way to write a thread in Python is to subclass > "threading.thread". The subclass provides a "run" function, which > will be called from the new thread. Yes, it is. Does that conflict with what I wrote? No. If you want you class to have a private thread, make /another/ class to represent the behaviour of this private thread, and attach an instance of this to the first class. Or you can pass a closure or a bound method to the thread constructor. (That's probably cleaner, actually, but doesn't fit culturally.) > > If you stopped whining about how Python's object system might > > theoretically go wrong if you try to use it like it was C++ and > > started thinking about how to actually make effective use of the > > features it offers -- features which long predate Python, and have > > been thought about over many years, in languages such as Zetalisp, > > Common Lisp, Dylan, Scheme, and variants of Smalltalk -- you might > > got on much better. > > Ah, fanboys. Not exactly. I collect programming languages like some people collect postage stamps; it gives one a useful perspective. I mentioned those languages because they seem most historically relevant. Zetalisp's `Flavors' system introduced multiple inheritance; Common Lisp and Dylan fix the linearization properly (eventually culminating in the C3 linearization algorithm); Scheme has no standardized object system, but there are a number of -- mainly CLOS-like -- object systems available; and Smalltalk is both the classic dynamic object-oriented language and a single-dispatch contrast to the CLOS/Dylan generic-functions approach. > Of those, I've written code in Common Lisp, Scheme, and Smalltalk. > Most of the LISP variants really did objects very well; objects were > an afterthought. Smalltalk went a bit too far in the other direction; > the "everything is an object" mindset was overdoing it. CLOS actually does a remarkable integration job, bringing the existing types into the object system; but, yes, the seams are still visible, because you can't subclass some of the classes. > Python is reasonably well balanced in the object area. Everything > isn't an object. There are explicit classes, unlike the > instance-copying model of Self and Javascript. Is that a major win? Self's prototype-based approach seems quite capable of expressing anything you might want to express with classes, and a few other things besides. (The implementation works by attempting to deduce class structures dynamically, so there's an isomorphism here, of a sort, but the dynamism would make inventing classes on the fly rather inconvenient.) There's a significant difference between Javascript and Self, by the way: a Self object can have multiple `parent' slots, consequently with a form of multiple inheritance, while Javascript is limited to single inheritance (unless you fake it up). > However, multiple inheritance is something of a mess, as the original > starter of this thread found when he tried to document how to use it. Python's object system certainly isn't ideal. The main problem that I see is that dynamic delegation with `super' is hideously inconvenient to use, which means that programmers will tend towards C++'s static delegation instead. The Python object construction protocol (__new__ and __init__) is somewhat simplistic; constructing instances of multiply inherited classes in general requires a somewhat complicated dance with *args and **kw arguments -- and you lose the ability to reject unknown arguments -- which again leads to programmers taking shortcuts. Most of the rest of the object system seems pretty sound to me. > If you have real trouble writing documentation for a feature, it's > usually because the feature is badly designed. It might be that it was misunderstood. There seem to be two obvious ways of learning a programming language. One is to try and interpret its concepts in terms of concepts that you already understand. This works, but you end up having to `translate' between the new language; if the translation is imperfect then you'll be confused or frustrated. There's a constant temptation to force one's existing conceptual framework onto the new language -- to use it as if it worked just like something else one is more familiar with that doesn't quite work `right'. The new language is `broken Blub with funny syntax'. The other is to try to understand it on its own terms. This is the harder road that leads to mastery. -- [mdw] From mdw at distorted.org.uk Sat Nov 27 07:00:55 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Sat, 27 Nov 2010 12:00:55 +0000 Subject: inverse of a matrix with Fraction entries References: <8l50ulFhb4U1@mid.individual.net> <4cf01e79$0$1592$742ec2ed@news.sonic.net> <4cf03075$0$29994$c3e8da3$5496439d@news.astraweb.com> <4b430ffd-8184-46ac-981d-1f25c6b4d375@w29g2000vba.googlegroups.com> Message-ID: <878w0fvuvc.fsf.mdw@metalzone.distorted.org.uk> casevh writes: > I coded a quick matrix inversion function and measured running times > using GMPY2 rational and floating point types. For the floating point > tests, I used a precision of 1000 bits. With floating point values, > the running time grew as n^3. With rational values, the running time > grew as n^4*ln(n). Did you clear the denominators before you started? -- [mdw] From see at sig.for.address Sat Nov 27 07:42:32 2010 From: see at sig.for.address (Victor Eijkhout) Date: Sat, 27 Nov 2010 07:42:32 -0500 Subject: MATLAB to Python? References: <74f276c3-38a4-4df0-af39-7b1f2a81472e@c39g2000yqi.googlegroups.com> <40274408-8ae7-4500-983c-54714cf674d6@y23g2000yqd.googlegroups.com> Message-ID: <1jslup4.cqzxe31e28j3zN%see@sig.for.address> MATLABdude wrote: > Also the > values themselves are not identical compared to the values of the > MATLAB program. In numerical analysis there is no such thing as identical. If they differ by 1.e-10 I'd call it close enough. The difference comes from differing numerical methods. Victor. -- Victor Eijkhout -- eijkhout at tacc utexas edu From Marc-Andre.Belzile at autodesk.com Sat Nov 27 08:24:58 2010 From: Marc-Andre.Belzile at autodesk.com (Marc-Andre Belzile) Date: Sat, 27 Nov 2010 13:24:58 +0000 Subject: Kind of plugin system In-Reply-To: References: Message-ID: I guess you could just define an entry-point in your source provider files that would return a specific instance of an InformationProvider class. This entry-point would be called by your main app (maybe at startup time or during an update phase). There are plenty of articles on the web about python plugins that could help you out, such as this one: http://wehart.blogspot.com/2009/01/python-plugin-frameworks.html -mab From: python-list-bounces+marc-andre.belzile=autodesk.com at python.org [mailto:python-list-bounces+marc-andre.belzile=autodesk.com at python.org] On Behalf Of Ga?tan Podevijn Sent: Friday, November 26, 2010 12:46 PM To: python-list at python.org Subject: Kind of plugin system Hello, Here is my problem. I need to get some informations from files stored on my filesystem, Flickr and Picasa. So the idea is to create a class (for instance, "InformationsProvider") that provides common methods for those three sources, then, for each source, I create a class that inherits from "InformationsProvider" such as "InformationsLocalProvider", "InformationsFlickrProvider" and "InformationPicasaProvider". It is clearly needed because the method to get the informations is totally different for each source (the connection with flickr or picasa for exemple). However, I'd like, in the future, to be able to add new source and thus, just add a new class that implements the methods from Provider. The thing is, I'd like to add only one class, and that the rest of the application is able to use that class without really knowing how many class there are. I'd have something like : for each provider that exists: get the informations file and if I add a new .py that implements a new provider (say Delicious of GMail), the code above takes account of the new class. It must be "dynamic". Could you help me with that ? I hope I was clear enough. Thanks a lot, Ga?tan From vlastimil.brom at gmail.com Sat Nov 27 08:25:05 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sat, 27 Nov 2010 14:25:05 +0100 Subject: Using Python for a demonstration in historical linguistics In-Reply-To: <7593fb0d-2f2c-4a10-9ddd-3b35684b2da3@g19g2000yqg.googlegroups.com> References: <5a85f233-d463-4ef5-a045-342b83873b13@32g2000yqz.googlegroups.com> <7593fb0d-2f2c-4a10-9ddd-3b35684b2da3@g19g2000yqg.googlegroups.com> Message-ID: 2010/11/27 Dax Bloom : > On Nov 6, 6:41?am, Vlastimil Brom wrote: >> 2010/11/6 Dax Bloom : >> ... >> Rask_Grimm_re = ur"[bdgptk]??" >> Rask_Grimm_dct = {u"b":u"p", u"b?": u"b", u"t": u"?", } # ... >> >> def repl_fn(m): >> ? ? return Rask_Grimm_dct.get(m.group(), m.group()) >> >> ie_txt = u" b?r?ter ... " >> almost_germ_txt = re.sub(Rask_Grimm_re, repl_fn, ie_txt) >> print u"%s >> %s" % (ie_txt, almost_germ_txt) # vowel changes etc. TBD >> >> ######################################## >> >> ?b?r?ter ... ?>> ?br??er ... >> >> hth, >> ? vbr > ... > Hello Vlastimil, > > Could you please explain what the variables %s and % mean and how to > implement this part of the code in a working python program? I can't > fully appreciate Peter's quote on rules > > > Best regards, > > Dax Bloom > Hi, the mentioned part is called string interpolation; the last line is equivalent to print u"%s >> %s" % (ie_txt, almost_germ_txt) # vowel changes etc. TBD is equivalent to the simple string concatenation: print ie_txt+ u" >> " + almost_germ_txt see: http://docs.python.org/library/stdtypes.html#string-formatting-operations The values of the tuple (or eventually dict or another mapping) given after the modulo operator % are inserted at the respective positions (here %s) of the preceding string (or unicode); some more advanced adjustments or conversions are also possible here, which aren't needed in this simple case. (There is also another string formatting mechanism in the newer versions of python http://docs.python.org/library/string.html#formatstrings which may be more suitable for more complex tasks.) The implementation depends on the rest of your program and the input/output of the data, you wish to have (to be able to print the output with rather non-trivial characters, you will need the unicode enabled console (Idle is a basic one available with python). Otherwise the sample is self contained and should be runnable as is; you can add other needed items to Rask_Grimm_dct and all substrings matching Rask_Grimm_re will be replaced in one pass. You can also add a series of such replacements (re pattern and a dict of a ie: germ pairs), of course only for context-free changes. On the other hand, I have no simple idea how th deal with Verner's Law and the like (even if you passed the accents in the PIE forms); well besides a lexicographic approach, where you would have to identify the word stems to decide the changes to be applied. hth, vbr From peteRE at MpeteOzilla.Vco.ukE Sat Nov 27 10:18:46 2010 From: peteRE at MpeteOzilla.Vco.ukE (Peter Chant) Date: Sat, 27 Nov 2010 15:18:46 +0000 Subject: Convert QStingList to Python list Message-ID: The following code generates a QStringList: fileNames = QFileDialog.getOpenFileNames(None,"Chose raw file",".",) Printing it: print "Files selected "+QStringList(fileNames) Results in: TypeError: cannot concatenate 'str' and 'QStringList' objects Any idea how to convert a QStingList into a python list? pythonQtConv seems to come up in google but I've no idea how to import or invoke it. Thoughts? Pete -- http://www.petezilla.co.uk From __peter__ at web.de Sat Nov 27 10:57:07 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 27 Nov 2010 16:57:07 +0100 Subject: Convert QStingList to Python list References: Message-ID: Peter Chant wrote: > The following code generates a QStringList: > > fileNames = QFileDialog.getOpenFileNames(None,"Chose raw file",".",) > > Printing it: > > print "Files selected "+QStringList(fileNames) You say that fileNames already is a QStringList. Why are you trying to convert it to a QStringList then? Anyway, it wouldn't work with a python list either. > Results in: > > TypeError: cannot concatenate 'str' and 'QStringList' objects > > Any idea how to convert a QStingList into a python list? pythonQtConv > seems to come up in google but I've no idea how to import or invoke it. > > Thoughts? Try it out yourself in the interactive interpreter. Here's a sample session: >>> files = QStringList(["alpha.txt", "beta.txt"]) >>> print files >>> print list(files) [PyQt4.QtCore.QString(u'alpha.txt'), PyQt4.QtCore.QString(u'beta.txt')] >>> print [str(f) for f in files] ['alpha.txt', 'beta.txt'] >>> print "Selected files:", ", ".join(str(f) for f in files) Selected files: alpha.txt, beta.txt >>> files = QStringList([u"???.txt", "beta.txt"]) >>> print "Selected files:", ", ".join(str(f) for f in files) Selected files: Traceback (most recent call last): File "", line 1, in File "", line 1, in UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2: ordinal not in range(128) >>> print "Selected files:", ", ".join(unicode(f) for f in files) Selected files: ???.txt, beta.txt Peter From casevh at gmail.com Sat Nov 27 11:23:19 2010 From: casevh at gmail.com (casevh) Date: Sat, 27 Nov 2010 08:23:19 -0800 (PST) Subject: inverse of a matrix with Fraction entries References: <8l50ulFhb4U1@mid.individual.net> <4cf01e79$0$1592$742ec2ed@news.sonic.net> <4cf03075$0$29994$c3e8da3$5496439d@news.astraweb.com> <4b430ffd-8184-46ac-981d-1f25c6b4d375@w29g2000vba.googlegroups.com> <878w0fvuvc.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On Nov 27, 4:00?am, m... at distorted.org.uk (Mark Wooding) wrote: > casevh writes: > > I coded a quick matrix inversion function and measured running times > > using GMPY2 rational and floating point types. For the floating point > > tests, I used a precision of 1000 bits. With floating point values, > > the running time grew as n^3. With rational values, the running time > > grew as n^4*ln(n). > > Did you clear the denominators before you started? > > -- [mdw] No. It more of an exercise in illustrating the difference between arithmetic operations that have a constant running time versus those that have an n*ln(n) or worse running time. casevh From REMpeteOVE at petezilla.co.uk Sat Nov 27 11:38:51 2010 From: REMpeteOVE at petezilla.co.uk (Peter Chant) Date: Sat, 27 Nov 2010 16:38:51 +0000 Subject: Convert QStingList to Python list References: Message-ID: <8lcqimFubmU1@mid.individual.net> Peter Otten wrote: > > Try it out yourself in the interactive interpreter. Here's a sample > session: > Peter, thanks. I've got some way to go with python and have only just started looking at Qt, your help has been very useful. Pete -- http://www.petezilla.co.uk From raffaelcavallaro at pas.despam.s.il.vous.plait.mac.com Sat Nov 27 11:51:33 2010 From: raffaelcavallaro at pas.despam.s.il.vous.plait.mac.com (Raffael Cavallaro) Date: Sat, 27 Nov 2010 11:51:33 -0500 Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014020136.6e85d70b@tritium.streitmacht.eu> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> <08823dd4-588a-4729-a660-711e266c96b0@y23g2000yqd.googlegroups.com> <396f8de7-ece5-4e9c-919b-886eb65ae14a@a30g2000vbt.googlegroups.com> <967678a1-fc5d-4b61-86c5-79a298999582@p1g2000vbo.googlegroups.com> <18cd9337-736b-427c-9cac-14c99056750a@p1g2000yqm.googlegroups.com> <87vd3l8iy3.fsf@padme.localdomain> Message-ID: On 2010-11-25 11:30:12 -0500, Mario S. Mommer said: > In the realm of pure logic, ad hominems are logically invalid, > period. We don't live in the realm of pure logic (whatever that would mean - pretty sure no human beings exist in the realm of pure logic, so there is no homo hominis to make an ad hominem argument against in the land of pure logic...) Here in the real world, no amount of the rigid application of pure logic is going to substitute for the very necessary social skill of inferring the motives of a participant to a debate. Again, not all ad hominem arguments are ad hominem fallacies. JH has repeatedly trumpeted the virtues of languages whose adoption by others brings him financial gain, and repeatedly made pejorative statements about other languages in newsgroups for these other langauges, in a clear attempt to drum up clients for his training consultancy. Pure logic alone won't help you here; the ordinary human social skill of inferring a person's motives does. warmest regards, Ralph -- Raffael Cavallaro From anurag.chourasia at gmail.com Sat Nov 27 13:43:46 2010 From: anurag.chourasia at gmail.com (Anurag Chourasia) Date: Sun, 28 Nov 2010 00:13:46 +0530 Subject: AIX 5.3 - Enabling Shared Library Support Vs Extensions In-Reply-To: <20101125101117.GA3437@yoda.bytereef.org> References: <20101125101117.GA3437@yoda.bytereef.org> Message-ID: Hi Stefan, I followed your suggestion and configured LDFLAGS but the make step fails for another error now. My configuration options are as follows ./configure --enable-shared --disable-ipv6 --with-gcc=gcc CPPFLAGS="-I /opt/freeware/include -I /opt/freeware/include/readline -I /opt/freeware/include/ncurses" LDFLAGS="-L. -L/usr/local/lib" Below is the transcript from the make step. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ running build running build_ext ldd: /lib/libreadline.a: File is an archive. INFO: Can't locate Tcl/Tk libs and/or headers building '_struct' extension gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I. -I/u01/home/apli/wm/GDD/Python-2.6.6/./Include -I. -IInclude -I./Include -I/opt/freeware/include -I/opt/freeware/include/readline -I/opt/freeware/include/ncurses -I/usr/local/include -I/u01/home/apli/wm/GDD/Python-2.6.6/Include -I/u01/home/apli/wm/GDD/Python-2.6.6 -c /u01/home/apli/wm/GDD/Python-2.6.6/Modules/_struct.c -o build/temp.aix-5.3-2.6/u01/home/apli/wm/GDD/Python-2.6.6/Modules/_struct.o ./Modules/ld_so_aix gcc -pthread -bI:Modules/python.exp -L. -L/usr/local/lib build/temp.aix-5.3-2.6/u01/home/apli/wm/GDD/Python-2.6.6/Modules/_struct.o -L. -L/usr/local/lib -lpython2.6 -o build/lib.aix-5.3-2.6/_struct.so *Fatal Python error: Interpreter not initialized (version mismatch?)* *make: 1254-059 The signal code from the last command is 6.* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ The last command that i see above (ld_so_aix) seems to have completed as the file _struct.so exists after this command and hence I am not sure which step is failing. There is no other Python version on my machine. Please guide. On Thu, Nov 25, 2010 at 3:41 PM, Stefan Krah wrote: > Anurag Chourasia wrote: > > When I configure python to enable shared libraries, none of the > extensions are getting built during the make step due to this error. > > > > building 'cStringIO' extension > > gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall > > -Wstrict-prototypes -I. -I/u01/home/apli/wm/GDD/Python-2.6.6/./Include > -I. > > -IInclude -I./Include -I/opt/freeware/include > > -I/opt/freeware/include/readline -I/opt/freeware/include/ncurses > > -I/usr/local/include -I/u01/home/apli/wm/GDD/Python-2.6.6/Include > > -I/u01/home/apli/wm/GDD/Python-2.6.6 -c > > /u01/home/apli/wm/GDD/Python-2.6.6/Modules/cStringIO.c -o > > > build/temp.aix-5.3-2.6/u01/home/apli/wm/GDD/Python-2.6.6/Modules/cStringIO.o > > ./Modules/ld_so_aix gcc -pthread -bI:Modules/python.exp > > > build/temp.aix-5.3-2.6/u01/home/apli/wm/GDD/Python-2.6.6/Modules/cStringIO.o > > -L/usr/local/lib *-lpython2.6* -o build/lib.aix-5.3-2.6/cStringIO.so > ^^^^^^^^^^^^^^^^ > > Try these flags: -L. -L/usr/local/lib > > > If this solves the problem and the issue is also present in Python-2.7, > you should report a bug at http://bugs.python.org/ . > > > Stefan Krah > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From anurag.chourasia at gmail.com Sat Nov 27 13:45:44 2010 From: anurag.chourasia at gmail.com (Anurag Chourasia) Date: Sun, 28 Nov 2010 00:15:44 +0530 Subject: Python make fails with error "Fatal Python error: Interpreter not initialized (version mismatch?)" Message-ID: Hi All, During the make step of python, I am encountering a weird error. This is on AIX 5.3 using gcc as the compiler. My configuration options are as follows ./configure --enable-shared --disable-ipv6 --with-gcc=gcc CPPFLAGS="-I /opt/freeware/include -I /opt/freeware/include/readline -I /opt/freeware/include/ncurses" LDFLAGS="-L. -L/usr/local/lib" Below is the transcript from the make step. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ running build running build_ext ldd: /lib/libreadline.a: File is an archive. INFO: Can't locate Tcl/Tk libs and/or headers building '_struct' extension gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I. -I/u01/home/apli/wm/GDD/Python-2.6.6/./Include -I. -IInclude -I./Include -I/opt/freeware/include -I/opt/freeware/include/readline -I/opt/freeware/include/ncurses -I/usr/local/include -I/u01/home/apli/wm/GDD/Python-2.6.6/Include -I/u01/home/apli/wm/GDD/Python-2.6.6 -c /u01/home/apli/wm/GDD/Python-2.6.6/Modules/_struct.c -o build/temp.aix-5.3-2.6/u01/home/apli/wm/GDD/Python-2.6.6/Modules/_struct.o ./Modules/ld_so_aix gcc -pthread -bI:Modules/python.exp -L. -L/usr/local/lib build/temp.aix-5.3-2.6/u01/home/apli/wm/GDD/Python-2.6.6/Modules/_struct.o -L. -L/usr/local/lib -lpython2.6 -o build/lib.aix-5.3-2.6/_struct.so *Fatal Python error: Interpreter not initialized (version mismatch?)* *make: 1254-059 The signal code from the last command is 6.* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ The last command that i see above (ld_so_aix) seems to have completed as the file _struct.so exists after this command and hence I am not sure which step is failing. There is no other Python version on my machine. Please guide. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rambiusparkisanius at gmail.com Sat Nov 27 16:07:11 2010 From: rambiusparkisanius at gmail.com (rambius) Date: Sat, 27 Nov 2010 13:07:11 -0800 (PST) Subject: What's wrong with my logging configuration Message-ID: <48ac93bb-c16e-45b6-be3c-c68fb5d60cb0@t35g2000yqj.googlegroups.com> Hello, I am using python logging and as of today it stopped working. Here is my program: #!/usr/bin/env python import base64 import getpass import httplib import logging import logging.config import sys import urlparse logging.config.fileConfig('logging.config') logger = logging.getLogger(sys.argv[0]) def main(): from optparse import OptionParser usage = '%prog -u [options] ' parser = OptionParser(usage=usage) parser.add_option('-u', '--user', help='The user that will be authenticated') (options, args) = parser.parse_args() if len(args) != 1: logger.error('Please provide a url') sys.exit(1) url = args[0] if not options.user: logger.error('Please provide a user') sys.exit(2) password = getpass.getpass('Password: ') if __name__ == '__main__': main() Here is my logging.config: [loggers] keys=root [handlers] keys=console,file [formatters] keys=consolefmt,filefmt [formatter_consolefmt] format=%(name)-12s: %(levelname)-8s %(message)s class=logging.Formatter [formatter_filefmt] format=%(asctime)s %(name)-12s %(levelname)-8s %(message)s datefmt=%d/%m/%Y %H:%M:%S [handler_console] class=StreamHandler level=INFO formatter=consolefmt args=(sys.stdout,) [handler_file] class=FileHandler level=DEBUG formatter=filefmt args=('dav.log', 'a') [logger_root] level=NOTSET handlers=console,file Yesterday, it was working and I have not touched it - logging has been working for months. This morning it stopped working and I was debugging it for half a day and I am clueless. It does not the errors neither on the console nor in the log file. I will appreciate any help! Thank you in advance! Regards Rambius From rambiusparkisanius at gmail.com Sat Nov 27 16:11:55 2010 From: rambiusparkisanius at gmail.com (rambius) Date: Sat, 27 Nov 2010 13:11:55 -0800 (PST) Subject: What's wrong with my logging configuration References: <48ac93bb-c16e-45b6-be3c-c68fb5d60cb0@t35g2000yqj.googlegroups.com> Message-ID: On Nov 27, 4:07?pm, rambius wrote: > Hello, > > I am using python logging and as of today it stopped working. Here is > my program: > .... I forgot to give my environment: $ uname -a Darwin arielmac.lan 10.5.0 Darwin Kernel Version 10.5.0: Fri Nov 5 23:20:39 PDT 2010; root:xnu-1504.9.17~1/RELEASE_I386 i386 $ python -V Python 2.6.6 Regards Rambius From rambiusparkisanius at gmail.com Sat Nov 27 17:00:41 2010 From: rambiusparkisanius at gmail.com (rambius) Date: Sat, 27 Nov 2010 14:00:41 -0800 (PST) Subject: What's wrong with my logging configuration References: <48ac93bb-c16e-45b6-be3c-c68fb5d60cb0@t35g2000yqj.googlegroups.com> Message-ID: <067121ce-5ce3-480f-9d25-3cd20ac4fb26@r29g2000yqj.googlegroups.com> Hello, I was able to reproduce the problem with even a smaller program: #!/usr/bin/env python import logging import logging.config logging.config.fileConfig('logging.config') logger = logging.getLogger('test') def main(): logger.fatal('test1') import optparse logger.fatal('test2') if __name__ == '__main__': main() When I run this program the logger statement after 'import optparse' does not appear. The first logger statement before optparse does appear. Has anyone experienced similar behaviour? Regards Rambius From ben+python at benfinney.id.au Sat Nov 27 17:09:40 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 28 Nov 2010 09:09:40 +1100 Subject: What's wrong with my logging configuration References: <48ac93bb-c16e-45b6-be3c-c68fb5d60cb0@t35g2000yqj.googlegroups.com> <067121ce-5ce3-480f-9d25-3cd20ac4fb26@r29g2000yqj.googlegroups.com> Message-ID: <8739qm7717.fsf@benfinney.id.au> rambius writes: > When I run this program the logger statement after 'import optparse' > does not appear. The first logger statement before optparse does > appear. Has anyone experienced similar behaviour? I use the same config file (from your first message) and your shorter program, and I see this output: ===== test : CRITICAL test1 test : CRITICAL test2 ===== -- \ ?I have a large seashell collection, which I keep scattered on | `\ the beaches all over the world. Maybe you've seen it.? ?Steven | _o__) Wright | Ben Finney From rambiusparkisanius at gmail.com Sat Nov 27 17:25:32 2010 From: rambiusparkisanius at gmail.com (rambius) Date: Sat, 27 Nov 2010 14:25:32 -0800 (PST) Subject: What's wrong with my logging configuration References: <48ac93bb-c16e-45b6-be3c-c68fb5d60cb0@t35g2000yqj.googlegroups.com> <067121ce-5ce3-480f-9d25-3cd20ac4fb26@r29g2000yqj.googlegroups.com> <8739qm7717.fsf@benfinney.id.au> Message-ID: Hello Ben, On what environment did you try it? On Nov 27, 5:09?pm, Ben Finney wrote: > rambius writes: > > When I run this program the logger statement after 'import optparse' > > does not appear. The first logger statement before optparse does > > appear. Has anyone experienced similar behaviour? > > I use the same config file (from your first message) and your shorter > program, and I see this output: > > ===== > test ? ? ? ?: CRITICAL test1 > test ? ? ? ?: CRITICAL test2 > ===== > This is so strange. If I import optparse outside of main() it works. If I import it between the two logging statement, the second one does not appear. Regards Rambius From steve+comp.lang.python at pearwood.info Sat Nov 27 17:34:59 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 Nov 2010 22:34:59 GMT Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> <4ceef381$0$1659$742ec2ed@news.sonic.net> <5c92a83e-9de1-4a03-828c-2cce79ce5a30@v17g2000prc.googlegroups.com> <4cf011b9$0$1619$742ec2ed@news.sonic.net> <87y68fwr89.fsf.mdw@metalzone.distorted.org.uk> <4cf0b232$0$1651$742ec2ed@news.sonic.net> Message-ID: <4cf18792$0$29997$c3e8da3$5496439d@news.astraweb.com> On Fri, 26 Nov 2010 23:24:30 -0800, John Nagle wrote: > On 11/26/2010 4:21 PM, Mark Wooding wrote: [...] >>> @This catches the case where two classed both inherit from, say >>> "threading.thread", each expecting to have a private thread. >> >> Why on earth would anyone do such a bizarre thing? If you want a >> private thread, then attach one as an attribute. Inheriting is simply >> madness. > > This must be from someone who hasn't used threads in Python. > > The usual way to write a thread in Python is to subclass > "threading.thread". The subclass provides a "run" function, which will > be called from the new thread. Wanting a private thread, and writing a thread, are not the same. Of course you have to subclass threading.thread to write a thread. But if you want a private thread, there's no need to subclass thread just to get one. You would add a thread as an attribute, exactly as you would add a list or a dict or an int as an attribute if you wanted a private list or dict or int. Trying to juggle access from *multiple* classes to a *private* thread doesn't seem sensible, which was Mark's point. >> If you >> stopped whining about how Python's object system might theoretically go >> wrong if you try to use it like it was C++ and started thinking about >> how to actually make effective use of the features it offers -- >> features which long predate Python, and have been thought about over >> many years, in languages such as Zetalisp, Common Lisp, Dylan, Scheme, >> and variants of Smalltalk -- you might got on much better. > > Ah, fanboys. > > Of those, I've written code in Common Lisp, Scheme, and Smalltalk. > Most of the LISP variants really did objects very well; objects were an > afterthought. Describing something as an afterthought is normally meant as a pejorative. To say that Lisp "really did objects very well" *and* that they were afterthoughts seems like a contradiction. > Smalltalk went a bit too far in the other direction; the > "everything is an object" mindset was overdoing it. > > Python is reasonably well balanced in the object area. > Everything isn't an object. I don't understand what you mean by this. Can you give an example of a thing in Python that is not an object? > There are explicit classes, unlike the > instance-copying model of Self and Javascript. However, multiple > inheritance is something of a mess, as the original starter of this > thread found when he tried to document how to use it. > > If you have real trouble writing documentation for a feature, it's > usually because the feature is badly designed. The problem isn't writing documentation for the feature, but coming up with real-world use-cases. The documentation for super and the MRO is extensive and detailed. It's also complicated, because multiple inheritance is complicated. But it seems that multiple inheritance might not be that useful outside of a small number of cases. -- Steven From robert.kern at gmail.com Sat Nov 27 17:38:46 2010 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 27 Nov 2010 16:38:46 -0600 Subject: Matlab equivalent syntax in Python In-Reply-To: <42086c34-43bd-44d8-a1e3-f220f62826b0@g19g2000yqg.googlegroups.com> References: <99f8ef31-646e-4e9c-912d-e607389d5191@r31g2000prg.googlegroups.com> <42086c34-43bd-44d8-a1e3-f220f62826b0@g19g2000yqg.googlegroups.com> Message-ID: On 2010-11-26 18:23 , Akand Islam wrote: > On Nov 26, 3:50 pm, Cameron Simpson wrote: >> On 26Nov2010 13:15, Akand Islam wrote: >> | Thanks for your posting. Like, here is the following Matlab codes >> | which I am trying to transform into Python. Here you >> | will find "profile clear, profile on, profile off, profile resume, >> | profile viewer, and drawnow" syntaxes. So, what will be these >> | equivalents >> | in Python? >> >> I would start by looking at the "profile" python module: >> >> http://docs.python.org/library/profile.html#module-profile >> >> Cheers, >> -- >> Cameron Simpson DoD#743http://www.cskk.ezoshosting.com/cs/ >> >> Their are thre mistakes in this sentence. >> - Rob Ray DoD#33333 > > Dear Cameron Simpson, > Thanks for co-operation. I have gone through the link, however, I am > not much clear. Can you please show me some python syntaxes which > contain Matlab like "profile on.., drawnow.." and so forth? Perhaps you could explain what those MATLAB commands do. Not everyone here is familiar with MATLAB. For the most part, an API like "profile on; profile off" is inappropriate for the "profile" Python module. It profiles the times each function call takes, not each line. Turning it on and off doesn't make much sense. The API described in the above link is better for what it does. If you want to visualize the profile, you may want to try RunSnakeRun: http://www.vrplumber.com/programming/runsnakerun/ If you want line-by-line profiling, you may want to check out my package, line_profiler: http://pypi.python.org/pypi/line_profiler/ Again, we don't turn it on and off like you might do in MATLAB. Just follow the directions and give up trying to find a correspondence with the MATLAB commands. -- 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 macroasm at gmail.com Sat Nov 27 17:51:48 2010 From: macroasm at gmail.com (macroasm) Date: Sat, 27 Nov 2010 14:51:48 -0800 (PST) Subject: google group api with python Message-ID: <85a3bbf0-041f-4d67-b524-8d9db8327484@j25g2000yqa.googlegroups.com> hi. i want google group with send python. how do user api. From no.email at please.post Sat Nov 27 17:55:10 2010 From: no.email at please.post (kj) Date: Sat, 27 Nov 2010 22:55:10 +0000 (UTC) Subject: Comparing floats Message-ID: I'm defining a class (Spam) of objects that are characterized by three parameters, A, B, C, where A and C are n-tuples of floats and B is an n*n tuple-of-tuples of floats. I'm defining a limited multiplication for these objects, like this: Spam(A, B, C) * Spam(D, E, F) = Spam(A, dot(B, E), F) if and only if C == D. (Here dot(B, E) represents the matrix multiplication of B and E). In other words, this multiplication is defined only for the case where the last parameter of the first object is equal to first parameter of the second object. An exception should be thrown if one attempts to multiply two objects that fail to meet this requirement. Therefore, to implement this multiplication operation I need to have a way to verify that the float tuples C and D are "equal". Certainly, I want to do this in in a way that takes into account the fact machine computations with floats can produce small differences between numbers that are notionally the same. E.g. (in Python 2.6.1 at least): >>> 49.0 * (1.0/49.0) 0.99999999999999989 >>> 1.0 == 49.0 * (1.0/49.0) False The only approach I know of is to pick some arbitrary tolerance epsilon (e.g. 1e-6) and declare floats x and y equal iff the absolute value of x - y is less than epsilon. Does the Python standard library provide any better methods for performing such comparisons? I understand that, in Python 2.7 and 3.x >= 3.1, when the interactive shell displays a float it shows "the shortest decimal fraction that rounds correctly back to the true binary value". Is there a way to access this rounding functionality from code that must be able to run under version 2.6? (The idea would be to implement float comparison as a comparison of the rounded versions of floats.) Absent these possibilities, does Python provide any standard value of epsilon for this purpose? TIA! ~kj From steve+comp.lang.python at pearwood.info Sat Nov 27 18:08:02 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 Nov 2010 23:08:02 GMT Subject: inverse of a matrix with Fraction entries References: <8l50ulFhb4U1@mid.individual.net> <4cf01e79$0$1592$742ec2ed@news.sonic.net> <4cf03075$0$29994$c3e8da3$5496439d@news.astraweb.com> <4b430ffd-8184-46ac-981d-1f25c6b4d375@w29g2000vba.googlegroups.com> Message-ID: <4cf18f52$0$29997$c3e8da3$5496439d@news.astraweb.com> On Fri, 26 Nov 2010 19:21:47 -0800, casevh wrote: > On Nov 26, 2:11?pm, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> On Fri, 26 Nov 2010 12:54:12 -0800, John Nagle wrote: >> > For ordinary number crunching, >> > rational arithmetic is completely inappropriate. >> >> Why? >> >> -- >> Steven > As you perform repeated calculations with rationals, the size of the > values (usually) keep growing. (Where size is measured as the length of > numerator and denominator.) The speed and memory requirements are no > longer constant. You're not comparing apples with apples. You're comparing arbitrary precision calculations with fixed precision calculations. If you want fixed memory requirements, you should use fixed-precision rationals. Most rationals I know of have a method for limiting the denominator to a maximum value (even if not necessarily convenient). On the other hand, if you want infinite precision, there are floating point implementations that offer that too. How well do you think they perform relative to rationals? (Hint: what are the memory requirements for an infinite precision binary float equal to fraction(1, 3)? *wink*) Forth originally didn't offer floats, because there is nothing you can do with floats that can't be done slightly less conveniently but more accurately with a pair of integers treated as a rational. Floats, after all, *are* rationals, where the denominator is implied rather than explicit. I suspect that if rational arithmetic had been given half the attention that floating point arithmetic has been given, most of the performance difficulties would be significantly reduced. Perhaps not entirely eliminated, but I would expect that for a fixed precision calculation, we should have equivalent big-Oh behaviour, differing on the multiplicative factors. In any case, the real lesson of your benchmark is that infinite precision is quite costly, no matter how you implement it :) -- Steven From tjreedy at udel.edu Sat Nov 27 18:23:48 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 27 Nov 2010 18:23:48 -0500 Subject: Comparing floats In-Reply-To: References: Message-ID: On 11/27/2010 5:55 PM, kj wrote: > Therefore, to implement this multiplication operation I need to > have a way to verify that the float tuples C and D are "equal". I might try the average relative difference: sum(abs((i-j)/(i+j)) for i,j in zip(C,D))/n # assuming lengths constant > Certainly, I want to do this in in a way that takes into account > the fact machine computations with floats can produce small > differences between numbers that are notionally the same. The problem is that the appropriate value may depend on the application and the source of the floats. If they are measured to 3 decimal places, you need a large value. If they are calculated, you need much smaller. -- Terry Jan Reedy From rambiusparkisanius at gmail.com Sat Nov 27 18:33:24 2010 From: rambiusparkisanius at gmail.com (rambius) Date: Sat, 27 Nov 2010 15:33:24 -0800 (PST) Subject: What's wrong with my logging configuration References: <48ac93bb-c16e-45b6-be3c-c68fb5d60cb0@t35g2000yqj.googlegroups.com> <067121ce-5ce3-480f-9d25-3cd20ac4fb26@r29g2000yqj.googlegroups.com> <8739qm7717.fsf@benfinney.id.au> Message-ID: <8597a2f5-1c74-4799-b613-89656211cfed@f20g2000yqi.googlegroups.com> Hello, I found the culprit. Yesterday I added a file called copy.py. It clashed with the python built-in module copy and caused that nasty error. Regards Rambius From casevh at gmail.com Sat Nov 27 18:44:38 2010 From: casevh at gmail.com (casevh) Date: Sat, 27 Nov 2010 15:44:38 -0800 (PST) Subject: inverse of a matrix with Fraction entries References: <8l50ulFhb4U1@mid.individual.net> <4cf01e79$0$1592$742ec2ed@news.sonic.net> <4cf03075$0$29994$c3e8da3$5496439d@news.astraweb.com> <4b430ffd-8184-46ac-981d-1f25c6b4d375@w29g2000vba.googlegroups.com> <4cf18f52$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Nov 27, 3:08?pm, Steven D'Aprano wrote: > On Fri, 26 Nov 2010 19:21:47 -0800, casevh wrote: > > On Nov 26, 2:11?pm, Steven D'Aprano > +comp.lang.pyt... at pearwood.info> wrote: > >> On Fri, 26 Nov 2010 12:54:12 -0800, John Nagle wrote: > >> > For ordinary number crunching, > >> > rational arithmetic is completely inappropriate. > > >> Why? > > >> -- > >> Steven > > As you perform repeated calculations with rationals, the size of the > > values (usually) keep growing. (Where size is measured as the length of > > numerator and denominator.) The speed and memory requirements are no > > longer constant. > > You're not comparing apples with apples. You're comparing arbitrary > precision calculations with fixed precision calculations. If you want > fixed memory requirements, you should use fixed-precision rationals. Most > rationals I know of have a method for limiting the denominator to a > maximum value (even if not necessarily convenient). > > On the other hand, if you want infinite precision, there are floating > point implementations that offer that too. How well do you think they > perform relative to rationals? (Hint: what are the memory requirements > for an infinite precision binary float equal to fraction(1, 3)? *wink*) > > Forth originally didn't offer floats, because there is nothing you can do > with floats that can't be done slightly less conveniently but more > accurately with a pair of integers treated as a rational. Floats, after > all, *are* rationals, where the denominator is implied rather than > explicit. > > I suspect that if rational arithmetic had been given half the attention > that floating point arithmetic has been given, most of the performance > difficulties would be significantly reduced. Perhaps not entirely > eliminated, but I would expect that for a fixed precision calculation, we > should have equivalent big-Oh behaviour, differing on the multiplicative > factors. > > In any case, the real lesson of your benchmark is that infinite precision > is quite costly, no matter how you implement it :) > > -- > Steven I think most users are expecting infinite precision when they use rationals. Trying to explain limited precision rational arithmetic might be interesting. Knuth described "floating-slash" arithmetic that used a fixed number of bits for both the numerator and denominator and a rounding algorithm that prefers "simple" fractions versus more complex fractions. IIRC, the original paper was from the 1960s. casevh From arnodel at gmail.com Sat Nov 27 19:09:59 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Sun, 28 Nov 2010 00:09:59 +0000 Subject: Comparing floats References: Message-ID: <87d3pqtijs.fsf@gmail.com> Terry Reedy writes: > On 11/27/2010 5:55 PM, kj wrote: > >> Therefore, to implement this multiplication operation I need to >> have a way to verify that the float tuples C and D are "equal". > > I might try the average relative difference: > sum(abs((i-j)/(i+j)) for i,j in zip(C,D))/n # assuming lengths constant That'll throw an exception if i == -j. You could replace (i+j) with math.hypot(i, j) or abs(i)+abs(j) but it will still fail when i == j == 0. -- Arnaud From steve+comp.lang.python at pearwood.info Sat Nov 27 19:56:48 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 Nov 2010 00:56:48 GMT Subject: inverse of a matrix with Fraction entries References: <8l50ulFhb4U1@mid.individual.net> <4cf01e79$0$1592$742ec2ed@news.sonic.net> <4cf03075$0$29994$c3e8da3$5496439d@news.astraweb.com> <4b430ffd-8184-46ac-981d-1f25c6b4d375@w29g2000vba.googlegroups.com> <4cf18f52$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4cf1a8cf$0$29972$c3e8da3$5496439d@news.astraweb.com> On Sat, 27 Nov 2010 15:44:38 -0800, casevh wrote: > I think most users are expecting infinite precision when they use > rationals. Trying to explain limited precision rational arithmetic might > be interesting. Most users are expecting infinite precision decimals when they use floats, and get surprised and dismayed by things like these: >>> sum([0.1]*10) == 1 False >>> 0.1 + 1e50 + 0.1 - 1e50 0.0 >>> a, b, c = 0.1, 0.7, 0.3 >>> a*b + a*c == a*(b+c) False Trying to explain arithmetic on computers is interesting, no matter what you use. -- Steven From ben+python at benfinney.id.au Sat Nov 27 19:59:50 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 28 Nov 2010 11:59:50 +1100 Subject: What's wrong with my logging configuration References: <48ac93bb-c16e-45b6-be3c-c68fb5d60cb0@t35g2000yqj.googlegroups.com> <067121ce-5ce3-480f-9d25-3cd20ac4fb26@r29g2000yqj.googlegroups.com> <8739qm7717.fsf@benfinney.id.au> Message-ID: <87y68e5kl5.fsf@benfinney.id.au> rambius writes: > On what environment did you try it? I get the same results with both Python 2 and Python 3 on GNU+Linux: ===== $ python Python 2.6.6 (r266:84292, Oct 9 2010, 13:53:14) [?] $ python3 Python 3.1.3rc1 (r313rc1:86453, Nov 14 2010, 05:49:40) [?] ===== > This is so strange. If I import optparse outside of main() it works. > If I import it between the two logging statement, the second one does > not appear. Troubleshooting questions: Is there a rogue module in your project tree that, by being named the same as one of the standard library modules, shadows that module? Does the same problem behaviour occur if you import some other module in place of ?optparse?? Can you reduce the content of your ?logging.config? and still see the same problem behaviour (i.e. do you really have the minimum complete example yet)? What is the minimal config file that still results in the same behaviour for you? -- \ ?Welchen Teil von ?Gestalt? verstehen Sie nicht? [What part of | `\ ?gestalt? don't you understand?]? ?Karsten M. Self | _o__) | Ben Finney From ben+python at benfinney.id.au Sat Nov 27 20:13:40 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 28 Nov 2010 12:13:40 +1100 Subject: What's wrong with my logging configuration References: <48ac93bb-c16e-45b6-be3c-c68fb5d60cb0@t35g2000yqj.googlegroups.com> <067121ce-5ce3-480f-9d25-3cd20ac4fb26@r29g2000yqj.googlegroups.com> <8739qm7717.fsf@benfinney.id.au> <8597a2f5-1c74-4799-b613-89656211cfed@f20g2000yqi.googlegroups.com> Message-ID: <87tyj25jy3.fsf@benfinney.id.au> rambius writes: > I found the culprit. Yesterday I added a file called copy.py. It > clashed with the python built-in module copy and caused that nasty > error. You may be glad to know that newer versions of Python can distinguish absolute imports from relative imports, to address this very problem . -- \ ?I don't accept the currently fashionable assertion that any | `\ view is automatically as worthy of respect as any equal and | _o__) opposite view.? ?Douglas Adams | Ben Finney From steve+comp.lang.python at pearwood.info Sat Nov 27 20:19:31 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 Nov 2010 01:19:31 GMT Subject: Comparing floats References: Message-ID: <4cf1ae22$0$29997$c3e8da3$5496439d@news.astraweb.com> On Sat, 27 Nov 2010 22:55:10 +0000, kj wrote: [...] > Therefore, to implement this multiplication operation I need to have a > way to verify that the float tuples C and D are "equal". That C and D are tuples of floats is irrelevant. The problem boils down to testing floats for equality. It's easy to test two floats for equality, that's exactly what == does, but two floats which should be equal might not be due to calculation errors. To work around this, we loosen the definition of "equal" to give some allowance for rounding errors. Unfortunately, you need to decide what you mean by "two floats are equal", since that will depend on the semantics of your problem and data. There is no standard answer that applies everywhere. I suggest you leave it up to the user to decide what tolerance their data can support, and offer a sensible default for cases that they don't know or don't care. This might be useful for you, or at least give you some ideas: http://code.activestate.com/recipes/577124-approximately-equal/ [...] > The only approach I know of is to pick some arbitrary tolerance epsilon > (e.g. 1e-6) and declare floats x and y equal iff the absolute value of x > - y is less than epsilon. The four basic approaches are: (1) Is the absolute difference between the values <= some tolerance? (2) Is the relative difference between the values <= some tolerance? (3) Round the two values to a fixed number of decimal places, then compare for equality. This is a variation on (1) above. (4) How many differences in the least significant bits of the two values do we accept? > I understand that, in Python 2.7 and 3.x >= 3.1, when the interactive > shell displays a float it shows "the shortest decimal fraction that > rounds correctly back to the true binary value". Is there a way to > access this rounding functionality from code that must be able to run > under version 2.6? (The idea would be to implement float comparison as a > comparison of the rounded versions of floats.) How do you expect to access code in the Python 2.7 interpreter from Python 2.6? If you have 2.7 available, just use 2.7 :) It is a standard, royalty-free algorithm that you can find on the Internet somewhere. Worst case, you could copy it from the Python 2.7 source code, re-write it in Python if need be, and distribute it in your own application. But I don't think it will help you, since it isn't dealing with the fundamental problem that: * equality between two floats is well-defined, but not useful * equality given some tolerance is useful, but not well-defined (there is no tolerance that is always best, and there is no general way to decide whether absolute or relative error is more important) -- Steven From steve at holdenweb.com Sat Nov 27 21:13:24 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 27 Nov 2010 20:13:24 -0600 Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance In-Reply-To: <4cf18792$0$29997$c3e8da3$5496439d@news.astraweb.com> References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> <4ceef381$0$1659$742ec2ed@news.sonic.net> <5c92a83e-9de1-4a03-828c-2cce79ce5a30@v17g2000prc.googlegroups.com> <4cf011b9$0$1619$742ec2ed@news.sonic.net> <87y68fwr89.fsf.mdw@metalzone.distorted.org.uk> <4cf0b232$0$1651$742ec2ed@news.sonic.net> <4cf18792$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 11/27/2010 4:34 PM, Steven D'Aprano wrote: [...] > The problem isn't writing documentation for the feature, but coming up > with real-world use-cases. The documentation for super and the MRO is > extensive and detailed. It's also complicated, because multiple > inheritance is complicated. But it seems that multiple inheritance might > not be that useful outside of a small number of cases. It isn't. Even inheritance itself isn't as useful as it at first appears, and composition turns out in practice to be much more useful. That goes double for multiple inheritance. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From vithyam6 at gmail.com Sat Nov 27 21:44:55 2010 From: vithyam6 at gmail.com (cinema) Date: Sat, 27 Nov 2010 18:44:55 -0800 (PST) Subject: ANJELINA JOLIE - KATE WINSLET HOT PICTURES AND PROFILES HERE Message-ID: http://www.cinemaulagam.org http://www.cinemaulagam.org http://www.cinemaulagam.org http://www.cinemaulagam.org http://www.cinemaulagam.org From sohel807 at gmail.com Sat Nov 27 22:10:10 2010 From: sohel807 at gmail.com (Akand Islam) Date: Sat, 27 Nov 2010 19:10:10 -0800 (PST) Subject: Matlab equivalent syntax in Python References: <99f8ef31-646e-4e9c-912d-e607389d5191@r31g2000prg.googlegroups.com> <42086c34-43bd-44d8-a1e3-f220f62826b0@g19g2000yqg.googlegroups.com> Message-ID: On Nov 27, 4:38?pm, Robert Kern wrote: > On 2010-11-26 18:23 , Akand Islam wrote: > > > > > > > > > > > On Nov 26, 3:50 pm, Cameron Simpson ?wrote: > >> On 26Nov2010 13:15, Akand Islam ?wrote: > >> | Thanks for your posting. Like, here is the following Matlab codes > >> | which I am trying to transform into Python. Here you > >> | will find "profile clear, profile on, profile off, profile resume, > >> | profile viewer, and drawnow" syntaxes. So, what will be these > >> | equivalents > >> | in Python? > > >> I would start by looking at the "profile" python module: > > >> ?http://docs.python.org/library/profile.html#module-profile > > >> Cheers, > >> -- > >> Cameron Simpson ?DoD#743http://www.cskk.ezoshosting.com/cs/ > > >> Their are thre mistakes in this sentence. > >> ? ? ? ? ?- Rob Ray DoD#33333 > > > Dear Cameron Simpson, > > Thanks for co-operation. I have gone through the link, however, I am > > not much clear. Can you please show me some python syntaxes which > > contain Matlab like "profile on.., drawnow.." and so forth? > > Perhaps you could explain what those MATLAB commands do. Not everyone here is > familiar with MATLAB. For the most part, an API like "profile on; profile off" > is inappropriate for the "profile" Python module. It profiles the times each > function call takes, not each line. Turning it on and off doesn't make much > sense. The API described in the above link is better for what it does. > > If you want to visualize the profile, you may want to try RunSnakeRun: > > ? ?http://www.vrplumber.com/programming/runsnakerun/ > > If you want line-by-line profiling, you may want to check out my package, > line_profiler: > > ? ?http://pypi.python.org/pypi/line_profiler/ > > Again, we don't turn it on and off like you might do in MATLAB. Just follow the > directions and give up trying to find a correspondence with the MATLAB commands. > > -- > 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 Dear Robert Kern, I do appreciate your reply. Surely I will dig through your package. -- Akand From bhanu2srinivas at gmail.com Sat Nov 27 22:13:45 2010 From: bhanu2srinivas at gmail.com (bhanu) Date: Sat, 27 Nov 2010 19:13:45 -0800 (PST) Subject: earn 200-300% just launched new doubler 15 m ago join fast Message-ID: http://fast2double.com?bhanusri join 30$ get 5$ line bonus From benjamin at python.org Sat Nov 27 23:33:43 2010 From: benjamin at python.org (Benjamin Peterson) Date: Sat, 27 Nov 2010 22:33:43 -0600 Subject: [RELEASED] Python 2.7.1 Message-ID: On behalf of the Python development team, I'm happy as a clam to announce the immediate availability of Python 2.7.1. 2.7 includes many features that were first released in Python 3.1. The faster io module, the new nested with statement syntax, improved float repr, set literals, dictionary views, and the memoryview object have been backported from 3.1. Other features include an ordered dictionary implementation, unittests improvements, a new sysconfig module, auto-numbering of fields in the str/unicode format method, and support for ttk Tile in Tkinter. For a more extensive list of changes in 2.7, see http://doc.python.org/dev/whatsnew/2.7.html or Misc/NEWS in the Python distribution. To download Python 2.7.1 visit: http://www.python.org/download/releases/2.7.1/ The 2.7.1 changelog is at: http://svn.python.org/projects/python/tags/r271/Misc/NEWS 2.7 documentation can be found at: http://docs.python.org/2.7/ This is a production release. Please report any bugs you find to the bug tracker: http://bugs.python.org/ Enjoy! -- Benjamin Peterson Release Manager benjamin at python.org (on behalf of the entire python-dev team and 2.7.1's contributors) From benjamin at python.org Sat Nov 27 23:34:42 2010 From: benjamin at python.org (Benjamin Peterson) Date: Sat, 27 Nov 2010 22:34:42 -0600 Subject: [RELEASED] Python 3.1.3 Message-ID: On behalf of the Python development team, I'm happy as a lark to announce the third bugfix release for the Python 3.1 series, Python 3.1.3. This bug fix release features numerous bug fixes and documentation improvements over 3.1.2. The Python 3.1 version series focuses on the stabilization and optimization of the features and changes that Python 3.0 introduced. For example, the new I/O system has been rewritten in C for speed. File system APIs that use unicode strings now handle paths with undecodable bytes in them. Other features include an ordered dictionary implementation, a condensed syntax for nested with statements, and support for ttk Tile in Tkinter. For a more extensive list of changes in 3.1, see http://doc.python.org/3.1/whatsnew/3.1.html or Misc/NEWS in the Python distribution. This is a production release. To download Python 3.1.3 visit: http://www.python.org/download/releases/3.1.3/ A list of changes in 3.1.3 can be found here: http://svn.python.org/projects/python/tags/r313/Misc/NEWS The 3.1 documentation can be found at: http://docs.python.org/3.1 Bugs can always be reported to: http://bugs.python.org Enjoy! -- Benjamin Peterson Release Manager benjamin at python.org (on behalf of the entire python-dev team and 3.1.3's contributors) From chenxiangmei84 at gmail.com Sun Nov 28 02:56:30 2010 From: chenxiangmei84 at gmail.com (cntrade09) Date: Sat, 27 Nov 2010 23:56:30 -0800 (PST) Subject: Moncler Sheepskin&Feather short Down Jacket Discount Wholesale (http://www.moncler-saler.com//) Message-ID: <1eb27b3d-070f-4842-aa95-a6ff5bafbaee@k14g2000pra.googlegroups.com> Moncler long down coats brown Discount Wholesale (http://www.moncler -saler.com//) 2010 New! Moncler New Pop star Women down coat long brownDiscount Wholesale (http://www.moncler-saler.com//) Moncler 2010 Men Down cap Jacket Discount Wholesale (http://www.moncler-saler.com//) claire Down Moncler CoatsDiscount Wholesale (http://www.moncler- saler.com//) 09 Moncler Quincy WomenDiscount Wholesale (http://www.moncler- saler.com//) MONCLER - Angers belted quilt jacket Discount Wholesale (http://www.moncler-saler.com//) MONCLER - Bady quilted hooded jacket Black Discount Wholesale (http://www.moncler-saler.com//) Moncler 2010 Men Down Gray Jacket Discount Wholesale (http://www.moncler-saler.com//) Mel Hooded Parka Puffer blackDiscount Wholesale (http://www.moncler- saler.com//) MONCLER - Quilted jacket with hoodDiscount Wholesale (http://www.moncler-saler.com//) BADIA MONCLER very shinyDiscount Wholesale (http://www.moncler- saler.com//) Fashion Moncler Messina Women Down Jackets apricot Discount Wholesale (http://www.moncler-saler.com//) MONCLER - Bady quilted hooded jacket Blue Classic Monlcer purple Jackets MONCLER - Quilted jacket with hoody Moncler 2010 Men Down cap Jacket ncler 2010 Men Down Gray Jacket Moncler 2010 Men Down Jacket black Moncler Affton Jacket Discount Wholesale (http://www.moncler- saler.com//) Moncler BRANSON Down Jacket Grey Discount Wholesale (http://www.moncler-saler.com//) Moncler Branson Navy Jacket Black Discount Wholesale (http://www.moncler-saler.com//) Moncler Branson Navy Jacket Dark Bule Discount Wholesale (http://www.moncler-saler.com//) Moncler Branson Navy Jacket Red Moncler Bulgarie Jacket black Discount Wholesale (http://www.moncler- saler.com//) Moncler Chartreuse Down Jackets Grey Moncler Christmas Edition Down Jacket Black Discount Wholesale (http://www.moncler-saler.com//) Moncler Christmas Edition Down Jacket Red Discount Wholesale (http://www.moncler-saler.com//) Moncler Down Jacket Black Moncler Himalaya doudoune brillante veste taille Black Moncler Himalaya doudoune Down Jacket RedDiscount Wholesale (http://www.moncler-saler.com//) Moncler Himalaya DownJackets Blue Moncler KARAK Jackets Men purple Moncler long down coat dark blue Discount Wholesale (http://www.moncler-saler.com//) Moncler long down coats brown Discount Wholesale (http://www.moncler- saler.com//) Moncler Men Down-Hat Jacket$880.00 Save: 73% offMoncler Men Down-No Hat Jacket $238.00 Save: 70% off Discount Wholesale (http://www.moncler-saler.com//) Moncler Men Down-No Hat Jacket Discount Wholesale (http://www.moncler-saler.com//) Moncler Men Long Down Jacket Discount Wholesale (http://www.moncler- saler.com//) Moncler Opaque Sport Jacket Discount Wholesale (http://www.moncler- saler.com//) Moncler Sheepskin&Feather short Down Jacket Discount Wholesale (http://www.moncler-saler.com//) Moncler Sheepskin&Feather short Down Jacket Discount Wholesale (http://www.moncler-saler.com//) From __peter__ at web.de Sun Nov 28 03:37:34 2010 From: __peter__ at web.de (Peter Otten) Date: Sun, 28 Nov 2010 09:37:34 +0100 Subject: Comparing floats References: Message-ID: kj wrote: > I understand that, in Python 2.7 and 3.x >= 3.1, when the interactive > shell displays a float it shows "the shortest decimal fraction that > rounds correctly back to the true binary value". Is there a way > to access this rounding functionality from code that must be able > to run under version 2.6? (The idea would be to implement float > comparison as a comparison of the rounded versions of floats.) Doesn't float(str(x)) == x for all x imply that str(x) == str(y) if and only if x == y? If so, what would be the benefit of converting to string at all? From gpodevij at gmail.com Sun Nov 28 05:27:14 2010 From: gpodevij at gmail.com (=?ISO-8859-1?Q?Ga=EBtan_Podevijn?=) Date: Sun, 28 Nov 2010 11:27:14 +0100 Subject: Kind of plugin system In-Reply-To: References: Message-ID: Hello, Thank you both, I'll look at this in more depth ! Regards, Ga?tan 2010/11/27 Marc-Andre Belzile > I guess you could just define an entry-point in your source provider files > that would return a specific instance of an InformationProvider class. This > entry-point would be called by your main app (maybe at startup time or > during an update phase). > > There are plenty of articles on the web about python plugins that could > help you out, such as this one: > > http://wehart.blogspot.com/2009/01/python-plugin-frameworks.html > > -mab > > > > From: python-list-bounces+marc-andre.belzile=autodesk.com at python.org[mailto: > python-list-bounces+marc-andre.belzile > =autodesk.com at python.org] On Behalf Of Ga?tan Podevijn > Sent: Friday, November 26, 2010 12:46 PM > To: python-list at python.org > Subject: Kind of plugin system > > Hello, > > Here is my problem. > > I need to get some informations from files stored on my filesystem, Flickr > and Picasa. So the idea is to create a class (for instance, > "InformationsProvider") that provides common methods for those three > sources, then, for each source, I create a class that inherits from > "InformationsProvider" such as "InformationsLocalProvider", > "InformationsFlickrProvider" and "InformationPicasaProvider". It is clearly > needed because the method to get the informations is totally different for > each source (the connection with flickr or picasa for exemple). > > However, I'd like, in the future, to be able to add new source and thus, > just add a new class that implements the methods from Provider. The thing > is, I'd like to add only one class, and that the rest of the application is > able to use that class without really knowing how many class there are. > > I'd have something like : > for each provider that exists: get the informations file > > and if I add a new .py that implements a new provider (say Delicious of > GMail), the code above takes account of the new class. It must be "dynamic". > > Could you help me with that ? I hope I was clear enough. > > Thanks a lot, > > Ga?tan > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rustompmody at gmail.com Sun Nov 28 05:58:54 2010 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 28 Nov 2010 16:28:54 +0530 Subject: TDD in python Message-ID: Does anyone know of something like this for python? http://www.vimeo.com/13240481 From vriolk at gmail.com Sun Nov 28 07:36:26 2010 From: vriolk at gmail.com (coldpizza) Date: Sun, 28 Nov 2010 04:36:26 -0800 (PST) Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> Message-ID: <8b03c7fa-7751-4fc8-a518-caf3c9da515d@z9g2000yqz.googlegroups.com> On Nov 24, 11:08?pm, Raymond Hettinger wrote: > I'm writing-up more guidance on how to use super() and would like to > point at some real-world Python examples of cooperative multiple > inheritance. > > Google searches take me to old papers for C++ and Eiffel, but that > don't seem to be relevant to most Python programmers (i.e. a > WalkingMenu example where a submenu is both a Entry in a Menu and a > Menu itself). ?Another published example is in a graphic library where > some widgets inherit GraphicalFeature methods such as location, size > and NestingGroupingFeatures such as finding parents, siblings, and > children. ?I don't find either of those examples compelling because > there is no particular reason that they would have to have overlapping > method names. > > So far, the only situation I can find where method names necessarily > overlap is for the basics like __init__(), close(), flush(), and > save() where multiple parents need to have their own initialization > and finalization. > > If you guys know of good examples, I would appreciate a link or a > recap. > > Thanks, > > Raymond Did you try google code search? It is *not* the same as google code hosting. The site is http://www.google.com/codesearch and you can select Python in the 'language' dropdown. From mdw at distorted.org.uk Sun Nov 28 08:01:34 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Sun, 28 Nov 2010 13:01:34 +0000 Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> <4ceef381$0$1659$742ec2ed@news.sonic.net> <5c92a83e-9de1-4a03-828c-2cce79ce5a30@v17g2000prc.googlegroups.com> <4cf011b9$0$1619$742ec2ed@news.sonic.net> <87y68fwr89.fsf.mdw@metalzone.distorted.org.uk> <4cf0b232$0$1651$742ec2ed@news.sonic.net> <4cf18792$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87bp59vbyp.fsf.mdw@metalzone.distorted.org.uk> Steve Holden writes: > It isn't. Even inheritance itself isn't as useful as it at first > appears, and composition turns out in practice to be much more useful. > That goes double for multiple inheritance. Composition /with a convenient notation for delegation/ works fairly well. Indeed, this can be seen as the basis of Self. But downwards delegation -- where a superclass leaves part of its behaviour unspecified and requires (concrete) subclasses to fill in the resulting blanks -- is hard to express like this without some kind of means of identifying the original recipient of the delegated message. Once you've done that, there isn't much of a difference between a superclass and a component with implicit delegation. -- [mdw] From candide at free.invalid Sun Nov 28 09:08:45 2010 From: candide at free.invalid (candide) Date: Sun, 28 Nov 2010 15:08:45 +0100 Subject: Standard module implementation Message-ID: <4cf2626e$0$21696$426a34cc@news.free.fr> I was wondering if all the standard module are implemented in C. For instance, I can't find a C implementation for the minidom xml parser under Python 2.6. From benjamin.kaplan at case.edu Sun Nov 28 09:50:22 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sun, 28 Nov 2010 09:50:22 -0500 Subject: Standard module implementation In-Reply-To: <4cf2626e$0$21696$426a34cc@news.free.fr> References: <4cf2626e$0$21696$426a34cc@news.free.fr> Message-ID: On Sun, Nov 28, 2010 at 9:08 AM, candide wrote: > I was wondering if all the standard module are implemented in C. For > instance, I can't find a C implementation for the minidom xml parser under > Python 2.6. > -- No they aren't. A good chunk of the standard library is implemented in Python. Which is nice because Python the language isn't only implemented in C (CPython, the main implementation). It's also implemented in Java (Jython), C# (IronPython), and even in a restricted subset of Python itself (PyPy). From stefan_ml at behnel.de Sun Nov 28 09:52:45 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 28 Nov 2010 15:52:45 +0100 Subject: TDD in python In-Reply-To: References: Message-ID: Rustom Mody, 28.11.2010 11:58: > Does anyone know of something like this for python? > > http://www.vimeo.com/13240481 The page seems to require a recent version of the Flash player. Could you describe what exactly you are looking for? Stefan From news1234 at free.fr Sun Nov 28 10:05:47 2010 From: news1234 at free.fr (News123) Date: Sun, 28 Nov 2010 16:05:47 +0100 Subject: google group api with python In-Reply-To: <85a3bbf0-041f-4d67-b524-8d9db8327484@j25g2000yqa.googlegroups.com> References: <85a3bbf0-041f-4d67-b524-8d9db8327484@j25g2000yqa.googlegroups.com> Message-ID: <4cf26fcb$0$25464$426a34cc@news.free.fr> On 11/27/2010 11:51 PM, macroasm wrote: > hi. i want google group with send python. how do user api. Hi macroasm, You will probably increase tha amount of replies if you elaborate on your question. I personally do not really understand what you exactly asked for. From hejibo at gmail.com Sun Nov 28 10:06:40 2010 From: hejibo at gmail.com (He Jibo) Date: Sun, 28 Nov 2010 07:06:40 -0800 (PST) Subject: How do I get the URL of the active tab in Firefox/IE/Chrome? Message-ID: <5a3c7ec0-1a6c-411b-bee1-91f8245ce295@k22g2000yqh.googlegroups.com> Hi, I am writing a small program, which needs to get the URL of the active tab in either of firefox, internet exploerer or chrome. My need is similar as the one posted at, http://stackoverflow.com/questions/3631 ... -ie-chrome I did a lot of Googling, and get the following code. The following code can get the url of the first tab in internet explorer. My question is, how can I get the url of the current active tab? Thanks. ''' http://efreedom.com/Question/1-2555905/ ... Bar-Python http://blogs.msdn.com/b/oldnewthing/arc ... 35657.aspx http://mail.python.org/pipermail/python ... 02040.html http://code.activestate.com/recipes/302 ... lass-file/ ''' from win32com.client import Dispatch import win32api, win32con,win32gui SHELL = Dispatch("Shell.Application") def get_ie(shell): for win in shell.Windows(): # print win if win.Name == "Windows Internet Explorer": return win return None def main(): ie = get_ie(SHELL) if ie: print ie.LocationURL print ie.LocationName print ie.ReadyState print ie print ie.Document.title print ie.Document.location print ie.Document.forms # title = win32gui.GetWindowText(ie) # print title else: print "no ie window" if __name__ == '__main__': main() From vithyam6 at gmail.com Sun Nov 28 10:15:06 2010 From: vithyam6 at gmail.com (cinema) Date: Sun, 28 Nov 2010 07:15:06 -0800 (PST) Subject: HOLLYWOOD ACTRESS HOT PICTURES AND VIDEOS HERE Message-ID: http://www.cinemaulagam.org http://www.cinemaulagam.org http://www.cinemaulagam.org http://www.cinemaulagam.org http://www.cinemaulagam.org From news1234 at free.fr Sun Nov 28 10:22:33 2010 From: news1234 at free.fr (News123) Date: Sun, 28 Nov 2010 16:22:33 +0100 Subject: remote control firefox with python Message-ID: <4cf273b9$0$19685$426a74cc@news.free.fr> Hi, I wondered whether there is a simpe way to 'remote' control fire fox with python. With remote controlling I mean: - enter a url in the title bar and click on it - create a new tab - enter another url click on it - save the html document of this page - Probably the most difficult one: emulate a click or 'right click' on a certain button or link of the current page. - other interesting things would be to be able to enter the master password from a script - to enable disable proxy settings while running. The reason why I want to stay within Firefox and not use any other 'mechanize' frame work is, that the pages I want to automate might contain a lot of javascript for the construction of the actual page. Thanks in advance for any pointers ideas. From gnarlodious at gmail.com Sun Nov 28 10:35:18 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Sun, 28 Nov 2010 07:35:18 -0800 (PST) Subject: Python 3.1.3 References: Message-ID: <9ae5c47a-f5dd-4549-ac55-8527586f4f57@r14g2000prj.googlegroups.com> Don't know why, but in Terminal the uparrow now gives me: ^[[A which means I no longer have history scrolling. -- Gnarlie From perry at nomail.net.invalid Sun Nov 28 10:46:48 2010 From: perry at nomail.net.invalid (Perry Johnson) Date: Sun, 28 Nov 2010 15:46:48 +0000 (UTC) Subject: Subprocesses and Ctrl-C handling on windows Message-ID: I have a python script which spawns a subprocess that takes a few seconds to complete. If I hit Ctrl-C while the subprocess is executing, sometimes the python script and the subprocess end silently and I get back to the shell prompt and sometimes I get the KeyboardInterrupt exception. Is there any kind of method underneath this seemingly random behavior? From mohammed.php.developer at gmail.com Sun Nov 28 10:53:05 2010 From: mohammed.php.developer at gmail.com (mohammed_a_o) Date: Sun, 28 Nov 2010 07:53:05 -0800 (PST) Subject: send free sms to any mobile in the world Message-ID: <38b0b7e3-2807-4534-aeb9-ac10b8045bcd@l8g2000yqh.googlegroups.com> send free sms to any mobile in the world http://www.phpforweb.com/askany/sms.php?sms From stefan_ml at behnel.de Sun Nov 28 10:59:03 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 28 Nov 2010 16:59:03 +0100 Subject: Python 3.1.3 In-Reply-To: <9ae5c47a-f5dd-4549-ac55-8527586f4f57@r14g2000prj.googlegroups.com> References: <9ae5c47a-f5dd-4549-ac55-8527586f4f57@r14g2000prj.googlegroups.com> Message-ID: Gnarlodious, 28.11.2010 16:35: > Don't know why, but in Terminal the uparrow now gives me: > > ^[[A > > which means I no longer have history scrolling. You seem to be mailing from a Mac, is that the system you're having this problem with? Did you build Python yourself or use a provided binary? (and, if the latter, from where?) Stefan From gnarlodious at gmail.com Sun Nov 28 11:14:19 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Sun, 28 Nov 2010 08:14:19 -0800 (PST) Subject: Python 3.1.3 References: <9ae5c47a-f5dd-4549-ac55-8527586f4f57@r14g2000prj.googlegroups.com> Message-ID: <2b22dfa0-41d5-4047-8cfe-7a18e00e3760@o23g2000prh.googlegroups.com> Ah yes, sorry. This is Mac OSX 10.6.5, I did it build from the file at http://www.python.org/ftp/python/3.1.3/Python-3.1.3.tgz -- Gnarlie From roy at panix.com Sun Nov 28 11:27:36 2010 From: roy at panix.com (Roy Smith) Date: Sun, 28 Nov 2010 11:27:36 -0500 Subject: Python 3.1.3 References: <9ae5c47a-f5dd-4549-ac55-8527586f4f57@r14g2000prj.googlegroups.com> <2b22dfa0-41d5-4047-8cfe-7a18e00e3760@o23g2000prh.googlegroups.com> Message-ID: In article <2b22dfa0-41d5-4047-8cfe-7a18e00e3760 at o23g2000prh.googlegroups.com>, Gnarlodious wrote: > Ah yes, sorry. > This is Mac OSX 10.6.5, I did it build from the file at > http://www.python.org/ftp/python/3.1.3/Python-3.1.3.tgz > > -- Gnarlie I'm seeing the same behavior on a build I did of Python 3.2a4+ (py3k:86538, Nov 19 2010, 20:52:31) last week, also on 10.6.5. From the configure output, it looks like it found readline: py3k$ grep -i readline config.status D["HAVE_LIBREADLINE"]=" 1" but it's not acting like it. The Python 2.6.1 which came with the system works properly. From gnarlodious at gmail.com Sun Nov 28 11:36:56 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Sun, 28 Nov 2010 08:36:56 -0800 (PST) Subject: Python 3.1.3 References: <9ae5c47a-f5dd-4549-ac55-8527586f4f57@r14g2000prj.googlegroups.com> <2b22dfa0-41d5-4047-8cfe-7a18e00e3760@o23g2000prh.googlegroups.com> Message-ID: <53c154fa-e957-4266-ad12-eaf8c2ef3207@35g2000prt.googlegroups.com> Well I don't know what a readline is, but I upgraded from 3.1.1 and it was working fine. I might also add that the downarrow is also broken: ^[[B -- Gnarlie From nad at acm.org Sun Nov 28 11:48:36 2010 From: nad at acm.org (Ned Deily) Date: Sun, 28 Nov 2010 08:48:36 -0800 Subject: Python 3.1.3 References: <9ae5c47a-f5dd-4549-ac55-8527586f4f57@r14g2000prj.googlegroups.com> <2b22dfa0-41d5-4047-8cfe-7a18e00e3760@o23g2000prh.googlegroups.com> Message-ID: In article <2b22dfa0-41d5-4047-8cfe-7a18e00e3760 at o23g2000prh.googlegroups.com>, Gnarlodious wrote: > Ah yes, sorry. > This is Mac OSX 10.6.5, I did it build from the file at > http://www.python.org/ftp/python/3.1.3/Python-3.1.3.tgz For Python 3.1 on OS X, you'll need to supply a version of the GNU readline library, which is not supplied by Apple in OS X, during the build. Python 2.7 and 3.2 are able to make use of the BSD editline libedit which does comes with OS X. -- Ned Deily, nad at acm.org From nad at acm.org Sun Nov 28 12:03:00 2010 From: nad at acm.org (Ned Deily) Date: Sun, 28 Nov 2010 09:03:00 -0800 Subject: Python 3.1.3 References: <9ae5c47a-f5dd-4549-ac55-8527586f4f57@r14g2000prj.googlegroups.com> <2b22dfa0-41d5-4047-8cfe-7a18e00e3760@o23g2000prh.googlegroups.com> Message-ID: In article , Roy Smith wrote: > I'm seeing the same behavior on a build I did of > > Python 3.2a4+ (py3k:86538, Nov 19 2010, 20:52:31) > > last week, also on 10.6.5. From the configure output, it looks like it > found readline: > > py3k$ grep -i readline config.status > D["HAVE_LIBREADLINE"]=" 1" > > but it's not acting like it. The Python 2.6.1 which came with the > system works properly. As noted, Python 3.2 on OS X should link to the OS X copy of the BSD editline (libedit). You may have to adjust your PYTHONSTARTUP script to use the different commands. Here's a snippet from mine: try: import readline except ImportError: print("Module readline not available.") else: import rlcompleter if 'libedit' in readline.__doc__: readline.parse_and_bind("bind ^I rl_complete") else: readline.parse_and_bind("tab: complete") http://docs.python.org/py3k/library/readline.html Also, see: man 5 editrc BTW, python.org 3.2a4 installers for OS X are now available so you might not need to build your own: http://www.python.org/download/releases/3.2/ -- Ned Deily, nad at acm.org From usernet at ilthio.net Sun Nov 28 12:19:50 2010 From: usernet at ilthio.net (Tim Harig) Date: Sun, 28 Nov 2010 17:19:50 +0000 (UTC) Subject: remote control firefox with python References: <4cf273b9$0$19685$426a74cc@news.free.fr> Message-ID: On 2010-11-28, News123 wrote: > Thanks in advance for any pointers ideas. google XPCOM From dfgfh336 at gmail.com Sun Nov 28 12:24:23 2010 From: dfgfh336 at gmail.com (dgf dg) Date: Sun, 28 Nov 2010 09:24:23 -0800 (PST) Subject: nike jordan shoes coach, chane bag COOGI Message-ID: <804bee89-42b0-42b7-945f-cf932a59168d@s5g2000yqm.googlegroups.com> === http://www.stefsclothes.net === Handbags(Coach lv fendi d&g) $35 Tshirts (Polo ,ed hardy,lacoste) $16 Jean(True Religion,ed hardy,coogi) $30 Sunglasses(Oakey,coach,gucci,Armaini) $16 New era cap $15 Bikini (Ed hardy,polo) $25 ==== http://www.stefsclothes.net ==== From nagle at animats.com Sun Nov 28 13:40:14 2010 From: nagle at animats.com (John Nagle) Date: Sun, 28 Nov 2010 10:40:14 -0800 Subject: Getting current time zone in Python in tzinfo format not implemented Message-ID: <4cf2a211$0$1624$742ec2ed@news.sonic.net> Getting the local time zone in Python is rather difficult. As of 2008, two articles indicate that the current mechanisms totally suck: "Python and time zones part 2: The beast returns!": http://regebro.wordpress.com/2008/05/10/python-and-time-zones-part-2-the-beast-returns/ "Time zones in Python ? welcome to hell": http://blog.mfabrik.com/2008/06/30/relativity-of-time-shortcomings-in-python-datetime-and-workaround/ (Despite that article, there is a straightforward way to get that information in Windows: "GetDynamicTimeZoneInformation".) Did something useful ever get done about that? This ought to be in the "time" module for each platform. John Nagle From xi at gamma.dn.ua Sun Nov 28 14:22:54 2010 From: xi at gamma.dn.ua (Kirill Simonov) Date: Sun, 28 Nov 2010 14:22:54 -0500 Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance In-Reply-To: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> Message-ID: <4CF2AC0E.7030802@gamma.dn.ua> Hi Raymond, We've been using cooperative inheritance to implement stacked utilities such as WSGI middleware or connecting to a database. An example of a WSGI middleware stack: # Declare the interface and provide the default implementation. class WSGI(Utility): def __call__(self, environ, start_response): # The main WSGI application is implemented here. start_response("200 OK", [('Content-Type', 'text/plain')]) return ["Hello World!"] # GZip middleware (may be defined in a different module or a plugin) class GZIP(WSGI): # To indicate relative position in the middleware stack weights(100) def __call__(self, environ, start_response): # Call the next middleware in the stack to generate data. # Also, need to wrap start_response here... generator = super(GZIP, self).__call__(environ, start_response) # Pack the output... # Error handling middleware (defined in a different module or a plugin) class LogErrors(WSGI): weights(1000) def __call__(self, environ, start_response): # Call the next middleware in the stack, catch any errors. try: generator = super(LogErrors, self).__call__(environ, start_response) except: # Log errors... # Now glue them all together def wsgi(environ, start_response): wsgi = WSGI() # !!! return wsgi(environ, start_response) The trick here is that the constructor of `WSGI` (actually, `Utility.__new__()`) is overridden. Instead of producing a new instance of `WSGI` , it does the following: - use `__subclasses__()` to find all components of the utility; - order the components by their weights; - create a new class: `type(name, list_of_components, {})`; - return an instance of the class. Here is another example, database connection. # The interface, no default implementation. class Connect(Utility): def __init__(self, host, port, user, password, database): self.host = host self.port = port self.user = user self.password = password self.database = database def __call__(self): raise NotImplementedError() # Public API def connect(host, port, user, password, database): # Same trick here. connect = Connect(host, port, user, password, database) return connect() # PostgreSQL implementation (defined in a plugin) import psycopg2 class PGSQLConnect(Connect): def __call__(self): return psycopg2.connect(...) # Connection pooling (defined in a plugin) class Pooling(Connect): weights(100) def __call__(self): # Check if we could reuse an existing connection # ... # If no free connections available connection = super(Pooling, self).__call__() # Save it somewhere and return it... Note that utility instances are short-lived so any persistent state must be kept elsewhere. We also use the same pattern to implement Cecil/Diesel-style multimethods and general predicate dispatch, but that's probably outside the scope of your question. A public version of the code lives here: https://bitbucket.org/prometheus/htsql Unfortunately it doesn't exactly match my examples above: connection pooling and most of the wsgi middleware are still to be ported, `weights()` is missing, etc. Hope it helps. Thanks, Kirill On 11/24/2010 03:08 PM, Raymond Hettinger wrote: > I'm writing-up more guidance on how to use super() and would like to > point at some real-world Python examples of cooperative multiple > inheritance. > > Google searches take me to old papers for C++ and Eiffel, but that > don't seem to be relevant to most Python programmers (i.e. a > WalkingMenu example where a submenu is both a Entry in a Menu and a > Menu itself). Another published example is in a graphic library where > some widgets inherit GraphicalFeature methods such as location, size > and NestingGroupingFeatures such as finding parents, siblings, and > children. I don't find either of those examples compelling because > there is no particular reason that they would have to have overlapping > method names. > > So far, the only situation I can find where method names necessarily > overlap is for the basics like __init__(), close(), flush(), and > save() where multiple parents need to have their own initialization > and finalization. > > If you guys know of good examples, I would appreciate a link or a > recap. > > Thanks, > > > Raymond > From roy at panix.com Sun Nov 28 14:30:08 2010 From: roy at panix.com (Roy Smith) Date: Sun, 28 Nov 2010 14:30:08 -0500 Subject: Python 3.1.3 References: <9ae5c47a-f5dd-4549-ac55-8527586f4f57@r14g2000prj.googlegroups.com> <2b22dfa0-41d5-4047-8cfe-7a18e00e3760@o23g2000prh.googlegroups.com> <53c154fa-e957-4266-ad12-eaf8c2ef3207@35g2000prt.googlegroups.com> Message-ID: In article <53c154fa-e957-4266-ad12-eaf8c2ef3207 at 35g2000prt.googlegroups.com>, Gnarlodious wrote: > Well I don't know what a readline is, but I upgraded from 3.1.1 and it > was working fine. > > I might also add that the downarrow is also broken: ^[[B > > -- Gnarlie Readline is the (very cool) library which handles all the interactive line editing, including the up and down arrows. From tjreedy at udel.edu Sun Nov 28 14:30:24 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 28 Nov 2010 14:30:24 -0500 Subject: TDD in python In-Reply-To: References: Message-ID: On 11/28/2010 5:58 AM, Rustom Mody wrote: > Does anyone know of something like this for python? > > http://www.vimeo.com/13240481 "This is the first in a series of videos demonstrating TDD in C++ using the Eclipse CDT and CppUTest" TDD = Test-Driven Development is a development philosophy applicable to any language. It is not all that different from Hypothesis-Driven Science (HDS) (I just made that connection!) I suspect CppUTest is derived from Java JUnit (or whatever), as is Python's unittest. Python also has doctest and other public and private test frameworks and function. -- Terry Jan Reedy From perry at nomail.net.invalid Sun Nov 28 14:45:16 2010 From: perry at nomail.net.invalid (Perry Johnson) Date: Sun, 28 Nov 2010 19:45:16 +0000 (UTC) Subject: Subprocesses and Ctrl-C handling on windows References: Message-ID: On 2010-11-28, Perry Johnson wrote: > I have a python script which spawns a subprocess that takes a few > seconds to complete. If I hit Ctrl-C while the subprocess is > executing, sometimes the python script and the subprocess end silently > and I get back to the shell prompt and sometimes I get the > KeyboardInterrupt exception. Is there any kind of method underneath > this seemingly random behavior? False alarm, please disregard the quoted post. From ndparker at gmail.com Sun Nov 28 14:46:07 2010 From: ndparker at gmail.com (=?UTF-8?B?QW5kcsOp?= Malo) Date: Sun, 28 Nov 2010 20:46:07 +0100 Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> <4ceef381$0$1659$742ec2ed@news.sonic.net> <5c92a83e-9de1-4a03-828c-2cce79ce5a30@v17g2000prc.googlegroups.com> <4cf011b9$0$1619$742ec2ed@news.sonic.net> <87y68fwr89.fsf.mdw@metalzone.distorted.org.uk> <4cf0b232$0$1651$742ec2ed@news.sonic.net> <4cf18792$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <2100371.ySKtRVgNeu@news.perlig.de> * Steve Holden wrote: > Even inheritance itself isn't as useful as it at first > appears, and composition turns out in practice to be much more useful. > That goes double for multiple inheritance. Amen. nd -- my @japh = (sub{q~Just~},sub{q~Another~},sub{q~Perl~},sub{q~Hacker~}); my $japh = q[sub japh { }]; print join ######################### [ $japh =~ /{(.)}/] -> [0] => map $_ -> () # Andr? Malo # => @japh; # http://www.perlig.de/ # From usernet at ilthio.net Sun Nov 28 14:59:57 2010 From: usernet at ilthio.net (Tim Harig) Date: Sun, 28 Nov 2010 19:59:57 +0000 (UTC) Subject: How do I get the URL of the active tab in Firefox/IE/Chrome? References: <5a3c7ec0-1a6c-411b-bee1-91f8245ce295@k22g2000yqh.googlegroups.com> Message-ID: On 2010-11-28, He Jibo wrote: > I did a lot of Googling, and get the following code. The following > code can get the url of the first tab in internet explorer. My > question is, how can I get the url of the current active tab? Thanks. It would be beneficial to know what your ultimate goal is. The "InternetExplorer.Application" automation object doesn't contain any way to manipulate tabs directly; but, there are likely less direct methods of achieving whatever you are trying to accomplish if you let us know what that is. From python at bdurham.com Sun Nov 28 15:47:24 2010 From: python at bdurham.com (python at bdurham.com) Date: Sun, 28 Nov 2010 15:47:24 -0500 Subject: Using property() to extend Tkinter classes but Tkinter classes are old-style classes? Message-ID: <1290977244.17714.1407556497@webmail.messagingengine.com> I had planned on subclassing Tkinter.Toplevel() using property() to wrap access to properties like a window's title. After much head scratching and a peek at the Tkinter.py source, I realized that all Tkinter classes are old-style classes (even under Python 2.7). 1. Is there a technical reason why Tkinter classes are still old-style classes? 2. Is there a technique I can use to get property() to work with old-style classes? Or, must I use composition and wrap a reference to a Tkinter.Toplevel() window in a new style class? Thanks, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Sun Nov 28 15:54:44 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 28 Nov 2010 12:54:44 -0800 Subject: Standard module implementation In-Reply-To: <4cf2626e$0$21696$426a34cc@news.free.fr> References: <4cf2626e$0$21696$426a34cc@news.free.fr> Message-ID: On Sun, Nov 28, 2010 at 6:08 AM, candide wrote: > I was wondering if all the standard module are implemented in C. For > instance, I can't find a C implementation for the minidom xml parser under > Python 2.6. As was already said, no; a significant portion if not the majority of the std lib is written in pure Python, not C. You can usually determine how a module is implemented by looking at the file extension of the module's __file__ attribute. For example: $ python Python 2.6.6 (r266:84292, Oct 12 2010, 14:31:05) [GCC 4.2.1 (Apple Inc. build 5664)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import cPickle # obviously in C >>> cPickle.__file__ '/sw/lib/python2.6/lib-dynload/cPickle.so' >>> import pickle # pure Python version >>> pickle.__file__ '/sw/lib/python2.6/pickle.pyc' Cheers, Chris -- http://blog.rebertia.com From news1234 at free.fr Sun Nov 28 16:58:19 2010 From: news1234 at free.fr (News123) Date: Sun, 28 Nov 2010 22:58:19 +0100 Subject: remote control firefox with python In-Reply-To: References: <4cf273b9$0$19685$426a74cc@news.free.fr> Message-ID: <4cf2d07b$0$26085$426a74cc@news.free.fr> On 11/28/2010 06:19 PM, Tim Harig wrote: > On 2010-11-28, News123 wrote: >> Thanks in advance for any pointers ideas. > > google XPCOM thanks a lot From tjreedy at udel.edu Sun Nov 28 18:15:28 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 28 Nov 2010 18:15:28 -0500 Subject: Using property() to extend Tkinter classes but Tkinter classes are old-style classes? In-Reply-To: <1290977244.17714.1407556497@webmail.messagingengine.com> References: <1290977244.17714.1407556497@webmail.messagingengine.com> Message-ID: On 11/28/2010 3:47 PM, python at bdurham.com wrote: > I had planned on subclassing Tkinter.Toplevel() using property() to wrap > access to properties like a window's title. > After much head scratching and a peek at the Tkinter.py source, I > realized that all Tkinter classes are old-style classes (even under > Python 2.7). > 1. Is there a technical reason why Tkinter classes are still old-style > classes? To not break old code. Being able to break code by upgrading all classes in the stdlib was one of the reasons for 3.x. -- Terry Jan Reedy From nobody at nowhere.com Sun Nov 28 18:20:13 2010 From: nobody at nowhere.com (Nobody) Date: Sun, 28 Nov 2010 23:20:13 +0000 Subject: Comparing floats References: Message-ID: On Sat, 27 Nov 2010 18:23:48 -0500, Terry Reedy wrote: >> Therefore, to implement this multiplication operation I need to have a >> way to verify that the float tuples C and D are "equal". > > I might try the average relative difference: > sum(abs((i-j)/(i+j)) for i,j in zip(C,D))/n # assuming lengths constant The division is unstable if i and j are close to zero. For scalars, I'd use: abs(i-j) <= epsilon * (1 + abs(i+j)) This amounts to a relative error check for large values and an absolute error check for values close to zero. For a vector, I'd check that the above holds for all pairs. From hemant.dmp at gmail.com Sun Nov 28 18:36:45 2010 From: hemant.dmp at gmail.com (BansalMaddy) Date: Sun, 28 Nov 2010 15:36:45 -0800 (PST) Subject: Help required with Tranformation of coordinate system Message-ID: <1e8c75f4-e5c8-4263-9f4c-34fff241725a@t35g2000yqj.googlegroups.com> hi all! i need a help in python! i am struggling to implement this since last 2/3 days. suppose i have a 2D plot (say y=x**2). now on the same plot i want to transform my origin of coordinate system to a point (x',y' on this curve and again create a new plot with origin at x',y') can somebody help me how can i offset my cordinate system ... From goldtech at worldpost.com Sun Nov 28 18:58:19 2010 From: goldtech at worldpost.com (goldtech) Date: Sun, 28 Nov 2010 15:58:19 -0800 (PST) Subject: list of regex special characters Message-ID: <53e3530d-27b4-4d19-b96d-74429b28c119@o11g2000prf.googlegroups.com> I am looking for a list of special character in python regular expressions that need to be escaped if you want their literal meaning. I searched and can not find the list. Any help appreciated. From ben+python at benfinney.id.au Sun Nov 28 19:13:14 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 29 Nov 2010 11:13:14 +1100 Subject: list of regex special characters References: <53e3530d-27b4-4d19-b96d-74429b28c119@o11g2000prf.googlegroups.com> Message-ID: <87fwul56n9.fsf@benfinney.id.au> goldtech writes: > I am looking for a list of special character in python regular > expressions that need to be escaped if you want their literal meaning. You can avoid caring about that by using ?re.escape?, which escapes any characters in its input character that are not alphanumeric. > I searched and can not find the list. Any help appreciated. >>> import re >>> help(re) ? DESCRIPTION ? The special characters are: ? -- \ ?I got some new underwear the other day. Well, new to me.? ?Emo | `\ Philips | _o__) | Ben Finney From python.list at tim.thechases.com Sun Nov 28 19:23:46 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 28 Nov 2010 18:23:46 -0600 Subject: list of regex special characters In-Reply-To: <53e3530d-27b4-4d19-b96d-74429b28c119@o11g2000prf.googlegroups.com> References: <53e3530d-27b4-4d19-b96d-74429b28c119@o11g2000prf.googlegroups.com> Message-ID: <4CF2F292.7070105@tim.thechases.com> On 11/28/2010 05:58 PM, goldtech wrote: > I am looking for a list of special character in python regular > expressions that need to be escaped if you want their literal meaning. > > I searched and can not find the list. Any help appreciated. Trust the re module to tell you: >>> import re >>> chars = [chr(i) for i in range(0,256)] >>> escaped = [c for c in chars if re.escape(c) != c] >>> print len(escaped) 194 >>> print escaped [...] >>> can_use_unescaped = [c for c in chars if re.escape(c) == c] (adjust "chars" accordingly if you want to check unicode characters too). -tkc From ben+python at benfinney.id.au Sun Nov 28 19:49:27 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 29 Nov 2010 11:49:27 +1100 Subject: list of regex special characters References: <53e3530d-27b4-4d19-b96d-74429b28c119@o11g2000prf.googlegroups.com> Message-ID: <877hfx54yw.fsf@benfinney.id.au> Tim Chase writes: > On 11/28/2010 05:58 PM, goldtech wrote: > > I am looking for a list of special character in python regular > > expressions that need to be escaped if you want their literal > > meaning. > > Trust the re module to tell you: > > >>> import re > >>> chars = [chr(i) for i in range(0,256)] > >>> escaped = [c for c in chars if re.escape(c) != c] Note that, according to its docstring, ?re.escape? doesn't distinguish characters that *need to be* escaped for their literal meaning; it simply escapes any non-alphanumeric character. > >>> can_use_unescaped = [c for c in chars if re.escape(c) == c] Right. There are three classes of character for this purpose: * those that have a literal meaning *only if* escaped * those that have literal meaning whether or not they are escaped * those that have a literal meaning *only if not* escaped The ?re.escape? function, according to its docstring, simply says any non-alphanumerics can safely be said to exist in one of the first two classes, and both are safe to escape without bothering to distinguish between them. The OP was asking for the first class specifically, but I question whether that's actually needed for the purpose. -- \ ?The cost of education is trivial compared to the cost of | `\ ignorance.? ?Thomas Jefferson | _o__) | Ben Finney From tjreedy at udel.edu Sun Nov 28 20:03:29 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 28 Nov 2010 20:03:29 -0500 Subject: Help required with Tranformation of coordinate system In-Reply-To: <1e8c75f4-e5c8-4263-9f4c-34fff241725a@t35g2000yqj.googlegroups.com> References: <1e8c75f4-e5c8-4263-9f4c-34fff241725a@t35g2000yqj.googlegroups.com> Message-ID: On 11/28/2010 6:36 PM, BansalMaddy wrote: > hi all! > i need a help in python! i am struggling to implement this since last > 2/3 days. suppose i have a 2D plot (say y=x**2). > now on the same plot i want to transform my origin of coordinate > system to a point (x',y' on this curve and again create a new plot > with origin at x',y') > can somebody help me how can i offset my cordinate system ... Plot y-y' == (x-x')**2 - y' against x-x'. -- Terry Jan Reedy From sridatta9247 at gmail.com Sun Nov 28 21:38:25 2010 From: sridatta9247 at gmail.com (guru) Date: Sun, 28 Nov 2010 18:38:25 -0800 (PST) Subject: KARO HOT MASTI Message-ID: <9d37e093-e103-4612-891d-dfdbb6d67492@d24g2000prj.googlegroups.com> FOR HOT MASTI http://karomasti9.blogspot.com/ AMISHAPATEL HOT VIDEOS http://karomasti9.blogspot.com/search/label/amisha HANSIKHA HOT SEXY PHOTOS http://karomasti9.blogspot.com/search/label/HANSIKA HOT SEXY COLLEGE GIRLS http://karomasti9.blogspot.com/search/label/hot BEAUTIFUL LARADATTA http://karomasti9.blogspot.com/search/label/laradatta NIKISHA HOT BOOBS http://karomasti9.blogspot.com/search/label/nikisha PRIYANKA SPICY LATEST PICS http://karomasti9.blogspot.com/search/label/priyanka ONLY FOR YOUTH http://karomasti9.blogspot.com/search/label/spicy SRILEKHA UNSEENED PHOTOS http://karomasti9.blogspot.com/search/label/Srilekha CHOPRA UNBELIVABLE PHOTOS http://karomasti9.blogspot.com/search/label/chopra From sridharr at activestate.com Sun Nov 28 22:38:32 2010 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Sun, 28 Nov 2010 19:38:32 -0800 Subject: ANN: ActivePython 2.6.6.17 is now available Message-ID: ActiveState is pleased to announce ActivePython 2.6.6.17, a complete, ready-to-install binary distribution of Python 2.6. http://www.activestate.com/activepython/downloads What's New in ActivePython-2.6.6.17 =================================== *Release date: 19-Nov-2010* New Features & Upgrades ----------------------- - Security upgrade to openssl-0.9.8p - Upgrade to PyPM 1.2.5; noteworthy changes: - New command 'pypm log' to view log entries for last operation - depgraph bug fixes (Bug #88664, #88825) - Fix: ignore empty lines in requirements.txt - Ignore comments (starting with #) in the requirements file What's New in ActivePythonEE-2.6.6.16 ===================================== *Release date: 05-Nov-2010* New Features & Upgrades ----------------------- - Upgrade to PyPM 1.2.3; noteworthy changes: - Faster startup (performance) especially on Windows. - Rewrite of an improved dependency algorithm (#88038) - install/uninstall now accepts the --nodeps option - 'pypm install ' to directly download and install a .pypm file - 'pypm show' shows other installed packages depending on the shown package - 'pypm show' accepts --rdepends to show the list of dependents - 'pypm show' shows extra dependencies (for use in the 'install' cmd) - 'pypm show' lists all available versions in the repository - 'pypm freeze' to dump installed packages as requirements (like 'pip freeze') - Support for pip-stye requirements file ('pypm install -r requirements.txt') - Bug #87764: 'pypm upgrade' will not error out for missing packages - Bug #87902: fix infinite loops with cyclic package dependencies (eg: plone) - Bug #88370: Handle file-overwrite conflicts (implement --force) - Upgraded the following packages: - Distribute-0.6.14 - pip-0.8.1 - SQLAlchemy-0.6.5 - virtualenv-1.5.1 What is ActivePython? ===================== ActivePython is ActiveState's binary distribution of Python. Builds for Windows, Mac OS X, Linux are made freely available. Solaris, HP-UX and AIX builds, and access to older versions are available in ActivePython Business, Enterprise and OEM editions: http://www.activestate.com/python ActivePython includes the Python core and the many core extensions: zlib and bzip2 for data compression, the Berkeley DB (bsddb) and SQLite (sqlite3) database libraries, OpenSSL bindings for HTTPS support, the Tix GUI widgets for Tkinter, ElementTree for XML processing, ctypes (on supported platforms) for low-level library access, and others. The Windows distribution ships with PyWin32 -- a suite of Windows tools developed by Mark Hammond, including bindings to the Win32 API and Windows COM. ActivePython 2.6, 2.7 and 3.1 also include a binary package manager for Python (PyPM) that can be used to install packages much easily. For example: C:\>pypm install mysql-python [...] C:\>python >>> import MySQLdb >>> See this page for full details: http://docs.activestate.com/activepython/2.6/whatsincluded.html As well, ActivePython ships with a wealth of documentation for both new and experienced Python programmers. In addition to the core Python docs, ActivePython includes the "What's New in Python" series, "Dive into Python", the Python FAQs & HOWTOs, and the Python Enhancement Proposals (PEPs). An online version of the docs can be found here: http://docs.activestate.com/activepython/2.6/ We would welcome any and all feedback to: activepython-feedback at activestate.com Please file bugs against ActivePython at: http://bugs.activestate.com/enter_bug.cgi?product=ActivePython Supported Platforms =================== ActivePython is available for the following platforms: - Windows/x86 (32-bit) - Windows/x64 (64-bit) (aka "AMD64") - Mac OS X (32-bit and 64-bit; 10.5+) - Linux/x86 (32-bit) - Linux/x86_64 (64-bit) (aka "AMD64") - Solaris/SPARC (32-bit and 64-bit) (Business, Enterprise or OEM edition only) - Solaris/x86 (32-bit) (Business, Enterprise or OEM edition only) - HP-UX/PA-RISC (32-bit) (Business, Enterprise or OEM edition only) - HP-UX/IA-64 (32-bit and 64-bit) (Enterprise or OEM edition only) - AIX/PowerPC (32-bit and 64-bit) (Business, Enterprise or OEM edition only) More information about the Business Edition can be found here: http://www.activestate.com/business-edition Custom builds are available in the Enterprise Edition: http://www.activestate.com/enterprise-edition Thanks, and enjoy! The Python Team -- Sridhar Ratnakumar Python Developer ActiveState, The Dynamic Language Experts sridharr at activestate.com http://www.activestate.com Get insights on Open Source and Dynamic Languages at www.activestate.com/blog From timr at probo.com Sun Nov 28 23:22:15 2010 From: timr at probo.com (Tim Roberts) Date: Sun, 28 Nov 2010 20:22:15 -0800 Subject: SQLite date fields References: Message-ID: Duncan Booth wrote: >Tim Roberts wrote: > >>>However, when it comes to writing-back data to the table, SQLite is >>>very forgiving and is quite happy to store '25/06/2003' in a date >>>field, >> >> SQLite is essentially typeless. ALL fields are stored as strings, >> with no interpretation. You can store whatever you want in any >> column. The column types are basically there to remind YOU how to >> handle the data. > >Not all fields are stored as strings; they may also be stored as >integer, floating point values or binary data. Sorry. Up through SQLite version 2, ALL fields were stored as strings, even if you typed them as integers or floats. I see that has changed in v3. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From r1chardj0n3s at gmail.com Mon Nov 29 00:01:04 2010 From: r1chardj0n3s at gmail.com (Richard Jones) Date: Mon, 29 Nov 2010 16:01:04 +1100 Subject: Next Melbourne PUG meeting Monday 6th of December Message-ID: Hi all, The Melbourne Python Users Group will be meeting 6PM next Monday, the 6th of December at RMIT University. For details see http://bit.ly/mpug. From hejibo at gmail.com Mon Nov 29 00:53:52 2010 From: hejibo at gmail.com (He Jibo) Date: Sun, 28 Nov 2010 21:53:52 -0800 (PST) Subject: How do I get the URL of the active tab in Firefox/IE/Chrome? Message-ID: Hi, I am writing a small program, which needs to get the URL of the active tab in either of firefox, internet exploerer or chrome. My need is similar as the one posted at, http://stackoverflow.com/questions/3631216/how-do-i-get-the-url-of-the-visible-tab-in-firefox-ie-chrome I did a lot of Googling, and get the following code. The following code can get the url of the first tab in internet explorer. My question is, how can I get the url of the current active tab? Thanks. ''' http://efreedom.com/Question/1-2555905/Get-Internet-Explorer-Address-Bar-Python http://blogs.msdn.com/b/oldnewthing/archive/2005/07/05/435657.aspx http://mail.python.org/pipermail/python-win32/2004-June/002040.html http://code.activestate.com/recipes/302324-browser-automation-tool-py-class-file/ ''' from win32com.client import Dispatch import win32api, win32con,win32gui SHELL = Dispatch("Shell.Application") def get_ie(shell): for win in shell.Windows(): # print win if win.Name == "Windows Internet Explorer": return win return None def main(): ie = get_ie(SHELL) if ie: print ie.LocationURL print ie.LocationName print ie.ReadyState print ie print ie.Document.title print ie.Document.location print ie.Document.forms # title = win32gui.GetWindowText(ie) # print title else: print "no ie window" if __name__ == '__main__': main() From python.leojay at gmail.com Mon Nov 29 01:01:38 2010 From: python.leojay at gmail.com (Leo Jay) Date: Mon, 29 Nov 2010 14:01:38 +0800 Subject: How do you find out what's happening in a process? Message-ID: Hi all, I'd like to know how do you guys find out what's happening in your code if the process seems not work. In java, I will use jstack to check stacks of threads and lock status. But I don't know how to do it in python. -- Best Regards, Leo Jay From python at rcn.com Mon Nov 29 01:07:35 2010 From: python at rcn.com (Raymond Hettinger) Date: Sun, 28 Nov 2010 22:07:35 -0800 (PST) Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> <8b03c7fa-7751-4fc8-a518-caf3c9da515d@z9g2000yqz.googlegroups.com> Message-ID: <5ce6298b-56be-4d40-abe5-f18af83fe2b0@r31g2000prg.googlegroups.com> On Nov 28, 4:36?am, coldpizza wrote: > Did you try google code search? It is *not* the same as google code > hosting. > The site ishttp://www.google.com/codesearchand you can select Python > in the 'language' dropdown. Yes, I use Google's code search frequently and did try it for super(). However, you still need to drill into many of the hits manually, because it is difficult to disambiguate a single inheritance use of super() (which is very common) from a design with cooperative multiple inheritance. You have to read a lot of code and can still come up empty handed. Raymond From enleverLesX_XXmcX at XmclavXeauX.com.invalid Mon Nov 29 01:26:49 2010 From: enleverLesX_XXmcX at XmclavXeauX.com.invalid (Michel Claveau - MVP) Date: Mon, 29 Nov 2010 07:26:49 +0100 Subject: How do I get the URL of the active tab in Firefox/IE/Chrome? References: Message-ID: <4cf347aa$0$7701$ba4acef3@reader.news.orange.fr> Hello! > The "InternetExplorer.Application" automation object doesn't contain > any way to manipulate tabs directly False. Try this example: import win32com.client for instance in win32com.client.Dispatch('{9BA05972-F6A8-11CF-A442-00A0C90A8F39}'): print instance," URL :",instance.LocationURL @-salutations -- Michel Claveau From hemant.dmp at gmail.com Mon Nov 29 01:55:19 2010 From: hemant.dmp at gmail.com (BansalMaddy) Date: Sun, 28 Nov 2010 22:55:19 -0800 (PST) Subject: Help required with Tranformation of coordinate system References: <1e8c75f4-e5c8-4263-9f4c-34fff241725a@t35g2000yqj.googlegroups.com> Message-ID: <5f788fe7-eb82-4fb4-9476-ae95f3f89c2c@30g2000yql.googlegroups.com> On Nov 29, 2:03?am, Terry Reedy wrote: > On 11/28/2010 6:36 PM, BansalMaddy wrote: > > > hi all! > > i need a help in python! i am struggling to implement this since last > > 2/3 days. suppose i have a 2D plot (say y=x**2). > > now on the same plot i want to transform my origin of coordinate > > system to a point (x',y' on this curve and again create a new plot > > with origin at x',y') > > can somebody help me how can i offset my cordinate system ... > > Plot y-y' == (x-x')**2 - y' against x-x'. > > -- > Terry Jan Reedy Thanks for the reply, but i was looking for some built in function to offset coordinate system, because my problem is not very simple as i mentioned in my query, actually i need to plot some kind of closed loops. e..g 1. curve will be y=f(x) then i have to search for a point on y=f(x) curve and i have to plot another function y'=f(x'), where x' and y' are (-2x) and (-2y) repectively. 2. then again i hve to search for a pont on y'=f(x') and do some third kind of operations, on that. in that case if can shift my coordinate system to desired location on curve the computation becomes simpler. THanks again, hope i made myself clear :) From ben+python at benfinney.id.au Mon Nov 29 02:15:31 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 29 Nov 2010 18:15:31 +1100 Subject: Next Melbourne PUG meeting Monday 6th of December References: Message-ID: <87lj4c4n3g.fsf@benfinney.id.au> Richard Jones writes: > The Melbourne Python Users Group will be meeting 6PM next Monday, the > 6th of December at RMIT University. > > For details see http://bit.ly/mpug. Or for those who prefer their URLs to avoid unnecessary points of failure, that's . Hope to see you there! -- \ ?Killing the creator was the traditional method of patent | `\ protection? ?Terry Pratchett, _Small Gods_ | _o__) | Ben Finney From priyanka.2910 at gmail.com Mon Nov 29 02:23:24 2010 From: priyanka.2910 at gmail.com (Priyanka Kalpande) Date: Sun, 28 Nov 2010 23:23:24 -0800 (PST) Subject: Urgent requirement for Php Developer Message-ID: Urgent requirment for Python programmer. For the further details contact us on 9930698901 or eMail your resumes to hr.manager at pfhit.com From usernet at ilthio.net Mon Nov 29 02:28:24 2010 From: usernet at ilthio.net (Tim Harig) Date: Mon, 29 Nov 2010 07:28:24 +0000 (UTC) Subject: How do I get the URL of the active tab in Firefox/IE/Chrome? References: <4cf347aa$0$7701$ba4acef3@reader.news.orange.fr> Message-ID: On 2010-11-29, Michel Claveau - MVP wrote: > Hello! > >> The "InternetExplorer.Application" automation object doesn't contain >> any way to manipulate tabs directly > > False. Try this example: > import win32com.client > for instance in win32com.client.Dispatch('{9BA05972-F6A8-11CF-A442-00A0C90A8F39}'): > print instance," URL :",instance.LocationURL A Shell collection object != a InternetExplorer.Application object. The problem with using a ShellWindows object is that you could easily connect to the wrong instance, especially since the OP doesn't know the LocationURL of the instance that he is looking for. That is why I asked for clarification. Once we know what the OP is trying to do, we can make sure that he has a reliable method to connect to the proper instance. From michele.simionato at gmail.com Mon Nov 29 03:45:01 2010 From: michele.simionato at gmail.com (Michele Simionato) Date: Mon, 29 Nov 2010 00:45:01 -0800 (PST) Subject: STARTTLS extension not supported by server References: <6e4c8009-7d17-4d04-91dd-75e834b9cde0@o14g2000yqe.googlegroups.com> Message-ID: For future googlers: it turns out in my case the call to .starttls() was not needed: I removed it and everything worked. Dunno why I was there in the first place, the original code was written by somebody else. From simon at brunningonline.net Mon Nov 29 04:39:57 2010 From: simon at brunningonline.net (Simon Brunning) Date: Mon, 29 Nov 2010 09:39:57 +0000 Subject: remote control firefox with python In-Reply-To: <4cf273b9$0$19685$426a74cc@news.free.fr> References: <4cf273b9$0$19685$426a74cc@news.free.fr> Message-ID: On 28 November 2010 15:22, News123 wrote: > > I wondered whether there is a simpe way to > 'remote' control fire fox with python. Selenium might be worth a look, too: -- Cheers, Simon B. From dmw at coder.cl Mon Nov 29 04:50:51 2010 From: dmw at coder.cl (Daniel Molina Wegener) Date: Mon, 29 Nov 2010 06:50:51 -0300 Subject: remote control firefox with python References: <4cf273b9$0$19685$426a74cc@news.free.fr> <4cf2d07b$0$26085$426a74cc@news.free.fr> Message-ID: On Domingo 28 Noviembre 2010 18:58, News123 wrote: > On 11/28/2010 06:19 PM, Tim Harig wrote: >> On 2010-11-28, News123 wrote: >>> Thanks in advance for any pointers ideas. >> >> google XPCOM > thanks a lot For XPCOM (I've worked with it), you can try the following articles and references: "XPCOM" http://en.wikipedia.org/wiki/XPCOM "XPCOM Part 1: An introduction to XPCOM": http://www.ibm.com/developerworks/webservices/library/co-xpcom.html "XPCOM Part 2: XPCOM component basics": http://www.ibm.com/developerworks/webservices/library/co-xpcom2.html "XPCOM Part 3: Setting up XPCOM" http://www.ibm.com/developerworks/webservices/library/co-xpcom3.html "Mozilla Reference Documentation" https://developer.mozilla.org/en/XPCOM Best regards, -- Daniel Molina Wegener System Programmer & Web Developer Phone: +56 (2) 979-0277 | Blog: http://coder.cl/ From dmw at coder.cl Mon Nov 29 04:55:35 2010 From: dmw at coder.cl (Daniel Molina Wegener) Date: Mon, 29 Nov 2010 06:55:35 -0300 Subject: Standard module implementation References: <4cf2626e$0$21696$426a34cc@news.free.fr> Message-ID: On Domingo 28 Noviembre 2010 11:08, candide wrote: > I was wondering if all the standard module are implemented in C. For > instance, I can't find a C implementation for the minidom xml parser > under Python 2.6. If you are looking for a C implementation of DOM as Python Extension, you can try the lxml extension, which uses the LibXML2 bindings: http://codespeak.net/lxml/ Best regards, -- Daniel Molina Wegener System Programmer & Web Developer Phone: +56 (2) 979-0277 | Blog: http://coder.cl/ From vithyam6 at gmail.com Mon Nov 29 05:23:05 2010 From: vithyam6 at gmail.com (cinema) Date: Mon, 29 Nov 2010 02:23:05 -0800 (PST) Subject: EARN MONEY FROM FOREX TRADING ONLINE? Message-ID: http://forextradingonlinetoday.blogspot.com http://forextradingonlinetoday.blogspot.com http://forextradingonlinetoday.blogspot.com http://forextradingonlinetoday.blogspot.com http://forextradingonlinetoday.blogspot.com From michele.simionato at gmail.com Mon Nov 29 05:33:19 2010 From: michele.simionato at gmail.com (Michele Simionato) Date: Mon, 29 Nov 2010 02:33:19 -0800 (PST) Subject: Using property() to extend Tkinter classes but Tkinter classes are old-style classes? References: <1290977244.17714.1407556497@webmail.messagingengine.com> Message-ID: <053e6470-219d-4036-b5da-99d172654ff1@w18g2000vbe.googlegroups.com> On Nov 29, 12:15?am, Terry Reedy wrote: > On 11/28/2010 3:47 PM, pyt... at bdurham.com wrote: > > > I had planned on subclassing Tkinter.Toplevel() using property() to wrap > > access to properties like a window's title. > > After much head scratching and a peek at the Tkinter.py source, I > > realized that all Tkinter classes are old-style classes (even under > > Python 2.7). > > 1. Is there a technical reason why Tkinter classes are still old-style > > classes? > > To not break old code. Being able to break code by upgrading all classes > in the stdlib was one of the reasons for 3.x. > > -- > Terry Jan Reedy Notice that you can upgrade a Tkinter class to a new-style class simply by deriving from object. For instance you could define a new-style Label class as: class Label(Tkinter.Label, object): pass then you can attach properties to it. You have a good chance of not breaking anything in doing so, but you cannot know for sure unless you try. I don't know if Tkinter uses features of old-style classes which are inconsistent with new- style classes, but probably the answer is not much. Michele Simionato From michele.simionato at gmail.com Mon Nov 29 05:44:10 2010 From: michele.simionato at gmail.com (Michele Simionato) Date: Mon, 29 Nov 2010 02:44:10 -0800 (PST) Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> <4ceef381$0$1659$742ec2ed@news.sonic.net> <5c92a83e-9de1-4a03-828c-2cce79ce5a30@v17g2000prc.googlegroups.com> <4cf011b9$0$1619$742ec2ed@news.sonic.net> <87y68fwr89.fsf.mdw@metalzone.distorted.org.uk> <4cf0b232$0$1651$742ec2ed@news.sonic.net> <4cf18792$0$29997$c3e8da3$5496439d@news.astraweb.com> <87bp59vbyp.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <77166587-7dd8-43a2-8f48-7d2a90abd79f@e4g2000vbi.googlegroups.com> On Nov 28, 2:01?pm, m... at distorted.org.uk (Mark Wooding) wrote: > Steve Holden writes: > > It isn't. Even inheritance itself isn't as useful as it at first > > appears, and composition turns out in practice to be much more useful. > > That goes double for multiple inheritance. > > Composition /with a convenient notation for delegation/ works fairly > well. ?Indeed, this can be seen as the basis of Self. ?But downwards > delegation -- where a superclass leaves part of its behaviour > unspecified and requires (concrete) subclasses to fill in the resulting > blanks -- is hard to express like this without some kind of means of > identifying the original recipient of the delegated message. ?Once > you've done that, there isn't much of a difference between a superclass > and a component with implicit delegation. > > -- [mdw] For a long time I had the feeling that in a language with pattern matching inheritance (both single and double) is basically useless. You can easily define objects as functions responding to messages and classes becomes useless. However I have never implemented a large project with such techniques, so I am not sure how much my gut feeling is sound. Apparently here at work we are going to use Erlang in the near future and I hope to get my hand dirty and see in practice how well one can work with a language without inheritance. BTW, is there anybody here with experience on such languages and caring to share his learned lessons? Michele Simionato From nawijn at gmail.com Mon Nov 29 06:27:11 2010 From: nawijn at gmail.com (Marco Nawijn) Date: Mon, 29 Nov 2010 03:27:11 -0800 (PST) Subject: Comparing floats References: Message-ID: On 29 nov, 00:20, Nobody wrote: > On Sat, 27 Nov 2010 18:23:48 -0500, Terry Reedy wrote: > >> Therefore, to implement this multiplication operation I need to have a > >> way to verify that the float tuples C and D are "equal". > > > I might try the average relative difference: > > sum(abs((i-j)/(i+j)) for i,j in zip(C,D))/n # assuming lengths constant > > The division is unstable if i and j are close to zero. > > For scalars, I'd use: > > ? ? ? ? abs(i-j) <= epsilon * (1 + abs(i+j)) > > This amounts to a relative error check for large values and an absolute > error check for values close to zero. > > For a vector, I'd check that the above holds for all pairs. Hi All, Why don't you treat the C and D tuples as vectors? You can than check dot product and norm (length) for equality. Using scipy (www.scipy.org), you even get very nice performance. Marco From rustompmody at gmail.com Mon Nov 29 06:31:56 2010 From: rustompmody at gmail.com (rustom) Date: Mon, 29 Nov 2010 03:31:56 -0800 (PST) Subject: TDD in python References: Message-ID: On Nov 28, 7:52?pm, Stefan Behnel wrote: > Rustom Mody, 28.11.2010 11:58: > > > Does anyone know of something like this for python? > > >http://www.vimeo.com/13240481 > > The page seems to require a recent version of the Flash player. Could you > describe what exactly you are looking for? > > Stefan Well most modern languages have TDD frameworks. However TDD is learnt by doing and not from books (like swimming/ cycling). This screencast gives a detailed demo of *doing it* in eclipse/C++ I was hoping for something similar for python From kent37 at tds.net Mon Nov 29 06:51:51 2010 From: kent37 at tds.net (Kent Johnson) Date: Mon, 29 Nov 2010 03:51:51 -0800 (PST) Subject: Python 2.7.1 References: Message-ID: <80faa2c4-11ca-4b7e-9f66-01c1cb75a61b@fj16g2000vbb.googlegroups.com> On Nov 27, 11:33?pm, Benjamin Peterson wrote: > On behalf of the Python development team, I'm happy as a clam to announce the > immediate availability of Python 2.7.1. Will there be Mac binaries for 2.7.1 and 3.1.3? Currently the web site shows only source and Windows binaries. Thanks, Kent From andre.roberge at gmail.com Mon Nov 29 06:59:05 2010 From: andre.roberge at gmail.com (=?ISO-8859-1?Q?Andr=E9?=) Date: Mon, 29 Nov 2010 03:59:05 -0800 (PST) Subject: TDD in python References: Message-ID: <0906c010-709d-41d9-8b29-2f42afb87f94@32g2000yqz.googlegroups.com> On Nov 29, 7:31?am, rustom wrote: > On Nov 28, 7:52?pm, Stefan Behnel wrote: > > > Rustom Mody, 28.11.2010 11:58: > > > > Does anyone know of something like this for python? > > > >http://www.vimeo.com/13240481 > > > The page seems to require a recent version of the Flash player. Could you > > describe what exactly you are looking for? > > > Stefan > > Well most modern languages have TDD frameworks. > However TDD is learnt by doing and not from books (like swimming/ > cycling). > This screencast gives a detailed demo of *doing it* in eclipse/C++ > I was hoping for something similar for python Go to showmedo.com and do a search for "python tdd"; you'll find many such screencasts. Andr? From hv at tbz-pariv.de Mon Nov 29 08:50:50 2010 From: hv at tbz-pariv.de (Thomas Guettler) Date: Mon, 29 Nov 2010 14:50:50 +0100 Subject: hashlib in one line Message-ID: <8lhpcfF65iU1@mid.individual.net> Hi, I think it would be nice if you could use the hashlib in one line: hashlib.sha256().update('abc').hexdigest() Unfortunately update() returns None. Is there a way to convert a string to the hexdigest of sha256 in one line? Thomas -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de From gerlach_joerg at web.de Mon Nov 29 08:54:58 2010 From: gerlach_joerg at web.de (J. Gerlach) Date: Mon, 29 Nov 2010 14:54:58 +0100 Subject: hashlib in one line In-Reply-To: <8lhpcfF65iU1@mid.individual.net> References: <8lhpcfF65iU1@mid.individual.net> Message-ID: Am 29.11.2010 14:50, schrieb Thomas Guettler: > Hi, > > I think it would be nice if you could use the hashlib in one line: > > hashlib.sha256().update('abc').hexdigest() > > Unfortunately update() returns None. > > Is there a way to convert a string to the hexdigest of sha256 in one line? > > Thomas > > Yeah, something like this would be nice: ;) hashlib.sha256('abc').hexdigest() (tested in 2.6.6) From stefan.sonnenberg at pythonmeister.com Mon Nov 29 09:01:41 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Mon, 29 Nov 2010 15:01:41 +0100 Subject: hashlib in one line In-Reply-To: <8lhpcfF65iU1@mid.individual.net> References: <8lhpcfF65iU1@mid.individual.net> Message-ID: <4CF3B245.6030204@pythonmeister.com> Am 29.11.2010 14:50, schrieb Thomas Guettler: > Hi, > > I think it would be nice if you could use the hashlib in one line: > > hashlib.sha256().update('abc').hexdigest() > > Unfortunately update() returns None. > > Is there a way to convert a string to the hexdigest of sha256 in one line? > > Thomas > > Like so ? >>> hashlib.sha256('abc').hexdigest() 'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad' From python at bdurham.com Mon Nov 29 09:09:07 2010 From: python at bdurham.com (python at bdurham.com) Date: Mon, 29 Nov 2010 09:09:07 -0500 Subject: Using property() to extend Tkinter classes but Tkinter classes are old-style classes? In-Reply-To: <053e6470-219d-4036-b5da-99d172654ff1@w18g2000vbe.googlegroups.com> References: <1290977244.17714.1407556497@webmail.messagingengine.com> <053e6470-219d-4036-b5da-99d172654ff1@w18g2000vbe.googlegroups.com> Message-ID: <1291039747.28741.1407672133@webmail.messagingengine.com> Michele and Terry, > From: "Michele Simionato" > > Notice that you can upgrade a Tkinter class to a new-style class simply by deriving from object. For instance you could define a new-style Label class as: > > class Label(Tkinter.Label, object): > pass Michele - your technique is *exactly* what I was searching for (and works well so far!). Terry - your explanation why Tkinter still uses old style classes (for compatibility with existing code) makes sense. Thank you both. Malcolm From hv at tbz-pariv.de Mon Nov 29 09:14:03 2010 From: hv at tbz-pariv.de (Thomas Guettler) Date: Mon, 29 Nov 2010 15:14:03 +0100 Subject: hashlib in one line In-Reply-To: References: <8lhpcfF65iU1@mid.individual.net> Message-ID: <8lhqnvFek9U1@mid.individual.net> Thank you, I was blind: See "condensed": http://docs.python.org/library/hashlib.html Stefan Sonnenberg-Carstens wrote: > Am 29.11.2010 14:50, schrieb Thomas Guettler: >> Hi, >> >> I think it would be nice if you could use the hashlib in one line: >> >> hashlib.sha256().update('abc').hexdigest() >> >> Unfortunately update() returns None. >> >> Is there a way to convert a string to the hexdigest of sha256 in one >> line? >> >> Thomas >> >> > Like so ? > >>>> hashlib.sha256('abc').hexdigest() > 'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad' -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de From xi at gamma.dn.ua Mon Nov 29 10:00:48 2010 From: xi at gamma.dn.ua (Kirill Simonov) Date: Mon, 29 Nov 2010 10:00:48 -0500 Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance In-Reply-To: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> Message-ID: <4CF3C020.5000306@gamma.dn.ua> Hi Raymond, Another example: extensions in Mercurial. Mercurial is a VCS with a typical command line syntax: $ hg Mercurial has an extension mechanism for adding new and modifying existing commands. A big chunk of Mercurial functionality is implemented in `ui` and `repo` classes and extensions often patch those to override the default behavior. For instance, you could check the `color` extension, which patches `ui` to override `write*` methods: http://selenic.com/hg/file/3790452d499b/hgext/color.py#l152 Thanks, Kirill On 11/24/2010 03:08 PM, Raymond Hettinger wrote: > I'm writing-up more guidance on how to use super() and would like to > point at some real-world Python examples of cooperative multiple > inheritance. > > Google searches take me to old papers for C++ and Eiffel, but that > don't seem to be relevant to most Python programmers (i.e. a > WalkingMenu example where a submenu is both a Entry in a Menu and a > Menu itself). Another published example is in a graphic library where > some widgets inherit GraphicalFeature methods such as location, size > and NestingGroupingFeatures such as finding parents, siblings, and > children. I don't find either of those examples compelling because > there is no particular reason that they would have to have overlapping > method names. > > So far, the only situation I can find where method names necessarily > overlap is for the basics like __init__(), close(), flush(), and > save() where multiple parents need to have their own initialization > and finalization. > > If you guys know of good examples, I would appreciate a link or a > recap. > > Thanks, > > > Raymond > From klausfpga at gmail.com Mon Nov 29 10:11:29 2010 From: klausfpga at gmail.com (klausfpga) Date: Mon, 29 Nov 2010 07:11:29 -0800 (PST) Subject: How to start a windows application minimized (or hidden) Message-ID: Hi, I'd like to start a windows application minimized As an example I used calc.exe what I tried was using the startupinfo field of subprocess.Popen though I'm not sure, that 'hidden' is really the same as minimized. st_info = subprocess.STARTUPINFO() st_info.dwFlags |= subprocess.STARTF_USESHOWWINDOW st_info.wShowWindow = subprocess.SW_HIDE proc = Popen( [ "cmd.exe" ], startupinfo = st_info) I also tried creating a shortut of calc on my desktop and setting it to 'start minimized' if I click on the shortcut, then calc.exe shows up as a visible window What am I doing wrong/ Thanks in advance for any ideas somehow I do not see, that From ulrich.eckhardt at dominolaser.com Mon Nov 29 10:40:43 2010 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Mon, 29 Nov 2010 16:40:43 +0100 Subject: How do you find out what's happening in a process? References: Message-ID: Leo Jay wrote: > I'd like to know how do you guys find out what's happening in your > code if the process seems not work. > In java, I will use jstack to check stacks of threads and lock > status. But I don't know how to do it in python. import pdb pdb.set_trace() Generally, searching "python debugger howto" should turn up a few useful results. ;) Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From g.rodola at gmail.com Mon Nov 29 10:48:11 2010 From: g.rodola at gmail.com (=?ISO-8859-1?Q?Giampaolo_Rodol=E0?=) Date: Mon, 29 Nov 2010 16:48:11 +0100 Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance In-Reply-To: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> Message-ID: 2010/11/24 Raymond Hettinger : > I'm writing-up more guidance on how to use super() and would like to > point at some real-world Python examples of cooperative multiple > inheritance. > > Google searches take me to old papers for C++ and Eiffel, but that > don't seem to be relevant to most Python programmers (i.e. a > WalkingMenu example where a submenu is both a Entry in a Menu and a > Menu itself). ?Another published example is in a graphic library where > some widgets inherit GraphicalFeature methods such as location, size > and NestingGroupingFeatures such as finding parents, siblings, and > children. ?I don't find either of those examples compelling because > there is no particular reason that they would have to have overlapping > method names. > > So far, the only situation I can find where method names necessarily > overlap is for the basics like __init__(), close(), flush(), and > save() where multiple parents need to have their own initialization > and finalization. > > If you guys know of good examples, I would appreciate a link or a > recap. > > Thanks, > > > Raymond > > -- > http://mail.python.org/mailman/listinfo/python-list > In pyftpdlib I used multiple inheritance to implement FTP over SSL: http://code.google.com/p/pyftpdlib/source/browse/tags/release-0.5.2/demo/tls_ftpd.py#125 I can't say it's been natural/intuitive though, and it took me a while to make it work properly. super() is one of the few things in Python I really don't understand properly. --- Giampaolo http://code.google.com/p/pyftpdlib/ http://code.google.com/p/psutil/ From joe at goldthwaites.com Mon Nov 29 11:20:20 2010 From: joe at goldthwaites.com (Joe Goldthwaite) Date: Mon, 29 Nov 2010 09:20:20 -0700 Subject: Parsing markup. In-Reply-To: <4CEF318F.2090308@mrabarnett.plus.com> References: <4CEF318F.2090308@mrabarnett.plus.com> Message-ID: <2545A800F14347C3BF4847C7844377C4@NewMBP> Hi MRAB, I was trying to avoid regex because my poor old brain has trouble with it. I have to admin though, that line is slick! I'll have to go through my regex documentation to try and figure out what it actually means. Thanks! -----Original Message----- From: python-list-bounces+joe=goldthwaites.com at python.org [mailto:python-list-bounces+joe=goldthwaites.com at python.org] On Behalf Of MRAB Sent: Thursday, November 25, 2010 9:03 PM To: python-list at python.org Subject: Re: Parsing markup. On 26/11/2010 03:28, Joe Goldthwaite wrote: > I'm attempting to parse some basic tagged markup. The output of the > TinyMCE editor returns a string that looks something like this; > >

This is a paragraph with bold and italic elements in > it

It can be made up of multiple lines separated by pagagraph > tags.

> > I'm trying to render the paragraph into a bit mapped image. I need > to parse it out into the various paragraph and bold/italic pieces. > I'm not sure the best way to approach it. Elementree and lxml seem > to want a full formatted page, not a small segment like this one. > When I tried to feed a line similar to the above to lxml I got an > error; "XMLSyntaxError: Extra content at the end of the document". > I'd probably use a regex: >>> import re >>> text = "

This is a paragraph with bold and italic elements in it

It can be made up of multiple lines separated by pagagraph tags.

" >>> re.findall(r"|[^<>]+", text) ['

', 'This is a paragraph with ', '', 'bold', '', ' and ', '', 'italic', '', ' elements in it', '

', '

', 'It can be made up of multiple lines separated by pagagraph tags.', '

'] -- http://mail.python.org/mailman/listinfo/python-list From stefan_ml at behnel.de Mon Nov 29 11:34:10 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 29 Nov 2010 17:34:10 +0100 Subject: Parsing markup. In-Reply-To: <9cb996fe-39b0-4780-bd56-5323b7269b0f@t8g2000prh.googlegroups.com> References: <9cb996fe-39b0-4780-bd56-5323b7269b0f@t8g2000prh.googlegroups.com> Message-ID: Jon Clements, 26.11.2010 13:58: > On Nov 26, 4:03 am, MRAB wrote: >> On 26/11/2010 03:28, Joe Goldthwaite wrote: >> > I?m attempting to parse some basic tagged markup. The output of the >> > TinyMCE editor returns a string that looks something like this; >> > >> >

This is a paragraph withbold anditalic elements in >> > it

It can be made up of multiple lines separated by pagagraph >> > tags.

>> > >> > I?m trying to render the paragraph into a bit mapped image. I need >> > to parse it out into the various paragraph and bold/italic pieces. >> > I?m not sure the best way to approach it. Elementree and lxml seem >> > to want a full formatted page, not a small segment like this one. >> > When I tried to feed a line similar to the above to lxml I got an >> > error; ?XMLSyntaxError: Extra content at the end of the document?. This exception indicates that the OP is using the XML parser. > lxml works fine for me - have you tried: > > from lxml import html > text = "

This is a paragraph withbold anditalic > elements in it

It can be made up of multiple lines separated by > pagagraph tags.

" > tree = html.fromstring(text) > print tree.findall('p') > # should print [,] Yep, either use lxml.etree's HTML parser or lxml.html. Stefan From michele.simionato at gmail.com Mon Nov 29 11:53:09 2010 From: michele.simionato at gmail.com (Michele Simionato) Date: Mon, 29 Nov 2010 08:53:09 -0800 (PST) Subject: How do you find out what's happening in a process? References: Message-ID: On Nov 29, 7:01?am, Leo Jay wrote: > Hi all, > > I'd like to know how do you guys find out what's happening in your > code if the process seems not work. > In java, I will use jstack to check stacks of threads and lock status. > But I don't know how to do it in python. > > -- > Best Regards, > Leo Jay If you give a CTRL-C the Python process will die with a traceback showing the line where the process got stuck (assuming you started it from the command-line). You can even run the script under the debugger and give a CTRL-C after a while, as follows: $ python -m pdb thescript.py (Pdb) c CTRL-C Traceback ... ... (Pdb) From tinauser at libero.it Mon Nov 29 13:12:53 2010 From: tinauser at libero.it (tinauser) Date: Mon, 29 Nov 2010 10:12:53 -0800 (PST) Subject: sqlite autoincrement of primary key Message-ID: Dear List I'm writing an application that has to create and populate an SQLite database. I'm doing pretty well, but now I'm facing a problem I can not solve. I create a table with a primary key autoincrement, something like sqlcmd="CREATE TABLE foo (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)" cur.execute(sqlcmd) Now comes the time of populating the database. I perfectly know that if I do something like: sqlcmd="INSERT INTO foo (name) VALUES (?))" cur.execute(sqlcmd, ('xxx',)) The table will automatically insert the value of id. However, for readibility problem, I need to use the sqlite insert command giving all the entries. I want, however, to let sqlite to handle the primary key. Normally, the sqlite command that works would be INSERT INTO 'foo' VALUES (NULL, 'yyy' ) however, if in python i try to execute a script like: cur.execute( ''' INSERT INTO 'foo' VALUES (?,?) ''' ,('NULL','yyy')) I get a datatype mismatch error. Has anyone a workaround ? From mwilson at the-wire.com Mon Nov 29 13:19:19 2010 From: mwilson at the-wire.com (Mel) Date: Mon, 29 Nov 2010 13:19:19 -0500 Subject: sqlite autoincrement of primary key References: Message-ID: tinauser wrote: > Normally, the sqlite command that works would be > > INSERT INTO 'foo' VALUES (NULL, 'yyy' ) > > however, if in python i try to execute a script like: > > cur.execute( > ''' > INSERT INTO 'foo' VALUES (?,?) > ''' > ,('NULL','yyy')) > > I get a datatype mismatch error. > > Has anyone a workaround ? Have you tried '''INSERT INTO foo VALUES (NULL, ?)''' Mel. From john at castleamber.com Mon Nov 29 13:25:53 2010 From: john at castleamber.com (John Bokma) Date: Mon, 29 Nov 2010 12:25:53 -0600 Subject: sqlite autoincrement of primary key References: Message-ID: <87y68cyojy.fsf@castleamber.com> tinauser writes: > however, if in python i try to execute a script like: > > cur.execute( > ''' > INSERT INTO 'foo' VALUES (?,?) > ''' > ,('NULL','yyy')) ,(None, 'yyy')) Or use VALUES(NULL, ?) as suggested in another post. -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From usernet at ilthio.net Mon Nov 29 13:28:22 2010 From: usernet at ilthio.net (Tim Harig) Date: Mon, 29 Nov 2010 18:28:22 +0000 (UTC) Subject: sqlite autoincrement of primary key References: Message-ID: On 2010-11-29, tinauser wrote: > ''' > INSERT INTO 'foo' VALUES (?,?) > ''' > ,('NULL','yyy')) s/'NULL'/None/ > I get a datatype mismatch error. The sqlite module is smart enough to convert between Python types and Sqlite types. If you pass it 'NULL' it thinks you are passing it a string. Python uses None in much the same way that databases use NULL, so the module converts None to 'NULL' and vise versa. From darcy at druid.net Mon Nov 29 13:46:00 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Mon, 29 Nov 2010 13:46:00 -0500 Subject: sqlite autoincrement of primary key In-Reply-To: References: Message-ID: <20101129134600.e1f70d73.darcy@druid.net> On Mon, 29 Nov 2010 13:19:19 -0500 Mel wrote: > tinauser wrote: > '''INSERT INTO foo VALUES (NULL, ?)''' Does this work in SQLite: INSERT INTO foo (name) VALUES ('xxx') That's the standard SQL way. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From alice at gothcandy.com Mon Nov 29 13:47:02 2010 From: alice at gothcandy.com (=?utf-8?Q?Alice_Bevan=E2=80=93McGregor?=) Date: Mon, 29 Nov 2010 10:47:02 -0800 Subject: Strategies for unit testing an HTTP server. Message-ID: Hello! Two things are missing from the web server I've been developing before I can release 1.0: unit tests and documentation. Documentation being entirely my problem, I've run into a bit of a snag with unit testing; just how would you go about it? Specifically, I need to test things like HTTP/1.0 request/response cycles, HTTP/1.0 keep-alives, HTTP/1.1 pipelined reuqest/response cycles, HTTP/1.1 connection: close, HTTP/1.1 chunked requests/responses, etc. What is the recommended / best way to test a daemon in Python? (Note that some of the tests need to keep the "client" socket open.) Is there an easy way to run a daemon in another thread, then kill it after running some tests across it? Even better, are there any dedicated (Python or non-Python) HTTP/1.1 compliance testing suites? Thank you for any assistance, ? Alice. From usernet at ilthio.net Mon Nov 29 14:11:18 2010 From: usernet at ilthio.net (Tim Harig) Date: Mon, 29 Nov 2010 19:11:18 +0000 (UTC) Subject: sqlite autoincrement of primary key References: Message-ID: On 2010-11-29, D'Arcy J.M. Cain wrote: > On Mon, 29 Nov 2010 13:19:19 -0500 > Mel wrote: >> tinauser wrote: >> '''INSERT INTO foo VALUES (NULL, ?)''' > > Does this work in SQLite: > > INSERT INTO foo (name) VALUES ('xxx') > > That's the standard SQL way. Yes, it works; but, the OP asked specifically to be able to enter all of the field values, including the autoincrement field. From tinauser at libero.it Mon Nov 29 14:25:34 2010 From: tinauser at libero.it (tinauser) Date: Mon, 29 Nov 2010 11:25:34 -0800 (PST) Subject: sqlite autoincrement of primary key References: Message-ID: <99c2549a-75bf-49a6-be3d-cf202dabcc79@n30g2000vbb.googlegroups.com> On Nov 29, 7:28?pm, Tim Harig wrote: > On 2010-11-29, tinauser wrote: > > > ''' > > INSERT INTO 'foo' VALUES (?,?) > > ''' > > ,('NULL','yyy')) > > s/'NULL'/None/ > > > I get a datatype mismatch error. > > The sqlite module is smart enough to convert between Python types and > Sqlite types. ?If you pass it 'NULL' it thinks you are passing it a string. > Python uses None in much the same way that databases use NULL, so the > module converts None to 'NULL' and vise versa. Thanks all of you for the fast answers! From tjreedy at udel.edu Mon Nov 29 14:33:02 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 29 Nov 2010 14:33:02 -0500 Subject: Help required with Tranformation of coordinate system In-Reply-To: <5f788fe7-eb82-4fb4-9476-ae95f3f89c2c@30g2000yql.googlegroups.com> References: <1e8c75f4-e5c8-4263-9f4c-34fff241725a@t35g2000yqj.googlegroups.com> <5f788fe7-eb82-4fb4-9476-ae95f3f89c2c@30g2000yql.googlegroups.com> Message-ID: On 11/29/2010 1:55 AM, BansalMaddy wrote: > On Nov 29, 2:03 am, Terry Reedy wrote: >> On 11/28/2010 6:36 PM, BansalMaddy wrote: >> >>> hi all! >>> i need a help in python! i am struggling to implement this since last >>> 2/3 days. suppose i have a 2D plot (say y=x**2). >>> now on the same plot i want to transform my origin of coordinate >>> system to a point (x',y' on this curve and again create a new plot >>> with origin at x',y') >>> can somebody help me how can i offset my cordinate system ... >> >> Plot y-y' == (x-x')**2 - y' against x-x'. >> >> -- >> Terry Jan Reedy > > Thanks for the reply, but i was looking for some built in function to > offset coordinate system, because my problem is not very simple as i > mentioned in my query, actually i need to plot some kind of closed > loops. > e..g > 1. curve will be y=f(x) then i have to search for a point on y=f(x) > curve and i have to plot another function y'=f(x'), where x' and y' > are (-2x) and (-2y) repectively. > 2. then again i hve to search for a pont on y'=f(x') and do some third > kind of operations, on that. > in that case if can shift my coordinate system to desired location on > curve the computation becomes simpler. > > THanks again, hope i made myself clear :) You would have to look at the docs for particular third-party plotting libraries, such as you might find on PyPI. -- Terry Jan Reedy From tjreedy at udel.edu Mon Nov 29 14:35:21 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 29 Nov 2010 14:35:21 -0500 Subject: Python 2.7.1 In-Reply-To: <80faa2c4-11ca-4b7e-9f66-01c1cb75a61b@fj16g2000vbb.googlegroups.com> References: <80faa2c4-11ca-4b7e-9f66-01c1cb75a61b@fj16g2000vbb.googlegroups.com> Message-ID: On 11/29/2010 6:51 AM, Kent Johnson wrote: > On Nov 27, 11:33 pm, Benjamin Peterson wrote: >> On behalf of the Python development team, I'm happy as a clam to announce the >> immediate availability of Python 2.7.1. > > Will there be Mac binaries for 2.7.1 and 3.1.3? Currently the web site > shows only source and Windows binaries. I presume yes. Mac binaries typically trail each release. They are done by a different volunteer. -- Terry Jan Reedy From ameyer2 at yahoo.com Mon Nov 29 15:28:22 2010 From: ameyer2 at yahoo.com (Alan Meyer) Date: Mon, 29 Nov 2010 15:28:22 -0500 Subject: sqlite autoincrement of primary key In-Reply-To: References: Message-ID: <4CF40CE6.4090008@yahoo.com> On 11/29/2010 1:12 PM, tinauser wrote: > Dear List > I'm writing an application that has to create and populate an SQLite > database. > I'm doing pretty well, but now I'm facing a problem I can not solve. > > I create a table with a primary key autoincrement, something like > > sqlcmd="CREATE TABLE foo (id INTEGER PRIMARY KEY AUTOINCREMENT, name > TEXT)" > cur.execute(sqlcmd) > > Now comes the time of populating the database. > I perfectly know that if I do something like: > > sqlcmd="INSERT INTO foo (name) VALUES (?))" > cur.execute(sqlcmd, ('xxx',)) > The table will automatically insert the value of id. > > > However, for readibility problem, I need to use the sqlite insert > command giving all the entries. I want, however, to let sqlite to > handle the primary key. > Normally, the sqlite command that works would be > > INSERT INTO 'foo' VALUES (NULL, 'yyy' ) > > however, if in python i try to execute a script like: > > cur.execute( > ''' > INSERT INTO 'foo' VALUES (?,?) > ''' > ,('NULL','yyy')) > > I get a datatype mismatch error. > > Has anyone a workaround ? There are two red flags popping up for me here. The first is your switch from: "INSERT INTO foo ..." to "INSERT INTO 'foo' ..." I don't know sqllite, however, quotes around the foo is not standard SQL and should cause an error. "datatype mismatch" is not exactly the message I'd expect, but it could be appropriate. The second red flag is your desire to increase readability by inserting something into an auto-increment field. That might just confuse me if I were reading it and knew that NULL (or None) is an invalid and inappropriate value for that column. To me at least, readability is reduced by that, not increased. I'm a little surprised that sqllite would accept it no matter how you did it. You could do something like this: INSERT INTO foo (name) VALUES ('whatever') as another poster suggested. That seems to me more readable than leaving out the column name list but including an auto-increment field in the values list. It gives more, and more valid, information to the programmer who reads your code. Alan From chris at simplistix.co.uk Mon Nov 29 15:41:49 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 29 Nov 2010 20:41:49 +0000 Subject: Use company name for module In-Reply-To: References: Message-ID: <4CF4100D.1090901@simplistix.co.uk> On 12/11/2010 15:50, Robert Kern wrote: > On 11/12/10 8:12 AM, Micah Carrick wrote: >> My company is working on releasing some of our code as open-source python >> modules. I don't want my "foo" module conflicting with other modules >> called >> "foo" on PyPi or github or a user's system. Is there anything wrong, >> from a >> conventions standpoint, with having modules like company.foo and >> company.bar >> even if foo and bar are not necessarily related other than being >> released by us? >> I really don't like the cryptic module names or things like foo2 and >> the like. > > Yes, using namespace packages. You need to use `distribute` in your > setup.py in order to accomplish this. > > http://pypi.python.org/pypi/distribute/ > http://packages.python.org/distribute/setuptools.html#namespace-packages ...or setuptools. ...or just pick a different naming scheme, the Pyramid guys have gone for: company_foo ...and I'm inclined to do the same. Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From jkpeck at gmail.com Mon Nov 29 16:23:37 2010 From: jkpeck at gmail.com (JKPeck) Date: Mon, 29 Nov 2010 13:23:37 -0800 (PST) Subject: Use company name for module References: Message-ID: <220f0536-5a41-4e15-8e77-f6ec2fec513e@j18g2000prn.googlegroups.com> On Nov 29, 1:41?pm, Chris Withers wrote: > On 12/11/2010 15:50, Robert Kern wrote: > > > > > On 11/12/10 8:12 AM, Micah Carrick wrote: > >> My company is working on releasing some of our code as open-source python > >> modules. I don't want my "foo" module conflicting with other modules > >> called > >> "foo" on PyPi or github or a user's system. Is there anything wrong, > >> from a > >> conventions standpoint, with having modules like company.foo and > >> company.bar > >> even if foo and bar are not necessarily related other than being > >> released by us? > >> I really don't like the cryptic module names or things like foo2 and > >> the like. > > > Yes, using namespace packages. You need to use `distribute` in your > > setup.py in order to accomplish this. > > >http://pypi.python.org/pypi/distribute/ > >http://packages.python.org/distribute/setuptools.html#namespace-packages > > ...or setuptools. > > ...or just pick a different naming scheme, the Pyramid guys have gone for: > > company_foo > > ...and I'm inclined to do the same. > > Chris > > -- > Simplistix - Content Management, Batch Processing & Python Consulting > ? ? ? ? ? ? -http://www.simplistix.co.uk You might want to check with your company legal folks before adopting a naming rule base on the company name. Some companies whose names are trademarked will not allow their name to be used in certain contexts, possibly including this. (I am not a lawyer!) From drsalists at gmail.com Mon Nov 29 16:44:56 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 29 Nov 2010 13:44:56 -0800 Subject: Reading lines of null-terminated text? Message-ID: What's the best way of reading lines of null terminated (ASCII NUL, \0) text in Python 2.x? How about for 3.x? I've been using http://stromberg.dnsalias.org/~strombrg/readline0.html with 2.x, but I'm moving some of my stuff to 3.x, and am wondering if there's a way that would obviate readline0. TIA! -------------- next part -------------- An HTML attachment was scrubbed... URL: From darcy at druid.net Mon Nov 29 16:49:31 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Mon, 29 Nov 2010 16:49:31 -0500 Subject: sqlite autoincrement of primary key In-Reply-To: References: Message-ID: <20101129164931.8930f894.darcy@druid.net> On Mon, 29 Nov 2010 19:11:18 +0000 (UTC) Tim Harig wrote: > > INSERT INTO foo (name) VALUES ('xxx') > > > > That's the standard SQL way. > > Yes, it works; but, the OP asked specifically to be able to enter all of > the field values, including the autoincrement field. You're right, I missed that. However reading the OP's message I am still confused. How does removing the field name and adding a positional NULL or None improve readability. I now wonder if it was more of an assignment requirement rather than a real one. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From usernet at ilthio.net Mon Nov 29 16:58:29 2010 From: usernet at ilthio.net (Tim Harig) Date: Mon, 29 Nov 2010 21:58:29 +0000 (UTC) Subject: sqlite autoincrement of primary key References: Message-ID: On 2010-11-29, D'Arcy J.M. Cain wrote: > On Mon, 29 Nov 2010 19:11:18 +0000 (UTC) > Tim Harig wrote: >> > INSERT INTO foo (name) VALUES ('xxx') >> > >> > That's the standard SQL way. >> >> Yes, it works; but, the OP asked specifically to be able to enter all of >> the field values, including the autoincrement field. > > You're right, I missed that. However reading the OP's message I am > still confused. How does removing the field name and adding a > positional NULL or None improve readability. I now wonder if it was > more of an assignment requirement rather than a real one. That, I don't know. I would agree that it seems like a mis-guided approach; but, it is what he asked for. From hemant.dmp at gmail.com Mon Nov 29 17:06:10 2010 From: hemant.dmp at gmail.com (BansalMaddy) Date: Mon, 29 Nov 2010 14:06:10 -0800 (PST) Subject: Help required with Tranformation of coordinate system References: <1e8c75f4-e5c8-4263-9f4c-34fff241725a@t35g2000yqj.googlegroups.com> <5f788fe7-eb82-4fb4-9476-ae95f3f89c2c@30g2000yql.googlegroups.com> Message-ID: On Nov 29, 8:33?pm, Terry Reedy wrote: > On 11/29/2010 1:55 AM, BansalMaddy wrote: > > > > > On Nov 29, 2:03 am, Terry Reedy ?wrote: > >> On 11/28/2010 6:36 PM, BansalMaddy wrote: > > >>> hi all! > >>> i need a help in python! i am struggling to implement this since last > >>> 2/3 days. suppose i have a 2D plot (say y=x**2). > >>> now on the same plot i want to transform my origin of coordinate > >>> system to a point (x',y' on this curve and again create a new plot > >>> with origin at x',y') > >>> can somebody help me how can i offset my cordinate system ... > > >> Plot y-y' == (x-x')**2 - y' against x-x'. > > >> -- > >> Terry Jan Reedy > > > Thanks for the reply, but i was looking for some built in function to > > offset coordinate system, because my problem is not very simple as i > > mentioned in my query, actually i need to plot some kind of closed > > loops. > > e..g > > 1. curve will be y=f(x) then i have to search for a point on y=f(x) > > curve and i have to plot another function y'=f(x'), where x' and y' > > are (-2x) and (-2y) repectively. > > 2. then again i hve to search for a pont on y'=f(x') and do some third > > kind of operations, on that. > > in that case if can shift my coordinate system to desired location on > > curve the computation becomes simpler. > > > THanks again, hope i made myself clear :) > > You would have to look at the docs for particular third-party plotting > libraries, such as you might find on PyPI. > > -- > Terry Jan Reedy OK thanks From tinauser at libero.it Mon Nov 29 17:19:30 2010 From: tinauser at libero.it (tinauser) Date: Mon, 29 Nov 2010 14:19:30 -0800 (PST) Subject: sqlite autoincrement of primary key References: Message-ID: <34b9f7a8-9a91-436d-9cbf-96fa91268555@s4g2000yql.googlegroups.com> On Nov 29, 10:49?pm, "D'Arcy J.M. Cain" wrote: > On Mon, 29 Nov 2010 19:11:18 +0000 (UTC) > > Tim Harig wrote: > > > ? INSERT INTO foo (name) VALUES ('xxx') > > > > That's the standard SQL way. > > > Yes, it works; but, the OP asked specifically to be able to enter all of > > the field values, including the autoincrement field. > > You're right, I missed that. ?However reading the OP's message I am > still confused. ?How does removing the field name and adding a > positional NULL or None improve readability. ?I now wonder if it was > more of an assignment requirement rather than a real one. > > -- > D'Arcy J.M. Cain ? ? ? ? | ?Democracy is three wolveshttp://www.druid.net/darcy/? ? ? ? ? ? ? ?| ?and a sheep voting on > +1 416 425 1212 ? ? (DoD#0082) ? ?(eNTP) ? | ?what's for dinner. Was not an assignment. I created a general table class and several specific tables. The application I'm going to write is going to be used by scientist that might not have a strong computational background, but they might be willing of adding some new tables. Their code knowledge might be so low that they might not go further a copy-paste. The way I defined the table, they just have to create lists indicating the name of the columns, their content and eventually some initial values for instance. self.colNames= [ 'id' , 'name' , 'surname', 'age' ] self.colType = [INTEGER, TEXT , TEXT , INTEGER] self.init.append([ None , 'john' , 'Lennon' , '51' ]) i.e. the code has to resable the structure of the table and be easily copy and paste (this last thing makes this system better than, instead, using python dictionary...also because the future user might not be familiar at all with dictionary).I might think of doing an automatic substitution of the primarykey with None, that is not a problem Anyhow, as said, thanks for all the answers, you solved my question Regards From greg.ewing at canterbury.ac.nz Mon Nov 29 17:27:38 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 30 Nov 2010 11:27:38 +1300 Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance In-Reply-To: <7xsjyp2d12.fsf@ruckus.brouhaha.com> References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> <7xsjyp2d12.fsf@ruckus.brouhaha.com> Message-ID: <8linmqF99gU1@mid.individual.net> Paul Rubin wrote: > The classic example though is a window system, where you have a "window" > class, and a "scroll bar" class, and a "drop-down menu" class, etc. and > if you want a window with a scroll bar and a drop-down menu, you inherit > from all three of those classes. Not in any GUI library I've ever seen. Normally there would be three objects involved in such an arrangement, a Window, a ScrollBar and a DropDownMenu, connected to each other in some way. -- Greg From stackslip at gmail.com Mon Nov 29 17:55:31 2010 From: stackslip at gmail.com (Garland Fulton) Date: Mon, 29 Nov 2010 13:55:31 -0900 Subject: Arrays In-Reply-To: References: <4ceef22b.1a1c640a.442c.2e69@mx.google.com> Message-ID: At the top of the last post I didn't understand how I was supposed to have my e mail headers or my quotes formatted. I also would like to change the header to my e mail thread. To I appolpgize and thank you for clearing up my thinking. I just got done with a java class and I should have paid more attention. Now that I went back and reviewed. array[] // in java Is not the same as list[] // in python. I will go back and try my way again. I have a list of objects built to form numbers given to me already. I would like to take the list apart iterate over each component and replace it with the corresponding number, and put it back together again everytime I call that number(str object) to be printed from my list. To clear my goals up I don't want to be a bad to this e mail list. Thank you, Slie On Nov 25, 2010 8:43 PM, "Dennis Lee Bieber" wrote: > On Thu, 25 Nov 2010 14:32:57 -0900, Slie declaimed > the following in gmane.comp.python.general: > >> I have an exercise im working on. >> I have an array of strings, and I would like to take each peace of the array and assign it to a new array so I can iterate over each of those pieces and replace the sting I want then put it back together. >> >> I hope that is not too confusing. This is how im trying to solve the problem. >> >> I have a program that takes in integers and it prints out the integers in bigger ones made up of asterisks. Im supposed to alter the program so so that instead of asterisks it prints them in bigger ones made up of the number itself. >> >> I am given arrays built to look like the numbers, already. > > {Note: this newsgroup/list prefers the "trim and follow" method of > quoting; persist ant "top-posting" will earn the ire of the readers} > > We still have the problem that you are referring to "arrays" which > are NOT native data types in Python... There is an importable module for > "arrays", and most of the numerics packages (a la numpy) define arrays, > but Python itself has dynamically sized "lists" (and "lists of lists..." > to add additional dimensions). > > Off-hand, it sounds like you are just substituting a list-of-lists > (of strings) of asterisks with a list-of-lists containing characters of > each digit... > > Now which part are you having problems with? Extracting the digits > from the input "number", indexing into the list of digit data, indexing > into the row of digit data, collecting the data into one output > structure? > > I'm probably giving away too much here but using just 0/1 and input > as a string... > > -=-=-=-=-=- > > digits = [ [ " 000 ", > "0 0", > "0 0", > "0 0", > "0 0", > " 000 " ], > [ " 1 ", > " 11 ", > " 1 ", > " 1 ", > " 1 ", > " 111 " ] ] > > output = [] > > DATA = "01101" > > for row in range(6): > rowparts = [] > for d in DATA: > dint = int(d, 10) > rowparts.append(digits[dint][row]) > output.append(" ".join(rowparts)) > > print output > print > > for rout in output: > print rout > -=-=-=-=-=-=- (use fixed width font to view) > [' 000 1 1 000 1 ', '0 0 11 11 0 0 11 > ', '0 0 1 1 0 0 1 ', '0 0 1 1 0 0 1 > ', '0 0 1 1 0 0 1 ', ' 000 111 111 000 111 > '] > > 000 1 1 000 1 > 0 0 11 11 0 0 11 > 0 0 1 1 0 0 1 > 0 0 1 1 0 0 1 > 0 0 1 1 0 0 1 > 000 111 111 000 111 > > -- > Wulfraed Dennis Lee Bieber AF6VN > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From matthew at cuneiformsoftware.com Mon Nov 29 18:11:28 2010 From: matthew at cuneiformsoftware.com (Spider) Date: Mon, 29 Nov 2010 15:11:28 -0800 (PST) Subject: Python 2.7.1 References: Message-ID: <7c7d85f5-740c-4a29-8899-cdab38865ac9@32g2000yqz.googlegroups.com> > 2.7 includes many features that were first released in Python 3.1. The faster io module ... I understand that I/O in Python 3.0 was slower than 2.x (due to quite a lot of the code being in Python rather than C, I gather), and that this was fixed up in 3.1. So, io in 3.1 is faster than in 3.0. Is it also true that io is faster in 2.7 than 2.6? That's what the release notes imply, but I wonder whether that comment has been back- ported from the 3.1 release notes, and doesn't actually apply to 2.7. Of course, I probably should benchmark it, but if someone who knows the history of the io module can respond, that would be great. My specific interest is in file read/write speeds. Thanks From python at mrabarnett.plus.com Mon Nov 29 18:17:59 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 29 Nov 2010 23:17:59 +0000 Subject: Reading lines of null-terminated text? In-Reply-To: References: Message-ID: <4CF434A7.9010309@mrabarnett.plus.com> On 29/11/2010 21:44, Dan Stromberg wrote: > > What's the best way of reading lines of null terminated (ASCII NUL, \0) > text in Python 2.x? How about for 3.x? > > I've been using http://stromberg.dnsalias.org/~strombrg/readline0.html > with 2.x, but I'm moving some of my stuff to 3.x, and am wondering if > there's a way that would obviate readline0. > You could read as binary data and then split on b"\x00". In Python 3 it's possible to specify the newline character, but I've found that it won't accept the null character as newline. I don't know why. :-( From ian.g.kelly at gmail.com Mon Nov 29 19:00:02 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 29 Nov 2010 17:00:02 -0700 Subject: Reading lines of null-terminated text? In-Reply-To: <4CF434A7.9010309@mrabarnett.plus.com> References: <4CF434A7.9010309@mrabarnett.plus.com> Message-ID: On Mon, Nov 29, 2010 at 4:17 PM, MRAB wrote: > In Python 3 it's possible to specify the newline character, but I've > found that it won't accept the null character as newline. I don't know > why. :-( Because it isn't a legal value. "newline controls how universal newlines works (it only applies to text mode). It can be None, '', '\n', '\r', and '\r\n'." Why it was designed that way, I don't know. Maybe to avoid scenarios where the selected newline has more than one representation in the selected encoding. Cheers, Ian From ian.g.kelly at gmail.com Mon Nov 29 19:00:02 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 29 Nov 2010 17:00:02 -0700 Subject: Reading lines of null-terminated text? In-Reply-To: <4CF434A7.9010309@mrabarnett.plus.com> References: <4CF434A7.9010309@mrabarnett.plus.com> Message-ID: On Mon, Nov 29, 2010 at 4:17 PM, MRAB wrote: > In Python 3 it's possible to specify the newline character, but I've > found that it won't accept the null character as newline. I don't know > why. :-( Because it isn't a legal value. "newline controls how universal newlines works (it only applies to text mode). It can be None, '', '\n', '\r', and '\r\n'." Why it was designed that way, I don't know. Maybe to avoid scenarios where the selected newline has more than one representation in the selected encoding. Cheers, Ian From ameyer2 at yahoo.com Mon Nov 29 20:46:08 2010 From: ameyer2 at yahoo.com (Alan Meyer) Date: Mon, 29 Nov 2010 20:46:08 -0500 Subject: Parsing markup. In-Reply-To: References: <4CEF318F.2090308@mrabarnett.plus.com> Message-ID: <4CF45760.1080601@yahoo.com> On 11/29/2010 11:20 AM, Joe Goldthwaite wrote: > Hi MRAB, > > I was trying to avoid regex because my poor old brain has trouble with it. I > have to admin though, that line is slick! I'll have to go through my regex > documentation to try and figure out what it actually means. Personally, I'd be hesitant to use a regex. It can be done and I've done it myself on occasion when I had a simple job to do and a very, very, very well defined target. The problem with using regular expressions is that there is are many variations in the text of valid XML. There can be namespaces, attributes, newlines in surprising places, unexpected character encodings, alternative quoting styles (e.g. id='123' or id = "123"), character entities ("<") and possibly other things that I haven't thought of. The parser authors have thought of those things and written parsing code that works properly on legal XML, even in these surprising cases that rarely show up in your data but can. You might think there won't ever be any surprises that break your regexes, but then some new programmer appears on the project and thinks, Aha, this is XML, I can solve my problem by adding a new attribute to that 'p' tag. He will be tearing his hair and muttering sentences that happen to have your name in them when he discovers that his perfectly legal XML content won't parse correctly in your regex based parser. The muttering will get much louder if he only discovers this after much data has been processed and important items silently skipped over by the parser. Alan From rustompmody at gmail.com Mon Nov 29 23:50:48 2010 From: rustompmody at gmail.com (rustom) Date: Mon, 29 Nov 2010 20:50:48 -0800 (PST) Subject: TDD in python References: <0906c010-709d-41d9-8b29-2f42afb87f94@32g2000yqz.googlegroups.com> Message-ID: <58fe3680-21f5-42f8-9341-e069cbb88975@r19g2000prm.googlegroups.com> On Nov 29, 4:59?pm, Andr? wrote: > On Nov 29, 7:31?am, rustom wrote: > > > > > On Nov 28, 7:52?pm, Stefan Behnel wrote: > > > > Rustom Mody, 28.11.2010 11:58: > > > > > Does anyone know of something like this for python? > > > > >http://www.vimeo.com/13240481 > > > > The page seems to require a recent version of the Flash player. Could you > > > describe what exactly you are looking for? > > > > Stefan > > > Well most modern languages have TDD frameworks. > > However TDD is learnt by doing and not from books (like swimming/ > > cycling). > > This screencast gives a detailed demo of *doing it* in eclipse/C++ > > I was hoping for something similar for python > > Go to showmedo.com and do a search for "python tdd"; you'll find many > such screencasts. > > Andr? Looking around I found this: http://bytes.com/topic/python/answers/43330-unittest-vs-py-test where Raymond Hettinger no less says quite unequivocally that he prefers test.py to builtin unittest because it is not so heavy-weight Is this the general consensus nowadays among pythonistas? [Note I tend to agree but Ive no experience so asking] From goldtech at worldpost.com Tue Nov 30 00:17:16 2010 From: goldtech at worldpost.com (goldtech) Date: Mon, 29 Nov 2010 21:17:16 -0800 (PST) Subject: regular expression help Message-ID: <3276d8a0-422b-468c-b1e0-71cf562afc68@t8g2000prh.googlegroups.com> Hi, say: >>> import re >>>> m="oooocccvlvlvlvnnnflfllffccclfnnnooo" >>> re.compile(r'ccc.*nnn') >>> rtt=pppp.sub("||",m) >>> rtt 'oooo||ooo' The regex is eating up too much. What I want is every non-overlapping occurrence I think. so rtt would be: 'oooo||flfllff||ooo' just like findall acts but in this case I want sub to act like that. Thanks From drsalists at gmail.com Tue Nov 30 00:26:23 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 29 Nov 2010 21:26:23 -0800 Subject: Python 3 encoding question: Read a filename from stdin, subsequently open that filename Message-ID: I've got a couple of programs that read filenames from stdin, and then open those files and do things with them. These programs sort of do the *ix xargs thing, without requiring xargs. In Python 2, these work well. Irrespective of how filenames are encoded, things are opened OK, because it's all just a stream of single byte characters. In Python 3, I'm finding that I have encoding issues with characters with their high bit set.? Things are fine with strictly ASCII filenames. With high-bit-set characters, even if I change stdin's encoding with: ? ? ? import io ? ? ? STDIN = io.open(sys.stdin.fileno(), 'r', encoding='ISO-8859-1') ...even with that, when I read a filename from stdin with a single-character Spanish n~, the program cannot open that filename because the n~ is apparently internally converted to two bytes, but remains one byte in the filesystem. I decided to try ISO-8859-1 with Python 3, because I have a Java program that encountered a similar problem until I used en_US.ISO-8859-1 in an environment variable to set the JVM's encoding for stdin. Python 2 shows the n~ as 0xf1 in an os.listdir('.'). Python 3 with an encoding of ISO-8859-1 wants it to be 0xc3 followed by 0xb1. Does anyone know what I need to do to read filenames from stdin with Python 3.1 and subsequently open them, when some of those filenames include characters with their high bit set? TIA! From usernet at ilthio.net Tue Nov 30 00:34:59 2010 From: usernet at ilthio.net (Tim Harig) Date: Tue, 30 Nov 2010 05:34:59 +0000 (UTC) Subject: regular expression help References: <3276d8a0-422b-468c-b1e0-71cf562afc68@t8g2000prh.googlegroups.com> Message-ID: On 2010-11-30, goldtech wrote: > Hi, > > say: >>>> import re >>>>> m="oooocccvlvlvlvnnnflfllffccclfnnnooo" >>>> re.compile(r'ccc.*nnn') >>>> rtt=pppp.sub("||",m) >>>> rtt > 'oooo||ooo' > > The regex is eating up too much. What I want is every non-overlapping > occurrence I think. > > so rtt would be: > > 'oooo||flfllff||ooo' Python 3.1.2 (r312:79147, Oct 9 2010, 00:16:06) [GCC 4.4.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import re >>> m="oooocccvlvlvlvnnnflfllffccclfnnnooo" >>> pattern = re.compile(r'ccc[^n]*nnn') >>> pattern.sub("||", m) 'oooo||flfllff||ooo' >>> From lanyjie at yahoo.com Tue Nov 30 00:39:45 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Mon, 29 Nov 2010 21:39:45 -0800 (PST) Subject: regular expression help In-Reply-To: <3276d8a0-422b-468c-b1e0-71cf562afc68@t8g2000prh.googlegroups.com> Message-ID: <457935.48828.qm@web54207.mail.re2.yahoo.com> --- On Tue, 11/30/10, goldtech wrote: > From: goldtech > Subject: regular expression help > To: python-list at python.org > Date: Tuesday, November 30, 2010, 9:17 AM > The regex is eating up too much. What I want is every > non-overlapping > occurrence I think. > > so rtt would be: > > 'oooo||flfllff||ooo' > Hi, I'll just let Python do most of the talk here. >>> import re >>> m="oooocccvlvlvlvnnnflfllffccclfnnnooo" >>> p=re.compile(r'ccc.*?nnn') >>> p.sub("||", m) 'oooo||flfllff||ooo' Cheers, Yingjie From usernet at ilthio.net Tue Nov 30 00:45:39 2010 From: usernet at ilthio.net (Tim Harig) Date: Tue, 30 Nov 2010 05:45:39 +0000 (UTC) Subject: regular expression help References: <3276d8a0-422b-468c-b1e0-71cf562afc68@t8g2000prh.googlegroups.com> Message-ID: Python 3.1.2 (r312:79147, Oct 9 2010, 00:16:06) [GCC 4.4.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import re >>> m="oooocccvlvlvlvnnnflfllffccclfnnnooo" >>> pattern = re.compile(r'ccc[^n]*nnn') >>> pattern.sub("||", m) 'oooo||flfllff||ooo' >>> # or, assuming that the middle sequence might contain singular or >>> # double 'n's >>> pattern = re.compile(r'ccc.*?nnn') >>> pattern.sub("||", m) 'oooo||flfllff||ooo' >>> From lanyjie at yahoo.com Tue Nov 30 00:52:07 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Mon, 29 Nov 2010 21:52:07 -0800 (PST) Subject: Python 3 encoding question: Read a filename from stdin, subsequently open that filename In-Reply-To: Message-ID: <339421.80548.qm@web54205.mail.re2.yahoo.com> --- On Tue, 11/30/10, Dan Stromberg wrote: > In Python 3, I'm finding that I have encoding issues with > characters > with their high bit set.? Things are fine with strictly > ASCII > filenames.? With high-bit-set characters, even if I > change stdin's > encoding with: Co-ask. I have also had problems with file names in Chinese characters with Python 3. I unzipped the turtle demo files into the desktop folder (of course, the word 'desktop' is in Chinese, it is a windows XP system, localization is Chinese), then all in a sudden some of the demos won't work anymore. But if I move it to a folder whose path contains only english characters, everything comes back to normal. Another related issue on the same platform is this: if you have your source file in the chinese 'desktop' folder, and when you run the code and got some exceptions, the path information printed out by the tracer wrongly encoded the chinese name for 'desktop'. Yingjie From glyph at twistedmatrix.com Tue Nov 30 01:07:57 2010 From: glyph at twistedmatrix.com (Glyph Lefkowitz) Date: Tue, 30 Nov 2010 01:07:57 -0500 Subject: [ANNOUNCE] Twisted 10.2.0 Released Message-ID: <48EF5F73-CAE0-43CC-89A9-FD273C334E79@twistedmatrix.com> Twisted 10.2.0, the third Twisted release of 2010, has emerged from the mysterious depths of Twisted Matrix Labs, as so many releases before it. Survivors of the release process - what few there were of them - have been heard to claim that this version is "awesome", "even more robust", "fun-sized" and "oven fresh". Crossing several things that shouldn't ought to be, including the streams and the rubicon, I have assumed the triple responsibilities of feature author, project leader, *and* release manager for 10.2: with this dark and terrible power - a power which no man ought to wield alone - I have wrought a release which contains many exciting new features, including: - A plug-in API for adding new types of endpoint descriptions. - A new, simpler, substantially more robust CoreFoundation reactor. - Improvements to the implementation of Deferred which should both improve performance and fix certain runtime errors with long callback chains. - Deferred.setTimeout is (finally) gone. To quote the author of this change: "A new era of peace has started." - NetstringReceiver is substantially faster. And, of course, nearly one hundred smaller bug fixes, documentation updates, and general improvements. See the NEWS file included in the release for more details. Look upon our Twisted, ye mighty, and make your network applications event-driven: get it now, from: ... or simply install the 'Twisted' package from PyPI. Many thanks to Christopher Armstrong, for his work on release-automation tools that made this possible; to Jonathan Lange, for thoroughly documenting the process and thereby making my ascent to the throne of release manager possible, and to Jean-Paul Calderone for his tireless maintenance of our build and test infrastructure as well as his help with the release. Most of all, thanks to everyone who contributed a patch, reported a bug or reviewed a ticket for 10.2. Not including those already thanked, there are 41 of you, so it would be a bit tedious to go through everyone, but you know who you are and we absolutely couldn't do it without you! Thanks a ton! From goldtech at worldpost.com Tue Nov 30 01:08:03 2010 From: goldtech at worldpost.com (goldtech) Date: Mon, 29 Nov 2010 22:08:03 -0800 (PST) Subject: regular expression help References: <3276d8a0-422b-468c-b1e0-71cf562afc68@t8g2000prh.googlegroups.com> Message-ID: <8864cf46-f584-4a85-8857-e6a22a528a31@p7g2000prb.googlegroups.com> .*? fixed it. Every occurrence of the pattern is now affected, which is what I want. Thank you very much. From python at bdurham.com Tue Nov 30 03:59:44 2010 From: python at bdurham.com (python at bdurham.com) Date: Tue, 30 Nov 2010 03:59:44 -0500 Subject: Possible to determine number of rows affected by a SQLite update or delete command? Message-ID: <1291107584.8529.1407836997@webmail.messagingengine.com> Is there a cursor or connection property that returns the number of rows affected by a SQLite update or delete command? Or, if we want this information, do we have to pre-query our database for a count of records that will be affected by an operation? Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From kushal.kumaran+python at gmail.com Tue Nov 30 04:21:14 2010 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Tue, 30 Nov 2010 14:51:14 +0530 Subject: Possible to determine number of rows affected by a SQLite update or delete command? In-Reply-To: <1291107584.8529.1407836997@webmail.messagingengine.com> References: <1291107584.8529.1407836997@webmail.messagingengine.com> Message-ID: On Tue, Nov 30, 2010 at 2:29 PM, wrote: > Is there a cursor or connection property that returns the number of rows > affected by a SQLite update or delete command? > The cursor has a rowcount attribute. The documentation of the sqlite3 module says the implementation is "quirky". You might take a look at it and see if it fits your needs. > Or, if we want this information, do we have to pre-query our database for a > count of records that will be affected by an operation? > -- regards, kushal From usenet at solar-empire.de Tue Nov 30 05:06:45 2010 From: usenet at solar-empire.de (Marc Christiansen) Date: Tue, 30 Nov 2010 11:06:45 +0100 Subject: Python 3 encoding question: Read a filename from stdin, subsequently?open that filename References: Message-ID: Dan Stromberg wrote: > I've got a couple of programs that read filenames from stdin, and then > open those files and do things with them. These programs sort of do > the *ix xargs thing, without requiring xargs. > > In Python 2, these work well. Irrespective of how filenames are > encoded, things are opened OK, because it's all just a stream of > single byte characters. > > In Python 3, I'm finding that I have encoding issues with characters > with their high bit set.? Things are fine with strictly ASCII > filenames. With high-bit-set characters, even if I change stdin's > encoding with: > > ? ? ? import io > ? ? ? STDIN = io.open(sys.stdin.fileno(), 'r', encoding='ISO-8859-1') > > ...even with that, when I read a filename from stdin with a > single-character Spanish n~, the program cannot open that filename > because the n~ is apparently internally converted to two bytes, but > remains one byte in the filesystem. I decided to try ISO-8859-1 with > Python 3, because I have a Java program that encountered a similar > problem until I used en_US.ISO-8859-1 in an environment variable to > set the JVM's encoding for stdin. > > Python 2 shows the n~ as 0xf1 in an os.listdir('.'). Python 3 with an > encoding of ISO-8859-1 wants it to be 0xc3 followed by 0xb1. > > Does anyone know what I need to do to read filenames from stdin with > Python 3.1 and subsequently open them, when some of those filenames > include characters with their high bit set? > > TIA! Try using sys.stdin.buffer instead of sys.stdin. It gives you bytes instead of strings. Also use byteliterals instead of stringliterals for paths, i.e. os.listdir(b'.'). Marc From owgs at bii.a-star.edu.sg Tue Nov 30 05:29:35 2010 From: owgs at bii.a-star.edu.sg (OW Ghim Siong) Date: Tue, 30 Nov 2010 18:29:35 +0800 Subject: Memory issues when storing as List of Strings vs List of List Message-ID: <4CF4D20F.4060400@bii.a-star.edu.sg> Hi all, I have a big file 1.5GB in size, with about 6 million lines of tab-delimited data. I have to perform some filtration on the data and keep the good data. After filtration, I have about 5.5 million data left remaining. As you might already guessed, I have to read them in batches and I did so using .readlines(100000000). After reading each batch, I will split the line (in string format) to a list using .split("\t") and then check several conditions, after which if all conditions are satisfied, I will store the list into a matrix. The code is as follows: -----Start------ a=open("bigfile") matrix=[] while True: lines = a.readlines(100000000) for line in lines: data=line.split("\t") if several_conditions_are_satisfied: matrix.append(data) print "Number of lines read:", len(lines), "matrix.__sizeof__:", matrix.__sizeof__() if len(lines)==0: break -----End----- Results: Number of lines read: 461544 matrix.__sizeof__: 1694768 Number of lines read: 449840 matrix.__sizeof__: 3435984 Number of lines read: 455690 matrix.__sizeof__: 5503904 Number of lines read: 451955 matrix.__sizeof__: 6965928 Number of lines read: 452645 matrix.__sizeof__: 8816304 Number of lines read: 448555 matrix.__sizeof__: 9918368 Traceback (most recent call last): MemoryError The peak memory usage at the task manager is > 2GB which results in the memory error. However, if I modify the code, to store as a list of string rather than a list of list by changing the append statement stated above to "matrix.append("\t".join(data))", then I do not run out of memory. Results: Number of lines read: 461544 matrix.__sizeof__: 1694768 Number of lines read: 449840 matrix.__sizeof__: 3435984 Number of lines read: 455690 matrix.__sizeof__: 5503904 Number of lines read: 451955 matrix.__sizeof__: 6965928 Number of lines read: 452645 matrix.__sizeof__: 8816304 Number of lines read: 448555 matrix.__sizeof__: 9918368 Number of lines read: 453455 matrix.__sizeof__: 12552984 Number of lines read: 432440 matrix.__sizeof__: 14122132 Number of lines read: 432921 matrix.__sizeof__: 15887424 Number of lines read: 464259 matrix.__sizeof__: 17873376 Number of lines read: 450875 matrix.__sizeof__: 20107572 Number of lines read: 458552 matrix.__sizeof__: 20107572 Number of lines read: 453261 matrix.__sizeof__: 22621044 Number of lines read: 413456 matrix.__sizeof__: 22621044 Number of lines read: 166464 matrix.__sizeof__: 25448700 Number of lines read: 0 matrix.__sizeof__: 25448700 In this case, the peak memory according to the task manager is about 1.5 GB. Does anyone know why is there such a big difference memory usage when storing the matrix as a list of list, and when storing it as a list of string? According to __sizeof__ though, the values are the same whether storing it as a list of list, or storing it as a list of string. Is there any methods how I can store all the info into a list of list? I have tried creating such a matrix of equivalent size and it only uses 35mb of memory but I am not sure why when using the code above, the memory usage shot up so fast and exceeded 2GB. Any advice is greatly appreciated. Regards, Jinxiang From __peter__ at web.de Tue Nov 30 05:52:27 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 30 Nov 2010 11:52:27 +0100 Subject: Python 3 encoding question: Read a filename from stdin, subsequently open that filename References: Message-ID: Dan Stromberg wrote: > I've got a couple of programs that read filenames from stdin, and then > open those files and do things with them. These programs sort of do > the *ix xargs thing, without requiring xargs. > > In Python 2, these work well. Irrespective of how filenames are > encoded, things are opened OK, because it's all just a stream of > single byte characters. I think you're wrong. The filenames' encoding as they are read from stdin must be the same as the encoding used by the file system. If the file system expects UTF-8 and you feed it ISO-8859-1 you'll run into errors. You always have to know either (a) both the file system's and stdin's actual encoding, or (b) that both encodings are the same. If byte strings work you are in situation (b) or just lucky. I'd guess the latter ;) > In Python 3, I'm finding that I have encoding issues with characters > with their high bit set. Things are fine with strictly ASCII > filenames. With high-bit-set characters, even if I change stdin's > encoding with: > > import io > STDIN = io.open(sys.stdin.fileno(), 'r', encoding='ISO-8859-1') I suppose you can handle (b) with STDIN = sys.stdin.buffer or STDIN = io.TextIOWrapper(sys.stdin.buffer, encoding=sys.getfilesystemencoding()) in Python 3. I'd prefer the latter because it makes your assumptions explicit. (Disclaimer: I'm not sure whether I'm using the io API as Guido intended it) > ...even with that, when I read a filename from stdin with a > single-character Spanish n~, the program cannot open that filename > because the n~ is apparently internally converted to two bytes, but > remains one byte in the filesystem. I decided to try ISO-8859-1 with > Python 3, because I have a Java program that encountered a similar > problem until I used en_US.ISO-8859-1 in an environment variable to > set the JVM's encoding for stdin. > > Python 2 shows the n~ as 0xf1 in an os.listdir('.'). Python 3 with an > encoding of ISO-8859-1 wants it to be 0xc3 followed by 0xb1. > > Does anyone know what I need to do to read filenames from stdin with > Python 3.1 and subsequently open them, when some of those filenames > include characters with their high bit set? > > TIA! From ulrich.eckhardt at dominolaser.com Tue Nov 30 06:30:41 2010 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Tue, 30 Nov 2010 12:30:41 +0100 Subject: Memory issues when storing as List of Strings vs List of List References: Message-ID: OW Ghim Siong wrote: > I have a big file 1.5GB in size, with about 6 million lines of > tab-delimited data. How many fields are there an each line? > I have to perform some filtration on the data and > keep the good data. After filtration, I have about 5.5 million data left > remaining. As you might already guessed, I have to read them in batches > and I did so using .readlines(100000000). I'd have guessed differently. Typically, I would say that you read one line, apply whatever operation you want to it and then write out the result. At least that is the "typical" operation of filtering. > a=open("bigfile") I guess you are on MS Windows. There, you have different handling of textual and non-textual files with regards to the handling of line endings. Generally, using non-textual as input is easier, because it doesn't require any translations. However, textual input is the default, therefore: a = open("bigfile", "rb") Or, even better: with open("bigfile", "rb") as a: to make sure the file is closed correctly and in time. > matrix=[] > while True: > lines = a.readlines(100000000) > for line in lines: I believe you could do for line in a: # use line here > data=line.split("\t") Question here: How many elements does each line contain? And what is their content? The point is that each object has its overhead, and if the content is just e.g. an integral number or a short string, the ratio of interesting content to overhead is rather bad! Compare this to storing a longer string with just the overhead of a single string object instead, it should be obvious. > However, if I modify the code, to store as a list of string rather than > a list of list by changing the append statement stated above to > "matrix.append("\t".join(data))", then I do not run out of memory. You already have the result of that join: matrix.append(line) > Does anyone know why is there such a big difference memory usage when > storing the matrix as a list of list, and when storing it as a list of > string? According to __sizeof__ though, the values are the same whether > storing it as a list of list, or storing it as a list of string. I can barely believe that. How are you using __sizeof__? Why aren't you using sys.getsizeof() instead? Are you aware that the size of a list doesn't include the size for its content (even though it grows with the number of elements), while the size of a string does? > Is there any methods how I can store all the info into a list of list? I > have tried creating such a matrix of equivalent size and it only uses > 35mb of memory but I am not sure why when using the code above, the > memory usage shot up so fast and exceeded 2GB. The size of an empty list is 20 here, plus 4 per element (makes sense on a 32-bit machine), excluding the elements themselves. That means that you have around 8M elements (25448700/4). These take around 32MB of memory, which is what you are probably seeing. The point is that your 35mb don't include any content, probably just a single interned integer or None, so that all elements of your list are the same and only require memory once. In your real-world application that is obviously not so. My suggestions: 1. Find out what exactly is going on here, in particular why our interpretations of the memory usage differ. 2. Redesign your code to really use a filtering design, i.e. don't keep the whole data in memory. 3. If you still have memory issues, take a look at the array library, which should make storage of large arrays a bit more efficient. Good luck! Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From aotto1968 at users.berlios.de Tue Nov 30 06:56:28 2010 From: aotto1968 at users.berlios.de (Andreas Otto) Date: Tue, 30 Nov 2010 12:56:28 +0100 Subject: ANNOUNCE: NHI1-0.10, PLMK-1.8 und libmsgque-4.8 Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Dear User, ANNOUNCE: Major Feature Release ==================================== libmsgque: Application-Server-Toolkit for C, C++, JAVA, C#, Go, TCL, PERL, PHP, PYTHON, RUBY, VB.NET PLMK: Programming-Language-Microkernel NHI1: Non-Human-Intelligence #1 STATEMENT ========= "It takes 2 years" "and a team of qualified software developers" "to implement a new programming language," "but it takes only 2 weeks to add a micro-kernel" - - aotto1968 SUMMARY ======= Add support from the programming language "Go" from Google LINKS ===== UPDATE - PLMK definition > http://openfacts2.berlios.de/wikien/index.php/BerliosProject:NHI1_-_TheKernel ChangeLog: > http://nhi1.berlios.de/theLink/changelog.htm libmsgque including PHP documentation: > http://nhi1.berlios.de/theLink/index.htm NHI1: > http://nhi1.berlios.de/ DOWNLOAD: > http://developer.berlios.de/projects/nhi1/ Go man pages: > reference: gomsgqueref.n > tutorial: gomsgquetut.n mfg, Andreas Otto (aotto1968) -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.15 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org/ iQEcBAEBAgAGBQJM9OZsAAoJEGTcPijNG3/A+qwH/1WT3K8619eLzQ78dylS623r qrZtHXRxieD+4GIBgkU7KbNu+LGztxasLW9upafmmF2mGcWtIFuiOEJtw6MJM+07 0X7elXM5WZkXK65dbLE5bbSfO0DHw5T6aIweogA3zjcjDbB3rSC/T6WIlZB4HNYh nBj9xC6WMP7s/jEjs4i5FCRT6gTRzDDJbR+SXqNEEYc/z8wVKPUDfpU/6JGxl9MV rPSUsO+YdZX0XI7+imiUYSVyt+kniL3C36kGON/qGDahscoQYFS6GdoI5XDzI0c+ jN7Q2Ecrphd5F5G/2plNLbVy4mPVd9k/I8VjXMaHLm+skT2Z4Zt7aF29A1FFw68= =/O74 -----END PGP SIGNATURE----- From __peter__ at web.de Tue Nov 30 07:22:40 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 30 Nov 2010 13:22:40 +0100 Subject: Memory issues when storing as List of Strings vs List of List References: Message-ID: OW Ghim Siong wrote: > Hi all, > > I have a big file 1.5GB in size, with about 6 million lines of > tab-delimited data. I have to perform some filtration on the data and > keep the good data. After filtration, I have about 5.5 million data left > remaining. As you might already guessed, I have to read them in batches > and I did so using .readlines(100000000). After reading each batch, I > will split the line (in string format) to a list using .split("\t") and > then check several conditions, after which if all conditions are > satisfied, I will store the list into a matrix. > > The code is as follows: > -----Start------ > a=open("bigfile") > matrix=[] > while True: > lines = a.readlines(100000000) > for line in lines: > data=line.split("\t") > if several_conditions_are_satisfied: > matrix.append(data) > print "Number of lines read:", len(lines), "matrix.__sizeof__:", > matrix.__sizeof__() > if len(lines)==0: > break > -----End----- As Ulrich says, don't use readlines(), use for line in a: ... that way you have only one line in memory at a time instead of the huge lines list. > Results: > Number of lines read: 461544 matrix.__sizeof__: 1694768 > Number of lines read: 449840 matrix.__sizeof__: 3435984 > Number of lines read: 455690 matrix.__sizeof__: 5503904 > Number of lines read: 451955 matrix.__sizeof__: 6965928 > Number of lines read: 452645 matrix.__sizeof__: 8816304 > Number of lines read: 448555 matrix.__sizeof__: 9918368 > > Traceback (most recent call last): > MemoryError > > The peak memory usage at the task manager is > 2GB which results in the > memory error. > > However, if I modify the code, to store as a list of string rather than > a list of list by changing the append statement stated above to > "matrix.append("\t".join(data))", then I do not run out of memory. > > Results: > Number of lines read: 461544 matrix.__sizeof__: 1694768 > Number of lines read: 449840 matrix.__sizeof__: 3435984 > Number of lines read: 455690 matrix.__sizeof__: 5503904 > Number of lines read: 451955 matrix.__sizeof__: 6965928 > Number of lines read: 452645 matrix.__sizeof__: 8816304 > Number of lines read: 448555 matrix.__sizeof__: 9918368 > Number of lines read: 453455 matrix.__sizeof__: 12552984 > Number of lines read: 432440 matrix.__sizeof__: 14122132 > Number of lines read: 432921 matrix.__sizeof__: 15887424 > Number of lines read: 464259 matrix.__sizeof__: 17873376 > Number of lines read: 450875 matrix.__sizeof__: 20107572 > Number of lines read: 458552 matrix.__sizeof__: 20107572 > Number of lines read: 453261 matrix.__sizeof__: 22621044 > Number of lines read: 413456 matrix.__sizeof__: 22621044 > Number of lines read: 166464 matrix.__sizeof__: 25448700 > Number of lines read: 0 matrix.__sizeof__: 25448700 > > In this case, the peak memory according to the task manager is about 1.5 > GB. > > Does anyone know why is there such a big difference memory usage when > storing the matrix as a list of list, and when storing it as a list of > string? According to __sizeof__ though, the values are the same whether > storing it as a list of list, or storing it as a list of string. Is sizeof gives you the "shallow" size of the list, basically the memory to hold C pointers to the items in the list. A better approximation for the total size of a list of lists of string is >>> from sys import getsizeof as sizeof >>> matrix = [["alpha", "beta"], ["gamma", "delta"]] >>> sizeof(matrix), sum(sizeof(row) for row in matrix), sum(sizeof(entry) for row in matrix for entry in row) (88, 176, 179) >>> sum(_) 443 As you can see the outer list requires only a small portion of the total memory, and its relative size will decrease as the matrix grows. The above calculation may still be wrong because some of the strings could be identical. Collapsing identical strings into a single object is also a way to save memory if you have a significant number of repetitions. Try matrix = [] with open(...) as f: for line in f: data = line.split("\t") if ...: matrix.append(map(intern, data)) to see whether it sufficiently reduces the amount of memory needed. > there any methods how I can store all the info into a list of list? I > have tried creating such a matrix of equivalent size and it only uses > 35mb of memory but I am not sure why when using the code above, the > memory usage shot up so fast and exceeded 2GB. > > Any advice is greatly appreciated. > > Regards, > Jinxiang From hpj at urpla.net Tue Nov 30 08:30:30 2010 From: hpj at urpla.net (Hans-Peter Jansen) Date: Tue, 30 Nov 2010 14:30:30 +0100 Subject: remote control firefox with python In-Reply-To: <4cf273b9$0$19685$426a74cc@news.free.fr> References: <4cf273b9$0$19685$426a74cc@news.free.fr> Message-ID: <201011301430.30180.hpj@urpla.net> On Sunday 28 November 2010, 16:22:33 News123 wrote: > Hi, > > > I wondered whether there is a simpe way to > 'remote' control fire fox with python. > > > With remote controlling I mean: > - enter a url in the title bar and click on it > - create a new tab > - enter another url click on it > - save the html document of this page > - Probably the most difficult one: emulate a click or 'right click' > on a certain button or link of the current page. > - other interesting things would be to be able to enter the master > password from a script > - to enable disable proxy settings while running. > > The reason why I want to stay within Firefox and not use any other > 'mechanize' frame work is, that the pages I want to automate might > contain a lot of javascript for the construction of the actual page. If webkit based rendering in an option (since its javascript engine is respected by web developers nowadays..), you might want to check out PyQt, based on current versions of Qt. It provides very easy access to a full featured web browser engine without sacrificing low level details. All your requirements are provided easily (if you're able to grok the Qt documentation, e.g. ignore all C++ clutter, you're set). I've transcoded all available QtWebKit examples to python lately, available here: http://www.riverbankcomputing.com/pipermail/pyqt/2010-November/028614.html The attachment is a tar.bz2 archive, btw. Clicking is archived by: webelement.evaluateJavaScript( "var event = document.createEvent('MouseEvents');" "event.initEvent('click', true, true);" "this.dispatchEvent(event);" ) Cheers, Pete From roy at panix.com Tue Nov 30 08:33:11 2010 From: roy at panix.com (Roy Smith) Date: Tue, 30 Nov 2010 08:33:11 -0500 Subject: TDD in python References: <0906c010-709d-41d9-8b29-2f42afb87f94@32g2000yqz.googlegroups.com> <58fe3680-21f5-42f8-9341-e069cbb88975@r19g2000prm.googlegroups.com> Message-ID: In article <58fe3680-21f5-42f8-9341-e069cbb88975 at r19g2000prm.googlegroups.com>, rustom wrote: > Looking around I found this: > http://bytes.com/topic/python/answers/43330-unittest-vs-py-test > where Raymond Hettinger no less says quite unequivocally that he > prefers test.py to builtin unittest > because it is not so heavy-weight > > Is this the general consensus nowadays among pythonistas? > [Note I tend to agree but Ive no experience so asking] Both frameworks have their fans; I doubt you'll find any consensus. Pick one, learn it, and use it. What's important is that you write tests, write lots of tests, and write good tests. Which framework you use is a detail. From marduk at letterboxes.org Tue Nov 30 08:46:53 2010 From: marduk at letterboxes.org (Albert Hopkins) Date: Tue, 30 Nov 2010 08:46:53 -0500 Subject: Python 3 encoding question: Read a filename from stdin, subsequently open that filename In-Reply-To: References: Message-ID: <1291124813.414884.22.camel@WOPR> On Tue, 2010-11-30 at 11:52 +0100, Peter Otten wrote: Dan Stromberg wrote: > > > I've got a couple of programs that read filenames from stdin, and then > > open those files and do things with them. These programs sort of do > > the *ix xargs thing, without requiring xargs. > > > > In Python 2, these work well. Irrespective of how filenames are > > encoded, things are opened OK, because it's all just a stream of > > single byte characters. > > I think you're wrong. The filenames' encoding as they are read from stdin > must be the same as the encoding used by the file system. If the file system > expects UTF-8 and you feed it ISO-8859-1 you'll run into errors. > > I think this is wrong. In Unix there is no concept of filename encoding. Filenames can have any arbitrary set of bytes (except '/' and '\0'). But the filesystem itself neither knows nor cares about encoding. You always have to know either > > (a) both the file system's and stdin's actual encoding, or > (b) that both encodings are the same. > > If this is true, then I think that it is wrong to do in Python3. Any language should be able to deal with the filenames that the host OS allows. Anyway, going on with the OP.. can you open stdin so that you can accept arbitrary bytes instead of strings and then open using the bytes as the filename? I don't have that much experience with Python3 to say for sure. -a From jason.heeris at gmail.com Tue Nov 30 09:16:24 2010 From: jason.heeris at gmail.com (Jason) Date: Tue, 30 Nov 2010 06:16:24 -0800 (PST) Subject: How does GC affect generator context managers? Message-ID: <53061109-470b-4ea3-8718-cd383da796bd@a28g2000prb.googlegroups.com> I've been reading through the docs for contextlib and PEP 343, and came across this: Note that we're not guaranteeing that the finally-clause is executed immediately after the generator object becomes unused, even though this is how it will work in CPython. ...referring to context managers created via the contextlib.contextmanager decorator containing cleanup code in a "finally" clause. While I understand that Python-the-language does not specify GC semantics, and different implementations can do different things with that, what I don't get is how GC even relates to a context manager created from a generator. As I understood it, when the "with" block exits, the __exit__() method is called immediately. This calls the next() method on the underlying generator, which forces it to run to completion (and raise a StopIteration), which includes the finally clause... right? ? Jason From sda457 at gmail.com Tue Nov 30 09:21:29 2010 From: sda457 at gmail.com (SA sada) Date: Tue, 30 Nov 2010 06:21:29 -0800 (PST) Subject: nike shoes , fashi on clothes ; brand hand bags Message-ID: Dear customers, thank you for your support of our company. Here, there's good news to tell you: The company recently launched a number of new fashion items! ! Fashionable and welcome everyone to come buy. If necessary, please plut:==== http://www.vipshops.org ====== ==== http://www.vipshops.org ====== ==== http://www.vipshops.org ====== ==== http://www.vipshops.org ====== ==== http://www.vipshops.org ====== ==== http://www.vipshops.org ====== ==== http://www.vipshops.org ====== 1) More pictures available on our website (===== http://www.vipshops.org ====) 2) Many colors available . 3) Perfect quality, 4) 100% safe door to door delivery, Best reputation , Best services Posted: 4:13 pm on November 21st From xheruacles at gmail.com Tue Nov 30 09:37:47 2010 From: xheruacles at gmail.com (Xavier Heruacles) Date: Tue, 30 Nov 2010 22:37:47 +0800 Subject: how to go on learning python Message-ID: I'm basically a c/c++ programmer and recently come to python for some web development. Using django and javascript I'm afraid I can develop some web application now. But often I feel I'm not good at python. I don't know much about generators, descriptors and decorators(although I can use some of it to accomplish something, but I don't think I'm capable of knowing its internals). I find my code ugly, and it seems near everything are already gotten done by the libraries. When I want to do something, I just find some libraries or modules and then just finish the work. So I'm a bit tired of just doing this kind of high level scripting, only to find myself a bad programmer. Then my question is after one coded some kind of basic app, how one can keep on learning programming using python? Do some more interesting projects? Read more general books about programming? or...? -------------- next part -------------- An HTML attachment was scrubbed... URL: From duncan.booth at invalid.invalid Tue Nov 30 10:01:15 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 30 Nov 2010 15:01:15 GMT Subject: How does GC affect generator context managers? References: <53061109-470b-4ea3-8718-cd383da796bd@a28g2000prb.googlegroups.com> Message-ID: Jason wrote: > As I understood it, when the "with" block exits, the __exit__() method > is called immediately. This calls the next() method on the underlying > generator, which forces it to run to completion (and raise a > StopIteration), which includes the finally clause... right? > That is true if the "with" block exits, but if the "with" block (or "try".."finally" block) contains "yield" you have a generator. In that case if you simply drop the generator on the floor the cleanup at the end of the "with" will still happen, but maybe not until the generator is garbage collected. def foo(): with open("foo") as foo: for line in foo: yield line ... bar = foo() print bar.next() del bar # May close the file now or maybe later... -- Duncan Booth http://kupuguy.blogspot.com From sol2ray at gmail.com Tue Nov 30 10:03:26 2010 From: sol2ray at gmail.com (Sol Toure) Date: Tue, 30 Nov 2010 10:03:26 -0500 Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance In-Reply-To: <8linmqF99gU1@mid.individual.net> References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> <7xsjyp2d12.fsf@ruckus.brouhaha.com> <8linmqF99gU1@mid.individual.net> Message-ID: Most of the examples presented here can use the "decorator pattern" instead. Especially the window system On Mon, Nov 29, 2010 at 5:27 PM, Gregory Ewing wrote: > Paul Rubin wrote: > > The classic example though is a window system, where you have a "window" >> class, and a "scroll bar" class, and a "drop-down menu" class, etc. and >> if you want a window with a scroll bar and a drop-down menu, you inherit >> from all three of those classes. >> > > Not in any GUI library I've ever seen. Normally there would > be three objects involved in such an arrangement, a Window, > a ScrollBar and a DropDownMenu, connected to each other in > some way. > > -- > Greg > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://www.afroblend.com African news as it happens. -------------- next part -------------- An HTML attachment was scrubbed... URL: From bloom.dax at gmail.com Tue Nov 30 10:03:28 2010 From: bloom.dax at gmail.com (Dax Bloom) Date: Tue, 30 Nov 2010 07:03:28 -0800 (PST) Subject: Programming games in historical linguistics with Python Message-ID: Hello, Following a discussion that began 3 weeks ago I would like to ask a question regarding substitution of letters according to grammatical rules in historical linguistics. I would like to automate the transformation of words according to complex rules of phonology and integrate that script in a visual environment. Here follows the previous thread: http://groups.google.com/group/comp.lang.python/browse_thread/thread/3c55f9f044c3252f/fe7c2c82ecf0dbf5?lnk=gst&q=evolutionary+linguistics#fe7c2c82ecf0dbf5 Is there a way to refer to vowels and consonants as a subcategory of text? Is there a function to remove all vowels? How should one create and order the dictionary file for the rules? How to chain several transformations automatically from multiple rules? Finally can anyone show me what existing python program or phonological software can do this? What function could tag syllables, the word nucleus and the codas? How easy is it to bridge this with a more visual environment where interlinear, aligned text can be displayed with Greek notations and braces as usual in the phonology textbooks? Best regards, Dax Bloom From python.list at tim.thechases.com Tue Nov 30 10:15:47 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 30 Nov 2010 09:15:47 -0600 Subject: Memory issues when storing as List of Strings vs List of List In-Reply-To: <4CF4D20F.4060400@bii.a-star.edu.sg> References: <4CF4D20F.4060400@bii.a-star.edu.sg> Message-ID: <4CF51523.9000107@tim.thechases.com> On 11/30/2010 04:29 AM, OW Ghim Siong wrote: > a=open("bigfile") > matrix=[] > while True: > lines = a.readlines(100000000) > for line in lines: > data=line.split("\t") > if several_conditions_are_satisfied: > matrix.append(data) > print "Number of lines read:", len(lines), "matrix.__sizeof__:", > matrix.__sizeof__() > if len(lines)==0: > break As others have mentiond, don't use .readlines() but use the file-object as an iterator instead. This can even be rewritten as a simple list-comprehension: from csv import reader matrix = [data for data in reader(file('bigfile.txt', 'rb'), delimiter='\t') if several_conditions_are_satisfied(data) ] Assuming that you're throwing away most of the data (the final "matrix" fits well within memory, even if the source file doesn't). -tkc From ph.ton.sharma at gmail.com Tue Nov 30 10:15:55 2010 From: ph.ton.sharma at gmail.com (ton ph) Date: Tue, 30 Nov 2010 20:45:55 +0530 Subject: Help: problem in setting the background colour ListBox Message-ID: Hi everyone , I have a requirement of displaying my data in a textCtrl like widget , but i need that the data in the row be clickable , so as when i click the data i could be able to get fire and even and get me the selected data value.After a long search i found ListBox to be perfect for my use but When i try to set the backGround colour to the colour of my application requirement i am not able to do so, but i am able to set the foreground colour . Hope someone will guide me in solving my problem.... Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From solipsis at pitrou.net Tue Nov 30 10:16:52 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Tue, 30 Nov 2010 16:16:52 +0100 Subject: Python 2.7.1 References: <7c7d85f5-740c-4a29-8899-cdab38865ac9@32g2000yqz.googlegroups.com> Message-ID: <20101130161652.79117e8e@pitrou.net> On Mon, 29 Nov 2010 15:11:28 -0800 (PST) Spider wrote: > > 2.7 includes many features that were first released in Python 3.1. The faster io module ... > > I understand that I/O in Python 3.0 was slower than 2.x (due to quite > a lot of the code being in Python rather than C, I gather), and that > this was fixed up in 3.1. So, io in 3.1 is faster than in 3.0. > > Is it also true that io is faster in 2.7 than 2.6? That's what the > release notes imply, but I wonder whether that comment has been back- > ported from the 3.1 release notes, and doesn't actually apply to 2.7. The `io` module, which was backported from 3.1/3.2, is faster than in 2.6, but that's not what is used by default in 2.x when calling e.g. open() or file() (you'd have to use io.open() instead). So, as you suspect, the speed of I/O in 2.7 hasn't changed. The `io` module is available in 2.6/2.7 so that you can experiment with some 3.x features without switching, and in this case it's much faster than 2.6. Regards Antoine. From solipsis at pitrou.net Tue Nov 30 10:19:19 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Tue, 30 Nov 2010 16:19:19 +0100 Subject: Python 3 encoding question: Read a filename from stdin, subsequently open that filename References: <339421.80548.qm@web54205.mail.re2.yahoo.com> Message-ID: <20101130161919.693a1d78@pitrou.net> On Mon, 29 Nov 2010 21:52:07 -0800 (PST) Yingjie Lan wrote: > --- On Tue, 11/30/10, Dan Stromberg wrote: > > In Python 3, I'm finding that I have encoding issues with > > characters > > with their high bit set.? Things are fine with strictly > > ASCII > > filenames.? With high-bit-set characters, even if I > > change stdin's > > encoding with: > > Co-ask. I have also had problems with file names in > Chinese characters with Python 3. I unzipped the > turtle demo files into the desktop folder (of > course, the word 'desktop' is in Chinese, it is > a windows XP system, localization is Chinese), then > all in a sudden some of the demos won't work > anymore. But if I move it to a folder whose > path contains only english characters, everything > comes back to normal. Can you try the latest 3.2alpha4 (*) and check if this is fixed? If not, then could you please open a bug on http://bugs.python.org ? (*) http://python.org/download/releases/3.2/ Thank you Antoine. From solipsis at pitrou.net Tue Nov 30 10:27:40 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Tue, 30 Nov 2010 16:27:40 +0100 Subject: Memory issues when storing as List of Strings vs List of List References: <4CF4D20F.4060400@bii.a-star.edu.sg> Message-ID: <20101130162740.79789b34@pitrou.net> On Tue, 30 Nov 2010 18:29:35 +0800 OW Ghim Siong wrote: > > Does anyone know why is there such a big difference memory usage when > storing the matrix as a list of list, and when storing it as a list of > string? That's because any object has a fixed overhead (related to metadata and allocation), so storing a matrix line as a sequence of several objects rather than a single string makes the total overhead larger, especially when the payload of each object is small. If you want to mitigate the issue, you could store your lines as tuples rather than lists, since tuples have a smaller memory footprint: matrix.append(tuple(data)) > According to __sizeof__ though, the values are the same whether > storing it as a list of list, or storing it as a list of string. As mentioned by others, __sizeof__ only gives you the size of the container, not the size of the contained values (which is where the difference is here). Regards Antoine. From alice at gothcandy.com Tue Nov 30 10:30:09 2010 From: alice at gothcandy.com (=?utf-8?Q?Alice_Bevan=E2=80=93McGregor?=) Date: Tue, 30 Nov 2010 07:30:09 -0800 Subject: how to go on learning python References: Message-ID: Howdy Xavier! [Apologies for the length of this; I didn't expect to write so much!] I've been a Python programmer for many years now (having come from a PHP, Perl, C, and Pascal background) and I'm constantly learning new idioms and ways of doing things that are more "Pythonic"; cleaner, more efficient, or simply more beautiful. I learn by coding, rather than by reading books, taking lectures, or sitting idly watching screencasts. I constantly try to break the problems I come up with in my head into smaller and smaller pieces, then write the software for those pieces in as elegant a method as possible. Because of my "turtles all the way down" design philosophy, a lot of my spare time projects have no immediate demonstrable benefit; I code them for fun! I have a folder full of hundreds of these little projects, the vast majority of which never see a public release. I also collect little snippets of code that I come across[1] or write, and often experiment with performance tests[2] of small Python snippets. Often I'll assign myself the task of doing something far outside my comfort zone; a recent example is writing a HTTP/1.1 web server. I had no idea how to do low-level socket programming in Python, let alone how HTTP actually worked under-the-hood, and because my goal wasn't (originally) to produce a production-quality product for others it gave me the freedom to experiment, rewrite, and break things in as many ways as I wanted. :) I had people trying to convince me that I shouldn't re-invent the wheel ("just use Twisted!") though they mis-understood the reason for my re-invention: to learn. It started as a toy 20-line script to dump a static HTTP/1.0 response on each request and has grown into a ~270 line fully HTTP/1.1 compliant, ultra-performant multi-process HTTP server rivalling pretty much every other pure-Python web server I've tested. (I still don't consider it production ready, though.) Progressive enhancement as I came up with and implemented ideas meant that sometimes I had to rewrite it from scratch, but I'm quite proud of the result and have learned far more than I expected in the process. While I don't necessarily study books on Python, I did reference HTTP: The Definitive Guide and many websites in developing that server, and I often use the Python Quick Reference[3] when I zone out and forget something basic or need to find something more advanced. In terms of understanding how Python works, or how you can use certain semantics (or even better, why you'd want to!) Python Enhancement Proposals (PEPs) can be an invaluable resource. For example, PEP 318[4] defines what a decorator is, why they're useful, how they work, and how you can write your own. Pretty much everything built into Python after Python 2.0 was first described, reasoned, and discussed in a PEP. If you haven't seen this already, the Zen of Python[5] (a PEP) has many great guidelines. I try to live and breathe the Zen. So that's my story: how I learn to improve my own code. My motto, "re-inventing the wheel, every time," is the short version of the above. Of course, for commercial work I don't generally spend so much time on the nitty-gritty details; existing libraries are there for a reason, and, most of the time, Getting Things Done? is more important than linguistic purity! ;) ? Alice. [1] https://github.com/GothAlice/Random/ [2] https://gist.github.com/405354 [3] http://rgruet.free.fr/PQR26/PQR2.6.html [4] http://www.python.org/dev/peps/pep-0318/ [5] http://www.python.org/dev/peps/pep-0020/ From smallpox911 at gmail.com Tue Nov 30 10:56:32 2010 From: smallpox911 at gmail.com (small Pox) Date: Tue, 30 Nov 2010 07:56:32 -0800 (PST) Subject: Iran slams Wiki-release as US psywar - WIKILEAKS is replacing those BIN LADEN communiques of CIA (the global ELITE) intended to threaten MASSES Message-ID: <1fc67adb-212d-40a7-8602-c354ca5349dd@l17g2000yqe.googlegroups.com> Iran slams Wiki-release as US psywar - WIKILEAKS is replacing those BIN LADEN communiques of CIA (the global ELITE) intended to threaten MASSES CIA is the criminal agency of the global elite. They want to destroy the middle class from the planet and also create a global tyranny of a police state. http://presstv.ir/detail/153128.html http://presstv.ir/detail/153128.html http://presstv.ir/detail/153128.html Iran slams Wiki-release as US psywar Mon Nov 29, 2010 12:56PM Share | Email | Print Iran's President Mahmoud Ahmadinejad has questioned the recent 'leaked' documents published by Wikileaks website, describing them as part of a US "psychological warfare." In response to a question by Press TV on Monday over the whistleblower website's "leaks," President Mahmoud Ahmadinejad said "let me first correct you. The material was not leaked, but rather released in an organized effort." "The US administration releases documents and makes a judgment based on them. They are mostly like a psychological warfare and lack legal basis," President Ahmadinejad told reporters on Monday. "The documents will certainly have no political effects. Nations are vigilant today and such moves will have no impact on international relations," the Iranian chief executive added at the press briefing in Tehran. President Ahmadinejad stressed that the Wikileaks "game" is "not even worth a discussion and that no one would waste their time analysing them." "The countries in the region are like friends and brothers and these acts of mischief will not affect their relations," he concluded. Talks with the West The president announced that aside from Brazil and Turkey a number of other countries may take part in the new round of talks between Iran and the P5+1 -- Britain, China, France, Russia, the US, plus Germany. Human rights "They (Western powers) trample on the dignity of man, their identity and real freedom. They infringe all of these and then they call it human rights," Ahmadinejad said. Earlier this month, the UN General Assembly's Third Committee accused Iran of violating human rights regulations. The 118-member Non-Aligned Movement and the 57-member Organization of the Islamic Conference have condemned the resolution against the Islamic Republic. "In 2005, the human rights [issue] got a new mechanism in the United Nations ... human rights was pushed away and human rights was used for political manipulation," Secretary General of Iran's High Council for Human Rights Mohammed Javad Larijani told Press TV following the vote on the resolution. This is while the United Nations Human Rights Council reviewed the US human rights record for the first time in its history. The council then issued a document making 228 suggestions to the US to improve its rights record. IAEA 'leak' The president said that Iran has always had a positive relationship with the International Atomic Energy Agency but criticized the UN nuclear agency for caving under pressure from the "masters of power and wealth." The president said due to this pressure the IAEA has at times adopted "unfair and illegal stances" against the Islamic Republic. "Their recent one (IAEA report) is better than the previous ones and is closer to the truth but still all the facts are not reflected," he added. "Of course the latest report also has shortcomings, for example all [of Iran's nuclear] information has been released and these are secret and confidential documents belonging to the country." Ahmadinejad said since Iran was following a policy of nuclear transparency, it did not care about the leaks, but called the move 'illegal." New world order "The world needs order ? an order in which different people form different walks of life enjoy equal rights and proper dignity," the president said in his opening speech before taking questions form Iranian and foreign journalist. The president added that the world was already on the path to setting up this order. Iran isolation When asked to comment on the US and Western media claims that Iran has become highly isolated in the region despite an active diplomacy with Persian Gulf littoral states, the president said the remarks were part of the "discourse of hegemony." "In the hegemonic discourse, it seems that concepts and words take on different meanings than those offered by dictionaries," Ahmadinejad said. "When they say they have isolated Iran, it means that they themselves are isolated and when they say Iran is economically weak, it means that it has strengthened," the president reasoned. When they say there is a dictatorship somewhere, it means that country is really chosen by the people and vise a versa, the president further noted, adding, "I do not want to name names." ZHD/HGH/SF/MMN/MB Comments Add Comment Click Here Note: The views expressed and the links provided on our comment pages are the personal views of individual contributors and do not necessarily reflect the views of Press TV. check this out 11/30/2010 9:18:05 AMit is a coincidence that ?documents regarding Israel, their spying, influence peddling, suspicions of complicity in terrorism, Yemen, Iraq, Pakistan, Somalia, across Europe and even the Detroit bombing, those reports are there, they are classified but you will never see one on Wikileaks. In fact, they are the only classified information that never gets out to the news.? Ali 11/30/2010 7:47:47 AM"The world needs order ? an order in which different people form different walks of life enjoy equal rights and proper dignity,"very true! JHK 11/30/2010 7:37:09 AMIran should offer support to Western Media which is trying to portray the Truth. Moving these outlets outside the United States may help with this. Everyday American Citizens are at a loss as to what to do, and they need our support, some of them are Muslims. It's time4Africa 11/30/2010 7:19:25 AMDefinitely a zionist plot. All her enemies were bashed, and it was the only country to be praised in these 'leaks'. People are wiser and smarter now. "Fool me ones, shame on you. Fool me twice, shame on me!" SMARTI 11/30/2010 7:04:09 AMLOOK AT THE WESTERN MANIPULATING MEDIA, LIKE CNN FOX NEWS.FRONTPAGE HEADLINES LIKE; 'HOSTILITY TOWARDS IRAN BY NEIGHBORS'.BUT THIS LIE MEDIA ALWAYS FAILS TO MENTION THE ARAB PUBLIC OPINION TOWARDS IRAN! THEIR PROPAGANDA DON'T DISTINGUISH BETWEEN ARAB PEOPLE AND THEIR LEADERS! REASON?!: DIVIDE AND RULE!. THIS PRINCIPLE NEVER CHANGES!. IRAN BE CAREFULL, REMEMBER WHAT HIZBOLLAH LEADER ONCE SAID:THEY HAVE FAILED ON ALL THEIR PLOTS, THEY WILL TRY THEIR LAST ATTEMPT BY CREATING SUNNI-SHIA DIVISIONS 11/30/2010 6:49:48 AMI ask Sunni brothers to view Shiite not as a different religion but as a different school of thought. For example we have Hanafi, Hanbaly, etc... within Sunni Islam, why not view Shia also as such? The differences are not in the paradigm, therefore unity can be maintained. IRAN IS TOO WISE FOR CIA 11/30/2010 6:27:35 AMTHE USA IS USING WIKILEAKS TO CO-ORDINATE AND RELEASE MATERIAL WITH ALL THE OTHER STUFF TO MAKE IT LOOK LIKE IT WAS WIKILEAKS BUT IT ISNT IT IS THE CIA AND IN THIS WAY THEY CAN CAUSE PROBLEMS FOR IRAN AND NEIGHBOURING COUNTRIES. IRAN rules 11/30/2010 5:54:27 AMWIKILEAKS, IS AMERICA NEW PUBLIC RELATION TOOLS.WIKILEAKS IS HEAVELY INFLUENCED BY AMERICAN DOLLARS.AS USUAL AMERICA HIDE ITS CRIMES BY THIS TYPE OF MISINFORMATION. ify1979 11/30/2010 5:21:30 AMwiki leaks is just a proppganda game its playing wih iran! The Open Conspiracy 11/30/2010 4:36:52 AMThis is a plan that Winston Churchill had predicted would be the policy for the New World Order. Tony Blair was a typical "spill the beans" kind of speaker and the new ones are copying his style, sometimes chuckling as they make their statements. mumbo 11/30/2010 4:32:13 AMI almost think that there has never been a military coup in the US cause the military always gets (almost) all the money it wants. So the head of state has to take care of the military apparatus sustain their need for growing budgets and ongoing conflicts whether it was the red indians, french, spanish of the 19th century or the germans, vietnamese, arabs, soviets etc of the 20th and 21st century and beyond 11/30/2010 2:59:05 AMWhat many seem to have forgotten is that the so- called anti-Iranian sentiments of all the Arab PG states have been constantly touted by Western media for quite a while, long before these "leaks". Such news were also reported by PressTV and you don't think Iranians know what's going on? @ Political Game 11/30/2010 2:55:16 AMThe media is a great tool if one knows how to use it, and one of the oldest tricks in the game is a controlled leak. This is the case here. Sure, you can fool a few ignorant westerners with this trick, but Iran is an old and civilized country. Your tricks won't work here. The game is up. 11/30/2010 2:39:42 AMDamage Control by Iran's President who is rushing in, I would recommend him to be on "wait and see" mode rather than making any comments. Wikileaks may be RIGHT and maybe NOT. Political Game 11/30/2010 2:25:14 AMPresident Ahmadinejad is in denial, He knows that Wikileaks files are based on FACTS & TRUETH, however to show the world and assure the neighbouring countries(Saudis, UAE, Bahrain,etc) that Iran won't buy those facts. Just a little Political Game going on here. PEACE 11/30/2010 2:12:46 AMIt is a fabrication, how come 1/4 millions documents leak and some must br fake. @european 11/30/2010 2:07:23 AMThese are also not leaks because there are strategic elements in the contents to achieve certain agenda as with Iran and certain other countries only. Well said John Ellis 11/30/2010 1:56:06 AMThe Western media is owned by builderbergs who sees the public as dispensable items that can be best served at the lowest level of cognitive recall of events without inference, deduction, analysis, and any form of reasoning. The truth is the public may be ahead of the builderbergs in at least not tuning in as predicted. No body is in charge. So, the builderbergs have opted for offshore investments and outsourcing for the last couple of decades. The dynamics continue to indicate a bizarre future. Ranim Kalif 11/30/2010 1:46:55 AMRumour has it... That wikileaks is nothing but a CIA propaganda/counter propaganda program. The proof lies with The head honcho Julian Asange. Apparently Mr. Asange believes that 9/11 was done by fanatics from a cave in afghanistan, but anyone with half a brain can tell you that 3 steel framed building cannot collapse due to fire, its just not mathematically possible. And math does not lie, but people do. @Anti-bully 11/30/2010 12:54:13 AMAfter this week, you can retrospectively analyse and find more clues from the so-called WL documents that can be told now based on extrapolation using systemic hypocrisy templates. The West is so easy to read in either way. But, stay on the objective track. Anti-bully 11/30/2010 12:22:43 AM(Cont.) After the "Second Wikileaks" a month ago I said: "The answer to the Western idiocy is simple: Iran, Iraq & Afghanistan are neighbours, and you [[]the West INCL. Israel] DON'T BELONG THERE! SHOO!" Those neighbours of course include: Pakistan, Turkey, Azerbaijan, Syria, Lebanon, Central Asia, .... Revenge and Blessing 11/30/2010 12:12:39 AMRevenge is like Hurricane Katrina, California forest fire, American soldiers' suicides, Gulf of Mexico Spills, US rescue helicopters colliding and falling in an Iranian desert ....Blessings come with gentle earthquakes as wake-up calls to improve construction of buildings, wisdom to take technological leaps, intelligence to see the Wikileak psychological warfare,.... John Ellis 11/30/2010 12:06:17 AMWikiLeaks is doing to the public what Western corporate media does each and every day -- keep society locked in darkness by not saying a word about the root cause or solution to a problem, disclosing only the confusion, controversy, blood and guts of a problem, until finally the people in disgust back away and let the corporate rich to be enriched by the problem. Iranians know from their history 11/29/2010 11:57:39 PMthat when their leaders are liked by the West the country is in trouble and vice versa when the leaders are criticized by the West they must be very good leaders! New World Order = Slavery For All 11/29/2010 11:47:02 PMIt is already evident in the West through the public disenchantment and the authority's unwillingness to serve the public as before. The governments are not doing their usual services as if they are preparing to run slave camps soon. There are lots of telltales like trampling on constitutional rights that are bothersome. Saul 11/29/2010 11:36:33 PMI hear that the President Of Iran will soon be impeached. Is this true. Iran helps because Iran believes in God 11/29/2010 11:32:12 PM...and helps even those who have attacked Iran in the past. Because Iran does not believe in revenge like the West that is for ever occupying Germany, Japan, South Korea, etc. Iran knows better that revenge is best left to God. european 11/29/2010 10:51:03 PMThese are not leaks at all. They never compliment or give more attention to such things... just like 9/11, nobody could suggest a possiblity of an inside job. Nobody. So how come, Assange comes in and publish leaks and he becomes an idol of masses?This is one big joke.The US behaves like a shaitan, then issues a represantative to openly admit that their country belongs to the devil. AB 11/29/2010 10:49:56 PMToday popularity contest is base on economic liberty not on propaganda policy. If Iran didn?t help Lebanon or Iraq to back on their feet, today had no popularity the same as Egypt. Abd 11/29/2010 10:02:12 PMThe enemies of humanity who think they have saved a face behind addiction, corruption and oppression of even their citizens are actually at an ideological dead end. The US demons and their Salary worshiper pupits in the almost expired UN should cry their heart out and get drunk before lying about Iran. Sincerely.www.criesofdarwinism.com Iranian 11/29/2010 10:00:35 PMAnd some people criticize his foreign policy. this announcement is something that every Iranian can be proud of, proud of their president, unfortunately it is fashionable to criticize or insult Ahmadinejad without any reason thanks to zionist media. To Anti-Bully 11/29/2010 10:00:00 PMEven when there is a physical court, it is inconspicuously hollowed out in favour of the Western dictatorships that pretend to be democratic. scott68 11/29/2010 9:53:56 PMcertain comments that were leaked to the western media from Wikileaks is being used by western media to create a hostile climate on the subject of say for example Iran's nuclear program by using the names of certain key leaders in the middle east who have said the US should attack Iran to prevent them obtaining nuclear weapons it seems as though the western media want to create a hostile reaction towards Iran with this information Anti-bully 11/29/2010 9:51:10 PMThe 3-step Wikileaks (WL) rocket. First WL: US army atrocities. 2nd WL: People in ME kill and bribe each other (which according to West's fascist "logic" makes it OK if US/UK/NATO/Israel do it as well). 3rd WL: The big fish panjandrums are in on it. IOW: 1) "We, WEST, have the muscles", 2) "You, ME, deserve what's coming to you" 3) "WE-HAVE-THE-POWER". Conclusion: "You, the "REST", can do ZIT!". @Anti-bully 11/29/2010 9:38:54 PMAffirmative! Took me more than 45 years in the West to research the systemic anatomy of hypocricy. You have come a long way, and so have most of those who have commented here. Anti-bully 11/29/2010 9:18:07 PMWest, when it deems convenient, shows evidences of it's atrocities (Vietnam files, Wikileaks, Abu Ghraib pics) and boohoos "look how TERRIBLE we are", but you wouldn't SEE the smirk. Of course, some evidences could hold in a court of law, but what if there is NO court? This makes the Anglo-American psycho-West grin even wider. IOW, West gets off flaunting how disgusting it can be. You think Iran was joking when calling them "Great Satan"? PIONEER 11/29/2010 8:58:05 PMso it's true (and quoted by iran) when it's about the u.s. and the west, but untrue when it's about iran? EB 11/29/2010 8:30:55 PMSo when something bad about the US is released by wikileaks, Iran agrees with them, but when something bad about Iran comes out, they say it's not true and planned by the west.. Wonderful double standards. PressTV is a joke, and it's just like FoxNews, completely biased. Katifa 11/29/2010 8:22:24 PMI wish Ahmadinejad would go into more detail as to why he feels the US benefits from this leak. I don't understand his point of view and usually I do! mumbo 11/29/2010 7:52:07 PMsome of the statements by Bahraini, UAE or Saudi Arab leaders would have never been made, even in private if it weren't for certain imperialist powers constantly dabbling in this region. Now that they do dabble, it should be treated as private thoughts - nothing more nothing less. However let s remember that it was superpower support of Saddam Hussein that got many arab leaders to dole money to Saddam fighting the Persians. hussain mehdi 11/29/2010 7:33:06 PMthis is leak??? first they announce and then they publish leak!!! this is leak??? is this leak??? 11/29/2010 7:13:06 PMYhere was time Muslims were divided in Shia and Sunni but the Ediots of West have helped us to get rid of the prejudices and now Thanks God we are one. Iran was always Great Shia Nation and Turkey Great Sinni Nation. Now they Mashallah are Great Islamic Nation. subhan Allah. The enemy has cut its own throat. fred Kay 11/29/2010 6:15:06 PMALL ARAB COUNTRIES HAVE PUPPET GOVERNMENTS PUT IN POWER BY THE MASTERS IN THE WEST.MUSLIM BROTHERHOOD WITH ARABS?!MY FOOT,WHAT POSITIVE STEPS HAVE THEY TAKEN TOWARDS IRAN?,NONE.IRAN MUST PAY THEM IN KIND AND SHAKE THEIR GLASS HOUSES.ISRAEL IS RIGHT TO GIVE THEM A BLOW EVERY TIME THEY OPEN THEIR BRAINLESS MOUTHS. Pak 11/29/2010 6:12:52 PMHis Excellency Mr. AhamdiNejad is a great leader of Muslim nation.And the arrogant powers are scared from this thing.For Non Muslims nations there is nothing Shia or Sunni only Muslims.And these Non Muslims nations always try their best to use all resources to make difference between Muslims. RESON 11/29/2010 5:51:43 PMWEST HAVE BIG SOCIAL PROBLEM & THAT IS THRUST BETWEEN ITS PEAPOL V GOVT TO BUILD THAT THRUST NEED TO PROVE DOMACRECY EXCICT. IRAQ WAR PRODUCE BIG MASS OF SOCIAL UNREST INWEST IN TOTAL. THE LEAK WORKS LIKE PRESUR COOKER.HAVE RELISE AIR OUT Abu bukk 11/29/2010 5:34:50 PMVery well said asgar I'm a Muslim Sunni aswell and I agree that all Muslims are brothers wa Salam Albert Hakim 11/29/2010 4:56:39 PMWhat if this is a real leak?! Then what? I think if Iranians are smart, they should give it a possibility. I believe, Iranians should not trust Arabs who have proven to be America's servants in the Middle East. Truth seeker 11/29/2010 4:42:26 PMThe Council on Foreign Relations (most influential foreign-policy think tank), are the secret rulers of every country and they can knock out anyone who doesn't obey their rules. Make for Public 11/29/2010 4:27:41 PMWikileaks is an Zionist Agent Provocateur, Period. sana 11/29/2010 4:09:26 PMThis is a cheap game and will not work at all. if they think people in the ME are stupid; they prove themselves to be stupid. At the end of the day, they will be the losing party. We consider themselves brothers and sisters and will remains so. Days of colonialism and imperialism are over. You cannot rule the whole China with a bunch of colonial thiefs anymore. ASGAR 11/29/2010 3:43:47 PMIM a Sunni if the west or Arab Leaders are trying to divide shia and Sunni they will fail with me, my friends and people i talk to. We all see the Good Iran is doing and i hope it will bring us closer and end the man made divied of sunni /shia for good. south african 11/29/2010 3:39:24 PMAgreed. America would have stopped this if they were not behind it. They are a super power and should be able to stop some man from stealing their top secret documents, which are probably hidden inside a thick vault with 10 CIA agents guarding it. James 11/29/2010 3:38:07 PMIran has not fallen for childish Amreican tricks. Congratulations. Iran knows Wiki and other such attempts are ploys of its enemies. Every child can see throught them. Ernest in USA 11/29/2010 3:37:56 PMSince our government has lost all its credibility with us Americans due to its lies to get us in a war against Iraq, it has to release propaganda through other sources, like wikileaks. These are not leaks, but deliberate propaganda attempts to incite hatred against Iran, and division between Muslim governments. We Americans are not falling for it! Former US Marine 11/29/2010 3:27:28 PMWikileaks spreads the OFFICIAL 9/11 propaganda and even says Bin Laden is still alive. So funny. Anyone with half a brain knows that 9/11 was a DEMOLITION done by Israel and Zionist Traitors. Wikileaks is 100[[]%] Zionist approved propaganda. Wikileaks = controlled opposition NY 11/29/2010 3:22:45 PMPresident Ahmadinejad is absolutely correct in what he says. It is so nice to read facts and not the lies and deceptions in the US media that even a baby can see through. Long live Iran! Londoner 11/29/2010 3:20:37 PMThe leaks said Netanyahu is "a charming man." Most other leaders were insulted. Guess who is behind these "leaks." KIKI 11/29/2010 3:06:24 PMLOOK ONLY TO THE MEDIA THAT WIKILEAKS HAVE CHOSEN TO GIVE THEM THE SO/CALLED LEAKS, DER SPIEGEL AND LE MONDE ARE THE SAME MEDIA THAT PUBLISHED THE SO/CALLED ACCUSATIONS OF HIZBOLLAH ON THE HARIRI CASE. I WONDER WHY THE ISRAELI MEDIA LOOKS SOO HAPPY ABOUT ALL THIS. WHY THEIR IS SOO FEW THINGS ABOUT ISRAEL IN THE SO/CALLED LEAKS. IT DOESNT SEEM RATIONAL THAT ONE MAN CAN LEAK SOOO MUCH OF THE SO/CALLED SECRET DOC. bob 11/29/2010 3:03:01 PMWikileaks is israel!!!! Its so obvious!! truthseeker 11/29/2010 2:59:23 PMJulian Assange works for the cia and is also funded by George Soros. Do you really think that this guy would still be walking around as freely as he does if they did not want this info out. This guy is well known in the alternative media for being funded by soros and why does he release the info first to state controlled newspapers, why not alternative news, which is getting bigger by the day. CD 11/29/2010 2:58:04 PMYes, President Mahmoud Ahmadinejad is right and we should all come together united against western imperialisme. Unity and Tolerance amongst the people is the "Leitmotive" and a new equale world order,permetting us to secure the future of the humanity and making this world a better place to live for our children. Nick 11/29/2010 2:57:03 PMThe US government controls our finances eg. wall street derivatives... They control our business, eg. government motors (GM)... and they control our press, along with all these so-called 'Wiki leaks' ! To All Iranians 11/29/2010 2:22:30 PMAlways ask yourselve what is the consequence of what you say in reacting to hearsay accounts like WikiLeak stories. Your enemies live in hypocricy. They force international commissions like IAEA to act and report in hypocricy. They demonstrate in their own courts to judge as hypocrites. They blame you and find you guilty with hypocricy. Do not fall for it. Demand facts and proofs. Rely on the verified public statements of leaders. Show your enemies that they are the stupid ones. Iranian 11/29/2010 2:12:43 PMWell, it's quite obvious. lots of was about Iran and how Iran hated by american puppets in the middle east. and also some ridiculous useless about some other things that we already knew about them, just to make the whole thing acceptable. I really thought that they would prepare the material much better than the first time. but it was even more obvious who leaked those. Seems they are getting sloppy and desperate. Common Sense 11/29/2010 1:51:01 PMChances leak ever to survive World of Zionis regime that include US. Agent will be assassinate period (even their President). Infomation need to be filted carefully and wisely. To good to be true for sure. Pakistani 11/29/2010 1:49:44 PMAhmadinejad is very wise to ignore wikileaks revelations by branding it a propagenda.Although you have to be very naive to actually believe this is a propaganda but Ahmadinejad is right to call it a propaganda in public. I would have done the exact same thing. Disagreement between iran and saudiarabia should never turn into a war between sunni and shias. Mona Montgomery 11/29/2010 1:40:45 PMMohammed, thank you for explaing that. Mohammed 11/29/2010 1:16:40 PMYes, very smart man. I think the same thing. There is something not quite right about the Wikileaks. Maybe the this whole 'leak' thing is a controlled dissent by the Western powers. The real juicy stuff will stay in storage for the next 100 years. From baloand at googlemail.com Tue Nov 30 11:10:39 2010 From: baloand at googlemail.com (baloan) Date: Tue, 30 Nov 2010 08:10:39 -0800 (PST) Subject: remote control firefox with python References: <4cf273b9$0$19685$426a74cc@news.free.fr> Message-ID: <0b5e1c60-b594-4479-a429-35629b7e61d9@y23g2000yqd.googlegroups.com> On Nov 28, 4:22?pm, News123 wrote: > Hi, > > I wondered whether there is a simpe way to > 'remote' control fire fox with python. > > With remote controlling I mean: > - enter a url in the title bar and click on it > - create a new tab > - enter another url click on it > - save the html document of this page > - Probably the most difficult one: emulate a click or 'right click' on a > certain button or link of the current page. > - other interesting things would be to be able to enter the master > ? ? ? ? password from a script > - to enable disable proxy settings while running. > > The reason why I want to stay within Firefox and not use any other > 'mechanize' frame work is, that the pages I want to automate might > contain a lot of javascript for the construction of the actual page. > > Thanks in advance for any pointers ideas. I have had some good experience with Sikuli. http://sikuli.org/ Regards, Andreas baloan at gmail.com From giacomo.boffi at polimi.it Tue Nov 30 12:00:41 2010 From: giacomo.boffi at polimi.it (Giacomo Boffi) Date: Tue, 30 Nov 2010 18:00:41 +0100 Subject: Using property() to extend Tkinter classes but Tkinter classes are old-style classes? References: <1290977244.17714.1407556497@webmail.messagingengine.com> Message-ID: <8639qikapy.fsf@aiuole.stru.polimi.it> Terry Reedy writes: > On 11/28/2010 3:47 PM, python at bdurham.com wrote: >> I had planned on subclassing Tkinter.Toplevel() using property() to wrap >> access to properties like a window's title. >> After much head scratching and a peek at the Tkinter.py source, I >> realized that all Tkinter classes are old-style classes (even under >> Python 2.7). >> 1. Is there a technical reason why Tkinter classes are still old-style >> classes? > > To not break old code. Being able to break code by upgrading all > classes in the stdlib was one of the reasons for 3.x. In 3.x, are Tkinter classes still derived by old-style classes? From __peter__ at web.de Tue Nov 30 12:53:14 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 30 Nov 2010 18:53:14 +0100 Subject: Python 3 encoding question: Read a filename from stdin, subsequently open that filename References: <1291124813.414884.22.camel@WOPR> Message-ID: Albert Hopkins wrote: > On Tue, 2010-11-30 at 11:52 +0100, Peter Otten wrote: > Dan Stromberg wrote: >> >> > I've got a couple of programs that read filenames from stdin, and > then >> > open those files and do things with them. These programs sort of do >> > the *ix xargs thing, without requiring xargs. >> > >> > In Python 2, these work well. Irrespective of how filenames are >> > encoded, things are opened OK, because it's all just a stream of >> > single byte characters. >> >> I think you're wrong. The filenames' encoding as they are read from stdin >> must be the same as the encoding used by the file system. If the file >> system expects UTF-8 and you feed it ISO-8859-1 you'll run into errors. >> > I think this is wrong. In Unix there is no concept of filename > encoding. Filenames can have any arbitrary set of bytes (except '/' and > '\0'). But the filesystem itself neither knows nor cares about > encoding. I think you misunderstood what I was trying to say. If you write a list of filenames into files.txt, and use an encoding (ISO-8859-1, say) other than that used by the shell to display file names (on Linux typically UTF-8 these days) and then write a Python script exist.py that reads filenames and checks for the files' existence, $ python3 exist.py < files.txt will report that a file b'\xe4\xf6\xfc.txt' doesn't exist. The user looking at his editor with the encoding set to ISO-8859-1 seeing the line ???.txt and then going to the console typing $ ls ???.txt will be confused even though everything is working correctly. The system may be shuffling bytes, but the user thinks in codepoints and sometimes assumes that codepoints and bytes are the same. > You always have to know either >> >> (a) both the file system's and stdin's actual encoding, or >> (b) that both encodings are the same. >> >> > If this is true, then I think that it is wrong to do in Python3. Any > language should be able to deal with the filenames that the host OS > allows. > > Anyway, going on with the OP.. can you open stdin so that you can accept > arbitrary bytes instead of strings and then open using the bytes as the > filename? You can access the underlying stdin.buffer that feeds you the raw bytes with no attempt to shoehorn them into codepoints. You can use filenames that are not valid in the encoding that the system uses to display filenames: $ ls $ python3 Python 3.1.1+ (r311:74480, Nov 2 2009, 15:45:00) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> with open(b"\xe4\xf6\xfc.txt", "w") as f: ... f.write("hello\n") ... 6 >>> $ ls ???.txt > I don't have that much experience with Python3 to say for sure. Me neither. Peter From hansmu at xs4all.nl Tue Nov 30 13:01:05 2010 From: hansmu at xs4all.nl (Hans Mulder) Date: Tue, 30 Nov 2010 19:01:05 +0100 Subject: Using property() to extend Tkinter classes but Tkinter classes are old-style classes? In-Reply-To: <8639qikapy.fsf@aiuole.stru.polimi.it> References: <1290977244.17714.1407556497@webmail.messagingengine.com> <8639qikapy.fsf@aiuole.stru.polimi.it> Message-ID: <4cf53bf6$0$65870$e4fe514c@news.xs4all.nl> Giacomo Boffi wrote: > Terry Reedy writes: > >> On 11/28/2010 3:47 PM, python at bdurham.com wrote: >>> I had planned on subclassing Tkinter.Toplevel() using property() to wrap >>> access to properties like a window's title. >>> After much head scratching and a peek at the Tkinter.py source, I >>> realized that all Tkinter classes are old-style classes (even under >>> Python 2.7). >>> 1. Is there a technical reason why Tkinter classes are still old-style >>> classes? >> To not break old code. Being able to break code by upgrading all >> classes in the stdlib was one of the reasons for 3.x. > > In 3.x, are Tkinter classes still derived by old-style classes? 3.x does not provide old-style classes. Oh, and the name Tkinter was changed to tkinter: all modules in the standard library have lower case names in 3.x. HTH, -- HansM From iamforufriends at gmail.com Tue Nov 30 13:43:12 2010 From: iamforufriends at gmail.com (dating for ad^u lt girls) Date: Tue, 30 Nov 2010 10:43:12 -0800 (PST) Subject: HAI...THIS POST FOR GIRLS ONLY.. FREE DATING FOR GIRLS WAITING A GIRLS GROUP HERE. Message-ID: <5cf43f0d-73cf-4735-9788-5e0df97acba3@h17g2000pre.googlegroups.com> HAI...THIS POST FOR GIRLS ONLY.. FREE DATING FOR GIRLS WAITING A GIRLS GROUP HERE. http://u3.co.za/mm http://u3.co.za/mm http://u3.co.za/mm http://u3.co.za/mm http://u3.co.za/mm From robert.kern at gmail.com Tue Nov 30 13:49:05 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 30 Nov 2010 12:49:05 -0600 Subject: Using property() to extend Tkinter classes but Tkinter classes are old-style classes? In-Reply-To: <8639qikapy.fsf@aiuole.stru.polimi.it> References: <1290977244.17714.1407556497@webmail.messagingengine.com> <8639qikapy.fsf@aiuole.stru.polimi.it> Message-ID: On 11/30/10 11:00 AM, Giacomo Boffi wrote: > Terry Reedy writes: > >> On 11/28/2010 3:47 PM, python at bdurham.com wrote: >>> I had planned on subclassing Tkinter.Toplevel() using property() to wrap >>> access to properties like a window's title. >>> After much head scratching and a peek at the Tkinter.py source, I >>> realized that all Tkinter classes are old-style classes (even under >>> Python 2.7). >>> 1. Is there a technical reason why Tkinter classes are still old-style >>> classes? >> >> To not break old code. Being able to break code by upgrading all >> classes in the stdlib was one of the reasons for 3.x. > > In 3.x, are Tkinter classes still derived by old-style classes? No. [~]$ python3 Python 3.1.2 (r312:79360M, Mar 24 2010, 01:33:18) [GCC 4.0.1 (Apple Inc. build 5493)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import tkinter >>> tkinter.Tk.mro() [, , , ] >>> -- 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 eric.frederich at gmail.com Tue Nov 30 13:57:56 2010 From: eric.frederich at gmail.com (Eric Frederich) Date: Tue, 30 Nov 2010 13:57:56 -0500 Subject: C struct to Python Message-ID: I am not sure how to proceed. I am writing a Python interface to a C library. The C library uses structures. I was looking at the struct module but struct.unpack only seems to deal with data that was packed using struct.pack or some other buffer. All I have is the struct itself, a pointer in C. Is there a way to unpack directly from a memory address? Right now on the C side of things I can create a buffer of the struct data like so... MyStruct ms; unsigned char buffer[sizeof(MyStruct) + 1]; memcpy(buffer, &ms, sizeof(MyStruct)); return Py_BuildValue("s#", buffer, sizeof(MyStruct)); Then on the Python side I can unpack it using struct.unpack. I'm just wondering if I need to jump through these hoops of packing it on the C side or if I can do it directly from Python. Thanks, ~Eric From nbtulley at gmail.com Tue Nov 30 14:03:01 2010 From: nbtulley at gmail.com (iGet) Date: Tue, 30 Nov 2010 11:03:01 -0800 (PST) Subject: Almost free iPod Message-ID: I know nothing is ever free and that is true. However, you can get things really cheap. Two offers I am working on right now are: (Copy and Paste link into your web browser) A Free iPod 64gb - http://www.YouriPodTouch4free.com/index.php?ref=6695331 Here is how it works: You click on one of the links above, select the item you want, then enter your email in the sign-up section. The next page it will ask you if you want to do the offer as referral or points, I would suggest referral. Now it is going to take you to your main page. Here you will need to complete a level A offer or 50 points in level B offers. Now you may have the question, is this legit. Surf the internet about these sites and you will find out that they are legit. I will not lie; it is hard to get the referrals needed to get the items. A suggestion is try joining the Freebie Forums. There are several people at these forums doing the same thing we are doing and this may help you get some referrals quicker. From debatem1 at gmail.com Tue Nov 30 14:16:24 2010 From: debatem1 at gmail.com (geremy condra) Date: Tue, 30 Nov 2010 11:16:24 -0800 Subject: C struct to Python In-Reply-To: References: Message-ID: On Tue, Nov 30, 2010 at 10:57 AM, Eric Frederich wrote: > I am not sure how to proceed. > I am writing a Python interface to a C library. > The C library uses structures. > I was looking at the struct module but struct.unpack only seems to > deal with data that was packed using struct.pack or some other buffer. > All I have is the struct itself, a pointer in C. > Is there a way to unpack directly from a memory address? > > Right now on the C side of things I can create a buffer of the struct > data like so... > > ? ?MyStruct ms; > ? ?unsigned char buffer[sizeof(MyStruct) + 1]; > ? ?memcpy(buffer, &ms, sizeof(MyStruct)); > ? ?return Py_BuildValue("s#", buffer, sizeof(MyStruct)); > > Then on the Python side I can unpack it using struct.unpack. > > I'm just wondering if I need to jump through these hoops of packing it > on the C side or if I can do it directly from Python. > > Thanks, > ~Eric ctypes[0] sounds like a possible solution, although if you're already writing a C extension it might be better practice to just write a Python object that wraps your C struct appropriately. If you're not wedded to the C extension, though, I've had very good luck writing C interfaces with with ctypes and a few useful decorators [1], [2]. Others prefer Cython[3], which I like for speed but which sometimes seems to get in my way when I'm trying to interface with existing code. There's a good, if somewhat dated, overview of a few other strategies here[4]. Geremy Condra [0]: http://docs.python.org/library/ctypes.html [1]: http://code.activestate.com/recipes/576734-c-struct-decorator/ [2]: http://code.activestate.com/recipes/576731/ [3]: http://www.cython.org/ [4]: http://www.suttoncourtenay.org.uk/duncan/accu/integratingpython.html From martin at v.loewis.de Tue Nov 30 14:47:57 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Tue, 30 Nov 2010 20:47:57 +0100 Subject: Python 3 encoding question: Read a filename from stdin, subsequently open that filename In-Reply-To: References: Message-ID: <4CF554ED.9050706@v.loewis.de> > Does anyone know what I need to do to read filenames from stdin with > Python 3.1 and subsequently open them, when some of those filenames > include characters with their high bit set? If your files on disk use file names encoded in iso-8859-1, don't set your locale to a UTF-8 locale (as you apparently do), but set it to a locale that actually matches the encoding that you use. Regards, Martin From martin at v.loewis.de Tue Nov 30 14:47:57 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Tue, 30 Nov 2010 20:47:57 +0100 Subject: Python 3 encoding question: Read a filename from stdin, subsequently open that filename In-Reply-To: References: Message-ID: <4CF554ED.9050706@v.loewis.de> > Does anyone know what I need to do to read filenames from stdin with > Python 3.1 and subsequently open them, when some of those filenames > include characters with their high bit set? If your files on disk use file names encoded in iso-8859-1, don't set your locale to a UTF-8 locale (as you apparently do), but set it to a locale that actually matches the encoding that you use. Regards, Martin From portoms at gmail.com Tue Nov 30 15:09:14 2010 From: portoms at gmail.com (Thomas Portmann) Date: Tue, 30 Nov 2010 21:09:14 +0100 Subject: [Q] get device major/minor number Message-ID: Hello all, In a script I would like to extract all device infos from block or character device. The "stat" function gives me most of the infos (mode, timestamp, user and group id, ...), however I did not find how to get the devices major and minor numbers. Of course I could do it by calling an external program, but is it possible to stay within python? In the example below, I would like to get the major (8) and minor (0, 1, 2) numbers of /dev/sda{,1,2}. How can I get them? user at host:~$ ls -l /dev/sda /dev/sda1 /dev/sda2 brw-rw---- 1 root disk 8, 0 Nov 30 19:10 /dev/sda brw-rw---- 1 root disk 8, 1 Nov 30 19:10 /dev/sda1 brw-rw---- 1 root disk 8, 2 Nov 30 19:10 /dev/sda2 user at host:~$ python3.1 -c 'import os for el in ["","1","2"]: print(os.stat("/dev/sda"+el));' posix.stat_result(st_mode=25008, st_ino=1776, st_dev=5, st_nlink=1, st_uid=0, st_gid=6, st_size=0, st_atime=1291140641, st_mtime=1291140640, st_ctime=1291140640) posix.stat_result(st_mode=25008, st_ino=1780, st_dev=5, st_nlink=1, st_uid=0, st_gid=6, st_size=0, st_atime=1291140644, st_mtime=1291140641, st_ctime=1291140641) posix.stat_result(st_mode=25008, st_ino=1781, st_dev=5, st_nlink=1, st_uid=0, st_gid=6, st_size=0, st_atime=1291140644, st_mtime=1291140641, st_ctime=1291140641) Thanks Tom From dan at catfolks.net Tue Nov 30 15:18:38 2010 From: dan at catfolks.net (Dan M) Date: Tue, 30 Nov 2010 14:18:38 -0600 Subject: [Q] get device major/minor number References: Message-ID: <5O6dnWNw3MaDwWjRnZ2dnUVZ_vOdnZ2d@powerusenet.com> On Tue, 30 Nov 2010 21:09:14 +0100, Thomas Portmann wrote: > Hello all, > > In a script I would like to extract all device infos from block or > character device. The "stat" function gives me most of the infos (mode, > timestamp, user and group id, ...), however I did not find how to get > the devices major and minor numbers. Of course I could do it by calling > an external program, but is it possible to stay within python? > > In the example below, I would like to get the major (8) and minor (0, 1, > 2) numbers of /dev/sda{,1,2}. How can I get them? I think the os.major() and os.minor() calls ought to do what you want. >>> import os >>> s = os.stat('/dev/sda1') >>> os.major(s.st_rdev) 8 >>> os.minor(s.st_rdev) 1 >>> dan at dan:~$ ls -l /dev/sda1 brw-rw---- 1 root disk 8, 1 2010-11-18 05:41 /dev/sda1 From ben+python at benfinney.id.au Tue Nov 30 15:19:32 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 01 Dec 2010 07:19:32 +1100 Subject: Memory issues when storing as List of Strings vs List of List References: Message-ID: <87vd3e36p7.fsf@benfinney.id.au> OW Ghim Siong writes: > I have a big file 1.5GB in size, with about 6 million lines of > tab-delimited data. I have to perform some filtration on the data and > keep the good data. After filtration, I have about 5.5 million data > left remaining. As you might already guessed, I have to read them in > batches and I did so using .readlines(100000000). Why do you need to handle the batching in your code? Perhaps you're not aware that a file object is already an iterator for the lines of text in the file. > After reading each batch, I will split the line (in string format) to > a list using .split("\t") and then check several conditions, after > which if all conditions are satisfied, I will store the list into a > matrix. As I understand it, you don't need a line after moving to the next. So there's no need to maintain a manual buffer of lines at all; please explain if there is something additional requiring a huge buffer of input lines. > The code is as follows: > -----Start------ > a=open("bigfile") > matrix=[] > while True: > lines = a.readlines(100000000) > for line in lines: > data=line.split("\t") > if several_conditions_are_satisfied: > matrix.append(data) > print "Number of lines read:", len(lines), "matrix.__sizeof__:", > matrix.__sizeof__() > if len(lines)==0: > break > -----End----- Using the file's native line iterator:: infile = open("bigfile") matrix = [] for line in infile: record = line.split("\t") if several_conditions_are_satisfied: matrix.append(record) > Results: > Number of lines read: 461544 matrix.__sizeof__: 1694768 > Number of lines read: 449840 matrix.__sizeof__: 3435984 > Number of lines read: 455690 matrix.__sizeof__: 5503904 > Number of lines read: 451955 matrix.__sizeof__: 6965928 > Number of lines read: 452645 matrix.__sizeof__: 8816304 > Number of lines read: 448555 matrix.__sizeof__: 9918368 > > Traceback (most recent call last): > MemoryError If you still get a MemoryError, you can use the ?pdb? module to debug it interactively. Another option is to catch the MemoryError and construct a diagnostic message similar to the one you had above:: import sys infile = open("bigfile") matrix = [] for line in infile: record = line.split("\t") if several_conditions_are_satisfied: try: matrix.append(record) except MemoryError: matrix_len = len(matrix) sys.stderr.write( "len(matrix): %(matrix_len)d\n" % vars()) raise > I have tried creating such a matrix of equivalent size and it only > uses 35mb of memory but I am not sure why when using the code above, > the memory usage shot up so fast and exceeded 2GB. > > Any advice is greatly appreciated. With large data sets, and the manipulation and computation you will likely be wanting to perform, it's probably time to consider the NumPy library which has much more powerful array types, part of the SciPy library . -- \ ?[It's] best to confuse only one issue at a time.? ?Brian W. | `\ Kernighan, Dennis M. Ritchie, _The C programming language_, 1988 | _o__) | Ben Finney From goldtech at worldpost.com Tue Nov 30 15:28:38 2010 From: goldtech at worldpost.com (goldtech) Date: Tue, 30 Nov 2010 12:28:38 -0800 (PST) Subject: SAX unicode and ascii parsing problem Message-ID: Hi, I'm trying to parse an xml file using SAX. About half-way through a file I get this error: Traceback (most recent call last): File "C:\Python26\Lib\site-packages\pythonwin\pywin\framework \scriptutils.py", line 325, in RunScript exec codeObject in __main__.__dict__ File "E:\sc\b2.py", line 58, in parser.parse(open(r'ppb5.xml')) File "C:\Python26\Lib\xml\sax\expatreader.py", line 107, in parse xmlreader.IncrementalParser.parse(self, source) File "C:\Python26\Lib\xml\sax\xmlreader.py", line 123, in parse self.feed(buffer) File "C:\Python26\Lib\xml\sax\expatreader.py", line 207, in feed self._parser.Parse(data, isFinal) File "C:\Python26\Lib\xml\sax\expatreader.py", line 304, in end_element self._cont_handler.endElement(name) File "E:\sc\b2.py", line 51, in endElement d.write(csv+"\n") UnicodeEncodeError: 'ascii' codec can't encode characters in position 146-147: ordinal not in range(128) I'm using ActivePython 2.6. I trying to figure out the simplest fix. If there's a Python way to just take the source XML file and covert/ process it so this will not happen - that would be best. Or should I just update to Python 3 ? I tried this but nothing changed, I thought this might convert it and then I'd paerse the new file - didn't work: uc = open(r'E:\sc\ppb4.xml').read().decode('utf8') ascii = uc.decode('ascii') mex9 = open( r'E:\scrapes\ppb5.xml', 'w' ) mex9.write(ascii) Again I'm looking for something simple even it's a few more lines of codes...or upgrade(?) Thanks, appreciate any help. mex9.close() From mohammed.php.developer at gmail.com Tue Nov 30 15:30:28 2010 From: mohammed.php.developer at gmail.com (mohammed_a_o) Date: Tue, 30 Nov 2010 12:30:28 -0800 (PST) Subject: get a free domain , free design , and free host Message-ID: <83cc9e82-635d-46ce-b712-22b7b4b748ce@i32g2000pri.googlegroups.com> get a free domain , free design , and free host http://freedesignandhost.co.cc/ get a free domain , free design , and free host http://freedesignandhost.co.cc/free-design.php http://freedesignandhost.co.cc/free-host.php http://freedesignandhost.co.cc/free-domain.php From portoms at gmail.com Tue Nov 30 15:35:43 2010 From: portoms at gmail.com (Thomas Portmann) Date: Tue, 30 Nov 2010 21:35:43 +0100 Subject: [Q] get device major/minor number In-Reply-To: <5O6dnWNw3MaDwWjRnZ2dnUVZ_vOdnZ2d@powerusenet.com> References: <5O6dnWNw3MaDwWjRnZ2dnUVZ_vOdnZ2d@powerusenet.com> Message-ID: On Tue, Nov 30, 2010 at 9:18 PM, Dan M wrote: > On Tue, 30 Nov 2010 21:09:14 +0100, Thomas Portmann wrote: >> In the example below, I would like to get the major (8) and minor (0, 1, >> 2) numbers of /dev/sda{,1,2}. How can I get them? > > I think the os.major() and os.minor() calls ought to do what you want. > >>>> import os >>>> s = os.stat('/dev/sda1') >>>> os.major(s.st_rdev) > 8 >>>> os.minor(s.st_rdev) > 1 Thank you very much Dan, this is exactly what I was looking for. Tom From dan at catfolks.net Tue Nov 30 15:41:47 2010 From: dan at catfolks.net (Dan M) Date: Tue, 30 Nov 2010 14:41:47 -0600 Subject: [Q] get device major/minor number References: <5O6dnWNw3MaDwWjRnZ2dnUVZ_vOdnZ2d@powerusenet.com> Message-ID: <5O6dnWJw3MYW_GjRnZ2dnUVZ_vOdnZ2d@powerusenet.com> On Tue, 30 Nov 2010 21:35:43 +0100, Thomas Portmann wrote: > Thank you very much Dan, this is exactly what I was looking for. > > > Tom You're very welcome. From goldtech at worldpost.com Tue Nov 30 15:43:55 2010 From: goldtech at worldpost.com (goldtech) Date: Tue, 30 Nov 2010 12:43:55 -0800 (PST) Subject: SAX unicode and ascii parsing problem Message-ID: <7fd52fd8-c6e0-48fa-bc50-1cff3354c3a3@u9g2000pra.googlegroups.com> Hi, I'm trying to parse an xml file using SAX. About half-way through a file I get this error: Traceback (most recent call last): File "C:\Python26\Lib\site-packages\pythonwin\pywin\framework \scriptutils.py", line 325, in RunScript exec codeObject in __main__.__dict__ File "E:\sc\b2.py", line 58, in parser.parse(open(r'ppb5.xml')) File "C:\Python26\Lib\xml\sax\expatreader.py", line 107, in parse xmlreader.IncrementalParser.parse(self, source) File "C:\Python26\Lib\xml\sax\xmlreader.py", line 123, in parse self.feed(buffer) File "C:\Python26\Lib\xml\sax\expatreader.py", line 207, in feed self._parser.Parse(data, isFinal) File "C:\Python26\Lib\xml\sax\expatreader.py", line 304, in end_element self._cont_handler.endElement(name) File "E:\sc\b2.py", line 51, in endElement d.write(csv+"\n") UnicodeEncodeError: 'ascii' codec can't encode characters in position 146-147: ordinal not in range(128) I'm using ActivePython 2.6. I trying to figure out the simplest fix. If there's a Python way to just take the source XML file and covert/ process it so this will not happen - that would be best. Or should I just update to Python 3 ? I tried this but nothing changed, I thought this might convert it and then I'd paerse the new file - didn't work: uc = open(r'E:\sc\ppb4.xml').read().decode('utf8') ascii = uc.decode('ascii') mex9 = open( r'E:\scrapes\ppb5.xml', 'w' ) mex9.write(ascii) Again I'm looking for something simple even it's a few more lines of codes...or upgrade(?) Thanks, appreciate any help. mex9.close() From steve at holdenweb.com Tue Nov 30 16:02:30 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 30 Nov 2010 16:02:30 -0500 Subject: SAX unicode and ascii parsing problem In-Reply-To: <7fd52fd8-c6e0-48fa-bc50-1cff3354c3a3@u9g2000pra.googlegroups.com> References: <7fd52fd8-c6e0-48fa-bc50-1cff3354c3a3@u9g2000pra.googlegroups.com> Message-ID: On 11/30/2010 3:43 PM, goldtech wrote: > Hi, > > I'm trying to parse an xml file using SAX. About half-way through a > file I get this error: > > Traceback (most recent call last): > File "C:\Python26\Lib\site-packages\pythonwin\pywin\framework > \scriptutils.py", line 325, in RunScript > exec codeObject in __main__.__dict__ > File "E:\sc\b2.py", line 58, in > parser.parse(open(r'ppb5.xml')) > File "C:\Python26\Lib\xml\sax\expatreader.py", line 107, in parse > xmlreader.IncrementalParser.parse(self, source) > File "C:\Python26\Lib\xml\sax\xmlreader.py", line 123, in parse > self.feed(buffer) > File "C:\Python26\Lib\xml\sax\expatreader.py", line 207, in feed > self._parser.Parse(data, isFinal) > File "C:\Python26\Lib\xml\sax\expatreader.py", line 304, in > end_element > self._cont_handler.endElement(name) > File "E:\sc\b2.py", line 51, in endElement > d.write(csv+"\n") > UnicodeEncodeError: 'ascii' codec can't encode characters in position > 146-147: ordinal not in range(128) > > I'm using ActivePython 2.6. I trying to figure out the simplest fix. > If there's a Python way to just take the source XML file and covert/ > process it so this will not happen - that would be best. Or should I > just update to Python 3 ? > > I tried this but nothing changed, I thought this might convert it and > then I'd paerse the new file - didn't work: > > uc = open(r'E:\sc\ppb4.xml').read().decode('utf8') > ascii = uc.decode('ascii') > mex9 = open( r'E:\scrapes\ppb5.xml', 'w' ) > mex9.write(ascii) > > Again I'm looking for something simple even it's a few more lines of > codes...or upgrade(?) > > Thanks, appreciate any help. > mex9.close() I'm just as stumped as I was when you first asked this question 13 minutes ago. ;-) regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From pakalk at gmail.com Tue Nov 30 16:03:24 2010 From: pakalk at gmail.com (pakalk) Date: Tue, 30 Nov 2010 13:03:24 -0800 (PST) Subject: IMAP support References: <13ee8219-5925-4978-ba89-83ee0f7b7820@30g2000yqm.googlegroups.com> Message-ID: <8ec7b311-8278-4617-8de5-2c58d335d91d@e20g2000vbx.googlegroups.com> Please, give me an example of raw query to IMAP server? And why do you focus on "Nevermind is so ekhm... nevermind... "?? Cannot you just help? From goldtech at worldpost.com Tue Nov 30 16:15:53 2010 From: goldtech at worldpost.com (goldtech) Date: Tue, 30 Nov 2010 13:15:53 -0800 (PST) Subject: SAX unicode and ascii parsing problem References: <7fd52fd8-c6e0-48fa-bc50-1cff3354c3a3@u9g2000pra.googlegroups.com> Message-ID: snip... > > I'm just as stumped as I was when you first asked this question 13 > minutes ago. ;-) > > regards > ?Steve > snip... Hi Steve, Think I found it, for example: line = 'my big string' line.encode('ascii', 'ignore') I processed the problem strings during parsing with this and it works now. Got this from: http://stackoverflow.com/questions/2365411/python-convert-unicode-to-ascii-without-errors Best, Lee :^) From justin.mailinglists at gmail.com Tue Nov 30 16:20:45 2010 From: justin.mailinglists at gmail.com (Justin Ezequiel) Date: Tue, 30 Nov 2010 13:20:45 -0800 (PST) Subject: SAX unicode and ascii parsing problem References: Message-ID: can't check right now but are you sure it's the parser and not this line d.write(csv+"\n") that's failing? what is d? From awilliam at whitemice.org Tue Nov 30 16:26:19 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Tue, 30 Nov 2010 16:26:19 -0500 Subject: IMAP support In-Reply-To: <8ec7b311-8278-4617-8de5-2c58d335d91d@e20g2000vbx.googlegroups.com> References: <13ee8219-5925-4978-ba89-83ee0f7b7820@30g2000yqm.googlegroups.com> <8ec7b311-8278-4617-8de5-2c58d335d91d@e20g2000vbx.googlegroups.com> Message-ID: <1291152379.12209.1.camel@linux-yu4c.site> On Tue, 2010-11-30 at 13:03 -0800, pakalk wrote: > Please, give me an example of raw query to IMAP server? I'm not certain what you mean by "raw query". > And why do you focus on "Nevermind is so ekhm... nevermind... "?? > Cannot you just help? This list does suffer from a case of "attitude". Most programming forums have that; Python "attitude" has its own special flavor. From javiervandam at gmail.com Tue Nov 30 16:31:26 2010 From: javiervandam at gmail.com (javivd) Date: Tue, 30 Nov 2010 13:31:26 -0800 (PST) Subject: Reading by positions plain text files Message-ID: <39a07597-02b9-4ef8-9ca9-93e2d2425e66@p7g2000prb.googlegroups.com> Hi all, Sorry, newbie question: I have database in a plain text file (could be .txt or .dat, it's the same) that I need to read in python in order to do some data validation. In other files I read this kind of files with the split() method, reading line by line. But split() relies on a separator character (I think... all I know is that it's work OK). I have a case now in wich another file has been provided (besides the database) that tells me in wich column of the file is every variable, because there isn't any blank or tab character that separates the variables, they are stick together. This second file specify the variable name and his position: VARIABLE NAME POSITION (COLUMN) IN FILE var_name_1 123-123 var_name_2 124-125 var_name_3 126-126 .. .. var_name_N 512-513 (last positions) How can I read this so each position in the file it's associated with each variable name? Thanks a lot!! Javier From khamenya at gmail.com Tue Nov 30 16:35:32 2010 From: khamenya at gmail.com (Valery Khamenya) Date: Tue, 30 Nov 2010 22:35:32 +0100 Subject: How to initialize each multithreading Pool worker with an individual value? Message-ID: Hi, multithreading.pool Pool has a promissing initializer argument in its constructor. However it doesn't look possible to use it to initialize each Pool's worker with some individual value (I'd wish to be wrong here) So, how to initialize each multithreading Pool worker with the individual values? The typical use case might be a connection pool, say, of 3 workers, where each of 3 workers has its own TCP/IP port. from multiprocessing.pool import Pool def port_initializer(_port): global port port = _port def use_connection(some_packet): global _port print "sending data over port # %s" % port if __name__ == "__main__": ports=((4001,4002, 4003), ) p = Pool(3, port_initializer, ports) # oops... :-) some_data_to_send = range(20) p.map(use_connection, some_data_to_send) best regards -- Valery A.Khamenya From pakalk at gmail.com Tue Nov 30 16:36:44 2010 From: pakalk at gmail.com (pakalk) Date: Tue, 30 Nov 2010 13:36:44 -0800 (PST) Subject: IMAP support References: <13ee8219-5925-4978-ba89-83ee0f7b7820@30g2000yqm.googlegroups.com> <8ec7b311-8278-4617-8de5-2c58d335d91d@e20g2000vbx.googlegroups.com> Message-ID: <170a6933-6b1e-4abd-bc80-6e4bc2fbd661@p38g2000vbn.googlegroups.com> On 30 Lis, 22:26, Adam Tauno Williams wrote: > On Tue, 2010-11-30 at 13:03 -0800, pakalk wrote: > > Please, give me an example of raw query to IMAP server? > > > > I'm not certain what you mean by "raw query". m = imap() m.query('UID SORT ...') # etc. Thanks for link :) From usernet at ilthio.net Tue Nov 30 17:43:21 2010 From: usernet at ilthio.net (Tim Harig) Date: Tue, 30 Nov 2010 22:43:21 +0000 (UTC) Subject: Reading by positions plain text files References: <39a07597-02b9-4ef8-9ca9-93e2d2425e66@p7g2000prb.googlegroups.com> Message-ID: On 2010-11-30, javivd wrote: > I have a case now in wich another file has been provided (besides the > database) that tells me in wich column of the file is every variable, > because there isn't any blank or tab character that separates the > variables, they are stick together. This second file specify the > variable name and his position: > > VARIABLE NAME POSITION (COLUMN) IN FILE > var_name_1 123-123 > var_name_2 124-125 > var_name_3 126-126 > .. > .. > var_name_N 512-513 (last positions) I am unclear on the format of these positions. They do not look like what I would expect from absolute references in the data. For instance, 123-123 may only contain one byte??? which could change for different encodings and how you mark line endings. Frankly, the use of the world columns in the header suggests that the data *is* separated by line endings rather then absolute position and the position refers to the line number. In which case, you can use splitlines() to break up the data and then address the proper line by index. Nevertheless, you can use file.seek() to move to an absolute offset in the file, if that really is what you are looking for. From mpnordland at gmail.com Tue Nov 30 17:47:32 2010 From: mpnordland at gmail.com (mpnordland) Date: Tue, 30 Nov 2010 14:47:32 -0800 (PST) Subject: Catching user switching and getting current active user from root on linux Message-ID: <1a9bdbd4-2997-4e0f-a24f-cd148247e312@r40g2000prh.googlegroups.com> I have situation where I need to be able to get the current active user, and catch user switching eg user1 locks screen, leaves computer, user2 comes, and logs on. basically, when there is any type of user switch my script needs to know. From usernet at ilthio.net Tue Nov 30 17:54:49 2010 From: usernet at ilthio.net (Tim Harig) Date: Tue, 30 Nov 2010 22:54:49 +0000 (UTC) Subject: Catching user switching and getting current active user from root on linux References: <1a9bdbd4-2997-4e0f-a24f-cd148247e312@r40g2000prh.googlegroups.com> Message-ID: On 2010-11-30, mpnordland wrote: > I have situation where I need to be able to get the current active > user, and catch user switching eg user1 locks screen, leaves computer, > user2 comes, and logs on. > basically, when there is any type of user switch my script needs to > know. Well you could use inotify to trigger on any changes to /var/log/wtmp. When a change is detected, you could check of deltas in the output of "who -a" to figure out what has changed since the last time wtmp triggered. From prologic at shortcircuit.net.au Tue Nov 30 18:04:10 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 1 Dec 2010 09:04:10 +1000 Subject: Catching user switching and getting current active user from root on linux In-Reply-To: References: <1a9bdbd4-2997-4e0f-a24f-cd148247e312@r40g2000prh.googlegroups.com> Message-ID: On Wed, Dec 1, 2010 at 8:54 AM, Tim Harig wrote: > Well you could use inotify to trigger on any changes to /var/log/wtmp. > When a change is detected, you could check of deltas in the output of "who > -a" to figure out what has changed since the last time wtmp triggered. This is a good idea and you could also make use of the following library: http://pypi.python.org/pypi?:action=search&term=utmp&submit=search cheers James -- -- James Mills -- -- "Problems are solved by method" From tjreedy at udel.edu Tue Nov 30 18:30:36 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 30 Nov 2010 18:30:36 -0500 Subject: how to go on learning python In-Reply-To: References: Message-ID: On 11/30/2010 9:37 AM, Xavier Heruacles wrote: > I'm basically a c/c++ programmer and recently come to python for some > web development. Using django and javascript I'm afraid I can develop > some web application now. But often I feel I'm not good at python. I > don't know much about generators, descriptors and decorators(although I > can use some of it to accomplish something, but I don't think I'm > capable of knowing its internals). I find my code ugly, and it seems > near everything are already gotten done by the libraries. When I want to > do something, I just find some libraries or modules and then just finish > the work. So I'm a bit tired of just doing this kind of high level > scripting, only to find myself a bad programmer. Then my question is > after one coded some kind of basic app, how one can keep on learning > programming using python? > Do some more interesting projects? Read more general books about > programming? or...? You can use both your old C skills and new Python skills by helping to develop Python by working on issues on the tracker bugs.python.org. If you are interested but needed help getting started, ask. -- Terry Jan Reedy From python at mrabarnett.plus.com Tue Nov 30 18:36:49 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 30 Nov 2010 23:36:49 +0000 Subject: Reading by positions plain text files In-Reply-To: <39a07597-02b9-4ef8-9ca9-93e2d2425e66@p7g2000prb.googlegroups.com> References: <39a07597-02b9-4ef8-9ca9-93e2d2425e66@p7g2000prb.googlegroups.com> Message-ID: <4CF58A91.50100@mrabarnett.plus.com> On 30/11/2010 21:31, javivd wrote: > Hi all, > > Sorry, newbie question: > > I have database in a plain text file (could be .txt or .dat, it's the > same) that I need to read in python in order to do some data > validation. In other files I read this kind of files with the split() > method, reading line by line. But split() relies on a separator > character (I think... all I know is that it's work OK). > > I have a case now in wich another file has been provided (besides the > database) that tells me in wich column of the file is every variable, > because there isn't any blank or tab character that separates the > variables, they are stick together. This second file specify the > variable name and his position: > > > VARIABLE NAME POSITION (COLUMN) IN FILE > var_name_1 123-123 > var_name_2 124-125 > var_name_3 126-126 > .. > .. > var_name_N 512-513 (last positions) > > How can I read this so each position in the file it's associated with > each variable name? > It sounds like a similar problem to this: http://groups.google.com/group/comp.lang.python/browse_thread/thread/53ebbbb6f41bfff6/123422d510187dc3?show_docid=123422d510187dc3 From vlastimil.brom at gmail.com Tue Nov 30 19:45:48 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Wed, 1 Dec 2010 01:45:48 +0100 Subject: Programming games in historical linguistics with Python In-Reply-To: References: Message-ID: 2010/11/30 Dax Bloom : > Hello, > > Following a discussion that began 3 weeks ago I would like to ask a > question regarding substitution of letters according to grammatical > rules in historical linguistics. I would like to automate the > transformation of words according to complex rules of phonology and > integrate that script in a visual environment. > Here follows the previous thread: > http://groups.google.com/group/comp.lang.python/browse_thread/thread/3c55f9f044c3252f/fe7c2c82ecf0dbf5?lnk=gst&q=evolutionary+linguistics#fe7c2c82ecf0dbf5 > > Is there a way to refer to vowels and consonants as a subcategory of > text? Is there a function to remove all vowels? How should one create > and order the dictionary file for the rules? How to chain several > transformations automatically from multiple rules? Finally can anyone > show me what existing python program or phonological software can do > this? > > What function could tag syllables, the word nucleus and the codas? How > easy is it to bridge this with a more visual environment where > interlinear, aligned text can be displayed with Greek notations and > braces as usual in the phonology textbooks? > > Best regards, > > Dax Bloom > -- > http://mail.python.org/mailman/listinfo/python-list > Hi, as far as I know, there is no predefined function or library for distinguishing vowels or consonants, but these can be simply implemented individually according to the exact needs. e.g. regular expressions can be used here: to remove vowels, the code could be (example from the command prompt): >>> import re >>> re.sub(r"(?i)[aeiouy]", "", "This is a SAMPLE TEXT") 'Ths s SMPL TXT' >>> See http://docs.python.org/library/re.html or http://www.regular-expressions.info/ for the regexp features. You may eventually try the new development version regex, which adds many interesting new features and remove some limitations http://bugs.python.org/issue2636 In some cases regular expressions aren't really appropriate or may become too complicated. Sometimes a parsing library like pyparsing may be a more adequate tool: http://pyparsing.wikispaces.com/ If the rules are simple enough, that they can be formulated for single characters or character clusters with a regular expression, you can model the phonological changes as a series of replacements with matching patterns and the respective replacement patterns. For character-wise matching and replacing the regular expressions are very effective; using lookarounds http://www.regular-expressions.info/lookaround.html even some combinatorics for conditional changes can be expressed; however, i would find some more complex conditions, suprasegmentals, morpheme boundaries etc. rather difficult to formalise this way... hth, vbr From drsalists at gmail.com Tue Nov 30 19:51:44 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 30 Nov 2010 16:51:44 -0800 Subject: Python 3 encoding question: Read a filename from stdin, subsequently open that filename In-Reply-To: <4CF554ED.9050706@v.loewis.de> References: <4CF554ED.9050706@v.loewis.de> Message-ID: On Tue, Nov 30, 2010 at 11:47 AM, Martin v. Loewis wrote: >> Does anyone know what I need to do to read filenames from stdin with >> Python 3.1 and subsequently open them, when some of those filenames >> include characters with their high bit set? > > If your files on disk use file names encoded in iso-8859-1, don't set > your locale to a UTF-8 locale (as you apparently do), but set it to > a locale that actually matches the encoding that you use. > > Regards, > Martin > It'd be great if all programs used the same encoding on a given OS, but at least on Linux, I believe historically filenames have been created with different encodings. IOW, if I pick one encoding and go with it, filenames written in some other encoding are likely to cause problems. So I need something for which a filename is just a blob that shouldn't be monkeyed with. From drsalists at gmail.com Tue Nov 30 19:57:57 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 30 Nov 2010 16:57:57 -0800 Subject: Python 3 encoding question: Read a filename from stdin, subsequently open that filename In-Reply-To: <20101130161919.693a1d78@pitrou.net> References: <339421.80548.qm@web54205.mail.re2.yahoo.com> <20101130161919.693a1d78@pitrou.net> Message-ID: On Tue, Nov 30, 2010 at 7:19 AM, Antoine Pitrou wrote: > On Mon, 29 Nov 2010 21:52:07 -0800 (PST) > Yingjie Lan wrote: >> --- On Tue, 11/30/10, Dan Stromberg wrote: >> > In Python 3, I'm finding that I have encoding issues with >> > characters >> > with their high bit set.? Things are fine with strictly >> > ASCII >> > filenames.? With high-bit-set characters, even if I >> > change stdin's >> > encoding with: >> >> Co-ask. I have also had problems with file names in >> Chinese characters with Python 3. I unzipped the >> turtle demo files into the desktop folder (of >> course, the word 'desktop' is in Chinese, it is >> a windows XP system, localization is Chinese), then >> all in a sudden some of the demos won't work >> anymore. But if I move it to a folder whose >> path contains only english characters, everything >> comes back to normal. > > Can you try the latest 3.2alpha4 (*) and check if this is fixed? > If not, then could you please open a bug on http://bugs.python.org ? > > (*) http://python.org/download/releases/3.2/ > > Thank you > > Antoine. I have the same problem using 3.2alpha4: the word man~ana (6 characters long) in a filename causes problems (I'm catching the exception and skipping the file for now) despite using what I believe is an 8-bit, all 256-bytes-are-characters encoding: iso-8859-1. 'not sure if you wanted both of us to try this, or Yingjie alone though. From drsalists at gmail.com Tue Nov 30 20:03:14 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 30 Nov 2010 17:03:14 -0800 Subject: Python 3 encoding question: Read a filename from stdin, subsequently open that filename In-Reply-To: References: <1291124813.414884.22.camel@WOPR> Message-ID: On Tue, Nov 30, 2010 at 9:53 AM, Peter Otten <__peter__ at web.de> wrote: > $ ls > $ python3 > Python 3.1.1+ (r311:74480, Nov ?2 2009, 15:45:00) > [GCC 4.4.1] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> with open(b"\xe4\xf6\xfc.txt", "w") as f: > ... ? ? f.write("hello\n") > ... > 6 >>>> > $ ls > ???.txt This sounds like a strong prospect for how to get things working (I didn't realize open would accept a bytes argument for the filename), but I'm also interested in whether reading filenames from stdin and subsequently opening them is supposed to "just work" given a suitable encoding - like with Java which also uses unicode strings. In Java, I'm told that ISO-8859-1 is supposed to "guarantee a roundtrip conversion". From gnarlodious at gmail.com Tue Nov 30 20:08:57 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Tue, 30 Nov 2010 17:08:57 -0800 (PST) Subject: Change one list item in place Message-ID: <17175f49-087f-4d05-ada2-7e8c7e7e86dd@z17g2000prz.googlegroups.com> This works for me: def sendList(): return ["item0", "item1"] def query(): l=sendList() return ["Formatting only {0} into a string".format(l[0]), l[1]] query() However, is there a way to bypass the l=sendList() and change one list item in-place? Possibly a list comprehension operating on a numbered item? -- Gnarlie From drsalists at gmail.com Tue Nov 30 20:12:33 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 30 Nov 2010 17:12:33 -0800 Subject: How to initialize each multithreading Pool worker with an individual value? In-Reply-To: References: Message-ID: On Tue, Nov 30, 2010 at 1:35 PM, Valery Khamenya wrote: > Hi, > > multithreading.pool Pool has a promissing initializer argument in its > constructor. > However it doesn't look possible to use it to initialize each Pool's > worker with some individual value (I'd wish to be wrong here) > > So, how to initialize each multithreading Pool worker with the > individual values? > > The typical use case might be a connection pool, say, of 3 workers, > where each of 3 workers has its own TCP/IP port. > > from multiprocessing.pool import Pool > > def port_initializer(_port): > ? ?global port > ? ?port = _port > > def use_connection(some_packet): > ? ?global _port > ? ?print "sending data over port # %s" % port > > if __name__ == "__main__": > ? ?ports=((4001,4002, 4003), ) > ? ?p = Pool(3, port_initializer, ports) # oops... :-) > ? ?some_data_to_send = range(20) > ? ?p.map(use_connection, some_data_to_send) Using an initializer with multiprocessing is something I've never tried. I have used queues with multiprocessing though, and I believe you could use them, at least as a fallback plan if you prefer to get the initializer to work. If you create in the parent a queue in shared memory (multiprocessing facilitates this nicely), and fill that queue with the values in your ports tuple, then you could have each child in the worker pool extract a single value from this queue so each worker can have its own, unique port value. HTH From nobody at nowhere.com Tue Nov 30 20:14:05 2010 From: nobody at nowhere.com (Nobody) Date: Wed, 01 Dec 2010 01:14:05 +0000 Subject: Python 3 encoding question: Read a filename from stdin, subsequently open that filename References: Message-ID: On Mon, 29 Nov 2010 21:26:23 -0800, Dan Stromberg wrote: > Does anyone know what I need to do to read filenames from stdin with > Python 3.1 and subsequently open them, when some of those filenames > include characters with their high bit set? Use "bytes" rather than "str". Everywhere. This means reading names from sys.stdin.buffer (which is a binary stream) rather than sys.stdin (which is a text stream). If you pass a "bytes" to an I/O function (e.g. open()), it will just pass the bytes directly to the OS without any decoding. But really, if you're writing *nix system utilities, you should probably stick with Python 2.x until the end of time. Using 3.x will just make life difficult for no good reason (e.g. in 3.x, os.environ also contains Unicode strings). From drsalists at gmail.com Tue Nov 30 20:27:26 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 30 Nov 2010 17:27:26 -0800 Subject: Intro to Python slides, was Re: how to go on learning python Message-ID: On Tue, Nov 30, 2010 at 6:37 AM, Xavier Heruacles wrote: > I'm basically a c/c++ programmer and recently come to python for some web > development. Using django and javascript I'm afraid I can develop some web > application now. But often I feel I'm not good at python. I don't know much > about generators, descriptors and decorators(although I can use some of it > to accomplish something, but I don't think I'm capable of knowing its > internals). I find my code ugly, and it seems near everything are already > gotten done by the libraries. When I want to do something, I just find some > libraries or modules and then just finish the work. So I'm a bit tired of > just doing this kind of high level scripting, only to find myself a bad > programmer. Then my question is after one coded some kind of basic app, how > one can keep on learning programming using python? > Do some more interesting projects? Read more general books about > programming? or...? > -- > http://mail.python.org/mailman/listinfo/python-list You could check out these slides from an Intro to Python talk I'm giving tonight: http://stromberg.dnsalias.org/~dstromberg/Intro-to-Python/ ...perhaps especially the Further Resources section at the end. The Koans might be very nice for you, as might Dive Into Python. BTW, if you're interested in Python and looking into Javascript anew, you might look at Pyjamas. It lets you write web apps in Python that also run on a desktop; you can even call into Raphael from it. Only thing about it is it's kind of a young project compared to most Python implementations. PS: I mostly came from C too - knowing C can be a real advantage for a Python programmer sometimes. From python at mrabarnett.plus.com Tue Nov 30 20:28:11 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 01 Dec 2010 01:28:11 +0000 Subject: Change one list item in place In-Reply-To: <17175f49-087f-4d05-ada2-7e8c7e7e86dd@z17g2000prz.googlegroups.com> References: <17175f49-087f-4d05-ada2-7e8c7e7e86dd@z17g2000prz.googlegroups.com> Message-ID: <4CF5A4AB.7090600@mrabarnett.plus.com> On 01/12/2010 01:08, Gnarlodious wrote: > This works for me: > > def sendList(): > return ["item0", "item1"] > > def query(): > l=sendList() > return ["Formatting only {0} into a string".format(l[0]), l[1]] > > query() > > > However, is there a way to bypass the > > l=sendList() > > and change one list item in-place? Possibly a list comprehension > operating on a numbered item? > There's this: return ["Formatting only {0} into a string".format(x) if i == 0 else x for i, x in enumerate(sendList())] but that's too clever for its own good. Keep it simple. :-) From nobody at nowhere.com Tue Nov 30 20:28:50 2010 From: nobody at nowhere.com (Nobody) Date: Wed, 01 Dec 2010 01:28:50 +0000 Subject: Python 3 encoding question: Read a filename from stdin, subsequently open that filename References: <1291124813.414884.22.camel@WOPR> Message-ID: On Tue, 30 Nov 2010 18:53:14 +0100, Peter Otten wrote: >> I think this is wrong. In Unix there is no concept of filename >> encoding. Filenames can have any arbitrary set of bytes (except '/' and >> '\0'). But the filesystem itself neither knows nor cares about >> encoding. > > I think you misunderstood what I was trying to say. If you write a list of > filenames into files.txt, and use an encoding (ISO-8859-1, say) other than > that used by the shell to display file names (on Linux typically UTF-8 these > days) and then write a Python script exist.py that reads filenames and > checks for the files' existence, I think you misunderstood. In the Unix kernel, there aren't any encodings. Strings of bytes are /just/ strings of bytes. A text file containing a list of filenames doesn't /have/ an encoding. The filenames passed to API functions don't /have/ an encoding. This is why Unix filenames are case-sensitive: because there isn't any "case". The number 65 has no more in common with the number 97 than it does with the number 255. The fact that 65 is the ASCII code for "A" while 97 is the ASCII code for "a" doesn't come into it. Case-insensitive filenames require knowledge of the encoding in order to determine when filenames are "equivalent". DOS/Windows tried this and never really got it right (it works fine on a standalone system, or within later versions of a Windows-only ecosystem, but becomes a nightmare when files get transferred between systems via older or non-Microsoft channels). Python 3.x's decision to treat filenames (and environment variables) as text even on Unix is, in short, a bug. One which, IMNSHO, will mean that Python 2.x is still around when Python 4 is released. From gnarlodious at gmail.com Tue Nov 30 20:35:36 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Tue, 30 Nov 2010 17:35:36 -0800 (PST) Subject: Programming games in historical linguistics with Python References: Message-ID: Have you considered entering all this data into an SQLite database? You could do fast searches based on any features you deem relevant to the phoneme. Using an SQLite editor application you can get started building a database right away. You can add columns as you get the inspiration, along with any tags you want. Putting it all in database tables can really make chaotic linguistic data seem manageable. My own linguistics project uses mostly SQLite and a number of OrderedDict's based on .plist files. It is all working very nicely, although I haven't tried to deal with any phonetics (yet). -- Gnarlie http://Sectrum.com From gnarlodious at gmail.com Tue Nov 30 20:52:14 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Tue, 30 Nov 2010 17:52:14 -0800 (PST) Subject: Change one list item in place References: <17175f49-087f-4d05-ada2-7e8c7e7e86dd@z17g2000prz.googlegroups.com> Message-ID: Thanks. Unless someone has a simpler solution, I'll stick with 2 lines. -- Gnarlie From javiervandam at gmail.com Tue Nov 30 21:03:50 2010 From: javiervandam at gmail.com (javivd) Date: Tue, 30 Nov 2010 18:03:50 -0800 (PST) Subject: Reading by positions plain text files References: <39a07597-02b9-4ef8-9ca9-93e2d2425e66@p7g2000prb.googlegroups.com> Message-ID: On Nov 30, 11:43?pm, Tim Harig wrote: > On 2010-11-30, javivd wrote: > > > I have a case now in wich another file has been provided (besides the > > database) that tells me in wich column of the file is every variable, > > because there isn't any blank or tab character that separates the > > variables, they are stick together. This second file specify the > > variable name and his position: > > > VARIABLE NAME ? ? ?POSITION (COLUMN) IN FILE > > var_name_1 ? ? ? ? ? ? ? ? 123-123 > > var_name_2 ? ? ? ? ? ? ? ? 124-125 > > var_name_3 ? ? ? ? ? ? ? ? 126-126 > > .. > > .. > > var_name_N ? ? ? ? ? ? ? ? 512-513 (last positions) > > I am unclear on the format of these positions. ?They do not look like > what I would expect from absolute references in the data. ?For instance, > 123-123 may only contain one byte??? which could change for different > encodings and how you mark line endings. ?Frankly, the use of the > world columns in the header suggests that the data *is* separated by > line endings rather then absolute position and the position refers to > the line number. In which case, you can use splitlines() to break up > the data and then address the proper line by index. ?Nevertheless, > you can use file.seek() to move to an absolute offset in the file, > if that really is what you are looking for. I work in a survey research firm. the data im talking about has a lot of 0-1 variables, meaning yes or no of a lot of questions. so only one position of a character is needed (not byte), explaining the 123-123 kind of positions of a lot of variables. and no, MRAB, it's not the similar problem (at least what i understood of it). I have to associate the position this file give me with the variable name this file give me for those positions. thank you both and sorry for my english! J From python at mrabarnett.plus.com Tue Nov 30 21:14:09 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 01 Dec 2010 02:14:09 +0000 Subject: Python 3 encoding question: Read a filename from stdin, subsequently open that filename In-Reply-To: References: <1291124813.414884.22.camel@WOPR> Message-ID: <4CF5AF71.3090705@mrabarnett.plus.com> On 01/12/2010 01:28, Nobody wrote: > On Tue, 30 Nov 2010 18:53:14 +0100, Peter Otten wrote: > >>> I think this is wrong. In Unix there is no concept of filename >>> encoding. Filenames can have any arbitrary set of bytes (except '/' and >>> '\0'). But the filesystem itself neither knows nor cares about >>> encoding. >> >> I think you misunderstood what I was trying to say. If you write a list of >> filenames into files.txt, and use an encoding (ISO-8859-1, say) other than >> that used by the shell to display file names (on Linux typically UTF-8 these >> days) and then write a Python script exist.py that reads filenames and >> checks for the files' existence, > > I think you misunderstood. > > In the Unix kernel, there aren't any encodings. Strings of bytes are > /just/ strings of bytes. A text file containing a list of filenames > doesn't /have/ an encoding. The filenames passed to API functions don't > /have/ an encoding. > > This is why Unix filenames are case-sensitive: because there isn't any > "case". The number 65 has no more in common with the number 97 than it > does with the number 255. The fact that 65 is the ASCII code for "A" while > 97 is the ASCII code for "a" doesn't come into it. Case-insensitive > filenames require knowledge of the encoding in order to determine when > filenames are "equivalent". DOS/Windows tried this and never really got it > right (it works fine on a standalone system, or within later versions of > a Windows-only ecosystem, but becomes a nightmare when files get > transferred between systems via older or non-Microsoft channels). > > Python 3.x's decision to treat filenames (and environment variables) as > text even on Unix is, in short, a bug. One which, IMNSHO, will mean that > Python 2.x is still around when Python 4 is released. > If the filenames are to be shown to a user then there needs to be a mapping between bytes and glyphs. That's an encoding. If different users use different encodings then exchange of textual data becomes difficult. That's where encodings which can be used globally come in. By the time Python 4 is released I'd be surprised if Unix hadn't standardised on a single encoding like UTF-8. From python at mrabarnett.plus.com Tue Nov 30 21:20:57 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 01 Dec 2010 02:20:57 +0000 Subject: Reading by positions plain text files In-Reply-To: References: <39a07597-02b9-4ef8-9ca9-93e2d2425e66@p7g2000prb.googlegroups.com> Message-ID: <4CF5B109.4070203@mrabarnett.plus.com> On 01/12/2010 02:03, javivd wrote: > On Nov 30, 11:43 pm, Tim Harig wrote: >> On 2010-11-30, javivd wrote: >> >>> I have a case now in wich another file has been provided (besides the >>> database) that tells me in wich column of the file is every variable, >>> because there isn't any blank or tab character that separates the >>> variables, they are stick together. This second file specify the >>> variable name and his position: >> >>> VARIABLE NAME POSITION (COLUMN) IN FILE >>> var_name_1 123-123 >>> var_name_2 124-125 >>> var_name_3 126-126 >>> .. >>> .. >>> var_name_N 512-513 (last positions) >> >> I am unclear on the format of these positions. They do not look like >> what I would expect from absolute references in the data. For instance, >> 123-123 may only contain one byte??? which could change for different >> encodings and how you mark line endings. Frankly, the use of the >> world columns in the header suggests that the data *is* separated by >> line endings rather then absolute position and the position refers to >> the line number. In which case, you can use splitlines() to break up >> the data and then address the proper line by index. Nevertheless, >> you can use file.seek() to move to an absolute offset in the file, >> if that really is what you are looking for. > > I work in a survey research firm. the data im talking about has a lot > of 0-1 variables, meaning yes or no of a lot of questions. so only one > position of a character is needed (not byte), explaining the 123-123 > kind of positions of a lot of variables. > > and no, MRAB, it's not the similar problem (at least what i understood > of it). I have to associate the position this file give me with the > variable name this file give me for those positions. > > thank you both and sorry for my english! > You just have to parse the second file to build a list (or dict) containing the name, start position and end position of each variable: variables = [("var_name_1", 123, 123), ...] and then work through that list, extracting the data between those positions in the first file and putting the values in another list (or dict). You also need to check whether the positions are 1-based or 0-based (Python uses 0-based). From prologic at shortcircuit.net.au Tue Nov 30 21:24:14 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 1 Dec 2010 12:24:14 +1000 Subject: How to initialize each multithreading Pool worker with an individual value? In-Reply-To: References: Message-ID: On Wed, Dec 1, 2010 at 7:35 AM, Valery Khamenya wrote: > multithreading.pool Pool has a promissing initializer argument in its > constructor. > However it doesn't look possible to use it to initialize each Pool's > worker with some individual value (I'd wish to be wrong here) > > So, how to initialize each multithreading Pool worker with the > individual values? > > The typical use case might be a connection pool, say, of 3 workers, > where each of 3 workers has its own TCP/IP port. > > from multiprocessing.pool import Pool > > def port_initializer(_port): > ? ?global port > ? ?port = _port > > def use_connection(some_packet): > ? ?global _port > ? ?print "sending data over port # %s" % port > > if __name__ == "__main__": > ? ?ports=((4001,4002, 4003), ) > ? ?p = Pool(3, port_initializer, ports) # oops... :-) > ? ?some_data_to_send = range(20) > ? ?p.map(use_connection, some_data_to_send) I assume you are talking about multiprocessing despite you mentioning "multithreading" in the mix. Have a look at the source code for multiprocessing.pool and how the Pool object works and what it does with the initializer argument. I'm not entirely sure it does what you expect and yes documentation on this is lacking... cheers James -- -- James Mills -- -- "Problems are solved by method" From python.list at tim.thechases.com Tue Nov 30 21:32:56 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 30 Nov 2010 20:32:56 -0600 Subject: Reading by positions plain text files In-Reply-To: References: <39a07597-02b9-4ef8-9ca9-93e2d2425e66@p7g2000prb.googlegroups.com> Message-ID: <4CF5B3D8.3030206@tim.thechases.com> On 11/30/2010 08:03 PM, javivd wrote: > On Nov 30, 11:43 pm, Tim Harig wrote: >>> VARIABLE NAME POSITION (COLUMN) IN FILE >>> var_name_1 123-123 >>> var_name_2 124-125 >>> var_name_3 126-126 >>> .. >>> .. >>> var_name_N 512-513 (last positions) >> > and no, MRAB, it's not the similar problem (at least what i understood > of it). I have to associate the position this file give me with the > variable name this file give me for those positions. MRAB may be referring to my reply in that thread where you can do something like OFFSETS = 'offsets.txt' offsets = {} f = file(OFFSETS) f.next() # throw away the headers for row in f: varname, rest = row.split()[:2] # sanity check if varname in offsets: print "[%s] in %s twice?!" % (varname, OFFSETS) if '-' not in rest: continue start, stop = map(int, rest.split('-')) offsets[varname] = slice(start, stop+1) # 0-based offsets #offsets[varname] = slice(start+1, stop+2) # 1-based offsets f.close() def do_something_with(data): # your real code goes here print data['var_name_2'] for row in file('data.txt'): data = dict((name, row[offsets[name]]) for name in offsets) do_something_with(data) There's additional robustness-checks I'd include if your offsets-file isn't controlled by you (people send me daft data). -tkc From whatsjacksemail at gmail.com Tue Nov 30 21:45:50 2010 From: whatsjacksemail at gmail.com (Jack Keegan) Date: Wed, 1 Dec 2010 02:45:50 +0000 Subject: To Thread or not to Thread....? Message-ID: Hi there, I'm currently writing an application to control and take measurements during an experiments. This is to be done on an embedded computer running XPe so I am happy to have python available, although I am pretty new to it. The application basically runs as a state machine, which transitions through it's states based on inputs read in from a set of general purpose input/output (GPIO) lines. So when a certain line is pulled low/high, do something and move to another state. All good so far and since I get through main loop pretty quickly, I can just do a read of the GPIO lines on each pass through the loop and respond accordingly. However, in one of the states I have to start reading in, and storing frames from a camera. In another, I have to start reading accelerometer data from an I2C bus (which operates at 400kHz). I haven't implemented either yet but I would imagine that, in the case of the camera data, reading a frame would take a large amount of time as compared to other operations. Therefore, if I just tried to read one (or one set of) frames on each pass through the loop then I would hold up the rest of the application. Conversely, as the I2C bus will need to be read at such a high rate, I may not be able to get the required data rate I need even without the camera data. This naturally leads me to think I need to use threads. As I am no expert in either I2C, cameras, python or threading I thought I would chance asking for some advice on the subject. Do you think I need threads here or would I be better off using some other method. I was previously toying with the idea of using generators to create weightless threads (as detailed in http://www.ibm.com/developerworks/library/l-pythrd.html) for reading the GPIOs. Do you think this would work in this situation? Another option would be to write separately programs, perhaps even in C, and spawn these in the background when needed. I'm a little torn as to which way to go. If it makes a difference and more in case you are wondering, I will be interfacing to the GPIOs, cameras and I2C bus through a set of C DLLs using Ctypes. Any help or suggestions will be greatly appreciated, Thanks very much, Jack -------------- next part -------------- An HTML attachment was scrubbed... URL: From marduk at letterboxes.org Tue Nov 30 22:22:01 2010 From: marduk at letterboxes.org (Albert Hopkins) Date: Tue, 30 Nov 2010 22:22:01 -0500 Subject: Python 3 encoding question: Read a filename from stdin, subsequently open that filename In-Reply-To: <4CF5AF71.3090705@mrabarnett.plus.com> References: <1291124813.414884.22.camel@WOPR> <4CF5AF71.3090705@mrabarnett.plus.com> Message-ID: <1291173721.687410.18.camel@WOPR> On Wed, 2010-12-01 at 02:14 +0000, MRAB wrote: > If the filenames are to be shown to a user then there needs to be a > mapping between bytes and glyphs. That's an encoding. If different > users use different encodings then exchange of textual data becomes > difficult. That's presentation, that's separate. Indeed, I have my user encoding set to UTF-8, and if there is a filename that's not valid utf-8 then my GUI (GNOME will show "(invalid encoding)" and even allow me to rename it and my shell (bash) will show '?' next to the invalid "characters" (and make it a little more challenging to rename ;)). And I can freely copy these "invalid" files across different (Unix) systems, because the OS doesn't care about encoding. But that's completely different from the actual name of the file. Unix doesn't care about presentation in filenames. It just cares about the data. There are not "glyphs" in Unix, only in the UI that runs on top of it. Or to put it another way, Unix's filename encoding is RAW-DATA. It's not "textual" data. The fact that most filenames contain mainly human-readable text is a convenient convention, but not required or enforced by the OS. > That's where encodings which can be used globally come in. > By the time Python 4 is released I'd be surprised if Unix hadn't > standardised on a single encoding like UTF-8. I have serious doubts about that. At least in the Linux world the kernel wants to stay out of encoding debates (except where it has to like Window filesystems). But the point is that: The world does not revolve around Python. Unix filenames have been encoding-agnostic long before Python was around. If Python3 does not support this then it's a regression on Python's part. From steve at holdenweb.com Tue Nov 30 22:52:14 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 30 Nov 2010 22:52:14 -0500 Subject: Change one list item in place In-Reply-To: <4CF5A4AB.7090600@mrabarnett.plus.com> References: <17175f49-087f-4d05-ada2-7e8c7e7e86dd@z17g2000prz.googlegroups.com> <4CF5A4AB.7090600@mrabarnett.plus.com> Message-ID: On 11/30/2010 8:28 PM, MRAB wrote: > On 01/12/2010 01:08, Gnarlodious wrote: >> This works for me: >> >> def sendList(): >> return ["item0", "item1"] >> >> def query(): >> l=sendList() >> return ["Formatting only {0} into a string".format(l[0]), l[1]] >> >> query() >> >> >> However, is there a way to bypass the >> >> l=sendList() >> >> and change one list item in-place? Possibly a list comprehension >> operating on a numbered item? >> > There's this: > > return ["Formatting only {0} into a string".format(x) if i == 0 else > x for i, x in enumerate(sendList())] > > but that's too clever for its own good. Keep it simple. :-) I quite agree. That solution is so clever it would be asking for a fight walking into a bar in Glasgow. However, an unpacking assignment can make everything much more comprehensible [pun intended] by removing the index operations. The canonical solution would be something like: def query(): x, y = sendList() return ["Formatting only {0} into a string".format(x), y] regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From rantingrick at gmail.com Mon Nov 1 00:00:32 2010 From: rantingrick at gmail.com (rantingrick) Date: Sun, 31 Oct 2010 21:00:32 -0700 (PDT) Subject: I heard about python needing some sort of _VariableName_ boiler plate? References: Message-ID: <49ac60cd-9c07-4f9d-8ac6-58bdaec42993@c20g2000yqj.googlegroups.com> On Oct 31, 10:18?pm, Chris Rebert wrote: > On Sun, Oct 31, 2010 at 7:09 PM, Braden Faulkner wrote: > > I heard about python needing some sort of _VariableName_ boiler plate? > > Can anyone explain to me how this works, I don't seem to have to do it in > > IDLE? Oh thats just more FUD and spin from the legions of "Perl mongers" and "Lisp leaches" who continually try to sow discontent within the ranks of our newbies here at c.l.p. As you have found yourself Python is a super clean language. However, since they cannot argue the language on merits and facts they will resort to these despicable (and might i say desperate) lies and political propagandas in a feeble attempt to sway the masses against us. However, do not be fearful of their threats or influenced by such bombastic claims and nonsensical rubbish. Go and tell Xerxes he faces free men here... not slaves! From rantingrick at gmail.com Mon Nov 1 00:34:46 2010 From: rantingrick at gmail.com (rantingrick) Date: Sun, 31 Oct 2010 21:34:46 -0700 (PDT) Subject: I heard about python needing some sort of_VariableName_ boiler plate? References: Message-ID: <37de0154-f623-41e7-8268-2bad525357c0@s4g2000yql.googlegroups.com> On Oct 31, 10:37?pm, brad... at hotmail.com wrote: > Sorry, to clarify I heard that when you declare a variable in python you have to use some sort of standard boiler plate _variable_ however this has not been my experience using IDLE so is this even true? Halloween night and i am bored... hmm... i know! plan A: Ask a really perplexing and insane question on c.l.p. ...hmm, well i did not get the answer i wanted so i'll just open a new thread and... plan B: Ask ask the same question again! ...surely i'll get a better answer with this plan!! urm, rinse and repeat maybe? From rantingrick at gmail.com Mon Nov 1 00:37:37 2010 From: rantingrick at gmail.com (rantingrick) Date: Sun, 31 Oct 2010 21:37:37 -0700 (PDT) Subject: I heard about python needing some sort of_VariableName_ boiler plate? References: Message-ID: Brad, Serously, i have never heard of any boilerplate variables in Python. Could you show us an example using Python code that compiles? Of could you even show us some puesdo that resembles any thing that you are suggesting? I am perplexed! Is this a troll or are you really serious? From lanyjie at yahoo.com Mon Nov 1 00:44:47 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Sun, 31 Oct 2010 21:44:47 -0700 (PDT) Subject: A bug for raw string literals in Py3k? In-Reply-To: <4CCE395D.9050806@mrabarnett.plus.com> Message-ID: <935717.4038.qm@web54206.mail.re2.yahoo.com> > According to msg56377, the behaviour is "optimal" for regular > expressions. Well, I use regular expressions a lot, and I > still think it's a nuisance! Thanks for bringing that up. Using an otherwise 'dead' backlash to escape quotes in raw strings seems like the black magic of necromancy to me. :) To include quotes in a string, there are a couple of known choices: If you need single quotes in the string, start the literal by a double-quote, and vice versa. In case you need both, you can use a long string: >>> r''''ab\c"''' Note that when the last character is also a quote, we can use the other type of quote three times to delimit the long string. Of course, there are still some corner cases: 1. when we need three consecutive single quotes AND three consecutive double quotes in the string. 2. When the last is a single quote, and we also need three consecutive double-quotes in the string, or the other way around. Then we can abandon the raw string literal, or use concatenation of string literals wisely to get it done. But in total, I still would vote against the nacromancy. Yingjie From prologic at shortcircuit.net.au Mon Nov 1 00:50:04 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Mon, 1 Nov 2010 14:50:04 +1000 Subject: [Beginer Question] I heard about python needing some sort of_VariableName_ boiler plate? In-Reply-To: <2112376356-1288582649-cardhu_decombobulator_blackberry.rim.net-1426431676-@bda480.bisx.prod.on.blackberry> References: <2112376356-1288582649-cardhu_decombobulator_blackberry.rim.net-1426431676-@bda480.bisx.prod.on.blackberry> Message-ID: On Mon, Nov 1, 2010 at 1:37 PM, wrote: > Sorry, to clarify I heard that when you declare a variable in python you have to use some sort of standard boiler plate _variable_ however this has not been my experience using IDLE so is this even true? Boilerplate, what boilerplate ? To define variables, just assign a value to a name: >>> x = 1 >>> x 1 cheers James -- -- James Mills -- -- "Problems are solved by method" From ben+python at benfinney.id.au Mon Nov 1 00:51:42 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 01 Nov 2010 15:51:42 +1100 Subject: [Beginer Question] I heard about python needing some sort of_VariableName_ boiler plate? References: Message-ID: <878w1dlk81.fsf@benfinney.id.au> bradenf at hotmail.com writes: > Sorry, to clarify I heard that when you declare a variable in python > you have to use some sort of standard boiler plate _variable_ however > this has not been my experience using IDLE so is this even true? I don't know what ?some sort of boiler plate _variable_? might mean. Can you point to someone's actual message saying this, so we can see what they might be talking about? -- \ ?With Lisp or Forth, a master programmer has unlimited power | `\ and expressiveness. With Python, even a regular guy can reach | _o__) for the stars.? ?Raymond Hettinger | Ben Finney From lanyjie at yahoo.com Mon Nov 1 01:03:52 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Sun, 31 Oct 2010 22:03:52 -0700 (PDT) Subject: with block for multiple files Message-ID: <942901.77636.qm@web54203.mail.re2.yahoo.com> Hi, Suppose I am working with two files simultaneously, it might make sense to do this: with open('scores.csv'), open('grades.csv', wt) as f,g: g.write(f.read()) sure, you can do this with nested with-blocks, but the one above does not seem too complicated, it is like having a multiple assignment... Any thoughts? Another mini-proposal: Allow the conditions in the if-, elif-, while-, for-, and with-clauses to span multiple lines without using a backlalsh, just like when you specify literal lists, tuples, dicts, etc. across multiple lines (similar to comprehensions too). My reason is this: because they all must end with a required colon ':', so nobody will mistake it. Just some half-baked ideas, would appreciate thos who shed light on these issues. Yingjie From clp2 at rebertia.com Mon Nov 1 01:10:25 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 31 Oct 2010 22:10:25 -0700 Subject: with block for multiple files In-Reply-To: <942901.77636.qm@web54203.mail.re2.yahoo.com> References: <942901.77636.qm@web54203.mail.re2.yahoo.com> Message-ID: On Sun, Oct 31, 2010 at 10:03 PM, Yingjie Lan wrote: > Hi, > > Suppose I am working with two files simultaneously, > it might make sense to do this: > > with open('scores.csv'), open('grades.csv', wt) as f,g: > ? ? g.write(f.read()) > > sure, you can do this with nested with-blocks, > but the one above does not seem too complicated, > it is like having a multiple assignment... > > Any thoughts? Guido's time machine strikes again! It's already in Python 3; your example would be spelled: with open('scores.csv') as f, open('grades.csv', wt) as g: g.write(f.read()) Cheers, Chris -- Where does GvR source his flux capacitors from? http://blog.rebertia.com From prologic at shortcircuit.net.au Mon Nov 1 01:13:44 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Mon, 1 Nov 2010 15:13:44 +1000 Subject: with block for multiple files In-Reply-To: <942901.77636.qm@web54203.mail.re2.yahoo.com> References: <942901.77636.qm@web54203.mail.re2.yahoo.com> Message-ID: On Mon, Nov 1, 2010 at 3:03 PM, Yingjie Lan wrote: > with open('scores.csv'), open('grades.csv', wt) as f,g: > ? ? g.write(f.read()) One could write their own ContextManager here... cheers James -- -- James Mills -- -- "Problems are solved by method" From lanyjie at yahoo.com Mon Nov 1 02:02:21 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Sun, 31 Oct 2010 23:02:21 -0700 (PDT) Subject: Allow multiline conditions and the like Message-ID: <291834.82757.qm@web54201.mail.re2.yahoo.com> Hi, This is a mini-proposal I piggy-tailed in the other topic: Allow the conditions in the if-, elif-, while-, for-, and with-clauses to span multiple lines without using a backlalsh at the end of a line, just like when you specify literal lists, tuples, dicts, etc. across multiple lines (similar to comprehensions too). My reasons: because they all must end with a required colon ':', so nobody will mistake it. also, if we don't allow it, people just have to use parenthesis around the expressions to make that happen. Just a half-baked idea, appreciate all comments. Yingjie From lanyjie at yahoo.com Mon Nov 1 02:05:00 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Sun, 31 Oct 2010 23:05:00 -0700 (PDT) Subject: with block for multiple files In-Reply-To: Message-ID: <403882.60405.qm@web54208.mail.re2.yahoo.com> > Guido's time machine strikes again! It's already in Python > 3; your > example would be spelled: > > with open('scores.csv') as f, open('grades.csv', wt) as g: > ? ? g.write(f.read()) > Indeed! Thanks, Chris and James. Yingjie From lanyjie at yahoo.com Mon Nov 1 02:13:19 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Sun, 31 Oct 2010 23:13:19 -0700 (PDT) Subject: Allowing comments after the line continuation backslash Message-ID: <628312.39922.qm@web54205.mail.re2.yahoo.com> Hi, Sorry if I am baking too many ideas today. I am just having trouble with the backslashes.... I would like to have comments after the line continuation backslash. >>> if a > 0 \ #comments for this condition and b > 0: #do something here This is currently not OK, but this might be a good thing to have. Yingjie From charugangal at gmail.com Mon Nov 1 02:16:11 2010 From: charugangal at gmail.com (charu gangal) Date: Sun, 31 Oct 2010 23:16:11 -0700 (PDT) Subject: python script to read google spreadsheet Message-ID: <0b6f704c-e108-4fb9-afc2-3616d92d6694@t13g2000yqm.googlegroups.com> import gdata.spreadsheet.service username = 'prakhil.purchase at gmail.com' passwd = 'purchase' doc_name = 'googleapps_spreadsheet' gd_client = gdata.spreadsheet.service.SpreadsheetsService() gd_client.email = username gd_client.password =passwd #gd_client.source = 'pythonsample12' gd_client.ProgrammaticLogin() q = gdata.spreadsheet.service.DocumentQuery() q['title'] = doc_name q['title-exact'] = 'true' feed = gd_client.GetSpreadsheetsFeed(query=q) spreadsheet_id = feed.entry[0].id.text.rsplit('/',1)[1] feed = gd_client.GetWorksheetsFeed(spreadsheet_id) worksheet_id = feed.entry[0].id.text.rsplit('/',1)[1] rows = gd_client.GetListFeed(spreadsheet_id, worksheet_id).entry for row in rows: for key in row.custom: print " %s: %s" % (key, row.custom[key].text) This is the python code I was trying to access the cell information from a google spreadsheet but the issue is that i am able to make it work on Eclipse but when i deploy it, it is not showing me the result. Maybe I am missing some of the google packages to import that is making it unable to run on google environment. Kindly guide me.Thanks in advance. From iwawi123 at gmail.com Mon Nov 1 02:46:29 2010 From: iwawi123 at gmail.com (iwawi) Date: Sun, 31 Oct 2010 23:46:29 -0700 (PDT) Subject: text file reformatting References: <78daefd1-59a1-4b3a-9bc2-5910315515ce@r14g2000yqa.googlegroups.com> Message-ID: <57ec83dd-3f30-4000-acf6-f49a44568d22@k22g2000yqh.googlegroups.com> On 31 loka, 21:48, Tim Chase wrote: > > PRJ01001 4 00100END > > PRJ01002 3 00110END > > > I would like to pick only some columns to a new file and put them to a > > certain places (to match previous data) - definition file (def.csv) > > could be something like this: > > > VARIABLE ? FIELDSTARTS ? ? FIELD SIZE ? ? ?NEW PLACE IN NEW DATA FILE > > ProjID ? ? ; ? ? ? 1 ? ? ? ; ? ? ? 5 ? ? ? ; ? ? ? 1 > > CaseID ? ? ; ? ? ? 6 ? ? ? ; ? ? ? 3 ? ? ? ; ? ? ? 10 > > UselessV ?; ? ? ? ?10 ? ? ?; ? ? ? 1 ? ? ? ; > > Zipcode ? ?; ? ? ? 12 ? ? ?; ? ? ? 5 ? ? ? ; ? ? ? 15 > > > So the new datafile should look like this: > > > PRJ01 ? ?001 ? ? ? 00100END > > PRJ01 ? ?002 ? ? ? 00110END > > How flexible is the def.csv format? ?The difficulty I see with > your def.csv format is that it leaves undefined gaps (presumably > to be filled in with spaces) and that you also have a blank "new > place in new file" value. ?If instead, you could specify the > width to which you want to pad it and omit variables you don't > want in the output, ordering the variables in the same order you > want them in the output: > > ? Variable; Start; Size; Width > ? ProjID; 1; 5; 10 > ? CaseID; 6; 3; 10 > ? Zipcode; 12; 5; 5 > ? End; 16; 3; 3 > > (note that I lazily use the same method to copy the END from the > source to the destination, rather than coding specially for it) > you could do something like this (untested) > > ? ?import csv > ? ?f = file('def.csv', 'rb') > ? ?f.next() # discard the header row > ? ?r = csv.reader(f, delimiter=';') > ? ?fields = [ > ? ? ?(varname, slice(int(start), int(start)+int(size)), width) > ? ? ?for varname, start, size, width > ? ? ?in r > ? ? ?] > ? ?f.close() > ? ?out = file('out.txt', 'w') > ? ?try: > ? ? ?for row in file('data.txt'): > ? ? ? ?for varname, slc, width in fields: > ? ? ? ? ?out.write(row[slc].ljust(width)) > ? ? ? ?out.write('\n') > ? ?finally: > ? ? ?out.close() > > Hope that's fairly easy to follow and makes sense. ?There might > be some fence-posting errors (particularly your use of "1" as the > initial offset, while python uses "0" as the initial offset for > strings) > > If you can't modify the def.csv format, then things are a bit > more complex and I'd almost be tempted to write a script to try > and convert your existing def.csv format into something simpler > to process like what I describe. > > -tkc- Piilota siteerattu teksti - > > - N?yt? siteerattu teksti - Hi, Thanks for your reply. Def.csv could be modified so that every line has the same structure: variable name, field start, field size and new place and would be separated with semicolomns as you mentioned. I tried your script (which seems quite logical) but I get this Traceback (most recent call last): File "testing.py", line 16, in out.write (row[slc].ljust(width)) TypeError: an integer is required Yes - you said it was untested, but I can't figure out how to proceed... From bob.martin at excite.com Mon Nov 1 03:01:08 2010 From: bob.martin at excite.com (Bob Martin) Date: Mon, 01 Nov 2010 07:01:08 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> Message-ID: <8j76tkFs4dU1@mid.individual.net> in 645437 20101031 230912 Lawrence D'Oliveiro wrote: >In message <4ccd5ad9$0$19151$426a74cc at news.free.fr>, jf wrote: > >> I edit each file to remove tabs ... > >expand -i newfile > >> Do you know a tools to compare the initial file with the cleaned one to >> know if the algorithms are the same ? > >diff -b oldfile newfile meld From ben+python at benfinney.id.au Mon Nov 1 03:13:13 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 01 Nov 2010 18:13:13 +1100 Subject: Allow multiline conditions and the like References: Message-ID: <874oc1ldo6.fsf@benfinney.id.au> Yingjie Lan writes: > Allow the conditions in the if-, elif-, while-, for-, and with-clauses > to span multiple lines without using a backlalsh at the end of a line, You can already do this with any expression: use parentheses. Yingjie Lan writes: > I would like to have comments after the line continuation backslash. I have almost never needed a line continuation backslash; I consider them a code smell. > >>> if a > 0 \ #comments for this condition > and b > 0: > #do something here if (a > 0 # Comments for this condition and b > 0): # Do something here -- \ ?Alternative explanations are always welcome in science, if | `\ they are better and explain more. Alternative explanations that | _o__) explain nothing are not welcome.? ?Victor J. Stenger, 2001-11-05 | Ben Finney From ldo at geek-central.gen.new_zealand Mon Nov 1 03:16:34 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 01 Nov 2010 20:16:34 +1300 Subject: Allow multiline conditions and the like References: <874oc1ldo6.fsf@benfinney.id.au> Message-ID: In message <874oc1ldo6.fsf at benfinney.id.au>, Ben Finney wrote: > Yingjie Lan writes: > >> Allow the conditions in the if-, elif-, while-, for-, and with-clauses >> to span multiple lines without using a backlalsh at the end of a line, > > You can already do this with any expression: use parentheses. It?s easy enough to do things like this: if ( TheMesh.vertices[OtherVertex].select and OtherVertex != ThatVertex and OtherVertex != ThisLine[-2] and OtherVertex != ThisVertex ) : ... #end if From ldo at geek-central.gen.new_zealand Mon Nov 1 03:18:34 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 01 Nov 2010 20:18:34 +1300 Subject: Allowing comments after the line continuation backslash References: Message-ID: In message , Yingjie Lan wrote: > I would like to have comments after the line continuation backslash. What language allows that? From ldo at geek-central.gen.new_zealand Mon Nov 1 03:20:42 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 01 Nov 2010 20:20:42 +1300 Subject: How on Factorial References: <1cf81147-06f4-4e48-9255-ea87bf3f93be@k22g2000yqh.googlegroups.com> Message-ID: In message , Ulrich Eckhardt wrote: > Geobird wrote: > >> def fact(x): >> return x > 1 and x * fact(x - 1) or 1 > > I'd say this is about as small as it gets. fact = lambda x : x > 1 and x * fact(x - 1) or 1 -- Lawrence ?Functionalism Strikes Again? D?Oliveiro From ldo at geek-central.gen.new_zealand Mon Nov 1 03:23:42 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 01 Nov 2010 20:23:42 +1300 Subject: How on Factorial References: <1cf81147-06f4-4e48-9255-ea87bf3f93be@k22g2000yqh.googlegroups.com> <85dcd37b-871d-4058-b6af-8fc825afcc96@a37g2000yqi.googlegroups.com> Message-ID: In message , Jussi Piitulainen wrote: > (I agree that no one should write factorial like that, except as > a joke. I have nothing against (x if (a > b) else y). The trick > with and and or was used before Python had an actual conditional > expression.) You know what, I think I actually prefer the trick to Python?s backwards-if syntax... From ldo at geek-central.gen.new_zealand Mon Nov 1 03:26:18 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 01 Nov 2010 20:26:18 +1300 Subject: Why "flat is better than nested"? References: <4CC58C87.6030306@chamonix.reportlab.co.uk> Message-ID: In message , Stefan Behnel wrote: > What's a "that boy"? A boy who?s the opposite of fin. From martin at v.loewis.de Mon Nov 1 03:44:54 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Mon, 01 Nov 2010 08:44:54 +0100 Subject: Allowing comments after the line continuation backslash In-Reply-To: References: Message-ID: <4CCE6FF6.2050408@v.loewis.de> > Sorry if I am baking too many ideas today. > I am just having trouble with the backslashes.... > > I would like to have comments after the line continuation backslash. > >>>> if a > 0 \ #comments for this condition > and b > 0: > #do something here > > This is currently not OK, but this might be a good thing to have. Can you say why it would be a good idea? FWIW, I would write your fragment as if (a > 0 #comments for this condition and b > 0): #do something here i.e. avoid the backslash for multi-line conditions altogether (in fact, I can't think any situation where I would use the backslash). Regards, Martin From ldo at geek-central.gen.new_zealand Mon Nov 1 03:46:22 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 01 Nov 2010 20:46:22 +1300 Subject: python script to read google spreadsheet References: <0b6f704c-e108-4fb9-afc2-3616d92d6694@t13g2000yqm.googlegroups.com> Message-ID: In message <0b6f704c-e108-4fb9-afc2-3616d92d6694 at t13g2000yqm.googlegroups.com>, charu gangal wrote: > This is the python code I was trying to access the cell information > from a google spreadsheet but the issue is that i am able to make it > work on Eclipse but when i deploy it, it is not showing me the result. What does it do instead? From eckhardt at satorlaser.com Mon Nov 1 03:50:36 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Mon, 01 Nov 2010 08:50:36 +0100 Subject: Allowing comments after the line continuation backslash References: Message-ID: Yingjie Lan wrote: > I would like to have comments after the line continuation backslash. > >>>> if a > 0 \ #comments for this condition > and b > 0: > #do something here Historically, and also in Python, the backslash escapes the immediately following character. That means that _nothing_ may follow the backslash and that the backslash is not a "line continuation backslash" per se. Now, there are ways around this, just add parens: if (a > 0 and b > 0): Note that this also applies to (), [] and {} when forming tuples, lists and dicts, which you can spread across different lines. > This is currently not OK, but this might be a good thing to have. I'd actually argue that even the currently used backslash is a bad idea to have. Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From steve-REMOVE-THIS at cybersource.com.au Mon Nov 1 03:51:50 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 01 Nov 2010 07:51:50 GMT Subject: Allow multiline conditions and the like References: Message-ID: <4cce7196$0$29965$c3e8da3$5496439d@news.astraweb.com> On Sun, 31 Oct 2010 23:02:21 -0700, Yingjie Lan wrote: > Hi, > > This is a mini-proposal I piggy-tailed in the other topic: > > Allow the conditions in the if-, elif-, while-, for-, and with-clauses > to span multiple lines [...] > also, if we don't allow it, people just have to use > parenthesis around the expressions to make that happen. You say that like it's a bad thing. That is kind of like saying "We should allow people to speed through red traffic lights, because if we don't, they'll just wait for the light to turn green!". Er, yes, and the problem is? If you need a multi-line conditional, wrap it in parentheses. -- Steven From cbrown at cbrownsystems.com Mon Nov 1 03:59:10 2010 From: cbrown at cbrownsystems.com (cbrown at cbrownsystems.com) Date: Mon, 1 Nov 2010 00:59:10 -0700 (PDT) Subject: text file reformatting References: <78daefd1-59a1-4b3a-9bc2-5910315515ce@r14g2000yqa.googlegroups.com> <57ec83dd-3f30-4000-acf6-f49a44568d22@k22g2000yqh.googlegroups.com> Message-ID: On Oct 31, 11:46?pm, iwawi wrote: > On 31 loka, 21:48, Tim Chase wrote: > > > > > > PRJ01001 4 00100END > > > PRJ01002 3 00110END > > > > I would like to pick only some columns to a new file and put them to a > > > certain places (to match previous data) - definition file (def.csv) > > > could be something like this: > > > > VARIABLE ? FIELDSTARTS ? ? FIELD SIZE ? ? ?NEW PLACE IN NEW DATA FILE > > > ProjID ? ? ; ? ? ? 1 ? ? ? ; ? ? ? 5 ? ? ? ; ? ? ? 1 > > > CaseID ? ? ; ? ? ? 6 ? ? ? ; ? ? ? 3 ? ? ? ; ? ? ? 10 > > > UselessV ?; ? ? ? ?10 ? ? ?; ? ? ? 1 ? ? ? ; > > > Zipcode ? ?; ? ? ? 12 ? ? ?; ? ? ? 5 ? ? ? ; ? ? ? 15 > > > > So the new datafile should look like this: > > > > PRJ01 ? ?001 ? ? ? 00100END > > > PRJ01 ? ?002 ? ? ? 00110END > > > How flexible is the def.csv format? ?The difficulty I see with > > your def.csv format is that it leaves undefined gaps (presumably > > to be filled in with spaces) and that you also have a blank "new > > place in new file" value. ?If instead, you could specify the > > width to which you want to pad it and omit variables you don't > > want in the output, ordering the variables in the same order you > > want them in the output: > > > ? Variable; Start; Size; Width > > ? ProjID; 1; 5; 10 > > ? CaseID; 6; 3; 10 > > ? Zipcode; 12; 5; 5 > > ? End; 16; 3; 3 > > > (note that I lazily use the same method to copy the END from the > > source to the destination, rather than coding specially for it) > > you could do something like this (untested) > > > ? ?import csv > > ? ?f = file('def.csv', 'rb') > > ? ?f.next() # discard the header row > > ? ?r = csv.reader(f, delimiter=';') > > ? ?fields = [ > > ? ? ?(varname, slice(int(start), int(start)+int(size)), width) > > ? ? ?for varname, start, size, width > > ? ? ?in r > > ? ? ?] > > ? ?f.close() > > ? ?out = file('out.txt', 'w') > > ? ?try: > > ? ? ?for row in file('data.txt'): > > ? ? ? ?for varname, slc, width in fields: > > ? ? ? ? ?out.write(row[slc].ljust(width)) > > ? ? ? ?out.write('\n') > > ? ?finally: > > ? ? ?out.close() > > > Hope that's fairly easy to follow and makes sense. ?There might > > be some fence-posting errors (particularly your use of "1" as the > > initial offset, while python uses "0" as the initial offset for > > strings) > > > If you can't modify the def.csv format, then things are a bit > > more complex and I'd almost be tempted to write a script to try > > and convert your existing def.csv format into something simpler > > to process like what I describe. > > > -tkc- Piilota siteerattu teksti - > > > - N?yt? siteerattu teksti - > > Hi, > > Thanks for your reply. > > Def.csv could be modified so that every line has the same structure: > variable name, field start, field size and new place and would be > separated with semicolomns as you mentioned. > > I tried your script (which seems quite logical) but I get this > > Traceback (most recent call last): > ? File "testing.py", line 16, in > ? ? out.write (row[slc].ljust(width)) > TypeError: an integer is required > > Yes - you said it was untested, but I can't figure out how to > proceed... The line (varname, slice(int(start), int(start)+int(size)), width) should instead be (varname, slice(int(start), int(start)+int(size)), int(width)) although you give an example where there is no width - what does that imply? In the above case, it will throw an exception. Anyway, I think you'll find there's something a bit off in the output loop with the parameter passed to ljust() as well. The value given in your csv seems to be the absolute position, but as it's implemented by Tim, it acts as the relative position. Given Tim's parsing into the list fields, I have a feeling that what you really want instead of for varname, slc, width in fields: out.write(row[slc].ljust(width)) out.write('\n') is to have s = '' for varname, slc, width in fields: s += " "*(width - len(s)) + row[slc] out.write(s+'\n') And if that is what you want, then you will surely want to globally replace the name 'width' with for example 'start_column', because then it all makes sense :). Cheers - Chas From steve-REMOVE-THIS at cybersource.com.au Mon Nov 1 04:02:37 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 01 Nov 2010 08:02:37 GMT Subject: Allowing comments after the line continuation backslash References: Message-ID: <4cce741d$0$29965$c3e8da3$5496439d@news.astraweb.com> On Sun, 31 Oct 2010 23:13:19 -0700, Yingjie Lan wrote: > Hi, > > Sorry if I am baking too many ideas today. I am just having trouble with > the backslashes.... Then don't use them. If you are having so much trouble keeping your lines short, then I suggest you're trying to do too much in one line. > I would like to have comments after the line continuation backslash. > >>>> if a > 0 \ #comments for this condition > and b > 0: > #do something here I'm actually sympathetic to the idea of having a backslash followed by any whitespace mean line continuation, allowing comments after the line. The problem is, what should you do here? Presumably if you follow the backslash with anything other than whitespace or a comment, you get a SyntaxError: if a > 0 \ and b > 0: # do something In any case, there is a moratorium on language changes, so it will probably be 2 or 3 years before this could even be considered. What you can do instead: if a > 0 and b > 0: # comment for a condition # comment for b condition do_something() There's nothing wrong with that. But if you insist on in-line comments: if (a > 0 # comment for a condition and b > 0 # comment for b condition ): do_something() But best of all, write literate code that doesn't need comments because it documents itself: if number_of_pages > 0 and not all(page.is_blank() for page in pages): do_something() -- Steven From charugangal at gmail.com Mon Nov 1 04:14:09 2010 From: charugangal at gmail.com (charu gangal) Date: Mon, 1 Nov 2010 01:14:09 -0700 (PDT) Subject: python script to read google spreadsheet References: <0b6f704c-e108-4fb9-afc2-3616d92d6694@t13g2000yqm.googlegroups.com> Message-ID: <45e3864a-6a63-49e9-ae0f-df3aeb8740c5@j2g2000yqf.googlegroups.com> This is the page i am getting on localhost 8080. The code is showing me thr result only in Eclipse but not through google app engine launcher. Traceback (most recent call last): File "C:\Program Files (x86)\Google\google_appengine\google\appengine \tools\dev_appserver.py", line 3211, in _HandleRequest self._Dispatch(dispatcher, self.rfile, outfile, env_dict) File "C:\Program Files (x86)\Google\google_appengine\google\appengine \tools\dev_appserver.py", line 3154, in _Dispatch base_env_dict=env_dict) File "C:\Program Files (x86)\Google\google_appengine\google\appengine \tools\dev_appserver.py", line 527, in Dispatch base_env_dict=base_env_dict) File "C:\Program Files (x86)\Google\google_appengine\google\appengine \tools\dev_appserver.py", line 2404, in Dispatch self._module_dict) File "C:\Program Files (x86)\Google\google_appengine\google\appengine \tools\dev_appserver.py", line 2314, in ExecuteCGI reset_modules = exec_script(handler_path, cgi_path, hook) File "C:\Program Files (x86)\Google\google_appengine\google\appengine \tools\dev_appserver.py", line 2210, in ExecuteOrImportScript exec module_code in script_module.__dict__ File "C:\Users\Admin\Pythonworkspace\pythonsample12\src \engineapp202\main.py", line 4, in import gdata.spreadsheet.service ImportError: No module named gdata.spreadsheet.service From steve-REMOVE-THIS at cybersource.com.au Mon Nov 1 04:16:41 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 01 Nov 2010 08:16:41 GMT Subject: Py3: Import relative path module References: <044f2fb7-a6a9-4bb9-b2a6-8ee1d0c19612@u17g2000yqi.googlegroups.com> Message-ID: <4cce7768$0$29965$c3e8da3$5496439d@news.astraweb.com> On Mon, 01 Nov 2010 01:08:52 -0700, Gnarlodious wrote: > On Oct 31, 11:09?am, ?????? ??????????? wrote: >> from .. import Data.DumpHT as DumpHT > > That doesn't work. Any more ideas? Define "doesn't work". Does it? Print a warning message but continue execution? Import the wrong module? Abort Python without warning? Dump core? Reboot the operating system without warning? Lock up the computer? Something else? -- Steven From whitequill.bj at gmail.com Mon Nov 1 04:19:26 2010 From: whitequill.bj at gmail.com (Bj Raz) Date: Mon, 1 Nov 2010 04:19:26 -0400 Subject: factorial of negative one (-1) In-Reply-To: References: Message-ID: On Fri, Oct 29, 2010 at 1:02 AM, Chris Rebert wrote: > On Thu, Oct 28, 2010 at 9:41 PM, Bj Raz wrote: > > I am working with differential equations of the higher roots of negative > > one. (dividing enormous numbers into other enormous numbers to come out > with > > very reasonable numbers). > > I am mixing this in to a script for Maya (the final output is graph-able > as > > a spiral.) > > I have heard that Sage, would be a good program to do this in, but I'd > like > > to try and get this to work in native python if I can. > > The script I am trying to port to Python is; > http://pastebin.com/sc1jW1n4. > > Unless your code is really long, just include it in the message in the > future. > So, for the archive: > indvar = 200; > q = 0; > lnanswer = 0; > for m = 1:150 > lnanswer = (3 * m) * log(indvar) - log(factorial(3 * m)) ; > q(m+1) = q(m)+ ((-1)^m) * exp(lnanswer); > end > lnanswer > q > > Also, it helps to point out *what language non-Python code is in*. I'm > guessing MATLAB in this case. > > Naive translation attempt (Disclaimer: I don't know much MATLAB): > > from math import log, factorial, exp > indvar = 200 > q = [0] > lnanswer = 0 > for m in range(1, 151): > lnanswer = (3 * m) * log(indvar) - log(factorial(3 * m)) > q.append(q[-1] + (1 if m % 2 == 0 else -1) * exp(lnanswer)) > print(lnanswer) > print(q) > > Cheers, > Chris > -- > http://blog.rebertia.com > I'm sorry I didn't read the thread very carefully. thank you for your help Chris. :) -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Mon Nov 1 04:22:15 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 1 Nov 2010 01:22:15 -0700 Subject: Allow multiline conditions and the like In-Reply-To: <4cce7196$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <4cce7196$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Nov 1, 2010 at 12:51 AM, Steven D'Aprano wrote: > On Sun, 31 Oct 2010 23:02:21 -0700, Yingjie Lan wrote: >> Hi, >> >> This is a mini-proposal I piggy-tailed in the other topic: >> >> Allow the conditions in the if-, elif-, while-, for-, and with-clauses >> to span multiple lines > [...] >> ? ?also, if we don't allow it, people just have to use >> parenthesis around the expressions to make that happen. > > You say that like it's a bad thing. > > That is kind of like saying "We should allow people to speed through red > traffic lights, because if we don't, they'll just wait for the light to > turn green!". Er, yes, and the problem is? > > If you need a multi-line conditional, wrap it in parentheses. Or, if possible, refactor the conditional into a function (call) so it's no longer multiline in the first place. Cheers, Chris From whitequill.bj at gmail.com Mon Nov 1 04:23:28 2010 From: whitequill.bj at gmail.com (Bj Raz) Date: Mon, 1 Nov 2010 04:23:28 -0400 Subject: factorial of negative one (-1) In-Reply-To: References: Message-ID: Simply out of curiosity is there a way to force python to print more then 16 places from the decimal? For better accuracy. On Mon, Nov 1, 2010 at 4:19 AM, Bj Raz wrote: > > > On Fri, Oct 29, 2010 at 1:02 AM, Chris Rebert wrote: > >> On Thu, Oct 28, 2010 at 9:41 PM, Bj Raz wrote: >> > I am working with differential equations of the higher roots of negative >> > one. (dividing enormous numbers into other enormous numbers to come out >> with >> > very reasonable numbers). >> > I am mixing this in to a script for Maya (the final output is graph-able >> as >> > a spiral.) >> > I have heard that Sage, would be a good program to do this in, but I'd >> like >> > to try and get this to work in native python if I can. >> > The script I am trying to port to Python is; >> http://pastebin.com/sc1jW1n4. >> >> Unless your code is really long, just include it in the message in the >> future. >> So, for the archive: >> indvar = 200; >> q = 0; >> lnanswer = 0; >> for m = 1:150 >> lnanswer = (3 * m) * log(indvar) - log(factorial(3 * m)) ; >> q(m+1) = q(m)+ ((-1)^m) * exp(lnanswer); >> end >> lnanswer >> q >> >> Also, it helps to point out *what language non-Python code is in*. I'm >> guessing MATLAB in this case. >> >> Naive translation attempt (Disclaimer: I don't know much MATLAB): >> >> from math import log, factorial, exp >> indvar = 200 >> q = [0] >> lnanswer = 0 >> for m in range(1, 151): >> lnanswer = (3 * m) * log(indvar) - log(factorial(3 * m)) >> q.append(q[-1] + (1 if m % 2 == 0 else -1) * exp(lnanswer)) >> print(lnanswer) >> print(q) >> >> Cheers, >> Chris >> -- >> http://blog.rebertia.com >> > I'm sorry I didn't read the thread very carefully. thank you for your help > Chris. :) -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Mon Nov 1 04:36:32 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 1 Nov 2010 01:36:32 -0700 Subject: factorial of negative one (-1) In-Reply-To: References: Message-ID: > On Mon, Nov 1, 2010 at 4:19 AM, Bj Raz wrote: >> On Fri, Oct 29, 2010 at 1:02 AM, Chris Rebert wrote: >>> On Thu, Oct 28, 2010 at 9:41 PM, Bj Raz wrote: >>> > I am working with differential equations of the higher roots of >>> > negative >>> > one. (dividing enormous numbers into other enormous numbers to come out >>> > with >>> > very reasonable numbers). >>> > I am mixing this in to a script for Maya (the final output is >>> > graph-able as >>> > a spiral.) >>> > I have heard that Sage, would be a good program to do this in, but I'd >>> > like >>> > to try and get this to work in native python if I can. >>> > The script I am trying to port to Python >>> > is;?http://pastebin.com/sc1jW1n4. >>> >>> Unless your code is really long, just include it in the message in the >>> future. >>> So, for the archive: >>> indvar = 200; >>> q = 0; >>> lnanswer = 0; >>> for m = 1:150 >>> ?lnanswer = (3 * m) * log(indvar) - log(factorial(3 * m)) ?; >>> q(m+1) = q(m)+ ((-1)^m) * exp(lnanswer); >>> end >>> lnanswer >>> q On Mon, Nov 1, 2010 at 1:23 AM, Bj Raz wrote: > Simply out of curiosity is there a way to force python to print more then 16 > places from the decimal? For better accuracy. (1) Please don't top-post. (http://en.wikipedia.org/wiki/Top-post ) (2) The underlying double-precision floating-point number only has ~16 decimal digits of precision, so it's pointless to print out "further" digits. (3) If you actually need more than 16 decimal places, use something like the `decimal.Decimal` datatype: http://docs.python.org/library/decimal.html Cheers, Chris -- http://blog.rebertia.com From qq263020776 at gmail.com Mon Nov 1 04:38:21 2010 From: qq263020776 at gmail.com (nu) Date: Mon, 1 Nov 2010 01:38:21 -0700 (PDT) Subject: how to sync file on client and server Message-ID: I want to sync the file foder in different server,and I can't use ftp protocl. I try to sync files during defferent server and not use username and password to login. Anyone has good ideas? From steve-REMOVE-THIS at cybersource.com.au Mon Nov 1 04:43:44 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 01 Nov 2010 08:43:44 GMT Subject: How on Factorial References: <1cf81147-06f4-4e48-9255-ea87bf3f93be@k22g2000yqh.googlegroups.com> <85dcd37b-871d-4058-b6af-8fc825afcc96@a37g2000yqi.googlegroups.com> Message-ID: <4cce7dc0$0$29965$c3e8da3$5496439d@news.astraweb.com> On Mon, 01 Nov 2010 20:23:42 +1300, Lawrence D'Oliveiro wrote: > In message , Jussi Piitulainen > wrote: > >> (I agree that no one should write factorial like that, except as a >> joke. I have nothing against (x if (a > b) else y). The trick with and >> and or was used before Python had an actual conditional expression.) > > You know what, I think I actually prefer the trick to Python?s > backwards-if syntax... What backwards-if syntax? I tried writing it backwards: true_clause fi condition esle false_clause and got a syntax error, so I tried writing it backwards another way: false_clause else condition if true_clause and still got a syntax error, so I can only conclude that you're using some hacked version of Python with non-standard syntax, if you're serious, else you're unaware that Python's ternary if operator follows English syntax. -- Steven From iwawi123 at gmail.com Mon Nov 1 04:58:50 2010 From: iwawi123 at gmail.com (iwawi) Date: Mon, 1 Nov 2010 01:58:50 -0700 (PDT) Subject: text file reformatting References: <78daefd1-59a1-4b3a-9bc2-5910315515ce@r14g2000yqa.googlegroups.com> <57ec83dd-3f30-4000-acf6-f49a44568d22@k22g2000yqh.googlegroups.com> Message-ID: On 1 marras, 09:59, "cbr... at cbrownsystems.com" wrote: > On Oct 31, 11:46?pm, iwawi wrote: > > > > > > > On 31 loka, 21:48, Tim Chase wrote: > > > > > PRJ01001 4 00100END > > > > PRJ01002 3 00110END > > > > > I would like to pick only some columns to a new file and put them to a > > > > certain places (to match previous data) - definition file (def.csv) > > > > could be something like this: > > > > > VARIABLE ? FIELDSTARTS ? ? FIELD SIZE ? ? ?NEW PLACE IN NEW DATA FILE > > > > ProjID ? ? ; ? ? ? 1 ? ? ? ; ? ? ? 5 ? ? ? ; ? ? ? 1 > > > > CaseID ? ? ; ? ? ? 6 ? ? ? ; ? ? ? 3 ? ? ? ; ? ? ? 10 > > > > UselessV ?; ? ? ? ?10 ? ? ?; ? ? ? 1 ? ? ? ; > > > > Zipcode ? ?; ? ? ? 12 ? ? ?; ? ? ? 5 ? ? ? ; ? ? ? 15 > > > > > So the new datafile should look like this: > > > > > PRJ01 ? ?001 ? ? ? 00100END > > > > PRJ01 ? ?002 ? ? ? 00110END > > > > How flexible is the def.csv format? ?The difficulty I see with > > > your def.csv format is that it leaves undefined gaps (presumably > > > to be filled in with spaces) and that you also have a blank "new > > > place in new file" value. ?If instead, you could specify the > > > width to which you want to pad it and omit variables you don't > > > want in the output, ordering the variables in the same order you > > > want them in the output: > > > > ? Variable; Start; Size; Width > > > ? ProjID; 1; 5; 10 > > > ? CaseID; 6; 3; 10 > > > ? Zipcode; 12; 5; 5 > > > ? End; 16; 3; 3 > > > > (note that I lazily use the same method to copy the END from the > > > source to the destination, rather than coding specially for it) > > > you could do something like this (untested) > > > > ? ?import csv > > > ? ?f = file('def.csv', 'rb') > > > ? ?f.next() # discard the header row > > > ? ?r = csv.reader(f, delimiter=';') > > > ? ?fields = [ > > > ? ? ?(varname, slice(int(start), int(start)+int(size)), width) > > > ? ? ?for varname, start, size, width > > > ? ? ?in r > > > ? ? ?] > > > ? ?f.close() > > > ? ?out = file('out.txt', 'w') > > > ? ?try: > > > ? ? ?for row in file('data.txt'): > > > ? ? ? ?for varname, slc, width in fields: > > > ? ? ? ? ?out.write(row[slc].ljust(width)) > > > ? ? ? ?out.write('\n') > > > ? ?finally: > > > ? ? ?out.close() > > > > Hope that's fairly easy to follow and makes sense. ?There might > > > be some fence-posting errors (particularly your use of "1" as the > > > initial offset, while python uses "0" as the initial offset for > > > strings) > > > > If you can't modify the def.csv format, then things are a bit > > > more complex and I'd almost be tempted to write a script to try > > > and convert your existing def.csv format into something simpler > > > to process like what I describe. > > > > -tkc- Piilota siteerattu teksti - > > > > - N?yt? siteerattu teksti - > > > Hi, > > > Thanks for your reply. > > > Def.csv could be modified so that every line has the same structure: > > variable name, field start, field size and new place and would be > > separated with semicolomns as you mentioned. > > > I tried your script (which seems quite logical) but I get this > > > Traceback (most recent call last): > > ? File "testing.py", line 16, in > > ? ? out.write (row[slc].ljust(width)) > > TypeError: an integer is required > > > Yes - you said it was untested, but I can't figure out how to > > proceed... > > The line > > ? ? (varname, slice(int(start), int(start)+int(size)), width) > > should instead be > > ? ? (varname, slice(int(start), int(start)+int(size)), int(width)) > > although you give an example where there is no width - what does that > imply? In the above case, it will throw an exception. > > Anyway, I think you'll find there's something a bit off in the output > loop with the parameter passed to ljust() as well. The value given in > your csv seems to be the absolute position, but as it's implemented by > Tim, it acts as the relative position. > > Given Tim's parsing into the list fields, I have a feeling that what > you really want instead of > > ? ? for varname, slc, width in fields: > ? ? ? ? out.write(row[slc].ljust(width)) > ? ? out.write('\n') > > is to have > > ? ? s = '' > ? ? for varname, slc, width in fields: > ? ? ? ? s += " "*(width - len(s)) + row[slc] > ? ? out.write(s+'\n') > > And if that is what you want, then you will surely want to globally > replace the name 'width' with for example 'start_column', because then > it all makes sense :). > > Cheers - Chas- Piilota siteerattu teksti - > > - N?yt? siteerattu teksti - Yes, it's meant to be the absolute column position in a new file like you said. I used your changes to the csv-reading cause it seems more flexible, but the end of the code is still not working. Here's were I stand now: import re parse_columns = re.compile(r'\s*;\s*') f = file('def.csv', 'rb') f.readline() # discard the header row r = (parse_columns.split(line.strip()) for line in f) fields = [ (varname, slice(int(start), int(start)+int(size), int(width) if width else 0)) for varname, start, size, width in r ] f.close() print fields out = file('out.txt', 'w') try: for row in file('data.txt'): s = ' ' for varname, slc, width in fields: s += " "*(width - len(s)) + row[slc] out.write(s+'\n') finally: out.close() When executed, I get this: File "toimi.py", line 20, in for varname, slc, width in fields: ValueError: need more than 2 values to unpack From charugangal at gmail.com Mon Nov 1 05:05:43 2010 From: charugangal at gmail.com (charu gangal) Date: Mon, 1 Nov 2010 02:05:43 -0700 (PDT) Subject: using google app through python Message-ID: Hey! Can anyone help me with python script for reading google spreadsheets? what all packages do i need to import to make the code run successfully after deploying it on google environment..thnx in advance From hniksic at xemacs.org Mon Nov 1 05:42:06 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Mon, 01 Nov 2010 10:42:06 +0100 Subject: factorial of negative one (-1) References: Message-ID: <87r5f55qj5.fsf@xemacs.org> Chris Rebert writes: > (2) The underlying double-precision floating-point number only has ~16 > decimal digits of precision, so it's pointless to print out "further" > digits. A digression which has nothing to do with Raj's desire for "better accuracy"... Printing out further digits (without quotes) is not pointless if you want to find out the exact representation of your number in python's floating point, for educational purposes or otherwise. Python has a little-known but very instructive method for determining the makeup of a float: >>> 1.1 .as_integer_ratio() (2476979795053773, 2251799813685248) 1.1 is represented with the closest fraction with a power-of-two denominator, 2476979795053773/2251799813685248. As is the case with all Python floats, this fraction has an exact decimal representation, 1.100000000000000088817841970012523233890533447265625. It is not that unreasonable to request that the whole number be printed, and python will happily oblige: >>> "%.100g" % 1.1 '1.100000000000000088817841970012523233890533447265625' The digits after the first cluster of zeros are not garbage, at least not in the sense of what you get reading uninitialized memory and such; they're mathematically precise decimal digits of the number that "1.1" has turned into during conversion to float. From phil at riverbankcomputing.com Mon Nov 1 06:52:03 2010 From: phil at riverbankcomputing.com (Phil Thompson) Date: Mon, 01 Nov 2010 10:52:03 +0000 Subject: ANN: PyQt v4.8.1 Released Message-ID: PyQt v4.8.1 has been released and is available from http://www.riverbankcomputing.com/software/pyqt/. PyQt is a comprehensive set of bindings for the Qt application and UI framework from Nokia. It supports the same platforms as Qt (Windows, Linux and MacOS/X). PyQt supports Python v3 and Python v2.3 and later. The highlight of this release is full support for Qt v4.7.0 including the ability to integrate Python with QML, the new declarative markup language for building highly dynamic user interfaces. Windows installers are provided for the GPL version of PyQt which contains everything needed for PyQt development (including Qt, Qt Designer, QScintilla, and MySQL, PostgreSQL, SQLite and ODBC drivers) except Python itself. PyQt v4 is implemented as a set of 19 extension modules containing over 400 classes and over 6,000 functions and methods. QtCore The non-GUI infrastructure including event loops, threads, i18n, Unicode, signals and slots, user and application settings, mapped files and shared memory. QtDeclarative A set of classes that implement a framework for building highly dynamic user interfaces using the QML declarative language that can be integrated with Python. QtDesigner A set of classes that allow the Qt Designer GUI design tool to be extended with PyQt. QtGui A rich collection of GUI widgets. QtHelp A set of classes for creating and viewing searchable documentation and being able to integrate online help with PyQt applications. It includes the C++ port of the Lucene text search engine. QtNetwork A set of classes to support TCP and UDP socket programming and higher level protocols (eg. HTTP, SSL). QtOpenGL A set of classes that allows PyOpenGL to render onto Qt widgets. QtScript A set of classes that implements a JavaScript interpreter. Python objects may be exposed in the interpreter as JavaScript objects. QtScriptTools A debugger for the JavaScript interpreter. QtSql A set of classes that implement SQL data models and interfaces to industry standard databases. The Windows installers include support for SQLite, MySQL, PostgreSQL and ODBC. QtSvg A set of classes to render SVG files onto Qt widgets. QtTest A set of classes to automate unit testing of PyQt applications and GUIs. QtWebKit This implements a web browser engine based on the WebKit engine used by Apple's Safari browser. It allows the methods and properties of Python objects to be published and appear as JavaScript objects to scripts embedded in HTML pages. QtXML A set of classes that implement DOM and SAX parsers. QtXMLPatterns A set of classes that implement XQuery and XPath support for XML and custom data models. QAxContainer A set of classes for Windows that allows the integration of ActiveX controls and COM objects. phonon A cross-platform multimedia framework that enables the use of audio and video content in PyQt applications. DirectX is used as the Windows backend, QuickTime as the MacOS/X backend, and GStreamer as the Linux backend. QtMultimedia A set of classes that provide low-level multimedia functions. Application developers would normally use the phonon module. DBus PyQt includes dbus.mainloop.qt that allows the Qt event loop to be used with the standard DBus Python bindings. PyQt includes the pyuic4 utility which generates Python code to implement user interfaces created with Qt Designer in the same way that the uic utility generates C++ code. It is also able to load Designer XML files dynamically. PyQt is available under the GPL and a commercial license. Unlike Qt, PyQt is not available under the LGPL. The commercial PyQt license allows GPL applications to be relicensed at any time. From gnarlodious at gmail.com Mon Nov 1 06:54:31 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Mon, 1 Nov 2010 03:54:31 -0700 (PDT) Subject: Py3: Import relative path module References: <044f2fb7-a6a9-4bb9-b2a6-8ee1d0c19612@u17g2000yqi.googlegroups.com> <4cce7768$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Nov 1, 2:16?am, Steven D'Aprano wrote: > On Mon, 01 Nov 2010 01:08:52 -0700, Gnarlodious wrote: > > On Oct 31, 11:09?am, ?????? ??????????? wrote: > >> from .. import Data.DumpHT as DumpHT > > > That doesn't work. Any more ideas? > > Define "doesn't work". LOL. I get error: from .. import Data.DumpHT as DumpHT ^ SyntaxError: invalid syntax Rewording gets me closer: from ..Data import DumpHT ValueError: Attempted relative import in non-package I do have the empty __init__.py file in the Data folder. What is wrong? -- Gnarlie From alex at moreati.org.uk Mon Nov 1 06:55:37 2010 From: alex at moreati.org.uk (Alex Willmer) Date: Mon, 1 Nov 2010 03:55:37 -0700 (PDT) Subject: Would you recommend python as a first programming language? References: Message-ID: On Oct 30, 7:16?pm, brad... at hotmail.com wrote: > I was thinking of recommending this to a friend but what do you all think? > I think 1. Python is a great language, and a good starting point for many people. 2. You really haven't given us much to go on. Regards, Alex From xwraithanx at gmail.com Mon Nov 1 07:23:25 2010 From: xwraithanx at gmail.com (Chris McDonald) Date: Mon, 1 Nov 2010 04:23:25 -0700 Subject: 2to3 urllib.URLopener -> urllib.request.URLopener Message-ID: Howdy, I was going through, evaluating how hard a project would be to move over to a hybrid codebase of python2 and python3 using 2to3. I found that while it would convert most other urllib renames and moves, 2to3 currently leaves urllib.URLopener as is, instead of changing it to go via the request module. Not sure if this is a bug or intended, so thought I'd bring it up to the list. -Chris 'Wraithan' McDonald From kwatford+python at gmail.com Mon Nov 1 07:26:30 2010 From: kwatford+python at gmail.com (Ken Watford) Date: Mon, 1 Nov 2010 07:26:30 -0400 Subject: factorial of negative one (-1) In-Reply-To: <87r5f55qj5.fsf@xemacs.org> References: <87r5f55qj5.fsf@xemacs.org> Message-ID: On Mon, Nov 1, 2010 at 5:42 AM, Hrvoje Niksic wrote: > > Printing out further digits (without quotes) is not pointless if you > want to find out the exact representation of your number in python's > floating point, for educational purposes or otherwise. ?Python has a > little-known but very instructive method for determining the makeup of a > float: > >>>> 1.1 .as_integer_ratio() > (2476979795053773, 2251799813685248) > Handy, but if you need the exact representation, my preference is float.hex, which seems to be the same as C99's %a format. >>> math.pi.hex() '0x1.921fb54442d18p+1' >>> float.fromhex(math.pi.hex()) == math.pi True Granted, it's not as easy for humans to interpret, but it's useful for certain things. From neilc at norwich.edu Mon Nov 1 07:27:59 2010 From: neilc at norwich.edu (Neil Cerutti) Date: 1 Nov 2010 11:27:59 GMT Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> Message-ID: <8j7mhvFk3eU1@mid.individual.net> On 2010-11-01, Martin v. Loewis wrote: > i.e. avoid the backslash for multi-line conditions altogether > (in fact, I can't think any situation where I would use the > backslash). The horrible-to-nest with statement. -- Neil Cerutti From __peter__ at web.de Mon Nov 1 07:36:26 2010 From: __peter__ at web.de (Peter Otten) Date: Mon, 01 Nov 2010 12:36:26 +0100 Subject: Py3: Import relative path module References: <044f2fb7-a6a9-4bb9-b2a6-8ee1d0c19612@u17g2000yqi.googlegroups.com> <4cce7768$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: Gnarlodious wrote: > On Nov 1, 2:16 am, Steven D'Aprano T... at cybersource.com.au> wrote: >> On Mon, 01 Nov 2010 01:08:52 -0700, Gnarlodious wrote: >> > On Oct 31, 11:09 am, ?????? ??????????? wrote: >> >> from .. import Data.DumpHT as DumpHT >> >> > That doesn't work. Any more ideas? >> >> Define "doesn't work". > > LOL. > I get error: > > from .. import Data.DumpHT as DumpHT > ^ > SyntaxError: invalid syntax > > Rewording gets me closer: > > from ..Data import DumpHT > ValueError: Attempted relative import in non-package > > I do have the empty __init__.py file in the Data folder. What is > wrong? Remove the directory containing the importing file from your sys.path. E. g. if you have $ tree . `-- alpha |-- __init__.py |-- beta | |-- __init__.py | `-- one.py `-- gamma |-- __init__.py `-- two.py only the parent of alpha should be in your sys.path. Then to import alpha/gamma/two.py from alpha/beta/one.py use from ..gamma import two Peter From python.list at tim.thechases.com Mon Nov 1 08:10:18 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 01 Nov 2010 07:10:18 -0500 Subject: [Beginer Question] I heard about python needing some sort of_VariableName_ boiler plate? In-Reply-To: <878w1dlk81.fsf@benfinney.id.au> References: <878w1dlk81.fsf@benfinney.id.au> Message-ID: <4CCEAE2A.8030802@tim.thechases.com> On 10/31/10 23:51, Ben Finney wrote: >> Sorry, to clarify I heard that when you declare a variable in python >> you have to use some sort of standard boiler plate _variable_ however >> this has not been my experience using IDLE so is this even true? > > I don't know what ?some sort of boiler plate _variable_? might mean. With the same lack of context as everybody else, two ideas occur to me, both involve thinking the OP means "__variable__" (with the double-underscores) instead of with single underscores: 1) the *completely optional and certainly not manditory CONVENTION* of using things like __author__ or __version__ in a module for various meta-data. For some projects, these sorts of faux-special-variables may be more demanded, but that's a project-thing, not a Python-thing 2) the use of the __foo__ magic methods such as __init__ or __add__ to hook into language bindings/functionality. In this case, there's not a lot of use a boiler-plate template would do for you...what? perhaps create def __|__(self): """Docstring""" (leaving the cursor on the "|") But this isn't really much different from a generic function template with extra underscores and automatically adding "self" as the first parameter. But I've never found that terribly hard to type in the first place -- this is Python, not Pascal (where I'd have to distinguish between "procedure" and "function" and remember to correctly spell both) Or, it could be way too early on a Monday morning and I don't have a clue what the OP is talking about...which doesn't put me any further behind the other folks on the list. :*) -tkc From sadashiv.linux at gmail.com Mon Nov 1 08:52:11 2010 From: sadashiv.linux at gmail.com (Sadashiv) Date: Mon, 1 Nov 2010 05:52:11 -0700 (PDT) Subject: pcs pcap not able to recognize interface Message-ID: I'm facing following error while running Python script. Any idea what causing this error -- execute_local_command: Traceback (most recent call last): File "./pcapreplay/flowreplay.py", line 376, in main() File "./pcapreplay/flowreplay.py", line 177, in main cPcapC = pcs.PcapConnector(clientIface) File "/usr/lib/python2.7/site-packages/pcs/__init__.py", line 1850, in __init__ self.file = pcap.pcap(name, snaplen, promisc, timeout_ms) File "pcap.pyx", line 215, in pcs.pcap.pcap.__init__ (pcs/pcap/ pcap.c:1673) OSError: ioctl: No such device [53334 refs] start.py: ERROR connection_036: execute_local_command: Traceback (most recent call last): File "./pcapreplay/flowreplay.py", line 376, in main() File "./pcapreplay/flowreplay.py", line 177, in main cPcapC = pcs.PcapConnector(clientIface) File "/usr/lib/python2.7/site-packages/pcs/__init__.py", line 1850, in __init__ self.file = pcap.pcap(name, snaplen, promisc, timeout_ms) File "pcap.pyx", line 215, in pcs.pcap.pcap.__init__ (pcs/pcap/ pcap.c:1673) OSError: ioctl: No such device [53334 refs] From whitequill.bj at gmail.com Mon Nov 1 08:52:44 2010 From: whitequill.bj at gmail.com (Bj Raz) Date: Mon, 1 Nov 2010 08:52:44 -0400 Subject: factorial of negative one (-1) In-Reply-To: <87r5f55qj5.fsf@xemacs.org> References: <87r5f55qj5.fsf@xemacs.org> Message-ID: On Nov 1, 2010, at 5:42 AM, Hrvoje Niksic wrote: > Chris Rebert writes: > >> (2) The underlying double-precision floating-point number only has ~16 >> decimal digits of precision, so it's pointless to print out "further" >> digits. > > A digression which has nothing to do with Raj's desire for "better > accuracy"... > > Printing out further digits (without quotes) is not pointless if you > want to find out the exact representation of your number in python's > floating point, for educational purposes or otherwise. Python has a > little-known but very instructive method for determining the makeup of a > float: > >>>> 1.1 .as_integer_ratio() > (2476979795053773, 2251799813685248) > > 1.1 is represented with the closest fraction with a power-of-two > denominator, 2476979795053773/2251799813685248. As is the case with all > Python floats, this fraction has an exact decimal representation, > 1.100000000000000088817841970012523233890533447265625. It is not that > unreasonable to request that the whole number be printed, and python > will happily oblige: > >>>> "%.100g" % 1.1 > '1.100000000000000088817841970012523233890533447265625' > > The digits after the first cluster of zeros are not garbage, at least > not in the sense of what you get reading uninitialized memory and such; > they're mathematically precise decimal digits of the number that "1.1" > has turned into during conversion to float. Thank you Chris. > -- > http://mail.python.org/mailman/listinfo/python-list From invalid at invalid.invalid Mon Nov 1 09:03:28 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 1 Nov 2010 13:03:28 +0000 (UTC) Subject: Would you recommend python as a first programming language? References: Message-ID: On 2010-10-30, bradenf at hotmail.com wrote: > I was thinking of recommending this to a friend but what do you all think? Sounds like a great idea to me. > Sent wirelessly from my BlackBerry. Well bully for you! -- Grant Edwards grant.b.edwards Yow! I am having FUN... at I wonder if it's NET FUN or gmail.com GROSS FUN? From dan.kluev at gmail.com Mon Nov 1 09:21:36 2010 From: dan.kluev at gmail.com (Daniel Kluev) Date: Mon, 1 Nov 2010 23:21:36 +1000 Subject: Would you recommend python as a first programming language? In-Reply-To: <1852590440-1288466169-cardhu_decombobulator_blackberry.rim.net-702637351-@bda480.bisx.prod.on.blackberry> References: <1852590440-1288466169-cardhu_decombobulator_blackberry.rim.net-702637351-@bda480.bisx.prod.on.blackberry> Message-ID: > > I was thinking of recommending this to a friend but what do you all think? > Python is great language to learn programming. I've heard MIT switched from Scheme to Python as introductory language for their students. -- With best regards, Daniel Kluev -------------- next part -------------- An HTML attachment was scrubbed... URL: From dan at catfolks.net Mon Nov 1 11:03:41 2010 From: dan at catfolks.net (Dan M) Date: Mon, 01 Nov 2010 10:03:41 -0500 Subject: python script to read google spreadsheet References: <0b6f704c-e108-4fb9-afc2-3616d92d6694@t13g2000yqm.googlegroups.com> <45e3864a-6a63-49e9-ae0f-df3aeb8740c5@j2g2000yqf.googlegroups.com> Message-ID: On Mon, 01 Nov 2010 01:14:09 -0700, charu gangal wrote: > This is the page i am getting on localhost 8080. The code is showing me > thr result only in Eclipse but not through google app engine launcher. > > Traceback (most recent call last): > File "C:\Program Files (x86)\Google\google_appengine\google\appengine > \tools\dev_appserver.py", line 3211, in _HandleRequest > self._Dispatch(dispatcher, self.rfile, outfile, env_dict) > File "C:\Program Files (x86)\Google\google_appengine\google\appengine > \tools\dev_appserver.py", line 3154, in _Dispatch > base_env_dict=env_dict) > File "C:\Program Files (x86)\Google\google_appengine\google\appengine > \tools\dev_appserver.py", line 527, in Dispatch > base_env_dict=base_env_dict) > File "C:\Program Files (x86)\Google\google_appengine\google\appengine > \tools\dev_appserver.py", line 2404, in Dispatch > self._module_dict) > File "C:\Program Files (x86)\Google\google_appengine\google\appengine > \tools\dev_appserver.py", line 2314, in ExecuteCGI > reset_modules = exec_script(handler_path, cgi_path, hook) > File "C:\Program Files (x86)\Google\google_appengine\google\appengine > \tools\dev_appserver.py", line 2210, in ExecuteOrImportScript > exec module_code in script_module.__dict__ > File "C:\Users\Admin\Pythonworkspace\pythonsample12\src > \engineapp202\main.py", line 4, in > import gdata.spreadsheet.service > ImportError: No module named gdata.spreadsheet.service I'm something of a Python newbie, but could Eclipse be modifying your PYTHONPATH by adding the directory in which gdata.spreadsheet.service is installed? From gnarlodious at gmail.com Mon Nov 1 11:30:34 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Mon, 1 Nov 2010 08:30:34 -0700 (PDT) Subject: Py3: Import relative path module References: <044f2fb7-a6a9-4bb9-b2a6-8ee1d0c19612@u17g2000yqi.googlegroups.com> <4cce7768$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <770dd3de-25f5-404c-a05a-7bdd2eb07179@26g2000yqv.googlegroups.com> On Nov 1, 5:36?am, Peter Otten wrote: > Remove the directory containing the importing file from your sys.path. I removed all sys.path customizations and rebooted. In the following scenario, I am programming in one.py attempting to import Data.py which is in the alpha folder: > $ tree > . > `-- alpha > ? ? |-- __init__.py > ? ? |-- beta > ? ? | ? |-- __init__.py > ? ? | ? `-- one.py > ? ? `-- gamma > ? ? ? ? |-- __init__.py > ? ? ? ? `-- two.py However, all I can get is error: from .. import Data ValueError: Attempted relative import in non-package Why is the parent folder not recognized as a package? Because right now I am liberally using sys.path, which works but is a little too messy. -- Gnarlie From __peter__ at web.de Mon Nov 1 12:02:25 2010 From: __peter__ at web.de (Peter Otten) Date: Mon, 01 Nov 2010 17:02:25 +0100 Subject: Py3: Import relative path module References: <044f2fb7-a6a9-4bb9-b2a6-8ee1d0c19612@u17g2000yqi.googlegroups.com> <4cce7768$0$29965$c3e8da3$5496439d@news.astraweb.com> <770dd3de-25f5-404c-a05a-7bdd2eb07179@26g2000yqv.googlegroups.com> Message-ID: Gnarlodious wrote: > On Nov 1, 5:36 am, Peter Otten wrote: > >> Remove the directory containing the importing file from your sys.path. > I removed all sys.path customizations and rebooted. > > In the following scenario, I am programming in one.py attempting to > import Data.py which is in the alpha folder: >> $ tree >> . >> `-- alpha >> |-- __init__.py >> |-- beta >> | |-- __init__.py >> | `-- one.py >> `-- gamma >> |-- __init__.py >> `-- two.py > > However, all I can get is error: > > from .. import Data > ValueError: Attempted relative import in non-package > > Why is the parent folder not recognized as a package? Because right > now I am liberally using sys.path, which works but is a little too > messy. If you didn't add '/path/to/alpha' to your path explicitly then you may be starting one.py as a script with $ python /path/to/alpha/beta/one.py one.py then becomes the __main__ module instead of alpha.beta.one. Or your working directory is /path/to/alpha and you import one.py with import beta.one which makes beta instead of alpha the toplevel package. Peter From darcy at druid.net Mon Nov 1 12:26:19 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Mon, 1 Nov 2010 12:26:19 -0400 Subject: Would you recommend python as a first programming language? In-Reply-To: <1852590440-1288466169-cardhu_decombobulator_blackberry.rim.net-702637351-@bda480.bisx.prod.on.blackberry> References: <1852590440-1288466169-cardhu_decombobulator_blackberry.rim.net-702637351-@bda480.bisx.prod.on.blackberry> Message-ID: <20101101122619.7ed69524.darcy@druid.net> On Sat, 30 Oct 2010 19:16:10 +0000 bradenf at hotmail.com wrote: > I was thinking of recommending this to a friend but what do you all think? Of course! But then, what did you expect from this group. :-) -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From zak.mc.kraken at libero.it Mon Nov 1 12:41:40 2010 From: zak.mc.kraken at libero.it (Vito 'ZeD' De Tullio) Date: Mon, 01 Nov 2010 17:41:40 +0100 Subject: How on Factorial References: <1cf81147-06f4-4e48-9255-ea87bf3f93be@k22g2000yqh.googlegroups.com> <85dcd37b-871d-4058-b6af-8fc825afcc96@a37g2000yqi.googlegroups.com> Message-ID: Lawrence D'Oliveiro wrote: > You know what, I think I actually prefer the trick to Python?s > backwards-if syntax... fact = lambda x: x*fact(x-1) if x>1 else 1 naa, it's not too bad... -- By ZeD From cbrown at cbrownsystems.com Mon Nov 1 12:50:16 2010 From: cbrown at cbrownsystems.com (cbrown at cbrownsystems.com) Date: Mon, 1 Nov 2010 09:50:16 -0700 (PDT) Subject: text file reformatting References: <78daefd1-59a1-4b3a-9bc2-5910315515ce@r14g2000yqa.googlegroups.com> <57ec83dd-3f30-4000-acf6-f49a44568d22@k22g2000yqh.googlegroups.com> Message-ID: <31a905d6-982d-479d-b988-e8324a1a16c7@j25g2000yqa.googlegroups.com> On Nov 1, 1:58?am, iwawi wrote: > On 1 marras, 09:59, "cbr... at cbrownsystems.com" > > > > wrote: > > On Oct 31, 11:46?pm, iwawi wrote: > > > > On 31 loka, 21:48, Tim Chase wrote: > > > > > > PRJ01001 4 00100END > > > > > PRJ01002 3 00110END > > > > > > I would like to pick only some columns to a new file and put them to a > > > > > certain places (to match previous data) - definition file (def.csv) > > > > > could be something like this: > > > > > > VARIABLE ? FIELDSTARTS ? ? FIELD SIZE ? ? ?NEW PLACE IN NEW DATA FILE > > > > > ProjID ? ? ; ? ? ? 1 ? ? ? ; ? ? ? 5 ? ? ? ; ? ? ? 1 > > > > > CaseID ? ? ; ? ? ? 6 ? ? ? ; ? ? ? 3 ? ? ? ; ? ? ? 10 > > > > > UselessV ?; ? ? ? ?10 ? ? ?; ? ? ? 1 ? ? ? ; > > > > > Zipcode ? ?; ? ? ? 12 ? ? ?; ? ? ? 5 ? ? ? ; ? ? ? 15 > > > > > > So the new datafile should look like this: > > > > > > PRJ01 ? ?001 ? ? ? 00100END > > > > > PRJ01 ? ?002 ? ? ? 00110END > > > > > How flexible is the def.csv format? ?The difficulty I see with > > > > your def.csv format is that it leaves undefined gaps (presumably > > > > to be filled in with spaces) and that you also have a blank "new > > > > place in new file" value. ?If instead, you could specify the > > > > width to which you want to pad it and omit variables you don't > > > > want in the output, ordering the variables in the same order you > > > > want them in the output: > > > > > ? Variable; Start; Size; Width > > > > ? ProjID; 1; 5; 10 > > > > ? CaseID; 6; 3; 10 > > > > ? Zipcode; 12; 5; 5 > > > > ? End; 16; 3; 3 > > > > > (note that I lazily use the same method to copy the END from the > > > > source to the destination, rather than coding specially for it) > > > > you could do something like this (untested) > > > > > ? ?import csv > > > > ? ?f = file('def.csv', 'rb') > > > > ? ?f.next() # discard the header row > > > > ? ?r = csv.reader(f, delimiter=';') > > > > ? ?fields = [ > > > > ? ? ?(varname, slice(int(start), int(start)+int(size)), width) > > > > ? ? ?for varname, start, size, width > > > > ? ? ?in r > > > > ? ? ?] > > > > ? ?f.close() > > > > ? ?out = file('out.txt', 'w') > > > > ? ?try: > > > > ? ? ?for row in file('data.txt'): > > > > ? ? ? ?for varname, slc, width in fields: > > > > ? ? ? ? ?out.write(row[slc].ljust(width)) > > > > ? ? ? ?out.write('\n') > > > > ? ?finally: > > > > ? ? ?out.close() > > > > > Hope that's fairly easy to follow and makes sense. ?There might > > > > be some fence-posting errors (particularly your use of "1" as the > > > > initial offset, while python uses "0" as the initial offset for > > > > strings) > > > > > If you can't modify the def.csv format, then things are a bit > > > > more complex and I'd almost be tempted to write a script to try > > > > and convert your existing def.csv format into something simpler > > > > to process like what I describe. > > > > > -tkc- Piilota siteerattu teksti - > > > > > - N?yt? siteerattu teksti - > > > > Hi, > > > > Thanks for your reply. > > > > Def.csv could be modified so that every line has the same structure: > > > variable name, field start, field size and new place and would be > > > separated with semicolomns as you mentioned. > > > > I tried your script (which seems quite logical) but I get this > > > > Traceback (most recent call last): > > > ? File "testing.py", line 16, in > > > ? ? out.write (row[slc].ljust(width)) > > > TypeError: an integer is required > > > > Yes - you said it was untested, but I can't figure out how to > > > proceed... > > > The line > > > ? ? (varname, slice(int(start), int(start)+int(size)), width) > > > should instead be > > > ? ? (varname, slice(int(start), int(start)+int(size)), int(width)) > > > although you give an example where there is no width - what does that > > imply? In the above case, it will throw an exception. > > > Anyway, I think you'll find there's something a bit off in the output > > loop with the parameter passed to ljust() as well. The value given in > > your csv seems to be the absolute position, but as it's implemented by > > Tim, it acts as the relative position. > > > Given Tim's parsing into the list fields, I have a feeling that what > > you really want instead of > > > ? ? for varname, slc, width in fields: > > ? ? ? ? out.write(row[slc].ljust(width)) > > ? ? out.write('\n') > > > is to have > > > ? ? s = '' > > ? ? for varname, slc, width in fields: > > ? ? ? ? s += " "*(width - len(s)) + row[slc] > > ? ? out.write(s+'\n') > > > And if that is what you want, then you will surely want to globally > > replace the name 'width' with for example 'start_column', because then > > it all makes sense :). > > > Cheers - Chas- Piilota siteerattu teksti - > > > - N?yt? siteerattu teksti - > > Yes, it's meant to be the absolute column position in a new file like > you said. > > I used your changes to the csv-reading cause it seems more flexible, > but the end of the code is still not working. Here's were I stand now: > > import re > > parse_columns = re.compile(r'\s*;\s*') > > f = file('def.csv', 'rb') > f.readline() # discard the header row > r = (parse_columns.split(line.strip()) for line in f) > fields = [ > ?(varname, slice(int(start), int(start)+int(size), int(width) if width > else 0)) there's a misplaced parentheses; replace the above line (which yields a 2-tuple of values) with: (varname, slice(int(start), int(start)+int(size)), int(width) if width else 0) which yields a 3-tuple. Cheers - Chas > ? for varname, start, size, width in r > ?] > f.close() > print fields > > out = file('out.txt', 'w') > > try: > ?for row in file('data.txt'): > ? s = ' ' > ? for varname, slc, width in fields: > ? ?s += " "*(width - len(s)) + row[slc] > ? out.write(s+'\n') > finally: > ?out.close() > > When executed, I get this: > ? File "toimi.py", line 20, in > ? ? for varname, slc, width in fields: > ValueError: need more than 2 values to unpack From mygogo2011 at gmail.com Mon Nov 1 12:54:47 2010 From: mygogo2011 at gmail.com (PHP.CCC) Date: Mon, 1 Nov 2010 09:54:47 -0700 (PDT) Subject: PHP (PHP Hypertext Preprocessor) Programming is Similar to C ... Message-ID: PHP (PHP Hypertext Preprocessor) Programming is Similar to C ... PHP programming is similar to C / JavaScript and Java. ... Modeling Agencies - Helping Teen Models ? Fashion and Success - Starting a Retail ... Read More http://childschooledu.blogspot.com/ From ppearson at nowhere.invalid Mon Nov 1 13:11:33 2010 From: ppearson at nowhere.invalid (Peter Pearson) Date: 1 Nov 2010 17:11:33 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> Message-ID: <8j8am4Fk2jU1@mid.individual.net> On Mon, 01 Nov 2010 12:09:12 +1300, Lawrence D'Oliveiro wrote: > In message <4ccd5ad9$0$19151$426a74cc at news.free.fr>, jf wrote: > >> I edit each file to remove tabs ... > > expand -i newfile > >> Do you know a tools to compare the initial file with the cleaned one to >> know if the algorithms are the same ? > > diff -b oldfile newfile Warning: "diff -b" won't detect changes in indentation. Changes in indentation can change a Python program. -- To email me, substitute nowhere->spamcop, invalid->net. From python at mrabarnett.plus.com Mon Nov 1 13:33:22 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 01 Nov 2010 17:33:22 +0000 Subject: [Beginer Question] I heard about python needing some sort of_VariableName_ boiler plate? In-Reply-To: <878w1dlk81.fsf@benfinney.id.au> References: <878w1dlk81.fsf@benfinney.id.au> Message-ID: <4CCEF9E2.2000803@mrabarnett.plus.com> On 01/11/2010 04:51, Ben Finney wrote: > bradenf at hotmail.com writes: > >> Sorry, to clarify I heard that when you declare a variable in python >> you have to use some sort of standard boiler plate _variable_ however >> this has not been my experience using IDLE so is this even true? > > I don't know what ?some sort of boiler plate _variable_? might mean. > > Can you point to someone's actual message saying this, so we can see > what they might be talking about? > Perhaps the OP means: if __name__ == "__main__": ... although the "declare a variable" bit has me puzzled. From nagle at animats.com Mon Nov 1 13:56:51 2010 From: nagle at animats.com (John Nagle) Date: Mon, 01 Nov 2010 10:56:51 -0700 Subject: Exception Handling in Python 3 In-Reply-To: References: Message-ID: <4cceff62$0$1672$742ec2ed@news.sonic.net> On 10/24/2010 5:36 AM, Steve Holden wrote: > On 10/24/2010 2:22 AM, Lawrence D'Oliveiro wrote: >> In message, Steve >> Holden wrote: > Yes, *if the exception is caught* then it doesn't make any difference. > If the exception creates a traceback, however, I maintain that the > additional information is confusing to the consumer (while helpful to > the debugger of the consumed code). If an exception propagates all the way out to the top level and all the user gets is a system traceback, the program isn't very good. Really. If you're concerned about the display format of Python tracebacks seen by end users, you have bigger problems with your code. If it's a server-side program, you need to catch exceptions and log them somewhere, traceback and all. If it's a client-side GUI program, letting an exception unwind all the way out of the program loses whatever the user was doing. It's usually desirable to at least catch EnviromentError near the top level of your program. If some external problem causes a program abort, the user should get an error message, not a traceback. If it's a program bug, you can let the traceback unwind, displaying information that should be sent in with a bug report. John Nagle From bradenf at hotmail.com Mon Nov 1 14:18:45 2010 From: bradenf at hotmail.com (bradenf at hotmail.com) Date: Mon, 1 Nov 2010 18:18:45 +0000 Subject: [Beginer Question] I heard about python needing somesort of_VariableName_ boiler plate? In-Reply-To: <4CCEF9E2.2000803@mrabarnett.plus.com> References: <878w1dlk81.fsf@benfinney.id.au><4CCEF9E2.2000803@mrabarnett.plus.com> Message-ID: <1946543087-1288635527-cardhu_decombobulator_blackberry.rim.net-1324044669-@bda480.bisx.prod.on.blackberry> Sorry that is what I mean. What is it for? Sent wirelessly from my BlackBerry. -----Original Message----- From: MRAB Sender: python-list-bounces+bradenf=hotmail.com at python.org Date: Mon, 01 Nov 2010 17:33:22 To: Reply-To: python-list at python.org Subject: Re: [Beginer Question] I heard about python needing some sort of_VariableName_ boiler plate? On 01/11/2010 04:51, Ben Finney wrote: > bradenf at hotmail.com writes: > >> Sorry, to clarify I heard that when you declare a variable in python >> you have to use some sort of standard boiler plate _variable_ however >> this has not been my experience using IDLE so is this even true? > > I don't know what ?some sort of boiler plate _variable_? might mean. > > Can you point to someone's actual message saying this, so we can see > what they might be talking about? > Perhaps the OP means: if __name__ == "__main__": ... although the "declare a variable" bit has me puzzled. -- http://mail.python.org/mailman/listinfo/python-list From python at mrabarnett.plus.com Mon Nov 1 14:40:12 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 01 Nov 2010 18:40:12 +0000 Subject: [Beginer Question] I heard about python needing somesort of_VariableName_ boiler plate? In-Reply-To: <1946543087-1288635527-cardhu_decombobulator_blackberry.rim.net-1324044669-@bda480.bisx.prod.on.blackberry> References: <878w1dlk81.fsf@benfinney.id.au><4CCEF9E2.2000803@mrabarnett.plus.com> <1946543087-1288635527-cardhu_decombobulator_blackberry.rim.net-1324044669-@bda480.bisx.prod.on.blackberry> Message-ID: <4CCF098C.3070503@mrabarnett.plus.com> On 01/11/2010 18:18, bradenf at hotmail.com wrote: > Sorry that is what I mean. What is it for? > Sent wirelessly from my BlackBerry. > > -----Original Message----- > From: MRAB > Sender: python-list-bounces+bradenf=hotmail.com at python.org > Date: Mon, 01 Nov 2010 17:33:22 > To: > Reply-To: python-list at python.org > Subject: Re: [Beginer Question] I heard about python needing some > sort of_VariableName_ boiler plate? > > On 01/11/2010 04:51, Ben Finney wrote: >> bradenf at hotmail.com writes: >> >>> Sorry, to clarify I heard that when you declare a variable in python >>> you have to use some sort of standard boiler plate _variable_ however >>> this has not been my experience using IDLE so is this even true? >> >> I don't know what ?some sort of boiler plate _variable_? might mean. >> >> Can you point to someone's actual message saying this, so we can see >> what they might be talking about? >> > Perhaps the OP means: > > if __name__ == "__main__": > ... > > although the "declare a variable" bit has me puzzled. When a module is imported __name__ is bound to the name of the module, but when the module is run directly __name__ is bound to "__main__". See: http://docs.python.org/faq/programming.html?highlight=__name__ From benjamin.kaplan at case.edu Mon Nov 1 14:45:38 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 1 Nov 2010 14:45:38 -0400 Subject: [Beginer Question] I heard about python needing somesort of_VariableName_ boiler plate? In-Reply-To: <1946543087-1288635527-cardhu_decombobulator_blackberry.rim.net-1324044669-@bda480.bisx.prod.on.blackberry> References: <878w1dlk81.fsf@benfinney.id.au> <4CCEF9E2.2000803@mrabarnett.plus.com> <1946543087-1288635527-cardhu_decombobulator_blackberry.rim.net-1324044669-@bda480.bisx.prod.on.blackberry> Message-ID: On Mon, Nov 1, 2010 at 2:18 PM, wrote: > Sorry that is what I mean. What is it for? > Sent wirelessly from my BlackBerry. > What is what for? There is no boiler plate on variable names. *BY CONVENTION*, variables and methods with a special meaning will start and end with two underscores. *BY CONVENTION* something that you want to identify as an internal variable (what would be private in languages that enforce this) is prefixed with a single underscore. But neither of these are actually enforced by the language. For instance, an object's doc-string is stored as it's __doc__ attribute. The constructor is the __init__ method. The method that controls attribute access (which you can override) is __getattr__. Using str(object) to get the string representation works by calling the object's __str__ method. a + b is the same thing as a.__add__(b) > -----Original Message----- > From: MRAB > Sender: python-list-bounces+bradenf=hotmail.com at python.org > Date: Mon, 01 Nov 2010 17:33:22 > To: > Reply-To: python-list at python.org > Subject: Re: [Beginer Question] I heard about python needing some > ? ? ? ?sort ? ?of_VariableName_ boiler plate? > > On 01/11/2010 04:51, Ben Finney wrote: >> bradenf at hotmail.com writes: >> >>> Sorry, to clarify I heard that when you declare a variable in python >>> you have to use some sort of standard boiler plate _variable_ however >>> this has not been my experience using IDLE so is this even true? >> >> I don't know what ?some sort of boiler plate _variable_? might mean. >> >> Can you point to someone's actual message saying this, so we can see >> what they might be talking about? >> > Perhaps the OP means: > > ? ? if __name__ == "__main__": > ? ? ? ? ... > > although the "declare a variable" bit has me puzzled. > -- > http://mail.python.org/mailman/listinfo/python-list > -- > http://mail.python.org/mailman/listinfo/python-list > From usenot at geekmail.INVALID Mon Nov 1 15:38:35 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Mon, 1 Nov 2010 15:38:35 -0400 Subject: [Beginer Question] I heard about python needing somesort of_VariableName_ boiler plate? References: <878w1dlk81.fsf@benfinney.id.au> <4CCEF9E2.2000803@mrabarnett.plus.com> Message-ID: <20101101153835.08a5a02f@geekmail.INVALID> On Mon, 1 Nov 2010 18:18:45 +0000 bradenf at hotmail.com wrote: > Sorry that is what I mean. What is it for? > Sent wirelessly from my BlackBerry. > >>> andreas.quick_hot_anger = True Braden! Stop Top-Posting already! Please. If your BlackBerry makes this hard, then get another mail client. It gets confusing. And thereby, annoying. >>> andreas.quick_hot_anger = False /W -- To reach me via email, replace INVALID with the country code of my home country. But if you spam me, I'll be one sour Kraut. From tjreedy at udel.edu Mon Nov 1 15:42:52 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 01 Nov 2010 15:42:52 -0400 Subject: [Beginer Question] I heard about python needing somesort of_VariableName_ boiler plate? In-Reply-To: <1946543087-1288635527-cardhu_decombobulator_blackberry.rim.net-1324044669-@bda480.bisx.prod.on.blackberry> References: <878w1dlk81.fsf@benfinney.id.au><4CCEF9E2.2000803@mrabarnett.plus.com> <1946543087-1288635527-cardhu_decombobulator_blackberry.rim.net-1324044669-@bda480.bisx.prod.on.blackberry> Message-ID: On 11/1/2010 2:18 PM, bradenf at hotmail.com wrote: > Sorry that is what I mean. What is it for? > Sent wirelessly from my BlackBerry. Does it require you to toppost? Understanding the above requires one to guess what 'that' forward references. > Perhaps the OP means: > > if __name__ == "__main__": I presume that this is the 'that' which you forward-referenced. If so... Python reserves names of the form __xyz__ for itself. This is intentionally a bit awkward so as to stand out in code and not conflict with names a programmer might choose. This form is used for names that programmers *mostly* do not need to use. The system names that we do need to use constantly, like 'None', 'def', and 'int' have normal spellings. These are easy to type, but may conflict with a name that a programmer might be using. Every module has a name stored in its __name__ attribute. The the interpreter starts, it names the top level module, which is run directly instead of being imported, as '__main__'. When a module is run indirectly, by being imported, its name is what you expect from the docs or from the name of its file. So: 1. a module can have one of two runtime names (as defined by it __name__ attribute): '__main__' or its proper name. 2. a module's runtime name depends on whether it is run directly or imported. 3. a module can therefor tell how it is being run; this is usually done with "if __name__ == '__main__'. 4. a module can change its behavior depending on how it is run by putting code in the body of the conditional statement. Such a conditional statement is entirely OPTIONAL. There are two things people do in such a body. a. If the module is meant either imported or run as a useful standalone program (such as the stdlib trace module), check for arguments in sys.argv, do some useful work, and report. b. If the module is normally only meant to be imported, run a test. If a module is only meant to run as a program, or if it is only meant to be imported and all its tests are in a separate file, there there is no need for the conditional statement. -- Terry Jan Reedy From whitequill.bj at gmail.com Mon Nov 1 15:46:33 2010 From: whitequill.bj at gmail.com (Bj Raz) Date: Mon, 1 Nov 2010 15:46:33 -0400 Subject: factorial of negative one (-1) In-Reply-To: References: <87r5f55qj5.fsf@xemacs.org> Message-ID: On Mon, Nov 1, 2010 at 8:52 AM, Bj Raz wrote: > On Nov 1, 2010, at 5:42 AM, Hrvoje Niksic wrote: > > > Chris Rebert writes: > > > >> (2) The underlying double-precision floating-point number only has ~16 > >> decimal digits of precision, so it's pointless to print out "further" > >> digits. > > > > A digression which has nothing to do with Raj's desire for "better > > accuracy"... > > > > Printing out further digits (without quotes) is not pointless if you > > want to find out the exact representation of your number in python's > > floating point, for educational purposes or otherwise. Python has a > > little-known but very instructive method for determining the makeup of a > > float: > > > >>>> 1.1 .as_integer_ratio() > > (2476979795053773, 2251799813685248) > > > > 1.1 is represented with the closest fraction with a power-of-two > > denominator, 2476979795053773/2251799813685248. As is the case with all > > Python floats, this fraction has an exact decimal representation, > > 1.100000000000000088817841970012523233890533447265625. It is not that > > unreasonable to request that the whole number be printed, and python > > will happily oblige: > > > >>>> "%.100g" % 1.1 > > '1.100000000000000088817841970012523233890533447265625' > > > > The digits after the first cluster of zeros are not garbage, at least > > not in the sense of what you get reading uninitialized memory and such; > > they're mathematically precise decimal digits of the number that "1.1" > > has turned into during conversion to float. > > Thank you Chris. > > -- > > http://mail.python.org/mailman/listinfo/python-list > Would "math.fsum" be of any use to me? and what is a good application of the ".as_integer_ratio()" for the out put? Also I really just need the last number that starts to replete at the end of each iteration. Is there a way to isolate that number that repeats a whole bunch of times? Or at least cut off the output when it stops repeating? So I get an output that looks like; "[0, -1.3333333333333333, -1.2444444444444445, -1.2458553791887126, -1.2458468280690504, -1.2458468531272766, -1.2458468530863318, -1.2458468530863729]" or "[-1.2458468530863729]" and not: [0, -1.3333333333333333, -1.2444444444444445, -1.2458553791887126, -1.2458468280690504, -1.2458468531272766, -1.2458468530863318, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729, -1.2458468530863729]. and when I am working with, other numbers; is there a way to get more repetitions if I really need it? Thank you everyone for all your suggestions and help. :) -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Mon Nov 1 15:54:53 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 01 Nov 2010 15:54:53 -0400 Subject: Py3: Import relative path module In-Reply-To: References: <044f2fb7-a6a9-4bb9-b2a6-8ee1d0c19612@u17g2000yqi.googlegroups.com> <4cce7768$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 11/1/2010 6:54 AM, Gnarlodious wrote: > On Nov 1, 2:16 am, Steven D'Aprano T... at cybersource.com.au> wrote: >> On Mon, 01 Nov 2010 01:08:52 -0700, Gnarlodious wrote: >>> On Oct 31, 11:09 am, ?????? ??????????? wrote: >>>> from .. import Data.DumpHT as DumpHT >> >>> That doesn't work. Any more ideas? >> >> Define "doesn't work". > > LOL. > I get error: > > from .. import Data.DumpHT as DumpHT > ^ > SyntaxError: invalid syntax > > Rewording gets me closer: > > from ..Data import DumpHT > ValueError: Attempted relative import in non-package > > I do have the empty __init__.py file in the Data folder. What is > wrong? What about the folder above it? As far as I know, the main reason to use relative imports is if you have a subpackage that you expect to use within more then one package. Otherwise, it is usually a lot easier to use absolute imports starting with the top-level package. -- Terry Jan Reedy From tjreedy at udel.edu Mon Nov 1 16:30:30 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 01 Nov 2010 16:30:30 -0400 Subject: 2to3 urllib.URLopener -> urllib.request.URLopener In-Reply-To: References: Message-ID: On 11/1/2010 7:23 AM, Chris McDonald wrote: > Howdy, > > I was going through, evaluating how hard a project would be to move > over to a hybrid codebase of python2 and python3 using 2to3. I found > that while it would convert most other urllib renames and moves, 2to3 > currently leaves urllib.URLopener as is, instead of changing it to go > via the request module. > > Not sure if this is a bug or intended, so thought I'd bring it up to the list. Good catch. Bug. Thanks for reporting. Lib/lib2to3/fixes/fix_urllib.py has (near the top) ''' MAPPING = {'urllib': [ ('urllib.request', ['URLOpener', 'FancyURLOpener', 'urlretrieve', ''' I reported the double misspelling of 'opener' as 'Opener' in http://bugs.python.org/issue10286 You can fix your local copy now. Good luck with the conversion. -- Terry Jan Reedy From fetchinson at googlemail.com Mon Nov 1 16:31:07 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Mon, 1 Nov 2010 21:31:07 +0100 Subject: playful coding problems for 10 year olds Message-ID: Hi folks, My niece is interested in programming and python looks like a good choice (she already wrote a couple of lines :)) She is 10 and I thought it would be good to have a bunch of playful coding problems for her, stuff that she could code herself maybe after some initial help. Do you guys know problems like these? Or a good resource where to look them up? Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From invalid at invalid.invalid Mon Nov 1 16:57:24 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 1 Nov 2010 20:57:24 +0000 (UTC) Subject: [Beginer Question] I heard about python needing somesort of_VariableName_ boiler plate? References: <878w1dlk81.fsf@benfinney.id.au> <4CCEF9E2.2000803@mrabarnett.plus.com> <1946543087-1288635527-cardhu_decombobulator_blackberry.rim.net-1324044669-@bda480.bisx.prod.on.blackberry> Message-ID: On 2010-11-01, Benjamin Kaplan wrote: > On Mon, Nov 1, 2010 at 2:18 PM, wrote: >> Sorry that is what I mean. What is it for? >> Sent wirelessly from my BlackBerry. > > What is what for? I think I smell troll... -- Grant Edwards grant.b.edwards Yow! hubub, hubub, HUBUB, at hubub, hubub, hubub, HUBUB, gmail.com hubub, hubub, hubub. From dirknbr at gmail.com Mon Nov 1 16:58:36 2010 From: dirknbr at gmail.com (Dirk Nachbar) Date: Mon, 1 Nov 2010 13:58:36 -0700 (PDT) Subject: playful coding problems for 10 year olds References: Message-ID: <3385082a-7b24-4a9d-b452-c3fa7db44cd1@26g2000yqv.googlegroups.com> This is in JS but have a look here http://github.com/ryanmcgrath/splash On 1 Nov, 20:31, Daniel Fetchinson wrote: > Hi folks, > > My niece is interested in programming and python looks like a good > choice (she already wrote a couple of lines :)) She is 10 and I > thought it would be good to have a bunch of playful coding problems > for her, stuff that she could code herself maybe after some initial > help. > > Do you guys know problems like these? Or a good resource where to look them up? > > Cheers, > Daniel > > -- > Psss, psss, put it down! -http://www.cafepress.com/putitdown From dirknbr at gmail.com Mon Nov 1 17:03:07 2010 From: dirknbr at gmail.com (Dirk Nachbar) Date: Mon, 1 Nov 2010 14:03:07 -0700 (PDT) Subject: using google app through python References: Message-ID: Why don't you start here http://code.google.com/apis/spreadsheets/data/1.0/developers_guide_python.html On 1 Nov, 09:05, charu gangal wrote: > Hey! Can anyone help me with python script for reading google > spreadsheets? what all packages do i need to import to make the code > run successfully after deploying it on google environment..thnx in > advance From iamforufriends at gmail.com Mon Nov 1 17:03:09 2010 From: iamforufriends at gmail.com (ADULTS GROUP FOR FUN WITH SE ^X) Date: Mon, 1 Nov 2010 14:03:09 -0700 (PDT) Subject: HAI ALL... U KNOW, NOW DATING WITH SWEETHARTS IS EAZY AND FREE....... Message-ID: <522e2b5b-d5be-4768-848a-4e2afdab3627@26g2000yqv.googlegroups.com> HAI ALL... U KNOW, NOW DATING WITH SWEETHARTS IS EAZY AND FREE....... HAI ALL... U KNOW, NOW DATING WITH SWEETHARTS IS EAZY AND FREE....... JUST FOLLOW THE LINK....... http://tinyurl.com/eazy-dating http://tinyurl.com/eazy-dating http://tinyurl.com/eazy-dating http://tinyurl.com/eazy-dating http://tinyurl.com/eazy-dating http://tinyurl.com/eazy-dating http://tinyurl.com/eazy-dating http://tinyurl.com/eazy-dating http://tinyurl.com/eazy-dating From arnodel at gmail.com Mon Nov 1 17:13:42 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Mon, 01 Nov 2010 21:13:42 +0000 Subject: playful coding problems for 10 year olds References: Message-ID: <87d3qo692x.fsf@gmail.com> Daniel Fetchinson writes: > Hi folks, > > My niece is interested in programming and python looks like a good > choice (she already wrote a couple of lines :)) She is 10 and I > thought it would be good to have a bunch of playful coding problems > for her, stuff that she could code herself maybe after some initial > help. > > Do you guys know problems like these? Or a good resource where to look > them up? > > Cheers, > Daniel I don't have a list of problems, but I think it's nice to have an environment that provides a very easy way to draw graphics and interact with the user (the way it could be done in the 80s on most personal computers). If you want to use Python, Pyprocessing [1] is an attempt to provide such an environment. Python has a sig that might be relevant: edu-sig [2]. The web page has a lot of links. Finally, I have written an online programming game [3] provisionally called "Robo2flags" where the player has to direct a robot through a maze to catch all the flags it contains. But the robot can't be controlled in real-time; you have to design a circuit board for it (in fact, a program). It's not quite the finished product, but it works and the server is in Python! It needs a browser that implements canvas though (e.g. Firefox, Chrome, Safari). [1] http://code.google.com/p/pyprocessing/ [2] http://www.python.org/community/sigs/current/edu-sig/ [3] http://www.marooned.org.uk/robo -- Arnaud From martin at v.loewis.de Mon Nov 1 17:48:05 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Mon, 01 Nov 2010 22:48:05 +0100 Subject: playful coding problems for 10 year olds In-Reply-To: References: Message-ID: <4CCF3595.2060102@v.loewis.de> > My niece is interested in programming and python looks like a good > choice (she already wrote a couple of lines :)) She is 10 and I > thought it would be good to have a bunch of playful coding problems > for her, stuff that she could code herself maybe after some initial > help. I think anything that has to do with drawing and colors will be attractive, animated if possible. It has to look nice. Take a look at the turtle demos. Regards, Martin From mskcrpttnrmt at gmail.com Mon Nov 1 17:55:06 2010 From: mskcrpttnrmt at gmail.com (Fossil) Date: Mon, 1 Nov 2010 14:55:06 -0700 (PDT) Subject: serial I/O install fail -- DLL not found Message-ID: Just starting with Python. Installed: Python 2.7 pywin32-214.win32-py2.7.exe pyserial-2.5.win32.exe on a Home WinXP SP3 Toshiba laptop with 2GB memory. Open Python and try to do simple I/O test and can't even get past first line. Transcript below. You will see that __name__ is defined as '__main__" but path is not defined. Could this be due to creating the folder holding the Python.exe being on the E: drive or for some other obscure reason? The DOS path environmental variable includes: e:\Program Files\Python27 Thanks in advance for for any help. **********transcript************* Python 2.7 (r27:82525, Jul 4 2010, 09:01:59) [MSC v.1500 32 bit (Intel)] on win 32 Type "help", "copyright", "credits" or "license" for more information. >>> from uspp import * Traceback (most recent call last): File "", line 1, in File "E:\Python27\lib\uspp.py", line 189, in from SerialPort_win import * File "E:\Python27\lib\SerialPort_win.py", line 54, in from win32file import * File "E:\Python27\lib\win32file.py", line 12, in __load() File "E:\Python27\lib\win32file.py", line 10, in __load mod = imp.load_dynamic(__name__, path) ImportError: DLL load failed: The specified module could not be found. >>> path Traceback (most recent call last): File "", line 1, in NameError: name 'path' is not defined >>> __name__ '__main__' >>> From ldo at geek-central.gen.new_zealand Mon Nov 1 18:16:46 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 02 Nov 2010 11:16:46 +1300 Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> Message-ID: In message <4CCE6FF6.2050408 at v.loewis.de>, Martin v. Loewis wrote: > (in fact, I can't think any situation where I would use the backslash). for \ Description, Attr, ColorList \ in \ ( ("normal", "image", MainWindow.ColorsNormalList), ("highlighted", "highlight", MainWindow.ColorsHighlightedList), ("selected", "select", MainWindow.ColorsSelectedList), ) \ : ... #end for From ldo at geek-central.gen.new_zealand Mon Nov 1 18:18:23 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 02 Nov 2010 11:18:23 +1300 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: In message <8j8am4Fk2jU1 at mid.individual.net>, Peter Pearson wrote: > On Mon, 01 Nov 2010 12:09:12 +1300, Lawrence D'Oliveiro wrote: > >> In message <4ccd5ad9$0$19151$426a74cc at news.free.fr>, jf wrote: >> >>> I edit each file to remove tabs ... >> >> expand -i newfile >> >>> Do you know a tools to compare the initial file with the cleaned one to >>> know if the algorithms are the same ? >> >> diff -b oldfile newfile > > Warning: "diff -b" won't detect changes in indentation. Changes in > indentation can change a Python program. I?m getting less and less keen on that particular feature of Python... From invalid at invalid.invalid Mon Nov 1 18:24:03 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 1 Nov 2010 22:24:03 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: On 2010-11-01, Lawrence D'Oliveiro wrote: > In message <8j8am4Fk2jU1 at mid.individual.net>, Peter Pearson wrote: >> >>> diff -b oldfile newfile >> >> Warning: "diff -b" won't detect changes in indentation. Changes in >> indentation can change a Python program. > > I'm getting less and less keen on that particular feature of Python... Why? Other languages have similar problems if you remove salient bits of syntax before comparing two source files files. For exmaple, if you remove all of the curly-braces from two C source files before comparing them, you don't get useful results. -- Grant Edwards grant.b.edwards Yow! I'm continually AMAZED at at th'breathtaking effects gmail.com of WIND EROSION!! From ldo at geek-central.gen.new_zealand Mon Nov 1 18:25:14 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 02 Nov 2010 11:25:14 +1300 Subject: playful coding problems for 10 year olds References: <4CCF3595.2060102@v.loewis.de> Message-ID: In message <4CCF3595.2060102 at v.loewis.de>, Martin v. Loewis wrote: > Take a look at the turtle demos. Are turtle graphics still enough to hold the kids? interest these days? I?ve been visiting a local Computer Clubhouse, and it seems like they mostly spend their time in Google SketchUp and Photoshop. I managed to get one older one interested in Blender. What kind of easy programming exercises could compare with that? From benjamin.kaplan at case.edu Mon Nov 1 18:32:51 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 1 Nov 2010 18:32:51 -0400 Subject: serial I/O install fail -- DLL not found In-Reply-To: References: Message-ID: On Mon, Nov 1, 2010 at 5:55 PM, Fossil wrote: > Just starting with Python. > Installed: > ?Python 2.7 > ?pywin32-214.win32-py2.7.exe > ?pyserial-2.5.win32.exe > on a Home WinXP SP3 Toshiba laptop with 2GB memory. ?Open Python and > try to do simple I/O test and can't even get past first line. > Transcript below. ?You will see that > __name__ is defined as '__main__" > but path is not defined. ?Could this be due to creating the folder > holding the Python.exe being on the E: drive or for some other obscure > reason? ?The DOS path environmental variable includes: > e:\Program Files\Python27 > Thanks in advance for for any help. > **********transcript************* > > Python 2.7 (r27:82525, Jul ?4 2010, 09:01:59) [MSC v.1500 32 bit > (Intel)] on win > 32 > Type "help", "copyright", "credits" or "license" for more information. >>>> from uspp import * > Traceback (most recent call last): > ?File "", line 1, in > ?File "E:\Python27\lib\uspp.py", line 189, in > ? ?from SerialPort_win import * > ?File "E:\Python27\lib\SerialPort_win.py", line 54, in > ? ?from win32file import * > ?File "E:\Python27\lib\win32file.py", line 12, in > ? ?__load() > ?File "E:\Python27\lib\win32file.py", line 10, in __load > ? ?mod = imp.load_dynamic(__name__, path) > ImportError: DLL load failed: The specified module could not be found. >>>> path > Traceback (most recent call last): > ?File "", line 1, in > NameError: name 'path' is not defined >>>> __name__ > '__main__' >>>> > -- Python does not have true globals. At most, a variable is global to the module. __name__ in win32file.py is going to be 'win32file'. path is going to be something else. Without looking at the source of the file, I can't tell you what it is. The fact that you From emile at fenx.com Mon Nov 1 18:36:43 2010 From: emile at fenx.com (Emile van Sebille) Date: Mon, 01 Nov 2010 15:36:43 -0700 Subject: playful coding problems for 10 year olds In-Reply-To: <4CCF3595.2060102@v.loewis.de> References: <4CCF3595.2060102@v.loewis.de> Message-ID: On 11/1/2010 2:48 PM Martin v. Loewis said... >> My niece is interested in programming and python looks like a good >> choice (she already wrote a couple of lines :)) She is 10 and I >> thought it would be good to have a bunch of playful coding problems >> for her, stuff that she could code herself maybe after some initial >> help. > > I think anything that has to do with drawing and colors will be > attractive, animated if possible. It has to look nice. > > Take a look at the turtle demos. > Six or eight years ago when my kids were about that age I got them to play around with pygame, but frankly, I had more success getting them to read html and identify cut n paste-able fragments to put in their myspaceface places. Emile From exarkun at twistedmatrix.com Mon Nov 1 18:43:23 2010 From: exarkun at twistedmatrix.com (exarkun at twistedmatrix.com) Date: Mon, 01 Nov 2010 22:43:23 -0000 Subject: [ANN] pyOpenSSL 0.11 released Message-ID: <20101101224323.2040.732989284.divmod.xquotient.500@localhost.localdomain> Hello all, I'm happy to announce the release of pyOpenSSL 0.11. The primary change from the last release is that Python 3.2 is now supported. Python 2.4 through Python 2.7 are still supported as well. This release also fixes a handful of bugs in error handling code. It also adds APIs for generating and verifying cryptographic signatures and it improves the test suite to cover nearly 80% of the implementation. Downloads and more details about the release can be found on the release page: https://launchpad.net/pyopenssl/main/0.11 Enjoy, Jean-Paul From dalist0 at gmail.com Mon Nov 1 18:44:01 2010 From: dalist0 at gmail.com (Daniel) Date: Mon, 1 Nov 2010 15:44:01 -0700 (PDT) Subject: extracting variables accessed and written from function / rule-based function calls Message-ID: <0d74ca46-657c-41cc-a582-0d78f11350a3@30g2000yql.googlegroups.com> Hello, I have a class with some members that depend on others. Initially most of them are None. For each one there is a function to calculate it as soon as some other dependencies become available. In the end, all values can be computed by the right sequence of function applications. class A: def __init__(self): self.a = None self.b = None self.c = none def f1(self): # compute a given b and c self.a = 2*self.b + math.sin(self.c) Now I am looking for a way to call these functions only when the preconditions are met (in this case b and c are not None) and when the result is needed (a is None). I could wrap each function in a class like this: class rule_a_from_b_and_c: def __init__(self, parent): self.parent = parent def pre(self): return self.parent.b is not None and self.parent.c is not None def needed(self): return self.parent.a is None def rule(self): self.parent.a = 2*self.parent.b + math.sin(self.parent.c) This way I have to replicate the inputs an the output of the function for each rule, which is a lot of work. Is there a way to access the values read by the function and written to by the function f? Like values _read(f) returns (self.b, self.c), values_written(f) returns (self.a,) Dan From ben+python at benfinney.id.au Mon Nov 1 18:46:03 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 02 Nov 2010 09:46:03 +1100 Subject: [Beginer Question] I heard about python needing somesort of_VariableName_ boiler plate? References: <878w1dlk81.fsf@benfinney.id.au> <4CCEF9E2.2000803@mrabarnett.plus.com> Message-ID: <87zktsk6hg.fsf@benfinney.id.au> bradenf at hotmail.com writes: > Sorry that is what I mean. What is it for? Branden, you're welcome to ask questions about Python here. But please, help us help you: Don't top-post. It makes the flow of conversation difficult to follow. Instead, respond in-line beneath the point you're responding to, and remove extraneous quoted material that you're not responding to (this message is an example). That way, references like ?that is what I mean? make a whole lot more sense. > Sent wirelessly from my BlackBerry. If you are using a mail client that spams us with its advertising, and makes normal message composition difficult, then please don't; instead compose your messages using a better mail client. Hope that helps, and good hunting to you as you learn Python :-) -- \ ?What if the Hokey Pokey IS what it's all about?? ?anonymous | `\ | _o__) | Ben Finney From ppearson at nowhere.invalid Mon Nov 1 18:48:16 2010 From: ppearson at nowhere.invalid (Peter Pearson) Date: 1 Nov 2010 22:48:16 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: <8j8udgFlkvU1@mid.individual.net> On Mon, 1 Nov 2010 22:24:03 +0000 (UTC), Grant Edwards wrote: > On 2010-11-01, Lawrence D'Oliveiro wrote: >> In message <8j8am4Fk2jU1 at mid.individual.net>, Peter Pearson wrote: >>> >>>> diff -b oldfile newfile >>> >>> Warning: "diff -b" won't detect changes in indentation. Changes in >>> indentation can change a Python program. >> >> I'm getting less and less keen on that particular feature of Python... > > Why? > > Other languages have similar problems if you remove salient bits of > syntax before comparing two source files files. > > For exmaple, if you remove all of the curly-braces from two C source > files before comparing them, you don't get useful results. True, but diff doesn't come with an "ignore curly braces" option. I'm not personally repelled by Python's use of significant indentation, but I must concede that some awkwardness results from assigning significance to something (whitespace) that many tools are inclined to treat as insignificant. -- To email me, substitute nowhere->spamcop, invalid->net. From gherron at digipen.edu Mon Nov 1 19:17:37 2010 From: gherron at digipen.edu (Gary Herron) Date: Mon, 01 Nov 2010 16:17:37 -0700 Subject: playful coding problems for 10 year olds In-Reply-To: References: Message-ID: <4CCF4A91.3070007@digipen.edu> On 11/01/2010 01:31 PM, Daniel Fetchinson wrote: > Hi folks, > > My niece is interested in programming and python looks like a good > choice (she already wrote a couple of lines :)) She is 10 and I > thought it would be good to have a bunch of playful coding problems > for her, stuff that she could code herself maybe after some initial > help. > > Do you guys know problems like these? Or a good resource where to look them up? > > Cheers, > Daniel > > Does she like robots? My kid's school started a program last year (for 5th and 6th graders) that taught some Python programming in the guise of controlling a small robot. The programs was created by Institute for Personal Robots in Education (IPRE) at http://wiki.roboteducation.org/Main_Page. The hardware is the scribbler robot (http://wiki.roboteducation.org/Myro_Hardware) controlled via a bluetooth connection. It has the ability to move forward/backward at varying speeds and turn radii, dragging a pen for drawing if you wish. It has IR and light sensors, and a camera. It also has several programmable LEDs, and can play music and make beeps. The software is a Python library called Myro (http://wiki.roboteducation.org/Myro_Reference_Manual) that allows to control the scribbler interactively (through Idle) or via written/save Python files. By the end of one semester, (some of) the kids were able to program small Python loops and a few if statements based on sensor values for object avoidance or light following and such. Great fun (and a bit of Python programming) was had by all. -- Gary Herron, PhD. Department of Computer Science DigiPen Institute of Technology (425) 895-4418 From emile at fenx.com Mon Nov 1 19:18:20 2010 From: emile at fenx.com (Emile van Sebille) Date: Mon, 01 Nov 2010 16:18:20 -0700 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: On 11/1/2010 3:18 PM Lawrence D'Oliveiro said... > In message<8j8am4Fk2jU1 at mid.individual.net>, Peter Pearson wrote: >> Warning: "diff -b" won't detect changes in indentation. Changes in >> indentation can change a Python program. > > I?m getting less and less keen on that particular feature of Python... That feature being indentation based structure? At least you can look at python code and _know_ that spurious placement of required line noise don't have the ability to impact what the code does. Emile From ldo at geek-central.gen.new_zealand Mon Nov 1 19:22:41 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 02 Nov 2010 12:22:41 +1300 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: In message , Emile van Sebille wrote: > At least you can look at python code and _know_ that spurious placement of > required line noise don't have the ability to impact what the code does. But it does. What is spurious whitespace if not noise, after all? From python at mrabarnett.plus.com Mon Nov 1 19:23:47 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 01 Nov 2010 23:23:47 +0000 Subject: extracting variables accessed and written from function / rule-based function calls In-Reply-To: <0d74ca46-657c-41cc-a582-0d78f11350a3@30g2000yql.googlegroups.com> References: <0d74ca46-657c-41cc-a582-0d78f11350a3@30g2000yql.googlegroups.com> Message-ID: <4CCF4C03.2020203@mrabarnett.plus.com> On 01/11/2010 22:44, Daniel wrote: > Hello, > > > I have a class with some members that depend on others. Initially most > of them are None. > For each one there is a function to calculate it as soon as some other > dependencies become available. > In the end, all values can be computed by the right sequence of > function applications. > > class A: > def __init__(self): > self.a = None > self.b = None > self.c = none > > def f1(self): # compute a given b and c > self.a = 2*self.b + math.sin(self.c) > > Now I am looking for a way to call these functions only when the > preconditions are met (in this case b and c are not None) and when the > result is needed (a is None). > I could wrap each function in a class like this: > class rule_a_from_b_and_c: > def __init__(self, parent): self.parent = parent > def pre(self): return self.parent.b is not None and self.parent.c > is not None > def needed(self): return self.parent.a is None > def rule(self): self.parent.a = 2*self.parent.b + > math.sin(self.parent.c) > > This way I have to replicate the inputs an the output of the function > for each rule, which is a lot of work. > Is there a way to access the values read by the function and written > to by the function f? > Like values _read(f) returns (self.b, self.c), values_written(f) > returns (self.a,) > You might be interested by the story of how AstraZeneca tackled that kind of problem in PyDrone: http://www.python.org/about/success/astra/ From ldo at geek-central.gen.new_zealand Mon Nov 1 19:24:12 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 02 Nov 2010 12:24:12 +1300 Subject: how to sync file on client and server References: Message-ID: In message , nu wrote: > I want to sync the file foder in different server,and I can't use ftp > protocl. > I try to sync files during defferent server and not use username and > password to login. Set up an SSH public/private key pair. Then run Rsync over SSH. Job done. From ldo at geek-central.gen.new_zealand Mon Nov 1 19:30:39 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 02 Nov 2010 12:30:39 +1300 Subject: import ImageGrab fails on Ubuntu 10.04 References: <4ccd9394$0$4326$426a74cc@news.free.fr> <4ccd954f$0$12350$426a74cc@news.free.fr> Message-ID: In message <4ccd954f$0$12350$426a74cc at news.free.fr>, News123 wrote: > Is there any other way to make screen shots in Linux, ideally without > creating an intermediate file The ImageMagick ?import? command lets you grab the contents of any window (including the root window) from your X server . It wants an output filename, but of course that can be /dev/stdout, e.g. import -window root /dev/stdout | display From ian.g.kelly at gmail.com Mon Nov 1 19:37:55 2010 From: ian.g.kelly at gmail.com (Ian) Date: Mon, 1 Nov 2010 16:37:55 -0700 (PDT) Subject: serial I/O install fail -- DLL not found References: Message-ID: <59d3eeea-3776-479e-b754-04e188f9be07@u17g2000yqi.googlegroups.com> On Nov 1, 3:55?pm, Fossil wrote: > Just starting with Python. > Installed: > ? Python 2.7 > ? pywin32-214.win32-py2.7.exe > ? pyserial-2.5.win32.exe > on a Home WinXP SP3 Toshiba laptop with 2GB memory. ?Open Python and > try to do simple I/O test and can't even get past first line. > Transcript below. ?You will see that > __name__ is defined as '__main__" > but path is not defined. ?Could this be due to creating the folder > holding the Python.exe being on the E: drive or for some other obscure > reason? ?The DOS path environmental variable includes: > e:\Program Files\Python27 Unlikely. Where I work we run Python with pywin32 across the company from a network drive and don't have any problems like this one. > **********transcript************* > > Python 2.7 (r27:82525, Jul ?4 2010, 09:01:59) [MSC v.1500 32 bit > (Intel)] on win > 32 > Type "help", "copyright", "credits" or "license" for more information.>>> from uspp import * > > Traceback (most recent call last): > ? File "", line 1, in > ? File "E:\Python27\lib\uspp.py", line 189, in > ? ? from SerialPort_win import * > ? File "E:\Python27\lib\SerialPort_win.py", line 54, in > ? ? from win32file import * > ? File "E:\Python27\lib\win32file.py", line 12, in > ? ? __load() > ? File "E:\Python27\lib\win32file.py", line 10, in __load > ? ? mod = imp.load_dynamic(__name__, path) > ImportError: DLL load failed: The specified module could not be found. The paths in this traceback are weird. If E:\Python27 is where Python is installed, E:\Python27\lib should be where the files in the Python standard library reside. Installed third-party modules such as the ones above should be located in E:\Python27\lib\site-packages. It would appear that some zip files were incorrectly extracted into this folder. Anyway, your problem appears to be the win32file.py in E: \Python27\lib. This is a wrapper file that the isapi package includes when creating an executable with py2exe. It doesn't make any sense for it to be found in this location, and all it's succeeding in doing is obscuring the real win32file import, which should be a dll at E: \Python27\lib\site-packages\win32\win32file.pyd. I suggest reinstalling, putting things into their proper directories this time, and skipping whatever you unzipped that got you that win32file.py file. Hope this helps, Ian From prologic at shortcircuit.net.au Mon Nov 1 19:38:47 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Tue, 2 Nov 2010 09:38:47 +1000 Subject: extracting variables accessed and written from function / rule-based function calls In-Reply-To: <4CCF4C03.2020203@mrabarnett.plus.com> References: <0d74ca46-657c-41cc-a582-0d78f11350a3@30g2000yql.googlegroups.com> <4CCF4C03.2020203@mrabarnett.plus.com> Message-ID: On Tue, Nov 2, 2010 at 9:23 AM, MRAB wrote: > You might be interested by the story of how AstraZeneca tackled that > kind of problem in PyDrone: http://www.python.org/about/success/astra/ This might be a good use-case (if I'm reading the post correctly) for "Traits" (1) cheers James 1. http://pypi.python.org/pypi/Traits/3.5.0 -- -- James Mills -- -- "Problems are solved by method" From clp2 at rebertia.com Mon Nov 1 19:42:41 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 1 Nov 2010 16:42:41 -0700 Subject: Allowing comments after the line continuation backslash In-Reply-To: References: <4CCE6FF6.2050408@v.loewis.de> Message-ID: On Mon, Nov 1, 2010 at 3:16 PM, Lawrence D'Oliveiro wrote: > In message <4CCE6FF6.2050408 at v.loewis.de>, Martin v. Loewis wrote: > >> (in fact, I can't think any situation where I would use the backslash). > > ? ?for \ > ? ? ? ?Description, Attr, ColorList \ > ? ?in \ > ? ? ? ?( > ? ? ? ? ? ?("normal", "image", MainWindow.ColorsNormalList), > ? ? ? ? ? ?("highlighted", "highlight", MainWindow.ColorsHighlightedList), > ? ? ? ? ? ?("selected", "select", MainWindow.ColorsSelectedList), > ? ? ? ?) \ > ? ?: > ? ? ? ... > ? ?#end for > > I find the level of deviation from PEP 8 in that file rather disturbing. In any case, the backslashes are easily avoided, and readability improved IMHO, via refactoring: desc_attr_colors_triples = (("normal", "image", MainWindow.ColorsNormalList), ("highlighted", "highlight", MainWindow.ColorsHighlightedList), ("selected", "select", MainWindow.ColorsSelectedList)) for in description, attr, color_list in desc_attr_colors_triples: ... Cheers, Chris -- http://blog.rebertia.com From ian.g.kelly at gmail.com Mon Nov 1 19:54:20 2010 From: ian.g.kelly at gmail.com (Ian) Date: Mon, 1 Nov 2010 16:54:20 -0700 (PDT) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <8j8udgFlkvU1@mid.individual.net> Message-ID: <0c3f009d-631f-4e39-9c0f-99628566d794@s5g2000yqm.googlegroups.com> On Nov 1, 4:48?pm, Peter Pearson wrote: > True, but diff doesn't come with an "ignore curly braces" option. > I'm not personally repelled by Python's use of significant indentation, > but I must concede that some awkwardness results from assigning > significance to something (whitespace) that many tools are inclined > to treat as insignificant. Beyond Compare at least is smart enough to know that leading whitespace is significant in .py files, using the default configuration. Cheers, Ian From python at mrabarnett.plus.com Mon Nov 1 20:15:14 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 02 Nov 2010 00:15:14 +0000 Subject: extracting variables accessed and written from function / rule-based function calls In-Reply-To: References: <0d74ca46-657c-41cc-a582-0d78f11350a3@30g2000yql.googlegroups.com> <4CCF4C03.2020203@mrabarnett.plus.com> Message-ID: <4CCF5812.40007@mrabarnett.plus.com> On 01/11/2010 23:38, James Mills wrote: > On Tue, Nov 2, 2010 at 9:23 AM, MRAB wrote: >> You might be interested by the story of how AstraZeneca tackled that >> kind of problem in PyDrone: http://www.python.org/about/success/astra/ > > This might be a good use-case (if I'm reading the post correctly) for > "Traits" (1) > > cheers > James > > 1. http://pypi.python.org/pypi/Traits/3.5.0 > There's a difference between "Traits" and what PyDrone does. In Traits, when a value changes, it notifies other values which depend on it. In PyDrone, there are constants, some of which depend on other constants and need to be calculated. When a value is first requested it is calculated, which might trigger the calculation of other values if it's the first time that they've been requested, so no calculation (work) is done until it's needed. From mskcrpttnrmt at gmail.com Mon Nov 1 20:44:58 2010 From: mskcrpttnrmt at gmail.com (Fossil) Date: Mon, 1 Nov 2010 17:44:58 -0700 (PDT) Subject: serial I/O install fail -- DLL not found References: <59d3eeea-3776-479e-b754-04e188f9be07@u17g2000yqi.googlegroups.com> Message-ID: Thank you, Ian. You put your finger on the problem. As I thrashed around earlier, I had installed serial i/o pieces before the clean install pieces of pywin32-214.win32-py2.7.exe pyserial-2.5.win32.exe I did a complete de-install and re-install. Now the serial i/o is functioning -- I'm still stumbling along with the typical mistakes of a 'newbie'. Thanks again. Chas. From lightsilver3 at gmail.com Mon Nov 1 21:10:36 2010 From: lightsilver3 at gmail.com (silver light) Date: Mon, 1 Nov 2010 18:10:36 -0700 (PDT) Subject: *** FBI gets a warm welcome in Chicago for their EXCELLENT performance - cheers to NEW CONS *** Message-ID: <26f97f70-9043-490c-9e6e-35159f38d76b@r29g2000yqj.googlegroups.com> *** FBI gets a warm welcome in Chicago for their EXCELLENT performance - cheers to NEW CONS *** http://www.youtube.com/watch?v=eq2ZvSd-z0M&feature=player_embedded&related http://www.youtube.com/watch?v=eq2ZvSd-z0M&feature=player_embedded&related http://www.youtube.com/watch?v=eq2ZvSd-z0M&feature=player_embedded&related http://www.youtube.com/watch?v=eq2ZvSd-z0M&feature=player_embedded&related http://www.youtube.com/watch?v=eq2ZvSd-z0M&feature=player_embedded&related From glyph at twistedmatrix.com Mon Nov 1 21:15:22 2010 From: glyph at twistedmatrix.com (Glyph Lefkowitz) Date: Mon, 1 Nov 2010 21:15:22 -0400 Subject: [pyOpenSSL] [ANN] pyOpenSSL 0.11 released In-Reply-To: <20101101224323.2040.732989284.divmod.xquotient.500@localhost.localdomain> References: <20101101224323.2040.732989284.divmod.xquotient.500@localhost.localdomain> Message-ID: On Nov 1, 2010, at 6:43 PM, exarkun at twistedmatrix.com wrote: > I'm happy to announce the release of pyOpenSSL 0.11. Congratulations, JP! It's great to see this effort coming together. -------------- next part -------------- An HTML attachment was scrubbed... URL: From brf256 at gmail.com Mon Nov 1 21:21:56 2010 From: brf256 at gmail.com (brf256 at gmail.com) Date: Tue, 2 Nov 2010 01:21:56 +0000 Subject: *** FBI gets a warm welcome in Chicago for their EXCELLENTperformance - cheers to NEW CONS *** In-Reply-To: <26f97f70-9043-490c-9e6e-35159f38d76b@r29g2000yqj.googlegroups.com> References: <26f97f70-9043-490c-9e6e-35159f38d76b@r29g2000yqj.googlegroups.com> Message-ID: <787900953-1288660917-cardhu_decombobulator_blackberry.rim.net-361156004-@bda480.bisx.prod.on.blackberry> How exactly does this relate to python? Sent wirelessly from my BlackBerry device on the Bell network. Envoy? sans fil par mon terminal mobile BlackBerry sur le r?seau de Bell. -----Original Message----- From: silver light Sender: python-list-bounces+brf256=gmail.com at python.org Date: Mon, 1 Nov 2010 18:10:36 To: Cc: Subject: *** FBI gets a warm welcome in Chicago for their EXCELLENT performance - cheers to NEW CONS *** *** FBI gets a warm welcome in Chicago for their EXCELLENT performance - cheers to NEW CONS *** http://www.youtube.com/watch?v=eq2ZvSd-z0M&feature=player_embedded&related http://www.youtube.com/watch?v=eq2ZvSd-z0M&feature=player_embedded&related http://www.youtube.com/watch?v=eq2ZvSd-z0M&feature=player_embedded&related http://www.youtube.com/watch?v=eq2ZvSd-z0M&feature=player_embedded&related http://www.youtube.com/watch?v=eq2ZvSd-z0M&feature=player_embedded&related -- http://mail.python.org/mailman/listinfo/python-list From clp2 at rebertia.com Mon Nov 1 21:35:12 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 1 Nov 2010 18:35:12 -0700 Subject: *** FBI gets a warm welcome in Chicago for their EXCELLENTperformance - cheers to NEW CONS *** In-Reply-To: <787900953-1288660917-cardhu_decombobulator_blackberry.rim.net-361156004-@bda480.bisx.prod.on.blackberry> References: <26f97f70-9043-490c-9e6e-35159f38d76b@r29g2000yqj.googlegroups.com> <787900953-1288660917-cardhu_decombobulator_blackberry.rim.net-361156004-@bda480.bisx.prod.on.blackberry> Message-ID: > -----Original Message----- > From: silver light > Sender: python-list-bounces+brf256=gmail.com at python.org > Date: Mon, 1 Nov 2010 18:10:36 > To: > Cc: > Subject: *** FBI gets a warm welcome in Chicago for their EXCELLENT > ? ? ? ?performance - cheers to NEW CONS *** > > *** FBI gets a warm welcome in Chicago for their EXCELLENT performance > - cheers to NEW CONS *** On Mon, Nov 1, 2010 at 6:21 PM, wrote: > How exactly does this relate to python? It doesn't. It's spam that was apparently also cross-posted to sci.math, sci.physics, comp.text.tex, and comp.unix.shell. I advise reporting the sender, lightsilver3 at gmail.com, to Gmail's abuse team: http://mail.google.com/support/bin/request.py?contact_type=abuse Cheers, Chris From wuwei23 at gmail.com Mon Nov 1 22:00:00 2010 From: wuwei23 at gmail.com (alex23) Date: Mon, 1 Nov 2010 19:00:00 -0700 (PDT) Subject: Allow multiline conditions and the like References: <4cce7196$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: Chris Rebert wrote: > Or, if possible, refactor the conditional into a function (call) so > it's no longer multiline in the first place. Or even simpler, assign the condition result to a variable: a_b_positive = a > 0 and b > 0 if a_b_positive: ... From ldo at geek-central.gen.new_zealand Mon Nov 1 23:15:03 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 02 Nov 2010 16:15:03 +1300 Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> Message-ID: In message , Chris Rebert wrote: > desc_attr_colors_triples = (("normal", "image", > MainWindow.ColorsNormalList), > ("highlighted", "highlight", MainWindow.ColorsHighlightedList), > ("selected", "select", MainWindow.ColorsSelectedList)) > for in description, attr, color_list in desc_attr_colors_triples: > ... And so you have managed to separate one set of looping conditions into two parts. What is the significance of the name ?desc_attr_colors_triples?? None at all. What purpose does it serve? None, really. Does it ease the maintenance burden? No, but by splitting your attention across two places, it actually adds to it. If this is all your PEP-8 can achieve, then a pox on it. From ldo at geek-central.gen.new_zealand Mon Nov 1 23:18:09 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 02 Nov 2010 16:18:09 +1300 Subject: serial I/O install fail -- DLL not found References: <59d3eeea-3776-479e-b754-04e188f9be07@u17g2000yqi.googlegroups.com> Message-ID: In message , Fossil wrote: > I did a complete de-install and re-install. Standard solution to Dimdows problems, really... From smallpox911 at gmail.com Mon Nov 1 23:18:28 2010 From: smallpox911 at gmail.com (small Pox) Date: Mon, 1 Nov 2010 20:18:28 -0700 (PDT) Subject: *** FBI gets a warm welcome in Chicago for their EXCELLENTperformance - cheers to NEW CONS *** References: <26f97f70-9043-490c-9e6e-35159f38d76b@r29g2000yqj.googlegroups.com> <787900953-1288660917-cardhu_decombobulator_blackberry.rim.net-361156004-@bda480.bisx.prod.on.blackberry> Message-ID: <4d568ef3-e637-4408-9e02-818faaf440c3@r14g2000yqa.googlegroups.com> On Nov 1, 6:35?pm, Chris Rebert wrote: > > -----Original Message----- > > From: silver light > > Sender: python-list-bounces+brf256=gmail.... at python.org > > Date: Mon, 1 Nov 2010 18:10:36 > > To: > > Cc: > > Subject: *** FBI gets a warm welcome in Chicago for their EXCELLENT > > ? ? ? ?performance - cheers to NEW CONS *** > > > *** FBI gets a warm welcome in Chicago for their EXCELLENT performance > > - cheers to NEW CONS *** > > > > On Mon, Nov 1, 2010 at 6:21 PM, ? wrote: > > How exactly does this relate to python? > > It doesn't. It's spam that was apparently also cross-posted to > sci.math, sci.physics, comp.text.tex, and comp.unix.shell. IT IS MOST CERTAINLY NOTTTTTT a SPAM. THIS FBI CENSORSHIP MOTHER FOCKER is the REAL SPAMMER AND CRIMINAL who wants to limit the news of their HEINOUS CRIMES and INCOMPETENCE to be SPREAD. The fact is that the real spammers are those who post PORNOGRAPHIC and COMMERCIAL messages on which the FBI CIA BLACKWATER and MOSSAD mother fockers masterbate and rape their mothers daily. AND NEVER SPEAK OUT. The truth of 911 bites them like the sting of a snake and truth it is. > I advise reporting the sender, lightsilv... at gmail.com, to Gmail's abuse team:http://mail.google.com/support/bin/request.py?contact_type=abuse > > Cheers, > Chris From ldo at geek-central.gen.new_zealand Mon Nov 1 23:21:42 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 02 Nov 2010 16:21:42 +1300 Subject: factorial of negative one (-1) References: <87r5f55qj5.fsf@xemacs.org> Message-ID: In message <87r5f55qj5.fsf at xemacs.org>, Hrvoje Niksic wrote: > Python has a little-known but very instructive method for determining the > makeup of a float: > >>>> 1.1 .as_integer_ratio() > (2476979795053773, 2251799813685248) Only available in 2.6 or later. Are we already talking as though 2.5 doesn?t exist any more? I still have client machines running that (Debian Stable 5.0). :) From ldo at geek-central.gen.new_zealand Mon Nov 1 23:26:46 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 02 Nov 2010 16:26:46 +1300 Subject: ANN: PyQt v4.8.1 Released References: Message-ID: In message , Phil Thompson wrote: > PyQt is available under the GPL and a commercial license. Surely you mean ?proprietary? rather than ?commercial?. There is nothing about the GPL that prevents ?commercial? use. From ldo at geek-central.gen.new_zealand Mon Nov 1 23:30:40 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 02 Nov 2010 16:30:40 +1300 Subject: functions, list, default parameters References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <20101021235138.609fe668@geekmail.INVALID> Message-ID: In message <20101021235138.609fe668 at geekmail.INVALID>, Andreas Waldenburger wrote: > While not very commonly needed, why should a shared default argument be > forbidden? Because it?s safer to disallow it than to allow it. From ldo at geek-central.gen.new_zealand Mon Nov 1 23:31:18 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 02 Nov 2010 16:31:18 +1300 Subject: functions, list, default parameters References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <8ivelpFif1U1@mid.individual.net> <4cca88bc$0$29987$c3e8da3$5496439d@news.astraweb.com> <8j1seqFa1eU2@mid.individual.net> Message-ID: In message <8j1seqFa1eU2 at mid.individual.net>, Gregory Ewing wrote: > Steven D'Aprano wrote: > >> And how does Python know whether some arbitrary default object is mutable >> or not? > > It doesn't, that's the whole point. Of course it knows. It is the one defining the concept in the first place, after all. From ldo at geek-central.gen.new_zealand Mon Nov 1 23:34:38 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 02 Nov 2010 16:34:38 +1300 Subject: str(int_var) formatted References: <4ccaef45$0$27972$4fafbaef@reader5.news.tin.it> Message-ID: In message , John Yeung wrote: > I will give zfill a little exposure, as it seems unloved/underused: > > str(x).zfill(2) The inside of my brain is a finite place. Each thing I put in there leaves less room for something else. So I have to think very carefully before deciding what to keep in there. Up to this point I have learned to do all this kind of formatting using format strings; is it worth making room in my brain to remember about zfill as well? Somehow, I think not. From python at mrabarnett.plus.com Mon Nov 1 23:58:14 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 02 Nov 2010 03:58:14 +0000 Subject: *** FBI gets a warm welcome in Chicago for their EXCELLENTperformance - cheers to NEW CONS *** In-Reply-To: <4d568ef3-e637-4408-9e02-818faaf440c3@r14g2000yqa.googlegroups.com> References: <26f97f70-9043-490c-9e6e-35159f38d76b@r29g2000yqj.googlegroups.com> <787900953-1288660917-cardhu_decombobulator_blackberry.rim.net-361156004-@bda480.bisx.prod.on.blackberry> <4d568ef3-e637-4408-9e02-818faaf440c3@r14g2000yqa.googlegroups.com> Message-ID: <4CCF8C56.5010409@mrabarnett.plus.com> On 02/11/2010 03:18, small Pox wrote: > On Nov 1, 6:35 pm, Chris Rebert wrote: >>> -----Original Message----- >>> From: silver light >>> Sender: python-list-bounces+brf256=gmail.... at python.org >>> Date: Mon, 1 Nov 2010 18:10:36 >>> To: >>> Cc: >>> Subject: *** FBI gets a warm welcome in Chicago for their EXCELLENT >>> performance - cheers to NEW CONS *** >> >>> *** FBI gets a warm welcome in Chicago for their EXCELLENT performance >>> - cheers to NEW CONS *** >> >> >> >> On Mon, Nov 1, 2010 at 6:21 PM, wrote: >>> How exactly does this relate to python? >> >> It doesn't. It's spam that was apparently also cross-posted to >> sci.math, sci.physics, comp.text.tex, and comp.unix.shell. > > IT IS MOST CERTAINLY NOTTTTTT a SPAM. > [snip] You should look up the definition sometime. From astronautameya at gmail.com Tue Nov 2 00:03:16 2010 From: astronautameya at gmail.com (Ameya the ______) Date: Mon, 1 Nov 2010 21:03:16 -0700 (PDT) Subject: Would you recommend python as a first programming language? References: Message-ID: <19a4eb7e-fe30-4894-966a-586799062239@k22g2000yqh.googlegroups.com> Post this question on the C/C++ group... and do post those replie here :P From robert.kern at gmail.com Tue Nov 2 00:07:00 2010 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 01 Nov 2010 23:07:00 -0500 Subject: functions, list, default parameters In-Reply-To: References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <8ivelpFif1U1@mid.individual.net> <4cca88bc$0$29987$c3e8da3$5496439d@news.astraweb.com> <8j1seqFa1eU2@mid.individual.net> Message-ID: On 2010-11-01 22:31 , Lawrence D'Oliveiro wrote: > In message<8j1seqFa1eU2 at mid.individual.net>, Gregory Ewing wrote: > >> Steven D'Aprano wrote: >> >>> And how does Python know whether some arbitrary default object is mutable >>> or not? >> >> It doesn't, that's the whole point. > > Of course it knows. It is the one defining the concept in the first place, > after all. No, the Python interpreter doesn't define the concept. The Python language developers did. "Immutable objects" are just those without an obvious API for modifying them. With various trickeries, I can mutate any immutable object. The Python interpreter doesn't know what's an "obvious API" and what isn't. It's a reasonably vague concept that doesn't have an algorithmic formulation. -- 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 usenet-nospam at seebs.net Tue Nov 2 00:16:28 2010 From: usenet-nospam at seebs.net (Seebs) Date: 02 Nov 2010 04:16:28 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: On 2010-11-01, Grant Edwards wrote: > On 2010-11-01, Lawrence D'Oliveiro wrote: >> In message <8j8am4Fk2jU1 at mid.individual.net>, Peter Pearson wrote: >>> Warning: "diff -b" won't detect changes in indentation. Changes in >>> indentation can change a Python program. >> I'm getting less and less keen on that particular feature of Python... > Why? > Other languages have similar problems if you remove salient bits of > syntax before comparing two source files files. Sure. > For exmaple, if you remove all of the curly-braces from two C source > files before comparing them, you don't get useful results. Right. But there's no *reason* to do that, while there are many common daily events which result in whitespace changes. e.g., any email sent to my work account is being magically transformed into HTML (no one knows why) on the server, so I can't get correct indentation except in attachments. Many editors helpfully convert spaces to tabs by default some or all of the time. And so on. The more I use it, the more I think it was an interesting experiment which has worked out about as well as scanf. The "problem" it fixes is something that's hardly ever been a problem for me in C or related languages -- and which could be completely eliminated by automated indenters, which were actually conceptually possible. I've lost more time to indentation issues in Python in a month than I've lost to mismatches between indentation and flow in C in twenty years. In theory, it sounds like it would help to eliminate the ambiguity. In practice, eliminating the question of whether code was intended to follow explicit flow rather than indentation just means that when there's a mistake you don't even get a warning that someone was confused. At least in C, if I see: if (foo) a; else b; c; I *know* that something is wrong. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From lanyjie at yahoo.com Tue Nov 2 00:31:12 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Mon, 1 Nov 2010 21:31:12 -0700 (PDT) Subject: Why this result with the re module Message-ID: <853660.45854.qm@web54207.mail.re2.yahoo.com> Hi, I am rather confused by these results below. I am not a re expert at all. the module version of re is 2.2.1 with python 3.1.2 >>> import re >>> re.findall('.a.', 'Mary has a lamb') #OK ['Mar', 'has', ' a ', 'lam'] >>> re.findall('(.a.)*', 'Mary has a lamb') #?? ['Mar', '', '', 'lam', '', ''] >>> re.findall('(.a.)+', 'Mary has a lamb') #?? ['Mar', 'lam'] Thanks in advance for any comments. Yingjie From darcy at druid.net Tue Nov 2 00:40:31 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 2 Nov 2010 00:40:31 -0400 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: <20101102004031.43d99537.darcy@druid.net> On 02 Nov 2010 04:16:28 GMT Seebs wrote: > But there's no *reason* to do that, while there are many common daily > events which result in whitespace changes. e.g., any email sent > to my work account is being magically transformed into HTML (no one > knows why) on the server, so I can't get correct indentation except > in attachments. Many editors helpfully convert spaces to tabs > by default some or all of the time. And so on. You have problems. Indentation as syntax isn't one of them. "No one knows why" email is being "magically" transformed? Your editor has a mind of its own? Yikes! > I've lost more time to indentation issues in Python in a month than > I've lost to mismatches between indentation and flow in C in twenty Your experience is 180 from mine. > years. In theory, it sounds like it would help to eliminate the > ambiguity. In practice, eliminating the question of whether code > was intended to follow explicit flow rather than indentation just > means that when there's a mistake you don't even get a warning that > someone was confused. > > At least in C, if I see: > if (foo) > a; > else > b; > c; > > I *know* that something is wrong. Does it look right? With Python looking right and being right are the same thing. Once I realized that indentation should only be done using spaces in Python I never had a problem. I certainly had problems with C when the code looked right. Sometimes you can't even see the problem because it's hidden in a badly defined macro. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From lists at asd-group.com Tue Nov 2 01:30:59 2010 From: lists at asd-group.com (John Bond) Date: Tue, 02 Nov 2010 05:30:59 +0000 Subject: Why this result with the re module In-Reply-To: <853660.45854.qm@web54207.mail.re2.yahoo.com> References: <853660.45854.qm@web54207.mail.re2.yahoo.com> Message-ID: <4CCFA213.5090209@asd-group.com> On 2/11/2010 4:31 AM, Yingjie Lan wrote: > Hi, I am rather confused by these results below. > I am not a re expert at all. the module version > of re is 2.2.1 with python 3.1.2 > >>>> import re >>>> re.findall('.a.', 'Mary has a lamb') #OK > ['Mar', 'has', ' a ', 'lam'] >>>> re.findall('(.a.)*', 'Mary has a lamb') #?? > ['Mar', '', '', 'lam', '', ''] >>>> re.findall('(.a.)+', 'Mary has a lamb') #?? > ['Mar', 'lam'] > > > Thanks in advance for any comments. > > Yingjie > > > It's because you're using capturing groups, and because of how they work - specifically they only return the LAST match if used with repetition (and multiple matches occur). For example, take the second example and make it non-capturing: re.findall('(?:.a.)+', 'Mary has a lamb') ['Mar', 'has a lam'] That shows you there are two matches: 1) a three character one at the start of the string (matching one occurance of '.a.'), and 2) a 9 character one a bit later in the string (matching three occurances of '.a.') Turn that back into a capturing group: re.findall('(.a.)+', 'Mary has a lamb') ['Mar', 'lam'] You still have the same two matches as before, but in using the capturing group you're telling findall to return its value each time it matches (not what's actually matched overall). That doesn't affect the first result as it matched a single occurance of what's in the group ('Mar'). But the second one matched three occurances of what's in the group ('has', ' a ', and 'lam'), and the nature of capturing groups is that they only return the last match, so the second returned value is now just 'lam'. So - see if you can explain the first "problematic" result now. From mygogo2011 at gmail.com Tue Nov 2 01:31:27 2010 From: mygogo2011 at gmail.com (PHP.CCC) Date: Mon, 1 Nov 2010 22:31:27 -0700 (PDT) Subject: Advance I.T Training 2011 Message-ID: Advance I.T Training 2011 Advance Excel VBA There are lot of erp software in market erp like Peachtree ,tally software ,account software ,medi cal billing ,tax software, financial soft wares or Software for Finance But We bring you a web site which teach you or guide you to developed a good account, of medi cal billing or Tax Software etc, at you own. We all know that microsoft excel give a unique platform in excel 2003 and excel 2007 as spreadsheet on excel which give excellent opportunity to build our own software. Read more >>> http://childschooledu.blogspot.com/ From vinirma2008 at yahoo.com Tue Nov 2 02:03:59 2010 From: vinirma2008 at yahoo.com (VAM SYSTEMS) Date: Mon, 1 Nov 2010 23:03:59 -0700 (PDT) Subject: Urgent :Required for Oracle DBA in Qatar Message-ID: VAM SYSTEMS is a Business Consulting, IT Solutions and Services company with operations in UAE, Qatar, Bahrain, USA, Australia, Singapore & India. VAM SYSTEMS is currently looking for Oracle DBA for our Qatar operations with the following skill set and terms and conditions: Skill Set required: Strong administration experience in Oracle. Banking experience is mandatory. Experience Required: 5+ years. Terms and conditions: Joining time frame: Immediate (maximum 2 weeks) The selected candidates shall join VAM SYSTEMS ? Qatar and shall be deputed to one of the leading banks in Qatar. Should you be interested in this opportunity, please send your latest resume in MS Word format at the earliest at ambili.krishnan at vamsystems.com or call us +91 0476 2680150. From lanyjie at yahoo.com Tue Nov 2 03:00:52 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Tue, 2 Nov 2010 00:00:52 -0700 (PDT) Subject: Why this result with the re module In-Reply-To: <4CCFA213.5090209@asd-group.com> Message-ID: <589172.15864.qm@web54202.mail.re2.yahoo.com> > From: John Bond > Subject: Re: Why this result with the re module > >>>> re.findall('(.a.)*', 'Mary has a lamb') > > ['Mar', '', '', 'lam', '', ''] > So - see if you can explain the first "problematic" result > now. Thanks a lot for explaining to me the second "problematic" result! But the first one is even more puzzling...mainly because the pattern matches any empty string. Here are more examples: >>> re.findall('(.a.)*','') [''] >>> re.findall('(.a.)*',' ') #one space ['', ''] >>> re.findall('(.a.)*',' ') #two spaces ['', '', ''] >>> len(re.findall('(.a.)*',' '*4)) #four 5 >>> len(re.findall('(.a.)*',' '*8)) #eight 9 I must need more details of the matching algorithm to explain this? Regards, Yingjie From lanyjie at yahoo.com Tue Nov 2 03:05:19 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Tue, 2 Nov 2010 00:05:19 -0700 (PDT) Subject: Why this result with the re module In-Reply-To: <4CCFA213.5090209@asd-group.com> Message-ID: <21513.57929.qm@web54203.mail.re2.yahoo.com> > From: John Bond > >>>> re.findall('(.a.)+', 'Mary has a lamb') > > ['Mar', 'lam'] > It's because you're using capturing groups, and because of > how they work - specifically they only return the LAST match > if used with repetition (and multiple matches occur). It seems capturing groups is assumed by default, but this is somehow against my intuition... Ituitively, it should be what matches the whole regex '(.a.)+', shouldn't it? Regards, Yingjie From ldo at geek-central.gen.new_zealand Tue Nov 2 03:07:13 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 02 Nov 2010 20:07:13 +1300 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: In message , Seebs wrote: > At least in C, if I see: > if (foo) > a; > else > b; > c; > > I *know* that something is wrong. This is why, when I started learning Python, I soon developed the habit of inserting explicit ?#end? markers. To Pythonize your example my way, it would have come out as if foo : a else : b #end if c which should also give a hint that something might be wrong. From ldo at geek-central.gen.new_zealand Tue Nov 2 03:12:49 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 02 Nov 2010 20:12:49 +1300 Subject: functions, list, default parameters References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <8ivelpFif1U1@mid.individual.net> <4cca88bc$0$29987$c3e8da3$5496439d@news.astraweb.com> <8j1seqFa1eU2@mid.individual.net> Message-ID: In message , Robert Kern wrote: > On 2010-11-01 22:31 , Lawrence D'Oliveiro wrote: > >> In message<8j1seqFa1eU2 at mid.individual.net>, Gregory Ewing wrote: >> >>> Steven D'Aprano wrote: >>> >>>> And how does Python know whether some arbitrary default object is >>>> mutable or not? >>> >>> It doesn't, that's the whole point. >> >> Of course it knows. It is the one defining the concept in the first >> place, after all. > > No, the Python interpreter doesn't define the concept. The Python language > developers did. The Python language developers said ?let there be light?, and the Python interpreter gave forth light. So which one defines the concept of ?light?? > "Immutable objects" are just those without an obvious API for modifying > them. They are ones with NO legal language constructs for modifying them. Hint: if a selector of some part of such an object were to occur on the LHS of an assignment, and that would raise an error, then the object is immutable. The interpreter already knows all this. > With various trickeries, I can mutate any immutable object. None within the Python language itself. Which is what we?re talking about here: a language construct which is probably one of the top 3 sources of grief to Python newbies. And not-so-newbies. From clp2 at rebertia.com Tue Nov 2 03:40:17 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 2 Nov 2010 00:40:17 -0700 Subject: functions, list, default parameters In-Reply-To: <4cc13ef5$0$29979$c3e8da3$5496439d@news.astraweb.com> References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <4cc13ef5$0$29979$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Oct 22, 2010 at 12:36 AM, Steven D'Aprano wrote: > On Thu, 21 Oct 2010 19:53:53 -0700, John Nagle wrote: >>> This is a common newbie stumbling-block: Don't use lists (or anything >>> mutable) as default argument values >> >> ? ? ?That really should be an error. > > No it shouldn't. Punishing everybody for a newbie mistake that nobody > makes twice would be the error. > > Default mutable arguments have their place But it's a rather obscure one where it is almost never strictly necessary to venture. Cheers, Chris From lists at asd-group.com Tue Nov 2 03:50:35 2010 From: lists at asd-group.com (John Bond) Date: Tue, 02 Nov 2010 07:50:35 +0000 Subject: Why this result with the re module In-Reply-To: <589172.15864.qm@web54202.mail.re2.yahoo.com> References: <589172.15864.qm@web54202.mail.re2.yahoo.com> Message-ID: <4CCFC2CB.2080500@asd-group.com> On 2/11/2010 7:00 AM, Yingjie Lan wrote: >>> re.findall('(.a.)*',' ') #two spaces > ['', '', ''] > I must need more details of the matching algorithm to explain this? > > Regards, > > Yingjie > > > > Sorry - I hit enter prematurely on my last message. To take the above as an example (all your examples boil down to the same issue), you're asking findall to look for all occurances of something that can exist ZERO or more times, in a string where it doesn't actually exist anywhere. So you get three matches of zero occurrences each - one before the first space, one between the two spaces, and one after the last space. An empty string (indicating that the match consumed no text) is returned for each. The spaces themselves don't match because they aren't zero or more occurrences of '.a.', so they are skipped. You might wonder why something that can match no input text, doesn't return an infinite number of those matches at every possible position, but they would be overlapping, and findall explicitly says matches have to be non-overlapping. Cheers, JB From usenet-nospam at seebs.net Tue Nov 2 04:12:18 2010 From: usenet-nospam at seebs.net (Seebs) Date: 02 Nov 2010 08:12:18 GMT Subject: *** FBI gets a warm welcome in Chicago for their EXCELLENTperformance - cheers to NEW CONS *** References: <26f97f70-9043-490c-9e6e-35159f38d76b@r29g2000yqj.googlegroups.com> Message-ID: On 2010-11-02, brf256 at gmail.com wrote: > How exactly does this relate to python? 1. It doesn't. It's spam. Duh. 2. Don't respond to spam. 3. Don't top-post. 4. If I see even one more post from you where the entire previous post is quoted under your text, I will plonk you. I warn you now because most posters will do the same thing, and you will get very lonely once no one bothers to read your posts. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From lanyjie at yahoo.com Tue Nov 2 04:53:17 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Tue, 2 Nov 2010 01:53:17 -0700 (PDT) Subject: Why this result with the re module In-Reply-To: <4CCFC2CB.2080500@asd-group.com> Message-ID: <512575.3904.qm@web54204.mail.re2.yahoo.com> > From: John Bond > You might wonder why something that can match no input > text, doesn't return an infinite number of those matches at > every possible position, but they would be overlapping, and > findall explicitly says matches have to be non-overlapping. That scrabbed my itches, though the notion of overlapping empty strings is quite interesting in itself. Obviously we have to assume there is one and only one empty string between two consecutive characters. Now I slightly modified my regex, and it suddenly looks self-explanatory: >>> re.findall('((.a.)+)', 'Mary has a lamb') [('Mar', 'Mar'), ('has a lam', 'lam')] >>> re.findall('((.a.)*)', 'Mary has a lamb') [('Mar', 'Mar'), ('', ''), ('', ''), ('has a lam', 'lam'), ('', ''), ('', '')] BUT, but. 1. I expected findall to find matches of the whole regex '(.a.)+', not just the subgroup (.a.) from >>> re.findall('(.a.)+', 'Mary has a lamb') Thus it is probably a misunderstanding/bug?? 2. Here is an statement from the documentation on non-capturing groups: see http://docs.python.org/dev/howto/regex.html "Except for the fact that you can?t retrieve the contents of what the group matched, a non-capturing group behaves exactly the same as a capturing group; " Thus, I'm again confused, despite of your previous explanation. This might be a better explanation: when a subgroup is repeated, it only captures the last repetition. 3. It would be convenient to have '(*...)' for non-capturing groups -- but of course, that's only a remote suggestion. 4. By reason of greediness of '*', and the concept of non-overlapping, it should go like this for re.findall('((.a.)*)', 'Mary has a lamb') step 1: Match 'Mar' + '' (gready!) step 2: skip 'y' step 3: Match '' step 4: skip ' ' step 5: Match ''+'has'+' a '+'lam'+'' (greedy!) step 7: skip 'b' step 8: Match '' So there should be 4 matches in total: 'Mar', '', 'has a lam', '' Also, if a repeated subgroup only captures the last repetition, the repeated subgroup (.a.)* should always be ''. Yet the execution in Python results in 6 matches. Here is the documentation of re.findall: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ findall(pattern, string, flags=0) Return a list of all non-overlapping matches in the string. If one or more groups are present in the pattern, return a list of groups; this will be a list of tuples if the pattern has more than one group. Empty matches are included in the result. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Thus from >>> re.findall('(.a.)*', 'Mary has a lamb') I should get this result [('',), ('',), ('',), ('',)] Finally, The name findall implies all matches should be returned, whether there are subgroups in the pattern or not. It might be best to return all the match objects (like a re.match call) instead of the matched strings. Then there is no need to return tuples of subgroups. Even if tuples of subgroups were to be returned, group(0) must also be included in the returned tuple. Regards, Yingjie From johann.spies at gmail.com Tue Nov 2 04:58:24 2010 From: johann.spies at gmail.com (Johann Spies) Date: Tue, 2 Nov 2010 10:58:24 +0200 Subject: Python equivalent of SOAP-ISIWoK Message-ID: SOAP-ISIWoK is a Perl library for assessing Thomson Reuters Web of Knowledge Web Services. I don't know Perl well enough to use that library without spending too much time on it. Is there a Python equivalent available? Regards Johann -- ?May grace and peace be yours in abundance through the full knowledge of God and of Jesus our Lord! ?His divine power has given us everything we need for life and godliness through the full knowledge of the one who called us by his own glory and excellence. ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ?2 Pet. 1:2b,3a From ldo at geek-central.gen.new_zealand Tue Nov 2 05:06:40 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 02 Nov 2010 22:06:40 +1300 Subject: functions, list, default parameters References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <4cc13ef5$0$29979$c3e8da3$5496439d@news.astraweb.com> Message-ID: In message , Chris Rebert wrote: > On Fri, Oct 22, 2010 at 12:36 AM, Steven D'Aprano > wrote: >> >> Default mutable arguments have their place > > But it's a rather obscure one where it is almost never strictly > necessary to venture. Mediocre programmers with a hankering towards cleverness latch onto it as an ingenious way of maintaing persistent context in-between calls to a function, completely overlooking the fact that Python offers much more straightforward, comprehensible, flexible, and above all maintainable ways of doing that sort of thing. From tartley at tartley.com Tue Nov 2 05:19:08 2010 From: tartley at tartley.com (Jonathan Hartley) Date: Tue, 2 Nov 2010 02:19:08 -0700 (PDT) Subject: playful coding problems for 10 year olds References: Message-ID: On Nov 1, 8:31?pm, Daniel Fetchinson wrote: > Hi folks, > > My niece is interested in programming and python looks like a good > choice (she already wrote a couple of lines :)) She is 10 and I > thought it would be good to have a bunch of playful coding problems > for her, stuff that she could code herself maybe after some initial > help. > > Do you guys know problems like these? Or a good resource where to look them up? > > Cheers, > Daniel > > -- > Psss, psss, put it down! -http://www.cafepress.com/putitdown There's a great book valled 'Invent your own computer games using Python', aimed at kids, which teaches programming from tne ground up, in the context of writing games, starting with terminal word games, ending with Pygame fullscreen 2D vector graphic & bitmaps affairs. http://inventwithpython.com/ The website says aimed at kids 'ages 10 to 12 and upwards', so it sounds like she's on the minimum cusp. (now I come to look at the website, one of the quotes he features is from an Amazon review I wrote months ago! :-) From paul at subsignal.org Tue Nov 2 05:37:54 2010 From: paul at subsignal.org (=?UTF-8?B?UGF1bCBLw7ZsbGU=?=) Date: Tue, 02 Nov 2010 10:37:54 +0100 Subject: [Beginer Question] I heard about python needing somesort of_VariableName_ boiler plate? In-Reply-To: <1946543087-1288635527-cardhu_decombobulator_blackberry.rim.net-1324044669-@bda480.bisx.prod.on.blackberry> References: <878w1dlk81.fsf@benfinney.id.au><4CCEF9E2.2000803@mrabarnett.plus.com> <1946543087-1288635527-cardhu_decombobulator_blackberry.rim.net-1324044669-@bda480.bisx.prod.on.blackberry> Message-ID: <4CCFDBF2.4030305@subsignal.org> Its the entry point if the script is executed directly. This message was sent from my 7 years old Dell D800 (without cables) Am 01.11.2010 19:18, schrieb bradenf at hotmail.com: > Sorry that is what I mean. What is it for? > Sent wirelessly from my BlackBerry. > > -----Original Message----- > From: MRAB > Sender: python-list-bounces+bradenf=hotmail.com at python.org > Date: Mon, 01 Nov 2010 17:33:22 > To: > Reply-To: python-list at python.org > Subject: Re: [Beginer Question] I heard about python needing some > sort of_VariableName_ boiler plate? > > On 01/11/2010 04:51, Ben Finney wrote: >> bradenf at hotmail.com writes: >> >>> Sorry, to clarify I heard that when you declare a variable in python >>> you have to use some sort of standard boiler plate _variable_ however >>> this has not been my experience using IDLE so is this even true? >> >> I don't know what ?some sort of boiler plate _variable_? might mean. >> >> Can you point to someone's actual message saying this, so we can see >> what they might be talking about? >> > Perhaps the OP means: > > if __name__ == "__main__": > ... > > although the "declare a variable" bit has me puzzled. From paul at subsignal.org Tue Nov 2 05:37:54 2010 From: paul at subsignal.org (=?UTF-8?B?UGF1bCBLw7ZsbGU=?=) Date: Tue, 02 Nov 2010 10:37:54 +0100 Subject: [Beginer Question] I heard about python needing somesort of_VariableName_ boiler plate? In-Reply-To: <1946543087-1288635527-cardhu_decombobulator_blackberry.rim.net-1324044669-@bda480.bisx.prod.on.blackberry> References: <878w1dlk81.fsf@benfinney.id.au><4CCEF9E2.2000803@mrabarnett.plus.com> <1946543087-1288635527-cardhu_decombobulator_blackberry.rim.net-1324044669-@bda480.bisx.prod.on.blackberry> Message-ID: <4CCFDBF2.4030305@subsignal.org> Its the entry point if the script is executed directly. This message was sent from my 7 years old Dell D800 (without cables) Am 01.11.2010 19:18, schrieb bradenf at hotmail.com: > Sorry that is what I mean. What is it for? > Sent wirelessly from my BlackBerry. > > -----Original Message----- > From: MRAB > Sender: python-list-bounces+bradenf=hotmail.com at python.org > Date: Mon, 01 Nov 2010 17:33:22 > To: > Reply-To: python-list at python.org > Subject: Re: [Beginer Question] I heard about python needing some > sort of_VariableName_ boiler plate? > > On 01/11/2010 04:51, Ben Finney wrote: >> bradenf at hotmail.com writes: >> >>> Sorry, to clarify I heard that when you declare a variable in python >>> you have to use some sort of standard boiler plate _variable_ however >>> this has not been my experience using IDLE so is this even true? >> >> I don't know what ?some sort of boiler plate _variable_? might mean. >> >> Can you point to someone's actual message saying this, so we can see >> what they might be talking about? >> > Perhaps the OP means: > > if __name__ == "__main__": > ... > > although the "declare a variable" bit has me puzzled. From hniksic at xemacs.org Tue Nov 2 06:11:52 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Tue, 02 Nov 2010 11:11:52 +0100 Subject: factorial of negative one (-1) References: <87r5f55qj5.fsf@xemacs.org> Message-ID: <87vd4gm3vb.fsf@xemacs.org> Ken Watford writes: >>>>> 1.1 .as_integer_ratio() >> (2476979795053773, 2251799813685248) > > Handy, but if you need the exact representation, my preference is > float.hex, which seems to be the same as C99's %a format. [...] > Granted, it's not as easy for humans to interpret, but it's useful for > certain things. Since it's used by both C99 and Java, supporting it is a nice interoperability feature: http://download.oracle.com/javase/6/docs/api/java/lang/Double.html#toHexString(double) In fact, the float output provides educational insight of its own because it shows rounding effects without the apparent "garbage digits" syndrome: >>> 1.1 .hex() '0x1.199999999999ap+0' Here it is immediately obvious that the final digit of the infinite sequence "1.1999..." is rounded from 9 to a. Printing the number with any more digits would just reveal zeros, as expected. Does anyone know why Python doesn't accept hex float literals in source code? From lists at asd-group.com Tue Nov 2 06:23:10 2010 From: lists at asd-group.com (John Bond) Date: Tue, 02 Nov 2010 10:23:10 +0000 Subject: Why this result with the re module In-Reply-To: <512575.3904.qm@web54204.mail.re2.yahoo.com> References: <512575.3904.qm@web54204.mail.re2.yahoo.com> Message-ID: <4CCFE68E.4070208@asd-group.com> On 2/11/2010 8:53 AM, Yingjie Lan wrote: > > BUT, but. > > 1. I expected findall to find matches of the whole > regex '(.a.)+', not just the subgroup (.a.) from >>>> re.findall('(.a.)+', 'Mary has a lamb') > Thus it is probably a misunderstanding/bug?? Again, as soon as you put a capturing group in your expression, you change the nature of what findall returns as described in the documentation. It then returns what gets assigned to each capturing group, not what chunk of text was matched by the whole expression at each matching point in the string. A capturing group returns what was matched by the regex fregment *inside it*. If you put repetition *outside it* (as you have - "(.a.)*+*") that doesn't change but, if the repetition clause results in it being matched multiple times, only the last match is returned as the capturing groups single, only allowed return value. I find that strange, and limiting (why not return a list of all matches caused by the repetition?) but that's the way it is. Have you read the "Regular Exp[ression HOWTO" in the docs? It explains all this stuff. > 2. Here is an statement from the documentation on > non-capturing groups: > see http://docs.python.org/dev/howto/regex.html > > "Except for the fact that you can?t retrieve the > contents of what the group matched, a non-capturing > group behaves exactly the same as a capturing group; " In terms of how the regular expression works when matching text, which is what the above is addressing, that's true. In terms of how the results are returned to API callers, it isn't true. > Thus, I'm again confused, despite of your > previous explanation. This might be a better > explanation: when a subgroup is repeated, it > only captures the last repetition. That's true, but it's not related to the above. > 3. It would be convenient to have '(*...)' for > non-capturing groups -- but of course, that's > only a remote suggestion. Fair enough - each to their own preferences. > 4. By reason of greediness of '*', and the concept > of non-overlapping, it should go like this for > re.findall('((.a.)*)', 'Mary has a lamb') > > step 1: Match 'Mar' + '' (gready!) > step 2: skip 'y' > step 3: Match '' > step 4: skip ' ' > step 5: Match ''+'has'+' a '+'lam'+'' (greedy!) > step 7: skip 'b' > step 8: Match '' > > So there should be 4 matches in total: > > 'Mar', '', 'has a lam', '' > > Also, if a repeated subgroup only captures > the last repetition, the repeated > subgroup (.a.)* should always be ''. > > Yet the execution in Python results in 6 matches. > > ..... All you have done is wrapped one of your earlier regexes, '*(*.a.*)**' in another, outer capturing group, to make '*(*(.a.)**)*'. This doesn't change what is actually matched, so there are still the same six matches found. However it does change what is *returned *- you now have two capturing groups that findall has to return information about (at each match), so you will see that it returns 6 tuples (each with two items - one for each capturing group) instead of six strings, ie: re.findall('(.a.)*', 'Mary has a lamb') ['Mar', '', '', 'lam', '', ''] becomes: re.findall('((.a.)*)', 'Mary has a lamb') [('Mar', 'Mar'), ('', ''), ('', ''), ('has a lam', 'lam'), ('', ''), ('', '')] As you can see, the top set of results appear in the bottom set (in the second item in each tuple, because the original capturing group is the second one now - the new, outer one is the first). If you look at the fourth tuple, ('has a lam', 'lam'), you can see the "capturing group with repetition only returns the last match" rule in action. The inner capturing group (which has repetition) returns 'lam' because that was the last occurrence of ".a." in the three ("has", " a ", "lam") that it matched that time. However the outer capturing group, which doesn't have repetition, returns the whole thing ('has a lam'). > Finally, The name findall implies all matches > should be returned, whether there are subgroups in > the pattern or not. It might be best to return all > the match objects (like a re.match call) instead > of the matched strings. Then there is no need > to return tuples of subgroups. Even if tuples > of subgroups were to be returned, group(0) must > also be included in the returned tuple. > > Regards, > > Yingjie > > > All matches are returned by findall, so I don't understand that. I really do suggest that you read the above-mentioned HOWTO, or any of the numerous tutorials on the net. Regexes are hard to get your head around at first, not helped by a few puzzling API design choices, but it's worth the effort, and those will be far more useful than lots of typed explanations here. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dylan at contentfree.info Tue Nov 2 06:32:13 2010 From: dylan at contentfree.info (Dylan Evans) Date: Tue, 2 Nov 2010 20:32:13 +1000 Subject: Mail Merge from python data Message-ID: I'm setting up a database for an organisation who want to do mail merges in office 2010. I know i can use the MySQL ODBC driver for the mail merge but i have set up the database with lots of relations and many-to-many links which i'm sure will lead to a huge amount of confusion (I think, i don't really know much about mail merge). What i want to know is, is there anyway to send data from python, which the UI is written in, to office templates and mail merges? -- "The UNIX system has a command, nice ... in order to be nice to the other users. Nobody ever uses it." - Andrew S. Tanenbaum -------------- next part -------------- An HTML attachment was scrubbed... URL: From sanjo_ie at yahoo.com Tue Nov 2 06:42:22 2010 From: sanjo_ie at yahoo.com (jk) Date: Tue, 2 Nov 2010 03:42:22 -0700 (PDT) Subject: Python documentation too difficult for beginners Message-ID: Hi, I've been coding in PHP and Java for years, and their documentation is concise, well structured and easy to scan. Others have mentioned this apparently for years (see: http://stackoverflow.com/questions/4046166/easy-to-navigate-online-python-reference-manual/4070851 and http://www.russellbeattie.com/blog/python-library-docs-still-suck and http://xahlee.org/perl-python/xlali_skami_cukta.html). Compare for instance the differences in ease of use, and speed of use, of these: http://docs.python.org/library/functions.html#open http://uk.php.net/manual/en/function.fopen.php The former is difficult to find (try searching for 'open' in the search box and see what you get). It is simply a collection of paragraphs without strong enough contrast to differentiate the different parts - parameters, parameter values, return types, exceptions and related functions. It is slow to read and doesn't allow easy visual scanning. The latter has clearly delineated, standardised content areas for each of these without excessive text. It uses tables which are easy to scan for possible opening modes and allows users to contribute their own examples. Sadly, the use of restructured text by python doesn't allow a new document generator to be written - all existing documentation would need updating with docblocks or something similar. Has anyone else struggled while trying to learn the language? The whole documentation system seems geared towards people who already know what they're looking for and is close to useless for beginners. I'm not the only one who finds google an easier way to find documentation about python. Is there much chance that the Python maintainers will change their documentation system to make it more like Java or PHP? How would I go about trying to make that happen? From hnsri49 at gmail.com Tue Nov 2 06:48:40 2010 From: hnsri49 at gmail.com (srinivas hn) Date: Tue, 2 Nov 2010 16:48:40 +0600 Subject: Python documentation too difficult for beginners In-Reply-To: References: Message-ID: If you are really beginner in python you can look into the dive into python,search as in google as the same its quite helpful for beginners.Also you can go for the byte of python. CHEERS CNA 9986229891 On Tue, Nov 2, 2010 at 4:42 PM, jk wrote: > Hi, > > I've been coding in PHP and Java for years, and their documentation is > concise, well structured and easy to scan. > > Others have mentioned this apparently for years (see: > > http://stackoverflow.com/questions/4046166/easy-to-navigate-online-python-reference-manual/4070851 > and http://www.russellbeattie.com/blog/python-library-docs-still-suck > and http://xahlee.org/perl-python/xlali_skami_cukta.html). > > Compare for instance the differences in ease of use, and speed of use, > of these: > > http://docs.python.org/library/functions.html#open > http://uk.php.net/manual/en/function.fopen.php > > The former is difficult to find (try searching for 'open' in the > search box and see what you get). It is simply a collection of > paragraphs without strong enough contrast to differentiate the > different parts - parameters, parameter values, return types, > exceptions and related functions. It is slow to read and doesn't allow > easy visual scanning. > > The latter has clearly delineated, standardised content areas for each > of these without excessive text. It uses tables which are easy to scan > for possible opening modes and allows users to contribute their own > examples. > > Sadly, the use of restructured text by python doesn't allow a new > document generator to be written - all existing documentation would > need updating with docblocks or something similar. > > Has anyone else struggled while trying to learn the language? The > whole documentation system seems geared towards people who already > know what they're looking for and is close to useless for beginners. > I'm not the only one who finds google an easier way to find > documentation about python. > > Is there much chance that the Python maintainers will change their > documentation system to make it more like Java or PHP? How would I go > about trying to make that happen? > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Tue Nov 2 07:02:30 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 02 Nov 2010 11:02:30 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: <4ccfefc6$0$29966$c3e8da3$5496439d@news.astraweb.com> On Mon, 01 Nov 2010 22:24:03 +0000, Grant Edwards wrote: > On 2010-11-01, Lawrence D'Oliveiro > wrote: [...] >> I'm getting less and less keen on that particular feature of Python... > > Why? > > Other languages have similar problems if you remove salient bits of > syntax before comparing two source files files. > > For exmaple, if you remove all of the curly-braces from two C source > files before comparing them, you don't get useful results. Ah, but other languages don't make the guarantee that you can add or remove random whitespace in arbitrary places and still have code that works correctly! Of course, neither does Python, but there's a certain type of personality that is never happy unless they are bitching and moaning, and if they can't find something more substantial to bitch and moan about, they'll bitch and moan about the fact that they can't make random changes to syntactically significant tokens in their source code without things breaking. Boo hoo, cry me a river. Personally, I'm more disturbed by the default prompt in the interactive interpreter. >>> clashes with the symbol used for quoting text in email and news. That causes me far more distress than indentation. Doing a bit of my own bitching and moaning'ly y'rs, -- Steven From steve at REMOVE-THIS-cybersource.com.au Tue Nov 2 07:22:19 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 02 Nov 2010 11:22:19 GMT Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> Message-ID: <4ccff46b$0$29966$c3e8da3$5496439d@news.astraweb.com> On Tue, 02 Nov 2010 11:16:46 +1300, Lawrence D'Oliveiro wrote: > In message <4CCE6FF6.2050408 at v.loewis.de>, Martin v. Loewis wrote: > >> (in fact, I can't think any situation where I would use the backslash). > > for \ > Description, Attr, ColorList \ > in \ > ( > ("normal", "image", MainWindow.ColorsNormalList), > ("highlighted", "highlight", > MainWindow.ColorsHighlightedList), ("selected", "select", > MainWindow.ColorsSelectedList), > ) \ > : > ... > #end for If it were your intention to show why backslashes should be avoided, you succeeded admirably. The above can be written much more cleanly as: for Description, Attr, ColorList in ( ("normal", "image", MainWindow.ColorsNormalList), ("highlighted", "highlight", MainWindow.ColorsHighlightedList), ("selected", "select", MainWindow.ColorsSelectedList), ): pass with no backslashes required. An even better way would be to given the tuples descriptive names, so that anyone maintaining this software can easily see what they are for: # States should be tuples (description, attribute name, colour list). standard = ("normal", "image", MainWindow.ColorsNormalList) highlighted = ("highlighted", "highlight", MainWindow.ColorsHighlightedList) selected = ("selected", "select", MainWindow.ColorsSelectedList) for desc, attr, color_list in (standard, highlighted, selected): pass -- Steven From steve at REMOVE-THIS-cybersource.com.au Tue Nov 2 07:23:48 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 02 Nov 2010 11:23:48 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <8j8udgFlkvU1@mid.individual.net> Message-ID: <4ccff4c4$0$29966$c3e8da3$5496439d@news.astraweb.com> On Mon, 01 Nov 2010 22:48:16 +0000, Peter Pearson wrote: > I must concede that some awkwardness results from assigning significance > to something (whitespace) that many tools are inclined to treat as > insignificant. Then the tools are broken. Or perhaps I should say: Th enth etool sarebroke n. -- Steven From sanjo_ie at yahoo.com Tue Nov 2 07:23:49 2010 From: sanjo_ie at yahoo.com (jk) Date: Tue, 2 Nov 2010 04:23:49 -0700 (PDT) Subject: Python documentation too difficult for beginners References: Message-ID: This (http://epydoc.sourceforge.net/stdlib/) is what I'm talking about. Why aren't the official docs like this, and why has it taken me 2 days of searching? All this needs is a search engine behind it and it'd be perfect. From fetchinson at googlemail.com Tue Nov 2 07:32:14 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Tue, 2 Nov 2010 12:32:14 +0100 Subject: playful coding problems for 10 year olds In-Reply-To: References: Message-ID: >> Hi folks, >> >> My niece is interested in programming and python looks like a good >> choice (she already wrote a couple of lines :)) She is 10 and I >> thought it would be good to have a bunch of playful coding problems >> for her, stuff that she could code herself maybe after some initial >> help. >> >> Do you guys know problems like these? Or a good resource where to look >> them up? >> >> Cheers, >> Daniel >> > > There's a great book valled 'Invent your own computer games using > Python', aimed at kids, which teaches programming from tne ground up, > in the context of writing games, starting with terminal word games, > ending with Pygame fullscreen 2D vector graphic & bitmaps affairs. > http://inventwithpython.com/ > > The website says aimed at kids 'ages 10 to 12 and upwards', so it > sounds like she's on the minimum cusp. > > (now I come to look at the website, one of the quotes he features is > from an Amazon review I wrote months ago! :-) Thanks a lot for everyone for the suggestions, I think I'll be able to cook things up from all the references you sent! Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From steve at REMOVE-THIS-cybersource.com.au Tue Nov 2 07:36:34 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 02 Nov 2010 11:36:34 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> On Tue, 02 Nov 2010 04:16:28 +0000, Seebs wrote: > e.g., any email sent > to my work account is being magically transformed into HTML (no one > knows why) on the server, so I can't get correct indentation except > in attachments. I suppose then you're going to insist that Python should stop using > and < for comparison operators, because your mail server converts them to > and < escapes? > I've lost more time to indentation issues in Python in a month than I've > lost to mismatches between indentation and flow in C in twenty years. I've lost more time to reading people's bitching about indentation than I have dealing with indentation problems. But then, I don't insist on using tools which are broken by design. If your email server converts plain text to HTML, it is broken. If your editor changes spaces to tabs, or visa versa, without being told to do so (either by an explicit command or an obvious setting), then your editor is broken. If you are stuck with broken mail servers and broken editors and broken tools because of political reasons, then you have my sympathy. But stop insisting that everybody has to carry the overhead of your work-arounds for your broken tools. -- Steven From tim.wintle at teamrubber.com Tue Nov 2 07:41:26 2010 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Tue, 02 Nov 2010 11:41:26 +0000 Subject: Python documentation too difficult for beginners In-Reply-To: References: Message-ID: <1288698086.9950.28.camel@tim-laptop.config> On Tue, 2010-11-02 at 04:23 -0700, jk wrote: > This (http://epydoc.sourceforge.net/stdlib/) is what I'm talking > about. Aaaarrrgggghhhh > Why aren't the official docs like this, Because not everyone likes documentation like that. Personally I far prefer the existing documentation to the JavaDoc-style link you sent. > and why has it taken me 2 days of searching? > All this needs is a search engine behind it and it'd be > perfect. Personally I use Google, e.g. "list site:docs.python.org" to bring up documentation about the list type. From roy at panix.com Tue Nov 2 07:46:23 2010 From: roy at panix.com (Roy Smith) Date: Tue, 02 Nov 2010 07:46:23 -0400 Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> Message-ID: In article , Chris Rebert wrote: > I find the level of deviation from PEP 8 in that file rather disturbing. > In any case, the backslashes are easily avoided, and readability > improved IMHO, via refactoring: > > desc_attr_colors_triples = (("normal", "image", MainWindow.ColorsNormalList), > ("highlighted", "highlight", MainWindow.ColorsHighlightedList), > ("selected", "select", MainWindow.ColorsSelectedList)) > for in description, attr, color_list in desc_attr_colors_triples: > ... I like and use PEP-8. At the start of any project involving myself, other people, and Python, I'll generally suggest we follow PEP-8 style, and I can't remember ever getting any pushback. That being said, I don't hold it in awe. Likewise, I don't worry in the least about deviating when readability would be improved by doing so. In this case, I think I would do: styles = [("normal", "image", MainWindow.ColorsNormalList), ("highlighted", "highlight", MainWindow.ColorsHighlightedList), ("selected", "select", MainWindow.ColorsSelectedList)] for in description, attr, color_list in styles: blah, blah, blah For those reading this in a non-fixed width font, I've laid out the definition of styles as a table, with spaces inserted to make the columns line up. For data like this, I think it makes it easier to read and comprehend. As a minor nit, note that I made it a list of tuples, not a tuple of tuples. I'm tempted to do an additional refactoring to get rid of the verbose color list names: CL_Normal = MainWindow.ColorsNormalList) CL_Highlighted = MainWindow.ColorsHighlightedList CL_Selected = MainWindow.ColorsSelectedList styles = [("normal", "image", CL_Normal), ("highlighted", "highlight", CL_Highlighted), ("selected", "select", CL_Selected)] I haven't decided if this makes things better or worse. For this small table, I'm inclined to say worse. If the table were much larger and I were reusing many of the color list names over and over, I would certainly do that. If MainWindow were a well-designed module and I could do import * from MainWindow without cluttering up my namespace too much, I would do that, then just use the unadorned names. Also, depending on what I was doing inside the loop, I might pick shorter names. For example: for in d, a, c in styles: window.set_description(d) window.set_attribute(a) window.set_color_list(c) is perfectly clear. Normally, I don't use single-letter variable names, but in this particular case, the descriptive function names provide all the context that's need to explain what they are. From mail at timgolden.me.uk Tue Nov 2 07:49:42 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 02 Nov 2010 11:49:42 +0000 Subject: Python documentation too difficult for beginners In-Reply-To: References: Message-ID: <4CCFFAD6.9020601@timgolden.me.uk> On 02/11/2010 11:23, jk wrote: > This (http://epydoc.sourceforge.net/stdlib/) is what I'm talking > about. > > Why aren't the official docs like this, and why has it taken me 2 days > of searching? All this needs is a search engine behind it and it'd be > perfect. I'm glad you find the epydoc format useful. And I'm glad that various people have taken the trouble to produce documentation for Python in various formats that suit them. But why do you imagine that the core Python documentation -- developed and maintained by a group of people who clearly have some idea what they're doing -- should change to a format which happens to suit you? The Python documentation source and the source code of Python itself are all freely available. Any initiative by you or by others to produce alternative, possibly searchable and commentable, versions of them would I'm sure be welcomed by many. But not everyone finds, eg, the PHP style of user annotation helpful. Not everyone likes epydoc output: I don't myself. In short, please feel free to contribute directly to the core documentation effort, or to produce alternatives yourself and to advertise them here or elsewhere within the Python community. But please don't come along and say "Why aren't the Python docs like which happens to suit me better?" TJG From martin.hellwig at dcuktec.org Tue Nov 2 07:52:07 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Tue, 02 Nov 2010 11:52:07 +0000 Subject: Python documentation too difficult for beginners In-Reply-To: References: Message-ID: On 11/02/10 10:42, jk wrote: > Is there much chance that the Python maintainers will change their > documentation system to make it more like Java or PHP? How would I go > about trying to make that happen? I am by no means an authority however since you ask it here I feel compelled to give you my opinion :-) In general I would think that more documentation is always welcome, if you feel like you can make a contribution, excellent, please do! However, I found that the documentation available was enough for me, and I didn't even have to go to the googles for that. Typing help(thing_i_want_info_of) in the interpreter gives me precise consistent information for what I need to do with whatever it is I am doing and yes that is largely a replication of what is mentioned on the site itself (well more the other way around actually). In the odd cases this doesn't help me, I google for examples. If that doesn't help I look at the modules __file__ and open that module to read the source. And when I started 10 odd years ago with Python it was my first language with no prior confusion of other languages, since then I extended my knowledge with C and assembler but on a day to day basis I still use Python. -- mph From steve at REMOVE-THIS-cybersource.com.au Tue Nov 2 07:59:25 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 02 Nov 2010 11:59:25 GMT Subject: functions, list, default parameters References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <4cc13ef5$0$29979$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4ccffd1c$0$29966$c3e8da3$5496439d@news.astraweb.com> On Tue, 02 Nov 2010 22:06:40 +1300, Lawrence D'Oliveiro wrote: > In message , Chris > Rebert wrote: > >> On Fri, Oct 22, 2010 at 12:36 AM, Steven D'Aprano >> wrote: >>> >>> Default mutable arguments have their place >> >> But it's a rather obscure one where it is almost never strictly >> necessary to venture. > > Mediocre programmers with a hankering towards cleverness latch onto it > as an ingenious way of maintaing persistent context in-between calls to > a function, completely overlooking the fact that Python offers much more > straightforward, comprehensible, flexible, and above all maintainable > ways of doing that sort of thing. Perhaps. Or maybe it's the mediocre programmers who find mutable defaults confusing, incomprehensible and unmaintainable. Certainly it's the mediocre programmers who seem to be incapable of understanding that Python has no way of telling whether arbitrary objects are mutable or not. def foo(x, y=list()): pass Is y a mutable default or not? For the benefit of any mediocre programmers out there, be careful before you answer. This *is* a trick question. -- Steven From brf256 at gmail.com Tue Nov 2 08:04:29 2010 From: brf256 at gmail.com (brf256 at gmail.com) Date: Tue, 2 Nov 2010 12:04:29 +0000 Subject: Python documentation too difficult for beginners Message-ID: <802401459-1288699467-cardhu_decombobulator_blackberry.rim.net-753506867-@bda480.bisx.prod.on.blackberry> A tutorial type book can also be great for reference and documentation (as long as its current). I would recommend a non-programmers tutorial to python even if you have started programming in other languages before. Also its a wiki book and is free. -Braden Faulkner Sent wirelessly from my BlackBerry device on the Bell network. Envoy? sans fil par mon terminal mobile BlackBerry sur le r?seau de Bell. From steve at REMOVE-THIS-cybersource.com.au Tue Nov 2 08:14:55 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 02 Nov 2010 12:14:55 GMT Subject: functions, list, default parameters References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <8ivelpFif1U1@mid.individual.net> <4cca88bc$0$29987$c3e8da3$5496439d@news.astraweb.com> <8j1seqFa1eU2@mid.individual.net> Message-ID: <4cd000bf$0$29966$c3e8da3$5496439d@news.astraweb.com> On Tue, 02 Nov 2010 20:12:49 +1300, Lawrence D'Oliveiro wrote about mutable defaults: > Which is what we?re talking about > here: a language construct which is probably one of the top 3 sources of > grief to Python newbies. And not-so-newbies. I call bullshit. Maybe you should spend some time on the tutor at python.org mailing list for a while to see what the common problems newbies actually have. Mutable defaults are *way* down the list. In any case, Python isn't written solely for newbies. Most people will make this mistake once, or twice if they're particularly slow learning. If newbies have a problem with mutable defaults, oh well, they'll learn, or they'll give up and go back to griefing their friends on Facebook. Either way, problem solved. -- Steven From steve at REMOVE-THIS-cybersource.com.au Tue Nov 2 08:16:58 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 02 Nov 2010 12:16:58 GMT Subject: functions, list, default parameters References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <4cc13ef5$0$29979$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4cd00139$0$29966$c3e8da3$5496439d@news.astraweb.com> On Tue, 02 Nov 2010 00:40:17 -0700, Chris Rebert wrote: > On Fri, Oct 22, 2010 at 12:36 AM, Steven D'Aprano > wrote: >> On Thu, 21 Oct 2010 19:53:53 -0700, John Nagle wrote: >>>> This is a common newbie stumbling-block: Don't use lists (or anything >>>> mutable) as default argument values >>> >>> ? ? ?That really should be an error. >> >> No it shouldn't. Punishing everybody for a newbie mistake that nobody >> makes twice would be the error. >> >> Default mutable arguments have their place > > But it's a rather obscure one where it is almost never strictly > necessary to venture. Very few language features are *strictly* necessary. I mean, all you really need is the ability to set the current memory location, a way to read and write to it, and a way to branch. Everything else is just gravy. Not that I'm suggesting we should all use Turing machines, but there are many things which aren't strictly necessary but are nice to have. In any case, this discussion is pointless. There is code out there that uses this feature, whether you (generic you) like it or not, and changing the behaviour *can't* happen until the moratorium ends. Even if there was consensus to make this change -- and there won't be -- it almost certainly won't happen before Python 4000. Even if it did happen, adding extra type-checks to every def statement with a default value, or adding extra complexity to the parser, won't and can't catch every mutable default because there is no way of telling whether an arbitrary object is mutable. It will just slow down the language for bugger-all benefit. -- Steven From lanyjie at yahoo.com Tue Nov 2 08:19:15 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Tue, 2 Nov 2010 05:19:15 -0700 (PDT) Subject: Why this result with the re module Message-ID: <552223.15146.qm@web54201.mail.re2.yahoo.com> > From: John Bond > Subject: Re: Why this result with the re module Firstly, thanks a lot for your patient explanation. this time I have understood all your points perfectly. Secondly, I'd like to clarify some of my points, which did not get through because of my poor presentation. I suggested findall return a tuple of re.MatchObject(s), with each MatchObject instance representing a match. This is consistent with the re.match() function anyway. And it will eliminate the need of returning tuples, and it is much more precise and information rich. If that's not possible, and a tuple must be returned, then the whole match (not just subgroups) should always be included as the first element in the tuple, as that's group(0) or '\0'. Less surprise would arise. Finally, it seems to me the algo for findall is WRONG. To re.findall('(.a.)*', 'Mary has a lamb'), by reason of greediness of '*', and the requirement of non-overlapping, it should go like this (suppose an '' is at the beginning and at the end, and between two consecutive characters there is one and only one empty string ''. To show the match of empty strings clearly, I am concatenating each repeated match below): Steps for re.findall('(.a.)*', 'Mary has a lamb'): step 1: Match '' + 'Mar' + '' (gready!) step 2: skip 'y' step 3: Match '' step 4: skip ' ' step 5: Match ''+'has'+' a '+'lam'+'' (greedy!) step 6: skip 'b' step 7: Match '' So there should be exactly 4 matches in total: 'Mar', '', 'has a lam', '' Also, the matches above shows that if a repeated subgroup only captures the last match, the subgroup (.a.)* should always capture '' here (see steps 1, 3, 5, 7) above. Yet the execution in Python results in 6 matches! And, the capturing subgroup with repetition sometimes got the wrong guy. So I believe the algorithm for findall must be WRONG. Regards, Yingjie From solipsis at pitrou.net Tue Nov 2 08:19:28 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Tue, 2 Nov 2010 13:19:28 +0100 Subject: Python documentation too difficult for beginners References: Message-ID: <20101102131928.27216029@pitrou.net> On Tue, 2 Nov 2010 04:23:49 -0700 (PDT) jk wrote: > This (http://epydoc.sourceforge.net/stdlib/) is what I'm talking > about. > > Why aren't the official docs like this, and why has it taken me 2 days > of searching? What's wrong with this: http://docs.python.org/library/ ? If you have specific ideas for improvements, you can open issues at http://bugs.python.org. Thank you Antoine. From vlastimil.brom at gmail.com Tue Nov 2 08:34:56 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Tue, 2 Nov 2010 13:34:56 +0100 Subject: Why this result with the re module In-Reply-To: <552223.15146.qm@web54201.mail.re2.yahoo.com> References: <552223.15146.qm@web54201.mail.re2.yahoo.com> Message-ID: 2010/11/2 Yingjie Lan : >> From: John Bond >> Subject: Re: Why this result with the re module > ... > I suggested findall return a tuple of re.MatchObject(s), > with each MatchObject instance representing a match. > This is consistent with the re.match() function anyway. > And it will eliminate the need of returning tuples, > and it is much more precise and information rich. > > Hi, in that case you may use re.finditer(...), which seem to provide, what you need here. (It returns an iterator over the Match objects, which can be easily fed to tuple(...) if it were needed.) hth, vbr From neilc at norwich.edu Tue Nov 2 08:34:59 2010 From: neilc at norwich.edu (Neil Cerutti) Date: 2 Nov 2010 12:34:59 GMT Subject: playful coding problems for 10 year olds References: <4CCF3595.2060102@v.loewis.de> Message-ID: <8jaerjFjdaU6@mid.individual.net> On 2010-11-01, Martin v. Loewis wrote: >> My niece is interested in programming and python looks like a good >> choice (she already wrote a couple of lines :)) She is 10 and I >> thought it would be good to have a bunch of playful coding problems >> for her, stuff that she could code herself maybe after some initial >> help. > > I think anything that has to do with drawing and colors will be > attractive, animated if possible. It has to look nice. > > Take a look at the turtle demos. The book _Simply Scheme_ contains a lot of word problems, which I think is quite nice. possessive,is_palindrom, pig_latin, and so forth might make good Python exercises, too. -- Neil Cerutti From emile at fenx.com Tue Nov 2 09:19:31 2010 From: emile at fenx.com (Emile van Sebille) Date: Tue, 02 Nov 2010 06:19:31 -0700 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: On 11/1/2010 4:22 PM Lawrence D'Oliveiro said... > In message, Emile van > Sebille wrote: > >> At least you can look at python code and _know_ that spurious placement of >> required line noise don't have the ability to impact what the code does. > > But it does. What is spurious whitespace if not noise, after all? But it does so by intent. Other languages lend only an appearance of structure through the indentation style of the writer. It's as good as outdated comments. Emile From sanjo_ie at yahoo.com Tue Nov 2 09:23:43 2010 From: sanjo_ie at yahoo.com (jk) Date: Tue, 2 Nov 2010 06:23:43 -0700 (PDT) Subject: Python documentation too difficult for beginners References: Message-ID: <9a58b8bd-9716-41d6-a497-33c5eb56e60a@a37g2000yqi.googlegroups.com> On Nov 2, 11:49 am, Tim Golden wrote: > But why do you imagine that the core > Python documentation -- developed and maintained by a group of people > who clearly have some idea what they're doing -- should change to a > format which happens to suit you? It's not just me who's found the current documentation frustrating. And sure, the developers know how to code, but they probably can't see the project with the eyes of a beginner any more. Making a change to how code is documented to allow more javadoc-style documentation to be produced could help people migrate from a java background and ease the learning curve for them, leading to wider adoption of the language. It wouldn't necessarily mean that the current documentation style would need to change either. > In short, please feel free to contribute directly to the core > documentation effort, or to produce alternatives yourself I may well do that. @Tim Wintle > Personally I use Google, e.g. > "list site:docs.python.org" > to bring up documentation about the list type. Surely you shouldn't have to go to google though? Or the interpreter? Maybe it's just what you're used to, but I'd expect the language's web site to provide enough of a reference in itself, while using google for examples. From msarro at gmail.com Tue Nov 2 09:40:00 2010 From: msarro at gmail.com (Matty Sarro) Date: Tue, 2 Nov 2010 09:40:00 -0400 Subject: Learning book recommendation? Message-ID: Hey Everyone! I'm looking for a Python book to start really learning the language since I've been using it more and more. Something similar to what you'd see in a computer science class - a few pages of theory and explanation of commands/syntax/constructs/data structures and then some exercises to help you learn how to put it to work. I've tried the MIT OCW intro to python/CS but it quickly went beyond my abilities (sadly, I am no MIT student). -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Tue Nov 2 09:42:17 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 02 Nov 2010 13:42:17 GMT Subject: Python documentation too difficult for beginners References: Message-ID: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> On Tue, 02 Nov 2010 03:42:22 -0700, jk wrote: > Hi, > > I've been coding in PHP and Java for years, and their documentation is > concise, well structured and easy to scan. Well, that's one opinion. > Others have mentioned this apparently for years (see: > http://stackoverflow.com/questions/4046166/easy-to-navigate-online- python-reference-manual/4070851 > and http://www.russellbeattie.com/blog/python-library-docs-still-suck > and http://xahlee.org/perl-python/xlali_skami_cukta.html). > > Compare for instance the differences in ease of use, and speed of use, > of these: > > http://docs.python.org/library/functions.html#open > http://uk.php.net/manual/en/function.fopen.php > > The former is difficult to find (try searching for 'open' in the search > box and see what you get). A fair point -- the built-in open comes up as hit #30, whereas searching for open in the PHP page brings up fopen as hit #1. But the PHP search also brings up many, many hits -- ten pages worth. But in any case, the Python search functionality could be smarter. If I had a complaint about the docs, that would be it. Fortunately, I have google :) > It is simply a collection of paragraphs > without strong enough contrast to differentiate the different parts - > parameters, parameter values, return types, exceptions and related > functions. It is slow to read and doesn't allow easy visual scanning. It's *nine* paragraphs, three of which are one-liners, the longest of which is eight lines. If you have trouble reading that, well, you have a problem. The PHP docs for fopen are FIFTY-EIGHT paragraphs. Okay, okay, I was unfair. I counted section headings as separate paragraphs. A more reasonable count is... twenty-six paragraphs, tables, sections and subsections. Plus *dozens* of user-contributed recipes, bug reports, tricks, tips and comments. And you call this concise??? Reading the docs, I'd say that PHP needs all this extra documentation because it's so much more complicated. fopen has all this implicit magic behaviour that needs documenting -- it will try to guess a scheme from the file name, if it can't guess the scheme it will guess that it's a local file, and the behaviour depends on various globals. In comparison, Python's open is very simple: it only opens files. No wonder Python's docs are simpler. The PHP docs felt it necessary to give a warning *three times*, one after the other, about using binary mode when opening files. Apparently once was not enough. The Description subsection of the PHP fopen doc says: fopen() binds a named resource, specified by filename, to a stream. What's a stream? So I read, and read, and read, and eventually, almost at the bottom of the official docs, I find the section "Return Values": Returns a file pointer resource on success, or FALSE on error. Great! Now, what's a file pointer resource, and how does it differ from a stream? No idea. Contrast that with the Python docs. In the *very first sentence*, it says: Open a file, returning an object of the file type described in section File Objects. with both "file" and "File Objects" being hyperlinks to the appropriate part of the docs. I think I'll stick with the Python style, thank you very much. > The latter has clearly delineated, standardised content areas for each > of these without excessive text. It uses tables which are easy to scan > for possible opening modes and allows users to contribute their own > examples. There has been discussion on python-dev about user contributed examples. The pros are that users can add tricks and tips. The cons are that, without constant attention, the user-contributed content will grow old and stale, or worse, be filled with nonsense. However, there is a Python wiki. It doesn't get anywhere near as much love as it deserves, and (I think) the consensus was that the official Python docs should stay official, but link to the wiki for user- contributed content. This hasn't happened yet. http://wiki.python.org/moin/ > Sadly, the use of restructured text by python doesn't allow a new > document generator to be written - all existing documentation would need > updating with docblocks or something similar. > > Has anyone else struggled while trying to learn the language? The whole > documentation system seems geared towards people who already know what > they're looking for and is close to useless for beginners. I'm not the > only one who finds google an easier way to find documentation about > python. Why do you think this is a bad thing? The Python docs are the reference manual, not a tutorial. Quite frankly, if I were a PHP developer, I'd be pretty annoyed at having to read this in the docs for fopen: If you use the wrong line ending characters when writing your files, you might find that other applications that open those files will "look funny". Gosh, really? Thanks for the tip, Captain Obvious. It's always difficult to know how much information is too much. The PHP docs seem to take an "everything including the kitchen sink" approach. Given that approach, it makes sense to divide everything into subsections, one page per function. But with Python's minimalist approach, it would just be annoying. Compare the four lines of: http://docs.python.org/library/functions.html#id with this re-write in the PHP fashion: ===== id ===== (Python 1.x, Python 2.x, Python 3.x) id -- id of an object Description ----------- id(object) id returns the numeric "identity" of an object, which is guaranteed to be unique and constant for this object during its lifetime. Note: two objects with non-overlapping lifetimes may have the same id() value. Note: CPython implementation detail: This is the address of the object. Parameters ---------- * object Any object. Note: all data in Python are objects, even ints and strings. Note: there are no undefined objects in Python. If you call id(variable) on an unbound variable name, Python will raise an exception. Return values ------------- Returns an integer or long integer object representing the ID of the argument. Errors/exceptions ----------------- If the argument to id() is a named variable rather than a literal, and that name is not bound to any object, then a NameError will be raised. Otherwise every call to id() must succeed. Note: if the call to id() is inside a function, the exception may be a subclass of NameError such as UnboundLocalError. Note: literals are not guaranteed to always refer to the same object. Changelog --------- 0.9 First version added (I think). Examples -------- id(x) id(alist[1]) id(instance.attribute) id(module.name.attribute['key'].method(arg1, arg2).seq[2]) Notes ----- If you're still reading, I admire your persistence. See also -------- Python's object model Exceptions > Is there much chance that the Python maintainers will change their > documentation system to make it more like Java or PHP? How would I go > about trying to make that happen? Unlikely. You could raise the issue on the python-dev list, or see if there is a SIG mailing list specifically for the docs. Frankly, I think that the best thing you could do is start a fork of the docs and see if you get any interest from people. If you do, then you can go back to python-dev with proof that there is a genuine popular desire for more structured, PHP-style documentation. -- Steven From brf256 at gmail.com Tue Nov 2 09:50:53 2010 From: brf256 at gmail.com (brf256 at gmail.com) Date: Tue, 2 Nov 2010 13:50:53 +0000 Subject: Learning book recommendation? Message-ID: <1053302592-1288705850-cardhu_decombobulator_blackberry.rim.net-148438442-@bda480.bisx.prod.on.blackberry> Hey there, I would reccomend a non-programmers tutorial to python by Josh coglatti and its a free wiki book. Also I would recommend byte into python. Both are great for beginers. Best of luck! -- Braden Faulkner Sent wirelessly from my BlackBerry device on the Bell network. Envoy? sans fil par mon terminal mobile BlackBerry sur le r?seau de Bell. From invalid at invalid.invalid Tue Nov 2 10:14:32 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 2 Nov 2010 14:14:32 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <8j8udgFlkvU1@mid.individual.net> Message-ID: On 2010-11-01, Peter Pearson wrote: > On Mon, 1 Nov 2010 22:24:03 +0000 (UTC), Grant Edwards wrote: >> On 2010-11-01, Lawrence D'Oliveiro wrote: >>> In message <8j8am4Fk2jU1 at mid.individual.net>, Peter Pearson wrote: >>>> >>>>> diff -b oldfile newfile >>>> >>>> Warning: "diff -b" won't detect changes in indentation. Changes in >>>> indentation can change a Python program. >>> >>> I'm getting less and less keen on that particular feature of Python... >> >> Why? >> >> Other languages have similar problems if you remove salient bits of >> syntax before comparing two source files files. >> >> For exmaple, if you remove all of the curly-braces from two C source >> files before comparing them, you don't get useful results. > > True, but diff doesn't come with an "ignore curly braces" option. True, but the fact that diff has an option that for Python sources will produces useless results doesn't seem like a valid indictment of Python's syntax and semantics. > I'm not personally repelled by Python's use of significant > indentation, but I must concede that some awkwardness results from > assigning significance to something (whitespace) that many tools are > inclined to treat as insignificant. However, the human brain does treat whitespace as significant. -- Grant Edwards grant.b.edwards Yow! I joined scientology at at a garage sale!! gmail.com From invalid at invalid.invalid Tue Nov 2 10:20:21 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 2 Nov 2010 14:20:21 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: On 2010-11-02, Seebs wrote: > On 2010-11-01, Grant Edwards wrote: >> On 2010-11-01, Lawrence D'Oliveiro wrote: >>> I'm getting less and less keen on that particular feature of >>> Python... > >> Why? > >> Other languages have similar problems if you remove salient bits of >> syntax before comparing two source files files. > > Sure. > >> For exmaple, if you remove all of the curly-braces from two C source >> files before comparing them, you don't get useful results. > > Right. > > But there's no *reason* to do that, while there are many common daily > events which result in whitespace changes. e.g., any email sent to > my work account is being magically transformed into HTML (no one > knows why) on the server, so I can't get correct indentation except > in attachments. And you think compatibility with your broken e-mail server is a good reason to change the syntax of a programming language? > Many editors helpfully convert spaces to tabs by default some or all > of the time. And so on. Such editors are broken. > The more I use it, the more I think it was an interesting experiment > which has worked out about as well as scanf. I think it's brilliant (indentation that actually means something, not scanf). > The "problem" it fixes is something that's hardly ever been a problem > for me in C or related languages -- and which could be completely > eliminated by automated indenters, which were actually conceptually > possible. They're only possible if you put redundant block markers in the source. > I've lost more time to indentation issues in Python in a month than > I've lost to mismatches between indentation and flow in C in twenty > years. Then you're doing something terribly wrong. I find indentation-based structure to be completely effortless. Are you using an editor that doesn't have a Python mode? > In theory, it sounds like it would help to eliminate the ambiguity. > In practice, eliminating the question of whether code was intended to > follow explicit flow rather than indentation just means that when > there's a mistake you don't even get a warning that someone was > confused. > > At least in C, if I see: > if (foo) > a; > else > b; > c; > > I *know* that something is wrong. I suppose you can add comments to Python if you some syntactically null "redudundacy" to indicate the intended structure. Personally, -- Grant Edwards grant.b.edwards Yow! I'm having a at quadrophonic sensation gmail.com of two winos alone in a steel mill! From invalid at invalid.invalid Tue Nov 2 10:27:49 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 2 Nov 2010 14:27:49 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccfefc6$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-02, Steven D'Aprano wrote: > Ah, but other languages don't make the guarantee that you can add or > remove random whitespace in arbitrary places and still have code that > works correctly! > > Of course, neither does Python, but there's a certain type of > personality that is never happy unless they are bitching and moaning, > and if they can't find something more substantial to bitch and moan > about, they'll bitch and moan about the fact that they can't make > random changes to syntactically significant tokens in their source > code without things breaking. Boo hoo, cry me a river. :) > Personally, I'm more disturbed by the default prompt in the > interactive interpreter. >>> clashes with the symbol used for quoting > text in email and news. That causes me far more distress than > indentation. I've tripped over that as well. Not very often, but it's a bigger problem than significant whitespace. I must admit that the first few minutes I worked with Python having significant whitespace seemed awkward -- probably because it invoked unpleasant memories of Fortran IV on punch-cards. After a short time, I suddenly realized that Python got it right: the compiler and my brain are using the _same_thing_ to denote program structure. All those years of my brain using one thing and the compiler using a different thing were (and are) obviously the wrong way to do it. -- Grant Edwards grant.b.edwards Yow! My BIOLOGICAL ALARM at CLOCK just went off ... It gmail.com has noiseless DOZE FUNCTION and full kitchen!! From invalid at invalid.invalid Tue Nov 2 10:33:29 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 2 Nov 2010 14:33:29 +0000 (UTC) Subject: Python documentation too difficult for beginners References: Message-ID: On 2010-11-02, brf256 at gmail.com wrote: > A tutorial type book can also be great for reference and > documentation (as long as its current). I would recommend a > non-programmers tutorial to python even if you have started > programming in other languages before. Also its a wiki book and is > free. To what does "it" refer in the last sentence? > Sent wirelessly from my BlackBerry device on the Bell network. That's nice, thank's for sharing. -- Grant Edwards grant.b.edwards Yow! Do you think the at "Monkees" should get gas on gmail.com odd or even days? From lanyjie at yahoo.com Tue Nov 2 10:37:51 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Tue, 2 Nov 2010 07:37:51 -0700 (PDT) Subject: Why this result with the re module In-Reply-To: Message-ID: <415473.28393.qm@web54204.mail.re2.yahoo.com> > From: Vlastimil Brom > Subject: Re: Why this result with the re module > in that case you may use re.finditer(...) Thanks for pointing this out. Still I'd love to see re.findall never discards the whole match, even if a tuple is returned. Yingjie From sanjo_ie at yahoo.com Tue Nov 2 10:47:29 2010 From: sanjo_ie at yahoo.com (jk) Date: Tue, 2 Nov 2010 07:47:29 -0700 (PDT) Subject: Python documentation too difficult for beginners References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <024ef21a-9ef9-48a6-8372-1d66895583c3@v16g2000yqn.googlegroups.com> On Nov 2, 1:42?pm, Steven D'Aprano wrote: > It's always difficult to know how much information is too much. The PHP > docs seem to take an "everything including the kitchen sink" approach. > Given that approach, it makes sense to divide everything into > subsections, one page per function. But with Python's minimalist > approach, it would just be annoying. Compare the four lines of: > > http://docs.python.org/library/functions.html#id > > with this re-write in the PHP fashion: > > ===== > id > ===== > (Python 1.x, Python 2.x, Python 3.x) > > id -- id of an object > > Description > ----------- > > id(object) > > id returns the numeric "identity" of an object, which is guaranteed to be > unique and constant for this object during its lifetime. > > Note: two objects with non-overlapping lifetimes may have the same id() > value. > > Note: CPython implementation detail: This is the address of the object. > > Parameters > ---------- > > * object > > ? Any object. > > ? Note: all data in Python are objects, even ints and strings. > > ? Note: there are no undefined objects in Python. If you call > ? id(variable) on an unbound variable name, Python will raise an > ? exception. > > Return values > ------------- > > Returns an integer or long integer object representing the ID of the > argument. > > Errors/exceptions > ----------------- > > If the argument to id() is a named variable rather than a literal, and > that name is not bound to any object, then a NameError will be raised. > Otherwise every call to id() must succeed. > > Note: if the call to id() is inside a function, the exception may be a > subclass of NameError such as UnboundLocalError. > > Note: literals are not guaranteed to always refer to the same object. > > Changelog > --------- > > ? 0.9 ?First version added (I think). > > Examples > -------- > > ? ?id(x) > ? ?id(alist[1]) > ? ?id(instance.attribute) > ? ?id(module.name.attribute['key'].method(arg1, arg2).seq[2]) > > Notes > ----- > > ? ?If you're still reading, I admire your persistence. > > See also > -------- > > ? ?Python's object model > ? ?Exceptions > > Steven You're right in that the python docs in this case are less lines, but that's one of the problems. It doesn't mention anywhere the extra detail you've added regarding exceptions thrown. That's the kind of thing that probably comes through experience or some kind of convention which isn't obvious to beginners. Having things split into sections - parameters, return types, exceptions, etc - lets me find what I'm looking for quickly. As for the 9 paragraphs statement, there's a usability book that applies here - it's called "Don't make me think". I shouldn't have to go through freeform text to find what I'm looking for when a list would make that information easier to find. And splitting the docs into sections would allow me to skip to what I'm looking for. I really would be much happier with your example documentation. I think the key difference is that I don't want to have to *read* the python docs - I want to be able to scan for what I'm looking for and find it easily. That makes me productive. From paul.nospam at rudin.co.uk Tue Nov 2 10:53:34 2010 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Tue, 02 Nov 2010 14:53:34 +0000 Subject: Python documentation too difficult for beginners References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <871v73kc9d.fsf@rudin.co.uk> Steven D'Aprano writes: > A fair point -- the built-in open comes up as hit #30, whereas searching > for open in the PHP page brings up fopen as hit #1. But the PHP search > also brings up many, many hits -- ten pages worth. > OTOH googling for "python open" gives you the correct (for 2.7) page as hit #1 - although you then have to use your browser's "find" facilty to actually get to the description of the function in question. From dalist0 at gmail.com Tue Nov 2 10:57:12 2010 From: dalist0 at gmail.com (Daniel) Date: Tue, 2 Nov 2010 07:57:12 -0700 (PDT) Subject: extracting variables accessed and written from function / rule-based function calls References: <0d74ca46-657c-41cc-a582-0d78f11350a3@30g2000yql.googlegroups.com> <4CCF4C03.2020203@mrabarnett.plus.com> Message-ID: <58a67616-d3b8-4186-8ca8-d9ce95a1839e@y23g2000yqd.googlegroups.com> > >> You might be interested by the story of how AstraZeneca tackled that > >> kind of problem in PyDrone:http://www.python.org/about/success/astra/ that is interesting! So it seems they store the values in a dictionary. For each value they associate a function that gets called when the value is not available. This function uses the same dictionary to access the other values, which might trigger more evaluations. I like this approach. Unfortunately in my case it would not work, because I might have more than one rule associated with each function, depending on which values are available. If the wrong rule gets called which needs to call other (wrong) rules I could end up in a loop, even though everything could be computed in principle. lets say a follows from b or c (r1, r2) , b follows from a or c (r3, r4) and c is given. Using this approach I would end up in a loop of rules r1 and r3 to compute a. I don't see how this approach could be made to work the other way round, each value could have a rule attached that, given the availability of other dependencies computes the dependent values. That seems complicated, because one rule would need to be associated with several values. One possibility I thought of was to write the rules as python functions and use the ast module to extract all the variables that are being referenced. In principle this should be possible. Is there any library around that does that? Dan From bruno.42.desthuilliers at websiteburo.invalid Tue Nov 2 11:28:28 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 02 Nov 2010 16:28:28 +0100 Subject: Python documentation too difficult for beginners In-Reply-To: References: Message-ID: <4cd02e1b$0$7393$426a74cc@news.free.fr> jk a ?crit : > Hi, > > I've been coding in PHP and Java for years, and their documentation is > concise, well structured and easy to scan. > > Others have mentioned this apparently for years (see: > http://stackoverflow.com/questions/4046166/easy-to-navigate-online-python-reference-manual/4070851 > and http://www.russellbeattie.com/blog/python-library-docs-still-suck > and http://xahlee.org/perl-python/xlali_skami_cukta.html). Totally unrelated, but the last example is nothing but a reference - xahlee is one of the worst internet troll ever. > Compare for instance the differences in ease of use, and speed of use, > of these: > > http://docs.python.org/library/functions.html#open > http://uk.php.net/manual/en/function.fopen.php Sorry but as far as I'm concerned, PHP doc sucks big time, and I find Javadoc-style stuff close to useless. (snip) > Has anyone else struggled while trying to learn the language? Not as far as I'm concerned. I found Python the easiest language to learn right from the beginning. Not to say the doc couldn't be improved, or that alternate documentations could help, but I never had any problem with it. From lists at asd-group.com Tue Nov 2 12:09:59 2010 From: lists at asd-group.com (John Bond) Date: Tue, 02 Nov 2010 16:09:59 +0000 Subject: Why this result with the re module In-Reply-To: <552223.15146.qm@web54201.mail.re2.yahoo.com> References: <552223.15146.qm@web54201.mail.re2.yahoo.com> Message-ID: <4CD037D7.7070408@asd-group.com> On 2/11/2010 12:19 PM, Yingjie Lan wrote: >> From: John Bond >> Subject: Re: Why this result with the re module > Firstly, thanks a lot for your patient explanation. > this time I have understood all your points perfectly. > > Secondly, I'd like to clarify some of my points, which > did not get through because of my poor presentation. > > I suggested findall return a tuple of re.MatchObject(s), > with each MatchObject instance representing a match. > This is consistent with the re.match() function anyway. > And it will eliminate the need of returning tuples, > and it is much more precise and information rich. > > If that's not possible, and a tuple must be returned, > then the whole match (not just subgroups) should > always be included as the first element in the tuple, > as that's group(0) or '\0'. Less surprise would arise. > > Finally, it seems to me the algo for findall is WRONG. > > To re.findall('(.a.)*', 'Mary has a lamb'), > by reason of greediness of '*', and the requirement > of non-overlapping, it should go like this > (suppose an '' is at the beginning and at the end, > and between two consecutive characters there is > one and only one empty string ''. To show the > match of empty strings clearly, > I am concatenating each repeated match below): > > Steps for re.findall('(.a.)*', 'Mary has a lamb'): > > step 1: Match '' + 'Mar' + '' (gready!) > step 2: skip 'y' > step 3: Match '' > step 4: skip ' ' > step 5: Match ''+'has'+' a '+'lam'+'' (greedy!) > step 6: skip 'b' > step 7: Match '' > > So there should be exactly 4 matches in total: > > 'Mar', '', 'has a lam', '' > > Also, the matches above shows > that if a repeated subgroup only captures > the last match, the subgroup (.a.)* > should always capture '' here (see steps > 1, 3, 5, 7) above. > > Yet the execution in Python results in 6 matches! > And, the capturing subgroup with repetition > sometimes got the wrong guy. > > So I believe the algorithm for findall must be WRONG. > > Regards, > > Yingjie At a guess, I'd say what is happening is something like this: Steps for re.findall('(.a.)*', 'Mary has a lamb'): step 1: Match 'Mar' at string index 0 step 2: Match '' at string index 3 (before 'y') step 3: skip 'y' step 4: Match '' at string index 4 (before ' ') step 5: skip ' ' step 6: Match 'has a lam' at string index 5 step 7: Match '' at string index 14 (before 'b') step 8: skip 'b' step 9: Match '' at string index 15 (before EOS) matches: ('Mar', '', '', 'has a lam', '', '') returns: ['Mar', '', '', 'lam', '', ''] (*) (*) "has a " lost due to not being last repetition at that match point Which seems about right to me! Greediness has nothing to do with it, except that it causes 'has a lam' to be matched in one match, instead of as three separate matches (of 'has', ' a ' and 'lam'). From tjreedy at udel.edu Tue Nov 2 12:57:59 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 02 Nov 2010 12:57:59 -0400 Subject: factorial of negative one (-1) In-Reply-To: <87vd4gm3vb.fsf@xemacs.org> References: <87r5f55qj5.fsf@xemacs.org> <87vd4gm3vb.fsf@xemacs.org> Message-ID: On 11/2/2010 6:11 AM, Hrvoje Niksic wrote: >>>> 1.1 .hex() > '0x1.199999999999ap+0' > > Here it is immediately obvious that the final digit of the infinite > sequence "1.1999..." is rounded from 9 to a. Printing the number with > any more digits would just reveal zeros, as expected. > > Does anyone know why Python doesn't accept hex float literals in source > code? Assuming that the parser would have no problem with them: 1. the format is relatively recent 2. you can write float.fromhex('') 3. it never occurred to anyone to do so 4. literals are values supplied by the programmer; hex float values are rare and when they do occur, they are usually the stored output of a previous .hex() in Python or similar in other languages. 5. too easy to confuse in quick reading with normal float literals 6. the format is a bit weird and too esoteric for most programmers; they should not be part of the basic syntax that everyone has to learn; someone who reads float.fromhex(something) can look it up. -- Terry Jan Reedy From tjreedy at udel.edu Tue Nov 2 13:16:27 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 02 Nov 2010 13:16:27 -0400 Subject: functions, list, default parameters In-Reply-To: References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <8ivelpFif1U1@mid.individual.net> <4cca88bc$0$29987$c3e8da3$5496439d@news.astraweb.com> <8j1seqFa1eU2@mid.individual.net> Message-ID: On 11/2/2010 3:12 AM, Lawrence D'Oliveiro wrote: >> "Immutable objects" are just those without an obvious API for modifying >> them. After initial creation ;-)/ > They are ones with NO legal language constructs for modifying them. Suppose I write an nasty C extension that mutates tuples. What then would be illegal about import tuple_mutator t = (1,2) tuple_mutator.inc(t) t # (2,3) > Hint: if > a selector of some part of such an object were to occur on the LHS of an > assignment, and that would raise an error, then the object is immutable. I am not sure what you are saying here, and how it applies to >>> lt = [(0,)] >>> lt[0][0] = 1 Traceback (most recent call last): File "", line 1, in lt[0][0] = 1 TypeError: 'tuple' object does not support item assignment >>> tl = ([0],) >>> tl[0][0] = 1 >>> tl ([1],) -- Terry Jan Reedy From robert.kern at gmail.com Tue Nov 2 13:24:44 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 02 Nov 2010 12:24:44 -0500 Subject: functions, list, default parameters In-Reply-To: References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <8ivelpFif1U1@mid.individual.net> <4cca88bc$0$29987$c3e8da3$5496439d@news.astraweb.com> <8j1seqFa1eU2@mid.individual.net> Message-ID: On 11/2/10 2:12 AM, Lawrence D'Oliveiro wrote: > In message, Robert Kern > wrote: > >> On 2010-11-01 22:31 , Lawrence D'Oliveiro wrote: >> >>> In message<8j1seqFa1eU2 at mid.individual.net>, Gregory Ewing wrote: >>> >>>> Steven D'Aprano wrote: >>>> >>>>> And how does Python know whether some arbitrary default object is >>>>> mutable or not? >>>> >>>> It doesn't, that's the whole point. >>> >>> Of course it knows. It is the one defining the concept in the first >>> place, after all. >> >> No, the Python interpreter doesn't define the concept. The Python language >> developers did. > > The Python language developers said ?let there be light?, and the Python > interpreter gave forth light. So which one defines the concept of ?light?? I'm sorry, but that's not even a meaningful reply. They said no such thing and the interpreter does no such thing. Let's talk about things the developers did say and the things the interpreter does do, shall we? The Python language developers defined the concept of mutable objects. However, they defined it in human terms, not algorithmic ones. They did not imbue the interpreter with a way of determining immutability. >> "Immutable objects" are just those without an obvious API for modifying >> them. > > They are ones with NO legal language constructs for modifying them. Hint: if > a selector of some part of such an object were to occur on the LHS of an > assignment, and that would raise an error, then the object is immutable. The > interpreter already knows all this. Incorrect. RHS method calls can often modify objects. set.add() mutates the set even though it does not have the usual LHS mutation methods like .__setitem__(). And even among the LHS APIs, raising an error does not determine immutability. int.__iadd__() does not raise an error, but ints are still immutable. list.__iadd__() does not raise an error, and lists are mutable. And even if it were reliable, how would the interpreter know what arguments to pass? list.__iadd__() doesn't work for any object. And why do you think that testing mutability in such a way would be safe since attempting those would necessarily alter the object if it is mutable? Show me the algorithm that the interpreter can use to determine whether or not an object is mutable. Or better, since you think the interpreter already knows this, show me the implementation in the interpreter's source code. >> With various trickeries, I can mutate any immutable object. > > None within the Python language itself. Which is what we?re talking about > here: a language construct which is probably one of the top 3 sources of > grief to Python newbies. And not-so-newbies. "import ctypes" is within the Python language. -- 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 ian.g.kelly at gmail.com Tue Nov 2 13:34:27 2010 From: ian.g.kelly at gmail.com (Ian) Date: Tue, 2 Nov 2010 10:34:27 -0700 (PDT) Subject: functions, list, default parameters References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <4cc13ef5$0$29979$c3e8da3$5496439d@news.astraweb.com> <4ccffd1c$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5f6eceec-1eef-4db7-82a6-e5f553349229@k22g2000yqh.googlegroups.com> On Nov 2, 5:59?am, Steven D'Aprano wrote: > Certainly it's the mediocre programmers who seem to be incapable of > understanding that Python has no way of telling whether arbitrary objects > are mutable or not. > > def foo(x, y=list()): > ? ? pass > > Is y a mutabledefaultor not? > > For the benefit of any mediocre programmers out there, be careful before > you answer. This *is* a trick question. I fail to see your point. You might as well argue that Python has no way of knowing whether it should raise a TypeError in the following example: my_tuple = (1, 2, 3) + list(xrange(4, 7)) Dynamic typing means that these sorts of checks must be delayed until runtime, but that doesn't make them useless or impossible. It seems to me that there is a rather simple case to be made for allowing mutable default arguments: instances of user-defined classes are fundamentally mutable. Disallowing mutable default arguments would mean disallowing instances of user-defined classes entirely. That would be excessive and would violate Python's general rule of staying out of the programmer's way. Cheers, Ian From paul.nospam at rudin.co.uk Tue Nov 2 13:45:46 2010 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Tue, 02 Nov 2010 17:45:46 +0000 Subject: functions, list, default parameters References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <8ivelpFif1U1@mid.individual.net> <4cca88bc$0$29987$c3e8da3$5496439d@news.astraweb.com> <8j1seqFa1eU2@mid.individual.net> Message-ID: <87tyjzippx.fsf@rudin.co.uk> Terry Reedy writes: > Suppose I write an nasty C extension that mutates tuples. What then > would be illegal about... Depends on exactly what we mean by legal. If immutability is part of the language spec (rather than an artifact of a particular implementation) then a compiler could assume immutability. From tjreedy at udel.edu Tue Nov 2 13:47:07 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 02 Nov 2010 13:47:07 -0400 Subject: Python documentation too difficult for beginners In-Reply-To: References: Message-ID: On 11/2/2010 6:42 AM, jk wrote: > Compare for instance the differences in ease of use, and speed of use, > of these: > > http://docs.python.org/library/functions.html#open > http://uk.php.net/manual/en/function.fopen.php > > The former is difficult to find (try searching for 'open' in the > search box and see what you get). duh. 'open' is a common word and if you make an unstructured search for it in all text, you should get a lot of hits. The Python docs have both a Global Module Index (which I use constantly) and a General Index of functions (methods), classes, and terms. Learn to use them. If you look in the [o] section for 'open', the first entry is "open() (built-in function)" -- just what you were looking for. There are also about 30 more nicely labelled entries for 'open' in various modules. > It is simply a collection of > paragraphs without strong enough contrast to differentiate the > different parts - parameters, parameter values, return types, > exceptions and related functions. It is slow to read and doesn't allow > easy visual scanning. It is possible that this particular entry could be improved. > Is there much chance that the Python maintainers will change their > documentation system to make it more like Java or PHP? There are plans to make doc feedback from users easier. -- Terry Jan Reedy From nagle at animats.com Tue Nov 2 13:54:46 2010 From: nagle at animats.com (John Nagle) Date: Tue, 02 Nov 2010 10:54:46 -0700 Subject: Python equivalent of SOAP-ISIWoK In-Reply-To: References: Message-ID: <4cd05064$0$1662$742ec2ed@news.sonic.net> On 11/2/2010 1:58 AM, Johann Spies wrote: > SOAP-ISIWoK is a Perl library for assessing Thomson Reuters Web of > Knowledge Web Services. I don't know Perl well enough to use that > library without spending too much time on it. > > Is there a Python equivalent available? The "Suds" library can call SOAP interfaces, and is not difficult to use. https://fedorahosted.org/suds/ > > Regards > Johann > -- > May grace and peace be yours in abundance through the full knowledge > of God and of Jesus our Lord! His divine power has given us > everything we need for life and godliness through the full knowledge > of the one who called us by his own glory and excellence. > 2 Pet. 1:2b,3a God helps those who help themselves. Benj. Franklin From usenet-nospam at seebs.net Tue Nov 2 13:58:06 2010 From: usenet-nospam at seebs.net (Seebs) Date: 02 Nov 2010 17:58:06 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: On 2010-11-02, D'Arcy J.M. Cain wrote: > You have problems. Indentation as syntax isn't one of them. In the absence of indentation as syntax, they haven't bugged me. > "No one > knows why" email is being "magically" transformed? Yay for a large company IT department with both MS and Blackberry stuff involved. > Your editor has a > mind of its own? Yikes! It is extremely useful to me to have spaces converted to tabs for every other file I edit. >> I've lost more time to indentation issues in Python in a month than >> I've lost to mismatches between indentation and flow in C in twenty > Your experience is 180 from mine. Could be. But really, I've simply never seen a real problem with flow/indentation mismatches in C. >> At least in C, if I see: >> if (foo) >> a; >> else >> b; >> c; >> >> I *know* that something is wrong. > Does it look right? With Python looking right and being right are the > same thing. No, they aren't. See... That would work *if I knew for sure what the intent was*. if foo: bar else: baz quux Does it look right? We have *no idea*, because we don't actually know whether quux was *intended* to be in the else branch or whether that's a typo. So the only way I can figure that out is by fully figuring out the function of all the code bits -- meaning I have to fully understand the code, same as I would to debug the C. The fact that indentation is flow control just means I have only one set of cues, so I can't watch for mismatches. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From hobson42 at gmaiil.com Tue Nov 2 14:07:15 2010 From: hobson42 at gmaiil.com (Ian) Date: Tue, 02 Nov 2010 18:07:15 +0000 Subject: Python documentation too difficult for beginners In-Reply-To: <024ef21a-9ef9-48a6-8372-1d66895583c3@v16g2000yqn.googlegroups.com> References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> <024ef21a-9ef9-48a6-8372-1d66895583c3@v16g2000yqn.googlegroups.com> Message-ID: <4CD05353.1040002@gmaiil.com> On 02/11/2010 14:47, jk wrote: > I think the key difference is that I don't want to have to*read* the > python docs - I want to be able to scan for what I'm looking for and > find it easily. That makes me productive. Hi jk, I totally agree. But you will get nowhere. A few weeks back I complained that http://docs.python.org/reference/executionmodel.html#naming-and-binding was more than a little opaque - and was not understood by Python noobs such as myself. I was invited to rewrite it and submit an improved version. Remember I said I was a noob and did not understand it. Just how can I rewrite it from that base? But I'm sure that the trouble is with me. It is clear from this statement (rom that page)... "If a name binding operation occurs anywhere within a code block, all uses of the name within the block are treated as references to the current block." that, (in the given situation), name binding does not bind a name to a variable but to a block. Just for the record, I really know it is not me. English is my mother tongue, and I have some programming experience, in a variety of languages. I wrote my first program in 1964, and have been earning a living programming since '74. I have used Cobol, Lisp, Smalltalk, C, Javascript, Notes, PHP and many other languages in a commercial environment over the last 36 (good gracious!) years. This lack of documentation is almost universal. You will have heard of the "with batteries" tag. This means that, whatever you want to do, there are usually many libraries available to help you do it. Every one will be poorly documented and most are hard to find. Yes there are batteries - but it is not clear which is more productive: write what is needed from scratch, or investigate what "batteries" are available and risk finding that the one you chose is missing some important feature down the line? Observe though that having poor introductory documentation sells a lot of "How to Program in Python" type books. Its sad really. Python is a great little language, and deserves better. Without an on-ramp, noobs will struggle to get on the freeway. And yet, enough will get on, that these pleas for better documentation can be ignored by those who know and could do something about it. Regards Ian -------------- next part -------------- An HTML attachment was scrubbed... URL: From usenet-nospam at seebs.net Tue Nov 2 14:10:48 2010 From: usenet-nospam at seebs.net (Seebs) Date: 02 Nov 2010 18:10:48 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-02, Steven D'Aprano wrote: > I've lost more time to reading people's bitching about indentation than I > have dealing with indentation problems. Doesn't totally surprise me. :) > But then, I don't insist on using tools which are broken by design. Neither do I. > If your email server converts plain text to HTML, it is broken. Yup. I have an open ticket with the IT department. :) > If your > editor changes spaces to tabs, or visa versa, without being told to do so > (either by an explicit command or an obvious setting), then your editor > is broken. Yes. But that's the thing -- I *want* that behavior for every other tool, file format, or other thing I work with. > If you are stuck with broken mail servers and broken editors and broken > tools because of political reasons, then you have my sympathy. But stop > insisting that everybody has to carry the overhead of your work-arounds > for your broken tools. I have made no such insistance. I have not said Python should change. I have not said other people should want what I want. I'm not the one telling other people that editors they've used happily for twenty years without any problems are clearly wrong. I have merely observed that Python is, in this respect, gratuitously brittle. It doesn't observe the robustness principle; it is conservative in what it accepts, and in particular, is vulnerable to a category of problem which is fairly common, well-known, and likely to remain common for the next few decades. There are reasons for it to be this way, and I don't object to the existence of people who prefer that side of the tradeoff. I do dislike it when people smugly tell me off for having different preferences. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From invalid at invalid.invalid Tue Nov 2 14:15:03 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 2 Nov 2010 18:15:03 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: On 2010-11-02, Seebs wrote: > On 2010-11-02, D'Arcy J.M. Cain wrote: >> You have problems. Indentation as syntax isn't one of them. > > In the absence of indentation as syntax, they haven't bugged me. > >> "No one >> knows why" email is being "magically" transformed? > > Yay for a large company IT department with both MS and Blackberry > stuff involved. > >> Your editor has a >> mind of its own? Yikes! > > It is extremely useful to me to have spaces converted to tabs > for every other file I edit. > >>> I've lost more time to indentation issues in Python in a month than >>> I've lost to mismatches between indentation and flow in C in twenty > >> Your experience is 180 from mine. > > Could be. But really, I've simply never seen a real problem with > flow/indentation mismatches in C. > >>> At least in C, if I see: >>> if (foo) >>> a; >>> else >>> b; >>> c; >>> >>> I *know* that something is wrong. > >> Does it look right? With Python looking right and being right are the >> same thing. > > No, they aren't. See... That would work *if I knew for sure what the intent > was*. > > if foo: > bar > else: > baz > quux > > Does it look right? We have *no idea*, because we don't actually know > whether quux was *intended* to be in the else branch or whether that's a typo. > > So the only way I can figure that out is by fully figuring out the function > of all the code bits -- meaning I have to fully understand the code, same > as I would to debug the C. The fact that indentation is flow control > just means I have only one set of cues, so I can't watch for mismatches. You can add redundant, semantically empty structure info to Python programs just as easily as you can to C programs: if foo: bar else: baz quux #endif -- Grant Edwards grant.b.edwards Yow! With YOU, I can be at MYSELF ... We don't NEED gmail.com Dan Rather ... From emile at fenx.com Tue Nov 2 14:18:50 2010 From: emile at fenx.com (Emile van Sebille) Date: Tue, 02 Nov 2010 11:18:50 -0700 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: On 11/2/2010 10:58 AM Seebs said... > No, they aren't. See... That would work *if I knew for sure what the intent > was*. > > if foo: > bar > else: > baz > quux > > Does it look right? We have *no idea*, because we don't actually know > whether quux was *intended* to be in the else branch or whether that's a typo. What is right is that there's no question that quux is subsequent to baz in all cases barring exceptions (and assuming no tabs intermixed) The apparent structure in python _is_ the structure, whereas otherwise you've got to count your ;'s and {}'s etc to determine and verify the structure matches the apparent structure provided by the programmer. Whether that's what the specs called for or not is always a source for bugs. Emile From invalid at invalid.invalid Tue Nov 2 14:22:57 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 2 Nov 2010 18:22:57 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: On 2010-11-02, Emile van Sebille wrote: > On 11/2/2010 10:58 AM Seebs said... >> No, they aren't. See... That would work *if I knew for sure what the intent >> was*. >> >> if foo: >> bar >> else: >> baz >> quux >> >> Does it look right? We have *no idea*, because we don't actually know >> whether quux was *intended* to be in the else branch or whether that's a typo. > > What is right is that there's no question that quux is subsequent to baz > in all cases barring exceptions (and assuming no tabs intermixed) > > The apparent structure in python _is_ the structure, whereas otherwise > you've got to count your ;'s and {}'s etc to determine and verify the > structure matches the apparent structure provided by the programmer. > > Whether that's what the specs called for or not is always a source > for bugs. Yup. I've never found that the ability to write incorrect code that _appears_ correct to be a good thing. Nor do I find the ability to write correct code that appears to be incorrect to be valuable. In Python, if the structure looks right, then structure _is_ right. -- Grant Edwards grant.b.edwards Yow! Now we can become at alcoholics! gmail.com From darcy at druid.net Tue Nov 2 14:37:40 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 2 Nov 2010 14:37:40 -0400 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: <20101102143740.603f2769.darcy@druid.net> On 02 Nov 2010 17:58:06 GMT Seebs wrote: > On 2010-11-02, D'Arcy J.M. Cain wrote: > > "No one > > knows why" email is being "magically" transformed? > > Yay for a large company IT department with both MS and Blackberry > stuff involved. "Large" is no excuse for incompetency. > > Your editor has a > > mind of its own? Yikes! > > It is extremely useful to me to have spaces converted to tabs > for every other file I edit. So configure it to recognize Python files and act accordingly. > No, they aren't. See... That would work *if I knew for sure what the intent > was*. > > if foo: > bar > else: > baz > quux > > Does it look right? We have *no idea*, because we don't actually know > whether quux was *intended* to be in the else branch or whether that's a typo. And C has the same problem. if (foo) bar; else baz; quux; Is quux meant to be part of the else clause? The writer's indentation suggests "yes" but the code says "no". > So the only way I can figure that out is by fully figuring out the function Same is true for the C code. In both cases you can tell what the code will do (modulo weird macros in the C code) but the intention is impossible to determine without mind reading abilities in both cases. We do know that the Python code *appears* to be doing exactly what the author intended and the C code *appears* to not be. In either case, != . -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From darcy at druid.net Tue Nov 2 14:42:14 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 2 Nov 2010 14:42:14 -0400 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: <20101102144214.23f3b738.darcy@druid.net> On Tue, 2 Nov 2010 18:15:03 +0000 (UTC) Grant Edwards wrote: > You can add redundant, semantically empty structure info to Python > programs just as easily as you can to C programs: > > if foo: > bar > else: > baz > quux > #endif "Redundant" is right. However, there is a use for such comments: if foo: bar else: baz if snafu: cookie #endif snafu quux #endif foo Useful in more complicated code, of course. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From usernet at ilthio.net Tue Nov 2 14:43:08 2010 From: usernet at ilthio.net (Tim Harig) Date: Tue, 2 Nov 2010 18:43:08 +0000 (UTC) Subject: Python documentation too difficult for beginners References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> <024ef21a-9ef9-48a6-8372-1d66895583c3@v16g2000yqn.googlegroups.com> Message-ID: On 2010-11-02, jk wrote: > As for the 9 paragraphs statement, there's a usability book that > applies here - it's called "Don't make me think". I shouldn't have to Anything that promotes a lack of thinking sends up red flags in my head. We want to recruit smart people who think, not idiots. > go through freeform text to find what I'm looking for when a list > would make that information easier to find. And splitting the docs > into sections would allow me to skip to what I'm looking for. I really > would be much happier with your example documentation. ctrl-f will bring up a search dialog in most graphical browsers. '/' will in many others. With some practice, your fingers will be able to find something far faster then your eyes can see it happen. There is a religious war in the GNU community between info page as documentation versus the traditional manual format. The manual format contains all of the information on one page that can be easily searched whereas the info pages are split into sections that must be viewed individually. With the man pages, you can almost always find what you want with a quick search through the document. Info pages are much harder to use because you have to try and figure out which section the author decided to place the information that you are looking for. The information may be stored several levels deep, which means that it can be a deep productivity hit if you don't guess the proper location on the first try. > I think the key difference is that I don't want to have to *read* the > python docs - I want to be able to scan for what I'm looking for and > find it easily. That makes me productive. The real question is what do you want to gain by your posts here. You should already know that most groups are, by their very nature, slow to make changes to the status quo. The problem tends to be exasperated in open source projects where any changes mean that people have to donate their time to make anything happen. You will in general find two things to be true: 1. Since they are dontating their time, you will find that people tend to scratch their own iches first. 2. People who do take the time to contribute to open source projects are people of action. They don't tend to be appreciative of those who constantly generate feature requests but have no inclination to do any of the work themselves. They do appreciate other people of action who are interested in making the project better. Therefore, if you truly want changes in the documentation, I suggest that, rather then whining to the group, you make some of the changes yourself. When you are finished, you can post a link to your alternate documentation to this group. If you documentation is truly better then the existing documentation, you will not have to say another word. People within the community will rally around it and promote it. If it gains wide enough support, then there will be a movement to use it to supplant the existing documentation. It is the difference between whining from the sidelines and actively participating in the game. From ian.g.kelly at gmail.com Tue Nov 2 14:51:42 2010 From: ian.g.kelly at gmail.com (Ian) Date: Tue, 2 Nov 2010 11:51:42 -0700 (PDT) Subject: Python documentation too difficult for beginners References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> <024ef21a-9ef9-48a6-8372-1d66895583c3@v16g2000yqn.googlegroups.com> Message-ID: <7be6c287-dd46-4931-8d26-d1aef1a1df23@p1g2000yqm.googlegroups.com> On Nov 2, 8:47?am, jk wrote: > You're right in that the python docs in this case are less lines, but > that's one of the problems. It doesn't mention anywhere the extra > detail you've added regarding exceptions thrown. That's the kind of > thing that probably comes through experience or some kind of > convention which isn't obvious to beginners. Having things split into > sections - parameters, return types, exceptions, etc - lets me find > what I'm looking for quickly. It doesn't mention it because those exceptions don't actually have anything to do with the id() function. They're just what happens any time an unbound variable name is evaluated, in any context. The exact same thing could be said about any Python function in existence that takes at least one argument. Cheers, Ian From kee at kagi.com Tue Nov 2 14:56:57 2010 From: kee at kagi.com (Kee Nethery) Date: Tue, 2 Nov 2010 11:56:57 -0700 Subject: Python documentation too difficult for beginners In-Reply-To: <4CD05353.1040002@gmaiil.com> References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> <024ef21a-9ef9-48a6-8372-1d66895583c3@v16g2000yqn.googlegroups.com> <4CD05353.1040002@gmaiil.com> Message-ID: On Nov 2, 2010, at 11:07 AM, Ian wrote: > On 02/11/2010 14:47, jk wrote: >> I think the key difference is that I don't want to have to *read* >> the >> python docs - I want to be able to scan for what I'm looking for and >> find it easily. That makes me productive. >> > Hi jk, > > I totally agree. But you will get nowhere. > > A few weeks back I complained that > http://docs.python.org/reference/executionmodel.html#naming-and-binding > was more than a little opaque - and was not understood by Python noobs such as myself. > > I was invited to rewrite it and submit an improved version. In this world of moderated wikis one would think that noobs such as myself could enhance the docs when we find something confusing in the docs. Kee From tlikonen at iki.fi Tue Nov 2 15:04:05 2010 From: tlikonen at iki.fi (Teemu Likonen) Date: Tue, 02 Nov 2010 21:04:05 +0200 Subject: Man pages and info pages (was: Python documentation too difficult for beginners) References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> <024ef21a-9ef9-48a6-8372-1d66895583c3@v16g2000yqn.googlegroups.com> Message-ID: <87zktr5yze.fsf_-_@mithlond.arda> * 2010-11-02 18:43 (UTC), Tim Harig wrote: > The manual format contains all of the information on one page that can > be easily searched whereas the info pages are split into sections that > must be viewed individually. With the man pages, you can almost always > find what you want with a quick search through the document. Info > pages are much harder to use because you have to try and figure out > which section the author decided to place the information that you are > looking for. There is also the problem that people are less familiar with info browsers than the usual "less" pager which is used by "man" command. With the text terminal info browser called "info" as well as Emacs' info browser you can use command "s" (stands for "search"). It prompts for a regexp pattern to search in the whole document, including subsections etc. From nagle at animats.com Tue Nov 2 15:04:39 2010 From: nagle at animats.com (John Nagle) Date: Tue, 02 Nov 2010 12:04:39 -0700 Subject: Python documentation too difficult for beginners In-Reply-To: <871v73kc9d.fsf@rudin.co.uk> References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> <871v73kc9d.fsf@rudin.co.uk> Message-ID: <4cd060c5$0$1633$742ec2ed@news.sonic.net> On 11/2/2010 7:53 AM, Paul Rudin wrote: > Steven D'Aprano writes: > >> A fair point -- the built-in open comes up as hit #30, whereas searching >> for open in the PHP page brings up fopen as hit #1. But the PHP search >> also brings up many, many hits -- ten pages worth. >> > > OTOH googling for "python open" gives you the correct (for 2.7) page as > hit #1 - although you then have to use your browser's "find" facilty to > actually get to the description of the function in question. Right. Google does a far better job of organizing Python's documentation than the Python community does. I don't even try looking up anything starting at Python.org; I always start with a Google search. Even though Python.org's search is powered by Google, it's inferior to a general search. Compare: http://www.google.com/search?domains=www.python.org&sitesearch=www.python.org&q=open http://www.google.com/search?q=Python+open John Nagle From ethan at stoneleaf.us Tue Nov 2 15:08:34 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 02 Nov 2010 12:08:34 -0700 Subject: Compare source code In-Reply-To: <4ccfefc6$0$29966$c3e8da3$5496439d@news.astraweb.com> References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccfefc6$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4CD061B2.6040404@stoneleaf.us> Steven D'Aprano wrote: > Personally, I'm more disturbed by the default prompt in the interactive > interpreter. >>> clashes with the symbol used for quoting text in email > and news. That causes me far more distress than indentation. Here here! I finally did "sys.ps1 = '--> '" in my interactive startup file. :) ~Ethan~ From gdamjan at gmail.com Tue Nov 2 15:15:36 2010 From: gdamjan at gmail.com (=?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLRgdC60Lg=?=) Date: Tue, 02 Nov 2010 20:15:36 +0100 Subject: ANN: PyQt v4.8.1 Released References: Message-ID: >> PyQt is available under the GPL and a commercial license. > > Surely you mean ?proprietary? rather than ?commercial?. There is > nothing about the GPL that prevents ?commercial? use. I think he means a license that *he* sells comercially :) -- ?????? ((( http://damjan.softver.org.mk/ ))) Religion ends and philosophy begins, just as alchemy ends and chemistry begins and astrology ends, and astronomy begins. From usenet-nospam at seebs.net Tue Nov 2 15:24:44 2010 From: usenet-nospam at seebs.net (Seebs) Date: 02 Nov 2010 19:24:44 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <8j8udgFlkvU1@mid.individual.net> Message-ID: On 2010-11-02, Grant Edwards wrote: > True, but the fact that diff has an option that for Python sources > will produces useless results doesn't seem like a valid indictment of > Python's syntax and semantics. The question is *why* diff has that option. The answer is because whitespace changes (spaces to tabs, different tab stops, etcetera) are an extremely common failure mode, such that it's quite common for files to end up with unintentional whitespace changes. This, in turn, is why there are so many tools to automatically fix up whitespace type issues, such as cb/indent for C, auto-indentation for many languages (including stuff like XML) features in editors, and so on -- because it's a common problem. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usernet at ilthio.net Tue Nov 2 15:26:56 2010 From: usernet at ilthio.net (Tim Harig) Date: Tue, 2 Nov 2010 19:26:56 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-02, Seebs wrote: > On 2010-11-02, Steven D'Aprano wrote: >> If your >> editor changes spaces to tabs, or visa versa, without being told to do so >> (either by an explicit command or an obvious setting), then your editor >> is broken. > > Yes. But that's the thing -- I *want* that behavior for every other tool, > file format, or other thing I work with. I agree with Seebs, Python is the only language I know that promotes the use of spaces over tabs; and there are equally picky syntaxs (ie, Makefiles) that mandate the use of tabs. I personally prefer tabs as it lets *me* decide how far the apparent indentations are in the code. You may like four spaces; but, I agree with Linus Torvalds that eight spaces is much clearer. The beautiful thing about tabs is that we can both set our tab stops to match our own viewing preferences. >> If you are stuck with broken mail servers and broken editors and broken >> tools because of political reasons, then you have my sympathy. But stop >> insisting that everybody has to carry the overhead of your work-arounds >> for your broken tools. > > I have made no such insistance. I have not said Python should change. I > have not said other people should want what I want. I'm not the one telling > other people that editors they've used happily for twenty years without > any problems are clearly wrong. Indeed, a simple script is enough to identify how levels are indented and convert the present indenting to whatever is your preference. > There are reasons for it to be this way, and I don't object to the > existence of people who prefer that side of the tradeoff. I do dislike > it when people smugly tell me off for having different preferences. This is Python's most noticable blemish outside of the community. Everybody knows that Python is the language that forces you to use a particular style of formatting; and, that is a turn-off for many people. It is a big mistake that whenever the issue arises, the community effectively attacks anybody who might have disagreements with the tradeoffs made for the Python language. This tends to set people on the defensive and gives them a bad taste about the language as a whole. It would be much better if the community would simply acknowledge that this is a tradeoff the the language has made and one which is often misunderstood by many first time Python programmers. Then it is possible transition to Python's strengths. Don't simply ignore that there *are* potential downfalls to this approach. From usenet-nospam at seebs.net Tue Nov 2 15:28:05 2010 From: usenet-nospam at seebs.net (Seebs) Date: 02 Nov 2010 19:28:05 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: On 2010-11-02, Grant Edwards wrote: > And you think compatibility with your broken e-mail server is a good > reason to change the syntax of a programming language? No. I never said that. >> Many editors helpfully convert spaces to tabs by default some or all >> of the time. And so on. > Such editors are broken. If I use an editor for twenty years, and it works beautifully with fifteen different programming languages across five operating systems, and someone comes along with a file format which tends to silently break when treated the same way, my first response is not to blame the editor. > I think it's brilliant (indentation that actually means something, not > scanf). It is. However, it's also brittle. >> The "problem" it fixes is something that's hardly ever been a problem >> for me in C or related languages -- and which could be completely >> eliminated by automated indenters, which were actually conceptually >> possible. > They're only possible if you put redundant block markers in the > source. Yes. Or make the block markers not-redundant. > Then you're doing something terribly wrong. I find indentation-based > structure to be completely effortless. And it is *ABSOLUTELY CERTAIN* that, if any two people have different experiences of how easy or hard something is, it's because one of them is doing something wrong, right? Because people are *never* actually different. There is no such thing as "preferences". There is no such thing as a "matter of taste". No, no. If one person finds something comfortable, and another dislikes it, it's because the second one is *doing something terribly wrong*. > Are you using an editor that > doesn't have a Python mode? Yes. I haven't used "modes" in editors until now. I've never needed to. Every other file format I work with is robust about this. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usernet at ilthio.net Tue Nov 2 15:36:11 2010 From: usernet at ilthio.net (Tim Harig) Date: Tue, 2 Nov 2010 19:36:11 +0000 (UTC) Subject: Man pages and info pages (was: Python documentation too difficult for beginners) References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> <024ef21a-9ef9-48a6-8372-1d66895583c3@v16g2000yqn.googlegroups.com> <87zktr5yze.fsf_-_@mithlond.arda> Message-ID: On 2010-11-02, Teemu Likonen wrote: > * 2010-11-02 18:43 (UTC), Tim Harig wrote: > >> The manual format contains all of the information on one page that can >> be easily searched whereas the info pages are split into sections that >> must be viewed individually. With the man pages, you can almost always >> find what you want with a quick search through the document. Info >> pages are much harder to use because you have to try and figure out >> which section the author decided to place the information that you are >> looking for. > > There is also the problem that people are less familiar with info > browsers than the usual "less" pager which is used by "man" command. I thoroughly agree. The default info viewers are quite possibly the most counterintuitive programs I have ever encountered. I never did bother to learn how to use them. I instead installed the more intuitive pinfo program. > With the text terminal info browser called "info" as well as Emacs' info > browser you can use command "s" (stands for "search"). It prompts for a > regexp pattern to search in the whole document, including subsections > etc. Right, pinfo offers this as well; but, then you have to figure out where in the nodes that the search has taken you and how to navigate from that node to find additional information that you may need. I have, in general, come to think of info pages as a failed experiment and I know very few people who actually prefer them over the simpler man pages. From rustompmody at gmail.com Tue Nov 2 15:38:45 2010 From: rustompmody at gmail.com (rustom) Date: Tue, 2 Nov 2010 12:38:45 -0700 (PDT) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> Message-ID: <20472710-e3ac-4e61-8d1a-1822d7702cd3@j25g2000yqa.googlegroups.com> Sigh! How flame-wars tend to lose the original question: On Oct 31, 5:02?pm, jf wrote: > Hi, > > I've a project with tabs and spaces mixed (yes I know it's bad). Do python aficionados want to suggest that mixing spaces and tabs is a 'good thing'? From lists at asd-group.com Tue Nov 2 15:48:35 2010 From: lists at asd-group.com (John Bond) Date: Tue, 02 Nov 2010 19:48:35 +0000 Subject: Ways of accessing this mailing list? Message-ID: <4CD06B13.3040008@asd-group.com> Hope this isn't too O/T - I was just wondering how people read/send to this mailing list, eg. normal email client, gmane, some other software or online service? My normal inbox is getting unmanageable, and I think I need to find a new way of following this and other lists. Thanks for any suggestions. Cheers, JB. From usernet at ilthio.net Tue Nov 2 16:02:02 2010 From: usernet at ilthio.net (Tim Harig) Date: Tue, 2 Nov 2010 20:02:02 +0000 (UTC) Subject: Man pages and info pages (was: Python documentation too difficult for beginners) References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> <024ef21a-9ef9-48a6-8372-1d66895583c3@v16g2000yqn.googlegroups.com> <87zktr5yze.fsf_-_@mithlond.arda> Message-ID: On 2010-11-02, Tim Harig wrote: > On 2010-11-02, Teemu Likonen wrote: >> With the text terminal info browser called "info" as well as Emacs' info >> browser you can use command "s" (stands for "search"). It prompts for a >> regexp pattern to search in the whole document, including subsections >> etc. > > Right, pinfo offers this as well; but, then you have to figure out where in > the nodes that the search has taken you and how to navigate from that node > to find additional information that you may need. I have, in general, come > to think of info pages as a failed experiment and I know very few people > who actually prefer them over the simpler man pages. I should add two more things here: 1. Another confusing aspect of the info pages is that you often have to know what package a command came from or you don't get the information that you are looking for. 2. Series of man pages can be used in a way that seem like they have a structure as they can effectively link to other pages. If I open one of the ncurses man pages in pinfo, I can follow what seem like links to other man pages. I can open the main curses page and I effectively get an index to all of the other curses functions. From invalid at invalid.invalid Tue Nov 2 16:11:23 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 2 Nov 2010 20:11:23 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccfefc6$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-02, Ethan Furman wrote: > Steven D'Aprano wrote: >> Personally, I'm more disturbed by the default prompt in the interactive >> interpreter. >>> clashes with the symbol used for quoting text in email >> and news. That causes me far more distress than indentation. > > Here here! > > I finally did "sys.ps1 = '--> '" in my interactive startup file. :) So _now_ what are going to whinge about? -- Grant Edwards grant.b.edwards Yow! I am NOT a nut.... at gmail.com From smallpox911 at gmail.com Tue Nov 2 16:39:04 2010 From: smallpox911 at gmail.com (small Pox) Date: Tue, 2 Nov 2010 13:39:04 -0700 (PDT) Subject: *** FBI gets a warm welcome in Chicago for their EXCELLENTperformance - cheers to NEW CONS *** References: <26f97f70-9043-490c-9e6e-35159f38d76b@r29g2000yqj.googlegroups.com> Message-ID: <47e0b3a3-54fb-4489-95a8-b5ec6015c99d@j25g2000yqa.googlegroups.com> If you want to act like a NETCOP then you must identify yourself and your organization or else you are considered a FACELESS COWARD CRIMINAL whose sole intent is to carry out CENSORSHIP of truth. Unless you ACTIVELY apply the same PURSUIT to ALL OTHER IRRELEVANT postings, you will be considered a STALKER, A CRIMINAL, A RACIST, A CENSORER, and SUPPRESSOR OF TRUTH and PARTNER CRIMINAL in the CRIME WE ARE TRYING TO EXPOSE. On Nov 1, 6:35 pm, Chris Rebert wrote: - Hide quoted text - - Show quoted text - > > -----Original Message----- > > From: silver light > > Sender: python-list-bounces+brf256=gmail.... at python.org > > Date: Mon, 1 Nov 2010 18:10:36 > > To: > > Cc: > > Subject: *** FBI gets a warm welcome in Chicago for their EXCELLENT > > performance - cheers to NEW CONS *** > > *** FBI gets a warm welcome in Chicago for their EXCELLENT performance > > - cheers to NEW CONS *** > > On Mon, Nov 1, 2010 at 6:21 PM, wrote: > > How exactly does this relate to python? > It doesn't. It's spam that was apparently also cross-posted to > sci.math, sci.physics, comp.text.tex, and comp.unix.shell. IT IS MOST CERTAINLY NOTTTTTT a SPAM. THIS FBI CENSORSHIP MOTHER FOCKER is the REAL SPAMMER AND CRIMINAL who wants to limit the news of their HEINOUS CRIMES and INCOMPETENCE to be SPREAD. The fact is that the real spammers are those who post PORNOGRAPHIC and COMMERCIAL messages on which the FBI CIA BLACKWATER and MOSSAD mother fockers masterbate and rape their mothers daily. AND NEVER SPEAK OUT. The truth of 911 bites them like the sting of a snake and truth it is. - Hide quoted text - - Show quoted text - > I advise reporting the sender, lightsilv... at gmail.com, to Gmail's abuse team:http://mail.google.com/support/bin/request.py?contact_type=abuse > Cheers, > Chris On Nov 2, 1:12?am, Seebs wrote: > On 2010-11-02, brf... at gmail.com wrote: > > > How exactly does this relate to python? > > 1. ?It doesn't. ?It's spam. ?Duh. > 2. ?Don't respond to spam. > 3. ?Don't top-post. > 4. ?If I see even one more post from you where the entire previous post > is quoted under your text, I will plonk you. ?I warn you now because > most posters will do the same thing, and you will get very lonely > once no one bothers to read your posts. > > -s > -- > Copyright 2010, all wrongs reversed. ?Peter Seebach / usenet-nos... at seebs.nethttp://www.seebs.net/log/<-- lawsuits, religion, and funny pictureshttp://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! > I am not speaking for my employer, although they do rent some of my opinions. If you want to act like a NETCOP then you must identify yourself and your organization or else you are considered a FACELESS COWARD CRIMINAL whose sole intent is to carry out CENSORSHIP of truth. Unless you ACTIVELY apply the same PURSUIT to ALL OTHER IRRELEVANT postings, you will be considered a STALKER, A CRIMINAL, A RACIST, A CENSORER, and SUPPRESSOR OF TRUTH and PARTNER CRIMINAL in the CRIME WE ARE TRYING TO EXPOSE. I am doing a sandwich posting - its called the BIG MAC ... cheers From zkinion at gmail.com Tue Nov 2 16:55:15 2010 From: zkinion at gmail.com (Zak Kinion) Date: Tue, 2 Nov 2010 13:55:15 -0700 Subject: problem with opening a new python program in a new window (and keeping track of the process) Message-ID: Hello all, What I want to do: launch seperate python programs from one main program (multi-threading will not achieve this because the mechanize library uses one shared global opener object which will not suit my needs) I want the scripts launched to be in seperate windows that i can see the output of on screen, seperate processes. I can accomplish this in win32 by: import subprocess; args = ["cmd", "/c", "START", "python", "myScript.py"]; process1 = subprocess.Popen(args, shell=False); however, doing will open a new window, but will lose the process id: e.g. process1.poll() will always return 0 no matter if the process is open or not, meaning that python always thinks its closed. It should return None if the process is still running. I can do it without using cmd /c start, but then the newly launched python script is trapped in my original cmd terminal where i launched the script from in the first place. I can keep track of the process now, but the one cmd window open is insufficient to keep track of the output that a multitude of programs running will produce. Doing it without the /c argument will still keep the new script in the same console. Yes, I have read I can do this in linux with Konsole or whatever like: child = subprocess.Popen("konsole -e python foo.py", shell=True) however, I need this to run in windows. Any help or solution is appreciated, -- Zak Kinion zkinion at gmail.com From richgrise at example.net Tue Nov 2 16:58:16 2010 From: richgrise at example.net (Rich Grise) Date: Tue, 02 Nov 2010 13:58:16 -0700 Subject: *** FBI gets a warm welcome in Chicago for their EXCELLENTperformance - cheers to NEW CONS *** References: <26f97f70-9043-490c-9e6e-35159f38d76b@r29g2000yqj.googlegroups.com> <47e0b3a3-54fb-4489-95a8-b5ec6015c99d@j25g2000yqa.googlegroups.com> Message-ID: On Tue, 02 Nov 2010 14:17:29 -0700, Gunner Asch wrote: > > But...shrug..there will be far less after the Great Cull........ I think some people might be surprised as to exactly _who_ gets "culled". Good Luck! Rich From malaclypse2 at gmail.com Tue Nov 2 17:01:41 2010 From: malaclypse2 at gmail.com (Jerry Hill) Date: Tue, 2 Nov 2010 17:01:41 -0400 Subject: Trouble with importing In-Reply-To: References: Message-ID: On Tue, Nov 2, 2010 at 3:33 PM, Ben Ahrens wrote: > Jerry, thanks for the reply, I was swamped with other things for the > better part of a week.. Anyway, I tried using the verbose flag when > attempting the import. ?I didn't see anything that meant anything to > me, but here's the bit surrounding the part where it fails: > > # /usr/lib/python2.6/dist-packages/gnuradio/__init__.pyc matches > /usr/lib/python2.6/dist-packages/gnuradio/__init__.py > import gnuradio # precompiled from > /usr/lib/python2.6/dist-packages/gnuradio/__init__.pyc > # /usr/lib/python2.6/re.pyc matches /usr/lib/python2.6/re.py > import re # precompiled from /usr/lib/python2.6/re.pyc > # /usr/lib/python2.6/sre_compile.pyc matches /usr/lib/python2.6/sre_compile.py > import sre_compile # precompiled from /usr/lib/python2.6/sre_compile.pyc > import _sre # builtin > # /usr/lib/python2.6/sre_parse.pyc matches /usr/lib/python2.6/sre_parse.py > import sre_parse # precompiled from /usr/lib/python2.6/sre_parse.pyc > # /usr/lib/python2.6/sre_constants.pyc matches > /usr/lib/python2.6/sre_constants.py > import sre_constants # precompiled from /usr/lib/python2.6/sre_constants.pyc > Traceback (most recent call last): > ?File "", line 1, in > ImportError: cannot import name rfid > # clear __builtin__._ > # clear sys.path > # clear sys.argv > > > As for the permissions, as a bit of a python novice, I wasn't sure > whether permissions on the package referred to the gnuradio folder or > to something else. ?The permissions on the gnuradio folder are > drwxr-sr-x. ?I have sort of the same problem with the rfid module, but > hopefully this gives you the info you were asking about: > > -rwxr-xr-x 1 root staff ? 1067 2010-10-14 15:27 _rfid.la > -rw-r--r-- 1 root staff ?17988 2010-10-14 15:27 rfid.py > -rw-r--r-- 1 root staff ?30771 2010-10-14 15:27 rfid.pyc > -rw-r--r-- 1 root staff ?30771 2010-10-14 15:27 rfid.pyo > -rwxr-xr-x 1 root staff 939872 2010-10-14 15:27 _rfid.so > > > Thanks again for giving this some thought. ?Let me know if you have > any other tips! I'm copying your reply back to the list. You'll get more and better responses if you keep all of the discussion on there. I don't see anything unusual going on there either. I do see that the project page for gen2_rfid is asking for a particular SVN revision of gnuradio with custom edits applied. Is that how you installed gnuradio? I'm looking at the notes in https://www.cgran.org/browser/projects/gen2_rfid/trunk/README.txt and https://www.noisebridge.net/wiki/RFID_Hacking/usrp/ -- Jerry From ethan at stoneleaf.us Tue Nov 2 17:09:33 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 02 Nov 2010 14:09:33 -0700 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccfefc6$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4CD07E0D.7020008@stoneleaf.us> Grant Edwards wrote: > On 2010-11-02, Ethan Furman wrote: >> Steven D'Aprano wrote: >>> Personally, I'm more disturbed by the default prompt in the interactive >>> interpreter. >>> clashes with the symbol used for quoting text in email >>> and news. That causes me far more distress than indentation. >> >> I finally did "sys.ps1 = '--> '" in my interactive startup file. :) > > So _now_ what are going to whinge about? ^- \ missing a word? ;) If the word is "you" -- how about complaints about the documentation? elif the word is "we" -- maybe lack of reading comprehension? elif the word is "Steven" -- absolutely no clue ;) else -- maybe multiple inheritance being a bug... http://bugs.python.org/issue2667 ~Ethan~ From gunnerasch at gmail.com Tue Nov 2 17:17:29 2010 From: gunnerasch at gmail.com (Gunner Asch) Date: Tue, 02 Nov 2010 14:17:29 -0700 Subject: *** FBI gets a warm welcome in Chicago for their EXCELLENTperformance - cheers to NEW CONS *** References: <26f97f70-9043-490c-9e6e-35159f38d76b@r29g2000yqj.googlegroups.com> <47e0b3a3-54fb-4489-95a8-b5ec6015c99d@j25g2000yqa.googlegroups.com> Message-ID: On Tue, 02 Nov 2010 22:13:40 GMT, david.bostwick at chemistry.gatech.edu (David Bostwick) wrote: >In article <47e0b3a3-54fb-4489-95a8-b5ec6015c99d at j25g2000yqa.googlegroups.com>, small Pox wrote: >[...] > >Some WD40 on your keyboard might help keep the Caps Lock key from sticking so >often. The mentally ill often use mostly caps lock key strokes to emphasize their postings as they rant and rave. Shrug Get used to it. There are a lot of those poor sick bastards out there. But...shrug..there will be far less after the Great Cull........ Gunner "Confiscating wealth from those who have earned it, inherited it, or got lucky is never going to help 'the poor.' Poverty isn't caused by some people having more money than others, just as obesity isn't caused by McDonald's serving super-sized orders of French fries Poverty, like obesity, is caused by the life choices that dictate results." - John Tucci, From bahrens at gmail.com Tue Nov 2 17:27:44 2010 From: bahrens at gmail.com (Ben Ahrens) Date: Tue, 2 Nov 2010 16:27:44 -0500 Subject: Trouble with importing In-Reply-To: References: Message-ID: I did indeed use the particular revision compiled with the addons. I discovered that if I log in as root or make myself a user with full privileges I can successfully import the rfid module, just not using sudo. Of course neither of those options are particularly good ones, but that's the only way I've gotten it to work thus far. Ben On Tue, Nov 2, 2010 at 4:01 PM, Jerry Hill wrote: > On Tue, Nov 2, 2010 at 3:33 PM, Ben Ahrens wrote: >> Jerry, thanks for the reply, I was swamped with other things for the >> better part of a week.. Anyway, I tried using the verbose flag when >> attempting the import. ?I didn't see anything that meant anything to >> me, but here's the bit surrounding the part where it fails: >> >> # /usr/lib/python2.6/dist-packages/gnuradio/__init__.pyc matches >> /usr/lib/python2.6/dist-packages/gnuradio/__init__.py >> import gnuradio # precompiled from >> /usr/lib/python2.6/dist-packages/gnuradio/__init__.pyc >> # /usr/lib/python2.6/re.pyc matches /usr/lib/python2.6/re.py >> import re # precompiled from /usr/lib/python2.6/re.pyc >> # /usr/lib/python2.6/sre_compile.pyc matches /usr/lib/python2.6/sre_compile.py >> import sre_compile # precompiled from /usr/lib/python2.6/sre_compile.pyc >> import _sre # builtin >> # /usr/lib/python2.6/sre_parse.pyc matches /usr/lib/python2.6/sre_parse.py >> import sre_parse # precompiled from /usr/lib/python2.6/sre_parse.pyc >> # /usr/lib/python2.6/sre_constants.pyc matches >> /usr/lib/python2.6/sre_constants.py >> import sre_constants # precompiled from /usr/lib/python2.6/sre_constants.pyc >> Traceback (most recent call last): >> ?File "", line 1, in >> ImportError: cannot import name rfid >> # clear __builtin__._ >> # clear sys.path >> # clear sys.argv >> >> >> As for the permissions, as a bit of a python novice, I wasn't sure >> whether permissions on the package referred to the gnuradio folder or >> to something else. ?The permissions on the gnuradio folder are >> drwxr-sr-x. ?I have sort of the same problem with the rfid module, but >> hopefully this gives you the info you were asking about: >> >> -rwxr-xr-x 1 root staff ? 1067 2010-10-14 15:27 _rfid.la >> -rw-r--r-- 1 root staff ?17988 2010-10-14 15:27 rfid.py >> -rw-r--r-- 1 root staff ?30771 2010-10-14 15:27 rfid.pyc >> -rw-r--r-- 1 root staff ?30771 2010-10-14 15:27 rfid.pyo >> -rwxr-xr-x 1 root staff 939872 2010-10-14 15:27 _rfid.so >> >> >> Thanks again for giving this some thought. ?Let me know if you have >> any other tips! > > I'm copying your reply back to the list. ?You'll get more and better > responses if you keep all of the discussion on there. > > I don't see anything unusual going on there either. ?I do see that the > project page for gen2_rfid is asking for a particular SVN revision of > gnuradio with custom edits applied. ?Is that how you installed > gnuradio? ?I'm looking at the notes in > https://www.cgran.org/browser/projects/gen2_rfid/trunk/README.txt and > https://www.noisebridge.net/wiki/RFID_Hacking/usrp/ > > -- > Jerry > From david.bostwick at chemistry.gatech.edu Tue Nov 2 18:13:40 2010 From: david.bostwick at chemistry.gatech.edu (David Bostwick) Date: Tue, 02 Nov 2010 22:13:40 GMT Subject: *** FBI gets a warm welcome in Chicago for their EXCELLENTperformance - cheers to NEW CONS *** References: <26f97f70-9043-490c-9e6e-35159f38d76b@r29g2000yqj.googlegroups.com> <47e0b3a3-54fb-4489-95a8-b5ec6015c99d@j25g2000yqa.googlegroups.com> Message-ID: In article <47e0b3a3-54fb-4489-95a8-b5ec6015c99d at j25g2000yqa.googlegroups.com>, small Pox wrote: [...] Some WD40 on your keyboard might help keep the Caps Lock key from sticking so often. From jmcmonagle at NO.SPAM.velseis.com.au Tue Nov 2 18:27:42 2010 From: jmcmonagle at NO.SPAM.velseis.com.au (John McMonagle) Date: Wed, 03 Nov 2010 08:27:42 +1000 Subject: Python documentation too difficult for beginners In-Reply-To: <4cd060c5$0$1633$742ec2ed@news.sonic.net> References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> <871v73kc9d.fsf@rudin.co.uk> <4cd060c5$0$1633$742ec2ed@news.sonic.net> Message-ID: <4CD0905E.4000600@NO.SPAM.velseis.com.au> On 03/11/10 05:04, John Nagle wrote: > Right. Google does a far better job of organizing Python's > documentation than the Python community does. I don't even try > looking up anything starting at Python.org; I always start > with a Google search. Even though Python.org's search is > powered by Google, it's inferior to a general search. > > Compare: > > http://www.google.com/search?domains=www.python.org&sitesearch=www.python.org&q=open > > > http://www.google.com/search?q=Python+open > Even better: http://www.google.com/search?sitesearch=docs.python.org&q=open Regards, John McMonagle From lightsilver3 at gmail.com Tue Nov 2 18:28:03 2010 From: lightsilver3 at gmail.com (silver light) Date: Tue, 2 Nov 2010 15:28:03 -0700 (PDT) Subject: *** FBI gets a warm welcome in Chicago for their EXCELLENT performance - cheers to NEW CONS *** References: <73cd58e5-5aae-4d90-93fa-5bd481f8da62@y23g2000yqd.googlegroups.com> Message-ID: <0367d386-3175-4e4e-8b10-d33937322292@s4g2000yql.googlegroups.com> On Nov 2, 11:03?am, t... at sevak.isi.edu (Thomas A. Russ) wrote: > silver light writes: > > *** FBI gets a warm welcome in Chicago for their EXCELLENT performance > > - cheers to NEW CONS *** > > Oh geez. ?Just when we've beaten back the infix hordes, someone comes up > and suggests replacing CONS with something, new different and most > likely inferior. > > - Grumpy Old Programmer. > > -- > Thomas A. Russ, ?USC/Information Sciences Institute Google censored my post and deleted it not because they are trying to defend the FBI or cover them up. They just dont like silverlight which is from Microsoft. It is well known that google and oracle are trying to get control of the whole cyberspace either alone or in alliance with each other. This way they can control the federal government. Most senators and congressmen are pea brain and go along with whatever the corporations show them with music, viagra, champagne, food, cruise tickets, girls and pocket money. ========== Submitted by jkeogh on Tue, 11/02/2010 - 6:44am http://911blogger.com/news/2010-10-20/foia-funds-request Litigation seeking the release of never before seen 9/11 FBI records is currently underway in the federal courts. There is a immediate need for a FOIA attorney to assist with the case. The defendants are operating with a nearly unlimited funding and have a large body of legal experts working to prevent the release of these records. A public interest FOIA attorney has offered their services at a reduced public interest rate. We need the research communities help to raise the required funds. Release of these requested records may help settle questions surrounding the Pentagon and Shanksville controversies, as well as others. Release of these records could also help overcome future claims of release exemption by the FBI for other 9/11 records requests. From lightsilver3 at gmail.com Tue Nov 2 18:30:17 2010 From: lightsilver3 at gmail.com (silver light) Date: Tue, 2 Nov 2010 15:30:17 -0700 (PDT) Subject: *** FBI gets a warm welcome in Chicago for their EXCELLENTperformance - cheers to NEW CONS *** References: <26f97f70-9043-490c-9e6e-35159f38d76b@r29g2000yqj.googlegroups.com> <47e0b3a3-54fb-4489-95a8-b5ec6015c99d@j25g2000yqa.googlegroups.com> Message-ID: On Nov 2, 1:58?pm, Rich Grise wrote: > On Tue, 02 Nov 2010 14:17:29 -0700, Gunner Asch wrote: > > > But...shrug..there will be far less after the Great Cull........ > > I think some people might be surprised as to exactly _who_ gets "culled". > > Good Luck! > Rich On Nov 2, 11:03 am, t... at sevak.isi.edu (Thomas A. Russ) wrote: > silver light writes: > > *** FBI gets a warm welcome in Chicago for their EXCELLENT performance > > - cheers to NEW CONS *** > > Oh geez. Just when we've beaten back the infix hordes, someone comes up > and suggests replacing CONS with something, new different and most > likely inferior. > > - Grumpy Old Programmer. > > -- > Thomas A. Russ, USC/Information Sciences Institute Google censored my post and deleted it not because they are trying to defend the FBI or cover them up. They just dont like silverlight which is from Microsoft. It is well known that google and oracle are trying to get control of the whole cyberspace either alone or in alliance with each other. This way they can control the federal government. Most senators and congressmen are pea brain and go along with whatever the corporations show them with music, viagra, champagne, food, cruise tickets, girls and pocket money. ========== Submitted by jkeogh on Tue, 11/02/2010 - 6:44am http://911blogger.com/news/2010-10-20/foia-funds-request Litigation seeking the release of never before seen 9/11 FBI records is currently underway in the federal courts. There is a immediate need for a FOIA attorney to assist with the case. The defendants are operating with a nearly unlimited funding and have a large body of legal experts working to prevent the release of these records. A public interest FOIA attorney has offered their services at a reduced public interest rate. We need the research communities help to raise the required funds. Release of these requested records may help settle questions surrounding the Pentagon and Shanksville controversies, as well as others. Release of these records could also help overcome future claims of release exemption by the FBI for other 9/11 records requests. From evilmrhenry at emhsoft.com Tue Nov 2 18:50:39 2010 From: evilmrhenry at emhsoft.com (evilmrhenry) Date: Tue, 02 Nov 2010 15:50:39 -0700 Subject: Multiple cookie headers and urllib2 Message-ID: <4CD095BF.9010207@emhsoft.com> Python 2.6.4 on Ubuntu. I'm not sure if this is a bug or if I'm just doing this wrong... I'm trying to include two cookies when I use urllib2 to view a page. #Code Start import urllib2 opener = urllib2.build_opener(urllib2.HTTPCookieProcessor()) opener.addheaders.append(("Cookie", "user=abcd")) opener.addheaders.append(("Cookie", "password=12345")) print opener.addheaders r = opener.open("http://emhsoft.com/docs/cookies.php") print r.readlines() #Code End http://emhsoft.com/docs/cookies.php is live, and just includes The output is [('User-agent', 'Python-urllib/2.6'), ('Cookie', 'user=abcd'), ('Cookie', 'password=12345')] ['Array\n', '(\n', ' [user] => abcd\n', ')\n', ' '] I expected both of the cookies to show up, not just one. From ldo at geek-central.gen.new_zealand Tue Nov 2 18:54:47 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 03 Nov 2010 11:54:47 +1300 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: In message , Emile van Sebille wrote: > On 11/1/2010 4:22 PM Lawrence D'Oliveiro said... > >> In message, Emile van >> Sebille wrote: >> >>> At least you can look at python code and _know_ that spurious placement >>> of required line noise don't have the ability to impact what the code >>> does. >> >> But it does. What is spurious whitespace if not noise, after all? > > But it does so by intent. Other languages lend only an appearance of > structure through the indentation style of the writer. No, the indentation is there to make the structure clearer, not to act as a substitute for the structure. Try to conflate the two, and you end up with problems such as we are discussing. > It's as good as outdated comments. Outdated comments are a bug like any other, and should be fixed. From tjreedy at udel.edu Tue Nov 2 18:55:59 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 02 Nov 2010 18:55:59 -0400 Subject: Python documentation too difficult for beginners In-Reply-To: References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> <024ef21a-9ef9-48a6-8372-1d66895583c3@v16g2000yqn.googlegroups.com> Message-ID: On 11/2/2010 2:43 PM, Tim Harig wrote: > The real question is what do you want to gain by your posts here. You > should already know that most groups are, by their very nature, slow to > make changes to the status quo. The problem tends to be exasperated in > open source projects where any changes mean that people have to donate > their time to make anything happen. You will in general find two things to > be true: > > 1. Since they are dontating their time, you will find that people tend to > scratch their own iches first. > > 2. People who do take the time to contribute to open source projects are > people of action. They don't tend to be appreciative of those who > constantly generate feature requests but have no inclination to do > any of the work themselves. They do appreciate other people of > action who are interested in making the project better. > > Therefore, if you truly want changes in the documentation, I suggest that, > rather then whining to the group, you make some of the changes yourself. I agree up to here, with a different interpretation of the last clause. Work within the existing system. There are currently 250 open doc issues on the tracker at bugs.python.org. After registering, go to the search page http://bugs.python.org/issue?@template=search&status=1 select Components: Documentation and hit Return (or [Search]) Find an issue that is waiting for someone to suggest a new or replacement sentence or paragraph, and make one. No .diff patch required, just put it in the message. Or look at existing suggestions and comment. -- Terry Jan Reedy From ldo at geek-central.gen.new_zealand Tue Nov 2 19:01:06 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 03 Nov 2010 12:01:06 +1300 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: In message , Grant Edwards wrote: > On 2010-11-01, Lawrence D'Oliveiro > wrote: > >> In message <8j8am4Fk2jU1 at mid.individual.net>, Peter Pearson wrote: >>> >>>> diff -b oldfile newfile >>> >>> Warning: "diff -b" won't detect changes in indentation. Changes in >>> indentation can change a Python program. >> >> I'm getting less and less keen on that particular feature of Python... > > Why? > > Other languages have similar problems if you remove salient bits of > syntax before comparing two source files files. But other languages don?t make those ?salient bits of syntax? invisible. I.e. they are actually ?salient?. From nizumzen at mcnuggets.com Tue Nov 2 19:05:03 2010 From: nizumzen at mcnuggets.com (Nizumzen) Date: Tue, 2 Nov 2010 23:05:03 +0000 Subject: Python documentation too difficult for beginners References: Message-ID: <2010110223050345181-nizumzen@mcnuggetscom> On 2010-11-02 10:42:22 +0000, jk said: > Hi, > > I've been coding in PHP and Java for years, and their documentation is > concise, well structured and easy to scan. Are you mad? Javadoc is one of the worst examples of source code documentation I can possibly imagine. I would go as far to say that the Python guys should do exactly the opposite of Javadoc. From ldo at geek-central.gen.new_zealand Tue Nov 2 19:06:30 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 03 Nov 2010 12:06:30 +1300 Subject: Python documentation too difficult for beginners References: Message-ID: In message , jk wrote: > This (http://epydoc.sourceforge.net/stdlib/) is what I'm talking > about. Framesets? Is that really your idea of well-laid-out documentation? Using a feature which has been derided (and dropped in HTML5) because of its effect on usability and accessibility? From ldo at geek-central.gen.new_zealand Tue Nov 2 19:11:52 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 03 Nov 2010 12:11:52 +1300 Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> Message-ID: In message , Roy Smith wrote: > In this case, I think I would do: > > styles = [("normal", "image", MainWindow.ColorsNormalList), > ("highlighted", "highlight", MainWindow.ColorsHighlightedList), > ("selected", "select", MainWindow.ColorsSelectedList)] > > for in description, attr, color_list in styles: > blah, blah, blah And so you have managed to separate one set of looping conditions into two parts. What is the significance of the name ?styles?? None at all. What purpose does it serve? None, really. Does it ease the maintenance burden? No, but by splitting your attention across two places, it actually adds to it. Here?s another example for you to chew on: for \ name, reg, doindir \ in \ ( ("R0", 0, True), ("R1", 1, True), ("R2", 2, True), ("R3", 3, True), ("R4", 4, True), ("R5", 5, True), ("R6", 6, True), ("SP", 6, True), ("R7", 7, False), ("PC", 7, False), ) \ : ... #end for From mike.terrell at earthlink.net Tue Nov 2 19:16:27 2010 From: mike.terrell at earthlink.net (Michael A. Terrell) Date: Tue, 02 Nov 2010 19:16:27 -0400 Subject: *** FBI gets a warm welcome in Chicago for their EXCELLENTperformance - cheers to NEW CONS *** References: <26f97f70-9043-490c-9e6e-35159f38d76b@r29g2000yqj.googlegroups.com> <47e0b3a3-54fb-4489-95a8-b5ec6015c99d@j25g2000yqa.googlegroups.com> Message-ID: Gunner Asch wrote: > > On Tue, 02 Nov 2010 22:13:40 GMT, david.bostwick at chemistry.gatech.edu > (David Bostwick) wrote: > > ?In article ?47e0b3a3-54fb-4489-95a8-b5ec6015c99d at j25g2000yqa.googlegroups.com?, small Pox ?smallpox911 at gmail.com? wrote: > ?[...] > ? > ?Some WD40 on your keyboard might help keep the Caps Lock key from sticking so > ?often. > > The mentally ill often use mostly caps lock key strokes to emphasize > their postings as they rant and rave. > > Shrug > > Get used to it. > > There are a lot of those poor sick bastards out there. > > But...shrug..there will be far less after the Great Cull........ Concertina neckties. They won't dare move. -- Politicians should only get paid if the budget is balanced, and there is enough left over to pay them. From anton.list at gmail.com Tue Nov 2 19:32:39 2010 From: anton.list at gmail.com (AD.) Date: Tue, 2 Nov 2010 16:32:39 -0700 (PDT) Subject: Python documentation too difficult for beginners References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> <024ef21a-9ef9-48a6-8372-1d66895583c3@v16g2000yqn.googlegroups.com> Message-ID: <4716193c-2e9f-4469-b8c7-bba600fba8a2@p1g2000yqm.googlegroups.com> On Nov 3, 7:43?am, Tim Harig wrote: > On 2010-11-02, jk wrote: > > > As for the 9 paragraphs statement, there's a usability book that > > applies here - it's called "Don't make me think". I shouldn't have to > > Anything that promotes a lack of thinking sends up red flags in my head. > We want to recruit smart people who think, not idiots. "Don't make me think" is the UI equivalent of "There should be one and preferably only one obvious way to do it". Not about advocating no thinking, but about reducing the amount of unimportant decisions you require your users to make. But I don't think the book specifically addresses Dutch users though. Back on topic - I do like the Python docs overall. Especially compared to the PHP docs. I like the overall look and format of the new Sphinx generated ones too. My only criticism is that the content can sometimes be a little too terse/concise. It's fine for experienced developers, but in some places a little more explanation and/or examples would help out the less experienced. I can usually figure out how to do something eventually, but the docs for some modules take more deciphering than others. -- Cheers Anton From invalid at invalid.invalid Tue Nov 2 19:36:46 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 2 Nov 2010 23:36:46 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: On 2010-11-02, Lawrence D'Oliveiro wrote: > In message , Grant Edwards wrote: > >> On 2010-11-01, Lawrence D'Oliveiro >> wrote: >> >>> In message <8j8am4Fk2jU1 at mid.individual.net>, Peter Pearson wrote: >>>> >>>>> diff -b oldfile newfile >>>> >>>> Warning: "diff -b" won't detect changes in indentation. Changes in >>>> indentation can change a Python program. >>> >>> I'm getting less and less keen on that particular feature of Python... >> >> Why? >> >> Other languages have similar problems if you remove salient bits of >> syntax before comparing two source files files. > > But other languages don???t make those ???salient bits of syntax??? > invisible. Huh? Indentation is invisible? You can't see the indentation in Python source code? I'm baffled... -- Grant From prologic at shortcircuit.net.au Tue Nov 2 19:38:58 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 3 Nov 2010 09:38:58 +1000 Subject: Python documentation too difficult for beginners In-Reply-To: <2010110223050345181-nizumzen@mcnuggetscom> References: <2010110223050345181-nizumzen@mcnuggetscom> Message-ID: On Wed, Nov 3, 2010 at 9:05 AM, Nizumzen wrote: > Are you mad? Javadoc is one of the worst examples of source code > documentation I can possibly imagine. I would go as far to say that the > Python guys should do exactly the opposite of Javadoc. For what it's worth, I concur. cheers James -- -- James Mills -- -- "Problems are solved by method" From roy at panix.com Tue Nov 2 20:17:06 2010 From: roy at panix.com (Roy Smith) Date: Tue, 02 Nov 2010 20:17:06 -0400 Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> Message-ID: In article , Lawrence D'Oliveiro wrote: > In message , Roy Smith wrote: > > > In this case, I think I would do: > > > > styles = [("normal", "image", MainWindow.ColorsNormalList), > > ("highlighted", "highlight", MainWindow.ColorsHighlightedList), > > ("selected", "select", MainWindow.ColorsSelectedList)] > > > > for in description, attr, color_list in styles: > > blah, blah, blah > > And so you have managed to separate one set of looping conditions into two > parts. What is the significance of the name ???styles???? None at all. What > purpose does it serve? None, really. Does it ease the maintenance burden? > No, but by splitting your attention across two places, it actually adds to > it. I suppose readability is in the eye of the reader, but, yes, I agree that I have split this into two parts. The parts are 1) The table of data 2) The looping construct Where we seem to disagree is whether that makes things more or less readable :-) To me, it makes is more readable because it lets me understand one chunk, then move on to understanding the next chunk. You may disagree. That's OK. From usernet at ilthio.net Tue Nov 2 20:41:46 2010 From: usernet at ilthio.net (Tim Harig) Date: Wed, 3 Nov 2010 00:41:46 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: On 2010-11-02, D'Arcy J.M. Cain wrote: > "Redundant" is right. However, there is a use for such comments: > > if foo: > bar > else: > baz > if snafu: > cookie > #endif snafu > quux > #endif foo Actually, I have found similar markers to be useful everywhere. I don't like the way my editor tries to fold Python code, so I started inserting folding markers myself: # foo {{{ if foo: bar else: baz # snafu {{{ if snafu: cookie # }}} quux # }}} If the bar, baz, and quux blocks are large enough logical units, I will fold them as well. What I found is that the makers become an incredibly useful form of organzational tool. From kee at kagi.com Tue Nov 2 20:43:24 2010 From: kee at kagi.com (Kee Nethery) Date: Tue, 2 Nov 2010 17:43:24 -0700 Subject: Python documentation too difficult for beginners In-Reply-To: References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> <024ef21a-9ef9-48a6-8372-1d66895583c3@v16g2000yqn.googlegroups.com> Message-ID: > >> >> Therefore, if you truly want changes in the documentation, I suggest that, >> rather then whining to the group, you make some of the changes yourself. > > I agree up to here, with a different interpretation of the last clause. > Work within the existing system. There are currently 250 open doc issues on the tracker at bugs.python.org. wow, a backlog of 250. Either 250 is the weekly submittal amount and they get dealt with within a week, OR the backlog is months old and the bug system is not an effective way to get changes or enhancements to the documentation. Either way, 250 open doc issues gives me the feeling that the existing documentation system is not working for the people trying to use it. > After registering, go to the search page > http://bugs.python.org/issue?@template=search&status=1 > select Components: Documentation and hit Return (or [Search]) > > Find an issue that is waiting for someone to suggest a new or replacement sentence or paragraph, and make one. No .diff patch required, just put it in the message. Or look at existing suggestions and comment. Given that newbies are the ones who run into these issues and have a great desire to spare others the pain they have suffered trying to learn Python, and newbies typically do not know about the bug tracking system as the way to request enhancements to the docs (that's not how wikipedia and other sites do changes to information), perhaps it would be useful to put a link to a page that explains how to improve the docs, on each doc page? I have to agree with others. My preferred Python documentation is either the books I have, or a search on Google. A google search typically has several postings from people on non-official sites with the exact same confusion I have, and what they have tried and what ultimately worked. The suggestion was made that people create their own documentation if they don't like the official documentation, and that does seem to be a good source for python documentation. Kee Nethery From ben+python at benfinney.id.au Tue Nov 2 20:46:01 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 03 Nov 2010 11:46:01 +1100 Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> Message-ID: <87aalrjkty.fsf@benfinney.id.au> Roy Smith writes: > In article , > Lawrence D'Oliveiro wrote: > > > In message , Roy Smith wrote: > > > > > In this case, I think I would do: > > > > > > styles = [("normal", "image", MainWindow.ColorsNormalList), > > > ("highlighted", "highlight", MainWindow.ColorsHighlightedList), > > > ("selected", "select", MainWindow.ColorsSelectedList)] > > > > > > for in description, attr, color_list in styles: > > > blah, blah, blah I would do the same, but fix the indentation. Making indentation depend on the *length* of the previous line is needlessly making a maintenance burden. Instead, I'd do:: styles = [ ("normal", "image", MainWindow.ColorsNormalList), ("highlighted", "highlight", MainWindow.ColorsHighlightedList), ("selected", "select", MainWindow.ColorsSelectedList)] for in description, attr, color_list in styles: # blah, blah, blah A single consistent level of indentation on continuation lines, no matter what happens to the first line. > Where we seem to disagree is whether that makes things more or less > readable :-) To me, it makes is more readable because it lets me > understand one chunk, then move on to understanding the next chunk. Agreed. > You may disagree. That's OK. It's okay until that code gets out in the wild; then it's no longer just a matter of one person's taste. Hence the need for conventions. -- \ ?Anyone who puts a small gloss on [a] fundamental technology, | `\ calls it proprietary, and then tries to keep others from | _o__) building on it, is a thief.? ?Tim O'Reilly, 2000-01-25 | Ben Finney From ian.g.kelly at gmail.com Tue Nov 2 20:52:13 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 2 Nov 2010 18:52:13 -0600 Subject: Multiple cookie headers and urllib2 In-Reply-To: <4CD095BF.9010207@emhsoft.com> References: <4CD095BF.9010207@emhsoft.com> Message-ID: On Tue, Nov 2, 2010 at 4:50 PM, evilmrhenry wrote: > Python 2.6.4 on Ubuntu. I'm not sure if this is a bug or if I'm just doing > this wrong... > > I'm trying to include two cookies when I use urllib2 to view a page. > #Code Start > import urllib2 > > opener = urllib2.build_opener(urllib2.HTTPCookieProcessor()) > opener.addheaders.append(("Cookie", "user=abcd")) > opener.addheaders.append(("Cookie", "password=12345")) > print opener.addheaders > r = opener.open("http://emhsoft.com/docs/cookies.php") > print r.readlines() > #Code End > > http://emhsoft.com/docs/cookies.php is live, and just includes > > The output is > [('User-agent', 'Python-urllib/2.6'), ('Cookie', 'user=abcd'), ('Cookie', > 'password=12345')] > ['Array\n', '(\n', ' [user] => abcd\n', ')\n', ' '] > > I expected both of the cookies to show up, not just one. > It is expected that all the cookies are contained within a single header, e.g.: opener.addheaders.append(("Cookie", "user=abcd; password=12345")) You probably shouldn't be manually adding Cookie headers if you're using HTTPCookieProcessor; they will tend to clobber each other. You could add the cookies to the cookie jar object directly, although it's not really designed for that use case. Better to just let the web app set the cookies -- if you want to log in programmatically, pass the username and password in the POST data, and then the web app can set whatever cookies it wants to remember the session. And in case you aren't aware, storing the user's password in a cookie is generally considered bad form as it poses a greater security risk than storing an opaque session token. That way the password need only be sent across the wire once and cannot be discovered by inspecting the user's browser cache. Cheers, Ian -------------- next part -------------- An HTML attachment was scrubbed... URL: From evilmrhenry at emhsoft.com Tue Nov 2 21:12:20 2010 From: evilmrhenry at emhsoft.com (evilmrhenry) Date: Tue, 02 Nov 2010 18:12:20 -0700 Subject: Multiple cookie headers and urllib2 In-Reply-To: References: <4CD095BF.9010207@emhsoft.com> Message-ID: <4CD0B6F4.20708@emhsoft.com> Ian Kelly wrote: > > > On Tue, Nov 2, 2010 at 4:50 PM, evilmrhenry > wrote: > > Python 2.6.4 on Ubuntu. I'm not sure if this is a bug or if I'm just > doing this wrong... > > I'm trying to include two cookies when I use urllib2 to view a page. > #Code Start > import urllib2 > > opener = urllib2.build_opener(urllib2.HTTPCookieProcessor()) > opener.addheaders.append(("Cookie", "user=abcd")) > opener.addheaders.append(("Cookie", "password=12345")) > print opener.addheaders > r = opener.open("http://emhsoft.com/docs/cookies.php") > print r.readlines() > #Code End > > http://emhsoft.com/docs/cookies.php is live, and just includes > > The output is > [('User-agent', 'Python-urllib/2.6'), ('Cookie', 'user=abcd'), > ('Cookie', 'password=12345')] > ['Array\n', '(\n', ' [user] => abcd\n', ')\n', ' '] > > I expected both of the cookies to show up, not just one. > > > It is expected that all the cookies are contained within a single > header, e.g.: > > opener.addheaders.append(("Cookie", "user=abcd; password=12345")) > > You probably shouldn't be manually adding Cookie headers if you're using > HTTPCookieProcessor; they will tend to clobber each other. You could > add the cookies to the cookie jar object directly, although it's not > really designed for that use case. Better to just let the web app set > the cookies -- if you want to log in programmatically, pass the username > and password in the POST data, and then the web app can set whatever > cookies it wants to remember the session. > > And in case you aren't aware, storing the user's password in a cookie is > generally considered bad form as it poses a greater security risk than > storing an opaque session token. That way the password need only be > sent across the wire once and cannot be discovered by inspecting the > user's browser cache. > > Cheers, > Ian Yes, this works. Thank you. (I am aware of the cookie jar, and would normally use it. It just wouldn't work well in this case. Also, the user/pass was just an example, and *not* how I was going to do this.) From usenet-nospam at seebs.net Tue Nov 2 21:20:16 2010 From: usenet-nospam at seebs.net (Seebs) Date: 03 Nov 2010 01:20:16 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: On 2010-11-02, D'Arcy J.M. Cain wrote: > "Large" is no excuse for incompetency. It is in practice. > So configure it to recognize Python files and act accordingly. So far as I know, it doesn't have a feature to do this. In any event, I work around it okay. >> No, they aren't. See... That would work *if I knew for sure what the intent >> was*. >> >> if foo: >> bar >> else: >> baz >> quux >> >> Does it look right? We have *no idea*, because we don't actually know >> whether quux was *intended* to be in the else branch or whether that's a typo. > And C has the same problem. Not quite! > if (foo) > bar; > else > baz; > > quux; > Is quux meant to be part of the else clause? The writer's indentation > suggests "yes" but the code says "no". Right. And that's the thing: In C, I know there's something wrong here. I may not know what it is, but I know *something* is wrong. > Same is true for the C code. Pretty much! > In both cases you can tell what the code > will do (modulo weird macros in the C code) but the intention is > impossible to determine without mind reading abilities in both cases. > We do know that the Python code *appears* to be doing exactly what the > author intended and the C code *appears* to not be. Yes. And in my experience, that means that since the code must be wrong (or I wouldn't be looking at it), it's very nice that in one of them, I've just been told for sure that the writer was confused right here at this line. In the other, I have no way of knowing that the writer was confused. What was it someone once said? "Explicit is better than implicit." I *like* my parity bits. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Tue Nov 2 21:20:40 2010 From: usenet-nospam at seebs.net (Seebs) Date: 03 Nov 2010 01:20:40 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: On 2010-11-02, Emile van Sebille wrote: > What is right is that there's no question that quux is subsequent to baz > in all cases barring exceptions (and assuming no tabs intermixed) Yes, but that doesn't mean it does what the programmer intended, just that it does what it does. > The apparent structure in python _is_ the structure, whereas otherwise > you've got to count your ;'s and {}'s etc to determine and verify the > structure matches the apparent structure provided by the programmer. Yes. I understand this. However, I have probably seen all of two or three bugs ever related to mis-indented C, and I've had various things screw up or wreck indentation on dozens of occasions. Being able to recover has been nice. (So's being able to use fence matching to jump to the other end of a block.) -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Tue Nov 2 21:25:56 2010 From: usenet-nospam at seebs.net (Seebs) Date: 03 Nov 2010 01:25:56 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-02, Tim Harig wrote: > This is Python's most noticable blemish outside of the community. > Everybody knows that Python is the language that forces you to use a > particular style of formatting; and, that is a turn-off for many people. Honestly, I could probably live with that; the killer is the impossibility of recovering from white space damage. I have had many things happen to code over the years which required someone to run them through indent/cb. > It is a big mistake that whenever the issue arises, the community > effectively attacks anybody who might have disagreements with the tradeoffs > made for the Python language. This tends to set people on the defensive > and gives them a bad taste about the language as a whole. Yes. It does not create an impression that this is an engineering tradeoff which has been considered and understood; it creates the impression that people are defensive enough about it that they're not able to confidently acknowledge the shortcomings while maintaining that the tradeoff is worth it. I like C. If you tell me that C's macro processor sucks, I will agree with you. I don't have to make excuses or pretend that there's no downsides; I can justify my preference for the language even *granting* those downsides (and downsides aplenty are to be found). > It would be much better if the community would simply acknowledge that > this is a tradeoff the the language has made and one which is often > misunderstood by many first time Python programmers. Then it is possible > transition to Python's strengths. Don't simply ignore that there *are* > potential downfalls to this approach. Amen. I am fine with this tradeoff. It's not what I would have picked, but hey, I'm not Dutch. What I'm not fine with is people telling me that it's not a tradeoff and that all the problems are my fault. If someone designed a protocol where a particular kind of file was required to be sent via email, as plain text, with many lines starting "From ", and the protocol died horribly whenever it encountered ">From " at the beginning of a line, no amount of pointing out that the mail servers in question were wrong would make it a good design for a protocol. Whitespace damage is, indeed, wrong. It's a bad thing. It is an *extremely common* bad thing, and I fundamentally don't think it was a good choice to build a system with no redundancy against it. That "redundant" information saves our hides on a regular basis in an imperfect world. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Tue Nov 2 21:27:35 2010 From: usenet-nospam at seebs.net (Seebs) Date: 03 Nov 2010 01:27:35 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: On 2010-11-02, Grant Edwards wrote: > Huh? Indentation is invisible? You can't see the indentation in > Python source code? The difference between tabs and spaces is invisible on a great number of the devices on which people display code. Indentation is visible, but the underlying structure of it may not be. (It's worse than that, because for instance " " is quite hard to distinguish from the quite similar " ".) And at least one of them is clearly wrong. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From darcy at druid.net Tue Nov 2 21:29:02 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 2 Nov 2010 21:29:02 -0400 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: <20101102212902.001ce7d0.darcy@druid.net> On Wed, 3 Nov 2010 00:41:46 +0000 (UTC) Tim Harig wrote: > On 2010-11-02, D'Arcy J.M. Cain wrote: > Actually, I have found similar markers to be useful everywhere. I don't > like the way my editor tries to fold Python code, so I started inserting > folding markers myself: > > # foo {{{ > if foo: Now that is redundant. We know it's "foo" at the top of the block. Identifying the end of the block has some value. And the braces just make the code noisy. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From darcy at druid.net Tue Nov 2 21:35:44 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 2 Nov 2010 21:35:44 -0400 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: <20101102213544.f22111bb.darcy@druid.net> On 03 Nov 2010 01:20:40 GMT Seebs wrote: > However, I have probably seen all of two or three bugs ever related to > mis-indented C, and I've had various things screw up or wreck indentation Really? I have never seen bugs in C related to indentation. I have seen plenty related to braces. What I have seen is bugs hidden by the indentation not matching the block structure. Wrong indentation in Python *is* a bug. There's no other visual signal to hide the error. > on dozens of occasions. Being able to recover has been nice. (So's being > able to use fence matching to jump to the other end of a block.) But I can see the other end of the block in Python. I don't need any tricks to make sure that it is the end. And if your block is too big to see the structure easily then that just means that some code should be factored out to a method. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From lanyjie at yahoo.com Tue Nov 2 21:41:55 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Tue, 2 Nov 2010 18:41:55 -0700 (PDT) Subject: Must be a bug in the re module [was: Why this result with the re module] In-Reply-To: <4CD037D7.7070408@asd-group.com> Message-ID: <259282.72742.qm@web54208.mail.re2.yahoo.com> > From: John Bond > Subject: Re: Why this result with the re module > To: "Yingjie Lan" > Cc: python-list at python.org > Date: Tuesday, November 2, 2010, 8:09 PM > On 2/11/2010 12:19 PM, Yingjie Lan > wrote: > >> From: John Bond > >> Subject: Re: Why this result with the re module > > Firstly, thanks a lot for your patient explanation. > > this time I have understood all your points > perfectly. > > > > Secondly, I'd like to clarify some of my points, > which > > did not get through because of my poor presentation. > > > > I suggested findall return a tuple of > re.MatchObject(s), > > with each MatchObject instance representing a match. > > This is consistent with the re.match() function > anyway. > > And it will eliminate the need of returning tuples, > > and it is much more precise and information rich. > > > > If that's not possible, and a tuple must be returned, > > then the whole match (not just subgroups) should > > always be included as the first element in the tuple, > > as that's group(0) or '\0'. Less surprise would > arise. > > > > Finally, it seems to me the algo for findall is > WRONG. > > > > To re.findall('(.a.)*', 'Mary has a lamb'), > > by reason of greediness of '*', and the requirement > > of non-overlapping, it should go like this > > (suppose an '' is at the beginning and at the end, > > and between two consecutive characters there is > > one and only one empty string ''. To show the > > match of empty strings clearly, > > I am concatenating each repeated match below): > > > > Steps for re.findall('(.a.)*', 'Mary has a lamb'): > > > > step 1: Match '' + 'Mar' + '' (gready!) > > step 2: skip 'y' > > step 3: Match '' > > step 4: skip ' ' > > step 5: Match ''+'has'+' a '+'lam'+'' (greedy!) > > step 6: skip 'b' > > step 7: Match '' > > > > So there should be exactly 4 matches in total: > > > > 'Mar', '', 'has a lam', '' > > > > Also, the matches above shows > > that if a repeated subgroup only captures > > the last match, the subgroup (.a.)* > > should always capture '' here (see steps > > 1, 3, 5, 7) above. > > > > Yet the execution in Python results in 6 matches! > > And, the capturing subgroup with repetition > > sometimes got the wrong guy. > > > > So I believe the algorithm for findall must be WRONG. > > > > Regards, > > > > Yingjie > At a guess, I'd say what is happening is something like > this: > > Steps for re.findall('(.a.)*', 'Mary has a lamb'): > > step 1: Match 'Mar' at string index 0 > step 2: Match '' at string index 3 (before 'y') > step 3: skip 'y' > step 4: Match '' at string index 4 (before ' ') > step 5: skip ' ' > step 6: Match 'has a lam' at string index 5 > step 7: Match '' at string index 14 (before 'b') > step 8: skip 'b' > step 9: Match '' at string index 15 (before EOS) > > > > matches: ('Mar', '', '', 'has a lam', '', '') > returns: ['Mar', '', '', 'lam', '', ''] (*) > > (*) "has a " lost due to not being last repetition at that > match point > > Which seems about right to me! Greediness has nothing to do > with it, except that it causes 'has a lam' to be matched in > one match, instead of as three separate matches (of 'has', ' > a ' and 'lam'). Disagree in this case, where the whole regex matches an empty string. Greadiness will match as much as possible. So it will also match the empty strings between consecutive characters as much as possible, once we have properly defined all the unique empty strings. Because of greadiness, fewer matches should be found. In this case, it should find only 4 matches (shown in my steps) instead of 6 matches (shown in your steps). Yingjie From gnarlodious at gmail.com Tue Nov 2 21:48:37 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Tue, 2 Nov 2010 18:48:37 -0700 (PDT) Subject: Py3: Import relative path module References: <044f2fb7-a6a9-4bb9-b2a6-8ee1d0c19612@u17g2000yqi.googlegroups.com> <4cce7768$0$29965$c3e8da3$5496439d@news.astraweb.com> <770dd3de-25f5-404c-a05a-7bdd2eb07179@26g2000yqv.googlegroups.com> Message-ID: <3e7dbd88-4d44-43fa-a0e2-6987c025ccdb@26g2000yqv.googlegroups.com> I admit I don't understand any of what was said here. Or why it is so hard what I am trying to do. I searched Google for a few hours looking for a way to import a module from an absolute path, but that was a waste of time too. To reiterate, I am trying to import a Def function from a file one level up. Let's say relative import is unreasonable to expect from Python. If it is possible using an absolute path, please let me know how, in plain language. Otherwise I can continue to copy and paste my programming into several files. Thank you for any help. -- Gnarlie From usernet at ilthio.net Tue Nov 2 22:20:49 2010 From: usernet at ilthio.net (Tim Harig) Date: Wed, 3 Nov 2010 02:20:49 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: On 2010-11-03, D'Arcy J.M. Cain wrote: > On Wed, 3 Nov 2010 00:41:46 +0000 (UTC) > Tim Harig wrote: >> On 2010-11-02, D'Arcy J.M. Cain wrote: >> Actually, I have found similar markers to be useful everywhere. I don't >> like the way my editor tries to fold Python code, so I started inserting >> folding markers myself: >> >> # foo {{{ >> if foo: > > Now that is redundant. We know it's "foo" at the top of the block. In practice the comment would explain why and how the conditional is being used just like any other comment. Since your example as abstract, I didn't have anything useful to say about it as I would for real code. When the code is folded, I will see nothing but the comments. It is often helpful to look at a section of code with all of the code blocks folded to gain a high level understanding of the code before zeroing in on the specific section that I wish to edit. When I do edit a section, I unfold no more code blocks then necessary. If I have to unfold too many blocks to to edit a single section of code, then it is a powerful indication that either the code block is not properly self contained or that the comments of the surrounding code blocks are insufficient to convey information about their code block. > Identifying the end of the block has some value. And the braces just > make the code noisy. With good syntax highlighting, you don't notice them unless you are looking for something because the markers are in comments and the markers for a block are only visible when the block is unfolded. As a benefit, they allow the folding stucture to provide expression of the code structure that cannot be expressed in the code itself. I often group blocks together that would not otherwise be indented or otherwise expressed together as they were in your example. # top level group {{{ # part 1 {{{ code # }}} # part 2 {{{ code # }}} # part 3 {{{ code # }}} # }}} Folded in my editor, it looks like this: 44 +--- 15 lines: # top level group ------------------------------------------- Unfolding the top level group, it looks like this: 44 # top level group {{{ 45 46 +---- 3 lines: # part 1 --------------------------------------------------- 49 50 +---- 3 lines: # part 2 --------------------------------------------------- 53 54 +---- 3 lines: # part 3 --------------------------------------------------- 57 58 # }}} It is therefore clear that all three of the parts are logically connected. I can keep them all folded and view them as a group or a can look into the group and edit just the relevant section of the group: 44 # top level group {{{ 45 46 +---- 3 lines: # part 1 --------------------------------------------------- 49 50 # part 2 {{{ 51 code 52 # }}} 53 54 +---- 3 lines: # part 3 --------------------------------------------------- 57 58 # }}} I have effectively added a meta structure to the blocks inside of the fuction at a finer grain then is supported by the syntax itself. Should I decide later that the top level group is becoming autonomous enough to warrant moving to a separate function, I can simply grab the entire folded block as an entity and move it to its own function body. From python at mrabarnett.plus.com Tue Nov 2 22:29:30 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 03 Nov 2010 02:29:30 +0000 Subject: Py3: Import relative path module In-Reply-To: <3e7dbd88-4d44-43fa-a0e2-6987c025ccdb@26g2000yqv.googlegroups.com> References: <044f2fb7-a6a9-4bb9-b2a6-8ee1d0c19612@u17g2000yqi.googlegroups.com> <4cce7768$0$29965$c3e8da3$5496439d@news.astraweb.com> <770dd3de-25f5-404c-a05a-7bdd2eb07179@26g2000yqv.googlegroups.com> <3e7dbd88-4d44-43fa-a0e2-6987c025ccdb@26g2000yqv.googlegroups.com> Message-ID: <4CD0C90A.7030307@mrabarnett.plus.com> On 03/11/2010 01:48, Gnarlodious wrote: > I admit I don't understand any of what was said here. Or why it is so > hard what I am trying to do. I searched Google for a few hours looking > for a way to import a module from an absolute path, but that was a > waste of time too. > > To reiterate, I am trying to import a Def function from a file one > level up. Let's say relative import is unreasonable to expect from > Python. If it is possible using an absolute path, please let me know > how, in plain language. Otherwise I can continue to copy and paste my > programming into several files. > > Thank you for any help. > After some experimentation (and Googling!) I think the problem is that a module can do your relative import but a main script can't. Or, to put it another way, if __name__ is "__main__" then it won't work. From pub at melv.org Tue Nov 2 22:30:36 2010 From: pub at melv.org (Chris Melville) Date: Wed, 03 Nov 2010 02:30:36 +0000 Subject: Must be a bug in the re module [was: Why this result with the re module] In-Reply-To: <259282.72742.qm@web54208.mail.re2.yahoo.com> References: <259282.72742.qm@web54208.mail.re2.yahoo.com> Message-ID: <4CD0C94C.30701@melv.org> > Disagree in this case, where the whole regex > matches an empty string. Greadiness will match > as much as possible. So it will also match > the empty strings between consecutive > characters as much as possible, once > we have properly defined all the unique > empty strings. Because of greadiness, > fewer matches should be found. In this > case, it should find only 4 matches > (shown in my steps) instead of 6 matches > (shown in your steps). > > Yingjie > I'm sorry but I really don't understand where your coming from. Your regex says "Zero or more consecutive occurrences of something, always returning the most possible". That's what it does, at every position - only matching emptyness where it couldn't match anything (findall then skips a character to avoid overlapping/infinite empty matches), and at all other times matching the most possible (eg. "has a lam" not "has", " a ", "lam"). Perhaps someone else can look at this and comment on whether findall is doing what it is supposed to, or not. To me, it is. Cheers, JB From usernet at ilthio.net Tue Nov 2 22:34:43 2010 From: usernet at ilthio.net (Tim Harig) Date: Wed, 3 Nov 2010 02:34:43 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: On 2010-11-03, Tim Harig wrote: > On 2010-11-03, D'Arcy J.M. Cain wrote: >> On Wed, 3 Nov 2010 00:41:46 +0000 (UTC) >> Tim Harig wrote: >> Identifying the end of the block has some value. And the braces just >> make the code noisy. > > With good syntax highlighting, you don't notice them unless you are looking > for something because the markers are in comments and the markers for > a block are only visible when the block is unfolded. As a benefit, they allow the folding > stucture to provide expression of the code structure that cannot be > expressed in the code itself. Also note that you can use whatever you like for the folding markers if the braces intimidate you. {{{ just happens to be the most recognized standard. The Erlang crowd like to use ## for this sort of thing. From usenet-nospam at seebs.net Tue Nov 2 22:40:11 2010 From: usenet-nospam at seebs.net (Seebs) Date: 03 Nov 2010 02:40:11 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: On 2010-11-03, D'Arcy J.M. Cain wrote: > On 03 Nov 2010 01:20:40 GMT > Seebs wrote: >> However, I have probably seen all of two or three bugs ever related to >> mis-indented C, and I've had various things screw up or wreck indentation > Really? I have never seen bugs in C related to indentation. I have > seen plenty related to braces. What I have seen is bugs hidden by the > indentation not matching the block structure. Right. That's *related to* indentation -- it wouldn't be there (we hope) had the indentation been right. > Wrong indentation in > Python *is* a bug. There's no other visual signal to hide the error. Sure, but there's also no way for you to spot that something looks suspicious. In Python, if something is misindented, it does what you told it to do, and there's no way for you to tell, by looking at it, that it isn't what was intended. In C, if something is misindented, it does what you told it to do, but it's obvious looking at the code that something went wrong. > But I can see the other end of the block in Python. I don't need any > tricks to make sure that it is the end. And if your block is too big > to see the structure easily then that just means that some code should > be factored out to a method. This level of dogmatism about what should always be the case is not conducive to good software engineering practices. It is not obvious to me that it's *always* the case. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Tue Nov 2 22:41:31 2010 From: usenet-nospam at seebs.net (Seebs) Date: 03 Nov 2010 02:41:31 GMT Subject: Trouble with importing References: Message-ID: On 2010-11-02, Ben Ahrens wrote: > I did indeed continue to top-post, and you should plonk me. Edited for accuracy. Done. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From ldo at geek-central.gen.new_zealand Tue Nov 2 22:45:02 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 03 Nov 2010 15:45:02 +1300 Subject: Python documentation too difficult for beginners References: <2010110223050345181-nizumzen@mcnuggetscom> Message-ID: In message <2010110223050345181-nizumzen at mcnuggetscom>, Nizumzen wrote: > On 2010-11-02 10:42:22 +0000, jk said: > >> I've been coding in PHP and Java for years, and their documentation is >> concise, well structured and easy to scan. > > Are you mad? Javadoc is one of the worst examples of source code > documentation I can possibly imagine. It appeals to corporate herds of code-cutter drones, though. It follows tedious rules that can be officially adopted as corporation policy, and cited as a conformance feature by third-party products that these corporations seem happy to spend money on. So the comments can be extracted from the code, sorted, collated, stamped, filed, indexed, and collated again, all as part of the make-work activity that seems to pass for actual productivity in so many big corporations. From python at mrabarnett.plus.com Tue Nov 2 23:01:17 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 03 Nov 2010 03:01:17 +0000 Subject: Must be a bug in the re module [was: Why this result with the re module] In-Reply-To: <259282.72742.qm@web54208.mail.re2.yahoo.com> References: <259282.72742.qm@web54208.mail.re2.yahoo.com> Message-ID: <4CD0D07D.5030903@mrabarnett.plus.com> On 03/11/2010 01:41, Yingjie Lan wrote: >> From: John Bond >> Subject: Re: Why this result with the re module >> To: "Yingjie Lan" >> Cc: python-list at python.org >> Date: Tuesday, November 2, 2010, 8:09 PM >> On 2/11/2010 12:19 PM, Yingjie Lan >> wrote: >>>> From: John Bond >>>> Subject: Re: Why this result with the re module >>> Firstly, thanks a lot for your patient explanation. >>> this time I have understood all your points >> perfectly. >>> >>> Secondly, I'd like to clarify some of my points, >> which >>> did not get through because of my poor presentation. >>> >>> I suggested findall return a tuple of >> re.MatchObject(s), >>> with each MatchObject instance representing a match. >>> This is consistent with the re.match() function >> anyway. >>> And it will eliminate the need of returning tuples, >>> and it is much more precise and information rich. >>> >>> If that's not possible, and a tuple must be returned, >>> then the whole match (not just subgroups) should >>> always be included as the first element in the tuple, >>> as that's group(0) or '\0'. Less surprise would >> arise. >>> >>> Finally, it seems to me the algo for findall is >> WRONG. >>> >>> To re.findall('(.a.)*', 'Mary has a lamb'), >>> by reason of greediness of '*', and the requirement >>> of non-overlapping, it should go like this >>> (suppose an '' is at the beginning and at the end, >>> and between two consecutive characters there is >>> one and only one empty string ''. To show the >>> match of empty strings clearly, >>> I am concatenating each repeated match below): >>> >>> Steps for re.findall('(.a.)*', 'Mary has a lamb'): >>> >>> step 1: Match '' + 'Mar' + '' (gready!) >>> step 2: skip 'y' >>> step 3: Match '' >>> step 4: skip ' ' >>> step 5: Match ''+'has'+' a '+'lam'+'' (greedy!) >>> step 6: skip 'b' >>> step 7: Match '' >>> >>> So there should be exactly 4 matches in total: >>> >>> 'Mar', '', 'has a lam', '' >>> >>> Also, the matches above shows >>> that if a repeated subgroup only captures >>> the last match, the subgroup (.a.)* >>> should always capture '' here (see steps >>> 1, 3, 5, 7) above. >>> >>> Yet the execution in Python results in 6 matches! >>> And, the capturing subgroup with repetition >>> sometimes got the wrong guy. >>> >>> So I believe the algorithm for findall must be WRONG. >>> >>> Regards, >>> >>> Yingjie >> At a guess, I'd say what is happening is something like >> this: >> >> Steps for re.findall('(.a.)*', 'Mary has a lamb'): >> >> step 1: Match 'Mar' at string index 0 >> step 2: Match '' at string index 3 (before 'y') >> step 3: skip 'y' >> step 4: Match '' at string index 4 (before ' ') >> step 5: skip ' ' >> step 6: Match 'has a lam' at string index 5 >> step 7: Match '' at string index 14 (before 'b') >> step 8: skip 'b' >> step 9: Match '' at string index 15 (before EOS) >> >> >> >> matches: ('Mar', '', '', 'has a lam', '', '') >> returns: ['Mar', '', '', 'lam', '', ''] (*) >> >> (*) "has a " lost due to not being last repetition at that >> match point >> >> Which seems about right to me! Greediness has nothing to do >> with it, except that it causes 'has a lam' to be matched in >> one match, instead of as three separate matches (of 'has', ' >> a ' and 'lam'). > > Disagree in this case, where the whole regex > matches an empty string. Greadiness will match > as much as possible. So it will also match > the empty strings between consecutive > characters as much as possible, once > we have properly defined all the unique > empty strings. Because of greadiness, > fewer matches should be found. In this > case, it should find only 4 matches > (shown in my steps) instead of 6 matches > (shown in your steps). > Attempt 1 starts at the beginning of the string: [Mar]y has a lamb Matches once, returns 'Mar' Attempt 2 starts where the previous match ended: Mar[]y has a lamb Matches an empty string, returns '' Attempt 3 starts where the previous match ended: Mary[] has a lamb Matches an empty string, returns '' Attempt 4 starts where the previous match ended: Mary [has][ a ][lam]b Matches 3 times, returns 'lam' Attempt 5 starts where the previous match ended: Mary has a lam[]b Matches an empty string, returns '' Attempt 6 starts where the previous match ended: Mary has a lamb[] Matches an empty string, returns '' The result is therefore ['Mar', '', '', 'lam', '', ''] From lists at asd-group.com Tue Nov 2 23:20:38 2010 From: lists at asd-group.com (John Bond) Date: Wed, 03 Nov 2010 03:20:38 +0000 Subject: Python documentation too difficult for beginners In-Reply-To: References: <2010110223050345181-nizumzen@mcnuggetscom> Message-ID: <4CD0D506.3080904@asd-group.com> My 2c: I use the ActiveState distro, and it's winhelp doco. It's generally ok and some things, like Dive Into Python, I've found excellent. But I do quite regularly find myself cursing at the vagueness of the index, and some of the content seems to require that you know it before you read it (I wish I could remember an example). Like everything, it could be improved. Cheers, JB From robert.kern at gmail.com Tue Nov 2 23:26:10 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 02 Nov 2010 22:26:10 -0500 Subject: Allowing comments after the line continuation backslash In-Reply-To: <87aalrjkty.fsf@benfinney.id.au> References: <4CCE6FF6.2050408@v.loewis.de> <87aalrjkty.fsf@benfinney.id.au> Message-ID: On 2010-11-02 19:46 , Ben Finney wrote: > Instead, I'd do:: > > styles = [ > ("normal", "image", MainWindow.ColorsNormalList), > ("highlighted", "highlight", MainWindow.ColorsHighlightedList), > ("selected", "select", MainWindow.ColorsSelectedList)] I'd go one step further: styles = [ ("normal", "image", MainWindow.ColorsNormalList), ("highlighted", "highlight", MainWindow.ColorsHighlightedList), ("selected", "select", MainWindow.ColorsSelectedList), ] Keeping the []s separate from the items and using the trailing comma means that I can easily add new items or reorder the items. -- 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 lanyjie at yahoo.com Tue Nov 2 23:28:09 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Tue, 2 Nov 2010 20:28:09 -0700 (PDT) Subject: Must be a bug in the re module [was: Why this result with the re module] In-Reply-To: <4CD0C94C.30701@melv.org> Message-ID: <495005.91127.qm@web54207.mail.re2.yahoo.com> > Your regex says "Zero or more consecutive occurrences of > something, always returning the most possible".? That's > what it does, at every position - only matching emptyness > where it couldn't match anything (findall then skips a > character to avoid overlapping/infinite empty > matches),? and at all other times matching the most > possible (eg. "has a lam" not "has", " a ", "lam"). You are about to convince me now. You are correct for the regex '(.a.)*'. What I thought was for this regex: '((.a.)*)*', I confused myself when I added an enclosing (). Could you please reconsider how would you work with this new one and see if my steps are correct? If you agree with my 7-step execution for the new regex, then: We finally found a real bug for re.findall: >>> re.findall('((.a.)*)*', 'Mary has a lamb') [('', 'Mar'), ('', ''), ('', ''), ('', 'lam'), ('', ''), ('', '')] Cheers, Yingjie From gunnerasch at gmail.com Tue Nov 2 23:33:18 2010 From: gunnerasch at gmail.com (Gunner Asch) Date: Tue, 02 Nov 2010 20:33:18 -0700 Subject: *** FBI gets a warm welcome in Chicago for their EXCELLENTperformance - cheers to NEW CONS *** References: <26f97f70-9043-490c-9e6e-35159f38d76b@r29g2000yqj.googlegroups.com> <47e0b3a3-54fb-4489-95a8-b5ec6015c99d@j25g2000yqa.googlegroups.com> Message-ID: <6vl1d6lbohrsgg6fucilc0dj235qfs5ak6@4ax.com> On Tue, 02 Nov 2010 13:58:16 -0700, Rich Grise wrote: >On Tue, 02 Nov 2010 14:17:29 -0700, Gunner Asch wrote: >> >> But...shrug..there will be far less after the Great Cull........ > >I think some people might be surprised as to exactly _who_ gets "culled". > >Good Luck! >Rich Indeed. So stock up, and watch your six. Gunner "Confiscating wealth from those who have earned it, inherited it, or got lucky is never going to help 'the poor.' Poverty isn't caused by some people having more money than others, just as obesity isn't caused by McDonald's serving super-sized orders of French fries Poverty, like obesity, is caused by the life choices that dictate results." - John Tucci, From lanyjie at yahoo.com Tue Nov 2 23:42:37 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Tue, 2 Nov 2010 20:42:37 -0700 (PDT) Subject: Must be a bug in the re module [was: Why this result with the re module] In-Reply-To: <4CD0D07D.5030903@mrabarnett.plus.com> Message-ID: <292222.415.qm@web54207.mail.re2.yahoo.com> > Matches an empty string, returns '' > > The result is therefore ['Mar', '', '', 'lam', '', ''] Thanks, now I see it through with clarity. Both you and JB are right about this case. However, what if the regex is ((.a.)*)* ? From lists at asd-group.com Tue Nov 2 23:55:44 2010 From: lists at asd-group.com (John Bond) Date: Wed, 03 Nov 2010 03:55:44 +0000 Subject: Must be a bug in the re module [was: Why this result with the re module] In-Reply-To: <495005.91127.qm@web54207.mail.re2.yahoo.com> References: <495005.91127.qm@web54207.mail.re2.yahoo.com> Message-ID: <4CD0DD40.6030306@asd-group.com> > Could you please reconsider how would you > work with this new one and see if my steps > are correct? If you agree with my 7-step > execution for the new regex, then: > > We finally found a real bug for re.findall: > >>>> re.findall('((.a.)*)*', 'Mary has a lamb') > [('', 'Mar'), ('', ''), ('', ''), ('', 'lam'), ('', ''), ('', '')] > > > Cheers, > > Yingjie > > > Nope, I'm afraid it is lack of understanding again. The outer capturing group that you've added is matching the entirety of what's matched by the inner one (which is six matches, that you now accept). Because it only returns the last of them, it returns one thing - an empty string (that being the last thing that the inner group matched). Findall is simply returning that in each of the six return values it needs to return because of the inner one. You just need to accept that findall (like all of re) works fine, and if it doesn't seem to do what you expect, it's because the expectation is wrong. Cheers, JB From python at mrabarnett.plus.com Wed Nov 3 00:02:45 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 03 Nov 2010 04:02:45 +0000 Subject: Must be a bug in the re module [was: Why this result with the re module] In-Reply-To: <292222.415.qm@web54207.mail.re2.yahoo.com> References: <292222.415.qm@web54207.mail.re2.yahoo.com> Message-ID: <4CD0DEE5.2060702@mrabarnett.plus.com> On 03/11/2010 03:42, Yingjie Lan wrote: >> Matches an empty string, returns '' >> >> The result is therefore ['Mar', '', '', 'lam', '', ''] > > Thanks, now I see it through with clarity. > Both you and JB are right about this case. > However, what if the regex is ((.a.)*)* ? > Actually, in hindsight, my explanation is slightly wrong! re.search and the others return None for an unmatched group, but re.findall returns '' for an unmatched group, so instead of saying: Matches an empty string, returns '' I should have said: The group doesn't match at all, so .findall returns '' As for "((.a.)*)*", the inner group and repeat match like before, but then the outer repeat and group try again. The inner group can't match again, so it's unchanged (and it still remembers the last successful capture), and the outer group therefore matches an empty string. Therefore the outer (first) group is always an empty string and the inner (second) group is the same as the previous example (the last capture or '' if no capture). From lists at asd-group.com Wed Nov 3 00:09:17 2010 From: lists at asd-group.com (John Bond) Date: Wed, 03 Nov 2010 04:09:17 +0000 Subject: Must be a bug in the re module [was: Why this result with the re module] In-Reply-To: <4CD0DD40.6030306@asd-group.com> References: <495005.91127.qm@web54207.mail.re2.yahoo.com> <4CD0DD40.6030306@asd-group.com> Message-ID: <4CD0E06D.6010400@asd-group.com> On 3/11/2010 3:55 AM, John Bond wrote: > >> Could you please reconsider how would you >> work with this new one and see if my steps >> are correct? If you agree with my 7-step >> execution for the new regex, then: >> >> We finally found a real bug for re.findall: >> >>>>> re.findall('((.a.)*)*', 'Mary has a lamb') >> [('', 'Mar'), ('', ''), ('', ''), ('', 'lam'), ('', ''), ('', '')] >> >> >> Cheers, >> >> Yingjie >> >> >> > > Nope, I'm afraid it is lack of understanding again. > > The outer capturing group that you've added is matching the entirety > of what's matched by the inner one (which is six matches, that you now > accept). Because it only returns the last of them, it returns one > thing - an empty string (that being the last thing that the inner > group matched). Findall is simply returning that in each of the six > return values it needs to return because of the inner one. > > You just need to accept that findall (like all of re) works fine, and > if it doesn't seem to do what you expect, it's because the expectation > is wrong. > > Cheers, JB Just to clarify - findall is returning: [ (only match in outer group, 1st match in inner group) , (only match in outer group, 2nd match in inner group) , (only match in outer group, 3rd match in inner group) , (only match in outer group, 4th match in inner group) , (only match in outer group, 5th match in inner group) , (only match in outer group, 6th match in inner group) ] Where "only match in outer group" = "6th match in inner group" owing to the way that capturing groups with repetition only return the last thing they matched. Cheers, JB From lists at asd-group.com Wed Nov 3 00:10:57 2010 From: lists at asd-group.com (John Bond) Date: Wed, 03 Nov 2010 04:10:57 +0000 Subject: Must be a bug in the re module [was: Why this result with the re module] In-Reply-To: <4CD0DEE5.2060702@mrabarnett.plus.com> References: <292222.415.qm@web54207.mail.re2.yahoo.com> <4CD0DEE5.2060702@mrabarnett.plus.com> Message-ID: <4CD0E0D1.7070902@asd-group.com> On 3/11/2010 4:02 AM, MRAB wrote: > On 03/11/2010 03:42, Yingjie Lan wrote: >>> Matches an empty string, returns '' >>> >>> The result is therefore ['Mar', '', '', 'lam', '', ''] >> >> Thanks, now I see it through with clarity. >> Both you and JB are right about this case. >> However, what if the regex is ((.a.)*)* ? >> > Actually, in hindsight, my explanation is slightly wrong! > > re.search and the others return None for an unmatched group, but > re.findall returns '' for an unmatched group, so instead of saying: > > Matches an empty string, returns '' > > I should have said: > > The group doesn't match at all, so .findall returns '' > > As for "((.a.)*)*", the inner group and repeat match like before, but > then the outer repeat and group try again. > > The inner group can't match again, so it's unchanged (and it still > remembers the last successful capture), and the outer group therefore > matches an empty string. > > Therefore the outer (first) group is always an empty string and the > inner (second) group is the same as the previous example (the last > capture or '' if no capture). Now I'm confused - how can something with "zero or more occurrences" not match? Cheers, JB From gnarlodious at gmail.com Wed Nov 3 00:16:11 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Tue, 2 Nov 2010 21:16:11 -0700 (PDT) Subject: Py3: decode subprocess output Message-ID: Under Python 2.6, commands.getoutput returns text type str containing ANSI Terminal formatting hex characters: "\x1b[1;31mSun : \x1b[1;36m114.902\x1b[0m - 0\xf800' (-)\x1b[1;33m I have a system for parsing out the relevant parts and I prefer to keep using that system. Under Python 3, subprocess.check_output returns a bytestring that doesn't parse. Since the CLI program (written in the 1990's) will never send Unicode, is there a way to downconvert the bytestring into type str so as to emulate Py2.6 behavior? Or alternatively, is there a whizbang Py3 method to parse out strings delimited by hex? I tried several tricks but it is all beyond my skills. Thanks. -- Gnarlie From lanyjie at yahoo.com Wed Nov 3 00:17:07 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Tue, 2 Nov 2010 21:17:07 -0700 (PDT) Subject: Must be a bug in the re module [was: Why this result with the re module] In-Reply-To: <4CD0E06D.6010400@asd-group.com> Message-ID: <333352.24512.qm@web54202.mail.re2.yahoo.com> --- On Wed, 11/3/10, John Bond wrote: > Just to clarify - findall is returning: > > [ (only match in outer group, 1st match in inner group) > , (only match in outer group, 2nd match in inner group) > , (only match in outer group, 3rd match in inner group) > , (only match in outer group, 4th match in inner group) > , (only match in outer group, 5th match in inner group) > , (only match in outer group, 6th match in inner group) > ] > > Where "only match in outer group" = "6th match in inner > group" owing to the way that capturing groups with > repetition only return the last thing they matched. > ---On Wed, 11/3/10, MRAB wrote------- > Therefore the outer (first) group is always an empty string and the > inner (second) group is the same as the previous example (the last > capture or '' if no capture). OK, I've got that, and I have no problem with the capturing part. My real problem is with the number of total matches. I think it should be 4 matches in total but findall gives 6 matches, for the new regex '((.a.)*)*'. I'd love to know what you think about this. Many thanks! Yingjie From lanyjie at yahoo.com Wed Nov 3 00:23:11 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Tue, 2 Nov 2010 21:23:11 -0700 (PDT) Subject: Must be a bug in the re module [was: Why this result with the re module] In-Reply-To: <4CD0DEE5.2060702@mrabarnett.plus.com> Message-ID: <66841.34190.qm@web54202.mail.re2.yahoo.com> --- On Wed, 11/3/10, MRAB wrote: > From: MRAB > Subject: Re: Must be a bug in the re module [was: Why this result with the re module] > To: python-list at python.org > Date: Wednesday, November 3, 2010, 8:02 AM > On 03/11/2010 03:42, Yingjie Lan > wrote: > Therefore the outer (first) group is always an empty string > and the > inner (second) group is the same as the previous example > (the last > capture or '' if no capture). Now I am confused also: If the outer group \1 is empty, how could the inner group \2 actually have something? Yingjie From ben+python at benfinney.id.au Wed Nov 3 00:24:15 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 03 Nov 2010 15:24:15 +1100 Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> <87aalrjkty.fsf@benfinney.id.au> Message-ID: <87wrovhw5s.fsf@benfinney.id.au> Robert Kern writes: > I'd go one step further: > > styles = [ > ("normal", "image", MainWindow.ColorsNormalList), > ("highlighted", "highlight", MainWindow.ColorsHighlightedList), > ("selected", "select", MainWindow.ColorsSelectedList), > ] > > Keeping the []s separate from the items and using the trailing comma > means that I can easily add new items or reorder the items. No problem with that, except I'd still keep the closing character indented:: styles = [ ("normal", "image", MainWindow.ColorsNormalList), ("highlighted", "highlight", MainWindow.ColorsHighlightedList), ("selected", "select", MainWindow.ColorsSelectedList), ] because it's consistent with how lines are grouped everywhere else in Python: the grouping continues while the same indentation level continues, and stops once the indentation stops. -- \ ?By instructing students how to learn, unlearn, and relearn, a | `\ powerful new dimension can be added to education.? ?Alvin | _o__) Toffler, _Future Shock_, 1970 | Ben Finney From lists at asd-group.com Wed Nov 3 00:33:15 2010 From: lists at asd-group.com (John Bond) Date: Wed, 03 Nov 2010 04:33:15 +0000 Subject: Must be a bug in the re module [was: Why this result with the re module] In-Reply-To: <333352.24512.qm@web54202.mail.re2.yahoo.com> References: <333352.24512.qm@web54202.mail.re2.yahoo.com> Message-ID: <4CD0E60B.7010402@asd-group.com> > OK, I've got that, and I have no problem with the capturing part. > My real problem is with the number of total matches. > *I think it should be 4 matches in total but findall > gives 6 matches*, for the new regex '((.a.)*)*'. > I'd love to know what you think about this. > > Many thanks! > Yingjie > > > > We've already been through that, and nothing's changed - all you've done is: 1) taken something that you know (now!) has six matches: (.a.)* 2) added an outer capturing group (which does not change the actual matches, only what gets returned): ((.a.)*) 3) then said there must be >=0 occurrences of what's inside it, which of course there is, so that has no effect. ((.a.)*)* End result: the matching is exactly the same, findall still needs to return the 6 things it did in the first place, but now it also has to return an extra value at each return location (that being what's captured by the new outer group) hence the tuples. Cheers, JB -------------- next part -------------- An HTML attachment was scrubbed... URL: From tlikonen at iki.fi Wed Nov 3 00:34:20 2010 From: tlikonen at iki.fi (Teemu Likonen) Date: Wed, 03 Nov 2010 06:34:20 +0200 Subject: Man pages and info pages References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> <024ef21a-9ef9-48a6-8372-1d66895583c3@v16g2000yqn.googlegroups.com> <87zktr5yze.fsf_-_@mithlond.arda> Message-ID: <877hgv2fg3.fsf@mithlond.arda> * 2010-11-02 19:36 (UTC), Tim Harig wrote: > On 2010-11-02, Teemu Likonen wrote: >> There is also the problem that people are less familiar with info >> browsers than the usual "less" pager which is used by "man" command. > > I thoroughly agree. The default info viewers are quite possibly the > most counterintuitive programs I have ever encountered. I never did > bother to learn how to use them. I instead installed the more > intuitive pinfo program. It seems that we only agree on the part that I explicitly wrote about: people are less familiar with info browsers than "less" pager. I didn't mean to imply any reasons why this might be the case. I think "info" browser is intuitive and easy to use. The basic commands: Enter Follow a link (down to node) u up node level h help (general how-to) ? help (commands) s search Arrow keys, page up, page down keys work as usual. What's counter-intuitive in it? >> With the text terminal info browser called "info" as well as Emacs' >> info browser you can use command "s" (stands for "search"). It >> prompts for a regexp pattern to search in the whole document, >> including subsections etc. > > Right, pinfo offers this as well; but, then you have to figure out > where in the nodes that the search has taken you and how to navigate > from that node to find additional information that you may need. I usually return to the top node with "t" command or go one or more levels up in the tree with "u" command. The first line in the window tells where I am. From lists at asd-group.com Wed Nov 3 00:43:18 2010 From: lists at asd-group.com (John Bond) Date: Wed, 03 Nov 2010 04:43:18 +0000 Subject: Must be a bug in the re module [was: Why this result with the re module] In-Reply-To: <66841.34190.qm@web54202.mail.re2.yahoo.com> References: <66841.34190.qm@web54202.mail.re2.yahoo.com> Message-ID: <4CD0E866.7070707@asd-group.com> On 3/11/2010 4:23 AM, Yingjie Lan wrote: > --- On Wed, 11/3/10, MRAB wrote: > >> From: MRAB >> Subject: Re: Must be a bug in the re module [was: Why this result with the re module] >> To: python-list at python.org >> Date: Wednesday, November 3, 2010, 8:02 AM >> On 03/11/2010 03:42, Yingjie Lan >> wrote: >> Therefore the outer (first) group is always an empty string >> and the >> inner (second) group is the same as the previous example >> (the last >> capture or '' if no capture). > Now I am confused also: > > If the outer group \1 is empty, how could the inner > group \2 actually have something? > > Yingjie > > > I just explained that (I think!)! The outer capturing group uses repetition, so it returns the last thing that was matched by the inner group, which was an empty string. I If you took away the outer groups repetition: re.findall('((.a.)*)', 'Mary has a lamb') then, for each of the six matches, it returns the full thing that was matched: ('Mar', 'Mar'), ('', ''), ('', ''), ('has a lam', 'lam'), ('', ''), ('', '')] Cheers, JB From mygogo2011 at gmail.com Wed Nov 3 00:56:43 2010 From: mygogo2011 at gmail.com (PHP.CCC) Date: Tue, 2 Nov 2010 21:56:43 -0700 (PDT) Subject: Coca Cola Scholarship: Are You Qualified? Message-ID: <4fc593c3-9e29-47dd-9051-b165ebff80c6@s5g2000yqm.googlegroups.com> Coca Cola Scholarship: Are You Qualified? Before you apply for Coca Cola scholarship, here are the things you should know: Coca-Cola Scholars Foundation programs There are two types of Coca-Cola Scholars Foundation programs: ?2-Year Colleges Scholarship Program ? Scholars Program for high school seniors 1. 2-Year Colleges Scholarship Program Read more.... http://childschooledu.blogspot.com From usernet at ilthio.net Wed Nov 3 01:08:45 2010 From: usernet at ilthio.net (Tim Harig) Date: Wed, 3 Nov 2010 05:08:45 +0000 (UTC) Subject: Man pages and info pages References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> <024ef21a-9ef9-48a6-8372-1d66895583c3@v16g2000yqn.googlegroups.com> <87zktr5yze.fsf_-_@mithlond.arda> <877hgv2fg3.fsf@mithlond.arda> Message-ID: On 2010-11-03, Teemu Likonen wrote: > * 2010-11-02 19:36 (UTC), Tim Harig wrote: >> I thoroughly agree. The default info viewers are quite possibly the >> most counterintuitive programs I have ever encountered. I never did >> bother to learn how to use them. I instead installed the more >> intuitive pinfo program. > > It seems that we only agree on the part that I explicitly wrote about: > people are less familiar with info browsers than "less" pager. I didn't > mean to imply any reasons why this might be the case. I think "info" The reason is really simple. Less' interface derives from more. Less and more have a long history on the *nix platform and many programs have emulated their interface. When the GNU folk decided to clone *nix they decided that they knew better and simply decided to create their own interfaces. I guess they figured that everybody loves to have to learn multiple varying interfaces to use different programs. > browser is intuitive and easy to use. The basic commands: [SNIP] > Arrow keys, page up, page down keys work as usual. Actually, the left arrow key does not work at all intuitively. One would expect that it should go back to the previous page as it would in lynx, etc. It does not. By tradition 'n' and 'p' are broken for scrolling in a page. 'b' is often used in place of p but that seems to take one back to the top of the page. The s key for a search is another example that has already been discussed. > What's counter-intuitive in it? Maybe its intutitive to an emacs user; but, I find pinfo's default key bindings much easier. >>> With the text terminal info browser called "info" as well as Emacs' >>> info browser you can use command "s" (stands for "search"). It >>> prompts for a regexp pattern to search in the whole document, >>> including subsections etc. >> >> Right, pinfo offers this as well; but, then you have to figure out >> where in the nodes that the search has taken you and how to navigate >> from that node to find additional information that you may need. > > I usually return to the top node with "t" command or go one or more > levels up in the tree with "u" command. The first line in the window > tells where I am. That assumes that you understand the node structure used or that you don't mind returning to the top and having to re-walk the node structure every time that you want to find new piece of information. I already discussed that just finding the info pages can be difficult because you have to know that they are stored under the package name and that multiple pages can be used for man page structure. From rantingrick at gmail.com Wed Nov 3 01:17:20 2010 From: rantingrick at gmail.com (rantingrick) Date: Tue, 2 Nov 2010 22:17:20 -0700 (PDT) Subject: Python documentation too difficult for beginners References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> <024ef21a-9ef9-48a6-8372-1d66895583c3@v16g2000yqn.googlegroups.com> <4716193c-2e9f-4469-b8c7-bba600fba8a2@p1g2000yqm.googlegroups.com> Message-ID: <13cc0ada-88a3-4a95-9fb8-d376664bed0c@p1g2000yqm.googlegroups.com> AD i agree with you! The official python tutorial and the official docs are pretty much a twisted mass of confusion to the initiated programmer. Even today when i try yo search the docs i find the result quite frankly useless. And the search reminds me of the old XP "puppy dog" search. The doc ARE fairly well written HOWEVER the search engine needs an update. For me, i just Google it, and forget it! From usernet at ilthio.net Wed Nov 3 01:20:52 2010 From: usernet at ilthio.net (Tim Harig) Date: Wed, 3 Nov 2010 05:20:52 +0000 (UTC) Subject: Mail Merge from python data References: Message-ID: This page didn't make it to through to my nntp server so I appologize if I miss something that was covered. On 2010-11-03, Dennis Lee Bieber wrote: > On Tue, 2 Nov 2010 20:32:13 +1000, Dylan Evans > declaimed the following in gmane.comp.python.general: > >> I'm setting up a database for an organisation who want to do mail merges in >> office 2010. I know i can use the MySQL ODBC driver for the mail merge but i >> have set up the database with lots of relations and many-to-many links which >> i'm sure will lead to a huge amount of confusion (I think, i don't really >> know much about mail merge). Many to many relationships without some kind of intersection table are considered a rather poor practice in general. >> What i want to know is, is there anyway to send data from python, which the >> UI is written in, to office templates and mail merges? > > If a long lived form, I'd probably define a query or view (I think > MySQL 5.x has output-only views) that isolates just to the data fields > used in the mail merge. I agree that a view would be the best solution if you have the access to do so; but, a couple of other alternatives come to mind in case you do not. 1. Do the mail merge in Python using a Word template. Then you can add any kind of logic that you need to the merge. 2. Add some kind of export function to your python UI that allows you to export the data to an Excel sheet, CSV, or even another ODBC data source (like another MySQL table or database that you might have access to). From lanyjie at yahoo.com Wed Nov 3 02:16:29 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Tue, 2 Nov 2010 23:16:29 -0700 (PDT) Subject: Must be a bug in the re module [was: Why this result with the re module] Message-ID: <869719.99302.qm@web54202.mail.re2.yahoo.com> --- On Wed, 11/3/10, John Bond wrote: > 3) then said there must be >=0 occurrences of what's inside it, > which of course there is, so that has no effect. > > ((.a.)*)* Hi, I think there should be a difference: unlike before, now what's inside the outer group can match an empty string. And so by reason of the greediness of the quantifier * of the outer group (that is, the last *), it should take up the empty string after each non-empty match. So, the first match in 'Mary has a lamb' must be: '' + 'Mar' + '' (the empty string before the 'y') (note the first '' is before the 'M') Then, after skipping the 'y' (remember, the empty string before 'y' is already taken), comes a second: '' (the one between 'y' and ' ') Then after skipping the space ' ', comes a third: 'has' + ' a ' + 'lam' + '' (the empty string before the 'b') And finally, it matches the empty string after 'b': '' So there should be total of four matches -- isn't it? Yingjie From iwawi123 at gmail.com Wed Nov 3 02:26:06 2010 From: iwawi123 at gmail.com (iwawi) Date: Tue, 2 Nov 2010 23:26:06 -0700 (PDT) Subject: text file reformatting References: <78daefd1-59a1-4b3a-9bc2-5910315515ce@r14g2000yqa.googlegroups.com> <57ec83dd-3f30-4000-acf6-f49a44568d22@k22g2000yqh.googlegroups.com> <31a905d6-982d-479d-b988-e8324a1a16c7@j25g2000yqa.googlegroups.com> Message-ID: On Nov 1, 6:50?pm, "cbr... at cbrownsystems.com" wrote: > On Nov 1, 1:58?am, iwawi wrote: > > > > > > > On 1 marras, 09:59, "cbr... at cbrownsystems.com" > > > wrote: > > > On Oct 31, 11:46?pm, iwawi wrote: > > > > > On 31 loka, 21:48, Tim Chase wrote: > > > > > > > PRJ01001 4 00100END > > > > > > PRJ01002 3 00110END > > > > > > > I would like to pick only some columns to a new file and put them to a > > > > > > certain places (to match previous data) - definition file (def.csv) > > > > > > could be something like this: > > > > > > > VARIABLE ? FIELDSTARTS ? ? FIELD SIZE ? ? ?NEW PLACE IN NEW DATA FILE > > > > > > ProjID ? ? ; ? ? ? 1 ? ? ? ; ? ? ? 5 ? ? ? ; ? ? ? 1 > > > > > > CaseID ? ? ; ? ? ? 6 ? ? ? ; ? ? ? 3 ? ? ? ; ? ? ? 10 > > > > > > UselessV ?; ? ? ? ?10 ? ? ?; ? ? ? 1 ? ? ? ; > > > > > > Zipcode ? ?; ? ? ? 12 ? ? ?; ? ? ? 5 ? ? ? ; ? ? ? 15 > > > > > > > So the new datafile should look like this: > > > > > > > PRJ01 ? ?001 ? ? ? 00100END > > > > > > PRJ01 ? ?002 ? ? ? 00110END > > > > > > How flexible is the def.csv format? ?The difficulty I see with > > > > > your def.csv format is that it leaves undefined gaps (presumably > > > > > to be filled in with spaces) and that you also have a blank "new > > > > > place in new file" value. ?If instead, you could specify the > > > > > width to which you want to pad it and omit variables you don't > > > > > want in the output, ordering the variables in the same order you > > > > > want them in the output: > > > > > > ? Variable; Start; Size; Width > > > > > ? ProjID; 1; 5; 10 > > > > > ? CaseID; 6; 3; 10 > > > > > ? Zipcode; 12; 5; 5 > > > > > ? End; 16; 3; 3 > > > > > > (note that I lazily use the same method to copy the END from the > > > > > source to the destination, rather than coding specially for it) > > > > > you could do something like this (untested) > > > > > > ? ?import csv > > > > > ? ?f = file('def.csv', 'rb') > > > > > ? ?f.next() # discard the header row > > > > > ? ?r = csv.reader(f, delimiter=';') > > > > > ? ?fields = [ > > > > > ? ? ?(varname, slice(int(start), int(start)+int(size)), width) > > > > > ? ? ?for varname, start, size, width > > > > > ? ? ?in r > > > > > ? ? ?] > > > > > ? ?f.close() > > > > > ? ?out = file('out.txt', 'w') > > > > > ? ?try: > > > > > ? ? ?for row in file('data.txt'): > > > > > ? ? ? ?for varname, slc, width in fields: > > > > > ? ? ? ? ?out.write(row[slc].ljust(width)) > > > > > ? ? ? ?out.write('\n') > > > > > ? ?finally: > > > > > ? ? ?out.close() > > > > > > Hope that's fairly easy to follow and makes sense. ?There might > > > > > be some fence-posting errors (particularly your use of "1" as the > > > > > initial offset, while python uses "0" as the initial offset for > > > > > strings) > > > > > > If you can't modify the def.csv format, then things are a bit > > > > > more complex and I'd almost be tempted to write a script to try > > > > > and convert your existing def.csv format into something simpler > > > > > to process like what I describe. > > > > > > -tkc- Piilota siteerattu teksti - > > > > > > - N?yt? siteerattu teksti - > > > > > Hi, > > > > > Thanks for your reply. > > > > > Def.csv could be modified so that every line has the same structure: > > > > variable name, field start, field size and new place and would be > > > > separated with semicolomns as you mentioned. > > > > > I tried your script (which seems quite logical) but I get this > > > > > Traceback (most recent call last): > > > > ? File "testing.py", line 16, in > > > > ? ? out.write (row[slc].ljust(width)) > > > > TypeError: an integer is required > > > > > Yes - you said it was untested, but I can't figure out how to > > > > proceed... > > > > The line > > > > ? ? (varname, slice(int(start), int(start)+int(size)), width) > > > > should instead be > > > > ? ? (varname, slice(int(start), int(start)+int(size)), int(width)) > > > > although you give an example where there is no width - what does that > > > imply? In the above case, it will throw an exception. > > > > Anyway, I think you'll find there's something a bit off in the output > > > loop with the parameter passed to ljust() as well. The value given in > > > your csv seems to be the absolute position, but as it's implemented by > > > Tim, it acts as the relative position. > > > > Given Tim's parsing into the list fields, I have a feeling that what > > > you really want instead of > > > > ? ? for varname, slc, width in fields: > > > ? ? ? ? out.write(row[slc].ljust(width)) > > > ? ? out.write('\n') > > > > is to have > > > > ? ? s = '' > > > ? ? for varname, slc, width in fields: > > > ? ? ? ? s += " "*(width - len(s)) + row[slc] > > > ? ? out.write(s+'\n') > > > > And if that is what you want, then you will surely want to globally > > > replace the name 'width' with for example 'start_column', because then > > > it all makes sense :). > > > > Cheers - Chas- Piilota siteerattu teksti - > > > > - N?yt? siteerattu teksti - > > > Yes, it's meant to be the absolute column position in a new file like > > you said. > > > I used your changes to the csv-reading cause it seems more flexible, > > but the end of the code is still not working. Here's were I stand now: > > > import re > > > parse_columns = re.compile(r'\s*;\s*') > > > f = file('def.csv', 'rb') > > f.readline() # discard the header row > > r = (parse_columns.split(line.strip()) for line in f) > > fields = [ > > ?(varname, slice(int(start), int(start)+int(size), int(width) if width > > else 0)) > > there's a misplaced parentheses; replace the above line (which yields > a 2-tuple of values) with: > > ? (varname, slice(int(start), int(start)+int(size)), int(width) if > width else 0) > > which yields a 3-tuple. > > Cheers - Chas > > > > > ? for varname, start, size, width in r > > ?] > > f.close() > > print fields > > > out = file('out.txt', 'w') > > > try: > > ?for row in file('data.txt'): > > ? s = ' ' > > ? for varname, slc, width in fields: > > ? ?s += " "*(width - len(s)) + row[slc] > > ? out.write(s+'\n') > > finally: > > ?out.close() > > > When executed, I get this: > > ? File "toimi.py", line 20, in > > ? ? for varname, slc, width in fields: > > ValueError: need more than 2 values to unpack- Hide quotedtext- > > - Show quotedtext-- Hide quotedtext- > > - Show quotedtext- I could not thank you enough - you totally solved my problem and speeded up my routine about 1500 %, if not more. Many thanks man! -iwawi From vgnulinux at gmail.com Wed Nov 3 02:32:04 2010 From: vgnulinux at gmail.com (VGNU Linux) Date: Wed, 3 Nov 2010 12:02:04 +0530 Subject: How to highlight Label/Text in tkinter ? Message-ID: Hi, I am writing a program teach myself python and tkinter. Below given is a program which displays label with different fonts and sizes. How to highlight text and change font size if the up/down arrow keys are pressed ? from Tkinter import * import tkFont class MyFrame(Frame): def __init__(self, root): Frame.__init__(self, root) self.txt = Label(self, text="Arial 10 bold", font=("Arial",10,"bold")) self.txt.grid(row=1,column=1) self.txt = Label(self, text="Courier 12 bold", font=("Courier",12,"bold")) self.txt.grid(row=2,column=1) self.txt = Label(self, text="Comic Sans MS 14 bold", font=("Comic Sans MS",14,"bold")) self.txt.grid(row=3,column=1) self.txt = Label(self, text="Fixedsys 16 bold", font=("Fixedsys",16,"bold")) self.txt.grid(row=4,column=1) self.txt = Label(self, text="MS Sans Serif 18 bold", font=("MS Sans Serif",18,"bold")) self.txt.grid(row=5,column=1) self.txt = Label(self, text="MS Serif, Symbol 20 bold", font=("MS Serif, Symbol",20,"bold")) self.txt.grid(row=6,column=1) self.txt = Label(self, text="System 22 bold", font=("System",22,"bold")) self.txt.grid(row=7,column=1) self.txt = Label(self, text="Verdana 24 bold", font=("Verdana",24,"bold")) self.txt.grid(row=8,column=1) if __name__ == '__main__': root = Tk() c = MyFrame(root) c.pack(fill=BOTH, expand=1) root.mainloop() any help? Regards, VGNU -------------- next part -------------- An HTML attachment was scrubbed... URL: From lanyjie at yahoo.com Wed Nov 3 02:32:18 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Tue, 2 Nov 2010 23:32:18 -0700 (PDT) Subject: Must be a bug in the re module [was: Why this result with the re module] In-Reply-To: <4CD0E866.7070707@asd-group.com> Message-ID: <844169.1635.qm@web54201.mail.re2.yahoo.com> --- On Wed, 11/3/10, John Bond wrote: > I just explained that (I think!)! The outer capturing group > uses > repetition, so it returns the last thing that was matched > by the inner > group, which was an empty string. > According to yourself, the last match of the inner group is also empty! Generally speaking, as a match for the outer group always contains some matches for the inner group, it must be the case that the last match for the inner group must be contained inside the last match of the outer group. So if the last match of the outer group is empty, then the last match for the inner group must also be empty. Regards, Yingjie --- On Wed, 11/3/10, John Bond wrote: > From: John Bond > Subject: Re: Must be a bug in the re module [was: Why this result with the re module] > To: python-list at python.org > Date: Wednesday, November 3, 2010, 8:43 AM > On 3/11/2010 4:23 AM, Yingjie Lan > wrote: > > --- On Wed, 11/3/10, MRAB? > wrote: > > > >> From: MRAB > >> Subject: Re: Must be a bug in the re module [was: > Why this result with the re module] > >> To: python-list at python.org > >> Date: Wednesday, November 3, 2010, 8:02 AM > >> On 03/11/2010 03:42, Yingjie Lan > >> wrote: > >> Therefore the outer (first) group is always an > empty string > >> and the > >> inner (second) group is the same as the previous > example > >> (the last > >> capture or '' if no capture). > > Now I am confused also: > > > > If the outer group \1 is empty, how could the inner > > group \2 actually have something? > > > > Yingjie > > > > > > > I just explained that (I think!)! The outer capturing group > uses > repetition, so it returns the last thing that was matched > by the inner > group, which was an empty string. I > > If you took away the outer groups repetition: > > re.findall('((.a.)*)', 'Mary has a lamb') > > then, for each of the six matches, it returns the full > thing that was > matched: > > ('Mar', 'Mar'), ('', ''), ('', ''), ('has a lam', 'lam'), > ('', ''), ('', > '')] > > Cheers, JB > -- > http://mail.python.org/mailman/listinfo/python-list > From martin at v.loewis.de Wed Nov 3 03:34:19 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Wed, 03 Nov 2010 08:34:19 +0100 Subject: Py3: decode subprocess output In-Reply-To: References: Message-ID: > Under Python 3, subprocess.check_output returns a bytestring that > doesn't parse. Since the CLI program (written in the 1990's) will > never send Unicode, is there a way to downconvert the bytestring into > type str so as to emulate Py2.6 behavior? What do you mean by "that doesn't parse"? Returning a byte string is *already* emulating 2.6's behaviour: in 2.6, you also get a byte string, and most likely the very same string. > Or alternatively, is there a whizbang Py3 method to parse out strings > delimited by hex? I tried several tricks but it is all beyond my > skills. Please understand that there really aren't "hex characters" here. Each individual character is a byte, i.e. "Sun" == "\x53\x75\x6d". So the strings you get aren't delimited by a "hex character", but by a "control character". That said: how did you try to parse it, and how did that fail? Regards, Martin From ldo at geek-central.gen.new_zealand Wed Nov 3 03:48:10 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 03 Nov 2010 20:48:10 +1300 Subject: Python documentation too difficult for beginners References: Message-ID: In message , Dennis Lee Bieber wrote: > Whereas I have a whole shelf of Java documentation and it still > takes me an hour to write "Hello World"... Java's one class per file > results in a plethora of bloody names one has to remember just to find > out where to start looking for a standard library operation. You know Alan Kay?s dictum that ?simple things should be simple, and complex things should be possible?? Well, Java isn?t designed to make simple things simple. :) From ldo at geek-central.gen.new_zealand Wed Nov 3 03:50:40 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 03 Nov 2010 20:50:40 +1300 Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> Message-ID: In message , Roy Smith wrote: > In article , > Lawrence D'Oliveiro wrote: > >> In message , Roy Smith wrote: >> >> > In this case, I think I would do: >> > >> > styles = [("normal", "image", MainWindow.ColorsNormalList), >> > ("highlighted", "highlight", >> > MainWindow.ColorsHighlightedList), >> > ("selected", "select", MainWindow.ColorsSelectedList)] >> > >> > for in description, attr, color_list in styles: >> > blah, blah, blah >> >> And so you have managed to separate one set of looping conditions into >> two parts. What is the significance of the name ?styles?? None at all. >> What purpose does it serve? None, really. Does it ease the maintenance >> burden? No, but by splitting your attention across two places, it >> actually adds to it. > > I suppose readability is in the eye of the reader, but, yes, I agree > that I have split this into two parts. The parts are > > 1) The table of data > > 2) The looping construct But the table of data makes no sense outside of the looping construct. That table does nothing other than define the bounds of the loop. Without the loop, it has no reason to exist. It makes no more sense than styles = range(0, 100) for i in styles : ... > Where we seem to disagree is whether that makes things more or less > readable :-) To me, it makes is more readable because it lets me > understand one chunk, then move on to understanding the next chunk. Which means you don?t understand the purpose of the code at all. Go look at it in its entirety, and you?ll see what I mean. From ldo at geek-central.gen.new_zealand Wed Nov 3 03:52:16 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 03 Nov 2010 20:52:16 +1300 Subject: functions, list, default parameters References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <4cc13ef5$0$29979$c3e8da3$5496439d@news.astraweb.com> <4ccffd1c$0$29966$c3e8da3$5496439d@news.astraweb.com> <5f6eceec-1eef-4db7-82a6-e5f553349229@k22g2000yqh.googlegroups.com> Message-ID: In message <5f6eceec-1eef-4db7-82a6-e5f553349229 at k22g2000yqh.googlegroups.com>, Ian wrote: > It seems to me that there is a rather simple case to be made for > allowing mutable default arguments: instances of user-defined classes > are fundamentally mutable. Disallowing mutable default arguments > would mean disallowing instances of user-defined classes entirely. > That would be excessive and would violate Python's general rule of > staying out of the programmer's way. Unless you offered a way for user-defined classes to declare that they were immutable. From clp2 at rebertia.com Wed Nov 3 04:02:27 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 3 Nov 2010 01:02:27 -0700 Subject: Allowing comments after the line continuation backslash In-Reply-To: References: <4CCE6FF6.2050408@v.loewis.de> Message-ID: On Mon, Nov 1, 2010 at 8:15 PM, Lawrence D'Oliveiro wrote: > In message , Chris > Rebert wrote: > >> desc_attr_colors_triples = (("normal", "image", >> MainWindow.ColorsNormalList), >> ? ? ("highlighted", "highlight", MainWindow.ColorsHighlightedList), >> ? ? ("selected", "select", MainWindow.ColorsSelectedList)) >> for in description, attr, color_list in desc_attr_colors_triples: >> ? ? ... > > And so you have managed to separate one set of looping conditions into two > parts. What is the significance of the name ?desc_attr_colors_triples?? None > at all. What purpose does it serve? None, really. Does it ease the > maintenance burden? No, but by splitting your attention across two places, > it actually adds to it. > > If this is all your PEP-8 can achieve, then a pox on it. Actually, my PEP 8 reference was in regards to the (imo, terrible) UseOfCamelCaseForNonClasses (Python != C#), not the formatting of the for-loop; hence the "In any case" qualification. Cheers, Chris From lists at asd-group.com Wed Nov 3 04:02:29 2010 From: lists at asd-group.com (John Bond) Date: Wed, 3 Nov 2010 08:02:29 +0000 (UTC) Subject: What people are using to access this mailing list Message-ID: Hope this isn't too O/T - I was just wondering how people read/send to this mailing list, eg. normal email client, gmane, some other software or online service? My normal inbox is getting unmanageable, and I think I need to find a new way of following this and other lists. Thanks for any suggestions. Cheers, JB. From usernet at ilthio.net Wed Nov 3 04:03:54 2010 From: usernet at ilthio.net (Tim Harig) Date: Wed, 3 Nov 2010 08:03:54 +0000 (UTC) Subject: Py3: decode subprocess output References: Message-ID: On 2010-11-03, Gnarlodious wrote: > Under Python 3, subprocess.check_output returns a bytestring that > doesn't parse. Since the CLI program (written in the 1990's) will > never send Unicode, is there a way to downconvert the bytestring into > type str so as to emulate Py2.6 behavior? str() will convert a bytestring into a Python string object which you will be able to parse so long as the output remains ASCII (which your example is). If the input uses another encoding or contains characters with the high order bit set, you might need to fiddle with the strings encoding. From dylan at contentfree.info Wed Nov 3 04:09:08 2010 From: dylan at contentfree.info (Dylan Evans) Date: Wed, 3 Nov 2010 18:09:08 +1000 Subject: Mail Merge from python data In-Reply-To: References: Message-ID: On Wed, Nov 3, 2010 at 3:20 PM, Tim Harig wrote: > This page didn't make it to through to my nntp server so I appologize if I > miss something that was covered. > > On 2010-11-03, Dennis Lee Bieber wrote: > > On Tue, 2 Nov 2010 20:32:13 +1000, Dylan Evans > > declaimed the following in gmane.comp.python.general: > > > >> I'm setting up a database for an organisation who want to do mail merges > in > >> office 2010. I know i can use the MySQL ODBC driver for the mail merge > but i > >> have set up the database with lots of relations and many-to-many links > which > >> i'm sure will lead to a huge amount of confusion (I think, i don't > really > >> know much about mail merge). > > Many to many relationships without some kind of intersection table are > considered a rather poor practice in general. Yes an intersection table with a description char field. > > >> What i want to know is, is there anyway to send data from python, which > the > >> UI is written in, to office templates and mail merges? > > > > If a long lived form, I'd probably define a query or view (I think > > MySQL 5.x has output-only views) that isolates just to the data fields > > used in the mail merge. > > I agree that a view would be the best solution if you have the access to do > so; but, a couple of other alternatives come to mind in case you do not. > > That would help alot, it would certainly make it easier for then, i didn't know about views, i will rtfm. > 1. Do the mail merge in Python using a Word template. Then you can add any > kind of logic that you need to the merge. > > Can this be done in pure python? Bearing in mind that the server will be linux > 2. Add some kind of export function to your python UI that allows you to > export the data to an Excel sheet, CSV, or even another ODBC data > source (like another MySQL table or database that you might have > access to). > I have considered this one, ideally the file saving would be skipped, since it's only temporary and i am concerned that users may save many files mixing them up, or try to use old export files which are out of sync with the database. This is a community organisation with volunteers, so i expect technical competency to be low. However if i can send the data directly from python to office somehow i could avoid that issue. What would be perfect is an ODBC driver which connected via XMLRPC or some other simple protocol. Thanks for the help. -- > > http://mail.python.org/mailman/listinfo/python-list > -- "The UNIX system has a command, nice ... in order to be nice to the other users. Nobody ever uses it." - Andrew S. Tanenbaum -- "The UNIX system has a command, nice ... in order to be nice to the other users. Nobody ever uses it." - Andrew S. Tanenbaum -------------- next part -------------- An HTML attachment was scrubbed... URL: From sanjo_ie at yahoo.com Wed Nov 3 04:50:48 2010 From: sanjo_ie at yahoo.com (jk) Date: Wed, 3 Nov 2010 01:50:48 -0700 (PDT) Subject: Python documentation too difficult for beginners References: Message-ID: <0ba75a36-b9b9-4bb8-9aad-db6fc9a40135@r14g2000yqa.googlegroups.com> On Nov 2, 11:06?pm, Lawrence D'Oliveiro wrote: > In message > , jk > wrote: > > > This (http://epydoc.sourceforge.net/stdlib/) is what I'm talking > > about. > > Framesets? Is that really your idea of well-laid-out documentation? Using a > feature which has been derided (and dropped in HTML5) because of its effect > on usability and accessibility? No, the framesets suck, and I agree that Javadoc isn't perfect. Actually, I do think the PHP docs are the best I've found as a reference. Javadocs just need a few tweaks and they'd be better (an index at the top so you don't have to scroll down, no framesets, a search engine). Still think they're better than the python docs though. From __peter__ at web.de Wed Nov 3 04:51:46 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 03 Nov 2010 09:51:46 +0100 Subject: Py3: Import relative path module References: <044f2fb7-a6a9-4bb9-b2a6-8ee1d0c19612@u17g2000yqi.googlegroups.com> <4cce7768$0$29965$c3e8da3$5496439d@news.astraweb.com> <770dd3de-25f5-404c-a05a-7bdd2eb07179@26g2000yqv.googlegroups.com> <3e7dbd88-4d44-43fa-a0e2-6987c025ccdb@26g2000yqv.googlegroups.com> Message-ID: MRAB wrote: > On 03/11/2010 01:48, Gnarlodious wrote: >> I admit I don't understand any of what was said here. Or why it is so >> hard what I am trying to do. I searched Google for a few hours looking >> for a way to import a module from an absolute path, but that was a >> waste of time too. >> >> To reiterate, I am trying to import a Def function from a file one >> level up. Let's say relative import is unreasonable to expect from >> Python. If it is possible using an absolute path, please let me know >> how, in plain language. Otherwise I can continue to copy and paste my >> programming into several files. >> >> Thank you for any help. >> > After some experimentation (and Googling!) I think the problem is that > a module can do your relative import but a main script can't. > > Or, to put it another way, if __name__ is "__main__" then it won't work. Slightly generalized: have the importing module print its __name__. There has to be at least one dot in the name for from .. import whatever to succeed. From hniksic at xemacs.org Wed Nov 3 05:31:18 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Wed, 03 Nov 2010 10:31:18 +0100 Subject: functions, list, default parameters References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <8ivelpFif1U1@mid.individual.net> <4cca88bc$0$29987$c3e8da3$5496439d@news.astraweb.com> <8j1seqFa1eU2@mid.individual.net> <87tyjzippx.fsf@rudin.co.uk> Message-ID: <87oca6n47t.fsf@xemacs.org> Paul Rudin writes: > Terry Reedy writes: > >> Suppose I write an nasty C extension that mutates tuples. What then >> would be illegal about... > > Depends on exactly what we mean by legal. If immutability is part of the > language spec (rather than an artifact of a particular implementation) > then a compiler could assume immutability. And, indeed, it does exactly that. Tuples of constant literals are created at compilation time and reused across function invocations. Mutating a tuple using a C extension is "illegal" in that it breaks the rules of the system, by changing the semantics of valid code in unexpected ways. A more extreme example of this would be mutating the constant 0 or the empty tuple. From hniksic at xemacs.org Wed Nov 3 05:39:11 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Wed, 03 Nov 2010 10:39:11 +0100 Subject: Man pages and info pages References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> <024ef21a-9ef9-48a6-8372-1d66895583c3@v16g2000yqn.googlegroups.com> <87zktr5yze.fsf_-_@mithlond.arda> <877hgv2fg3.fsf@mithlond.arda> Message-ID: <87hbfyn3uo.fsf@xemacs.org> Teemu Likonen writes: > Enter Follow a link (down to node) > u up node level > h help (general how-to) > ? help (commands) > s search And don't forget: l last viewed page (aka "back") That one seems to be the info reader's best-kept secret. From contact at xavierho.com Wed Nov 3 05:57:27 2010 From: contact at xavierho.com (Xavier Ho) Date: Wed, 3 Nov 2010 19:57:27 +1000 Subject: What people are using to access this mailing list In-Reply-To: References: Message-ID: Gmail. -Xav On 3 November 2010 18:02, John Bond wrote: > Hope this isn't too O/T - I was just wondering how people read/send to this > mailing list, eg. normal email client, gmane, some other software or online > service? > > My normal inbox is getting unmanageable, and I think I need to find a new > way > of following this and other lists. > > Thanks for any suggestions. > > Cheers, JB. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dan.kluev at gmail.com Wed Nov 3 06:04:18 2010 From: dan.kluev at gmail.com (Daniel Kluev) Date: Wed, 3 Nov 2010 20:04:18 +1000 Subject: What people are using to access this mailing list In-Reply-To: References: Message-ID: I use gmail with according filters and labels, so each mailing list has its own label and is removed from inbox. -- With best regards, Daniel Kluev -------------- next part -------------- An HTML attachment was scrubbed... URL: From ddasilva at umd.edu Wed Nov 3 06:11:40 2010 From: ddasilva at umd.edu (Daniel da Silva) Date: Wed, 3 Nov 2010 06:11:40 -0400 Subject: Man pages and info pages In-Reply-To: <87hbfyn3uo.fsf@xemacs.org> References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> <024ef21a-9ef9-48a6-8372-1d66895583c3@v16g2000yqn.googlegroups.com> <87zktr5yze.fsf_-_@mithlond.arda> <877hgv2fg3.fsf@mithlond.arda> <87hbfyn3uo.fsf@xemacs.org> Message-ID: Guys, this really has nothing to do with python. On Wednesday, November 3, 2010, Hrvoje Niksic wrote: > Teemu Likonen writes: > >> ? ? Enter ? Follow a link (down to node) >> ? ? u ? ? ? up node level >> ? ? h ? ? ? help (general how-to) >> ? ? ? ? ? ? help (commands) >> ? ? s ? ? ? search > > And don't forget: > > ? ? ?l ? ? ? last viewed page (aka "back") > > That one seems to be the info reader's best-kept secret. > -- > http://mail.python.org/mailman/listinfo/python-list > From h.b.furuseth at usit.uio.no Wed Nov 3 06:27:05 2010 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: Wed, 03 Nov 2010 11:27:05 +0100 Subject: Python documentation too difficult for beginners References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano writes: > On Tue, 02 Nov 2010 03:42:22 -0700, jk wrote: >> The former is difficult to find (try searching for 'open' in the search >> box and see what you get). > > A fair point -- the built-in open comes up as hit #30, whereas searching > for open in the PHP page brings up fopen as hit #1. But the PHP search > also brings up many, many hits -- ten pages worth. > > But in any case, the Python search functionality could be smarter. If I > had a complaint about the docs, that would be it. Fortunately, I have > google :) Actually that was one of the hair-tearing attitudes I heard a web search guru complain about. The smartest part of the search engine is the people running it, so why not apply their brains directly? Read the log like you did, look for poor results (like "open"), put in exceptions by hand. This might be a fraction of the work it takes to program that kind of smarts into the engine. Or you might discover a group of exceptions to put in - like all Python keywords. That makes it at least partially programmed, which may be preferable. -- Hallvard From rustompmody at gmail.com Wed Nov 3 06:31:07 2010 From: rustompmody at gmail.com (rustom) Date: Wed, 3 Nov 2010 03:31:07 -0700 (PDT) Subject: Man pages and info pages References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> <024ef21a-9ef9-48a6-8372-1d66895583c3@v16g2000yqn.googlegroups.com> <87zktr5yze.fsf_-_@mithlond.arda> <877hgv2fg3.fsf@mithlond.arda> <87hbfyn3uo.fsf@xemacs.org> Message-ID: <1bdce24e-4406-44c5-9133-bfd0acd0283d@p1g2000yqm.googlegroups.com> On Nov 3, 3:11?pm, Daniel da Silva wrote: > Guys, this really has nothing to do with python. ?? python docs have nothing to do with python?? python docs by default on linux are read with info and many seem to find info unpleasant to use. Myself an old emacs user and cant say info helps me as much as google. However comparing info and man is also a bit strange. The printed python docs come to several thousand pages. Do we want them to be 1 manpage? a hundred? a thousand? From vgnulinux at gmail.com Wed Nov 3 06:47:44 2010 From: vgnulinux at gmail.com (VGNU Linux) Date: Wed, 3 Nov 2010 16:17:44 +0530 Subject: How to highlight Label/Text in tkinter ? In-Reply-To: References: Message-ID: I was able to solve the problem. But unable to use Label or Text widget. Any idea as to why focus does not work with Label or Text widget. Here is the program using button widget. from Tkinter import * import tkFont class DisplayFrame: """ Uses GUI to display contacts """ def __init__(self, root): self.b = Button(root, text="Peter Pan",font=("Arial",10,"bold"), anchor=W, justify=LEFT, relief=FLAT) self.b.pack(fill=BOTH) self.b.focus_set() self.b = Button(root, text="Marry Joe", font=("Arial",10,"bold"), anchor=W, justify=LEFT, relief=FLAT) self.b.pack(fill=BOTH) self.b = Button(root, text="Michael Kin", font=("Arial",10,"bold"), anchor=W, justify=LEFT, relief=FLAT) self.b.pack(fill=BOTH) self.b = Button(root, text="Jennifer McConelly", font=("Arial",10,"bold"), anchor=W, justify=LEFT, relief=FLAT) self.b.pack(fill=BOTH) self.b = Button(root, text="Jonathen Broady", font=("Arial",10,"bold"), anchor=W, justify=LEFT, relief=FLAT) self.b.pack(fill=BOTH) def handleReturn(event): event.widget["font"] = "Arial 16 bold" print event.widget.focus_get() nxtwid = event.widget.tk_focusNext() prewid = event.widget.tk_focusPrev() prewid["font"] = "Arial 10 bold" nxtwid.focus_set() if __name__ == '__main__': root = Tk() frame = DisplayFrame(root) root.bind("",handleReturn) root.mainloop() Regards, VGNU On Wed, Nov 3, 2010 at 12:02 PM, VGNU Linux wrote: > Hi, > I am writing a program teach myself python and tkinter. > Below given is a program which displays label with different fonts and > sizes. > How to highlight text and change font size if the up/down arrow keys are > pressed ? > from Tkinter import * > import tkFont > > class MyFrame(Frame): > > def __init__(self, root): > Frame.__init__(self, root) > self.txt = Label(self, text="Arial 10 bold", > font=("Arial",10,"bold")) > self.txt.grid(row=1,column=1) > self.txt = Label(self, text="Courier 12 bold", > font=("Courier",12,"bold")) > self.txt.grid(row=2,column=1) > self.txt = Label(self, text="Comic Sans MS 14 bold", font=("Comic > Sans MS",14,"bold")) > self.txt.grid(row=3,column=1) > self.txt = Label(self, text="Fixedsys 16 bold", > font=("Fixedsys",16,"bold")) > self.txt.grid(row=4,column=1) > self.txt = Label(self, text="MS Sans Serif 18 bold", font=("MS Sans > Serif",18,"bold")) > self.txt.grid(row=5,column=1) > self.txt = Label(self, text="MS Serif, Symbol 20 bold", font=("MS > Serif, Symbol",20,"bold")) > self.txt.grid(row=6,column=1) > self.txt = Label(self, text="System 22 bold", > font=("System",22,"bold")) > self.txt.grid(row=7,column=1) > self.txt = Label(self, text="Verdana 24 bold", > font=("Verdana",24,"bold")) > self.txt.grid(row=8,column=1) > > if __name__ == '__main__': > root = Tk() > c = MyFrame(root) > c.pack(fill=BOTH, expand=1) > root.mainloop() > > any help? > > Regards, > VGNU > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Wed Nov 3 07:17:32 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 03 Nov 2010 11:17:32 GMT Subject: What people are using to access this mailing list References: Message-ID: <4cd144cc$0$29966$c3e8da3$5496439d@news.astraweb.com> On Wed, 03 Nov 2010 08:02:29 +0000, John Bond wrote: > Hope this isn't too O/T - I was just wondering how people read/send to > this mailing list, eg. normal email client, gmane, some other software > or online service? Usenet via my ISP, on comp.lang.python. -- Steven From python.list at tim.thechases.com Wed Nov 3 07:25:07 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 03 Nov 2010 06:25:07 -0500 Subject: What people are using to access this mailing list In-Reply-To: References: Message-ID: <4CD14693.6070104@tim.thechases.com> On 11/03/10 03:02, John Bond wrote: > Hope this isn't too O/T - I was just wondering how people read/send to this > mailing list, eg. normal email client, gmane, some other software or online > service? > > My normal inbox is getting unmanageable, and I think I need to find a new way > of following this and other lists. Currently using Gmane NNTP via Thunderbird. If TB offered the ability to kill-thread normal email (the "kill thread" functionality only seems to work in newsgroups), I'd stick to getting them via email, filtered into my Python folder. -tkc From cs at zip.com.au Wed Nov 3 07:32:29 2010 From: cs at zip.com.au (Cameron Simpson) Date: Wed, 3 Nov 2010 22:32:29 +1100 Subject: What people are using to access this mailing list In-Reply-To: References: Message-ID: <20101103113229.GA6045@cskk.homeip.net> On 03Nov2010 08:02, John Bond wrote: | Hope this isn't too O/T - I was just wondering how people read/send to this | mailing list, eg. normal email client, gmane, some other software or online | service? | | My normal inbox is getting unmanageable, and I think I need to find a new way | of following this and other lists. I use mutt to read my python folder. I use getmail to collect email via POP and deliver via procmail, which files this list (and python-ideas etc) into a "python" folder, out of my main inbox. -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ It is impossible to travel faster than light, and certainly not desirable as ones hat keeps blowing off. - Woody Allen From steve at REMOVE-THIS-cybersource.com.au Wed Nov 3 07:36:20 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 03 Nov 2010 11:36:20 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> On Tue, 02 Nov 2010 19:26:56 +0000, Tim Harig wrote: > I agree with Seebs, Python is the only language I know that promotes the > use of spaces over tabs; Really? I'm not aware of *any* language that promotes tabs over spaces. I thought the tabs vs spaces war was mostly won by spaces over a decade ago (apart from a few plucky freedom fighters who will never surrender). > and there are equally picky syntaxs (ie, > Makefiles) that mandate the use of tabs. I personally prefer tabs as it > lets *me* decide how far the apparent indentations are in the code. You > may like four spaces; but, I agree with Linus Torvalds that eight spaces > is much clearer. The beautiful thing about tabs is that we can both set > our tab stops to match our own viewing preferences. Actually I agree with you about tabs. I think tabs are far more logical and sensible. But I'm stuck with broken tools that don't deal with tabs, and with PEP 8 that mandates the use of spaces, and popular opinion that says make is crazy for using tabs. So, I bite my lip, stop using broken tools that make dealing with space- indents painful, and just deal with it. And you know what? It's not so bad after all. > This is Python's most noticable blemish outside of the community. > Everybody knows that Python is the language that forces you to use a > particular style of formatting; and, that is a turn-off for many people. Their loss. I don't miss the flame wars over the One True Brace Style. There are enough disagreements over coding conventions without adding to them. > It is a big mistake that whenever the issue arises, the community > effectively attacks anybody who might have disagreements with the > tradeoffs made for the Python language. This tends to set people on the > defensive and gives them a bad taste about the language as a whole. That's very insightful. Why don't you apply some of that insight to the other side? It is *incredibly* annoying to see the same old people making the same old snide remarks about the same old issues over and over again, particularly when: * it's not an issue for thousands of other users; * even if it were an issue, if you use the right tool for the job, the issue disappears; * and even if there is no right tool for the job, the feature isn't going to change; * and even if it would change, the people doing the whinging aren't going to volunteer to make the change. > It would be much better if the community would simply acknowledge that > this is a tradeoff the the language has made and one which is often > misunderstood by many first time Python programmers. Been there, done that. This is *old news*. -- Steven From steve at REMOVE-THIS-cybersource.com.au Wed Nov 3 07:37:03 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 03 Nov 2010 11:37:03 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: <4cd1495f$0$29966$c3e8da3$5496439d@news.astraweb.com> On Wed, 03 Nov 2010 12:01:06 +1300, Lawrence D'Oliveiro wrote: > In message , Grant Edwards wrote: >> Other languages have similar problems if you remove salient bits of >> syntax before comparing two source files files. > > But other languages don?t make those ?salient bits of syntax? invisible. > I.e. they are actually ?salient?. (1) Indentation is visible. Compare: This line has leading visible whitespace. This line has leading invisible characters. See the difference? (2) Salient doesn't mean visible. It means "prominent, conspicuous, noticeable". Something can be conspicuous by its absence; conspicuous whitespace can be very noticeable. -- Steven From tinnews at isbd.co.uk Wed Nov 3 07:54:34 2010 From: tinnews at isbd.co.uk (tinnews at isbd.co.uk) Date: Wed, 3 Nov 2010 11:54:34 +0000 Subject: What people are using to access this mailing list References: Message-ID: John Bond wrote: > Hope this isn't too O/T - I was just wondering how people read/send to this > mailing list, eg. normal email client, gmane, some other software or online > service? > > My normal inbox is getting unmanageable, and I think I need to find a new way > of following this and other lists. > > Thanks for any suggestions. > I read it as a Usenet newsgroup, far better than as an E-Mail list IMHO. Wherever I have a choice (quite a few mailing lists are 'gatewayed' with newsgroups) I choose the newsgroup, newsreaders are much more able to manage this sort of discussion group. Alternatively, if you want to stay with the E-Mail format then use some sort of filtering that will allow you to send each mailing list to its own folder. I do this with a home-grown python script but most E-Mail programs have the ability to do this themselves nowadays. -- Chris Green From lists at asd-group.com Wed Nov 3 07:58:07 2010 From: lists at asd-group.com (John Bond) Date: Wed, 03 Nov 2010 11:58:07 +0000 Subject: What people are using to access this mailing list In-Reply-To: <4cd144cc$0$29966$c3e8da3$5496439d@news.astraweb.com> References: <4cd144cc$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4CD14E4F.1020508@asd-group.com> On 3/11/2010 11:17 AM, Steven D'Aprano wrote: > On Wed, 03 Nov 2010 08:02:29 +0000, John Bond wrote: > >> Hope this isn't too O/T - I was just wondering how people read/send to >> this mailing list, eg. normal email client, gmane, some other software >> or online service? > Usenet via my ISP, on comp.lang.python. > > > Using what client (or web client)? Cheers, JB From paul.nospam at rudin.co.uk Wed Nov 3 08:01:58 2010 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Wed, 03 Nov 2010 12:01:58 +0000 Subject: What people are using to access this mailing list References: <4cd144cc$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87r5f2wr7t.fsf@rudin.co.uk> John Bond writes: > On 3/11/2010 11:17 AM, Steven D'Aprano wrote: >> On Wed, 03 Nov 2010 08:02:29 +0000, John Bond wrote: >> >>> Hope this isn't too O/T - I was just wondering how people read/send to >>> this mailing list, eg. normal email client, gmane, some other software >>> or online service? >> Usenet via my ISP, on comp.lang.python. >> >> >> > Using what client (or web client)? > Emacs, of course :-; From roy at panix.com Wed Nov 3 08:17:46 2010 From: roy at panix.com (Roy Smith) Date: Wed, 03 Nov 2010 08:17:46 -0400 Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> Message-ID: In article , Lawrence D'Oliveiro wrote: > > I suppose readability is in the eye of the reader, but, yes, I agree > > that I have split this into two parts. The parts are > > > > 1) The table of data > > > > 2) The looping construct > > But the table of data makes no sense outside of the looping construct. That > table does nothing other than define the bounds of the loop. I look at it the other way around. The data is the important part, and the loop is just plumbing. Once I've got the data in an easy to manage form, I can do lots of things with it. I could iterate over it (as originally written) with a "for" loop. I could refactor the code to pass the data to some function which processes it. I could refactor it a different way and use map() to process the data. > Which means you don???t understand the purpose of the code at all. Go look at > it in its entirety, and you???ll see what I mean. > > That URL takes me to a github page. Can you be more specific about which file I should be looking at? I did take a look at one file, overscan_margins.py. Here's a few stylistic comments. 1) I like the fact that the file starts out with a block comment describing what it does, how to install it, and how to run it. Documentation is A Good Thing, and most people don't do enough of it. 2) You have provided comments for each function, such as (lines 36-37): def NewLayer(svg, LayerName) : # adds a new layer to the SVG document and returns it. This is good, but would be even more useful if it were turned into a docstring, such as: def NewLayer(svg, LayerName) : "adds a new layer to the SVG document and returns it." For the same amount of typing, you now have a piece of text which can be retrieved by help() and processed in various useful ways with other tools. 3) I find the deeply nested style you use very difficult to read. For example, on lines 80-103. As I read this, here's how I mentally process it: "OK, here's a function call (minor stumble over the open paren not being on the same line as the function name, but I can get past that). The first argument is TheLayer. The second argument is whatever inkex.addNS() returns. Umm..." At that point, I can't scan quickly any more. It took me a while to understand that the third argument was a dictionary. The nesting is just too deep for me to continue to mentally hold the context of "I'm looking at a function call and gathering up the arguments" while I drill down through the dictionary structure to understand what it is. This would be a lot easier to scan if it were written as: inkex.etree.SubElement(TheLayer, inkex.addNS("path", "svg"), stuff) where "stuff" is the big complicated dictionary, which is defined before the call. Of course, "stuff" is not a useful name for it, but not being familiar with the domain, I don't know what a useful name would be. Hmmm, googling for inkex.etree.SubElement found me some Inkscape documentation. Looks like "attribs" would be a good name for the dictionary, since that's the name they use in the docs. In fact, if you look at http://tinyurl.com/24wa3q8, you'll see they use exactly the style I describe above (modulo whitespace). From awilliam at whitemice.org Wed Nov 3 08:26:48 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Wed, 03 Nov 2010 08:26:48 -0400 Subject: What people are using to access this mailing list In-Reply-To: <4cd144cc$0$29966$c3e8da3$5496439d@news.astraweb.com> References: <4cd144cc$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1288787208.3988.2.camel@linux-yu4c.site> On Wed, 2010-11-03 at 11:17 +0000, Steven D'Aprano wrote: > On Wed, 03 Nov 2010 08:02:29 +0000, John Bond wrote: > > Hope this isn't too O/T - I was just wondering how people read/send to > > this mailing list, eg. normal email client, gmane, some other software > > or online service? GNOME's awesome Evolution mail (IMAP) client. Via a SIEVE script on a Cyrus IMAP server the mailist traffic is automatically placed in a folder. Then it can be read with any IMAP traffic. Delete the silly traffic and that folder becomes an invaluable resource of useful information [no wading through pages and pages of search-result-swill]. -- Adam Tauno Williams LPIC-1, Novell CLA OpenGroupware, Cyrus IMAPd, Postfix, OpenLDAP, Samba From roy at panix.com Wed Nov 3 08:31:03 2010 From: roy at panix.com (Roy Smith) Date: Wed, 03 Nov 2010 08:31:03 -0400 Subject: What people are using to access this mailing list References: Message-ID: In article , John Bond wrote: > Hope this isn't too O/T - I was just wondering how people read/send to this > mailing list, eg. normal email client, gmane, some other software or online > service? Usenet group comp.lang.python. Most of the time, using MT-NewsWatcher on my Mac. Occasionally via the Google Groups web interface. From neilc at norwich.edu Wed Nov 3 08:42:49 2010 From: neilc at norwich.edu (Neil Cerutti) Date: 3 Nov 2010 12:42:49 GMT Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> <87aalrjkty.fsf@benfinney.id.au> Message-ID: <8jd3m9Fr55U7@mid.individual.net> On 2010-11-03, Ben Finney wrote: > I would do the same, but fix the indentation. Making > indentation depend on the *length* of the previous line is > needlessly making a maintenance burden. > > Instead, I'd do:: > > styles = [ > ("normal", "image", MainWindow.ColorsNormalList), > ("highlighted", "highlight", MainWindow.ColorsHighlightedList), > ("selected", "select", MainWindow.ColorsSelectedList)] Agreed, except cute stuff like putting those three items in columns is just as bad. Code should be utilitarian rather than ornate, Shaker rather than Victorian. -- Neil Cerutti From roy at panix.com Wed Nov 3 08:48:38 2010 From: roy at panix.com (Roy Smith) Date: Wed, 03 Nov 2010 08:48:38 -0400 Subject: Subclassing unittest.TestCase? Message-ID: I'm using Python 2.6, with unittest2 imported as unittest. I'm writing a test suite for a web application. There is a subclass of TestCase for each basic page type. One thing that's in common between all the pages is that every page must have a valid copyright notice. It seems like the logical thing would be to put the common test(s) in a subclass unittest.TestCase and have all my real test cases derive from that: class CommonTestCase(unittest.TestCase): def test_copyright(self): self.assert_(find copyright notice in DOM tree) class HomepageTestCase(CommonTestCase): def setUp(self): self.url = "http://site.com" def test_whatever(self): self.assert_(whatever) This works fine as far as HomepageTestCase running test_copyright() and test_whatever(). The problem is that CommonTestCase *also* runs test_copyright(), which fails because there's no setUp(), and thus no retrieved page for it to work on. The hack that I came up with is: class CommonTestCase(unittest.TestCase): def test_copyright(self): if self.__class__.__name__ == 'CommonTestCase': return self.assert_(find copyright notice in DOM tree) which works, but it's ugly. It also counts CommonTestCase.test_copyright() as passing, which messes up the statistics. Is there a cleaner way to define some common test methods which all of my test cases can inherit, without having them be run in the base class? From invalid at invalid.invalid Wed Nov 3 08:57:46 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 3 Nov 2010 12:57:46 +0000 (UTC) Subject: Ways of accessing this mailing list? References: Message-ID: On 2010-11-02, John Bond wrote: > Hope this isn't too O/T - I was just wondering how people read/send to > this mailing list, eg. normal email client, gmane, some other software > or online service? > > My normal inbox is getting unmanageable, and I think I need to find a > new way of following this and other lists. Point an NNTP client at new.gmane.org. This "list" is also a Usenet newsgroup (comp.lang.python), and there are a number of cheap/low-cost text-only Usenet providers. -- Grant Edwards grant.b.edwards Yow! ... or were you at driving the PONTIAC that gmail.com HONKED at me in MIAMI last Tuesday? From invalid at invalid.invalid Wed Nov 3 09:00:47 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 3 Nov 2010 13:00:47 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: On 2010-11-03, D'Arcy J.M. Cain wrote: > On 03 Nov 2010 01:20:40 GMT > Seebs wrote: >> However, I have probably seen all of two or three bugs ever related to >> mis-indented C, and I've had various things screw up or wreck indentation > > Really? I have never seen bugs in C related to indentation. I have > seen plenty related to braces. Same here. > What I have seen is bugs hidden by the indentation not matching the > block structure. Wrong indentation in Python *is* a bug. There's no > other visual signal to hide the error. Exactly. -- Grant Edwards grant.b.edwards Yow! I selected E5 ... but at I didn't hear "Sam the Sham gmail.com and the Pharoahs"! From invalid at invalid.invalid Wed Nov 3 09:02:22 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 3 Nov 2010 13:02:22 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: On 2010-11-03, Seebs wrote: > On 2010-11-02, Grant Edwards wrote: >> Huh? Indentation is invisible? You can't see the indentation in >> Python source code? > > The difference between tabs and spaces is invisible on a great > number of the devices on which people display code. Allowing a mixture of tabs/spaces for indentation was a mistake, and pretty much everybody agrees on that. However, that isn't what's being discussed. > Indentation is visible, but the underlying structure of it may not > be. (It's worse than that, because for instance " " is quite hard to > distinguish from the quite similar " ".) And at least one of them is > clearly wrong. -- Grant Edwards grant.b.edwards Yow! An air of FRENCH FRIES at permeates my nostrils!! gmail.com From invalid at invalid.invalid Wed Nov 3 09:05:23 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 3 Nov 2010 13:05:23 +0000 (UTC) Subject: What people are using to access this mailing list References: <4cd144cc$0$29966$c3e8da3$5496439d@news.astraweb.com> <87r5f2wr7t.fsf@rudin.co.uk> Message-ID: On 2010-11-03, Paul Rudin wrote: > John Bond writes: > >> On 3/11/2010 11:17 AM, Steven D'Aprano wrote: >>> On Wed, 03 Nov 2010 08:02:29 +0000, John Bond wrote: >>> >>>> Hope this isn't too O/T - I was just wondering how people read/send to >>>> this mailing list, eg. normal email client, gmane, some other software >>>> or online service? >>> Usenet via my ISP, on comp.lang.python. >>> >> Using what client (or web client)? > > Emacs, of course :-; Slrn, of course. -- Grant Edwards grant.b.edwards Yow! I am having FUN... at I wonder if it's NET FUN or gmail.com GROSS FUN? From gnarlodious at gmail.com Wed Nov 3 09:05:43 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Wed, 3 Nov 2010 06:05:43 -0700 (PDT) Subject: Py3: Import relative path module References: <044f2fb7-a6a9-4bb9-b2a6-8ee1d0c19612@u17g2000yqi.googlegroups.com> <4cce7768$0$29965$c3e8da3$5496439d@news.astraweb.com> <770dd3de-25f5-404c-a05a-7bdd2eb07179@26g2000yqv.googlegroups.com> <3e7dbd88-4d44-43fa-a0e2-6987c025ccdb@26g2000yqv.googlegroups.com> Message-ID: <01c6e36a-c4e0-499a-adc1-cb61d7b53725@r14g2000yqa.googlegroups.com> On Nov 3, 2:51?am, Peter Otten wrote: > Slightly generalized: have the importing module print its __name__. There > has to be at least one dot in the name for > > from .. import whatever > > to succeed. Just spent about 3 hours trying every permutation I could think of, and searching Google for exactly how to do it, but all I get is: ValueError: Attempted relative import in non-package How do I import a module so that a dot will appear in its name? -- Gnarlie From __peter__ at web.de Wed Nov 3 09:42:10 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 03 Nov 2010 14:42:10 +0100 Subject: Py3: Import relative path module References: <044f2fb7-a6a9-4bb9-b2a6-8ee1d0c19612@u17g2000yqi.googlegroups.com> <4cce7768$0$29965$c3e8da3$5496439d@news.astraweb.com> <770dd3de-25f5-404c-a05a-7bdd2eb07179@26g2000yqv.googlegroups.com> <3e7dbd88-4d44-43fa-a0e2-6987c025ccdb@26g2000yqv.googlegroups.com> <01c6e36a-c4e0-499a-adc1-cb61d7b53725@r14g2000yqa.googlegroups.com> Message-ID: Gnarlodious wrote: > On Nov 3, 2:51 am, Peter Otten wrote: > >> Slightly generalized: have the importing module print its __name__. There >> has to be at least one dot in the name for >> >> from .. import whatever >> >> to succeed. > > Just spent about 3 hours trying every permutation I could think of, > and searching Google for exactly how to do it, but all I get is: > > ValueError: Attempted relative import in non-package > > How do I import a module so that a dot will appear in its name? Make sure the no path in sys.path leads into a directory that contains an __init__.py. In particular, ensure that you aren't invoking the python interpreter from a working directory that contains an __init__.py and that the main script is in a directory that doesn't contain an __init__.py. Peter From dan at catfolks.net Wed Nov 3 09:47:37 2010 From: dan at catfolks.net (Dan M) Date: Wed, 03 Nov 2010 08:47:37 -0500 Subject: What people are using to access this mailing list References: Message-ID: On Wed, 03 Nov 2010 08:02:29 +0000, John Bond wrote: > Hope this isn't too O/T - I was just wondering how people read/send to > this mailing list, eg. normal email client, gmane, some other software > or online service? > > My normal inbox is getting unmanageable, and I think I need to find a > new way of following this and other lists. > > Thanks for any suggestions. > > Cheers, JB. Pan newsreader From __peter__ at web.de Wed Nov 3 09:50:45 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 03 Nov 2010 14:50:45 +0100 Subject: Py3: Import relative path module References: <044f2fb7-a6a9-4bb9-b2a6-8ee1d0c19612@u17g2000yqi.googlegroups.com> <4cce7768$0$29965$c3e8da3$5496439d@news.astraweb.com> <770dd3de-25f5-404c-a05a-7bdd2eb07179@26g2000yqv.googlegroups.com> <3e7dbd88-4d44-43fa-a0e2-6987c025ccdb@26g2000yqv.googlegroups.com> <01c6e36a-c4e0-499a-adc1-cb61d7b53725@r14g2000yqa.googlegroups.com> Message-ID: Peter Otten wrote: > Gnarlodious wrote: > >> On Nov 3, 2:51 am, Peter Otten wrote: >> >>> Slightly generalized: have the importing module print its __name__. >>> There has to be at least one dot in the name for >>> >>> from .. import whatever >>> >>> to succeed. >> >> Just spent about 3 hours trying every permutation I could think of, >> and searching Google for exactly how to do it, but all I get is: >> >> ValueError: Attempted relative import in non-package >> >> How do I import a module so that a dot will appear in its name? > > Make sure the no path in sys.path leads into a directory that contains an > __init__.py. In particular, ensure that you aren't invoking the python > interpreter from a working directory that contains an __init__.py and that > the main script is in a directory that doesn't contain an __init__.py. > > Peter Here's a working example that you can use as a starting point: $ tree . |-- alpha | |-- __init__.py | |-- beta | | |-- __init__.py | | `-- one.py | `-- two.py `-- main.py 2 directories, 5 files $ cat main.py import alpha.beta.one $ cat alpha/beta/one.py from ..alpha import two $ cat alpha/two.py print "success!" $ python main.py success! Peter From email at invalid.net Wed Nov 3 09:53:18 2010 From: email at invalid.net (QoS) Date: Wed, 03 Nov 2010 13:53:18 GMT Subject: What people are using to access this mailing list References: Message-ID: Dan M wrote in message-id: > > On Wed, 03 Nov 2010 08:02:29 +0000, John Bond wrote: > > > Hope this isn't too O/T - I was just wondering how people read/send to > > this mailing list, eg. normal email client, gmane, some other software > > or online service? > > > > My normal inbox is getting unmanageable, and I think I need to find a > > new way of following this and other lists. > > > > Thanks for any suggestions. > > > > Cheers, JB. > > Pan newsreader Using Perl and NewsSurfer to read this newsgroup (check headers). Thanks, J From __peter__ at web.de Wed Nov 3 10:02:34 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 03 Nov 2010 15:02:34 +0100 Subject: Py3: Import relative path module References: <044f2fb7-a6a9-4bb9-b2a6-8ee1d0c19612@u17g2000yqi.googlegroups.com> <4cce7768$0$29965$c3e8da3$5496439d@news.astraweb.com> <770dd3de-25f5-404c-a05a-7bdd2eb07179@26g2000yqv.googlegroups.com> <3e7dbd88-4d44-43fa-a0e2-6987c025ccdb@26g2000yqv.googlegroups.com> <01c6e36a-c4e0-499a-adc1-cb61d7b53725@r14g2000yqa.googlegroups.com> Message-ID: Peter Otten wrote: > Peter Otten wrote: > >> Gnarlodious wrote: >> >>> On Nov 3, 2:51 am, Peter Otten wrote: >>> >>>> Slightly generalized: have the importing module print its __name__. >>>> There has to be at least one dot in the name for >>>> >>>> from .. import whatever >>>> >>>> to succeed. >>> >>> Just spent about 3 hours trying every permutation I could think of, >>> and searching Google for exactly how to do it, but all I get is: >>> >>> ValueError: Attempted relative import in non-package >>> >>> How do I import a module so that a dot will appear in its name? >> >> Make sure the no path in sys.path leads into a directory that contains an >> __init__.py. In particular, ensure that you aren't invoking the python >> interpreter from a working directory that contains an __init__.py and >> that the main script is in a directory that doesn't contain an >> __init__.py. >> >> Peter > > Here's a working example that you can use as a starting point: > > $ tree > . > |-- alpha > | |-- __init__.py > | |-- beta > | | |-- __init__.py > | | `-- one.py > | `-- two.py > `-- main.py > > 2 directories, 5 files > $ cat main.py > import alpha.beta.one > $ cat alpha/beta/one.py > from ..alpha import two > $ cat alpha/two.py > print "success!" > $ python main.py > success! Hmm, now I'm puzzled myself. > $ cat alpha/beta/one.py > from ..alpha import two That line should have been from .. import two For some reason (bug?) it seems to work with and without the extra alpha. Peter From felipe.bastosn at gmail.com Wed Nov 3 10:15:36 2010 From: felipe.bastosn at gmail.com (Felipe Bastos Nunes) Date: Wed, 3 Nov 2010 12:15:36 -0200 Subject: Learning book recommendation? In-Reply-To: <1053302592-1288705850-cardhu_decombobulator_blackberry.rim.net-148438442-@bda480.bisx.prod.on.blackberry> References: <1053302592-1288705850-cardhu_decombobulator_blackberry.rim.net-148438442-@bda480.bisx.prod.on.blackberry> Message-ID: The pyschools dot com have so many exercises that 'forces' you to learn. It shows some results, explains the algorithm and checks the results of your code. 2010/11/2, brf256 at gmail.com : > Hey there, > > I would reccomend a non-programmers tutorial to python by Josh coglatti and > its a free wiki book. Also I would recommend byte into python. Both are > great for beginers. Best of luck! > > -- Braden Faulkner > Sent wirelessly from my BlackBerry device on the Bell network. > Envoy? sans fil par mon terminal mobile BlackBerry sur le r?seau de Bell. > -- > http://mail.python.org/mailman/listinfo/python-list > -- Felipe Bastos Nunes From __peter__ at web.de Wed Nov 3 10:16:36 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 03 Nov 2010 15:16:36 +0100 Subject: Subclassing unittest.TestCase? References: Message-ID: Roy Smith wrote: > I'm using Python 2.6, with unittest2 imported as unittest. > > I'm writing a test suite for a web application. There is a subclass of > TestCase for each basic page type. One thing that's in common between > all the pages is that every page must have a valid copyright notice. It > seems like the logical thing would be to put the common test(s) in a > subclass unittest.TestCase and have all my real test cases derive from > that: > > class CommonTestCase(unittest.TestCase): > def test_copyright(self): > self.assert_(find copyright notice in DOM tree) > > class HomepageTestCase(CommonTestCase): > def setUp(self): > self.url = "http://site.com" > > def test_whatever(self): > self.assert_(whatever) > > This works fine as far as HomepageTestCase running test_copyright() and > test_whatever(). The problem is that CommonTestCase *also* runs > test_copyright(), which fails because there's no setUp(), and thus no > retrieved page for it to work on. > > The hack that I came up with is: > > class CommonTestCase(unittest.TestCase): > def test_copyright(self): > if self.__class__.__name__ == 'CommonTestCase': > return > self.assert_(find copyright notice in DOM tree) > > which works, but it's ugly. It also counts > CommonTestCase.test_copyright() as passing, which messes up the > statistics. Is there a cleaner way to define some common test methods > which all of my test cases can inherit, without having them be run in > the base class? Remove the base class from the module with del CommonTestCase before you invoke unittest.main(). Peter From mail at timgolden.me.uk Wed Nov 3 10:48:55 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 03 Nov 2010 14:48:55 +0000 Subject: problem with opening a new python program in a new window (and keeping track of the process) In-Reply-To: References: Message-ID: <4CD17657.7090307@timgolden.me.uk> On 02/11/2010 20:55, Zak Kinion wrote: > What I want to do: launch seperate python programs from one main > program (multi-threading will not achieve this because the mechanize > library uses one shared global opener object which will not suit my > needs) I want the scripts launched to be in seperate windows that i > can see the output of on screen, seperate processes. I can accomplish > this in win32 by: > > import subprocess; > args = ["cmd", "/c", "START", "python", "myScript.py"]; > process1 = subprocess.Popen(args, shell=False); Pass CREATE_NEW_CONSOLE as one of the creationflags: import os, sys import subprocess processes = [] cmd = [sys.executable, "-c", "import os; print os.getpid (); raw_input ()"] for i in range (3): processes.append (subprocess.Popen (cmd, creationflags=subprocess.CREATE_NEW_CONSOLE)) # # Keep looping round to see the current status # while True: for p in processes: print p.poll () raw_input () TJG From bruno.42.desthuilliers at websiteburo.invalid Wed Nov 3 10:58:27 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 03 Nov 2010 15:58:27 +0100 Subject: functions, list, default parameters In-Reply-To: References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <20101021235138.609fe668@geekmail.INVALID> Message-ID: <4cd1788b$0$5231$426a74cc@news.free.fr> Lawrence D'Oliveiro a ?crit : > In message <20101021235138.609fe668 at geekmail.INVALID>, Andreas Waldenburger > wrote: > >> While not very commonly needed, why should a shared default argument be >> forbidden? > > Because it?s safer to disallow it than to allow it. Then there are quite a few python features (or misfeatures depending on your personal tastes and whatnot) that should be "disabled" too. What about rebinding some_object.__class__ ?-) From theimmortalbum at gmail.com Wed Nov 3 11:30:00 2010 From: theimmortalbum at gmail.com (T.J. Simmons) Date: Wed, 3 Nov 2010 10:30:00 -0500 Subject: Serializing a user-defined class Message-ID: Hi all, got a question regarding serializing classes that I've defined. I have some classes like class Foo: def __init__(self, x, y): self.x = x, self.y = y then a class that can contain multiple Foos, such as: class Bar: def __init__(self): self.foos = [Foo(a, b), Foo(1, 2)] While that's a gross oversimplification of the real structure (it gets much, much more nested than that), that's a pretty decent overview. The actual data for this is coming from a pseudo-XML file without any actual structure, so I wrote a parser according to the spec given to me, so I now have all the data in a series of classes I've defined, with actual structure. What I'm wanting to do is take this data I have and spit it out into JSON, but I really don't see a good way (I'm new to Python, this is my first real project with it). I've defined a method in Foo, such as: def toDict(self): return dict(x = self.x, y = self.y) but that obviously isn't going to work out like I hope when I try to serialize Bar, with the multiple Foos. Does anyone have a great way of doing this? This has been a pretty much non-stop learning/codefest the past few days and I'm out of ideas for this, which is the last part of the project. Let me know if I can clarify in any way. Thanks, T.J. -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Wed Nov 3 11:35:33 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 3 Nov 2010 08:35:33 -0700 Subject: Serializing a user-defined class In-Reply-To: References: Message-ID: On Wed, Nov 3, 2010 at 8:30 AM, T.J. Simmons wrote: > Hi all, got a question regarding serializing classes that I've defined. I > have some classes like > class Foo: > ?? ? def __init__(self, x, y): > ?? ? ? ? ?self.x = x, self.y = y > then a class that can contain multiple Foos, such as: > class Bar: > ?? ? def __init__(self): > ?? ? ? ? ?self.foos = [Foo(a, b), Foo(1, 2)] > > While that's a gross oversimplification of the real structure (it gets much, > much more nested than that), that's a pretty decent overview. The actual > data for this is coming from a pseudo-XML file without any actual structure, > so I wrote a parser according to the spec given to me, so I now have all the > data in a series of classes I've defined, with actual structure. > What I'm wanting to do is take this data I have and spit it out into JSON, > but I really don't see a good way (I'm new to Python, this is my first real > project with it). Did you google for "python json"? The std lib `json` module is the very first hit: http://docs.python.org/library/json.html For future reference, here's the Global Module Index: http://docs.python.org/modindex.html Cheers, Chris -- http://blog.rebertia.com From darcy at druid.net Wed Nov 3 11:38:11 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Wed, 3 Nov 2010 11:38:11 -0400 Subject: What people are using to access this mailing list In-Reply-To: References: Message-ID: <20101103113811.270c1236.darcy@druid.net> On Wed, 3 Nov 2010 08:02:29 +0000 (UTC) John Bond wrote: > Hope this isn't too O/T - I was just wondering how people read/send to this It is completely off topic. What you need to do is research your own email client to see how to filter mailing lists into their own folders. Failing that look for a forum dedicated to your email client. There is nothing specific about Python in this regard. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From lists at asd-group.com Wed Nov 3 11:53:41 2010 From: lists at asd-group.com (John Bond) Date: Wed, 03 Nov 2010 15:53:41 +0000 Subject: What people are using to access this mailing list In-Reply-To: <20101103113811.270c1236.darcy@druid.net> References: <20101103113811.270c1236.darcy@druid.net> Message-ID: <4CD18585.7020207@asd-group.com> On 3/11/2010 3:38 PM, D'Arcy J.M. Cain wrote: > On Wed, 3 Nov 2010 08:02:29 +0000 (UTC) > John Bond wrote: >> Hope this isn't too O/T - I was just wondering how people read/send to this > It is completely off topic. What you need to do is research your own > email client to see how to filter mailing lists into their own > folders. Failing that look for a forum dedicated to your email > client. There is nothing specific about Python in this regard. > I know how to do that, thanks, but I was looking at broader options. Apologies to anyone whose time has been wasted by this heinous request, and thanks to those who have responded and given me ideas. I hope they'll help me better contribute to this (Python) list. Cheers, JB From gnarlodious at gmail.com Wed Nov 3 11:59:21 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Wed, 3 Nov 2010 08:59:21 -0700 (PDT) Subject: Py3: decode subprocess output References: Message-ID: <6c284fea-0831-4d48-b244-9c7ba1856908@c20g2000yqj.googlegroups.com> OK, it turns out I had to tweak the parsing minimally for Python3: 1) Substrings such as st[5] no longer work (returns an ascii number), instead st[5:6] selects one character 2) Replacements need to specified as bytes: s.replace('R','*') change to s.replace(b'R',b'*') So I think this problem is solved. -- Gnarlie From lists at asd-group.com Wed Nov 3 12:04:40 2010 From: lists at asd-group.com (John Bond) Date: Wed, 03 Nov 2010 16:04:40 +0000 Subject: Serializing a user-defined class In-Reply-To: References: Message-ID: <4CD18818.70109@asd-group.com> On 3/11/2010 3:30 PM, T.J. Simmons wrote: > Hi all, got a question regarding serializing classes that I've > defined. I have some classes like > > class Foo: > def __init__(self, x, y): > self.x = x, self.y = y > > then a class that can contain multiple Foos, such as: > > class Bar: > def __init__(self): > self.foos = [Foo(a, b), Foo(1, 2)] > > > While that's a gross oversimplification of the real structure (it gets > much, much more nested than that), that's a pretty decent overview. > The actual data for this is coming from a pseudo-XML file without any > actual structure, so I wrote a parser according to the spec given to > me, so I now have all the data in a series of classes I've defined, > with actual structure. > > What I'm wanting to do is take this data I have and spit it out into > JSON, but I really don't see a good way (I'm new to Python, this is my > first real project with it). > > I've defined a method in Foo, such as: > > def toDict(self): > return dict(x = self.x, y = self.y) > > but that obviously isn't going to work out like I hope when I try to > serialize Bar, with the multiple Foos. > > Does anyone have a great way of doing this? This has been a pretty > much non-stop learning/codefest the past few days and I'm out of ideas > for this, which is the last part of the project. > > Let me know if I can clarify in any way. > > Thanks, > T.J. Python has a JSON lib that may be what you want, alternatively you could have a common base class with a method that iterates through its own member variables (see dir() function) as key/value pairs, recursing when it finds further instances of that base class (see isinstance() function). That would let you iterate through all member variables in the object hierarchy from the top level object, and do what you wish with them. I'm sure there are other ways too. Cheers, JB -------------- next part -------------- An HTML attachment was scrubbed... URL: From darcy at druid.net Wed Nov 3 12:10:51 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Wed, 3 Nov 2010 12:10:51 -0400 Subject: What people are using to access this mailing list In-Reply-To: <4CD18585.7020207@asd-group.com> References: <20101103113811.270c1236.darcy@druid.net> <4CD18585.7020207@asd-group.com> Message-ID: <20101103121051.6aa164d7.darcy@druid.net> On Wed, 03 Nov 2010 15:53:41 +0000 John Bond wrote: > > It is completely off topic. What you need to do is research your own > > email client to see how to filter mailing lists into their own > > folders. Failing that look for a forum dedicated to your email > > client. There is nothing specific about Python in this regard. > > I know how to do that, thanks, but I was looking at broader options. Well, still off-topic but the question could have been put better. If you knew how to do that you should have mentioned it and explained why it wasn't suitable for your needs. You would have got a more focussed response. This applies to asking any questions here or elsewhere. The more information you provide in your question, the more relevant the responses will be. By the way, I am seeing two copies of every message from you. How are you posting? -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From clp2 at rebertia.com Wed Nov 3 12:18:52 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 3 Nov 2010 09:18:52 -0700 Subject: Serializing a user-defined class In-Reply-To: References: Message-ID: > On Wed, Nov 3, 2010 at 10:35 AM, Chris Rebert wrote: >> On Wed, Nov 3, 2010 at 8:30 AM, T.J. Simmons >> wrote: >> > Hi all, got a question regarding serializing classes that I've defined. >> > I >> > have some classes like >> > class Foo: >> > ?? ? def __init__(self, x, y): >> > ?? ? ? ? ?self.x = x, self.y = y >> > then a class that can contain multiple Foos, such as: >> > class Bar: >> > ?? ? def __init__(self): >> > ?? ? ? ? ?self.foos = [Foo(a, b), Foo(1, 2)] >> > >> > While that's a gross oversimplification of the real structure (it gets >> > much, >> > much more nested than that), that's a pretty decent overview. The actual >> > data for this is coming from a pseudo-XML file without any actual >> > structure, >> > so I wrote a parser according to the spec given to me, so I now have all >> > the >> > data in a series of classes I've defined, with actual structure. >> > What I'm wanting to do is take this data I have and spit it out into >> > JSON, >> > but I really don't see a good way (I'm new to Python, this is my first >> > real >> > project with it). >> >> Did you google for "python json"? The std lib `json` module is the >> very first hit: >> http://docs.python.org/library/json.html On Wed, Nov 3, 2010 at 8:39 AM, T.J. Simmons wrote: > Right, I know about the json module; that's not the problem. My problem is > with the fact that different instances of the same class, with different > data, have the same keys. Foo, in this instance, can be both a list of Foos > inside Bar, and also a list of Foos outside Bar. I'm just unsure of how to > get the data into a serializable form. So, if I'm understanding you correctly, your classes make use of dynamic typing and you think this will cause serialization problems? In that case, just define an appropriate JSONEncoder or object_hook; see the module docs, they give an example for complex numbers. If I've misunderstood you, a specific (pseudo-)code example of your problem would be helpful. Cheers, Chris From jed at jedsmith.org Wed Nov 3 12:20:32 2010 From: jed at jedsmith.org (Jed Smith) Date: Wed, 3 Nov 2010 12:20:32 -0400 Subject: What people are using to access this mailing list In-Reply-To: References: Message-ID: On Wed, Nov 3, 2010 at 4:02 AM, John Bond wrote: > My normal inbox is getting unmanageable, and I think I need to find a new way > of following this and other lists. I have to second (or third) the Gmail suggestion. I use Google Apps against my domain, and the Gmail interface is frightfully good at creating filters. For example, on most lists (particularly Mailman), I can hit "Filter messages like this", and Gmail automatically harvests the List header and writes a filter for it. I just prefer the Gmail philosophy to mail, with tags that are *like* folders but not really. -- Jed Smith jed at jedsmith.org From python at bdurham.com Wed Nov 3 12:29:12 2010 From: python at bdurham.com (python at bdurham.com) Date: Wed, 03 Nov 2010 12:29:12 -0400 Subject: Tkinter/ttk compatibility with Citrix/WTS (Windows Terminal Services)? Message-ID: <1288801752.27919.1403416637@webmail.messagingengine.com> Anyone have any experience using Python Tkinter/ttk applications with Citrix or WTS (Windows Terminal Services)? Any concerns, gotchas, or workarounds we should be aware of? I googled this topic [1], [2] and came up with nothing. No news is good news ... but just checking to make sure. Thanks, Malcolm [1] tkinter (citrix | ts|terminal services) [2] tcl (citrix | ts|terminal services) -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Wed Nov 3 12:43:20 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 3 Nov 2010 09:43:20 -0700 Subject: Serializing a user-defined class In-Reply-To: References: Message-ID: > On Wed, Nov 3, 2010 at 11:18 AM, Chris Rebert wrote: >> > On Wed, Nov 3, 2010 at 10:35 AM, Chris Rebert wrote: >> >> On Wed, Nov 3, 2010 at 8:30 AM, T.J. Simmons >> >> wrote: >> >> > Hi all, got a question regarding serializing classes that I've >> >> > defined. >> >> > I >> >> > have some classes like >> >> > class Foo: >> >> > ?? ? def __init__(self, x, y): >> >> > ?? ? ? ? ?self.x = x, self.y = y >> >> > then a class that can contain multiple Foos, such as: >> >> > class Bar: >> >> > ?? ? def __init__(self): >> >> > ?? ? ? ? ?self.foos = [Foo(a, b), Foo(1, 2)] >> >> > >> >> > While that's a gross oversimplification of the real structure (it >> >> > gets >> >> > much, >> >> > much more nested than that), that's a pretty decent overview. The >> >> > actual >> >> > data for this is coming from a pseudo-XML file without any actual >> >> > structure, >> >> > so I wrote a parser according to the spec given to me, so I now have >> >> > all >> >> > the >> >> > data in a series of classes I've defined, with actual structure. >> >> > What I'm wanting to do is take this data I have and spit it out into >> >> > JSON, >> >> > but I really don't see a good way (I'm new to Python, this is my >> >> > first >> >> > real >> >> > project with it). >> >> >> >> Did you google for "python json"? The std lib `json` module is the >> >> very first hit: >> >> http://docs.python.org/library/json.html >> >> On Wed, Nov 3, 2010 at 8:39 AM, T.J. Simmons >> wrote: >> > Right, I know about the json module; that's not the problem. My problem >> > is >> > with the fact that different instances of the same class, with different >> > data, have the same keys. Foo, in this instance, can be both a list of >> > Foos >> > inside Bar, and also a list of Foos outside Bar. I'm just unsure of how >> > to >> > get the data into a serializable form. >> >> So, if I'm understanding you correctly, your classes make use of >> dynamic typing and you think this will cause serialization problems? >> In that case, just define an appropriate JSONEncoder or object_hook; >> see the module docs, they give an example for complex numbers. >> If I've misunderstood you, a specific (pseudo-)code example of your >> problem would be helpful. On Wed, Nov 3, 2010 at 9:26 AM, T.J. Simmons wrote: > The issue with serialization is how I'm giving the data back to the > serializer, since I'm using dicts. Multiple dictionaries with a key of Foo > will overwrite each other, which isn't my desired behavior. Eh? There should be no key collision. The *outer attribute's* name (e.g. "foos") should be the key, not the value's type's name (e.g. "Foo"). The type information for an object should go inside that object's own dict. Again, see the example for `complex` in the json module docs. Also, avoid top-posting in the future. Cheers, Chris -- http://blog.rebertia.com From ben.wbr20 at gmail.com Wed Nov 3 12:47:21 2010 From: ben.wbr20 at gmail.com (bw) Date: Wed, 3 Nov 2010 09:47:21 -0700 (PDT) Subject: imaplib Search for Messages by Time Message-ID: Hello everyone. I've been writing a program that interfaces with a user's GMail account using OAuth, and I'm trying to find a way to search for messages that were received only after a certain date AND time. It seems pretty easy to get messages after a certain date. Here's the relevant code that I have now, which works: ... imap_conn = imaplib.IMAP4_SSL(imap_hostname) imap_conn.authenticate('XOAUTH', lambda x: xoauth_string) imap_conn.select('INBOX') (typ, data) = imap_conn.search(None, '(SINCE "01-Nov-2010")') ... But ideally I'd be able to do something like '(SINCE "01-Nov-2010 10:00:00")'. I know that I can do this locally, but time is a critical factor here so I'd like to avoid downloading any messages that I don't need. Thanks! From theimmortalbum at gmail.com Wed Nov 3 12:48:17 2010 From: theimmortalbum at gmail.com (T.J. Simmons) Date: Wed, 3 Nov 2010 11:48:17 -0500 Subject: Serializing a user-defined class In-Reply-To: References: Message-ID: The way it actually is now, there will be key collision in the dictionaries because each Foo has the same keys. I'm about to dive into the json docs for how it's done on complex, because that seems to be pretty much what I'm looking for. And I was about to ask what top-posting was, but then I realized I wasn't sending this back to the list. So I'm going to assume what that was. Thanks. On Wed, Nov 3, 2010 at 11:42 AM, Chris Rebert wrote: > > On Wed, Nov 3, 2010 at 11:18 AM, Chris Rebert wrote: > >> > On Wed, Nov 3, 2010 at 10:35 AM, Chris Rebert > wrote: > >> >> On Wed, Nov 3, 2010 at 8:30 AM, T.J. Simmons < > theimmortalbum at gmail.com> > >> >> wrote: > >> >> > Hi all, got a question regarding serializing classes that I've > >> >> > defined. > >> >> > I > >> >> > have some classes like > >> >> > class Foo: > >> >> > def __init__(self, x, y): > >> >> > self.x = x, self.y = y > >> >> > then a class that can contain multiple Foos, such as: > >> >> > class Bar: > >> >> > def __init__(self): > >> >> > self.foos = [Foo(a, b), Foo(1, 2)] > >> >> > > >> >> > While that's a gross oversimplification of the real structure (it > >> >> > gets > >> >> > much, > >> >> > much more nested than that), that's a pretty decent overview. The > >> >> > actual > >> >> > data for this is coming from a pseudo-XML file without any actual > >> >> > structure, > >> >> > so I wrote a parser according to the spec given to me, so I now > have > >> >> > all > >> >> > the > >> >> > data in a series of classes I've defined, with actual structure. > >> >> > What I'm wanting to do is take this data I have and spit it out > into > >> >> > JSON, > >> >> > but I really don't see a good way (I'm new to Python, this is my > >> >> > first > >> >> > real > >> >> > project with it). > >> >> > >> >> Did you google for "python json"? The std lib `json` module is the > >> >> very first hit: > >> >> http://docs.python.org/library/json.html > >> > >> On Wed, Nov 3, 2010 at 8:39 AM, T.J. Simmons > >> wrote: > >> > Right, I know about the json module; that's not the problem. My > problem > >> > is > >> > with the fact that different instances of the same class, with > different > >> > data, have the same keys. Foo, in this instance, can be both a list of > >> > Foos > >> > inside Bar, and also a list of Foos outside Bar. I'm just unsure of > how > >> > to > >> > get the data into a serializable form. > >> > >> So, if I'm understanding you correctly, your classes make use of > >> dynamic typing and you think this will cause serialization problems? > >> In that case, just define an appropriate JSONEncoder or object_hook; > >> see the module docs, they give an example for complex numbers. > >> If I've misunderstood you, a specific (pseudo-)code example of your > >> problem would be helpful. > > On Wed, Nov 3, 2010 at 9:26 AM, T.J. Simmons > wrote: > > The issue with serialization is how I'm giving the data back to the > > serializer, since I'm using dicts. Multiple dictionaries with a key of > Foo > > will overwrite each other, which isn't my desired behavior. > > Eh? There should be no key collision. The *outer attribute's* name > (e.g. "foos") should be the key, not the value's type's name (e.g. > "Foo"). The type information for an object should go inside that > object's own dict. Again, see the example for `complex` in the json > module docs. > > Also, avoid top-posting in the future. > > Cheers, > Chris > -- > http://blog.rebertia.com > -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Wed Nov 3 12:53:56 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 3 Nov 2010 09:53:56 -0700 Subject: Serializing a user-defined class In-Reply-To: References: Message-ID: On Wed, Nov 3, 2010 at 9:48 AM, T.J. Simmons wrote: > And I was about to ask what top-posting was, but then I realized I wasn't > sending this back to the list. So I'm going to assume what that was. Nope, actually it's about placing your reply below the quoted message you're replying to. (See Wikipedia's "Posting style" article) Though yes, you should also generally Reply-All on a mailinglist. Cheers, Chris From python at mrabarnett.plus.com Wed Nov 3 13:53:08 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 03 Nov 2010 17:53:08 +0000 Subject: Must be a bug in the re module [was: Why this result with the re module] In-Reply-To: <4CD0E0D1.7070902@asd-group.com> References: <292222.415.qm@web54207.mail.re2.yahoo.com> <4CD0DEE5.2060702@mrabarnett.plus.com> <4CD0E0D1.7070902@asd-group.com> Message-ID: <4CD1A184.1060400@mrabarnett.plus.com> On 03/11/2010 04:10, John Bond wrote: > On 3/11/2010 4:02 AM, MRAB wrote: >> On 03/11/2010 03:42, Yingjie Lan wrote: >>>> Matches an empty string, returns '' >>>> >>>> The result is therefore ['Mar', '', '', 'lam', '', ''] >>> >>> Thanks, now I see it through with clarity. >>> Both you and JB are right about this case. >>> However, what if the regex is ((.a.)*)* ? >>> >> Actually, in hindsight, my explanation is slightly wrong! >> >> re.search and the others return None for an unmatched group, but >> re.findall returns '' for an unmatched group, so instead of saying: >> >> Matches an empty string, returns '' >> >> I should have said: >> >> The group doesn't match at all, so .findall returns '' >> >> As for "((.a.)*)*", the inner group and repeat match like before, but >> then the outer repeat and group try again. >> >> The inner group can't match again, so it's unchanged (and it still >> remembers the last successful capture), and the outer group therefore >> matches an empty string. >> >> Therefore the outer (first) group is always an empty string and the >> inner (second) group is the same as the previous example (the last >> capture or '' if no capture). > > Now I'm confused - how can something with "zero or more occurrences" not > match? > Perhaps I just phrased it badly. Given a regex like "(.a.)*", the group might not match, but the regex itself will. From python at mrabarnett.plus.com Wed Nov 3 13:59:35 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 03 Nov 2010 17:59:35 +0000 Subject: Must be a bug in the re module [was: Why this result with the re module] In-Reply-To: <844169.1635.qm@web54201.mail.re2.yahoo.com> References: <844169.1635.qm@web54201.mail.re2.yahoo.com> Message-ID: <4CD1A307.2010809@mrabarnett.plus.com> On 03/11/2010 06:32, Yingjie Lan wrote: > --- On Wed, 11/3/10, John Bond wrote: >> I just explained that (I think!)! The outer capturing group >> uses >> repetition, so it returns the last thing that was matched >> by the inner >> group, which was an empty string. >> > According to yourself, the last match of the > inner group is also empty! > > Generally speaking, > as a match for the outer group always > contains some matches for the inner group, > it must be the case that the last match > for the inner group must be contained > inside the last match of the outer group. > So if the last match of the > outer group is empty, then the last > match for the inner group must > also be empty. > [snip] The outer group is repeated, so it can match again, but the inner group can't match again because it captured all it could the previous time. Therefore the outer group matches and captures an empty string and the inner group remembers its last capture. From jearl at notengoamigos.org Wed Nov 3 14:22:18 2010 From: jearl at notengoamigos.org (Jason Earl) Date: Wed, 03 Nov 2010 12:22:18 -0600 Subject: Man pages and info pages References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> <024ef21a-9ef9-48a6-8372-1d66895583c3@v16g2000yqn.googlegroups.com> <87zktr5yze.fsf_-_@mithlond.arda> <877hgv2fg3.fsf@mithlond.arda> <87hbfyn3uo.fsf@xemacs.org> <1bdce24e-4406-44c5-9133-bfd0acd0283d@p1g2000yqm.googlegroups.com> Message-ID: <87fwvigtd1.fsf@notengoamigos.org> On Wed, Nov 03 2010, rustom wrote: > On Nov 3, 3:11?pm, Daniel da Silva wrote: >> Guys, this really has nothing to do with python. > > ?? python docs have nothing to do with python?? python docs by > default on linux are read with info and many seem to find info > unpleasant to use. Actually, the Python documentation is no longer available in info format. Which is unfortunate, as that was the documentation format that I personally preferred. > Myself an old emacs user and cant say info helps me as much as google. > However comparing info and man is also a bit strange. The printed > python docs come to several thousand pages. Do we want them to be 1 > manpage? a hundred? a thousand? I am pretty conversant with the Python documentation. I almost never need to search them. I do miss being able to read (and search) the documentation in my editor though. Jason From news3 at mystrobl.de Wed Nov 3 14:35:02 2010 From: news3 at mystrobl.de (Wolfgang Strobl) Date: Wed, 03 Nov 2010 19:35:02 +0100 Subject: What people are using to access this mailing list References: Message-ID: <9v83d6pkpn7gt977lcn7072cqfcod9gq3m@4ax.com> John Bond : >Hope this isn't too O/T - I was just wondering how people read/send to this >mailing list, eg. normal email client, gmane, some other software or online >service? I'm reading comp.lang.python on usenet, using Fort? Agent as a newsreader, which connects via nntp to a locally managed leafnode, which in turn is fed by http://news.individual.net/ (for most newsgroups) and http://news.gmane.org/ (for some mailing lists which are only available there). I usually try to avoid reading mailing lists as mail. >My normal inbox is getting unmanageable, and I think I need to find a new way >of following this and other lists. Another way to regain control is to use separate mail adresses for different purposes. I'm adding another alias for a new subscription or a new registration email adress each time I subscribe to something. -- Thank you for observing all safety precautions From usernet at ilthio.net Wed Nov 3 14:49:06 2010 From: usernet at ilthio.net (Tim Harig) Date: Wed, 3 Nov 2010 18:49:06 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-03, Steven D'Aprano wrote: > On Tue, 02 Nov 2010 19:26:56 +0000, Tim Harig wrote: > >> I agree with Seebs, Python is the only language I know that promotes the >> use of spaces over tabs; > > Really? I'm not aware of *any* language that promotes tabs over spaces. I > thought the tabs vs spaces war was mostly won by spaces over a decade ago > (apart from a few plucky freedom fighters who will never surrender). Python is the only language that I know that *needs* to specify tabs versus spaces since it is the only language I know of which uses whitespace formating as part of its syntax and structure. Mixed usage may be annoying in other languages; but, it breaks Python. Otherwise, it is my experience that the preference for tabs versus spaces depends on the users chosen platform. *nix users prefer tabs while Windows users prefer spaces. >> and there are equally picky syntaxs (ie, >> Makefiles) that mandate the use of tabs. I personally prefer tabs as it >> lets *me* decide how far the apparent indentations are in the code. You >> may like four spaces; but, I agree with Linus Torvalds that eight spaces >> is much clearer. The beautiful thing about tabs is that we can both set >> our tab stops to match our own viewing preferences. > > Actually I agree with you about tabs. I think tabs are far more logical > and sensible. But I'm stuck with broken tools that don't deal with tabs, Where you not the one a few posts back telling Seebs that he needed to change his broken tools? > and with PEP 8 that mandates the use of spaces, and popular opinion that > says make is crazy for using tabs. Stupid rules are meant to be broken. > So, I bite my lip, stop using broken tools that make dealing with space- > indents painful, and just deal with it. And you know what? It's not so > bad after all. If I am using somebody elses project, then I will post my output using their code conventions. I have smart conversion scripts that convert between different indent formats. I edit in the format that I prefer and, in my projects, the indentation in the SCM is in my preferred format. >> This is Python's most noticable blemish outside of the community. >> Everybody knows that Python is the language that forces you to use a >> particular style of formatting; and, that is a turn-off for many people. > > Their loss. I don't miss the flame wars over the One True Brace Style. > There are enough disagreements over coding conventions without adding to > them. This choice has obviously not been effective in stopping flame wars. I can cite multiple threads where it has caused them. >> It is a big mistake that whenever the issue arises, the community >> effectively attacks anybody who might have disagreements with the >> tradeoffs made for the Python language. This tends to set people on the >> defensive and gives them a bad taste about the language as a whole. > > That's very insightful. Why don't you apply some of that insight to the > other side? It is *incredibly* annoying to see the same old people making > the same old snide remarks about the same old issues over and over again, > particularly when: A large part of the reason that the issue keeps coming up is that the community never really deals with it when it does. I have enough customer support experience to know that a client is never really satisfied until you acknowledge their problem. Until the problem is acknowledged, the client will have put up psychological communcation block that prevents them from hearing any workarounds that you might have. The community never acknowledges the problem. It simply sweeps the problem under the rug telling the people raising these issues that they don't know what they are talking about; strengthening the psychological block and further impeding the communication. The people with these problems therefore never feel that they have been heard, become unwilling to listen to the solutions, and will thus keep bringing the problem back up. > * it's not an issue for thousands of other users; You are now hearing the testimony of those who have had problems. I also know that it is human nature for advocates to simply overlook the problems when they arise. That doesn't mean that the problem is there. I have used Python for over a decade in spite of its problems because I believe that the benefits outway the detriments. I am however objective enough to be congnizant of the problems; and, I am fully aware of there effects on new members of the community. When prospective Python programmers approach me with these problems I: 1. Acknowledge that the problem exits. 2. Explain the trade-offs that have lead to the problem. 3. Suggest ways to work around the problem. 4. Point out why I believe the benefits of using Python outway its idiosyncrasies. I don't just tell them that there is no problem or that the problems they may be experiencing are their fault because they choose to do something differently then I might. > * even if it were an issue, if you use the right tool for the job, the > issue disappears; That a tools is needed is in itself an indication that the problem exists. That isn't to say that good tools don't have their place or that they cannot contribute to the solution. > * and even if it would change, the people doing the whinging aren't going > to volunteer to make the change. Funny that. I *do* have a history of submitting patches to open source projects. >> It would be much better if the community would simply acknowledge that >> this is a tradeoff the the language has made and one which is often >> misunderstood by many first time Python programmers. > > Been there, done that. This is *old news*. Except that you are not. Your general attitude is that since you don't experience problems nobody else must either. From iamforufriends at gmail.com Wed Nov 3 14:52:22 2010 From: iamforufriends at gmail.com (ADULTS GROUP FOR FUN WITH SE ^X) Date: Wed, 3 Nov 2010 11:52:22 -0700 (PDT) Subject: HAY... U KNOW, NOW DATING WITH SWEET AND CUTYS IS EAZY... AND FREE... Message-ID: <62e83987-6e72-432b-a0e7-f1503835111e@p20g2000prf.googlegroups.com> HAY... U KNOW, NOW DATING WITH SWEET AND CUTYS IS EAZY... AND FREE... JUST FOLLOW THE LINK....... http://tinyurl.com/eazy-dating http://tinyurl.com/eazy-dating http://tinyurl.com/eazy-dating http://tinyurl.com/eazy-dating http://tinyurl.com/eazy-dating http://tinyurl.com/eazy-dating http://tinyurl.com/eazy-dating http://tinyurl.com/eazy-dating http://tinyurl.com/eazy-dating http://tinyurl.com/eazy-dating http://tinyurl.com/eazy-dating From martin at address-in-sig.invalid Wed Nov 3 15:00:32 2010 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Wed, 3 Nov 2010 19:00:32 +0000 (UTC) Subject: What people are using to access this mailing list References: <4cd144cc$0$29966$c3e8da3$5496439d@news.astraweb.com> <87r5f2wr7t.fsf@rudin.co.uk> Message-ID: On Wed, 03 Nov 2010 13:05:23 +0000, Grant Edwards wrote: > On 2010-11-03, Paul Rudin wrote: >> John Bond writes: >> >>> On 3/11/2010 11:17 AM, Steven D'Aprano wrote: >>>> On Wed, 03 Nov 2010 08:02:29 +0000, John Bond wrote: >>>> >>>>> Hope this isn't too O/T - I was just wondering how people read/send >>>>> to this mailing list, eg. normal email client, gmane, some other >>>>> software or online service? >>>> Usenet via my ISP, on comp.lang.python. >>>> >>> Using what client (or web client)? >> >> Emacs, of course :-; > > Slrn, of course. Pan since I'm on Linux. Agent if I was still a Windows user. Its the best news reader I've used. -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From usernet at ilthio.net Wed Nov 3 15:07:48 2010 From: usernet at ilthio.net (Tim Harig) Date: Wed, 3 Nov 2010 19:07:48 +0000 (UTC) Subject: What people are using to access this mailing list References: <4cd144cc$0$29966$c3e8da3$5496439d@news.astraweb.com> <87r5f2wr7t.fsf@rudin.co.uk> Message-ID: On 2010-11-03, Grant Edwards wrote: > On 2010-11-03, Paul Rudin wrote: >> John Bond writes: >> >>> On 3/11/2010 11:17 AM, Steven D'Aprano wrote: >>>> On Wed, 03 Nov 2010 08:02:29 +0000, John Bond wrote: >>>> >>>>> Hope this isn't too O/T - I was just wondering how people read/send to >>>>> this mailing list, eg. normal email client, gmane, some other software >>>>> or online service? >>>> Usenet via my ISP, on comp.lang.python. >>>> >>> Using what client (or web client)? >> >> Emacs, of course :-; > > Slrn, of course. Of, course. From invalid at invalid.invalid Wed Nov 3 15:16:41 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 3 Nov 2010 19:16:41 +0000 (UTC) Subject: What people are using to access this mailing list References: <4cd144cc$0$29966$c3e8da3$5496439d@news.astraweb.com> <87r5f2wr7t.fsf@rudin.co.uk> Message-ID: On 2010-11-03, Tim Harig wrote: > On 2010-11-03, Grant Edwards wrote: >> On 2010-11-03, Paul Rudin wrote: >>> John Bond writes: >>> >>>> On 3/11/2010 11:17 AM, Steven D'Aprano wrote: >>>>> On Wed, 03 Nov 2010 08:02:29 +0000, John Bond wrote: >>>>> >>>>>> Hope this isn't too O/T - I was just wondering how people read/send to >>>>>> this mailing list, eg. normal email client, gmane, some other software >>>>>> or online service? >>>>> >>>>> Usenet via my ISP, on comp.lang.python. >>>> >>>> Using what client (or web client)? >>> >>> Emacs, of course :-; >> >> Slrn, of course. > > Of, course. The OP could have figured all this out by himself by merely looking at the headers for a sampling of articles. Heck, with about 50 lines of Python, one could probably produced a fairly comprehensive statistical report on access methods and clients used by posters to "this mailing list". [An NNTP client module is one of the "batteries", and that module's docs contains most of the code needed to access the articles.] Finding out the access methods used by people who don't post is somewhat more difficult. :) -- Grant Edwards grant.b.edwards Yow! Boy, am I glad it's at only 1971... gmail.com From steve at REMOVE-THIS-cybersource.com.au Wed Nov 3 15:21:40 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 03 Nov 2010 19:21:40 GMT Subject: What people are using to access this mailing list References: <4cd144cc$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4cd1b643$0$29966$c3e8da3$5496439d@news.astraweb.com> On Wed, 03 Nov 2010 11:58:07 +0000, John Bond wrote: > On 3/11/2010 11:17 AM, Steven D'Aprano wrote: >> On Wed, 03 Nov 2010 08:02:29 +0000, John Bond wrote: >> >>> Hope this isn't too O/T - I was just wondering how people read/send to >>> this mailing list, eg. normal email client, gmane, some other software >>> or online service? >> Usenet via my ISP, on comp.lang.python. >> >> >> > Using what client (or web client)? Usually Pan, sometimes KNode. -- Steven From steve at REMOVE-THIS-cybersource.com.au Wed Nov 3 15:36:05 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 03 Nov 2010 19:36:05 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> On Wed, 03 Nov 2010 02:40:11 +0000, Seebs wrote: > Sure, but there's also no way for you to spot that something looks > suspicious. In Python, if something is misindented, it does what you > told it to do, and there's no way for you to tell, by looking at it, > that it isn't what was intended. In C, if something is misindented, it > does what you told it to do, but it's obvious looking at the code that > something went wrong. If it's that obvious, why do people keep causing those indentation- related bugs in C? I'm glad for you that you have a finely trained attention to detail that is able to instantly spot misindented C code (or is that misplaced braces and correctly indented?), but it is a notoriously common error which suggests that it's not anywhere near as obvious as you think. It's *far* more common than Python code being misindented. There's even a commonly suggested style for C programmers: always use braces any time the syntax allows them, even when they're not needed, because the next guy who maintains the file may not be as careful and may forget to add the braces when needed. >> But I can see the other end of the block in Python. I don't need any >> tricks to make sure that it is the end. And if your block is too big >> to see the structure easily then that just means that some code should >> be factored out to a method. > > This level of dogmatism about what should always be the case is not > conducive to good software engineering practices. I question that assertion. Good engineering practices is about setting best practices, and following them, not avoiding them because there might be the odd exception here and there. > It is not obvious to me that it's *always* the case. So what if there is an exception one time in twenty thousand? You don't design a tool (such as a programming language) on the basis of what's good for the rare exceptional cases, but on what's good for the common cases. The common case is that functions and methods should be short enough to see the structure by eye. If it isn't, you have more problems than just the lack of begin/end markers. The language shouldn't make everyone carry the burden of supporting two-page functions all the time, just to save you an insignificant amount of trouble on the vanishingly rare occasion you need a function that is two pages long. -- Steven From emile at fenx.com Wed Nov 3 15:37:26 2010 From: emile at fenx.com (Emile van Sebille) Date: Wed, 03 Nov 2010 12:37:26 -0700 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 11/3/2010 11:49 AM Tim Harig said... > A large part of the reason that the issue keeps coming up is that the > community never really deals with it when it does. I have enough customer > support experience to know that a client is never really satisfied until > you acknowledge their problem. Then you likely also have enough experience to know that once the customer has made the decision you accept their call. As a consultant you move on after having done your duty bringing the issue to light. The same applies here -- it's not changing, so you (generic you) accept it and move on. The community has dealt with the issue by acknowledging that differing opinions exist and the BDFL makes the final call, which is certainly something the community accepts. I imagine a PEP could be submitted suggesting change, and it hasn't been done because the outcome is certain. Otherwise, there's always whython... http://writeonly.wordpress.com/2010/04/01/whython-python-for-people-who-hate-whitespace/ Emile From steve at REMOVE-THIS-cybersource.com.au Wed Nov 3 16:03:15 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 03 Nov 2010 20:03:15 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4cd1c003$0$29966$c3e8da3$5496439d@news.astraweb.com> On Wed, 03 Nov 2010 18:49:06 +0000, Tim Harig wrote: >> Actually I agree with you about tabs. I think tabs are far more logical >> and sensible. But I'm stuck with broken tools that don't deal with >> tabs, > > Where you not the one a few posts back telling Seebs that he needed to > change his broken tools? Yes, and I also said that I sympathized with him if he couldn't. >>> It is a big mistake that whenever the issue arises, the community >>> effectively attacks anybody who might have disagreements with the >>> tradeoffs made for the Python language. This tends to set people on >>> the defensive and gives them a bad taste about the language as a >>> whole. >> >> That's very insightful. Why don't you apply some of that insight to the >> other side? It is *incredibly* annoying to see the same old people >> making the same old snide remarks about the same old issues over and >> over again, particularly when: > > A large part of the reason that the issue keeps coming up is that the > community never really deals with it when it does. No. The community does deal with it. It deals with it by saying "It isn't going to change." If you want a language that forces you to wrap ever block in BEGIN END tags, you have a thousand choices. Python is not one of them. What is so hard to understand about this? > I have enough > customer support experience to know that a client is never really > satisfied until you acknowledge their problem. Until the problem is > acknowledged, the client will have put up psychological communcation > block that prevents them from hearing any workarounds that you might > have. Yes, well that too goes both ways. *I* have a psychological communication block that prevents me from hearing any complaints about the lack of braces from people who refuse to acknowledge that having to type braces is stupid and annoying, and that the use of braces in a language hurts readability. Frankly, I DON'T CARE how often your editor breaks your source code. I don't care about Seeb's mail server that converts his Python code to HTML. I don't give a rat's arse about how many times some buggy ftp client has mangled the indentation on Python files. Not my problem. Your pain is not my pain, and any solution to these problems that involves changing the way I read and write Python code is an anti-solution to a non-problem to me. Until the "Python is broken 'cos it has no braces" crowd acknowledge this fact, I just harden my heart against their complaints. Why should *I* have to acknowledge their issues when they don't acknowledge mine? -- Steven From steve at REMOVE-THIS-cybersource.com.au Wed Nov 3 16:05:58 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 03 Nov 2010 20:05:58 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4cd1c0a6$0$29966$c3e8da3$5496439d@news.astraweb.com> On Wed, 03 Nov 2010 01:25:56 +0000, Seebs wrote: > Whitespace damage is, indeed, wrong. It's a bad thing. It is an > *extremely common* bad thing, I question that. You've claimed that you have to deal with broken indentation on a regular basis. I've *never* had to deal with broken whitespace, except for certain websites that mangle leading whitespace when you post a comment. So I don't post code on those websites. > and I fundamentally don't think it was a > good choice to build a system with no redundancy against it. Python does have some redundancy against indentation mangling. Not all combinations of indentation are legal. # Not legal: y = x + 1 z = x*y # Not legal: if x: do_something() # Not legal: if x: do something() else: do_something_else() And so on. True, there are some failure modes which can't be easily recovered from without reading and understanding the code. That's okay. Such failure modes are vanishingly rare -- for every twenty thousand braces you avoid typing, you might, if you're unlucky, need to fix an instance of broken indentation. > That > "redundant" information saves our hides on a regular basis in an > imperfect world. So you say. -- Steven From usenet-nospam at seebs.net Wed Nov 3 16:30:43 2010 From: usenet-nospam at seebs.net (Seebs) Date: 03 Nov 2010 20:30:43 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-03, Steven D'Aprano wrote: > On Tue, 02 Nov 2010 19:26:56 +0000, Tim Harig wrote: >> I agree with Seebs, Python is the only language I know that promotes the >> use of spaces over tabs; > Really? Yes. > I'm not aware of *any* language that promotes tabs over spaces. Makefiles. > I > thought the tabs vs spaces war was mostly won by spaces over a decade ago > (apart from a few plucky freedom fighters who will never surrender). No. However, you've got a fallacy of the excluded middle here -- you're ignoring the very large set of "doesn't care either way", and looking only at things that prefer one or the other. > So, I bite my lip, stop using broken tools that make dealing with space- > indents painful, and just deal with it. And you know what? It's not so > bad after all. I don't consider it broken for a tool to favor a more logical style which is *actually* required by at least one format, and not a problem for anything I've ever used except (sort of) Python. In fact, Python works perfectly with tabs; it's just other Python programmers who get fussy. :) > Their loss. I don't miss the flame wars over the One True Brace Style. > There are enough disagreements over coding conventions without adding to > them. I don't miss them, or care about them; after all, I can just run indent/cb to format something however I like, and run it again to match any given coding style standard. Problem solved. > * it's not an issue for thousands of other users; This is a non-argument. That something isn't a problem for other people makes no difference to the people for whom it's a problem. > * even if it were an issue, if you use the right tool for the job, the > issue disappears; I have never found any other editor that I like as much as the one I use now. > * and even if there is no right tool for the job, the feature isn't going > to change; I think you miss the point of the observation. I'm not expecting it to change; I'm pointing out that insisting that it's not a problem is *insulting* to the people for whom it is a problem. > * and even if it would change, the people doing the whinging aren't going > to volunteer to make the change. Oh, I'd happily contribute code if it'd matter. But it wouldn't. >> It would be much better if the community would simply acknowledge that >> this is a tradeoff the the language has made and one which is often >> misunderstood by many first time Python programmers. > Been there, done that. This is *old news*. I haven't seen it done yet. I've seen a whole lot of people tell me that an editor I've been using for twenty years is "broken" because I found a program that is brittle with regards to its inputs that is prone to being triggered by a behavior which has been free of problems (and indeed in some cases *mandatory*) for everything else. I've seen people smugly tell me that I'd love this if I just tried it. That didn't work for pickles, it didn't work for Player-vs-Player fighting in video games, and it's not gonna work for the lack of end markers. Explicit is better than implicit. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Wed Nov 3 16:35:20 2010 From: usenet-nospam at seebs.net (Seebs) Date: 03 Nov 2010 20:35:20 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-03, Steven D'Aprano wrote: > On Wed, 03 Nov 2010 02:40:11 +0000, Seebs wrote: >> Sure, but there's also no way for you to spot that something looks >> suspicious. In Python, if something is misindented, it does what you >> told it to do, and there's no way for you to tell, by looking at it, >> that it isn't what was intended. In C, if something is misindented, it >> does what you told it to do, but it's obvious looking at the code that >> something went wrong. > If it's that obvious, why do people keep causing those indentation- > related bugs in C? I don't think they do. I can't remember the last time I've seen one. > I'm glad for you that you have a finely trained attention to detail that > is able to instantly spot misindented C code (or is that misplaced braces > and correctly indented?), but it is a notoriously common error which > suggests that it's not anywhere near as obvious as you think. It's "notoriously common", but can you show me an actual example of it happening in real code? Not a "hey guys look how misleading this would be" example conjured up for illustration, but an *actual* example in live code? I can't remember one, except I think maybe I saw one somewhere in... hmm. No, wait, that was perl. >> This level of dogmatism about what should always be the case is not >> conducive to good software engineering practices. > I question that assertion. Good engineering practices is about setting > best practices, and following them, not avoiding them because there might > be the odd exception here and there. I don't think I buy this. I've seen a whole lot of good writers and good programmers, and in both groups, they consistently report that you have to know how the rules work before you break them. > The language shouldn't make > everyone carry the burden of supporting two-page functions all the time, > just to save you an insignificant amount of trouble on the vanishingly > rare occasion you need a function that is two pages long. I don't think there's a particularly big burden there. Explicit is better than implicit. It is *better* to explicitly mark the ends of things than to have it be implicit in dropping indentation. That's not a burden, it's good engineering practice. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Wed Nov 3 16:39:47 2010 From: usenet-nospam at seebs.net (Seebs) Date: 03 Nov 2010 20:39:47 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1c0a6$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-03, Steven D'Aprano wrote: > On Wed, 03 Nov 2010 01:25:56 +0000, Seebs wrote: >> Whitespace damage is, indeed, wrong. It's a bad thing. It is an >> *extremely common* bad thing, > I question that. > You've claimed that you have to deal with broken indentation on a regular > basis. I'd guess I see something which got screwed up somehow every couple of weeks, usually while refactoring stuff. >> and I fundamentally don't think it was a >> good choice to build a system with no redundancy against it. > Python does have some redundancy against indentation mangling. Not all > combinations of indentation are legal. True, but it doesn't seem to catch the most common failure modes. > And so on. True, there are some failure modes which can't be easily > recovered from without reading and understanding the code. That's okay. > Such failure modes are vanishingly rare -- for every twenty thousand > braces you avoid typing, you might, if you're unlucky, need to fix an > instance of broken indentation. This is ridiculous overstatement. Moving a single block of overly-nested code out into a separate method could generate several indentation mishaps if Something Goes Wrong, which it does sometimes. I haven't written more than a couple hundred blocks in Python, so I'm a factor of a hundred out from twenty thousand braces, and I've had six or seven indentation problems. And yes, I can just recreate it, but it takes more effort, since I can't do things like just handing it to an automated tool that can correct it completely automatically. Furthermore, I don't WANT to skip closing braces. EXPLICIT IS BETTER THAN IMPLICIT. I *WANT* to have the beginnings and ends marked. I want end braces or "end" or something at the end of a block for the same reason that I prefer: x = "hello, world" to x = "hello, world where we just assume the string ends at the end of the line. >> That >> "redundant" information saves our hides on a regular basis in an >> imperfect world. > So you say. Well, it works for me. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From invalid at invalid.invalid Wed Nov 3 16:46:22 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 3 Nov 2010 20:46:22 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-03, Seebs wrote: > Explicit is better than implicit. It is *better* to explicitly mark the > ends of things than to have it be implicit in dropping indentation. That's > not a burden, it's good engineering practice. Dededenting does explicitly mark the end of a block. -- Grant Edwards grant.b.edwards Yow! What PROGRAM are they at watching? gmail.com From cs at zip.com.au Wed Nov 3 16:48:09 2010 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 4 Nov 2010 07:48:09 +1100 Subject: Python documentation too difficult for beginners In-Reply-To: References: Message-ID: <20101103204809.GA5306@cskk.homeip.net> On 02Nov2010 03:42, jk wrote: | I've been coding in PHP and Java for years, and their documentation is | concise, well structured and easy to scan. While I agree about Java, at least the core Java docs, and javadoc output in general (_great_ cross referencing!) I have mixed feelings about the PHP docs. Though I suspect that stems from a dislike of the PHP library API in general more than the docs, perhaps. | Others have mentioned this apparently for years (see: | http://stackoverflow.com/questions/4046166/easy-to-navigate-online-python-reference-manual/4070851 | and http://www.russellbeattie.com/blog/python-library-docs-still-suck | and http://xahlee.org/perl-python/xlali_skami_cukta.html). | | Compare for instance the differences in ease of use, and speed of use, | of these: | | http://docs.python.org/library/functions.html#open | http://uk.php.net/manual/en/function.fopen.php | | The former is difficult to find (try searching for 'open' in the | search box and see what you get). I confess I almost never use the search box - as you say the result relevance can be dodgy. However, I do find the docs easy to use and pleasant to read on the whole. My use is as follows: For speed and convenience I have the docs locally stored. I open the front page and then usually both the modules and index in adjacent brwoser tabs. I go to the index if I'm not sure of the module. The strength of the index is that it tends to contain stuff that people thought should be indexed (versus searches, which often have no contextual understanding of the text, so their relevance is weaker). The weakness of the index is that it can be hard to pick the relevant entry. Open-link-in-new-tab is my friend here:-( | It is simply a collection of | paragraphs without strong enough contrast to differentiate the | different parts - parameters, parameter values, return types, | exceptions and related functions. It is slow to read and doesn't allow | easy visual scanning. That is true (the scanning). But by contrast, it does read like prose and lends itself to a visit that gets you a complete feel for the function. [...] | Has anyone else struggled while trying to learn the language? The | whole documentation system seems geared towards people who already | know what they're looking for and is close to useless for beginners. | I'm not the only one who finds google an easier way to find | documentation about python. I certainly don't find the core docs hard to use (with some exceptions; I still don't really understand the urllib stuff for the cases where configuration is needed - weird proxy setups etc). I've only been using Python for a few years and have generally found that language easy to learn and the docs easy to read. I rarely reach for The Google unless I'm seeking examples; the docs could do with a few more of these IMHO. I understand the attraction of the structured layout javadoc yields but find it leads to "drier" documentation. It also works well for Java because it is strongly typed - a great deal of the structure in the docs can come directly from the code because argument counts, names and types are always explicit (or deducable). These are just initial responses. Now to wade the whole thread:-) -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ On the contrary of what you may think, your hacker is fully aware of your company's dress code. He is fully aware of the fact that it doesn't help him to do his job. - Gregory Hosler From usenet-nospam at seebs.net Wed Nov 3 16:59:46 2010 From: usenet-nospam at seebs.net (Seebs) Date: 03 Nov 2010 20:59:46 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-03, Grant Edwards wrote: > On 2010-11-03, Seebs wrote: >> Explicit is better than implicit. It is *better* to explicitly mark the >> ends of things than to have it be implicit in dropping indentation. That's >> not a burden, it's good engineering practice. > Dededenting does explicitly mark the end of a block. If you can't point to the token, it's implicit. :) -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From cs at zip.com.au Wed Nov 3 17:03:37 2010 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 4 Nov 2010 08:03:37 +1100 Subject: Python documentation too difficult for beginners In-Reply-To: References: Message-ID: <20101103210336.GA9858@cskk.homeip.net> On 02Nov2010 04:23, jk wrote: | This (http://epydoc.sourceforge.net/stdlib/) is what I'm talking | about. | | Why aren't the official docs like this, and why has it taken me 2 days | of searching? All this needs is a search engine behind it and it'd be | perfect. It looks a lot like javadoc. But its weakness is stuff like this: http://epydoc.sourceforge.net/stdlib/Canvas.Polygon-class.html Automatic docness, no useful information. And of course the ugliness; I find the python docs much nicer to look at. But I do wish the cross referencing was a bit better, often. -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ In an insane society, the sane man must appear insane. - Keith A. Schauer From martin at address-in-sig.invalid Wed Nov 3 17:18:17 2010 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Wed, 3 Nov 2010 21:18:17 +0000 (UTC) Subject: Python documentation too difficult for beginners References: Message-ID: On Thu, 04 Nov 2010 08:03:37 +1100, Cameron Simpson wrote: > On 02Nov2010 04:23, jk wrote: | This > (http://epydoc.sourceforge.net/stdlib/) is what I'm talking | about. > | > | Why aren't the official docs like this, and why has it taken me 2 days > | of searching? All this needs is a search engine behind it and it'd be > | perfect. > > It looks a lot like javadoc. But its weakness is stuff like this: > > http://epydoc.sourceforge.net/stdlib/Canvas.Polygon-class.html > > Automatic docness, no useful information. > You get the same problem in Java and it has exactly the same root: a lazy programmer who can't be arsed to document his code. -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From ben+python at benfinney.id.au Wed Nov 3 17:27:14 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 04 Nov 2010 08:27:14 +1100 Subject: Ways of accessing this mailing list? References: Message-ID: <87lj5ahzd9.fsf@benfinney.id.au> Grant Edwards writes: > On 2010-11-02, John Bond wrote: > > My normal inbox is getting unmanageable, and I think I need to find > > a new way of following this and other lists. > > Point an NNTP client at new.gmane.org. Ditto, but the correct hostname is ?news.gmane.org?. > This "list" is also a Usenet newsgroup (comp.lang.python), and there > are a number of cheap/low-cost text-only Usenet providers. Moreover, Gmane is (as John probably knows) an NNTP interface to many forums that would otherwise not be available via NNTP. -- \ ?Members of the general public commonly find copyright rules | `\ implausible, and simply disbelieve them.? ?Jessica Litman, | _o__) _Digital Copyright_ | Ben Finney From ben+python at benfinney.id.au Wed Nov 3 17:30:09 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 04 Nov 2010 08:30:09 +1100 Subject: What people are using to access this mailing list References: <4cd144cc$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87hbfyhz8e.fsf@benfinney.id.au> John Bond writes: > On 3/11/2010 11:17 AM, Steven D'Aprano wrote: > > Usenet via my ISP, on comp.lang.python. > Using what client (or web client)? Gnus on Emacs. -- \ ?Perchance you who pronounce my sentence are in greater fear | `\ than I who receive it.? ?Giordano Bruno, burned at the stake by | _o__) the Catholic church for the heresy of heliocentrism, 1600-02-16 | Ben Finney From usernet at ilthio.net Wed Nov 3 17:56:00 2010 From: usernet at ilthio.net (Tim Harig) Date: Wed, 3 Nov 2010 21:56:00 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1c003$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-03, Steven D'Aprano wrote: > On Wed, 03 Nov 2010 18:49:06 +0000, Tim Harig wrote: >>> Actually I agree with you about tabs. I think tabs are far more logical >>> and sensible. But I'm stuck with broken tools that don't deal with >>> tabs, >> >> Where you not the one a few posts back telling Seebs that he needed to >> change his broken tools? > > Yes, and I also said that I sympathized with him if he couldn't. Perhaps it would be more constructive, for everybody, to make suggestions on how to reliably transfer code using channels that distort whitespace. >>> That's very insightful. Why don't you apply some of that insight to the >>> other side? It is *incredibly* annoying to see the same old people >>> making the same old snide remarks about the same old issues over and >>> over again, particularly when: >> >> A large part of the reason that the issue keeps coming up is that the >> community never really deals with it when it does. > > No. The community does deal with it. It deals with it by saying "It isn't > going to change." If you want a language that forces you to wrap ever > block in BEGIN END tags, you have a thousand choices. Python is not one > of them. What is so hard to understand about this? Please to not mix my contentions with somebody else's. I have not, anywhere in this thread, asked to change the language. I certainly didn't say *anything* about adding "BEGIN END" tags to the code itself. I did say that I found code folding markers in the comments to be a useful form for expressing code structure; but, that has nothing to with chainging Python itself. I also expressed my opinion that I felt spaces for indenting was a poor choice for the standard; but, since it is also not part of the language proper, it can safely be ignored. What I did suggest was a more constructive way of dealing with these criticisms. You said that you found it "*incredibly* annoying" to have this to see the same old "snide remarks" from "the same old people." I merely suggested that if the community changes its attitude towards those making those remarks, that it might go a long way towards silencing some of those descents. The fact that you are unwilling to make these changes makes me question your conviction when you claim to be so annoyed. >> I have enough >> customer support experience to know that a client is never really >> satisfied until you acknowledge their problem. Until the problem is >> acknowledged, the client will have put up psychological communcation >> block that prevents them from hearing any workarounds that you might >> have. > > Yes, well that too goes both ways. *I* have a psychological communication > block that prevents me from hearing any complaints about the lack of > braces from people who refuse to acknowledge that having to type braces > is stupid and annoying, and that the use of braces in a language hurts > readability. I understand that you don't like braces; but, I have nowhere advocated adding them to the Python langauge. That is a different argument that you are having with Seebs. > Frankly, I DON'T CARE how often your editor breaks your source code. I Only you have even mentioned editors in this thread. > don't care about Seeb's mail server that converts his Python code to > HTML. I don't give a rat's arse about how many times some buggy ftp > client has mangled the indentation on Python files. Not my problem. Your Nobody else mentioned ftp servers in this either; but, I must admit that you are doing a good job of providing evidence for the alternate viewpoint. > pain is not my pain, and any solution to these problems that involves > changing the way I read and write Python code is an anti-solution to a > non-problem to me. Then why bother adding to the noise in this thread at all since it has nothing to do with you? I see however, since you have brought all this baggage to the table that was not otherwise in the thread, that you obviously have a axe to grind. > Until the "Python is broken 'cos it has no braces" crowd acknowledge this > fact, I just harden my heart against their complaints. Why should *I* > have to acknowledge their issues when they don't acknowledge mine? Then please state your Python language issues rather simply grinding your axe against those who are stating theirs. From steve-REMOVE-THIS at cybersource.com.au Wed Nov 3 18:30:12 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 03 Nov 2010 22:30:12 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> On Wed, 03 Nov 2010 20:35:20 +0000, Seebs wrote: >>> This level of dogmatism about what should always be the case is not >>> conducive to good software engineering practices. > >> I question that assertion. Good engineering practices is about setting >> best practices, and following them, not avoiding them because there >> might be the odd exception here and there. > > I don't think I buy this. I've seen a whole lot of good writers and > good programmers, and in both groups, they consistently report that you > have to know how the rules work before you break them. Yes. How does that contradict what I said? There is a huge difference between knowing when to break the rules, and avoiding the rules because there might someday be an exception. >> The language shouldn't make >> everyone carry the burden of supporting two-page functions all the >> time, just to save you an insignificant amount of trouble on the >> vanishingly rare occasion you need a function that is two pages long. > > I don't think there's a particularly big burden there. Good for you. > Explicit is better than implicit. Ah, argument by misunderstanding the Zen! > It is *better* to explicitly mark the > ends of things than to have it be implicit in dropping indentation. > That's not a burden, it's good engineering practice. Python does explicitly mark blocks. It does it by changes in indentation. An indent is an explicit start-block. An outdent is an explicit end- block. There is nothing implicit in a change in indent level. To illustrate the difference, this is how a hypothetical language might use implicit end of blocks: if condition: true_clause() another_true_clause() else: false_clause() The if block ends implicitly when you reach an else statement, and the else clause implicitly ends... where? It gets worse: if condition: if another_condition: true_clause() else: false_clause() another_clause() Such a hypothetical language might decide on a rule that else will always match the closest if, or the outermost if that is legal. That would be an implicit end of block. This is not even within the same galaxy as what Python does. It simply isn't possible to have implicit start/end block markers, unless you restrict your language in ways that exclude most blocks. E.g. if all if blocks were restricted to a single statement, then you could have an implicit block -- the block in one statement. Stating that Python uses implicit block markers is simply wrong. -- Steven From ldo at geek-central.gen.new_zealand Wed Nov 3 18:40:12 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 04 Nov 2010 11:40:12 +1300 Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> Message-ID: In message , Chris Rebert wrote: > Actually, my PEP 8 reference was in regards to the (imo, terrible) > UseOfCamelCaseForNonClasses (Python != C#), not the formatting of the > for-loop; hence the "In any case" qualification. Hmm ... OK, I might accept that particular criticism. I have to say it?s a habit I picked up in my Mac programming days, that I find hard to shake. I do sometimes deliberately use lowercase_with_underscores, but then I keep LapsingBackAgain. At least I prefer Bactrian to Dromedary. :) From zkinion at gmail.com Wed Nov 3 18:46:38 2010 From: zkinion at gmail.com (Zak Kinion) Date: Wed, 3 Nov 2010 15:46:38 -0700 Subject: Subject: Re: problem with opening a new python program in a new window (and keeping track of the process) Message-ID: >> What I want to do: ?launch seperate python programs from one main >> program (multi-threading will not achieve this because the mechanize >> library uses one shared global opener object which will not suit my >> needs) ?I want the scripts launched to be in seperate windows that i >> can see the output of on screen, seperate processes. ?I can accomplish >> this in win32 by: >> >> import subprocess; >> args = ["cmd", "/c", "START", "python", "myScript.py"]; >> process1 = subprocess.Popen(args, shell=False); > > Pass CREATE_NEW_CONSOLE as one of the creationflags: > > > import os, sys Yep, that definitely works. :) > import subprocess > > processes = [] > cmd = [sys.executable, "-c", "import os; print os.getpid (); raw_input ()"] > for i in range (3): > ?processes.append (subprocess.Popen (cmd, creationflags=subprocess.CREATE_NEW_CONSOLE)) > > # > # Keep looping round to see the current status > # > while True: > ?for p in processes: > ? ?print p.poll () > > ?raw_input () > > > > TJG > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Zak Kinion zkinion at gmail.com (702) 287-5613 From ldo at geek-central.gen.new_zealand Wed Nov 3 18:51:35 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 04 Nov 2010 11:51:35 +1300 Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> Message-ID: In message , Roy Smith wrote: >> > > That URL takes me to a github page. Can you be more specific about > which file I should be looking at? The extract I previously quoted was from dvd_menu_animator. > 2) You have provided comments for each function, such as (lines 36-37): > > def NewLayer(svg, LayerName) : > # adds a new layer to the SVG document and returns it. > > This is good, but would be even more useful if it were turned into a > docstring ... I am ambivalent about the usefulness of docstrings. I find them mainly handy in stuff imported from library modules, of which this is not one. > 3) I find the deeply nested style you use very difficult to read. For > example, on lines 80-103. As I read this, here's how I mentally process > it: > > "OK, here's a function call (minor stumble over the open paren not being > on the same line as the function name, but I can get past that). The > first argument is TheLayer. The second argument is whatever > inkex.addNS() returns. Umm..." You?re looking at it wrong. It?s building a data structure to go into an SVG file. Think of each piece of the expression as directly mapping to the corresponding piece of the structure being built. The value being built for the ?d? attribute is just a sequence of control points for the path. From rhodri at wildebst.demon.co.uk Wed Nov 3 19:07:00 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 03 Nov 2010 23:07:00 -0000 Subject: What people are using to access this mailing list References: <4cd144cc$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, 03 Nov 2010 11:58:07 -0000, John Bond wrote: > On 3/11/2010 11:17 AM, Steven D'Aprano wrote: >> On Wed, 03 Nov 2010 08:02:29 +0000, John Bond wrote: >> >>> Hope this isn't too O/T - I was just wondering how people read/send to >>> this mailing list, eg. normal email client, gmane, some other software >>> or online service? >> Usenet via my ISP, on comp.lang.python. >> >> >> > Using what client (or web client)? Opera (as an NNTP client, not a web client). -- Rhodri James *-* Wildebeest Herder to the Masses From usenet-nospam at seebs.net Wed Nov 3 19:09:10 2010 From: usenet-nospam at seebs.net (Seebs) Date: 03 Nov 2010 23:09:10 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-03, Steven D'Aprano wrote: > Yes. How does that contradict what I said? Once you understand that you do have to break the rules occasionally, it is a good idea to design things that will be robust when the rules are broken. > Ah, argument by misunderstanding the Zen! I see. So explicit boundaries are a good thing, except when they are one specific special case. Let us imagine a hypothetical mirror-universe person, who is otherwise like you, but: 1. Has a goatee. 2. Actually hates the indentation rules, wishes Python had braces, but has become emotionally invested in defending the status quo because if he had to suffer, dammit, everyone else should have to suffer too. You have not yet made a single argument that he wouldn't have made too. >> It is *better* to explicitly mark the >> ends of things than to have it be implicit in dropping indentation. >> That's not a burden, it's good engineering practice. > Python does explicitly mark blocks. It does it by changes in indentation. > An indent is an explicit start-block. An outdent is an explicit end- > block. There is nothing implicit in a change in indent level. What's the token that marks the end of a block, corresponding to the colon used to introduce it? > It simply isn't possible to have implicit start/end block markers, unless > you restrict your language in ways that exclude most blocks. E.g. if all > if blocks were restricted to a single statement, then you could have an > implicit block -- the block in one statement. Stating that Python uses > implicit block markers is simply wrong. No, it isn't. There's no token telling you where the block ended. C *allows* implicit blocks, and this is widely regarded as a key flaw. However, it also allows you to explicitly mark blocks in a way which is robust against common errors, allowing software to automatically fix up differences between, say, competing indentation styles. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From torriem at gmail.com Wed Nov 3 19:18:27 2010 From: torriem at gmail.com (Michael Torrie) Date: Wed, 03 Nov 2010 17:18:27 -0600 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1c0a6$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4CD1EDC3.3030305@gmail.com> On 11/03/2010 02:39 PM, Seebs wrote: > Furthermore, I don't WANT to skip closing braces. EXPLICIT IS BETTER > THAN IMPLICIT. I *WANT* to have the beginnings and ends marked. I suggest, then that Pascal or Ruby would suit your needs better than Python. > I want end braces or "end" or something at the end of a block for > the same reason that I prefer: > x = "hello, world" > to > x = "hello, world > where we just assume the string ends at the end of the line. Not even close to the same thing, sorry. As for refactoring code, vim makes it really easy to move blocks in and out. The only time I could see this becoming an issue is if functions or blocks of code are too long to see on a page at once. If this is the case, break them up. Sounds to me like your problems with refactoring and indention in python could be do to these kinds of design issues. Having curly braces certainly doesn't help in these situations either. More than once I've had C code I was refactoring that broke due to the fact that while trying to move blocks around I misplaced a brace, an issue I never have in Python. In the meantime, whitespace structure is one of the things about Python that I like the *most* about the language. Being able to crank out executable pseudo-code is pretty addictive. And I never write pseudo-code on paper with begin and end blocks cause it's too much effort when scribbling by hand. From steve-REMOVE-THIS at cybersource.com.au Wed Nov 3 19:20:30 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 03 Nov 2010 23:20:30 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> On Wed, 03 Nov 2010 20:30:43 +0000, Seebs wrote: > I'm not expecting it to change; Then why talk about it? Just to hear the sound of your voice? (Or see the font of your writing?) To waste our time? To feel more virtuous than those who don't see your point of view? If you don't expect a change, what's the point of this discussion? > I'm pointing out that insisting that it's not a problem is > *insulting* to the people for whom it is a problem. And insisting that it is a problem is equally insulting to those for whom it is not a problem. -- Steven From rhodri at wildebst.demon.co.uk Wed Nov 3 19:37:07 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 03 Nov 2010 23:37:07 -0000 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, 03 Nov 2010 18:49:06 -0000, Tim Harig wrote: > On 2010-11-03, Steven D'Aprano > wrote: >> On Tue, 02 Nov 2010 19:26:56 +0000, Tim Harig wrote: >> >>> I agree with Seebs, Python is the only language I know that promotes >>> the >>> use of spaces over tabs; >> >> Really? I'm not aware of *any* language that promotes tabs over spaces. >> I >> thought the tabs vs spaces war was mostly won by spaces over a decade >> ago >> (apart from a few plucky freedom fighters who will never surrender). > > Python is the only language that I know that *needs* to specify tabs > versus > spaces since it is the only language I know of which uses whitespace > formating as part of its syntax and structure. Mixed usage may be > annoying > in other languages; but, it breaks Python. I regard this as a strength. I have wasted far too much time at work writing review comments that could be paraphrased as "your broken editor settings have made this (C code) unreadable." -- Rhodri James *-* Wildebeest Herder to the Masses From python.list at tim.thechases.com Wed Nov 3 19:41:42 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 03 Nov 2010 18:41:42 -0500 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4CD1F336.1050703@tim.thechases.com> On 11/03/10 15:59, Seebs wrote: >> Dededenting does explicitly mark the end of a block. > > If you can't point to the token, it's implicit. :) Just because you asked for it to be pointed to: http://svn.python.org/view/python/trunk/Include/token.h?view=markup The DEDENT token is explicitly defined as the number "6", FWIW... :) -tkc From usenet-nospam at seebs.net Wed Nov 3 19:42:55 2010 From: usenet-nospam at seebs.net (Seebs) Date: 03 Nov 2010 23:42:55 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-03, Steven D'Aprano wrote: > On Wed, 03 Nov 2010 20:30:43 +0000, Seebs wrote: >> I'm not expecting it to change; > Then why talk about it? Because I find technical questions interesting in and of themselves. I will happily talk with people about the reasons for which the C preprocessor is the way it is, even though it's never going to change and we all hate it like poison. >> I'm pointing out that insisting that it's not a problem is >> *insulting* to the people for whom it is a problem. > And insisting that it is a problem is equally insulting to those for whom > it is not a problem. No, it isn't. A friend of mine is colorblind. For him, certain red/green pairings are indistinguishable. For me to insist that it is not a problem that a user interface uses those to distinguish two things is insulting to him; I am dismissing a very real problem. For him to insist that it is a problem for him is in no way insulting me. He's not saying that it's a problem for me. He's merely saying that *there exist* people for whom it is a problem. No one has claimed that this is a problem *for everybody*. Just that there exist real-world workflows for which it is a problem, or people for whom it is a problem. This is an asymmetrical situation. The opposite of "it's never a problem for anybody" isn't "it is always a problem for everybody" but "it is at least sometimes a problem for at least some people." The reality is, the indentation-instead-of-markers thing *does* sometimes lead to problems. We could blame it on tools, but the tools could just as easily blame the language for being brittle. Given the degree to which the rest of the world has standardized on not caring how *much* whitespace is between things (though sometimes caring whether or not there's *any* whitespace between them), it seems to me that the odd man out is the one who is creating the burden. Once many file formats exist which don't care how many spaces you use, and many tools have been developed with those file formats in mind, coming up with a new file format which cares how many spaces you use seems a little short-sighted. Demanding that all tools be changed to fit a new paradigm is a pretty big demand to place on people. On the whole, I don't personally think the benefits have been worth it. I think Python would be a better, richer, language if it used explicit end tokens of some sort. Maybe it wouldn't. I do know, though, that of the programmers I know outside the Python newsgroup, not a single one likes that aspect of Python. It is consistently regarded as an annoying quirk. Some use Python anyway; it has merits, certainly. If I were offered a choice between Python and PHP for a project, I would *absolutely* pick Python. (Subject, of course, to the assumption that the project would in some way involve computers, or programming, or that I would at some point have to either write code for the project use it, or possibly come within twenty feet of someone who was working on it; outside of those limitations, I might consider PHP.) I feel the same way about pretty much every language I use. C would be a much better language if the macro processor weren't such a giant filesystem verification stage for a filesystem distributed across multiple machines*. They all have flaws. Python's the only language I use where an obvious flaw, which is repeatedly observed by everyone I know who uses the language, is militantly and stridently defended by dismissing, insulting, and attacking the character and motives of anyone who suggests that it might be a bit of a nuisance. I suspect part of that is simply because it *is* a tradeoff, and there are good reasons for it. It offers some advantages. It's not something that you'd be insane to like; the problems are easily mitigated once you know about them, and the benefits are worth it. If I worked with a lot more novice-level C programmers who hadn't yet had the importance of careful style drilled into them, I might well find the indentation problems people keep talking about to be a real thing, possibly even a very serious one. But the fact remains, being brittle in the face of whitespace changes *is* a flaw. It breaks code under circumstances which are, for better or worse, common. As I pointed out before: There is a *REASON* that diff has an option for ignoring whitespace changes -- because they are common enough that such an option is commonly useful for distinguishing between real changes and inadvertant ones. Note that "whitespace indentation" in and of itself isn't the thing I'm describing as a flaw; it's the side-effect of being brittle when whitespace changes. The indentation thing as a whole has some definite plusses, and it's a tradeoff that I think may even be a good fit for a language specifically focused on easier readability. -s [*] clusterfsck. -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From ben+python at benfinney.id.au Wed Nov 3 19:53:40 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 04 Nov 2010 10:53:40 +1100 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87sjzige0r.fsf@benfinney.id.au> Seebs writes: > On 2010-11-03, Steven D'Aprano wrote: > > Python does explicitly mark blocks. It does it by changes in > > indentation. An indent is an explicit start-block. An outdent is an > > explicit end- block. There is nothing implicit in a change in indent > > level. > > What's the token that marks the end of a block, corresponding to the > colon used to introduce it? You have introduced this requirement for tokens; it's fallacious. The direct answer is: tokens aren't part of the requirement to be explicit. The more general answer is: the block is explicitly ended where the indentation ends. -- \ ?I must say that I find television very educational. The minute | `\ somebody turns it on, I go to the library and read a book.? | _o__) ?Groucho Marx | Ben Finney From ben+python at benfinney.id.au Wed Nov 3 19:55:14 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 04 Nov 2010 10:55:14 +1100 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1c0a6$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87oca6gdy5.fsf@benfinney.id.au> Seebs writes: > Furthermore, I don't WANT to skip closing braces. EXPLICIT IS BETTER > THAN IMPLICIT. I *WANT* to have the beginnings and ends marked. Python doesn't require that. You're going to be disappointed by most Python code if that's what you want. Which is not a failing of Python. -- \ ?Few things are harder to put up with than the annoyance of a | `\ good example.? ?Mark Twain, _Pudd'n'head Wilson_ | _o__) | Ben Finney From brf256 at gmail.com Wed Nov 3 19:58:10 2010 From: brf256 at gmail.com (brf256 at gmail.com) Date: Wed, 3 Nov 2010 23:58:10 +0000 Subject: What people are using to access this mailing list Message-ID: <1709014163-1288828693-cardhu_decombobulator_blackberry.rim.net-882162190-@bda480.bisx.prod.on.blackberry> I use my blackberry to access the list. - Braden Faulkner Sent wirelessly from my BlackBerry device on the Bell network. Envoy? sans fil par mon terminal mobile BlackBerry sur le r?seau de Bell. From roy at panix.com Wed Nov 3 19:59:05 2010 From: roy at panix.com (Roy Smith) Date: Wed, 03 Nov 2010 19:59:05 -0400 Subject: Subclassing unittest.TestCase? References: Message-ID: In article , Peter Otten <__peter__ at web.de> wrote: > Remove the base class from the module with > > del CommonTestCase > > before you invoke unittest.main(). Wow, what a clever idea! I tried it, and it does exactly what I need. Thanks! From usenet-nospam at seebs.net Wed Nov 3 20:00:04 2010 From: usenet-nospam at seebs.net (Seebs) Date: 04 Nov 2010 00:00:04 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1c0a6$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-03, Michael Torrie wrote: > I suggest, then that Pascal or Ruby would suit your needs better than > Python. In the absence of network effects, I'd just be using Ruby. I have reason to work with projects that have a lot of existing Python, though, so I use it too. > As for refactoring code, vim makes it really easy to move blocks in and > out. Yes, though I mostly use nvi, same thing -- basically. The issue I've had is that the automatic-tab thing (which I actively want for everything else I edit) tends to make it quirky. > The only time I could see this becoming an issue is if functions > or blocks of code are too long to see on a page at once. If this is the > case, break them up. Sounds to me like your problems with refactoring > and indention in python could be do to these kinds of design issues. > Having curly braces certainly doesn't help in these situations either. > More than once I've had C code I was refactoring that broke due to the > fact that while trying to move blocks around I misplaced a brace, an > issue I never have in Python. For me, I'd rather have the compiler choke because I have mismatched braces than have the code run apparently just fine except that something has unintentionally moved in or out of an else clause because there was no marker. I've had both happen, probably. > In the meantime, whitespace structure is one of the things about Python > that I like the *most* about the language. Being able to crank out > executable pseudo-code is pretty addictive. And I never write > pseudo-code on paper with begin and end blocks cause it's too much > effort when scribbling by hand. I never write on paper anyway. :) Anyway, I'm not disputing that there are things that it makes nicer. I'm just observing that there exists a category of failures which is completely unique to Python, which no other language (except BF, which I'm not sure I ought to count) has, which tends to show up occasionally until you've gotten all the changed tools and habits, and even then can show up when dealing with other people who use tools which, well, work perfectly for everything else. But not for this. Only other tool I know with a comparable dependance on spacing is Makefiles, and I have never in my life met someone who used them and didn't think that was a loathesome error which should never have made it into production code. Python's not nearly as bad, actually. :) -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From ldo at geek-central.gen.new_zealand Wed Nov 3 20:01:34 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 04 Nov 2010 13:01:34 +1300 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <8j8udgFlkvU1@mid.individual.net> Message-ID: In message , Seebs wrote: > The question is *why* diff has that option. > > The answer is because whitespace changes (spaces to tabs, different > tab stops, etcetera) are an extremely common failure mode, such that > it's quite common for files to end up with unintentional whitespace > changes. Except the diff option is to *ignore* such differences, not highlight them. From ldo at geek-central.gen.new_zealand Wed Nov 3 20:04:00 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 04 Nov 2010 13:04 +1300 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: In message , Seebs wrote: > It is extremely useful to me to have spaces converted to tabs > for every other file I edit. I?m thinking of going the other way. After many years of treating tabs as four-column steps, I might give up on them and use spaces everywhere. From emile at fenx.com Wed Nov 3 20:07:12 2010 From: emile at fenx.com (Emile van Sebille) Date: Wed, 03 Nov 2010 17:07:12 -0700 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 11/3/2010 4:09 PM Seebs said... > What's the token that marks the end of a block, corresponding to the > colon used to introduce it? > My thoughts tend more towards 'can we get Guido to eliminate the colon requirements' -- The indent level of the next line ought to suffice. Seriously. Emile From ldo at geek-central.gen.new_zealand Wed Nov 3 20:09:08 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 04 Nov 2010 13:09:08 +1300 Subject: Python documentation too difficult for beginners References: Message-ID: In message , Cameron Simpson wrote: > But its weakness is stuff like this: > > http://epydoc.sourceforge.net/stdlib/Canvas.Polygon-class.html > > Automatic docness, no useful information. But it Conforms to Documentation-Production Metrics as decreed by the Corporate Task Force on Policy. So long as the divisions are satisfying the official metrics on documentation production, that must mean the project is meeting its goals. From ldo at geek-central.gen.new_zealand Wed Nov 3 20:10:43 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 04 Nov 2010 13:10:43 +1300 Subject: Man pages and info pages References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> <024ef21a-9ef9-48a6-8372-1d66895583c3@v16g2000yqn.googlegroups.com> <87zktr5yze.fsf_-_@mithlond.arda> <877hgv2fg3.fsf@mithlond.arda> <87hbfyn3uo.fsf@xemacs.org> <1bdce24e-4406-44c5-9133-bfd0acd0283d@p1g2000yqm.googlegroups.com> Message-ID: In message <1bdce24e-4406-44c5-9133-bfd0acd0283d at p1g2000yqm.googlegroups.com>, rustom wrote: > The printed python docs come to several thousand pages. Do we want them > to be 1 manpage? a hundred? a thousand? Perl managed to condense a lot of useful information into a handful of man pages. From usenet-nospam at seebs.net Wed Nov 3 20:12:53 2010 From: usenet-nospam at seebs.net (Seebs) Date: 04 Nov 2010 00:12:53 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <8j8udgFlkvU1@mid.individual.net> Message-ID: On 2010-11-04, Lawrence D'Oliveiro wrote: > In message , Seebs wrote: >> The answer is because whitespace changes (spaces to tabs, different >> tab stops, etcetera) are an extremely common failure mode, such that >> it's quite common for files to end up with unintentional whitespace >> changes. > Except the diff option is to *ignore* such differences, not highlight them. Yes. That's because those changes are irrelevant, so people don't care about them, so they want an option to handle the common case where whitespace got changed but no one cares about that. But unintentional whitespace changes are common enough that you *need* the ability to filter them out and just look at "real" changes. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Wed Nov 3 20:13:44 2010 From: usenet-nospam at seebs.net (Seebs) Date: 04 Nov 2010 00:13:44 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: On 2010-11-04, Lawrence D'Oliveiro wrote: > In message , Seebs wrote: >> It is extremely useful to me to have spaces converted to tabs >> for every other file I edit. > I???m thinking of going the other way. After many years of treating tabs as > four-column steps, I might give up on them and use spaces everywhere. I *absolutely must* use tabs for Makefiles. For code in most other languages, it's merely a factor of 8 improvement in storage. :) -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From aahz at pythoncraft.com Wed Nov 3 21:13:40 2010 From: aahz at pythoncraft.com (Aahz) Date: 3 Nov 2010 18:13:40 -0700 Subject: What people are using to access this mailing list References: <87r5f2wr7t.fsf@rudin.co.uk> Message-ID: In article , Grant Edwards wrote: >On 2010-11-03, Paul Rudin wrote: >> John Bond writes: >>> On 3/11/2010 11:17 AM, Steven D'Aprano wrote: >>>> On Wed, 03 Nov 2010 08:02:29 +0000, John Bond wrote: >>>> >>>>> Hope this isn't too O/T - I was just wondering how people read/send to >>>>> this mailing list, eg. normal email client, gmane, some other software >>>>> or online service? >>>> Usenet via my ISP, on comp.lang.python. >>>> >>> Using what client (or web client)? >> >> Emacs, of course :-; > >Slrn, of course. trn3.6, of course. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." --Red Adair From brf256 at gmail.com Wed Nov 3 21:19:42 2010 From: brf256 at gmail.com (braden faulkner) Date: Wed, 3 Nov 2010 21:19:42 -0400 Subject: Best method for a menu in a command line program? Message-ID: I'm using a menu for my command line app using this method. choice = "foobar" while choice != "q": if choice == "c": temp = input("Celsius temperature:") print "Fahrenheit:",celsius_to_fahrenheit(temp) elif choice == "f": temp = input("Fahrenheit temperature:") print "Celsius:",fahrenheit_to_celsius(temp) elif choice != "q": print_options() choice = raw_input("option:") Just wondering if there is another or more efficient way I should be doing it? Thanks -- Braden Faulkner From email at invalid.net Wed Nov 3 21:37:10 2010 From: email at invalid.net (QoS) Date: Thu, 04 Nov 2010 01:37:10 GMT Subject: What people are using to access this mailing list References: Message-ID: Jed Smith wrote in message-id: > > On Wed, Nov 3, 2010 at 4:02 AM, John Bond wrote: > > My normal inbox is getting unmanageable, and I think I need to find a new way > > of following this and other lists. > > I have to second (or third) the Gmail suggestion. I use Google Apps > against my domain, and the Gmail interface is frightfully good at > creating filters. For example, on most lists (particularly Mailman), I > can hit "Filter messages like this", and Gmail automatically harvests > the List header and writes a filter for it. > > I just prefer the Gmail philosophy to mail, with tags that are *like* > folders but not really. > If that is what you used to post this reply then your client is broken somewhat. Your client did not post using a well-formed references header and so your post may/should not be grouped properly with the OP. Here is what your client determined the references to be, you will se it has no reference to the original posting. References: Below is a reply from someone using a well crafted client, this reply is certain to be organized by other clients in the same thread: References: <87r5f2wr7t.fsf at rudin.co.uk> Hth J From gnarlodious at gmail.com Wed Nov 3 21:38:14 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Wed, 3 Nov 2010 18:38:14 -0700 (PDT) Subject: Py3: Import relative path module References: <044f2fb7-a6a9-4bb9-b2a6-8ee1d0c19612@u17g2000yqi.googlegroups.com> <4cce7768$0$29965$c3e8da3$5496439d@news.astraweb.com> <770dd3de-25f5-404c-a05a-7bdd2eb07179@26g2000yqv.googlegroups.com> <3e7dbd88-4d44-43fa-a0e2-6987c025ccdb@26g2000yqv.googlegroups.com> <01c6e36a-c4e0-499a-adc1-cb61d7b53725@r14g2000yqa.googlegroups.com> Message-ID: <102a52fc-13be-4557-8ee0-279cc2c2ea3e@w38g2000pri.googlegroups.com> > Peter Otten wrote: > |-- alpha > | ? |-- __init__.py > | ? |-- beta > | ? | ? |-- __init__.py > | ? | ? `-- one.py > | ? `-- two.py > `-- main.py > > 2 directories, 5 files > $ cat main.py > import alpha.beta.one > $ cat alpha/beta/one.py > from ..alpha import two > $ cat alpha/two.py > print "success!" > $ python main.py > success! Thank you for that example, it works for me. However, what I want to do is go UP one folder to import the module(s) in some library: python main.py import ..alpha.beta.one ^ SyntaxError: invalid syntax python main.py from .. import alpha.beta.one ^ SyntaxError: invalid syntax So how to specify a relative path? -- Gnarlie From email at invalid.net Wed Nov 3 21:39:42 2010 From: email at invalid.net (QoS) Date: Thu, 04 Nov 2010 01:39:42 GMT Subject: What people are using to access this mailing list References: Message-ID: Jed Smith wrote in message-id: > > On Wed, Nov 3, 2010 at 4:02 AM, John Bond wrote: > > My normal inbox is getting unmanageable, and I think I need to find a new way > > of following this and other lists. > > I have to second (or third) the Gmail suggestion. I use Google Apps > against my domain, and the Gmail interface is frightfully good at > creating filters. For example, on most lists (particularly Mailman), I > can hit "Filter messages like this", and Gmail automatically harvests > the List header and writes a filter for it. > > I just prefer the Gmail philosophy to mail, with tags that are *like* > folders but not really. > If that is what you used to post this reply then your client is broken somewhat. Your client did not post using a well-formed references header and so your post may/should not be grouped properly with the OP. Here is what your client determined the references to be, you will se it has no reference to the original posting. References: Below is a reply from someone using a well crafted client, this reply is certain to be organized by other clients in the same thread: References: <87r5f2wr7t.fsf at rudin.co.uk> Hth J From email at invalid.net Wed Nov 3 21:40:39 2010 From: email at invalid.net (QoS) Date: Thu, 04 Nov 2010 01:40:39 GMT Subject: What people are using to access this mailing list References: Message-ID: Jed Smith wrote in message-id: > > On Wed, Nov 3, 2010 at 4:02 AM, John Bond wrote: > > My normal inbox is getting unmanageable, and I think I need to find a new way > > of following this and other lists. > > I have to second (or third) the Gmail suggestion. I use Google Apps > against my domain, and the Gmail interface is frightfully good at > creating filters. For example, on most lists (particularly Mailman), I > can hit "Filter messages like this", and Gmail automatically harvests > the List header and writes a filter for it. > > I just prefer the Gmail philosophy to mail, with tags that are *like* > folders but not really. > If that is what you used to post this reply then your client is broken somewhat. Your client did not post using a well-formed references header and so your post may/should not be grouped properly with the OP. Here is what your client determined the references to be, you will se it has no reference to the original posting. References: Below is a reply from someone using a well crafted client, this reply is certain to be organized by other clients in the same thread: References: <87r5f2wr7t.fsf at rudin.co.uk> Hth J From email at invalid.net Wed Nov 3 21:41:13 2010 From: email at invalid.net (QoS) Date: Thu, 04 Nov 2010 01:41:13 GMT Subject: What people are using to access this mailing list References: Message-ID: Jed Smith wrote in message-id: > > On Wed, Nov 3, 2010 at 4:02 AM, John Bond wrote: > > My normal inbox is getting unmanageable, and I think I need to find a new way > > of following this and other lists. > > I have to second (or third) the Gmail suggestion. I use Google Apps > against my domain, and the Gmail interface is frightfully good at > creating filters. For example, on most lists (particularly Mailman), I > can hit "Filter messages like this", and Gmail automatically harvests > the List header and writes a filter for it. > > I just prefer the Gmail philosophy to mail, with tags that are *like* > folders but not really. > If that is what you used to post this reply then your client is broken somewhat. Your client did not post using a well-formed references header and so your post may/should not be grouped properly with the OP. Here is what your client determined the references to be, you will se it has no reference to the original posting. References: Below is a reply from someone using a well crafted client, this reply is certain to be organized by other clients in the same thread: References: <87r5f2wr7t.fsf at rudin.co.uk> Hth J From email at invalid.net Wed Nov 3 21:41:53 2010 From: email at invalid.net (QoS) Date: Thu, 04 Nov 2010 01:41:53 GMT Subject: What people are using to access this mailing list References: Message-ID: Jed Smith wrote in message-id: > > On Wed, Nov 3, 2010 at 4:02 AM, John Bond wrote: > > My normal inbox is getting unmanageable, and I think I need to find a new way > > of following this and other lists. > > I have to second (or third) the Gmail suggestion. I use Google Apps > against my domain, and the Gmail interface is frightfully good at > creating filters. For example, on most lists (particularly Mailman), I > can hit "Filter messages like this", and Gmail automatically harvests > the List header and writes a filter for it. > > I just prefer the Gmail philosophy to mail, with tags that are *like* > folders but not really. > If that is what you used to post this reply then your client is broken somewhat. Your client did not post using a well-formed references header and so your post may/should not be grouped properly with the OP. Here is what your client determined the references to be, you will se it has no reference to the original posting. References: Below is a reply from someone using a well crafted client, this reply is certain to be organized by other clients in the same thread: References: <87r5f2wr7t.fsf at rudin.co.uk> Hth J From email at invalid.net Wed Nov 3 21:49:43 2010 From: email at invalid.net (QoS) Date: Thu, 04 Nov 2010 01:49:43 GMT Subject: What people are using to access this mailing list References: Message-ID: Jed Smith wrote in message-id: > > On Wed, Nov 3, 2010 at 4:02 AM, John Bond wrote: > > My normal inbox is getting unmanageable, and I think I need to find a new way > > of following this and other lists. > > I have to second (or third) the Gmail suggestion. I use Google Apps > against my domain, and the Gmail interface is frightfully good at > creating filters. For example, on most lists (particularly Mailman), I > can hit "Filter messages like this", and Gmail automatically harvests > the List header and writes a filter for it. > > I just prefer the Gmail philosophy to mail, with tags that are *like* > folders but not really. > Just in case the client may not display the headers, fyi: If gmail is what you used to post this reply then your client is broken somewhat. Your client did not post using a well-formed references header and so your post may/should not be grouped properly with the OP. Here is what your client determined the references to be, you will se it has no reference to the original posting. References: Below is a reply from someone using a well crafted client, this reply is certain to be organized by other clients in the same thread: References: <87r5f2wr7t.fsf at rudin.co.uk> Hth J From rantingrick at gmail.com Wed Nov 3 22:03:33 2010 From: rantingrick at gmail.com (rantingrick) Date: Wed, 3 Nov 2010 19:03:33 -0700 (PDT) Subject: Best method for a menu in a command line program? References: Message-ID: <8d21da84-66b8-4e87-a1a6-100069aad62c@f33g2000yqh.googlegroups.com> On Nov 3, 8:19?pm, braden faulkner wrote: > Just wondering if there is another or more efficient way I should be doing it? I would move the input inside the respective methods or functions, short of that, what is more efficient than a conditional... nothing, and it reads very intuitively. Sure you could throw all the funcs into a dict and it may clean up a long winded conditional, however then you have to make a trade. So Zero Sum at that point. From ben+python at benfinney.id.au Wed Nov 3 22:03:47 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 04 Nov 2010 13:03:47 +1100 Subject: Best method for a menu in a command line program? References: Message-ID: <87fwvhhmkc.fsf@benfinney.id.au> braden faulkner writes: > I'm using a menu for my command line app using this method. > > choice = "foobar" The default choice for a ?nothing here yet? value is the built-in ?None?. Sometimes that's not the right choice; but if you have no particular reaason in a specific program to avoid ?None? for that purpose, use it. > while choice != "q": > if choice == "c": > temp = input("Celsius temperature:") > print "Fahrenheit:",celsius_to_fahrenheit(temp) > elif choice == "f": > temp = input("Fahrenheit temperature:") > print "Celsius:",fahrenheit_to_celsius(temp) > elif choice != "q": > print_options() > choice = raw_input("option:") Python lacks a ?case? statement. But it does have functions as first-class objects; you can treat functions as data. So your approach above, with a chain of if-elif-elif clauses, is best replaced by a dispatch dictionary into functions specific to each command. Here's my attempt at making it more Pythonic and maintainable:: #! /usr/bin/python # -*- coding: utf-8 -*- import sys import textwrap def print_commands(): commands_display = ", ".join(commands.keys()) sys.stdout.write(textwrap.dedent("""\ Valid commands are: %(commands_display)s. """) % vars()) def quit(): raise SystemExit() def celsius_to_fahrenheit(in_value): return ((in_value * (9.0/5) + 32.0)) def fahrenheit_to_celsius(in_value): return ((in_value - 32.0) * (5.0/9)) def prompt_and_convert_temperature(labels, conversion_func): (from_label, to_label) = labels input = float(raw_input("%(from_label)s: " % vars())) result = conversion_func(input) sys.stdout.write("%(to_label)s temperature: %(result)0.2f\n" % vars()) commands = { 'q': (lambda: quit()), 'c': (lambda: prompt_and_convert_temperature( ["Celsius", "Fahrenheit"], celsius_to_fahrenheit)), 'f': (lambda: prompt_and_convert_temperature( ["Fahrenheit", "Celsius"], fahrenheit_to_celsius)), } if __name__ == '__main__': choice = None while choice is None: choice = raw_input("Command: ") if choice in commands: commands[choice]() else: choice = None print_commands() -- \ ?I am as agnostic about God as I am about fairies and the | `\ Flying Spaghetti Monster.? ?Richard Dawkins, 2006-10-13 | _o__) | Ben Finney From python at mrabarnett.plus.com Wed Nov 3 22:13:25 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 04 Nov 2010 02:13:25 +0000 Subject: Best method for a menu in a command line program? In-Reply-To: References: Message-ID: <4CD216C5.1080704@mrabarnett.plus.com> On 04/11/2010 01:19, braden faulkner wrote: > I'm using a menu for my command line app using this method. > > choice = "foobar" > while choice != "q": > if choice == "c": > temp = input("Celsius temperature:") > print "Fahrenheit:",celsius_to_fahrenheit(temp) > elif choice == "f": > temp = input("Fahrenheit temperature:") > print "Celsius:",fahrenheit_to_celsius(temp) > elif choice != "q": > print_options() > choice = raw_input("option:") > > Just wondering if there is another or more efficient way I should be doing it? > Here's an alternative: def option_c(): temp = input("Celsius temperature:") print "Fahrenheit:", celsius_to_fahrenheit(temp) def option_f(): temp = input("Fahrenheit temperature:") print "Celsius:", fahrenheit_to_celsius(temp) options = {"c": option_c, "f": option_f} while True: choice = raw_input("option:") if choice == "q": break options.get(choice, print_options)() From usernet at ilthio.net Wed Nov 3 22:19:23 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 4 Nov 2010 02:19:23 +0000 (UTC) Subject: Best method for a menu in a command line program? References: Message-ID: On 2010-11-04, braden faulkner wrote: > I'm using a menu for my command line app using this method. > > choice = "foobar" > while choice != "q": > if choice == "c": > temp = input("Celsius temperature:") > print "Fahrenheit:",celsius_to_fahrenheit(temp) > elif choice == "f": > temp = input("Fahrenheit temperature:") > print "Celsius:",fahrenheit_to_celsius(temp) > elif choice != "q": > print_options() > choice = raw_input("option:") > > Just wondering if there is another or more efficient way I should be doing it? You are looking for a dictionary with function references maybe? menu_options = { 'c':io_celsius_to_fahrenheit, 'f':io_fahrenheit_to_celsisus, 'q':print_options } The io versions of the functions would wrap the conversion functions to get the input and print the output. choice = "foobar" while choice != 'q': try: menu_options[choice]() except KeyError: # else code here choice = raw_input("option:") From invalid at invalid.invalid Wed Nov 3 22:20:26 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 4 Nov 2010 02:20:26 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-04, Emile van Sebille wrote: > On 11/3/2010 4:09 PM Seebs said... > >> What's the token that marks the end of a block, corresponding to the >> colon used to introduce it? >> > > > My thoughts tend more towards 'can we get Guido to eliminate the colon > requirements' -- The indent level of the next line ought to suffice. But without the colon, how are people who write programming editors going to know when to increase the indentation level as I enter code? > Seriously. Just as seriously. Syntactic sugar isn't just for humans... -- Grant From invalid at invalid.invalid Wed Nov 3 22:25:04 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 4 Nov 2010 02:25:04 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> Message-ID: On 2010-11-04, Seebs wrote: > On 2010-11-04, Lawrence D'Oliveiro wrote: >> In message , Seebs wrote: >>> It is extremely useful to me to have spaces converted to tabs >>> for every other file I edit. > >> I???m thinking of going the other way. After many years of treating tabs as >> four-column steps, I might give up on them and use spaces everywhere. I quit using tabs (except for Makefiles) about 30 years ago. > I *absolutely must* use tabs for Makefiles. And my editor (emacs) knows that. It uses tabs in Makefiles and spaces everywhere else. > For code in most other languages, it's merely a factor of 8 improvement > in storage. :) That's only true if your source code consists entirely of tabs. ;) -- Grant From brf256 at gmail.com Wed Nov 3 22:25:49 2010 From: brf256 at gmail.com (brf256 at gmail.com) Date: Thu, 4 Nov 2010 02:25:49 +0000 Subject: Best method for a menu in a command line program? Message-ID: <1976176960-1288837552-cardhu_decombobulator_blackberry.rim.net-370756585-@bda480.bisx.prod.on.blackberry> Thanks for the help! Ill incorporate this into my menu. Thanks again, Braden Faulkner Sent wirelessly from my BlackBerry device on the Bell network. Envoy? sans fil par mon terminal mobile BlackBerry sur le r?seau de Bell. From python.list at tim.thechases.com Wed Nov 3 22:26:30 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 03 Nov 2010 21:26:30 -0500 Subject: What people are using to access this mailing list In-Reply-To: References: Message-ID: <4CD219D6.1020702@tim.thechases.com> On 11/03/10 20:41, QoS wrote: > Jed Smith wrote >> I just prefer the Gmail philosophy to mail, with tags that are *like* >> folders but not really. > > If that is what you used to post this reply then your client is broken somewhat. I'm not sure I'd go casting aspersions on other peoples broken-clients when your own client seems to have sent 6 nearly-identical copies of the same message to the newsgroup. None of which appeared (at least in Thunderbird-as-NNTP-reader) as followups to Jed's message, but rather as follow-ups to the OP's initial post. -tkc From invalid at invalid.invalid Wed Nov 3 22:27:06 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 4 Nov 2010 02:27:06 +0000 (UTC) Subject: What people are using to access this mailing list References: Message-ID: On 2010-11-04, QoS wrote: > Jed Smith wrote in message-id: >> I just prefer the Gmail philosophy to mail, with tags that are *like* >> folders but not really. > > Just in case the client may not display the headers, fyi: > > If gmail is what you used to post this reply then your client is > broken somewhat. > > Your client did not post using a well-formed references header and so > your post may/should not be grouped properly with the OP. I prefer that over posting 8 duplicate messages like your client did. :) -- Grant From gnarlodious at gmail.com Wed Nov 3 22:48:35 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Wed, 3 Nov 2010 19:48:35 -0700 (PDT) Subject: Py3: Import relative path module References: <044f2fb7-a6a9-4bb9-b2a6-8ee1d0c19612@u17g2000yqi.googlegroups.com> <4cce7768$0$29965$c3e8da3$5496439d@news.astraweb.com> <770dd3de-25f5-404c-a05a-7bdd2eb07179@26g2000yqv.googlegroups.com> <3e7dbd88-4d44-43fa-a0e2-6987c025ccdb@26g2000yqv.googlegroups.com> <01c6e36a-c4e0-499a-adc1-cb61d7b53725@r14g2000yqa.googlegroups.com> <102a52fc-13be-4557-8ee0-279cc2c2ea3e@w38g2000pri.googlegroups.com> Message-ID: <1b4f9e09-b28a-47c1-b31b-0e0bf53165b2@m20g2000prc.googlegroups.com> OK I've had a modicum of success! However I was forced to add the path to my application folder to sys.path, which I suppose is the closest I can get to what I want. The example given then works in the shell. Apache is another problem. I added the same path to the script then Apache finds the application folder and does the importing. Not an ideal solution, but workable. I hope Apache3 in the future has more smarts about importing relative filepaths. Thank you Peter for your patience on this! -- Rachel http://google.com/profiles/Gnarlodious From calderone.jeanpaul at gmail.com Wed Nov 3 23:00:00 2010 From: calderone.jeanpaul at gmail.com (Jean-Paul Calderone) Date: Wed, 3 Nov 2010 20:00:00 -0700 (PDT) Subject: pyOpenSSL 0.11 released References: Message-ID: <3ae55264-4605-443d-9007-f913c7e292c5@s4g2000yql.googlegroups.com> On Nov 1, 6:43?pm, exar... at twistedmatrix.com wrote: > Hello all, > > I'm happy to announce the release of pyOpenSSL 0.11. ?The primary change > from the last release is that Python 3.2 is now supported. ?Python 2.4 > through Python 2.7 are still supported as well. ?This release also fixes > a handful of bugs in error handling code. ?It also adds APIs for > generating and verifying cryptographic signatures and it improves the > test suite to cover nearly 80% of the implementation. > > Downloads and more details about the release can be found on the release > page: > > ? ?https://launchpad.net/pyopenssl/main/0.11 > It was helpfully pointed out to me that I forgot to mention that the Python 3.2 support in this release of pyOpenSSL was made possible by a grant from the Python Software Foundation. > Enjoy, > Jean-Paul From pavlovevidence at gmail.com Wed Nov 3 23:02:59 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 3 Nov 2010 20:02:59 -0700 (PDT) Subject: Best method for a menu in a command line program? References: Message-ID: <18f366c3-2dc2-4231-89f4-3af433b161f4@r14g2000yqa.googlegroups.com> On Nov 3, 6:19?pm, braden faulkner wrote: > I'm using a menu for my command line app using this method. > > choice = "foobar" > while choice != "q": > ? ? if choice == "c": > ? ? ? ? temp = input("Celsius temperature:") > ? ? ? ? print "Fahrenheit:",celsius_to_fahrenheit(temp) > ? ? elif choice == "f": > ? ? ? ? temp = input("Fahrenheit temperature:") > ? ? ? ? print "Celsius:",fahrenheit_to_celsius(temp) > ? ? elif choice != "q": > ? ? ? ? print_options() > ? ? choice = raw_input("option:") > > Just wondering if there is another or more efficient way I should be doing it? You're not even close to the point where you have to start worrying about efficiency. If you're at a point where efficiency matters, then by that point you should have long ago refactored it into a function-call dispatch (which is what others have posted) for the sake of organizing code. For this program, what you have it fine. Carl Banks From ben+python at benfinney.id.au Wed Nov 3 23:06:20 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 04 Nov 2010 14:06:20 +1100 Subject: Best method for a menu in a command line program? References: <87fwvhhmkc.fsf@benfinney.id.au> Message-ID: <8762wdhjo3.fsf@benfinney.id.au> Ben Finney writes: > Here's my attempt at making it more Pythonic and maintainable:: [?] > def celsius_to_fahrenheit(in_value): > return ((in_value * (9.0/5) + 32.0)) Hmm. I went a bit overboard with the parens. This is what I'd prefer:: def celsius_to_fahrenheit(in_value): return (in_value * (9.0/5) + 32.0) -- \ ?There's a certain part of the contented majority who love | `\ anybody who is worth a billion dollars.? ?John Kenneth | _o__) Galbraith, 1992-05-23 | Ben Finney From jerradgenson at gmail.com Wed Nov 3 23:36:42 2010 From: jerradgenson at gmail.com (Jerrad Genson) Date: Wed, 3 Nov 2010 20:36:42 -0700 (PDT) Subject: Possible bug in multiprocessing.Queue() on Ubuntu Message-ID: Hello, While working with the multiprocessing module in Python 2.6.6 on Ubuntu 10.10 64-bit, the following exception was raised: >>> import multiprocessing >>> input_queue = multiprocessing.Queue() Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.6/multiprocessing/__init__.py", line 213, in Queue return Queue(maxsize) File "/usr/lib/python2.6/multiprocessing/queues.py", line 37, in __init__ self._rlock = Lock() File "/usr/lib/python2.6/multiprocessing/synchronize.py", line 117, in __init__ SemLock.__init__(self, SEMAPHORE, 1, 1) File "/usr/lib/python2.6/multiprocessing/synchronize.py", line 49, in __init__ sl = self._semlock = _multiprocessing.SemLock(kind, value, maxvalue) OSError: [Errno 30] Read-only file system The same exception was also raised in Python 3.1.2 on the same platform: >>> import multiprocessing >>> input_queue = multiprocessing.Queue() Traceback (most recent call last): File "", line 1, in File "/usr/lib/python3.1/multiprocessing/__init__.py", line 212, in Queue return Queue(maxsize) File "/usr/lib/python3.1/multiprocessing/queues.py", line 37, in __init__ self._rlock = Lock() File "/usr/lib/python3.1/multiprocessing/synchronize.py", line 121, in __init__ SemLock.__init__(self, SEMAPHORE, 1, 1) File "/usr/lib/python3.1/multiprocessing/synchronize.py", line 49, in __init__ sl = self._semlock = _multiprocessing.SemLock(kind, value, maxvalue) OSError: [Errno 30] Read-only file system This also occurs in Ubuntu 10.04 64-bit, but it works just fine in Ubuntu 10.10 32-bit. Out of curiosity, I downloaded the latest version of the Python 3.2a3+ source from the official Subversion repository, configured it for debugging mode, compiled, and ran the same commands. >>> import multiprocessing [66271 refs] >>> input_queue = multiprocessing.Queue() Traceback (most recent call last): File "/home/jerrad/Development/py3k/Lib/multiprocessing/ synchronize.py", line 28, in from _multiprocessing import SemLock ImportError: cannot import name SemLock During handling of the above exception, another exception occurred: Traceback (most recent call last): File "", line 1, in File "/home/jerrad/Development/py3k/Lib/multiprocessing/ __init__.py", line 212, in Queue from multiprocessing.queues import Queue File "/home/jerrad/Development/py3k/Lib/multiprocessing/queues.py", line 22, in from multiprocessing.synchronize import Lock, BoundedSemaphore, Semaphore, Condition File "/home/jerrad/Development/py3k/Lib/multiprocessing/ synchronize.py", line 33, in " function, see issue 3770.") ImportError: This platform lacks a functioning sem_open implementation, therefore, the required synchronization primitives needed will not function, see issue 3770. [69570 refs] After checking issue 3770 in Roundup, it appears this is a known issue for FreeBSD and OpenBSD, but not for Ubuntu (and it works fine in 32- bit Ubuntu!). I just want to ensure I'm not doing something stupid before I submit this to the issue tracker. From lists at asd-group.com Thu Nov 4 00:24:00 2010 From: lists at asd-group.com (John Bond) Date: Thu, 04 Nov 2010 04:24:00 +0000 Subject: What people are using to access this mailing list In-Reply-To: References: <4cd144cc$0$29966$c3e8da3$5496439d@news.astraweb.com> <87r5f2wr7t.fsf@rudin.co.uk> Message-ID: <4CD23560.9090101@asd-group.com> On 3/11/2010 7:16 PM, Grant Edwards wrote: > The OP could have figured all this out by himself by merely looking at > the headers for a sampling of articles. > > Heck, with about 50 lines of Python, one could probably produced a > fairly comprehensive statistical report on access methods and clients > used by posters to "this mailing list". [An NNTP client module is one > of the "batteries", and that module's docs contains most of the code > needed to access the articles.] > > Finding out the access methods used by people who don't post is > somewhat more difficult. :) > The OP isn't that clever! :o) Cheers, JB From mygogo2011 at gmail.com Thu Nov 4 00:47:43 2010 From: mygogo2011 at gmail.com (PHP.CCC) Date: Wed, 3 Nov 2010 21:47:43 -0700 (PDT) Subject: SCOLAR SHIP FOR USA UNIVERSITY (University of Phoenix ) Message-ID: SCOLAR SHIP FOR USA UNIVERSITY (University of Phoenix ) The campus location in Concord, California is located near Interstate 680 and State Route 242 in Contra Costa County, California. This location offers undergraduate and graduate degree programs that are targeted to meet the needs of students and working adults as well. Read More>>>> http://studyloc.blogspot.com/ From gstepken at googlemail.com Thu Nov 4 02:45:02 2010 From: gstepken at googlemail.com (Guido Stepken) Date: Thu, 04 Nov 2010 07:45:02 +0100 Subject: cms 4 static pages? Message-ID: hi folks! m looking 4 a framework, that allows to build static community software (similar to facebook) without having to start scripts, database connects, admin cookies, e.t.c. means - should be dynamic without really being dynamic, delivering just static pages. (yes, i know e.g. nginx does that by caching, thats not what i want!) features wanted: a not database driven b password access ist done by just renaming users home directory. User at logout will receive new secret subdirectory name 4 new login. c no clientside scripting. changing layout will be done by rebuilding all relevant static pages in user directory once by serverside script. d new entries e.g. mail, discussions will be queued, user just sees: tnx 4 your new article, page will be rebuilt in ... estimated 3 seconds ... or estimated 10 seconds ... depending on load and todo queue length. e load balancing is done by just replicating static pages between servers after new rebuild of static pages. f simulation of received mail directory through just rebuilding relevant static html tree. attachments not allowed. g intelligent todo queue 4 resorting mail sent, received, discussions, look and feel before rebuilding static user pages. (herein lies the intelligence of the whole system) h notifications 4 new mail, messages, e.t.c. are just updates in static html fields. if user gets offline (measured by time since last update of static pages) user will be informed once a day by mail. i simulation of locking can easily be done by dotfiles. j according 2 my calculations such system should be able 2 satisfy any bandwidth without causing significant load of cpu, due 2 low protocol overhead and no server side scripting, no database load. overload of server should not possible by design. k modules, addon 4 twitter e.g., nice 2 have (and no, no java!) any pointers? tnx in advance, Guido Stepken From ldo at geek-central.gen.new_zealand Thu Nov 4 03:07:31 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 04 Nov 2010 20:07:31 +1300 Subject: functions, list, default parameters References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <8ivelpFif1U1@mid.individual.net> <4cca88bc$0$29987$c3e8da3$5496439d@news.astraweb.com> <8j1seqFa1eU2@mid.individual.net> Message-ID: In message , Robert Kern wrote: > On 11/2/10 2:12 AM, Lawrence D'Oliveiro wrote: > >> In message, Robert >> Kern wrote: >> >>> "Immutable objects" are just those without an obvious API for modifying >>> them. >> >> They are ones with NO legal language constructs for modifying them. Hint: >> if a selector of some part of such an object were to occur on the LHS of >> an assignment, and that would raise an error, then the object is >> immutable. The interpreter already knows all this. > > Incorrect. RHS method calls can often modify objects. So bloody what? > Show me the algorithm that the interpreter can use to determine whether or > not an object is mutable. Go look in the code for the one it already uses in places where immutable objects are currently required. >>> With various trickeries, I can mutate any immutable object. >> >> None within the Python language itself. Which is what we?re talking about >> here: a language construct which is probably one of the top 3 sources of >> grief to Python newbies. And not-so-newbies. > > "import ctypes" is within the Python language. And in the old BASIC days, we had ?PEEK? and ?POKE?. So by your reasoning, that invalidated the language rules, too. From arnodel at gmail.com Thu Nov 4 03:15:33 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Thu, 04 Nov 2010 07:15:33 +0000 Subject: Best method for a menu in a command line program? References: <87fwvhhmkc.fsf@benfinney.id.au> Message-ID: <87hbfxk19m.fsf@gmail.com> Ben Finney writes: [...] > commands = { > 'q': (lambda: quit()), > 'c': (lambda: prompt_and_convert_temperature( > ["Celsius", "Fahrenheit"], celsius_to_fahrenheit)), > 'f': (lambda: prompt_and_convert_temperature( > ["Fahrenheit", "Celsius"], fahrenheit_to_celsius)), None: print_commands, > } > > > if __name__ == '__main__': > choice = None > while choice is None: > choice = raw_input("Command: ") commands.get(choice)() -- Arnaud From steve-REMOVE-THIS at cybersource.com.au Thu Nov 4 03:33:14 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 04 Nov 2010 07:33:14 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4cd261ba$0$29972$c3e8da3$5496439d@news.astraweb.com> On Wed, 03 Nov 2010 23:09:10 +0000, Seebs wrote: > On 2010-11-03, Steven D'Aprano > wrote: >> Yes. How does that contradict what I said? > > Once you understand that you do have to break the rules occasionally, it > is a good idea to design things that will be robust when the rules are > broken. That does not follow. As a general rule, one should not expect that electronic equipment should be safe to operate under water. But there are exceptional cases. So what should we do? (1) Insist that all consumer electronic equipment is designed to operate under water? (All blocks need redundant START/END tags just in case you're operating in an environment where indentation can't be trusted.) (2) Tell people not to drop their toaster into the bath tub, and leave it up to the exceptional cases to deal with the need for water-proof electronics in whatever way they see fit? (Trust the indentation, tell people not to mangle their source files with dodgy mail servers, and if you need redundant tags, build your own solution.) >> Ah, argument by misunderstanding the Zen! > > I see. So explicit boundaries are a good thing, except when they are > one specific special case. INDENT/OUTDENT is an explicit boundary. > Let us imagine a hypothetical mirror-universe person, who is otherwise > like you, but: > > 1. Has a goatee. > 2. Actually hates the indentation rules, wishes Python had braces, but > has become emotionally invested in defending the status quo because if > he had to suffer, dammit, everyone else should have to suffer too. I had to suffer? Funny, I hardly noticed. > You have not yet made a single argument that he wouldn't have made too. The arguments Evil-Steven would make would be your arguments: * redundant BEGIN/END tags make blocks robust in environments where indentation can't be trusted; * there are tools out there that assume that indentation is meaningless, and some people want to use those tools, so the language is poorly designed; I *understand* your arguments, I just don't value them. But in fact, non- evil Steven made the opposite arguments: Re extra redundancy: you aren't going to need it often enough to make up for the extra effort of dealing with BEGIN/END tags that can contradict the indentation. Re tools: if the tools don't fit your use-case, your tools are broken, and you should change your tools. >>> It is *better* to explicitly mark the ends of things than to have it >>> be implicit in dropping indentation. That's not a burden, it's good >>> engineering practice. > >> Python does explicitly mark blocks. It does it by changes in >> indentation. An indent is an explicit start-block. An outdent is an >> explicit end- block. There is nothing implicit in a change in indent >> level. > > What's the token that marks the end of a block, corresponding to the > colon used to introduce it? Your assumption is incorrect. Blocks are introduced by an increase in indentation level, not by a colon. The colon is enforced, but it's there for the benefit of readability rather than to mark a new block. You can write: if condition: true_clause() else: false_clause() No blocks are started, the clauses are limited to a single line, but the colons are still required. To end the block, you need a decrease in indentation limit. In fact, the Python parser actually places overt INDENT/OUTDENT tokens into the token stream. # From token.py: INDENT = 5 DEDENT = 6 >> It simply isn't possible to have implicit start/end block markers, >> unless you restrict your language in ways that exclude most blocks. >> E.g. if all if blocks were restricted to a single statement, then you >> could have an implicit block -- the block in one statement. Stating >> that Python uses implicit block markers is simply wrong. > > No, it isn't. There's no token telling you where the block ended. I disagree, but for the sake of the argument let's suppose you are correct. So what? x = 123+456 There's no tokens telling you where the ints 123 and 456 begin and end either. So where's the problem? Signals, or tokens if you like, can be explicitly made either by placing a distinct marker (a delimiter or separator), or by a change of state. In the case of ints, the explicit end-of-token is a change of state, not a marker: digit digit digit non-digit There's no need for a distinct End Of Int marker, because the change of state is explicit enough. But this is not the case for strings, which you mentioned in an earlier post. Strings require a special BEGIN/END tag because they may be terms in expressions and you can't assume they will end at the end of the line (a change of state). If you have an environment where strings do end at the end of the line, such as INI files, you can avoid the delimiters: [section] x = Hello world. y = Goodnight Gracie! but in a general purpose programming language where strings can be terms in expressions, you need delimiters. Blocks are more like ints than strings. They don't need delimiters, because they start and end according to an explicit change of state. -- Steven From steve-REMOVE-THIS at cybersource.com.au Thu Nov 4 03:37:24 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 04 Nov 2010 07:37:24 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> On Wed, 03 Nov 2010 23:42:55 +0000, Seebs wrote: > No one has claimed that this is a problem *for everybody*. Just that > there exist real-world workflows for which it is a problem, or people > for whom it is a problem. And people have suggested that if your workflow leads to indentation being mangled and your source code no longer running, the solution is to change the workflow. If you can't change the workflow, you have my sympathy, but that's not Python's fault, and Python isn't designed for your use-case of web servers that convert your source code to HTML and text editors that mangle indentation. Nor is Python designed for use on computers where the file system randomly corrupts files, or a work-flow where your Pointy-Haired boss keeps making random changes to production scripts in an effort to prove he knows best. If you have such a work-flow, don't suggest that we should add error-correcting codes to the language in order to fix your problem. We can sympathize with your troubles while still saying Not Our Problem. > Given the > degree to which the rest of the world has standardized on not caring how > *much* whitespace is between things (though sometimes caring whether or > not there's *any* whitespace between them), it seems to me that the odd > man out is the one who is creating the burden. What burden? You keep talking about this burden of not-having-to-type- braces, but I don't see any burden, and nor do the majority of Python programmers. What we see is dozens of languages, and thousands of people, who have built all these wonderful devices and tools for helping them carry a refrigerator on their head (a bar fridge, naturally, it would be foolish to carry a full-sized fridge and freezer combo). That's fine if you need to carry a fridge on your head, and I'm really glad that your tools take 90% of the weight for you. I'm sure you hardly even notice it any more. But then you start arguing that it's *really important* to carry a fridge on your head *everywhere* because you never know when you'll be somewhere where you MUST HAVE a fridge, and all hell will break loose if you don't have one, well, we just think you're a bit strange. It's not that we don't think fridges are useful. And we understand the logic -- yes, if you need a fridge and don't have one, bad things will happen, but why limit it to fridges? Why not a sewing machine, and a jack hammer, and a piano, and ... there's no limit to the number of things you might need, and the difference in risk between not having any of them and not having any of them bar one is negligible. And then you start telling us how we're the weird ones because we have the "burden" of not-carrying-a-fridge everywhere! -- Steven From eckhardt at satorlaser.com Thu Nov 4 03:44:01 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Thu, 04 Nov 2010 08:44:01 +0100 Subject: Subclassing unittest.TestCase? References: Message-ID: <1r4aq7-gs.ln1@satorlaser.homedns.org> Roy Smith wrote: > I'm writing a test suite for a web application. There is a subclass of > TestCase for each basic page type. [...] > class CommonTestCase(unittest.TestCase): > def test_copyright(self): > self.assert_(find copyright notice in DOM tree) > > class HomepageTestCase(CommonTestCase): [...] > This works fine as far as HomepageTestCase running test_copyright() and > test_whatever(). The problem is that CommonTestCase *also* runs > test_copyright(), which fails because there's no setUp(), and thus no > retrieved page for it to work on. Rename the function to _test_copyright and then in the derived class either call it or just test_copyrigth = CommonTestCase._test_copyright > Is there a cleaner way to define some common test methods which all of > my test cases can inherit, without having them be run in the base class? I haven't tried it, but you could put the test into a separate baseclass that doesn't derive from unittest.TestCase. All tests that pull a page and need to check for this then add this class to the baseclasses. Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From usenet-nospam at seebs.net Thu Nov 4 04:17:10 2010 From: usenet-nospam at seebs.net (Seebs) Date: 04 Nov 2010 08:17:10 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-04, Steven D'Aprano wrote: > And people have suggested that if your workflow leads to indentation > being mangled and your source code no longer running, the solution is to > change the workflow. Yup. But it strikes me as unmistakably a shortcoming of Python (and Makefiles, for that matter) that code for them can't survive a common failure mode that everything else I use can. > What burden? The burden of using different tools because suddenly the version of vi I've been using since 1990 is magically "broken" even though it's never caused a problem before. > You keep talking about this burden of not-having-to-type- > braces, but I don't see any burden, and nor do the majority of Python > programmers. Of course not. Most of the people who find it annoying *don't use Python*. Of the programmers I know who don't use Python, 100% have cited the annoyance value *to them* of the whitespace thing as the main reason they don't. Of the programmers I know outside this newsgroup who *do* use Python, 100% have said the whitespace thing is annoying and they wish Python didn't have it, but they have to use Python for some externally-imposed reason, so they put up with it. Outside of people who seem to be deeply emotionally invested in insisting that it is never, at all, in ANY way, for ANY person, annoying, it seems to be pretty consistent to observe that, benefits or no benefits, it has some kind of non-zero annoyance value. Other languages I use are mostly amenable to the development of tools to automatically indent code. Makefiles and Python are the only two exceptions... And if I were an advocate for a language, the fact that it's lumped itself in with Makefiles in a significant way would be a weakness I'd feel obliged to be up front about. :) The underlying issue is this: * Not having to type braces: Yay! * Having structure map to functionality: Some people quite like it, and certainly there exists a class of theoretical errors which it prevents. * Not being able to write an auto-indenter, ever, because it is by design theoretically impossible: Annoying. I guess if people could show me some of these errors in other languages where indentation is misleading and bugs resulted, I'd be more persuaded by the second point there. As is, I find the brittleness more annoying than I've ever found braces or 'end' or whatever. It's not annoying enough for me to refuse to use the language when there are other compelling reasons to, but it's certainly annoying enough that I'll never use Python for something where I have unfettered choice of language. It's less fun to program in, for me. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From goodman.m.w at gmail.com Thu Nov 4 04:22:09 2010 From: goodman.m.w at gmail.com (goodman) Date: Thu, 4 Nov 2010 01:22:09 -0700 (PDT) Subject: subprocess.Popen not replacing current process? Message-ID: <0f1a17f4-b6a9-4e89-ac26-74b1098a065e@b19g2000prj.googlegroups.com> Note: Our server is a Linux machine, but we're restricted to Python 2.4. Hi, I'm wondering why subprocess.Popen does not seem to replace the current process, even when it uses os.execvp (according to the documentation: http://docs.python.org/library/subprocess.html#subprocess.Popen). Specifically, when I try to kill a spawned process with Ctrl-C, the SIGINT does not seem to be sent to the spawned process. Some background: I have a Python script that calls shell scripts or commands. It does not need to regain control after calling these scripts or commands, so up to now I've been using an os.exec* command. It seems the subprocess module is the recommended way for spawning processes, but in this case perhaps it's better I stick with os.exec*? I've seen plenty of discussion about catching KeyboardInterrupt in the parent process and then manually killing the child, but (1) I can't use Popen.kill() on Python 2.4, and (2) this level of process management seems like overkill (pardon the potential for puns) in my case. Thanks for any help. From lanyjie at yahoo.com Thu Nov 4 05:14:25 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Thu, 4 Nov 2010 02:14:25 -0700 (PDT) Subject: Must be a bug in the re module [was: Why this result with the re module] In-Reply-To: <4CD1A307.2010809@mrabarnett.plus.com> Message-ID: <359401.16341.qm@web54203.mail.re2.yahoo.com> --- On Wed, 11/3/10, MRAB wrote: > [snip] > The outer group is repeated, so it can match again, but the > inner group > can't match again because it captured all it could the > previous time. > > Therefore the outer group matches and captures an empty > string and the > inner group remembers its last capture. Thanks, I got it. Basically, '(.a.)*' matched an empty string in the last outer group match, but not '(.a.)'. Now what remains hard for me to figure out is the number of matches: why is it 6 times with '((.a.)*)*' when matched to 'Mary has a lamb'? I think this is probably cuased by the limit of the matchobject: this object does not say anything about if an empty string is appended to the matched pattern or not. Hence some of the empty strings are repeated/overlapped by re.findall(). Regards, Yingjie From csjcg2 at gmail.com Thu Nov 4 05:37:31 2010 From: csjcg2 at gmail.com (Jo Chan) Date: Thu, 4 Nov 2010 17:37:31 +0800 Subject: Is there a OrderedDict which can perform an iteritems() in order? Message-ID: Hello all, I have working on a program which need a ordered dictionary that could perform iteritems() sequentially. I found a package on : http://www.voidspace.org.uk/python/odict.html#creating-an-ordered-dictionary but it could only perform items() in order, but iteritems()... Would you help me here? songjian 11.4 -- ------------------ Best Regards ??? ????????? ???? ????? 510006 Chen Songjian School of Information Science & Technology Sun Yat-sen(Zhongshan) University, Guangzhou Higher Education Mega Center, China, 510006 Mobile: +86-137-6069-6137 Email: csjcg2 at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From vlastimil.brom at gmail.com Thu Nov 4 05:49:29 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Thu, 4 Nov 2010 10:49:29 +0100 Subject: Is there a OrderedDict which can perform an iteritems() in order? In-Reply-To: References: Message-ID: 2010/11/4 Jo Chan : > Hello all, > ?? ? I have working on a program which need a ordered dictionary that could > perform iteritems() sequentially. > ?? ? I found a package on > :?http://www.voidspace.org.uk/python/odict.html#creating-an-ordered-dictionary > ?? ? but it ?could only perform items() in order, but iteritems()... > ?? ? Would you help me here? > songjian > ... Hi, it seems the standard library implementation in collections (OrderedDict) has the iteritems() method (checked on python 2.7). Does it not work the way you need? hth, vbr From pascal22p at parois.net Thu Nov 4 06:13:07 2010 From: pascal22p at parois.net (Pascal) Date: Thu, 04 Nov 2010 11:13:07 +0100 Subject: openmp do loops Message-ID: <4cd28734$0$12350$426a74cc@news.free.fr> Hi, I would like to parallelize this loop: do i=1,hklsize fcalctable(i)=structfact(hkltable(1,i),hkltable(2,i),hkltable(3,i)) end do I thought I would do this: !$OMP PARALLEL DO default(private) shared(hkltable, fcalctable,hklsize) do i=1,hklsize fcalctable(i)=structfact(hkltable(1,i),hkltable(2,i),hkltable(3,i)) end do !$OMP END PARALLEL DO However it seems that the order of the final table is not guarantee compared to the serial version. I need a j element of the table to stay there because I have an other table and I am using the index to match the data. Regards, Pascal From pascal22p at parois.net Thu Nov 4 06:31:20 2010 From: pascal22p at parois.net (Pascal) Date: Thu, 04 Nov 2010 11:31:20 +0100 Subject: openmp do loops In-Reply-To: <4cd28734$0$12350$426a74cc@news.free.fr> References: <4cd28734$0$12350$426a74cc@news.free.fr> Message-ID: <4cd28b78$0$10315$426a34cc@news.free.fr> On 11/04/2010 11:13 AM, Pascal wrote: > Hi, > Oops, wrong group, sorry... Pascal From michele.simionato at gmail.com Thu Nov 4 06:40:55 2010 From: michele.simionato at gmail.com (Michele Simionato) Date: Thu, 4 Nov 2010 03:40:55 -0700 (PDT) Subject: Best method for a menu in a command line program? References: Message-ID: <62c9c1f4-be12-4318-ad10-f9c8f84eabbc@t35g2000yqj.googlegroups.com> On Nov 4, 2:19?am, braden faulkner wrote: > I'm using a menu for my command line app using this method. > > choice = "foobar" > while choice != "q": > ? ? if choice == "c": > ? ? ? ? temp = input("Celsius temperature:") > ? ? ? ? print "Fahrenheit:",celsius_to_fahrenheit(temp) > ? ? elif choice == "f": > ? ? ? ? temp = input("Fahrenheit temperature:") > ? ? ? ? print "Celsius:",fahrenheit_to_celsius(temp) > ? ? elif choice != "q": > ? ? ? ? print_options() > ? ? choice = raw_input("option:") > > Just wondering if there is another or more efficient way I should be doing it? > > Thanks > -- Braden Faulkner Here is a solution using plac (http://pypi.python.org/pypi/plac): $ echo c2f.py import plac class Converter(object): commands = ['celsius_to_fahrenheit', 'fahrenheit_to_celsius'] @plac.annotations(t='convert Celsius to Fahrenheit') def celsius_to_fahrenheit(self, t): return round(32 + float(t) * 9/5) @plac.annotations(t='convert Fahrenheit to Celsius') def fahrenheit_to_celsius(self, t): return round((float(t) - 32) * 5 / 9.0) if __name__ == '__main__': import plac; plac.Interpreter.call(Converter) Here is an example of non-interactive usage: $ python c2f.py fahrenheit_to_celsius 212 100.0 $ python c2f.py celsius_to_fahrenheit 100 212.0 Here is an example of interactive usage:$ python c2f.py -i i> celsius_to_fahrenheit 100 212.0 i> celsius_to_fahrenheit 0 32.0 i> fahrenheit_to_celsius 32 0.0 i> fahrenheit_to_celsius 212 100.0 From stefan_ml at behnel.de Thu Nov 4 06:48:09 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 04 Nov 2010 11:48:09 +0100 Subject: openmp do loops In-Reply-To: <4cd28734$0$12350$426a74cc@news.free.fr> References: <4cd28734$0$12350$426a74cc@news.free.fr> Message-ID: Pascal, 04.11.2010 11:13: > I would like to parallelize this loop: > do i=1,hklsize > fcalctable(i)=structfact(hkltable(1,i),hkltable(2,i),hkltable(3,i)) > end do > > I thought I would do this: > !$OMP PARALLEL DO default(private) shared(hkltable, fcalctable,hklsize) > do i=1,hklsize > fcalctable(i)=structfact(hkltable(1,i),hkltable(2,i),hkltable(3,i)) > end do > !$OMP END PARALLEL DO Seeing this makes me seriously happy that I can write my code in Python (or Cython, for that purpose). Stefan From tinnews at isbd.co.uk Thu Nov 4 07:04:51 2010 From: tinnews at isbd.co.uk (tinnews at isbd.co.uk) Date: Thu, 4 Nov 2010 11:04:51 +0000 Subject: What people are using to access this mailing list References: <4cd144cc$0$29966$c3e8da3$5496439d@news.astraweb.com> <87r5f2wr7t.fsf@rudin.co.uk> Message-ID: Tim Harig wrote: > On 2010-11-03, Grant Edwards wrote: > > On 2010-11-03, Paul Rudin wrote: > >> John Bond writes: > >> > >>> On 3/11/2010 11:17 AM, Steven D'Aprano wrote: > >>>> On Wed, 03 Nov 2010 08:02:29 +0000, John Bond wrote: > >>>> > >>>>> Hope this isn't too O/T - I was just wondering how people read/send to > >>>>> this mailing list, eg. normal email client, gmane, some other software > >>>>> or online service? > >>>> Usenet via my ISP, on comp.lang.python. > >>>> > >>> Using what client (or web client)? > >> > >> Emacs, of course :-; > > > > Slrn, of course. > > Of, course. Well I actually prefer tin to slrn but that's what's good, both are available still and well supported. -- Chris Green From ben+python at benfinney.id.au Thu Nov 4 07:33:00 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 04 Nov 2010 22:33:00 +1100 Subject: Best method for a menu in a command line program? References: <87fwvhhmkc.fsf@benfinney.id.au> <87hbfxk19m.fsf@gmail.com> Message-ID: <871v71gw7n.fsf@benfinney.id.au> Arnaud Delobelle writes: > Ben Finney writes: > [...] > > commands = { > > 'q': (lambda: quit()), > > 'c': (lambda: prompt_and_convert_temperature( > > ["Celsius", "Fahrenheit"], celsius_to_fahrenheit)), > > 'f': (lambda: prompt_and_convert_temperature( > > ["Fahrenheit", "Celsius"], fahrenheit_to_celsius)), > > None: print_commands, This would be counter to the problem as stated by the OP. The program originally described loops *only* if no other command is specified; yours doesn't distinguish. -- \ ?It is far better to grasp the universe as it really is than to | `\ persist in delusion, however satisfying and reassuring.? ?Carl | _o__) Sagan | Ben Finney From jeanmichel at sequans.com Thu Nov 4 07:34:08 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 04 Nov 2010 12:34:08 +0100 Subject: python logging, handling multiline log entries Message-ID: <4CD29A30.30102@sequans.com> Hi python fellows, I'm looking to do the following : import logging l = logging.getLogger('aHeader') l.handlers = [] l.addHandler(logging.StreamHandler()) l.handlers[-1].setFormatter(logging.Formatter("%(asctime)s - %(name)s - %(message)s")) l.error('1st line\n2nd line') output: 2010-11-04 12:22:05,593 - aHeader - 1st line 2nd line I'd like to get something like: 2010-11-04 12:22:05,593 - aHeader - 1st line 2nd line I don't want to get the header on every line, otherwise I would just need to log every lines. Is there a simple way of doing that? anyone already gave a though on that ? The main problem I'm facing is that I cannot alter the log entry itself, I don't know the size of the header and I think it would be anti-pattern. My guess is that it should be handled in the formatter, overriding the format method, but how do you get the header size (i.e. the indentation size). So if anyone has a piece of code doing that, feel free to point it to me. Cheers, JM From ben+python at benfinney.id.au Thu Nov 4 07:35:29 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 04 Nov 2010 22:35:29 +1100 Subject: Best method for a menu in a command line program? References: Message-ID: <87wrotfhj2.fsf@benfinney.id.au> brf256 at gmail.com writes: > Thanks again, > Braden Faulkner > > Sent wirelessly from my BlackBerry device on the Bell network. > Envoy? sans fil par mon terminal mobile BlackBerry sur le r?seau de Bell. Please show your thanks by *not* spamming the forum with each message; compose your messages from a mail client that doesn't feel the need to blather about itself in the message body. -- \ ?For fast acting relief, try slowing down.? ?Jane Wagner, via | `\ Lily Tomlin | _o__) | Ben Finney From __peter__ at web.de Thu Nov 4 07:49:01 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 04 Nov 2010 12:49:01 +0100 Subject: Best method for a menu in a command line program? References: Message-ID: braden faulkner wrote: > I'm using a menu for my command line app using this method. > > choice = "foobar" > while choice != "q": > if choice == "c": > temp = input("Celsius temperature:") > print "Fahrenheit:",celsius_to_fahrenheit(temp) > elif choice == "f": > temp = input("Fahrenheit temperature:") > print "Celsius:",fahrenheit_to_celsius(temp) > elif choice != "q": > print_options() > choice = raw_input("option:") > > Just wondering if there is another or more efficient way I should be doing > it? The user interface will be slightly different, but the cmd module is great to build simple interactive command line apps quickly: # -*- coding: utf-8 -*- from __future__ import division import cmd class Cmd(cmd.Cmd): prompt = "Enter a command (? for help) --> " def do_celsius_to_fahrenheit(self, value): """Convert Celsius to Fahrenheit""" celsius = float(value) print u"%f ?F" % (celsius * 9/5 + 32) def do_fahrenheit_to_celsius(self, value): fahrenheit = float(value) print u"%f ?C" % ((fahrenheit - 32) * 5/9) def do_quit(self, value): return True do_EOF = do_quit Cmd().cmdloop() A sample session: $ python convert_temperature.py Enter a command (? for help) --> ? Documented commands (type help ): ======================================== celsius_to_fahrenheit Undocumented commands: ====================== EOF fahrenheit_to_celsius help quit Enter a command (? for help) --> ? celsius_to_fahrenheit Convert Celsius to Fahrenheit Enter a command (? for help) --> celsius_to_fahrenheit 0 32.000000 ?F Enter a command (? for help) --> fahrenheit_to_celsius 212 100.000000 ?C Enter a command (? for help) --> quit $ Peter From jeanmichel at sequans.com Thu Nov 4 07:57:52 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 04 Nov 2010 12:57:52 +0100 Subject: python logging, handling multiline log entries In-Reply-To: <4CD29A30.30102@sequans.com> References: <4CD29A30.30102@sequans.com> Message-ID: <4CD29FC0.30805@sequans.com> Jean-Michel Pichavant wrote: > Hi python fellows, > > I'm looking to do the following : > > import logging > > l = logging.getLogger('aHeader') > l.handlers = [] > l.addHandler(logging.StreamHandler()) > l.handlers[-1].setFormatter(logging.Formatter("%(asctime)s - %(name)s > - %(message)s")) > l.error('1st line\n2nd line') > > output: > 2010-11-04 12:22:05,593 - aHeader - 1st line > 2nd line > > > > I'd like to get something like: > 2010-11-04 12:22:05,593 - aHeader - 1st line > 2nd line > > I don't want to get the header on every line, otherwise I would just > need to log every lines. > > Is there a simple way of doing that? anyone already gave a though on > that ? > > The main problem I'm facing is that I cannot alter the log entry > itself, I don't know the size of the header and I think it would be > anti-pattern. My guess is that it should be handled in the formatter, > overriding the format method, but how do you get the header size (i.e. > the indentation size). > > So if anyone has a piece of code doing that, feel free to point it to me. > > Cheers, > > JM > > > You can ignore me, I just found an acceptable solution (i think). You guys still have been usefull because writing this mail helped me structure my thoughts :o) JM PS: class MultiLineFormatter(logging.Formatter): def format(self, record): str = logging.Formatter.format(self, record) header, footer = str.split(record.message) str = str.replace('\n', '\n' + ' '*len(header)) return str There could be a problem if "%(message)s" is not in the formatter string, but honestly, who would be doing that :) From Antoon.Pardon at rece.vub.ac.be Thu Nov 4 08:02:09 2010 From: Antoon.Pardon at rece.vub.ac.be (Antoon Pardon) Date: Thu, 4 Nov 2010 13:02:09 +0100 Subject: Compare source code In-Reply-To: <4cd1495f$0$29966$c3e8da3$5496439d@news.astraweb.com> References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1495f$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20101104120209.GA16757@rcpc42.vub.ac.be> On Wed, Nov 03, 2010 at 11:37:03AM +0000, Steven D'Aprano wrote: > On Wed, 03 Nov 2010 12:01:06 +1300, Lawrence D'Oliveiro wrote: > > > In message , Grant Edwards wrote: > > >> Other languages have similar problems if you remove salient bits of > >> syntax before comparing two source files files. > > > > But other languages don???t make those ???salient bits of syntax??? invisible. > > I.e. they are actually ???salient???. > > (1) Indentation is visible. Compare: > > > This line has leading visible whitespace. > > This line has leading invisible characters. > > See the difference? Unless, your code is split over different pages, as when it is printed in a book. You also need to see the next piece of code to notice the dedention. e.g. I have the following code at the bottom of my editor. for i := 0 to 9 do some(code); more(code); end; I can by just looking at this code notice that I'm looking at the whole for block. But when I have similar python code at the bottom of the page. for i in xrange(10): some(code) more(code) Then I can't make out whether I'm looking at the whole for suite or not. Indentation may be visible, but it is not context-free visible, It only becomes visible by looking by introducing context. So because it is only visible by looking at the context I would say the end of a block i made implicitly and not explicitly -- Antoon Pardon From invalid at invalid.invalid Thu Nov 4 09:43:13 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 4 Nov 2010 13:43:13 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-04, Seebs wrote: > On 2010-11-04, Steven D'Aprano wrote: >> And people have suggested that if your workflow leads to indentation >> being mangled and your source code no longer running, the solution is to >> change the workflow. > > Yup. > > But it strikes me as unmistakably a shortcoming of Python (and Makefiles, > for that matter) that code for them can't survive a common failure mode > that everything else I use can. I think the issue is that for whatever reason, white-space mangling is "a common failure mode" for you. I don't ever remember it happening to me. If whitespace mangling is common for you, then you just shouldn't be using Python any more than somebody who works on a system that randomly changes/deletes the strings "begin" and "end" should be using Pascal. -- Grant Edwards grant.b.edwards Yow! PEGGY FLEMMING is at stealing BASKET BALLS to gmail.com feed the babies in VERMONT. From moogyd at yahoo.co.uk Thu Nov 4 10:06:24 2010 From: moogyd at yahoo.co.uk (moogyd) Date: Thu, 4 Nov 2010 07:06:24 -0700 (PDT) Subject: Popen Question Message-ID: <891a9a80-c30d-4415-ac81-bddd0b564fa6@g13g2000yqj.googlegroups.com> Hi, I usually use csh for my simulation control scripts, but these scripts are becoming more complex, so I plan to use python for the next project. To this end, I am looking at subprocess.Popen() to actually call the simulations, and have a very basic question which is demonstrated below. [sde:staff at lbux03 ~]$ python Python 2.6 (r26:66714, Feb 21 2009, 02:16:04) [GCC 4.3.2 [gcc-4_3-branch revision 141291]] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import os, subprocess >>> os.environ['MYVAR'] = "myval" >>> p = subprocess.Popen(['echo', '$MYVAR'],shell=True) >>> >>> p = subprocess.Popen(['echo', '$MYVAR']) >>> $MYVAR >>> p = subprocess.Popen('echo $MYVAR',shell=True) >>> myval >>> p = subprocess.Popen('echo $MYVAR') Traceback (most recent call last): File "", line 1, in File "/usr/lib64/python2.6/subprocess.py", line 595, in __init__ errread, errwrite) File "/usr/lib64/python2.6/subprocess.py", line 1106, in _execute_child raise child_exception OSError: [Errno 2] No such file or directory I am not really sure I understand these results. 1) No idea what is going on 2) As (1). What isn't myval printed out (rather than $MYVAR) 3) Works as I wanted it to 4) Why do I need shell=True ? The documentation isn't very clear to me (it seems you need to understand the underlying system calls). Can anyone explain (or provide link) for this behaviour in simple English? Thanks, Steven From Antoon.Pardon at rece.vub.ac.be Thu Nov 4 10:08:13 2010 From: Antoon.Pardon at rece.vub.ac.be (Antoon Pardon) Date: Thu, 4 Nov 2010 15:08:13 +0100 Subject: Compare source code In-Reply-To: <4CD406A7.8040600@stoneleaf.us> References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1495f$0$29966$c3e8da3$5496439d@news.astraweb.com> <20101104120209.GA16757@rcpc42.vub.ac.be> <4CD406A7.8040600@stoneleaf.us> Message-ID: <20101104140813.GB16757@rcpc42.vub.ac.be> On Fri, Nov 05, 2010 at 06:29:11AM -0700, Ethan Furman wrote: > Antoon Pardon wrote: > >Unless, your code is split over different pages, as when it is printed in a book. > >You also need to see the next piece of code to notice the dedention. > > > >e.g. I have the following code at the bottom of my editor. > > > > for i := 0 to 9 do > > some(code); > > more(code); > > end; > > > >I can by just looking at this code notice that I'm looking at the whole for block. > > > > > >But when I have similar python code at the bottom of the page. > > > > for i in xrange(10): > > some(code) > > more(code) > > > >Then I can't make out whether I'm looking at the whole for suite or not. > These code pieces are not equivalent -- you have four lines of code > in the first piece, only three lines in the python piece; in other > words, if the "end;" were not on screen, you would still have no > idea if it was the whole block or not; in still other words, the > "end;", just like the dedented line, provides the context. That one piece of code is only three lines and the other is four doesn't make them not equivallent. Adding a fourth (empty) line to the python example wouldn't have changed things significantly. These two pieces are equivallent in any significant way. Both are examples of a for loop, one with its block the other with its suite. They are both complete for-statements as defined by the respective grammes. Both perform the same functionality. The complete for-statement is all you need to see, to know you are seeing the complete for-statement in the first example. So all you need is in context information. To know you see the complete for statement in python, you need to see more than just the complete for-statement. You need out of context information. -- Antoon Pardon From alain at dpt-info.u-strasbg.fr Thu Nov 4 10:10:13 2010 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Thu, 04 Nov 2010 15:10:13 +0100 Subject: openmp do loops References: <4cd28734$0$12350$426a74cc@news.free.fr> Message-ID: <87d3qlch8a.fsf@dpt-info.u-strasbg.fr> Stefan Behnel writes: >> !$OMP PARALLEL DO default(private) shared(hkltable, fcalctable,hklsize) >> do i=1,hklsize >> fcalctable(i)=structfact(hkltable(1,i),hkltable(2,i),hkltable(3,i)) >> end do >> !$OMP END PARALLEL DO (This is Fortan, BTW.) > Seeing this makes me seriously happy that I can write my code in > Python (or Cython, for that purpose). Does Cython support OpenMP? I've foudn nothing in the docs. -- Alain. From neilc at norwich.edu Thu Nov 4 10:15:25 2010 From: neilc at norwich.edu (Neil Cerutti) Date: 4 Nov 2010 14:15:25 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8jftftFelnU1@mid.individual.net> On 2010-11-05, Ethan Furman wrote: > Grant Edwards wrote: >> On 2010-11-04, Emile van Sebille wrote: >>> On 11/3/2010 4:09 PM Seebs said... >>>> What's the token that marks the end of a block, >>>> corresponding to the colon used to introduce it? >>> >>> My thoughts tend more towards 'can we get Guido to eliminate >>> the colon requirements' -- The indent level of the next line >>> ought to suffice. >> >> But without the colon, how are people who write programming >> editors going to know when to increase the indentation level >> as I enter code? > > Hopefully by the keywords used to introduce the block: if, > elif, else, for, while, with, etc. etc. It is not legal to > start a new indented block just by appending a colon to the > previous line. The handsome ':' terminator of if/elif/if statements allows us to omit a newline, conserving vertical space. This improves the readability of certain constructs. if x: print(x) elif y: print(y) else: print() versus if x print(x) elif y print(y) else print() Beauty-is-in-the-eye-of-the-BDFLly-yours, -- Neil Cerutti From jlconlin at gmail.com Thu Nov 4 10:53:38 2010 From: jlconlin at gmail.com (Jeremy) Date: Thu, 4 Nov 2010 07:53:38 -0700 (PDT) Subject: Compiling/Installing Python 2.7 on OSX 10.6 Message-ID: <3d9139ae-bd6f-4567-bb02-b21a8ba86e50@o15g2000prh.googlegroups.com> I'm having trouble installing Python 2.7 on OSX 10.6 I was able to successfully compile it from source, but ran into problems when I did make install. The error I got (I received many similar errors) was: /usr/bin/install -c -m 644 ../LICENSE /home/jlconlin/Library/ Frameworks/Python.framework/Versions/2.7/lib/python2.7/LICENSE.txt PYTHONPATH=/home/jlconlin/Library/Frameworks/Python.framework/Versions/ 2.7/lib/python2.7 DYLD_FRAMEWORK_PATH=/home/jlconlin/src/Python-2.7/ build: \ ./python -Wi -tt /home/jlconlin/Library/Frameworks/Python.framework/ Versions/2.7/lib/python2.7/compileall.py \ -d /home/jlconlin/Library/Frameworks/Python.framework/Versions/2.7/ lib/python2.7 -f \ -x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \ /home/jlconlin/Library/Frameworks/Python.framework/Versions/2.7/lib/ python2.7 Listing /home/jlconlin/Library/Frameworks/Python.framework/Versions/ 2.7/lib/python2.7 ... Compiling /home/jlconlin/Library/Frameworks/Python.framework/Versions/ 2.7/lib/python2.7/._BaseHTTPServer.py ... Sorry: TypeError: ('compile() expected string without null bytes',) Compiling /home/jlconlin/Library/Frameworks/Python.framework/Versions/ 2.7/lib/python2.7/._Bastion.py ... Sorry: TypeError: ('compile() expected string without null bytes',) Compiling /home/jlconlin/Library/Frameworks/Python.framework/Versions/ 2.7/lib/python2.7/._CGIHTTPServer.py ... Sorry: TypeError: ('compile() expected string without null bytes',) As you can see I am compiling/installing in my home directory instead of for the whole system. The script I used to compile Python 2.7 is: #! /bin/sh export CFLAGS="-arch x86_64" export LDFLAGS="-arch x86_64" ../configure --prefix=$HOME/usr/local \ --enable-framework=$HOME/Library/Frameworks \ --disable-toolbox-glue \ MACOSX_DEPLOYMENT_TARGET=10.6 make make install Can anyone help me fix the install error? Thanks, Jeremy PS. Python compiled correctly, but a few modules were not found/made but I don't think they are important. Python build finished, but the necessary bits to build these modules were not found: _bsddb dl gdbm imageop linuxaudiodev ossaudiodev spwd sunaudiodev To find the necessary bits, look in setup.py in detect_modules() for the module's name. From ra.ravi.rav at gmail.com Thu Nov 4 11:14:35 2010 From: ra.ravi.rav at gmail.com (Ravi) Date: Thu, 4 Nov 2010 08:14:35 -0700 (PDT) Subject: Popen Question References: <891a9a80-c30d-4415-ac81-bddd0b564fa6@g13g2000yqj.googlegroups.com> Message-ID: <31f5cbe2-112e-4f44-a913-245521e15d13@g28g2000pra.googlegroups.com> On Nov 4, 7:06?pm, moogyd wrote: > Hi, > I usually use csh for my simulation control scripts, but these scripts > are becoming more complex, so I plan to use python for the next > project. > To this end, I am looking at subprocess.Popen() to actually call the > simulations, and have a very basic question which is demonstrated > below. > > [sde:staff at lbux03 ~]$ python > Python 2.6 (r26:66714, Feb 21 2009, 02:16:04) > [GCC 4.3.2 [gcc-4_3-branch revision 141291]] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > > >>> import os, subprocess > >>> os.environ['MYVAR'] = "myval" > >>> p = subprocess.Popen(['echo', '$MYVAR'],shell=True) > > >>> p = subprocess.Popen(['echo', '$MYVAR']) > >>> $MYVAR > >>> p = subprocess.Popen('echo $MYVAR',shell=True) > >>> myval > >>> p = subprocess.Popen('echo $MYVAR') > > Traceback (most recent call last): > ? File "", line 1, in > ? File "/usr/lib64/python2.6/subprocess.py", line 595, in __init__ > ? ? errread, errwrite) > ? File "/usr/lib64/python2.6/subprocess.py", line 1106, in > _execute_child > ? ? raise child_exception > OSError: [Errno 2] No such file or directory > > I am not really sure I understand these results. > 1) No idea what is going on > 2) As (1). What isn't myval printed out (rather than $MYVAR) > 3) Works as I wanted it to > 4) Why do I need shell=True ? > The documentation isn't very clear to me (it seems you need to > understand the underlying system calls). > > Can anyone explain (or provide link) for this behaviour in simple > English? > Thanks, > Steven try giving /bin/echo From fetchinson at googlemail.com Thu Nov 4 11:21:18 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Thu, 4 Nov 2010 16:21:18 +0100 Subject: cms 4 static pages? In-Reply-To: References: Message-ID: > m looking 4 a framework, that allows to build static community software > (similar to facebook) without having to start scripts, database > connects, admin cookies, e.t.c. > > means - should be dynamic without really being dynamic, delivering just > static pages. (yes, i know e.g. nginx does that by caching, thats not > what i want!) > > features wanted: > > a not database driven > > b password access ist done by just renaming users home directory. User > at logout will receive new secret subdirectory name 4 new login. > > c no clientside scripting. changing layout will be done by rebuilding > all relevant static pages in user directory once by serverside script. > > d new entries e.g. mail, discussions will be queued, user just sees: tnx > 4 your new article, page will be rebuilt in ... estimated 3 seconds ... > or estimated 10 seconds ... depending on load and todo queue length. > > e load balancing is done by just replicating static pages between > servers after new rebuild of static pages. > > f simulation of received mail directory through just rebuilding relevant > static html tree. attachments not allowed. > > g intelligent todo queue 4 resorting mail sent, received, discussions, > look and feel before rebuilding static user pages. (herein lies the > intelligence of the whole system) > > h notifications 4 new mail, messages, e.t.c. are just updates in static > html fields. if user gets offline (measured by time since last update of > static pages) user will be informed once a day by mail. > > i simulation of locking can easily be done by dotfiles. > > j according 2 my calculations such system should be able 2 satisfy any > bandwidth without causing significant load of cpu, due 2 low protocol > overhead and no server side scripting, no database load. overload of > server should not possible by design. > > k modules, addon 4 twitter e.g., nice 2 have > > > (and no, no java!) any pointers? Yeah, rethink your design! Seriously, you listed a number of features which are not really features but implementation details and you haven't told us what your original goals are which you think are fulfilled by these implementation details. If you would clearly state what your goals are (regardless of how it is implemented) I'm 100% certain a better implementation can be found than the one you enumerated. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From g.rodola at gmail.com Thu Nov 4 11:29:15 2010 From: g.rodola at gmail.com (=?ISO-8859-1?Q?Giampaolo_Rodol=E0?=) Date: Thu, 4 Nov 2010 16:29:15 +0100 Subject: [ANN] pyOpenSSL 0.11 released In-Reply-To: <20101101224323.2040.732989284.divmod.xquotient.500@localhost.localdomain> References: <20101101224323.2040.732989284.divmod.xquotient.500@localhost.localdomain> Message-ID: 2010/11/1 : > Hello all, > > I'm happy to announce the release of pyOpenSSL 0.11. ?The primary change > from the last release is that Python 3.2 is now supported. ?Python 2.4 > through Python 2.7 are still supported as well. ?This release also fixes a > handful of bugs in error handling code. ?It also adds APIs for generating > and verifying cryptographic signatures and it improves the test suite to > cover nearly 80% of the implementation. > > Downloads and more details about the release can be found on the release > page: > > ? https://launchpad.net/pyopenssl/main/0.11 > > Enjoy, > Jean-Paul > -- > http://mail.python.org/mailman/listinfo/python-list > Congratulations! --- Giampaolo http://code.google.com/p/pyftpdlib/ http://code.google.com/p/psutil/ From macmanes at gmail.com Thu Nov 4 11:37:27 2010 From: macmanes at gmail.com (Matt) Date: Thu, 4 Nov 2010 08:37:27 -0700 (PDT) Subject: execute shell script from python, needs sys.argv Message-ID: Hi All, I am trying to execute a shell script from within python.. This shell script takes the format, where $1 and $2 are variables from the command line: cat $1 | Fastx_trimmer -n COUNT -o $2 straight into the cmd line it would be: cat file.1 | Fastx_trimmer -n COUNT -o file.2 So, know that there is a way to do this in python using the subprocess module, but despite a lot of effort, I can't seem to get this to work, and precisely because of those arguments taken from the command line. I was thinking that the easiest thing to so was to import sys, os, subprocess proc = subprocess.call([cat sys.argv[1] | fastx_trimmer -n COUNT -o sys.argv[2]], shell=True) this clearly does not work... alternatively, I could put the shell command in its own file, say fastx.sh, and pass it's arguments to it vie the command line. import sys, os, subprocess proc = subprocess.call([fastx.sh, sys.argv[1], sys.argv[2]], shell=True) But, this does not seem to work as this is not the proper way to pass arguments to the shell script. in short, I'm sure that this is a easy fix, but given my still limited python vocabulary, it eludes me. Thanks, Matt From alain at dpt-info.u-strasbg.fr Thu Nov 4 11:55:16 2010 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Thu, 04 Nov 2010 16:55:16 +0100 Subject: Popen Question References: <891a9a80-c30d-4415-ac81-bddd0b564fa6@g13g2000yqj.googlegroups.com> Message-ID: <8762wdccd7.fsf@dpt-info.u-strasbg.fr> moogyd writes: >>>> import os, subprocess >>>> os.environ['MYVAR'] = "myval" >>>> p = subprocess.Popen(['echo', '$MYVAR'],shell=True) >>>> >>>> p = subprocess.Popen(['echo', '$MYVAR']) >>>> $MYVAR > >>>> p = subprocess.Popen('echo $MYVAR',shell=True) >>>> myval > >>>> p = subprocess.Popen('echo $MYVAR') > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib64/python2.6/subprocess.py", line 595, in __init__ > errread, errwrite) > File "/usr/lib64/python2.6/subprocess.py", line 1106, in > _execute_child > raise child_exception > OSError: [Errno 2] No such file or directory > > I am not really sure I understand these results. > 1) No idea what is going on > 2) As (1). What isn't myval printed out (rather than $MYVAR) > 3) Works as I wanted it to > 4) Why do I need shell=True ? Expanding $MYVAR into its value is a feature of the shell (afaik all shells use the same syntax). Popen without shell=True uses the execvp() system call directly, without going through the shell variable expansion process (cases 2 and 4 above). For example, case 4 above asks execvp to (find and) execute a program named "echo $MYVAR" (an 11-letter name, where the fifth letter is space and the sixth is $ -- a perfectly valid file/program name). Then, if you use shell=True with a list, only the first word is used as a command, and the others are kept in positional parameters. That's why your first try fails (try 'sh -c echo $HOME' in a shell, without the single quotes, and you'll get empty output). > The documentation isn't very clear to me (it seems you need to > understand the underlying system calls). You're probably right. The base fact here is: the use of variables is a feature of the shell. No shell, no variable. > Can anyone explain (or provide link) for this behaviour in simple > English? Shell variables are explained in detail in any shell man page. The execvp() system call has its own man page. -- Alain. From benjamin.kaplan at case.edu Thu Nov 4 12:06:17 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 4 Nov 2010 12:06:17 -0400 Subject: execute shell script from python, needs sys.argv In-Reply-To: References: Message-ID: On Thu, Nov 4, 2010 at 11:37 AM, Matt wrote: > Hi All, > > I am trying to execute a shell script from within python.. ?This shell > script takes the format, where $1 and $2 are variables from the > command line: cat $1 | Fastx_trimmer -n COUNT -o $2 > > straight into the cmd line it would be: ?cat file.1 | Fastx_trimmer -n > COUNT -o file.2 > > So, ?know that there is a way to do this in python using the > subprocess module, but despite a lot of effort, I can't seem to get > this to work, and precisely because of those arguments taken from the > command line. > > I was thinking that the easiest thing to so was to > > import sys, os, subprocess > proc = subprocess.call([cat sys.argv[1] | fastx_trimmer -n COUNT -o > sys.argv[2]], shell=True) > Python is not the shell. Shell commands are not python commands. You need either a string or a list of strings, so any literal have to be in quotes. Also, subprocess can't handle the redirection. You need to run it as two commands. proc1 = subprocess.Popen(["cat", sys.argv[1]],stdout = subprocess.PIPE, shell = True) proc2 = subprocess.Popen(["fastx_trimmer", "-n", "COUNT", "-o", sys.argv[2]],stdin=proc1.stdout, shell=True) > this clearly does not work... > > alternatively, I could put the shell command in its own file, say > fastx.sh, and pass it's arguments to it vie the command line. > > import sys, os, subprocess > proc = subprocess.call([fastx.sh, sys.argv[1], sys.argv[2]], > shell=True) > Again, you need a string. fastx.sh looks for a python object called fastx and tries accessing an attribute called sh in that object. Ov course, there's no such thing. Put quotes around it and it will work. > But, this does not seem to work as this is not the proper way to pass > arguments to the shell script. > > in short, I'm sure that this is a easy fix, but given my still limited > python vocabulary, it eludes me. > > Thanks, Matt > > > -- > http://mail.python.org/mailman/listinfo/python-list > From __peter__ at web.de Thu Nov 4 12:11:06 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 04 Nov 2010 17:11:06 +0100 Subject: execute shell script from python, needs sys.argv References: Message-ID: Matt wrote: > I am trying to execute a shell script from within python.. This shell > script takes the format, where $1 and $2 are variables from the > command line: cat $1 | Fastx_trimmer -n COUNT -o $2 > > straight into the cmd line it would be: cat file.1 | Fastx_trimmer -n > COUNT -o file.2 > > So, know that there is a way to do this in python using the > subprocess module, but despite a lot of effort, I can't seem to get > this to work, and precisely because of those arguments taken from the > command line. > > I was thinking that the easiest thing to so was to > > import sys, os, subprocess > proc = subprocess.call([cat sys.argv[1] | fastx_trimmer -n COUNT -o > sys.argv[2]], shell=True) > > this clearly does not work... > > alternatively, I could put the shell command in its own file, say > fastx.sh, and pass it's arguments to it vie the command line. > > import sys, os, subprocess > proc = subprocess.call([fastx.sh, sys.argv[1], sys.argv[2]], > shell=True) > > But, this does not seem to work as this is not the proper way to pass > arguments to the shell script. > > in short, I'm sure that this is a easy fix, but given my still limited > python vocabulary, it eludes me. You could do it in two steps: >>> from subprocess import * >>> source = Popen(["cat", "/usr/share/dict/words"], stdout=PIPE) >>> call(["wc"], stdin=source.stdout) 98569 98568 931708 0 >>> A similar example is here, under a "can't miss" headline: http://docs.python.org/library/subprocess.html#replacing-shell-pipeline Peter From moura.mario at gmail.com Thu Nov 4 12:18:44 2010 From: moura.mario at gmail.com (macm) Date: Thu, 4 Nov 2010 09:18:44 -0700 (PDT) Subject: How find all childrens values of a nested dictionary, fast! Message-ID: Hi Folks How find all childrens values of a nested dictionary, fast! >>> a = {'a' : {'b' :{'/' :[1,2,3,4], 'ba' :{'/' :[41,42,44]} ,'bc' :{'/':[51,52,54], 'bcd' :{'/':[68,69,66]}}},'c' :{'/' :[5,6,7,8]}}, 'ab' : {'/' :[12,13,14,15]}, 'ac' :{'/' :[21,22,23]}} >>> a['a'] {'c': {'/': [5, 6, 7, 8]}, 'b': {'ba': {'/': [41, 42, 44]}, '/': [1, 2, 3, 4], 'bc': {'bcd': {'/': [68, 69, 66]}, '/': [51, 52, 54]}}} >>> a['a']['b'] {'ba': {'/': [41, 42, 44]}, '/': [1, 2, 3, 4], 'bc': {'bcd': {'/': [68, 69, 66]}, '/': [51, 52, 54]}} >>> a['a']['b'].values() [{'/': [41, 42, 44]}, [1, 2, 3, 4], {'bcd': {'/': [68, 69, 66]}, '/': [51, 52, 54]}] Now I want find all values of key "/" Desire result is [41, 42, 44, 1, 2, 3, 4, 68, 69, 66, 51, 52, 54] I am trying map, reduce, lambda. Regards macm From darcy at druid.net Thu Nov 4 12:20:45 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Thu, 4 Nov 2010 12:20:45 -0400 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20101104122045.8d466f82.darcy@druid.net> On 04 Nov 2010 08:17:10 GMT Seebs wrote: > Outside of people who seem to be deeply emotionally invested in insisting > that it is never, at all, in ANY way, for ANY person, annoying, it seems > to be pretty consistent to observe that, benefits or no benefits, it has > some kind of non-zero annoyance value. Who are these people that believe that no one finds indentation as syntax annoying? I haven't seen any evidence in this group. Let's leave the straw men out of this. Many of us don't find it annoying ourselves, that's for sure but we aren't trying to read anyone else's mind. We're all pretty sure that *you* find it annoying but there is no telepathy involved there. > * Not having to type braces: Yay! Which I always found annoying given that I was already adding signals (indentation) that I was starting a block. > * Having structure map to functionality: Some people quite like it, and Some of us think that it is a contender for the single greatest thing about Python. > * Not being able to write an auto-indenter, ever, because it is by > design theoretically impossible: Annoying. Right. And in C you can never write an auto-bracer for exactly the same reason. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From shashank.sunny.singh at gmail.com Thu Nov 4 12:42:03 2010 From: shashank.sunny.singh at gmail.com (Shashank Singh) Date: Thu, 4 Nov 2010 22:12:03 +0530 Subject: Final state of underlying sequence in islice Message-ID: Hi, Apologies if this has been discussed in this list before. Google has not been very helpful in locating any such previous discussion. Are there any promises made with regard to final state of the underlying sequence that islice slices? for example consider this >>> from itertools import * >>> c = count() >>> list(islice(c, 1, 3, 50)) [1] >>> c.next() 51 Now, the doc [1] says "If *stop* is None, then iteration continues until the iterator is exhausted, if at all; otherwise, it stops at the specified position". It clearly is not stopping at stop (3). Further, the doc gives an example of how this is *equivalent* to a generator defined in the same section. It turns out, these two are not exactly the same if the side-effect of the code is considered on the underlying sequence. Redefining islice using the generator function defined in the doc gives different (and from one pov, expected) result >>> def islice(iterable, *args): ... # islice('ABCDEFG', 2) --> A B ... >>> c = count() >>> list(islice(c, 1, 3, 50)) [1] >>> c.next() 2 While "fixing" this should be rather easy in terms of the change in code required it might break any code depending on this seemingly incorrect behavior. [1]. http://docs.python.org/library/itertools.html#itertools.islice -- Regards Shashank Singh shashank.sunny.singh at gmail.com http://www.cse.iitb.ac.in/~shashanksingh -------------- next part -------------- An HTML attachment was scrubbed... URL: From robert.kern at gmail.com Thu Nov 4 12:43:34 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 04 Nov 2010 11:43:34 -0500 Subject: functions, list, default parameters In-Reply-To: References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <8ivelpFif1U1@mid.individual.net> <4cca88bc$0$29987$c3e8da3$5496439d@news.astraweb.com> <8j1seqFa1eU2@mid.individual.net> Message-ID: On 11/4/10 2:07 AM, Lawrence D'Oliveiro wrote: > In message, Robert Kern > wrote: > >> On 11/2/10 2:12 AM, Lawrence D'Oliveiro wrote: >> >>> In message, Robert >>> Kern wrote: >>> >>>> "Immutable objects" are just those without an obvious API for modifying >>>> them. >>> >>> They are ones with NO legal language constructs for modifying them. Hint: >>> if a selector of some part of such an object were to occur on the LHS of >>> an assignment, and that would raise an error, then the object is >>> immutable. The interpreter already knows all this. >> >> Incorrect. RHS method calls can often modify objects. > > So bloody what? So examining LHS "selectors" is not sufficient for determining immutability. >> Show me the algorithm that the interpreter can use to determine whether or >> not an object is mutable. > > Go look in the code for the one it already uses in places where immutable > objects are currently required. Like hashes for dictionary keys? The code just calls the __hash__ method and trusts that you designed the object correctly. It does not verify anything. Although, strictly speaking, it doesn't require immutability of keys. This is actually another one of those places where the Python language developers defined a concept but did not equip the interpreter with a way to verify compliance with the concept. A proper hashable object has a __hash__ method and an __eq__ method defined such that if two objects compare equal, they also hash equal. But nothing in the interpreter ever tries to verify that this is true. Nor can it except by an impossible exhaustive search of all the possible objects. Care to point me to specific place in the Python code you are talking about? Or even just a slightly more specific direction would suffice. I don't really know what you might be talking about. >>>> With various trickeries, I can mutate any immutable object. >>> >>> None within the Python language itself. Which is what we?re talking about >>> here: a language construct which is probably one of the top 3 sources of >>> grief to Python newbies. And not-so-newbies. >> >> "import ctypes" is within the Python language. > > And in the old BASIC days, we had ?PEEK? and ?POKE?. So by your reasoning, > that invalidated the language rules, too. I'm not talking about BASIC at all. Nor am I talking about invalidation of language rules in either BASIC or Python. I am only talking about whether or not the Python interpreter is able to determine if an object is immutable or not. But this really is a side point. I'm happy to drop it. -- 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 nagle at animats.com Thu Nov 4 12:48:43 2010 From: nagle at animats.com (John Nagle) Date: Thu, 04 Nov 2010 09:48:43 -0700 Subject: Compare source code In-Reply-To: <4ccd7487$0$30068$426a74cc@news.free.fr> References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <4ccd7487$0$30068$426a74cc@news.free.fr> Message-ID: <4cd2e3e7$0$1586$742ec2ed@news.sonic.net> On 10/31/2010 6:52 AM, jf wrote: > Le 31/10/2010 13:10, Martin v. Loewis a ?crit : >>> I've a project with tabs and spaces mixed (yes I know it's bad). >>> >>> I edit each file to remove tabs, but it's so easy to make a mistake. >>> Do you know a tools to compare the initial file with the cleaned one to >>> know if the algorithms are the same ? >> >> Tools/scripts/reindent.py of the standard Python distribution normalizes >> white space in source code. > > So great, you save my time ! > Should I be worry about this comment in reindent.py "So long as the > input files get a clean bill of health from tabnanny.py, reindent should > do a good job." ? Are both of those tools consistent with the interpretation of mixed tabs and spaces in Python 3.x? The current CPython parser front end is smart about this. Tabs and spaces can be mixed provided that the semantics of the program do not depend on the width of a tab. This was not the case in early 2.x versions. (When did that go in?) The key to doing this right is to compare the whitespace of an indented line with the line above it. The longer whitespace string must start with the shorter whitespace string, whether it's tabs, spaces, or any combination thereof. If it does not, the indentation is ambiguous. For all unambiguous cases, you can then convert tabs to spaces or vice versa with any number of spaces to tabs, and the semantics of the program will not change. It's not clear whether "tabnanny" or "reindent" have smart semantics like CPython. The documentation doesn't say. If they don't, they should, or it should be documented that they're broken. John Nagle From mdw at distorted.org.uk Thu Nov 4 12:49:32 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 04 Nov 2010 16:49:32 +0000 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87r5f13ug3.fsf.mdw@metalzone.distorted.org.uk> Seebs writes: > Python's the only language I use where an obvious flaw, which is > repeatedly observed by everyone I know who uses the language, is > militantly and stridently defended by dismissing, insulting, and > attacking the character and motives of anyone who suggests that it > might be a bit of a nuisance. So you've not tried Lisp, then? Dissing Lisp's parentheses tends to get a pretty similar reaction. My observations on this general discussion. * Python is far from unique in its use of significant whitespace. Miranda was inferring program structure from indentation in 1985. Haskell and F# are more modern examples. * I don't have many problems with tools trashing whitespace in Python programs, though I have seen web forum software mangling indentation; since this makes nontrivial chunks of almost any programming language illegible, I'm more than willing to blame the forum software for this. I haven't personally seen indentation trashed by email software, for example (though I steer well clear of people who try to send me HTML mail). * I /do/ have a significant problem with cutting and pasting code in Python. In most languages, I can haul a chunk of code about, hit C-M-q, and Emacs magically indents the result properly. This is, unfortunately, impossible with Python. It has caused me real bugs, and I have to be extra careful to fix the indentation up. * I've just noticed that Emacs's Python mode has a magic keystroke which appears to do the right thing for cut-and-pasted code. This is symptomatic of a bigger problem: simply by being different from the mainstream, Python requires that one work with it differently. It requires different tools, and different techniques. Many languages use some kind of brackets to mark substructure, so tools have become good at handling bracketed substructure, whether for automatic indentation or navigation. Python marks (some) substructure differently, so users need to learn new techniques or tools for working with it. I /like/ Python. I use it frequently. I /don't/ want to change its structure marked by indentation. I'm /willing/ to put up with some inconvenience because Python makes up for it in other ways. But there /is/ inconvenience, and it does need putting up with. I think the benefits are worth the costs; others may disagree. -- [mdw], a smug Lisp weenie at heart. From mal at egenix.com Thu Nov 4 12:52:04 2010 From: mal at egenix.com (M.-A. Lemburg) Date: Thu, 04 Nov 2010 17:52:04 +0100 Subject: DateTime object In-Reply-To: <4ccaacd6$0$10750$426a74cc@news.free.fr> References: <4ccaacd6$0$10750$426a74cc@news.free.fr> Message-ID: <4CD2E4B4.7090109@egenix.com> jf wrote: > Hi, > > I've a bug in my code and I'm trying de reproduce it. > > To trace the bug I print arguments, and it produces this: > {'date': } > > My question is: what is: ? > > I use mx.DateTime put if I print it I get: > > > So what kind of object is ? You might be using the old Python implementation of mxDateTime (mx/DateTime/mxDateTime/mxDateTime_Python.py): def __repr__(self): return ""% ( self.year, self.month, self.day, self.hour, self.minute, self.second, id(self)) Note however, that there's no "T" in the string shown for the repr(), so perhaps this is some other implementation. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Nov 04 2010) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new 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 mdw at distorted.org.uk Thu Nov 4 12:57:05 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 04 Nov 2010 16:57:05 +0000 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87mxpp3u3i.fsf.mdw@metalzone.distorted.org.uk> Tim Harig writes: > Python is the only language that I know that *needs* to specify tabs > versus spaces since it is the only language I know of which uses > whitespace formating as part of its syntax and structure. You need to get out more. Miranda, Gofer, Haskell, F#, make(1), and many others, all use indentation to indicate structure; YAML isn't a programming language, but it also uses indentation to indicate structure, as do a number of wiki markup languages; there are also representations of Lisp S-expressions which use indentation instead of parentheses. > Mixed usage may be annoying in other languages; but, it breaks Python. I disagree. The Haskell '98 report specifies (correctly) that tabs are every eight columns, and a tab moves to the next tab stop. Python makes the same specification; it's just the users who actually want to stamp out tabs. Flamebait: it's not the tabs that cause the problem: it's that some people are under the mistaken impression that the position of tab stops in text files is a matter for local preference. -- [mdw] From ndbecker2 at gmail.com Thu Nov 4 13:03:12 2010 From: ndbecker2 at gmail.com (Neal Becker) Date: Thu, 04 Nov 2010 13:03:12 -0400 Subject: sigaction? Message-ID: Why doesn't python signal support sigaction? I'm interested in trying sigaction with SA_RESTART to prevent interrupted system calls. Or, would the usage of SA_RESTART within python cause other problems? From neilc at norwich.edu Thu Nov 4 13:11:52 2010 From: neilc at norwich.edu (Neil Cerutti) Date: 4 Nov 2010 17:11:52 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8jg7qoFhbnU2@mid.individual.net> On 2010-11-04, D'Arcy J.M. Cain wrote: >> * Not being able to write an auto-indenter, ever, because it >> is by design theoretically impossible: Annoying. > > Right. And in C you can never write an auto-bracer for exactly > the same reason. It's not right, actually. Auto-indent is fairly easy in Python. Auto-dedent is the impossible part. -- Neil Cerutti From deets at web.de Thu Nov 4 13:21:44 2010 From: deets at web.de (Diez B. Roggisch) Date: Thu, 04 Nov 2010 18:21:44 +0100 Subject: How find all childrens values of a nested dictionary, fast! References: Message-ID: <87r5f1ypg7.fsf@web.de> macm writes: > Hi Folks > > How find all childrens values of a nested dictionary, fast! There is no faster than O(n) here. > >>>> a = {'a' : {'b' :{'/' :[1,2,3,4], 'ba' :{'/' :[41,42,44]} ,'bc' :{'/':[51,52,54], 'bcd' :{'/':[68,69,66]}}},'c' :{'/' :[5,6,7,8]}}, 'ab' : {'/' :[12,13,14,15]}, 'ac' :{'/' :[21,22,23]}} >>>> a['a'] > {'c': {'/': [5, 6, 7, 8]}, 'b': {'ba': {'/': [41, 42, 44]}, '/': [1, > 2, 3, 4], 'bc': {'bcd': {'/': [68, 69, 66]}, '/': [51, 52, 54]}}} >>>> a['a']['b'] > {'ba': {'/': [41, 42, 44]}, '/': [1, 2, 3, 4], 'bc': {'bcd': {'/': > [68, 69, 66]}, '/': [51, 52, 54]}} >>>> a['a']['b'].values() > [{'/': [41, 42, 44]}, [1, 2, 3, 4], {'bcd': {'/': [68, 69, 66]}, '/': > [51, 52, 54]}] > > Now I want find all values of key "/" > > Desire result is [41, 42, 44, 1, 2, 3, 4, 68, 69, 66, 51, 52, 54] a = {'a' : {'b' :{'/' :[1,2,3,4], 'ba' :{'/' :[41,42,44]} ,'bc' :{'/':[51,52,54], 'bcd' :{'/':[68,69,66]}}},'c' :{'/' :[5,6,7,8]}}, 'ab' : {'/' :[12,13,14,15]}, 'ac' :{'/' :[21,22,23]}} def f(d): if "/" in d: for v in d["/"]: yield v for value in d.values(): if isinstance(value, dict): for v in f(value): yield v print list(f(a)) But that gives me a different result: [5, 6, 7, 8, 1, 2, 3, 4, 41, 42, 44, 51, 52, 54, 68, 69, 66, 21, 22, 23, 12, 13, 14, 15] Why don't you expect e.g. 23 in your output? Diez From __peter__ at web.de Thu Nov 4 13:26:03 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 04 Nov 2010 18:26:03 +0100 Subject: How find all childrens values of a nested dictionary, fast! References: Message-ID: macm wrote: > How find all childrens values of a nested dictionary, fast! > >>>> a = {'a' : {'b' :{'/' :[1,2,3,4], 'ba' :{'/' :[41,42,44]} ,'bc' >>>> :{'/':[51,52,54], 'bcd' :{'/':[68,69,66]}}},'c' :{'/' :[5,6,7,8]}}, >>>> 'ab' : {'/' :[12,13,14,15]}, 'ac' :{'/' :[21,22,23]}} a['a'] > {'c': {'/': [5, 6, 7, 8]}, 'b': {'ba': {'/': [41, 42, 44]}, '/': [1, > 2, 3, 4], 'bc': {'bcd': {'/': [68, 69, 66]}, '/': [51, 52, 54]}}} >>>> a['a']['b'] > {'ba': {'/': [41, 42, 44]}, '/': [1, 2, 3, 4], 'bc': {'bcd': {'/': > [68, 69, 66]}, '/': [51, 52, 54]}} >>>> a['a']['b'].values() > [{'/': [41, 42, 44]}, [1, 2, 3, 4], {'bcd': {'/': [68, 69, 66]}, '/': > [51, 52, 54]}] > > Now I want find all values of key "/" > > Desire result is [41, 42, 44, 1, 2, 3, 4, 68, 69, 66, 51, 52, 54] > > I am trying map, reduce, lambda. Hmm, I'm trying none of these and get a different result: >>> def f(d): ... stack = [d.iteritems()] ... while stack: ... for k, v in stack[-1]: ... if k == "/": ... yield v ... else: ... stack.append(v.iteritems()) ... break ... else: ... stack.pop() ... >>> b = [] >>> for v in f(a): ... b.extend(v) ... >>> b [5, 6, 7, 8, 41, 42, 44, 1, 2, 3, 4, 68, 69, 66, 51, 52, 54, 21, 22, 23, 12, 13, 14, 15] What am I missing? Peter From invalid at invalid.invalid Thu Nov 4 13:27:51 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 4 Nov 2010 17:27:51 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> Message-ID: On 2010-11-04, Neil Cerutti wrote: > On 2010-11-04, D'Arcy J.M. Cain wrote: >>> * Not being able to write an auto-indenter, ever, because it >>> is by design theoretically impossible: Annoying. >> >> Right. And in C you can never write an auto-bracer for exactly >> the same reason. > > It's not right, actually. Auto-indent is fairly easy in > Python. Auto-dedent is the impossible part. I think in common usage the term "auto-intender" refers to a program that can automatically control source indentation (which inclulde both "indenting" and "dindenting" source lines). -- Grant Edwards grant.b.edwards Yow! I'm having BEAUTIFUL at THOUGHTS about the INSIPID gmail.com WIVES of smug and wealthy CORPORATE LAWYERS ... From python at mrabarnett.plus.com Thu Nov 4 13:32:21 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 04 Nov 2010 17:32:21 +0000 Subject: Compare source code In-Reply-To: <87r5f13ug3.fsf.mdw@metalzone.distorted.org.uk> References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <87r5f13ug3.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <4CD2EE25.1010008@mrabarnett.plus.com> On 04/11/2010 16:49, Mark Wooding wrote: > Seebs writes: > >> Python's the only language I use where an obvious flaw, which is >> repeatedly observed by everyone I know who uses the language, is >> militantly and stridently defended by dismissing, insulting, and >> attacking the character and motives of anyone who suggests that it >> might be a bit of a nuisance. > > So you've not tried Lisp, then? Dissing Lisp's parentheses tends to get > a pretty similar reaction. > > My observations on this general discussion. > > * Python is far from unique in its use of significant whitespace. > Miranda was inferring program structure from indentation in 1985. > Haskell and F# are more modern examples. > occam was doing it in 1983. > * I don't have many problems with tools trashing whitespace in Python > programs, though I have seen web forum software mangling > indentation; since this makes nontrivial chunks of almost any > programming language illegible, I'm more than willing to blame the > forum software for this. I haven't personally seen indentation > trashed by email software, for example (though I steer well clear of > people who try to send me HTML mail). > If you don't use
 ... 
or some such then any programming language is going to look bad! [snip] From ppearson at nowhere.invalid Thu Nov 4 13:32:54 2010 From: ppearson at nowhere.invalid (Peter Pearson) Date: 4 Nov 2010 17:32:54 GMT Subject: What people are using to access this mailing list References: Message-ID: <8jg925FjpmU1@mid.individual.net> On Wed, 3 Nov 2010 08:02:29 +0000 (UTC), John Bond wrote: > Hope this isn't too O/T - I was just wondering how people read/send to this > mailing list, eg. normal email client, gmane, some other software or online > service? Usenet via a server at news.individual.net, newsgroup name comp.lang.python, client slrn. -- To email me, substitute nowhere->spamcop, invalid->net. From emile at fenx.com Thu Nov 4 13:36:04 2010 From: emile at fenx.com (Emile van Sebille) Date: Thu, 04 Nov 2010 10:36:04 -0700 Subject: Compare source code In-Reply-To: <8jftftFelnU1@mid.individual.net> References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jftftFelnU1@mid.individual.net> Message-ID: On 11/4/2010 7:15 AM Neil Cerutti said... > The handsome ':' terminator of if/elif/if statements allows us to > omit a newline, conserving vertical space. This improves the > readability of certain constructs. > > if x: print(x) > elif y: print(y) > else: print() > Analogously, x+=1;y=f(x);return We don't have to eliminate ':'s. Emile From usernet at ilthio.net Thu Nov 4 13:45:58 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 4 Nov 2010 17:45:58 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <87mxpp3u3i.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On 2010-11-04, Mark Wooding wrote: > Tim Harig writes: > >> Python is the only language that I know that *needs* to specify tabs >> versus spaces since it is the only language I know of which uses >> whitespace formating as part of its syntax and structure. > > You need to get out more. Miranda, Gofer, Haskell, F#, make(1), and I have never heard of Gofer. I have heard the name Miranda and I know that it is a (purely?) functional language; but, that is all that I know. I took a cursory look at Haskell a while back; but, I ultimately chose to learn Erlang instead as its error management constructs had real world application for me. I also looked at F# and Scala; but, neither are really applicable on my chosen platform. With F# being such a new language, I suspect that it borrowed its indent practices either from Haskell or from Python. I already introduced the make tab oriented syntax and Seebs has labeled it as a major anti-pattern. I am also aware of other langauges such as Boo; but, I don't really consider them individually relevant to the conversation as they are explicitly using a Python based syntax. For this discussion I merely group them with Python. >> Mixed usage may be annoying in other languages; but, it breaks Python. > > I disagree. The Haskell '98 report specifies (correctly) that tabs are > every eight columns, and a tab moves to the next tab stop. Python makes > the same specification; it's just the users who actually want to stamp > out tabs. So, your telling me that mixing tabs and spaces is considered a good practice in Haskell? No, mixing tabs and spaces in Python isn't illegal; but, I have never seen good outcomes from doing so. No matter how you define a tab, most people do not have their editor configured to show them the difference between a tab stop and the equivilant number of spaces. I have never experienced ill effects from using tabs alone. > Flamebait: it's not the tabs that cause the problem: it's that some > people are under the mistaken impression that the position of tab stops > in text files is a matter for local preference. I would argue that text files do not have tab stops -- text editors do. So long as you use tabs for all of your indenting, it is quite safe to set the editors tab stops however one likes since the editor's tab stop doesn't effect the output of the file. That way, everybody can edit their code using an apparent indent level that is comfortable for them without being disruptive to the code. It is a win-win situation for everybody. From usernet at ilthio.net Thu Nov 4 13:55:55 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 4 Nov 2010 17:55:55 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> Message-ID: On 2010-11-04, Neil Cerutti wrote: > On 2010-11-04, D'Arcy J.M. Cain wrote: Seebs Wrote: >>> * Not being able to write an auto-indenter, ever, because it >>> is by design theoretically impossible: Annoying. >> >> Right. And in C you can never write an auto-bracer for exactly >> the same reason. > > It's not right, actually. Auto-indent is fairly easy in > Python. Auto-dedent is the impossible part. What Seebs is refering to is that it is difficult or impossible to re-indent Python source automatically after the indent structure has been broken (such as his email being converted to html on the server or a web forum without the possibility of
 or [code] tags).  When C becomes
so obfiscated, you can run it through indent to recover the structure of
the source to something that you are familiar with (I actually think macros
could cause problems; but, Seebs has already admitted weaknesses in the C
preprocessor.).  The same is not always true for Python where information
about the code structure may be destroyed.


From moura.mario at gmail.com  Thu Nov  4 13:56:00 2010
From: moura.mario at gmail.com (macm)
Date: Thu, 4 Nov 2010 10:56:00 -0700 (PDT)
Subject: How find all childrens values of a nested dictionary, fast!
References: 
	
Message-ID: <80f5fd35-4689-4d5d-9937-8641992e4c40@k30g2000vbn.googlegroups.com>

Hi Folks

Thanks a lot

Script from Diez works:

print list(f(a))

but should be

print list(f(a['a']['b']))

to fit my example.



About Peter script

I am receiving

>>> for v in f(a['a']['b']):
...     b.extend(v)
...
Traceback (most recent call last):
  File "", line 2, in 
TypeError: 'int' object is not iterable

I am trying understand this error.

Best Regards and thanks a lot again!

Mario
macm






On 4 nov, 15:26, Peter Otten <__pete... at web.de> wrote:
> macm wrote:
> > How find all childrens values of a nested dictionary, fast!
>
> >>>> a = {'a' : {'b' :{'/' :[1,2,3,4], 'ba' :{'/' :[41,42,44]} ,'bc'
> >>>> :{'/':[51,52,54], 'bcd' :{'/':[68,69,66]}}},'c' :{'/' :[5,6,7,8]}},
> >>>> 'ab' : {'/' :[12,13,14,15]}, 'ac' :{'/' :[21,22,23]}} a['a']
> > {'c': {'/': [5, 6, 7, 8]}, 'b': {'ba': {'/': [41, 42, 44]}, '/': [1,
> > 2, 3, 4], 'bc': {'bcd': {'/': [68, 69, 66]}, '/': [51, 52, 54]}}}
> >>>> a['a']['b']
> > {'ba': {'/': [41, 42, 44]}, '/': [1, 2, 3, 4], 'bc': {'bcd': {'/':
> > [68, 69, 66]}, '/': [51, 52, 54]}}
> >>>> a['a']['b'].values()
> > [{'/': [41, 42, 44]}, [1, 2, 3, 4], {'bcd': {'/': [68, 69, 66]}, '/':
> > [51, 52, 54]}]
>
> > Now I want find all values of key "/"
>
> > Desire result is [41, 42, 44, 1, 2, 3, 4, 68, 69, 66, 51, 52, 54]
>
> > I am trying map, reduce, lambda.
>
> Hmm, I'm trying none of these and get a different result:
>
> >>> def f(d):
>
> ... ? ? stack = [d.iteritems()]
> ... ? ? while stack:
> ... ? ? ? ? ? ? for k, v in stack[-1]:
> ... ? ? ? ? ? ? ? ? ? ? if k == "/":
> ... ? ? ? ? ? ? ? ? ? ? ? ? ? ? yield v
> ... ? ? ? ? ? ? ? ? ? ? else:
> ... ? ? ? ? ? ? ? ? ? ? ? ? ? ? stack.append(v.iteritems())
> ... ? ? ? ? ? ? ? ? ? ? ? ? ? ? break
> ... ? ? ? ? ? ? else:
> ... ? ? ? ? ? ? ? ? ? ? stack.pop()
> ...>>> b = []
> >>> for v in f(a):
>
> ... ? ? b.extend(v)
> ...>>> b
>
> [5, 6, 7, 8, 41, 42, 44, 1, 2, 3, 4, 68, 69, 66, 51, 52, 54, 21, 22, 23, 12,
> 13, 14, 15]
>
> What am I missing?
>
> Peter



From usernet at ilthio.net  Thu Nov  4 13:58:51 2010
From: usernet at ilthio.net (Tim Harig)
Date: Thu, 4 Nov 2010 17:58:51 +0000 (UTC)
Subject: Compare source code
References: <4ccd5ad9$0$19151$426a74cc@news.free.fr>
	 <8j8am4Fk2jU1@mid.individual.net>
	 
	
	<4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com>
	
	
	<4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com>
	
	<4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com>
	
	<87r5f13ug3.fsf.mdw@metalzone.distorted.org.uk>
	
Message-ID: 

On 2010-11-04, MRAB  wrote:
> On 04/11/2010 16:49, Mark Wooding wrote:
>> Seebs  writes:
>>    * I don't have many problems with tools trashing whitespace in Python
>>      programs, though I have seen web forum software mangling
>>      indentation; since this makes nontrivial chunks of almost any
>>      programming language illegible, I'm more than willing to blame the
>>      forum software for this.  I haven't personally seen indentation
>>      trashed by email software, for example (though I steer well clear of
>>      people who try to send me HTML mail).
>>
> If you don't use 
 ... 
or some such then any programming > language is going to look bad! Looking bad and being unrecoverable are two different things. From moura.mario at gmail.com Thu Nov 4 14:01:54 2010 From: moura.mario at gmail.com (macm) Date: Thu, 4 Nov 2010 11:01:54 -0700 (PDT) Subject: How find all childrens values of a nested dictionary, fast! References: <80f5fd35-4689-4d5d-9937-8641992e4c40@k30g2000vbn.googlegroups.com> Message-ID: <7a75c991-5186-4746-8c29-e368673eda74@u10g2000yqk.googlegroups.com> Peter Ok! Both works fine! Thanks a lot! >>> for v in f(a['a']['b']): ... b.extend(v) b Now I will try find which script is the fast! Regards macm On 4 nov, 15:56, macm wrote: > Hi Folks > > Thanks a lot > > Script from Diez works: > > print list(f(a)) > > but should be > > print list(f(a['a']['b'])) > > to fit my example. > > About Peter script > > I am receiving > > >>> for v in f(a['a']['b']): > > ... ? ? b.extend(v) > ... > Traceback (most recent call last): > ? File "", line 2, in > TypeError: 'int' object is not iterable > > I am trying understand this error. > > Best Regards and thanks a lot again! > > Mario > macm > > On 4 nov, 15:26, Peter Otten <__pete... at web.de> wrote: > > > macm wrote: > > > How find all childrens values of a nested dictionary, fast! > > > >>>> a = {'a' : {'b' :{'/' :[1,2,3,4], 'ba' :{'/' :[41,42,44]} ,'bc' > > >>>> :{'/':[51,52,54], 'bcd' :{'/':[68,69,66]}}},'c' :{'/' :[5,6,7,8]}}, > > >>>> 'ab' : {'/' :[12,13,14,15]}, 'ac' :{'/' :[21,22,23]}} a['a'] > > > {'c': {'/': [5, 6, 7, 8]}, 'b': {'ba': {'/': [41, 42, 44]}, '/': [1, > > > 2, 3, 4], 'bc': {'bcd': {'/': [68, 69, 66]}, '/': [51, 52, 54]}}} > > >>>> a['a']['b'] > > > {'ba': {'/': [41, 42, 44]}, '/': [1, 2, 3, 4], 'bc': {'bcd': {'/': > > > [68, 69, 66]}, '/': [51, 52, 54]}} > > >>>> a['a']['b'].values() > > > [{'/': [41, 42, 44]}, [1, 2, 3, 4], {'bcd': {'/': [68, 69, 66]}, '/': > > > [51, 52, 54]}] > > > > Now I want find all values of key "/" > > > > Desire result is [41, 42, 44, 1, 2, 3, 4, 68, 69, 66, 51, 52, 54] > > > > I am trying map, reduce, lambda. > > > Hmm, I'm trying none of these and get a different result: > > > >>> def f(d): > > > ... ? ? stack = [d.iteritems()] > > ... ? ? while stack: > > ... ? ? ? ? ? ? for k, v in stack[-1]: > > ... ? ? ? ? ? ? ? ? ? ? if k == "/": > > ... ? ? ? ? ? ? ? ? ? ? ? ? ? ? yield v > > ... ? ? ? ? ? ? ? ? ? ? else: > > ... ? ? ? ? ? ? ? ? ? ? ? ? ? ? stack.append(v.iteritems()) > > ... ? ? ? ? ? ? ? ? ? ? ? ? ? ? break > > ... ? ? ? ? ? ? else: > > ... ? ? ? ? ? ? ? ? ? ? stack.pop() > > ...>>> b = [] > > >>> for v in f(a): > > > ... ? ? b.extend(v) > > ...>>> b > > > [5, 6, 7, 8, 41, 42, 44, 1, 2, 3, 4, 68, 69, 66, 51, 52, 54, 21, 22, 23, 12, > > 13, 14, 15] > > > What am I missing? > > > Peter > > From __peter__ at web.de Thu Nov 4 14:09:13 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 04 Nov 2010 19:09:13 +0100 Subject: How find all childrens values of a nested dictionary, fast! References: <80f5fd35-4689-4d5d-9937-8641992e4c40@k30g2000vbn.googlegroups.com> Message-ID: macm wrote: > About Peter script > > I am receiving > >>>> for v in f(a['a']['b']): > ... b.extend(v) > ... > Traceback (most recent call last): > File "", line 2, in > TypeError: 'int' object is not iterable > > I am trying understand this error. You are probably mixing Diez' implementation of f() with my invocation code. Or you have modified the input data and now it contains int values. Peter From mdw at distorted.org.uk Thu Nov 4 14:09:47 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 04 Nov 2010 18:09:47 +0000 Subject: Allow multiline conditions and the like References: <4cce7196$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87iq0d3qqc.fsf.mdw@metalzone.distorted.org.uk> Chris Rebert writes: > Or, if possible, refactor the conditional into a function (call) so > it's no longer multiline in the first place. No! This /increases/ cognitive load for readers, because they have to deal with the indirection through the name. If you actually use the function multiple times, the mental overhead of forming the abstraction and associating it with the function name is shared across the various call sites and it's probably worth it. If it's only called once, leave it inline. -- [mdw] From neilc at norwich.edu Thu Nov 4 14:18:28 2010 From: neilc at norwich.edu (Neil Cerutti) Date: 4 Nov 2010 18:18:28 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> Message-ID: <8jgbnkF8q1U1@mid.individual.net> On 2010-11-04, Grant Edwards wrote: > On 2010-11-04, Neil Cerutti wrote: >> On 2010-11-04, D'Arcy J.M. Cain wrote: >>>> * Not being able to write an auto-indenter, ever, because it >>>> is by design theoretically impossible: Annoying. >>> >>> Right. And in C you can never write an auto-bracer for >>> exactly the same reason. >> >> It's not right, actually. Auto-indent is fairly easy in >> Python. Auto-dedent is the impossible part. > > I think in common usage the term "auto-intender" refers to a > program that can automatically control source indentation > (which inclulde both "indenting" and "dindenting" source > lines). Thanks for the correction. Autoindent doesn't mean that to me (I'm a vi user), but I should have figured out what he meant from the context. -- Neil Cerutti From darcy at druid.net Thu Nov 4 14:39:04 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Thu, 4 Nov 2010 14:39:04 -0400 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> Message-ID: <20101104143904.f2ac4a5e.darcy@druid.net> On Thu, 4 Nov 2010 17:55:55 +0000 (UTC) Tim Harig wrote: > What Seebs is refering to is that it is difficult or impossible to > re-indent Python source automatically after the indent structure has been > broken (such as his email being converted to html on the server or a web Right. If you mangle spaces in Python or mangle braces in C then recovery becomes impossible. I don't think anyone is contesting that. What we question is the idea that somehow Python is special in this regard. If you move files around in ways that change them then your tools are broken. The fact that the breakage is somewhat "friendlier" to some types of files is interesting but irrelevant. What would you say to a file transfer program that changed Word documents? What about executable files? -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From mdw at distorted.org.uk Thu Nov 4 14:48:05 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 04 Nov 2010 18:48:05 +0000 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <87mxpp3u3i.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <87aalp3oyi.fsf.mdw@metalzone.distorted.org.uk> Tim Harig writes: > So, your telling me that mixing tabs and spaces is considered a good > practice in Haskell? It doesn't seem to be a matter which is discussed much. I think Haskell programmers are used to worrying their brains with far more complicated things like wobbly[1] types. > I would argue that text files do not have tab stops -- text editors > do. So long as you use tabs for all of your indenting, it is quite > safe to set the editors tab stops however one likes since the editor's > tab stop doesn't effect the output of the file. This is wishful thinking. Firstly, code written with a narrow indentation offset (e.g., two spaces) can take up an uncomfortable width when viewed with a wider offset. Secondly, if you want other parts (e.g., per-line comments) of lines with different indentations to align, then you'll have to take into account the tab width. Technically, you could arrange that between any pair of alignment points of any pair of lines there are the same number of tab characters; but this is also doomed to uncomfortably wide lines; it also suffers because it imposes an /a priori/ upper bound on the indentation level. [1] Proper technical term. I kid you not. -- [mdw] From moura.mario at gmail.com Thu Nov 4 14:48:28 2010 From: moura.mario at gmail.com (macm) Date: Thu, 4 Nov 2010 11:48:28 -0700 (PDT) Subject: How convert list to nested dictionary? Message-ID: <940876cd-2546-4673-aef4-ba11b4156287@fv1g2000vbb.googlegroups.com> Hi Folks How convert list to nested dictionary? >>> l ['k1', 'k2', 'k3', 'k4', 'k5'] >>> result {'k1': {'k2': {'k3': {'k4': {'k5': {}}}}}} Regards macm From clp2 at rebertia.com Thu Nov 4 14:53:36 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 4 Nov 2010 11:53:36 -0700 Subject: How convert list to nested dictionary? In-Reply-To: <940876cd-2546-4673-aef4-ba11b4156287@fv1g2000vbb.googlegroups.com> References: <940876cd-2546-4673-aef4-ba11b4156287@fv1g2000vbb.googlegroups.com> Message-ID: On Thu, Nov 4, 2010 at 11:48 AM, macm wrote: > Hi Folks > > How convert list to nested dictionary? > >>>> l > ['k1', 'k2', 'k3', 'k4', 'k5'] >>>> result > {'k1': {'k2': {'k3': {'k4': {'k5': {}}}}}} We don't do homework. Hint: Iterate through the list in reverse order, building up your result. Using reduce() is one option. Cheers, Chris From nad at acm.org Thu Nov 4 15:12:01 2010 From: nad at acm.org (Ned Deily) Date: Thu, 04 Nov 2010 12:12:01 -0700 Subject: Best method for a menu in a command line program? References: <87wrotfhj2.fsf@benfinney.id.au> Message-ID: In article <87wrotfhj2.fsf at benfinney.id.au>, Ben Finney wrote: > brf256 at gmail.com writes: > > Thanks again, > > Braden Faulkner > > > > Sent wirelessly from my BlackBerry device on the Bell network. > > Envoy? sans fil par mon terminal mobile BlackBerry sur le r?seau de Bell. > > Please show your thanks by *not* spamming the forum with each message; > compose your messages from a mail client that doesn't feel the need to > blather about itself in the message body. > > -- > \ ?For fast acting relief, try slowing down.? ?Jane Wagner, via | > `\ Lily Tomlin | > _o__) | > Ben Finney If I were a rude person, I might observe that "spamming" is relative: some who obsess about "spam" might consider 2 lines less of an evil than 5 lines. But I'm not, so I won't. -- Ned Deily, nad at acm.org From mdw at distorted.org.uk Thu Nov 4 15:16:56 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 04 Nov 2010 19:16:56 +0000 Subject: Man pages and info pages References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> <024ef21a-9ef9-48a6-8372-1d66895583c3@v16g2000yqn.googlegroups.com> <87zktr5yze.fsf_-_@mithlond.arda> <877hgv2fg3.fsf@mithlond.arda> Message-ID: <8762wc526v.fsf.mdw@metalzone.distorted.org.uk> Tim Harig writes: > When the GNU folk decided to clone *nix they decided that they knew > better and simply decided to create their own interfaces. This isn't the case. Actually Info has a long history prior to GNU: it was the way that the documentation was presented at the MIT AI lab. In fact, Info was used rather like a modern wiki. The operating system they used, called ITS, didn't have a concept of file permissions, and users were encouraged to improve documentation (and programs). The original Info viewer was implemented in Emacs (which also originated in ITS, years before GNU). Texinfo was a GNU innovation: the idea that you could build both the Info document and a nice printable manual from a single source was novel, as was the application to Unix. But, since Stallman was documenting large software systems like Emacs and GCC, it doesn't seem unreasonable to provide manuals which are somewhat more discursive and leisurely than traditional Unix manpages. I have a printed copy of the GNU Emacs 18 manual (from 1987): it's almost 300 pages long. The modern manual for Emacs 23 is several /times/ larger than this. Man pages don't scale that well. I do agree it's annoying that the official coreutils documentation is in Texinfo. > Actually, the left arrow key does not work at all intuitively. One > would expect that it should go back to the previous page as it would > in lynx, etc. It does not. It moves the cursor so you can hit links. The l key takes you back through your recent viewing history -- and has done for thirty years. > By tradition 'n' and 'p' are broken for scrolling in a page. 'b' is > often used in place of p but that seems to take one back to the top of > the page. Space and backspace are an older tradition. > The s key for a search is another example that has already been > discussed. I find C-s more useful in Info, because it searches interactively. I frequently get muddled when I try to search in `modern' programs like web browsers, because they've gratuitously made C-s try to save the page (something one hardly ever wants to do) rather than search. (Finding is different: finding is what happens at the end of a /successful/ search. So C-f is poorly chosen.) -- [mdw] From nad at acm.org Thu Nov 4 15:23:28 2010 From: nad at acm.org (Ned Deily) Date: Thu, 04 Nov 2010 12:23:28 -0700 Subject: Compiling/Installing Python 2.7 on OSX 10.6 References: <3d9139ae-bd6f-4567-bb02-b21a8ba86e50@o15g2000prh.googlegroups.com> Message-ID: In article <3d9139ae-bd6f-4567-bb02-b21a8ba86e50 at o15g2000prh.googlegroups.com>, Jeremy wrote: > I'm having trouble installing Python 2.7 on OSX 10.6 I was able to > successfully compile it from source, but ran into problems when I did > make install. The error I got (I received many similar errors) was: > > /usr/bin/install -c -m 644 ../LICENSE /home/jlconlin/Library/ > Frameworks/Python.framework/Versions/2.7/lib/python2.7/LICENSE.txt > PYTHONPATH=/home/jlconlin/Library/Frameworks/Python.framework/Versions/ > 2.7/lib/python2.7 DYLD_FRAMEWORK_PATH=/home/jlconlin/src/Python-2.7/ > build: \ > ./python -Wi -tt /home/jlconlin/Library/Frameworks/Python.framework/ > Versions/2.7/lib/python2.7/compileall.py \ > -d /home/jlconlin/Library/Frameworks/Python.framework/Versions/2.7/ > lib/python2.7 -f \ > -x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \ > /home/jlconlin/Library/Frameworks/Python.framework/Versions/2.7/lib/ > python2.7 > Listing /home/jlconlin/Library/Frameworks/Python.framework/Versions/ > 2.7/lib/python2.7 ... > Compiling /home/jlconlin/Library/Frameworks/Python.framework/Versions/ > 2.7/lib/python2.7/._BaseHTTPServer.py ... > Sorry: TypeError: ('compile() expected string without null bytes',) > Compiling /home/jlconlin/Library/Frameworks/Python.framework/Versions/ > 2.7/lib/python2.7/._Bastion.py ... > Sorry: TypeError: ('compile() expected string without null bytes',) > Compiling /home/jlconlin/Library/Frameworks/Python.framework/Versions/ > 2.7/lib/python2.7/._CGIHTTPServer.py ... > Sorry: TypeError: ('compile() expected string without null bytes',) How did you obtain and unpack the source? It looks like you used something that created the old-style "._" hidden forks when extracting the source. The path names look a little suspicious, too: /home/jlconlin. What file system type are these files on? You shouldn't run into problems if you use an HFS+ file system (for instance) and extract the tarball from the command line using /usr/bin/tar. > PS. Python compiled correctly, but a few modules were not found/made > but I don't think they are important. > > Python build finished, but the necessary bits to build these modules > were not found: > _bsddb dl gdbm > imageop linuxaudiodev ossaudiodev > spwd sunaudiodev Yes, all of those are to be expected on an OS X 64-bit build. -- Ned Deily, nad at acm.org From usernet at ilthio.net Thu Nov 4 15:25:30 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 4 Nov 2010 19:25:30 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <87mxpp3u3i.fsf.mdw@metalzone.distorted.org.uk> <87aalp3oyi.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On 2010-11-04, Mark Wooding wrote: > Tim Harig writes: > This is wishful thinking. Firstly, code written with a narrow > indentation offset (e.g., two spaces) can take up an uncomfortable width > when viewed with a wider offset. I can accept that as a trade-off. People have different ideas about acceptable column width anyway. I use 8 space tab stops and target to no more then 80 columns. If somebody uses 2 space tab stops, its going to go over the 80 columns a little bit; but, not so much as cause a major issue. > Secondly, if you want other parts (e.g., per-line comments) of lines > with different indentations to align, then you'll have to take into > account the tab width. Technically, you could arrange that between any > pair of alignment points of any pair of lines there are the same number > of tab characters; but this is also doomed to uncomfortably wide lines; > it also suffers because it imposes an /a priori/ upper bound on the > indentation level. I use simple comments that are not effected by white space. I don't waste my time trying to make comments look artistic. They are there to convey information; not to look pretty. I really detest having to edit other peoples comment formatting where you have to re-align everything if the length of any of comment lines change. From jlconlin at gmail.com Thu Nov 4 15:33:04 2010 From: jlconlin at gmail.com (Jeremy) Date: Thu, 4 Nov 2010 12:33:04 -0700 (PDT) Subject: Compiling/Installing Python 2.7 on OSX 10.6 References: <3d9139ae-bd6f-4567-bb02-b21a8ba86e50@o15g2000prh.googlegroups.com> Message-ID: <238cec6d-2f47-4c97-8941-e28e6808946c@a9g2000pro.googlegroups.com> On Nov 4, 1:23?pm, Ned Deily wrote: > In article > <3d9139ae-bd6f-4567-bb02-b21a8ba86... at o15g2000prh.googlegroups.com>, > > > > > > ?Jeremy wrote: > > I'm having trouble installing Python 2.7 on OSX 10.6 ?I was able to > > successfully compile it from source, but ran into problems when I did > > make install. ?The error I got (I received many similar errors) was: > > > /usr/bin/install -c -m 644 ../LICENSE /home/jlconlin/Library/ > > Frameworks/Python.framework/Versions/2.7/lib/python2.7/LICENSE.txt > > PYTHONPATH=/home/jlconlin/Library/Frameworks/Python.framework/Versions/ > > 2.7/lib/python2.7 ?DYLD_FRAMEWORK_PATH=/home/jlconlin/src/Python-2.7/ > > build: \ > > ? ? ? ? ? ?./python -Wi -tt /home/jlconlin/Library/Frameworks/Python.framework/ > > Versions/2.7/lib/python2.7/compileall.py \ > > ? ? ? ? ? ?-d /home/jlconlin/Library/Frameworks/Python.framework/Versions/2.7/ > > lib/python2.7 -f \ > > ? ? ? ? ? ?-x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \ > > ? ? ? ? ? ?/home/jlconlin/Library/Frameworks/Python.framework/Versions/2.7/lib/ > > python2.7 > > Listing /home/jlconlin/Library/Frameworks/Python.framework/Versions/ > > 2.7/lib/python2.7 ... > > Compiling /home/jlconlin/Library/Frameworks/Python.framework/Versions/ > > 2.7/lib/python2.7/._BaseHTTPServer.py ... > > Sorry: TypeError: ('compile() expected string without null bytes',) > > Compiling /home/jlconlin/Library/Frameworks/Python.framework/Versions/ > > 2.7/lib/python2.7/._Bastion.py ... > > Sorry: TypeError: ('compile() expected string without null bytes',) > > Compiling /home/jlconlin/Library/Frameworks/Python.framework/Versions/ > > 2.7/lib/python2.7/._CGIHTTPServer.py ... > > Sorry: TypeError: ('compile() expected string without null bytes',) > > How did you obtain and unpack the source? ?It looks like you used > something that created the old-style "._" hidden forks when extracting > the source. ? I downloaded the source from python.org and extracted with 'tar -xzvf Python-2.7.tgz' My home space is on some network somewhere. I think the network filesystem creates the ._ at the beginning of the files. It's really quite annoying. > The path names look a little suspicious, too: > /home/jlconlin. ?What file system type are these files on? ?You > shouldn't run into problems if you use an HFS+ file system (for > instance) and extract the tarball from the command line using > /usr/bin/tar. I am intentionally installing in my home directory (i.e., /home/ jlconlin) because I don't have access to /usr/local. Supposedly this is possible, and in fact common. > > > PS. Python compiled correctly, but a few modules were not found/made > > but I don't think they are important. > > > Python build finished, but the necessary bits to build these modules > > were not found: > > _bsddb ? ? ? ? ? ? dl ? ? ? ? ? ? ? ? gdbm > > imageop ? ? ? ? ? ?linuxaudiodev ? ? ?ossaudiodev > > spwd ? ? ? ? ? ? ? sunaudiodev > > Yes, all of those are to be expected on an OS X 64-bit build. Is it safe to ignore these modules then? Thanks, Jeremy From usernet at ilthio.net Thu Nov 4 15:37:25 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 4 Nov 2010 19:37:25 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> Message-ID: On 2010-11-04, D'Arcy J.M. Cain wrote: > On Thu, 4 Nov 2010 17:55:55 +0000 (UTC) > Tim Harig wrote: >> What Seebs is refering to is that it is difficult or impossible to >> re-indent Python source automatically after the indent structure has been >> broken (such as his email being converted to html on the server or a web > > Right. If you mangle spaces in Python or mangle braces in C then > recovery becomes impossible. I don't think anyone is contesting that. Examples of communication channels that mangle white space abound. I don't know of any that mangle either braces or pascal style start/end blocks. You are the one who seems to be on a crusade against against braces. It would seem to me, that if you want people to accept that white space formatting is superior, that you would be looking for a simple way to solve the white space mangling problem. > What we question is the idea that somehow Python is special in this > regard. If you move files around in ways that change them then your > tools are broken. The fact that the breakage is somewhat "friendlier" The world is full of broken tools that many of us have to use; but, why should we accept that your choice is superior when other choices manage to work with these tools without issues. > tools are broken. The fact that the breakage is somewhat "friendlier" > to some types of files is interesting but irrelevant. What would you > say to a file transfer program that changed Word documents? What about > executable files? Transfering binary programs has always been an issue and using text based communications (preferably human readable) has always been considered a good design decision. I put up with Python's white space idiosyncrasies; I wouldn't even bother looking at a language that requires me to enter the source in binary. I also consider the move toward XML based document formats a move in the right direction. From nad at acm.org Thu Nov 4 15:41:53 2010 From: nad at acm.org (Ned Deily) Date: Thu, 04 Nov 2010 12:41:53 -0700 Subject: Final state of underlying sequence in islice References: Message-ID: In article , Shashank Singh wrote: > Are there any promises made with regard to final state of the underlying > sequence that islice slices? [...] > While "fixing" this should be rather easy in terms of the change in code > required it might break any code depending > on this seemingly incorrect behavior. I suggest you open an issue at http://bugs.python.org/. -- Ned Deily, nad at acm.org From invalid at invalid.invalid Thu Nov 4 15:46:28 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 4 Nov 2010 19:46:28 +0000 (UTC) Subject: Best method for a menu in a command line program? References: <87wrotfhj2.fsf@benfinney.id.au> Message-ID: On 2010-11-04, Ned Deily wrote: > Ben Finney wrote: >> brf256 at gmail.com writes: >> > Thanks again, >> > Braden Faulkner >> > >> > Sent wirelessly from my BlackBerry device on the Bell network. >> > Envoy?? sans fil par mon terminal mobile BlackBerry sur le r??seau de Bell. >> >> Please show your thanks by *not* spamming the forum with each message; >> compose your messages from a mail client that doesn't feel the need to >> blather about itself in the message body. >> >> -- >> \ ???For fast acting relief, try slowing down.??? ???Jane Wagner, via | >> `\ Lily Tomlin | >> _o__) | >> Ben Finney > > If I were a rude person, I might observe that "spamming" is relative: > some who obsess about "spam" might consider 2 lines less of an evil than > 5 lines. > > But I'm not, so I won't. I must admit that I sympathise with Ben: I find those "sent from my iphone/blackberry" lines exruciatingly annoying, and I'm not really sure why. They waste less space than my (or Ben's) sig, and actually do convey some sort of (pointless) information -- unlike randomly chosen Zippy-the-pinhead quotes. Still, I find them very smug, self-satisfied and irritating. Sort of like those doors from the Serious Cybernetics Corporation. I don't know whether it's that somebody is bragging about having a blackberry/iphone (whoop-de-friggin-do!), or that having one is somehow a valid excuse for poorly-written postings. I'm not specifically accusing Braden Faulkner of posting badly written articles, but it does seem to be a trend among people who use iphones and blackberrys to post. -- Grant Edwards grant.b.edwards Yow! I didn't order any at WOO-WOO ... Maybe a YUBBA gmail.com ... But no WOO-WOO! Posted from my Linux computer using mutt! From news1234 at free.fr Thu Nov 4 15:57:30 2010 From: news1234 at free.fr (News123) Date: Thu, 04 Nov 2010 20:57:30 +0100 Subject: Python documentation too difficult for beginners In-Reply-To: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4cd3102a$0$22754$426a74cc@news.free.fr> On 11/02/2010 02:42 PM, Steven D'Aprano wrote: > However, there is a Python wiki. It doesn't get anywhere near as much > love as it deserves, and (I think) the consensus was that the official > Python docs should stay official, but link to the wiki for user- > contributed content. This hasn't happened yet. > > http://wiki.python.org/moin/ That sounds like an excellent idea. I often would have appreciated more examples or discussions about a given module/class/function without having to fall back to Google. It might be a good compromise: clearly separating official doc and examples, but accepting, that the doc is often insufficient without digging into the sources or searching for more xamples. The more one uses python, the easier it becomes to find what one looks for. My first Impression about Python however was: - the basic language is rather easy to learn - the library documentation was more difficult to understand than the one for PHP or for Perl. > Frankly, I think that the best thing you could do is start a fork of the > docs and see if you get any interest from people. If you do, then you can > go back to python-dev with proof that there is a genuine popular desire > for more structured, PHP-style documentation. I'd prefer crosslinking the doc with something, that's easier for beginners of for people who never used a given library before. From mdw at distorted.org.uk Thu Nov 4 15:57:39 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 04 Nov 2010 19:57:39 +0000 Subject: Ways of accessing this mailing list? References: Message-ID: <871v7050b0.fsf.mdw@metalzone.distorted.org.uk> John Bond writes: > Hope this isn't too O/T - I was just wondering how people read/send to > this mailing list, eg. normal email client, gmane, some other software > or online service? > > My normal inbox is getting unmanageable, and I think I need to find a > new way of following this and other lists. I read and post to it as comp.lang.python. I maintain a local NNTP server, which interacts with my ISP's news server. I read and post news (and mail) using GNU Emacs and Gnus. (Interestingly, if enormous folders are your problem, Gnus can apply news-like expiry rules to email folders.) -- [mdw] From darcy at druid.net Thu Nov 4 16:04:47 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Thu, 4 Nov 2010 16:04:47 -0400 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> Message-ID: <20101104160447.a5e72505.darcy@druid.net> On Thu, 4 Nov 2010 19:37:25 +0000 (UTC) Tim Harig wrote: > On 2010-11-04, D'Arcy J.M. Cain wrote: > You are the one who seems to be on a crusade against against braces. It You totally misunderstand me. I am not on a crusade of any sort. I am happy with Python and the number of other people who are happy with it is interesting but does not change my life in any significant way. As long as there are enough people using it to keep it alive that's all I care about. If no one was on a crusade to convince people that indentation as syntax (can we call is IAS from now on?) was evil then I wouldn't be posting anything at all on the subject. I am being totally reactionary here. > would seem to me, that if you want people to accept that white space > formatting is superior, that you would be looking for a simple way to solve > the white space mangling problem. I might if it was a problem for me. > The world is full of broken tools that many of us have to use; but, why > should we accept that your choice is superior when other choices manage to > work with these tools without issues. You don't have to accept anything. Choose your own tools. I happen to choose Python and the tools that I choose to use work fine for me. > the source in binary. I also consider the move toward XML based document > formats a move in the right direction. Don't get me started on XML. ;-) -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From nad at acm.org Thu Nov 4 16:05:22 2010 From: nad at acm.org (Ned Deily) Date: Thu, 04 Nov 2010 13:05:22 -0700 Subject: Compiling/Installing Python 2.7 on OSX 10.6 References: <3d9139ae-bd6f-4567-bb02-b21a8ba86e50@o15g2000prh.googlegroups.com> <238cec6d-2f47-4c97-8941-e28e6808946c@a9g2000pro.googlegroups.com> Message-ID: In article <238cec6d-2f47-4c97-8941-e28e6808946c at a9g2000pro.googlegroups.com>, Jeremy wrote: [...] > I downloaded the source from python.org and extracted with 'tar -xzvf > Python-2.7.tgz' My home space is on some network somewhere. I think > the network filesystem creates the ._ at the beginning of the files. > It's really quite annoying. It is and really shouldn't be happening. If I understand correctly, whoever administers your system is doing its users a disservice by putting OS X home directories on such a file system. > > The path names look a little suspicious, too: > > /home/jlconlin. ?What file system type are these files on? ?You > > shouldn't run into problems if you use an HFS+ file system (for > > instance) and extract the tarball from the command line using > > /usr/bin/tar. > > I am intentionally installing in my home directory (i.e., /home/ > jlconlin) because I don't have access to /usr/local. Supposedly this > is possible, and in fact common. It is common and not normally a problem. I was just noting that the path name was not the OS X default of /Users/jlconlin. That said, there are a couple of options. Either find another file system to install to or, after extracting, you may be able to delete the spurious '._' files by a judicious use of find (-name '\.\_*' perhaps), or you could probably just ignore all the "compiling" errors. Those aren't "compile" errors in the sense of C compiler errors; rather they are from one of the final install steps that produces optimized .pyc and .pyo versions of all of the standard library .py files. The ._ files aren't python files but they do end in .py so compileall mistakenly tries to bytecompile them, too. > Is it safe to ignore these modules then? Yes. -- Ned Deily, nad at acm.org From darcy at druid.net Thu Nov 4 16:11:31 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Thu, 4 Nov 2010 16:11:31 -0400 Subject: Best method for a menu in a command line program? In-Reply-To: References: <87wrotfhj2.fsf@benfinney.id.au> Message-ID: <20101104161131.a74f213c.darcy@druid.net> On Thu, 4 Nov 2010 19:46:28 +0000 (UTC) Grant Edwards wrote: > I don't know whether it's that somebody is bragging about having a > blackberry/iphone (whoop-de-friggin-do!), or that having one is > somehow a valid excuse for poorly-written postings. I'm not It's really just a matter of not knowing or caring how to change the default. Mine says "Sent from my brain". -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From usenet-nospam at seebs.net Thu Nov 4 16:11:36 2010 From: usenet-nospam at seebs.net (Seebs) Date: 04 Nov 2010 20:11:36 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> Message-ID: On 2010-11-04, D'Arcy J.M. Cain wrote: > Right. If you mangle spaces in Python or mangle braces in C then > recovery becomes impossible. I don't think anyone is contesting that. > What we question is the idea that somehow Python is special in this > regard. If you move files around in ways that change them then your > tools are broken. The fact that the breakage is somewhat "friendlier" > to some types of files is interesting but irrelevant. Again, why does "diff -b" exist? It exists because so many things change whitespace unintentionally that it's a common failure mode. Thus, people developing data file formats often put substantial effort into *guaranteeing* that they will survive changes to the contents of blocks of whitespace -- it won't matter whether you used spaces or tabs, or how many spaces there are. This is done because, if you don't do it, your files sometimes get broken. I have never heard of a problem where sending something via a common commercial mail client with its default settings resulted in the destruction of braces. I have regularly seen people report that one mail client or another is losing or adding spaces, converting tabs to spaces, converting spaces to tabs, or whatever. To some extent, it may be largely a matter of convention; it is conceivable that, had Python been a major and influential language in 1970, tools in general would be much more careful about preserving spaces. But that's not what happened. Python was created in a world where the decision had already been made by many engineers (often poor ones) that it was not a big deal to mess up spacing a bit. I'd guess this decision goes back to early typesetting. Spaces are fungible; other content isn't. The distinction that is tracked is "was there space between these characters or not". Given that widespread presupposition, and that many file formats have been adapted to that, I don't think it was a good choice to build something which would be broken by that common failure mode. It's not as though widespread spacing problems are a surprise. They are so commonplace that multiple utility programs provide, as standard options, features to work around them. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Thu Nov 4 16:17:35 2010 From: usenet-nospam at seebs.net (Seebs) Date: 04 Nov 2010 20:17:35 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <87r5f13ug3.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On 2010-11-04, Mark Wooding wrote: > Seebs writes: >> Python's the only language I use where an obvious flaw, which is >> repeatedly observed by everyone I know who uses the language, is >> militantly and stridently defended by dismissing, insulting, and >> attacking the character and motives of anyone who suggests that it >> might be a bit of a nuisance. > So you've not tried Lisp, then? Dissing Lisp's parentheses tends to get > a pretty similar reaction. I don't use it. I'm also not as sure that the parens are an obvious flaw -- I am not aware of whole categories of software which regularly destroy parens. > * I /do/ have a significant problem with cutting and pasting code in > Python. In most languages, I can haul a chunk of code about, hit > C-M-q, and Emacs magically indents the result properly. This is, > unfortunately, impossible with Python. It has caused me real bugs, > and I have to be extra careful to fix the indentation up. That was the thing which bit me the worst. I had a fairly large block of code in a first-pass ugly program. I wanted to start refactoring it, so I moved a big hunk of code into a method (with plans to further refactor). It took about fifteen minutes to redo the logic. > I /like/ Python. I use it frequently. I /don't/ want to change its > structure marked by indentation. I'm /willing/ to put up with some > inconvenience because Python makes up for it in other ways. But there > /is/ inconvenience, and it does need putting up with. I think the > benefits are worth the costs; others may disagree. That makes sense to me. I think it depends a lot on what I compare Python to. I get along quite well with Ruby, but I loathe PHP. Comparing Python to Ruby, I find the indentation quite annoying. Comparing Python to PHP, I find the indentation a very mild price to pay for my sanity. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From tjreedy at udel.edu Thu Nov 4 16:21:21 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 04 Nov 2010 16:21:21 -0400 Subject: Best method for a menu in a command line program? In-Reply-To: References: Message-ID: On 11/3/2010 9:19 PM, braden faulkner wrote: > I'm using a menu for my command line app using this method. > > choice = "foobar" > while choice != "q": > if choice == "c": > temp = input("Celsius temperature:") > print "Fahrenheit:",celsius_to_fahrenheit(temp) > elif choice == "f": > temp = input("Fahrenheit temperature:") > print "Celsius:",fahrenheit_to_celsius(temp) > elif choice != "q": > print_options() > choice = raw_input("option:") > > Just wondering if there is another or more efficient way I should be doing it? Others have answered that, but I would point to the inefficiency for users of having to enter unit and value on two separate lines. The prompt could be "Enter value and unit (f, c, or k) or q to quit: " Allow upper and lower case, with or without a space between. -- Terry Jan Reedy From philip at semanchuk.com Thu Nov 4 16:22:53 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Thu, 4 Nov 2010 16:22:53 -0400 Subject: Compiling/Installing Python 2.7 on OSX 10.6 In-Reply-To: References: <3d9139ae-bd6f-4567-bb02-b21a8ba86e50@o15g2000prh.googlegroups.com> <238cec6d-2f47-4c97-8941-e28e6808946c@a9g2000pro.googlegroups.com> Message-ID: <6F087CE1-5391-4EE3-B92A-5A499FDF0E6C@semanchuk.com> On Nov 4, 2010, at 4:05 PM, Ned Deily wrote: > In article > <238cec6d-2f47-4c97-8941-e28e6808946c at a9g2000pro.googlegroups.com>, > Jeremy wrote: > [...] >> I downloaded the source from python.org and extracted with 'tar -xzvf >> Python-2.7.tgz' My home space is on some network somewhere. I think >> the network filesystem creates the ._ at the beginning of the files. >> It's really quite annoying. > > It is and really shouldn't be happening. If I understand correctly, > whoever administers your system is doing its users a disservice by > putting OS X home directories on such a file system. > >>> The path names look a little suspicious, too: >>> /home/jlconlin. What file system type are these files on? You >>> shouldn't run into problems if you use an HFS+ file system (for >>> instance) and extract the tarball from the command line using >>> /usr/bin/tar. >> >> I am intentionally installing in my home directory (i.e., /home/ >> jlconlin) because I don't have access to /usr/local. Supposedly this >> is possible, and in fact common. > > It is common and not normally a problem. I was just noting that the > path name was not the OS X default of /Users/jlconlin. > > That said, there are a couple of options. Either find another file > system to install to or, after extracting, you may be able to delete the > spurious '._' files by a judicious use of find (-name '\.\_*' perhaps), > or you could probably just ignore all the "compiling" errors. Those > aren't "compile" errors in the sense of C compiler errors; rather they > are from one of the final install steps that produces optimized .pyc and > .pyo versions of all of the standard library .py files. The ._ files > aren't python files but they do end in .py so compileall mistakenly > tries to bytecompile them, too. You might want to try this before running tar to see if it inhibits the ._ files: export COPYFILE_DISABLE=True I know that tells tar to ignore those files (resource forks, no?) when building a tarball. I don't know if it helps with extraction though. Good luck Philip From mdw at distorted.org.uk Thu Nov 4 16:23:31 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 04 Nov 2010 20:23:31 +0000 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <87mxpp3u3i.fsf.mdw@metalzone.distorted.org.uk> <87aalp3oyi.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <87tyjw3kjg.fsf.mdw@metalzone.distorted.org.uk> Tim Harig writes: > I use simple comments that are not effected by white space. I don't > waste my time trying to make comments look artistic. They are there > to convey information; not to look pretty. I really detest having to > edit other peoples comment formatting where you have to re-align > everything if the length of any of comment lines change. I view source code as primarily a means of communication with human readers, and only secondarily as being machine readable. I therefore think it's worth the effort to make source code readily legible, for example by making effective use of horizontal and vertical whitespace. A long time ago, I spent a little while studying graphic design, so I try to keep an eye on this sort of thing. I'm interested in line length for two reasons: firstly, because I believe that there's an optimum line length for easy and rapid reading, which is probably a bit less than 80 columns; and secondly because I find that I make more effective use of the available space on my screen if I have several narrow columns rather than a few wide ones -- since most lines in source files are short, a wide column ends up being mostly empty on the right hand side, which is wasteful. It's true that a source file is not the same as a typeset document: the most obvious difference is that source files are modified over time, sometimes by many hands, and that therefore some of the tradeoffs are different. I dislike `pretty' boxes around large comments, for example, because maintaining the right hand edge is unnecessarily tedious. But sometimes careful alignment can help a reader spot a symmetry or find his way through a repetitive section such a table more easily. (Unfortunately, I appear to have strange ideas about what `legible' means...) -- [mdw] From invalid at invalid.invalid Thu Nov 4 16:54:09 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 4 Nov 2010 20:54:09 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> Message-ID: On 2010-11-04, Seebs wrote: > On 2010-11-04, D'Arcy J.M. Cain wrote: >> Right. If you mangle spaces in Python or mangle braces in C then >> recovery becomes impossible. I don't think anyone is contesting that. >> What we question is the idea that somehow Python is special in this >> regard. If you move files around in ways that change them then your >> tools are broken. The fact that the breakage is somewhat "friendlier" >> to some types of files is interesting but irrelevant. > > Again, why does "diff -b" exist? > > It exists because so many things change whitespace unintentionally that > it's a common failure mode. It exists because so many people change whitespace intentionally in C source code because no two C programmers seem able to agree on how to format code. Diff -b allows you to attempt to ignore semantically null stylistic changes made by programmers. -- Grant Edwards grant.b.edwards Yow! I'm having a RELIGIOUS at EXPERIENCE ... and I don't gmail.com take any DRUGS From bigfatwhale at gmail.com Thu Nov 4 17:00:44 2010 From: bigfatwhale at gmail.com (Pix) Date: Thu, 4 Nov 2010 14:00:44 -0700 (PDT) Subject: 3rd party python module with pyd picking up wrong dlls Message-ID: <4d01a7f1-18d6-44e9-8ce2-37321d20231a@t35g2000yqj.googlegroups.com> Hi, I'm trying to install OpenSSL by placing it in site-packages\OpenSSL. In the directory there the following files, crypto.pyd libeay32.dll rand.pyd SSL.pyd ssleay32.dll When i try to import the module by doing "import OpenSSL" i get an import error saying "ImportError: DLL load failed: The specified module could not be found". It turns out that there is another module (call it XXX) that is install which contains different versions of libeay32.dll and ssleay32.dll. And the path to the XXX appears earlier in os.environ['PATH'] than the OpenSSL dir. So this cause it to pick up the wrong dll which in turn causes the import error. If i renamed the dlls in XXX's dir then the import will work fine. So my question is, shouldn't the import be picking up the dlls in the module directory first before following the PATH in it's search order? Seem that is doesn't make sense because if i put OpenSSL earlier in the path, it would work for OpenSSL, but then XXX will be picking up the wrong dll. Any help is much appreciated! Regards, Pix From clp2 at rebertia.com Thu Nov 4 17:00:56 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 4 Nov 2010 14:00:56 -0700 Subject: Allow multiline conditions and the like In-Reply-To: <87iq0d3qqc.fsf.mdw@metalzone.distorted.org.uk> References: <4cce7196$0$29965$c3e8da3$5496439d@news.astraweb.com> <87iq0d3qqc.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On Thu, Nov 4, 2010 at 11:09 AM, Mark Wooding wrote: > Chris Rebert writes: >> Or, if possible, refactor the conditional into a function (call) so >> it's no longer multiline in the first place. > > No! ?This /increases/ cognitive load for readers, because they have to > deal with the indirection through the name. If it's well-named, then the reader can delay having to read the definition. > If you actually use the > function multiple times, the mental overhead of forming the abstraction > and associating it with the function name is shared across the various > call sites and it's probably worth it. ?If it's only called once, leave > it inline. I'd say it's a judgment call. If the condition is sufficiently complicated and can be well-named, then I see justifying refactoring it into a function even if it's only used once. However, this is admittedly not a common situation. Cheers, Chris -- http://blog.rebertia.com From tjreedy at udel.edu Thu Nov 4 17:04:55 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 04 Nov 2010 17:04:55 -0400 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 11/4/2010 4:17 AM, Seebs wrote: I am sorry you feel compelled to use a language you so dislike. Not our fault though. > Other languages I use are mostly amenable to the development of tools > to automatically indent code. Makefiles and Python are the only two > exceptions... If you add the normally redundant information in the form of explicit dedents (anything starting with '#' and distinguishable from normal comments), then it is not too hard to re-indent even after all indents have been removed. I believe this has been dome more than once. By using a stylized comment, the augmented code runs without preprocessing. I also believe at lease one person has written a preprocessor for 'python-with-braces'. -- Terry Jan Reedy From moura.mario at gmail.com Thu Nov 4 17:10:12 2010 From: moura.mario at gmail.com (macm) Date: Thu, 4 Nov 2010 14:10:12 -0700 (PDT) Subject: How convert list to nested dictionary? References: <940876cd-2546-4673-aef4-ba11b4156287@fv1g2000vbb.googlegroups.com> Message-ID: <44817c9a-647b-4bed-9162-faf0fb5313bc@f20g2000yqi.googlegroups.com> Hi Chris Thanks for your hint. I am reading this http://www.amk.ca/python/writing/functional Do you have good links or books to me learn "Functional Programming"? but I am not asking "...because is easy but because is hard." Show me, please! if you can. Thanks is advance. Best regards macm On 4 nov, 16:53, Chris Rebert wrote: > On Thu, Nov 4, 2010 at 11:48 AM, macm wrote: > > Hi Folks > > > How convert list to nested dictionary? > > >>>> l > > ['k1', 'k2', 'k3', 'k4', 'k5'] > >>>> result > > {'k1': {'k2': {'k3': {'k4': {'k5': {}}}}}} > > We don't do homework. > Hint: Iterate through the list in reverse order, building up your > result. Using reduce() is one option. > > Cheers, > Chris From arnodel at gmail.com Thu Nov 4 17:20:04 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Thu, 04 Nov 2010 21:20:04 +0000 Subject: How find all childrens values of a nested dictionary, fast! References: Message-ID: <87d3qkkcqj.fsf@gmail.com> macm writes: > Hi Folks > > How find all childrens values of a nested dictionary, fast! > >>>> a = {'a' : {'b' :{'/' :[1,2,3,4], 'ba' :{'/' :[41,42,44]} ,'bc' :{'/':[51,52,54], 'bcd' :{'/':[68,69,66]}}},'c' :{'/' :[5,6,7,8]}}, 'ab' : {'/' :[12,13,14,15]}, 'ac' :{'/' :[21,22,23]}} >>>> a['a'] > {'c': {'/': [5, 6, 7, 8]}, 'b': {'ba': {'/': [41, 42, 44]}, '/': [1, > 2, 3, 4], 'bc': {'bcd': {'/': [68, 69, 66]}, '/': [51, 52, 54]}}} >>>> a['a']['b'] > {'ba': {'/': [41, 42, 44]}, '/': [1, 2, 3, 4], 'bc': {'bcd': {'/': > [68, 69, 66]}, '/': [51, 52, 54]}} >>>> a['a']['b'].values() > [{'/': [41, 42, 44]}, [1, 2, 3, 4], {'bcd': {'/': [68, 69, 66]}, '/': > [51, 52, 54]}] > > Now I want find all values of key "/" > > Desire result is [41, 42, 44, 1, 2, 3, 4, 68, 69, 66, 51, 52, 54] > > I am trying map, reduce, lambda. Tough requirement, but I think I've got it. Two lambdas, one reduce, one map ;) >>> a = {'a' : {'b' :{'/' :[1,2,3,4], 'ba' :{'/' :[41,42,44]}, 'bc' :{'/':[51,52,54], 'bcd' :{'/':[68,69,66]}}},'c' :{'/' :[5,6,7,8]}},'ab' : {'/' :[12,13,14,15]}, 'ac' :{'/' :[21,22,23]}} >>> f = lambda v,k=None: v if k=="/" else reduce(list.__add__, map(lambda k: f(v[k],k), v), []) >>> f(a) [5, 6, 7, 8, 41, 42, 44, 1, 2, 3, 4, 68, 69, 66, 51, 52, 54, 21, 22, 23, 12, 13, 14, 15] This doesn't correspond with your desire result though. -- Arnaud From usernet at ilthio.net Thu Nov 4 17:26:00 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 4 Nov 2010 21:26:00 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <87mxpp3u3i.fsf.mdw@metalzone.distorted.org.uk> <87aalp3oyi.fsf.mdw@metalzone.distorted.org.uk> <87tyjw3kjg.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On 2010-11-04, Mark Wooding wrote: > Tim Harig writes: > >> I use simple comments that are not effected by white space. I don't >> waste my time trying to make comments look artistic. They are there >> to convey information; not to look pretty. I really detest having to >> edit other peoples comment formatting where you have to re-align >> everything if the length of any of comment lines change. > > I view source code as primarily a means of communication with human > readers, and only secondarily as being machine readable. I therefore > think it's worth the effort to make source code readily legible, for > example by making effective use of horizontal and vertical whitespace. > A long time ago, I spent a little while studying graphic design, so I > try to keep an eye on this sort of thing. I agree that it should be clean, ledgible, and easy to parse; but, I can that I can achieve this without making too many assumptions about whitespace. Think of it like the way HTML is *supposed* to work. Ideally, the web designer should stipulate the basic layout of the page; but, details such as how wide the display is are better left to the browser to figure out based on the actual conditions that it needs to display the page. > I'm interested in line length for two reasons: firstly, because I > believe that there's an optimum line length for easy and rapid reading, > which is probably a bit less than 80 columns; and secondly because I > find that I make more effective use of the available space on my screen > if I have several narrow columns rather than a few wide ones -- since > most lines in source files are short, a wide column ends up being mostly > empty on the right hand side, which is wasteful. Don't get me wrong, I am not arguing against the eighty column stylistic limit. I totally agree with it within reason. What I am arguing for is choice on how the code is displayed -- not how it is actually written. By using tabs, I can choose the trade-offs myself when reading the code rather then being confined to how the writer made their decision to view it. Assuming that I have sufficient screen space, I might choose a wider indent even though it might make the document wider then 80 columns *when viewed*. Other times, I may resign to view at the shorter column width so that it fits in my window without side scrolling. Either way, its my choice; and, when I am finished editing the file, even if it exceeds 80 columns at my chosen column width, the file will not exceed 80 columns, at the origional column width, in the actual source as it is *written*. Adjusting tab stops is merely for my viewing pleasure and it gives everybody the choice to view it their way without effecting the code. That is why I prefer tabs. From steve at holdenweb.com Thu Nov 4 17:29:19 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 04 Nov 2010 17:29:19 -0400 Subject: using google app through python In-Reply-To: References: Message-ID: On 11/1/2010 5:05 AM, charu gangal wrote: > Hey! Can anyone help me with python script for reading google > spreadsheets? what all packages do i need to import to make the code > run successfully after deploying it on google environment..thnx in > advance I've found the xlrd module very usable. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From brf256 at gmail.com Thu Nov 4 17:30:40 2010 From: brf256 at gmail.com (braden faulkner) Date: Thu, 4 Nov 2010 17:30:40 -0400 Subject: Best method for a menu in a command line program? In-Reply-To: References: <87wrotfhj2.fsf@benfinney.id.au> Message-ID: Sorry, I wasn't aware it was doing that but... I've removed it :-) Sorry about that, Braden Faulkner From clp2 at rebertia.com Thu Nov 4 17:32:59 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 4 Nov 2010 14:32:59 -0700 Subject: How convert list to nested dictionary? In-Reply-To: <44817c9a-647b-4bed-9162-faf0fb5313bc@f20g2000yqi.googlegroups.com> References: <940876cd-2546-4673-aef4-ba11b4156287@fv1g2000vbb.googlegroups.com> <44817c9a-647b-4bed-9162-faf0fb5313bc@f20g2000yqi.googlegroups.com> Message-ID: > On 4 nov, 16:53, Chris Rebert wrote: >> On Thu, Nov 4, 2010 at 11:48 AM, macm wrote: >> > Hi Folks >> >> > How convert list to nested dictionary? >> >> >>>> l >> > ['k1', 'k2', 'k3', 'k4', 'k5'] >> >>>> result >> > {'k1': {'k2': {'k3': {'k4': {'k5': {}}}}}} >> >> We don't do homework. >> Hint: Iterate through the list in reverse order, building up your >> result. Using reduce() is one option. On Thu, Nov 4, 2010 at 2:10 PM, macm wrote: > Thanks for your hint. > Do you have good links or books to me learn "Functional Programming"? Relevant to the particular problem you posed: http://en.wikipedia.org/wiki/Fold_(higher-order_function) > Show me, please! if you can. I will give you this further hint: def reducer(accumulator, elem): # if accumulator = {'k5': {} } # and elem = 'k4' # then we want to return {'k4': {'k5': {} } } now_implement_me() l = ['k1', 'k2', 'k3', 'k4', 'k5'] result = reduce(reducer, reversed(l), {}) Note that: reduce(reducer, reversed(l), {}) Is basically equivalent to: reducer( reducer( reducer( reducer( reducer({}, 'k5'), 'k4'), 'k3'), 'k2'), 'k1') Cheers, Chris -- http://blog.rebertia.com From arnodel at gmail.com Thu Nov 4 17:38:02 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Thu, 04 Nov 2010 21:38:02 +0000 Subject: How convert list to nested dictionary? References: <940876cd-2546-4673-aef4-ba11b4156287@fv1g2000vbb.googlegroups.com> Message-ID: <878w18kbwl.fsf@gmail.com> macm writes: > Hi Folks > > How convert list to nested dictionary? > >>>> l > ['k1', 'k2', 'k3', 'k4', 'k5'] >>>> result > {'k1': {'k2': {'k3': {'k4': {'k5': {}}}}}} > > Regards > > macm reduce(lambda x,y: {y:x}, reversed(l), {}) -- Arnaud From usernet at ilthio.net Thu Nov 4 17:38:54 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 4 Nov 2010 21:38:54 +0000 (UTC) Subject: Man pages and info pages References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> <024ef21a-9ef9-48a6-8372-1d66895583c3@v16g2000yqn.googlegroups.com> <87zktr5yze.fsf_-_@mithlond.arda> <877hgv2fg3.fsf@mithlond.arda> <8762wc526v.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On 2010-11-04, Mark Wooding wrote: > Tim Harig writes: > >> When the GNU folk decided to clone *nix they decided that they knew >> better and simply decided to create their own interfaces. > > This isn't the case. Actually Info has a long history prior to GNU: it > was the way that the documentation was presented at the MIT AI lab. In > fact, Info was used rather like a modern wiki. The operating system > they used, called ITS, didn't have a concept of file permissions, and > users were encouraged to improve documentation (and programs). The > original Info viewer was implemented in Emacs (which also originated in > ITS, years before GNU). I was aware of Emacs history. I was not aware that info actually dated all the way back to ITS. In retrospect, Stallman might have done better cloning ITS as that seems to have been what he wanted to do anyway. I suppose that Emacs is basically just an ITS lookalike shell for making *nix systems look like ITS. Coming from a *nix background and not being an Emacs users, I prefer the traditional *nix methods. > documenting large software systems like Emacs and GCC, it doesn't seem > unreasonable to provide manuals which are somewhat more discursive and > leisurely than traditional Unix manpages. I have a printed copy of the > GNU Emacs 18 manual (from 1987): it's almost 300 pages long. The modern > manual for Emacs 23 is several /times/ larger than this. Man pages > don't scale that well. Actually, they are capable of the same scalability. I would suggest that you read the ncurses man pages as they are displayed by pinfo. The man page links to other man pages that are organized by functionality in the same kind of tree organization that is used for (text)info pages. >> Actually, the left arrow key does not work at all intuitively. One >> would expect that it should go back to the previous page as it would >> in lynx, etc. It does not. > > It moves the cursor so you can hit links. The l key takes you back > through your recent viewing history -- and has done for thirty years. As I said, that is probably intuitive for Emacs users; but, not all *nix users are Emacs users. To those of us that are not, the info interface seems quite alien. >> By tradition 'n' and 'p' are broken for scrolling in a page. 'b' is >> often used in place of p but that seems to take one back to the top of >> the page. > > Space and backspace are an older tradition. Right, and in info with the default key bindings, backspace takes me to the command help. I would have expected it to either scroll up the page or take me to the previously visited node. >> The s key for a search is another example that has already been >> discussed. > > I find C-s more useful in Info, because it searches interactively. I > frequently get muddled when I try to search in `modern' programs like > web browsers, because they've gratuitously made C-s try to save the page > (something one hardly ever wants to do) rather than search. (Finding is > different: finding is what happens at the end of a /successful/ search. > So C-f is poorly chosen.) / is even more intiuitive yet, it works in more, it works in less, it works in vi, and it even works in firefox. From usernet at ilthio.net Thu Nov 4 17:47:59 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 4 Nov 2010 21:47:59 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> Message-ID: On 2010-11-04, Grant Edwards wrote: > On 2010-11-04, Seebs wrote: >> On 2010-11-04, D'Arcy J.M. Cain wrote: >>> Right. If you mangle spaces in Python or mangle braces in C then >>> recovery becomes impossible. I don't think anyone is contesting that. >>> What we question is the idea that somehow Python is special in this >>> regard. If you move files around in ways that change them then your >>> tools are broken. The fact that the breakage is somewhat "friendlier" >>> to some types of files is interesting but irrelevant. >> >> Again, why does "diff -b" exist? >> >> It exists because so many things change whitespace unintentionally that >> it's a common failure mode. > > It exists because so many people change whitespace intentionally in C > source code because no two C programmers seem able to agree on how to > format code. Diff -b allows you to attempt to ignore semantically > null stylistic changes made by programmers. I have seen huge patches caused by nothing more then some edit that accidently added a trailing space to a large number of lines. White space mangling happens all the time without people even knowing about it. From usenet-nospam at seebs.net Thu Nov 4 17:52:01 2010 From: usenet-nospam at seebs.net (Seebs) Date: 04 Nov 2010 21:52:01 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> Message-ID: On 2010-11-04, Grant Edwards wrote: > It exists because so many people change whitespace intentionally in C > source code because no two C programmers seem able to agree on how to > format code. Diff -b allows you to attempt to ignore semantically > null stylistic changes made by programmers. I don't agree with this interpretation, just because the changes it filters out are hardly ever intentional when I actually look at them. They're a mix of space/tab changes which don't affect actual indentation, trailing whitespace, and the like. The kinds of changes that would be made by C programmers trying to change source formatting are usually far beyond what "diff -b" would "fix". -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Thu Nov 4 17:54:56 2010 From: usenet-nospam at seebs.net (Seebs) Date: 04 Nov 2010 21:54:56 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-04, Terry Reedy wrote: > I am sorry you feel compelled to use a language you so dislike. Not our > fault though. I don't dislike it all that much. What I dislike is being told that the problems don't exist. > If you add the normally redundant information in the form of explicit > dedents (anything starting with '#' and distinguishable from normal > comments), then it is not too hard to re-indent even after all indents > have been removed. I believe this has been dome more than once. By using > a stylized comment, the augmented code runs without preprocessing. I > also believe at lease one person has written a preprocessor for > 'python-with-braces'. Yes. They did this because there is no reason that anyone would ever prefer it or find some benefit to it, of course. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From tjreedy at udel.edu Thu Nov 4 17:57:09 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 04 Nov 2010 17:57:09 -0400 Subject: Final state of underlying sequence in islice In-Reply-To: References: Message-ID: On 11/4/2010 12:42 PM, Shashank Singh wrote: > Are there any promises made with regard to final state of the underlying > sequence that islice slices? The one you quote below. > for example consider this > > >>> from itertools import * > >>> c = count() > >>> list(islice(c, 1, 3, 50)) > [1] > >>> c.next() > 51 When posting code and result, it is always a good idea to include version. It is even more important when reporting a (possible) bug, which might have been fixed already. As it turns out, I get the same behavior above and below with 3.1.2. > Now, the doc [1] says "If /stop/ is None, then iteration continues until > the iterator is exhausted, if at all; otherwise, it stops at the > specified position". With a step greater than 1, 'specified position' is ambiguous. Any stop value in [2,51] gives the same result. One could argue that the effective stop value is either last returned + step as above does, or last returned + 1 as Python version does. > It clearly is not stopping at stop (3). > > Further, the doc gives an example of how this is *equivalent* to a > generator defined in the same section. It turns out, these two are not > exactly the > same if the side-effect of the code is considered on the underlying > sequence. > > Redefining islice using the generator function defined in the doc gives > different (and from one pov, expected) result > >>> def islice(iterable, *args): > ... # islice('ABCDEFG', 2) --> A B > ... > >>> c = count() > >>> list(islice(c, 1, 3, 50)) > [1] > >>> c.next() > 2 > > While "fixing" this should be rather easy in terms of the change in code > required it might break any code depending > on this seemingly incorrect behavior. > > [1]. http://docs.python.org/library/itertools.html#itertools.islice If you file a bug report, please give the link. If you do not want to, say so and I will. -- Terry Jan Reedy From brandon.harris at reelfx.com Thu Nov 4 18:13:09 2010 From: brandon.harris at reelfx.com (Brandon Harris) Date: Thu, 04 Nov 2010 17:13:09 -0500 Subject: Passing File Objects into Subprocess.Popen Message-ID: <4CD32FF5.5090101@reelfx.com> I'm running python 2.5 and have bumped into an issue whereby the PIPE in subprocess.Popen locks up after taking too many characters. I found some documentation that discuss this problem and offers some ideas for solutions, the best one being to pass a file object into subprocess instead of PIPE. This will allow for much larger std output. http://thraxil.org/users/anders/posts/2008/03/13/Subprocess-Hanging-PIPE-is-your-enemy/ The problem is that, while I can pass in a tempfile.TemporaryFile() and everything seems to go swimmingly, there doesn't seem to be anything written to file I handed Popen. import tempfile import subprocess def awesome(): # I understand that not everyone has nuke, but it doesn't seem to matter what I run through it # the result is the same. my_cmd = '/usr/local/Nuke6.0v3/Nuke6.0 -V' my_stderr = tempfile.TemporaryFile() my_stdout = tempfile.TemporaryFile() process = subprocess.Popen(my_cmd, stderr=my_stderr, stdout=my_stdout) process.wait() print my_stderr.read() print my_stdout.read() print "Finished!!!" Any help on this issue would be awesome! thanks! Brandon L. Harris From mdw at distorted.org.uk Thu Nov 4 18:34:07 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 04 Nov 2010 22:34:07 +0000 Subject: functions, list, default parameters References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <20101021235138.609fe668@geekmail.INVALID> Message-ID: <87pquk3ehs.fsf.mdw@metalzone.distorted.org.uk> Lawrence D'Oliveiro writes: > In message <20101021235138.609fe668 at geekmail.INVALID>, Andreas > Waldenburger wrote: > > While not very commonly needed, why should a shared default argument be > > forbidden? > > Because it?s safer to disallow it than to allow it. Scissors with rounded ends are safer than scissors without. Chopsticks and plastic sporks are safer than metal cutlery. We have sharp things because they're /useful/. Similarly, having mutable objects as argument defaults can be useful. (Based on experience with other languages, I suspect that evaluating the default expression afresh for each call where it's needed would be more useful; but it's way too late to change that now.) -- [mdw] From solipsis at pitrou.net Thu Nov 4 18:39:54 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Thu, 4 Nov 2010 23:39:54 +0100 Subject: Passing File Objects into Subprocess.Popen References: <4CD32FF5.5090101@reelfx.com> Message-ID: <20101104233954.2e191e35@pitrou.net> On Thu, 04 Nov 2010 17:13:09 -0500 Brandon Harris wrote: > I'm running python 2.5 and have bumped into an issue whereby the PIPE > in subprocess.Popen locks up after taking too many characters. I found > some documentation that discuss this problem and offers some ideas for > solutions, the best one being to pass a file object into subprocess > instead of PIPE. This sounds rather unlikely. Have you used communicate()? > process = subprocess.Popen(my_cmd, stderr=my_stderr, stdout=my_stdout) > process.wait() > > print my_stderr.read() > print my_stdout.read() Try to rewind the file pointer before reading from it. Regards Antoine. From mdw at distorted.org.uk Thu Nov 4 18:42:00 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 04 Nov 2010 22:42:00 +0000 Subject: functions, list, default parameters References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <4cc13ef5$0$29979$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87lj583e4n.fsf.mdw@metalzone.distorted.org.uk> Lawrence D'Oliveiro writes: > Mediocre programmers with a hankering towards cleverness latch onto it > as an ingenious way of maintaing persistent context in-between calls > to a function, completely overlooking the fact that Python offers much > more straightforward, comprehensible, flexible, and above all > maintainable ways of doing that sort of thing. It does nowadays. Once upon a time, Python didn't have proper closures, and argument defaults, evaluated at function-definition time, were the only way of capturing data from the surrounding environment. You may be confusing `mediocre' with `old-fashioned', and `a hankering towards cleverness' with `wanting to run code on old Python interpreters'. This last may be because the relevant code was written back when those `old' interpreters were shiny and new. -- [mdw] From brandon.harris at reelfx.com Thu Nov 4 18:49:19 2010 From: brandon.harris at reelfx.com (Brandon Harris) Date: Thu, 04 Nov 2010 17:49:19 -0500 Subject: Passing File Objects into Subprocess.Popen In-Reply-To: <20101104233954.2e191e35@pitrou.net> References: <4CD32FF5.5090101@reelfx.com> <20101104233954.2e191e35@pitrou.net> Message-ID: <4CD3386F.4030902@reelfx.com> What do you mean by rewind the file pointer before reading from it? Seek back to the beginning? And It sounded very unlikely to me too, but it's the only thing I have found that explains why a very verbose job with tons of feedback locks up at the same point and won't process at all. I did try running communicate before and after the wait() but to no avail. Brandon L. Harris On 11/04/2010 05:39 PM, Antoine Pitrou wrote: > Try to rewind the file pointer before reading from it. From mdw at distorted.org.uk Thu Nov 4 18:51:47 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 04 Nov 2010 22:51:47 +0000 Subject: Man pages and info pages References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> <024ef21a-9ef9-48a6-8372-1d66895583c3@v16g2000yqn.googlegroups.com> <87zktr5yze.fsf_-_@mithlond.arda> <877hgv2fg3.fsf@mithlond.arda> <8762wc526v.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <87eib03doc.fsf.mdw@metalzone.distorted.org.uk> Tim Harig writes: > Right, and in info with the default key bindings, backspace takes me > to the command help. I would have expected it to either scroll up the > page or take me to the previously visited node. Sounds like your terminal is misconfigured. Backspace should produce ^?, not ^H. (Delete should produce some awful escape sequence.) -- [mdw] From brandon.harris at reelfx.com Thu Nov 4 18:57:28 2010 From: brandon.harris at reelfx.com (Brandon Harris) Date: Thu, 04 Nov 2010 17:57:28 -0500 Subject: Passing File Objects into Subprocess.Popen In-Reply-To: <4CD3386F.4030902@reelfx.com> References: <4CD32FF5.5090101@reelfx.com> <20101104233954.2e191e35@pitrou.net> <4CD3386F.4030902@reelfx.com> Message-ID: <4CD33A58.1090806@reelfx.com> ok. Jumping back to the start of the file solved the problem. (file.seek(0)) Big thanks for that insight! Brandon L. Harris On 11/04/2010 05:49 PM, Brandon Harris wrote: > What do you mean by rewind the file pointer before reading from it? > Seek back to the beginning? And It sounded very unlikely to me too, > but it's the only thing I have found that explains why a very verbose > job with tons of feedback locks up at the same point and won't process > at all. > > I did try running communicate before and after the wait() but to no > avail. > > Brandon L. Harris > > > On 11/04/2010 05:39 PM, Antoine Pitrou wrote: >> Try to rewind the file pointer before reading from it. > From nad at acm.org Thu Nov 4 19:08:18 2010 From: nad at acm.org (Ned Deily) Date: Thu, 04 Nov 2010 16:08:18 -0700 Subject: Compiling/Installing Python 2.7 on OSX 10.6 References: <3d9139ae-bd6f-4567-bb02-b21a8ba86e50@o15g2000prh.googlegroups.com> <238cec6d-2f47-4c97-8941-e28e6808946c@a9g2000pro.googlegroups.com> <6F087CE1-5391-4EE3-B92A-5A499FDF0E6C@semanchuk.com> Message-ID: In article <6F087CE1-5391-4EE3-B92A-5A499FDF0E6C at semanchuk.com>, Philip Semanchuk wrote: > You might want to try this before running tar to see if it inhibits the ._ > files: > export COPYFILE_DISABLE=True > > > I know that tells tar to ignore those files (resource forks, no?) when > building a tarball. I don't know if it helps with extraction though. Interesting. It's been so long since I've had to deal with ._ 's (which is where metadata for extended attributes including resource forks are stored), I had forgotten about that poorly documented option for 10.5 and 10.6. A little experiment: from OS X 10.6, I NFS-mount a remote Linux (ext3) file system and have created files on it with extended attributes. Using ls on either the OS X or the Linux side, the ._ files appear as regular files. On the Linux side, I use gnu tar to archive the files and move that archive back to OS X. If I then use the stock Apple 10.6 tar to extract that archive to an HFS+ directory, the extended attributes are by default restored properly (they can be viewed with ls -l@) and no '._' files - great! If I first export COPYFILE_DISABLE=True, then the tar extraction appears to ignore the ._ files: the extended attributes are not set and the ._ files still do not appear. So the COPYFILE_DISABLE trick may very well work for this issue. It still raises the question of why the ._ files are being created in the first place. They shouldn't be on the python.org tarball so it would seem most likely they are due to some operation on the OS X machine that causes extended attributes to be created. Nothing wrong with that, just kind of interesting. -- Ned Deily, nad at acm.org From ldo at geek-central.gen.new_zealand Thu Nov 4 19:43:00 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 05 Nov 2010 12:43 +1300 Subject: subprocess.Popen not replacing current process? References: <0f1a17f4-b6a9-4e89-ac26-74b1098a065e@b19g2000prj.googlegroups.com> Message-ID: In message <0f1a17f4-b6a9-4e89-ac26-74b1098a065e at b19g2000prj.googlegroups.com>, goodman wrote: > Hi, I'm wondering why subprocess.Popen does not seem to replace the > current process, even when it uses os.execvp (according to the > documentation: > http://docs.python.org/library/subprocess.html#subprocess.Popen). You?ll notice that in the list at the top of the functions that subprocess replaces, there are no os.exec* entries. subprocess is only for spawning new processes; if all you need to do is an exec, do an exec ; subprocess can?t offer anything to make that any simpler. From goodman.m.w at gmail.com Thu Nov 4 19:48:25 2010 From: goodman.m.w at gmail.com (goodman) Date: Thu, 4 Nov 2010 16:48:25 -0700 (PDT) Subject: subprocess.Popen not replacing current process? References: <0f1a17f4-b6a9-4e89-ac26-74b1098a065e@b19g2000prj.googlegroups.com> Message-ID: On Nov 4, 1:22?am, goodman wrote: > Note: Our server is a Linux machine, but we're restricted to Python > 2.4. > > Hi, I'm wondering why subprocess.Popen does not seem to replace the > current process, even when it uses os.execvp (according to the > documentation:http://docs.python.org/library/subprocess.html#subprocess.Popen). > Specifically, when I try to kill a spawned process with Ctrl-C, the > SIGINT does not seem to be sent to the spawned process. > > Some background: I have a Python script that calls shell scripts or > commands. It does not need to regain control after calling these > scripts or commands, so up to now I've been using an os.exec* command. > It seems the subprocess module is the recommended way for spawning > processes, but in this case perhaps it's better I stick with os.exec*? > I've seen plenty of discussion about catching KeyboardInterrupt in the > parent process and then manually killing the child, but (1) I can't > use Popen.kill() on Python 2.4, and (2) this level of process > management seems like overkill (pardon the potential for puns) in my > case. > > Thanks for any help. Following up, I can get the effect I want with the following: try: p = subprocess.Popen([cmd, arg1, arg2]) p.wait() except KeyboardInterrupt: import signal os.kill(p.pid, signal.SIGKILL) ...but like I said, I don't think I should be managing this myself, since I don't need to return from the new process. How can I make the new process handle its own signals? From ben+python at benfinney.id.au Thu Nov 4 19:51:26 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 05 Nov 2010 10:51:26 +1100 Subject: Best method for a menu in a command line program? References: Message-ID: <87sjzgfy0x.fsf@benfinney.id.au> Terry Reedy writes: > Others have answered that, but I would point to the inefficiency for > users of having to enter unit and value on two separate lines. The > prompt could be "Enter value and unit (f, c, or k) or q to quit: " > Allow upper and lower case, with or without a space between. Well, if we're going to critique the design, I'd say that I find the GNU Units program to be a good flexible implementation of a command-line units converter. I suspect, though, that the object of the OP was not so much to make a good unit converter, but rather to learn from a simple example exercise. -- \ ?I am too firm in my consciousness of the marvelous to be ever | `\ fascinated by the mere supernatural ?? ?Joseph Conrad, _The | _o__) Shadow-Line_ | Ben Finney From ben+python at benfinney.id.au Thu Nov 4 19:52:19 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 05 Nov 2010 10:52:19 +1100 Subject: Best method for a menu in a command line program? References: <87wrotfhj2.fsf@benfinney.id.au> Message-ID: <87oca4fxzg.fsf@benfinney.id.au> braden faulkner writes: > Sorry, I wasn't aware it was doing that but... I've removed it :-) Thank you, it's good to keep a polite discourse going :-) -- \ ?I don't accept the currently fashionable assertion that any | `\ view is automatically as worthy of respect as any equal and | _o__) opposite view.? ?Douglas Adams | Ben Finney From goodman.m.w at gmail.com Thu Nov 4 19:53:03 2010 From: goodman.m.w at gmail.com (goodman) Date: Thu, 4 Nov 2010 16:53:03 -0700 (PDT) Subject: subprocess.Popen not replacing current process? References: <0f1a17f4-b6a9-4e89-ac26-74b1098a065e@b19g2000prj.googlegroups.com> Message-ID: <7c5be6d7-5782-44ad-aae7-7f7bbc798d43@n32g2000prc.googlegroups.com> On Nov 4, 4:43?pm, Lawrence D'Oliveiro wrote: > In message > <0f1a17f4-b6a9-4e89-ac26-74b1098a0... at b19g2000prj.googlegroups.com>, goodman > wrote: > > > Hi, I'm wondering why subprocess.Popen does not seem to replace the > > current process, even when it uses os.execvp (according to the > > documentation: > >http://docs.python.org/library/subprocess.html#subprocess.Popen). > > You?ll notice that in the list at the top of the functions that subprocess > replaces, there are no os.exec* entries. subprocess is only for spawning new > processes; if all you need to do is an exec, do an exec > ; subprocess > can?t offer anything to make that any simpler. Thanks Lawrence. Forgive my recent followup, as I posted it before I saw your message. I noticed that the exec*s were not replaced by subprocess, so that makes sense to just use exec. Though I'm still a little confused how, if subprocess.Popen is using os.execvp, it still maintains control of things like interrupts. Anyway, my problem is solved. Thanks! From ben+python at benfinney.id.au Thu Nov 4 19:58:45 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 05 Nov 2010 10:58:45 +1100 Subject: Man pages and info pages References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> <024ef21a-9ef9-48a6-8372-1d66895583c3@v16g2000yqn.googlegroups.com> <87zktr5yze.fsf_-_@mithlond.arda> <877hgv2fg3.fsf@mithlond.arda> <8762wc526v.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <87hbfwfxoq.fsf@benfinney.id.au> Tim Harig writes: > On 2010-11-04, Mark Wooding wrote: > > Tim Harig writes: > >> Actually, the left arrow key does not work at all intuitively. One > >> would expect that it should go back to the previous page as it > >> would in lynx, etc. It does not. > > > > It moves the cursor so you can hit links. The l key takes you back > > through your recent viewing history -- and has done for thirty years. > > As I said, that is probably intuitive for Emacs users; but, not all > *nix users are Emacs users. To those of us that are not, the info > interface seems quite alien. You might make more headway in this discussion if you avoided conflating ?intuitive? (no computer UI is intuitive) with ?familiar? (which is relative to each user). As has been noted before, there is no intuitive interface except the nipple. Everything else is not intuitive, but must be learned. -- \ ?Facts are meaningless. You could use facts to prove anything | `\ that's even remotely true!? ?Homer, _The Simpsons_ | _o__) | Ben Finney From lists at cheimes.de Thu Nov 4 19:59:21 2010 From: lists at cheimes.de (Christian Heimes) Date: Fri, 05 Nov 2010 00:59:21 +0100 Subject: Passing File Objects into Subprocess.Popen In-Reply-To: <4CD3386F.4030902@reelfx.com> References: <4CD32FF5.5090101@reelfx.com> <20101104233954.2e191e35@pitrou.net> <4CD3386F.4030902@reelfx.com> Message-ID: Am 04.11.2010 23:49, schrieb Brandon Harris: > What do you mean by rewind the file pointer before reading from it? > Seek back to the beginning? And It sounded very unlikely to me too, but > it's the only thing I have found that explains why a very verbose job > with tons of feedback locks up at the same point and won't process at all. Look at a file handler like an old style magnetic tape. You just have recorded your favorite song from radio onto a tape. What do you have to do in order to listen to the song again? Press play? No, you have to rewind first. The MP3 generation will never understand the hard work of a mix tape created recorded from radio broadcasts. ;) Christian From contact at xavierho.com Thu Nov 4 20:22:26 2010 From: contact at xavierho.com (Xavier Ho) Date: Fri, 5 Nov 2010 10:22:26 +1000 Subject: C++ comment in Javadoc style -> reStructuredText compiler? Message-ID: Hey all, Apologies if I am posting this in the wrong list. Does anyone know of a good compiler for javadoc comment style into reStructuredText, for Sphinx to chew? Cheers, Xavier -------------- next part -------------- An HTML attachment was scrubbed... URL: From usernet at ilthio.net Thu Nov 4 21:21:43 2010 From: usernet at ilthio.net (Tim Harig) Date: Fri, 5 Nov 2010 01:21:43 +0000 (UTC) Subject: Man pages and info pages References: <4cd01539$0$29966$c3e8da3$5496439d@news.astraweb.com> <024ef21a-9ef9-48a6-8372-1d66895583c3@v16g2000yqn.googlegroups.com> <87zktr5yze.fsf_-_@mithlond.arda> <877hgv2fg3.fsf@mithlond.arda> <8762wc526v.fsf.mdw@metalzone.distorted.org.uk> <87hbfwfxoq.fsf@benfinney.id.au> Message-ID: On 2010-11-04, Ben Finney wrote: > As has been noted before, there is no intuitive interface except the > nipple. Everything else is not intuitive, but must be learned. What exactly is so intuitive about being slapped in the face followed by being slapped with a lawsuit? From jlconlin at gmail.com Thu Nov 4 21:37:47 2010 From: jlconlin at gmail.com (Jeremy) Date: Thu, 4 Nov 2010 18:37:47 -0700 (PDT) Subject: Compiling/Installing Python 2.7 on OSX 10.6 References: <3d9139ae-bd6f-4567-bb02-b21a8ba86e50@o15g2000prh.googlegroups.com> <238cec6d-2f47-4c97-8941-e28e6808946c@a9g2000pro.googlegroups.com> <6F087CE1-5391-4EE3-B92A-5A499FDF0E6C@semanchuk.com> Message-ID: <64cfb3eb-7cc3-46bf-b511-ade07d780c9d@w30g2000prj.googlegroups.com> On Nov 4, 5:08?pm, Ned Deily wrote: > In article <6F087CE1-5391-4EE3-B92A-5A499FDF0... at semanchuk.com>, > ?Philip Semanchuk wrote: > > > You might want to try this before running tar to see if it inhibits the ._ > > files: > > export COPYFILE_DISABLE=True > > > I know that tells tar to ignore those files (resource forks, no?) when > > building a tarball. I don't know if it helps with extraction though. > > Interesting. ?It's been so long since I've had to deal with ._ 's (which > is where metadata for extended attributes including resource forks are > stored), I had forgotten about that poorly documented option for 10.5 > and 10.6. > > A little experiment: from OS X 10.6, I NFS-mount a remote Linux (ext3) > file system and have created files on it with extended attributes. ? > Using ls on either the OS X or the Linux side, the ._ files appear as > regular files. ?On the Linux side, ?I use gnu tar to archive the files > and move that archive back to OS X. ?If I then use the stock Apple 10.6 > tar to extract that archive to an HFS+ directory, the extended > attributes are by default restored properly (they can be viewed with ls > -l@) and no '._' files - great! ?If I first export > COPYFILE_DISABLE=True, then the tar extraction appears to ignore the ._ > files: the extended attributes are not set and the ._ files still do not > appear. > > So the COPYFILE_DISABLE trick may very well work for this issue. ?It > still raises the question of why the ._ files are being created in the > first place. ?They shouldn't be on the python.org tarball so it would > seem most likely they are due to some operation on the OS X machine that > causes extended attributes to be created. ?Nothing wrong with that, just > kind of interesting. > > -- > ?Ned Deily, > ?n... at acm.org What I have done is perform the installation on a local hard drive (not network storage). This prevents any ._* files from being created. Now I just have to copy the installation to ~/Library/ Frameworks or just link to the local copy. I started the compilation when I left, tomorrow I'll finish up and see how it went. I don't anticipate any more problems. Thanks, Jeremy From ldo at geek-central.gen.new_zealand Thu Nov 4 21:54:55 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 05 Nov 2010 14:54:55 +1300 Subject: subprocess.Popen not replacing current process? References: <0f1a17f4-b6a9-4e89-ac26-74b1098a065e@b19g2000prj.googlegroups.com> <7c5be6d7-5782-44ad-aae7-7f7bbc798d43@n32g2000prc.googlegroups.com> Message-ID: In message <7c5be6d7-5782-44ad-aae7-7f7bbc798d43 at n32g2000prc.googlegroups.com>, goodman wrote: > Though I'm still a little confused how, if subprocess.Popen is using > os.execvp, it still maintains control of things like interrupts. The implied point, being that we are spawning subprocesses, is that there is a fork call before the exec. > Anyway, my problem is solved. Thanks! Glad to hear it. From rustompmody at gmail.com Thu Nov 4 22:47:02 2010 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 5 Nov 2010 08:17:02 +0530 Subject: Compare source code Message-ID: The real issue is not tabs/spaces vs braces but academic/scientific orientation vs engineering/commercial needs. Mostly these worlds are so far separated that no dialogue happens -- think C vs Pascal, Java vs Eiffel etc The problem -- actually advantage -- is that Python straddles both worlds. Mailers messing code, even editors messing (large) refactorings are engineering concerns. The visual clarity of (usually small) pieces of code is an academic concern. Ive been in both worlds: being able to have a significant piece of code projected on a single screen is often the single biggest factor which makes something teachable or not. And indentation based structure is not the only thing that aids this in languages like python and haskell -- think of comprehensions, no type declarations, REPL removing the need for (most) print statements etc etc. Conversely there are 'real-world' situations where python's indentation breaks things -- eg python-server-pages where python's indentation mixes badly with html's As far as I am concerned python would not be python if its indentation=structure went. However the original question -- mixing tabs and spaces is bad -- has got lost in the flames. Do the most die-hard python fanboys deny this? And if not is it asking too much (say in python3) that mixing tabs and spaces be flagged as an error or at least warning? From tjreedy at udel.edu Thu Nov 4 23:15:13 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 04 Nov 2010 23:15:13 -0400 Subject: Best method for a menu in a command line program? In-Reply-To: <87sjzgfy0x.fsf@benfinney.id.au> References: <87sjzgfy0x.fsf@benfinney.id.au> Message-ID: On 11/4/2010 7:51 PM, Ben Finney wrote: > Terry Reedy writes: > >> Others have answered that, but I would point to the inefficiency for >> users of having to enter unit and value on two separate lines. The >> prompt could be "Enter value and unit (f, c, or k) or q to quit: " >> Allow upper and lower case, with or without a space between. > > Well, if we're going to critique the design, I'd say that I find the GNU > Units program to be a > good flexible implementation of a command-line units converter. > > I suspect, though, that the object of the OP was not so much to make a > good unit converter, but rather to learn from a simple example exercise. Right. I think he would learn something from the exercize I suggest. -- Terry Jan Reedy From tjreedy at udel.edu Thu Nov 4 23:25:42 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 04 Nov 2010 23:25:42 -0400 Subject: Compare source code In-Reply-To: References: Message-ID: On 11/4/2010 10:47 PM, Rustom Mody wrote: > As far as I am concerned python would not be python if its > indentation=structure went. However the original question -- mixing > tabs and spaces is bad -- has got lost in the flames. Do the most > die-hard python fanboys deny this? Of course not. Not mixing tabs and spaces has been the recommendation for perhaps a decade. > And if not is it asking too much (say in python3) that mixing tabs and spaces > be flagged as an error or at least warning? Making all mixture an error was considered but rejected as causing too much gratuitous breakage. One reason: you cut code from some source with the 'other' style and paste into code with 'your' style. Should you be *forced* (rather than merely advised) to convert before running the result even once. Guido decided that there was enough breakage from important things like unicode text and all new-style classes. On the other hand, someone said that ambiguous mixtures now are prohibited. -- Terry Jan Reedy From rantingrick at gmail.com Fri Nov 5 01:03:36 2010 From: rantingrick at gmail.com (rantingrick) Date: Thu, 4 Nov 2010 22:03:36 -0700 (PDT) Subject: Compare source code References: Message-ID: <7ed584f8-a0c6-4972-8d0f-c847512eba55@s9g2000vby.googlegroups.com> On Nov 4, 9:47?pm, Rustom Mody wrote: > However the original question -- mixing > tabs and spaces is bad -- has got lost in the flames. ?Do the most > die-hard python fanboys deny this? Hey we need to get something strait right now... i am the only true fanboy around here, all the others are puesdo fanboys. Got it! ;-) From hdc1112 at gmail.com Fri Nov 5 02:46:37 2010 From: hdc1112 at gmail.com (dachuan) Date: Fri, 5 Nov 2010 14:46:37 +0800 Subject: Hello, Everyone. I have a problem when using Pexpect module. Message-ID: hi, everyone. When I use Pexpect Module, I met the following problem and don't know how to handle it. Any advice is appreciated ! My environment: Linux node08_xen3.4.3_rhel5_1 2.6.18.8-xen #1 SMP Wed Jul 14 17:20:01 CST 2010 i686 i686 i386 GNU/Linux (FYI: this is a virtual machine.) Python 2.5.5 and by the way, I have installed pexpect in another machine, and it works pretty well, its environment is: Linux WEB1 2.6.9-42.ELlargesmp #1 SMP Wed Jul 12 23:46:39 EDT 2006 x86_64 x86_64 x86_64 GNU/Linux Python 2.5.5 -bash-3.1$ ./ssh_mutual_trust.py -n Traceback (most recent call last): File "./ssh_mutual_trust.py", line 427, in start(sys.argv[1:]) File "./ssh_mutual_trust.py", line 405, in start sshkeygen() File "./ssh_mutual_trust.py", line 137, in sshkeygen keygen_child = pexpect.spawn(new_keygen_cmd) File "/usr/local/lib/python2.5/site-packages/pexpect.py", line 430, in __init__ self._spawn (command, args) File "/usr/local/lib/python2.5/site-packages/pexpect.py", line 530, in _spawn raise ExceptionPexpect('Error! pty.fork() failed: ' + str(e)) pexpect.ExceptionPexpect: Error! pty.fork() failed: out of pty devices -bash-3.1$ -- Dachuan Huang, Graduate Candidate ----------------------------------------------------------- Cluster and Grid Computing Lab Services Computing Technology and System Lab Huazhong University of Science and Technology Wuhan, 430074, China Tel: +86-15902733227 Email: hdc1112 at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From rustompmody at gmail.com Fri Nov 5 03:20:09 2010 From: rustompmody at gmail.com (rustom) Date: Fri, 5 Nov 2010 00:20:09 -0700 (PDT) Subject: Compare source code References: Message-ID: On Nov 5, 8:25?am, Terry Reedy wrote: > On 11/4/2010 10:47 PM, Rustom Mody wrote: > > > As far as I am concerned python would not be python if its > > indentation=structure went. ?However the original question -- mixing > > tabs and spaces is bad -- has got lost in the flames. ?Do the most > > die-hard python fanboys deny this? > > Of course not. Not mixing tabs and spaces has been the recommendation > for perhaps a decade. > > > And if not is it asking too much (say in python3) that mixing tabs and spaces > > ?> be flagged as an error or at least warning? > > Making all mixture an error was considered but rejected as causing too > much gratuitous breakage. One reason: you cut code from some source with > the 'other' style and paste into code with 'your' style. Should you be > *forced* (rather than merely advised) to convert before running the > result even once. Guido decided that there was enough breakage from > important things like unicode text and all new-style classes. That means that obvious and easily repairable-with-trivial-tools breakage is being traded for more insidious breakage > > On the other hand, someone said that ambiguous mixtures now are prohibited. > Not sure I understand the issues here. From python at rcn.com Fri Nov 5 04:58:10 2010 From: python at rcn.com (Raymond Hettinger) Date: Fri, 5 Nov 2010 01:58:10 -0700 (PDT) Subject: Final state of underlying sequence in islice References: Message-ID: <4b599f9b-5d99-4a9a-85a8-4ccba233bdc4@35g2000prb.googlegroups.com> > ?Shashank Singh wrote: > > > Are there any promises made with regard to final state of the underlying > > sequence that islice slices? Currently, there are no promises or guarantees about the final state of the iterator. To the extent the pure Python version in the docs differs from the CPython implementation in this regard, it is an accidental implementation detail. That being said, we could introduce some guarantees (earliest possible stop point, latest possible stop point, or decide to leave it undefined). I'm curious about your use case, as it might guide the decision. Are there any useful invariants that might arise from one choice or the other? The case is question seems a bit rare (the stop argument indexes an element before the iterator terminates, the step argument is more than one, the stop argument is not at the start plus an exact multiple of step, and you care about where the iterator is afterwards). The question is why you would have all of those conditions and not have stop==start+n*step. For regular slices, you seem to get useful invariants only when stop falls along the natural boundaries: s[a:b:step] + s[b:c:step] == s[a:c:step] # only when b == a+n*step So, it's not obvious what the semantics should be when b != a+n*step. Raymond From steve at REMOVE-THIS-cybersource.com.au Fri Nov 5 04:58:19 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Nov 2010 08:58:19 GMT Subject: functions, list, default parameters References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <20101021235138.609fe668@geekmail.INVALID> <87pquk3ehs.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <4cd3c72b$0$30004$c3e8da3$5496439d@news.astraweb.com> On Thu, 04 Nov 2010 22:34:07 +0000, Mark Wooding wrote: > (Based on experience with other languages, I suspect that evaluating the > default expression afresh for each call where it's needed would be more > useful; but it's way too late to change that now.) Let's call the two strategies: defaults initialise on function definition (DID) defaults initialise on function call (DIC) I claim that when designing a general purpose language, DID (Python's existing behaviour) is better than DIC: (1) most function defaults only need to be set once; (2) it's easy to get DIC if the language uses DID, but hard the other way; (3) DIC is needless wasteful for common function definitions; (4) DIC can lead to surprising bugs. That last isn't a big concern, since DID can lead to surprising bugs as well *wink*, but it's worth mentioning the failure mode. #1 Most default values are things like True, False, None, integer or string literals. Since they're literals, they will never change, so you only need to set them once. #2 It's easy to get default values to initialise on function call in a language that uses initialisation on function definition semantics: just move the initialisation into the function body. Python has a particularly short and simple idiom for it: def f(x=None): if x is None: x = some_expression() But if the situations were reversed, it's hard to get the DID semantics: def f(x=None): if x is None: global _f_default_arg try: x = _f_default_arg except NameError: _f_default_arg = x = default_calculation() #3 Re-initialising default values is wasteful for many functions, perhaps the majority of them. (Of course, if you *need* DIC semantics, it isn't wasteful, but I'm talking about the situations where you don't care either way.) In current Python, nobody would write code like this: def f(x=None, y=None, z=None): if x is None: x = 1 if y is None: y = 2 if z is None: z = 3 but that's what the DIC semantics effectively does. When you need it, it's useful, but most of the time it's just a performance hit for no good reason. A smart compiler would factor out the assignment to a constant and do it once, when the function were defined -- which is just what DID semantics are. If you're unconvinced about this being a potential performance hit, consider: def expensive_function(): time.sleep(30) # simulate a lot of computation return 1.23456789 def f(x=expensive_function()): ... What would you prefer, the default value to be calculated once, or every time you called f()? #4 Just as DID leads to surprising behaviour with mutable defaults, so DIC can lead to surprising behaviour: def f(x=expression): do_something_with(x) If expression is anything except a literal, it could be changed after f is defined but before it is called. If so, then f() will change it's behaviour. -- Steven From hdc1112 at gmail.com Fri Nov 5 05:03:55 2010 From: hdc1112 at gmail.com (dachuan) Date: Fri, 5 Nov 2010 17:03:55 +0800 Subject: Hello, Everyone. I have a problem when using Pexpect module. In-Reply-To: References: Message-ID: maybe i found why pexpect doesn't work in my environment. (but still, i don't know how solve it) my machine is actually a xen domain U, whose kernel is host's kernel. when I test pexpect module directly on host machine, it works pretty fine. and that's all I can do about it, maybe pexpect use pseudo-terminal, and domain U doesn't support this well. maybe nobody here has encountered this problem before, and i write here just for everyone's information. On Fri, Nov 5, 2010 at 2:46 PM, dachuan wrote: > hi, everyone. > When I use Pexpect Module, I met the following problem and don't know how > to handle it. > Any advice is appreciated ! > > My environment: > Linux node08_xen3.4.3_rhel5_1 2.6.18.8-xen #1 SMP Wed Jul 14 17:20:01 CST > 2010 i686 i686 i386 GNU/Linux (FYI: this is a virtual machine.) > Python 2.5.5 > > and by the way, I have installed pexpect in another machine, and it works > pretty well, its environment is: > Linux WEB1 2.6.9-42.ELlargesmp #1 SMP Wed Jul 12 23:46:39 EDT 2006 x86_64 > x86_64 x86_64 GNU/Linux > Python 2.5.5 > > > -bash-3.1$ ./ssh_mutual_trust.py -n > Traceback (most recent call last): > File "./ssh_mutual_trust.py", line 427, in > start(sys.argv[1:]) > File "./ssh_mutual_trust.py", line 405, in start > sshkeygen() > File "./ssh_mutual_trust.py", line 137, in sshkeygen > keygen_child = pexpect.spawn(new_keygen_cmd) > File "/usr/local/lib/python2.5/site-packages/pexpect.py", line 430, in > __init__ > self._spawn (command, args) > File "/usr/local/lib/python2.5/site-packages/pexpect.py", line 530, in > _spawn > raise ExceptionPexpect('Error! pty.fork() failed: ' + str(e)) > pexpect.ExceptionPexpect: Error! pty.fork() failed: out of pty devices > -bash-3.1$ > > > -- > Dachuan Huang, Graduate Candidate > ----------------------------------------------------------- > Cluster and Grid Computing Lab > Services Computing Technology and System Lab > Huazhong University of Science and Technology > Wuhan, 430074, China > Tel: +86-15902733227 > > Email: hdc1112 at gmail.com > -- Dachuan Huang, Graduate Candidate ----------------------------------------------------------- Cluster and Grid Computing Lab Services Computing Technology and System Lab Huazhong University of Science and Technology Wuhan, 430074, China Tel: +86-15902733227 Email: hdc1112 at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From nospam at torek.net Fri Nov 5 06:03:07 2010 From: nospam at torek.net (Chris Torek) Date: 5 Nov 2010 10:03:07 GMT Subject: Popen Question References: <891a9a80-c30d-4415-ac81-bddd0b564fa6@g13g2000yqj.googlegroups.com> Message-ID: In article <891a9a80-c30d-4415-ac81-bddd0b564fa6 at g13g2000yqj.googlegroups.com> moogyd wrote: >[sde:staff at lbux03 ~]$ python >Python 2.6 (r26:66714, Feb 21 2009, 02:16:04) >[GCC 4.3.2 [gcc-4_3-branch revision 141291]] on linux2 >Type "help", "copyright", "credits" or "license" for more information. >>>> import os, subprocess >>>> os.environ['MYVAR'] = "myval" >>>> p = subprocess.Popen(['echo', '$MYVAR'],shell=True) Alain Ketterlin has already explained these to some extent. Here is a bit more. This runs, underneath: ['/bin/sh', '-c', 'echo', '$MYVAR'] (with arguments expressed as a Python list). /bin/sh takes the string after '-c' as a command, and the remaining argument(s) if any are assigned to positional parameters ($0, $1, etc). If you replace the command with something a little more explicit, you can see this: >>> p = subprocess.Popen( ... [r'echo \$0=$0 \$1=$1', 'arg0', '$MYVAR'], shell=True) >>> $0=arg0 $1=$MYVAR p.wait() 0 >>> (I like to call p.communicate() or p.wait(), although p.communicate() is pretty much a no-op if you have not done any redirecting. Note that p.communicate() does a p.wait() for you.) >>>> p = subprocess.Popen(['echo', '$MYVAR']) >>>> $MYVAR This time, as Alain noted, the shell does not get involved so no variable expansion occurs. However, you could do it yourself: >>> p = subprocess.Popen(['echo', os.environ['MYVAR']]) >>> myval p.wait() 0 >>> >>>> p = subprocess.Popen('echo $MYVAR',shell=True) >>>> myval (here /bin/sh does the expansion, because you invoked it) >>>> p = subprocess.Popen('echo $MYVAR') >Traceback (most recent call last): > File "", line 1, in > File "/usr/lib64/python2.6/subprocess.py", line 595, in __init__ > errread, errwrite) > File "/usr/lib64/python2.6/subprocess.py", line 1106, in >_execute_child > raise child_exception >OSError: [Errno 2] No such file or directory This attempted to run the executable named 'echo $MYVAR'. It did not exist so the underlying exec (after the fork) failed. The exception was passed back to the subprocess module, which raised it in the parent for you to see. If you were to create an executable named 'echo $MYVAR' (including the blank and dollar sign) somewhere in your path (or use an explicit path to it), it would run. I will also capture the actual output this time: $ cat '/tmp/echo $MYVAR' #! /usr/bin/awk NR>1{print} this is a self-printing file anything after the first line has NR > 1, so gets printed $ chmod +x '/tmp/echo $MYVAR' $ python Python 2.5.1 (r251:54863, Feb 6 2009, 19:02:12) [GCC 4.0.1 (Apple Inc. build 5465)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import subprocess >>> p = subprocess.Popen('/tmp/echo $MYVAR', stdout=subprocess.PIPE) >>> print p.communicate()[0] this is a self-printing file anything after the first line has NR > 1, so gets printed >>> p.returncode 0 >>> Incidentally, fun with #!: you can make self-renaming scripts: sh-3.2$ echo '#! /bin/mv' > /tmp/selfmove; chmod +x /tmp/selfmove sh-3.2$ ls /tmp/*move* /tmp/selfmove sh-3.2$ /tmp/selfmove /tmp/I_moved sh-3.2$ ls /tmp/*move* /tmp/I_moved sh-3.2$ or even self-removing scripts: sh-3.2$ echo '#! /bin/rm' > /tmp/rmme; chmod +x /tmp/rmme sh-3.2$ /tmp/rmme sh-3.2$ /tmp/rmme sh: /tmp/rmme: No such file or directory (nothing to do with python, just the way #! interpreter lines work). -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html From alain at dpt-info.u-strasbg.fr Fri Nov 5 06:21:57 2010 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Fri, 05 Nov 2010 11:21:57 +0100 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87mxpoax4q.fsf@dpt-info.u-strasbg.fr> Terry Reedy writes: > If you add the normally redundant information in the form of explicit > dedents (anything starting with '#' and distinguishable from normal > comments), then it is not too hard to re-indent even after all indents > have been removed. I actually use such a trick in emacs, not with comments but with "pass" (emacs' python mode knows that pass end return end the current block). It's extrememly useful in heavily nested code, or if I need to paste some piece of code from one level to another. This lets my editor's auto-indenter do the right thing. And I see immediately if/when I did the nesting wrong. I really like "indentation as structure" (code is more compact and clearer), but I really hate that it relies on me putting the right spaces at the right place. I would love to be able to put, e.g., a period at the end of a line, to indicate that the next line is one level upper. Something like: for i in ... : for j in ... : whatever(i,j). . No lost vertical space (except when I decide it), no ambiguity. It looks to me like the exact opposite of ':'. End-of-line periods (or exclamation marks) would let tools reindent correctly in all cases. I don't think it conflicts with any other syntax. -- Alain. From steve at REMOVE-THIS-cybersource.com.au Fri Nov 5 06:36:14 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Nov 2010 10:36:14 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <87mxpoax4q.fsf@dpt-info.u-strasbg.fr> Message-ID: <4cd3de1d$0$30004$c3e8da3$5496439d@news.astraweb.com> On Fri, 05 Nov 2010 11:21:57 +0100, Alain Ketterlin wrote: > I really like "indentation as structure" (code is more compact and > clearer), but I really hate that it relies on me putting the right > spaces at the right place. Er what? You really like indentation as structure, but you don't like putting in the indentation? > I would love to be able to put, e.g., a > period at the end of a line, to indicate that the next line is one level > upper. Something like: > > for i in ... : > for j in ... : > whatever(i,j). > . How is that different from this? for i in ... : for j in ... : whatever(i,j) What's the point of the dots? Is that just to save you from having to hit shift-tab (or whatever your editor's decrease-indent command is)? > No lost vertical space (except when I decide it), no ambiguity. What lost vertical space are you worried about? > It looks > to me like the exact opposite of ':'. End-of-line periods (or > exclamation marks) would let tools reindent correctly in all cases. I > don't think it conflicts with any other syntax. for i in ... : for j in ... : n = 2. -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Nov 5 06:37:05 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Nov 2010 10:37:05 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> Message-ID: <4cd3de51$0$30004$c3e8da3$5496439d@news.astraweb.com> On Thu, 04 Nov 2010 21:47:59 +0000, Tim Harig wrote: > I have seen huge patches caused by nothing more then some edit that > accidently added a trailing space to a large number of lines. White > space mangling happens all the time without people even knowing about > it. How does an edit accidentally add a trailing space to a large number of lines? (1) The programmer shifted the cursor to the end of the line, pressed space, moved down a line, shift to eol, press space, repeat a large number of times. I don't call that an "accident". (2) Some programmer used a tool that thought it was okay to add whitespace to the end of lines without being told to. I don't call that an accident either, I call that using a broken tool. So we keep coming back to work-arounds for tools that mangle your data for no good reason... -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Nov 5 06:41:40 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Nov 2010 10:41:40 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <87r5f13ug3.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <4cd3df64$0$30004$c3e8da3$5496439d@news.astraweb.com> On Thu, 04 Nov 2010 20:17:35 +0000, Seebs wrote: >> * I /do/ have a significant problem with cutting and pasting code in >> Python. In most languages, I can haul a chunk of code about, hit >> C-M-q, and Emacs magically indents the result properly. This is, >> unfortunately, impossible with Python. It has caused me real bugs, >> and I have to be extra careful to fix the indentation up. > > That was the thing which bit me the worst. I had a fairly large block > of code in a first-pass ugly program. I wanted to start refactoring it, > so I moved a big hunk of code into a method (with plans to further > refactor). It took about fifteen minutes to redo the logic. Well there's your problem -- you are relying on tools that operate by magic. Rather than re-create the logic, why not just hit Undo and then re-paste the code *without* the magic auto-reformat? Half a second, to undo and re- paste, followed by 10 or 20 seconds to select the appropriate lines and *explicitly* re-indent the lines to the correct level. For somebody who keeps tossing around the mantra that "explicit is better than implicit", you're amazingly reliant on a tool that performs massive, apparently irreversible formatting operations implicitly. And then rather than accept that your magic DWIM tool is unsuitable for the task you are putting it to, you then blame the data for not having error-correction codes that would allow *another* magic tool to fix the breakage caused by the first magic tool! -- Steven From sschwarzer at sschwarzer.net Fri Nov 5 07:34:35 2010 From: sschwarzer at sschwarzer.net (Stefan Schwarzer) Date: Fri, 05 Nov 2010 12:34:35 +0100 Subject: Tools for turning Python code into XMI? In-Reply-To: References: <4CC3FAD1.5080703@sschwarzer.net> Message-ID: <4CD3EBCB.8020206@sschwarzer.net> Hi Lawrence, I missed your answer because I didn't expect someone to respond after all this time. :-) On 2010-10-30 04:07, Lawrence D'Oliveiro wrote: >> I'm looking for a tool which can read Python files and write >> a corresponding XMI file for import into UML tools. > > UML ... isn?t that something more in vogue among the > Java/DotNet corporate-code-cutter-drone crowd? I don't know, that may well be. I still find it useful from time to time. I don't mind using tools I find useful, regardless who else uses them. :-) > Specifically, you?re asking for something that can parse a > dynamic language and generate a static structural > description of that code. I don?t think it?s possible, in > general. The tools I described in my previous post go a great length towards extracting the necessary information. But of course it's not reliably possible to extract all information, for example dynamically generated methods. But few Python programs use this extensively, and a good tool will extract most of the information interesting for me. I'm always surprised about what Pylint finds out about my source code. :) Given the existing open source tools, the problem rather seems to be the effort of implementing XMI generation than to get the information out of the Python code in the first place. Stefan From alain at dpt-info.u-strasbg.fr Fri Nov 5 07:36:44 2010 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Fri, 05 Nov 2010 12:36:44 +0100 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <87mxpoax4q.fsf@dpt-info.u-strasbg.fr> <4cd3de1d$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87sjzggfxv.fsf@dpt-info.u-strasbg.fr> Steven D'Aprano writes: >> I really like "indentation as structure" (code is more compact and >> clearer), but I really hate that it relies on me putting the right >> spaces at the right place. > > Er what? You really like indentation as structure, but you don't like > putting in the indentation? Exactly. I want the extra safety belt of not relying on spaces only. >> for i in ... : >> for j in ... : >> whatever(i,j). >> . > > How is that different from this? > > for i in ... : > for j in ... : > whatever(i,j) At this point exactly, there's no way to know what the indentation of the next line should be. My example above explicitely indicates the next line should be at the same level as "for j ...". Now suppose that, at this very place, you have to paste some other if/for/while block whose original indentation is not exactly aligned with the fragment above. No way to decide automatically how to align it (under "for j"? under "whatever"?). The dots I suggest are nothing more than tiny closing braces. > What's the point of the dots? Is that just to save you from having to hit > shift-tab (or whatever your editor's decrease-indent command is)? Redundancy. I often have deeply nested constructs, that I sometimes need to move around. A real pain, compared to brace-based languages, where constructs are explicitely terminated (i.e., not implicitely by the start of the next construct). Have automatically indented source is a useful and quick check. >> No lost vertical space (except when I decide it), no ambiguity. > > What lost vertical space are you worried about? You've cut the part of my message where I say that python's (vertical) compactness is one of its strong points. >> It looks to me like the exact opposite of ':'. End-of-line periods >> (or exclamation marks) would let tools reindent correctly in all >> cases. I don't think it conflicts with any other syntax. > for i in ... : > for j in ... : > n = 2. You're right, I forgot this one (probably because I never use this kind of elision). No big deal: for i in ... : for j in ... : n = 2. m = 3. . for j in ... : f = 2 . ... -- Alain. From mdw at distorted.org.uk Fri Nov 5 08:17:00 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Fri, 05 Nov 2010 12:17:00 +0000 Subject: functions, list, default parameters References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <20101021235138.609fe668@geekmail.INVALID> <87pquk3ehs.fsf.mdw@metalzone.distorted.org.uk> <4cd3c72b$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8739rg2ceb.fsf.mdw@metalzone.distorted.org.uk> Steven D'Aprano writes: > defaults initialise on function definition (DID) > defaults initialise on function call (DIC) > > I claim that when designing a general purpose language, DID (Python's > existing behaviour) is better than DIC: > > #1 Most default values are things like True, False, None, integer or > string literals. Since they're literals, they will never change, so you > only need to set them once. Right; so a half-decent compiler can notice this and optimize appropriately. Result: negligible difference. > #2 It's easy to get default values to initialise on function call in a > language that uses initialisation on function definition semantics: just > move the initialisation into the function body. Python has a particularly > short and simple idiom for it: > > def f(x=None): > if x is None: > x = some_expression() That's actually rather clumsy. Also, it's using in-band signalling: you've taken None and used it as a magic marker meaning `not supplied'. Suppose you want to distinguish /any/ supplied value from a missing argument: how do you do this /correctly/? The approaches I see are (a) to invent some unforgeable token or (b) emulate the argument processing by rifling through * and ** arguments. Solution (a) looks like this: _missing = ['missing'] def foo(arg = _missing): if arg is _missing: arg = ... ... But now _missing is kicking around in the module's namespace. Fixing that is rather messy. (No, you can't just `del' it.) Maybe this can be improved: def _magic(): _missing = ['missing'] def foo(arg = _missing): if arg is _missing: arg = ... ... return foo foo = _magic() del foo Solution (b) is just too grim. > But if the situations were reversed, it's hard to get the DID semantics: > > def f(x=None): > if x is None: > global _f_default_arg > try: > x = _f_default_arg > except NameError: > _f_default_arg = x = default_calculation() Ugh. This is artificially awful and doesn't correspond to existing Python DID semantics. * Python evaluates the default argument expression at function definition time. You've implemented delayed evaluation for no obvious reason. * Python evaluates the default argument expression in the enclosing environment. You've evaluated the expression in the function, again for no obvious reason. I'm interested to know why you did this. You know Python well enough that it's probably not just a misunderstanding, and you have enough integrity that it's probably not a dishonest debating tactic. A more faithful implementation of the actual semantics is considerably simpler. _default_arg = ... def func(arg = _default_arg): ... This is always correct, and actually simpler than even the standard but incorrect simulation of DIC. > #3 Re-initialising default values is wasteful for many functions, perhaps > the majority of them. (Of course, if you *need* DIC semantics, it isn't > wasteful, but I'm talking about the situations where you don't care > either way.) In current Python, nobody would write code like this: > > def f(x=None, y=None, z=None): > if x is None: x = 1 > if y is None: y = 2 > if z is None: z = 3 > > but that's what the DIC semantics effectively does. When you need it, > it's useful, but most of the time it's just a performance hit for no good > reason. A smart compiler would factor out the assignment to a constant > and do it once, when the function were defined -- which is just what DID > semantics are. Python's compiler is already clever enough to notice a constant expression when it sees one, and memoizing the default argument values is straightforward enough. There's therefore nothing to choose between the two on constant expressions. > If you're unconvinced about this being a potential performance hit, > consider: No, I can see that clearly, thanks. That comes up much less frequently than the case where a default argument value should be a fresh list or dictionary, in my experience. > What would you prefer, the default value to be calculated once, or every > time you called f()? This situation is rare enough that I'd put up with manual memoization. > #4 Just as DID leads to surprising behaviour with mutable defaults, so > DIC can lead to surprising behaviour: > > def f(x=expression): > do_something_with(x) > > If expression is anything except a literal, it could be changed after f > is defined but before it is called. If so, then f() will change it's > behaviour. Yes. Most usefully, the expression may refer to other argument values (to its left, only, presumably). This is frequently handy, not least in object constructors. This is an enormous sidetrack on what I'd hoped would be a parenthetical remark left unremarked. I'm not sure that further discussion will be especially interesting, unless others have experience (not speculation) of DIC semantics that they wish to share. For my part, I've used both and found DIC a winner -- [mdw] From gerlach_joerg at web.de Fri Nov 5 09:19:47 2010 From: gerlach_joerg at web.de (J. Gerlach) Date: Fri, 05 Nov 2010 14:19:47 +0100 Subject: Why "flat is better than nested"? In-Reply-To: <4cc8d49c$0$29982$c3e8da3$5496439d@news.astraweb.com> References: <4cc8d49c$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: Am 28.10.2010 03:40, schrieb Steven D'Aprano: > [ snip a lot of wise words ] Can I put this (translated) in the german python wiki? I guess it might help more people to understand some decisions taken during python's development - and I'm to lazy to do something similar myself ;) Greetings from Berlin J?rg Gerlach From ethan at stoneleaf.us Fri Nov 5 09:29:11 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 05 Nov 2010 06:29:11 -0700 Subject: Compare source code In-Reply-To: <20101104120209.GA16757@rcpc42.vub.ac.be> References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1495f$0$29966$c3e8da3$5496439d@news.astraweb.com> <20101104120209.GA16757@rcpc42.vub.ac.be> Message-ID: <4CD406A7.8040600@stoneleaf.us> Antoon Pardon wrote: > Unless, your code is split over different pages, as when it is printed in a book. > You also need to see the next piece of code to notice the dedention. > > e.g. I have the following code at the bottom of my editor. > > for i := 0 to 9 do > some(code); > more(code); > end; > > I can by just looking at this code notice that I'm looking at the whole for block. > > > But when I have similar python code at the bottom of the page. > > for i in xrange(10): > some(code) > more(code) > > Then I can't make out whether I'm looking at the whole for suite or not. These code pieces are not equivalent -- you have four lines of code in the first piece, only three lines in the python piece; in other words, if the "end;" were not on screen, you would still have no idea if it was the whole block or not; in still other words, the "end;", just like the dedented line, provides the context. ~Ethan~ From bborcic at gmail.com Fri Nov 5 09:42:59 2010 From: bborcic at gmail.com (Boris Borcic) Date: Fri, 05 Nov 2010 14:42:59 +0100 Subject: How convert list to nested dictionary? In-Reply-To: <878w18kbwl.fsf@gmail.com> References: <940876cd-2546-4673-aef4-ba11b4156287@fv1g2000vbb.googlegroups.com> <878w18kbwl.fsf@gmail.com> Message-ID: Arnaud Delobelle wrote: > macm writes: > >> Hi Folks >> >> How convert list to nested dictionary? >> >>>>> l >> ['k1', 'k2', 'k3', 'k4', 'k5'] >>>>> result >> {'k1': {'k2': {'k3': {'k4': {'k5': {}}}}}} >> >> Regards >> >> macm > > reduce(lambda x,y: {y:x}, reversed(l), {}) > d={} while L : d={L.pop():d} From msarro at gmail.com Fri Nov 5 09:43:25 2010 From: msarro at gmail.com (Matty Sarro) Date: Fri, 5 Nov 2010 09:43:25 -0400 Subject: Silly newbie question - Carrot character (^) Message-ID: Hey Everyone, Just curious - I'm working on a program which includes a calculation of a circle, and I found myself trying to use pi*radius^2, and getting errors that data types float and int are unsupported for "^". Now, I realized I was making the mistake of using '^' instead of "**". I've corrected this and its now working. However, what exactly does ^ do? I know its used in regular expressions but I can't seem to find anything about using it as an operator. Sadly my google foo is failing since the character gets filtered out. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Fri Nov 5 09:46:56 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 05 Nov 2010 06:46:56 -0700 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4CD40AD0.4080703@stoneleaf.us> Grant Edwards wrote: > On 2010-11-04, Emile van Sebille wrote: >> On 11/3/2010 4:09 PM Seebs said... >> >>> What's the token that marks the end of a block, corresponding to the >>> colon used to introduce it? >>> >> >> My thoughts tend more towards 'can we get Guido to eliminate the colon >> requirements' -- The indent level of the next line ought to suffice. > > But without the colon, how are people who write programming editors > going to know when to increase the indentation level as I enter code? > Hopefully by the keywords used to introduce the block: if, elif, else, for, while, with, etc. etc. It is not legal to start a new indented block just by appending a colon to the previous line. ~Ethan~ From krister.svanlund at gmail.com Fri Nov 5 09:56:52 2010 From: krister.svanlund at gmail.com (Krister Svanlund) Date: Fri, 5 Nov 2010 14:56:52 +0100 Subject: Silly newbie question - Carrot character (^) In-Reply-To: References: Message-ID: On Fri, Nov 5, 2010 at 2:43 PM, Matty Sarro wrote: > Hey Everyone, > Just curious - I'm working on a program which includes a calculation of a > circle, and I found myself trying to use pi*radius^2, and getting errors > that data types float and int are unsupported for "^". Now, I realized I was > making the mistake of using '^' instead of "**". I've corrected this and its > now working. However, what exactly does ^ do? I know its used in regular > expressions but I can't seem to find anything about using it as an operator. > Sadly my google foo is failing since the character gets filtered out. It's a binary operator i think... something like xor. From __peter__ at web.de Fri Nov 5 09:57:18 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 05 Nov 2010 14:57:18 +0100 Subject: How convert list to nested dictionary? References: <940876cd-2546-4673-aef4-ba11b4156287@fv1g2000vbb.googlegroups.com> <878w18kbwl.fsf@gmail.com> Message-ID: Boris Borcic wrote: > Arnaud Delobelle wrote: >> macm writes: >> >>> Hi Folks >>> >>> How convert list to nested dictionary? >>> >>>>>> l >>> ['k1', 'k2', 'k3', 'k4', 'k5'] >>>>>> result >>> {'k1': {'k2': {'k3': {'k4': {'k5': {}}}}}} >>> >>> Regards >>> >>> macm >> >> reduce(lambda x,y: {y:x}, reversed(l), {}) >> > > d={} > while L : d={L.pop():d} Iterating over the keys in normal order: >>> keys = "abcde" >>> d = outer = {} >>> for key in keys: ... outer[key] = inner = {} ... outer = inner ... >>> d {'a': {'b': {'c': {'d': {'e': {}}}}}} The "functional" variant: >>> d = {} >>> reduce(lambda outer, key: outer.setdefault(key, {}), "abcde", d) {} >>> d {'a': {'b': {'c': {'d': {'e': {}}}}}} In a single expression if you are willing to pay the price: >>> reduce(lambda (accu, outer), key: (accu, outer.setdefault(key, {})), "abcde", ({},)*2)[0] {'a': {'b': {'c': {'d': {'e': {}}}}}} Peter From vlastimil.brom at gmail.com Fri Nov 5 09:57:31 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Fri, 5 Nov 2010 14:57:31 +0100 Subject: Silly newbie question - Carrot character (^) In-Reply-To: References: Message-ID: 2010/11/5 Matty Sarro : > Hey Everyone, > Just curious - I'm working on a program which includes a calculation of a > circle, and I found myself trying to use pi*radius^2, and getting errors > that data types float and int are unsupported for "^". Now, I realized I was > making the mistake of using '^' instead of "**". I've corrected this and its > now working. However, what exactly does ^ do? I know its used in regular > expressions but I can't seem to find anything about using it as an operator. > Sadly my google foo is failing since the character gets filtered out. > > -- > http://mail.python.org/mailman/listinfo/python-list > > Hi, see http://docs.python.org/reference/expressions.html#binary-bitwise-operations for bitwise XOR. The usage in regular expressions is different, of course; hth, vbr From urban.dani at gmail.com Fri Nov 5 10:00:03 2010 From: urban.dani at gmail.com (Daniel Urban) Date: Fri, 5 Nov 2010 15:00:03 +0100 Subject: Silly newbie question - Carrot character (^) In-Reply-To: References: Message-ID: > However, what exactly does ^ do? Bitwise XOR: http://docs.python.org/py3k/reference/expressions.html#binary-bitwise-operations From darcy at druid.net Fri Nov 5 10:00:43 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Fri, 5 Nov 2010 10:00:43 -0400 Subject: Silly newbie question - Carrot character (^) In-Reply-To: References: Message-ID: <20101105100043.70d414aa.darcy@druid.net> On Fri, 5 Nov 2010 09:43:25 -0400 Matty Sarro wrote: > now working. However, what exactly does ^ do? I know its used in regular > expressions but I can't seem to find anything about using it as an operator. It's the XOR operator. Try "help('^')" for more detail. By the way, it's "caret", not "carrot". -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From anand.shashwat at gmail.com Fri Nov 5 10:02:52 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Fri, 5 Nov 2010 19:32:52 +0530 Subject: Silly newbie question - Carrot character (^) In-Reply-To: References: Message-ID: On Fri, Nov 5, 2010 at 7:26 PM, Krister Svanlund wrote: > On Fri, Nov 5, 2010 at 2:43 PM, Matty Sarro wrote: > > Hey Everyone, > > Just curious - I'm working on a program which includes a calculation of a > > circle, and I found myself trying to use pi*radius^2, and getting errors > > that data types float and int are unsupported for "^". Now, I realized I > was > > making the mistake of using '^' instead of "**". I've corrected this and > its > > now working. However, what exactly does ^ do? I know its used in regular > > expressions but I can't seem to find anything about using it as an > operator. > > Sadly my google foo is failing since the character gets filtered out. > > It's a binary operator i think... something like xor. > Yes. Infact '^' is binary XOR. >>> a = 4 >>> bin(a) '0b100' >>> b = 5 >>> bin(b) '0b101' >>> a ^ b 1 100 ^ 101 = 001 > -- > http://mail.python.org/mailman/listinfo/python-list > -- ~l0nwlf -------------- next part -------------- An HTML attachment was scrubbed... URL: From msarro at gmail.com Fri Nov 5 10:05:43 2010 From: msarro at gmail.com (Matty Sarro) Date: Fri, 5 Nov 2010 10:05:43 -0400 Subject: Silly newbie question - Carrot character (^) In-Reply-To: References: Message-ID: Thanks everyone, that explains it :) -Matty On Fri, Nov 5, 2010 at 9:43 AM, Matty Sarro wrote: > Hey Everyone, > Just curious - I'm working on a program which includes a calculation of a > circle, and I found myself trying to use pi*radius^2, and getting errors > that data types float and int are unsupported for "^". Now, I realized I was > making the mistake of using '^' instead of "**". I've corrected this and its > now working. However, what exactly does ^ do? I know its used in regular > expressions but I can't seem to find anything about using it as an operator. > Sadly my google foo is failing since the character gets filtered out. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From philip at semanchuk.com Fri Nov 5 10:12:05 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Fri, 5 Nov 2010 10:12:05 -0400 Subject: Silly newbie question - Carrot character (^) In-Reply-To: References: Message-ID: <386C05F7-692E-4C2C-A75A-E7DC1B7061BF@semanchuk.com> On Nov 5, 2010, at 9:43 AM, Matty Sarro wrote: > Hey Everyone, > Just curious - I'm working on a program which includes a calculation of a > circle, and I found myself trying to use pi*radius^2, and getting errors > that data types float and int are unsupported for "^". Now, I realized I was > making the mistake of using '^' instead of "**". I've corrected this and its > now working. However, what exactly does ^ do? I know its used in regular > expressions but I can't seem to find anything about using it as an operator. > Sadly my google foo is failing since the character gets filtered out. As others have said, ^ is for XOR. That's buried here in the documentation: http://docs.python.org/release/2.7/reference/expressions.html#binary-bitwise-operations Not that I would have expected you to find it there since that's pretty dense. In fact, older versions of the Python doc used to describe this section as "for language lawyers" but I see they've changed that now. BTW the more common name for this character is caret (ka-RAY). Cheers Philip From greenyballz at yahoo.com Fri Nov 5 11:08:19 2010 From: greenyballz at yahoo.com (No Name) Date: Fri, 05 Nov 2010 15:08:19 GMT Subject: newbie qns : how do i use xmldiff? References: Message-ID: <201011511810usenet@eggheadcafe.com> I had to do some fishing around to figure this much out. Hope it helps. from input import * # From the xmldiff directory from fmes import * # From the xmldiff directory from format import * # From the xmldiff directory from StringIO import * # Build your original tree text1 = '123' stream1 = StringIO(text) tree1 = tree_from_stream(stream) # Build your modified tree text2 = '223' stream2 = StringIO(text2) tree2 = tree_from_stream(stream2) # Compare the trees formatter = InternalPrinter() corrector = FmesCorrector(formatter) corrector.process_trees(tree, tree2) ## OUTPUT: ## Instructions for modifying original to modified # [rename, /point[1]/y[1], x] # [insert-after, /point[1]/x[2], # # 2 # # ] # [remove, /point[1]/x[1]] > On Wednesday, February 03, 2010 1:38 AM sWrath swrath wrote: > Hi , > > I am pretty new to python , and reading up on it. > > Basically I am trying to compare xml files . I know difflib have it > but it does not work out as expected. I was looking at xmldiff , > unfortunately I am not able to find documentation how to call it from > python. Anyone knows a link or doc to it as I have been looking high > and low for few days? > > lastly , is there a py (or algorithm) where it behaves exactly like > diff ? Greatly appreciated. > > Thanks > john >> On Wednesday, February 03, 2010 3:34 PM Terry Reedy wrote: >> On 2/3/2010 1:38 AM, sWrath swrath wrote: >> >> When asking such a question, it is good to explain what sort of thing, >> in this case, 'xmldiff' is and where it is is from. Let us assume you >> meant xmldiff from >> >> http://www.logilab.org/859 >> >> It says it is a python tool that can "be used be used as a library or as >> a command line tool." It includes a README file. Have you read that? >> That says "USAGE ... Read the HELP.txt file.". Have you read *that*? >> HELP.txt seems to focus on command line usage. I would start with that. >> To use it as a library (via import ...), you might have to look at the >> source code as I did not see importing covered in my quick look at that >> file. >> >> Terry Jan Reedy >> Submitted via EggHeadCafe - Software Developer Portal of Choice >> FireAndForget Asynchronous Utility Class for SQL Server Inserts and Updates >> http://www.eggheadcafe.com/tutorials/aspnet/7a22d9a4-59fc-40b0-8337-75c76f14fb3b/fireandforget-asynchronous-utility-class-for-sql-server-inserts-and-updates.aspx From cdalten at gmail.com Fri Nov 5 11:16:41 2010 From: cdalten at gmail.com (chad) Date: Fri, 5 Nov 2010 08:16:41 -0700 (PDT) Subject: What is the best way to handle a missing newline in the following case Message-ID: I have an text file with the following numbers 1 3 5 7 3 9 Now the program reads in this file. When it encounters a '\n', it will do some stuff and then move to the next line. For example, it will read 1 and then '\n'. When it sees '\n', it will do some stuff and go on to read 3. The problem is when I get to the last line. When the program sees '\n' after the 9, everything works fine. However, when there isn't a '\n', the program doesn't process the last line. What would be the best approach to handle the case of the possible missing '\n' at the end of the file? From __peter__ at web.de Fri Nov 5 11:32:57 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 05 Nov 2010 16:32:57 +0100 Subject: What is the best way to handle a missing newline in the following case References: Message-ID: chad wrote: > I have an text file with the following numbers > > 1 > 3 > 5 > 7 > 3 > 9 > > > > Now the program reads in this file. When it encounters a '\n', it will > do some stuff and then move to the next line. For example, it will > read 1 and then '\n'. When it sees '\n', it will do some stuff and go > on to read 3. > > The problem is when I get to the last line. When the program sees '\n' > after the 9, everything works fine. However, when there isn't a '\n', > the program doesn't process the last line. > > What would be the best approach to handle the case of the possible > missing '\n' at the end of the file? Don't split the data into lines yourself, delegate to python >>> with open("tmp.txt", "wb") as f: ... f.write("1\n2\n3\r\n4\r5") ... >>> for line in open("tmp.txt", "U"): ... print repr(line) ... '1\n' '2\n' '3\n' '4\n' '5' As you can see "\n", "\r\n" and "\r" are all converted to "\n". This is called universal newline mode and enabled by open(..., "U"). If your client code insists that a line has to end with "\n" and there's no way to change that you can wrap the file >>> def ensure_newline(instream): ... prev = next(instream) ... for cur in instream: ... yield prev ... prev = cur ... if not prev.endswith("\n"): ... prev += "\n" ... yield prev ... >>> for line in ensure_newline(open("tmp.txt", "U")): ... print repr(line) ... '1\n' '2\n' '3\n' '4\n' '5\n' But often the opposite direction, removing any newlines, works just as well and is easier to achieve: >>> for line in open("tmp.txt", "U"): ... print repr(line.strip("\n")) ... '1' '2' '3' '4' '5' Peter From danmcleran at yahoo.com Fri Nov 5 11:37:13 2010 From: danmcleran at yahoo.com (danmcleran at yahoo.com) Date: Fri, 5 Nov 2010 08:37:13 -0700 (PDT) Subject: What is the best way to handle a missing newline in the following case References: Message-ID: <2c298c1f-cb52-4399-a516-897865fd9d89@r4g2000prj.googlegroups.com> > The problem is when I get to the last line. When the program sees '\n' > after the 9, everything works fine. However, when there isn't a '\n', > the program doesn't process the last line. > > What would be the best approach to handle the case of the possible > missing '\n' at the end of the file? use readines to read all lines into a list and then iterate thru the list: f = open(r'c:\test.txt', 'rb') print f.readlines() >> ['1\r\n', '3\r\n', '5\r\n', '7\r\n', '3\r\n', '9'] From paul.nospam at rudin.co.uk Fri Nov 5 11:47:10 2010 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Fri, 05 Nov 2010 15:47:10 +0000 Subject: What is the best way to handle a missing newline in the following case References: <2c298c1f-cb52-4399-a516-897865fd9d89@r4g2000prj.googlegroups.com> Message-ID: <87zktndb7l.fsf@rudin.co.uk> "danmcleran at yahoo.com" writes: >> The problem is when I get to the last line. When the program sees '\n' >> after the 9, everything works fine. However, when there isn't a '\n', >> the program doesn't process the last line. >> >> What would be the best approach to handle the case of the possible >> missing '\n' at the end of the file? > > use readines to read all lines into a list and then iterate thru the > list: > > f = open(r'c:\test.txt', 'rb') > print f.readlines() > >>> > ['1\r\n', '3\r\n', '5\r\n', '7\r\n', '3\r\n', '9'] There's no real point in contructing a list. Just do with open(r'c:\test.txt') as f: for l in f: print int(l) As long as you just have digits and whitespace then that's fine - int() will do as you want. From neilc at norwich.edu Fri Nov 5 11:54:41 2010 From: neilc at norwich.edu (Neil Cerutti) Date: 5 Nov 2010 15:54:41 GMT Subject: What is the best way to handle a missing newline in the following case References: <2c298c1f-cb52-4399-a516-897865fd9d89@r4g2000prj.googlegroups.com> <87zktndb7l.fsf@rudin.co.uk> Message-ID: <8jinm1Ft6eU1@mid.individual.net> On 2010-11-05, Paul Rudin wrote: > "danmcleran at yahoo.com" writes: >>> The problem is when I get to the last line. When the program >>> sees '\n' after the 9, everything works fine. However, when >>> there isn't a '\n', the program doesn't process the last >>> line. >>> >>> What would be the best approach to handle the case of the possible >>> missing '\n' at the end of the file? >> >> use readines to read all lines into a list and then iterate thru the >> list: >> >> f = open(r'c:\test.txt', 'rb') >> print f.readlines() >> >>>> >> ['1\r\n', '3\r\n', '5\r\n', '7\r\n', '3\r\n', '9'] > > There's no real point in contructing a list. Just do > > with open(r'c:\test.txt') as f: > for l in f: > print int(l) > > As long as you just have digits and whitespace then that's fine > - int() will do as you want. Keep in mind that a file that a text file that doesn't end with a newline isn't strictly legal. You can expect problems, or at least warnings, with other tools with such files. -- Neil Cerutti From moura.mario at gmail.com Fri Nov 5 12:41:36 2010 From: moura.mario at gmail.com (macm) Date: Fri, 5 Nov 2010 09:41:36 -0700 (PDT) Subject: How convert list to nested dictionary? References: <940876cd-2546-4673-aef4-ba11b4156287@fv1g2000vbb.googlegroups.com> <878w18kbwl.fsf@gmail.com> Message-ID: <9c917109-92fe-4d1f-9310-b62ff64693f5@k11g2000vbf.googlegroups.com> Hi Folks thanks a lot all. All solutions work fine. while I am doing my home work. Reading "Learning Python" and much more. Let me ask again to close my doubts: >>> l = ['k1', 'k2', 'k3', 'k4', 'k5'] >>> d = reduce(lambda x,y: {y:x}, reversed(l), {'/':[1,2,3]}) >>> d {'k1': {'k2': {'k3': {'k4': {'k5': {'/': [1, 2, 3]}}}}}} >>> d['k1']['k2']['k3']['k4']['k5'] {'/': [1, 2, 3]} >>> d['k1']['k2']['k3']['k4']['k5']['/'] [1, 2, 3] >>> now I want generate the "index" to access the element. ==> d['k1']['k2']['k3']['k4']['k5']['/'] from l So again I have only. >>> l = ['k1', 'k2', 'k3', 'k4', 'k5'] z = ?magicCode? z = d['k1']['k2']['k3']['k4']['k5']['/'] >>> z [1, 2, 3] >>>z.append('4') >>>z [1, 2, 3, 4] Best Regards macm On 5 nov, 11:57, Peter Otten <__pete... at web.de> wrote: > Boris Borcic wrote: > > Arnaud Delobelle wrote: > >> macm ?writes: > > >>> Hi Folks > > >>> How convert list to nested dictionary? > > >>>>>> l > >>> ['k1', 'k2', 'k3', 'k4', 'k5'] > >>>>>> result > >>> {'k1': {'k2': {'k3': {'k4': {'k5': {}}}}}} > > >>> Regards > > >>> macm > > >> reduce(lambda x,y: {y:x}, reversed(l), {}) > > > d={} > > while L : d={L.pop():d} > > Iterating over the keys in normal order: > > >>> keys = "abcde" > >>> d = outer = {} > >>> for key in keys: > > ... ? ? outer[key] = inner = {} > ... ? ? outer = inner > ...>>> d > > {'a': {'b': {'c': {'d': {'e': {}}}}}} > > The "functional" variant: > > >>> d = {} > >>> reduce(lambda outer, key: outer.setdefault(key, {}), "abcde", d) > {} > >>> d > > {'a': {'b': {'c': {'d': {'e': {}}}}}} > > In a single expression if you are willing to pay the price: > > >>> reduce(lambda (accu, outer), key: (accu, outer.setdefault(key, {})), > > "abcde", ({},)*2)[0] > {'a': {'b': {'c': {'d': {'e': {}}}}}} > > Peter From ppearson at nowhere.invalid Fri Nov 5 12:43:37 2010 From: ppearson at nowhere.invalid (Peter Pearson) Date: 5 Nov 2010 16:43:37 GMT Subject: Silly newbie question - Carrot character (^) References: Message-ID: <8jiqhpFmj3U2@mid.individual.net> On Fri, 5 Nov 2010 10:12:05 -0400, Philip Semanchuk wrote: > > BTW the more common name for this character is caret (ka-RAY). Yes, it's caret, but no, it's KA-rit, almost the same as carrot. It's straight from Latin, with no detour through French. -- To email me, substitute nowhere->spamcop, invalid->net. From gb345 at invalid.com Fri Nov 5 12:55:31 2010 From: gb345 at invalid.com (gb345) Date: Fri, 5 Nov 2010 16:55:31 +0000 (UTC) Subject: How to get dynamically-created fxn's source? Message-ID: For a project I'm working on I need a way to retrieve the source code of dynamically generated Python functions. (These functions are implemented dynamically in order to simulate "partial application" in Python.[1]) The ultimate goal is to preserve a textual record of transformations performed on data, along with all the data (both pre- and post- transformation) itself. These transformation functions could be dynamically generated as closures, but I suspect that this would make it more difficult to extract source code that could serve as a reasonably self-contained description of the transformation (because this source code would refer to variables defined outside of the function). An alternative would be to generate the *source code* for the functions dynamically, from a template having slots (within the function's definition) that gets filled in with actual parameter values, and pass this source code to exec. In any case, the problem remains of how to extract the dynamically-generated function's source code. One possibility would be to define a Transformation wrapper class whose __init__ takes the dynamically-generated source code (a string) as argument, keeps it around as an instance attribute for future reference, and exec's it to define its __call__ method. Is this overkill/reinventing the wheel? IOW, does Python already have a built-in way to achieve this same effect? (Also, the wrapper scheme above is somewhat loose: it's relatively easy for the source code instance attribute (as described) to fall out of sync with the function that actually executes when __call__ runs. Maybe a tighter connection between the obtained source code and the code that actually executes when __call__ runs is possible.) I'm aware of the inspect module, but from reading its source code I gather that it is designed for inspecting source code that is explicitly written in files, and would not be too good at inspecting functions that are generated dynamically (i.e. not from source code explicitly given in a source file--I hope that made sense). Your comments and suggestions would be much appreciated. Many thanks in advance! G [1] For example, given a base function spam that has the signature (typeT, typeT, typeT, int, int, int) and three specific integer values X, Y, and Z, dynamically generate a new function spamXYZ with signature (typeT, typeT, typeT) such that spamXYZ(A, B, C) is identical to spam(A, B, C, X, Y, Z), for all possible values of A, B, C. From azeynel1 at gmail.com Fri Nov 5 12:59:38 2010 From: azeynel1 at gmail.com (Zeynel) Date: Fri, 5 Nov 2010 09:59:38 -0700 (PDT) Subject: Exception handling with NameError Message-ID: Hello, I want to append new input to list SESSION_U without erasing its content. I try this: ... try: SESSION_U.append(UNIQUES) except NameError: SESSION_U = [] SESSION_U.append(UNIQUES) ... I would think that at first try I would get the NameError and SESSION_U list would be created and appended; the second time try would work. But it does not. Do you know why? From __peter__ at web.de Fri Nov 5 13:26:27 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 05 Nov 2010 18:26:27 +0100 Subject: Exception handling with NameError References: Message-ID: Zeynel wrote: > I want to append new input to list SESSION_U without erasing its > content. I try this: > > ... > try: > SESSION_U.append(UNIQUES) > except NameError: > SESSION_U = [] > SESSION_U.append(UNIQUES) > ... > I would think that at first try I would get the NameError and > SESSION_U list would be created and appended; the second time try > would work. But it does not. Do you know why? If you want SESSION_U to be global you must say so. E. g.: def your_func(): global SESSION_U # ... > try: > SESSION_U.append(UNIQUES) > except NameError: > SESSION_U = [] > SESSION_U.append(UNIQUES) # ... Of course I'm only guessing because you don't provide enough context. Peter From emile at fenx.com Fri Nov 5 13:32:18 2010 From: emile at fenx.com (Emile van Sebille) Date: Fri, 05 Nov 2010 10:32:18 -0700 Subject: How to get dynamically-created fxn's source? In-Reply-To: References: Message-ID: On 11/5/2010 9:55 AM gb345 said... > In any case, the problem remains of how to extract the > dynamically-generated function's source code. > Are you looking for the source code of the dynamically created wrapper function (effectively the piece that calls the original function) or of the wrapped function? (the piece that ultimately gets called?) I'm pretty sure you can't get source from the executable function (python 2.x anyway), but with your naming scheme, it may be possible to trace into the wrapped function's source. Emile From __peter__ at web.de Fri Nov 5 13:36:30 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 05 Nov 2010 18:36:30 +0100 Subject: How to get dynamically-created fxn's source? References: Message-ID: gb345 wrote: > For a project I'm working on I need a way to retrieve the source > code of dynamically generated Python functions. (These functions > are implemented dynamically in order to simulate "partial application" > in Python.[1]) The ultimate goal is to preserve a textual record > of transformations performed on data, along with all the data (both > pre- and post- transformation) itself. Are you aware of functools.partial? >>> from functools import partial >>> def f(a, b, c, x, y, z): ... return a*x + b*y*y + c*z*z*z ... >>> fstar = partial(f, x=1, y=2, z=3) >>> fstar(1, 0, 0) 1 >>> fstar(0, 1, 0) 4 >>> fstar(0, 0, 1) 27 >>> fstar.args, fstar.keywords ((), {'y': 2, 'x': 1, 'z': 3}) >>> fstar.func From __peter__ at web.de Fri Nov 5 13:40:40 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 05 Nov 2010 18:40:40 +0100 Subject: How convert list to nested dictionary? References: <940876cd-2546-4673-aef4-ba11b4156287@fv1g2000vbb.googlegroups.com> <878w18kbwl.fsf@gmail.com> <9c917109-92fe-4d1f-9310-b62ff64693f5@k11g2000vbf.googlegroups.com> Message-ID: macm wrote: > thanks a lot all. All solutions work fine. > > while I am doing my home work. > Reading "Learning Python" and much more. > > Let me ask again to close my doubts: > >>>> l = ['k1', 'k2', 'k3', 'k4', 'k5'] >>>> d = reduce(lambda x,y: {y:x}, reversed(l), {'/':[1,2,3]}) >>>> d > {'k1': {'k2': {'k3': {'k4': {'k5': {'/': [1, 2, 3]}}}}}} >>>> d['k1']['k2']['k3']['k4']['k5'] > {'/': [1, 2, 3]} >>>> d['k1']['k2']['k3']['k4']['k5']['/'] > [1, 2, 3] >>>> > > now I want generate the "index" to access the element. > > ==> d['k1']['k2']['k3']['k4']['k5']['/'] from l > > So again I have only. >>>> l = ['k1', 'k2', 'k3', 'k4', 'k5'] > > z = ?magicCode? > > z = d['k1']['k2']['k3']['k4']['k5']['/'] You'll eventually have to start and write your first line of code. Why not doing it right now? It is sure more rewarding than copying other people's canned solutions and it can even be fun. Peter From rbroze at yahoo.com Fri Nov 5 13:50:13 2010 From: rbroze at yahoo.com (robert roze) Date: Fri, 5 Nov 2010 10:50:13 -0700 (PDT) Subject: decimal.py ver 2.6,2.7 not working with python 2.7 Message-ID: <281783.63405.qm@web114408.mail.gq1.yahoo.com> I have a 'Python 2.7' installed. It seems like the decimal.py module that comes with the Python2.7 package is not working. I hope I'm wrong, but here's why I think so: If I simply try to import the module, I get this error: >>> import decimal Traceback (most recent call last): File "", line 1, in File "/opt/ictools/python_2_7/lib/python2.7/decimal.py", line 3700, in _numbers.Number.register(Decimal) AttributeError: 'module' object has no attribute 'Number' >>> But, if I download, and import the 2.5 version of decimal.py, it imports with no complaint. In the 2.5 version of decimal.py, there is no reference to '_numbers' like there is in the 2.6 and 2.7 versions. Is this a bug, or is there something I can do to fix it (as a user, with limited permissions)? I don't feel good about continuing to run with the 2.5 decimal.py, since I'll be using alot of numpy and other modules that use decimal, and I don't know how they'll react. Thanks, Bob -------------- next part -------------- An HTML attachment was scrubbed... URL: From usernet at ilthio.net Fri Nov 5 14:02:45 2010 From: usernet at ilthio.net (Tim Harig) Date: Fri, 5 Nov 2010 18:02:45 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> <4cd3de51$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-05, Steven D'Aprano wrote: > On Thu, 04 Nov 2010 21:47:59 +0000, Tim Harig wrote: > >> I have seen huge patches caused by nothing more then some edit that >> accidently added a trailing space to a large number of lines. White >> space mangling happens all the time without people even knowing about >> it. > > How does an edit accidentally add a trailing space to a large number of > lines? Putting it back in context, it doesn't matter. Seeb's point stands. diff -b was designed because there are so many tools and channels that mangle whitespace. Changes in something such as brace style would make non-whitespace changes that would not be eliminated by diff -b. Probably the biggest reason for -b is for handling the differences in line endings used on different platforms. > (1) The programmer shifted the cursor to the end of the line, pressed > space, moved down a line, shift to eol, press space, repeat a large > number of times. I don't call that an "accident". A search and replace operation could easily add extra whitespace and since whitespace is not normally visible, the changes most likely go unnoticed. The bottom line is that it happens and assigning blame really doesn't change that fact. > (2) Some programmer used a tool that thought it was okay to add > whitespace to the end of lines without being told to. I don't call that > an accident either, I call that using a broken tool. Yep, there are probably thousands of tools that mangle whitespace. In many cases, such as differences in line endings, what they are doing is not even wrong. You can blame the tools all you like; but, they are not going away. You keep trying to tell us that using whitespace is superior; but, other languages manage to work with these thousands of imperfect tools without issue. The use of whitespace was a stylistic change and stylistic holy wars exist because it is almost impossible to prove that any reasonable style has benefit over another. That whitespace causes issues is verifiable. I find it hard to concluded that that whitespace based syntax is superior when it tells us that we cannot use thousands of otherwise useful tools that other langauges manage to work with. I find it hard to select a matter of taste with no verifiable benefit over a verifiable disadvantage that happens to strike many people. From invalid at invalid.invalid Fri Nov 5 14:07:07 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 5 Nov 2010 18:07:07 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> <4cd3de51$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-05, Tim Harig wrote: > On 2010-11-05, Steven D'Aprano wrote: >> On Thu, 04 Nov 2010 21:47:59 +0000, Tim Harig wrote: >> >>> I have seen huge patches caused by nothing more then some edit that >>> accidently added a trailing space to a large number of lines. White >>> space mangling happens all the time without people even knowing about >>> it. And how does that affect a Python program? The same as it does a C program. >> How does an edit accidentally add a trailing space to a large number of >> lines? > > Putting it back in context, it doesn't matter. Seeb's point stands. > diff -b was designed because there are so many tools and channels that > mangle whitespace. Changes in something such as brace style would make > non-whitespace changes that would not be eliminated by diff -b. > > Probably the biggest reason for -b is for handling the differences in line > endings used on different platforms. Different line-endings are tolerated by Python just as well as they are by C. -- Grant Edwards grant.b.edwards Yow! They collapsed at ... like nuns in the gmail.com street ... they had no teen appeal! From azeynel1 at gmail.com Fri Nov 5 14:12:49 2010 From: azeynel1 at gmail.com (Zeynel) Date: Fri, 5 Nov 2010 11:12:49 -0700 (PDT) Subject: Exception handling with NameError References: Message-ID: On Nov 5, 1:26?pm, Peter Otten <__pete... at web.de> wrote: > Of course I'm only guessing because you don't provide enough context. > > Peter Thanks. This is the problem I am having, in general: K = [] # a container list K = ["A", "B"] ARCHIVE = [] # a list where items from K is archived ARCHIVE.append(K) # K is updated K = ["C", "D"] # append new K to ARCHIVE ARCHIVE.append(K) The problem I am having is this: If I do: K = [] ARCHIVE = [] ARCHIVE.append(K) any time K is updated (user submits new input) the content of ARCHIVE is erased: If I do this: K = [] ARCHIVE.append(K) I get NameError: "Name ARCHIVE not defined" What is the solution? From usernet at ilthio.net Fri Nov 5 14:13:44 2010 From: usernet at ilthio.net (Tim Harig) Date: Fri, 5 Nov 2010 18:13:44 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> Message-ID: On 2010-11-04, D'Arcy J.M. Cain wrote: > On Thu, 4 Nov 2010 19:37:25 +0000 (UTC) > Tim Harig wrote: >> On 2010-11-04, D'Arcy J.M. Cain wrote: >> You are the one who seems to be on a crusade against against braces. It > > You totally misunderstand me. I am not on a crusade of any sort. I am I appologize that I confused your name with Steven D'Aprano; but, your positions are pretty much the same. > care about. If no one was on a crusade to convince people that > indentation as syntax (can we call is IAS from now on?) was evil then I > wouldn't be posting anything at all on the subject. I am being totally > reactionary here. Neither of you are really adding anything to the conversation other then to assert that you like whitespace syntax and that the problems do not effect you. Good for you; but, that doesn't help the people who are finding that it presents problems. >> would seem to me, that if you want people to accept that white space >> formatting is superior, that you would be looking for a simple way to solve >> the white space mangling problem. > > I might if it was a problem for me. Good for you but telling us that doesn't really help those that do. Your stance is based an a stylistic preference. Holy wars around style continue to exist because, in most cases, it is almost impossible to prove the advantages of one reasonable style over another. It is, however, verifiable that white space syntax causes issues with a large number of common tools. I am a man of science. When choosing between the intangible and verifiable, I choose the verifable truth. >> The world is full of broken tools that many of us have to use; but, why >> should we accept that your choice is superior when other choices manage to >> work with these tools without issues. > > You don't have to accept anything. Choose your own tools. I happen to > choose Python and the tools that I choose to use work fine for me. It is simply hard for me to accept that your solution is better when it is telling us that we have to abandon thousands of tools that other solutions manage to work with without difficulty. From edreamleo at gmail.com Fri Nov 5 14:15:23 2010 From: edreamleo at gmail.com (Edward K. Ream) Date: Fri, 5 Nov 2010 11:15:23 -0700 (PDT) Subject: ANN: Leo 4.8 beta 1 released Message-ID: <3856f751-9440-45c9-871e-4f50b7356c2c@u25g2000pra.googlegroups.com> Leo 4.8 beta 1 is now available at: http://sourceforge.net/project/showfiles.php?group_id=3458&package_id=29106 Leo is a text editor, data organizer, project manager and much more. See: http://webpages.charter.net/edreamleo/intro.html The highlights of Leo 4.8: -------------------------- - Leo now uses the simplest possible sentinel lines in external files. External files with sentinels now look like Emacs org-mode files. - Leo Qt gui now supports Drag and Drop. This was one of the most frequently requested features. - Improved abbreviation commands. You now define abbreviations in Leo settings nodes, not external files. - @url nodes may contain url's in body text. This allows headlines to contain summaries: very useful. - Leo now uses PyEnchant to check spelling. - Leo can now open multiple files from the command line. - Leo's ancient Tangle and Untangle commands are now deprecated. This will help newbies how to learn Leo. - Leo now shows "Resurrected" and "Recovered" nodes. These protect data and show how data have changed. These fix several long-standing data-related problems. - A new "screenshots" plugin for creating slide shows with Leo. I used this plugin to create Leo's introductory slide shows. - A better installer. - Many bug fixes. Links: ------ Leo: http://webpages.charter.net/edreamleo/front.html Forum: http://groups.google.com/group/leo-editor Download: http://sourceforge.net/project/showfiles.php?group_id=3458 Bzr: http://code.launchpad.net/leo-editor/ Quotes: http://webpages.charter.net/edreamleo/testimonials.html From usernet at ilthio.net Fri Nov 5 14:19:05 2010 From: usernet at ilthio.net (Tim Harig) Date: Fri, 5 Nov 2010 18:19:05 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <87mxpoax4q.fsf@dpt-info.u-strasbg.fr> Message-ID: On 2010-11-05, Alain Ketterlin wrote: > Terry Reedy writes: > >> If you add the normally redundant information in the form of explicit >> dedents (anything starting with '#' and distinguishable from normal >> comments), then it is not too hard to re-indent even after all indents >> have been removed. > > I actually use such a trick in emacs, not with comments but with "pass" > (emacs' python mode knows that pass end return end the current block). > It's extrememly useful in heavily nested code, or if I need to paste > some piece of code from one level to another. This lets my editor's > auto-indenter do the right thing. And I see immediately if/when I did > the nesting wrong. Thank-you for your tip. It is nice to know that some people are thinking of ways to work around the trade-offs rather then just asserting that we shouldn't use tools that happen to collide with Python. From msarro at gmail.com Fri Nov 5 14:23:12 2010 From: msarro at gmail.com (Matty Sarro) Date: Fri, 5 Nov 2010 14:23:12 -0400 Subject: Using %x to format number to hex and number of digits Message-ID: I'm currently trying to convert a digit from decimal to hex, however I need the full 4 digit hex form. Python appears to be shortening the form. Example: num = 10 num = "%x"%(num) print(num) >a num = 10 num = "%#x"%(num) print(num) >0xa I need it to output as 0x0a, and the exercise is requiring me to use %x to format the string. Any help would be appreciated. -------------- next part -------------- An HTML attachment was scrubbed... URL: From usernet at ilthio.net Fri Nov 5 14:25:44 2010 From: usernet at ilthio.net (Tim Harig) Date: Fri, 5 Nov 2010 18:25:44 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> <4cd3de51$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-05, Grant Edwards wrote: > On 2010-11-05, Tim Harig wrote: >> On 2010-11-05, Steven D'Aprano wrote: >>> On Thu, 04 Nov 2010 21:47:59 +0000, Tim Harig wrote: >>> >>>> I have seen huge patches caused by nothing more then some edit that >>>> accidently added a trailing space to a large number of lines. White >>>> space mangling happens all the time without people even knowing about >>>> it. > > And how does that affect a Python program? The same as it does a C > program. I wasn't making any statement of C versus Python in this thread. Those have been covered elsewhere. I was responding to your assertion: It exists because so many people change whitespace intentionally in C source code because no two C programmers seem able to agree on how to format code. Diff -b allows you to attempt to ignore semantically null stylistic changes made by programmers. That is clearly wrong. If a C programmer changes the format of the code, it is almost universally true that they will make changes that affect more then just the whitespace on a single line. Diff will register these changes even with the -b option. I provided a couple of common scenerios that are more likely to have justified the -b option. From clp2 at rebertia.com Fri Nov 5 14:35:05 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 5 Nov 2010 11:35:05 -0700 Subject: decimal.py ver 2.6,2.7 not working with python 2.7 In-Reply-To: <281783.63405.qm@web114408.mail.gq1.yahoo.com> References: <281783.63405.qm@web114408.mail.gq1.yahoo.com> Message-ID: On Fri, Nov 5, 2010 at 10:50 AM, robert roze wrote: > I have a 'Python 2.7' installed. > > It seems like the decimal.py module that comes with the Python2.7 package is > not working. I hope I'm wrong, but here's why I think so: > > If I simply try to import the module, I get this error: > >>>> import decimal > Traceback (most recent call last): > ? File "", line 1, in > ? File "/opt/ictools/python_2_7/lib/python2.7/decimal.py", line 3700, in > > ??? _numbers.Number.register(Decimal) > AttributeError: 'module' object has no attribute 'Number' >>>> What does the following output for you?: import numbers print(numbers.__file__) print(dir(numbers)) Cheers, Chris -- http://blog.rebertia.com From nagle at animats.com Fri Nov 5 14:35:31 2010 From: nagle at animats.com (John Nagle) Date: Fri, 05 Nov 2010 11:35:31 -0700 Subject: Compare source code In-Reply-To: <4cd3df64$0$30004$c3e8da3$5496439d@news.astraweb.com> References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <87r5f13ug3.fsf.mdw@metalzone.distorted.org.uk> <4cd3df64$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4cd44e7a$0$1610$742ec2ed@news.sonic.net> On 11/5/2010 3:41 AM, Steven D'Aprano wrote: > On Thu, 04 Nov 2010 20:17:35 +0000, Seebs wrote: > >>> * I /do/ have a significant problem with cutting and pasting code in >>> Python. In most languages, I can haul a chunk of code about, hit >>> C-M-q, and Emacs magically indents the result properly. This is, >>> unfortunately, impossible with Python. It has caused me real bugs, >>> and I have to be extra careful to fix the indentation up. >> >> That was the thing which bit me the worst. I had a fairly large block >> of code in a first-pass ugly program. I wanted to start refactoring it, >> so I moved a big hunk of code into a method (with plans to further >> refactor). It took about fifteen minutes to redo the logic. > > Well there's your problem -- you are relying on tools that operate by > magic. Not magic, just code understanding. INTERLISP's editor allowed the user to select a block of LISP code and make it into a function. The selected block would be analyzed to determine which local variables it referenced, and a new function would be created with those parameters. The block of code at the original point would then be replaced by a call to the function. Today's editors are too dumb to do that right. They're text editors with the illusion of knowing something about the language, not language editors which also format text. John Nagle From emile at fenx.com Fri Nov 5 14:35:55 2010 From: emile at fenx.com (Emile van Sebille) Date: Fri, 05 Nov 2010 11:35:55 -0700 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> Message-ID: On 11/5/2010 11:13 AM Tim Harig said... > It is simply hard for me to accept that your solution is better when > it is telling us that we have to abandon thousands of tools that other > solutions manage to work with without difficulty. I only work with a few tools none of which alter or strip leading whitespace, and I don't try to transport python code in ways that allow harmful transformations to take place, eg, reinterpreted by html or email rendering engines, which aren't effective programming tools anyway. So, which of your tools are you married to that are causing your issues? If-you-got-a-bigger-hammer-you-could-drive-that-phillips-screw-into-anything-ly y'rs, Emile From usenet-nospam at seebs.net Fri Nov 5 14:42:41 2010 From: usenet-nospam at seebs.net (Seebs) Date: 05 Nov 2010 18:42:41 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> <4cd3de51$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-05, Steven D'Aprano wrote: > How does an edit accidentally add a trailing space to a large number of > lines? I would love to know the answer to this question. However, empirically, it happens. My guess would be cutting and pasting in some way. > So we keep coming back to work-arounds for tools that mangle your data > for no good reason... To some extent, this is true. How about this. How about we make the Python TCP Stack. The Python TCP Stack works on the same principles that you advocate for the Python language. For instance, if any packet it receives is malformed or contrary to the applicable specs, it has a 95% chance of dropping the packet, and a 5% chance of interpreting the packet as being of a different type entirely. This will NEVER be a problem, and is a good design, because handling packets which contain any kind of spec violation is just work-arounds for broken tools, right? And the first thing we should do is *always* to ensure that, if anything anywhere does not live up to our proposed specification, it causes us to fail in spectacular ways. Of course, to fully capture the feel of Python's choice here, we have to include some common packet variant, which violates no RFCs, as one of the "broken" ones on the grounds that it doesn't make sense to us and isn't easy for a newcomer to read. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Fri Nov 5 14:45:39 2010 From: usenet-nospam at seebs.net (Seebs) Date: 05 Nov 2010 18:45:39 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <87r5f13ug3.fsf.mdw@metalzone.distorted.org.uk> <4cd3df64$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-05, Steven D'Aprano wrote: > On Thu, 04 Nov 2010 20:17:35 +0000, Seebs wrote: >> That was the thing which bit me the worst. I had a fairly large block >> of code in a first-pass ugly program. I wanted to start refactoring it, >> so I moved a big hunk of code into a method (with plans to further >> refactor). It took about fifteen minutes to redo the logic. > Well there's your problem -- you are relying on tools that operate by > magic. Wrong. > Rather than re-create the logic, why not just hit Undo and then re-paste > the code *without* the magic auto-reformat? Half a second, to undo and re- > paste, followed by 10 or 20 seconds to select the appropriate lines and > *explicitly* re-indent the lines to the correct level. There was no magic auto-reformat. Where did you invent that from? Why are you making stuff up which I never said or referred to? > For somebody who keeps tossing around the mantra that "explicit is better > than implicit", you're amazingly reliant on a tool that performs massive, > apparently irreversible formatting operations implicitly. No, I am not. No such tool was involved. I never mentioned one, referred to one, or hinted at one -- and have never used one, because I hate them. In fact, it is ludicrous to imagine that I was using one, given that I've stated in this very thread that so far as I know such a tool cannot be created for Python. Your decision to invent something I never referred to is not a problem with my approach to the language. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Fri Nov 5 14:48:20 2010 From: usenet-nospam at seebs.net (Seebs) Date: 05 Nov 2010 18:48:20 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> Message-ID: On 2010-11-05, Emile van Sebille wrote: > So, which of your tools are you married to that are causing your issues? Python. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From moura.mario at gmail.com Fri Nov 5 14:51:51 2010 From: moura.mario at gmail.com (macm) Date: Fri, 5 Nov 2010 11:51:51 -0700 (PDT) Subject: How convert list to nested dictionary? References: <940876cd-2546-4673-aef4-ba11b4156287@fv1g2000vbb.googlegroups.com> <878w18kbwl.fsf@gmail.com> <9c917109-92fe-4d1f-9310-b62ff64693f5@k11g2000vbf.googlegroups.com> Message-ID: <471f4f12-f7c4-437d-b435-989bbd8e64c1@o15g2000prh.googlegroups.com> Hi Peter Thanks a lot for your tips and codes, Cake Recipes are good to learn! So I post just basic issues. Hopping a good soul like you can help me! But I am still learning... : ) Best Regards macm On 5 nov, 15:40, Peter Otten <__pete... at web.de> wrote: > macm wrote: > > thanks a lot all. All solutions work fine. > > > while I am doing my home work. > > Reading "Learning Python" and much more. > > > Let me ask again to close my doubts: > > >>>> l = ['k1', 'k2', 'k3', 'k4', 'k5'] > >>>> d = reduce(lambda x,y: {y:x}, reversed(l), {'/':[1,2,3]}) > >>>> d > > {'k1': {'k2': {'k3': {'k4': {'k5': {'/': [1, 2, 3]}}}}}} > >>>> d['k1']['k2']['k3']['k4']['k5'] > > {'/': [1, 2, 3]} > >>>> d['k1']['k2']['k3']['k4']['k5']['/'] > > [1, 2, 3] > > > now I want generate the "index" to access the element. > > > ==> d['k1']['k2']['k3']['k4']['k5']['/'] from l > > > So again I have only. > >>>> l = ['k1', 'k2', 'k3', 'k4', 'k5'] > > > z = ?magicCode? > > > z = d['k1']['k2']['k3']['k4']['k5']['/'] > > You'll eventually have to start and write your first line of code. Why not > doing it right now? It is sure more rewarding than copying other people's > canned solutions and it can even be fun. > > Peter From philip at semanchuk.com Fri Nov 5 14:54:40 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Fri, 5 Nov 2010 14:54:40 -0400 Subject: Silly newbie question - Carrot character (^) In-Reply-To: <8jiqhpFmj3U2@mid.individual.net> References: <8jiqhpFmj3U2@mid.individual.net> Message-ID: On Nov 5, 2010, at 12:43 PM, Peter Pearson wrote: > On Fri, 5 Nov 2010 10:12:05 -0400, Philip Semanchuk wrote: >> >> BTW the more common name for this character is caret (ka-RAY). > > Yes, it's caret, but no, it's KA-rit, almost the same as > carrot. It's straight from Latin, with no detour through > French. This I did not know (obviously). Thanks. I knew all those years of studying French would ruin me somehow. From clp2 at rebertia.com Fri Nov 5 14:57:14 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 5 Nov 2010 11:57:14 -0700 Subject: Using %x to format number to hex and number of digits In-Reply-To: References: Message-ID: On Fri, Nov 5, 2010 at 11:23 AM, Matty Sarro wrote: > I'm currently trying to convert a digit from decimal to hex, however I need > the full 4 digit hex form. Python appears to be shortening the form. > Example: > > num = 10 > num = "%x"%(num) > print(num) > >>a > > num = 10 > num = "%#x"%(num) > print(num) > >>0xa > > I need it to output as 0x0a, and the exercise is requiring me to use %x to > format the string. Any help would be appreciated. Use str.zfill() and add the 0x manually: num = 10 hexdig = "%x" % num padded = hexdig.zfill(2) # pad with 0 if necessary oxd = "0x" + padded print(oxd) Cheers, Chris -- http://blog.rebertia.com From invalid at invalid.invalid Fri Nov 5 15:02:05 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 5 Nov 2010 19:02:05 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> Message-ID: On 2010-11-05, Seebs wrote: > On 2010-11-05, Emile van Sebille wrote: >> So, which of your tools are you married to that are causing your issues? > > Python. I think you should quit using Python and choose a language that works with whatever tools are causing all your white-space corruption problems. -- Grant Edwards grant.b.edwards Yow! My pants just went to at high school in the Carlsbad gmail.com Caverns!!! From invalid at invalid.invalid Fri Nov 5 15:05:42 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 5 Nov 2010 19:05:42 +0000 (UTC) Subject: Using %x to format number to hex and number of digits References: Message-ID: On Fri, Nov 5, 2010 at 11:23 AM, Matty Sarro wrote: > I'm currently trying to convert a digit from decimal to hex, however I need > the full 4 digit hex form. Python appears to be shortening the form. > Example: > > num = 10 > num = "%x"%(num) > print(num) > >>a > > num = 10 > num = "%#x"%(num) > print(num) > >>0xa > > I need it to output as 0x0a, and the exercise is requiring me to use %x to > format the string. Any help would be appreciated. http://docs.python.org/release/2.5.2/lib/typesseq-strings.html What you're asking for is called "zero padding", so if I were you, I'd search the above page for the phrase "zero pad". -- Grant Edwards grant.b.edwards Yow! BARBARA STANWYCK makes at me nervous!! gmail.com From rbroze at yahoo.com Fri Nov 5 15:14:08 2010 From: rbroze at yahoo.com (robert roze) Date: Fri, 5 Nov 2010 12:14:08 -0700 (PDT) Subject: decimal.py ver 2.6,2.7 not working with python 2.7 Message-ID: <954451.88002.qm@web114415.mail.gq1.yahoo.com> Hi Chris, Aha! yes, you figured it out. My PYTHONPATH env variable had an old experiment in it, which happened to be called numbers.py. Take it out, and decimal.py works fine. Thank you, Bob >What does the following output for you?: > >import numbers >print(numbers.__file__) >print(dir(numbers)) > >Cheers, >Chris >-- >http://blog.rebertia.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From msarro at gmail.com Fri Nov 5 15:26:42 2010 From: msarro at gmail.com (Matty Sarro) Date: Fri, 5 Nov 2010 15:26:42 -0400 Subject: Using %x to format number to hex and number of digits In-Reply-To: References: Message-ID: I actually was able to get it working a few minutes after posting the question. My apologies for not posting a followup :) I ended up using the following format: num = 10 num = "%#0.2x"%(num) print(num) It works, however I'm not sure if it'd be considered very "pythonic" or not. Thanks for your thoughts! On Fri, Nov 5, 2010 at 2:57 PM, Chris Rebert wrote: > On Fri, Nov 5, 2010 at 11:23 AM, Matty Sarro wrote: > > I'm currently trying to convert a digit from decimal to hex, however I > need > > the full 4 digit hex form. Python appears to be shortening the form. > > Example: > > > > num = 10 > > num = "%x"%(num) > > print(num) > > > >>a > > > > num = 10 > > num = "%#x"%(num) > > print(num) > > > >>0xa > > > > I need it to output as 0x0a, and the exercise is requiring me to use %x > to > > format the string. Any help would be appreciated. > > Use str.zfill() and add the 0x manually: > > num = 10 > hexdig = "%x" % num > padded = hexdig.zfill(2) # pad with 0 if necessary > oxd = "0x" + padded > print(oxd) > > Cheers, > Chris > -- > http://blog.rebertia.com > -------------- next part -------------- An HTML attachment was scrubbed... URL: From darcy at druid.net Fri Nov 5 15:33:37 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Fri, 5 Nov 2010 15:33:37 -0400 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> Message-ID: <20101105153337.4871389b.darcy@druid.net> On Fri, 5 Nov 2010 18:13:44 +0000 (UTC) Tim Harig wrote: > > care about. If no one was on a crusade to convince people that > > indentation as syntax (can we call is IAS from now on?) was evil then I > > wouldn't be posting anything at all on the subject. I am being totally > > reactionary here. > > Neither of you are really adding anything to the conversation other then to Well, whether I am adding anything is a judgement call. That I don't accept your premise doesn't mean that my postings are content free. > It is, however, verifiable that white space syntax causes issues with a > large number of common tools. I am a man of science. When choosing The simple fact is that the combination of your tools and Python is broken. The combination of my tools and Python is not. That's lucky for me since I really, really like IAS. That's unlucky for people who have to work with tools that mangle code. But don't crusade to change my language. Use Perl or C or even pybraces. > It is simply hard for me to accept that your solution is better when > it is telling us that we have to abandon thousands of tools that other > solutions manage to work with without difficulty. I am offering no solutions. Why would I since I don't see a problem? -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From ethan at stoneleaf.us Fri Nov 5 15:34:28 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 05 Nov 2010 12:34:28 -0700 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> <4cd3de51$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4CD45C44.7010600@stoneleaf.us> Tim Harig wrote: > The use of whitespace was a stylistic change and > stylistic holy wars exist because it is almost impossible to prove that > any reasonable style has benefit over another. That whitespace causes > issues is verifiable. I find it hard to concluded that that whitespace > based syntax is superior when it tells us that we cannot use thousands > of otherwise useful tools that other langauges manage to work with. > I find it hard to select a matter of taste with no verifiable benefit > over a verifiable disadvantage that happens to strike many people. The verifiable benefit for me is ease of use, ease of thought, ease of typing... I realize these are not benefits for everyone, but they are for some -- and I would venture a guess that the ease of thought benefit is one of the primary reasons Python is popular. I am definitely one of those that think indentation based structure is one of Python's best features. I do acknowledge that if you don't think that way, it can be major hassle, and I sympathize. ~Ethan~ From j.reid at mail.cryst.bbk.ac.uk Fri Nov 5 15:39:12 2010 From: j.reid at mail.cryst.bbk.ac.uk (John Reid) Date: Fri, 05 Nov 2010 19:39:12 +0000 Subject: *** glibc detected *** gdb: malloc(): smallbin double linked list Message-ID: Hi, I've compiled Python 2.7 (r27:82500, Nov 2 2010, 09:00:37) [GCC 4.4.3] on linux2 with the following configure options ./configure --prefix=/home/john/local/python-dbg --with-pydebug I've installed numpy and some other packages but when I try to run my extension code under gdb I get the errors below. Does anyone have any ideas of how to track down what's happening here? I imagine I've misconfigured something somewhere. Is valgrind the answer? Thanks, John. *** glibc detected *** gdb: malloc(): smallbin double linked list corrupted: 0x0000000004de7ad0 *** ======= Backtrace: ========= /lib/libc.so.6(+0x775b6)[0x7f0a252215b6] /lib/libc.so.6(+0x7b8e9)[0x7f0a252258e9] /lib/libc.so.6(__libc_malloc+0x6e)[0x7f0a2522658e] gdb(xmalloc+0x18)[0x45bc38] gdb[0x476df1] gdb[0x474c9b] gdb[0x474ee8] gdb(execute_command+0x2dd)[0x458d1d] gdb(catch_exception+0x50)[0x535510] gdb[0x4b5191] gdb(interp_exec+0x17)[0x535637] gdb(mi_cmd_interpreter_exec+0x6c)[0x4b9adc] gdb[0x4ba71a] gdb(catch_exception+0x50)[0x535510] gdb(mi_execute_command+0x97)[0x4ba137] gdb[0x53a0f8] gdb(gdb_do_one_event+0x29a)[0x53b38a] gdb(catch_errors+0x5b)[0x53531b] gdb(start_event_loop+0x1e)[0x53a90e] gdb[0x44f619] gdb(catch_errors+0x5b)[0x53531b] gdb[0x450166] gdb(catch_errors+0x5b)[0x53531b] gdb(gdb_main+0x24)[0x44f554] gdb(main+0x2e)[0x44f51e] /lib/libc.so.6(__libc_start_main+0xfd)[0x7f0a251c8c4d] gdb[0x44f429] ======= Memory map: ======== 00400000-00818000 r-xp 00000000 08:05 4832730 /usr/bin/gdb 00a17000-00a18000 r--p 00417000 08:05 4832730 /usr/bin/gdb 00a18000-00a25000 rw-p 00418000 08:05 4832730 /usr/bin/gdb 00a25000-00a43000 rw-p 00000000 00:00 0 0287f000-0b920000 rw-p 00000000 00:00 0 [heap] 7f0a1c000000-7f0a1c021000 rw-p 00000000 00:00 0 7f0a1c021000-7f0a20000000 ---p 00000000 00:00 0 7f0a20fc0000-7f0a20fd6000 r-xp 00000000 08:05 3498245 /lib/libgcc_s.so.1 7f0a20fd6000-7f0a211d5000 ---p 00016000 08:05 3498245 /lib/libgcc_s.so.1 7f0a211d5000-7f0a211d6000 r--p 00015000 08:05 3498245 /lib/libgcc_s.so.1 7f0a211d6000-7f0a211d7000 rw-p 00016000 08:05 3498245 /lib/libgcc_s.so.1 7f0a211fd000-7f0a21211000 r--p 000dc000 08:05 4825848 /usr/lib/libstdc++.so.6.0.13 7f0a21211000-7f0a21218000 r--p 00018000 08:05 4841756 /usr/lib/debug/lib/librt-2.11.1.so 7f0a21218000-7f0a21226000 r--p 00001000 08:05 4841756 /usr/lib/debug/lib/librt-2.11.1.so 7f0a21226000-7f0a2123e000 r--p 000bc000 08:05 4653290 /home/john/Dev/MyProjects/Bio/MotifSearch/python/stempy/_debug/libboost_python.so.1.44.0 7f0a2123e000-7f0a21287000 r--p 003dd000 08:05 4653290 /home/john/Dev/MyProjects/Bio/MotifSearch/python/stempy/_debug/libboost_python.so.1.44.0 7f0a21287000-7f0a21299000 r--p 00425000 08:05 4653290 /home/john/Dev/MyProjects/Bio/MotifSearch/python/stempy/_debug/libboost_python.so.1.44.0 7f0a21299000-7f0a213e7000 r--p 0018c000 08:05 4653290 /home/john/Dev/MyProjects/Bio/MotifSearch/python/stempy/_debug/libboost_python.so.1.44.0 7f0a213e7000-7f0a2152f000 r--p 0207c000 08:05 4653324 /home/john/Dev/MyProjects/Bio/MotifSearch/python/stempy/_debug/_stempy.so 7f0a2152f000-7f0a22027000 r--p 01585000 08:05 4653324 /home/john/Dev/MyProjects/Bio/MotifSearch/python/stempy/_debug/_stempy.so 7f0a22027000-7f0a22400000 rw-p 00000000 00:00 0 7f0a22408000-7f0a224d1000 r--p 00315000 08:05 4653290 /home/john/Dev/MyProjects/Bio/MotifSearch/python/stempy/_debug/libboost_python.so.1.44.0 7f0a224d1000-7f0a224ff000 r--p 002e8000 08:05 4653290 /home/john/Dev/MyProjects/Bio/MotifSearch/python/stempy/_debug/libboost_python.so.1.44.0 7f0a224ff000-7f0a22526000 r--p 00038000 08:05 4653310 /home/john/Dev/MyProjects/Bio/MotifSearch/python/stempy/_debug/myrrh_pylib-d 7f0a22526000-7f0a2259c000 r--p 01510000 08:05 4653324 /home/john/Dev/MyProjects/Bio/MotifSearch/python/stempy/_debug/_stempy.so 7f0a2259c000-7f0a2280c000 r--p 012a0000 08:05 4653324 /home/john/Dev/MyProjects/Bio/MotifSearch/python/stempy/_debug/_stempy.so 7f0a2280c000-7f0a2343f000 rw-p 00000000 00:00 0 7f0a23443000-7f0a2344c000 r--p 0001a000 08:05 6169643 /home/john/local/python-dbg/lib/python2.7/lib-dynload/datetime.so 7f0a2344c000-7f0a2345c000 r--p 002d9000 08:05 4653290 /home/john/Dev/MyProjects/Bio/MotifSearch/python/stempy/_debug/libboost_python.so.1.44.0 7f0a2345c000-7f0a23461000 r--p 0005e000 08:05 4653310 /home/john/Dev/MyProjects/Bio/MotifSearch/python/stempy/_debug/myrrh_pylib-d 7f0a23461000-7f0a23477000 r--p 0001f000 08:05 4653310 /home/john/Dev/MyProjects/Bio/MotifSearch/python/stempy/_debug/myrrh_pylib-d 7f0a23477000-7f0a2347d000 r--p 00004000 08:05 4653095 /home/john/Dev/MyProjects/Bio/MotifSearch/python/stempy/_debug/libboost_system.so.1.44.0 7f0a2347d000-7f0a2350c000 r--p 00757000 08:05 4653324 /home/john/Dev/MyProjects/Bio/MotifSearch/python/stempy/_debug/_stempy.so 7f0a2350c000-7f0a23555000 r--p 021c3000 08:05 4653324 /home/john/Dev/MyProjects/Bio/MotifSearch/python/stempy/_debug/_stempy.so 7f0a23555000-7f0a2355b000 r--p 00048000 08:05 6169627 /home/john/local/python-dbg/lib/python2.7/lib-dynload/_ctypes.so 7f0a2355b000-7f0a2356f000 r--p 0002d000 08:05 6169627 /home/john/local/python-dbg/lib/python2.7/lib-dynload/_ctypes.so 7f0a2356f000-7f0a23575000 r--p 000b1000 08:05 3489898 /home/john/local/python-dbg/lib/python2.7/site-packages/numpy-1.5.1rc1-py2.7-linux-x86_64.egg/numpy/random/mtrand.so 7f0a23575000-7f0a2357c000 r--p 000ab000 08:05 3489898 /home/john/local/python-dbg/lib/python2.7/site-packages/numpy-1.5.1rc1-py2.7-linux-x86_64.egg/numpy/random/mtrand.so 7f0a2357c000-7f0a2358d000 r--p 0009b000 08:05 3489898 /home/john/local/python-dbg/lib/python2.7/site-packages/numpy-1.5.1rc1-py2.7-linux-x86_64.egg/numpy/random/mtrand.so 7f0a2358d000-7f0a2359b000 r--p 000dd000 08:05 4827887 /usr/lib/libgfortran.so.3.0.0 7f0a2359b000-7f0a235ac000 r--p 00416000 08:05 6709644 /home/john/local/python-dbg/lib/python2.7/site-packages/numpy-1.5.1rc1-py2.7-linux-x86_64.egg/numpy/linalg/lapack_lite.so 7f0a235ac000-7f0a23668000 rw-p 00000000 00:00 0 7f0a23668000-7f0a2366d000 r--p 00033000 08:05 3180358 /home/john/local/python-dbg/lib/python2.7/site-packages/numpy-1.5.1rc1-py2.7-linux-x86_64.egg/numpy/core/scalarmath.so 7f0a2366d000-7f0a23678000 r--p 00052000 08:05 3180358 /home/john/local/python-dbg/lib/python2.7/site-packages/numpy-1.5.1rc1-py2.7-linux-x86_64.egg/numpy/core/scalarmath.so 7f0a23678000-7f0a2367d000 r--p 0004c000 08:05 3180358 /home/john/local/python-dbg/lib/python2.7/site-packages/numpy-1.5.1rc1-py2.7-linux-x86_64.egg/numpy/core/scalarmath.so 7f0a2367d000-7f0a23690000 r--p 00039000 08:05 3180358 /home/john/local/python-dbg/lib/python2.7/site-packages/numpy-1.5.1rc1-py2.7-linux-x86_64.egg/numpy/core/scalarmath.so 7f0a23690000-7f0a23698000 r--p 0001b000 08:05 6169649 /home/john/local/python-dbg/lib/python2.7/lib-dynload/cPickle.so 7f0a23698000-7f0a236a7000 r--p 004fd000 08:05 3180355 /home/john/local/python-dbg/lib/python2.7/site-packages/numpy-1.5.1rc1-py2.7-linux-x86_64.egg/numpy/core/_dotblas.so 7f0a236a7000-7f0a2374f000 rw-p 00000000 00:00 0 7f0a2374f000-7f0a2375a000 r--p 0001b000 08:05 3180353 /home/john/local/python-dbg/lib/python2.7/site-packages/numpy-1.5.1rc1-py2.7-linux-x86_64.egg/numpy/core/_sort.so 7f0a2375a000-7f0a23762000 r--p 00065000 08:05 3180320 /home/john/local/python-dbg/lib/python2.7/site-packages/numpy-1.5.1rc1-py2.7-linux-x86_64.egg/numpy/core/umath.so 7f0a23762000-7f0a23774000 r--p 000ae000 08:05 3180320 /home/john/local/python-dbg/lib/python2.7/site-packages/numpy-1.5.1rc1-py2.7-linux-x86_64.egg/numpy/core/umath.so 7f0a23774000-7f0a2377a000 r--p 000a9000 08:05 3180320 /home/john/local/python-dbg/lib/python2.7/site-packages/numpy-1.5.1rc1-py2.7-linux-x86_64.egg/numpy/core/umath.so 7f0a2377a000-7f0a23780000 r--p 000a4000 08:05 3180320 /home/john/local/python-dbg/lib/python2.7/site-packages/numpy-1.5.1rc1-py2.7-linux-x86_64.egg/numpy/core/umath.so 7f0a23780000-7f0a237b4000 r--p 00071000 08:05 3180320 /home/john/local/python-dbg/lib/python2.7/site-packages/numpy-1.5.1rc1-py2.7-linux-x86_64.egg/numpy/core/umath.so 7f0a237b4000-7f0a23881000 rw-p 00000000 00:00 0 7f0a23883000-7f0a23888000 r--p 0000f000 08:05 3146117 /home/john/local/python-dbg/lib/python2.7/site-packages/numpy-1.5.1rc1-py2.7-linux-x86_64.egg/numpy/fft/fftpack_lite.so 7f0a23888000-7f0a23897000 r--p 000b9000 08:05 3180362 /home/john/local/python-dbg/lib/python2.7/site-packages/numpy-1.5.1rc1-py2.7-linux-x86_64.egg/numpy/core/multiarray.so 7f0a23897000-7f0a238a1000 r--p 00118000 08:05 3180362 /home/john/local/python-dbg/lib/python2.7/site-packages/numpy-1.5.1rc1-py2.7-linux-x86_64.egg/numpy/core/multiarray.so 7f0a238a1000-7f0a238ae000 r--p 0010c000 08:05 3180362 /home/john/local/python-dbg/lib/python2.7/site-packages/numpy-1.5.1rc1-py2.7-linux-x86_64.egg/numpy/core/multiarray.so 7f0a238ae000-7f0a238e8000 r--p 000d3000 08:05 3180362 /home/john/local/python-dbg/lib/python2.7/site-packages/numpy-1.5.1rc1-py2.7-linux-x86_64.egg/numpy/core/multiarray.so 7f0a238e8000-7f0a23aa4000 r--p 004e2000 08:05 4841832 /usr/lib/debug/lib/libc-2.11.1.so 7f0a23aa4000-7f0a23b03000 r--p 0069d000 08:05 4841832 /usr/lib/debug/lib/libc-2.11.1.so 7f0a23b03000-7f0a23b27000 r--p 004bf000 08:05 4841832 /usr/lib/debug/lib/libc-2.11.1.so 7f0a23b27000-7f0a23bc3000 r--p 00424000 08:05 4841832 /usr/lib/debug/lib/libc-2.11.1.so 7f0a23bc3000-7f0a23c3e000 r--p 003aa000 08:05 4841832 /usr/lib/debug/lib/libc-2.11.1.so 7f0a23c3e000-7f0a23fca000 r--p 0001f000 08:05 4841832 /usr/lib/debug/lib/libc-2.11.1.so 7f0a23fca000-7f0a240f6000 rw-p 00000000 00:00 0 7f0a240f8000-7f0a24118000 r--p 00121000 08:05 3180362 /home/john/local/python-dbg/lib/python2.7/site-packages/numpy-1.5.1rc1-py2.7-linux-x86_64.egg/numpy/core/multiarray.so 7f0a24118000-7f0a24129000 r--p 0000e000 08:05 4950482 /usr/lib/debug/lib/libz.so.1.2.3.3 7f0a24129000-7f0a24133000 r--p 00000000 08:05 4950482 /usr/lib/debug/lib/libz.so.1.2.3.3 7f0a24133000-7f0a24154000 r--p 00155000 08:05 2900170 /lib/libc-2.11.1.so 7f0a24154000-7f0a241a2000 r--p 00061000 08:05 4841716 /usr/lib/debug/lib/libm-2.11.1.so 7f0a241a2000-7f0a241a8000 r--p 0005c000 08:05 4841716 /usr/lib/debug/lib/libm-2.11.1.so 7f0a241a8000-7f0a241bb000 r--p 0004a000 08:05 4841716 /usr/lib/debug/lib/libm-2.11.1.so 7f0a241bb000-7f0a241ed000 r--p 00007000 08:05 4841716 /usr/lib/debug/lib/libm-2.11.1.so 7f0a241ed000-7f0a241f4000 r-xp 00000000 08:05 2900165 /lib/libthread_db-1.0.so 7f0a241f4000-7f0a243f3000 ---p 00007000 08:05 2900165 /lib/libthread_db-1.0.so 7f0a243f3000-7f0a243f4000 r--p 00006000 08:05 2900165 /lib/libthread_db-1.0.so 7f0a243f4000-7f0a243f5000 rw-p 00007000 08:05 2900165 /lib/libthread_db-1.0.so 7f0a243f9000-7f0a2440c000 r--p 00038000 08:05 4841716 /usr/lib/debug/lib/libm-2.11.1.so 7f0a2440c000-7f0a2441b000 r--p 00000000 08:05 4841839 /usr/lib/debug/lib/libdl-2.11.1.so 7f0a2441b000-7f0a24431000 r--p 00078000 08:05 4841828 /usr/lib/debug/lib/libpthread-2.11.1.so 7f0a24431000-7f0a24439000 r--p 00071000 08:05 4841828 /usr/lib/debug/lib/libpthread-2.11.1.so 7f0a24439000-7f0a2444c000 r--p 0005f000 08:05 4841828 /usr/lib/debug/lib/libpthread-2.11.1.so 7f0a2444c000-7f0a2445c000 r--p 00050000 08:05 4841828 /usr/lib/debug/lib/libpthread-2.11.1.so 7f0a2445c000-7f0a244a9000 r--p 00004000 08:05 4841828 /usr/lib/debug/lib/libpthread-2.11.1.so 7f0a244a9000-7f0a244cc000 r--p 00063000 08:05 4841753 /usr/lib/debug/lib/ld-2.11.1.so 7f0a244cc000-7f0a244d6000 r--p 00085000 08:05 4841753 /usr/lib/debug/lib/ld-2.11.1.so 7f0a244d6000-7f0a244f3000 r--p 001be000 08:05 221210 /home/john/local/python-dbg/bin/python2.7 7f0a244f3000-7f0a24537000 r--p 00370000 08:05 221210 /home/john/local/python-dbg/bin/python2.7 7f0a24537000-7f0a2453e000 r--p 003b3000 08:05 221210 /home/john/local/python-dbg/bin/python2.7 7f0a2453e000-7f0a2455c000 r--p 00353000 08:05 221210 /home/john/local/python-dbg/bin/python2.7 7f0a2455c000-7f0a24583000 r--p 0032d000 08:05 221210 /home/john/local/python-dbg/bin/python2.7 7f0a24583000-7f0a24591000 r--p 00320000 08:05 221210 /home/john/local/python-dbg/bin/python2.7 7f0a24591000-7f0a2468b000 r--p 00227000 08:05 221210 /home/john/local/python-dbg/bin/python2.7 7f0a2468b000-7f0a247a8000 rw-p 00000000 00:00 0 7f0a247a8000-7f0a247aa000 r-xp 00000000 08:05 2900166 /lib/libutil-2.11.1.so 7f0a247aa000-7f0a249a9000 ---p 00002000 08:05 2900166 /lib/libutil-2.11.1.so 7f0a249a9000-7f0a249aa000 r--p 00001000 08:05 2900166 /lib/libutil-2.11.1.so 7f0a249aa000-7f0a249ab000 rw-p 00002000 08:05 2900166 /lib/libutil-2.11.1.so 7f0a249ab000-7f0a249c3000 r-xp 00000000 08:05 2900168 /lib/libpthread-2.11.1.so 7f0a249c3000-7f0a24bc2000 ---p 00018000 08:05 2900168 /lib/libpthread-2.11.1.so 7f0a24bc2000-7f0a24bc3000 r--p 00017000 08:05 2900168 /lib/libpthread-2.11.1.so 7f0a24bc3000-7f0a24bc4000 rw-p 00018000 08:05 2900168 /lib/libpthread-2.11.1.so 7f0a24bc4000-7f0a24bc8000 rw-p 00000000 00:00 0 7f0a24bc8000-7f0a24d30000 r-xp 00000000 08:05 2901949 /lib/libcrypto.so.0.9.8 7f0a24d30000-7f0a24f2f000 ---p 00168000 08:05 2901949 /lib/libcrypto.so.0.9.8 7f0a24f2f000-7f0a24f3c000 r--p 00167000 08:05 2901949 /lib/libcrypto.so.0.9.8 7f0a24f3c000-7f0a24f54000 rw-p 00174000 08:05 2901949 /lib/libcrypto.so.0.9.8 7f0a24f54000-7f0a24f58000 rw-p 00000000 00:00 0 7f0a24f58000-7f0a24fa3000 r-xp 00000000 08:05 2901950 /lib/libssl.so.0.9.8 7f0a24fa3000-7f0a251a2000 ---p 0004b000 08:05 2901950 /lib/libssl.so.0.9.8 7f0a251a2000-7f0a251a4000 r--p 0004a000 08:05 2901950 /lib/libssl.so.0.9.8 7f0a251a4000-7f0a251a9000 rw-p 0004c000 08:05 2901950 /lib/libssl.so.0.9.8 7f0a251a9000-7f0a251aa000 rw-p 00000000 00:00 0 7f0a251aa000-7f0a25324000 r-xp 00000000 08:05 2900170 /lib/libc-2.11.1.so 7f0a25324000-7f0a25523000 ---p 0017a000 08:05 2900170 /lib/libc-2.11.1.so 7f0a25523000-7f0a25527000 r--p 00179000 08:05 2900170 /lib/libc-2.11.1.so 7f0a25527000-7f0a25528000 rw-p 0017d000 08:05 2900170 /lib/libc-2.11.1.so 7f0a25528000-7f0a2552d000 rw-p 00000000 00:00 0 7f0a2552d000-7f0a2552f000 r-xp 00000000 08:05 2900174 /lib/libdl-2.11.1.so 7f0a2552f000-7f0a2572f000 ---p 00002000 08:05 2900174 /lib/libdl-2.11.1.so 7f0a2572f000-7f0a25730000 r--p 00002000 08:05 2900174 /lib/libdl-2.11.1.so 7f0a25730000-7f0a25731000 rw-p 00003000 08:05 2900174 /lib/libdl-2.11.1.so 7f0a25731000-7f0a25757000 r-xp 00000000 08:05 2900004 /lib/libexpat.so.1.5.2 7f0a25757000-7f0a25957000 ---p 00026000 08:05 2900004 /lib/libexpat.so.1.5.2 7f0a25957000-7f0a25959000 r--p 00026000 08:05 2900004 /lib/libexpat.so.1.5.2 7f0a25959000-7f0a2595a000 rw-p 00028000 08:05 2900004 /lib/libexpat.so.1.5.2 7f0a2595a000-7f0a25b98000 r-xp 00000000 08:05 4827971 /usr/lib/libpython2.6.so.1.0 7f0a25b98000-7f0a25d98000 ---p 0023e000 08:05 4827971 /usr/lib/libpython2.6.so.1.0 7f0a25d98000-7f0a25d9a000 r--p 0023e000 08:05 4827971 /usr/lib/libpython2.6.so.1.0 7f0a25d9a000-7f0a25dfc000 rw-p 00240000 08:05 4827971 /usr/lib/libpython2.6.so.1.0 7f0a25dfc000-7f0a25e0b000 rw-p 00000000 00:00 0 7f0a25e0b000-7f0a25e8d000 r-xp 00000000 08:05 2900011 /lib/libm-2.11.1.so 7f0a25e8d000-7f0a2608c000 ---p 00082000 08:05 2900011 /lib/libm-2.11.1.so 7f0a2608c000-7f0a2608d000 r--p 00081000 08:05 2900011 /lib/libm-2.11.1.so 7f0a2608d000-7f0a2608e000 rw-p 00082000 08:05 2900011 /lib/libm-2.11.1.so 7f0a2608e000-7f0a260a4000 r-xp 00000000 08:05 2900157 /lib/libz.so.1.2.3.3 7f0a260a4000-7f0a262a3000 ---p 00016000 08:05 2900157 /lib/libz.so.1.2.3.3 7f0a262a3000-7f0a262a4000 r--p 00015000 08:05 2900157 /lib/libz.so.1.2.3.3 7f0a262a4000-7f0a262a5000 rw-p 00016000 08:05 2900157 /lib/libz.so.1.2.3.3 7f0a262a5000-7f0a262e3000 r-xp 00000000 08:05 3498266 /lib/libncurses.so.5.7 7f0a262e3000-7f0a264e3000 ---p 0003e000 08:05 3498266 /lib/libncurses.so.5.7 7f0a264e3000-7f0a264e7000 r--p 0003e000 08:05 3498266 /lib/libncurses.so.5.7 7f0a264e7000-7f0a264e8000 rw-p 00042000 08:05 3498266 /lib/libncurses.so.5.7 7f0a264e8000-7f0a26521000 r-xp 00000000 08:05 3498308 /lib/libreadline.so.6.1 7f0a26521000-7f0a26720000 ---p 00039000 08:05 3498308 /lib/libreadline.so.6.1 7f0a26720000-7f0a26722000 r--p 00038000 08:05 3498308 /lib/libreadline.so.6.1 7f0a26722000-7f0a26728000 rw-p 0003a000 08:05 3498308 /lib/libreadline.so.6.1 7f0a26728000-7f0a26729000 rw-p 00000000 00:00 0 7f0a26729000-7f0a26749000 r-xp 00000000 08:05 2900131 /lib/ld-2.11.1.so 7f0a26749000-7f0a2674f000 r--p 00013000 08:05 6169622 /home/john/local/python-dbg/lib/python2.7/lib-dynload/itertools.so 7f0a2674f000-7f0a26758000 r--p 0004c000 08:05 4841753 /usr/lib/debug/lib/ld-2.11.1.so 7f0a26758000-7f0a267a4000 r--p 00001000 08:05 4841753 /usr/lib/debug/lib/ld-2.11.1.so 7f0a267a4000-7f0a26857000 rw-p 00000000 00:00 0 7f0a26857000-7f0a26858000 r--p 00000000 08:05 5792628 /usr/share/locale-langpack/en_GB/LC_MESSAGES/libc.mo 7f0a26858000-7f0a268da000 rw-p 00000000 00:00 0 7f0a268da000-7f0a26919000 r--p 00000000 08:05 4874536 /usr/lib/locale/en_GB.utf8/LC_CTYPE 7f0a26919000-7f0a26920000 rw-p 00000000 00:00 0 7f0a26922000-7f0a26928000 r--p 0005e000 08:05 4841753 /usr/lib/debug/lib/ld-2.11.1.so 7f0a26928000-7f0a26933000 r--p 00054000 08:05 4841753 /usr/lib/debug/lib/ld-2.11.1.so 7f0a26935000-7f0a26938000 rw-p 00000000 00:00 0 7f0a26938000-7f0a2693e000 r--p 00000000 08:05 5792627 /usr/share/locale-langpack/en_GB/LC_MESSAGES/gdb.mo 7f0a2693e000-7f0a26945000 r--s 00000000 08:05 5417899 /usr/lib/gconv/gconv-modules.cache 7f0a26945000-7f0a26946000 r--p 00000000 08:05 4875999 /usr/lib/locale/en_GB.utf8/LC_MESSAGES/SYS_LC_MESSAGES 7f0a26946000-7f0a26948000 rw-p 00000000 00:00 0 7f0a26948000-7f0a26949000 r--p 0001f000 08:05 2900131 /lib/ld-2.11.1.so 7f0a26949000-7f0a2694a000 rw-p 00020000 08:05 2900131 /lib/ld-2.11.1.so 7f0a2694a000-7f0a2694b000 rw-p 00000000 00:00 0 7ffff92d6000-7ffff92f8000 rw-p 00000000 00:00 0 [stack] 7ffff93ff000-7ffff9400000 r-xp 00000000 00:00 0 [vdso] ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall] From moura.mario at gmail.com Fri Nov 5 15:40:35 2010 From: moura.mario at gmail.com (macm) Date: Fri, 5 Nov 2010 12:40:35 -0700 (PDT) Subject: How convert list to nested dictionary? References: <940876cd-2546-4673-aef4-ba11b4156287@fv1g2000vbb.googlegroups.com> <878w18kbwl.fsf@gmail.com> <9c917109-92fe-4d1f-9310-b62ff64693f5@k11g2000vbf.googlegroups.com> <471f4f12-f7c4-437d-b435-989bbd8e64c1@o15g2000prh.googlegroups.com> Message-ID: Ok. Done >>> def appendNested(nest, path, val): ... nest2 = nest ... for key in path[:-1]: ... nest2 = nest2[key] ... nest2[path[-1]].append(val) ... return nest ... >>> >>> l = ['k1','k2','k3','k4','k5'] >>> ndict = reduce(lambda x,y: {y:x}, reversed(l), {'/':[1,2,3]}) >>> x = l + list('/') >>> print appendNested(ndict, x, 5) {'k1': {'k2': {'k3': {'k4': {'k5': {'/': [1, 2, 3, 5]}}}}}} >>> I need make lambda but now is friday night here and I guess I will go drink a beer or three! Cheers! macm On 5 nov, 16:51, macm wrote: > Hi Peter > > Thanks a lot for your tips and codes, > > Cake Recipes are good to learn! So I post just basic issues. > > Hopping a good soul like you can help me! > > But I am still learning... : ) > > Best Regards > > macm > > On 5 nov, 15:40, Peter Otten <__pete... at web.de> wrote: > > > macm wrote: > > > thanks a lot all. All solutions work fine. > > > > while I am doing my home work. > > > Reading "Learning Python" and much more. > > > > Let me ask again to close my doubts: > > > >>>> l = ['k1', 'k2', 'k3', 'k4', 'k5'] > > >>>> d = reduce(lambda x,y: {y:x}, reversed(l), {'/':[1,2,3]}) > > >>>> d > > > {'k1': {'k2': {'k3': {'k4': {'k5': {'/': [1, 2, 3]}}}}}} > > >>>> d['k1']['k2']['k3']['k4']['k5'] > > > {'/': [1, 2, 3]} > > >>>> d['k1']['k2']['k3']['k4']['k5']['/'] > > > [1, 2, 3] > > > > now I want generate the "index" to access the element. > > > > ==> d['k1']['k2']['k3']['k4']['k5']['/'] from l > > > > So again I have only. > > >>>> l = ['k1', 'k2', 'k3', 'k4', 'k5'] > > > > z = ?magicCode? > > > > z = d['k1']['k2']['k3']['k4']['k5']['/'] > > > You'll eventually have to start and write your first line of code. Why not > > doing it right now? It is sure more rewarding than copying other people's > > canned solutions and it can even be fun. > > > Peter > > From msarro at gmail.com Fri Nov 5 15:44:58 2010 From: msarro at gmail.com (Matty Sarro) Date: Fri, 5 Nov 2010 15:44:58 -0400 Subject: Silly newbie question - Carrot character (^) In-Reply-To: References: <8jiqhpFmj3U2@mid.individual.net> Message-ID: It's ok, people who refer to a labret piercing as a "la-BRAY" piercing are also incorrect. It's pronounced lab-RET, as its base word is the latin "labretta." French as a language shall doom us all :) On Fri, Nov 5, 2010 at 2:54 PM, Philip Semanchuk wrote: > > On Nov 5, 2010, at 12:43 PM, Peter Pearson wrote: > > > On Fri, 5 Nov 2010 10:12:05 -0400, Philip Semanchuk wrote: > >> > >> BTW the more common name for this character is caret (ka-RAY). > > > > Yes, it's caret, but no, it's KA-rit, almost the same as > > carrot. It's straight from Latin, with no detour through > > French. > > This I did not know (obviously). Thanks. I knew all those years of studying > French would ruin me somehow. > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Fri Nov 5 15:52:44 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 05 Nov 2010 14:52:44 -0500 Subject: Using %x to format number to hex and number of digits Message-ID: <4CD4608C.3040803@tim.thechases.com> On 11/05/10 13:23, Matty Sarro wrote: >> I'm currently trying to convert a digit from decimal to hex, >> however I need the full 4 digit hex form. Python appears to >> be shortening the form. >> Example: >> >> num = 10 >> num = "%x"%(num) >> print(num) >> >>>> a >> >> num = 10 >> num = "%#x"%(num) >> print(num) >> >>>> 0xa >> >> I need it to output as 0x0a, and the exercise is requiring >> me to use %x to format the string. Any help would be >> appreciated. Though it feels hokey to me, using "%#04x" % 10 works for me. The "#" adds the "0x" prefix (the "alternate form"), the "0" pads with zeros, and the "4" is really "2 places + 2 characters for the prefix". So if you want 4 hex characters + the 2 prefix characters, you'd use "%#06x". IMHO, this would make more sense if it didn't take the 2-character prefix into consideration (being written as "%#02x" for a byte or "%#04x" for a short), but it's not really a burr in my saddle. -tkc From ian.g.kelly at gmail.com Fri Nov 5 15:56:52 2010 From: ian.g.kelly at gmail.com (Ian) Date: Fri, 5 Nov 2010 12:56:52 -0700 (PDT) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <87r5f13ug3.fsf.mdw@metalzone.distorted.org.uk> <4cd3df64$0$30004$c3e8da3$5496439d@news.astraweb.com> <4cd44e7a$0$1610$742ec2ed@news.sonic.net> Message-ID: On Nov 5, 12:35?pm, John Nagle wrote: > ? ? INTERLISP's editor allowed the user to select a block of > LISP code and make it into a function. ?The selected block > would be analyzed to determine which local variables it referenced, > and a new function would be created with those parameters. ?The > block of code at the original point would then be replaced by > a call to the function. > > ? ? Today's editors are too dumb to do that right. ?They're text > editors with the illusion of knowing something about the language, > not language editors which also format text. Eclipse does that. Visual Studio does that. As for Python, I hear that Eric IDE has a plugin to do that, although I haven't tested it myself. Cheers, Ian From arnodel at gmail.com Fri Nov 5 15:59:17 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Fri, 05 Nov 2010 19:59:17 +0000 Subject: How convert list to nested dictionary? References: <940876cd-2546-4673-aef4-ba11b4156287@fv1g2000vbb.googlegroups.com> <878w18kbwl.fsf@gmail.com> Message-ID: <874obvk0dm.fsf@gmail.com> Peter Otten <__peter__ at web.de> writes: > Boris Borcic wrote: > >> Arnaud Delobelle wrote: >>> macm writes: >>> >>>> Hi Folks >>>> >>>> How convert list to nested dictionary? >>>> >>>>>>> l >>>> ['k1', 'k2', 'k3', 'k4', 'k5'] >>>>>>> result >>>> {'k1': {'k2': {'k3': {'k4': {'k5': {}}}}}} >>>> >>>> Regards >>>> >>>> macm >>> >>> reduce(lambda x,y: {y:x}, reversed(l), {}) >>> >> >> d={} >> while L : d={L.pop():d} > > Iterating over the keys in normal order: > >>>> keys = "abcde" >>>> d = outer = {} >>>> for key in keys: > ... outer[key] = inner = {} > ... outer = inner > ... >>>> d > {'a': {'b': {'c': {'d': {'e': {}}}}}} > > The "functional" variant: > >>>> d = {} >>>> reduce(lambda outer, key: outer.setdefault(key, {}), "abcde", d) > {} >>>> d > {'a': {'b': {'c': {'d': {'e': {}}}}}} > > In a single expression if you are willing to pay the price: > >>>> reduce(lambda (accu, outer), key: (accu, outer.setdefault(key, {})), > "abcde", ({},)*2)[0] > {'a': {'b': {'c': {'d': {'e': {}}}}}} > > Peter The most basic functional version: >>> f = lambda l: {l[0]: f(l[1:])} if l else {} >>> f('abcde') {'a': {'b': {'c': {'d': {'e': {}}}}}} -- Arnaud From tjreedy at udel.edu Fri Nov 5 16:05:54 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 05 Nov 2010 16:05:54 -0400 Subject: Final state of underlying sequence in islice In-Reply-To: <4b599f9b-5d99-4a9a-85a8-4ccba233bdc4@35g2000prb.googlegroups.com> References: <4b599f9b-5d99-4a9a-85a8-4ccba233bdc4@35g2000prb.googlegroups.com> Message-ID: On 11/5/2010 4:58 AM, Raymond Hettinger wrote: >> Shashank Singh wrote: >> >>> Are there any promises made with regard to final state of the underlying >>> sequence that islice slices? > > Currently, there are no promises or guarantees about the final state > of the iterator. I interpret the current doc statement as a promise that becomes ambiguous when step > 1. > To the extent the pure Python version in the docs differs from the > CPython implementation in this regard, it is an accidental > implementation detail. > > That being said, we could introduce some guarantees (earliest possible > stop point, latest possible stop point, or decide to leave it > undefined). In between earliest and latest, depending on the stop value, is another possibility. If it is relatively easy to patch the C version to match the Python version (earliest stop point) I would go for that. It is easy to skip over and ignore more items, impossible to go back. -- Terry Jan Reedy From usenet-nospam at seebs.net Fri Nov 5 16:09:37 2010 From: usenet-nospam at seebs.net (Seebs) Date: 05 Nov 2010 20:09:37 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> Message-ID: On 2010-11-05, Grant Edwards wrote: > On 2010-11-05, Seebs wrote: >> On 2010-11-05, Emile van Sebille wrote: >>> So, which of your tools are you married to that are causing your issues? >> Python. > I think you should quit using Python and choose a language that works > with whatever tools are causing all your white-space corruption > problems. Ahh, but that's the thing. I'm married to it -- there's existing projects I want to work on which are in Python. Anyway, it was a sort of frivolous answer, but it's ha-ha-only-serious; after all, there were no serious issues with any of these tools before. There's a saying a friend of mine has; "a lack of communication is never exclusively one party's fault." This applies, in many cases, to things like "issues" that occur when two programs clash in some aspect of their designs. In some cases, there might be a real and unambiguous standard to be violated. In others, though, you can have a problem which arises from a clash in expectations between two programs, either of which is fine on its own. There is a clash between Python and the whole category of things which sometimes lose whitespace. Because that category is reasonably large, and known to be large, and unlikely to vanish, many language designers choose to build their languages to be robust in the face of minor changes in whitespace. Python chose not to, and that is a source of conflicts. Were someone to invent a *new* text editor, which mangled whitespace, I would accuse it of being gratuitously incompatible with Python; I tend to regard compatibility, once you get past the standards, as a matter of temporal precedence. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From invalid at invalid.invalid Fri Nov 5 16:10:29 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 5 Nov 2010 20:10:29 +0000 (UTC) Subject: Using %x to format number to hex and number of digits References: Message-ID: On 2010-11-05, Tim Chase wrote: > On 11/05/10 13:23, Matty Sarro wrote: >>> I'm currently trying to convert a digit from decimal to hex, >>> however I need the full 4 digit hex form. Python appears to >>> be shortening the form. >>> Example: >>> >>> num = 10 >>> num = "%x"%(num) >>> print(num) >>> >>>>> a >>> >>> num = 10 >>> num = "%#x"%(num) >>> print(num) >>> >>>>> 0xa >>> >>> I need it to output as 0x0a, and the exercise is requiring >>> me to use %x to format the string. Any help would be >>> appreciated. > > Though it feels hokey to me, using > > "%#04x" % 10 > > works for me. I think "0x%02x" % 10 is a bit more readable, but it accomplishes the same thing -- you just don't have to do the mental math to add the prefix width to the number of desired hex digits in the output. -- Grant Edwards grant.b.edwards Yow! Quick, sing me the at BUDAPEST NATIONAL ANTHEM!! gmail.com From usenet-nospam at seebs.net Fri Nov 5 16:10:43 2010 From: usenet-nospam at seebs.net (Seebs) Date: 05 Nov 2010 20:10:43 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> <4cd3de51$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-05, Ethan Furman wrote: > The verifiable benefit for me is ease of use, ease of thought, ease of > typing... I realize these are not benefits for everyone, but they are > for some -- and I would venture a guess that the ease of thought benefit > is one of the primary reasons Python is popular. I am definitely one of > those that think indentation based structure is one of Python's best > features. Could you explain more the "ease of thought" thing? I haven't yet noticed it, but it might be something to look out for as I get more experienced. It certainly sounds like something that would be a benefit. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Fri Nov 5 16:14:47 2010 From: usenet-nospam at seebs.net (Seebs) Date: 05 Nov 2010 20:14:47 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> Message-ID: On 2010-11-05, D'Arcy J.M. Cain wrote: > The simple fact is that the combination of your tools and Python is > broken. The combination of my tools and Python is not. That's lucky > for me since I really, really like IAS. That's unlucky for people who > have to work with tools that mangle code. But don't crusade to change > my language. Use Perl or C or even pybraces. No one is crusading to change Python, or even suggesting that it should be changed. > I am offering no solutions. Why would I since I don't see a problem? One of the things many people try to do is develop the ability to "see" problems that affect other people but possibly not themselves. This allows people to offer solutions to those problems, which is often viewed as a kind of contribution to a community. Certainly, it's more useful than posting nothing more than "that's not a problem for me." I can just see how well this attitude must work in other circumstances: Some Guy: Oh, *!@#. I think I just sprained my ankle. Darcy: I didn't. Some Guy: I don't think I can walk up these stairs. Darcy: I don't have a problem with stairs. Stop trying to change this path. It works fine. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From tjreedy at udel.edu Fri Nov 5 16:18:29 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 05 Nov 2010 16:18:29 -0400 Subject: Silly newbie question - Carrot character (^) In-Reply-To: References: Message-ID: On 11/5/2010 9:43 AM, Matty Sarro wrote: > Hey Everyone, > Just curious - I'm working on a program which includes a calculation of > a circle, and I found myself trying to use pi*radius^2, and getting > errors that data types float and int are unsupported for "^". Now, I > realized I was making the mistake of using '^' instead of "**". I've > corrected this and its now working. However, what exactly does ^ do? I > know its used in regular expressions but I can't seem to find anything > about using it as an operator. Sadly my google foo is failing since the > character gets filtered out. All such symbol questions are aswered (or should be) in PySymbols.html: https://code.google.com/p/xploro/downloads/detail?name=PySymbols.html -- Terry Jan Reedy From python at rcn.com Fri Nov 5 16:51:32 2010 From: python at rcn.com (Raymond Hettinger) Date: Fri, 5 Nov 2010 13:51:32 -0700 (PDT) Subject: Final state of underlying sequence in islice References: <4b599f9b-5d99-4a9a-85a8-4ccba233bdc4@35g2000prb.googlegroups.com> Message-ID: On Nov 5, 1:05?pm, Terry Reedy wrote: > > Currently, there are no promises or guarantees about the final state > > of the iterator. > > I interpret the current doc statement as a promise that becomes > ambiguous when step > 1. You may have missed my point. I wrote the tools, the docs, and the tests. If you interpret a "promise" in text, I can assure you it was not intended. The behavior *is* undefined because I never defined it. I'm happy to clarify the docs to make that explicit. Or I can alter the implementation a bit to make a guarantee if it looks like there is a good reason to do so. The OP doesn't have any use cases to light the way and I don't yet see any useful invariants that would arise out of either definition. And since the ambiguity only shows-up in a somewhat rare case, I'm inclined to just mark it as undefined. Raymond From tjreedy at udel.edu Fri Nov 5 16:51:33 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 05 Nov 2010 16:51:33 -0400 Subject: Compare source code In-Reply-To: <20101105153337.4871389b.darcy@druid.net> References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> <20101105153337.4871389b.darcy@druid.net> Message-ID: On 11/5/2010 3:33 PM, D'Arcy J.M. Cain wrote: > my language. Use Perl or C or even pybraces. http://timhatch.com/projects/pybraces/ "I work with a guy who hates Python's significant whitespace and wishes that he could just use curly braces." > I am offering no solutions. Except you just did ;-). And using a braces encoding makes it looks easier than I expected. -- Terry Jan Reedy From tjreedy at udel.edu Fri Nov 5 16:57:44 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 05 Nov 2010 16:57:44 -0400 Subject: decimal.py ver 2.6,2.7 not working with python 2.7 In-Reply-To: <954451.88002.qm@web114415.mail.gq1.yahoo.com> References: <954451.88002.qm@web114415.mail.gq1.yahoo.com> Message-ID: On 11/5/2010 3:14 PM, robert roze wrote: > Aha! yes, you figured it out. My PYTHONPATH env variable had an > old experiment in it, which happened to be called > numbers.py. Take it out, and decimal.py works fine. Python has a large test suite in Lib/test, which includes test_decimal.py. It is run daily on several machines, and must pass before any release. So a gross failure like an import failure is very likely due to a local cause. >>What does the following output for you?: >> >>import numbers >>print(numbers.__file__) >>print(dir(numbers)) These are good test steps for any gross module failure. -- Terry Jan Reedy From nobody at nowhere.com Fri Nov 5 17:21:19 2010 From: nobody at nowhere.com (Nobody) Date: Fri, 05 Nov 2010 21:21:19 +0000 Subject: Silly newbie question - Carrot character (^) References: Message-ID: On Fri, 05 Nov 2010 10:12:05 -0400, Philip Semanchuk wrote: > As others have said, ^ is for XOR. That's buried here in the > documentation: > http://docs.python.org/release/2.7/reference/... > > Not that I would have expected you to find it there since that's pretty > dense. In fact, older versions of the Python doc used to describe this > section as "for language lawyers" but I see they've changed that now. However, it's still written for language lawyers. IMHO, the lack of a reference manual for the language itself is a major hole in Python's documentation. From nobody at nowhere.com Fri Nov 5 17:30:17 2010 From: nobody at nowhere.com (Nobody) Date: Fri, 05 Nov 2010 21:30:17 +0000 Subject: *** glibc detected *** gdb: malloc(): smallbin double linked list References: Message-ID: On Fri, 05 Nov 2010 19:39:12 +0000, John Reid wrote: > I've compiled > Python 2.7 (r27:82500, Nov 2 2010, 09:00:37) [GCC 4.4.3] on linux2 > > with the following configure options > ./configure --prefix=/home/john/local/python-dbg --with-pydebug > > I've installed numpy and some other packages but when I try to run my > extension code under gdb I get the errors below. Does anyone have any > ideas of how to track down what's happening here? I imagine I've > misconfigured something somewhere. Is valgrind the answer? I imagine that your extension code is trashing the heap, in which case, valgrind is probably the answer. My first guess would be that something is writing to a heap block after it has been deallocated (possibly due to omitting a Py_INCREF). Of course, other causes are possible, but writing to deallocated memory is a common problem when writing extensions for languages with garbage collection. From philip at semanchuk.com Fri Nov 5 17:47:32 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Fri, 5 Nov 2010 17:47:32 -0400 Subject: Silly newbie question - Carrot character (^) In-Reply-To: References: Message-ID: <12EC562D-9970-42B3-A05B-7C37DBFDA0E7@semanchuk.com> On Nov 5, 2010, at 5:21 PM, Nobody wrote: > On Fri, 05 Nov 2010 10:12:05 -0400, Philip Semanchuk wrote: > >> As others have said, ^ is for XOR. That's buried here in the >> documentation: >> http://docs.python.org/release/2.7/reference/... >> >> Not that I would have expected you to find it there since that's pretty >> dense. In fact, older versions of the Python doc used to describe this >> section as "for language lawyers" but I see they've changed that now. > > However, it's still written for language lawyers. > > IMHO, the lack of a reference manual for the language itself is a major > hole in Python's documentation. I agree. From ldo at geek-central.gen.new_zealand Fri Nov 5 18:14:38 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 06 Nov 2010 11:14:38 +1300 Subject: ANN: PyQt v4.8.1 Released References: Message-ID: In message , ?????? ??????????? wrote: >>> PyQt is available under the GPL and a commercial license. >> >> Surely you mean ?proprietary? rather than ?commercial?. There is >> nothing about the GPL that prevents ?commercial? use. > > I think he means a license that *he* sells comercially :) Presumably that?s a proprietary licence. From usenet-nospam at seebs.net Fri Nov 5 18:51:10 2010 From: usenet-nospam at seebs.net (Seebs) Date: 05 Nov 2010 22:51:10 GMT Subject: Silly newbie question - Carrot character (^) References: Message-ID: On 2010-11-05, Nobody wrote: > However, it's still written for language lawyers. > IMHO, the lack of a reference manual for the language itself is a major > hole in Python's documentation. I'm a bit lost here. Could you highlight some of the differences between "a reference manual for the language itself" and "something written for language lawyers"? -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From ian.g.kelly at gmail.com Fri Nov 5 18:52:18 2010 From: ian.g.kelly at gmail.com (Ian) Date: Fri, 5 Nov 2010 15:52:18 -0700 (PDT) Subject: Final state of underlying sequence in islice References: <4b599f9b-5d99-4a9a-85a8-4ccba233bdc4@35g2000prb.googlegroups.com> Message-ID: On Nov 5, 2:51?pm, Raymond Hettinger wrote: > You may have missed my point. ?I wrote the tools, the docs, and the > tests. > If you interpret a "promise" in text, I can assure you it was not > intended. ?The behavior *is* undefined because I never defined it. > I'm happy to clarify the docs to make that explicit. Does the existence of a test case imply a guarantee? # Test number of items consumed SF #1171417 it = iter(range(10)) self.assertEqual(list(islice(it, 3)), range(3)) self.assertEqual(list(it), range(3, 10)) From stefan_ml at behnel.de Fri Nov 5 19:21:14 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 06 Nov 2010 00:21:14 +0100 Subject: [ANN] Lupa 0.17 released - Lua in Python Message-ID: Hi all, I am happy to announce the release of Lupa 0.17, Lua in Python. http://pypi.python.org/pypi/lupa/0.17 Have fun, Stefan What is Lupa? -------------- Lupa integrates the LuaJIT2 runtime [1] into CPython. It is a rewrite of LunaticPython in Cython with several advanced features. This release features iteration support for Python objects in Lua. Changes in this release: 0.17 (2010-11-05) * new helper function "python.enumerate()" in Lua that returns a Lua iterator for a Python object and adds the 0-based index to each item. * new helper function "python.iterex()" in Lua that returns a Lua iterator for a Python object and unpacks any tuples that the iterator yields into separate Lua arguments. * new helper function "python.iter()" in Lua that returns a Lua iterator for a Python object. * resurrected the "python.as_function()" helper function for Lua code as it can be needed in cases where Lua cannot determine how to run a Python function. [1] LuaJIT2: http://luajit.org/ Features --------- * separate Lua runtime states through a LuaRuntime class * frees the GIL and supports threading in separate runtimes when calling into Lua * Python compatible coroutine wrapper for Lua coroutines * iteration support for Python objects in Lua and Lua objects in Python * proper encoding and decoding of strings (configurable per runtime, UTF-8 by default) * supports Python 2.x and 3.x, potentially starting with Python 2.3 (currently untested) * written for LuaJIT2, as opposed to the Lua interpreter (tested with LuaJIT 2.0.0-beta5) * easy to hack on and extend as it is written in Cython, not C Why use it? ------------ It complements Python very well. Lua is a language as dynamic as Python, but LuaJIT compiles it to very fast machine code, sometimes faster than many other compiled languages for computational code. The language runtime is extremely small and carefully designed for embedding. The complete binary module of Lupa, including a statically linked LuaJIT2 runtime, is only some 500KB on a 64 bit machine. However, the Lua ecosystem lacks many of the batteries that Python readily includes, either directly in its standard library or as third party packages. This makes real-world Lua applications harder to write than equivalent Python applications. Lua is therefore not commonly used as primary language for large applications, but it makes for a fast, high-level and resource-friendly backup language inside of Python when raw speed is required and the edit-compile-run cycle of binary extension modules is too heavy and too static for agile development or hot-deployment. Lupa is a very fast and thin wrapper around LuaJIT. It makes it easy to write dynamic Lua code that accompanies dynamic Python code by switching between the two languages at runtime, based on the tradeoff between simplicity and speed. Examples --------- >>> from lupa import LuaRuntime >>> lua = LuaRuntime() >>> lua.eval('1+1') 2 >>> lua_func = lua.eval('function(f, n) return f(n) end') >>> def py_add1(n): return n+1 >>> lua_func(py_add1, 2) 3 >>> lua_code = '''\ ... function(N) ... for i=0,N do ... coroutine.yield( i%2 ) ... end ... end ... ''' >>> f = lua.eval(lua_code) >>> gen = f.coroutine(4) >>> list(enumerate(gen)) [(0, 0), (1, 1), (2, 0), (3, 1), (4, 0)] >>> lua_code = '''\ ... function(L) ... for item in python.iter(L) do ... if item == 3 then return 1 end ... end ... return 0 ... end ... ''' >>> f = lua.eval(lua_code) >>> f([1,2,3]) 1 >>> f([1,2]) 0 From darcy at druid.net Fri Nov 5 19:26:48 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Fri, 5 Nov 2010 19:26:48 -0400 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> Message-ID: <20101105192648.45be9606.darcy@druid.net> On 05 Nov 2010 20:14:47 GMT Seebs wrote: > I can just see how well this attitude must work in other circumstances: I guess this message ends the topic for me. Bye. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From python at rcn.com Fri Nov 5 20:32:01 2010 From: python at rcn.com (Raymond Hettinger) Date: Fri, 5 Nov 2010 17:32:01 -0700 (PDT) Subject: Final state of underlying sequence in islice References: <4b599f9b-5d99-4a9a-85a8-4ccba233bdc4@35g2000prb.googlegroups.com> Message-ID: <777bd489-ef2a-4898-8d69-27ebff7832ea@x7g2000prj.googlegroups.com> On Nov 5, 3:52?pm, Ian wrote: > On Nov 5, 2:51?pm, Raymond Hettinger wrote: > > > You may have missed my point. ?I wrote the tools, the docs, and the > > tests. > > If you interpret a "promise" in text, I can assure you it was not > > intended. ?The behavior *is* undefined because I never defined it. > > I'm happy to clarify the docs to make that explicit. > > Does the existence of a test case imply a guarantee? > > ? ? ? ? # Test number of items consumed ? ? SF #1171417 > ? ? ? ? it = iter(range(10)) > ? ? ? ? self.assertEqual(list(islice(it, 3)), range(3)) > ? ? ? ? self.assertEqual(list(it), range(3, 10)) That tests a "natural boundary". In contrast, the OP's issue concerns an odd case where step > 1 and stop != start + n * step and len(list(it)) > start + n * step There's no test for that case and it is not clear what the desired behavior should be. And AFAICT there are no use cases or meaningful invariants to guide the way, so I'm reluctant to lock-in the choice (much like Tim and Guido waited a long time before they guaranteed the stability of list.sort()). If the RightAnswer(tm) is obvious to you, I would like to hear it. If I had to make a choice right now, I would choose stopping at the earlier possible point rather than scanning to the next natural boundary. Raymond From python.list at tim.thechases.com Fri Nov 5 21:22:53 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 05 Nov 2010 20:22:53 -0500 Subject: Using %x to format number to hex and number of digits In-Reply-To: References: Message-ID: <4CD4ADED.1030709@tim.thechases.com> On 11/05/10 15:10, Grant Edwards wrote: > On 2010-11-05, Tim Chase wrote: >> On 11/05/10 13:23, Matty Sarro wrote: >>>> I need it to output as 0x0a, and the exercise is requiring >>>> me to use %x to format the string. Any help would be >>>> appreciated. >> >> Though it feels hokey to me, using >> >> "%#04x" % 10 >> >> works for me. > > I think "0x%02x" % 10 is a bit more readable, but it accomplishes the > same thing -- you just don't have to do the mental math to add the > prefix width to the number of desired hex digits in the output. Which, I confess, is what I usually use because I didn't know about the "#" until this thread, and just made the assumption that one can get the zero-padding along with the "alternate form" in my experimentation this afternoon. So while it _can_ be done with just variants of the "%x" place-holder (as suggested by the OP's exercise), at least two of us on the list prefer to explicitly add the "0x" to the beginning. -tkc From paul.hemans at gmail.com Fri Nov 5 21:25:52 2010 From: paul.hemans at gmail.com (Paul Hemans) Date: Sat, 6 Nov 2010 12:25:52 +1100 Subject: Regular expression Message-ID: I need to extract the quoted text from : _("get this") The following works: re.compile( "_\(['\"]([^'\"]+)['\"]\)" ) However, I don't want to match if there is A-Z or a-z or 0-9 or _ immediately preceding the "_" so I have tried: "[^0-9a-zA-Z]*_\(['\"]([^'\"]+)['\"]\)" "[^\w]{0,1}_\(['\"]([^'\"]+)['\"]\)" "\W*_\(['\"]([^'\"]+)['\"]\)" to match against: skip this text _("get this") Thanks From steve at REMOVE-THIS-cybersource.com.au Fri Nov 5 21:36:36 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Nov 2010 01:36:36 GMT Subject: Why "flat is better than nested"? References: <4cc8d49c$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4cd4b124$0$30004$c3e8da3$5496439d@news.astraweb.com> On Fri, 05 Nov 2010 14:19:47 +0100, J. Gerlach wrote: > Am 28.10.2010 03:40, schrieb Steven D'Aprano: >> [ snip a lot of wise words ] > > Can I put this (translated) in the german python wiki? I guess it might > help more people to understand some decisions taken during python's > development - and I'm to lazy to do something similar myself ;) Sure, go ahead. I would appreciate a link back to my post, and/or credit, but that's not essential. (I understand it's a wiki and there's no guarantee that the link will remain there forever.) -- Steven From pavlovevidence at gmail.com Fri Nov 5 21:58:04 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 5 Nov 2010 18:58:04 -0700 (PDT) Subject: Lupa 0.17 released - Lua in Python References: Message-ID: <39c33bbe-e734-4aea-966a-ecb4e6105980@f20g2000yqi.googlegroups.com> On Nov 5, 4:21?pm, Stefan Behnel wrote: > Hi all, > > I am happy to announce the release of Lupa 0.17, Lua in Python. > > http://pypi.python.org/pypi/lupa/0.17 > > Have fun, > > Stefan Thanks, interesting projection. Good idea. Carl Banks From steve at REMOVE-THIS-cybersource.com.au Fri Nov 5 21:59:41 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Nov 2010 01:59:41 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> Message-ID: <4cd4b68c$0$30004$c3e8da3$5496439d@news.astraweb.com> On Thu, 04 Nov 2010 19:37:25 +0000, Tim Harig wrote: > Examples of communication channels that mangle white space abound. Yes. So what? If your communication channel mangles your data, change your communication channel, don't expect users of clean communication channels to hand-enter error-correcting codes (braces) into the data. > I > don't know of any that mangle either braces or pascal style start/end > blocks. > > You are the one who seems to be on a crusade against against braces. It > would seem to me, that if you want people to accept that white space > formatting is superior, that you would be looking for a simple way to > solve the white space mangling problem. Why is it the responsibility of the programming language syntax to correct the problem with Seebs' faulty mail server? I've experienced the spilled-coke-on-the-keyboard problem more often than mangled whitespace, but you don't see me arguing that what every language needs is error-correcting codes that let me work with keyboards that have had Coke spilled on them. [...] > Transfering binary programs has always been an issue and using text > based communications (preferably human readable) has always been > considered a good design decision. I put up with Python's white space > idiosyncrasies; I wouldn't even bother looking at a language that > requires me to enter the source in binary. I also consider the move > toward XML based document formats a move in the right direction. Okay, now you have zero credibility. XML is not a data format for human use, it is for use by machines. It is slow, inefficient, and uneditable by humans except for the most trivial cases. -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Nov 5 22:01:17 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Nov 2010 02:01:17 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <87mxpp3u3i.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <4cd4b6ed$0$30004$c3e8da3$5496439d@news.astraweb.com> On Thu, 04 Nov 2010 17:45:58 +0000, Tim Harig wrote: >>> Python is the only language that I know that *needs* to specify tabs >>> versus spaces since it is the only language I know of which uses >>> whitespace formating as part of its syntax and structure. [...] > I am also aware of other langauges such as Boo; but, I don't really > consider them individually relevant to the conversation as they are > explicitly using a Python based syntax. For this discussion I merely > group them with Python. You might as well say that C is the only language that uses tags around blocks, since for this discussion "I merely group" Pascal, Algol, Java, etc with C. -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Nov 5 22:13:59 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Nov 2010 02:13:59 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <87r5f13ug3.fsf.mdw@metalzone.distorted.org.uk> <4cd3df64$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4cd4b9e7$0$30004$c3e8da3$5496439d@news.astraweb.com> On Fri, 05 Nov 2010 18:45:39 +0000, Seebs wrote: > On 2010-11-05, Steven D'Aprano > wrote: >> On Thu, 04 Nov 2010 20:17:35 +0000, Seebs wrote: >>> That was the thing which bit me the worst. I had a fairly large block >>> of code in a first-pass ugly program. I wanted to start refactoring >>> it, so I moved a big hunk of code into a method (with plans to further >>> refactor). It took about fifteen minutes to redo the logic. > >> Well there's your problem -- you are relying on tools that operate by >> magic. > > Wrong. Really? Then how did the logic get screwed up from a mere copy-and-paste operation? In context (which you deleted), you were agreeing with Mark Wooding who wrote: "I /do/ have a significant problem with cutting and pasting code in Python. In most languages, I can haul a chunk of code about, hit C-M-q, and Emacs magically indents the result properly. This is, unfortunately, impossible with Python. It has caused me real bugs, and I have to be extra careful to fix the indentation up." [Aside: he isn't having problems with cutting and pasting code in Python, but in Emacs.] You *agreed with him*, and related your story. In context, I think it was perfectly reasonable to conclude that you too used C-M-q in Emacs, which then "magically indents the result". Mark's words, not mine. But perhaps you were using Notepad, and you just hit Ctrl-V, and something else mangled the code so badly you needed to spend 15 minutes re-creating the program logic. I am open to correction either way. >> Rather than re-create the logic, why not just hit Undo and then >> re-paste the code *without* the magic auto-reformat? Half a second, to >> undo and re- paste, followed by 10 or 20 seconds to select the >> appropriate lines and *explicitly* re-indent the lines to the correct >> level. > > There was no magic auto-reformat. Where did you invent that from? Why > are you making stuff up which I never said or referred to? Then how did the logic get mangled from a simple copy and paste operation? What god-awful editor are you using that can't copy and paste text without mangling it? -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Nov 5 22:15:49 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Nov 2010 02:15:49 GMT Subject: Silly newbie question - Carrot character (^) References: Message-ID: <4cd4ba55$0$30004$c3e8da3$5496439d@news.astraweb.com> On Fri, 05 Nov 2010 22:51:10 +0000, Seebs wrote: > On 2010-11-05, Nobody wrote: >> However, it's still written for language lawyers. > >> IMHO, the lack of a reference manual for the language itself is a major >> hole in Python's documentation. > > I'm a bit lost here. Could you highlight some of the differences > between "a reference manual for the language itself" and "something > written for language lawyers"? +1 QOTW -- Steven From python at mrabarnett.plus.com Fri Nov 5 22:16:00 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 06 Nov 2010 02:16:00 +0000 Subject: Regular expression In-Reply-To: References: Message-ID: <4CD4BA60.5090807@mrabarnett.plus.com> On 06/11/2010 01:25, Paul Hemans wrote: > I need to extract the quoted text from : > _("get this") > > The following works: > re.compile( "_\(['\"]([^'\"]+)['\"]\)" ) > However, I don't want to match if there is A-Z or a-z or 0-9 or _ > immediately preceding the "_" so I have tried: > "[^0-9a-zA-Z]*_\(['\"]([^'\"]+)['\"]\)" > "[^\w]{0,1}_\(['\"]([^'\"]+)['\"]\)" > "\W*_\(['\"]([^'\"]+)['\"]\)" > > to match against: > skip this text _("get this") > Use a negative lookbehind: re.compile(r'''(? Hello, In the framework of a project on evolutionary linguistics I wish to have a program to process words and simulate the effect of sound shift, for instance following the Rask's-Grimm's rule. I look to have python take a dictionary file or a string input and replace the consonants in it with the Grimm rule equivalent. For example: b? ? b ? p ? f d? ? d ? t ? ? g? ? g ? k ? x g?? ? g? ? k? ? x? If the dictionary file has the word "Abe" I want the program to replace the letter b with f forming the word "Afe" and write the result in a tabular file. How easy is it to find the python functions to do that? Best regards, Dax Bloom From clp2 at rebertia.com Fri Nov 5 22:36:49 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 5 Nov 2010 19:36:49 -0700 Subject: Using Python for a demonstration in historical linguistics In-Reply-To: <5a85f233-d463-4ef5-a045-342b83873b13@32g2000yqz.googlegroups.com> References: <5a85f233-d463-4ef5-a045-342b83873b13@32g2000yqz.googlegroups.com> Message-ID: On Fri, Nov 5, 2010 at 7:17 PM, Dax Bloom wrote: > Hello, > > In the framework of a project on evolutionary linguistics I wish to > have a program to process words and simulate the effect of sound > shift, for instance following the Rask's-Grimm's rule. I look to have > python take a dictionary file or a string input and replace the > consonants in it with the Grimm rule equivalent. For example: > b? ? b ? p ? f > d? ? d ? t ? ? > g? ? g ? k ? x > g?? ? g? ? k? ? x? > If the dictionary file has the word "Abe" I want the program to > replace the letter b with f forming the word "Afe" and write the > result in a tabular file. How easy is it to find the python functions > to do that? Tabular files: http://docs.python.org/library/csv.html Character substitution: (a) http://docs.python.org/library/string.html#string.maketrans and http://docs.python.org/library/stdtypes.html#str.translate (b) http://docs.python.org/library/stdtypes.html#str.replace In either case, learn about dicts: http://docs.python.org/library/stdtypes.html#dict Cheers, Chris -- http://blog.rebertia.com From python at mrabarnett.plus.com Fri Nov 5 22:37:06 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 06 Nov 2010 02:37:06 +0000 Subject: Using Python for a demonstration in historical linguistics In-Reply-To: <5a85f233-d463-4ef5-a045-342b83873b13@32g2000yqz.googlegroups.com> References: <5a85f233-d463-4ef5-a045-342b83873b13@32g2000yqz.googlegroups.com> Message-ID: <4CD4BF52.9030405@mrabarnett.plus.com> On 06/11/2010 02:17, Dax Bloom wrote: > Hello, > > In the framework of a project on evolutionary linguistics I wish to > have a program to process words and simulate the effect of sound > shift, for instance following the Rask's-Grimm's rule. I look to have > python take a dictionary file or a string input and replace the > consonants in it with the Grimm rule equivalent. For example: > b? ? b ? p ? f > d? ? d ? t ? ? > g? ? g ? k ? x > g?? ? g? ? k? ? x? > If the dictionary file has the word "Abe" I want the program to > replace the letter b with f forming the word "Afe" and write the > result in a tabular file. How easy is it to find the python functions > to do that? > Very. :-) I'd build a dict of each rule: b? ? b b ? p etc, and then use the re module to perform the replacements in one pass, looking up the new sound for each match. From steve at REMOVE-THIS-cybersource.com.au Fri Nov 5 23:09:03 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Nov 2010 03:09:03 GMT Subject: Compare source code References: Message-ID: <4cd4c6cf$0$30004$c3e8da3$5496439d@news.astraweb.com> On Fri, 05 Nov 2010 08:17:02 +0530, Rustom Mody wrote: > However the original question -- mixing tabs and spaces is bad -- has > got lost in the flames. Do the most die-hard python fanboys deny this? > And if not is it asking too much (say in python3) that mixing tabs and > spaces be flagged as an error or at least warning? Mixing spaces and tabs for indentation can be ambiguous. Python 2.x will attempt to ignore the ambiguity, and therefore run the code if it can, but Python 3.x treats mixed indentation in a single block as an error. [steve at sylar ~]$ cat ambiguous.py def f(): print("indented with 8 spaces") print("indented with tab") f() [steve at sylar ~]$ cat unambiguous.py def f(): print("indented with 8 spaces") def g(): print("indented with tab") f() g() Python 2.x will execute both files. Python 3.x will happily execute unambiguous.py, but raises an error on the other: [steve at sylar ~]$ python3 ambiguous.py File "ambiguous.py", line 3 print("indented with tab") ^ TabError: inconsistent use of tabs and spaces in indentation -- Steven From usenet-nospam at seebs.net Fri Nov 5 23:19:53 2010 From: usenet-nospam at seebs.net (Seebs) Date: 06 Nov 2010 03:19:53 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> <4cd4b68c$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-06, Steven D'Aprano wrote: > On Thu, 04 Nov 2010 19:37:25 +0000, Tim Harig wrote: >> Examples of communication channels that mangle white space abound. > Yes. So what? So something which is broken by them is brittle. And in every circumstance *other* than the syntax of Python, specifically, we regard brittleness to common events as a flaw in a design. For instance, Makefiles require tabs to indent rules, and behave strangely if for some reason you use spaces. Many editors, though, can be configured to insert spaces when you hit the tab key. This setup is not intrinsically "broken", it's just a matter of preference. And yet, when used with make, it produces cryptic failures. Everyone, without exception, agrees that this is a flaw in the design of make, and that the "tabs" rule should never have existed. > If your communication channel mangles your data, change > your communication channel, don't expect users of clean communication > channels to hand-enter error-correcting codes (braces) into the data. If you have to hand-enter them, perhaps you should get better tools, as many tools don't require you to hand-enter them. Ahh, but I forgot. You only need to get "better" tools if you're talking about why you *don't* find Python's design to be the one true pinnacle of idealized and perfect engineering. If you're talking about any other language which works fine and is no hassle if you have suitable tools, it is of course ridiculous to suggest that people should need to change away from tools which currently suit them fine. > Why is it the responsibility of the programming language syntax to > correct the problem with Seebs' faulty mail server? It's not. And honestly, if it were just one misconfigured mail server, no one would probably ever start this conversation. But instead it's dozens of mail servers, dozens of web forums, dozens of editors, OCR scanning of printouts, and dozens of other media in which it is easy for small whitespace changes to creep in or appear. All of which were known to exist when the decision was made to design a new file format to be brittle in the face of such changes. > XML is not a data format for human use, it is for use by machines. It is > slow, inefficient, and uneditable by humans except for the most trivial > cases. There are thousands of web pages which have been entered in something which could easily be imagined to be a variant of XML. For that matter, OS X ".plist" files are often stored in XML, which is widely liked because it gives you a nice, robust, human-readable format. Which is amenable to hand-editing if you want to tweak something. XML isn't a *great* format for human use, and it's certainly been aimed much more at use by machines. However, there's a lot to be said for designing machines to use formats which happen also to be easy for humans to read, at the very least, and possibly even easy to write. ("Easy" being, of course a relative term.) -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From philip at semanchuk.com Fri Nov 5 23:21:11 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Fri, 5 Nov 2010 23:21:11 -0400 Subject: Silly newbie question - Carrot character (^) In-Reply-To: References: Message-ID: On Nov 5, 2010, at 6:51 PM, Seebs wrote: > On 2010-11-05, Nobody wrote: >> However, it's still written for language lawyers. > >> IMHO, the lack of a reference manual for the language itself is a major >> hole in Python's documentation. > > I'm a bit lost here. Could you highlight some of the differences > between "a reference manual for the language itself" and "something > written for language lawyers"? The former refers to something that programmers would use to learn the language once they've gone through the tutorial a few times. The latter is great for writing a Python parser but isn't the friendliest guide to language constructs. Take the OP's question. How is one supposed to find out about bitwise operators in Python? AFAICT they're not mentioned in the tutorial, and neither are decorators, assert(), global, exec, the ternary if statement, etc. It seems that plowing through a document written for language lawyers is the only formal way to learn about those language features, and that could be improved upon IMO. Cheers Philip From usenet-nospam at seebs.net Fri Nov 5 23:23:36 2010 From: usenet-nospam at seebs.net (Seebs) Date: 06 Nov 2010 03:23:36 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <87r5f13ug3.fsf.mdw@metalzone.distorted.org.uk> <4cd3df64$0$30004$c3e8da3$5496439d@news.astraweb.com> <4cd4b9e7$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-06, Steven D'Aprano wrote: > On Fri, 05 Nov 2010 18:45:39 +0000, Seebs wrote: >> On 2010-11-05, Steven D'Aprano >> wrote: >>> Well there's your problem -- you are relying on tools that operate by >>> magic. >> Wrong. > Really? Then how did the logic get screwed up from a mere copy-and-paste > operation? I inserted four spaces in front of a bunch of lines. :) > [Aside: he isn't having problems with cutting and pasting code in Python, > but in Emacs.] True. > You *agreed with him*, and related your story. In context, I think it was > perfectly reasonable to conclude that you too used C-M-q in Emacs, which > then "magically indents the result". Mark's words, not mine. Ahh, okay. I can see how you would have inferred that, but no, that's not what I did. > What god-awful editor are you using that can't copy and paste text > without mangling it? It's a side-effect of vi being, by default, configured to prefer to convert things to tabs. The particular vi I'm using doesn't, so far as I know "recognize" file formats, and that default behavior is not merely tolerable but *preferable* for all of the dozens of other kinds of files I edit. I've since learned to work around it, but the fact remains that, given a fairly common behavior, which is *preferable* for every other context, I ended up with a file where an operation which would have worked for re-indenting any other language I use didn't for re-indenting Python. I've long since figured out ways to prevent that, but that wasn't the point; the point was how much harder it was to fix indentation once it had gotten mangled than it would be in, oh, any other programming language or file format I've used. (Even Makefiles are easier to fix, if only because they're so much simpler.) -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From ldo at geek-central.gen.new_zealand Fri Nov 5 23:32:08 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 06 Nov 2010 16:32:08 +1300 Subject: *** glibc detected *** gdb: malloc(): smallbin double linked list References: Message-ID: In message , Nobody wrote: > I imagine that your extension code is trashing the heap, in which case, > valgrind is probably the answer. Something simpler to try first is to run the code with the MALLOC_CHECK_ environment variable set to 2 or 3. That might give a few more clues. From steve at REMOVE-THIS-cybersource.com.au Fri Nov 5 23:33:08 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Nov 2010 03:33:08 GMT Subject: functions, list, default parameters References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <20101021235138.609fe668@geekmail.INVALID> <87pquk3ehs.fsf.mdw@metalzone.distorted.org.uk> <4cd3c72b$0$30004$c3e8da3$5496439d@news.astraweb.com> <8739rg2ceb.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <4cd4cc74$0$30004$c3e8da3$5496439d@news.astraweb.com> On Fri, 05 Nov 2010 12:17:00 +0000, Mark Wooding wrote: >> #1 Most default values are things like True, False, None, integer or >> string literals. Since they're literals, they will never change, so you >> only need to set them once. > > Right; so a half-decent compiler can notice this and optimize > appropriately. Result: negligible difference. You're right, of course, a sufficiently smart compiler could do this. It might even be worth doing in a language that otherwise re-initialises function defaults on every call. But such optimizations don't happen for free, they have costs: somebody has to write it, debug it, maintain it, deal with the added complexity. Python -- at least CPython -- tends to go for the simplest compiler that will work. Perhaps the biggest cost is that now your language has inconsistent semantics: some function defaults are set on every call, and some are set once, when the function is defined, and the choice between the two happens via "magic" -- the compiler decides what to do, you don't. I have mixed feelings about compiler optimizations. Things like constant folding seems to be both harmless and useful, but other optimizations not so much. It sets up a discrepancy between what the source code does and what the compiled code does, and in the case of (say) floating point code, can introduce *serious* bugs. So while I like the idea of compiler optimizations is principle, in practice I tend to think they should be avoided. >> #2 It's easy to get default values to initialise on function call in a >> language that uses initialisation on function definition semantics: >> just move the initialisation into the function body. Python has a >> particularly short and simple idiom for it: >> >> def f(x=None): >> if x is None: >> x = some_expression() > > That's actually rather clumsy. You think so? I think it's quite simple, obvious and neat. > Also, it's using in-band signalling: > you've taken None and used it as a magic marker meaning `not supplied'. > Suppose you want to distinguish /any/ supplied value from a missing > argument: how do you do this /correctly/? > > The approaches I see are (a) to invent some unforgeable token That's the simplest way. _sentinel = object() def f(x=_sentinel): if x is _sentinel: x = some_expression() > or (b) > emulate the argument processing by rifling through * and ** arguments. > > Solution (a) looks like this: > > _missing = ['missing'] > def foo(arg = _missing): > if arg is _missing: arg = ... > ... A curious choice for the sentinel value. We're not using Python 1.5 any longer :) > But now _missing is kicking around in the module's namespace. Er, yes. That's what namespaces are for. >> But if the situations were reversed, it's hard to get the DID >> semantics: >> >> def f(x=None): >> if x is None: >> global _f_default_arg >> try: >> x = _f_default_arg >> except NameError: >> _f_default_arg = x = default_calculation() > > Ugh. This is artificially awful and doesn't correspond to existing > Python DID semantics. [snip] Yes, you're right, those are good points and I stand corrected. -- Steven From ladasky at my-deja.com Sat Nov 6 00:06:14 2010 From: ladasky at my-deja.com (John Ladasky) Date: Fri, 5 Nov 2010 21:06:14 -0700 (PDT) Subject: How find all childrens values of a nested dictionary, fast! References: <87r5f1ypg7.fsf@web.de> Message-ID: <142db8da-536e-48ee-a7a2-ace296a50434@r4g2000prj.googlegroups.com> On Nov 4, 10:21?am, de... at web.de (Diez B. Roggisch) wrote: > macm writes: > ? ? for value in d.values(): > ? ? ? ? if isinstance(value, dict): I'm not a Python guru, but... do you care that you're breaking duck typing here? I've had other programmers warn me against using isinstance() for this reason. Yes, it's part of the Python language, but some people wonder whether it should be there. From ladasky at my-deja.com Sat Nov 6 00:10:14 2010 From: ladasky at my-deja.com (John Ladasky) Date: Fri, 5 Nov 2010 21:10:14 -0700 (PDT) Subject: Exception Handling in Python 3 References: <3d03cc6c-d71a-4d93-8db9-3a3a0297d25d@p1g2000yqm.googlegroups.com> Message-ID: <20e3e6f3-54a3-4f50-b51f-76a6217048ca@s12g2000prs.googlegroups.com> On Oct 29, 8:53?am, rantingrick wrote: > I am the programmer, and when i say to my interpretor "show this > exception instead of that exception" i expect my interpretor to do > exactly as i say or risk total annihilation!! I don't want my > interpreter "interpreting" my intentions and then doing what it > "thinks" is best for me. I have a wife already, i don't need a virtual > one! OK, Ranting Rick, that was funny, and worthy of your name. :^) From usenet-nospam at seebs.net Sat Nov 6 00:14:34 2010 From: usenet-nospam at seebs.net (Seebs) Date: 06 Nov 2010 04:14:34 GMT Subject: Compare source code References: <4cd4c6cf$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-06, Steven D'Aprano wrote: > On Fri, 05 Nov 2010 08:17:02 +0530, Rustom Mody wrote: >> However the original question -- mixing tabs and spaces is bad -- has >> got lost in the flames. Do the most die-hard python fanboys deny this? >> And if not is it asking too much (say in python3) that mixing tabs and >> spaces be flagged as an error or at least warning? > Mixing spaces and tabs for indentation can be ambiguous. Specifically: Four spaces followed by a tab nearly always actually means "eight spaces" to most editors (and Python seems to treat it that way), but it's hard to tell. Worse, a tab may have been intended to be the same thing as four spaces, and someone was expecting it NOT to be the same as eight spaces... -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Sat Nov 6 00:21:44 2010 From: usenet-nospam at seebs.net (Seebs) Date: 06 Nov 2010 04:21:44 GMT Subject: Silly newbie question - Carrot character (^) References: Message-ID: On 2010-11-06, Philip Semanchuk wrote: > The former refers to something that programmers would use to learn >the language once they've gone through the tutorial a few times. >The latter is great for writing a Python parser but isn't the >friendliest guide to language constructs. That sounds, then, like it's not very well written, even for language lawyers. > It seems that plowing through a document written for language >lawyers is the only formal way to learn about those language features, >and that could be improved upon IMO. It sounds to me like it could be improved on, but I don't think the problem is "written for language lawyers", but "not very well done". If you do a good job of writing something useful to language lawyers, any programmer should be able to look things up in it. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From steve at REMOVE-THIS-cybersource.com.au Sat Nov 6 00:33:25 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Nov 2010 04:33:25 GMT Subject: Silly newbie question - Carrot character (^) References: Message-ID: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> On Fri, 05 Nov 2010 23:21:11 -0400, Philip Semanchuk wrote: > Take the OP's question. How is one supposed to find out about bitwise > operators in Python? AFAICT they're not mentioned in the tutorial, and > neither are decorators, assert(), global, exec, the ternary if > statement, etc. The tutorial isn't meant as an exhaustive lesson on every single Python feature. There are plenty of other resources available: learning Python *starts* with the python.org tutorial (or some equivalent), it doesn't end there. As far as the OP's question, I'm kind of surprised that he wasn't told that Google is his friend. The very first hit for "python caret" answers his question. If he had spent even five seconds googling, he would have got his answer. http://www.google.co.uk/search?hl=en&safe=off&q=python+caret&btnG=Search > It seems that plowing through a document written for language lawyers is > the only formal way to learn about those language features, and that > could be improved upon IMO. Google on "Python book" and you will find dozens of other formal ways to learn about language features. At the interactive interpreter, type help("^") and press Enter, and (assuming your help system is set up correctly, which it may not be) you will get a table of operators, including ^ and &. Is it reasonable to assume somebody knows that symbols like + - * and ^ are called "operators" in most programming languages? I think so -- you have to assume some level of knowledge. So you could start at the Python language reference and scan the table of contents by eye for "operators" "operations", "ops" or similar. This gives: 5. Expressions 5.1. Arithmetic conversions 5.2. Atoms 5.3. Primaries 5.4. The power operator 5.5. Unary arithmetic and bitwise operations 5.6. Binary arithmetic operations 5.7. Shifting operations 5.8. Binary bitwise operations ... Admittedly, the language reference is a bit n00b-hostile with it's use of extended BNF notation for syntax. But I don't think it's entirely unreasonable to expect even a newbie to read and understand: "The ^ operator yields the bitwise XOR (exclusive OR) of its arguments, which must be plain or long integers. The arguments are converted to a common type." So, yes, the docs could be improved. They could *always* be improved, because somebody will always find something they don't like -- too detailed, not detailed enough, too long, too short, too hard for newbies, too dumbed down, not dumbed down enough... -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Nov 6 00:38:25 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Nov 2010 04:38:25 GMT Subject: Silly newbie question - Carrot character (^) References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4cd4dbc1$0$30004$c3e8da3$5496439d@news.astraweb.com> On Sat, 06 Nov 2010 04:33:25 +0000, Steven D'Aprano wrote: > As far as the OP's question, I'm kind of surprised that he wasn't told > that Google is his friend. The very first hit for "python caret" answers > his question. If he had spent even five seconds googling, he would have > got his answer. > > http://www.google.co.uk/search?hl=en&safe=off&q=python+caret&btnG=Search Ha, on the other hand googling for "python carrot" isn't helpful at all. But "python carrot operator" *does* give the same link as above. -- Steven From rustompmody at gmail.com Sat Nov 6 01:16:29 2010 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 6 Nov 2010 10:46:29 +0530 Subject: Why "flat is better than nested"? Message-ID: On Oct 26, 12:11 am, kj wrote: > In Steve Holden writes: > > > > >And everyone taking the Zen too seriously should remember that it was > >written by Tim Peters one night during the commercial breaks between > >rounds of wrestling on television. So while it can give useful guidance, > >it's nether prescriptive nor a bible ... > > Well, it's pretty *enshrined*, wouldn't you say? After all, it is > part of the standard distribution, has an easy-to-remember invocation, > etc. *Someone* must have taken it seriously enough to go through > all this bother. If it is as trivial as you suggest (and for all > I know you're absolutely right), then let's knock it off its pedestal > once and for all, and remove it from the standard distribution. > > ~kj If you take zen seriously you dont get it If you dont take zen seriously you dont get it That -- seriously -- is zen From rustompmody at gmail.com Sat Nov 6 01:51:48 2010 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 6 Nov 2010 11:21:48 +0530 Subject: Compare source code Message-ID: As for tools' brokeness regarding spaces/tabs/indentation heres a thread on the emacs list wherein emacs dev Stefan Monnier admits to the fact that emacs' handling in this regard is not perfect. http://groups.google.com/group/gnu.emacs.help/browse_thread/thread/1bd0c33a3e755730/89cbd920ee651b5a?q=tabs+stefan+spaces+group:gnu.emacs.help#89cbd920ee651b5a From tjreedy at udel.edu Sat Nov 6 02:07:18 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 06 Nov 2010 02:07:18 -0400 Subject: Final state of underlying sequence in islice In-Reply-To: References: <4b599f9b-5d99-4a9a-85a8-4ccba233bdc4@35g2000prb.googlegroups.com> Message-ID: On 11/5/2010 4:51 PM, Raymond Hettinger wrote: > On Nov 5, 1:05 pm, Terry Reedy wrote: >>> Currently, there are no promises or guarantees about the final state >>> of the iterator. >> >> I interpret the current doc statement as a promise that becomes >> ambiguous when step> 1. > > You may have missed my point. And you may have missed mine ;-) > I wrote the tools, the docs, and the tests. As I know. Thank you again. > If you interpret a "promise" in text, I can assure you it was not > intended. The behavior *is* undefined because I never defined it. > I'm happy to clarify the docs to make that explicit. Let me be clearer. Looking at that sentence *before* your initial answer to the OP, I interpreted (past tense) it as I said above. > Or I can alter the implementation a bit to make a guarantee > if it looks like there is a good reason to do so. One reason is that it is too easy for someone experimenting with islice to write a call that will run for a l o n g time. I had to cancel a couple of times when I was investigating the C versus Python versions and islice versus range behavior with large numbers (for the other islice issue on the tracker). In other words, the current implementation is a bit of a trap, especially since the C version runs for as long as possible while the Python version as short as possible. -- Terry Jan Reedy From shashank.sunny.singh at gmail.com Sat Nov 6 02:43:21 2010 From: shashank.sunny.singh at gmail.com (Shashank Singh) Date: Sat, 6 Nov 2010 12:13:21 +0530 Subject: Final state of underlying sequence in islice In-Reply-To: References: <4b599f9b-5d99-4a9a-85a8-4ccba233bdc4@35g2000prb.googlegroups.com> Message-ID: I have created an issue in roundup at http://bugs.python.org/issue10323. I was expecting the discussion to move to that place but since it has not, for the sake of completion I am quoting my response to Raymond that I had posted on roundup. > @Raymond: I don't have a particular use case where I had a problem with this behavior. I came across this "problem" when looking at this issue http://bugs.python.org/issue6305. > > An important problem that can happen with this behavior is that it does extra work that is not needed. Consider the case (it appears in Lib/test/test_itertools.py ): > > islice(count(), 1, 10, maxsize) > > where maxsize is MAX_Py_ssize_t > > Current implementation goes all the way up to maxsize when it should have just stopped at 10. > > You are probably right in saying that the caller can make sure that the parameters are such that such cases don't arise but I would still like to see python doing the best possible thing as far as possible. > > -- Regards Shashank Singh shashank.sunny.singh at gmail.com http://www.cse.iitb.ac.in/~shashanksingh -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at asd-group.com Sat Nov 6 03:24:13 2010 From: lists at asd-group.com (John Bond) Date: Sat, 06 Nov 2010 07:24:13 +0000 Subject: Regular expression In-Reply-To: <4CD4BA60.5090807@mrabarnett.plus.com> References: <4CD4BA60.5090807@mrabarnett.plus.com> Message-ID: <4CD5029D.1070905@asd-group.com> On 6/11/2010 2:16 AM, MRAB wrote: > On 06/11/2010 01:25, Paul Hemans wrote: >> I need to extract the quoted text from : >> _("get this") >> >> The following works: >> re.compile( "_\(['\"]([^'\"]+)['\"]\)" ) >> However, I don't want to match if there is A-Z or a-z or 0-9 or _ >> immediately preceding the "_" so I have tried: >> "[^0-9a-zA-Z]*_\(['\"]([^'\"]+)['\"]\)" >> "[^\w]{0,1}_\(['\"]([^'\"]+)['\"]\)" >> "\W*_\(['\"]([^'\"]+)['\"]\)" >> >> to match against: >> skip this text _("get this") >> > Use a negative lookbehind: > > re.compile(r'''(? References: Message-ID: <4CD5029F.4020508@holdenweb.com> On 11/5/2010 3:26 PM, Matty Sarro wrote: > It works, however I'm not sure if it'd be considered very "pythonic" or not. If working isn't pythonic then nothing is. > Thanks for your thoughts! There really are still some amazingly helpful people around here, I am pleased to note. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Open source meetings? When, and where? Call for details PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ Ob Open Source ? http://www.holdenweb.org/ From ldo at geek-central.gen.new_zealand Sat Nov 6 03:24:27 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 06 Nov 2010 20:24:27 +1300 Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> <87aalrjkty.fsf@benfinney.id.au> <8jd3m9Fr55U7@mid.individual.net> Message-ID: In message <8jd3m9Fr55U7 at mid.individual.net>, Neil Cerutti wrote: > On 2010-11-03, Ben Finney wrote: > >> styles = [ >> ("normal", "image", MainWindow.ColorsNormalList), >> ("highlighted", "highlight", MainWindow.ColorsHighlightedList), >> ("selected", "select", MainWindow.ColorsSelectedList)] > > Agreed, except cute stuff like putting those three items in > columns is just as bad. > > Code should be utilitarian rather than ornate, Shaker rather than > Victorian. Tufte?s concept of ?chartjunk? could perhaps be extended to ?formatjunk? or ?prettyprintjunk?. From steve at holdenweb.com Sat Nov 6 03:34:45 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 06 Nov 2010 03:34:45 -0400 Subject: ANN: PyQt v4.8.1 Released In-Reply-To: References: Message-ID: On 11/5/2010 6:14 PM, Lawrence D'Oliveiro wrote: > In message , ?????? ??????????? > wrote: > >>>> PyQt is available under the GPL and a commercial license. >>> >>> Surely you mean ?proprietary? rather than ?commercial?. There is >>> nothing about the GPL that prevents ?commercial? use. >> >> I think he means a license that *he* sells comercially :) > > Presumably that?s a proprietary licence. I don't see why. GPL v2, for example, has nothing to say about the price charged for the software: simply that the source must be made available. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Sat Nov 6 03:41:12 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 06 Nov 2010 03:41:12 -0400 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> Message-ID: On 11/5/2010 4:09 PM, Seebs wrote: > On 2010-11-05, Grant Edwards wrote: >> On 2010-11-05, Seebs wrote: >>> On 2010-11-05, Emile van Sebille wrote: >>>> So, which of your tools are you married to that are causing your issues? > >>> Python. > >> I think you should quit using Python and choose a language that works >> with whatever tools are causing all your white-space corruption >> problems. > > Ahh, but that's the thing. I'm married to it -- there's existing projects > I want to work on which are in Python. > > Anyway, it was a sort of frivolous answer, but it's ha-ha-only-serious; > after all, there were no serious issues with any of these tools before. > > There's a saying a friend of mine has; "a lack of communication is never > exclusively one party's fault." This applies, in many cases, to things > like "issues" that occur when two programs clash in some aspect of their > designs. In some cases, there might be a real and unambiguous standard > to be violated. In others, though, you can have a problem which arises > from a clash in expectations between two programs, either of which is fine > on its own. > > There is a clash between Python and the whole category of things which > sometimes lose whitespace. Because that category is reasonably large, > and known to be large, and unlikely to vanish, many language designers > choose to build their languages to be robust in the face of minor changes > in whitespace. Python chose not to, and that is a source of conflicts. > The whitespace-eating nanovirus was conquered in 2005, and is not expected to reappear. > Were someone to invent a *new* text editor, which mangled whitespace, I > would accuse it of being gratuitously incompatible with Python; I tend > to regard compatibility, once you get past the standards, as a matter > of temporal precedence. > > -s If someone were to use a text editor which had always historically mangled whitespace I would find myself wondering why they found it necessary to restrict themselves to such stone-age tools. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From rustompmody at gmail.com Sat Nov 6 03:47:47 2010 From: rustompmody at gmail.com (rustom) Date: Sat, 6 Nov 2010 00:47:47 -0700 (PDT) Subject: Why "flat is better than nested"? References: Message-ID: On Oct 26, 12:11?am, kj wrote: > In Steve Holden writes: > > > > >On 10/25/2010 10:47 AM, rantingrick wrote: > >> On Oct 25, 5:07 am, kj wrote: > >>> In "The Zen of Python", one of the "maxims" is "flat is better than > >>> nested"? ?Why? ?Can anyone give me a concrete example that illustrates > >>> this point? > > >> Simple. This commandment (endowed by the anointed one, GvR) is > >> directed directly at lisp and those filthy lispers. If you don't know > >> what lisp is then Google it. Then try to program with it for one hour. > >> Very soon after your head will explode from the nested bracket plague > >> and then you shall be enlightened! > > >And everyone taking the Zen too seriously should remember that it was > >written by Tim Peters one night during the commercial breaks between > >rounds of wrestling on television. So while it can give useful guidance, > >it's nether prescriptive nor a bible ... > > Well, it's pretty *enshrined*, wouldn't you say? ?After all, it is > part of the standard distribution, has an easy-to-remember invocation, > etc. ?*Someone* must have taken it seriously enough to go through > all this bother. ?If it is as trivial as you suggest (and for all > I know you're absolutely right), then let's knock it off its pedestal > once and for all, and remove it from the standard distribution. > > ~kj If you take zen seriously you dont get it If you dont take zen seriously you dont get it That -- seriously -- is zen From steve at REMOVE-THIS-cybersource.com.au Sat Nov 6 04:14:54 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Nov 2010 08:14:54 GMT Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> <87aalrjkty.fsf@benfinney.id.au> <8jd3m9Fr55U7@mid.individual.net> Message-ID: <4cd50e7e$0$30004$c3e8da3$5496439d@news.astraweb.com> On Wed, 03 Nov 2010 12:42:49 +0000, Neil Cerutti wrote: > On 2010-11-03, Ben Finney wrote: >> I would do the same, but fix the indentation. Making indentation depend >> on the *length* of the previous line is needlessly making a maintenance >> burden. >> >> Instead, I'd do:: >> >> styles = [ >> ("normal", "image", MainWindow.ColorsNormalList), >> ("highlighted", "highlight", MainWindow.ColorsHighlightedList), >> ("selected", "select", MainWindow.ColorsSelectedList)] > > Agreed, except cute stuff like putting those three items in columns is > just as bad. > > Code should be utilitarian rather than ornate, Shaker rather than > Victorian. Perhaps, but lining up the columns in a 3x3 table is hardly "ornate". I have mixed feelings here. On the one hand, there's no doubt in my mind that the extra whitespace and aligned columns make the data easier to read for me. On the other hand, I know that it is easy to fall into the trap of spending hours carefully aligning code that doesn't need to be aligned. -- Steven From usenet-nospam at seebs.net Sat Nov 6 04:27:00 2010 From: usenet-nospam at seebs.net (Seebs) Date: 06 Nov 2010 08:27:00 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> Message-ID: On 2010-11-06, Steve Holden wrote: > If someone were to use a text editor which had always historically > mangled whitespace I would find myself wondering why they found it > necessary to restrict themselves to such stone-age tools. I have yet to find an editor that allows me to, well, *edit*, more comfortably than vi. As to what it does with whitespace... What it does is exactly what is most desireable in every other kind of file I edit. I wouldn't normally refer to it as "mangling" in the pejorative sense; it mostly leaves spaces alone, but when preserving indentation from one line to the next, uses tabs. That, it turns out, is useful and desireable in nearly all programming languages, and in particular, in all the other programming languages I use. I don't think it's fair to accuse tools of being "stone age" on the grounds that they do something which most users want most of the time by default. The "no tabs, only spaces" thing is an interesting idiosyncrasy of a particular community, which places a high value on telling people to change everything about their computing environment so they can appreciate how robust Python is when you make a point of blaming any and all quirks or nuisances on tools. We might as well insist that everyone use editors which automatically add the braces to C code (such exist) when they complain about the "effort" of typing matching braces. Surely, if you have to type braces by hand, the problem isn't with C, but with your stone age editor? Oh, wait. That kind of smug dismissiveness is considered rude unless it's done in *favor* of Python. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From steve at REMOVE-THIS-cybersource.com.au Sat Nov 6 04:52:13 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Nov 2010 08:52:13 GMT Subject: Split iterator into multiple streams Message-ID: <4cd5173d$0$30004$c3e8da3$5496439d@news.astraweb.com> Suppose I have an iterator that yields tuples of N items (a, b, ... n). I want to split this into N independent iterators: iter1 -> a, a2, a3, ... iter2 -> b, b2, b3, ... ... iterN -> n, n2, n3, ... The iterator may be infinite, or at least too big to collect in a list. My first attempt was this: def split(iterable, n): iterators = [] for i, iterator in enumerate(itertools.tee(iterable, n)): iterators.append((t[i] for t in iterator)) return tuple(iterators) But it doesn't work, as all the iterators see the same values: >>> data = [(1,2,3), (4,5,6), (7,8,9)] >>> a, b, c = split(data, 3) >>> list(a), list(b), list(c) ([3, 6, 9], [3, 6, 9], [3, 6, 9]) I tried changing the t[i] to use operator.itergetter instead, but no luck. Finally I got this: def split(iterable, n): iterators = [] for i, iterator in enumerate(itertools.tee(iterable, n)): f = lambda it, i=i: (t[i] for t in it) iterators.append(f(iterator)) return tuple(iterators) which seems to work: >>> data = [(1,2,3), (4,5,6), (7,8,9)] >>> a, b, c = split(data, 3) >>> list(a), list(b), list(c) ([1, 4, 7], [2, 5, 8], [3, 6, 9]) Is this the right approach, or have I missed something obvious? -- Steven From ian.g.kelly at gmail.com Sat Nov 6 05:24:13 2010 From: ian.g.kelly at gmail.com (Ian) Date: Sat, 6 Nov 2010 02:24:13 -0700 (PDT) Subject: Split iterator into multiple streams References: <4cd5173d$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Nov 6, 2:52?am, Steven D'Aprano wrote: > My first attempt was this: > > def split(iterable, n): > ? ? iterators = [] > ? ? for i, iterator in enumerate(itertools.tee(iterable, n)): > ? ? ? ? iterators.append((t[i] for t in iterator)) > ? ? return tuple(iterators) > > But it doesn't work, as all the iterators see the same values: Because the value of i is not evaluated until the generator is actually run; so all the generators end up seeing only the final value of i rather than the intended values. This is a common problem with generator expressions that are not immediately run. > I tried changing the t[i] to use operator.itergetter instead, but no > luck. Finally I got this: > > def split(iterable, n): > ? ? iterators = [] > ? ? for i, iterator in enumerate(itertools.tee(iterable, n)): > ? ? ? ? f = lambda it, i=i: (t[i] for t in it) > ? ? ? ? iterators.append(f(iterator)) > ? ? return tuple(iterators) > > which seems to work: > > >>> data = [(1,2,3), (4,5,6), (7,8,9)] > >>> a, b, c = split(data, 3) > >>> list(a), list(b), list(c) > > ([1, 4, 7], [2, 5, 8], [3, 6, 9]) > > Is this the right approach, or have I missed something obvious? That avoids the generator problem, but in this case you could get the same result a bit more straight-forwardly by just using imap instead: def split(iterable, n): iterators = [] for i, iterator in enumerate(itertools.tee(iterable, n)): iterators.append(itertools.imap(operator.itemgetter(i), iterator)) return tuple(iterators) >>> map(list, split(data, 3)) [[1, 4, 7], [2, 5, 8], [3, 6, 9]] Cheers, Ian From __peter__ at web.de Sat Nov 6 05:25:42 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 06 Nov 2010 10:25:42 +0100 Subject: Split iterator into multiple streams References: <4cd5173d$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Suppose I have an iterator that yields tuples of N items (a, b, ... n). > > I want to split this into N independent iterators: > > iter1 -> a, a2, a3, ... > iter2 -> b, b2, b3, ... > ... > iterN -> n, n2, n3, ... > > The iterator may be infinite, or at least too big to collect in a list. > > My first attempt was this: > > > def split(iterable, n): > iterators = [] > for i, iterator in enumerate(itertools.tee(iterable, n)): > iterators.append((t[i] for t in iterator)) > return tuple(iterators) > > But it doesn't work, as all the iterators see the same values: > >>>> data = [(1,2,3), (4,5,6), (7,8,9)] >>>> a, b, c = split(data, 3) >>>> list(a), list(b), list(c) > ([3, 6, 9], [3, 6, 9], [3, 6, 9]) > > > I tried changing the t[i] to use operator.itergetter instead, but no > luck. Finally I got this: > > def split(iterable, n): > iterators = [] > for i, iterator in enumerate(itertools.tee(iterable, n)): > f = lambda it, i=i: (t[i] for t in it) > iterators.append(f(iterator)) > return tuple(iterators) > > which seems to work: > >>>> data = [(1,2,3), (4,5,6), (7,8,9)] >>>> a, b, c = split(data, 3) >>>> list(a), list(b), list(c) > ([1, 4, 7], [2, 5, 8], [3, 6, 9]) > > > > > Is this the right approach, or have I missed something obvious? Here's how to do it with operator.itemgetter(): >>> from itertools import * >>> from operator import itemgetter >>> data = [(1,2,3), (4,5,6), (7,8,9)] >>> abc = [imap(itemgetter(i), t) for i, t in enumerate(tee(data, 3))] >>> map(list, abc) [[1, 4, 7], [2, 5, 8], [3, 6, 9]] I'd say the improvement is marginal. If you want to go fancy you can calculate n: >>> def split(items, n=None): ... if n is None: ... items = iter(items) ... first = next(items) ... n = len(first) ... items = chain((first,), items) ... return [imap(itemgetter(i), t) for i, t in enumerate(tee(items, n))] ... >>> map(list, split([(1,2,3), (4,5,6), (7,8,9)])) [[1, 4, 7], [2, 5, 8], [3, 6, 9]] Peter From python at rcn.com Sat Nov 6 05:26:18 2010 From: python at rcn.com (Raymond Hettinger) Date: Sat, 6 Nov 2010 02:26:18 -0700 (PDT) Subject: Split iterator into multiple streams References: <4cd5173d$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9fd95af7-4c56-42e5-92e9-d3e2d11182ea@u25g2000pra.googlegroups.com> On Nov 6, 1:52?am, Steven D'Aprano wrote: > I tried changing the t[i] to use operator.itergetter instead, but no > luck. Finally I got this: > > def split(iterable, n): > ? ? iterators = [] > ? ? for i, iterator in enumerate(itertools.tee(iterable, n)): > ? ? ? ? f = lambda it, i=i: (t[i] for t in it) > ? ? ? ? iterators.append(f(iterator)) > ? ? return tuple(iterators) > > which seems to work: > > >>> data = [(1,2,3), (4,5,6), (7,8,9)] > >>> a, b, c = split(data, 3) > >>> list(a), list(b), list(c) > > ([1, 4, 7], [2, 5, 8], [3, 6, 9]) > > Is this the right approach, or have I missed something obvious? That looks about right to me. It can be compacted a bit: def split(iterable, n): return tuple(imap(itemgetter(i), it) for i, it in enumerate(tee(iterable, n))) Internally, the tee's iterators are going to accumulate a ton of data unless they are consumed roughly in parallel. Of course, if they are consumed *exactly* in lockstep, the you don't need to split them into separate iterables -- just use the tuples as they come. Raymond From no.email at nospam.invalid Sat Nov 6 05:31:03 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 06 Nov 2010 02:31:03 -0700 Subject: Split iterator into multiple streams References: <4cd5173d$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7xk4kqdciw.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > def split(iterable, n): > iterators = [] > for i, iterator in enumerate(itertools.tee(iterable, n)): > f = lambda it, i=i: (t[i] for t in it) > iterators.append(f(iterator)) > return tuple(iterators) > > Is this the right approach, or have I missed something obvious? I think there is no way around using tee. But the for loop looks ugly. This looks more direct to me, if I didn't mess something up: def split(iterable, n): return tuple(imap(itemgetter(i),t) for i,t in enumerate(tee(iterable,n))) From __peter__ at web.de Sat Nov 6 05:31:12 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 06 Nov 2010 10:31:12 +0100 Subject: Final state of underlying sequence in islice References: <4b599f9b-5d99-4a9a-85a8-4ccba233bdc4@35g2000prb.googlegroups.com> <777bd489-ef2a-4898-8d69-27ebff7832ea@x7g2000prj.googlegroups.com> Message-ID: Raymond Hettinger wrote: > If the RightAnswer(tm) is obvious to you, I would > like to hear it. It isnt ;) > If I had to make a choice right > now, I would choose stopping at the earlier possible > point rather than scanning to the next natural > boundary. +1 Not because it leaves the underlying iterator in a more useful state (I think it doesn't), but because I like the principle that generators do as little work as possible. Peter From __peter__ at web.de Sat Nov 6 05:52:07 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 06 Nov 2010 10:52:07 +0100 Subject: Why "flat is better than nested"? References: Message-ID: rustom wrote: > If you take zen seriously you dont get it > If you dont take zen seriously you dont get it You forgot: If you explain zen you don't get it From __peter__ at web.de Sat Nov 6 06:09:34 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 06 Nov 2010 11:09:34 +0100 Subject: Using Python for a demonstration in historical linguistics References: <5a85f233-d463-4ef5-a045-342b83873b13@32g2000yqz.googlegroups.com> Message-ID: Dax Bloom wrote: > Hello, > > In the framework of a project on evolutionary linguistics I wish to > have a program to process words and simulate the effect of sound > shift, for instance following the Rask's-Grimm's rule. I look to have > python take a dictionary file or a string input and replace the > consonants in it with the Grimm rule equivalent. For example: > b? ? b ? p ? f > d? ? d ? t ? ? > g? ? g ? k ? x > g?? ? g? ? k? ? x? > If the dictionary file has the word "Abe" I want the program to > replace the letter b with f forming the word "Afe" and write the > result in a tabular file. How easy is it to find the python functions > to do that? > > Best regards, > > Dax Bloom >>> s = """ ... In the framework of a project on evolutionary linguistics I wish to ... have a program to process words and simulate the effect of sound ... shift, for instance following the Rask's-Grimm's rule. I look to have ... python take a dictionary file or a string input and replace the ... consonants in it with the Grimm rule equivalent. For example: ... """ >>> rules = ["bpf", ("d", "t", "th"), "gkx"] >>> for rule in rules: ... rule = rule[::-1] # go back in time ... for i in range(len(rule)-1): ... s = s.replace(rule[i], rule[i+1]) ... >>> print s In de brameworg ob a brojecd on evoludionary linguisdics I wish do have a brogram do brocess words and simulade de ebbecd ob sound shibd, bor insdance bollowing de Rasg's-Grimm's rule. I loog do have bydon dage a dicdionary bile or a sdring inbud and reblace de consonands in id wid de Grimm rule equivalend. For egamble: ;) If you are using nonascii characters like ? you should use unicode instead of str. Basically this means writing string constants as u"..." instead of "..." and opening your files with f = codecs.open(filename, encoding="utf-8") instead of f = open(filename) Peter From __peter__ at web.de Sat Nov 6 06:23:37 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 06 Nov 2010 11:23:37 +0100 Subject: Exception handling with NameError References: Message-ID: Dennis Lee Bieber wrote: >> The problem I am having is this: If I do: >> >> K = [] >> ARCHIVE = [] >> ARCHIVE.append(K) >> >> any time K is updated (user submits new input) the content of ARCHIVE >> is erased: >> > No, it is NOT erased... It is MUTATED... But he rebinds the ARCHIVE name. From __peter__ at web.de Sat Nov 6 06:32:24 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 06 Nov 2010 11:32:24 +0100 Subject: Exception handling with NameError References: Message-ID: Zeynel wrote: > On Nov 5, 1:26 pm, Peter Otten <__pete... at web.de> wrote: > >> Of course I'm only guessing because you don't provide enough context. >> >> Peter > > Thanks. > > This is the problem I am having, in general: > > K = [] # a container list > K = ["A", "B"] > > ARCHIVE = [] # a list where items from K is archived > > ARCHIVE.append(K) > > # K is updated > K = ["C", "D"] > > # append new K to ARCHIVE > ARCHIVE.append(K) > > The problem I am having is this: If I do: > > K = [] > ARCHIVE = [] > ARCHIVE.append(K) > > any time K is updated (user submits new input) the content of ARCHIVE > is erased: > > If I do this: > > K = [] > ARCHIVE.append(K) > > I get NameError: "Name ARCHIVE not defined" > > What is the solution? archive = [] k = ["a", "b"] for new_k in get_container(): archive.append(k) k = new_k I. e. don't rebind the name archive if you don't want to lose old data. >>> import random, string >>> def get_container(): ... for i in range(5): ... yield [random.choice(string.ascii_lowercase) for _ in range(2)] ... >>> archive = [] >>> k = ["a", "b"] >>> for new_k in get_container(): ... archive.append(k) ... k = new_k ... print "k is now", k ... print "archive contents", archive ... k is now ['h', 'r'] archive contents [['a', 'b']] k is now ['t', 'y'] archive contents [['a', 'b'], ['h', 'r']] k is now ['y', 'q'] archive contents [['a', 'b'], ['h', 'r'], ['t', 'y']] k is now ['p', 'i'] archive contents [['a', 'b'], ['h', 'r'], ['t', 'y'], ['y', 'q']] k is now ['y', 'n'] archive contents [['a', 'b'], ['h', 'r'], ['t', 'y'], ['y', 'q'], ['p', 'i']] Peter From steve at REMOVE-THIS-cybersource.com.au Sat Nov 6 06:33:28 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Nov 2010 10:33:28 GMT Subject: Using Python for a demonstration in historical linguistics References: <5a85f233-d463-4ef5-a045-342b83873b13@32g2000yqz.googlegroups.com> Message-ID: <4cd52ef8$0$30004$c3e8da3$5496439d@news.astraweb.com> On Sat, 06 Nov 2010 11:09:34 +0100, Peter Otten wrote: > If you are using nonascii characters like ? you should use unicode > instead of str. Basically this means writing string constants as u"..." > instead of "..." Or using Python 3.1 instead of 2.x. -- Steven From garabik-news-2005-05 at kassiopeia.juls.savba.sk Sat Nov 6 06:49:28 2010 From: garabik-news-2005-05 at kassiopeia.juls.savba.sk (garabik-news-2005-05 at kassiopeia.juls.savba.sk) Date: Sat, 6 Nov 2010 10:49:28 +0000 (UTC) Subject: Using Python for a demonstration in historical linguistics References: <5a85f233-d463-4ef5-a045-342b83873b13@32g2000yqz.googlegroups.com> Message-ID: Dax Bloom wrote: ... > I look to have > python take a dictionary file or a string input and replace the > consonants in it with the Grimm rule equivalent. ... > How easy is it to find the python functions > to do that? > http://code.activestate.com/recipes/81330-single-pass-multiple-replace/ -- ----------------------------------------------------------- | 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 python at bdurham.com Sat Nov 6 07:04:56 2010 From: python at bdurham.com (python at bdurham.com) Date: Sat, 06 Nov 2010 07:04:56 -0400 Subject: Best practice approach for trapping Tkinter exceptions Message-ID: <1289041496.20059.1403897831@webmail.messagingengine.com> What is the best practice approach for trapping Tkinter exceptions? Example: When using the Text widget with undo=True, attempting an edit_undo or edit_redo raises a Tkinter exception when there are no actions to undo or redo. It doesn't look like there's a Tkinter specific exception being raised - only a general exception. Is there a better way to trap Tkinter exceptions than wrapping certain Tkinter commands like the following: try: widget_with_focus.edit_undo() except Exception as e: pass If I print the exception that I trapped, all I get is the name of the Tkinter method I tried to execute, eg. edit_undo. For bonus points: Is there a way to query a Tkinter Text widget to determine if there are undo or redo actions available to apply? Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Sat Nov 6 07:18:39 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 06 Nov 2010 12:18:39 +0100 Subject: Using Python for a demonstration in historical linguistics References: <5a85f233-d463-4ef5-a045-342b83873b13@32g2000yqz.googlegroups.com> Message-ID: Peter Otten wrote: >>>> s = """ > ... In the framework of a project on evolutionary linguistics I wish to > ... have a program to process words and simulate the effect of sound > ... shift, for instance following the Rask's-Grimm's rule. I look to have > ... python take a dictionary file or a string input and replace the > ... consonants in it with the Grimm rule equivalent. For example: > ... """ >>>> rules = ["bpf", ("d", "t", "th"), "gkx"] >>>> for rule in rules: > ... rule = rule[::-1] # go back in time > ... for i in range(len(rule)-1): > ... s = s.replace(rule[i], rule[i+1]) > ... Warning: this simple-minded approach somewhat limits the possible rules. E. g. it fails for a --> b b --> a >>> "abba".replace("a", "b").replace("b", "a") 'aaaa' while unicode.translate() can deal with it: >>> u"abba".translate({ord(u"a"): u"b", ord(u"b"): u"a"}) u'baab' Or, if you are using Python 3.x as Steven suggested: >>> "abba".translate({ord("a"): "b", ord("b"): "a"}) 'baab' Peter From kevin.p.dwyer at gmail.com Sat Nov 6 07:26:02 2010 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Sat, 6 Nov 2010 11:26:02 +0000 (UTC) Subject: What people are using to access this mailing list References: <4cd144cc$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, 03 Nov 2010 11:17:32 +0000, Steven D'Aprano wrote: > On Wed, 03 Nov 2010 08:02:29 +0000, John Bond wrote: > >> Hope this isn't too O/T - I was just wondering how people read/send to >> this mailing list, eg. normal email client, gmane, some other software >> or online service? > > Usenet via my ISP, on comp.lang.python. news.gmane.org, using Pan. From vlastimil.brom at gmail.com Sat Nov 6 07:41:09 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sat, 6 Nov 2010 12:41:09 +0100 Subject: Using Python for a demonstration in historical linguistics In-Reply-To: <5a85f233-d463-4ef5-a045-342b83873b13@32g2000yqz.googlegroups.com> References: <5a85f233-d463-4ef5-a045-342b83873b13@32g2000yqz.googlegroups.com> Message-ID: 2010/11/6 Dax Bloom : > Hello, > > In the framework of a project on evolutionary linguistics I wish to > have a program to process words and simulate the effect of sound > shift, for instance following the Rask's-Grimm's rule. I look to have > python take a dictionary file or a string input and replace the > consonants in it with the Grimm rule equivalent. For example: > b? ? b ? p ? f > d? ? d ? t ? ? > g? ? g ? k ? x > g?? ? g? ? k? ? x? > If the dictionary file has the word "Abe" I want the program to > replace the letter b with f forming the word "Afe" and write the > result in a tabular file. How easy is it to find the python functions > to do that? > > Best regards, > > Dax Bloom > -- > http://mail.python.org/mailman/listinfo/python-list > Hi, I guess, the most difficult part would be, to select appropriate words, to apply the simple rules on (in order not to get "problems" with Verner's Law or other special rules). You also normally wouldn't want to chain the changes like the above, but to keep them separated b? ? b; p ? f (ie. *b?r?ter- > ... brother and not *p-... (at least without the High German consonant shift)). of course, there are also vowel changes to be dealt with and many more peculiarities ... As for implementation, I guess, the simplest way might be to use regular expression replacements - re.sub(...) with a replace function looking up the appropriate results in a dictionary. maybe something along the lines: ######################################## Rask_Grimm_re = ur"[bdgptk]??" Rask_Grimm_dct = {u"b":u"p", u"b?": u"b", u"t": u"?", } # ... def repl_fn(m): return Rask_Grimm_dct.get(m.group(), m.group()) ie_txt = u" b?r?ter ... " almost_germ_txt = re.sub(Rask_Grimm_re, repl_fn, ie_txt) print u"%s >> %s" % (ie_txt, almost_germ_txt) # vowel changes etc. TBD ######################################## b?r?ter ... >> br??er ... hth, vbr From gerlach_joerg at web.de Sat Nov 6 07:49:39 2010 From: gerlach_joerg at web.de (J. Gerlach) Date: Sat, 06 Nov 2010 12:49:39 +0100 Subject: Why "flat is better than nested"? In-Reply-To: <4cd4b124$0$30004$c3e8da3$5496439d@news.astraweb.com> References: <4cc8d49c$0$29982$c3e8da3$5496439d@news.astraweb.com> <4cd4b124$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: Am 06.11.2010 02:36, schrieb Steven D'Aprano: > On Fri, 05 Nov 2010 14:19:47 +0100, J. Gerlach wrote: > >> Am 28.10.2010 03:40, schrieb Steven D'Aprano: >>> [ snip a lot of wise words ] >> >> Can I put this (translated) in the german python wiki? I guess it might >> help more people to understand some decisions taken during python's >> development - and I'm to lazy to do something similar myself ;) > > > Sure, go ahead. > > I would appreciate a link back to my post, and/or credit, but that's not > essential. (I understand it's a wiki and there's no guarantee that the > link will remain there forever.) > > Thank you, and of course I gave you credit. I linked back to your post via googlegroups. From python.list at tim.thechases.com Sat Nov 6 07:59:58 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 06 Nov 2010 06:59:58 -0500 Subject: Silly newbie question - Carrot character (^) In-Reply-To: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4CD5433E.1000805@tim.thechases.com> On 11/05/10 23:33, Steven D'Aprano wrote: > As far as the OP's question, I'm kind of surprised that he wasn't told > that Google is his friend. The very first hit for "python caret" answers > his question. If he had spent even five seconds googling, he would have > got his answer. > > http://www.google.co.uk/search?hl=en&safe=off&q=python+caret&btnG=Search The OP didn't seem to know the name for the character which makes it difficult. As they wrote in the initial message, "Sadly my google foo is failing since the character gets filtered out." I'm guessing the OP tried to search for "python ^", and the "^" just got filtered out, which makes for a rather unhelpful search for just "python". And since the OP had already tried to google it, they weren't told to attempt it again. ;-) Yes, with a little tweaking to the query, something like "python ^ operator" would get them to pages matching "python operator" in which they could have searched for "^", but at least they made the attempt (the lack of an *attempt* is what usually brings out the "GTFW" responses). -tkc From python.list at tim.thechases.com Sat Nov 6 08:00:20 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 06 Nov 2010 07:00:20 -0500 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> Message-ID: <4CD54354.90208@tim.thechases.com> On 11/06/10 03:27, Seebs wrote: > On 2010-11-06, Steve Holden wrote: >> If someone were to use a text editor which had always historically >> mangled whitespace I would find myself wondering why they found it >> necessary to restrict themselves to such stone-age tools. > > I have yet to find an editor that allows me to, well, *edit*, more > comfortably than vi. > > As to what it does with whitespace... What it does is exactly what > is most desireable in every other kind of file I edit. I wouldn't > normally refer to it as "mangling" in the pejorative sense; it mostly > leaves spaces alone, but when preserving indentation from one line > to the next, uses tabs. That, it turns out, is useful and desireable > in nearly all programming languages, and in particular, in all > the other programming languages I use. I think in a previous thread, you mentioned that you use nvi. While I can't speak to the knobs-and-dials that nvi offers, in vim, you can twiddle the 'expandtab' option (along with the associated 'tabwidth' and 'shiftwidth' settings) to get whatever behavior is deemed "correct" for the project you're working on. So if I'm working on a project with PEP-8 4-spaces-per-indent, I'll :set sw=4 ts=4 et and then if the file erroneously has tabs in it, I'll just issue :retab to fix it[1]. -tkc [1] Yes, if you have string literals with tabs that you want to keep in them, the solution is a little more complex, but doable; though in such cases I'd recommend using "\t" instead of a literal tab. From mdw at distorted.org.uk Sat Nov 6 08:21:34 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Sat, 06 Nov 2010 12:21:34 +0000 Subject: Compare source code References: Message-ID: <87fwveej75.fsf.mdw@metalzone.distorted.org.uk> Rustom Mody writes: > As for tools' brokeness regarding spaces/tabs/indentation heres a > thread on the emacs list wherein emacs dev Stefan Monnier admits to > the fact that emacs' handling in this regard is not perfect. > > http://groups.google.com/group/gnu.emacs.help/browse_thread/thread/1bd0c33a3e755730/89cbd920ee651b5a?q=tabs+stefan+spaces+group:gnu.emacs.help#89cbd920ee651b5a You've misunderstood. That discussion is about configuring Emacs to not do automatic indentation when the `tab' key is pressed or when language-specific punctuation is entered. It has very little to do with tab characters in files. -- [mdw] From mygogo2011 at gmail.com Sat Nov 6 08:29:08 2010 From: mygogo2011 at gmail.com (PHP.CCC) Date: Sat, 6 Nov 2010 05:29:08 -0700 (PDT) Subject: MY X+X NURSE AND NURSING SCHOOL Message-ID: MY X+X NURSE AND NURSING SCHOOL READ MORE >>>>> http://nursingschol.blogspot.com/ From rustompmody at gmail.com Sat Nov 6 08:34:37 2010 From: rustompmody at gmail.com (rustom) Date: Sat, 6 Nov 2010 05:34:37 -0700 (PDT) Subject: Why "flat is better than nested"? References: Message-ID: On Nov 6, 2:52?pm, Peter Otten <__pete... at web.de> wrote: > rustom wrote: > > If you take zen seriously you dont get it > > If you dont take zen seriously you dont get it > > You forgot: > > If you explain zen you don't get it I guess different communities have different settings for 'explanation- toleration' (as also 'seriousness') eg. Classical zen: If you the Buddha on the road kill him! Now :s/the Buddha/Jesus Christ/ and it suddenly seems more offensive -- not because the Buddha and Jesus Christ are all that different but because the respective communities have different seriousness defaults. And as for another teacher whose sphere of influence was a few hundred km from Jesus' I am going to be even more careful because the seriousness-defaults are set lower still... From mdw at distorted.org.uk Sat Nov 6 08:37:42 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Sat, 06 Nov 2010 12:37:42 +0000 Subject: functions, list, default parameters References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <20101021235138.609fe668@geekmail.INVALID> <87pquk3ehs.fsf.mdw@metalzone.distorted.org.uk> <4cd3c72b$0$30004$c3e8da3$5496439d@news.astraweb.com> <8739rg2ceb.fsf.mdw@metalzone.distorted.org.uk> <4cd4cc74$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87bp62eig9.fsf.mdw@metalzone.distorted.org.uk> Steven D'Aprano writes: > On Fri, 05 Nov 2010 12:17:00 +0000, Mark Wooding wrote: > > Right; so a half-decent compiler can notice this and optimize > > appropriately. Result: negligible difference. > > Perhaps the biggest cost is that now your language has inconsistent > semantics: some function defaults are set on every call, and some are set > once, when the function is defined, and the choice between the two > happens via "magic" -- the compiler decides what to do, you don't. The /semantics/ are indistinguishable. The implementations are different, and I'll grant that the performance model is more complex for optimized DIC. > I have mixed feelings about compiler optimizations. Things like constant > folding seems to be both harmless and useful, but other optimizations not > so much. It sets up a discrepancy between what the source code does and > what the compiled code does, and in the case of (say) floating point > code, can introduce *serious* bugs. Oooh, careful now. It's important not to muddle semantics-preserving transformations (like memoizing constant immutable objects, as I'm suggesting, or constant folding) and tolerated semantics-altering transformations such as increasing precision of intermediate floating-point values. (`Tolerated' here means that some language specifications grant specific permission for these optimizations despite the fact that they don't preserve semantics.) Semantics-altering optimizations are scary, to be approached only with great trepidation. Semantics-preserving optimizations are nearly free, except for the potentially complicated performance model. > > _missing = ['missing'] > > A curious choice for the sentinel value. We're not using Python 1.5 any > longer :) Two reasons. Firstly, this comes from my Lisp background: making a list is the obvious way of producing an unforgeable object. Secondly, if you see an objects that prints as ['missing'], you have a chance of working out where it came from; for a loose object() that's kind of hard without a wabbit hunter. -- [mdw] From roy at panix.com Sat Nov 6 08:44:38 2010 From: roy at panix.com (Roy Smith) Date: Sat, 06 Nov 2010 08:44:38 -0400 Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> <87aalrjkty.fsf@benfinney.id.au> <8jd3m9Fr55U7@mid.individual.net> Message-ID: In article , Lawrence D'Oliveiro wrote: > In message <8jd3m9Fr55U7 at mid.individual.net>, Neil Cerutti wrote: > > > On 2010-11-03, Ben Finney wrote: > > > >> styles = [ > >> ("normal", "image", MainWindow.ColorsNormalList), > >> ("highlighted", "highlight", MainWindow.ColorsHighlightedList), > >> ("selected", "select", MainWindow.ColorsSelectedList)] > > > > Agreed, except cute stuff like putting those three items in > > columns is just as bad. > > > > Code should be utilitarian rather than ornate, Shaker rather than > > Victorian. > > Tufte???s concept of ???chartjunk??? could perhaps be extended to ???formatjunk??? or > ???prettyprintjunk???. Not at all. Tufte is all about making data easy to understand visually. The chartjunk he rails about is colors, shadows, 3-d effects, etc, which make a chart "look pretty" but don't add to comprehension. If you take out the extra whitespace, you end up with this: > >> styles = [ > >> ("normal", "image", MainWindow.ColorsNormalList), > >> ("highlighted", "highlight", MainWindow.ColorsHighlightedList), > >> ("selected", "select", MainWindow.ColorsSelectedList)] which I think is more difficult to scan visually. In the first example, I can see from the overall layout, without reading a single character of punctuation, that this is a sequence of groups of three items. That's harder to see in the second example. Likewise, if I want to know what kinds of things are in the second field of all the items, it's easy for me to visually scan down the second column in the first example. To do that in the second example is much more difficult. If you want to talk about "codejunk", my biggest concern here is the things in the third column. They all start with "MainWindow.Color", and they all end with "List". Thus, those bits of text add bulk, and no useful information. It would be even more readable by doing: > >> styles = [ > >> ("normal", "image", Normal), > >> ("highlighted", "highlight", Highlighted), > >> ("selected", "select", Selected)] which, of course would require some more code elsewhere to define the new names. Whether this makes sense in the context of the overall codebase is an open question, but taking the table in isolation, it certainly improves the readability. Tufte would approve. From rustompmody at gmail.com Sat Nov 6 08:53:25 2010 From: rustompmody at gmail.com (rustom) Date: Sat, 6 Nov 2010 05:53:25 -0700 (PDT) Subject: Compare source code References: <87fwveej75.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <4533a1d2-2689-45a5-9e96-e4c6f6b8d9d9@p7g2000prb.googlegroups.com> On Nov 6, 5:21?pm, m... at distorted.org.uk (Mark Wooding) wrote: > Rustom Mody writes: > > As for tools' brokeness regarding spaces/tabs/indentation heres a > > thread on the emacs list wherein emacs dev Stefan Monnier admits to > > the fact that emacs' handling in this regard is not perfect. > > >http://groups.google.com/group/gnu.emacs.help/browse_thread/thread/1b... > > You've misunderstood. ?That discussion is about configuring Emacs to not > do automatic indentation when the `tab' key is pressed or when > language-specific punctuation is entered. ?It has very little to do with > tab characters in files. The OP there clearly says he needs help in dealing consistently with 'tabbed' files. Mixing up these 2 issues (actually 3) is the 'Eternal Holy War' that Jamie Zawinski talks about here http://www.jwz.org/doc/tabs-vs-spaces.html Note: I am in no way supporting the demand that python should suddenly get 'braced' beacuse: a. this would do too much violence to the essential -- 'executable- pseudo-code' -- spirit of the language b. Anyway for me personally python and haskell are two of my favorites and one their common features is this: indentation == program structure I am only pointing to the fact that one of the widely used and super- powerful editors is less than perfect in this regard From darragh.ssa at gmail.com Sat Nov 6 09:06:09 2010 From: darragh.ssa at gmail.com (Kruptein) Date: Sat, 6 Nov 2010 06:06:09 -0700 (PDT) Subject: Deditor 0.2.2 Message-ID: Hey, I released version 0.2.2 of my pythonic text-editor Deditor. It adds the use of projects, a project is a set of files which you can open all at once to make development much faster and easier. For more information visit launchpad: http://launchpad.net/deditor I also uploaded a video to introduce you to deditor: http://www.youtube.com/watch?v=hS8xBu-39VI (note: youtube is still processing the file so you might have to wait a bit to see it) From hniksic at xemacs.org Sat Nov 6 09:29:29 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Sat, 06 Nov 2010 14:29:29 +0100 Subject: Silly newbie question - Carrot character (^) References: Message-ID: <87k4kq60na.fsf@xemacs.org> Seebs writes: > I'm a bit lost here. Could you highlight some of the differences > between "a reference manual for the language itself" and "something > written for language lawyers"? I don't speak for "Nobody", but to me a reference manual would be a document intended for the user of the language. The thing for the language lawyer is something intended for the implementor, or possibly for the very advanced user who argues with the implementor about intricacies of behavior. The latter document is also known as the "specification" or the "standard". These two types of document serve different needs and are written for different audience. In Python the choice was made for the library to be written in a reference-manual way, and for the language reference to be written in a specification way. This choice is reasonable, but it can lead to problems when you want to refer a regular user to documentation about the language for educational purposes. From trevor at jcmanagement.net Sat Nov 6 09:38:34 2010 From: trevor at jcmanagement.net (Trevor J. Christensen) Date: Sat, 06 Nov 2010 07:38:34 -0600 Subject: Deditor 0.2.2 In-Reply-To: References: Message-ID: <1289050714.29221.2.camel@linux> I really like that editor! Great work!! Great ideas!! On Sat, 2010-11-06 at 06:06 -0700, Kruptein wrote: > Hey, > > I released version 0.2.2 of my pythonic text-editor Deditor. > It adds the use of projects, a project is a set of files which you can > open all at once to make development much faster and easier. > > For more information visit launchpad: http://launchpad.net/deditor > > I also uploaded a video to introduce you to deditor: > http://www.youtube.com/watch?v=hS8xBu-39VI > (note: youtube is still processing the file so you might have to wait > a bit to see it) From googler.1.webmaster at spamgourmet.com Sat Nov 6 09:54:49 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Sat, 6 Nov 2010 06:54:49 -0700 (PDT) Subject: Get frame object of last called function Message-ID: Hi, is there any chance to get the frame object of the previous called function? I just find the 'f_back' frame object but this is the frame object of the parent function, not the previous one. I try to get the line number of the exit point of the previous function. (0) def Test(): (1) print "OK" (2) return "Foo" p = Test() #get the line number where Test() returned Any ideas? Thanks a lot! Bye, moerchendiser From philip at semanchuk.com Sat Nov 6 10:22:47 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Sat, 6 Nov 2010 10:22:47 -0400 Subject: Silly newbie question - Carrot character (^) In-Reply-To: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> On Nov 6, 2010, at 12:33 AM, Steven D'Aprano wrote: > On Fri, 05 Nov 2010 23:21:11 -0400, Philip Semanchuk wrote: > >> Take the OP's question. How is one supposed to find out about bitwise >> operators in Python? AFAICT they're not mentioned in the tutorial, and >> neither are decorators, assert(), global, exec, the ternary if >> statement, etc. > > The tutorial isn't meant as an exhaustive lesson on every single Python > feature. I agree, and I don't expect otherwise. My point was that if the tutorial doesn't mention a feature, the only other place to learn about it (on python.org) is the language ref. Some people might think the language ref is a fine place to direct newcomers to Python. I don't. It's not awful, but it's dense and unfriendly for those just starting out. > There are plenty of other resources available: learning Python > *starts* with the python.org tutorial (or some equivalent), it doesn't > end there. Yes, I agree. That's what I said in my email too. One goes through the tutorial a few times and then...? There's not a formal document to turn to after that. There are plenty of resources -- books, mailing lists, etc. But they're 3rd party, unstructured, not maintained, etc. I realize that the Python Foundation doesn't have infinite resources to work with, so maybe they'd love to create & maintain a more readable language reference if they had time/money/people. I don't hear anyone talk about it, though. bye Philip From darcy at druid.net Sat Nov 6 10:45:02 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sat, 6 Nov 2010 10:45:02 -0400 Subject: Silly newbie question - Carrot character (^) In-Reply-To: <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> Message-ID: <20101106104502.dd0456bb.darcy@druid.net> On Sat, 6 Nov 2010 10:22:47 -0400 Philip Semanchuk wrote: > > The tutorial isn't meant as an exhaustive lesson on every single Python > > feature. > > I agree, and I don't expect otherwise. My point was that if the > tutorial doesn't mention a feature, the only other place to learn about > it (on python.org) is the language ref. Some people might think the > language ref is a fine place to direct newcomers to Python. I don't. I don't think that anyone was suggesting the reference as the first place to send newcomers. You send them there when they need something beyond the basics. I think the only issue here is that operators are pretty basic and that specific thing is missing in the tutorial. It would be a mistake to write a whole new document because the tutorial is missing one thing. Better would be to propose an operators section. > I realize that the Python Foundation doesn't have infinite resources > to work with, so maybe they'd love to create & maintain a more readable > language reference if they had time/money/people. I don't hear anyone > talk about it, though. Lots of people talk. Action, not so much. How about you? Are you ready to start writing a new reference manual? How about just that one section on operators that's missing from the tutorial. Remember, Python is "we," not "they." -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From gmcduffee at mcduffee-associates.us Sat Nov 6 10:59:06 2010 From: gmcduffee at mcduffee-associates.us (F. George McDuffee) Date: Sat, 06 Nov 2010 08:59:06 -0600 Subject: *** FBI gets a warm welcome in Chicago for their EXCELLENTperformance - cheers to NEW CONS *** References: <26f97f70-9043-490c-9e6e-35159f38d76b@r29g2000yqj.googlegroups.com> <47e0b3a3-54fb-4489-95a8-b5ec6015c99d@j25g2000yqa.googlegroups.com> <6vl1d6lbohrsgg6fucilc0dj235qfs5ak6@4ax.com> Message-ID: On Tue, 02 Nov 2010 20:33:18 -0700, Gunner Asch wrote: >On Tue, 02 Nov 2010 13:58:16 -0700, Rich Grise >wrote: > >>On Tue, 02 Nov 2010 14:17:29 -0700, Gunner Asch wrote: >>> >>> But...shrug..there will be far less after the Great Cull........ >> >>I think some people might be surprised as to exactly _who_ gets "culled". >> >>Good Luck! >>Rich > >Indeed. So stock up, and watch your six. > >Gunner > ========== Here is an article/book you may like. http://www.spiegel.de/international/europe/0,1518,726672,00.html -- Unka George (George McDuffee) .............................. The past is a foreign country; they do things differently there. L. P. Hartley (1895-1972), British author. The Go-Between, Prologue (1953). From tavares at fe.up.pt Sat Nov 6 11:30:03 2010 From: tavares at fe.up.pt (tavares at fe.up.pt) Date: Sat, 6 Nov 2010 08:30:03 -0700 (PDT) Subject: =?windows-1252?Q?Symposium_=93Image_Processing_and_Analysis_in_Biomed?= =?windows-1252?Q?ical_Engineering=94_within_CompBioMed_2011_=96_Announce_=26_Ca?= =?windows-1252?Q?ll?= Message-ID: Dear Colleague, Within the 2nd International Conference on Computational & Mathematical Biomedical Engineering (CompBioMed 2011), to be held in Washington D.C., USA, in 30th March - 1st April 2011 (www.compbiomed.net), we are organizing the Symposium ?Image Processing and Analysis in Biomedical Engineering?. The main goal of this symposium is to bring together researchers involved in the related fields (image acquisition, signal processing, image processing and analysis, medical imaging, scientific visualization, software development, grid computing, etc.), in order to set the major lines of development for the near future. Therefore, this symposium will consist of researchers representing various fields related to computational vision, computer graphics, computational mechanics, mathematics, statistics, medical imaging, biomedicine, bioengineering, etc. Thus, it endeavours to make a contribution to achieving better solutions for more realistic computational ?living? models from images, and attempts to establish a bridge between clinicians, researchers and hardware manufacturers from these diverse fields. Due to your research activities in those fields, we would like to invite you to submit your work and participate in the Symposium ?Image Processing and Analysis in Biomedical Engineering?. Topics (not limited to): - Image Processing and Analysis for Biomedical Images; - Segmentation, Reconstruction, Tracking and Motion Analyse in Biomedical Images; - Biomedical Signal and Image Acquisition and Processing; - Objects Simulation and Virtual Reality for Biomedicine; - Computer Aided Diagnosis, Surgery, Therapy, Treatment and Telemedicine Systems; - Software Development for Biomedical Images; - Grid and High Performance Computing for Biomedical Images. Instructions and Submission: - For instructions and submission, please access to the conference website at: www.compbiomed.net - Please note that, when submitting your work you should select the Symposium ?Image Processing and Analysis in Biomedical Engineering?. Important dates: - Four page abstract submission - expression of interest: 15 November 2010; - Notification of acceptance: 01 December 2010; - Final camara ready abstract submission deadline: 15 January 2011. Kind regards, Jo?o Manuel R. S. Tavares (University of Porto, Portugal, tavares at fe.up.pt) Renato Natal Jorge (University of Porto, Portugal, rnatal at fe.up.pt) Yongjie Zhang (Carnegie Mellon University, USA, jessicaz at andrew.cmu.edu) (Symposium organizers) From arnodel at gmail.com Sat Nov 6 11:45:18 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Sat, 06 Nov 2010 15:45:18 +0000 Subject: Split iterator into multiple streams References: <4cd5173d$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87zktmihgx.fsf@gmail.com> Steven D'Aprano writes: > Suppose I have an iterator that yields tuples of N items (a, b, ... n). > > I want to split this into N independent iterators: > > iter1 -> a, a2, a3, ... > iter2 -> b, b2, b3, ... > ... > iterN -> n, n2, n3, ... > > The iterator may be infinite, or at least too big to collect in a list. > > My first attempt was this: > > > def split(iterable, n): > iterators = [] > for i, iterator in enumerate(itertools.tee(iterable, n)): > iterators.append((t[i] for t in iterator)) > return tuple(iterators) > > But it doesn't work, as all the iterators see the same values: > >>>> data = [(1,2,3), (4,5,6), (7,8,9)] >>>> a, b, c = split(data, 3) >>>> list(a), list(b), list(c) > ([3, 6, 9], [3, 6, 9], [3, 6, 9]) > > > I tried changing the t[i] to use operator.itergetter instead, but no > luck. Finally I got this: > > def split(iterable, n): > iterators = [] > for i, iterator in enumerate(itertools.tee(iterable, n)): > f = lambda it, i=i: (t[i] for t in it) > iterators.append(f(iterator)) > return tuple(iterators) > > which seems to work: > >>>> data = [(1,2,3), (4,5,6), (7,8,9)] >>>> a, b, c = split(data, 3) >>>> list(a), list(b), list(c) > ([1, 4, 7], [2, 5, 8], [3, 6, 9]) > > > > > Is this the right approach, or have I missed something obvious? It is quite straightforward to implement your "split" function without itertools.tee: from collections import deque def split(iterable): it = iter(iterable) q = [deque([x]) for x in it.next()] def proj(qi): while True: if not qi: for qj, xj in zip(q, it.next()): qj.append(xj) yield qi.popleft() for qi in q: yield proj(qi) >>> data = [(1,2,3), (4,5,6), (7,8,9)] >>> a, b, c = split(data) >>> print list(a), list(b), list(c) [1, 4, 7] [2, 5, 8] [3, 6, 9] Interestingly, given "split" it is very easy to implement "tee": def tee(iterable, n=2): return split(([x]*n for x in iterable)) >>> a, b = tee(range(10), 2) >>> a.next(), a.next(), b.next() (0, 1, 0) >>> a.next(), a.next(), b.next() (2, 3, 1) In fact, split(x) is the same as zip(*x) when x is finite. The difference is that with split(x), x is allowed to be infinite and with zip(*x), each term of x is allowed to be infinite. It may be good to have a function unifying the two. -- Arnaud From robert.kern at gmail.com Sat Nov 6 13:38:03 2010 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 06 Nov 2010 12:38:03 -0500 Subject: ANN: PyQt v4.8.1 Released In-Reply-To: References: Message-ID: On 11/6/10 2:34 AM, Steve Holden wrote: > On 11/5/2010 6:14 PM, Lawrence D'Oliveiro wrote: >> In message, ?????? ??????????? >> wrote: >> >>>>> PyQt is available under the GPL and a commercial license. >>>> >>>> Surely you mean ?proprietary? rather than ?commercial?. There is >>>> nothing about the GPL that prevents ?commercial? use. >>> >>> I think he means a license that *he* sells comercially :) >> >> Presumably that?s a proprietary licence. > > I don't see why. GPL v2, for example, has nothing to say about the price > charged for the software: simply that the source must be made available. Given the context, "PyQt is available under the GPL and a commercial license," the commercial license Phil is talking about is not the GPL. -- 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 usenet-nospam at seebs.net Sat Nov 6 13:48:46 2010 From: usenet-nospam at seebs.net (Seebs) Date: 06 Nov 2010 17:48:46 GMT Subject: Silly newbie question - Carrot character (^) References: <87k4kq60na.fsf@xemacs.org> Message-ID: On 2010-11-06, Hrvoje Niksic wrote: > I don't speak for "Nobody", but to me a reference manual would be a > document intended for the user of the language. The thing for the > language lawyer is something intended for the implementor, or possibly > for the very advanced user who argues with the implementor about > intricacies of behavior. The latter document is also known as the > "specification" or the "standard". I guess I would think that if such a document cannot be used as a reference, it's not very well done. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From xrgtn at yandex.ru Sat Nov 6 13:51:06 2010 From: xrgtn at yandex.ru (Alexander Gattin) Date: Sat, 6 Nov 2010 19:51:06 +0200 Subject: How find all childrens values of a nested dictionary, fast! In-Reply-To: <87d3qkkcqj.fsf@gmail.com> References: <87d3qkkcqj.fsf@gmail.com> Message-ID: <20101106175106.GB20690@xrgtn-q40> Hello, On Thu, Nov 04, 2010 at 09:20:04PM +0000, Arnaud Delobelle wrote: > Tough requirement, but I think I've got it. Two > lambdas, one reduce, one map ;) > > >>> a = {'a' : {'b' :{'/' :[1,2,3,4], 'ba' :{'/' :[41,42,44]}, 'bc' :{'/':[51,52,54], 'bcd' :{'/':[68,69,66]}}},'c' :{'/' :[5,6,7,8]}},'ab' : {'/' :[12,13,14,15]}, 'ac' :{'/' :[21,22,23]}} > >>> f = lambda v,k=None: v if k=="/" else reduce(list.__add__, map(lambda k: f(v[k],k), v), []) Is it that new Python3 thing? :) P.S. Here is my variant that still works in python2: def i(x): r = [] for k, v in x.iteritems(): try: r.extend(i(v)) except: if k == '/': r.extend(v) return r -- With best regards, xrgtn From jon.dufresne at gmail.com Sat Nov 6 14:22:08 2010 From: jon.dufresne at gmail.com (Jon Dufresne) Date: Sat, 6 Nov 2010 11:22:08 -0700 Subject: How to test if a module exists? Message-ID: Hi, My python program has an extension system where the extension can have a optional magic python modules. Meaning if the extension module exists, the program will use it and if not, it will continue without the module. So my program tests if a module exists, if so use it, otherwise continue. This is how I originally did this (pseudo code): try: import extension_magic_module except ImportError: pass else: handle_extension_magic_module() However, if the the extension module exists but throws an ImportError, due to a bug in the extension this idiom will mask the error and I will never see it. Later on in the program I will get unexpected behavior because the module never successfully imported. I want the program to fail if the extension module fails to import, but continue if the module doesn't exist. Is there a correct way to handle this? Jon From clp2 at rebertia.com Sat Nov 6 14:35:26 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 6 Nov 2010 11:35:26 -0700 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: On Sat, Nov 6, 2010 at 11:22 AM, Jon Dufresne wrote: > Hi, > > My python program has an extension system where the extension can have > a optional magic python modules. Meaning if the extension module > exists, the program will use it and if not, it will continue without > the module. So my program tests if a module exists, if so use it, > otherwise continue. This is how I originally did this (pseudo code): > > > try: > ? ?import extension_magic_module > except ImportError: > ? ?pass > else: > ? ?handle_extension_magic_module() > > > However, if the the extension module exists but throws an ImportError, > due to a bug in the extension this idiom will mask the error and I > will never see it. Later on in the program I will get unexpected > behavior because the module never successfully imported. I want the > program to fail if the extension module fails to import, but continue > if the module doesn't exist. Is there a correct way to handle this? Here's what I came up with: try: ? ?import extension_magic_module except ImportError as err: if err.message != "No module named extension_magic_module": raise err else: handle_extension_magic_module() Cheers, Chris -- http://blog.rebertia.com From nad at acm.org Sat Nov 6 14:38:49 2010 From: nad at acm.org (Ned Deily) Date: Sat, 06 Nov 2010 11:38:49 -0700 Subject: Silly newbie question - Carrot character (^) References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> Message-ID: In article <11A0F261-1BF4-4C35-83FA-C47BF968D150 at semanchuk.com>, Philip Semanchuk wrote: > On Nov 6, 2010, at 12:33 AM, Steven D'Aprano wrote: > > On Fri, 05 Nov 2010 23:21:11 -0400, Philip Semanchuk wrote: > > > >> Take the OP's question. How is one supposed to find out about bitwise > >> operators in Python? AFAICT they're not mentioned in the tutorial, and > >> neither are decorators, assert(), global, exec, the ternary if > >> statement, etc. > > > > The tutorial isn't meant as an exhaustive lesson on every single Python > > feature. > > I agree, and I don't expect otherwise. My point was that if the tutorial > doesn't mention a feature, the only other place to learn about it (on > python.org) is the language ref. Some people might think the language ref is > a fine place to direct newcomers to Python. I don't. It's not awful, but it's > dense and unfriendly for those just starting out. In the Python documentation set, the language reference should usually be the second place to send someone. The first place is The Python Standard Library manual where built-in types and the methods supported by them are documented. For bit string operations: http://docs.python.org/library/stdtypes.html#bit-string-operations-on-int eger-types -- Ned Deily, nad at acm.org From jon.dufresne at gmail.com Sat Nov 6 14:50:35 2010 From: jon.dufresne at gmail.com (Jon Dufresne) Date: Sat, 6 Nov 2010 11:50:35 -0700 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: On Sat, Nov 6, 2010 at 11:35 AM, Chris Rebert wrote: > Here's what I came up with: > > try: > ?? ?import extension_magic_module > except ImportError as err: > ? ?if err.message != "No module named extension_magic_module": > ? ? ? ?raise err > else: > ? ?handle_extension_magic_module() > It seems less than ideal to tie my program's behavior to what essentially boils down to a documentation string. Is this the preferred way to handle this? Jon From gunnerasch at gmail.com Sat Nov 6 15:37:54 2010 From: gunnerasch at gmail.com (Gunner Asch) Date: Sat, 06 Nov 2010 12:37:54 -0700 Subject: *** FBI gets a warm welcome in Chicago for their EXCELLENTperformance - cheers to NEW CONS *** References: <26f97f70-9043-490c-9e6e-35159f38d76b@r29g2000yqj.googlegroups.com> <47e0b3a3-54fb-4489-95a8-b5ec6015c99d@j25g2000yqa.googlegroups.com> <6vl1d6lbohrsgg6fucilc0dj235qfs5ak6@4ax.com> Message-ID: On Sat, 06 Nov 2010 08:59:06 -0600, F. George McDuffee wrote: >On Tue, 02 Nov 2010 20:33:18 -0700, Gunner Asch > wrote: > >>On Tue, 02 Nov 2010 13:58:16 -0700, Rich Grise >>wrote: >> >>>On Tue, 02 Nov 2010 14:17:29 -0700, Gunner Asch wrote: >>>> >>>> But...shrug..there will be far less after the Great Cull........ >>> >>>I think some people might be surprised as to exactly _who_ gets "culled". >>> >>>Good Luck! >>>Rich >> >>Indeed. So stock up, and watch your six. >> >>Gunner >> >========== >Here is an article/book you may like. >http://www.spiegel.de/international/europe/0,1518,726672,00.html Like...no. Will have to read...yes. Danke Gunner > > >-- Unka George (George McDuffee) >.............................. >The past is a foreign country; >they do things differently there. >L. P. Hartley (1895-1972), British author. >The Go-Between, Prologue (1953). -- "Confiscating wealth from those who have earned it, inherited it, or got lucky is never going to help 'the poor.' Poverty isn't caused by some people having more money than others, just as obesity isn't caused by McDonald's serving super-sized orders of French fries Poverty, like obesity, is caused by the life choices that dictate results." - John Tucci, From mdw at distorted.org.uk Sat Nov 6 15:57:06 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Sat, 06 Nov 2010 19:57:06 +0000 Subject: functions, list, default parameters References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <20101021235138.609fe668@geekmail.INVALID> <87pquk3ehs.fsf.mdw@metalzone.distorted.org.uk> <4cd3c72b$0$30004$c3e8da3$5496439d@news.astraweb.com> <8739rg2ceb.fsf.mdw@metalzone.distorted.org.uk> <4cd4cc74$0$30004$c3e8da3$5496439d@news.astraweb.com> <87bp62eig9.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <87y696cjjh.fsf.mdw@metalzone.distorted.org.uk> Dennis Lee Bieber writes: > On Sat, 06 Nov 2010 12:37:42 +0000, mdw at distorted.org.uk (Mark Wooding) > declaimed the following in gmane.comp.python.general: > > > > > Two reasons. Firstly, this comes from my Lisp background: making a > > list is the obvious way of producing an unforgeable object. > > Secondly, if you see an objects that prints as ['missing'], you have > > a chance of working out where it came from; for a loose object() > > that's kind of hard without a wabbit hunter. > > > I think the Python form is to create a basic class instance, a la > > >>> class Sentinal(object): > ... pass > ... > >>> _missing = Sentinal() > >>> print _missing > <__main__.Sentinal object at 0x011F01B0> No, that doesn't tell me where it came from at all. Given a thingy that prints like that, I still need a wabbit hunter to tell me what /this/ particular sentinel value means. > Or, if one wants to get fancier (maybe stuff the class definition > into some common package) > > > >>> class Sentinal(object): > ... def __init__(self, text): > ... self.text = text > ... def __str__(self): > ... return "%s : %s" % (repr(self), self.text) > ... > >>> _missing = Sentinal("Missing Items") > >>> print _missing > <__main__.Sentinal object at 0x0120D070> : Missing Items And the advantage of all of this typing over ['missing'] is what, precisely? If I want to write Java, I know where to look; I don't. -- [mdw] From rtw at rtw.me.uk Sat Nov 6 15:59:46 2010 From: rtw at rtw.me.uk (Rob Williscroft) Date: Sat, 6 Nov 2010 19:59:46 +0000 (UTC) Subject: How to test if a module exists? References: Message-ID: Jon Dufresne wrote in news:AANLkTikr5euHQPupA3yRid98OaS92ZFHK8U9Lha5YVrv at mail.gmail.com in gmane.comp.python.general: > try: > import extension_magic_module > except ImportError: > pass > else: > handle_extension_magic_module() > > > However, if the the extension module exists but throws an ImportError, > due to a bug in the extension this idiom will mask the error and I > will never see it. import imp try: m = imp.find_module( "test_1" ) if m[0]: m[0].close() except ImportError: pass else: import test_1 http://docs.python.org/library/imp.html#imp.find_module Rob. From mdw at distorted.org.uk Sat Nov 6 16:01:17 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Sat, 06 Nov 2010 20:01:17 +0000 Subject: How to test if a module exists? References: Message-ID: <87r5eycjci.fsf.mdw@metalzone.distorted.org.uk> Chris Rebert writes: > if err.message != "No module named extension_magic_module": Ugh! Surely this can break if you use Python with different locale settings! -- [mdw] From rantingrick at gmail.com Sat Nov 6 16:41:33 2010 From: rantingrick at gmail.com (rantingrick) Date: Sat, 6 Nov 2010 13:41:33 -0700 (PDT) Subject: Silly newbie question - Carrot character (^) References: Message-ID: On Nov 5, 5:51?pm, Seebs wrote: > On 2010-11-05, Nobody wrote: > > > However, it's still written for language lawyers. > > IMHO, the lack of a reference manual for the language itself is a major > > hole in Python's documentation. > > I'm a bit lost here. ?Could you highlight some of the differences > between "a reference manual for the language itself" and "something > written for language lawyers"? In a word HUMOR! Obviously the commentator who has a lack of the hidden meaning of "language lawyers" has no sense of humor -- sadly another lost virtue of the French! From usenet-nospam at seebs.net Sat Nov 6 16:42:43 2010 From: usenet-nospam at seebs.net (Seebs) Date: 06 Nov 2010 20:42:43 GMT Subject: Silly newbie question - Carrot character (^) References: Message-ID: On 2010-11-06, rantingrick wrote: > On Nov 5, 5:51?pm, Seebs wrote: >> I'm a bit lost here. ?Could you highlight some of the differences >> between "a reference manual for the language itself" and "something >> written for language lawyers"? > In a word HUMOR! Huh? > Obviously the commentator who has a lack of the > hidden meaning of "language lawyers" has no sense of humor -- sadly > another lost virtue of the French! It is a shame that there was a guy standing behind you with a gun preventing you from explaining what the alleged hidden meaning was, so all you could do is allude to it without explaining it. Maybe later you can get away from your captors and post an explanation of what the "hidden meaning" is, in your eyes? -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From steve at holdenweb.com Sat Nov 6 16:52:17 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 06 Nov 2010 16:52:17 -0400 Subject: Silly newbie question - Carrot character (^) In-Reply-To: <20101106104502.dd0456bb.darcy@druid.net> References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> <20101106104502.dd0456bb.darcy@druid.net> Message-ID: <4CD5C001.9000202@holdenweb.com> On 11/6/2010 10:45 AM, D'Arcy J.M. Cain wrote: >> I realize that the Python Foundation doesn't have infinite resources >> > to work with, so maybe they'd love to create & maintain a more readable >> > language reference if they had time/money/people. I don't hear anyone >> > talk about it, though. While that isn't a current priority it certainly seems like a worthy goal to me. But the Python Software Foundation is people, and we certainly don't have the resources to simply enter into a contract with an organization to produce "a more readable language reference" - whether those resources are time, money or people (which can tend to become indistinguishable when planning is underway). We would love for Python's documentation to be even better, but the last major change in the documentation (the dropping of LATEX as the source language and the switch to Sphinx) was largely a result of one person (Georg Brandl) scratching an itch. Maybe a more readable language reference will come about the same way ... > Lots of people talk. Action, not so much. How about you? Are you > ready to start writing a new reference manual? How about just that one > section on operators that's missing from the tutorial. > That ought to be quite a manageable project. > Remember, Python is "we," not "they." > Quite. having-no-wish-to-be-they-ly - steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From roy at panix.com Sat Nov 6 16:52:35 2010 From: roy at panix.com (Roy Smith) Date: Sat, 06 Nov 2010 16:52:35 -0400 Subject: How to test if a module exists? References: Message-ID: In article , Chris Rebert wrote: > On Sat, Nov 6, 2010 at 11:22 AM, Jon Dufresne wrote: [...] > > However, if the the extension module exists but throws an ImportError, > > due to a bug in the extension this idiom will mask the error and I > > will never see it. Later on in the program I will get unexpected > > behavior because the module never successfully imported. I want the > > program to fail if the extension module fails to import, but continue > > if the module doesn't exist. Is there a correct way to handle this? > > Here's what I came up with: > > try: > ?? ??import extension_magic_module > except ImportError as err: > if err.message != "No module named extension_magic_module": > raise err > else: > handle_extension_magic_module() As Mark Wooding pointed out in another post, relying on the text of the exception message is a bad idea. It seems to me that if your module has a bug in it, it's likely to throw something other than ImportError, so catching ImportError is probably good enough. On the other hand, if your module's bug is that it in turn imports some other module, which doesn't exist, you'll also get an ImportError. It sounds like what you want to do is differentiate between ImportError thrown at the top level, and ImportError thrown somewhere deeper in the stack. The best way I can see to do that is to catch ImportError and look to see how long the chain of tb_next references is in sys.exc_traceback. If sys.exc_traceback.tb_next is None, the exception was thrown at the top level (and your magic module doesn't exist). Here's a rough example to illustrate what I'm talking about: import sys try: import xx except ImportError: tb = sys.exc_traceback while tb: print tb tb = tb.tb_next It's a little funky, but I think the concept is sound, and it should be portable. From clp2 at rebertia.com Sat Nov 6 16:54:09 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 6 Nov 2010 13:54:09 -0700 Subject: How to test if a module exists? In-Reply-To: <87r5eycjci.fsf.mdw@metalzone.distorted.org.uk> References: <87r5eycjci.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On Sat, Nov 6, 2010 at 1:01 PM, Mark Wooding wrote: > Chris Rebert writes: > >> ? ? if err.message != "No module named extension_magic_module": > > Ugh! ?Surely this can break if you use Python with different locale > settings! Since when does Python have translated error messages? Cheers, Chris From clp2 at rebertia.com Sat Nov 6 17:09:18 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 6 Nov 2010 14:09:18 -0700 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: On Sat, Nov 6, 2010 at 11:50 AM, Jon Dufresne wrote: > On Sat, Nov 6, 2010 at 11:35 AM, Chris Rebert wrote: >> Here's what I came up with: >> >> try: >> ?? ?import extension_magic_module >> except ImportError as err: >> ? ?if err.message != "No module named extension_magic_module": >> ? ? ? ?raise err >> else: >> ? ?handle_extension_magic_module() >> > > It seems less than ideal to tie my program's behavior to what > essentially boils down to a documentation string. Yeah, personally I was surprised and annoyed that the module name wasn't available by itself as some attribute of the ImportError (e.g. err.module_name); that would have lent itself to a very elegant solution to your problem. Cheers, Chris From mdw at distorted.org.uk Sat Nov 6 18:33:15 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Sat, 06 Nov 2010 22:33:15 +0000 Subject: How to test if a module exists? References: <87r5eycjci.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <877hgqccb8.fsf.mdw@metalzone.distorted.org.uk> Chris Rebert writes: > Since when does Python have translated error messages? It doesn't yet. How much are you willing to bet that it never will? ;-) -- [mdw] From steve at REMOVE-THIS-cybersource.com.au Sat Nov 6 18:37:23 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Nov 2010 22:37:23 GMT Subject: How to test if a module exists? References: <87r5eycjci.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <4cd5d8a3$0$30004$c3e8da3$5496439d@news.astraweb.com> On Sat, 06 Nov 2010 13:54:09 -0700, Chris Rebert wrote: > On Sat, Nov 6, 2010 at 1:01 PM, Mark Wooding > wrote: >> Chris Rebert writes: >> >>> ? ? if err.message != "No module named extension_magic_module": >> >> Ugh! ?Surely this can break if you use Python with different locale >> settings! > > Since when does Python have translated error messages? Since Python 3.2.4. Or will it be 3.3.5? I will forget. *wink* The point is that Python makes no promises about the error messages. The OP might be using a localised version, or some implementation that's not CPython, or the next version of Python might change the error message. Hell, a user should be able to hack their personal copy of Python and customize the error strings without having to fear that code will break. -- Steven From roy at panix.com Sat Nov 6 18:48:46 2010 From: roy at panix.com (Roy Smith) Date: Sat, 06 Nov 2010 18:48:46 -0400 Subject: How to test if a module exists? References: <87r5eycjci.fsf.mdw@metalzone.distorted.org.uk> <4cd5d8a3$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <4cd5d8a3$0$30004$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > > Since when does Python have translated error messages? > > Since Python 3.2.4. Or will it be 3.3.5? I will forget. > > *wink* from __future__ import bugs :-) From timr at probo.com Sat Nov 6 18:53:48 2010 From: timr at probo.com (Tim Roberts) Date: Sat, 06 Nov 2010 15:53:48 -0700 Subject: execute shell script from python, needs sys.argv References: Message-ID: <1vmbd65uaj2snq1v0vo49ktn0lsc2o5m1a@4ax.com> Benjamin Kaplan wrote: > >Python is not the shell. Shell commands are not python commands. You >need either a string or a list of strings, so any literal have to be >in quotes. Also, subprocess can't handle the redirection. You need to >run it as two commands. > >proc1 = subprocess.Popen(["cat", sys.argv[1]],stdout = >subprocess.PIPE, shell = True) >proc2 = subprocess.Popen(["fastx_trimmer", "-n", "COUNT", "-o", >sys.argv[2]],stdin=proc1.stdout, shell=True) I KNOW that we're still working on syntax here, and that it's too early for optimization, but it bothers me to see "cat" as the first thing in a pipeline. You don't actually need two steps here at all: proc1 = subprocess.Popen( ["fastx_trimmer", "-n", "COUNT", "-o", sys.argv[2], stdin=open(sys.argv[1]), shell=True ) With this, I don't think you even need "shell=True". -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From steve at REMOVE-THIS-cybersource.com.au Sat Nov 6 19:07:52 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Nov 2010 23:07:52 GMT Subject: functions, list, default parameters References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <20101021235138.609fe668@geekmail.INVALID> <87pquk3ehs.fsf.mdw@metalzone.distorted.org.uk> <4cd3c72b$0$30004$c3e8da3$5496439d@news.astraweb.com> <8739rg2ceb.fsf.mdw@metalzone.distorted.org.uk> <4cd4cc74$0$30004$c3e8da3$5496439d@news.astraweb.com> <87bp62eig9.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <4cd5dfc8$0$30004$c3e8da3$5496439d@news.astraweb.com> On Sat, 06 Nov 2010 12:37:42 +0000, Mark Wooding wrote: >> > _missing = ['missing'] >> >> A curious choice for the sentinel value. We're not using Python 1.5 any >> longer > > Two reasons. Firstly, this comes from my Lisp background: making a list > is the obvious way of producing an unforgeable object. Secondly, if you > see an objects that prints as ['missing'], you have a chance of working > out where it came from; for a loose object() that's kind of hard without > a wabbit hunter. But surely you shouldn't expect to only have the repr() of the value to go by. You'll have a traceback, which shows you not just that you have a sentinel, but where it ended up. It seems silly to me to fear seeing a bare object() more than all the other objects that give no context as to where they come from. If you see None, or [], or 1, out of context, you're going to have trouble working out what it's used for too. At least object() is rare -- it shouldn't be hard to do a search through the source code to find where it is created and from there find out where it is used. To me, the idiom x = object() says "missing value" MORE strongly than the Lisp-ism x = ['missing']. After all, x = object() has no state, and no methods to speak of, what else could it be other than a sentinel? But ['missing'] has state, it's mutable, it has methods up the whazoo. If you fear your code will expose it to the caller, why don't you fear that your code will mutate it to ['found now'], or something equally confounding? The problem with the Lisp-ism is that the object ['missing'] could have many uses and could be modified. Without context, I'd be wondering whether I'd stumbled across a really short list of gerunds ("the missing kettle") or verbs. If you're writing code that does a lot of text processing, that won't be an outlandish thought. If I had a lot of sentinels in the one module and for some bizarre reason couldn't re-use them, and so needed many different unique sentinels that needed to be distinguished, then I'd probably lean towards using ['the'] ['Lisp'] ['idiom']. But for just one, I stick with my claim that object() says "missing" more strongly than ['missing'], strange as it may seem :) -- Steven From nobody at nowhere.com Sat Nov 6 19:19:18 2010 From: nobody at nowhere.com (Nobody) Date: Sat, 06 Nov 2010 23:19:18 +0000 Subject: Silly newbie question - Carrot character (^) References: Message-ID: On Fri, 05 Nov 2010 22:51:10 +0000, Seebs wrote: >> IMHO, the lack of a reference manual for the language itself is a major >> hole in Python's documentation. > > I'm a bit lost here. Could you highlight some of the differences between > "a reference manual for the language itself" and "something written for > language lawyers"? A reference manual tells you how to use the language. A specification tells you how to implement it. It's possible to /deduce/ how to use the language from a specification, but it could take significant time and effort. A specification is typically designed to be read in its entirety, and may yield little usable information until you've read a substantial portion of it. A reference manual is structured such that you can easily locate the portion which is necessary for the task immediately to hand, and only need to read that portion. OTOH, a tutorial typically isn't exhaustive. And even if it is, the information related to a topic may be scattered throughout multiple sections, making it hard to find a specific piece of information. E.g. the syntax of expressions adheres rather rigidly to the grammar used for parsing, which is fine for a specification, but not how a reference manual would normally be written. From steve at REMOVE-THIS-cybersource.com.au Sat Nov 6 20:06:25 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 07 Nov 2010 00:06:25 GMT Subject: Silly newbie question - Carrot character (^) References: Message-ID: <4cd5ed80$0$30004$c3e8da3$5496439d@news.astraweb.com> On Sat, 06 Nov 2010 23:19:18 +0000, Nobody wrote: > On Fri, 05 Nov 2010 22:51:10 +0000, Seebs wrote: > >>> IMHO, the lack of a reference manual for the language itself is a >>> major hole in Python's documentation. >> >> I'm a bit lost here. Could you highlight some of the differences >> between "a reference manual for the language itself" and "something >> written for language lawyers"? > > A reference manual tells you how to use the language. A specification > tells you how to implement it. Surely a tutorial tells you *how* to use the language. I wouldn't expect a reference manual to teach me how to run and edit programs -- the *how* of using the language. And a specification ("for language lawyers") tells you *what* to implement, not how. E.g. a specification should tell you that the language needs a sorted() function, what arguments it takes, and what it should do. It should not tell you how to implement it (Quicksort or Timsort? Sort pointers to items or an array of items? External sort or in- memory sort?). Any instructions on how to implement the language will depend on what language you're implementing it in. An implementers guide written for C programmers will be very different from one written for Lisp or Forth or Haskell programmers. > It's possible to /deduce/ how to use the language from a specification, > but it could take significant time and effort. I think you're looking for hard distinctions that simply doesn't exist. By it's very nature, documentation of all types falls into a continuum of overlapping fuzzy sets. But to the extent that the terms have any specific meaning, a reference manual and something for the language lawyers (a specification) are the same thing. Different specific reference manuals may be aimed at different levels of sophistication, more or less successfully, but arguments about categories are pointless since we're rarely going to agree on the definition of the categories. If you want to argue that the Python reference manual is aimed at the wrong level of sophistication, specifically that the BNF syntax stuff should be ripped out into another document, then I might agree with you. But to argue that it's entirely the wrong "kind" of thing is, in my opinion, unjustified. -- Steven From usenet-nospam at seebs.net Sat Nov 6 20:34:55 2010 From: usenet-nospam at seebs.net (Seebs) Date: 07 Nov 2010 00:34:55 GMT Subject: How to test if a module exists? References: <87r5eycjci.fsf.mdw@metalzone.distorted.org.uk> <4cd5d8a3$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-06, Roy Smith wrote: > from __future__ import bugs Now I want this. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From mdw at distorted.org.uk Sat Nov 6 20:48:31 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Sun, 07 Nov 2010 00:48:31 +0000 Subject: Silly newbie question - Carrot character (^) References: <4cd5ed80$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87sjzearhc.fsf.mdw@metalzone.distorted.org.uk> Steven D'Aprano writes: > If you want to argue that the Python reference manual is aimed at the > wrong level of sophistication, specifically that the BNF syntax stuff > should be ripped out into another document, then I might agree with > you. But to argue that it's entirely the wrong "kind" of thing is, in > my opinion, unjustified. I certainly wouldn't agree with that. The language's syntax is essential part of the language, and must be described clearly and unambiguously. Formal grammars aren't especially hard to understand, and they're pretty much everywhere, so learning how to read them is an essential skill anyway. To be honest, I reckon the Python language reference is too friendly and fluffy. The manual for F#, say, is a harder read. The Standard ML language reference is a book full of mathematical notation (inference rules for operational semantics, mainly) and little else. The Scheme language used to be described by a page or so of equations giving a translation into lambda calculus (but now that's operational semantics too) -- oh, there are prose descriptions too, but they're not easy going either in places, and the formal semantics are necessary to clear up some of the details. You Python people have it easy. -- [mdw] From usenet-nospam at seebs.net Sat Nov 6 21:05:56 2010 From: usenet-nospam at seebs.net (Seebs) Date: 07 Nov 2010 01:05:56 GMT Subject: Silly newbie question - Carrot character (^) References: <4cd5ed80$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-07, Steven D'Aprano wrote: > Surely a tutorial tells you *how* to use the language. I wouldn't expect > a reference manual to teach me how to run and edit programs -- the *how* > of using the language. There's a sort of fuzzy boundary about how the term "reference manual" is used. Some people view it more in terms of presenting, for each major feature or class of functionality, an overview of what you need to know to use it, which may not be everything you need to know to implement it correctly. Consider: In Python, indentation determines control flow. Statements which take a block of code must be followed by at least one line of a greater indentation level; all following lines of that indentation level are part of the block, ending at the first line which is less indented than the block. Each block should be indented by four spaces from the preceeding block, and tabs should not be used. That might be quite suitable* for a "reference manual" as many people use the term, but would be useless for a language lawyer. A language lawyer needs to know that " \t" at the beginning of a line is construed to be the same indentation level as " " or "\t". A typical reference manual might simply ignore that information because it's telling you what you need to write good code, not what you need to know to write a compatible implementation. That said... I am certainly biased on the issue, but IMHO a reference manual should not "gloss over" things like that, but should be at least as detailed as a formal specification; where it might differ is in *additional* material with explanations and clarifications. YMMV. -s [*] Well, imagine that, only written better and properly edited, and so on. -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From hniksic at xemacs.org Sat Nov 6 21:17:25 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Sun, 07 Nov 2010 02:17:25 +0100 Subject: Silly newbie question - Carrot character (^) References: <87k4kq60na.fsf@xemacs.org> Message-ID: <87fwve53ve.fsf@xemacs.org> Seebs writes: > On 2010-11-06, Hrvoje Niksic wrote: >> I don't speak for "Nobody", but to me a reference manual would be a >> document intended for the user of the language. The thing for the >> language lawyer is something intended for the implementor, or possibly >> for the very advanced user who argues with the implementor about >> intricacies of behavior. The latter document is also known as the >> "specification" or the "standard". > > I guess I would think that if such a document cannot be used as a > reference, it's not very well done. It's not a matter of quality, but of intended audience. To most ordinary programmers the standards documents such as the C standard, the C++ standard, or the Python reference are quite dense and hard to use as a reference, and yet they are considered quite well done. From ldo at geek-central.gen.new_zealand Sat Nov 6 21:51:01 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 07 Nov 2010 14:51:01 +1300 Subject: ANN: PyQt v4.8.1 Released References: Message-ID: In message , Robert Kern wrote: > On 11/6/10 2:34 AM, Steve Holden wrote: > >> On 11/5/2010 6:14 PM, Lawrence D'Oliveiro wrote: >> >>> In message, ?????? >>> ??????????? wrote: >>> >>>>>> PyQt is available under the GPL and a commercial license. >>>>> >>>>> Surely you mean ?proprietary? rather than ?commercial?. There is >>>>> nothing about the GPL that prevents ?commercial? use. >>>> >>>> I think he means a license that *he* sells comercially :) >>> >>> Presumably that?s a proprietary licence. >> >> I don't see why. GPL v2, for example, has nothing to say about the price >> charged for the software: simply that the source must be made available. > > Given the context, "PyQt is available under the GPL and a commercial > license," the commercial license Phil is talking about is not the GPL. Which is a wrong interpretation of ?commercial?. From ldo at geek-central.gen.new_zealand Sat Nov 6 21:53:45 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 07 Nov 2010 14:53:45 +1300 Subject: Compare source code References: <4cd4c6cf$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: In message , Seebs wrote: > Specifically: > > Four spaces followed by a tab nearly always actually means "eight spaces" > to most editors (and Python seems to treat it that way), but it's hard to > tell. Worse, a tab may have been intended to be the same thing as four > spaces, and someone was expecting it NOT to be the same as eight spaces... Whereas explicitly-bracketed languages leave no ambiguity about how many brackets you need and where. From jon.dufresne at gmail.com Sat Nov 6 21:57:36 2010 From: jon.dufresne at gmail.com (Jon Dufresne) Date: Sat, 6 Nov 2010 18:57:36 -0700 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: On Sat, Nov 6, 2010 at 1:52 PM, Roy Smith wrote: > > import sys > try: > ? ?import xx > except ImportError: > ? ?tb = sys.exc_traceback > ? ?while tb: > ? ? ? ?print tb > ? ? ? ?tb = tb.tb_next > I went ahead and implemented this and it now works. I even uncovered a bug I wasn't previously seeing because now the program was failing early! :) I hope there isn't a hidden naivete in using this pattern. Thanks, Jon From usenet-nospam at seebs.net Sat Nov 6 22:19:41 2010 From: usenet-nospam at seebs.net (Seebs) Date: 07 Nov 2010 02:19:41 GMT Subject: Compare source code References: <4cd4c6cf$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-07, Lawrence D'Oliveiro wrote: > In message , Seebs wrote: >> Four spaces followed by a tab nearly always actually means "eight spaces" >> to most editors (and Python seems to treat it that way), but it's hard to >> tell. Worse, a tab may have been intended to be the same thing as four >> spaces, and someone was expecting it NOT to be the same as eight spaces... > Whereas explicitly-bracketed languages leave no ambiguity about how many > brackets you need and where. Well, the good ones don't. :P (I think the optional nature of brackets is probably a flaw in C. It would break too much existing code to fix it, sadly.) -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Sat Nov 6 22:26:01 2010 From: usenet-nospam at seebs.net (Seebs) Date: 07 Nov 2010 02:26:01 GMT Subject: Silly newbie question - Carrot character (^) References: <87k4kq60na.fsf@xemacs.org> <87fwve53ve.fsf@xemacs.org> Message-ID: On 2010-11-07, Hrvoje Niksic wrote: > It's not a matter of quality, but of intended audience. To most > ordinary programmers the standards documents such as the C standard, the > C++ standard, or the Python reference are quite dense and hard to use as > a reference, and yet they are considered quite well done. Huh. I quite liked the C spec as a reference. Yeah, it's a bit dense, but that just means it's all actually *reference*. :) -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From roy at panix.com Sat Nov 6 22:34:28 2010 From: roy at panix.com (Roy Smith) Date: Sat, 06 Nov 2010 22:34:28 -0400 Subject: How to test if a module exists? References: Message-ID: In article , Jon Dufresne wrote: > I went ahead and implemented this and it now works. I even uncovered a > bug I wasn't previously seeing because now the program was failing > early! :) Excellent. Fail early and often, that's what I say. From roy at panix.com Sat Nov 6 23:10:21 2010 From: roy at panix.com (Roy Smith) Date: Sat, 06 Nov 2010 23:10:21 -0400 Subject: Silly newbie question - Carrot character (^) References: <87k4kq60na.fsf@xemacs.org> <87fwve53ve.fsf@xemacs.org> Message-ID: In article <87fwve53ve.fsf at xemacs.org>, Hrvoje Niksic wrote: > It's not a matter of quality, but of intended audience. To most > ordinary programmers the standards documents such as the C standard, the > C++ standard, or the Python reference are quite dense and hard to use as > a reference, and yet they are considered quite well done. Not only is the C++ reference obtuse and dense, it's also not commonly available. It is copyright by ISO and only available for a fee. I own a copy, but I'd venture to say that the vast majority of C++ programmers out there have never seen one. Heck, if was a programmer and wanted to spend money today to buy a copy, I wouldn't even know where to go to order one. I googled for "iso c++ standard" and found http://www.open-std.org/jtc1/sc22/wg21/, which includes a well-hidden link to http://www.open-std.org/jtc1/sc22/wg21/docs/standards, which says, "Published ISO and IEC standards can be purchased from a member body of ISO or IEC". How one would go about figuring out who such member body is, I have no idea. Any self-respecting C++ programmer would have given up the scavenger hunt by now. Just kept throwing typecasts at your code until it compiles, and move on. Python may not have a reference manual which is up to the quality of the C++ manual, but what's there is freely available on docs.python.org. As for the subject of this thread, you might want to check out http://archive.midrange.com/midrange-l/200703/msg00036.html. From aahz at pythoncraft.com Sat Nov 6 23:31:08 2010 From: aahz at pythoncraft.com (Aahz) Date: 6 Nov 2010 20:31:08 -0700 Subject: how to handle network failures References: <7bee5155-f1a1-44aa-90f6-eaabb361729f@v6g2000prd.googlegroups.com> Message-ID: In article <7bee5155-f1a1-44aa-90f6-eaabb361729f at v6g2000prd.googlegroups.com>, harryos wrote: > >class DataGrabber(threading.Thread): > def __init__(self,url): > threading.Thread.__init__(self) > self.url=url > def run(self): > data=self.get_page_data() > process_data(data) > > def get_page_data(): > try: > f=urllib.urlopen(self.url) > data=f.read(1024) > except IOError: > #wait for some time and try again > time.sleep(120) > data=self.get_page_data() > return data Use urllib2 so that you can set a timeout (Python 2.6+). -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." --Red Adair From usenet-nospam at seebs.net Sat Nov 6 23:35:55 2010 From: usenet-nospam at seebs.net (Seebs) Date: 07 Nov 2010 03:35:55 GMT Subject: Silly newbie question - Carrot character (^) References: <87k4kq60na.fsf@xemacs.org> <87fwve53ve.fsf@xemacs.org> Message-ID: On 2010-11-07, Roy Smith wrote: > Any self-respecting C++ programmer would have given > up the scavenger hunt by now. Just kept throwing typecasts at your code > until it compiles, and move on. That does not sound like a self-respecting programmer of anything. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From steve at REMOVE-THIS-cybersource.com.au Sun Nov 7 00:26:16 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 07 Nov 2010 04:26:16 GMT Subject: Compare source code References: <4cd4c6cf$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4cd62a68$0$30004$c3e8da3$5496439d@news.astraweb.com> On Sun, 07 Nov 2010 14:53:45 +1300, Lawrence D'Oliveiro wrote: > In message , Seebs wrote: > >> Specifically: >> >> Four spaces followed by a tab nearly always actually means "eight >> spaces" to most editors (and Python seems to treat it that way), but >> it's hard to tell. Worse, a tab may have been intended to be the same >> thing as four spaces, and someone was expecting it NOT to be the same >> as eight spaces... > > Whereas explicitly-bracketed languages leave no ambiguity about how many > brackets you need and where. Yes, and? The way people[1] go on, and on, and ON about braces and indentation, anyone would think that the hardest part of programming was deciding how many times to press the tab key. Besides, if we used reverse Polish notation, we wouldn't need either brackets or indentation. Forth rules-ly y'rs, -- Steven [1] I include myself. From usenet-nospam at seebs.net Sun Nov 7 00:28:29 2010 From: usenet-nospam at seebs.net (Seebs) Date: 07 Nov 2010 04:28:29 GMT Subject: Compare source code References: <4cd4c6cf$0$30004$c3e8da3$5496439d@news.astraweb.com> <4cd62a68$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-07, Steven D'Aprano wrote: > On Sun, 07 Nov 2010 14:53:45 +1300, Lawrence D'Oliveiro wrote: >> In message , Seebs wrote: >>> Four spaces followed by a tab nearly always actually means "eight >>> spaces" to most editors (and Python seems to treat it that way), but >>> it's hard to tell. Worse, a tab may have been intended to be the same >>> thing as four spaces, and someone was expecting it NOT to be the same >>> as eight spaces... >> Whereas explicitly-bracketed languages leave no ambiguity about how many >> brackets you need and where. > Yes, and? In context, I think the comment was sarcastic, referring to C's famous ambiguities caused by optional braces. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From nobody at nowhere.com Sun Nov 7 00:39:17 2010 From: nobody at nowhere.com (Nobody) Date: Sun, 07 Nov 2010 04:39:17 +0000 Subject: Silly newbie question - Carrot character (^) References: <4cd5ed80$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, 07 Nov 2010 00:06:25 +0000, Steven D'Aprano wrote: >> A reference manual tells you how to use the language. A specification >> tells you how to implement it. > > Surely a tutorial tells you *how* to use the language. I wouldn't expect > a reference manual to teach me how to run and edit programs -- the *how* > of using the language. You're taking "how" too literally, so let me rephrase that: A reference manual tells you what you need to know in order to use the language. A specification tells you what you need to know in order to implement it. >> It's possible to /deduce/ how to use the language from a specification, >> but it could take significant time and effort. > > I think you're looking for hard distinctions that simply doesn't exist. There isn't a /hard/ distinction, but there is a distinction, IMHO. A tutorial provides an overview of the language, but won't necessarily describe every aspect (maybe not even close), and is generally designed to be read in order. In order to provide working examples, it may be necessary to introduce some features in the "wrong" order (e.g. in a language which doesn't provide an interactive read-eval-print loop, I/O may be introduced early on simply so that complete programs can be constructed). And once the feature is covered, it probably won't be repeated when the tutorial gets to a more appropriate section (e.g. the I/O section may omit features covered in the introduction). A reference manual would describe whatever you need to know in order to "use" the language. It shouldn't omit anything short of the "you are not expected to understand this" level. IOW, any omissions shouldn't matter unless you are e.g. writing analysis utilities which need to accept /any/ valid program and interpret it correctly. E.g. a reference manual would need to describe indentation, but details such as the interpretation of a mixture of tabs and spaces can be limited to "don't do this", whereas a specification would need to either specify the details or at least specify that it invokes "undefined behaviour". > If you want to argue that the Python reference manual is aimed at the > wrong level of sophistication, specifically that the BNF syntax stuff > should be ripped out into another document, then I might agree with you. > But to argue that it's entirely the wrong "kind" of thing is, in my > opinion, unjustified. I'm arguing that the reference manual reads too much like a specification. E.g. look at "5.2.4. List displays" and tell me whether you consider that it adequately /explains/ list displays to someone wishing to use them. I note that the "reference manual" contains very few examples. For a specification, this would be quite normal, as examples can serve to undermine precision. For a reference manual, precision has to be traded for clarity, which may mean using examples where appropriate. OTOH, a tutorial often contains little more than a sequence of examples along with informal explanations as to their structure and functioning. As a result, tutorials tend to lack precision; they provide specific cases which will work and some "clues" as to what else is likely to work. Regarding BNF: reference manuals tend to use less formal descriptions. E.g. something akin to to --help syntax, or a "dumbed-down" BNF which may technically be ambiguous, with ambiguities resolved by specifying precedences separately or listing would-be ambiguous cases along with a description of their correct interpretation. From rustompmody at gmail.com Sun Nov 7 01:26:46 2010 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 7 Nov 2010 10:56:46 +0530 Subject: python test frameworks Message-ID: There are a large number of test frameworks in/for python. Apart from what comes builtin with python there seems to be nose, staf, qmtest etc etc. Is there any central place where these are listed with short descriptions? 'Test framework' means widely different things in different contexts. Any explanations/tutorials around? [Disclaimer: I was educated a couple of decades before the TDD rage] From " " at libero.it Sun Nov 7 01:43:48 2010 From: " " at libero.it (not1xor1 (Alessandro)) Date: Sun, 07 Nov 2010 05:43:48 GMT Subject: subclassing str Message-ID: Hi, I'd like to know what is the best way to subclass str I need to add some new methods and that each method (both new and str ones) return my new type For instance I've seen I can do: class mystr(str): def between(self, start, end): i = self.index(start) + len(start) j = self.index(end, i) + len(end) return self[i:j], self[j:] def replace(self, old, new='', count=-1): return mystr(str.replace(self, old, new, count)) if __name__ == '__main__': s = mystr('one two four') print s print type(s) b,r = s.between('<', '>') print b print r print type(b) print type(r) c = s.replace('three', 'five') print c print type(c) when I ran it I get: one two four three> four one two four I guess that if I had redefined the slice method even 'between' would have returned I wonder if I have to redefine all methods one by one or if there is a sort of hook to intercept all methods calls and just change the return type thanks -- bye !(!1|1) From ldo at geek-central.gen.new_zealand Sun Nov 7 01:29:46 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 07 Nov 2010 19:29:46 +1300 Subject: sigaction? References: Message-ID: In message , Neal Becker wrote: > I'm interested in trying sigaction with SA_RESTART to prevent interrupted > system calls. Worse-is-better strikes again ... From ldo at geek-central.gen.new_zealand Sun Nov 7 01:33:52 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 07 Nov 2010 19:33:52 +1300 Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> <87aalrjkty.fsf@benfinney.id.au> <8jd3m9Fr55U7@mid.individual.net> Message-ID: In message , Roy Smith wrote: > In article , > Lawrence D'Oliveiro wrote: > >> In message <8jd3m9Fr55U7 at mid.individual.net>, Neil Cerutti wrote: >> >> > On 2010-11-03, Ben Finney wrote: >> > >> >> styles = [ >> >> ("normal", "image", MainWindow.ColorsNormalList), >> >> ("highlighted", "highlight", >> >> MainWindow.ColorsHighlightedList), >> >> ("selected", "select", MainWindow.ColorsSelectedList)] >> > >> > Agreed, except cute stuff like putting those three items in >> > columns is just as bad. >> > >> > Code should be utilitarian rather than ornate, Shaker rather than >> > Victorian. >> >> Tufte?s concept of ?chartjunk? could perhaps be extended to ?formatjunk? >> or ?prettyprintjunk?. > > Not at all. Tufte is all about making data easy to understand visually. > The chartjunk he rails about is colors, shadows, 3-d effects, etc, which > make a chart "look pretty" but don't add to comprehension. Precisely my point. > If you take out the extra whitespace, you end up with this: > >> >> styles = [ >> >> ("normal", "image", MainWindow.ColorsNormalList), >> >> ("highlighted", "highlight", >> >> MainWindow.ColorsHighlightedList), ("selected", "select", >> >> MainWindow.ColorsSelectedList)] > > which I think is more difficult to scan visually. Not surprising, since the above list has become completely divorced from its original purpose. Anybody remember what that was? It was supposed to be used in a loop, as follows: for \ Description, Attr, ColorList \ in \ ( ("normal", "image", MainWindow.ColorsNormalList), ("highlighted", "highlight", MainWindow.ColorsHighlightedList), ("selected", "select", MainWindow.ColorsSelectedList), ) \ : ... #end for Does this make more sense now? From clp2 at rebertia.com Sun Nov 7 01:41:44 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 6 Nov 2010 23:41:44 -0700 Subject: subclassing str In-Reply-To: References: Message-ID: On Sat, Nov 6, 2010 at 10:43 PM, not1xor1 (Alessandro) <" "@libero.it> wrote: > Hi, > > I'd like to know what is the best way to subclass str > I need to add some new methods and that each method (both new and str ones) > return my new type > > For instance I've seen I can do: > > class mystr(str): > > ? def between(self, start, end): > ? ? ?i = self.index(start) + len(start) > ? ? ?j = self.index(end, i) + len(end) > ? ? ?return self[i:j], self[j:] > > ? def replace(self, old, new='', count=-1): > ? ? ?return mystr(str.replace(self, old, new, count)) > > I wonder if I have to redefine all methods one by one or if there is a sort > of hook to intercept all methods calls and just change the return type You could subclass UserString instead of str; all of UserString's methods seem to ensure that instances of the subclass rather than just plain strs or UserStrings are returned. See http://docs.python.org/library/userdict.html#UserString.UserString But you should also consider whether your additions absolutely *must* be methods. Merely instead defining some functions that take strings as parameters is obviously a simpler, and probably more performant, approach. If you insist on subclassing str, there's no such hook; you'll have to override all the methods yourself.* Cheers, Chris -- *Well, you could override only the __special__ methods and __getattribute__(), or use metaprogramming, but at that point you might as well go the UserString route if possible. http://blog.rebertia.com From usenet-nospam at seebs.net Sun Nov 7 01:43:52 2010 From: usenet-nospam at seebs.net (Seebs) Date: 07 Nov 2010 06:43:52 GMT Subject: Silly newbie question - Carrot character (^) References: <4cd5ed80$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-07, Nobody wrote: > I'm arguing that the reference manual reads too much like a specification. > E.g. look at "5.2.4. List displays" and tell me whether you consider that > it adequately /explains/ list displays to someone wishing to use them. Seems pretty explanatory to me. I mean, maybe it helps that I already basically understood both of the things you could put in [], but it's pretty clear. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From steve at REMOVE-THIS-cybersource.com.au Sun Nov 7 03:00:11 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 07 Nov 2010 08:00:11 GMT Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> <87aalrjkty.fsf@benfinney.id.au> <8jd3m9Fr55U7@mid.individual.net> Message-ID: <4cd65c86$0$30004$c3e8da3$5496439d@news.astraweb.com> On Sun, 07 Nov 2010 19:33:52 +1300, Lawrence D'Oliveiro wrote: > for \ > Description, Attr, ColorList \ > in \ > ( > ("normal", "image", MainWindow.ColorsNormalList), > ("highlighted", "highlight", > MainWindow.ColorsHighlightedList), ("selected", "select", > MainWindow.ColorsSelectedList), > ) \ > : > ... > #end for > > Does this make more sense now? No, it makes less sense, and is ugly too boot. -- Steven From moogyd at yahoo.co.uk Sun Nov 7 03:35:21 2010 From: moogyd at yahoo.co.uk (moogyd) Date: Sun, 7 Nov 2010 01:35:21 -0700 (PDT) Subject: Popen Question References: <891a9a80-c30d-4415-ac81-bddd0b564fa6@g13g2000yqj.googlegroups.com> Message-ID: Hi, Thanks everyone for the replies - it is now clearer. Steven From ldo at geek-central.gen.new_zealand Sun Nov 7 03:48:10 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 07 Nov 2010 21:48:10 +1300 Subject: execute shell script from python, needs sys.argv References: <1vmbd65uaj2snq1v0vo49ktn0lsc2o5m1a@4ax.com> Message-ID: In message <1vmbd65uaj2snq1v0vo49ktn0lsc2o5m1a at 4ax.com>, Tim Roberts wrote: > I KNOW that we're still working on syntax here, and that it's too early > for optimization, but it bothers me to see "cat" as the first thing in a > pipeline. An anti-UUOC instinct. Very good. :) From ldo at geek-central.gen.new_zealand Sun Nov 7 05:26:51 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 07 Nov 2010 23:26:51 +1300 Subject: Silly newbie question - Caret character (^) References: Message-ID: In message , Nobody wrote: > A reference manual tells you how to use the language. A specification > tells you how to implement it. Speaking as someone who has read more reference manuals/specifications/whatever you want to call them than I can count, I have never come across any such distinction. Both programmers and implementors need to understand exactly how the language is defined. Because if there is any disagreement between their respective interpretations, things are not going to work well, are they? > It's possible to /deduce/ how to use the language from a specification, > but it could take significant time and effort. That?s what ?tutorials? are for. > A specification is typically designed to be read in its entirety, and may > yield little usable information until you've read a substantial portion of > it. Sounds like you?re describing a novel, rather than actual technical documentation. > A reference manual is structured such that you can easily locate the > portion which is necessary for the task immediately to hand, and only > need to read that portion. So is a specification. From sustainable.future116 at gmail.com Sun Nov 7 05:31:34 2010 From: sustainable.future116 at gmail.com (........) Date: Sun, 7 Nov 2010 02:31:34 -0800 (PST) Subject: Why you should change your vehicle to flex fuel Message-ID: <9e59040b-8f2d-4432-ada6-f4694d04b85f@g20g2000prg.googlegroups.com> Dear Everyone, as you know the price of the Oil is more and more increasing, while the oil supply is decreasing. Moreover Oil is causing wars, terror, oil spills and a lot of greenhouse gases. By upgrading your car to flex fuel, you will continue to be able to use oil. However you will also have the opportunity to use E85, that means more freedom of choice. The conversion cost is about 200-250 USD. By choosing ethanol, you choose local fuel production, which means labour for farmers, labour for enginneers and workers in the ethanol plant, labour for transportation. Moreover you also help for indirect labour. Since the money stays in your country, this money will turn and produce indirect labour. Since the farmer will gain your additional fuel money, he will buy other things (labour is again needed for their production), which in case of oil the oil-Sheikhs or their people would do. That ethanol production increases the food prices is also not totally right, first there is a by-product called "distillers dried grains with solubles", which is used as feed for livestock, that is also nothing else than food. Moreover, by using ethanol, you put pressure on oil prices, which has also an important effect on food prices. You also give your money for more research (again labour), which will yield in higher efficiency of production and alternative production methods like cellulosic ethanol, which will change the whole equation. Again in case of oil this money would be spent for oil rigs, oil- infrastructure, but also for weapons to defend the oil. By using ethanol, you produce less CO2, since it is produced by corn, which actually consumed the CO2 in the air for its growing. The more people use ethanol, the higher the efficiencies will come for production (similar to solar cells). The prices will go further down, and much less CO2 will be produced during production in the plant. Do you know that the production efficiencies already improved 30% ?* Another reason for using ethanol is that oil prices will come up again, when the barrel price of 150 USD is back you will be very happy to have your vehicle converted. The conversion also increases the value of your vehicle. Yours sincerely. Sources: *http://brownfieldagnews.com/2010/09/21/ethanol-production-efficiency- improves/ From ldo at geek-central.gen.new_zealand Sun Nov 7 05:33:29 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 07 Nov 2010 23:33:29 +1300 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: In message , Tim Harig wrote: > I agree with Seebs, Python is the only language I know that promotes > the use of spaces over tabs; and there are equally picky syntaxs (ie, > Makefiles) that mandate the use of tabs. That?s widely conceded to be a misfeature of Make. > I personally prefer tabs as it lets *me* decide how far the apparent > indentations are in the code. But they don?t. Other people can have different settings, and they will see different indentations for your code, so you don?t have control at all. The only way to ensure they see what you see is to use spaces, not tabs. From ldo at geek-central.gen.new_zealand Sun Nov 7 05:37:11 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 07 Nov 2010 23:37:11 +1300 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: In message , Grant Edwards wrote: > But without the colon, how are people who write programming editors > going to know when to increase the indentation level as I enter code? I hate editors (or editing modes) that think they know when to change indentation level on me. Hate, hate, hate. From ldo at geek-central.gen.new_zealand Sun Nov 7 05:39:40 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 07 Nov 2010 23:39:40 +1300 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jftftFelnU1@mid.individual.net> Message-ID: In message <8jftftFelnU1 at mid.individual.net>, Neil Cerutti wrote: > The handsome ':' terminator of if/elif/if statements allows us to > omit a newline, conserving vertical space. This improves the > readability of certain constructs. > > if x: print(x) > elif y: print(y) > else: print() I would never do that. ?Conserving vertical space? seems a stupid reason for doing it. In C, I even go the opposite way: if (x) { printf(..., x); } else if (y) { printf(..., y); } else { printf(...); } /*if*/ From ldo at geek-central.gen.new_zealand Sun Nov 7 05:40:18 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 07 Nov 2010 23:40:18 +1300 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> <87sjzige0r.fsf@benfinney.id.au> Message-ID: In message <87sjzige0r.fsf at benfinney.id.au>, Ben Finney wrote: > Seebs writes: > >> On 2010-11-03, Steven D'Aprano >> wrote: >> >>> Python does explicitly mark blocks. It does it by changes in >>> indentation. An indent is an explicit start-block. An outdent is an >>> explicit end- block. There is nothing implicit in a change in indent >>> level. >> >> What's the token that marks the end of a block, corresponding to the >> colon used to introduce it? > > You have introduced this requirement for tokens; it's fallacious. The > direct answer is: tokens aren't part of the requirement to be explicit. > > The more general answer is: the block is explicitly ended where the > indentation ends. That?s implicit, not explicit. From ldo at geek-central.gen.new_zealand Sun Nov 7 05:50:08 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 07 Nov 2010 23:50:08 +1300 Subject: cms 4 static pages? References: Message-ID: In message , Guido Stepken wrote: > a not database driven What do you mean by ?database?? Even flat files can be ?databases?. From roy at panix.com Sun Nov 7 07:42:03 2010 From: roy at panix.com (Roy Smith) Date: Sun, 07 Nov 2010 07:42:03 -0500 Subject: Silly newbie question - Carrot character (^) References: <87k4kq60na.fsf@xemacs.org> <87fwve53ve.fsf@xemacs.org> Message-ID: In article , Seebs wrote: > On 2010-11-07, Roy Smith wrote: > > Any self-respecting C++ programmer would have given > > up the scavenger hunt by now. Just kept throwing typecasts at your code > > until it compiles, and move on. > > That does not sound like a self-respecting programmer of anything. Well, maybe I was being a little sarcastic. The real point was that if you make it hard for people to do the right thing (i.e. look up the details in the reference manual), you should not be surprised if they do the wrong thing (i.e. find some way to make it work by trial and error). From mdw at distorted.org.uk Sun Nov 7 07:57:13 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Sun, 07 Nov 2010 12:57:13 +0000 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jftftFelnU1@mid.individual.net> Message-ID: <87oca1b8ba.fsf.mdw@metalzone.distorted.org.uk> Lawrence D'Oliveiro writes: > I would never do that. ?Conserving vertical space? seems a stupid reason for > doing it. Vertical space is a limiting factor on how much code one can see at a time. I use old-fashioned CRT monitors with 4x3 aspect ratios and dizzyingly high resolution; I usually work with two columns of code, but can get four if I give up on things like xterms. I still find it rather limiting: I have to remember everything which won't fit on the screen. I've no idea how people manage with these ridiculous widescreen monitors. -- [mdw] From darragh.ssa at gmail.com Sun Nov 7 08:09:48 2010 From: darragh.ssa at gmail.com (Kruptein) Date: Sun, 7 Nov 2010 05:09:48 -0800 (PST) Subject: Deditor 0.2.2 References: Message-ID: <675c61bd-12f9-46ae-8b7e-b169e14e5064@j2g2000yqf.googlegroups.com> I also uploaded a video with sound because there were a lot of people that asked that. link: http://www.youtube.com/watch?v=zidKSPWBGxU From invalid at invalid.invalid Sun Nov 7 08:23:26 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Sun, 7 Nov 2010 13:23:26 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jftftFelnU1@mid.individual.net> <87oca1b8ba.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On 2010-11-07, Mark Wooding wrote: > Lawrence D'Oliveiro writes: > >> I would never do that. "Conserving vertical space" seems a stupid >> reason for doing it. > > Vertical space is a limiting factor on how much code one can see at a > time. And one study I read shoed that how much code one can see at a time directly affects the number of bugs introduced while editing. The more code you could see at a time, the better off you were (at least as far as the measurements in that study went). IOW, editing a loop or other control structure where you couldn't see both ends was problematic. Conserving vertical space avoids that problem. > I use old-fashioned CRT monitors with 4x3 aspect ratios and > dizzyingly high resolution; I usually work with two columns of code, but > can get four if I give up on things like xterms. I still find it rather > limiting: I have to remember everything which won't fit on the screen. > > I've no idea how people manage with these ridiculous widescreen monitors. Rotate them 90 degrees? My monitors will do that mechanically, but I've never bothered to try setting up X to handle it. (I bought 4:3 monitors before they got replaced by cheap 16:8 screens). -- Grant From invalid at invalid.invalid Sun Nov 7 08:24:21 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Sun, 7 Nov 2010 13:24:21 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> <87sjzige0r.fsf@benfinney.id.au> Message-ID: On 2010-11-07, Lawrence D'Oliveiro wrote: > In message <87sjzige0r.fsf at benfinney.id.au>, Ben Finney wrote: > >> Seebs writes: >> >>> On 2010-11-03, Steven D'Aprano >>> wrote: >>> >>>> Python does explicitly mark blocks. It does it by changes in >>>> indentation. An indent is an explicit start-block. An outdent is an >>>> explicit end- block. There is nothing implicit in a change in indent >>>> level. >>> >>> What's the token that marks the end of a block, corresponding to the >>> colon used to introduce it? >> >> You have introduced this requirement for tokens; it's fallacious. The >> direct answer is: tokens aren't part of the requirement to be explicit. >> >> The more general answer is: the block is explicitly ended where the >> indentation ends. > > That's implicit, not explicit. If you can _see_ it, how is it implicit? -- Grant From mdw at distorted.org.uk Sun Nov 7 08:29:40 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Sun, 07 Nov 2010 13:29:40 +0000 Subject: Silly newbie question - Carrot character (^) References: <4cd5ed80$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87k4kpb6t7.fsf.mdw@metalzone.distorted.org.uk> Nobody writes: > You're taking "how" too literally, so let me rephrase that: > > A reference manual tells you what you need to know in order to use > the language. A specification tells you what you need to know in > order to implement it. I still don't see those as being different. A language reference should set out all of the details of the language syntax and semantics. It should answer every question of the form `what happens if I write this?' In so doing, it /must/ also provide enough information for an implementer to write an new implementation. > A tutorial provides an overview of the language, but won't necessarily > describe every aspect (maybe not even close), and is generally > designed to be read in order. Agreed. > A reference manual would describe whatever you need to know in order > to "use" the language. It shouldn't omit anything short of the "you > are not expected to understand this" level. IOW, any omissions > shouldn't matter unless you are e.g. writing analysis utilities which > need to accept /any/ valid program and interpret it correctly. `Using' a language involves two activities: writing it, and reading it. You're only considering one of those activities, and I think it's the less important one. > E.g. a reference manual would need to describe indentation, but > details such as the interpretation of a mixture of tabs and spaces can > be limited to "don't do this", whereas a specification would need to > either specify the details or at least specify that it invokes > "undefined behaviour". I'm confronted with some code, written by someone else, and when I run it I get an unexpected result. The language reference should be able to explain to me precisely why I get the result that I see. If it can't, it's of no value. > I'm arguing that the reference manual reads too much like a specification. > E.g. look at "5.2.4. List displays" and tell me whether you consider that > it adequately /explains/ list displays to someone wishing to use them. It doesn't adequately specify them either. That section is just poorly written. > I note that the "reference manual" contains very few examples. For a > specification, this would be quite normal, as examples can serve to > undermine precision. For a reference manual, precision has to be traded > for clarity, which may mean using examples where appropriate. I disagree with both claims. Examples cannot undermine precision: if the normative text is correct then an example can only demonstrate an application of the specified rules. If the normative text is wrong then the specification is broken and needs fixing. But the same applies to a reference. Either it supplies enough detail to answer every question about how programs behave or it's broken: precision is essential here, but is not -- and cannot -- be compromised by adding examples. > OTOH, a tutorial often contains little more than a sequence of examples > along with informal explanations as to their structure and functioning. As > a result, tutorials tend to lack precision; they provide specific cases > which will work and some "clues" as to what else is likely to work. Yes, I'm familiar with the `leave the reader to fill in the gaps in my exposition for himself' approach to documentation -- and with the unenjoyable task of fixing the reader's confused mental model afterwards. -- [mdw] From mdw at distorted.org.uk Sun Nov 7 08:41:27 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Sun, 07 Nov 2010 13:41:27 +0000 Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> <87aalrjkty.fsf@benfinney.id.au> <8jd3m9Fr55U7@mid.individual.net> Message-ID: <87fwvdb69k.fsf.mdw@metalzone.distorted.org.uk> Lawrence D'Oliveiro writes: > Not surprising, since the above list has become completely divorced from its > original purpose. Anybody remember what that was? It was supposed to be used > in a loop, as follows: > > for \ > Description, Attr, ColorList \ > in \ > ( > ("normal", "image", MainWindow.ColorsNormalList), > ("highlighted", "highlight", MainWindow.ColorsHighlightedList), > ("selected", "select", MainWindow.ColorsSelectedList), > ) \ > : > ... > #end for > > Does this make more sense now? Ugh, no! for descr, attr, colours in [ ('normal', 'image', 'Normal'), ('highlighted', 'highlight', 'Highlighted'), ('selected', 'select', 'Selected')]: colourlist = getattr(MainWindow, 'Colors%sList' % colours) ## ... To be honest, there's so much regularity in that table that I'd consider generating it from a shorter list. This would obviously involve refactoring something else to eliminate the image/normal asymmetry. I'd also consider making the ColorsMumbleList attribute collection into a dictionary. Note that my columns are aligned to 8-column tab stops for easy maintenance (although my editor has used physical spaces rather than tabs). -- [mdw] From kevin.p.dwyer at gmail.com Sun Nov 7 09:09:32 2010 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Sun, 7 Nov 2010 14:09:32 +0000 (UTC) Subject: python test frameworks References: Message-ID: On Sun, 07 Nov 2010 10:56:46 +0530, Rustom Mody wrote: > There are a large number of test frameworks in/for python. Apart from > what comes builtin with python there seems to be nose, staf, qmtest etc > etc. > > Is there any central place where these are listed with short > descriptions? 'Test framework' means widely different things in > different contexts. Any explanations/tutorials around? > > [Disclaimer: I was educated a couple of decades before the TDD rage] Hello, You could start with http://pycheesecake.org/wiki/PythonTestingToolsTaxonomy Kev From steve at holdenweb.com Sun Nov 7 09:26:33 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Nov 2010 09:26:33 -0500 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jftftFelnU1@mid.individual.net> <87oca1b8ba.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On 11/7/2010 8:23 AM, Grant Edwards wrote: [...] > (I bought 4:3 monitors before they got replaced by cheap 16:8 > screens) I think you'll find the new aspect ration is 16:9. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From roy at panix.com Sun Nov 7 09:39:15 2010 From: roy at panix.com (Roy Smith) Date: Sun, 07 Nov 2010 09:39:15 -0500 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jftftFelnU1@mid.individual.net> <87oca1b8ba.fsf.mdw@metalzone.distorted.org.uk> Message-ID: In article <87oca1b8ba.fsf.mdw at metalzone.distorted.org.uk>, mdw at distorted.org.uk (Mark Wooding) wrote: > Vertical space is a limiting factor on how much code one can see at a > time. Yup. Over three decades of programming, my personal upper bound for how long a function should be has always been "fits on one screen". In the old days, that meant a CRT with 24 lines (by 80 columns). These days, it means about 100-120 lines (depending on how squinty-eyed I'm willing to go). Thus, over the years, my idea of how long a function can be has grown several-fold. I still try to keep things well under 100 lines per function. I'm willing, however, to tolerate anything up to where I can no longer see the entire thing and the font is still big enough to read easily. Of course, in the real old days, with 66 lines to an 11-inch page of line printer paper, and 8 foot high ceilings, you could tape about 500 lines of code to the wall, but I digress :-) > I've no idea how people manage with these ridiculous widescreen monitors. My 15-inch laptop has 1680 x 1050 resolution (the new high-res flavor of the MacBook Pro). I love it. Mostly I use the screen real estate for one main shell window where I'm doing most of my work, and a variety of other windows (browser, pdf viewer, etc) which contain documents I'm referring to in support of what I'm doing in my main window. At work, I've got two 1920 x 1080 monitors side-by-side. I find I don't use the second monitor much. I'll generally shove some windows over there which I watch, but almost never interact with. Mostly things tailing log files or some other kind of status monitor function. I also find that to keep the angle of view comfortable, I can't sit as close to the monitors as I usually keep my laptop screen. So, I have to make the font size a little larger, which in turn means fewer lines of code visible. Ergonomics is complicated. I'm thinking of rotating the monitors 90 degrees, running them in side-by-side portrait mode. I know X11 can handle the video rotation, but I'm not sure I've got the right mounting brackets. Another factor is that the Mac display is sharp as a tack compared to my big LCD panels at work. I think it's party the display hardware itself, and partly that the Mac's text rendering just blows Linux out of the water. I can easily read text on my laptop at much smaller font sizes than I can on my desk monitors at work. From gdamjan at gmail.com Sun Nov 7 09:39:31 2010 From: gdamjan at gmail.com (=?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLRgdC60Lg=?=) Date: Sun, 07 Nov 2010 15:39:31 +0100 Subject: ANN: PyQt v4.8.1 Released References: Message-ID: <3aqiq7-46p.ln1@archaeopteryx.softver.org.mk> >> Given the context, "PyQt is available under the GPL and a commercial >> license," the commercial license Phil is talking about is not the >> GPL. > > Which is a wrong interpretation of ?commercial?. But he is not interpreting either ?commercial? or GPL. What he says is: here's the code for free (gratis, no price) under the GPL, but if you don't like it, I also offer it commercially (under an undisclosed license, maybe a custom one as required by the client). He is NOT offering the GPL version commercially, even if that's allowed by the GPL. For ex. You are free to do it, it's that he is not doing it (or just not advertising it - I'm sure he wouldn't mind someone paying for the GPL version either). -- ?????? ((( http://damjan.softver.org.mk/ ))) "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." - Brian W. Kernighan From python.list at tim.thechases.com Sun Nov 7 09:52:28 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 07 Nov 2010 08:52:28 -0600 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jftftFelnU1@mid.individual.net> <87oca1b8ba.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <4CD6BD2C.5050406@tim.thechases.com> On 11/07/10 08:26, Steve Holden wrote: > On 11/7/2010 8:23 AM, Grant Edwards wrote: > [...] >> (I bought 4:3 monitors before they got replaced by cheap 16:8 >> screens) > > I think you'll find the new aspect ration is 16:9. Unless that's why they're cheap... dual-16x9-widescreen-in-portrait-mode-is-a-wonderful-thing'ly, -tkc From invalid at invalid.invalid Sun Nov 7 10:46:34 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Sun, 7 Nov 2010 15:46:34 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jftftFelnU1@mid.individual.net> <87oca1b8ba.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On 2010-11-07, Steve Holden wrote: > On 11/7/2010 8:23 AM, Grant Edwards wrote: > [...] >> (I bought 4:3 monitors before they got replaced by cheap 16:8 >> screens) > > I think you'll find the new aspect ration is 16:9. I knew that. My keyboard didn't. I recently bought a close-out Lenovo T500 Thinkpad from their outlet because current models are now 16:9 instead of the older 16:10. My old 4:3 Thinkpad was still going strong, but I decided I'd better get a 16:10 while I could -- though I'd still prefer a 4:3. -- Grant From emile at fenx.com Sun Nov 7 10:48:32 2010 From: emile at fenx.com (Emile van Sebille) Date: Sun, 07 Nov 2010 07:48:32 -0800 Subject: Silly newbie question - Caret character (^) In-Reply-To: References: Message-ID: On 11/7/2010 2:26 AM Lawrence D'Oliveiro said... > In message, Nobody wrote: > >> A reference manual tells you how to use the language. A specification >> tells you how to implement it. > > Speaking as someone who has read more reference > manuals/specifications/whatever you want to call them than I can count, I > have never come across any such distinction. Surely you see the difference between RFC5321 and for example Courier's man pages? One's the specification and the other's the reference manual. Emile From ethan at stoneleaf.us Sun Nov 7 11:20:11 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 07 Nov 2010 08:20:11 -0800 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> <4cd3de51$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4CD6D1BB.90204@stoneleaf.us> Seebs wrote: > On 2010-11-05, Ethan Furman wrote: >> The verifiable benefit for me is ease of use, ease of thought, ease of >> typing... I realize these are not benefits for everyone, but they are >> for some -- and I would venture a guess that the ease of thought benefit >> is one of the primary reasons Python is popular. I am definitely one of >> those that think indentation based structure is one of Python's best >> features. > > Could you explain more the "ease of thought" thing? I haven't yet noticed > it, but it might be something to look out for as I get more experienced. Most if my programming experience is in FoxPro versions 2 and 6. Control structures start with if, for, do case, do while, with, procedure, and (I think) function. Control structures end with endif, endfor, endcase, endwhile, endwith, endproc, and (I think) endfunc. In Python, control structures start with if, for, while, try, def, and class, and each one ends with a dedent. This really comes into play when developing -- want to change that if to a while? Go ahead! And no need to worry about tracking down the closing endif to change it to endwhile, plus it's less clutter on the screen. I also really like the dynamic typing and not having to declare nor pre-initialize variable names, as well as the lack of a true global namespace. All in all, I am able to think about the code and what I want to do, and not think about the compiler/interpreter and keeping it happy. Hope this helps. ~Ethan~ From ethan at stoneleaf.us Sun Nov 7 11:36:01 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 07 Nov 2010 08:36:01 -0800 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4CD6D571.8070509@stoneleaf.us> Lawrence D'Oliveiro wrote: > In message , Tim Harig wrote: >> >> I personally prefer tabs as it lets *me* decide how far the apparent >> indentations are in the code. > > But they don?t. Other people can have different settings, and they will see > different indentations for your code That's exactly the point -- each person can decide what level of indentation they prefer to look at. ~Ethan~ From steve at holdenweb.com Sun Nov 7 11:39:38 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Nov 2010 11:39:38 -0500 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jftftFelnU1@mid.individual.net> <87oca1b8ba.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On 11/7/2010 10:46 AM, Grant Edwards wrote: > On 2010-11-07, Steve Holden wrote: >> On 11/7/2010 8:23 AM, Grant Edwards wrote: >> [...] >>> (I bought 4:3 monitors before they got replaced by cheap 16:8 >>> screens) >> >> I think you'll find the new aspect ration is 16:9. > "aspect ration". Sheesh. > I knew that. My keyboard didn't. > > I recently bought a close-out Lenovo T500 Thinkpad from their outlet > because current models are now 16:9 instead of the older 16:10. My > old 4:3 Thinkpad was still going strong, but I decided I'd better get > a 16:10 while I could -- though I'd still prefer a 4:3. > The thing that *really* pisses me off is that you *used* to be able to get 1920 x 1200 15" displays, but *now* you are lucky to go above 1080 vertical pixels even in a 17" laptop display. I don't want the resolution of my displays dictated by the resolution of my (current) media, yet it seems that's what's happened in the laptop market. I got a Lenovo T60 a while back as a touchpad machine. Wondering about switching that to Linux, but I haven't seen any touchpad distros in action yet. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From robert.kern at gmail.com Sun Nov 7 12:01:22 2010 From: robert.kern at gmail.com (Robert Kern) Date: Sun, 07 Nov 2010 11:01:22 -0600 Subject: ANN: PyQt v4.8.1 Released In-Reply-To: <3aqiq7-46p.ln1@archaeopteryx.softver.org.mk> References: <3aqiq7-46p.ln1@archaeopteryx.softver.org.mk> Message-ID: On 2010-11-07 08:39 , ?????? ??????????? wrote: >>> Given the context, "PyQt is available under the GPL and a commercial >>> license," the commercial license Phil is talking about is not the >>> GPL. >> >> Which is a wrong interpretation of ?commercial?. > > But he is not interpreting either ?commercial? or GPL. > > What he says is: here's the code for free (gratis, no price) under the > GPL, but if you don't like it, I also offer it commercially (under an > undisclosed license, maybe a custom one as required by the client). Right. In this case, "commercial" describes the way he is offering the license, not what uses of the software the license allows. Everyone here knew exactly what he meant. -- 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 rustompmody at gmail.com Sun Nov 7 12:01:42 2010 From: rustompmody at gmail.com (rustom) Date: Sun, 7 Nov 2010 09:01:42 -0800 (PST) Subject: python test frameworks References: Message-ID: <009da031-22f2-4719-b030-b1db76e953af@r4g2000prj.googlegroups.com> On Nov 7, 7:09?pm, Kev Dwyer wrote: > On Sun, 07 Nov 2010 10:56:46 +0530, Rustom Mody wrote: > > There are a large number of test frameworks in/for python. ?Apart from > > what comes builtin with python there seems to be nose, staf, qmtest etc > > etc. > > > Is there any central place where these are listed with short > > descriptions? 'Test framework' means widely different things in > > different contexts. Any explanations/tutorials around? > > > [Disclaimer: I was educated a couple of decades before the TDD rage] > > Hello, > > You could start withhttp://pycheesecake.org/wiki/PythonTestingToolsTaxonomy > > Kev Thanks -- that looks like a comprehensive resource. But it does not have staf http://staf.sourceforge.net/current/STAFPython.htm. Is that merely an item missing or a category? From cdalten at gmail.com Sun Nov 7 12:34:48 2010 From: cdalten at gmail.com (chad) Date: Sun, 7 Nov 2010 09:34:48 -0800 (PST) Subject: A question about yield Message-ID: <40dd2ea7-0b1d-4600-8fc7-a2d0027b98c0@f16g2000prj.googlegroups.com> I have an input file named 'freq' which contains the following data 123 0 133 3 146 1 200 0 233 10 400 2 Now I've attempted to write a script that would take a number from the standard input and then have the program return the number in the input file that is closest to that input file. #!/usr/local/bin/python import sys def construct_set(data): for line in data: lines = line.splitlines() for curline in lines: if curline.strip(): key = curline.split(' ') value = int(key[0]) yield value def approximate(first, second): midpoint = (first + second) / 2 return midpoint def format(input): prev = 0 value = int(input) with open("/home/cdalten/oakland/freq") as f: for next in construct_set(f): if value > prev: current = prev prev = next middle = approximate(current, prev) if middle < prev and value > middle: return prev elif value > current and current < middle: return current if __name__ == "__main__": if len(sys.argv) != 2: print >> sys.stderr, "You need to enter a number\n" sys.exit(1) nearest = format(sys.argv[1]) print "The closest value to", sys.argv[1], "is", nearest When I run it, I get the following... [cdalten at localhost oakland]$ ./android4.py 123 The closest value to 123 is 123 [cdalten at localhost oakland]$ ./android4.py 130 The closest value to 130 is 133 [cdalten at localhost oakland]$ ./android4.py 140 The closest value to 140 is 146 [cdalten at localhost oakland]$ ./android4.py 146 The closest value to 146 is 146 [cdalten at localhost oakland]$ ./android4.py 190 The closest value to 190 is 200 [cdalten at localhost oakland]$ ./android4.py 200 The closest value to 200 is 200 [cdalten at localhost oakland]$ ./android4.py 205 The closest value to 205 is 200 [cdalten at localhost oakland]$ ./android4.py 210 The closest value to 210 is 200 [cdalten at localhost oakland]$ ./android4.py 300 The closest value to 300 is 233 [cdalten at localhost oakland]$ ./android4.py 500 The closest value to 500 is 400 [cdalten at localhost oakland]$ ./android4.py 1000000 The closest value to 1000000 is 400 [cdalten at localhost oakland]$ The question is about the construct_set() function. def construct_set(data): for line in data: lines = line.splitlines() for curline in lines: if curline.strip(): key = curline.split(' ') value = int(key[0]) yield value I have it yield on 'value' instead of 'curline'. Will the program still read the input file named freq line by line even though I don't have it yielding on 'curline'? Or since I have it yield on 'value', will it read the entire input file into memory at once? Chad From cdalten at gmail.com Sun Nov 7 12:37:54 2010 From: cdalten at gmail.com (chad) Date: Sun, 7 Nov 2010 09:37:54 -0800 (PST) Subject: A question about yield References: <40dd2ea7-0b1d-4600-8fc7-a2d0027b98c0@f16g2000prj.googlegroups.com> Message-ID: On Nov 7, 9:34?am, chad wrote: > I have an input file named 'freq' which contains the following data > > 123 0 > > 133 3 > 146 1 > 200 0 > 233 10 > 400 2 > > Now I've attempted to write a script that would take a number from the > standard input and then > have the program return the number in the input file that is closest > to that input file. *and then have the program return the number in the input file that is closest to the number the user inputs (or enters).* From usenet-nospam at seebs.net Sun Nov 7 12:41:10 2010 From: usenet-nospam at seebs.net (Seebs) Date: 07 Nov 2010 17:41:10 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jftftFelnU1@mid.individual.net> <87oca1b8ba.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On 2010-11-07, Mark Wooding wrote: > I've no idea how people manage with these ridiculous widescreen monitors. Side space used for Other Stuff. It takes some reworking of the layout, but overall I sorta like it now. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From clp2 at rebertia.com Sun Nov 7 12:47:47 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 7 Nov 2010 09:47:47 -0800 Subject: A question about yield In-Reply-To: <40dd2ea7-0b1d-4600-8fc7-a2d0027b98c0@f16g2000prj.googlegroups.com> References: <40dd2ea7-0b1d-4600-8fc7-a2d0027b98c0@f16g2000prj.googlegroups.com> Message-ID: On Sun, Nov 7, 2010 at 9:34 AM, chad wrote: > #!/usr/local/bin/python > > import sys > > def construct_set(data): > ? ?for line in data: > ? ? ? ?lines = line.splitlines() > ? ? ? ?for curline in lines: > ? ? ? ? ? ?if curline.strip(): > ? ? ? ? ? ? ? ?key = curline.split(' ') > ? ? ? ? ? ? ? ?value = int(key[0]) > ? ? ? ? ? ? ? ?yield value > > def approximate(first, second): > ? ?midpoint = (first + second) / 2 > ? ?return midpoint > > def format(input): > ? ?prev = 0 > ? ?value = int(input) > > ? ?with open("/home/cdalten/oakland/freq") as f: > ? ? ? ?for next in construct_set(f): > ? ? ? ? ? ?if value > prev: > ? ? ? ? ? ? ? ?current = prev > ? ? ? ? ? ? ? ?prev = next > > ? ? ? ?middle = approximate(current, prev) > ? ? ? ?if middle < prev and value > middle: > ? ? ? ? ? ?return prev > ? ? ? ?elif value > current and current < middle: > ? ? ? ? ? ?return current > The question is about the construct_set() function. > I have it yield on 'value' instead of 'curline'. Will the program > still read the input file named freq line by line even though I don't > have it yielding on 'curline'? Or since I have it yield on 'value', > will it read the entire input file into memory at once? The former. The yield has no effect at all on how the file is read. The "for line in data:" iteration over the file object is what makes Python read from the file line-by-line. Incidentally, the use of splitlines() is pointless; you're already getting single lines from the file object by iterating over it, so splitlines() will always return a single-element list. Cheers, Chris -- http://blog.rebertia.com From usenet-nospam at seebs.net Sun Nov 7 12:50:01 2010 From: usenet-nospam at seebs.net (Seebs) Date: 07 Nov 2010 17:50:01 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> <87sjzige0r.fsf@benfinney.id.au> Message-ID: On 2010-11-07, Grant Edwards wrote: > On 2010-11-07, Lawrence D'Oliveiro wrote: >> In message <87sjzige0r.fsf at benfinney.id.au>, Ben Finney wrote: >>> The more general answer is: the block is explicitly ended where the >>> indentation ends. >> That's implicit, not explicit. > If you can _see_ it, how is it implicit? Humans can see negative space. It's still implicit. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Sun Nov 7 12:53:10 2010 From: usenet-nospam at seebs.net (Seebs) Date: 07 Nov 2010 17:53:10 GMT Subject: Silly newbie question - Carrot character (^) References: <87k4kq60na.fsf@xemacs.org> <87fwve53ve.fsf@xemacs.org> Message-ID: On 2010-11-07, Roy Smith wrote: > Well, maybe I was being a little sarcastic. The real point was that if > you make it hard for people to do the right thing (i.e. look up the > details in the reference manual), you should not be surprised if they do > the wrong thing (i.e. find some way to make it work by trial and error). Fair enough. That said, I don't think it's the *writing* of the C spec that would make it hard for people to look up details. Dunno for C++. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From cdalten at gmail.com Sun Nov 7 12:56:46 2010 From: cdalten at gmail.com (chad) Date: Sun, 7 Nov 2010 09:56:46 -0800 (PST) Subject: A question about yield References: <40dd2ea7-0b1d-4600-8fc7-a2d0027b98c0@f16g2000prj.googlegroups.com> Message-ID: On Nov 7, 9:47?am, Chris Rebert wrote: > On Sun, Nov 7, 2010 at 9:34 AM, chad wrote: > > > > > > > #!/usr/local/bin/python > > > import sys > > > def construct_set(data): > > ? ?for line in data: > > ? ? ? ?lines = line.splitlines() > > ? ? ? ?for curline in lines: > > ? ? ? ? ? ?if curline.strip(): > > ? ? ? ? ? ? ? ?key = curline.split(' ') > > ? ? ? ? ? ? ? ?value = int(key[0]) > > ? ? ? ? ? ? ? ?yield value > > > def approximate(first, second): > > ? ?midpoint = (first + second) / 2 > > ? ?return midpoint > > > def format(input): > > ? ?prev = 0 > > ? ?value = int(input) > > > ? ?with open("/home/cdalten/oakland/freq") as f: > > ? ? ? ?for next in construct_set(f): > > ? ? ? ? ? ?if value > prev: > > ? ? ? ? ? ? ? ?current = prev > > ? ? ? ? ? ? ? ?prev = next > > > ? ? ? ?middle = approximate(current, prev) > > ? ? ? ?if middle < prev and value > middle: > > ? ? ? ? ? ?return prev > > ? ? ? ?elif value > current and current < middle: > > ? ? ? ? ? ?return current > > > The question is about the construct_set() function. > > > I have it yield on 'value' instead of 'curline'. Will the program > > still read the input file named freq line by line even though I don't > > have it yielding on 'curline'? Or since I have it yield on 'value', > > will it read the entire input file into memory at once? > > The former. The yield has no effect at all on how the file is read. > The "for line in data:" iteration over the file object is what makes > Python read from the file line-by-line. Incidentally, the use of > splitlines() is pointless; you're already getting single lines from > the file object by iterating over it, so splitlines() will always > return a single-element list. > But what happens if the input file is say 250MB? Will all 250MB be loaded into memory at once? Just curious, because I thought maybe using something like 'yield curline' would prevent this scenario. From clp2 at rebertia.com Sun Nov 7 13:14:12 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 7 Nov 2010 10:14:12 -0800 Subject: A question about yield In-Reply-To: References: <40dd2ea7-0b1d-4600-8fc7-a2d0027b98c0@f16g2000prj.googlegroups.com> Message-ID: On Sun, Nov 7, 2010 at 9:56 AM, chad wrote: > On Nov 7, 9:47?am, Chris Rebert wrote: >> On Sun, Nov 7, 2010 at 9:34 AM, chad wrote: >> >> > #!/usr/local/bin/python >> >> > import sys >> >> > def construct_set(data): >> > ? ?for line in data: >> > ? ? ? ?lines = line.splitlines() >> > ? ? ? ?for curline in lines: >> > ? ? ? ? ? ?if curline.strip(): >> > ? ? ? ? ? ? ? ?key = curline.split(' ') >> > ? ? ? ? ? ? ? ?value = int(key[0]) >> > ? ? ? ? ? ? ? ?yield value >> >> > def approximate(first, second): >> > ? ?midpoint = (first + second) / 2 >> > ? ?return midpoint >> >> > def format(input): >> > ? ?prev = 0 >> > ? ?value = int(input) >> >> > ? ?with open("/home/cdalten/oakland/freq") as f: >> > ? ? ? ?for next in construct_set(f): >> > ? ? ? ? ? ?if value > prev: >> > ? ? ? ? ? ? ? ?current = prev >> > ? ? ? ? ? ? ? ?prev = next >> >> > ? ? ? ?middle = approximate(current, prev) >> > ? ? ? ?if middle < prev and value > middle: >> > ? ? ? ? ? ?return prev >> > ? ? ? ?elif value > current and current < middle: >> > ? ? ? ? ? ?return current >> >> > The question is about the construct_set() function. >> >> > I have it yield on 'value' instead of 'curline'. Will the program >> > still read the input file named freq line by line even though I don't >> > have it yielding on 'curline'? Or since I have it yield on 'value', >> > will it read the entire input file into memory at once? >> >> The former. The yield has no effect at all on how the file is read. >> The "for line in data:" iteration over the file object is what makes >> Python read from the file line-by-line. Incidentally, the use of >> splitlines() is pointless; you're already getting single lines from >> the file object by iterating over it, so splitlines() will always >> return a single-element list. > > But what happens if the input file is say 250MB? Will all 250MB be > loaded into memory at once? No. As I said, the file will be read from 1 line at a time, on an as-needed basis; which is to say, "line-by-line". > Just curious, because I thought maybe > using something like 'yield curline' would prevent this scenario. Using "for line in data:" is what prevents that scenario. The "yield" is only relevant to how the file is read insofar as the the alternative to yield-ing would be to return a list, which would necessitate going through the entire file in continuous go and then returning a very large list; but even then, the file's content would still be read from line-by-line, not all at once as one humongous string. Cheers, Chris -- http://blog.rebertia.com From cwc at cwc.name Sun Nov 7 14:25:42 2010 From: cwc at cwc.name (CWC) Date: Sun, 7 Nov 2010 11:25:42 -0800 (PST) Subject: Making ActivePython and Python co-exist on Windows Message-ID: I'm new to Python. Is it possible to make ActivePython 3.12 and Python 3.12 co-exist on Windows? I've got an app which requires the former, but I want to stay with the latter, since I'm interested in getting into development. The main area of collision appears to be the Registry. From usenet-nospam at seebs.net Sun Nov 7 14:56:32 2010 From: usenet-nospam at seebs.net (Seebs) Date: 07 Nov 2010 19:56:32 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> <4cd3de51$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-11-07, Ethan Furman wrote: > Seebs wrote: >> On 2010-11-05, Ethan Furman wrote: >>> The verifiable benefit for me is ease of use, ease of thought, ease of >>> typing... I realize these are not benefits for everyone, but they are >>> for some -- and I would venture a guess that the ease of thought benefit >>> is one of the primary reasons Python is popular. I am definitely one of >>> those that think indentation based structure is one of Python's best >>> features. >> Could you explain more the "ease of thought" thing? I haven't yet noticed >> it, but it might be something to look out for as I get more experienced. > Most if my programming experience is in FoxPro versions 2 and 6. > Control structures start with if, for, do case, do while, with, > procedure, and (I think) function. Control structures end with endif, > endfor, endcase, endwhile, endwith, endproc, and (I think) endfunc. Eww. > In Python, control structures start with if, for, while, try, def, and > class, and each one ends with a dedent. So they're more consistent. > This really comes into play when developing -- want to change that if to > a while? Go ahead! And no need to worry about tracking down the > closing endif to change it to endwhile, plus it's less clutter on the > screen. I can see that. I actually mostly prefer an explicit close. Of the things I've used, I'm happiest with braces, because punctuation is good at being interpreted unconsciously, but I'm okay with "end" as long as it's the same for everything. I do like having a things bounded, though; I find it easier to read: if (foo) { bar; } baz; than if foo: bar baz; (I'm not quite sure why, but I think it's because the trailing boundary is part of the thing it bounds, rather than being the start of the thing after it.) I would definitely agree, though, that the Python solution is better than what you describe for FoxPro. It's also better, IMHO, than sh. > I also really like the dynamic typing and not having to declare nor > pre-initialize variable names, as well as the lack of a true global > namespace. I am torn on declarations -- I am pretty sure I make more mistakes with clashing variable names when they aren't explicitly declared, but I do like the much shorter code that results from not having them. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From ozric at web.de Sun Nov 7 15:24:20 2010 From: ozric at web.de (chris) Date: Sun, 7 Nov 2010 12:24:20 -0800 (PST) Subject: { '0':'c->c->a' ,'1':'a->b->a' .........} Message-ID: <8961af78-5f7b-46e1-95d7-014534b6e637@s4g2000yql.googlegroups.com> Hi, have anybody a hint , how i get a dict from non unique id's and their different related values. Thanks for advance Chris ###random data # a=range(10)*3 def seqelem(): i=random.randint(0,2) elem=['a','b','c'][i] return elem s=[seqelem() for t in range(30)] print zip(a,s) ## favored result: { '0':'c->c->a' ,'1':'a->b->a' .........} From ladasky at my-deja.com Sun Nov 7 15:32:46 2010 From: ladasky at my-deja.com (John Ladasky) Date: Sun, 7 Nov 2010 12:32:46 -0800 (PST) Subject: { '0':'c->c->a' ,'1':'a->b->a' .........} References: <8961af78-5f7b-46e1-95d7-014534b6e637@s4g2000yql.googlegroups.com> Message-ID: <7e03db1b-66ac-49ea-bbed-05d782ea4307@g20g2000prg.googlegroups.com> Hi Chris, I may have time to look at the rest of your code later. For now I just want to comment on one line: On Nov 7, 12:24?pm, chris wrote: > ? ? elem=['a','b','c'][i] The string type, just like the list type, is a sequence type. So strings have all the standard sequence methods. You could just write: elem = "abc"[i] From benjamin.kaplan at case.edu Sun Nov 7 15:34:38 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sun, 7 Nov 2010 15:34:38 -0500 Subject: Making ActivePython and Python co-exist on Windows In-Reply-To: References: Message-ID: On Sun, Nov 7, 2010 at 2:25 PM, CWC wrote: > I'm new to Python. ?Is it possible to make ActivePython 3.12 and > Python 3.12 co-exist on Windows? ?I've got an app which requires the > former, but I want to stay with the latter, since I'm interested in > getting into development. ?The main area of collision appears to be > the Registry. > -- ActivePython is the same thing as the "normal" Python. They just bundle the standard Python 3.1.2 distribution with a couple of extra packages in a convenient installer for you. From arnodel at gmail.com Sun Nov 7 15:51:50 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Sun, 07 Nov 2010 20:51:50 +0000 Subject: { '0':'c->c->a' ,'1':'a->b->a' .........} References: <8961af78-5f7b-46e1-95d7-014534b6e637@s4g2000yql.googlegroups.com> Message-ID: <87tyjsyhzt.fsf@gmail.com> chris writes: > Hi, > > have anybody a hint , how i get a dict from non unique id's and their > different related values. > > Thanks for advance > Chris > > ###random data # > a=range(10)*3 > def seqelem(): > i=random.randint(0,2) > elem=['a','b','c'][i] > return elem > > s=[seqelem() for t in range(30)] > print zip(a,s) > > ## favored result: > { '0':'c->c->a' ,'1':'a->b->a' .........} Here's one way: >>> import random >>> >>> a=range(10)*3 >>> def seqelem(): ... i=random.randint(0,2) ... elem=['a','b','c'][i] ... return elem ... >>> s=[seqelem() for t in range(30)] >>> z = zip(a, s) >>> print z [(0, 'b'), (1, 'a'), (2, 'b'), (3, 'a'), (4, 'b'), (5, 'c'), (6, 'b'), (7, 'c'), (8, 'b'), (9, 'b'), (0, 'a'), (1, 'b'), (2, 'b'), (3, 'c'), (4, 'c'), (5, 'b'), (6, 'c'), (7, 'a'), (8, 'a'), (9, 'c'), (0, 'b'), (1, 'c'), (2, 'b'), (3, 'a'), (4, 'c'), (5, 'a'), (6, 'c'), (7, 'b'), (8, 'c'), (9, 'c')] >>> >>> from itertools import groupby >>> from operator import itemgetter >>> >>> z.sort(key=itemgetter(0)) >>> print dict((k, '->'.join(map(itemgetter(1), it))) ... for k, it in groupby(z, itemgetter(0))) {0: 'b->a->b', 1: 'a->b->c', 2: 'b->b->b', 3: 'a->c->a', 4: 'b->c->c', 5: 'c->b->a', 6: 'b->c->c', 7: 'c->a->b', 8: 'b->a->c', 9: 'b->c->c'} HTH -- Arnaud From __peter__ at web.de Sun Nov 7 16:00:38 2010 From: __peter__ at web.de (Peter Otten) Date: Sun, 07 Nov 2010 22:00:38 +0100 Subject: { '0':'c->c->a' ,'1':'a->b->a' .........} References: <8961af78-5f7b-46e1-95d7-014534b6e637@s4g2000yql.googlegroups.com> Message-ID: chris wrote: > have anybody a hint , how i get a dict from non unique id's and their > different related values. > > Thanks for advance > Chris > > ###random data # > a=range(10)*3 > def seqelem(): > i=random.randint(0,2) > elem=['a','b','c'][i] > return elem > > s=[seqelem() for t in range(30)] > print zip(a,s) > > ## favored result: > { '0':'c->c->a' ,'1':'a->b->a' .........} >>> import random >>> from collections import defaultdict >>> a = range(10)*3 >>> s = [random.choice("abc") for _ in a] >>> d = defaultdict(list) >>> for k, v in zip(a, s): ... d[k].append(v) ... >>> d defaultdict(, {0: ['b', 'a', 'a'], 1: ['c', 'a', 'c'], 2: ['c', 'c', 'c'], 3: ['c', 'a', 'a'], 4: ['b', 'c', 'a'], 5: ['b', 'c', 'c'], 6: ['c', 'a', 'b'], 7: ['b', 'b', 'a'], 8: ['a', 'c', 'c'], 9: ['b', 'a', 'b']}) >>> dict((k, "->".join(v)) for k, v in d.iteritems()) {0: 'b->a->a', 1: 'c->a->c', 2: 'c->c->c', 3: 'c->a->a', 4: 'b->c->a', 5: 'b->c->c', 6: 'c->a->b', 7: 'b->b->a', 8: 'a->c->c', 9: 'b->a->b'} Peter From smallpox911 at gmail.com Sun Nov 7 16:01:39 2010 From: smallpox911 at gmail.com (small Pox) Date: Sun, 7 Nov 2010 13:01:39 -0800 (PST) Subject: *** FBI gets a warm welcome in Chicago for their EXCELLENTperformance - cheers to NEW CONS *** References: <26f97f70-9043-490c-9e6e-35159f38d76b@r29g2000yqj.googlegroups.com> <47e0b3a3-54fb-4489-95a8-b5ec6015c99d@j25g2000yqa.googlegroups.com> Message-ID: <75c68fde-988e-4000-99d4-0b7ee596babf@x7g2000prj.googlegroups.com> *** FBI gets a warm welcome in Chicago for their EXCELLENT performance - cheers to NEW CONS *** http://www.youtube.com/watch?v=eq2ZvSd-z0M&feature=player_embedded&related http://www.youtube.com/watch?v=eq2ZvSd-z0M&feature=player_embedded&related http://www.youtube.com/watch?v=eq2ZvSd-z0M&feature=player_embedded&related http://www.youtube.com/watch?v=eq2ZvSd-z0M&feature=player_embedded&related http://www.youtube.com/watch?v=eq2ZvSd-z0M&feature=player_embedded&related On Nov 2, 2:30 pm, silver light wrote: > On Nov 2, 1:58 pm, Rich Grise wrote: > > > On Tue, 02 Nov 2010 14:17:29 -0700, Gunner Asch wrote: > > > > But...shrug..there will be far less after the Great Cull........ > > > I think some people might be surprised as to exactly _who_ gets "culled". > > > Good Luck! > > Rich > > On Nov 2, 11:03 am, t... at sevak.isi.edu (Thomas A. Russ) wrote: > > > silver light writes: > > > *** FBI gets a warm welcome in Chicago for their EXCELLENT performance > > > - cheers to NEW CONS *** > > > Oh geez. Just when we've beaten back the infix hordes, someone comes up > > and suggests replacing CONS with something, new different and most > > likely inferior. > > > - Grumpy Old Programmer. > > > -- > > Thomas A. Russ, USC/Information Sciences Institute > > Google censored my post and deleted it not because they are trying to > defend the FBI or cover them up. They just dont like silverlight which > is from Microsoft. > > It is well known that google and oracle are trying to get control of > the whole cyberspace either alone or in alliance with each other. > > This way they can control the federal government. Most senators and > congressmen are pea brain and go along with whatever the corporations > show them with music, viagra, champagne, food, cruise tickets, girls > and pocket money. > > ========== > Submitted by jkeogh on Tue, 11/02/2010 - 6:44am > > http://911blogger.com/news/2010-10-20/foia-funds-request > > Litigation seeking the release of never before seen 9/11 FBI records > is currently underway in the federal courts. There is a immediate need > for a FOIA attorney to assist with the case. The defendants are > operating with a nearly unlimited funding and have a large body of > legal experts working to prevent the release of these records. A > public interest FOIA attorney has offered their services at a reduced > public interest rate. We need the research communities help to raise > the required funds. Release of these requested records may help settle > questions surrounding the Pentagon and Shanksville controversies, as > well as others. Release of these records could also help overcome > future claims of release exemption by the FBI for other 9/11 records > requests. From smallpox911 at gmail.com Sun Nov 7 17:19:17 2010 From: smallpox911 at gmail.com (small Pox) Date: Sun, 7 Nov 2010 14:19:17 -0800 (PST) Subject: *** FBI gets a warm welcome in Chicago for their EXCELLENT performance - cheers to NEW CONS *** References: <73cd58e5-5aae-4d90-93fa-5bd481f8da62@y23g2000yqd.googlegroups.com> Message-ID: <261215f5-f71e-4728-90ee-284d701fda9c@x4g2000pre.googlegroups.com> On Nov 2, 10:03?am, t... at sevak.isi.edu (Thomas A. Russ) wrote: > silver light writes: > > *** FBI gets a warm welcome in Chicago for their EXCELLENT performance > > - cheers to NEW CONS *** > > Oh geez. ?Just when we've beaten back the infix hordes, someone comes up > and suggests replacing CONS with something, new different and most > likely inferior. > > - Grumpy Old Programmer. > > -- > Thomas A. Russ, ?USC/Information Sciences Institute Little-Known 9/11 Truth Organization Strikes Gold in Court Action Against NIST, Unearths Striking Video/Photo WTC Evidence Written by Eli Rika Saturday, 06 November 2010 Over the last century, the most astounding historical discoveries of man-made artifacts have often been accomplished by well-funded, highly experienced researchers. From the excavation of King Tut?s tomb to the sighting of the sunken Titanic, stunning finds have required immense financial and human resources, as well as the leadership by distinguished. So, how did a mountain of never-before-seen footage used in NIST?s World Trade Center investigations get exposed to the light of day last month? Was it the work of a billionaire adventurer? Not quite. You can thank an upstart non-profit, the International Center for 9/11 Studies, whose efforts have at last borne fruit. The International Center for 9/11 Studies was founded in 2008 by Director James Gourley, a Texas lawyer who began questioning the events of 9/11 after watching a presentation given by David Ray Griffin on C-SPAN. ?I was just floored by what I was hearing,? Gourley explained, ?and I?ve been looking into 9/11 ever since then. From philip at semanchuk.com Sun Nov 7 19:01:10 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Sun, 7 Nov 2010 19:01:10 -0500 Subject: Silly newbie question - Carrot character (^) In-Reply-To: <20101106104502.dd0456bb.darcy@druid.net> References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> <20101106104502.dd0456bb.darcy@druid.net> Message-ID: On Nov 6, 2010, at 10:45 AM, D'Arcy J.M. Cain wrote: > On Sat, 6 Nov 2010 10:22:47 -0400 > Philip Semanchuk wrote: >>> The tutorial isn't meant as an exhaustive lesson on every single Python >>> feature. >> >> I agree, and I don't expect otherwise. My point was that if the >> tutorial doesn't mention a feature, the only other place to learn about >> it (on python.org) is the language ref. Some people might think the >> language ref is a fine place to direct newcomers to Python. I don't. > > I don't think that anyone was suggesting the reference as the first > place to send newcomers. Hi D'Arcy, I agree, no one -- not even I -- suggested that. The tutorial is always the first stop. > You send them there when they need something > beyond the basics. But IMO this is still a problem. After the tutorial, then what? Someone who has read the tutorial can still be new to Python by my definition. You may feel that the current language ref is OK for newcomers. I don't, and that's my point. > I think the only issue here is that operators are > pretty basic and that specific thing is missing in the tutorial. It > would be a mistake to write a whole new document because the tutorial > is missing one thing. Better would be to propose an operators section. The issue is not just operators. As I mentioned, the tutorial doesn't cover decorators, assert, exec, ternary if, and maybe a few other things. IMO that's fine. A tutorial should introduce the basics. I'm sure we could have a fine argument about what features of Python are basic and which are advanced, but I'd rather not as long as we can agree with Steven D'Aprano's comment that "The tutorial isn't meant as an exhaustive lesson on every single Python feature". I certainly agree with that. Personally, I liked using the tutorial for learning Python. It's readable. But after getting familiar with the language I wanted to move on to something more structured. I also realized that the tutorial didn't cover every aspect of the language because I saw references in code and discussions to things that weren't mentioned in the tutorial. I didn't feel like the python.org documentation provided an obvious next step, though, because I started with Python 2.3, and the language reference was still entitled "for language lawyers" back then. The section's name may have changed since then, but it looks like the style hasn't changed much. I believe the lack of a complete, friendly post-tutorial document to read made learning Python more difficult for me. >> I realize that the Python Foundation doesn't have infinite resources >> to work with, so maybe they'd love to create & maintain a more readable >> language reference if they had time/money/people. I don't hear anyone >> talk about it, though. > > Lots of people talk. Action, not so much. How about you? Are you > ready to start writing a new reference manual? First you suggest that writing a whole new document would be a mistake, then you encourage me to do it. =) The old open source challenge of "If you don't like it, fix it" is liberating but it's also a nifty way of changing the subject. Whether or not I can or will fix a problem doesn't make my criticism any more or less legitimate which (I thought) was the issue at hand. To answer your question: no, I'm not willing to start writing a new reference manual. For one thing, I don't think it's wanted judging by the response I've seen here. I see a lot of people saying "what we have is fine". To put it another way, based on this small sample size survey, opinions are mixed on the current state of the documentation. The effort required to make substantial changes (e.g. create a reference manual that's sort of a marriage of the tutorial and the language spec) is large but would likely result in very little net improvement as perceived by the community as a whole. To put it a fifth way (Sir Galahad: "third, sir") -- people learn differently. Cheers Philip From jason.heeris at gmail.com Sun Nov 7 19:19:45 2010 From: jason.heeris at gmail.com (Jason) Date: Sun, 7 Nov 2010 16:19:45 -0800 (PST) Subject: Cross compiling (i386 from amd64) with distutils Message-ID: My situation is this: I have a Diamond Systems single-board computer with a matching GPIO board. DS have a library for controlling the GPIO board... but it's a static library (libdscud-6.02.a) with an accompanying header (dscud.h). I'd like to create a Python extension to use the device. The architecture of the SBC is 486, and it runs Debian Squeeze/Grip. While it is possible to develop on it directly, I'd rather use my desktop machine (Debian Squeeze, amd64). If I write a simple C program to control the device, I'd include the header file and cross-compile it like so: gcc -m32 -march=i386 -lpthread -I/usr/local/dscud-6.02 -o dio dio.c \ /usr/local/dscud-6.02/libdscud-6.02.a To get myself started with the Python extension, I've basically taken the "noddy" demo[1] and thrown in a function call from the DSC library just to see if I can get something to build. My distutils setup.py looks like: ---- from distutils.core import setup, Extension module1 = Extension('noddy', sources = ['src/noddy.c'], libraries = ['pthread'], include_dirs = ['/usr/local/dscud-6.02'], extra_objects = ['/usr/local/dscud-6.02/libdscud-6.02.a'], extra_compile_args = ['-m32', '-march=i386']) setup(name = 'Noddy', version = '1.0', description = 'This is a demo package', ext_modules = [module1]) ---- This works fine on the target machine with "python setup.py build", but when I try it on my desktop machine, I get: ---- $ python setup.py build running build running build_ext building 'noddy' extension creating build creating build/temp.linux-x86_64-2.6 creating build/temp.linux-x86_64-2.6/src gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/local/dscud-6.02 -I/usr/include/ python2.6 -c src/noddy.c -o build/temp.linux-x86_64-2.6/src/noddy.o -m32 - march=i386 In file included from /usr/include/python2.6/Python.h:58, from src/noddy.c:1: /usr/include/python2.6/pyport.h:694:2: error: #error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)." error: command 'gcc' failed with exit status 1 ---- So is it possible to get distutils to cross compile something like this, and if so, what am I missing? Or am I using the wrong tool for the job? Target python ver. is 2.6. GCC is 4.4.5. Cheers, Jason [1] http://docs.python.org/extending/newtypes.html From martin at v.loewis.de Sun Nov 7 19:30:25 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Mon, 08 Nov 2010 01:30:25 +0100 Subject: Cross compiling (i386 from amd64) with distutils In-Reply-To: References: Message-ID: > So is it possible to get distutils to cross compile something like > this, and > if so, what am I missing? Or am I using the wrong tool for the job? At a minimum, you should be using the target's python binary. distutils has close-to-none cross-compiling support. You can solve some of the problems by editing the Makefile which it uses to learn the compiler options from. Regards, Martin From ldo at geek-central.gen.new_zealand Sun Nov 7 19:52:52 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 08 Nov 2010 13:52:52 +1300 Subject: Silly newbie question - Caret character (^) References: Message-ID: In message , Emile van Sebille wrote: > On 11/7/2010 2:26 AM Lawrence D'Oliveiro said... >> In message, Nobody wrote: >> >>> A reference manual tells you how to use the language. A specification >>> tells you how to implement it. >> >> Speaking as someone who has read more reference >> manuals/specifications/whatever you want to call them than I can count, I >> have never come across any such distinction. > > Surely you see the difference between RFC5321 and for example Courier's > man pages? One's the specification and the other's the reference manual. The language in question being ... ? From ldo at geek-central.gen.new_zealand Sun Nov 7 19:53:56 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 08 Nov 2010 13:53:56 +1300 Subject: ANN: PyQt v4.8.1 Released References: <3aqiq7-46p.ln1@archaeopteryx.softver.org.mk> Message-ID: In message , Robert Kern wrote: > Everyone here knew exactly what he meant. But if you don?t banana the right tomato, everybody could be grapefruit, right? You know what I mean. From jason.heeris at gmail.com Sun Nov 7 19:55:36 2010 From: jason.heeris at gmail.com (Jason) Date: Sun, 7 Nov 2010 16:55:36 -0800 (PST) Subject: Cross compiling (i386 from amd64) with distutils References: Message-ID: On Nov 8, 8:30?am, "Martin v. Loewis" wrote: > At a minimum, you should be using the target's python binary. distutils > has close-to-none cross-compiling support. Do you know if virtualenv allows installing a Python environment with a different architecture than that of the system Python install? I suspect not, but maybe there's an option I don't know about. > You can solve some of the > problems by editing the Makefile which it uses to learn the compiler > options from. I don't understand this - do you mean I should edit the Makefile in the actual distutils package, and somehow use that in my project instead of setup.py? ? Jason From invalid at invalid.invalid Sun Nov 7 20:07:03 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 8 Nov 2010 01:07:03 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jftftFelnU1@mid.individual.net> <87oca1b8ba.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On 2010-11-07, Steve Holden wrote: > On 11/7/2010 10:46 AM, Grant Edwards wrote: >> On 2010-11-07, Steve Holden wrote: >>> On 11/7/2010 8:23 AM, Grant Edwards wrote: >>> [...] >>>> (I bought 4:3 monitors before they got replaced by cheap 16:8 >>>> screens) >>> >>> I think you'll find the new aspect ration is 16:9. >> > "aspect ration". Sheesh. > >> I knew that. My keyboard didn't. >> >> I recently bought a close-out Lenovo T500 Thinkpad from their outlet >> because current models are now 16:9 instead of the older 16:10. My >> old 4:3 Thinkpad was still going strong, but I decided I'd better get >> a 16:10 while I could -- though I'd still prefer a 4:3. >> > The thing that *really* pisses me off is that you *used* to be able to > get 1920 x 1200 15" displays, but *now* you are lucky to go above 1080 > vertical pixels even in a 17" laptop display. I don't want the > resolution of my displays dictated by the resolution of my (current) > media, yet it seems that's what's happened in the laptop market. It's getting really hard to find high-DPI displays on laptops any more. 1600x1200 used to be available on 16" laptop displays, and that looked great. Even my old 15" thinkpad at 1400x1050 wasn't bad. > I got a Lenovo T60 a while back as a touchpad machine. Wondering about > switching that to Linux, but I haven't seen any touchpad distros in > action yet. -- Grant From robert.kern at gmail.com Sun Nov 7 20:26:51 2010 From: robert.kern at gmail.com (Robert Kern) Date: Sun, 07 Nov 2010 19:26:51 -0600 Subject: ANN: PyQt v4.8.1 Released In-Reply-To: References: <3aqiq7-46p.ln1@archaeopteryx.softver.org.mk> Message-ID: On 2010-11-07 18:53 , Lawrence D'Oliveiro wrote: > In message, Robert Kern > wrote: > >> Everyone here knew exactly what he meant. > > But if you don?t banana the right tomato, everybody could be grapefruit, > right? > > You know what I mean. And as I reiterated in the part that you snipped, he is not using "commercial" as a synonym for "proprietary". It is the license that he sells commercially. -- 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 yuwenhuan at gmail.com Sun Nov 7 20:30:23 2010 From: yuwenhuan at gmail.com (Wenhuan Yu) Date: Sun, 7 Nov 2010 19:30:23 -0600 Subject: http error 301 for urlopen Message-ID: I tried to open a link with urlopen: import urllib2 alink = " http://feeds.nytimes.com/click.phdo?i=ff074d9e3895247a31e8e5efa5253183" f = urllib2.urlopen(alink) print f.read() and got the followinig error: urllib2.HTTPError: HTTP Error 301: The HTTP server returned a redirect error tha t would lead to an infinite loop. The last 30x error message was: Moved Permanently I can open the link in browser. Any way to get solve this? Thanks. Wen -------------- next part -------------- An HTML attachment was scrubbed... URL: From jason.heeris at gmail.com Sun Nov 7 20:41:20 2010 From: jason.heeris at gmail.com (Jason) Date: Sun, 7 Nov 2010 17:41:20 -0800 (PST) Subject: Cross compiling (i386 from amd64) with distutils References: Message-ID: <8cc6791f-5ed8-479f-bd1c-adc808bd048d@n32g2000pre.googlegroups.com> On Nov 8, 8:55?am, Jason wrote: > Do you know if virtualenv allows installing a Python environment with > a different architecture than that of the system Python install? I > suspect not, but maybe there's an option I don't know about. Found a better solution, which is to just compile Python from source to be 32 bit. This is from: http://indefinitestudies.org/2010/02/08/how-to-build-32-bit-python-on-ubuntu-9-10-x86_64/ Thanks for your help, Jason From darcy at druid.net Sun Nov 7 20:51:50 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sun, 7 Nov 2010 20:51:50 -0500 Subject: http error 301 for urlopen In-Reply-To: References: Message-ID: <20101107205150.ebb06684.darcy@druid.net> On Sun, 7 Nov 2010 19:30:23 -0600 Wenhuan Yu wrote: > I tried to open a link with urlopen: > > import urllib2 > alink = " > http://feeds.nytimes.com/click.phdo?i=ff074d9e3895247a31e8e5efa5253183" > f = urllib2.urlopen(alink) > print f.read() > > and got the followinig error: > > urllib2.HTTPError: HTTP Error 301: The HTTP server returned a redirect error > that would lead to an infinite loop. > The last 30x error message was: > Moved Permanently > > I can open the link in browser. Any way to get solve this? Thanks. I checked with my tools and was told that it redirects more than five times. Maybe it's not infinite but too many for urlopen. Or, maybe the browser just ignores the extra redirects and the part of the page with the redirects isn't critical for viewing it. I think that you are going to have to investigate the HTML manually and follow all the individual links to find the problem. You may have to put in a bug request with the New York Times. Good luck with that. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From roy at panix.com Sun Nov 7 20:54:30 2010 From: roy at panix.com (Roy Smith) Date: Sun, 07 Nov 2010 20:54:30 -0500 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jftftFelnU1@mid.individual.net> <87oca1b8ba.fsf.mdw@metalzone.distorted.org.uk> Message-ID: In article , Grant Edwards wrote: > It's getting really hard to find high-DPI displays on laptops any > more. 1600x1200 used to be available on 16" laptop displays, and that > looked great. Even my old 15" thinkpad at 1400x1050 wasn't bad. My 15" MacBook Pro is 1680 x 1050. From nobody at nowhere.com Sun Nov 7 21:41:29 2010 From: nobody at nowhere.com (Nobody) Date: Mon, 08 Nov 2010 02:41:29 +0000 Subject: http error 301 for urlopen References: Message-ID: On Sun, 07 Nov 2010 20:51:50 -0500, D'Arcy J.M. Cain wrote: >> urllib2.HTTPError: HTTP Error 301: The HTTP server returned a redirect error >> that would lead to an infinite loop. >> The last 30x error message was: >> Moved Permanently >> >> I can open the link in browser. Any way to get solve this? Thanks. > > I checked with my tools and was told that it redirects more than five > times. Maybe it's not infinite but too many for urlopen. The default value of urllib2.HTTPRedirectHandler.max_redirections is 10. Setting it to 11 allows the request to complete. From wuwei23 at gmail.com Sun Nov 7 22:28:52 2010 From: wuwei23 at gmail.com (alex23) Date: Sun, 7 Nov 2010 19:28:52 -0800 (PST) Subject: functions, list, default parameters References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <20101021235138.609fe668@geekmail.INVALID> <87pquk3ehs.fsf.mdw@metalzone.distorted.org.uk> <4cd3c72b$0$30004$c3e8da3$5496439d@news.astraweb.com> <8739rg2ceb.fsf.mdw@metalzone.distorted.org.uk> <4cd4cc74$0$30004$c3e8da3$5496439d@news.astraweb.com> <87bp62eig9.fsf.mdw@metalzone.distorted.org.uk> <87y696cjjh.fsf.mdw@metalzone.distorted.org.uk> Message-ID: m... at distorted.org.uk (Mark Wooding) wrote: > And the advantage of all of this typing over ['missing'] is what, > precisely? No chance of the sentinel object being accidentally mutated would be the big one for me, but clarity of intent would be a close second. From cwc at cwc.name Sun Nov 7 22:50:44 2010 From: cwc at cwc.name (CWC) Date: Sun, 7 Nov 2010 19:50:44 -0800 (PST) Subject: Making ActivePython and Python co-exist on Windows References: Message-ID: On Nov 7, 12:34?pm, Benjamin Kaplan wrote: > ActivePython is the same thing as the "normal" Python. They just > bundle the standard Python 3.1.2 distribution with a couple of extra > packages in a convenient installer for you. Thanks, Ben! Based on your response, I decided to go ahead and install ActivePython 3.1.2. From " " at libero.it Sun Nov 7 23:42:41 2010 From: " " at libero.it (not1xor1 (Alessandro)) Date: Mon, 08 Nov 2010 04:42:41 GMT Subject: subclassing str In-Reply-To: References: Message-ID: <5dLBo.1024$w8.406@twister2.libero.it> Il 07/11/2010 07:41, Chris Rebert wrote: > You could subclass UserString instead of str; all of UserString's > methods seem to ensure that instances of the subclass rather than just > plain strs or UserStrings are returned. See > http://docs.python.org/library/userdict.html#UserString.UserString I'll have a look at it, thanks > But you should also consider whether your additions absolutely *must* > be methods. Merely instead defining some functions that take strings > as parameters is obviously a simpler, and probably more performant, > approach. I regularly save web pages (mostly scientific research abstracts) from various web sites and use a python script to strip them of ads and unneeded informations, embedding the images directly in the html file (as base64 encoded data) and at times joining multiple pages into just one since those sites often change the format of their files I've to modify my script accordingly I'm already using plain functions, but thought that wrapping most of them in a str subclass would let me save some time and yield cleaner and more manageable code > If you insist on subclassing str, there's no such hook; you'll have to > override all the methods yourself.* I'll try this route too (at least for the methods I need) thanks for your help -- bye !(!1|1) From nagle at animats.com Mon Nov 8 01:28:10 2010 From: nagle at animats.com (John Nagle) Date: Sun, 07 Nov 2010 22:28:10 -0800 Subject: http error 301 for urlopen In-Reply-To: References: Message-ID: <4cd7987e$0$1674$742ec2ed@news.sonic.net> On 11/7/2010 5:51 PM, D'Arcy J.M. Cain wrote: > On Sun, 7 Nov 2010 19:30:23 -0600 > Wenhuan Yu wrote: >> I tried to open a link with urlopen: >> >> import urllib2 >> alink = " >> http://feeds.nytimes.com/click.phdo?i=ff074d9e3895247a31e8e5efa5253183" >> f = urllib2.urlopen(alink) >> print f.read() >> >> and got the followinig error: >> >> urllib2.HTTPError: HTTP Error 301: The HTTP server returned a redirect error >> that would lead to an infinite loop. >> The last 30x error message was: >> Moved Permanently >> >> I can open the link in browser. Any way to get solve this? Thanks. > > I checked with my tools and was told that it redirects more than five > times. Maybe it's not infinite but too many for urlopen. Or, maybe > the browser just ignores the extra redirects and the part of the page > with the redirects isn't critical for viewing it. I think that you are > going to have to investigate the HTML manually and follow all the > individual links to find the problem. You may have to put in a bug > request with the New York Times. Good luck with that. It's the New York Times' paywall. They're trying to set a cookie, and will redirect the URL until you store and return the cookie. John Nagle From johann.spies at gmail.com Mon Nov 8 02:47:31 2010 From: johann.spies at gmail.com (Johann Spies) Date: Mon, 8 Nov 2010 09:47:31 +0200 Subject: suds: how to set proxy? Message-ID: According to the suds documentation I can set the proxy setting like this: d = dict(http='host:80', https='host:443', ...) client.set_options(proxy=d) My problem is that you can only do that after 'client' was initiated like this: client = Client(url) And I need the proxy to reach the url. I have tried the following ending in a SYN_SENT each time - ignoring the proxy settings: proxy = dict(http='proxy.sun.ac.za:3128', https='proxy.sun.ac.za:3128') url = 'url_of_wdsl' t = HttpAuthenticated() client = Client(url, proxy = proxy, transport = t, username='myusername', password='pw') or url = 'url_of_wdsl' t = HttpAuthenticated() client = Client(url, transport = t, username='myusername', password='pw') client.set_options(proxy=proxy) So how do I get suds to respect the proxy setting? Regards Johann -- ?May grace and peace be yours in abundance through the full knowledge of God and of Jesus our Lord! ?His divine power has given us everything we need for life and godliness through the full knowledge of the one who called us by his own glory and excellence. ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ?2 Pet. 1:2b,3a From ldo at geek-central.gen.new_zealand Mon Nov 8 03:06:43 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 08 Nov 2010 21:06:43 +1300 Subject: Popen Question References: <891a9a80-c30d-4415-ac81-bddd0b564fa6@g13g2000yqj.googlegroups.com> Message-ID: In message , Chris Torek wrote: > ['/bin/sh', '-c', 'echo', '$MYVAR'] > > (with arguments expressed as a Python list). /bin/sh takes the > string after '-c' as a command, and the remaining argument(s) if > any are assigned to positional parameters ($0, $1, etc). Doesn?t work. I don?t know what happens to the extra arguments, but they just seem to be ignored if -c is specified. sh -c 'echo hi' echoes ?hi?, while sh -c echo hi just outputs a blank line. From ladasky at my-deja.com Mon Nov 8 03:06:46 2010 From: ladasky at my-deja.com (John Ladasky) Date: Mon, 8 Nov 2010 00:06:46 -0800 (PST) Subject: functions, list, default parameters References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <20101021235138.609fe668@geekmail.INVALID> Message-ID: <5061318e-e847-4b63-b5fa-5ea62db7ee17@w38g2000pri.googlegroups.com> On Nov 1, 7:30?pm, Lawrence D'Oliveiro wrote: > In message <20101021235138.609fe... at geekmail.INVALID>, Andreas Waldenburger > wrote: > > > While not very commonly needed, why should a shared default argument be > > forbidden? > > Because it?s safer to disallow it than to allow it. That's why Java is the way that it is, right? It tries -- too hard, some would say -- to "protect" the programmer from making "mistakes." From ldo at geek-central.gen.new_zealand Mon Nov 8 03:07:15 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 08 Nov 2010 21:07:15 +1300 Subject: Why "flat is better than nested"? References: Message-ID: In message , rustom wrote: > If you take zen seriously you dont get it > If you dont take zen seriously you dont get it > That -- seriously -- is zen I don?t get it. From martin at v.loewis.de Mon Nov 8 03:16:28 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Mon, 08 Nov 2010 09:16:28 +0100 Subject: Cross compiling (i386 from amd64) with distutils In-Reply-To: References: Message-ID: <4CD7B1DC.5080306@v.loewis.de> >> You can solve some of the >> problems by editing the Makefile which it uses to learn the compiler >> options from. > > I don't understand this - do you mean I should edit the Makefile in > the actual distutils package, and somehow use that in my project > instead of setup.py? No. A python *installation* has a Makefile, in config/Makefile. If you want distutils to use different options, you could edit this Makefile. Regards, Martin From jason.heeris at gmail.com Mon Nov 8 04:06:31 2010 From: jason.heeris at gmail.com (Jason) Date: Mon, 8 Nov 2010 01:06:31 -0800 (PST) Subject: Cross compiling (i386 from amd64) with distutils References: <4CD7B1DC.5080306@v.loewis.de> Message-ID: On Nov 8, 4:16?pm, "Martin v. Loewis" wrote: > No. A python *installation* has a Makefile, in config/Makefile. If > you want distutils to use different options, you could edit this > Makefile. Oh, I see what you mean. But then it would affect *everything* I build on that machine, so I'll stick with the "separate 32-bit installation" approach. Cheers, Jason From mdw at distorted.org.uk Mon Nov 8 04:43:27 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Mon, 08 Nov 2010 09:43:27 +0000 Subject: Popen Question References: <891a9a80-c30d-4415-ac81-bddd0b564fa6@g13g2000yqj.googlegroups.com> Message-ID: <87hbfs9mm8.fsf.mdw@metalzone.distorted.org.uk> Lawrence D'Oliveiro writes: > In message , Chris Torek wrote: > > > ['/bin/sh', '-c', 'echo', '$MYVAR'] > > > > (with arguments expressed as a Python list). /bin/sh takes the > > string after '-c' as a command, and the remaining argument(s) if > > any are assigned to positional parameters ($0, $1, etc). > > Doesn?t work. What doesn't work? You were being given an explanation, not a solution. > I don?t know what happens to the extra arguments, but they just seem > to be ignored if -c is specified. The argument to -c is taken as a shell script; the remaining arguments are made available as positional parameters to the script as usual (only starting with $0 rather than $1, for some unknown reason). -- [mdw] From see.my.homepage at gmail.com Mon Nov 8 06:06:01 2010 From: see.my.homepage at gmail.com (Maciej Sobczak) Date: Mon, 8 Nov 2010 03:06:01 -0800 (PST) Subject: YAMI4 v. 1.2.0 released Message-ID: <9e796ac5-04db-4bd5-aec4-5122729b604e@x42g2000yqx.googlegroups.com> Hello, I am pleased to announce that the new version of YAMI4, 1.2.0, has been just released and is available for download: http://www.inspirel.com/yami4/ The most important addition for Python programmers is the Python 2.5+ module that complements the already existing Python 3.x library. Thanks to this, both branches of the language are now properly supported. The following functional improvements were added in all modules: - Keepalive option for TCP/IP. - Propagation of events related to connection management. - Ability to customize the management of slow (overflowing) receivers in the publish-subscribe scenario. Please see the changelog.txt file for the detailed list of improvements. -- Maciej Sobczak * http://www.inspirel.com From antoniodeharomillan at gmail.com Mon Nov 8 06:22:45 2010 From: antoniodeharomillan at gmail.com (Antonio de Haro Millan) Date: Mon, 8 Nov 2010 12:22:45 +0100 Subject: Python 2.7 Message-ID: I can not install "*Python Imaging Library 1.1.7 for Python 2.6* (Windows only)" because I have the *Python 2.7. *A solution please... ___________________ Antonio de Haro Millan www.de-haro.es Tf.34.639.972.872 -------------- next part -------------- An HTML attachment was scrubbed... URL: From felipe.bastosn at gmail.com Mon Nov 8 06:50:53 2010 From: felipe.bastosn at gmail.com (Felipe Bastos Nunes) Date: Mon, 8 Nov 2010 09:50:53 -0200 Subject: Python 2.7 In-Reply-To: References: Message-ID: Install the python 2.6.x :-) 2010/11/8, Antonio de Haro Millan : > I can not install "*Python Imaging Library 1.1.7 for Python 2.6* (Windows > only)" > because I have the *Python 2.7. *A solution please... > > ___________________ > Antonio de Haro Millan > www.de-haro.es > Tf.34.639.972.872 > -- Felipe Bastos Nunes From duane.kaufman at gmail.com Mon Nov 8 07:06:11 2010 From: duane.kaufman at gmail.com (TheSeeker) Date: Mon, 8 Nov 2010 04:06:11 -0800 (PST) Subject: Deditor 0.2.2 References: Message-ID: <6cdb5dd1-1868-4a6e-8b59-5b871f8d412e@42g2000prt.googlegroups.com> On Nov 6, 7:06?am, Kruptein wrote: > Hey, > > I released version 0.2.2 of my pythonic text-editor ?Deditor. > It adds the use of projects, a project is a set of files which you can > open all at once to make development much faster and easier. > > For more information visit launchpad:http://launchpad.net/deditor > > I also uploaded a video to introduce you to deditor:http://www.youtube.com/watch?v=hS8xBu-39VI > (note: youtube is still processing the file so you might have to wait > a bit to see it) Hi, I might have missed this, but it seems deditor requires Python above 2.5? It would be nice to mention the requirements on the home page somewhere. Thanks, Duane From brf256 at gmail.com Mon Nov 8 07:14:03 2010 From: brf256 at gmail.com (brf256 at gmail.com) Date: Mon, 8 Nov 2010 12:14:03 +0000 Subject: Python 2.7 Message-ID: <1170667852-1289218443-cardhu_decombobulator_blackberry.rim.net-396203-@bda480.bisx.prod.on.blackberry> use python 2.6 :] - Braden Faulkner From drobinow at gmail.com Mon Nov 8 07:24:38 2010 From: drobinow at gmail.com (David Robinow) Date: Mon, 8 Nov 2010 07:24:38 -0500 Subject: Python 2.7 In-Reply-To: References: Message-ID: On Mon, Nov 8, 2010 at 6:22 AM, Antonio de Haro Millan wrote: > I can not install?"Python Imaging Library 1.1.7 for Python 2.6?(Windows > only)" > because I have the?Python 2.7. A solution please... download http://effbot.org/media/downloads/PIL-1.1.7/win32-py2.7.exe From roy at panix.com Mon Nov 8 07:39:46 2010 From: roy at panix.com (Roy Smith) Date: Mon, 08 Nov 2010 07:39:46 -0500 Subject: functions, list, default parameters References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <20101021235138.609fe668@geekmail.INVALID> Message-ID: In article , Lawrence D'Oliveiro wrote: > In message <20101021235138.609fe668 at geekmail.INVALID>, Andreas Waldenburger > wrote: > > > While not very commonly needed, why should a shared default argument be > > forbidden? > > Because it???s safer to disallow it than to allow it. The best way to deal with this is to have some kind of knob you can turn to enable or disable warnings about these sorts of things. Could be a command-line flag, a stand-alone tool (i.e. pylint), or even something in-line (like perl' 'use strict' directive). Good engineering practice would be use enable "debug mode" during testing and review all the warnings to see which ones surprise you. From simon at brunningonline.net Mon Nov 8 08:13:20 2010 From: simon at brunningonline.net (Simon Brunning) Date: Mon, 8 Nov 2010 13:13:20 +0000 Subject: A question about yield In-Reply-To: References: <40dd2ea7-0b1d-4600-8fc7-a2d0027b98c0@f16g2000prj.googlegroups.com> Message-ID: On 7 November 2010 18:14, Chris Rebert wrote: > On Sun, Nov 7, 2010 at 9:56 AM, chad wrote: >> But what happens if the input file is say 250MB? Will all 250MB be >> loaded into memory at once? > > No. As I said, the file will be read from 1 line at a time, on an > as-needed basis; which is to say, "line-by-line". IIRC, it's somewhere in between. Python will read the file in blocks. If only *looks* like it's reading the file line by line. -- Cheers, Simon B. From neilc at norwich.edu Mon Nov 8 08:29:05 2010 From: neilc at norwich.edu (Neil Cerutti) Date: 8 Nov 2010 13:29:05 GMT Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> <87aalrjkty.fsf@benfinney.id.au> <8jd3m9Fr55U7@mid.individual.net> <4cd50e7e$0$30004$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8jqc90FbsnU4@mid.individual.net> On 2010-11-06, Steven D'Aprano wrote: >>> styles = [ >>> ("normal", "image", MainWindow.ColorsNormalList), >>> ("highlighted", "highlight", MainWindow.ColorsHighlightedList), >>> ("selected", "select", MainWindow.ColorsSelectedList)] >> >> Code should be utilitarian rather than ornate, Shaker rather >> than Victorian. > > Perhaps, but lining up the columns in a 3x3 table is hardly > "ornate". > > I have mixed feelings here. On the one hand, there's no doubt > in my mind that the extra whitespace and aligned columns make > the data easier to read for me. On the other hand, I know that > it is easy to fall into the trap of spending hours carefully > aligning code that doesn't need to be aligned. Some sort of comprehension test is probably required to know for sure, but I doubt the code benefits much at all from the columns. styles = [ ("normal", "image", MainWindow.ColorsNormalList), ("highlighted", "highlight", MainWindow.ColorsHighlightedList), ("selected", "select", MainWindow.ColorsSelectedList)] Moreover, I jump the gun early on tables like this. styles = [csv.reader(open("styles.csv", newlines=''))] Maybe too early. ;) -- Neil Cerutti From neilc at norwich.edu Mon Nov 8 08:50:55 2010 From: neilc at norwich.edu (Neil Cerutti) Date: 8 Nov 2010 13:50:55 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jftftFelnU1@mid.individual.net> Message-ID: <8jqdhvFbsnU5@mid.individual.net> On 2010-11-07, Lawrence D'Oliveiro wrote: > In message <8jftftFelnU1 at mid.individual.net>, Neil Cerutti wrote: > >> The handsome ':' terminator of if/elif/if statements allows us to >> omit a newline, conserving vertical space. This improves the >> readability of certain constructs. >> >> if x: print(x) >> elif y: print(y) >> else: print() > > I would never do that. ???Conserving vertical space??? seems a > stupid reason for doing it. In C, I even go the opposite way: > > if (x) > { > printf(..., x); > } > else if (y) > { > printf(..., y); > } > else > { > printf(...); > } /*if*/ Interesting. I find conserving vertical space to be a big win. I understand why you'd enforce braces for virtually all code bodies in C. In C, I'm giving up the most obvious form of expression for something obviously more robust. In Python, there's no such trade-off. Forbidding one-line conditional statements in Python would sacrifice succinctness for nothing. -- Neil Cerutti From jeanmichel at sequans.com Mon Nov 8 09:01:42 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 08 Nov 2010 15:01:42 +0100 Subject: Deditor 0.2.2 In-Reply-To: <6cdb5dd1-1868-4a6e-8b59-5b871f8d412e@42g2000prt.googlegroups.com> References: <6cdb5dd1-1868-4a6e-8b59-5b871f8d412e@42g2000prt.googlegroups.com> Message-ID: <4CD802C6.9010603@sequans.com> TheSeeker wrote: > On Nov 6, 7:06 am, Kruptein wrote: > >> Hey, >> >> I released version 0.2.2 of my pythonic text-editor Deditor. >> It adds the use of projects, a project is a set of files which you can >> open all at once to make development much faster and easier. >> >> For more information visit launchpad:http://launchpad.net/deditor >> >> I also uploaded a video to introduce you to deditor:http://www.youtube.com/watch?v=hS8xBu-39VI >> (note: youtube is still processing the file so you might have to wait >> a bit to see it) >> > > Hi, > I might have missed this, but it seems deditor requires Python above > 2.5? > > It would be nice to mention the requirements on the home page > somewhere. > > Thanks, > Duane > I already point that on the last release. You should really just consider writing the requirements (python & wx). JM From invalid at invalid.invalid Mon Nov 8 09:57:18 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 8 Nov 2010 14:57:18 +0000 (UTC) Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jftftFelnU1@mid.individual.net> <87oca1b8ba.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On 2010-11-08, Roy Smith wrote: > In article , > Grant Edwards wrote: > >> It's getting really hard to find high-DPI displays on laptops any >> more. 1600x1200 used to be available on 16" laptop displays, and that >> looked great. Even my old 15" thinkpad at 1400x1050 wasn't bad. > > My 15" MacBook Pro is 1680 x 1050. Yep, Apple is one of the holdouts that still offers 16:10 high resolution displays. That's the same format/resolution that Lenovo used to offer before they switched to 16:9. -- Grant Edwards grant.b.edwards Yow! Boy, am I glad it's at only 1971... gmail.com From steve at holdenweb.com Mon Nov 8 10:55:46 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 08 Nov 2010 10:55:46 -0500 Subject: Compare source code In-Reply-To: <8jqdhvFbsnU5@mid.individual.net> References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jftftFelnU1@mid.individual.net> <8jqdhvFbsnU5@mid.individual.net> Message-ID: On 11/8/2010 8:50 AM, Neil Cerutti wrote: [...] > Interesting. I find conserving vertical space to be a big win. I > understand why you'd enforce braces for virtually all code bodies > in C. In C, I'm giving up the most obvious form of expression for > something obviously more robust. In Python, there's no such > trade-off. Forbidding one-line conditional statements in Python > would sacrifice succinctness for nothing. One-line conditional statements aren't "forbidden" or they would not be grammatically correct. Many stylists (and the PEP 8 style guide) eschew the single-line form as less readable because the guarded suites (in this case, simple statements) are not flagged as clearly by indentation or a trailing colon, and are therefore more likely to be missed by the casual reader. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From zinckiwi at gmail.com Mon Nov 8 11:17:30 2010 From: zinckiwi at gmail.com (Scott Gould) Date: Mon, 8 Nov 2010 08:17:30 -0800 (PST) Subject: Question about expression evaluation Message-ID: <295c7760-f122-41c3-9f00-0934d3395ab4@u25g2000pra.googlegroups.com> Hi folks, This is a head-scratcher to me. I occasionally get this error: --- File "/var/www/myproj/account/views.py", line 54, in account if request.account.is_instructor and request.account.contact and request.account.contact.relationship.institution_party_number: AttributeError: 'NoneType' object has no attribute 'relationship' --- I'm leaving out all the supporting code deliberately. My question is simple: if python short-circuits evaluation and "request.account.contact" is None, how is it even getting as far as "request.account.contact.relationship.institution_party_number"? Thanks! From pruebauno at latinmail.com Mon Nov 8 11:38:21 2010 From: pruebauno at latinmail.com (nn) Date: Mon, 8 Nov 2010 08:38:21 -0800 (PST) Subject: Question about expression evaluation References: <295c7760-f122-41c3-9f00-0934d3395ab4@u25g2000pra.googlegroups.com> Message-ID: On Nov 8, 11:17?am, Scott Gould wrote: > Hi folks, > > This is a head-scratcher to me. I occasionally get this error: > > --- > ? File "/var/www/myproj/account/views.py", line 54, in account > ? ? if request.account.is_instructor and request.account.contact and > request.account.contact.relationship.institution_party_number: > > AttributeError: 'NoneType' object has no attribute 'relationship' > --- > > I'm leaving out all the supporting code deliberately. My question is > simple: if python short-circuits evaluation and > "request.account.contact" is None, how is it even getting as far as > "request.account.contact.relationship.institution_party_number"? > > Thanks! Hard to tell without details. Maybe request.account.contact is an impure property with side effects? From gb345 at invalid.com Mon Nov 8 11:45:24 2010 From: gb345 at invalid.com (gb345) Date: Mon, 8 Nov 2010 16:45:24 +0000 (UTC) Subject: How to get dynamically-created fxn's source? References: Message-ID: In Peter Otten <__peter__ at web.de> writes: >gb345 wrote: >> For a project I'm working on I need a way to retrieve the source >> code of dynamically generated Python functions. (These functions >> are implemented dynamically in order to simulate "partial application" >> in Python.[1]) >Are you aware of functools.partial? >>>> from functools import partial >>>> def f(a, b, c, x, y, z): >... return a*x + b*y*y + c*z*z*z >... >>>> fstar = partial(f, x=1, y=2, z=3) >>>> fstar(1, 0, 0) >1 >>>> fstar(0, 1, 0) >4 >>>> fstar(0, 0, 1) >27 >>>> fstar.args, fstar.keywords >((), {'y': 2, 'x': 1, 'z': 3}) >>>> fstar.func > I was not aware of functools.partial. This makes the problem a lot easier. Thanks! G From malaclypse2 at gmail.com Mon Nov 8 11:48:07 2010 From: malaclypse2 at gmail.com (Jerry Hill) Date: Mon, 8 Nov 2010 11:48:07 -0500 Subject: Question about expression evaluation In-Reply-To: <295c7760-f122-41c3-9f00-0934d3395ab4@u25g2000pra.googlegroups.com> References: <295c7760-f122-41c3-9f00-0934d3395ab4@u25g2000pra.googlegroups.com> Message-ID: On Mon, Nov 8, 2010 at 11:17 AM, Scott Gould wrote: > --- > ?File "/var/www/myproj/account/views.py", line 54, in account > ? ?if request.account.is_instructor and request.account.contact and > request.account.contact.relationship.institution_party_number: > > AttributeError: 'NoneType' object has no attribute 'relationship' > --- > > I'm leaving out all the supporting code deliberately. Perhaps request.account is being mutated in another thread? -- Jerry From __peter__ at web.de Mon Nov 8 11:52:21 2010 From: __peter__ at web.de (Peter Otten) Date: Mon, 08 Nov 2010 17:52:21 +0100 Subject: Question about expression evaluation References: <295c7760-f122-41c3-9f00-0934d3395ab4@u25g2000pra.googlegroups.com> Message-ID: Scott Gould wrote: > Hi folks, > > This is a head-scratcher to me. I occasionally get this error: > > --- > File "/var/www/myproj/account/views.py", line 54, in account > if request.account.is_instructor and request.account.contact and > request.account.contact.relationship.institution_party_number: > > AttributeError: 'NoneType' object has no attribute 'relationship' > --- > > I'm leaving out all the supporting code deliberately. My question is > simple: if python short-circuits evaluation and > "request.account.contact" is None, how is it even getting as far as > "request.account.contact.relationship.institution_party_number"? Probably a race condition: contact is set to None after request.account.contact is evaluated, but before request.account.contact.relationship is evaluated. This may happen in your case because the underlying database was modified by a different user (I'm speculating). Here's a simulation: >>> class Contact: ... relationship = "SUCCESS" ... >>> class Account(object): ... def __init__(self): ... self._contact = Contact() ... @property ... def contact(self): ... try: return self._contact ... finally: self._contact = None ... >>> account = Account() >>> account.contact and account.contact.relationship Traceback (most recent call last): File "", line 1, in AttributeError: 'NoneType' object has no attribute 'relationship' You can avoid the problem with a different coding style: >>> account = Account() >>> try: ... print account.contact.relationship ... except AttributeError: ... print "failed" ... SUCCESS Peter From zinckiwi at gmail.com Mon Nov 8 12:45:29 2010 From: zinckiwi at gmail.com (Scott Gould) Date: Mon, 8 Nov 2010 09:45:29 -0800 (PST) Subject: Question about expression evaluation References: <295c7760-f122-41c3-9f00-0934d3395ab4@u25g2000pra.googlegroups.com> Message-ID: Thanks for the ideas, everyone. It's probably obvious that this is in a Django context, and while I do have WSGI configured to multi-thread its processes, there is nothing explicitly shared -- via threading, a multi-user situation, or otherwise -- about this data. It is entirely local to the request so I can't figure out how the "contact" object could change in a single line of code. But obviously there must be something going on like what you all suggest. I just can't figure out how. This is the entirety of the contact-producing code within Account: @property def contact(self): if not hasattr(self, '_contact'): self._contact = get_contact_for_id(self.profile.id) if self.profile and self.profile.id else None return self._contact As you can see, it's essentially read-only so once a self._contact always a self._contact. (Unless I'm misunderstanding something fundamental, which as an admitted amateur I could well be!) On Nov 8, 11:17?am, Scott Gould wrote: > Hi folks, > > This is a head-scratcher to me. I occasionally get this error: > > --- > ? File "/var/www/myproj/account/views.py", line 54, in account > ? ? if request.account.is_instructor and request.account.contact and > request.account.contact.relationship.institution_party_number: > > AttributeError: 'NoneType' object has no attribute 'relationship' > --- > > I'm leaving out all the supporting code deliberately. My question is > simple: if python short-circuits evaluation and > "request.account.contact" is None, how is it even getting as far as > "request.account.contact.relationship.institution_party_number"? > > Thanks! From jeff.hobbs at gmail.com Mon Nov 8 12:54:18 2010 From: jeff.hobbs at gmail.com (Jeff Hobbs) Date: Mon, 8 Nov 2010 09:54:18 -0800 (PST) Subject: Python 2.7 References: Message-ID: On Nov 8, 3:50?am, Felipe Bastos Nunes wrote: > Install the python 2.6.x :-) > > 2010/11/8, Antonio de Haro Millan : > > > I can not install "*Python Imaging Library 1.1.7 for Python 2.6* (Windows > > only)" > > because I have the *Python 2.7. *A solution please... If you need Python 2.7, PIL is available via pypm for ActivePython 2.7: http://code.activestate.com/pypm/pil/ Jeff From ian.g.kelly at gmail.com Mon Nov 8 12:57:08 2010 From: ian.g.kelly at gmail.com (Ian) Date: Mon, 8 Nov 2010 09:57:08 -0800 (PST) Subject: Popen Question References: <891a9a80-c30d-4415-ac81-bddd0b564fa6@g13g2000yqj.googlegroups.com> <87hbfs9mm8.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On Nov 8, 2:43?am, m... at distorted.org.uk (Mark Wooding) wrote: > > I don?t know what happens to the extra arguments, but they just seem > > to be ignored if -c is specified. > > The argument to -c is taken as a shell script; the remaining arguments > are made available as positional parameters to the script as usual (only > starting with $0 rather than $1, for some unknown reason). Perhaps this example better demonstrates what is going on: >>> p = subprocess.Popen(['echo one $0 three $1 five', 'two', 'four'], ... shell=True) one two three four five Cheers, Ian From __peter__ at web.de Mon Nov 8 13:06:18 2010 From: __peter__ at web.de (Peter Otten) Date: Mon, 08 Nov 2010 19:06:18 +0100 Subject: Question about expression evaluation References: <295c7760-f122-41c3-9f00-0934d3395ab4@u25g2000pra.googlegroups.com> Message-ID: Scott Gould wrote: > Thanks for the ideas, everyone. It's probably obvious that this is in > a Django context, and while I do have WSGI configured to multi-thread > its processes, there is nothing explicitly shared -- via threading, a > multi-user situation, or otherwise -- about this data. It is entirely > local to the request so I can't figure out how the "contact" object > could change in a single line of code. > > But obviously there must be something going on like what you all > suggest. I just can't figure out how. This is the entirety of the > contact-producing code within Account: > > @property > def contact(self): > if not hasattr(self, '_contact'): If one thread stops this point the _contact attribute is not yet set and another thread may trigger the if-suite, too. > self._contact = get_contact_for_id(self.profile.id) if self.profile > and self.profile.id else None > return self._contact > > As you can see, it's essentially read-only so once a self._contact > always a self._contact. (Unless I'm misunderstanding something > fundamental, which as an admitted amateur I could well be!) From __peter__ at web.de Mon Nov 8 13:07:23 2010 From: __peter__ at web.de (Peter Otten) Date: Mon, 08 Nov 2010 19:07:23 +0100 Subject: Question about expression evaluation References: <295c7760-f122-41c3-9f00-0934d3395ab4@u25g2000pra.googlegroups.com> Message-ID: Scott Gould wrote: > Thanks for the ideas, everyone. It's probably obvious that this is in > a Django context, and while I do have WSGI configured to multi-thread > its processes, there is nothing explicitly shared -- via threading, a > multi-user situation, or otherwise -- about this data. It is entirely > local to the request so I can't figure out how the "contact" object > could change in a single line of code. > > But obviously there must be something going on like what you all > suggest. I just can't figure out how. This is the entirety of the > contact-producing code within Account: > > @property > def contact(self): > if not hasattr(self, '_contact'): If one thread stops at this point the _contact attribute is not yet set and another thread may trigger the if-suite, too. > self._contact = get_contact_for_id(self.profile.id) if self.profile > and self.profile.id else None > return self._contact > > As you can see, it's essentially read-only so once a self._contact > always a self._contact. (Unless I'm misunderstanding something > fundamental, which as an admitted amateur I could well be!) From sridharr at activestate.com Mon Nov 8 13:30:10 2010 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Mon, 8 Nov 2010 10:30:10 -0800 Subject: Making ActivePython and Python co-exist on Windows In-Reply-To: References: Message-ID: <88FDA881-2EA1-4206-89A9-5E80E4DF6CE8@activestate.com> On 2010-11-07, at 12:34 PM, Benjamin Kaplan wrote: > On Sun, Nov 7, 2010 at 2:25 PM, CWC wrote: >> I'm new to Python. Is it possible to make ActivePython 3.12 and >> Python 3.12 co-exist on Windows? I've got an app which requires the >> former, but I want to stay with the latter, since I'm interested in >> getting into development. The main area of collision appears to be >> the Registry. >> -- > > ActivePython is the same thing as the "normal" Python. They just > bundle the standard Python 3.1.2 distribution with a couple of extra > packages in a convenient installer for you. Yup. And as the documentation details, http://docs.activestate.com/activepython/3.1/whatsincluded.html ActivePython includes PyWin32, Tkinter based on Tk 8.5 ... and PyPM for easy package management, http://code.activestate.com/pypm/ -srid From briank at logan.tv Mon Nov 8 13:42:34 2010 From: briank at logan.tv (Brian Krusic) Date: Mon, 8 Nov 2010 10:42:34 -0800 (PST) Subject: python dpx module Message-ID: <1068407369.51831289241754297.JavaMail.root@zmail> Hi all, Kind of at a loss here. trying to debug some old code belonging to some one else and I keep seeing an error; import dpx no module named dpx Would any one happen to know how I can get a hold if this elusive dpx Python module? From cjdrake at gmail.com Mon Nov 8 14:37:10 2010 From: cjdrake at gmail.com (Drake) Date: Mon, 8 Nov 2010 11:37:10 -0800 (PST) Subject: Intel C Compiler Message-ID: <8e65ce2e-6afd-4fc0-b4c5-741e99b62120@b19g2000prj.googlegroups.com> Hello, I'm an engineer who has access to the Intel C/C++ compiler (icc), and for the heck of it I compiled Python2.7 with it. Unsurprisingly, it compiled fine and functions correctly as far as I know. However, I was interested to discover that the icc compile printed literally thousands of various warnings and remarks. Examples: Parser/node.c(13): remark #2259: non-pointer conversion from "int" to "short" may lose significant bits n->n_type = type; Parser/metagrammar.c(156): warning #1418: external function definition with no prior declaration Py_meta_grammar(void) I was just wondering if anyone from the Python development team uses icc, or finds any value in the icc compilation info. Similarly, I would be interested to know if they use icc for benchmarking comparisons (yes, I know that Intel has been accused of crippling amd processors so let's not have a flame war please). Regards, Drake From stefan-usenet at bytereef.org Mon Nov 8 15:00:43 2010 From: stefan-usenet at bytereef.org (Stefan Krah) Date: Mon, 8 Nov 2010 21:00:43 +0100 Subject: Intel C Compiler In-Reply-To: <8e65ce2e-6afd-4fc0-b4c5-741e99b62120@b19g2000prj.googlegroups.com> References: <8e65ce2e-6afd-4fc0-b4c5-741e99b62120@b19g2000prj.googlegroups.com> Message-ID: <20101108200043.GA21291@yoda.bytereef.org> Drake wrote: > I'm an engineer who has access to the Intel C/C++ compiler (icc), and > for the heck of it I compiled Python2.7 with it. > > Unsurprisingly, it compiled fine and functions correctly as far as I > know. However, I was interested to discover that the icc compile > printed literally thousands of various warnings and remarks. > > Examples: > Parser/node.c(13): remark #2259: non-pointer conversion from "int" to > "short" may lose significant bits > n->n_type = type; I sometimes use icc. This is one of the most annoying warnings of the Intel compiler. See: http://software.intel.com/en-us/forums/showthread.php?t=62308 The problem is that the compiler issues this warning even when there is no way that significant bits could be lost. Stefan Krah From robert.kern at gmail.com Mon Nov 8 16:10:33 2010 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 08 Nov 2010 15:10:33 -0600 Subject: python dpx module In-Reply-To: <1068407369.51831289241754297.JavaMail.root@zmail> References: <1068407369.51831289241754297.JavaMail.root@zmail> Message-ID: On 11/8/10 12:42 PM, Brian Krusic wrote: > Hi all, > > Kind of at a loss here. > > trying to debug some old code belonging to some one else and I keep seeing an error; > > import dpx > no module named dpx > > Would any one happen to know how I can get a hold if this elusive dpx Python module? You'll have to ask them. I've never heard of it. I assume you have already checked Google. It might not be a publicly available module. -- 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 ghw at accutrol.com Mon Nov 8 16:56:50 2010 From: ghw at accutrol.com (ghw at accutrol.com) Date: Mon, 8 Nov 2010 16:56:50 -0500 Subject: populating a doubly-subscripted array Message-ID: <20101108214605.M50754@accutrol.com> What am I missing? I am using Python 3.1.2. ff = [[0.0]*5]*5 ff #(lists 5x5 array of 0.0) for i in range(5): for j in range(3): ff[i][j] = i*10+j print (i,j,ff[i][j]) # correctly prints ff array values ff # try this and see what happens! result of first print of ff [[0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0]] result of second print of ff 0 0 0 0 1 1 0 2 2 1 0 10 1 1 11 1 2 12 2 0 20 2 1 21 2 2 22 3 0 30 3 1 31 3 2 32 4 0 40 4 1 41 4 2 42 result of third print of ff [[40, 41, 42, 0.0, 0.0], [40, 41, 42, 0.0, 0.0], [40, 41, 42, 0.0, 0.0], [40, 41, 42, 0.0, 0.0], [40, 41, 42, 0.0, 0.0]] Obviously there is something missing in my understanding of how array values are populated. Why do all "rows" get populated with the same set of values (40, 41, 42)? Thanks for your help, Hamilton Woods From hansmu at xs4all.nl Mon Nov 8 17:35:13 2010 From: hansmu at xs4all.nl (Hans Mulder) Date: Mon, 08 Nov 2010 23:35:13 +0100 Subject: Popen Question In-Reply-To: References: <891a9a80-c30d-4415-ac81-bddd0b564fa6@g13g2000yqj.googlegroups.com> <87hbfs9mm8.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <4cd87b24$0$81481$e4fe514c@news.xs4all.nl> Ian wrote: > On Nov 8, 2:43 am, m... at distorted.org.uk (Mark Wooding) wrote: >>> I don?t know what happens to the extra arguments, but they just seem >>> to be ignored if -c is specified. >> The argument to -c is taken as a shell script; the remaining arguments >> are made available as positional parameters to the script as usual (only >> starting with $0 rather than $1, for some unknown reason). > > Perhaps this example better demonstrates what is going on: > >>>> p = subprocess.Popen(['echo one $0 three $1 five', 'two', 'four'], > ... shell=True) > one two three four five Maybe I'm thick, but I still don't understand. If I run a shell script, then the name of the script is in $0 and the first positional arguments is in $1, similar to how Python sets up sys.argv. But in this case the first positional argument is in $0. Why is that? Puzzled, -- HansM From robert.kern at gmail.com Mon Nov 8 17:36:36 2010 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 08 Nov 2010 16:36:36 -0600 Subject: populating a doubly-subscripted array In-Reply-To: <20101108214605.M50754@accutrol.com> References: <20101108214605.M50754@accutrol.com> Message-ID: On 11/8/10 3:56 PM, ghw at accutrol.com wrote: > What am I missing? I am using Python 3.1.2. > > ff = [[0.0]*5]*5 http://docs.python.org/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 torriem at gmail.com Mon Nov 8 18:12:54 2010 From: torriem at gmail.com (Michael Torrie) Date: Mon, 08 Nov 2010 16:12:54 -0700 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> Message-ID: <4CD883F6.5050307@gmail.com> On 11/06/2010 02:27 AM, Seebs wrote: > On 2010-11-06, Steve Holden wrote: >> If someone were to use a text editor which had always historically >> mangled whitespace I would find myself wondering why they found it >> necessary to restrict themselves to such stone-age tools. > > I have yet to find an editor that allows me to, well, *edit*, more > comfortably than vi. Indeed vi (or in my case, vim) works wonderfully well with python. I always use the following vim settings on python files: set sw=4 set ts=8 set softtabstop=4 set expandtab set ai If you set up a conditional thing in your vimrc to enable these settings for python files, you shouldn't have any more tab problems. From ldo at geek-central.gen.new_zealand Mon Nov 8 18:24:36 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 09 Nov 2010 12:24:36 +1300 Subject: functions, list, default parameters References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <8ivelpFif1U1@mid.individual.net> <4cca88bc$0$29987$c3e8da3$5496439d@news.astraweb.com> <8j1seqFa1eU2@mid.individual.net> Message-ID: In message , Robert Kern wrote: > On 11/4/10 2:07 AM, Lawrence D'Oliveiro wrote: > >> In message, Robert >> Kern wrote: >> >>> On 11/2/10 2:12 AM, Lawrence D'Oliveiro wrote: >>> >>>> In message, Robert >>>> Kern wrote: >>>> >>>>> "Immutable objects" are just those without an obvious API for >>>>> modifying them. >>>> >>>> They are ones with NO legal language constructs for modifying them. >>>> Hint: if a selector of some part of such an object were to occur on the >>>> LHS of an assignment, and that would raise an error, then the object is >>>> immutable. The interpreter already knows all this. >>> >>> Incorrect. RHS method calls can often modify objects. >> >> So bloody what? > > So examining LHS "selectors" is not sufficient for determining > immutability. Yes it is. All your attempts at counterexamples showed is that it is not necessary, not that it is not sufficient. From ben+python at benfinney.id.au Mon Nov 8 18:27:50 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 09 Nov 2010 10:27:50 +1100 Subject: populating a doubly-subscripted array References: Message-ID: <874obre6q1.fsf@benfinney.id.au> ghw at accutrol.com writes: > What am I missing? You're missing the fact that Python doesn't have a built-in ?array? type, nor really ?subscripts? for them. > ff = [[0.0]*5]*5 This creates a float object, ?0.0?. It then creates a list containing five references to that same object. It then creates a new list containing five references to the first list. It then binds the name ?ff? to the outer list. ff --+ | V +---+---+---+---+---+ | . | . | . | . | . | +-|-+-|-+-|-+-|-+-|-+ | | | | | +---+---+---+---+---+ | V +---+---+---+---+---+ | . | . | . | . | . | +-|-+-|-+-|-+-|-+-|-+ | | | | | +---+---+---+---+---+ | V 0.0 > ff #(lists 5x5 array of 0.0) Nope. It outputs the structure described above, serialised. There is no distinction in that output between objects that are different but have the same value, versus the same object displayed several times. Try the ?is? (identity) and ?==? (equality) operators to see the difference. > for i in range(5): > for j in range(3): > ff[i][j] = i*10+j This binds different integer values at some of the references in the inner list. As the loops continue, the reference used to get at the inner list is different; but it's always the same list. > print (i,j,ff[i][j]) # correctly prints ff array values It prints the values in the inner list immediately after they're assigned. As the loops continue, the references are re-bound to other integer values. > ff # try this and see what happens! After all the changes, the only references which have actually been re-bound are the first three items in the inner list. ff --+ | V +---+---+---+---+---+ | . | . | . | . | . | +-|-+-|-+-|-+-|-+-|-+ | | | | | +---+---+---+---+---+ | V +---+---+---+---+---+ | . | . | . | . | . | +-|-+-|-+-|-+-|-+-|-+ | | | | | | | | +---+---+ | | | | V V V V 40 41 42 0.0 > result of third print of ff > [[40, 41, 42, 0.0, 0.0], [40, 41, 42, 0.0, 0.0], > [40, 41, 42, 0.0, 0.0], [40, 41, 42, 0.0, 0.0], > [40, 41, 42, 0.0, 0.0]] > > Obviously there is something missing in my understanding of how array > values are populated. Why do all "rows" get populated with the same > set of values (40, 41, 42)? Because, as the above diagram hopefully clarifies, a list isn't an array, and its references aren't rows. If you actually want an array, there isn't a built-in type for it. Instead, use the standard library ?array? module , or (for more powerful numeric processing) the types in the third-party NumPy library . -- \ ?When you go in for a job interview, I think a good thing to | `\ ask is if they ever press charges.? ?Jack Handey | _o__) | Ben Finney From mdw at distorted.org.uk Mon Nov 8 18:28:11 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Mon, 08 Nov 2010 23:28:11 +0000 Subject: populating a doubly-subscripted array References: Message-ID: <87aaljmm44.fsf.mdw@metalzone.distorted.org.uk> ghw at accutrol.com writes: > What am I missing? I am using Python 3.1.2. > > ff = [[0.0]*5]*5 > ff #(lists 5x5 array of 0.0) > for i in range(5): > for j in range(3): > ff[i][j] = i*10+j > print (i,j,ff[i][j]) # correctly prints ff array values > > ff # try this and see what happens! > > result of third print of ff > [[40, 41, 42, 0.0, 0.0], [40, 41, 42, 0.0, 0.0], > [40, 41, 42, 0.0, 0.0], [40, 41, 42, 0.0, 0.0], > [40, 41, 42, 0.0, 0.0]] > > Obviously there is something missing in my understanding of > how array values are populated. Why do all "rows" get > populated with the same set of values (40, 41, 42)? [I suppose that the trailing 0.0 entries aren't in question: they're because the individual rows have width 5 -- from `[0.0]*5' -- but only the first three items of each is initialzed -- because j iterates only over range(3).] So, why do they all come out the same? The answer is because in fact there are only two lists involved. You probably thought that you were building something like the thing on the left. In fact, you have the thing on the right. (Try to forgive the rubbish ASCII art.) .--. .--.--.--.--.--. .--. | ----->| | | | | | | --. |__| `--^--^--^--^--' |__| \ | | .--.--.--.--.--. | | \ | ----->| | | | | | | ---. \ |__| `--^--^--^--^--' |__| \v | | .--.--.--.--.--. | | \.--.--.--.--.--. | ----->| | | | | | | ----->| | | | | | |__| `--^--^--^--^--' |__| /`--^--^--^--^--' | | .--.--.--.--.--. | | / ^ | ----->| | | | | | | --' / |__| `--^--^--^--^--' |__| / | | .--.--.--.--.--. | | / | ----->| | | | | | | --' `--' `--^--^--^--^--' `--' What [x] * n does is make a list, whose length is n, and all of whose entries are precisely the value x. If x itself is a list, then you get an outer list all of whose entries are the /same/ inner list -- not copies of it. So when you appear to change entries in one of the inner lists, all the other inner lists seem to change too -- because they're actually the same list. -- [mdw] From ldo at geek-central.gen.new_zealand Mon Nov 8 18:29:13 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 09 Nov 2010 12:29:13 +1300 Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> <87aalrjkty.fsf@benfinney.id.au> <8jd3m9Fr55U7@mid.individual.net> <87fwvdb69k.fsf.mdw@metalzone.distorted.org.uk> Message-ID: In message <87fwvdb69k.fsf.mdw at metalzone.distorted.org.uk>, Mark Wooding wrote: > Lawrence D'Oliveiro writes: > >> for \ >> Description, Attr, ColorList \ >> in \ >> ( >> ("normal", "image", MainWindow.ColorsNormalList), >> ("highlighted", "highlight",MainWindow.ColorsHighlightedList), >> ("selected", "select", MainWindow.ColorsSelectedList), >> ) \ >> : >> ... >> #end for >> >> Does this make more sense now? > > Ugh, no! > > for descr, attr, colours in [ > ('normal', 'image', 'Normal'), > ('highlighted', 'highlight', 'Highlighted'), > ('selected', 'select', 'Selected')]: > colourlist = getattr(MainWindow, 'Colors%sList' % colours) > ## ... But then you lose the ability to match up the bracketing symbols. That?s why I put them on lines by themselves. > To be honest, there's so much regularity in that table that I'd consider > generating it from a shorter list. This would obviously involve > refactoring something else to eliminate the image/normal asymmetry. I'd > also consider making the ColorsMumbleList attribute collection into a > dictionary. Maybe you should look at the code in context , then you can express some more opinions on how to improve it. From ldo at geek-central.gen.new_zealand Mon Nov 8 18:32:30 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 09 Nov 2010 12:32:30 +1300 Subject: Popen Question References: <891a9a80-c30d-4415-ac81-bddd0b564fa6@g13g2000yqj.googlegroups.com> <87hbfs9mm8.fsf.mdw@metalzone.distorted.org.uk> <4cd87b24$0$81481$e4fe514c@news.xs4all.nl> Message-ID: In message <4cd87b24$0$81481$e4fe514c at news.xs4all.nl>, Hans Mulder wrote: > But in this case the first positional argument is in $0. That?s what confused me. From usenet-nospam at seebs.net Mon Nov 8 18:32:58 2010 From: usenet-nospam at seebs.net (Seebs) Date: 08 Nov 2010 23:32:58 GMT Subject: Pythonic/idiomatic? Message-ID: I have an existing hunk of Makefile code: CPPFLAGS = "$(filter -D* -I* -i* -U*,$(TARGET_CFLAGS))" For those not familiar with GNU makeisms, this means "assemble a string which consists of all the words in $(TARGET_CFLAGS) which start with one of -D, -I, -i, or -U". So if you give it foo -Ibar baz it'll say -Ibar I have a similar situation in a Python context, and I am wondering whether this is an idiomatic spelling: ' '.join([x for x in target_cflags.split() if re.match('^-[DIiU]', x)]) This appears to do the same thing, but is it an idiomatic use of list comprehensions, or should I be breaking it out into more bits? You will note that of course, I have carefully made it a one-liner so I don't have to worry about indentation*. -s [*] Kidding, I just thought this seemed like a pretty clear expression. -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From ldo at geek-central.gen.new_zealand Mon Nov 8 18:35:20 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 09 Nov 2010 12:35:20 +1300 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jftftFelnU1@mid.individual.net> <87oca1b8ba.fsf.mdw@metalzone.distorted.org.uk> Message-ID: In message <87oca1b8ba.fsf.mdw at metalzone.distorted.org.uk>, Mark Wooding wrote: > Vertical space is a limiting factor on how much code one can see at a > time. One thing that helps me is that Emacs has commands for quickly jumping between matching brackets. Of course, this only works for languages that have brackets. From ldo at geek-central.gen.new_zealand Mon Nov 8 18:36:29 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 09 Nov 2010 12:36:29 +1300 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jftftFelnU1@mid.individual.net> <87oca1b8ba.fsf.mdw@metalzone.distorted.org.uk> Message-ID: In message , Grant Edwards wrote: > IOW, editing a loop or other control structure where you couldn't see both > ends was problematic. Conserving vertical space avoids that problem. No it doesn?t. It just moves it to a different, arbitrary, point a few percent away?not enough to be worth bothering about. From ldo at geek-central.gen.new_zealand Mon Nov 8 18:39:37 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 09 Nov 2010 12:39:37 +1300 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jftftFelnU1@mid.individual.net> <87oca1b8ba.fsf.mdw@metalzone.distorted.org.uk> Message-ID: In message , Grant Edwards wrote: > ... though I'd still prefer a 4:3. 4:3 still seems to be the best. It gives you a landscape A3-proportional view (or two A4-proportioned portrait pages side by side), and the little bit of space left over at the top or bottom can be used for toolbars, titlebars, that sort of thing. From brf256 at gmail.com Mon Nov 8 18:50:05 2010 From: brf256 at gmail.com (brf256 at gmail.com) Date: Mon, 8 Nov 2010 23:50:05 +0000 Subject: Best exercises for beginers to learn? Message-ID: <430901620-1289260207-cardhu_decombobulator_blackberry.rim.net-713929454-@bda480.bisx.prod.on.blackberry> Hello, I was wondering if there are any good exercises that you would recommend learning? I've already done a menu exercise. Thanks! - Braden Faulkner From robert.kern at gmail.com Mon Nov 8 18:53:56 2010 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 08 Nov 2010 17:53:56 -0600 Subject: functions, list, default parameters In-Reply-To: References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <8ivelpFif1U1@mid.individual.net> <4cca88bc$0$29987$c3e8da3$5496439d@news.astraweb.com> <8j1seqFa1eU2@mid.individual.net> Message-ID: On 11/8/10 5:24 PM, Lawrence D'Oliveiro wrote: > In message, Robert Kern > wrote: > >> On 11/4/10 2:07 AM, Lawrence D'Oliveiro wrote: >> >>> In message, Robert >>> Kern wrote: >>> >>>> On 11/2/10 2:12 AM, Lawrence D'Oliveiro wrote: >>>> >>>>> In message, Robert >>>>> Kern wrote: >>>>> >>>>>> "Immutable objects" are just those without an obvious API for >>>>>> modifying them. >>>>> >>>>> They are ones with NO legal language constructs for modifying them. >>>>> Hint: if a selector of some part of such an object were to occur on the >>>>> LHS of an assignment, and that would raise an error, then the object is >>>>> immutable. The interpreter already knows all this. >>>> >>>> Incorrect. RHS method calls can often modify objects. >>> >>> So bloody what? >> >> So examining LHS "selectors" is not sufficient for determining >> immutability. > > Yes it is. All your attempts at counterexamples showed is that it is not > necessary, not that it is not sufficient. file objects. hashlib hash objects. weakref.ref objects. Again, I ask you to point out a piece of code in the interpreter that makes this determination. You have repeatedly claimed that they exist, but you have not produced a single example. -- 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 kevin.p.dwyer at gmail.com Mon Nov 8 19:01:08 2010 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Tue, 9 Nov 2010 00:01:08 +0000 (UTC) Subject: python test frameworks References: <009da031-22f2-4719-b030-b1db76e953af@r4g2000prj.googlegroups.com> Message-ID: On Sun, 07 Nov 2010 09:01:42 -0800, rustom wrote: > On Nov 7, 7:09?pm, Kev Dwyer wrote: >> On Sun, 07 Nov 2010 10:56:46 +0530, Rustom Mody wrote: >> > There are a large number of test frameworks in/for python. ?Apart >> > from what comes builtin with python there seems to be nose, staf, >> > qmtest etc etc. >> >> > Is there any central place where these are listed with short >> > descriptions? 'Test framework' means widely different things in >> > different contexts. Any explanations/tutorials around? >> >> > [Disclaimer: I was educated a couple of decades before the TDD rage] >> >> Hello, >> >> You could start >> withhttp://pycheesecake.org/wiki/PythonTestingToolsTaxonomy >> >> Kev > > Thanks -- that looks like a comprehensive resource. But it does not > have staf > http://staf.sourceforge.net/current/STAFPython.htm. Is that merely an > item missing or a category? I'm afraid I couldn't say with any certainty - I'd throw that question at the python testing newsgroup, to whom I am cross-posting in the hope that they can help. Kev From debatem1 at gmail.com Mon Nov 8 19:11:47 2010 From: debatem1 at gmail.com (geremy condra) Date: Mon, 8 Nov 2010 19:11:47 -0500 Subject: Pythonic/idiomatic? In-Reply-To: References: Message-ID: On Mon, Nov 8, 2010 at 6:32 PM, Seebs wrote: > I have an existing hunk of Makefile code: > ? ? ? ?CPPFLAGS = "$(filter -D* -I* -i* -U*,$(TARGET_CFLAGS))" > For those not familiar with GNU makeisms, this means "assemble a string > which consists of all the words in $(TARGET_CFLAGS) which start with one > of -D, -I, -i, or -U". ?So if you give it > ? ? ? ?foo -Ibar baz > it'll say > ? ? ? ?-Ibar > > I have a similar situation in a Python context, and I am wondering > whether this is an idiomatic spelling: > > ? ? ? ?' '.join([x for x in target_cflags.split() if re.match('^-[DIiU]', x)]) > > This appears to do the same thing, but is it an idiomatic use of list > comprehensions, or should I be breaking it out into more bits? > > You will note that of course, I have carefully made it a one-liner so I > don't have to worry about indentation*. > > -s > [*] Kidding, I just thought this seemed like a pretty clear expression. I believe this is correct, but I may be wrong. Try and see. CPPFLAGS = ' '.join(filter(lambda x: x.startswith(('-D', '-I', '-i', '-U')), cflags)) Geremy Condra From jbiquez at icsmx.com Mon Nov 8 19:18:17 2010 From: jbiquez at icsmx.com (Jorge Biquez) Date: Mon, 08 Nov 2010 18:18:17 -0600 Subject: Commercial or Famous Applicattions.? Message-ID: <201011090026.oA90QP1S095565@krusty.intranet.com.mx> Hello all. Newbie question. Sorry. Can you mention applications/systems/solutions made with Python that are well known and used by public in general? ANd that maybe we do not know they are done with Python? I had a talk with a friend, "PHP-Only-Fan", and he said (you know the schema of those talks) that "his" language is better and that "just to prove it" there are not too many applications done with Python than the ones done with PHP and that "that of course is for something". That conversation , that by the way I guess is useless at all , makes me thing the idea of ask of applications done with Python. Not for debate the argument of that guy BUT to learn what can be done with Python. In grphical interface, schemas of jobs, etc. I know that there are tons of solutions but would like to hear of possible about the ones you have used most or recommend the most. As an example, I love and have used in the last years MAILMAN, never crashed, always works even on my small and old Intel Pentium III with a 10GB hard disk and 640KB of RAM. Still working and will work for sure (running under FreeBsd by the way). Thanks in advance for your comments. Jorge Biquez From ben+python at benfinney.id.au Mon Nov 8 19:26:53 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 09 Nov 2010 11:26:53 +1100 Subject: Pythonic/idiomatic? References: Message-ID: <87y693cpf6.fsf@benfinney.id.au> Seebs writes: > I have a similar situation in a Python context, and I am wondering > whether this is an idiomatic spelling: > > ' '.join([x for x in target_cflags.split() if re.match('^-[DIiU]', x)]) > > This appears to do the same thing, but is it an idiomatic use of list > comprehensions, or should I be breaking it out into more bits? One thing to know is that, if you want to create a sequence whose only purpose is to feed to something else and then throw away, a generator will be cleaner and (probably) better performing than a list. For this purpose, there is a generator expression syntax , almost identical to a list comprehension except without the enclosing brackets. ' '.join(x for x in target_cflags.split() if re.match('^-[DIiU]', x)) The regex is less clear for the purpose than I'd prefer. For a simple ?is it a member of this small set?, I'd find it more readable to use a simple list of the actual strings:: ' '.join( x for x in target_cflags.split() if x in ['-D', '-I', '-i', '-U']) or even an actual set:: ' '.join( x for x in target_cflags.split() if x in {'-D', '-I', '-i', '-U'}) The latter works only in Python with set literals (Python 2.7 or later). -- \ ?I find the whole business of religion profoundly interesting. | `\ But it does mystify me that otherwise intelligent people take | _o__) it seriously.? ?Douglas Adams | Ben Finney From usenet-nospam at seebs.net Mon Nov 8 19:31:08 2010 From: usenet-nospam at seebs.net (Seebs) Date: 09 Nov 2010 00:31:08 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1ee3e$0$29972$c3e8da3$5496439d@news.astraweb.com> <4cd262b3$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jg7qoFhbnU2@mid.individual.net> Message-ID: On 2010-11-08, Michael Torrie wrote: > On 11/06/2010 02:27 AM, Seebs wrote: >> I have yet to find an editor that allows me to, well, *edit*, more >> comfortably than vi. > Indeed vi (or in my case, vim) works wonderfully well with python. I > always use the following vim settings on python files: Ahh, but I use nvi, not vim. > If you set up a conditional thing in your vimrc to enable these settings > for python files, you shouldn't have any more tab problems. And I don't think I can do that in nvi -- I don't think it has conditionals. Although. You've just caused me to remember something which is in context both amusing and funny. Which is that I believe nvi has support for some embedded scripting functionality, at least as an optional build choice. Which I've never used, on the grounds that I don't know Python... So that may actually be possible. I'll look into it, for sure. Thanks for nudging my memory. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Mon Nov 8 19:31:51 2010 From: usenet-nospam at seebs.net (Seebs) Date: 09 Nov 2010 00:31:51 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jftftFelnU1@mid.individual.net> <87oca1b8ba.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On 2010-11-08, Lawrence D'Oliveiro wrote: > In message <87oca1b8ba.fsf.mdw at metalzone.distorted.org.uk>, Mark Wooding > wrote: >> Vertical space is a limiting factor on how much code one can see at a >> time. > One thing that helps me is that Emacs has commands for quickly jumping > between matching brackets. > Of course, this only works for languages that have brackets. Yes. One of the things I find frustrating about the Ruby idiom of preferring do/end for multiline blocks is that you can't fence-match them. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From wuwei23 at gmail.com Mon Nov 8 19:32:12 2010 From: wuwei23 at gmail.com (alex23) Date: Mon, 8 Nov 2010 16:32:12 -0800 (PST) Subject: Commercial or Famous Applicattions.? References: Message-ID: Jorge Biquez wrote: > Can you mention applications/systems/solutions made with Python that > are well known and used by public in general? ANd that maybe we do > not know they are done with Python? http://python.org/about/success/ This comes up semi-regularly so you might be able to find more examples in past threads. From rantingrick at gmail.com Mon Nov 8 19:33:54 2010 From: rantingrick at gmail.com (rantingrick) Date: Mon, 8 Nov 2010 16:33:54 -0800 (PST) Subject: Commercial or Famous Applicattions.? References: Message-ID: Commenting on which language is better than "this one" or which language boasts the most achievements is nothing more than time very poorly spent. Some people will find Python to be the best thing since sliced bread (and i am one of them!), however others will find Python to be the worst language they ever used (thankfully very few!). These are nothing more than personal opinions and you must leave them at that level. Because as they say... "Opinions are like sphincters -- everybody has at least one" ... or something like that i suppose :) From usenet-nospam at seebs.net Mon Nov 8 19:34:21 2010 From: usenet-nospam at seebs.net (Seebs) Date: 09 Nov 2010 00:34:21 GMT Subject: Pythonic/idiomatic? References: <87y693cpf6.fsf@benfinney.id.au> Message-ID: On 2010-11-09, Ben Finney wrote: > For this purpose, there is a generator expression syntax >, > almost identical to a list comprehension except without the enclosing > brackets. > > ' '.join(x for x in target_cflags.split() if re.match('^-[DIiU]', x)) Ahh, handy. I am torn very much on the generator/comprehension syntax, because on the one hand, I really prefer to have the structure first, but on the other hand, I can't easily figure out a way to make the syntax work for that. > The regex is less clear for the purpose than I'd prefer. For a simple > ???is it a member of this small set???, I'd find it more readable to use a > simple list of the actual strings:: > ' '.join( > x for x in target_cflags.split() > if x in ['-D', '-I', '-i', '-U']) The regex is intentionally not anchored with a $, because I'm looking for "starts with", not "is". > The latter works only in Python with set literals (Python 2.7 or later). I think we're stuck with backwards compatibility at least as far as 2.4. No, I'm not kidding. *sigh* -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Mon Nov 8 19:43:24 2010 From: usenet-nospam at seebs.net (Seebs) Date: 09 Nov 2010 00:43:24 GMT Subject: Commercial or Famous Applicattions.? References: Message-ID: On 2010-11-09, rantingrick wrote: > Commenting on which language is better than "this one" or which > language boasts the most achievements is nothing more than time very > poorly spent. This is mostly true, but I don't think it's entirely true. It is certainly possible for someone else's language choices to affect me (if I get called in to fix their code). And as a result, I do try to do at least a little language advocacy. Specifically, I try to steer people away from PHP. I can live with just about everything else. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From brf256 at gmail.com Mon Nov 8 19:47:08 2010 From: brf256 at gmail.com (brf256 at gmail.com) Date: Tue, 9 Nov 2010 00:47:08 +0000 Subject: Commercial or Famous Applicattions.? Message-ID: <1143731221-1289263630-cardhu_decombobulator_blackberry.rim.net-1731425422-@bda480.bisx.prod.on.blackberry> Mailman is of course. As well as redhats anaconda installer and google uses python internally for many of there "medium sized" projects. Also, calibre, gwibber, portage pms, ubuntu software center, YUM pms and many others including YouTube. Moral is many big companies do both for products and internally. Cheers, - Braden Faulkner From ian.g.kelly at gmail.com Mon Nov 8 19:49:44 2010 From: ian.g.kelly at gmail.com (Ian) Date: Mon, 8 Nov 2010 16:49:44 -0800 (PST) Subject: Popen Question References: <891a9a80-c30d-4415-ac81-bddd0b564fa6@g13g2000yqj.googlegroups.com> <87hbfs9mm8.fsf.mdw@metalzone.distorted.org.uk> <4cd87b24$0$81481$e4fe514c@news.xs4all.nl> Message-ID: On Nov 8, 3:35?pm, Hans Mulder wrote: > > Perhaps this example better demonstrates what is going on: > > >>>> p = subprocess.Popen(['echo one $0 three $1 five', 'two', 'four'], > > ... ? ? ? ? ? ? ? ? ? ? ?shell=True) > > one two three four five > > Maybe I'm thick, but I still don't understand. ?If I run a shell script, > then the name of the script is in $0 and the first positional arguments > is in $1, similar to how Python sets up sys.argv. > > But in this case the first positional argument is in $0. ?Why is that? It's just a quirk in the way the shell handles the -c option. The syntax for the shell invocation boils down to something like this: sh [-c command_string] command_name arg1 arg2 arg3 ... Without the -c option, sh runs the file indicated by command_name, setting $0 to command_name, $1 to arg1, $2 to arg2, etc. With the -c option, it does the same thing; it just runs the command_string instead of a file pointed to by command_name. The latter still conceptually exists as an argument, however, which is why it still gets stored in $0 instead of $1. We could argue about whether this approach is correct or not, but it's what the shell does, and that's not likely to change. Cheers, Ian From nagle at animats.com Mon Nov 8 19:59:05 2010 From: nagle at animats.com (John Nagle) Date: Mon, 08 Nov 2010 16:59:05 -0800 Subject: Commercial or Famous Applicattions.? In-Reply-To: References: Message-ID: <4cd89cdc$0$1588$742ec2ed@news.sonic.net> On 11/8/2010 4:47 PM, brf256 at gmail.com wrote: > Mailman is of course. As well as redhats anaconda installer and > google uses python internally for many of there "medium sized" > projects. Also, calibre, gwibber, portage pms, ubuntu software > center, YUM pms and many others including YouTube. Moral is many big > companies do both for products and internally. > > Cheers, - Braden Faulkner YouTube was rewritten a few years ago, as it was scaled up. Not sure what it's written in now. John Nagle From ben+python at benfinney.id.au Mon Nov 8 20:12:44 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 09 Nov 2010 12:12:44 +1100 Subject: Pythonic/idiomatic? References: <87y693cpf6.fsf@benfinney.id.au> Message-ID: <87lj53cnar.fsf@benfinney.id.au> Seebs writes: > On 2010-11-09, Ben Finney wrote: > > The regex is less clear for the purpose than I'd prefer. For a > > simple ???is it a member of this small set???, I'd find it more > > readable to use a simple list of the actual strings:: > > > ' '.join( > > x for x in target_cflags.split() > > if x in ['-D', '-I', '-i', '-U']) > > The regex is intentionally not anchored with a $, because I'm looking > for "starts with", not "is". Ah, okay. Strings have a built-in ?startswith? method, but it may be less convenient for the current case compared to a regex. Here's an attempt:: ' '.join( x for x in target_cflags.split() if any( x.startswith(opt_name) for opt_name in ['-D', '-I', '-i', '-U'])) I still find that more readable than the version using a regex, but it's pushing the boundaries of verbosity. Better would be to use the fact that ?str.startswith? can do the same as above with a tuple of prefix strings:: ' '.join( x for x in target_cflags.split() if x.startswith(('-D', '-I', '-i', '-U'))) > I think we're stuck with backwards compatibility at least as far as > 2.4. Then you don't yet have the ?any? and ?all? built-in functions, or the tuple-of-prefixes feature of ?str.startswith? either. Bummer. At which point, the Pythonic thing to do is to convince your organisation to use a version of Python that's at least officially supported by the PSF :-) -- \ ?Teach a man to make fire, and he will be warm for a day. Set a | `\ man on fire, and he will be warm for the rest of his life.? | _o__) ?John A. Hrastar | Ben Finney From alan.gauld at btinternet.com Mon Nov 8 20:30:21 2010 From: alan.gauld at btinternet.com (Alan Gauld) Date: Tue, 9 Nov 2010 01:30:21 -0000 Subject: Commercial or Famous Applicattions.? References: <201011090026.oA90QP1S095565@krusty.intranet.com.mx> Message-ID: "Jorge Biquez" wrote > Can you mention applications/systems/solutions made with Python that > are well known and used by public in general? ANd that maybe we do > not know they are done with Python? The Python web site has an advocacy section, you will find several success stories there. HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ From rantingrick at gmail.com Mon Nov 8 20:40:22 2010 From: rantingrick at gmail.com (rantingrick) Date: Mon, 8 Nov 2010 17:40:22 -0800 (PST) Subject: Commercial or Famous Applicattions.? References: Message-ID: On Nov 8, 6:43?pm, Seebs wrote: > On 2010-11-09, rantingrick wrote: > It is certainly possible for someone else's language choices to > affect me (if I get called in to fix their code). ?And as a result, I do > try to do at least a little language advocacy. ?Specifically, I try to > steer people away from PHP. ?I can live with just about everything else. True and i agree with your statements however i was alluding more to the fact that there exist no true winner in the battle of languages. Just as there exists no winners in the battle of composers. You can say "Hey this of group of talented fellows really shines above the rest". However you can NEVER say that "This specific fellow shines above the group of talented fellows". Can you compare the expansive depth and melodic genius of Chopin to the explosive (almost vengeful!) energy of Ludwig van Beethoven? How how about Rachmaninoff to Liszt? But yea i must agree... PHP... :-P" From python.list at tim.thechases.com Mon Nov 8 20:40:32 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 08 Nov 2010 19:40:32 -0600 Subject: Pythonic/idiomatic? In-Reply-To: References: <87y693cpf6.fsf@benfinney.id.au> Message-ID: <4CD8A690.9040103@tim.thechases.com> On 11/08/10 18:34, Seebs wrote: > On 2010-11-09, Ben Finney wrote: >> ' '.join(x for x in target_cflags.split() if re.match('^-[DIiU]', x)) > > Ahh, handy. ... >> The latter works only in Python with set literals (Python >> 2.7 or later). > > I think we're stuck with backwards compatibility at least as > far as 2.4. > > No, I'm not kidding. *sigh* I feel your pain :) At least be glad you don't have to go back to 2.3 where Ben's suggested generator-syntax isn't available. >> The regex is less clear for the purpose than I'd prefer. For a simple >> ???is it a member of this small set???, I'd find it more readable to use a >> simple list of the actual strings:: > >> ' '.join( >> x for x in target_cflags.split() >> if x in ['-D', '-I', '-i', '-U']) > > The regex is intentionally not anchored with a $, because I'm looking > for "starts with", not "is". I suppose you could do ' '.join( x for x in target_cflags.split() if x[:2] in ['-D', '-I', '-i', '-U'] ) or ' '.join( x for x in target_cflags.split() if x.startswith(('-D', '-I', '-i', '-U')) ) or even ' '.join( x for x in target_cflags.split() if x[:1] == '-' and x[1:2] in 'DIiU' ) -tkc From rabidpoobear at gmail.com Mon Nov 8 20:46:36 2010 From: rabidpoobear at gmail.com (Luke Paireepinart) Date: Mon, 8 Nov 2010 19:46:36 -0600 Subject: [Tutor] Commercial or Famous Applicattions.? In-Reply-To: <201011090026.oA90QP1S095565@krusty.intranet.com.mx> References: <201011090026.oA90QP1S095565@krusty.intranet.com.mx> Message-ID: just off the top of my head... NASA uses it. Lots of games use Python as their game logic/scripting language (how many use PHP? probably approaching 0. LUA is more popular than Python but Python is much more popular than PHP). The first ever bittorrent client (the official one) was written in Python. The game Eve Online is written completely in Python. Youtube uses lots of Python, Facebook uses some. Reddit is written in Python as well. Google App Engine has both Python and Java interfaces. They don't have a PHP interface; I wonder why? Lots of jobs at Google (even Java jobs and such) require Python experience; they don't tend to require PHP experience too. Because PHP doesn't really teach you much. The syntax is not nearly as elegant. It's buggy and rough around the edges. They have gross workarounds for a lot of things that should be language features. That's not to say that Python's the only language that is better than PHP for most things. Ruby is also a good option. But these languages are both infinitely more flexible _right now_ (not based almost solely for web apps) and better to use for almost everything than PHP. PHP has its place, and part of the reason it still has that place is because a lot of web hosts haven't started hosting Python and Ruby frameworks in a scalable, fast way. But it's not the frameworks' fault. That's just my 2c. On Mon, Nov 8, 2010 at 6:18 PM, Jorge Biquez wrote: > Hello all. > > Newbie question. Sorry. > > Can you mention applications/systems/solutions made with Python that are > well known and used by public in general? ANd that maybe we do not know they > are done with Python? > > I had a talk with a friend, "PHP-Only-Fan", and he said (you know the schema > of those talks) that "his" language is better and that "just to prove it" > there are not too many applications done with Python than the ones done with > PHP and that "that of course is for something". That conversation , that by > the way I guess is useless at all , makes me thing the idea of ask of > applications done with Python. Not for debate the argument of that guy BUT > to learn what can be done with Python. In grphical interface, schemas of > jobs, etc. I know that there are tons of solutions but would like to hear of > possible about the ones you have used most or recommend the most. > > As an example, I love and have used in the last years MAILMAN, never > crashed, always works even on my small and old Intel Pentium III with a 10GB > hard disk and 640KB of RAM. Still working and will work for sure (running > under FreeBsd by the way). > > Thanks in advance for your comments. > > Jorge Biquez > > _______________________________________________ > Tutor maillist ?- ?Tutor at python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > From jason.heeris at gmail.com Mon Nov 8 21:09:39 2010 From: jason.heeris at gmail.com (Jason) Date: Mon, 8 Nov 2010 18:09:39 -0800 (PST) Subject: Define macro when invoking setup.py Message-ID: <43ca24d3-72ac-470a-ab20-798770e7e6d1@29g2000prb.googlegroups.com> I'd like to be able switch between building my C extension with a certain preprocessor macro defined or not defined. I'm using the rudimentary distutils setup.py example given here: http://docs.python.org/extending/building.html Is there a command line option that distutils.core.setup() will interpret for me, like the "-D" option for gcc? Or do I need to do something more complicated? (I had a brief look at the distutils.command.build_* docs... but they're pretty sparse.) From ldo at geek-central.gen.new_zealand Mon Nov 8 21:10:24 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 09 Nov 2010 15:10:24 +1300 Subject: http error 301 for urlopen References: <4cd7987e$0$1674$742ec2ed@news.sonic.net> Message-ID: In message <4cd7987e$0$1674$742ec2ed at news.sonic.net>, John Nagle wrote: > It's the New York Times' paywall. They're trying to set a cookie, > and will redirect the URL until you store and return the cookie. And if they find out you?re acessing them from a script, they?ll probably try to find a way to block that as well. From usenet-nospam at seebs.net Mon Nov 8 21:13:11 2010 From: usenet-nospam at seebs.net (Seebs) Date: 09 Nov 2010 02:13:11 GMT Subject: Pythonic/idiomatic? References: <87y693cpf6.fsf@benfinney.id.au> <87lj53cnar.fsf@benfinney.id.au> Message-ID: On 2010-11-09, Ben Finney wrote: > Seebs writes: >> I think we're stuck with backwards compatibility at least as far as >> 2.4. > Then you don't yet have the ???any??? and ???all??? built-in functions, or the > tuple-of-prefixes feature of ???str.startswith??? either. Bummer. Eww. > At which point, the Pythonic thing to do is to convince your > organisation to use a version of Python that's at least officially > supported by the PSF :-) Unfortunately, we're selling something to people who will explode if we tell them to upgrade their RHEL4 systems, so we have to work on those. (There is some tiny hope that we'll be able to move the baseline to RHEL5 within another two years.) If it were only a matter of internal use, my job would be orders of magnitude easier. (I'm maintaining something that intercepts and wraps large hunks of the standard C library; if you think dealing with Python 2.4 is a burden, you ain't seen *nothing* compared to that.) -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From ldo at geek-central.gen.new_zealand Mon Nov 8 21:15:58 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 09 Nov 2010 15:15:58 +1300 Subject: Silly newbie question - Carrot character (^) References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> Message-ID: In message , Dennis Lee Bieber wrote: > On Sat, 6 Nov 2010 10:22:47 -0400, Philip Semanchuk > declaimed the following in > gmane.comp.python.general: > >> Some people might think the language ref> is a fine place to direct >> newcomers to Python. I don't. It's not awful, but it's dense and >> unfriendly for those just starting out. >> > Have you ever looked at the reference manual for Ada? Or even worse, the annotated reference. I thought annotations were supposed to clarify things; in this case they seemed to have the opposite effect... From ldo at geek-central.gen.new_zealand Mon Nov 8 21:18:31 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 09 Nov 2010 15:18:31 +1300 Subject: subclassing str References: <5dLBo.1024$w8.406@twister2.libero.it> Message-ID: In message <5dLBo.1024$w8.406 at twister2.libero.it>, not1xor1 (Alessandro) wrote: > I'm already using plain functions, but thought that wrapping most of > them in a str subclass would let me save some time and yield cleaner > and more manageable code How exactly does a.f(b, c) save time over f(a, b, c) ? From usenet-nospam at seebs.net Mon Nov 8 21:29:57 2010 From: usenet-nospam at seebs.net (Seebs) Date: 09 Nov 2010 02:29:57 GMT Subject: Silly newbie question - Carrot character (^) References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> Message-ID: On 2010-11-09, Lawrence D'Oliveiro wrote: > In message , Dennis Lee > Bieber wrote: >> Have you ever looked at the reference manual for Ada? > Or even worse, the annotated reference. I thought annotations were supposed > to clarify things; in this case they seemed to have the opposite effect... Clearly, you've never seen Schildt's infamous "Annotated ANSI C Standard". -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From lists at cheimes.de Mon Nov 8 21:48:10 2010 From: lists at cheimes.de (Christian Heimes) Date: Tue, 09 Nov 2010 03:48:10 +0100 Subject: Define macro when invoking setup.py In-Reply-To: <43ca24d3-72ac-470a-ab20-798770e7e6d1@29g2000prb.googlegroups.com> References: <43ca24d3-72ac-470a-ab20-798770e7e6d1@29g2000prb.googlegroups.com> Message-ID: Am 09.11.2010 03:09, schrieb Jason: > I'd like to be able switch between building my C extension with a > certain preprocessor macro defined or not defined. I'm using the > rudimentary distutils setup.py example given here: > > http://docs.python.org/extending/building.html > > Is there a command line option that distutils.core.setup() will > interpret for me, like the "-D" option for gcc? Or do I need to do > something more complicated? (I had a brief look at the > distutils.command.build_* docs... but they're pretty sparse.) You were looking at the wrong manual. Read http://docs.python.org/distutils/setupscript.html#preprocessor-options Extension(..., define_macros=[('NDEBUG', '1'), ('HAVE_STRFTIME', None)], undef_macros=['HAVE_FOO', 'HAVE_BAR']) Note that define_macros requires a list of tuples each having two members. Christian From rantingrick at gmail.com Mon Nov 8 21:55:04 2010 From: rantingrick at gmail.com (rantingrick) Date: Mon, 8 Nov 2010 18:55:04 -0800 (PST) Subject: subclassing str References: <5dLBo.1024$w8.406@twister2.libero.it> Message-ID: <6048c71a-fba9-4244-9a36-a5d19c8a5516@y23g2000yqd.googlegroups.com> On Nov 8, 8:18?pm, Lawrence D'Oliveiro wrote: > In message <5dLBo.1024$w8.... at twister2.libero.it>, not1xor1 (Alessandro) > wrote: > > > I'm already using plain functions, but thought that wrapping most of > > them in a str subclass would let me save some time and yield cleaner > > and more manageable code > > How exactly does > > ? ?a.f(b, c) > > save time over > > ? ? f(a, b, c) > > ? I think if you'll re-read the OP's statements (specifically the ones you quoted!) then you will see it's not an issue of time, its an issue of form and structure. Its an issue of paradigm. The OP wishes to keep his code as true to OOP as possible and what is wrong with that? Nothing in my book! One thing i love about Python is the fact that it can please almost all the "religious paradigm zealots" with it's multiple choice approach to programming. However some of the features that OOP fundamentalists hold dear in their heart are not always achievable in a clean manner with Python. Yes you could use a function but that is not the OOP way. Yes you could use UserString but that also seems too excessive. Ruby allows redefining everything. However this can open a REAL can of worms in group environment greater than one! From jason.heeris at gmail.com Mon Nov 8 21:56:06 2010 From: jason.heeris at gmail.com (Jason) Date: Mon, 8 Nov 2010 18:56:06 -0800 (PST) Subject: Define macro when invoking setup.py References: <43ca24d3-72ac-470a-ab20-798770e7e6d1@29g2000prb.googlegroups.com> Message-ID: On Nov 9, 10:48?am, Christian Heimes wrote: > You were looking at the wrong manual. Readhttp://docs.python.org/distutils/setupscript.html#preprocessor-options > > Extension(..., > ? ? ? ? ? define_macros=[('NDEBUG', '1'), > ? ? ? ? ? ? ? ? ? ? ? ? ?('HAVE_STRFTIME', None)], > ? ? ? ? ? undef_macros=['HAVE_FOO', 'HAVE_BAR']) > > Note that define_macros requires a list of tuples each having two members. But can they be selected or set from the command line, so I can do, say, "setup.py build -DDEBUG=1"? ? Jason From jason.heeris at gmail.com Mon Nov 8 22:04:13 2010 From: jason.heeris at gmail.com (Jason) Date: Mon, 8 Nov 2010 19:04:13 -0800 (PST) Subject: Define macro when invoking setup.py References: <43ca24d3-72ac-470a-ab20-798770e7e6d1@29g2000prb.googlegroups.com> Message-ID: <70efe9e9-96c6-4e3e-863e-f28575a008fe@u25g2000pra.googlegroups.com> On Nov 9, 10:56?am, Jason wrote: > But can they be selected or set from the command line, so I can do, > say, "setup.py build -DDEBUG=1"? Just answered my own question: there's an option for "build_ext" (NOT "build") that allows this. Thanks, Jason From azeynel1 at gmail.com Mon Nov 8 22:17:27 2010 From: azeynel1 at gmail.com (Zeynel) Date: Mon, 8 Nov 2010 19:17:27 -0800 (PST) Subject: Is there a way to pring a list object in Python? References: <88413b8d-e4dc-4eba-a19c-e9911e7eeb82@30g2000yql.googlegroups.com> Message-ID: <6d0b0de1-a66b-4991-85f5-1afb4e5109b8@y23g2000yqd.googlegroups.com> On Oct 31, 2:44?pm, Benjamin Kaplan wrote: > Rep() = Rep object > Rep.all() = Query object > list(Rep.all()) = List of Rep objects. > list(Rep.all())[0] = A single Rep object > list(Rep.all())[0].replist = A list > Thanks! This was very helpful. From lists at asd-group.com Mon Nov 8 23:16:23 2010 From: lists at asd-group.com (John Bond) Date: Tue, 09 Nov 2010 04:16:23 +0000 Subject: Commercial or Famous Applicattions.? In-Reply-To: <201011090026.oA90QP1S095565@krusty.intranet.com.mx> References: <201011090026.oA90QP1S095565@krusty.intranet.com.mx> Message-ID: <4CD8CB17.4060301@asd-group.com> On 9/11/2010 12:18 AM, Jorge Biquez wrote: > Hello all. > > Newbie question. Sorry. > > Can you mention applications/systems/solutions made with Python that > are well known and used by public in general? ANd that maybe we do not > know they are done with Python? > > ... > Jorge Biquez > Keep in mind that Python is also popular in frameworks such as Zope and Twisted, and things based on them are based on Python. It's also been reasonably popular and well supported on Symbian smartphones. The Wing IDE is a good example of a commercial Python app on the desktop. I once got asked to write a list things that I'd make different in the technology world if I could, to make it better for everyone. Number 3 was "everywhere you now see Javascript or PHP, you'd see Python instead". If only... Cheers, JB From etolv.computers.groups at gmail.com Mon Nov 8 23:28:55 2010 From: etolv.computers.groups at gmail.com (mohammed ahmed) Date: Mon, 8 Nov 2010 20:28:55 -0800 (PST) Subject: Send a free SMS to your friends from Gmail Message-ID: <6756c026-a4f2-486a-9d85-ee5fd86e16da@i32g2000pri.googlegroups.com> Send a free SMS to your friends from Gmail Did you know that you can now send free text messages (SMS) to your friends directly from your Gmail account? Try Gmail SMS today and start texting your friends from your computer. http://free-sms-sms-sms.blogspot.com/2010/11/gmail-sms.html send free sms from pc to mobile http://phpforweb.com/askany/sms.php?sms From etolv.computers.groups at gmail.com Mon Nov 8 23:28:56 2010 From: etolv.computers.groups at gmail.com (mohammed ahmed) Date: Mon, 8 Nov 2010 20:28:56 -0800 (PST) Subject: Send a free SMS to your friends from Gmail Message-ID: <96e5f7f8-8932-4123-a705-7aadd32f0ebf@g28g2000pra.googlegroups.com> Send a free SMS to your friends from Gmail Did you know that you can now send free text messages (SMS) to your friends directly from your Gmail account? Try Gmail SMS today and start texting your friends from your computer. http://free-sms-sms-sms.blogspot.com/2010/11/gmail-sms.html send free sms from pc to mobile http://phpforweb.com/askany/sms.php?sms From ldo at geek-central.gen.new_zealand Tue Nov 9 00:54:50 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 09 Nov 2010 18:54:50 +1300 Subject: Commercial or Famous Applicattions.? References: <201011090026.oA90QP1S095565@krusty.intranet.com.mx> Message-ID: In message , John Bond wrote: > I once got asked to write a list things that I'd make different in the > technology world if I could, to make it better for everyone. Number 3 > was "everywhere you now see Javascript or PHP, you'd see Python > instead". If only... PHP yes, JavaScript no. From ldo at geek-central.gen.new_zealand Tue Nov 9 00:57:14 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 09 Nov 2010 18:57:14 +1300 Subject: Commercial or Famous Applicattions.? References: Message-ID: In message , Jorge Biquez wrote: > ... there are not too many applications done with Python > than the ones done with PHP ... PHP is only used for server-side Web applications, nothing else. Python is used for lots of things, on and off the Web. From ldo at geek-central.gen.new_zealand Tue Nov 9 01:04:53 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 09 Nov 2010 19:04:53 +1300 Subject: Silly newbie question - Caret character (^) References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> Message-ID: In message , Seebs wrote: > On 2010-11-09, Lawrence D'Oliveiro > wrote: > >> In message , Dennis >> Lee Bieber wrote: >>> >>> Have you ever looked at the reference manual for Ada? > >> Or even worse, the annotated reference. I thought annotations were >> supposed to clarify things; in this case they seemed to have the opposite >> effect... > > Clearly, you've never seen Schildt's infamous "Annotated ANSI C Standard". There absolutely no chance (or at least no way I can imagine) that anyone could annotate a concise language like C up to the level of turgidity of the Ada spec. Hang on, is this Herb Schildt? I bought a couple of his books, back when I was trying to get to grips with C++ (I have the edition of ?C++ The Complete Reference? which proudly proclaims it ?Covers the New International Standard for C+?). Not as useful as I thought they would be; I ended up referring to the libstdc++ sources to clarify things. From lists at asd-group.com Tue Nov 9 01:31:48 2010 From: lists at asd-group.com (John Bond) Date: Tue, 09 Nov 2010 06:31:48 +0000 Subject: Commercial or Famous Applicattions.? In-Reply-To: References: <201011090026.oA90QP1S095565@krusty.intranet.com.mx> Message-ID: <4CD8EAD4.9080705@asd-group.com> On 9/11/2010 5:54 AM, Lawrence D'Oliveiro wrote: > In message, John Bond > wrote: > >> I once got asked to write a list things that I'd make different in the >> technology world if I could, to make it better for everyone. Number 3 >> was "everywhere you now see Javascript or PHP, you'd see Python >> instead". If only... > PHP yes, JavaScript no. Without wanting to go too far o/t, why? Cheers, JB. From ldo at geek-central.gen.new_zealand Tue Nov 9 01:52:22 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 09 Nov 2010 19:52:22 +1300 Subject: JavaScript vs Python (was Re: Commercial or Famous Applicattions.?) References: <201011090026.oA90QP1S095565@krusty.intranet.com.mx> Message-ID: In message , John Bond wrote: > On 9/11/2010 5:54 AM, Lawrence D'Oliveiro wrote: > >> In message, John Bond >> wrote: >> >>> I once got asked to write a list things that I'd make different in the >>> technology world if I could, to make it better for everyone. Number 3 >>> was "everywhere you now see Javascript or PHP, you'd see Python >>> instead". If only... >> >> PHP yes, JavaScript no. >> > ... why? Because JavaScript is actually a decent language in its own right. From usenet-nospam at seebs.net Tue Nov 9 02:00:00 2010 From: usenet-nospam at seebs.net (Seebs) Date: 09 Nov 2010 07:00:00 GMT Subject: Silly newbie question - Caret character (^) References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> Message-ID: On 2010-11-09, Lawrence D'Oliveiro wrote: > In message , Seebs wrote: >> On 2010-11-09, Lawrence D'Oliveiro >> wrote: >>> Or even worse, the annotated reference. I thought annotations were >>> supposed to clarify things; in this case they seemed to have the opposite >>> effect... >> Clearly, you've never seen Schildt's infamous "Annotated ANSI C Standard". > There absolutely no chance (or at least no way I can imagine) that anyone > could annotate a concise language like C up to the level of turgidity of the > Ada spec. Not so much turgidity as being WRONG. Consistently and often. > Hang on, is this Herb Schildt? I bought a couple of his books, back when I > was trying to get to grips with C++ (I have the edition of ???C++ The Complete > Reference??? which proudly proclaims it ???Covers the New International Standard > for C+???). Not as useful as I thought they would be; I ended up referring to > the libstdc++ sources to clarify things. Yes, Herb Schildt: http://www.seebs.net/c/c_tcn4e.html (I know too little about C++ to criticize is writings about it, but people have told me they're comparable.) -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From arnodel at gmail.com Tue Nov 9 02:08:18 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Tue, 09 Nov 2010 07:08:18 +0000 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jftftFelnU1@mid.individual.net> <87oca1b8ba.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <87pqufx9ct.fsf@gmail.com> Lawrence D'Oliveiro writes: > In message <87oca1b8ba.fsf.mdw at metalzone.distorted.org.uk>, Mark Wooding > wrote: > >> Vertical space is a limiting factor on how much code one can see at a >> time. > > One thing that helps me is that Emacs has commands for quickly jumping > between matching brackets. > > Of course, this only works for languages that have brackets. python-mode has python-beginning-of-block (C-c C-u) and python-end-of-block. -- Arnaud From infodmpcg at gmail.com Tue Nov 9 02:09:01 2010 From: infodmpcg at gmail.com (Karis Lee) Date: Mon, 8 Nov 2010 23:09:01 -0800 (PST) Subject: How to Write a Winning Dissertation Message-ID: <364295c9-ac73-4362-85ef-bfc757b5e542@z17g2000prz.googlegroups.com> Writing a Dissertation requires mastery of research methods for valid and reliable data collection, availability of all the resources and perfection of dissertation format, structure and citation styles. This article offers some guiltiness about how to write a winning dissertation. Dissertation Writing certainly is very challenging and time consuming task. Writing a dissertation requires to set before clear aims and objectives, define the research approach and methods and achieve the objectives with valid and reliable results. Dissertation Writing is the most vital and exigent task for students. It is in fact a real test of their academic learning, mastery of the language, and command of expression. For students, dissertation writing has become an adamant task because of countless reasons. The most obvious reason why students fail in writing a good dissertation is that they don?t give due attention to its format, structure and the citation style. The proper format of masters dissertation is very important and it should be consistent throughout to offer a professional look. Mostly, universities prefer times new roman 12 font size with 1.5? margin on both sides to allow binding. The proper structure of any acceptable dissertation is: 1. Dissertation title 2. Dissertation acknowledgment 3. Dissertation abstract 4. Table of contents 5. Dissertation Introduction 6. Dissertation Literature review 7. Dissertation methodology 8. Dissertation results 9. Dissertation conclusion Some universities prefer to break the dissertation even to six or seven chapters. For this purpose, the results are presented in fourth chapter while a critical analysis of these results is presented in fifth chapter. Then conclusion is offered in chapter six and in the seventh chapter dissertation recommendation and limitations are offered. Finally, the citation style is also very important and if students fail to follow the given citation style by the university they are sure to fail and lose their valuable degree. Citation is must for any academic writing and every reference to any research of the author must be quoted using the required citation style. For example, in UK universities Harvard citation style and APA citation style are mostly used. In order to be familiar with these citation styles, there is a lot of material on internet and APA citation examples as well as Harvard citation examples can be found easily. Besides the format, structure and the citation style, choosing the proper research methodology is very critical for data collection process. There are two kinds of data collected for academic research: primary and the secondary. The secondary data comes from the already written sources like books, articles, journals and information available from web. On the other hand, the primary data is collected personally through interviews, case study, and surveys. Dissertation Master is the best place to get help for writing a perfect dissertation as we have hired masters of dissertation writing who are well aware of the dissertation format, dissertation structure and the dissertation data collection. Besides, our prices are very affordable, competitive and we offer attractive discounts. For more detail, visit http://www.dissertationmaster.com From clp2 at rebertia.com Tue Nov 9 02:30:24 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 8 Nov 2010 23:30:24 -0800 Subject: JavaScript vs Python (was Re: Commercial or Famous Applicattions.?) In-Reply-To: References: <201011090026.oA90QP1S095565@krusty.intranet.com.mx> Message-ID: On Mon, Nov 8, 2010 at 10:52 PM, Lawrence D'Oliveiro wrote: > In message , John Bond > wrote: > >> On 9/11/2010 5:54 AM, Lawrence D'Oliveiro wrote: >>> In message, John Bond >>> wrote: >>> >>>> I once got asked to write a list things that I'd make different in the >>>> technology world if I could, to make it better for everyone. Number 3 >>>> was "everywhere you now see Javascript or PHP, you'd see Python >>>> instead". If only... >>> >>> PHP yes, JavaScript no. >>> >> ... why? > > Because JavaScript is actually a decent language in its own right. "The Good Parts" of it anyway. Cheers, Chris From ldo at geek-central.gen.new_zealand Tue Nov 9 02:34:29 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 09 Nov 2010 20:34:29 +1300 Subject: Silly newbie question - Caret character (^) References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> Message-ID: In message , Seebs wrote: > Not so much turgidity as being WRONG. Consistently and often. Wow. And the guy?s written so many books; how does he get away with it? > (I know too little about C++ to criticize is writings about it, but people > have told me they're comparable.) I suppose seeing that ?Covers the New International Standard for C+? should have set off my alarm bells... From arnodel at gmail.com Tue Nov 9 02:34:36 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Tue, 09 Nov 2010 07:34:36 +0000 Subject: Pythonic/idiomatic? References: Message-ID: <87lj53x84z.fsf@gmail.com> Seebs writes: > I have an existing hunk of Makefile code: > CPPFLAGS = "$(filter -D* -I* -i* -U*,$(TARGET_CFLAGS))" > For those not familiar with GNU makeisms, this means "assemble a string > which consists of all the words in $(TARGET_CFLAGS) which start with one > of -D, -I, -i, or -U". So if you give it > foo -Ibar baz > it'll say > -Ibar > > I have a similar situation in a Python context, and I am wondering > whether this is an idiomatic spelling: > > ' '.join([x for x in target_cflags.split() if re.match('^-[DIiU]', x)]) You can also use the (less favoured) filter: >>> target_cflags="-ifoo -abar -U -Dbaz".split() >>> def matches_flags(flags): ... return re.compile("^-[%s]" % flags).match ... >>> ' '.join(filter(matches_flags("DiIU"), target_cflags)) '-ifoo -U -Dbaz' -- Arnaud From ldo at geek-central.gen.new_zealand Tue Nov 9 02:35:48 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 09 Nov 2010 20:35:48 +1300 Subject: How to test if a module exists? References: Message-ID: In message , Roy Smith wrote: > On the other hand, if your module's bug is that it in turn imports some > other module, which doesn't exist, you'll also get an ImportError. Does it really matter? Either way, the module is unusable. From ian.g.kelly at gmail.com Tue Nov 9 02:50:20 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 9 Nov 2010 00:50:20 -0700 Subject: JavaScript vs Python (was Re: Commercial or Famous Applicattions.?) In-Reply-To: References: <201011090026.oA90QP1S095565@krusty.intranet.com.mx> Message-ID: On Tue, Nov 9, 2010 at 12:30 AM, Chris Rebert wrote: > "The Good Parts" of it anyway. > > All hail William Goldman! Wait, what were talking about? Ian -------------- next part -------------- An HTML attachment was scrubbed... URL: From usenet-nospam at seebs.net Tue Nov 9 02:55:14 2010 From: usenet-nospam at seebs.net (Seebs) Date: 09 Nov 2010 07:55:14 GMT Subject: Silly newbie question - Caret character (^) References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> Message-ID: On 2010-11-09, Lawrence D'Oliveiro wrote: > In message , Seebs wrote: >> Not so much turgidity as being WRONG. Consistently and often. > Wow. And the guy???s written so many books; how does he get away with it? No one knows or cares. I don't mean "no one knows or cares how he gets away with it"; I mean "no one knows or cares that he's awful". The publisher doesn't care whether the books are accurate, as long as they sell, and most reviewers don't read closely enough to realize he's full of crap. In particular, he's very good at making up complications from whole cloth which aren't really problems, and then offering "solutions" which show people a clever trick to work around the problem. (e.g., his elaborate revelations about how to use feof() in C to work around his failure to understand how EOF works.) -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Tue Nov 9 03:27:13 2010 From: usenet-nospam at seebs.net (Seebs) Date: 09 Nov 2010 08:27:13 GMT Subject: Best exercises for beginers to learn? References: Message-ID: On 2010-11-08, brf256 at gmail.com wrote: > I was wondering if there are any good exercises that you > would recommend learning? Yes. *Write something you want to use.* Nothing will teach you programming as fast as programming stuff you care about for the joy of having it. Exercises that you don't care about in their own right will not catch you the same way. If you write something you want to have, you will not stop when it happens to work, but will keep tweaking it and improving it so it does what you want. That will teach you more than *any* prefab exercise that has no particular significance to you. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From michele.simionato at gmail.com Tue Nov 9 03:29:54 2010 From: michele.simionato at gmail.com (Michele Simionato) Date: Tue, 9 Nov 2010 00:29:54 -0800 (PST) Subject: How to get dynamically-created fxn's source? References: Message-ID: <10aaf181-51b1-44f3-b8f8-3a921a729b6c@a9g2000pro.googlegroups.com> On Nov 5, 5:55?pm, gb345 wrote: > For a project I'm working on I need a way to retrieve the source > code of dynamically generated Python functions. ?(These functions > are implemented dynamically in order to simulate "partial application" > in Python.[1]) ?The ultimate goal is to preserve a textual record > of transformations performed on data, along with all the data (both > pre- and post- transformation) itself. > > These transformation functions could be dynamically generated as > closures, but I suspect that this would make it more difficult to > extract source code that could serve as a reasonably self-contained > description of the transformation (because this source code would > refer to variables defined outside of the function). ?An alternative > would be to generate the *source code* for the functions dynamically, > from a template having slots (within the function's definition) > that gets filled in with actual parameter values, and pass this > source code to exec. > > In any case, the problem remains of how to extract the > dynamically-generated function's source code. > > One possibility would be to define a Transformation wrapper class > whose __init__ takes the dynamically-generated source code (a > string) as argument, keeps it around as an instance attribute for > future reference, and exec's it to define its __call__ method. > > Is this overkill/reinventing the wheel? ?IOW, does Python already > have a built-in way to achieve this same effect? > > (Also, the wrapper scheme above is somewhat loose: it's relatively > easy for the source code instance attribute (as described) to fall > out of sync with the function that actually executes when __call__ > runs. ?Maybe a tighter connection between the obtained source code > and the code that actually executes when __call__ runs is possible.) > > I'm aware of the inspect module, but from reading its source code > I gather that it is designed for inspecting source code that is > explicitly written in files, and would not be too good at inspecting > functions that are generated dynamically (i.e. not from source code > explicitly given in a source file--I hope that made sense). > > Your comments and suggestions would be much appreciated. ?Many > thanks in advance! > > G > > [1] For example, given a base function spam that has the signature > (typeT, typeT, typeT, int, int, int) and three specific integer > values X, Y, and Z, dynamically generate a new function spamXYZ > with signature (typeT, typeT, typeT) such that spamXYZ(A, B, C) is > identical to spam(A, B, C, X, Y, Z), for all possible values of A, > B, C. I wondered a lot about this issue when writing my own decorator module. You may look at the source code of the FunctionMaker class which tries to address the problem by storing the source code of the generated function into an attribute. Using inspect.getsource does not work (see http://bugs.python.org/issue1764286). Of course if you functools.partial is enough to solve your problem use it and be done with it. From geoff.bache at gmail.com Tue Nov 9 04:18:55 2010 From: geoff.bache at gmail.com (Geoff Bache) Date: Tue, 9 Nov 2010 01:18:55 -0800 (PST) Subject: A way to get setup.py to create links instead of copy Message-ID: <5ec2edeb-14cf-4c1d-919f-d4246f4af10a@f20g2000yqi.googlegroups.com> Hi all, One of the things I've always loved about Python (having come from compiled languages) was the lack of an extra step between changing my code and running it. On my current project, however, I find that I have to install my Python code with setup.py before it will run. Being used to not having this step, I easily forget to run setup.py install before they will run, and then spend time wondering why my changes didn't work. So I went into the target directory and replaced the copies with symbolic links back to the original code. This felt like a hack but does mean I don't have to install the whole time any more. I wonder if there is some standard way to deal with this situation? Regards, Geoff Bache From ldo at geek-central.gen.new_zealand Tue Nov 9 04:23:47 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 09 Nov 2010 22:23:47 +1300 Subject: Silly newbie question - Caret character (^) References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> Message-ID: In message , Seebs wrote: > The publisher doesn't care whether the books are accurate ... A sad state for the once-proud name ?Osborne? ... From costin.gament at gmail.com Tue Nov 9 04:24:09 2010 From: costin.gament at gmail.com (=?UTF-8?Q?Costin_Gamen=C8=9B?=) Date: Tue, 9 Nov 2010 11:24:09 +0200 Subject: List index out of range, but list has enough elements Message-ID: Hi, I am trying to read a string as csv, but I encountered an odd problem. Here's my code: csvfile = csv.reader(datastr.split('\n'), delimiter=';') r = '' for i in csvfile: for j in i: print j print i[0] the "print j" statement works, but "print i[0]" returns "IndexError: list index out of range". Am I missing something? From ldo at geek-central.gen.new_zealand Tue Nov 9 04:25:11 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 09 Nov 2010 22:25:11 +1300 Subject: How to test if a module exists? References: Message-ID: In message , Roy Smith wrote: > Fail early and often, that's what I say. Good advice that could apply to lots of things. Except maybe procrastination ... :) From ldo at geek-central.gen.new_zealand Tue Nov 9 04:25:54 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 09 Nov 2010 22:25:54 +1300 Subject: JavaScript vs Python References: <201011090026.oA90QP1S095565@krusty.intranet.com.mx> Message-ID: In message , Chris Rebert wrote: > On Mon, Nov 8, 2010 at 10:52 PM, Lawrence D'Oliveiro > wrote: > >> Because JavaScript is actually a decent language in its own right. > > "The Good Parts" of it anyway. Python, too, has its good parts, you have to admit... From ldo at geek-central.gen.new_zealand Tue Nov 9 04:26:52 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 09 Nov 2010 22:26:52 +1300 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: In message , Ethan Furman wrote: > Lawrence D'Oliveiro wrote: > >> In message , Tim Harig wrote: >>> >>> I personally prefer tabs as it lets *me* decide how far the apparent >>> indentations are in the code. >> >> But they don?t. Other people can have different settings, and they will >> see different indentations for your code > > That's exactly the point -- each person can decide what level of > indentation they prefer to look at. But I thought Mr Harig was referring to ?*me*? as in the author of the code, not the reader. From __peter__ at web.de Tue Nov 9 04:31:21 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 09 Nov 2010 10:31:21 +0100 Subject: Pythonic/idiomatic? References: Message-ID: Seebs wrote: > I have an existing hunk of Makefile code: > CPPFLAGS = "$(filter -D* -I* -i* -U*,$(TARGET_CFLAGS))" > For those not familiar with GNU makeisms, this means "assemble a string > which consists of all the words in $(TARGET_CFLAGS) which start with one > of -D, -I, -i, or -U". So if you give it > foo -Ibar baz > it'll say > -Ibar > > I have a similar situation in a Python context, and I am wondering > whether this is an idiomatic spelling: > > ' '.join([x for x in target_cflags.split() if re.match('^-[DIiU]', x)]) > > This appears to do the same thing, but is it an idiomatic use of list > comprehensions, or should I be breaking it out into more bits? You may be able split and match with a single regex, e. g. >>> cflags = "-Dxxx -D zzz -i- -U42-U7 -i -U" >>> re.compile(r"-[DIiU]\S*").findall(cflags) ['-Dxxx', '-D', '-i-', '-U42-U7', '-i', '-U'] >>> re.compile(r"-[DIiU]\s*(?:[^-]\S*)?").findall(cflags) ['-Dxxx', '-D zzz', '-i', '-U42-U7', '-i ', '-U'] Peter From stefan_ml at behnel.de Tue Nov 9 04:33:28 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 09 Nov 2010 10:33:28 +0100 Subject: List index out of range, but list has enough elements In-Reply-To: References: Message-ID: Costin Gamen?, 09.11.2010 10:24: > Hi, I am trying to read a string as csv, but I encountered an odd > problem. Here's my code: > > csvfile = csv.reader(datastr.split('\n'), delimiter=';') > r = '' > for i in csvfile: > for j in i: > print j > print i[0] > > the "print j" statement works, but "print i[0]" returns "IndexError: > list index out of range". Am I missing something? Are you sure the output you get from the "print j" is from the same loop iteration as the "print i[0]"? Try adding "i" to the output. Stefan From __peter__ at web.de Tue Nov 9 04:37:58 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 09 Nov 2010 10:37:58 +0100 Subject: List index out of range, but list has enough elements References: Message-ID: Costin Gamen? wrote: > Hi, I am trying to read a string as csv, but I encountered an odd > problem. Here's my code: > > csvfile = csv.reader(datastr.split('\n'), delimiter=';') > r = '' > for i in csvfile: > for j in i: > print j > print i[0] > > the "print j" statement works, but "print i[0]" returns "IndexError: > list index out of range". Am I missing something? Change print i[0] to print i You'll see that there are empty rows in your data. You cannot detect these rows with for j in i: print j because you get zero iterations, i. e. the print j statement is never executed for these rows. Peter From mdw at distorted.org.uk Tue Nov 9 04:49:32 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 09 Nov 2010 09:49:32 +0000 Subject: Pythonic/idiomatic? References: Message-ID: <8762w6n7wz.fsf.mdw@metalzone.distorted.org.uk> Seebs writes: > ' '.join([x for x in target_cflags.split() if re.match('^-[DIiU]', x)]) > > This appears to do the same thing, but is it an idiomatic use of list > comprehensions, or should I be breaking it out into more bits? It looks OK to me. You say (elsewhere in the thread) that you're stuck with 2.4 compatibility. I'd personally avoid the regexp, though, and write this (actually tested with Python 2.4!): ' '.join(i for i in target_cflags.split() for p in 'DIiU' if i.startswith('-' + p)) > You will note that of course, I have carefully made it a one-liner so I > don't have to worry about indentation*. I failed at that. You have to put up with my indentation. -- [mdw] From costin.gament at gmail.com Tue Nov 9 04:51:56 2010 From: costin.gament at gmail.com (=?UTF-8?Q?Costin_Gamen=C8=9B?=) Date: Tue, 9 Nov 2010 11:51:56 +0200 Subject: List index out of range, but list has enough elements In-Reply-To: References: Message-ID: Thank you for your timely response. Yes, I am sure "i" and "j" are from the same iteration. I should point out that "i" actually has 8 elements and that str(i) gives a nice printout. On Tue, Nov 9, 2010 at 11:33 AM, Stefan Behnel wrote: > Costin Gamen?, 09.11.2010 10:24: >> >> Hi, I am trying to read a string as csv, but I encountered an odd >> problem. Here's my code: >> >> ? ? ? ?csvfile = csv.reader(datastr.split('\n'), delimiter=';') >> ? ? ? ?r = '' >> ? ? ? ?for i in csvfile: >> ? ? ? ? ? ? ? ?for j in i: >> ? ? ? ? ? ? ? ? ? ? ? ?print j >> ? ? ? ? ? ? ? ?print i[0] >> >> the "print j" statement works, but "print i[0]" returns "IndexError: >> list index out of range". Am I missing something? > > Are you sure the output you get from the "print j" is from the same loop > iteration as the "print i[0]"? Try adding "i" to the output. > > Stefan > > -- > http://mail.python.org/mailman/listinfo/python-list > From nitinpawar432 at gmail.com Tue Nov 9 05:02:44 2010 From: nitinpawar432 at gmail.com (Nitin Pawar) Date: Tue, 9 Nov 2010 15:32:44 +0530 Subject: List index out of range, but list has enough elements In-Reply-To: References: Message-ID: You may want to try a spilt if you are getting 8 different elements then it will give you a list of those elements On Tue, Nov 9, 2010 at 3:21 PM, Costin Gamen? wrote: > Thank you for your timely response. Yes, I am sure "i" and "j" are > from the same iteration. I should point out that "i" actually has 8 > elements and that str(i) gives a nice printout. > > On Tue, Nov 9, 2010 at 11:33 AM, Stefan Behnel > wrote: > > Costin Gamen?, 09.11.2010 10:24: > >> > >> Hi, I am trying to read a string as csv, but I encountered an odd > >> problem. Here's my code: > >> > >> csvfile = csv.reader(datastr.split('\n'), delimiter=';') > >> r = '' > >> for i in csvfile: > >> for j in i: > >> print j > >> print i[0] > >> > >> the "print j" statement works, but "print i[0]" returns "IndexError: > >> list index out of range". Am I missing something? > > > > Are you sure the output you get from the "print j" is from the same loop > > iteration as the "print i[0]"? Try adding "i" to the output. > > > > Stefan > > > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -------------- next part -------------- An HTML attachment was scrubbed... URL: From mdw at distorted.org.uk Tue Nov 9 05:12:43 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 09 Nov 2010 10:12:43 +0000 Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <4cd1b9a4$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd1e274$0$29972$c3e8da3$5496439d@news.astraweb.com> <8jftftFelnU1@mid.individual.net> <87oca1b8ba.fsf.mdw@metalzone.distorted.org.uk> <87pqufx9ct.fsf@gmail.com> Message-ID: <871v6un6uc.fsf.mdw@metalzone.distorted.org.uk> Arnaud Delobelle writes: > python-mode has python-beginning-of-block (C-c C-u) and > python-end-of-block. Yes. It was one of my explicit gripes that editing Python requires one to learn entirely new and unfamiliar keystrokes for doing fairly familiar editing tasks. -- [mdw] From costin.gament at gmail.com Tue Nov 9 05:44:45 2010 From: costin.gament at gmail.com (=?UTF-8?Q?Costin_Gamen=C8=9B?=) Date: Tue, 9 Nov 2010 12:44:45 +0200 Subject: List index out of range, but list has enough elements In-Reply-To: References: Message-ID: Thank you all for your interest in my problem. As Peter pointed out, there was one row with zero elements in it and that's where my problem was (of course it was the very last row, hence my confidence I have "good" data). Have a nice one, Costin On Tue, Nov 9, 2010 at 12:02 PM, Nitin Pawar wrote: > You may want to try a spilt if you are getting 8 different elements then it > will give you a list of those elements > > On Tue, Nov 9, 2010 at 3:21 PM, Costin Gamen? > wrote: >> >> Thank you for your timely response. Yes, I am sure "i" and "j" are >> from the same iteration. I should point out that "i" actually has 8 >> elements and that str(i) gives a nice printout. >> >> On Tue, Nov 9, 2010 at 11:33 AM, Stefan Behnel >> wrote: >> > Costin Gamen?, 09.11.2010 10:24: >> >> >> >> Hi, I am trying to read a string as csv, but I encountered an odd >> >> problem. Here's my code: >> >> >> >> ? ? ? ?csvfile = csv.reader(datastr.split('\n'), delimiter=';') >> >> ? ? ? ?r = '' >> >> ? ? ? ?for i in csvfile: >> >> ? ? ? ? ? ? ? ?for j in i: >> >> ? ? ? ? ? ? ? ? ? ? ? ?print j >> >> ? ? ? ? ? ? ? ?print i[0] >> >> >> >> the "print j" statement works, but "print i[0]" returns "IndexError: >> >> list index out of range". Am I missing something? >> > >> > Are you sure the output you get from the "print j" is from the same loop >> > iteration as the "print i[0]"? Try adding "i" to the output. >> > >> > Stefan >> > >> > -- >> > http://mail.python.org/mailman/listinfo/python-list >> > >> -- >> http://mail.python.org/mailman/listinfo/python-list > > > > -- > Nitin Pawar > > From stefan_ml at behnel.de Tue Nov 9 06:00:27 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 09 Nov 2010 12:00:27 +0100 Subject: List index out of range, but list has enough elements In-Reply-To: References: Message-ID: [rearranged the responses in the right order] Costin Gamen?, 09.11.2010 11:44: >> On Tue, Nov 9, 2010 at 3:21 PM, Costin Gamen? wrote: >>> On Tue, Nov 9, 2010 at 11:33 AM, Stefan Behnel wrote: >>>> Costin Gamen?, 09.11.2010 10:24: >>>>> Hi, I am trying to read a string as csv, but I encountered an odd >>>>> problem. Here's my code: >>>>> >>>>> csvfile = csv.reader(datastr.split('\n'), delimiter=';') >>>>> r = '' >>>>> for i in csvfile: >>>>> for j in i: >>>>> print j >>>>> print i[0] >>>>> >>>>> the "print j" statement works, but "print i[0]" returns "IndexError: >>>>> list index out of range". Am I missing something? >>>> >>>> Are you sure the output you get from the "print j" is from the same loop >>>> iteration as the "print i[0]"? Try adding "i" to the output. >>>> >>> Thank you for your timely response. Yes, I am sure "i" and "j" are >>> from the same iteration. I should point out that "i" actually has 8 >>> elements and that str(i) gives a nice printout. >>> > Thank you all for your interest in my problem. As Peter pointed out, > there was one row with zero elements in it and that's where my problem > was (of course it was the very last row, hence my confidence I have > "good" data). A classic "don't be sure before you've tested". ;-) Stefan From jeanmichel at sequans.com Tue Nov 9 06:02:22 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 09 Nov 2010 12:02:22 +0100 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: <4CD92A3E.1010706@sequans.com> Jon Dufresne wrote: > On Sat, Nov 6, 2010 at 1:52 PM, Roy Smith wrote: > >> import sys >> try: >> import xx >> except ImportError: >> tb = sys.exc_traceback >> while tb: >> print tb >> tb = tb.tb_next >> >> > > I went ahead and implemented this and it now works. I even uncovered a > bug I wasn't previously seeing because now the program was failing > early! :) > > I hope there isn't a hidden naivete in using this pattern. > > Thanks, > Jon > try: ....: import xx ....: except ImportError: ....: tb = sys.exc_traceback ....: while tb: ....: print tb ....: tb = tb.tb_next ....: I don't see how it solves your problem. It does not test if a module exists, nor does it handles missing or flawed modules differently. JM From roy at panix.com Tue Nov 9 07:30:45 2010 From: roy at panix.com (Roy Smith) Date: Tue, 09 Nov 2010 07:30:45 -0500 Subject: How to test if a module exists? References: Message-ID: In article , Lawrence D'Oliveiro wrote: > In message , Roy Smith wrote: > > > On the other hand, if your module's bug is that it in turn imports some > > other module, which doesn't exist, you'll also get an ImportError. > > Does it really matter? Either way, the module is unusable. If I understand correctly, he's trying to differentiate between: 1) The module is unusable because it's not installed 2) The module is unusable because it has a bug in it. The later case implies he needs to find and fix the bug. From fred.sells at adventistcare.org Tue Nov 9 07:57:35 2010 From: fred.sells at adventistcare.org (Sells, Fred) Date: Tue, 9 Nov 2010 07:57:35 -0500 Subject: { '0':'c->c->a' ,'1':'a->b->a' .........} In-Reply-To: References: <8961af78-5f7b-46e1-95d7-014534b6e637@s4g2000yql.googlegroups.com> Message-ID: Since your keys are not unique, I would think that you would want a list of values for the object corresponding to each key. Something like Mydict = {} Mydict.setdefault(mykey, []).append(avalue) -----Original Message----- From: python-list-bounces+frsells=adventistcare.org at python.org [mailto:python-list-bounces+frsells=adventistcare.org at python.org] On Behalf Of Peter Otten Sent: Sunday, November 07, 2010 4:01 PM To: python-list at python.org Subject: Re: { '0':'c->c->a' ,'1':'a->b->a' .........} chris wrote: > have anybody a hint , how i get a dict from non unique id's and their > different related values. > > Thanks for advance > Chris > > ###random data # > a=range(10)*3 > def seqelem(): > i=random.randint(0,2) > elem=['a','b','c'][i] > return elem > > s=[seqelem() for t in range(30)] > print zip(a,s) > > ## favored result: > { '0':'c->c->a' ,'1':'a->b->a' .........} >>> import random >>> from collections import defaultdict >>> a = range(10)*3 >>> s = [random.choice("abc") for _ in a] >>> d = defaultdict(list) >>> for k, v in zip(a, s): ... d[k].append(v) ... >>> d defaultdict(, {0: ['b', 'a', 'a'], 1: ['c', 'a', 'c'], 2: ['c', 'c', 'c'], 3: ['c', 'a', 'a'], 4: ['b', 'c', 'a'], 5: ['b', 'c', 'c'], 6: ['c', 'a', 'b'], 7: ['b', 'b', 'a'], 8: ['a', 'c', 'c'], 9: ['b', 'a', 'b']}) >>> dict((k, "->".join(v)) for k, v in d.iteritems()) {0: 'b->a->a', 1: 'c->a->c', 2: 'c->c->c', 3: 'c->a->a', 4: 'b->c->a', 5: 'b->c->c', 6: 'c->a->b', 7: 'b->b->a', 8: 'a->c->c', 9: 'b->a->b'} Peter -- http://mail.python.org/mailman/listinfo/python-list From magawake at gmail.com Tue Nov 9 08:20:45 2010 From: magawake at gmail.com (Mag Gam) Date: Tue, 9 Nov 2010 08:20:45 -0500 Subject: udp sockets with python Message-ID: Hello, When measuring round trip time for the UDP echo client/server the C version is much faster. I was wondering if there is anything I can do to speed up. My current code for client looks like this.... sock=socket(AF_INET,SOCK_DGRAM) for x in range (1000): sock.sendto("foo",(server,port)) a=sock.recv(256) sock.close() The server code looks like this: UDPsock=socket(AF_INET,SOCK_DGRAM) UDPSock.bind(addr) while 1: m,c=UDPsock,recvfrom(1024) UDPsock.sendto('bar',c) UDPsock.close() I am measuring the round trip time using tcpdump. The C version is giving me around 80 microseconds (average) and the python is giving me close to 300 microseconds (average). From neilc at norwich.edu Tue Nov 9 08:24:02 2010 From: neilc at norwich.edu (Neil Cerutti) Date: 9 Nov 2010 13:24:02 GMT Subject: Compare source code References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8jt0biFob3U1@mid.individual.net> On 2010-11-07, Ethan Furman wrote: > Lawrence D'Oliveiro wrote: >> In message , Tim Harig wrote: >>> I personally prefer tabs as it lets *me* decide how far the >>> apparent indentations are in the code. >> >> But they don???t. Other people can have different settings, >> and they will see different indentations for your code > > That's exactly the point -- each person can decide what level > of indentation they prefer to look at. That ideal works only if you are disciplined to never mix tabs and spaces. "Wrapped" lines can become ugly when tabstop is changed. -- Neil Cerutti From jeanmichel at sequans.com Tue Nov 9 08:31:59 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 09 Nov 2010 14:31:59 +0100 Subject: Pythonic/idiomatic? In-Reply-To: References: Message-ID: <4CD94D4F.8010508@sequans.com> Seebs wrote: > I have an existing hunk of Makefile code: > CPPFLAGS = "$(filter -D* -I* -i* -U*,$(TARGET_CFLAGS))" > For those not familiar with GNU makeisms, this means "assemble a string > which consists of all the words in $(TARGET_CFLAGS) which start with one > of -D, -I, -i, or -U". So if you give it > foo -Ibar baz > it'll say > -Ibar > > I have a similar situation in a Python context, and I am wondering > whether this is an idiomatic spelling: > > ' '.join([x for x in target_cflags.split() if re.match('^-[DIiU]', x)]) > > This appears to do the same thing, but is it an idiomatic use of list > comprehensions, or should I be breaking it out into more bits? > > You will note that of course, I have carefully made it a one-liner so I > don't have to worry about indentation*. > > -s > [*] Kidding, I just thought this seemed like a pretty clear expression. > One pythonic way to do it, is to use an option parser. optparse (or argparse if python > 2.7) JM From martin at address-in-sig.invalid Tue Nov 9 08:42:11 2010 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Tue, 9 Nov 2010 13:42:11 +0000 (UTC) Subject: Commercial or Famous Applicattions.? References: Message-ID: On Tue, 09 Nov 2010 00:47:08 +0000, brf256 wrote: > Mailman is of course. > ...and don't forget getmail, a better behaved replacement for fetchmail. -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From icanbob at gmail.com Tue Nov 9 09:03:06 2010 From: icanbob at gmail.com (bobicanprogram) Date: Tue, 9 Nov 2010 06:03:06 -0800 (PST) Subject: Cross compiling (i386 from amd64) with distutils References: Message-ID: <347be269-f40d-45a3-a564-874d85ebb288@w38g2000pri.googlegroups.com> On Nov 7, 7:19 pm, Jason wrote: > My situation is this: I have a Diamond Systems single-board computer > with a > matching GPIO board. DS have a library for controlling the GPIO > board... but > it's a static library (libdscud-6.02.a) with an accompanying header > (dscud.h). > I'd like to create a Python extension to use the device. > > The architecture of the SBC is 486, and it runs Debian Squeeze/Grip. > While it > is possible to develop on it directly, I'd rather use my desktop > machine > (Debian Squeeze, amd64). > > If I write a simple C program to control the device, I'd include the > header > file and cross-compile it like so: > > gcc -m32 -march=i386 -lpthread -I/usr/local/dscud-6.02 -o dio > dio.c \ > /usr/local/dscud-6.02/libdscud-6.02.a > > To get myself started with the Python extension, I've basically taken > the > "noddy" demo[1] and thrown in a function call from the DSC library > just to see > if I can get something to build. > > My distutils setup.py looks like: > > ---- > from distutils.core import setup, Extension > > module1 = Extension('noddy', > sources = ['src/noddy.c'], > libraries = ['pthread'], > include_dirs = ['/usr/local/dscud-6.02'], > extra_objects = ['/usr/local/dscud-6.02/libdscud-6.02.a'], > extra_compile_args = ['-m32', '-march=i386']) > > setup(name = 'Noddy', version = '1.0', description = 'This is a demo > package', > ext_modules = [module1]) > ---- > > This works fine on the target machine with "python setup.py build", > but when I > try it on my desktop machine, I get: > > ---- > $ python setup.py build > running build > running build_ext > building 'noddy' extension > creating build > creating build/temp.linux-x86_64-2.6 > creating build/temp.linux-x86_64-2.6/src > gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall > -Wstrict-prototypes -fPIC -I/usr/local/dscud-6.02 -I/usr/include/ > python2.6 -c > src/noddy.c -o build/temp.linux-x86_64-2.6/src/noddy.o -m32 - > march=i386 > In file included from /usr/include/python2.6/Python.h:58, > from src/noddy.c:1: > /usr/include/python2.6/pyport.h:694:2: error: #error "LONG_BIT > definition > appears wrong for platform (bad gcc/glibc config?)." > error: command 'gcc' failed with exit status 1 > > ---- > > So is it possible to get distutils to cross compile something like > this, and > if so, what am I missing? Or am I using the wrong tool for the job? > > Target python ver. is 2.6. GCC is 4.4.5. > > Cheers, > Jason > > [1]http://docs.python.org/extending/newtypes.html Cross compilation might be one solution to Python access. The SIMPL toolkit (http://www.icanprogram.com/simpl; http://www.icanprogram.com/06py/lesson1/lesson1.html) might be easier. If you ultimately want to communicate from a 64bit to a 32bit system, you'll probably want to use a text based tokenized messaging strategy as opposed to the binary one in these examples. bob From franapoli at gmail.com Tue Nov 9 09:14:11 2010 From: franapoli at gmail.com (Ciccio) Date: Tue, 09 Nov 2010 15:14:11 +0100 Subject: Dictionary of lists strange behaviour Message-ID: Hi all, hope you can help me understanding why the following happens: In [213]: g = {'a': ['a1','a2'], 'b':['b1','b2']} In [214]: rg = dict.fromkeys(g.keys(),[]) In [215]: rg Out[215]: {'a': [], 'b': []} In [216]: rg['a'].append('x') In [217]: rg Out[217]: {'a': ['x'], 'b': ['x']} What I meant was appending 'x' to the list pointed by the key 'a' in the dictionary 'rg'. Why rg['b'] is written too? Thanks. From msarro at gmail.com Tue Nov 9 09:16:29 2010 From: msarro at gmail.com (Matty Sarro) Date: Tue, 9 Nov 2010 09:16:29 -0500 Subject: Best exercises for beginers to learn? In-Reply-To: References: Message-ID: I agree completely with Seebs, however I will mention that until you find a project that tickles your fancy there are some good places to find exercises. Pyschools: http://www.pyschools.com Project Euler: http://projecteuler.net/ You can also check out: http://learnpythonthehardway.org/index The exercises are pretty good. On Tue, Nov 9, 2010 at 3:27 AM, Seebs wrote: > On 2010-11-08, brf256 at gmail.com wrote: > > I was wondering if there are any good exercises that you > > would recommend learning? > > Yes. > > *Write something you want to use.* > > Nothing will teach you programming as fast as programming stuff you care > about for the joy of having it. Exercises that you don't care about in > their own right will not catch you the same way. > > If you write something you want to have, you will not stop when it > happens to work, but will keep tweaking it and improving it so it does > what you want. That will teach you more than *any* prefab exercise that > has no particular significance to you. > > -s > -- > Copyright 2010, all wrongs reversed. Peter Seebach / > usenet-nospam at seebs.net > http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures > http://en.wikipedia.org/wiki/Fair_Game_(Scientology)<-- get educated! > I am not speaking for my employer, although they do rent some of my > opinions. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From landimatte at gmail.com Tue Nov 9 09:24:11 2010 From: landimatte at gmail.com (Matteo Landi) Date: Tue, 9 Nov 2010 15:24:11 +0100 Subject: Dictionary of lists strange behaviour In-Reply-To: References: Message-ID: On Tue, Nov 9, 2010 at 3:14 PM, Ciccio wrote: > Hi all, > > hope you can help me understanding why the following happens: > > In [213]: g = {'a': ['a1','a2'], 'b':['b1','b2']} > In [214]: rg = dict.fromkeys(g.keys(),[]) The argument you pass which is used to fill the values of the new dict, is created once; this means that the empty list is shared between all the keys of the dict. I think you need to create the new dict by hand. Regards, Matteo > In [215]: rg > Out[215]: {'a': [], 'b': []} > In [216]: rg['a'].append('x') > In [217]: rg > Out[217]: {'a': ['x'], 'b': ['x']} > > What I meant was appending 'x' to the list pointed by the key 'a' in the > dictionary 'rg'. Why rg['b'] is written too? > > Thanks. > -- > http://mail.python.org/mailman/listinfo/python-list > -- Matteo Landi http://www.matteolandi.net/ From homebuz11 at gmail.com Tue Nov 9 09:28:08 2010 From: homebuz11 at gmail.com (naveed ahmed) Date: Tue, 9 Nov 2010 06:28:08 -0800 (PST) Subject: Free E-Books collection Message-ID: Freeit http://freeit11.blogspot.comis the world's leading online source of ebooks, with a vast range of ebooks from academic, Popular and professional publishers. Freeit http://freeit11.blogspot.com eBook communicates my vision of exploring the whole universe to you. What if you had a plausible method (based on today's science and technology) freeit large selection of eBooks. New eBook releases and bestsellers in over 40 categories including science fiction, romance, mystery, for more e-books visit Freeit From philip at semanchuk.com Tue Nov 9 09:42:47 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 9 Nov 2010 09:42:47 -0500 Subject: Silly newbie question - Caret character (^) In-Reply-To: References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> Message-ID: <666482B8-FFC9-4A0E-B944-5D725C368DE1@semanchuk.com> On Nov 9, 2010, at 1:04 AM, Lawrence D'Oliveiro wrote: > In message , Seebs wrote: > >> On 2010-11-09, Lawrence D'Oliveiro >> wrote: >> >>> In message , Dennis >>> Lee Bieber wrote: >>>> >>>> Have you ever looked at the reference manual for Ada? >> >>> Or even worse, the annotated reference. I thought annotations were >>> supposed to clarify things; in this case they seemed to have the opposite >>> effect... >> >> Clearly, you've never seen Schildt's infamous "Annotated ANSI C Standard". > > There absolutely no chance (or at least no way I can imagine) that anyone > could annotate a concise language like C up to the level of turgidity of the > Ada spec. > > Hang on, is this Herb Schildt? I bought a couple of his books, back when I > was trying to get to grips with C++ (I have the edition of ?C++ The Complete > Reference? which proudly proclaims it ?Covers the New International Standard > for C+?). Not as useful as I thought they would be; I ended up referring to > the libstdc++ sources to clarify things. What's funny is that I went looking for a printed copy of the C standard a few years back and the advice I got was that the cheapest route was to find a used copy of Schildt's "Annotated ANSI C Standard" and ignore the annotations. So it serves at least one useful purpose. Cheers Philip From jeanmichel at sequans.com Tue Nov 9 09:43:05 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 09 Nov 2010 15:43:05 +0100 Subject: Dictionary of lists strange behaviour In-Reply-To: References: Message-ID: <4CD95DF9.50906@sequans.com> Ciccio wrote: > Hi all, > > hope you can help me understanding why the following happens: > > In [213]: g = {'a': ['a1','a2'], 'b':['b1','b2']} > In [214]: rg = dict.fromkeys(g.keys(),[]) > In [215]: rg > Out[215]: {'a': [], 'b': []} > In [216]: rg['a'].append('x') > In [217]: rg > Out[217]: {'a': ['x'], 'b': ['x']} > > What I meant was appending 'x' to the list pointed by the key 'a' in > the dictionary 'rg'. Why rg['b'] is written too? > > Thanks. rg = dict.fromkeys(g.keys(),[]) you are intialising the content with the same object []. write instead for key in g: rg[key] = [] # python create a new list everytime it hits this line For the same reason you never assign an empty list to default parameters value: In [37]: def a(p=[]): ....: return p ....: In [38]: a1 = a() In [39]: a2 = a() In [40]: id(a1) ; id(a2) Out[40]: 161119884 Out[40]: 161119884 Jean-Michel From davea at ieee.org Tue Nov 9 10:05:44 2010 From: davea at ieee.org (Dave Angel) Date: Tue, 09 Nov 2010 10:05:44 -0500 Subject: Dictionary of lists strange behaviour In-Reply-To: References: Message-ID: <4CD96348.3070300@ieee.org> On 2:59 PM, Ciccio wrote: > Hi all, > > hope you can help me understanding why the following happens: > > In [213]: g = {'a': ['a1','a2'], 'b':['b1','b2']} > In [214]: rg = dict.fromkeys(g.keys(),[]) > In [215]: rg > Out[215]: {'a': [], 'b': []} > In [216]: rg['a'].append('x') > In [217]: rg > Out[217]: {'a': ['x'], 'b': ['x']} > > What I meant was appending 'x' to the list pointed by the key 'a' in > the dictionary 'rg'. Why rg['b'] is written too? > > Thanks. > The second argument to the fromkeys() method is an empty list object. So that object is the value for *both* the new dictionary items. It does not make a new object each time, it uses the same one. You can check this for yourself, by doing id(rg["a"]) and id(rg["b"]) I'd do something like : rg = {} for key in g.keys(): rg[key] = [] DaveA From kw at codebykevin.com Tue Nov 9 10:19:10 2010 From: kw at codebykevin.com (Kevin Walzer) Date: Tue, 09 Nov 2010 10:19:10 -0500 Subject: Commercial or Famous Applicattions.? In-Reply-To: References: Message-ID: On 11/8/10 7:18 PM, Jorge Biquez wrote: > Hello all. > > Newbie question. Sorry. > > Can you mention applications/systems/solutions made with Python that are > well known and used by public in general? ANd that maybe we do not know > they are done with Python? There are several on the Mac: Checkout, a POS program: http://checkoutapp.com/ EagleFiler, a file organizer: http://c-command.com/eaglefiler/ Phynchronicity, a GUI for Fink package manager: http://www.codebykevin.com/phynchronicity.html QuickWho, a whois search tool: http://www.codebykevin.com/quickwho.html I'm also sure there are others that I'm not aware of. --Kevin -- Kevin Walzer Code by Kevin http://www.codebykevin.com From rbotting at csusb.edu Tue Nov 9 10:26:39 2010 From: rbotting at csusb.edu (RJB) Date: Tue, 9 Nov 2010 07:26:39 -0800 (PST) Subject: Help Documenting Python Syntax Message-ID: <4d15eca9-20a5-4ad1-bdd6-f66fb386220b@y2g2000prf.googlegroups.com> I have been trying to redevelop a syntax page for Python at http://cse.csusb.edu/dick/samples/python.syntax.html I would appreciate and encouragement or corrections -- because I know there is at least one gross error in there. By the way, this is part of a suite of language definitions... going back to the 1960's RJBotting Who was PAAAAAR in the early 1980's From tjreedy at udel.edu Tue Nov 9 10:47:45 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 09 Nov 2010 10:47:45 -0500 Subject: Dictionary of lists strange behaviour In-Reply-To: References: Message-ID: On 11/9/2010 9:14 AM, Ciccio wrote: > Hi all, > > hope you can help me understanding why the following happens: > > In [213]: g = {'a': ['a1','a2'], 'b':['b1','b2']} > In [214]: rg = dict.fromkeys(g.keys(),[]) If you rewrite this as bl = [] rg = dict.fromkeys(g.keys(),bl) is the answer any more obvious? > In [215]: rg > Out[215]: {'a': [], 'b': []} > In [216]: rg['a'].append('x') > In [217]: rg > Out[217]: {'a': ['x'], 'b': ['x']} > > What I meant was appending 'x' to the list pointed by the key 'a' in the > dictionary 'rg'. Why rg['b'] is written too? -- Terry Jan Reedy From invalid at invalid.invalid Tue Nov 9 10:53:42 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 9 Nov 2010 15:53:42 +0000 (UTC) Subject: Commercial or Famous Applicattions.? References: Message-ID: On 2010-11-09, Jorge Biquez wrote: > Can you mention applications/systems/solutions made with Python that > are well known and used by public in general? ANd that maybe we do > not know they are done with Python? I'm not sure how much the "public in general" knows about it, but one I ran across recently is OpenERP: http://www.openerp.com/ It's a complete CRM/purchasing/HR/Accouting/Inventory/etc. system for businesses. Other programs I've used that I noticed were written in Python: Freevo (PVR/DVR HTPC media center) bittorrent (the original apps) RedHat's installer and some admin utils. Gentoos "emerge" build system. meld (source code diff/merge tool) skencil (vector drafting program) bitpim (cellphone data synch app) PyNeighborhood (network neighborhood browser) I'm sure there are dozens more that I've used and never realized they were written in Python. Last time I checked IBM/Lenovo computers all came with Python installed, since some of the pre-installed admin/maintenance stuff is written in Python. -- Grant Edwards grant.b.edwards Yow! Are we live or on at tape? gmail.com From darragh.ssa at gmail.com Tue Nov 9 11:04:43 2010 From: darragh.ssa at gmail.com (Kruptein) Date: Tue, 9 Nov 2010 08:04:43 -0800 (PST) Subject: Deditor 0.2.2 References: <6cdb5dd1-1868-4a6e-8b59-5b871f8d412e@42g2000prt.googlegroups.com> Message-ID: <613e4abc-329b-4ab3-8349-b3ec047cb747@r14g2000yqa.googlegroups.com> On Nov 8, 3:01?pm, Jean-Michel Pichavant wrote: > TheSeeker wrote: > > On Nov 6, 7:06 am, Kruptein wrote: > > >> Hey, > > >> I released version 0.2.2 of my pythonic text-editor ?Deditor. > >> It adds the use of projects, a project is a set of files which you can > >> open all at once to make development much faster and easier. > > >> For more information visit launchpad:http://launchpad.net/deditor > > >> I also uploaded a video to introduce you to deditor:http://www.youtube.com/watch?v=hS8xBu-39VI > >> (note: youtube is still processing the file so you might have to wait > >> a bit to see it) > > > Hi, > > I might have missed this, but it seems deditor requires Python above > > 2.5? > > > It would be nice to mention the requirements on the home page > > somewhere. > > > Thanks, > > Duane > > I already point that on the last release. You should really just > consider writing the requirements (python & wx). > > JM I'm going todo that right now! I alswyas forget it :p From tjreedy at udel.edu Tue Nov 9 11:06:09 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 09 Nov 2010 11:06:09 -0500 Subject: Help Documenting Python Syntax In-Reply-To: <4d15eca9-20a5-4ad1-bdd6-f66fb386220b@y2g2000prf.googlegroups.com> References: <4d15eca9-20a5-4ad1-bdd6-f66fb386220b@y2g2000prf.googlegroups.com> Message-ID: On 11/9/2010 10:26 AM, RJB wrote: > I have been trying to redevelop a syntax page for Python at > http://cse.csusb.edu/dick/samples/python.syntax.html Page does not load correctly; had to hit refresh to get entire page. It should specify that this is the syntax for Python 2.5. To me "the Python language" is 3.2. > I would appreciate and encouragement or corrections -- because I know > there is at least one gross error in there. -- Terry Jan Reedy From invalid at invalid.invalid Tue Nov 9 11:14:30 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 9 Nov 2010 16:14:30 +0000 (UTC) Subject: Help Documenting Python Syntax References: <4d15eca9-20a5-4ad1-bdd6-f66fb386220b@y2g2000prf.googlegroups.com> Message-ID: On 2010-11-09, Terry Reedy wrote: > On 11/9/2010 10:26 AM, RJB wrote: >> I have been trying to redevelop a syntax page for Python at >> http://cse.csusb.edu/dick/samples/python.syntax.html > > Page does not load correctly; had to hit refresh to get entire page. > It should specify that this is the syntax for Python 2.5. To me "the > Python language" is 3.2. Nope. I just checked, and it's 2.6.5: $ python Python 2.6.5 (release26-maint, Aug 9 2010, 11:06:44) ;) My question is why bother with 2.5? I would think the logical choices would be 3.2 or 2.7 (or maybe 2.6). -- Grant Edwards grant.b.edwards Yow! I have a TINY BOWL in at my HEAD gmail.com From calderone.jeanpaul at gmail.com Tue Nov 9 11:20:40 2010 From: calderone.jeanpaul at gmail.com (Jean-Paul Calderone) Date: Tue, 9 Nov 2010 08:20:40 -0800 (PST) Subject: udp sockets with python References: Message-ID: <34f2de21-0bdf-46b1-9fef-77717fc56239@r4g2000prj.googlegroups.com> On Nov 9, 5:20?am, Mag Gam wrote: > Hello, > > When measuring round trip time for the UDP echo client/server the C > version is much faster. I was wondering if there is anything I can do > to speed up. > > My current code for client looks like this.... > > sock=socket(AF_INET,SOCK_DGRAM) > for x in range (1000): > ? sock.sendto("foo",(server,port)) > ? a=sock.recv(256) > > sock.close() > > The server code looks like this: > UDPsock=socket(AF_INET,SOCK_DGRAM) > UDPSock.bind(addr) > while 1: > ? m,c=UDPsock,recvfrom(1024) > ? UDPsock.sendto('bar',c) > > UDPsock.close() > > I am measuring the round trip time using tcpdump. The C version is > giving me around 80 microseconds (average) and the python is giving me > close to 300 microseconds (average). Try replacing the hostname in your send calls with an IP address. If you're not passing an IP address here, then the Python version has to do a name lookup for each send, I bet your C version is not. Jean-Paul From franapoli at gmail.com Tue Nov 9 12:19:32 2010 From: franapoli at gmail.com (Ciccio) Date: Tue, 09 Nov 2010 18:19:32 +0100 Subject: Dictionary of lists strange behaviour References: Message-ID: Il 09/11/2010 16:47, Terry Reedy ha scritto: > On 11/9/2010 9:14 AM, Ciccio wrote: >> Hi all, >> >> hope you can help me understanding why the following happens: >> >> In [213]: g = {'a': ['a1','a2'], 'b':['b1','b2']} >> In [214]: rg = dict.fromkeys(g.keys(),[]) > > If you rewrite this as > > bl = [] > rg = dict.fromkeys(g.keys(),bl) > > is the answer any more obvious? It isn't since I erroneously assumed that a clone of the object would be made in both cases. Thanks for your help From franapoli at gmail.com Tue Nov 9 12:23:07 2010 From: franapoli at gmail.com (Ciccio) Date: Tue, 09 Nov 2010 18:23:07 +0100 Subject: Dictionary of lists strange behaviour References: Message-ID: Thank you all, this was timely and helpful. francesco From moura.mario at gmail.com Tue Nov 9 12:32:17 2010 From: moura.mario at gmail.com (macm) Date: Tue, 9 Nov 2010 09:32:17 -0800 (PST) Subject: Learning Pyhton - Functional Programming - How intersect/difference two dict with dict/values? fast! Message-ID: <4d71519e-a232-427f-b4e0-5bae90fc4acb@n32g2000prc.googlegroups.com> Hi Folks, dict1 = {'ab':[[1,2,3,'d3','d4',5],12],'ac':[[1,3,'78a','79b'], 54],'ad': [[56,57,58,59],34], 'ax': [[56,57,58,59],34]} dict2 = {'ab':[[22,2,'a0','42s','c4','d3'],12],'ab':[[2,4,50,42,'c4'], 12],'ac':[[1,3,'79b',45,65,'er4'],54],'ae': [[56,57,58,59],34],'ax': [[9],34]} dict3 = {'ac':[[1,3,67,'gf'],12],'at':[[2,4,50,42,'c4'],12],'as': [[1,3,'79b',45,65,'er4'],54],'ae': [[56,57,58,59],34]} intersect = filter(dict1.has_key, dict2.keys()) intersect result: ['ax', 'ac', 'ab'] expect result dict1 intersection with dict2 {'ac':[1,3,'79b'], 'ab':[2,'d3']} # look last key/value 'ax' (dict1, dict2) even intersec a key but not values from list so not valid and difference from dict3 dict3 = {'ac':[[1,3,67,'gf'],12],'at':[[2,4,50,42,'c4'],12],'as': [[1,3,'79b',45,65,'er4'],54],'ae': [[56,57,58,59],34]} result from (intersect - dict3) {'ac':['79b'], 'ab':[2,'d3']} Thanks in advance! Before someone blame me. Yes I am trying learn python Functional Programming! ; ) Best Regards macm From steve at holdenweb.com Tue Nov 9 12:33:09 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 09 Nov 2010 12:33:09 -0500 Subject: A way to get setup.py to create links instead of copy In-Reply-To: <5ec2edeb-14cf-4c1d-919f-d4246f4af10a@f20g2000yqi.googlegroups.com> References: <5ec2edeb-14cf-4c1d-919f-d4246f4af10a@f20g2000yqi.googlegroups.com> Message-ID: On 11/9/2010 4:18 AM, Geoff Bache wrote: > Hi all, > > One of the things I've always loved about Python (having come from > compiled languages) was the lack of an extra step between changing my > code and running it. > > On my current project, however, I find that I have to install my > Python code with setup.py before it will run. Being used to not having > this step, I easily forget to run setup.py install before they will > run, and then spend time wondering why my changes didn't work. > > So I went into the target directory and replaced the copies with > symbolic links back to the original code. This felt like a hack but > does mean I don't have to install the whole time any more. > > I wonder if there is some standard way to deal with this situation? > Yes, there is. It involves (to a first approximation) understanding the role of sys.path, and its relationship with the PYTHONPATH environment variable. In brief, this tells the interpreter where to look for modules when it is importing. Installation with setup.py is normally reserved for a fairly permanent insertion of the code into your Python distribution, which might have added it for all users. If this is an issue you may want to undo the installation manually by removing its additions to your Python's Lib/site-packages directory. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From tjreedy at udel.edu Tue Nov 9 12:57:28 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 09 Nov 2010 12:57:28 -0500 Subject: Silly newbie question - Caret character (^) In-Reply-To: References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> Message-ID: On 11/9/2010 2:00 AM, Seebs wrote: > Yes, Herb Schildt: > http://www.seebs.net/c/c_tcn4e.html I've been wondering why C programmers keep writing code susceptible to buffer overruns ;=). Your two 'nitpicks' about fflush have both come up on this list as real issues causing people problems. So I agree that it needs to be explained properly and completely as you suggest. -- Terry Jan Reedy From jon.dufresne at gmail.com Tue Nov 9 13:06:39 2010 From: jon.dufresne at gmail.com (Jon Dufresne) Date: Tue, 9 Nov 2010 10:06:39 -0800 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: On Tue, Nov 9, 2010 at 4:30 AM, Roy Smith wrote: > In article , > ?Lawrence D'Oliveiro wrote: > >> In message , Roy Smith wrote: >> >> > On the other hand, if your module's bug is that it in turn imports some >> > other module, which doesn't exist, you'll also get an ImportError. >> >> Does it really matter? Either way, the module is unusable. > > If I understand correctly, he's trying to differentiate between: > > 1) The module is unusable because it's not installed > > 2) The module is unusable because it has a bug in it. > Yes. Case 1 is an acceptable case. In case 1, if the extension module (extension as in extension to my core program) does not have magic.py then the extension adds no behavior in the magic1 portion of the program. However, if the extension does have magic.py but it is buggy (case 2), I want my program to fail. Currently I am doing this using the traceback code suggested in an earlier post. From jon.dufresne at gmail.com Tue Nov 9 13:08:05 2010 From: jon.dufresne at gmail.com (Jon Dufresne) Date: Tue, 9 Nov 2010 10:08:05 -0800 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: On Mon, Nov 8, 2010 at 11:35 PM, Lawrence D'Oliveiro wrote: > In message , Roy Smith wrote: > >> On the other hand, if your module's bug is that it in turn imports some >> other module, which doesn't exist, you'll also get an ImportError. > > Does it really matter? Either way, the module is unusable. In my program it matters. If the module exists but is buggy, then I want to be notified immediately to fix it. However if the module does not exist in an extension module (keyword being extension) then the extensions doesn't add behavior to that part of the program. From __peter__ at web.de Tue Nov 9 13:14:15 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 09 Nov 2010 19:14:15 +0100 Subject: Learning Pyhton - Functional Programming - How intersect/difference two dict with dict/values? fast! References: <4d71519e-a232-427f-b4e0-5bae90fc4acb@n32g2000prc.googlegroups.com> Message-ID: macm wrote: > Hi Folks, > > dict1 = {'ab':[[1,2,3,'d3','d4',5],12],'ac':[[1,3,'78a','79b'], > 54],'ad': [[56,57,58,59],34], 'ax': [[56,57,58,59],34]} > dict2 = {'ab':[[22,2,'a0','42s','c4','d3'],12],'ab':[[2,4,50,42,'c4'], > 12],'ac':[[1,3,'79b',45,65,'er4'],54],'ae': [[56,57,58,59],34],'ax': > [[9],34]} > dict3 = {'ac':[[1,3,67,'gf'],12],'at':[[2,4,50,42,'c4'],12],'as': > [[1,3,'79b',45,65,'er4'],54],'ae': [[56,57,58,59],34]} > intersect = filter(dict1.has_key, dict2.keys()) > intersect > result: > ['ax', 'ac', 'ab'] > > expect result dict1 intersection with dict2 > {'ac':[1,3,'79b'], 'ab':[2,'d3']} # look last key/value 'ax' (dict1, > dict2) even intersec a key but not values from list so not valid > > and difference from dict3 > dict3 = {'ac':[[1,3,67,'gf'],12],'at':[[2,4,50,42,'c4'],12],'as': > [[1,3,'79b',45,65,'er4'],54],'ae': [[56,57,58,59],34]} > > result from (intersect - dict3) > {'ac':['79b'], 'ab':[2,'d3']} > > Thanks in advance! > > Before someone blame me. > > Yes I am trying learn python Functional Programming! ; ) >>> dict((k, v) for k, v in ((k, [a for a in v if a in w]) for k, v, w in ((k, v[0], set(dict2[k][0])) for k, v in dict1.iteritems() if k in dict2)) if v) {'ac': [1, 3, '79b'], 'ab': [2]} Replacing the genexps with map/filter/lambda is left as an exercise. > Before someone blame me. I'm trying to set new standards in readability ;) From tjreedy at udel.edu Tue Nov 9 13:43:43 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 09 Nov 2010 13:43:43 -0500 Subject: Dictionary of lists strange behaviour In-Reply-To: References: Message-ID: On 11/9/2010 12:19 PM, Ciccio wrote: > Il 09/11/2010 16:47, Terry Reedy ha scritto: >> On 11/9/2010 9:14 AM, Ciccio wrote: >>> Hi all, >>> >>> hope you can help me understanding why the following happens: >>> >>> In [213]: g = {'a': ['a1','a2'], 'b':['b1','b2']} >>> In [214]: rg = dict.fromkeys(g.keys(),[]) >> >> If you rewrite this as >> >> bl = [] >> rg = dict.fromkeys(g.keys(),bl) >> >> is the answer any more obvious? > > It isn't since I erroneously assumed that a clone of the object would be > made in both cases. I can see how you might think that, especially if you have experience with other languages where that would be usual. In Python, the general policy is to not copy objects unless explicitly requested. None, False, and True cannot be copied. There is essentially never a reason to copy a number or string or tuple. I believe dict.fromkeys is more usually given None or 0 or '' as value initializer. List *is* useful as an initializer for collecitons.defaultdicts. -- Terry Jan Reedy From msarro at gmail.com Tue Nov 9 14:00:17 2010 From: msarro at gmail.com (Matty Sarro) Date: Tue, 9 Nov 2010 14:00:17 -0500 Subject: An easier way to do this? (spoiler if you're using pyschools for fun) Message-ID: Hey everyone, I'm working on one of the puzzles on pyschools.com, and am trying to figure out if I can make my solution a bit more elegant. def getSumOfLastDigit(numList): sumOfDigits=0 for i in range(0, len(numList)): num=str(numList.pop()) sumOfDigits+=int(num[-1:]) return sumOfDigits Below is the problem. Basically you take the last digit of each number in the list, and add them together. Write a function: getSumOfLastDigit(numList) that takes in a list of positive numbers and returns the sum of all the last digit in the list. *Examples* >>> getSumOfLastDigit([12, 23, 34]) 9 >>> getSumOfLastDigit([2, 3, 4]) 9 >>> getSumOfLastDigit([1, 23, 456]) 10 -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Tue Nov 9 14:09:31 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 9 Nov 2010 11:09:31 -0800 Subject: An easier way to do this? (spoiler if you're using pyschools for fun) In-Reply-To: References: Message-ID: On Tue, Nov 9, 2010 at 11:00 AM, Matty Sarro wrote: > Hey everyone, > I'm working on one of the puzzles on pyschools.com, and am trying to figure > out if I can make my solution a bit more elegant. > > def getSumOfLastDigit(numList): > ??? sumOfDigits=0 > ??? for i in range(0, len(numList)): > ??? ??? num=str(numList.pop()) Just loop over the list directly: for num in numList: num = str(num) > ??? ??? sumOfDigits+=int(num[-1:]) No need for the colon: sumOfDigits+= int(num[-1]) > ??? return sumOfDigits And now for the much simpler math-based solution: def getSumOfLastDigit(numList): return sum(num%10 for num in numList) Cheers, Chris -- http://blog.rebertia.com From __peter__ at web.de Tue Nov 9 14:13:47 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 09 Nov 2010 20:13:47 +0100 Subject: An easier way to do this? (spoiler if you're using pyschools for fun) References: Message-ID: Matty Sarro wrote: > Hey everyone, > I'm working on one of the puzzles on pyschools.com, and am trying to > figure out if I can make my solution a bit more elegant. > > def getSumOfLastDigit(numList): > sumOfDigits=0 > for i in range(0, len(numList)): > num=str(numList.pop()) > sumOfDigits+=int(num[-1:]) > return sumOfDigits > > Below is the problem. Basically you take the last digit of each number in > the list, and add them together. > > Write a function: getSumOfLastDigit(numList) that takes in a list of > positive numbers and returns the sum of all the last digit in the list. > > *Examples* > > >>> getSumOfLastDigit([12, 23, 34]) > 9 > >>> getSumOfLastDigit([2, 3, 4]) > 9 > >>> getSumOfLastDigit([1, 23, 456]) > 10 Loop over a list directly: for n in numlist: # ... Use the modulo (%) operator to find the last digit: last_digit = n % 10 There is a built-in sum() function: sum([1,2,3]) # 6 There is an inlined form of the for-loop called "generator expression" sum(i*i for i in [1,2,3]) # 14 Putting it all together: >>> def gsold(numbers): ... return sum(i%10 for i in numbers) ... >>> gsold([12,23,34]) 9 >>> gsold([2,3,4]) 9 >>> gsold([1,23,456]) 10 Peter From tjreedy at udel.edu Tue Nov 9 14:18:34 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 09 Nov 2010 14:18:34 -0500 Subject: An easier way to do this? (spoiler if you're using pyschools for fun) In-Reply-To: References: Message-ID: On 11/9/2010 2:00 PM, Matty Sarro wrote: > I'm working on one of the puzzles on pyschools.com > , and am trying to figure out if I can make my > solution a bit more elegant. Definitely > def getSumOfLastDigit(numList): > sumOfDigits=0 > for i in range(0, len(numList)): > num=str(numList.pop()) This is an awkward way to iterate through a list ;-) > sumOfDigits+=int(num[-1:]) > return sumOfDigits > Write a function: getSumOfLastDigit(numList) that takes in a list of > positive numbers and returns the sum of all the last digit in the list. > > *Examples* > >>> getSumOfLastDigit([12, 23, 34]) > 9 > >>> getSumOfLastDigit([2, 3, 4]) > 9 > >>> getSumOfLastDigit([1, 23, 456]) > 10 # Straightforward version of what you did def getSumOfLastDigit(numList): sumOfDigits=0 for i in numList: sumOfDigits+=int(str(i)[-1:]) return sumOfDigits print(getSumOfLastDigit([12, 23, 34]), getSumOfLastDigit([2, 3, 4]), getSumOfLastDigit([1, 23, 456]) ) # 9 9 10 # Use generator expression with built-in sum function def getSumOfLastDigit(numList): return sum(int(str(i)[-1:]) for i in numList) print(getSumOfLastDigit([12, 23, 34]), getSumOfLastDigit([2, 3, 4]), getSumOfLastDigit([1, 23, 456]) ) # 9 9 10 -- Terry Jan Reedy From nagle at animats.com Tue Nov 9 15:39:07 2010 From: nagle at animats.com (John Nagle) Date: Tue, 09 Nov 2010 12:39:07 -0800 Subject: Learning Pyhton - Functional Programming - How intersect/difference two dict with dict/values? fast! In-Reply-To: <4d71519e-a232-427f-b4e0-5bae90fc4acb@n32g2000prc.googlegroups.com> References: <4d71519e-a232-427f-b4e0-5bae90fc4acb@n32g2000prc.googlegroups.com> Message-ID: <4cd9b16d$0$1640$742ec2ed@news.sonic.net> On 11/9/2010 9:32 AM, macm wrote: > Hi Folks, > > dict1 = {'ab':[[1,2,3,'d3','d4',5],12],'ac':[[1,3,'78a','79b'], > 54],'ad': [[56,57,58,59],34], 'ax': [[56,57,58,59],34]} > dict2 = {'ab':[[22,2,'a0','42s','c4','d3'],12],'ab':[[2,4,50,42,'c4'], > 12],'ac':[[1,3,'79b',45,65,'er4'],54],'ae': [[56,57,58,59],34],'ax': > [[9],34]} > dict3 = {'ac':[[1,3,67,'gf'],12],'at':[[2,4,50,42,'c4'],12],'as': > [[1,3,'79b',45,65,'er4'],54],'ae': [[56,57,58,59],34]} > intersect = filter(dict1.has_key, dict2.keys()) > intersect > result: > ['ax', 'ac', 'ab'] When you've spent a year maintaining and fixing code written by others, come back and we'll talk. John Nagle From greg.ewing at canterbury.ac.nz Tue Nov 9 15:44:29 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 10 Nov 2010 09:44:29 +1300 Subject: Why "flat is better than nested"? In-Reply-To: References: Message-ID: <8jtq5dF67vU1@mid.individual.net> Lawrence D'Oliveiro wrote: > In message > , rustom > wrote: > >>If you take zen seriously you dont get it >>If you dont take zen seriously you dont get it >>That -- seriously -- is zen > > I don?t get it. I get it. Does that mean that I don't get it? -- Greg From tjreedy at udel.edu Tue Nov 9 15:55:16 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 09 Nov 2010 15:55:16 -0500 Subject: Learning Pyhton - Functional Programming - How intersect/difference two dict with dict/values? fast! In-Reply-To: <4cd9b16d$0$1640$742ec2ed@news.sonic.net> References: <4d71519e-a232-427f-b4e0-5bae90fc4acb@n32g2000prc.googlegroups.com> <4cd9b16d$0$1640$742ec2ed@news.sonic.net> Message-ID: > On 11/9/2010 9:32 AM, macm wrote: >> dict1 = {'ab':[[1,2,3,'d3','d4',5],12],'ac':[[1,3,'78a','79b'], >> 54],'ad': [[56,57,58,59],34], 'ax': [[56,57,58,59],34]} To echo John Nagle's point, if you want non-masochist volunteers to read your code, write something readable like: dict1 = {'ab': [[1,2,3,'d3','d4',5], 12], 'ac': [[1,3,'78a','79b'], 54], 'ad': [[56,57,58,59], 34], 'ax': [[56,57,58,59], 34]} -- Terry Jan Reedy From darcy at druid.net Tue Nov 9 16:03:56 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 9 Nov 2010 16:03:56 -0500 Subject: Learning Pyhton - Functional Programming - How intersect/difference two dict with dict/values? fast! In-Reply-To: References: <4d71519e-a232-427f-b4e0-5bae90fc4acb@n32g2000prc.googlegroups.com> <4cd9b16d$0$1640$742ec2ed@news.sonic.net> Message-ID: <20101109160356.c9ea3ab2.darcy@druid.net> On Tue, 09 Nov 2010 15:55:16 -0500 Terry Reedy wrote: > To echo John Nagle's point, if you want non-masochist volunteers to read > your code, write something readable like: > > dict1 = {'ab': [[1,2,3,'d3','d4',5], 12], > 'ac': [[1,3,'78a','79b'], 54], > 'ad': [[56,57,58,59], 34], > 'ax': [[56,57,58,59], 34]} I have been learning to like this form: dict1 = dict( ab = [[1,2,3,'d3','d4',5], 12], ac = [[1,3,'78a','79b'], 54], ad = [[56,57,58,59], 34], ax = [[56,57,58,59], 34], ) Of course, it only works when all the keys are strings. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From stef.mientki at gmail.com Tue Nov 9 16:09:06 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Tue, 09 Nov 2010 22:09:06 +0100 Subject: JavaScript vs Python In-Reply-To: References: <201011090026.oA90QP1S095565@krusty.intranet.com.mx> Message-ID: <4CD9B872.3020905@gmail.com> On 09-11-2010 10:25, Lawrence D'Oliveiro wrote: > In message , Chris > Rebert wrote: > >> On Mon, Nov 8, 2010 at 10:52 PM, Lawrence D'Oliveiro >> wrote: >> >>> Because JavaScript is actually a decent language in its own right. >> "The Good Parts" of it anyway. > Python, too, has its good parts, you have to admit... And there's a (or even more) Python to JS compilers, I never heard of a JS to Python compiler. cheers, Stef From greg.ewing at canterbury.ac.nz Tue Nov 9 16:09:52 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 10 Nov 2010 10:09:52 +1300 Subject: populating a doubly-subscripted array In-Reply-To: <87aaljmm44.fsf.mdw@metalzone.distorted.org.uk> References: <87aaljmm44.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <8jtrl3FgvdU1@mid.individual.net> Mark Wooding wrote: > What [x] * n does is make a list, whose length is n, and all of whose > entries are precisely the value x. If x itself is a list, then you get > an outer list all of whose entries are the /same/ inner list A reasonably elegant way to fix this is to use list comprehensions for all except the innermost list: ff = [[0.0]*5 for i in xrange(5)] If you're computing heavily with arrays, you might also consider using numpy arrays instead of lists. -- Greg From jjposner at optimum.net Tue Nov 9 16:13:07 2010 From: jjposner at optimum.net (John Posner) Date: Tue, 09 Nov 2010 16:13:07 -0500 Subject: Why "flat is better than nested"? In-Reply-To: <8jtq5dF67vU1@mid.individual.net> References: <8jtq5dF67vU1@mid.individual.net> Message-ID: <4CD9B963.6060709@optimum.net> On 11/9/2010 3:44 PM, Gregory Ewing wrote: >> >> I don?t get it. > > I get it. Does that mean that I don't get it? Yes. As Dr. Feynman said about quantum mechanics. -John From mdw at distorted.org.uk Tue Nov 9 16:14:27 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 09 Nov 2010 21:14:27 +0000 Subject: functions, list, default parameters References: <4cc0fcc0$0$1593$742ec2ed@news.sonic.net> <8ivelpFif1U1@mid.individual.net> <4cca88bc$0$29987$c3e8da3$5496439d@news.astraweb.com> <8j1seqFa1eU2@mid.individual.net> Message-ID: <87tyjqkxn0.fsf.mdw@metalzone.distorted.org.uk> Lawrence D'Oliveiro writes: > In message , Robert Kern > wrote: > > So examining LHS "selectors" is not sufficient for determining > > immutability. > > Yes it is. All your attempts at counterexamples showed is that it is not > necessary, not that it is not sufficient. You've got them the wrong way around. A is sufficient for B if and only if B is true whenever A is true; i.e., it is never the case that A is true and B is false. In this case, we also say that B is necessary for A. See also http://en.wikipedia.org/wiki/Necessary_and_sufficient_condition -- [mdw] From mdw at distorted.org.uk Tue Nov 9 16:21:25 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 09 Nov 2010 21:21:25 +0000 Subject: Silly newbie question - Caret character (^) References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> Message-ID: <87pquekxbe.fsf.mdw@metalzone.distorted.org.uk> Philip Semanchuk writes: > What's funny is that I went looking for a printed copy of the C > standard a few years back and the advice I got was that the cheapest > route was to find a used copy of Schildt's "Annotated ANSI C Standard" > and ignore the annotations. So it serves at least one useful purpose. The book was much cheaper than a copy of the C standard from ANSI or ISO even when it was new. It was a common joke (HHOS) at the time that the difference in price reflected the value of the annotations. (It also has two errors in the actual text of the standard. There's a character missing in the syntax summary, and one page was omitted entirely, replaced by a copy of the previous page: my copy came with a corrected page ineptly glued in at the relevant place.) -- [mdw] From jjposner at optimum.net Tue Nov 9 16:25:51 2010 From: jjposner at optimum.net (John Posner) Date: Tue, 09 Nov 2010 16:25:51 -0500 Subject: Dictionary of lists strange behaviour In-Reply-To: References: Message-ID: <4CD9BC5F.9090707@optimum.net> On 11/9/2010 1:43 PM, Terry Reedy wrote: > ... List *is* useful as an initializer for > collecitons.defaultdicts. And it was useful when several members of this forum helped me to develop a prime-number generator. See http://www.mail-archive.com/python-list at python.org/msg288128.html. (I meant to post this to the "functions, list, default parameters" thread, but never got a round tuit.) -John From duane.kaufman at gmail.com Tue Nov 9 16:36:17 2010 From: duane.kaufman at gmail.com (TheSeeker) Date: Tue, 9 Nov 2010 13:36:17 -0800 (PST) Subject: Deditor 0.2.2 References: <6cdb5dd1-1868-4a6e-8b59-5b871f8d412e@42g2000prt.googlegroups.com> <613e4abc-329b-4ab3-8349-b3ec047cb747@r14g2000yqa.googlegroups.com> Message-ID: <8004a3c1-5c08-430a-b42d-11ca8c1e2f1a@v28g2000prn.googlegroups.com> On Nov 9, 10:04?am, Kruptein wrote: > On Nov 8, 3:01?pm, Jean-Michel Pichavant > wrote: > > > > > > > > > > > TheSeeker wrote: > > > On Nov 6, 7:06 am, Kruptein wrote: > > > >> Hey, > > > >> I released version 0.2.2 of my pythonic text-editor ?Deditor. > > >> It adds the use of projects, a project is a set of files which you can > > >> open all at once to make development much faster and easier. > > > >> For more information visit launchpad:http://launchpad.net/deditor > > > >> I also uploaded a video to introduce you to deditor:http://www.youtube.com/watch?v=hS8xBu-39VI > > >> (note: youtube is still processing the file so you might have to wait > > >> a bit to see it) > > > > Hi, > > > I might have missed this, but it seems deditor requires Python above > > > 2.5? > > > > It would be nice to mention the requirements on the home page > > > somewhere. > > > > Thanks, > > > Duane > > > I already point that on the last release. You should really just > > consider writing the requirements (python & wx). > > > JM > > I'm going todo that right now! I alswyas forget it :p Hi, I was wondering if there was any reason deditor will not work under Windows? I tried to run it and got the following (Python 2.6, wxPython 2.8): Traceback (most recent call last): File "C:\junk\deditor-0.2.2\deditor.py", line 910, in deditor = DEDITOR(None, -1, "") File "C:\junk\deditor-0.2.2\deditor.py", line 101, in __init__ self.initialize() File "C:\junk\deditor-0.2.2\deditor.py", line 342, in initialize self.menu.SetLabel(4,self.menu.GetLabel(4).strip("_") +"\t"+"+".join(self.get _base_config("keys", "ctab").split(","))) File "C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 1136 6, in GetLabel return _core_.MenuBar_GetLabel(*args, **kwargs) wx._core.PyAssertionError: C++ assertion "item" failed at ..\..\src \common\menuc mn.cpp(1125) in wxMenuBarBase::GetLabel(): wxMenuBar::GetLabel(): no such item Thanks, Duane From mdw at distorted.org.uk Tue Nov 9 16:36:52 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 09 Nov 2010 21:36:52 +0000 Subject: subclassing str References: <5dLBo.1024$w8.406@twister2.libero.it> <6048c71a-fba9-4244-9a36-a5d19c8a5516@y23g2000yqd.googlegroups.com> Message-ID: <87lj52kwln.fsf.mdw@metalzone.distorted.org.uk> rantingrick writes: > One thing i love about Python is the fact that it can please almost > all the "religious paradigm zealots" with it's multiple choice > approach to programming. However some of the features that OOP > fundamentalists hold dear in their heart are not always achievable in > a clean manner with Python. Yes you could use a function but that is > not the OOP way. It can be more than just an aesthetic difference. Sometimes it can be nice to extend existing classes to understand additional protocols. For example, suppose you're implementing some object serialization format: it'd be really nice if you could add `serialize' methods to `str', `int', `list' and friends. This is certainly the Smalltalk way. Unfortunately, you can't do it in Python. One option is to implement a subclass which implements the additional protocol. This causes fragmentation: now each protocol wants its own subclass: if you want an object which understands both protocols, you need to mess with multiple inheritance[1] (and, in Python, at least, hope that everyone is using `super' properly to implement upwards delegation). Otherwise you have to do the dispatch yourself, either by hand or by using one of the generic function/multimethod frameworks. [1] At least Python gives you a fighting chance of getting this to work. Java and C# won't countenance multiple inheritance at all, and C++ will botch it all by giving you a separate copy of the common superclass's state for each protocol implementation (what are the chances that everyone decided to use a virtual base class?) /and/ hideously breaking upwards delegation. -- [mdw] From muetted at gmail.com Tue Nov 9 16:45:23 2010 From: muetted at gmail.com (Sana Khan) Date: Tue, 9 Nov 2010 13:45:23 -0800 (PST) Subject: Kareena and Saif Kissing I Kurbaan sex scene | Kareena Topless Kiss | Kurbaan Kiss Message-ID: <9b55ec62-3549-4a79-90f1-e4317dbcf34a@n32g2000prc.googlegroups.com> http://groups.google.com/group/hsfun/t/8c6133cfeac2eff0 From mdw at distorted.org.uk Tue Nov 9 17:09:58 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 09 Nov 2010 22:09:58 +0000 Subject: populating a doubly-subscripted array References: <87aaljmm44.fsf.mdw@metalzone.distorted.org.uk> <8jtrl3FgvdU1@mid.individual.net> Message-ID: <87d3qekv2h.fsf.mdw@metalzone.distorted.org.uk> Gregory Ewing writes: > A reasonably elegant way to fix this is to use list comprehensions > for all except the innermost list: > > ff = [[0.0]*5 for i in xrange(5)] Yes, this is a good approach. I should have suggested something like this as a solution myself, rather than merely explaining the problem. > If you're computing heavily with arrays, you might also consider > using numpy arrays instead of lists. Also a good idea. -- [mdw] From ldo at geek-central.gen.new_zealand Tue Nov 9 17:24:45 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 10 Nov 2010 11:24:45 +1300 Subject: Silly newbie question - Caret character (^) References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> <87pquekxbe.fsf.mdw@metalzone.distorted.org.uk> Message-ID: In message <87pquekxbe.fsf.mdw at metalzone.distorted.org.uk>, Mark Wooding wrote: > The book was much cheaper than a copy of the C standard from ANSI or ISO > even when it was new. It was a common joke (HHOS) at the time that the > difference in price reflected the value of the annotations. Crapware in a book! :) From ldo at geek-central.gen.new_zealand Tue Nov 9 17:32:32 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 10 Nov 2010 11:32:32 +1300 Subject: Silly newbie question - Caret character (^) References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> Message-ID: In message , Terry Reedy wrote: > I've been wondering why C programmers keep writing code susceptible to > buffer overruns ;=). I am continually disappointed with the ?do as I say, not as I do? attitude among people offering up sample code. I remember writing to one contributor to a programming magazine many years ago, about his admonition not to simply copy-and-paste sample code, to point out that he had done exactly that (complete with bug). The main sticking point seems to be error checking; for some reason, writers of sample code seem to believe the code is ?clearer? if you leave this out, when in fact all real-world applications of the illustrated techniques would include the error checks. So what do they end up illustrating? Nothing relevant to the real world. Is this why so many real-world programs fail to check for errors in important places, and segfault or behave unpredictably instead of gracefully reporting a problem? From moura.mario at gmail.com Tue Nov 9 17:41:35 2010 From: moura.mario at gmail.com (macm) Date: Tue, 9 Nov 2010 14:41:35 -0800 (PST) Subject: Learning Pyhton - Functional Programming - How intersect/difference two dict with dict/values? fast! References: <4d71519e-a232-427f-b4e0-5bae90fc4acb@n32g2000prc.googlegroups.com> <4cd9b16d$0$1640$742ec2ed@news.sonic.net> Message-ID: Sorry Mr. Nagle and Folks I had a bad day today. I need forward but with fever, a grasp and headache is hard. You are absolute right, I was rude and I ask your pardon. About my code, sorry I thought was the best way to copy and paste in python console. Best Regards macm On Nov 9, 7:03?pm, "D'Arcy J.M. Cain" wrote: > On Tue, 09 Nov 2010 15:55:16 -0500 > > Terry Reedy wrote: > > To echo John Nagle's point, if you want non-masochist volunteers to read > > your code, write something readable like: > > > dict1 = {'ab': [[1,2,3,'d3','d4',5], 12], > > ? ? ? ? ? 'ac': [[1,3,'78a','79b'], 54], > > ? ? ? ? ? 'ad': [[56,57,58,59], 34], > > ? ? ? ? ? 'ax': [[56,57,58,59], 34]} > > I have been learning to like this form: > > dict1 = dict( > ? ab = [[1,2,3,'d3','d4',5], 12], > ? ac = [[1,3,'78a','79b'], 54], > ? ad = [[56,57,58,59], 34], > ? ax = [[56,57,58,59], 34], > ) > > Of course, it only works when all the keys are strings. > > -- > D'Arcy J.M. Cain ? ? ? ? | ?Democracy is three wolveshttp://www.druid.net/darcy/? ? ? ? ? ? ? ?| ?and a sheep voting on > +1 416 425 1212 ? ? (DoD#0082) ? ?(eNTP) ? | ?what's for dinner. From ldo at geek-central.gen.new_zealand Tue Nov 9 17:43:05 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 10 Nov 2010 11:43:05 +1300 Subject: Silly newbie question - Caret character (^) References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> Message-ID: In message , Terry Reedy wrote: > Your two 'nitpicks' about fflush have both come up on this list as real > issues causing people problems. Cache on disk drives is a bug, not a feature. Performance-wise, it?s fast RAM hobbled by being located on the wrong side of a connection to the CPU that isn?t designed to transfer data at RAM speeds. And of course correctness-wise, it?s another complication in implementing the semantics of OS operations that are supposed to guarantee that data has been saved to persistent storage. From macrocoders at gmail.com Tue Nov 9 17:43:59 2010 From: macrocoders at gmail.com (macro coders) Date: Wed, 10 Nov 2010 00:43:59 +0200 Subject: python script installation wizard Message-ID: i want simple "hello world" script. i want python installer. sample image http://img705.imageshack.us/img705/9430/py2exe.png how do python setup wizard? -- *Www.PythonTR.Org* -macrocoders- -------------- next part -------------- An HTML attachment was scrubbed... URL: From mdw at distorted.org.uk Tue Nov 9 17:51:06 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 09 Nov 2010 22:51:06 +0000 Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> <87aalrjkty.fsf@benfinney.id.au> <8jd3m9Fr55U7@mid.individual.net> <87fwvdb69k.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <878w12kt5x.fsf.mdw@metalzone.distorted.org.uk> Lawrence D'Oliveiro writes: > In message <87fwvdb69k.fsf.mdw at metalzone.distorted.org.uk>, Mark Wooding > wrote: > > for descr, attr, colours in [ > > ('normal', 'image', 'Normal'), > > ('highlighted', 'highlight', 'Highlighted'), > > ('selected', 'select', 'Selected')]: > > colourlist = getattr(MainWindow, 'Colors%sList' % colours) > > ## ... > > But then you lose the ability to match up the bracketing symbols. You're right. I do. > That?s why I put them on lines by themselves. But the bracketing symbols are thoroughly uninteresting! All that putting them on their own lines achieves is to draw attention to the scaffolding at the expense of the building. It's great if you like the Pompidou Centre, I suppose... Besides, any editor worth its salt will highlight bracket mismatches for the reader, or at least get its automatic indentation in a twist if you get the brackets wrong. > Maybe you should look at the code in context > , then you can express some > more opinions on how to improve it. 1. class keyval: `are there official symbolic names for these anywhere?' The gtk.keysyms module contains `Return', `KP_Enter', `Left', `Up', `Right', and `Down'. Question: why are `returnkey' and `enterkey' defined in hex and the others in decimal? 2. The MainWindow class only has the `Window' attribute described in its definition. Apparently there are other attributes as well (the ColorMumbleList family for one, also `LayerDisplay'). Similarly, the LoadedImage class has attributes `Contents' and `FileName', but I see attributes `RowStride', `ImageDrawSize' and `SrcDimensions' used immediately below. 3. In SelectSaveMenu, there's a curious `for' loop: for State in (gtk.STATE_NORMAL,) : # no need for gtk.STATE_INSENSITIVE ## blah Firstly, this is obviously equivalent to `state = gtk.STATE_NORMAL' followed by the loop body (YAGNI). Secondly, the loop is followed by an `#end if' comment. If you're going to write the things, at least get them right! 4. Ahh! I've tracked down where the MainWindow is actually populated. Ugh. The code appears to revel in boilerplate. (For those at home, we're now looking at `SetupMainWindow', specifically at the calls to `DefineScrollingList'.) I count six calls, each nearly (but not quite) identical, of about eleven lines each. Of course, being boilerplate, the similarities visually outweigh the differences, when in fact it's the differences that are interesting. It doesn't help that all of the names of the things involved are so wretchedly verbose. How about the following? def make_listview(label, render, colattr, head, bounds, osc, box): setattr(MainWindow, label + 'Display', DefineScrollingList(getattr(MainWindow, label + 'List'), 0, render, colattr, head, bounds, osc, box) def make_listview_l1(label, head, osc): make_listview(label, None, 'text, head, (160, 160), osc, List1Box) make_listview_l1('Button', 'Buttons', None) make_listview_l1('Layer', 'Button Layer', LayerSelectionChanged) MainWindow.colourlist = {} MainWindow.colourview = {} for head in ['Normal', 'Highlight', 'Select']: MainWindow.colourlist[head] = gtk.ListStore(gobject.TYPE_PYOBJECT) MainWindow.colourview[head] = \ DefineScrollingList(MainWindow.colourlist[head], 0, ColorCellRenderer(), None, head, (120, 120), None, List2Box) make_listview('LoadedColors', ColorCellRenderer(), None, '', (120, 240), None, MiddleBox) Looking at some of the rest of the code, it might (or might not) be worthwhile actually making a class to gather together a list's model and view; subclasses can then vary their individual parameters, and the various colour lists can also keep the various captions with them. (Sometimes a strong separation between model and view is a good thing; this doesn't seem to be one of those times.) 5. Much of the indentation and layout is rather unconventional, though not intolerable. But I found (deep in `SelectSaveMenu'): NewRenderPixels = array.array \ ( "B", FillColor * (ImageRowStride // 4 * ImageBounds[1]) ) to be most disconcerting. Also, I couldn't work out why some parens are indented only two spaces and others are indented the full eight. Oh! It's inconsistent tab/space selection. I'm afraid that about this point I had to get on with some other stuff. I've done enough throwing of stones, so I should point at a glass house of my own so that others can return the favour: http://git.distorted.org.uk/~mdw/tripe/tree The Python code is in `py', `svc' and `mon'. Those who believe PEP 8 is carven in stone will be disappointed. It's a bit... tricky in places. -- [mdw] From ian.g.kelly at gmail.com Tue Nov 9 18:30:40 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 9 Nov 2010 16:30:40 -0700 Subject: python script installation wizard In-Reply-To: References: Message-ID: On Tue, Nov 9, 2010 at 3:43 PM, macro coders wrote: > > i want simple "hello world" script. i want python installer. sample image > http://img705.imageshack.us/img705/9430/py2exe.png how do python setup > wizard? > Use the distutils package in the standard library. You'll need to write a setup.py file for your distribution, and the Windows installer will be created using the "setup.py bdist_wininst" command. See the distutils documentation for the details. -------------- next part -------------- An HTML attachment was scrubbed... URL: From robert.kern at gmail.com Tue Nov 9 19:05:26 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 09 Nov 2010 18:05:26 -0600 Subject: Allowing comments after the line continuation backslash In-Reply-To: <878w12kt5x.fsf.mdw@metalzone.distorted.org.uk> References: <4CCE6FF6.2050408@v.loewis.de> <87aalrjkty.fsf@benfinney.id.au> <8jd3m9Fr55U7@mid.individual.net> <87fwvdb69k.fsf.mdw@metalzone.distorted.org.uk> <878w12kt5x.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On 11/9/10 4:51 PM, Mark Wooding wrote: > Lawrence D'Oliveiro writes: > >> In message<87fwvdb69k.fsf.mdw at metalzone.distorted.org.uk>, Mark Wooding >> wrote: >>> for descr, attr, colours in [ >>> ('normal', 'image', 'Normal'), >>> ('highlighted', 'highlight', 'Highlighted'), >>> ('selected', 'select', 'Selected')]: >>> colourlist = getattr(MainWindow, 'Colors%sList' % colours) >>> ## ... >> >> But then you lose the ability to match up the bracketing symbols. > > You're right. I do. > >> That?s why I put them on lines by themselves. > > But the bracketing symbols are thoroughly uninteresting! All that > putting them on their own lines achieves is to draw attention to the > scaffolding at the expense of the building. It's great if you like the > Pompidou Centre, I suppose... For me, putting the brackets on their own lines (and using a trailing comma) has little to do with increasing readability. It's for making editing easier. Keeping all of the items consistent means that in order to add, delete, or move any item is the same operation everywhere in the list whether it is the first item, last item, or any item in between. -- 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 usenet-nospam at seebs.net Tue Nov 9 19:11:23 2010 From: usenet-nospam at seebs.net (Seebs) Date: 10 Nov 2010 00:11:23 GMT Subject: Pythonic/idiomatic? References: Message-ID: On 2010-11-09, Jean-Michel Pichavant wrote: > One pythonic way to do it, is to use an option parser. That seems like massive overkill -- I don't care about any of the other options. It seems like it'd result in doing more work to get and then extract the options, and most of that would be discarded instnatly. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Tue Nov 9 19:13:38 2010 From: usenet-nospam at seebs.net (Seebs) Date: 10 Nov 2010 00:13:38 GMT Subject: Silly newbie question - Caret character (^) References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> Message-ID: On 2010-11-09, Terry Reedy wrote: > I've been wondering why C programmers keep writing code susceptible to > buffer overruns ;=). Because we're dumb! (Actually, in my defense, my code almost never, if ever, has buffer overruns. I do in some rare cases have truncation issues with sufficiently ridiculous input data.) > Your two 'nitpicks' about fflush have both come up on this list as real > issues causing people problems. So I agree that it needs to be explained > properly and completely as you suggest. Huh. Since Schildt fell out of favor, I've almost never seen people trying to fflush(stdin), and the update rules are weird enough that I don't think I've ever seen anyone try to use it. :) -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From martin at address-in-sig.invalid Tue Nov 9 19:28:25 2010 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Wed, 10 Nov 2010 00:28:25 +0000 (UTC) Subject: Pythonic/idiomatic? References: Message-ID: On Wed, 10 Nov 2010 00:11:23 +0000, Seebs wrote: > On 2010-11-09, Jean-Michel Pichavant wrote: >> One pythonic way to do it, is to use an option parser. > > That seems like massive overkill -- I don't care about any of the other > options. It seems like it'd result in doing more work to get and then > extract the options, and most of that would be discarded instnatly. > I've always used an extended version of getopt() in C. I was so surprised to see that there's nothing equivalent in Java that I wrote my own and was consequently was very pleased to find that Python already has the optparse module. Using it is a no-brainer, particularly as it makes quite a good fist of being self-documenting and of spitting out a nicely formatted chunk of help text when asked to do so. -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From robert.kern at gmail.com Tue Nov 9 19:42:06 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 09 Nov 2010 18:42:06 -0600 Subject: Pythonic/idiomatic? In-Reply-To: References: <87y693cpf6.fsf@benfinney.id.au> <87lj53cnar.fsf@benfinney.id.au> Message-ID: On 11/8/10 8:13 PM, Seebs wrote: > On 2010-11-09, Ben Finney wrote: >> Seebs writes: >>> I think we're stuck with backwards compatibility at least as far as >>> 2.4. > >> Then you don't yet have the ???any??? and ???all??? built-in functions, or the >> tuple-of-prefixes feature of ???str.startswith??? either. Bummer. > > Eww. > >> At which point, the Pythonic thing to do is to convince your >> organisation to use a version of Python that's at least officially >> supported by the PSF :-) > > Unfortunately, we're selling something to people who will explode if > we tell them to upgrade their RHEL4 systems, so we have to work on those. > (There is some tiny hope that we'll be able to move the baseline to RHEL5 > within another two years.) When we deal with such people, we also sell them a recent Python interpreter. :-) -- 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 python.list at tim.thechases.com Tue Nov 9 20:02:33 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 09 Nov 2010 19:02:33 -0600 Subject: Allowing comments after the line continuation backslash In-Reply-To: References: <4CCE6FF6.2050408@v.loewis.de> <87aalrjkty.fsf@benfinney.id.au> <8jd3m9Fr55U7@mid.individual.net> <87fwvdb69k.fsf.mdw@metalzone.distorted.org.uk> <878w12kt5x.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <4CD9EF29.5030500@tim.thechases.com> On 11/09/10 18:05, Robert Kern wrote: > For me, putting the brackets on their own lines (and using a trailing comma) has > little to do with increasing readability. It's for making editing easier. It also makes diff's much easier to read (my big impetus for doing the same as Robert) -tkc From mdw at distorted.org.uk Tue Nov 9 20:39:01 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 10 Nov 2010 01:39:01 +0000 Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> <87aalrjkty.fsf@benfinney.id.au> <8jd3m9Fr55U7@mid.individual.net> <87fwvdb69k.fsf.mdw@metalzone.distorted.org.uk> <878w12kt5x.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <877hgmj6tm.fsf.mdw@metalzone.distorted.org.uk> Tim Chase writes: > On 11/09/10 18:05, Robert Kern wrote: > > For me, putting the brackets on their own lines (and using a > > trailing comma) has little to do with increasing readability. It's > > for making editing easier. > > It also makes diff's much easier to read (my big impetus for doing the > same as Robert) Hmm. That's a good point, actually. I'm not overly fussed about the ease of editing: it doesn't seem especially hard either way. But nice diffs are definitely valuable. Food for thought; thanks. -- [mdw] From afriere at yahoo.co.uk Tue Nov 9 21:06:07 2010 From: afriere at yahoo.co.uk (Asun Friere) Date: Tue, 9 Nov 2010 18:06:07 -0800 (PST) Subject: DTD Parsing Message-ID: <4e7a49ec-1816-46e5-bc51-9f7c88f4d025@37g2000prx.googlegroups.com> Now that PyXML (and thus xmlproc) is defunct, does anyone know any handy modules (apart from re :) for parsing DTDs? From python.list at tim.thechases.com Tue Nov 9 21:23:14 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 09 Nov 2010 20:23:14 -0600 Subject: Allowing comments after the line continuation backslash In-Reply-To: <877hgmj6tm.fsf.mdw@metalzone.distorted.org.uk> References: <4CCE6FF6.2050408@v.loewis.de> <87aalrjkty.fsf@benfinney.id.au> <8jd3m9Fr55U7@mid.individual.net> <87fwvdb69k.fsf.mdw@metalzone.distorted.org.uk> <878w12kt5x.fsf.mdw@metalzone.distorted.org.uk> <877hgmj6tm.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <4CDA0212.7000201@tim.thechases.com> On 11/09/10 19:39, Mark Wooding wrote: > Tim Chase writes: >> It also makes diff's much easier to read > > Hmm. That's a good point, actually. I'm not overly fussed > about the ease of editing: it doesn't seem especially hard > either way. But nice diffs are definitely valuable. Food for > thought; thanks. I find that diffs like for row in ( (item_bar, details_bar), (item_foo, details_foo), + (item_baz, details_baz), ): do_something(row) are much easier/faster to understand instead of for row in ( (item_bar, details_bar), - (item_foo, details_foo)): + (item_foo, details_foo), + (item_baz, details_baz)): do_something(row) -tkc From felipe.bastosn at gmail.com Tue Nov 9 21:44:53 2010 From: felipe.bastosn at gmail.com (Felipe Bastos Nunes) Date: Wed, 10 Nov 2010 00:44:53 -0200 Subject: DTD Parsing In-Reply-To: <4e7a49ec-1816-46e5-bc51-9f7c88f4d025@37g2000prx.googlegroups.com> References: <4e7a49ec-1816-46e5-bc51-9f7c88f4d025@37g2000prx.googlegroups.com> Message-ID: I'd like to know too. I work with java and jdom, but I'm doing personal things in python, and plan to go full python in the next 2 years. Xml is my first option for configuration files and simple storages. 2010/11/10, Asun Friere : > Now that PyXML (and thus xmlproc) is defunct, does anyone know any > handy modules (apart from re :) for parsing DTDs? > -- > http://mail.python.org/mailman/listinfo/python-list > -- Felipe Bastos Nunes From lists at cheimes.de Tue Nov 9 22:02:34 2010 From: lists at cheimes.de (Christian Heimes) Date: Wed, 10 Nov 2010 04:02:34 +0100 Subject: DTD Parsing In-Reply-To: References: <4e7a49ec-1816-46e5-bc51-9f7c88f4d025@37g2000prx.googlegroups.com> Message-ID: Am 10.11.2010 03:44, schrieb Felipe Bastos Nunes: > I'd like to know too. I work with java and jdom, but I'm doing > personal things in python, and plan to go full python in the next 2 > years. Xml is my first option for configuration files and simple > storages. Don't repeat the mistakes of others and use XML as a configuration language. XML isn't meant to be edited by humans. It's my strong believe that XML is great for stuff like data exchange and long time data storage, but not for configuration. Python has much more suited ways to deal with configuration. At work we used to have XML for configuration years ago. Today we use configobj [1], a ini style config system with config specs, validation and many more features. You can define a setting as e.g. list of ints and you actually get a list of ints from the resulting config object. Back to the initial question: I highly recommend LXML for any kind of XML processing, validation, XPath etc. It's super fast, extremely powerful and supports all features of libxml2 and libxslt. It also supports DTD, RelaxNG and XML schema. Christian [1] http://pypi.python.org/pypi/configobj [2] http://pypi.python.org/pypi/lxml From robert.kern at gmail.com Tue Nov 9 22:10:00 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 09 Nov 2010 21:10:00 -0600 Subject: Allowing comments after the line continuation backslash In-Reply-To: <877hgmj6tm.fsf.mdw@metalzone.distorted.org.uk> References: <4CCE6FF6.2050408@v.loewis.de> <87aalrjkty.fsf@benfinney.id.au> <8jd3m9Fr55U7@mid.individual.net> <87fwvdb69k.fsf.mdw@metalzone.distorted.org.uk> <878w12kt5x.fsf.mdw@metalzone.distorted.org.uk> <877hgmj6tm.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On 2010-11-09 19:39 , Mark Wooding wrote: > Tim Chase writes: > >> On 11/09/10 18:05, Robert Kern wrote: >>> For me, putting the brackets on their own lines (and using a >>> trailing comma) has little to do with increasing readability. It's >>> for making editing easier. >> >> It also makes diff's much easier to read (my big impetus for doing the >> same as Robert) > > Hmm. That's a good point, actually. I'm not overly fussed about the > ease of editing: it doesn't seem especially hard either way. It might just be my vim bias. Vim has such *very* easy ways to cut and paste whole lines that not taking the opportunity to permit them seems like a waste. -- 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 afriere at yahoo.co.uk Tue Nov 9 22:36:10 2010 From: afriere at yahoo.co.uk (Asun Friere) Date: Tue, 9 Nov 2010 19:36:10 -0800 (PST) Subject: DTD Parsing References: <4e7a49ec-1816-46e5-bc51-9f7c88f4d025@37g2000prx.googlegroups.com> Message-ID: <06071410-4684-4169-b1f8-0783e34f9062@f16g2000prj.googlegroups.com> On Nov 10, 2:02?pm, Christian Heimes wrote: > Am 10.11.2010 03:44, schrieb Felipe Bastos Nunes: > > > I'd like to know too. I work with java and jdom, but I'm doing > > personal things in python, and plan to go full python in the next 2 > > years. Xml is my first option for configuration files and simple > > storages. > > Don't repeat the mistakes of others and use XML as a configuration > language. XML isn't meant to be edited by humans. Yes but configuration files are not necessarily meant to be edited by humans either! Having said that, I'm actually old school and prefer "setting=value" human editable config files which are easily read into a dict via some code something like this: def read_config (file_obj) : """Reads a config file and returns values as a dictionary Config file is a series of lines in the format: #comment name=value name:value name = value #comment Neither name nor value may contain '#', '=', ':' nor any spaces. """ config = {} nameval = re.compile('^\s*([^=:\s]+)\s*(?:=|:)\s*([^=:\s]*) \s*(?:#.*)?\s*$').search comment = re.compile('^\s*($|#)').search for line in file_obj : if comment(line) : continue try : name, value = nameval(line).groups() except AttributeError : sys.stderr.write('WARNING: suspect entry: %s\n' % line) continue config[name]=value file_obj.close() return config Thanks Christian, I might check out 'configobj', but my needs are rarely more complicated than the above will satisfy. In any case Felipe, whether you intend to use XML for config or not (or for any other reason), there are good tools for XML parsing in python including with DTD validation. Try the modules 'libxml2', 'lxml', or even, if your needs are modest, the poorly named 'HTMLParser'. What I'm looking for instead is something to parse a DTD, such as xmlproc's DTDConsumer. It might even exist in the modules I've mentioned, but I can't find it. In the event, I think I'll use a DTD- >xsd conversion script and then simply use HTMLParser. Unless someone can point me in the way of a simple DTD parser, that is. From afriere at yahoo.co.uk Tue Nov 9 22:42:37 2010 From: afriere at yahoo.co.uk (Asun Friere) Date: Tue, 9 Nov 2010 19:42:37 -0800 (PST) Subject: DTD Parsing References: <4e7a49ec-1816-46e5-bc51-9f7c88f4d025@37g2000prx.googlegroups.com> Message-ID: <49f5805b-416a-4942-a17e-2703e5f79f10@g28g2000pra.googlegroups.com> On Nov 10, 2:02?pm, Christian Heimes wrote: > Back to the initial question: I highly recommend LXML for any kind of > XML processing, validation, XPath etc. Sorry Christian, didn't realise at first that that was a response to MY intial question. But does lxml actually have something for parsing DTDs, as opposed parsing XML and validating it against a DTD? From ldo at geek-central.gen.new_zealand Tue Nov 9 23:01:05 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 10 Nov 2010 17:01:05 +1300 Subject: Commercial or Famous Applicattions.? References: Message-ID: In message , Martin Gregorie wrote: > ...and don't forget getmail, a better behaved replacement for fetchmail. I was just looking this up in the Getmail FAQ, since I didn?t know about the issues with Fetchmail. That?s it, ESR is off my Christmas-card list... From ldo at geek-central.gen.new_zealand Tue Nov 9 23:11:29 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 10 Nov 2010 17:11:29 +1300 Subject: Silly newbie question - Caret character (^) References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> Message-ID: In message , Seebs wrote: > In particular, he's very good at making up complications from whole cloth > which aren't really problems, and then offering "solutions" which show > people a clever trick to work around the problem. (e.g., his elaborate > revelations about how to use feof() in C to work around his failure to > understand how EOF works.) What was sad to me to read was this phrase of yours: ... but rather, takes the shortest path to something that won't get those complaints anymore ... To me, this is the sign of someone who doesn?t really enjoy what they do. Because somebody who cares about what they do would take the trouble to get it right. But if he can?t be bothered, why does he keep doing it? There must be more pleasant ways of getting a meal ticket... From usenet-nospam at seebs.net Tue Nov 9 23:12:30 2010 From: usenet-nospam at seebs.net (Seebs) Date: 10 Nov 2010 04:12:30 GMT Subject: Silly newbie question - Caret character (^) References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> Message-ID: On 2010-11-10, Lawrence D'Oliveiro wrote: > What was sad to me to read was this > phrase of yours: > ... but rather, takes the shortest path to something that won't get > those complaints anymore ... > To me, this is the sign of someone who doesn't really enjoy what they do. Yes. I both write and program, and I do them because I love them. If I won the lottery tomorrow (and hey, my chances are only very very slightly lower than everyone else's), I wouldn't stop programming or writing. I might change my focus some, but both of them are things I'd keep doing. > Because somebody who cares about what they do would take the trouble to get > it right. But if he can't be bothered, why does he keep doing it? There must > be more pleasant ways of getting a meal ticket... It's hard to say. I get the feeling sometimes that he's one of the people to whom programming is sort-of-fun, but not fun when you have to get all persnickety about it. Similarly, writing is fun if you're getting praised for it, but dealing with criticism is harder. (Trust me, I know of this; I have gotten a fair number of corrections over the years.) That said, I suspect he's made a fairly large amount of money; multiple bestsellers is a pretty good way to make a decent bit of pocket change. I may have my gripes about Python, but I will say this: The Python community seems full of people who are passionate about writing good code. I would much rather be in a community of people who care a lot about how I should do things, but I think they're wrong, than about people who figure anything that the interpreter accepts is fine. I can learn from people I disagree with, but not from people who don't care. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From drsalists at gmail.com Tue Nov 9 23:41:08 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 9 Nov 2010 20:41:08 -0800 Subject: Compare source code In-Reply-To: References: <4ccd5ad9$0$19151$426a74cc@news.free.fr> <8j8am4Fk2jU1@mid.individual.net> <4ccff7c1$0$29966$c3e8da3$5496439d@news.astraweb.com> <4cd14933$0$29966$c3e8da3$5496439d@news.astraweb.com> <87mxpp3u3i.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On Thu, Nov 4, 2010 at 10:45 AM, Tim Harig wrote: > I also looked at F# and Scala; but, neither are really applicable on my > chosen platform. With F# being such a new language, I suspect that it > borrowed its indent practices either from Haskell or from Python. > I'm pretty sure F# gets its whitespace conventions from the ML family of (very interesting) languages. I believe F# is based largely on Objective Caml. http://stromberg.dnsalias.org/~strombrg/significant-whitespace.html -------------- next part -------------- An HTML attachment was scrubbed... URL: From wuwei23 at gmail.com Wed Nov 10 00:08:35 2010 From: wuwei23 at gmail.com (alex23) Date: Tue, 9 Nov 2010 21:08:35 -0800 (PST) Subject: Why "flat is better than nested"? References: <8jtq5dF67vU1@mid.individual.net> Message-ID: <48b37d9f-25de-45e5-864c-90ef7cfb4782@e26g2000vbz.googlegroups.com> Gregory Ewing wrote: > I get it. Does that mean that I don't get it? Mu. From stefan_ml at behnel.de Wed Nov 10 00:11:04 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 10 Nov 2010 06:11:04 +0100 Subject: DTD Parsing In-Reply-To: <49f5805b-416a-4942-a17e-2703e5f79f10@g28g2000pra.googlegroups.com> References: <4e7a49ec-1816-46e5-bc51-9f7c88f4d025@37g2000prx.googlegroups.com> <49f5805b-416a-4942-a17e-2703e5f79f10@g28g2000pra.googlegroups.com> Message-ID: Asun Friere, 10.11.2010 04:42: > On Nov 10, 2:02 pm, Christian Heimes wrote: > >> Back to the initial question: I highly recommend LXML for any kind of >> XML processing, validation, XPath etc. > > Sorry Christian, didn't realise at first that that was a response to > MY intial question. But does lxml actually have something for parsing > DTDs, as opposed parsing XML and validating it against a DTD? What's your interest in parsing a DTD if you're not up to validating XML? Stefan From afriere at yahoo.co.uk Wed Nov 10 00:41:36 2010 From: afriere at yahoo.co.uk (Asun Friere) Date: Tue, 9 Nov 2010 21:41:36 -0800 (PST) Subject: DTD Parsing References: <4e7a49ec-1816-46e5-bc51-9f7c88f4d025@37g2000prx.googlegroups.com> <49f5805b-416a-4942-a17e-2703e5f79f10@g28g2000pra.googlegroups.com> Message-ID: On Nov 10, 4:11?pm, Stefan Behnel wrote: > What's your interest in parsing a DTD if you're not up to validating XML? Spitting out boilerplate code. Just at the moment I'm creating a stub XSLT sheet, which creates a template per element (from a 3rd party DTD with 143 elements, yuk!) containing nothing more than a apply-templates line listing all possible child elements and a comment saying 'NOT IMPLEMENTED: %s' % element_name. This saves not only typing, but helps me work through and guards against any clumsy oversight on my part in writing a translation sheet for an IMO overly large schema. A few years back I used a similar technique to write some boiler plate python code where xml was isomorphically represented on a class per element basis (which will no doubt offend some people's sense of generalisation, but is none the less an interesting way to work with XML). While I'm here and just for the record, (as I don't imagine anyone would want to use the code I posted above), the line "file_obj.close()" has no place in a function which is passed an open file_object. My apologies. From aioe.org at technicalbloke.com Wed Nov 10 00:45:35 2010 From: aioe.org at technicalbloke.com (r0g) Date: Wed, 10 Nov 2010 05:45:35 +0000 Subject: Class extension confusion :( Message-ID: I have a subclass of BaseHHTPRequestHandler which uses a dictonary "paths" and a function "api_call" which are defined in the main namespace of the module. I'd rather I was able to pass these object to the constructor and store them as data attributes "self.paths" and "self.api_call" but I'm not sure how to do that properly. My understanding is that one may extend a constructor by defining it's __init__ method, calling the parents constructor and then adding ones own attributes to taste. What I don't understand is where or how I am supposed to get these extra constructor arguments into the class given that I don't instantiate it myself, it is seemingly instantiated by HTTPServer class that I pass it to e.g. httpd = HTTPServer(server_address, PlainAJAXRequestHandler) I wondered if I ought to instantiate an instance of PlainAJAXRequestHandler, set the attributes (either manually or by extending it's constructor) and pass that to HTTPServer but I figured it expects a class not an instance as it probably wants to spawn one instance for each request so that would be a non starter. Might I need to subclass HTTPServer, find the bit that instantiates the request handler and override that so it passes it's constructor more parameters? Right now I'm pretty confused, can somebody please tell me how I might accomplish this, what I'm failing to grasp or point me to the docs that explain it - I've spent the last hour or two plowing through docs to no avail, I guess it's a case of keyword ignorance on my part! Code follows... Thanks for reading! Roger. class PlainAJAXRequestHandler(BaseHTTPRequestHandler): paths = { "/": pages.main, "/jqtest/": pages.jqtest } def do_GET(self): # Handle JSON api calls if self.path[:6] == "/ajax?": getvars = urlparse.parse_qs( self.path[6:] ) api_key = getvars[ "api" ][0] json_string = getvars[ "qry" ][0] json_object = json.loads( json_string ) response = api_call( api_key, json_object ) if response: self.send_response(200) self.send_header("Content-type", "application/json") self.end_headers() self.wfile.write( response ) else: self.send_response(404) self.end_headers() return # Handle web pages try: page = self.paths[self.path]() except KeyError: self.send_response(404) self.end_headers() self.wfile.write( "404 - Document not found!" ) return self.send_response(200) self.send_header("Content-type", "text/html") self.end_headers() self.wfile.write( page ) return From stefan_ml at behnel.de Wed Nov 10 01:00:54 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 10 Nov 2010 07:00:54 +0100 Subject: DTD Parsing In-Reply-To: References: <4e7a49ec-1816-46e5-bc51-9f7c88f4d025@37g2000prx.googlegroups.com> <49f5805b-416a-4942-a17e-2703e5f79f10@g28g2000pra.googlegroups.com> Message-ID: Asun Friere, 10.11.2010 06:41: > On Nov 10, 4:11 pm, Stefan Behnel wrote: > >> What's your interest in parsing a DTD if you're not up to validating XML? > > Spitting out boilerplate code. >[...] > A few years back I used a similar technique to write some boiler plate > python code where xml was isomorphically represented on a class per > element basis (which will no doubt offend some people's sense of > generalisation, but is none the less an interesting way to work with > XML). Give lxml.objectify a try. It doesn't use DTDs, but does what you want. There are also some other similar tools like gnosis.objectify or Amara. I never benchmarked them in comparison, but I'd be surprised if lxml.objectify wasn't the fastest. I'd be interested in seeing the margin, though, in case anyone wants to give it a try. It's generally a good idea to state what you want to achieve, rather than just describing the failure of an intermediate step of one possible path towards your hidden goal. This list has a huge history of finding shortcuts that the OPs didn't think of. Stefan From aioe.org at technicalbloke.com Wed Nov 10 01:14:56 2010 From: aioe.org at technicalbloke.com (r0g) Date: Wed, 10 Nov 2010 06:14:56 +0000 Subject: DTD Parsing References: <4e7a49ec-1816-46e5-bc51-9f7c88f4d025@37g2000prx.googlegroups.com> <06071410-4684-4169-b1f8-0783e34f9062@f16g2000prj.googlegroups.com> Message-ID: On 10/11/10 03:36, Asun Friere wrote: > On Nov 10, 2:02 pm, Christian Heimes wrote: >> Am 10.11.2010 03:44, schrieb Felipe Bastos Nunes: >> >>> I'd like to know too. I work with java and jdom, but I'm doing >>> personal things in python, and plan to go full python in the next 2 >>> years. Xml is my first option for configuration files and simple >>> storages. >> >> Don't repeat the mistakes of others and use XML as a configuration >> language. XML isn't meant to be edited by humans. > > Yes but configuration files are not necessarily meant to be edited by > humans either! > > Having said that, I'm actually old school and prefer "setting=value" > human editable config files which are easily read into a dict via some > code something like this: > Me too when possible, TBH if I only needed strings and there was no pressing security issue I'd just do this... config = {} for line in (open("config.txt", 'r')): if len(line) > 0 and line[0] <> "#": param, value = line.rstrip().split("=",1) config[param] = value There is a place for XML settings though, they're nice and portable and for some apps you probably don't want end users editing their configurations by hand in a text editor anyway, you would prefer them to use the nice consistency preserving config interface you have lovingly built for them. You have built them a nice GUI config interface haven't you ??? ;) Roger From ldo at geek-central.gen.new_zealand Wed Nov 10 01:20:40 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 10 Nov 2010 19:20:40 +1300 Subject: Silly newbie question - Caret character (^) References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> Message-ID: In message , Seebs wrote: > I may have my gripes about Python, but I will say this: The Python > community seems full of people who are passionate about writing good code. And they know how to write good code in other languages, not just Python. In other words, they know programming, not just Python programming. You see that come through a lot of the time, when a discussion goes off- track like this. :) From ldo at geek-central.gen.new_zealand Wed Nov 10 01:26:50 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 10 Nov 2010 19:26:50 +1300 Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> <87aalrjkty.fsf@benfinney.id.au> <8jd3m9Fr55U7@mid.individual.net> <87fwvdb69k.fsf.mdw@metalzone.distorted.org.uk> <878w12kt5x.fsf.mdw@metalzone.distorted.org.uk> Message-ID: In message , Robert Kern wrote: > For me, putting the brackets on their own lines (and using a trailing > comma) has little to do with increasing readability. It's for making > editing easier. Keeping all of the items consistent means that in order to > add, delete, or move any item is the same operation everywhere in the list > whether it is the first item, last item, or any item in between. Yup, I like to do that when there?s nothing special about the last item in the list. Sometimes there is (e.g. an enumeration entry naming the number of values in the enumeration, or an all-zero sentinel marking the end of a list), in which case I omit the comma to indicate that nothing should come afterwards. I remember an early experience with JavaScript (back in the days of Netscape versus Internet Explorer 5.1 on a Mac), when I found that constructing a list in this way wasn?t working in IE: turned out it was inserting some kind of extra phantom list item after that last comma. Sigh... From ldo at geek-central.gen.new_zealand Wed Nov 10 01:48:49 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 10 Nov 2010 19:48:49 +1300 Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> <87aalrjkty.fsf@benfinney.id.au> <8jd3m9Fr55U7@mid.individual.net> <87fwvdb69k.fsf.mdw@metalzone.distorted.org.uk> <878w12kt5x.fsf.mdw@metalzone.distorted.org.uk> Message-ID: In message <878w12kt5x.fsf.mdw at metalzone.distorted.org.uk>, Mark Wooding wrote: > Lawrence D'Oliveiro writes: > >> Maybe you should look at the code in context >> , then you can express some >> more opinions on how to improve it. > > 1. class keyval: `are there official symbolic names for these > anywhere?' The gtk.keysyms module contains `Return', `KP_Enter', > `Left', `Up', `Right', and `Down'. Thanks, that?s useful. I couldn?t find mention of such in the documentation anywhere. > Question: why are `returnkey' and `enterkey' defined in hex and the > others in decimal? Can?t remember now. Does it matter? > 2. The MainWindow class only has the `Window' attribute described in > its definition. Apparently there are other attributes as well (the > ColorMumbleList family for one, also `LayerDisplay'). Similarly, > the LoadedImage class has attributes `Contents' and `FileName', but > I see attributes `RowStride', `ImageDrawSize' and `SrcDimensions' > used immediately below. These are really just namespaces, one for the GUI context and the other for the image data. > 3. In SelectSaveMenu, there's a curious `for' loop: > > for State in (gtk.STATE_NORMAL,) : # no need for > gtk.STATE_INSENSITIVE > ## blah > > Firstly, this is obviously equivalent to `state = gtk.STATE_NORMAL' > followed by the loop body (YAGNI). It?s a tuple of one element. It used to be a tuple of two, and there is the possibility it might need to become that again (as intimated at in the attached comment). That?s why it stays a tuple. > 4. Ahh! I've tracked down where the MainWindow is actually > populated. Ugh. The code appears to revel in boilerplate. (For > those at home, we're now looking at `SetupMainWindow', specifically > at the calls to `DefineScrollingList'.) I count six calls, each > nearly (but not quite) identical, of about eleven lines each. Could be worse. Imagine if I had written out the 30 lines of that function out each time instead. > Of course, being boilerplate, the similarities visually outweigh the > differences, when in fact it's the differences that are > interesting. That is generally how code reuse works. All the ?boilerplate? is in the function definition, so I just have to call it parameterized by the differences appropriate to each instance. > It doesn't help that all of the names of the things involved are so > wretchedly verbose. Oh please, no. Since when are explanatory names ?wretchedly verbose?? > How about the following? > > def make_listview_l1 ... And what, pray tell, is the significance of the name ?make_listview_l1?? If there is something I would describe as ?wretched?, it is the use of random numerical suffixes like this. > Looking at some of the rest of the code, it might (or might not) be > worthwhile actually making a class to gather together a list's model > and view; subclasses can then vary their individual parameters, and > the various colour lists can also keep the various captions with > them. Most of that variation is already handled without the limitations of thinking in classes. For example, selection of a colour in all three lists is handled through a single EditColor routine. And of course you?ve already seen how a single DefineScrollingList routine can be used to set up all the scrolling lists used in this GUI. > 5. Much of the indentation and layout is rather unconventional, though > not intolerable. But I found (deep in `SelectSaveMenu'): > > NewRenderPixels = array.array \ > ( > "B", > FillColor > * > (ImageRowStride // 4 * ImageBounds[1]) > ) > > to be most disconcerting. Is the structure of the expression not apparent to you? You?d probably need plenty of fresh air after something like this, then: PatternArray = array.array \ ( "I", 16 * (16 * (Light,) + 16 * (Dark,)) + 16 * (16 * (Dark,) + 16 * (Light,)) ) > Also, I couldn't work out why some parens are indented only two > spaces and others are indented the full eight. Eight?? You mean four. See, this is why I should probably stop using tabs... From ldo at geek-central.gen.new_zealand Wed Nov 10 01:53:58 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 10 Nov 2010 19:53:58 +1300 Subject: Am I The Only One Who Keeps Reading =?UTF-8?B?4oCcTnVtcHnigJ0gYXMg4oCcTnVtcHR54oCdPw==?= Message-ID: Sorry... From ian.g.kelly at gmail.com Wed Nov 10 02:36:37 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 10 Nov 2010 00:36:37 -0700 Subject: DTD Parsing In-Reply-To: References: <4e7a49ec-1816-46e5-bc51-9f7c88f4d025@37g2000prx.googlegroups.com> <06071410-4684-4169-b1f8-0783e34f9062@f16g2000prj.googlegroups.com> Message-ID: On 11/9/2010 11:14 PM, r0g wrote: > Me too when possible, TBH if I only needed strings and there was no > pressing security issue I'd just do this... > > config = {} > for line in (open("config.txt", 'r')): > if len(line) > 0 and line[0] <> "#": > param, value = line.rstrip().split("=",1) > config[param] = value That's five whole lines of code. Why go to all that trouble when you can just do this: import config I kid, but only partially. Where this really shines is when you're prototyping something and you need to configure complex object hierarchies. No need to spend time writing parsers to generate the hierarchies; you just construct the objects directly in the config. When the project becomes mature enough that configuration security is a concern, then you can replace the config with XML or whatever, and in the meantime you can focus on more important things, like the actual project. Cheers, Ian From aioe.org at technicalbloke.com Wed Nov 10 03:05:27 2010 From: aioe.org at technicalbloke.com (r0g) Date: Wed, 10 Nov 2010 08:05:27 +0000 Subject: DTD Parsing References: <4e7a49ec-1816-46e5-bc51-9f7c88f4d025@37g2000prx.googlegroups.com> <06071410-4684-4169-b1f8-0783e34f9062@f16g2000prj.googlegroups.com> Message-ID: On 10/11/10 07:36, Ian Kelly wrote: > On 11/9/2010 11:14 PM, r0g wrote: >> Me too when possible, TBH if I only needed strings and there was no >> pressing security issue I'd just do this... >> >> config = {} >> for line in (open("config.txt", 'r')): >> if len(line) > 0 and line[0] <> "#": >> param, value = line.rstrip().split("=",1) >> config[param] = value > > That's five whole lines of code. Why go to all that trouble when you can > just do this: > > import config > Heh, mainly because I figure the config module will have a lot more options than I have use for right now and therefore the docs will take me longer to read than I will save by not just typing in the above ;) Having said that, you've just prompted me to take a look... there goes another 10 minutes of my life! Roger From landimatte at gmail.com Wed Nov 10 03:06:48 2010 From: landimatte at gmail.com (Matteo Landi) Date: Wed, 10 Nov 2010 09:06:48 +0100 Subject: An easier way to do this? (spoiler if you're using pyschools for fun) In-Reply-To: References: Message-ID: I agree with Peter: * iterate over the list directly * use %10 instead of string conversion + slice (*) use genexps Good luck, Matteo On Tue, Nov 9, 2010 at 8:18 PM, Terry Reedy wrote: > On 11/9/2010 2:00 PM, Matty Sarro wrote: > >> I'm working on one of the puzzles on pyschools.com >> , and am trying to figure out if I can make my >> solution a bit more elegant. > > Definitely > >> def getSumOfLastDigit(numList): >> ? ? sumOfDigits=0 >> ? ? for i in range(0, len(numList)): >> ? ? ? ? num=str(numList.pop()) > > This is an awkward way to iterate through a list ;-) > >> ? ? ? ? sumOfDigits+=int(num[-1:]) >> ? ? return sumOfDigits > >> Write a function: getSumOfLastDigit(numList) that takes in a list of >> positive numbers and returns the sum of all the last digit in the list. >> >> *Examples* >> ? ?>>> ?getSumOfLastDigit([12, ?23, ?34]) >> ? ?9 >> ? ?>>> ?getSumOfLastDigit([2, ?3, ?4]) >> ? ?9 >> ? ?>>> ?getSumOfLastDigit([1, ?23, ?456]) >> ? ?10 > > # Straightforward version of what you did > > def getSumOfLastDigit(numList): > ? ?sumOfDigits=0 > ? ?for i in numList: > ? ? ? ?sumOfDigits+=int(str(i)[-1:]) > ? ?return sumOfDigits > > print(getSumOfLastDigit([12, 23, 34]), > ? ? ?getSumOfLastDigit([2, 3, 4]), > ? ? ?getSumOfLastDigit([1, 23, 456]) ) > # 9 9 10 > > # Use generator expression with built-in sum function > > def getSumOfLastDigit(numList): > ? ?return sum(int(str(i)[-1:]) for i in numList) > > print(getSumOfLastDigit([12, 23, 34]), > ? ? ?getSumOfLastDigit([2, 3, 4]), > ? ? ?getSumOfLastDigit([1, 23, 456]) ) > # 9 9 10 > > -- > Terry Jan Reedy > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Matteo Landi http://www.matteolandi.net/ From afriere at yahoo.co.uk Wed Nov 10 03:22:26 2010 From: afriere at yahoo.co.uk (Asun Friere) Date: Wed, 10 Nov 2010 00:22:26 -0800 (PST) Subject: DTD Parsing References: <4e7a49ec-1816-46e5-bc51-9f7c88f4d025@37g2000prx.googlegroups.com> <49f5805b-416a-4942-a17e-2703e5f79f10@g28g2000pra.googlegroups.com> Message-ID: <1a5c04df-be05-4e8e-858a-6124cd911770@29g2000prb.googlegroups.com> On Nov 10, 5:00?pm, Stefan Behnel wrote: > Give lxml.objectify a try. It doesn't use DTDs, but does what you want. Yes I should take the time to familiarise myself with the lxml API in general. I mostly use libxml2 and libxslt nowadays. For simple stuff (like this) I use a StateParser which is your common-or-garden variety State Pattern built on HTMLParser. (For the record it took 3 trivial state definitions and one hackish one :) However, my issue was not with any particular in any particular python technology for XML processing, but with eating a DTD. Once it's in xsd, it's all downhill from there! So the answer to my question turned out to be dtd2xsd.pl :) > It's generally a good idea to state what you want to achieve, rather than > just describing the failure of an intermediate step of one possible path > towards your hidden goal. This list has a huge history of finding shortcuts > that the OPs didn't think of. It's very simple really. I would like to know whether there is some generally used DTD parser around which could function as a replacement for xmlproc's DTDParser/DTDConsumer, the existence of which might have evaded my attention. I would still like to know. Without wanting to appear ungrateful, I'm not after any shortcut to any goal, hidden or otherwise, nor is the reason I want a DTD Parser (I only told you because you asked so nicely) strictly pertinent to my question. I simply meant to ask, precisely what I did ask. From afriere at yahoo.co.uk Wed Nov 10 03:27:51 2010 From: afriere at yahoo.co.uk (Asun Friere) Date: Wed, 10 Nov 2010 00:27:51 -0800 (PST) Subject: DTD Parsing References: <4e7a49ec-1816-46e5-bc51-9f7c88f4d025@37g2000prx.googlegroups.com> <06071410-4684-4169-b1f8-0783e34f9062@f16g2000prj.googlegroups.com> Message-ID: <6e32203f-b4e2-4466-ac05-e02800fc16dd@r31g2000prg.googlegroups.com> On Nov 10, 6:36?pm, Ian Kelly wrote: > That's five whole lines of code. ?Why go to all that trouble when you > can just do this: > > import config > > I kid, but only partially. ? For myself, generally because I only become aware of the module, or the module is only written after I written some stuff myself. I wrote a Date object before the standard one either existed or I knew of it and I'll keep on using it till you pry it from my cold ... on 2nd thoughts don't pry, just let me use it. From geoff.bache at gmail.com Wed Nov 10 03:33:29 2010 From: geoff.bache at gmail.com (Geoff Bache) Date: Wed, 10 Nov 2010 00:33:29 -0800 (PST) Subject: A way to get setup.py to create links instead of copy References: <5ec2edeb-14cf-4c1d-919f-d4246f4af10a@f20g2000yqi.googlegroups.com> Message-ID: <7e132838-91eb-4958-8acf-e305d77b4d03@r14g2000yqa.googlegroups.com> On Nov 9, 6:33?pm, Steve Holden wrote: > On 11/9/2010 4:18 AM, Geoff Bache wrote: > > > Hi all, > > > One of the things I've always loved about Python (having come from > > compiled languages) was the lack of an extra step between changing my > > code and running it. > > > On my current project, however, I find that I have to install my > > Python code with setup.py before it will run. Being used to not having > > this step, I easily forget to run setup.py install before they will > > run, and then spend time wondering why my changes didn't work. > > > So I went into the target directory and replaced the copies with > > symbolic links back to the original code. This felt like a hack but > > does mean I don't have to install the whole time any more. > > > I wonder if there is some standard way to deal with this situation? > > Yes, there is. It involves (to a first approximation) understanding the > role of sys.path, and its relationship with the PYTHONPATH environment > variable. In brief, this tells the interpreter where to look for modules > when it is importing. > > Installation with setup.py is normally reserved for a fairly permanent > insertion of the code into your Python distribution, which might have > added it for all users. If this is an issue you may want to undo the > installation manually by removing its additions to your Python's > Lib/site-packages directory. > Hi Steve, I think I understand this stuff fairly well. I have my own Python installation (using virtualenv) so I'm not affecting anyone else. The problem is that my program runs from the command line, and is tested via other programs that call it as a subprocess, and don't expect to have to invoke Python explicitly. It does not work with the default Python on my system, which is a too old version, so relies on the "#!" line at the top to be correct. As I cannot hardcode this in my source tree, it seems difficult to make it runnable from the source tree. Incidentally, I'm interested that you say setup.py is normally reserved for a permanent installation. I've run into many Python programs, including quite well known ones, which did not appear to be runnable directly from the download or source tree, but required running setup.py before they would work. Regards, Geoff From tjreedy at udel.edu Wed Nov 10 04:24:36 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 10 Nov 2010 04:24:36 -0500 Subject: Silly newbie question - Caret character (^) In-Reply-To: References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> Message-ID: On 11/9/2010 7:13 PM, Seebs wrote: > On 2010-11-09, Terry Reedy wrote: >> I've been wondering why C programmers keep writing code susceptible to >> buffer overruns ;=). > > Because we're dumb! > > (Actually, in my defense, my code almost never, if ever, has buffer > overruns. I do in some rare cases have truncation issues with sufficiently > ridiculous input data.) I was referring to Schildt using gets() all the time and thereby teaching new C generations to do he same. -- Terry Jan Reedy From ldo at geek-central.gen.new_zealand Wed Nov 10 04:47:57 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 10 Nov 2010 22:47:57 +1300 Subject: Learning Pyhton - Functional Programming - How intersect/difference two dict with dict/values? fast! References: <4d71519e-a232-427f-b4e0-5bae90fc4acb@n32g2000prc.googlegroups.com> <4cd9b16d$0$1640$742ec2ed@news.sonic.net> Message-ID: In message , Terry Reedy wrote: > To echo John Nagle's point, if you want non-masochist volunteers to read > your code, write something readable like: > > dict1 = {'ab': [[1,2,3,'d3','d4',5], 12], > 'ac': [[1,3,'78a','79b'], 54], > 'ad': [[56,57,58,59], 34], > 'ax': [[56,57,58,59], 34]} How come Python itself doesn?t display things that way? From ldo at geek-central.gen.new_zealand Wed Nov 10 04:50:02 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 10 Nov 2010 22:50:02 +1300 Subject: How to test if a module exists? References: Message-ID: In message , Jon Dufresne wrote: > On Mon, Nov 8, 2010 at 11:35 PM, Lawrence D'Oliveiro ... I see that you published my unobfuscated e-mail address on USENET for all to see. I obfuscated it for a reason, to keep the spammers away. I'm assuming this was a momentary lapse of judgement, for which I expect an apology. Otherwise, it becomes grounds for an abuse complaint to your ISP. From paul.nospam at rudin.co.uk Wed Nov 10 04:51:16 2010 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Wed, 10 Nov 2010 09:51:16 +0000 Subject: Learning Pyhton - Functional Programming - How intersect/difference two dict with dict/values? fast! References: <4d71519e-a232-427f-b4e0-5bae90fc4acb@n32g2000prc.googlegroups.com> <4cd9b16d$0$1640$742ec2ed@news.sonic.net> Message-ID: <87tyjpy0a3.fsf@rudin.co.uk> Lawrence D'Oliveiro writes: > In message , Terry Reedy > wrote: > >> To echo John Nagle's point, if you want non-masochist volunteers to read >> your code, write something readable like: >> >> dict1 = {'ab': [[1,2,3,'d3','d4',5], 12], >> 'ac': [[1,3,'78a','79b'], 54], >> 'ad': [[56,57,58,59], 34], >> 'ax': [[56,57,58,59], 34]} > > How come Python itself doesn?t display things that way? try: pprint.pprint(dict1) From __peter__ at web.de Wed Nov 10 04:52:40 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 10 Nov 2010 10:52:40 +0100 Subject: Class extension confusion :( References: Message-ID: r0g wrote: > I have a subclass of BaseHHTPRequestHandler which uses a dictonary > "paths" and a function "api_call" which are defined in the main > namespace of the module. I'd rather I was able to pass these object to > the constructor and store them as data attributes "self.paths" and > "self.api_call" but I'm not sure how to do that properly. My > understanding is that one may extend a constructor by defining it's > __init__ method, calling the parents constructor and then adding ones > own attributes to taste. What I don't understand is where or how I am > supposed to get these extra constructor arguments into the class given > that I don't instantiate it myself, it is seemingly instantiated by > HTTPServer class that I pass it to e.g. > > httpd = HTTPServer(server_address, PlainAJAXRequestHandler) > > I wondered if I ought to instantiate an instance of > PlainAJAXRequestHandler, set the attributes (either manually or by > extending it's constructor) and pass that to HTTPServer but I figured it > expects a class not an instance as it probably wants to spawn one > instance for each request so that would be a non starter. Might I need > to subclass HTTPServer, find the bit that instantiates the request > handler and override that so it passes it's constructor more parameters? > Right now I'm pretty confused, can somebody please tell me how I might > accomplish this, what I'm failing to grasp or point me to the docs that > explain it - I've spent the last hour or two plowing through docs to no > avail, I guess it's a case of keyword ignorance on my part! Code > follows... Try passing a factory function instead of a class. Untested: from functools import partial class PlainAJAXRequestHandler(BaseHTTPRequestHandler): def __init__(self, api_call, paths, *args, **kw): BaseHTTPRequestHandler.__init__(self, *args, **kw) self.api_call = api_call self.paths = paths paths = ... api_call = ... httpd = HTTPServer( server_address, partial(PlainAJAXRequestHandler, paths, api_call)) From ldo at geek-central.gen.new_zealand Wed Nov 10 04:52:52 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 10 Nov 2010 22:52:52 +1300 Subject: subclassing str References: <5dLBo.1024$w8.406@twister2.libero.it> <6048c71a-fba9-4244-9a36-a5d19c8a5516@y23g2000yqd.googlegroups.com> <87lj52kwln.fsf.mdw@metalzone.distorted.org.uk> Message-ID: In message <87lj52kwln.fsf.mdw at metalzone.distorted.org.uk>, Mark Wooding wrote: > One option is to implement a subclass which implements the additional > protocol. This is why I think object orientation ruins your ability to think properly. For ?protocol? read ?function?. If you want to implement a new function, then implement a new function, why do you have to go through this ?subclassing? malarkey just to do something so simple. From ldo at geek-central.gen.new_zealand Wed Nov 10 04:53:44 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 10 Nov 2010 22:53:44 +1300 Subject: Help Documenting Python Syntax References: <4d15eca9-20a5-4ad1-bdd6-f66fb386220b@y2g2000prf.googlegroups.com> Message-ID: In message , Grant Edwards wrote: > My question is why bother with 2.5? In mitigation, your honour, let me plead that the latest Debian Stable still ships with that version. From mdw at distorted.org.uk Wed Nov 10 05:56:31 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 10 Nov 2010 10:56:31 +0000 Subject: Allowing comments after the line continuation backslash References: <4CCE6FF6.2050408@v.loewis.de> <87aalrjkty.fsf@benfinney.id.au> <8jd3m9Fr55U7@mid.individual.net> <87fwvdb69k.fsf.mdw@metalzone.distorted.org.uk> <878w12kt5x.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <87tyjpih0g.fsf.mdw@metalzone.distorted.org.uk> Lawrence D'Oliveiro writes: > In message <878w12kt5x.fsf.mdw at metalzone.distorted.org.uk>, Mark Wooding > wrote: > > 2. The MainWindow class only has the `Window' attribute described in > > its definition. Apparently there are other attributes as well (the > > ColorMumbleList family for one, also `LayerDisplay'). Similarly, > > the LoadedImage class has attributes `Contents' and `FileName', but > > I see attributes `RowStride', `ImageDrawSize' and `SrcDimensions' > > used immediately below. > > These are really just namespaces, one for the GUI context and the other for > the image data. I think my point was about the rather selective documentation of the namespaces. The trivial-class trick is something I use myself (though usually to simulate a structure rather than just to carve up namespace) so I don't find it objectionable in and of itself. > > 3. In SelectSaveMenu, there's a curious `for' loop: > > > > for State in (gtk.STATE_NORMAL,) : # no need for > > gtk.STATE_INSENSITIVE > > ## blah > > > > Firstly, this is obviously equivalent to `state = gtk.STATE_NORMAL' > > followed by the loop body (YAGNI). > > It?s a tuple of one element. It used to be a tuple of two, and there is the > possibility it might need to become that again (as intimated at in the > attached comment). That?s why it stays a tuple. I guessed the history. I'm in two minds about this sort of thing. I /like/ history: I'm fascinated by the history of old programs and programming languages; but looping over a single thing just seems weird. > > Of course, being boilerplate, the similarities visually outweigh the > > differences, when in fact it's the differences that are > > interesting. > > That is generally how code reuse works. All the ?boilerplate? is in the > function definition, so I just have to call it parameterized by the > differences appropriate to each instance. Except that's not the case. There are extremely close similarities between the six calls which strongly suggest (to me, anyway) that further factoring would be beneficial. I detest writing anything more than once, and don't much enjoy playing spot-the-difference when reading code. The six calls are a screenful of spot-the-difference. > > It doesn't help that all of the names of the things involved are so > > wretchedly verbose. > > Oh please, no. Since when are explanatory names ?wretchedly verbose?? When the start and end bits are the same and the different bits are hidden in the middle. After staring at a screenful of MainWindow.MumbleDisplay my head starts spinning. > > How about the following? > > > > def make_listview_l1 ... > > And what, pray tell, is the significance of the name ?make_listview_l1?? If > there is something I would describe as ?wretched?, it is the use of random > numerical suffixes like this. It's a terse reference to List1Box (your name). Since it was only being used in the following two lines, I figured the name didn't matter much. (In Lisp, I'd have wrapped the two lines in FLET and simply called the function FROB.) > > Looking at some of the rest of the code, it might (or might not) be > > worthwhile actually making a class to gather together a list's model > > and view; subclasses can then vary their individual parameters, and > > the various colour lists can also keep the various captions with > > them. > > Most of that variation is already handled without the limitations of > thinking in classes. For example, selection of a colour in all three lists > is handled through a single EditColor routine. And of course you?ve already > seen how a single DefineScrollingList routine can be used to set up all the > scrolling lists used in this GUI. There's so much commonality in the arguments that I'm not convinced that they're fully factored. Worse, there are several tables involving your various ColorMumbleLists: adding another would require fiddling with all of them, which suggests that things have been sliced up the wrong way. (I'm aware in this instance that the set of such things is externally constrained in this case.) Maybe packaging all of the information about each individual list in one object and having a list of these objects would be better. > > 5. Much of the indentation and layout is rather unconventional, though > > not intolerable. But I found (deep in `SelectSaveMenu'): > > > > NewRenderPixels = array.array \ > > ( > > "B", > > FillColor > > * > > (ImageRowStride // 4 * ImageBounds[1]) > > ) > > > > to be most disconcerting. > > Is the structure of the expression not apparent to you? No, it really isn't. Oddly enough, I'd find (setf new-render-pixels (array:array "B" (* fill-color (floor image-row-stride 4) (aref image-bounds 1)))) much easier to cope with. > You?d probably need plenty of fresh air after something like this, > then: > > PatternArray = array.array \ > ( > "I", > 16 * (16 * (Light,) + 16 * (Dark,)) > + > 16 * (16 * (Dark,) + 16 * (Light,)) > ) That's not noticeably worse. The bizarre thing is the relative indentation of the operands to the * -- the oddness of which is emphasized by the initial argument. > > Also, I couldn't work out why some parens are indented only two > > spaces and others are indented the full eight. > > Eight?? You mean four. No, eight. Text editors are misleading: tab stops for plain text files are not a matter of individual preference. (I read the code straight off GitHub: my browser correctly interpreted tabs as moving to the next multiple of eight columns.) -- [mdw] From preyanthesila at ymail.com Wed Nov 10 06:17:07 2010 From: preyanthesila at ymail.com (preyanthesila at ymail.com) Date: Wed, 10 Nov 2010 03:17:07 -0800 (PST) Subject: Real profiles and real moms are alone Message-ID: <7b431995-efad-4aed-a065-01ee159c9ca5@a9g2000pro.googlegroups.com> Real profiles and real moms are alone http://urlrunt.me?c92 From preyanthesila at ymail.com Wed Nov 10 06:17:47 2010 From: preyanthesila at ymail.com (preyanthesila at ymail.com) Date: Wed, 10 Nov 2010 03:17:47 -0800 (PST) Subject: talk singles dads for make his life better Message-ID: <8652b2a9-a31f-4fa1-bf31-ea50a4e9d363@42g2000prt.googlegroups.com> talk singles dads for make his life better http://urlrunt.me?c92 From fetchinson at googlemail.com Wed Nov 10 06:39:40 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Wed, 10 Nov 2010 12:39:40 +0100 Subject: =?windows-1252?Q?Re=3A_Am_I_The_Only_One_Who_Keeps_Reading_=93Numpy=94_?= =?windows-1252?Q?as_=93Numpty=94=3F?= In-Reply-To: References: Message-ID: As in Numpty Dumpty? > Sorry... -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From duane.kaufman at gmail.com Wed Nov 10 06:49:05 2010 From: duane.kaufman at gmail.com (TheSeeker) Date: Wed, 10 Nov 2010 03:49:05 -0800 (PST) Subject: Deditor 0.2.2 References: <6cdb5dd1-1868-4a6e-8b59-5b871f8d412e@42g2000prt.googlegroups.com> <613e4abc-329b-4ab3-8349-b3ec047cb747@r14g2000yqa.googlegroups.com> Message-ID: <470b7ee0-b109-4bb6-afa0-391baf02033e@35g2000prt.googlegroups.com> On Nov 9, 10:04?am, Kruptein wrote: > On Nov 8, 3:01?pm, Jean-Michel Pichavant > wrote: > > > > > > > > > > > TheSeeker wrote: > > > On Nov 6, 7:06 am, Kruptein wrote: > > > >> Hey, > > > >> I released version 0.2.2 of my pythonic text-editor ?Deditor. > > >> It adds the use of projects, a project is a set of files which you can > > >> open all at once to make development much faster and easier. > > > >> For more information visit launchpad:http://launchpad.net/deditor > > > >> I also uploaded a video to introduce you to deditor:http://www.youtube.com/watch?v=hS8xBu-39VI > > >> (note: youtube is still processing the file so you might have to wait > > >> a bit to see it) > > > > Hi, > > > I might have missed this, but it seems deditor requires Python above > > > 2.5? > > > > It would be nice to mention the requirements on the home page > > > somewhere. > > > > Thanks, > > > Duane > > > I already point that on the last release. You should really just > > consider writing the requirements (python & wx). > > > JM > > I'm going todo that right now! I alswyas forget it :p Hi, In addition, on Debian Lenny, with Python 2.5: deditor.py:429: Warning: 'with' will become a reserved keyword in Python 2.6 Traceback (most recent call last): File "", line 1, in File "deditor.py", line 429 with open(cf,"wb") as configf: ^ SyntaxError: invalid syntax So I don't think Python 2.5 works . Thanks, Duane From mdw at distorted.org.uk Wed Nov 10 06:56:08 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 10 Nov 2010 11:56:08 +0000 Subject: subclassing str References: <5dLBo.1024$w8.406@twister2.libero.it> <6048c71a-fba9-4244-9a36-a5d19c8a5516@y23g2000yqd.googlegroups.com> <87lj52kwln.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <87lj51ie93.fsf.mdw@metalzone.distorted.org.uk> Lawrence D'Oliveiro writes: > In message <87lj52kwln.fsf.mdw at metalzone.distorted.org.uk>, Mark Wooding > wrote: > > > One option is to implement a subclass which implements the additional > > protocol. > > This is why I think object orientation ruins your ability to think > properly. For ?protocol? read ?function?. If you want to implement a > new function, then implement a new function, why do you have to go > through this ?subclassing? malarkey just to do something so simple. Functions don't do type-dependent dispatch, which was, of course, the whole point. A `protocol' is a collection of messages understood by a number of different kinds of objects, causing potentially object-specific behaviour. I gave the explicit example of serialization: string probably serializes differently from an integer or a list. The `__str__' and `__repr__' methods form a simple protocol for object printing, as an additional example. The `str' and `repr' functions provides a potentially useful external entry points into the protocol, but they work by doing a type-dependent dispatch on the argument -- calling the appropriate method. Object orientation isn't useless or an impediment to clear thinking. It does seem to have turned into a bizarre kind of religion by some, and many `mainstream' languages provide very poor object orientation features (yes, Java and C#, I'm looking at you). But OO can be useful. I think the notion of `protocol' is central to coherent OO design, but this seems largely overlooked in much of the literature I've read. This may mean that many people are muddled about what OO is actually for. -- [mdw] From mdw at distorted.org.uk Wed Nov 10 07:04:01 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 10 Nov 2010 12:04:01 +0000 Subject: How to test if a module exists? References: Message-ID: <87hbfpidvy.fsf.mdw@metalzone.distorted.org.uk> Lawrence D'Oliveiro writes: > I see that you published my unobfuscated e-mail address on USENET for all to > see. I obfuscated it for a reason, to keep the spammers away. I'm assuming > this was a momentary lapse of judgement, for which I expect an apology. > Otherwise, it becomes grounds for an abuse complaint to your ISP. Don't be silly! If anything, using forged email addresses in Usenet headers is closer to abuse. Note that there's nothing to stop `new_zealand' from becoming a TLD at some point (the underscore makes it unlikely, I grant). If you'd mangled the local part, or used an explicitly reserved TLD such as `example', then there wouldn't be a problem. -- [mdw] From aioe.org at technicalbloke.com Wed Nov 10 07:21:44 2010 From: aioe.org at technicalbloke.com (r0g) Date: Wed, 10 Nov 2010 12:21:44 +0000 Subject: How to test if a module exists? References: Message-ID: On 10/11/10 09:50, Lawrence D'Oliveiro wrote: > In message, Jon > Dufresne wrote: > >> On Mon, Nov 8, 2010 at 11:35 PM, Lawrence D'Oliveiro ... > > I see that you published my unobfuscated e-mail address on USENET for all to > see. I obfuscated it for a reason, to keep the spammers away. I'm assuming > this was a momentary lapse of judgement, for which I expect an apology. > Otherwise, it becomes grounds for an abuse complaint to your ISP. > You use your main address on USENET rather than a junk one!? Obfuscated or not that's either brave or foolhardy! Roger. From felipe.bastosn at gmail.com Wed Nov 10 07:34:06 2010 From: felipe.bastosn at gmail.com (Felipe Bastos Nunes) Date: Wed, 10 Nov 2010 10:34:06 -0200 Subject: DTD Parsing In-Reply-To: References: <4e7a49ec-1816-46e5-bc51-9f7c88f4d025@37g2000prx.googlegroups.com> <06071410-4684-4169-b1f8-0783e34f9062@f16g2000prj.googlegroups.com> Message-ID: I'll look at the options. But anyway, only to give an example of the configs I told, the ShoX project (at sourceforge.net) has xml as config files. I'm not talking about common users to edit the xmls, it's about the developer edit them :-) I'm working in a python wireless sensor network simulator, some builtin functions at python will greatly increase the ease in doing this. Does any, libxml2 or lxml, collect children like jdom does in java? List children = myRoot.getChildren(); Or just doing a Handler to find the children? 2010/11/10, Ian Kelly : > On 11/9/2010 11:14 PM, r0g wrote: >> Me too when possible, TBH if I only needed strings and there was no >> pressing security issue I'd just do this... >> >> config = {} >> for line in (open("config.txt", 'r')): >> if len(line) > 0 and line[0] <> "#": >> param, value = line.rstrip().split("=",1) >> config[param] = value > > That's five whole lines of code. Why go to all that trouble when you > can just do this: > > import config > > I kid, but only partially. Where this really shines is when you're > prototyping something and you need to configure complex object > hierarchies. No need to spend time writing parsers to generate the > hierarchies; you just construct the objects directly in the config. > When the project becomes mature enough that configuration security is a > concern, then you can replace the config with XML or whatever, and in > the meantime you can focus on more important things, like the actual > project. > > Cheers, > Ian > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Felipe Bastos Nunes From felipe.vinturini at gmail.com Wed Nov 10 07:36:41 2010 From: felipe.vinturini at gmail.com (Felipe Vinturini) Date: Wed, 10 Nov 2010 10:36:41 -0200 Subject: Questions: While And List Comprehension Message-ID: Hi Folks, I am quite new to python and I don't have a lot of experience with it yet. I have two simple questions: 1. Is there a way to limit the number of times a list comprehension will execute? E.g. I want to read from input only 5 values, so I would like something like (the values between # # are what I want): =================================================================================== COUNT = 0 print [ v for v in sys.stdin.readlines() *# *IF COUNT < 5* #* ] ## Increment COUNT somewhere =================================================================================== 2.* *I would like to know another way, a more pythonic way, to write the following: =================================================================================== import sys def Z(iNumber): sum=0 while (iNumber>=5): iNumber=iNumber/5 sum = sum + iNumber print sum def factorialCountZeros2(): sysStdinReadLine = sys.stdin.readline numValues = int(sysStdinReadLine()) [ Z(int(sysStdinReadLine())) for x in xrange(numValues) ] if __name__ == '__main__': factorialCountZeros2() =================================================================================== To be more specific, I would like to know about the Z function, is there a way to rewrite that while with list comprehension? This code is to solve the CodeChef problem: http://www.codechef.com/problems/FCTRL/ (I am still in the easy part) and it executed in 2.5 secs, I would like to know if there is something else I can improve performance. Thanks for your attention! Regards, Felipe. -------------- next part -------------- An HTML attachment was scrubbed... URL: From nomail at thisaddress.com Wed Nov 10 07:44:41 2010 From: nomail at thisaddress.com (Sven) Date: Wed, 10 Nov 2010 07:44:41 -0500 Subject: =?iso-8859-1?Q?Re:_Am_I_The_Only_One_Who_Keeps_Reading_=3FNumpy=3F_as_=3FNumpty=3F=3F?= References: Message-ID: <2010111007444115344-nomail@thisaddresscom> On 2010-11-10 01:53:58 -0500, Lawrence D'Oliveiro said: > Sorry... no. -- ./Sven From mdw at distorted.org.uk Wed Nov 10 07:45:07 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 10 Nov 2010 12:45:07 +0000 Subject: How to test if a module exists? References: Message-ID: <87d3qdibzg.fsf.mdw@metalzone.distorted.org.uk> r0g writes: > You use your main address on USENET rather than a junk one!? Obfuscated or > not that's either brave or foolhardy! I use my real email address. I also have an aggressive spam filter. But I don't think that much of my comes from Usenet harvesters any more, to be honest. -- [mdw] From nomail at thisaddress.com Wed Nov 10 07:49:47 2010 From: nomail at thisaddress.com (Sven) Date: Wed, 10 Nov 2010 07:49:47 -0500 Subject: Development Vs Release Message-ID: <201011100749474192-nomail@thisaddresscom> Hi, When developing tools I often also work on a module that I need to import into that tool. Once the work is complete both (or more) files go to a release location on the network. The question I have is: what is the easiest way to adjust the import path depending on whether it's a release or dev version. Right now I am using a custom env var (PYDEV) that I have to manually set when I work on the project that will insert the development module path into sys.path. This way the released version will not append the path and use the system wide PYTHONPATH Are there any better ways of doing this? I don't like the idea of flags inside the code as they can often get missed when developers release their code, ending up with released versions that import modules from the developer's working directory. Thanks -- ./Sven From martin at address-in-sig.invalid Wed Nov 10 08:07:58 2010 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Wed, 10 Nov 2010 13:07:58 +0000 (UTC) Subject: Commercial or Famous Applicattions.? References: Message-ID: On Wed, 10 Nov 2010 17:01:05 +1300, Lawrence D'Oliveiro wrote: > In message , Martin Gregorie wrote: > >> ...and don't forget getmail, a better behaved replacement for >> fetchmail. > > I was just looking this up in the Getmail FAQ, since I didn?t know about > the issues with Fetchmail. > FWIW the thing that really irritated me about fetchmail is the way it only deletes messages at the end of a session and never cleans up after itself. If a session gets timed out or otherwise interrupted the messages that were read in it are left in the server's mail marked 'read'. Subsequent sessions won't re-read them but won't go expunge them either. This leads to a gradual build-up of read but not expunged messages in the server's mailbox. The only fix I discovered was to go in manually with an MUA just after a fetchmail session so it could read and expunge this junk. getmail doesn't cause this problem. -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From ben+python at benfinney.id.au Wed Nov 10 08:10:10 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 11 Nov 2010 00:10:10 +1100 Subject: [OT] Usenet and email address exposure (was: How to test if a module exists?) References: Message-ID: <87zkthb9zh.fsf_-_@benfinney.id.au> r0g writes: > You use your main address on USENET rather than a junk one!? Yes. The amount of time spent keeping my spam filter well-trained is far smaller than the amount I'd lose faffing around with countless throwaway email addresses. I have to expose my address on the internet anyway for it to be useful. Hiding it from Usenet isn't going to gain me anything useful. > Obfuscated or not that's either brave or foolhardy! I haven't noticed much spam to email addresses I use on Usenet, and the spam filter catches it all. But regardless, a well-trained spam filter allows me to continue using a consistent, working email address. -- \ ?Everything you read in newspapers is absolutely true, except | `\ for that rare story of which you happen to have first-hand | _o__) knowledge.? ?Erwin Knoll | Ben Finney From martin at address-in-sig.invalid Wed Nov 10 08:12:24 2010 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Wed, 10 Nov 2010 13:12:24 +0000 (UTC) Subject: How to test if a module exists? References: <87hbfpidvy.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On Wed, 10 Nov 2010 12:04:01 +0000, Mark Wooding wrote: > Lawrence D'Oliveiro writes: > >> I see that you published my unobfuscated e-mail address on USENET for >> all to see. I obfuscated it for a reason, to keep the spammers away. >> I'm assuming this was a momentary lapse of judgement, for which I >> expect an apology. Otherwise, it becomes grounds for an abuse complaint >> to your ISP. > > Don't be silly! If anything, using forged email addresses in Usenet > headers is closer to abuse. Note that there's nothing to stop > `new_zealand' from becoming a TLD at some point (the underscore makes it > unlikely, I grant). If you'd mangled the local part, or used an > explicitly reserved TLD such as `example', then there wouldn't be a > problem. > Using the .invalid TLD is a generally accepted way of writing an intentionally fake address for use in USENET. -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From lnenov at mm-sol.com Wed Nov 10 08:12:46 2010 From: lnenov at mm-sol.com (lnenov) Date: Wed, 10 Nov 2010 15:12:46 +0200 Subject: Enumeration of strings and export of the constants Message-ID: <4CDA9A4E.1050106@mm-sol.com> Hi, I need to enumerate a couple hundred strings to constants and export them to another module(s) globals. In the mean time I want to keep my module's namespace as clear as I can and I don't want to use "import *" later. Here is the code I intend to use: test.py 1 class Apinamespace(): 2 @staticmethod 3 def import_to(destination): 4 5 for name, number in Apinamespace.__dict__.items(): 6 if (name.startswith('__') and name.endswith('__')) or name == "import_to": # :) 7 pass 8 else: 9 setattr(destination, name, number) 10 11 class Enumerate(): 12 def __init__(self, names, start = 0, step = 1): 13 enumerate_to = Apinamespace 14 15 for number, name in self.enumerate(names, start, step): 16 setattr(enumerate_to, name, number) 17 18 def enumerate(self, names, start = 0, step = 1): 19 for index in range(len(names)): 20 yield (start, names[index]) 21 start += step 22 23 example_names = ['Foo','Bar','Free', 'Beer'] 24 example_names2 = ['Foo_me_too', 'Bar_me_too', 'Free_me_too', 'Beer_me_too'] 25 Enumerate(example_names) 26 Enumerate(example_names2, 4, 2) This works like a charm: >>> import sys, test >>> thismodule = sys.modules[__name__] >>> test.Apinamespace.import_to(thismodule) >>> Beer 3 >>> Beer_me_too 10 Is there a better and more common way to do this? Do you know of a way to see the module in/from which a function was called without using traceback and frames? (I want to remove the argument from Apinamespace.import_me) And can line 6 be replaced by something less evil. Thanks for any suggestions. Lyudmil From darragh.ssa at gmail.com Wed Nov 10 08:51:05 2010 From: darragh.ssa at gmail.com (Kruptein) Date: Wed, 10 Nov 2010 05:51:05 -0800 (PST) Subject: Deditor 0.2.2 References: <6cdb5dd1-1868-4a6e-8b59-5b871f8d412e@42g2000prt.googlegroups.com> <613e4abc-329b-4ab3-8349-b3ec047cb747@r14g2000yqa.googlegroups.com> <470b7ee0-b109-4bb6-afa0-391baf02033e@35g2000prt.googlegroups.com> Message-ID: <84d92b8c-4592-4883-a8c4-929d93ff1138@j2g2000yqf.googlegroups.com> On Nov 10, 12:49?pm, TheSeeker wrote: > On Nov 9, 10:04?am, Kruptein wrote: > > > > > > > On Nov 8, 3:01?pm, Jean-Michel Pichavant > > wrote: > > > > TheSeeker wrote: > > > > On Nov 6, 7:06 am, Kruptein wrote: > > > > >> Hey, > > > > >> I released version 0.2.2 of my pythonic text-editor ?Deditor. > > > >> It adds the use of projects, a project is a set of files which you can > > > >> open all at once to make development much faster and easier. > > > > >> For more information visit launchpad:http://launchpad.net/deditor > > > > >> I also uploaded a video to introduce you to deditor:http://www.youtube.com/watch?v=hS8xBu-39VI > > > >> (note: youtube is still processing the file so you might have to wait > > > >> a bit to see it) > > > > > Hi, > > > > I might have missed this, but it seems deditor requires Python above > > > > 2.5? > > > > > It would be nice to mention the requirements on the home page > > > > somewhere. > > > > > Thanks, > > > > Duane > > > > I already point that on the last release. You should really just > > > consider writing the requirements (python & wx). > > > > JM > > > I'm going todo that right now! I alswyas forget it :p > > Hi, > > In addition, on Debian Lenny, with Python 2.5: > > deditor.py:429: Warning: 'with' will become a reserved keyword in > Python 2.6 > Traceback (most recent call last): > ? File "", line 1, in > ? File "deditor.py", line 429 > ? ? with open(cf,"wb") as configf: > ? ? ? ? ? ? ^ > SyntaxError: invalid syntax > > So I don't think Python 2.5 works . > > Thanks, > Duane that's possible, I was only able to test it with version 2.7, I'm going to change the dependencies then. thanks to point that out, 2.6 should work though? and the windows wxpython version and the linux version are different which causes some stupid bugs... :s From rbotting at csusb.edu Wed Nov 10 08:57:04 2010 From: rbotting at csusb.edu (RJB) Date: Wed, 10 Nov 2010 05:57:04 -0800 (PST) Subject: Help Documenting Python Syntax References: <4d15eca9-20a5-4ad1-bdd6-f66fb386220b@y2g2000prf.googlegroups.com> Message-ID: On Nov 9, 8:14?am, Grant Edwards wrote: > On 2010-11-09, Terry Reedy wrote: > > > On 11/9/2010 10:26 AM, RJB wrote: > >> I have been trying to redevelop a syntax page for Python at > >> ? ? ?http://cse.csusb.edu/dick/samples/python.syntax.html > > > Page does not load correctly; had to hit refresh to get entire page. > > It should specify that this is the syntax for Python 2.5. To me "the > > Python language" is 3.2. > > Nope. ?I just checked, and it's 2.6.5: > > ? $ python > ? Python 2.6.5 (release26-maint, Aug ?9 2010, 11:06:44) > > ;) > > My question is why bother with 2.5? > > I would think the logical choices would be 3.2 or 2.7 (or maybe 2.6). > I'm working from some grammars I've found on the web plus experiments. RJB From nobody at nowhere.com Wed Nov 10 08:59:02 2010 From: nobody at nowhere.com (Nobody) Date: Wed, 10 Nov 2010 13:59:02 +0000 Subject: Commercial or Famous Applicattions.? References: Message-ID: On Wed, 10 Nov 2010 13:07:58 +0000, Martin Gregorie wrote: > FWIW the thing that really irritated me about fetchmail is the way it > only deletes messages at the end of a session and never cleans up after > itself. If a session gets timed out or otherwise interrupted the messages > that were read in it are left in the server's mail marked 'read'. > Subsequent sessions won't re-read them but won't go expunge them either. > This leads to a gradual build-up of read but not expunged messages in the > server's mailbox. The --flush option will delete any "seen" messages before retrieving new messages. The --fetchall option will retrieve both seen and unseen messages. From pecora at anvil.nrl.navy.mil Wed Nov 10 09:10:49 2010 From: pecora at anvil.nrl.navy.mil (Lou Pecora) Date: Wed, 10 Nov 2010 09:10:49 -0500 Subject: Am I The Only One Who Keeps Reading ?Numpy? as ?Numpty?? References: <2010111007444115344-nomail@thisaddresscom> Message-ID: In article <2010111007444115344-nomail at thisaddresscom>, Sven wrote: > On 2010-11-10 01:53:58 -0500, Lawrence D'Oliveiro said: > > > Sorry... > > no. Yes, except for one other, above. :-) Bigger question: How do you pronouce it? Some say "num pee". Not the greatest image to English speakers. I say "num pie". Makes more sense to me since the "pie" sound is already in python a root for the name. This, of course, is a burning issue for us all. -- -- Lou Pecora From t33n4n at gmail.com Wed Nov 10 09:27:40 2010 From: t33n4n at gmail.com (Teenan) Date: Wed, 10 Nov 2010 14:27:40 +0000 Subject: Class extension confusion :( In-Reply-To: References: Message-ID: If memory serves, the following should work fine, as long as your happy for these vars to have the same value for all instances of the RequestHandler (static) MyHandler = PlainAJAXRequestHandler MyHandler.paths = my_paths_var webServer = HTTPServer( server_address, MyHandler) An alternative I've used in the past is to extend the server class in the same way, and store these vars in the server rather than the request handler. You can then use self.server in the requesthandler which holds the server instance. like self.server.my_var I seem to remember the documentation saying something about that the __init__ shouldn't be overriden for the HTTPRequestHandler class, so I wouldn't go down that route. Teenan. On Wed, Nov 10, 2010 at 5:45 AM, r0g wrote: > I have a subclass of BaseHHTPRequestHandler which uses a dictonary "paths" > and a function "api_call" which are defined in the main namespace of the > module. I'd rather I was able to pass these object to the constructor and > store them as data attributes "self.paths" and "self.api_call" but I'm not > sure how to do that properly. My understanding is that one may extend a > constructor by defining it's __init__ method, calling the parents > constructor and then adding ones own attributes to taste. What I don't > understand is where or how I am supposed to get these extra constructor > arguments into the class given that I don't instantiate it myself, it is > seemingly instantiated by HTTPServer class that I pass it to e.g. > > httpd = HTTPServer(server_address, PlainAJAXRequestHandler) > > I wondered if I ought to instantiate an instance of > PlainAJAXRequestHandler, set the attributes (either manually or by extending > it's constructor) and pass that to HTTPServer but I figured it expects a > class not an instance as it probably wants to spawn one instance for each > request so that would be a non starter. Might I need to subclass HTTPServer, > find the bit that instantiates the request handler and override that so it > passes it's constructor more parameters? Right now I'm pretty confused, can > somebody please tell me how I might accomplish this, what I'm failing to > grasp or point me to the docs that explain it - I've spent the last hour or > two plowing through docs to no avail, I guess it's a case of keyword > ignorance on my part! Code follows... > > Thanks for reading! > > Roger. > > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mdw at distorted.org.uk Wed Nov 10 09:28:28 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 10 Nov 2010 14:28:28 +0000 Subject: Am I The Only One Who Keeps Reading ?Numpy? as ?Numpty?? References: <2010111007444115344-nomail@thisaddresscom> Message-ID: <874obpi777.fsf.mdw@metalzone.distorted.org.uk> Lou Pecora writes: > Bigger question: How do you pronouce it? Rhymes with `grumpy'. -- [mdw] From bookredwu at gmail.com Wed Nov 10 09:42:44 2010 From: bookredwu at gmail.com (alexander) Date: Wed, 10 Nov 2010 06:42:44 -0800 (PST) Subject: Curses Programming Message-ID: Hi, all Here is the test. Plz help..... / ***************************************************************************************************************************************************/ If you use the new image search of Google, you will find that the result images are layouted in a way that each row has the same height, but contains different number of images dependents the width-height ratio of each image. The goal is to make each row of images having approximately same total width. Just try search any image inimages.google.com, you will get the idea. If you're the programmer designing this page, what algorithm would you use to select images for each row? Input: The input of the program is a plain text file, each line in the file containg 2 numbers, describing the width and height of an image e.g. 800 600 640 400 720 1280 ... Goal: Design an algorithm to put those images into a number of rows, each row is 150 pixel height and 1200 pixel wide. You could scale images proportionally to the same height. You need make sure the images are aligned as closely as possbile to the row boundary. Output: The indexes of the images you would put on each row followed by blank line. e.g. 0 1 2 According to the input file example, this output means image-0 (800 x 600) and image-1 (640 x 400) is put on the first row and image-2 (720 x 1280) is put on the second row. Constraint: Assuming, the input file contains less than 100 lines. Your algorithm should finish within 5 secs on a standard laptop. / **********************************************************************************************************************************************/ Could any give a hand? Thanks a lot Alex From bookredwu at gmail.com Wed Nov 10 09:49:01 2010 From: bookredwu at gmail.com (alexander) Date: Wed, 10 Nov 2010 06:49:01 -0800 (PST) Subject: Feed subscription IM bot Message-ID: <74b044f0-0188-4adf-af86-635cca338846@o15g2000prh.googlegroups.com> Hi, Can anyone help on this? / ********************************************************************************************************************/ The project should either be hosted online and usable from there, or can be run locally. Complete ource code should be delivered along with a brief readme for features. It should take about about 1-2 hours to complete. Basic requirements: Build a Python driven IM bot with the following features * A user can add the bot to his/her Google talk/jabber friends list. * The user types the words "sub [feed_url]" to the bot to begin subscribing to the feed at the specified feed_url ([feed_url] is the placeholder for the actual feed url. e.g. http://myweb.com/feed) * The user types the words "unsub [feed_url]" to stop subscribing to the feed * The bot scans the feed at a specified time interval, and sends new contents to the subscribing user Additional credits: * Additional bot commands: "ls", "pause [feed_url]", " resume[feed_url]", "grep [feed_url] [keywords]", whatever you think is useful and fun, even not feed subscription related * A web interface for reading/managing subscriptions * Beautiful, extensible and scalable architecture Requirements: * Python 2.5 * Robust and graceful error handling * Robust unicode handling / ************************************************************************************************************/ Thanks From azeynel1 at gmail.com Wed Nov 10 10:13:06 2010 From: azeynel1 at gmail.com (Zeynel) Date: Wed, 10 Nov 2010 07:13:06 -0800 (PST) Subject: How to read the Python tutorial? Message-ID: <59c26dd2-529f-4a4a-8f48-1ee5f35b068f@t7g2000vbj.googlegroups.com> For instance, when the tutorial has http://docs.python.org/release/2.6/library/datetime.html class datetime.datetime A combination of a date and a time. Attributes: year, month, day, hour, minute, second, microsecond, and tzinfo. What does this mean? How do I use it? For instance, I have a DateTimeProperty mDate that I get from a query in Google App Engine. This mDate has value mDATE = 2010-11-10 14:35:22.863000 But when I try datetime.datetime.mDATE.toordinal()) I get AttributeError. If I try something like td = mDATE.seconds in GAE development server I get AttributeError: 'datetime.datetime' object has no attribute 'seconds' What am I doing wrong? And how to understand this stuff so that I can start using the language instead of trying to figure out types. Thanks for your help. From martin at address-in-sig.invalid Wed Nov 10 10:19:16 2010 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Wed, 10 Nov 2010 15:19:16 +0000 (UTC) Subject: Commercial or Famous Applicattions.? References: Message-ID: On Wed, 10 Nov 2010 13:59:02 +0000, Nobody wrote: > On Wed, 10 Nov 2010 13:07:58 +0000, Martin Gregorie wrote: > >> FWIW the thing that really irritated me about fetchmail is the way it >> only deletes messages at the end of a session and never cleans up after >> itself. If a session gets timed out or otherwise interrupted the >> messages that were read in it are left in the server's mail marked >> 'read'. Subsequent sessions won't re-read them but won't go expunge >> them either. This leads to a gradual build-up of read but not expunged >> messages in the server's mailbox. > > The --flush option will delete any "seen" messages before retrieving new > messages. > ...and is described as dangerous, can cause message loss in the man page along with a warning to avoid including it as a permanent option - good enough reasons for not using it IMO. > The --fetchall option will retrieve both seen and unseen > messages. > Again, not useful as a permanent option since I don't want to receive duplicated messages. In both cases using them 'as required' requires: (a) monitoring the source mailbox for 'read' message build up (b) when 'read' messages are seen, executing a sequence of stop fetchmail alter configuration run it for one retrieval session change config back restart using the normal configuration That's far too much hassle to be part of SOP. Now, if ESR had fixed fetchmail to tidy up after itself (if getmail can do that, there's no reason why fetchmail can't) or had even added the ability for a daily or weekly cron job to enquire about 'read' messages and, if any are present, tell it to silently expunge them in a special session, I'd probably still use it. Without equivalent fixes its just a buggy bit of software, making getmail a superior replacement because it 'just works'. -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From invalid at invalid.invalid Wed Nov 10 10:30:26 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 10 Nov 2010 15:30:26 +0000 (UTC) Subject: Am I The Only One Who Keeps Reading ?Numpy? as ?Numpty?? References: <2010111007444115344-nomail@thisaddresscom> <874obpi777.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On 2010-11-10, Mark Wooding wrote: > Lou Pecora writes: >> Bigger question: How do you pronouce it? > > Rhymes with `grumpy'. Num-Pie -- Grant Edwards grant.b.edwards Yow! Boys, you have ALL at been selected to LEAVE th' gmail.com PLANET in 15 minutes!! From azeynel1 at gmail.com Wed Nov 10 10:40:37 2010 From: azeynel1 at gmail.com (Zeynel) Date: Wed, 10 Nov 2010 07:40:37 -0800 (PST) Subject: How to convert the date object 2010-11-10 14:52:35.026000 to integer? Message-ID: mDATE = "2010-11-10 14:52:35.026000" (Not sure if this is string or something else.) I would like to convert mDATE to integer to add, multiply etc. For instance, if I try to convert mDATE to seconds td = mDATE.seconds I get the error td = result.mDATE.seconds AttributeError: 'datetime.datetime' object has no attribute 'seconds' Thanks. From rantingrick at gmail.com Wed Nov 10 10:51:38 2010 From: rantingrick at gmail.com (rantingrick) Date: Wed, 10 Nov 2010 07:51:38 -0800 (PST) Subject: How to read the Python tutorial? References: <59c26dd2-529f-4a4a-8f48-1ee5f35b068f@t7g2000vbj.googlegroups.com> Message-ID: On Nov 10, 9:13?am, Zeynel wrote: > For instance, when the tutorial hashttp://docs.python.org/release/2.6/library/datetime.html > > class datetime.datetime > A combination of a date and a time. Attributes: year, month, day, > hour, minute, second, microsecond, and tzinfo. > > What does this mean? How do I use it? > > For instance, I have a DateTimeProperty mDate that I get from a query > in Google App Engine. This mDate has value > > mDATE = 2010-11-10 14:35:22.863000 Wait a minute i am confused...? Does Python have a "text" object that magically turns into a datetime object? >>> mDATE = 2010-11-10 14:35:22.863000 SyntaxError: invalid syntax hmm, apparently not! Usually in order to use methods of an object, you must create an object first or more specifically an instance. >>> dateobj = datetime.date(2010,11,10) >>> dir(dateobj) ['__add__', '__class__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__ne__', '__new__', '__radd__', '__reduce__', '__reduce_ex__', '__repr__', '__rsub__', '__setattr__', '__sizeof__', '__str__', '__sub__', '__subclasshook__', 'ctime', 'day', 'fromordinal', 'fromtimestamp', 'isocalendar', 'isoformat', 'isoweekday', 'max', 'min', 'month', 'replace', 'resolution', 'strftime', 'timetuple', 'today', 'toordinal', 'weekday', 'year'] From rantingrick at gmail.com Wed Nov 10 10:53:41 2010 From: rantingrick at gmail.com (rantingrick) Date: Wed, 10 Nov 2010 07:53:41 -0800 (PST) Subject: How to convert the date object 2010-11-10 14:52:35.026000 to integer? References: Message-ID: <6e22008f-4c72-4c1a-9722-50b92a96df3d@r14g2000yqa.googlegroups.com> On Nov 10, 9:40?am, Zeynel wrote: > mDATE = "2010-11-10 14:52:35.026000" > > (Not sure if this is string or something else.) > > I would like to convert mDATE to integer to add, multiply etc. > > For instance, if I try to convert mDATE to seconds > > td = mDATE.seconds > > I get the error > > ? ? td = result.mDATE.seconds > AttributeError: 'datetime.datetime' object has no attribute 'seconds' > > Thanks. No group likes when you ask the same question twice in two different threads. faus pas! Go back and check your other thread for enlightenment. From rantingrick at gmail.com Wed Nov 10 10:58:05 2010 From: rantingrick at gmail.com (rantingrick) Date: Wed, 10 Nov 2010 07:58:05 -0800 (PST) Subject: =?windows-1252?Q?Re=3A_Am_I_The_Only_One_Who_Keeps_Reading_=93Numpy=94_?= =?windows-1252?Q?as_=93Numpty=94=3F?= References: Message-ID: <940162c6-b61a-4bb7-9965-6e155716cda8@n30g2000vbb.googlegroups.com> On Nov 10, 12:53?am, Lawrence D'Oliveiro wrote: > Sorry... Was humpty dumpty your favorite nursery rhyme? And it's "Num-pee" for me. If the "py" is appended i use "x-pee" and if it is pre i use "pie- x". From hpj at urpla.net Wed Nov 10 11:03:03 2010 From: hpj at urpla.net (Hans-Peter Jansen) Date: Wed, 10 Nov 2010 17:03:03 +0100 Subject: http error 301 for urlopen In-Reply-To: References: <4cd7987e$0$1674$742ec2ed@news.sonic.net> Message-ID: <201011101703.03524.hpj@urpla.net> On Tuesday 09 November 2010, 03:10:24 Lawrence D'Oliveiro wrote: > In message <4cd7987e$0$1674$742ec2ed at news.sonic.net>, John Nagle wrote: > > It's the New York Times' paywall. They're trying to set a > > cookie, and will redirect the URL until you store and return the > > cookie. > > And if they find out you?re acessing them from a script, they?ll > probably try to find a way to block that as well. ..which could be alleviated by carefully crafting the requests ;-) Luckily, unpleasant related ground work was already done by others, e.g.: http://bugs.python.org/issue2275 Pete From azeynel1 at gmail.com Wed Nov 10 11:05:55 2010 From: azeynel1 at gmail.com (Zeynel) Date: Wed, 10 Nov 2010 08:05:55 -0800 (PST) Subject: How to read the Python tutorial? References: <59c26dd2-529f-4a4a-8f48-1ee5f35b068f@t7g2000vbj.googlegroups.com> Message-ID: <6b2d39f4-c9d9-4e77-9bb7-60e26dc334ee@j9g2000vbl.googlegroups.com> On Nov 10, 10:51?am, rantingrick wrote: > Wait a minute i am confused...? Does Python have a "text" object that > magically turns into a datetime object? > > >>> mDATE = 2010-11-10 14:35:22.863000 > > SyntaxError: invalid syntax This is the reason I am asking the question. I am confused about what mDATE is. It is defined as a DateTimeProperty in Google App Engine in the following model: class Rep(db.Model): mAUTHOR = db.UserProperty(auto_current_user=True) mUNIQUE = db.StringProperty() mCOUNT = db.IntegerProperty() mDATE = db.DateTimeProperty(auto_now=True) mDATE0 = db.DateTimeProperty(auto_now_add=True) mWEIGHT = db.IntegerProperty() When I acces it with this query: QUERY = Rep.all() QUERY.filter("mAUTHOR =", user) QUERY.order("-mCOUNT") RESULTS = QUERY.fetch(10) But when I try to use like this for instance: for result in RESULTS: WEIGHT = (datetime.datetime.result.mDATE.toordinal()) * result.mCOUNT I get AttributeError or if I try to use it like this dt = result.mDATE.seconds I get AttributeError: 'datetime.datetime' object has no attribute 'seconds' From rantingrick at gmail.com Wed Nov 10 11:19:19 2010 From: rantingrick at gmail.com (rantingrick) Date: Wed, 10 Nov 2010 08:19:19 -0800 (PST) Subject: How to read the Python tutorial? References: <59c26dd2-529f-4a4a-8f48-1ee5f35b068f@t7g2000vbj.googlegroups.com> <6b2d39f4-c9d9-4e77-9bb7-60e26dc334ee@j9g2000vbl.googlegroups.com> Message-ID: On Nov 10, 10:05?am, Zeynel wrote: > AttributeError: 'datetime.datetime' object has no attribute 'seconds' First of all put some scaffolding in this code. What is scaffolding. Basically some debug print statements so you can follow the trail of errors. You need to learn how to debug code and be self reliant. A few very important functions are. >>> a = 's' >>> b = 1 >>> a * b 's' >>> a + b Traceback (most recent call last): File "", line 1, in a + b TypeError: cannot concatenate 'str' and 'int' objects >>> type(a), type(b) (, ) >>> id(a), id(b) (26864768, 12844616) >>> print a, b s 1 >>> repr(a), repr(b) ("'s'", '1') >>> isinstance(a, str) True I would start at the loop and figure out what is going on from there with some print statements and the functions i showed you. Debugging is a large part of any programming project. We all do it everyday. So the sooner you learn the better. If you have a specific question feel free to ask, but general debug issues are better solved yourself. A few more indispensable functions are dir() and help() From robert.kern at gmail.com Wed Nov 10 12:02:35 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 10 Nov 2010 11:02:35 -0600 Subject: Allowing comments after the line continuation backslash In-Reply-To: References: <4CCE6FF6.2050408@v.loewis.de> <87aalrjkty.fsf@benfinney.id.au> <8jd3m9Fr55U7@mid.individual.net> <87fwvdb69k.fsf.mdw@metalzone.distorted.org.uk> <878w12kt5x.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On 11/10/10 12:26 AM, Lawrence D'Oliveiro wrote: > In message, Robert Kern > wrote: > >> For me, putting the brackets on their own lines (and using a trailing >> comma) has little to do with increasing readability. It's for making >> editing easier. Keeping all of the items consistent means that in order to >> add, delete, or move any item is the same operation everywhere in the list >> whether it is the first item, last item, or any item in between. > > Yup, I like to do that when there?s nothing special about the last item in > the list. Sometimes there is (e.g. an enumeration entry naming the number of > values in the enumeration, or an all-zero sentinel marking the end of a > list), in which case I omit the comma to indicate that nothing should come > afterwards. > > I remember an early experience with JavaScript (back in the days of Netscape > versus Internet Explorer 5.1 on a Mac), when I found that constructing a > list in this way wasn?t working in IE: turned out it was inserting some kind > of extra phantom list item after that last comma. Sigh... It's one of the things that pains me every time I code JavaScript. That and the lack of tuple unpacking. -- 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 igor.idziejczak at gmail.com Wed Nov 10 12:08:19 2010 From: igor.idziejczak at gmail.com (xoff) Date: Wed, 10 Nov 2010 09:08:19 -0800 (PST) Subject: multiple discontinued ranges Message-ID: I was wondering what the best method was in Python programming for 2 discontinued ranges. e.g. I want to use the range 3 to 7 and 17 to 23. Am I obliged to use 2 for loops defining the 2 ranges like this: for i in range (3,7): do bla for i in range (7,17): do bla or is there a more clever way to do this? From paul.nospam at rudin.co.uk Wed Nov 10 12:13:07 2010 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Wed, 10 Nov 2010 17:13:07 +0000 Subject: multiple discontinued ranges References: Message-ID: <87y691w198.fsf@rudin.co.uk> xoff writes: > I was wondering what the best method was in Python programming for 2 > discontinued ranges. e.g. I want to use the range 3 to 7 and 17 to 23. > Am I obliged to use 2 for loops defining the 2 ranges like this: > > for i in range (3,7): > do bla > for i in range (7,17): > do bla > > or is there a more clever way to do this? for i in itertools.chain(xrange(3,7), xrange(17,23)): print i From janssen at parc.com Wed Nov 10 12:15:18 2010 From: janssen at parc.com (Bill Janssen) Date: Wed, 10 Nov 2010 09:15:18 PST Subject: ANN: PyGUI 2.3 In-Reply-To: <8ivk3kFjhuU1@mid.individual.net> References: <8ivk3kFjhuU1@mid.individual.net> Message-ID: <35473.1289409318@parc.com> Gregory Ewing wrote: > Daniel Fetchinson wrote: > > > Any reason your project is not easy_installable? > > Mainly because I'm not a setuptools user and haven't been > motivated to learn how to do this so far. Applause!! Bill From no.email at nospam.invalid Wed Nov 10 12:15:38 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 10 Nov 2010 09:15:38 -0800 Subject: multiple discontinued ranges References: Message-ID: <7xy691w151.fsf@ruckus.brouhaha.com> xoff writes: > I was wondering what the best method was in Python programming for 2 > discontinued ranges. e.g. I want to use the range 3 to 7 and 17 to 23. you could use itertools.chain: from itertools import chain for i in chain(range(3,7), range(17,23)): ... I'm assuming you're using python 3. In python 2 each of those ranges expands immediately to a list, so on the one hand they're consuming potentially lots of storage (you should use xrange instead). On the other hand you could just concatenate the lists with +, but I wouldn't advise that. From eraserix at gmail.com Wed Nov 10 12:19:13 2010 From: eraserix at gmail.com (eraserix) Date: Wed, 10 Nov 2010 09:19:13 -0800 (PST) Subject: subprocess.Popen deadlocks Message-ID: <2cf9a225-7d1c-4490-8a62-807e79bdd06a@n30g2000vbb.googlegroups.com> Hi >From time to time I observe a deadlock in subprocess.Popen. I see the childprocess beeing and if I attach gdb to the stuck python script, I can see it waiting on line 1128 in subprocess.py ( data = _eintr_retry_call(os.read, errpipe_read, 1048576) ). Any ideas of whats going on? I'm on linux using python 2.6.5. I already found http://bugs.python.org/issue1731717 and stubbed out subprocess._cleanup, but this didn't really help and doesn't seem to be the problem anyway... A bit of information about what I'm trying to do: I try to control several process from a python script. Each process is started from a thread, the threads just wait() for the child to exit and can then be joined. Main waits for SIGINT. After it received the signal, it will send a signal to the processes spawned by the threads and then join() the threads (which should terminate after their process exits) Christoph From igor.idziejczak at gmail.com Wed Nov 10 12:23:06 2010 From: igor.idziejczak at gmail.com (xoff) Date: Wed, 10 Nov 2010 09:23:06 -0800 (PST) Subject: multiple discontinued ranges References: <87y691w198.fsf@rudin.co.uk> Message-ID: <45992bf6-7a5b-4612-9c57-7618a8d33307@t35g2000yqj.googlegroups.com> On 10 nov, 18:13, Paul Rudin wrote: > xoff writes: > > I was wondering what the best method was in Python programming for 2 > > discontinued ranges. e.g. I want to use the range 3 to 7 and 17 to 23. > > Am I obliged to use 2 for loops defining the 2 ranges like this: > > > for i in range (3,7): > > ?do bla > > for i in range (7,17): > > ?do bla > > > or is there a more clever way to do this? > > for i in itertools.chain(xrange(3,7), xrange(17,23)): > ? ? print i Thank you, that was exactly what I needed! From manu3d at gmail.com Wed Nov 10 12:25:45 2010 From: manu3d at gmail.com (Emanuele D'Arrigo) Date: Wed, 10 Nov 2010 09:25:45 -0800 (PST) Subject: A matter of queues, tasks and multiprocessing Message-ID: Greetings everybody, I've tried to come up with this message for a couple of weeks now and it doesn't look like I'm getting any clearer in my thoughts so I decided that it's probably best to take the plunge and ask you guys to kindly throw me a rope... What I'm trying to come up with is some kind of simple, dynamically scalable, domain-agnostic, multi-processor capable, tasking system. Maybe I'm already giving myself too many constraints here, i.e. it might all be possible except... the "simple" part. Clearly a good (the?) starting point is to think in terms of tasks, queues and worker threads. Once synchronization issues are properly attended this methodology feels, at least in theory, neat and intuitive. The problem is of course to put in practice. For example in my context I can think of tasks with very heterogeneous computing requirements, i.e. quick tasks such as UI interactions, slow tasks such as I/O with large files, and pretty much everything in- between. In this context, and given that I cannot know a priory a task's execution time, how can I create a system that is responsive on things like UI, takes its time on things such as I/O but gives the application the opportunity to further customize things? I.e. a user might want to limit the number of processors/core used to a subset of those available. Alternatively an application might want to create more threads than the optimal number simply because interleaving the executions of a few tasks is preferable to simply queuing them. And all this might have to happen at runtime. Currently on one end of the spectrum I'm considering a purely functional approach, with one queue for UI-related tasks, one for I/O- related tasks and one for everything else. On a single processor/core machine they'd simply be serviced by one thread each, all sharing one processor. On a two processors/cores machine UI and I/O queues might be serviced by two separate threads on the same processor while everything else is serviced by a worker thread on the other processor. As the number of cores/processors increases more threads/processor would be attached to each queue, but how to establish what should get more resources first? Alternatively I've read about queues with threads that "steal" from other queues. But that seems to assumes more or less homogeneous task execution or applications where responsiveness might drop to zero, i.e. because slow I/O tasks are being attended by all available threads/processors. In these cases, should the UI-related thread/queue never ever steal from the other queues, to maintain responsiveness at all times, effectively creating an hybrid approach with one purely functional thread/queue and (potentially) many other self-balancing threads/queues? Thoughts, hints, tips, tricks, directions, reading material of any kind will all be appreciated! =) Sincerely, Manu From igor.idziejczak at gmail.com Wed Nov 10 12:34:14 2010 From: igor.idziejczak at gmail.com (xoff) Date: Wed, 10 Nov 2010 09:34:14 -0800 (PST) Subject: multiple discontinued ranges References: <7xy691w151.fsf@ruckus.brouhaha.com> Message-ID: <3250c9df-deeb-4610-93f2-93ba4b1568e4@p1g2000yqm.googlegroups.com> On 10 nov, 18:15, Paul Rubin wrote: > you could use itertools.chain: > > ? from itertools import chain > > ? for i in chain(range(3,7), range(17,23)): > ? ? ... > > I'm assuming you're using python 3. ?In python 2 each of those ranges > expands immediately to a list, so on the one hand they're consuming > potentially lots of storage (you should use xrange instead). ?On the > other hand you could just concatenate the lists with +, but I wouldn't > advise that. I am curious, why wouldn't you advise something like this: for i in chain(range(3,7) + range(17,23)): Thanks again! From simon at mullis.co.uk Wed Nov 10 12:56:42 2010 From: simon at mullis.co.uk (Simon Mullis) Date: Wed, 10 Nov 2010 18:56:42 +0100 Subject: Is Eval *always* Evil? Message-ID: Hi All, I'm writing a Django App to webify a Python script I wrote that parses some big XML docs and summarizes certain data contained within. This app will be used by a closed group of people, all with their own login credentials to the system (backed off to the corp SSO system). I've already got Django, Celery and Rabbitmq working to handle uploads and passing the "offline" parsing / processing task to the backend. One way to do the XML processing is to use a number of XPath queries and a key point is the required output (and therefore the list of queries) is not yet complete (and will always be a little "fluid"). Ultimately, I don't want to be stuck with maintaining this list of XPath queries and want to allow my colleagues to add / change / remove them as they see fit. I didn't know my "xpath from my elbow" when I first started looking into this so I think they'll be able to learn it pretty easily. The only easy way to accomplish this I can think of is create a new table with { "name" : "xpath command" } key, value pairs and allow it to be edited via the browser (using Django's Admin scaffolding) . I plan on making sure that when amending the list of XPath queries, each entry is tested against a known good XML file so the user can see sample results before they're allowed to save it to the database. I'm aware that this will probably slow things down, as there'll be lots of serial XPath queries, but even if the job takes 5 minutes longer then it will still save man-days of manual work. I can live with this as long as it's flexible. # In the meantime - and as a proof of concept - I'm using a dict instead. xpathlib = { "houses" : r'[ y.tag for y in x.xpath("//houses/*") ]', "names" : r'[ y.text for y in x.xpath("//houses/name") ]', "footwear_type" : r'[ y.tag for y in x.xpath("//cupboard/bottom_shelf/*") ]', "shoes" : r'[ y.text for y in x.xpath("//cupboard/bottom_shelf/shoes/*") ]', "interface_types" : r'[ y.text[:2] for y in x.xpath("//interface/name") ]', } # (I left a real one at the bottom so you can see I might want to do some string manipulation on the results within the list comprehension). # Then in my backend task processing scripts I would have something like: def apply_xpath(xpath_command, xml_frag): x = xml_frag if re.findall(r'\[\sy\.\w+(?:\[.+\])?\s+for y in x\.xpath\("/{1,2}[\w+|\/|\*]+"\)\s\]', xml_frag): result = eval(xpath_command, {"__builtins__":[]},{"x": x}) if type(result).__name__ == "list": return result Yes, the regex is pretty unfriendly, but it works for all of the cases above and fails for other non-valid examples I've tried. # Let's try it in ipython: from lxml import etree f = open('/tmp/sample.xml') xml_frag = etree.fromstring(f.read()) print apply_xpath(xpathlib["footwear_type"], xml_frag) ['ballet shoes', 'loafers', 'ballet shoes', 'hiking boots', 'training shoes', 'hiking boots', 'socks'] Is this approach ok? I've been reading about this and know about the following example that bypass the __builtins__ restriction on eval (edited so it won't work). __import__('shutill').rmtreee('/') <===DO NOT TRY AND RUN THIS As the potential audience for this Web App is both known and controlled, am I being too cautious? If "eval" is not the way forward, are there any suggestions for another way to do this? Thanks From mwilson at the-wire.com Wed Nov 10 13:02:48 2010 From: mwilson at the-wire.com (Mel) Date: Wed, 10 Nov 2010 13:02:48 -0500 Subject: multiple discontinued ranges References: Message-ID: xoff wrote: > I was wondering what the best method was in Python programming for 2 > discontinued ranges. e.g. I want to use the range 3 to 7 and 17 to 23. > Am I obliged to use 2 for loops defining the 2 ranges like this: > > for i in range (3,7): > do bla > for i in range (7,17): > do bla > > or is there a more clever way to do this? One horribly clever way is to concoct a 9-th order polynomial to return 3,4,5,6,17,18,19,20,21,22 for input values 0,1,2,3,4,5,6,7,8,9. The reasonable way is to use two loops as you've done. If the pattern of discontinuous ranges is really important in your application, you'd perhaps want to package it up (not tested): def important_range (): for x in xrange (3, 7): yield x for x in xrange (17,23): yield x to be used elsewhere as for v in important_range(): # use v ... Mel. From __peter__ at web.de Wed Nov 10 13:19:03 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 10 Nov 2010 19:19:03 +0100 Subject: multiple discontinued ranges References: Message-ID: xoff wrote: > I was wondering what the best method was in Python programming for 2 > discontinued ranges. e.g. I want to use the range 3 to 7 and 17 to 23. > Am I obliged to use 2 for loops defining the 2 ranges like this: > > for i in range (3,7): > do bla > for i in range (7,17): > do bla > > or is there a more clever way to do this? >>> for r in xrange(3, 7), xrange(17, 23): ... for i in r: ... print i, ... 3 4 5 6 17 18 19 20 21 22 From data.2 at rediff.com Wed Nov 10 14:39:36 2010 From: data.2 at rediff.com (gaurav) Date: Wed, 10 Nov 2010 11:39:36 -0800 (PST) Subject: Big opportunity. Message-ID: <2c749249-3d9a-4c61-8cb1-eca2c0b074a3@j12g2000prm.googlegroups.com> Complete resource for free or paid Work at home jobs online/offline. http://rojgars1.webs.com/gov.htm http://rojgars.webs.com/bankingjobs.htm Get start earning at your Management work. Great career in Management Visit: http://managementjobs.webs.com/pm.htm & http://topcareer.webs.com/humanresourcemgmt.htm From nobody at nowhere.com Wed Nov 10 15:04:15 2010 From: nobody at nowhere.com (Nobody) Date: Wed, 10 Nov 2010 20:04:15 +0000 Subject: multiple discontinued ranges References: <7xy691w151.fsf@ruckus.brouhaha.com> <3250c9df-deeb-4610-93f2-93ba4b1568e4@p1g2000yqm.googlegroups.com> Message-ID: On Wed, 10 Nov 2010 09:34:14 -0800, xoff wrote: > I am curious, why wouldn't you advise something like this: > for i in chain(range(3,7) + range(17,23)): Because it constructs all three lists (both of the individual ranges and their concatenation) in memory. For a trivial example, that isn't a problem; for a real application, it could be. From moura.mario at gmail.com Wed Nov 10 15:14:22 2010 From: moura.mario at gmail.com (macm) Date: Wed, 10 Nov 2010 12:14:22 -0800 (PST) Subject: Learning Pyhton - Functional Programming - How intersect/difference two dict with dict/values? fast! References: <4d71519e-a232-427f-b4e0-5bae90fc4acb@n32g2000prc.googlegroups.com> <4cd9b16d$0$1640$742ec2ed@news.sonic.net> <87tyjpy0a3.fsf@rudin.co.uk> Message-ID: <7158677e-8b26-40ec-83a4-c46143e3ec3d@q18g2000vbm.googlegroups.com> Hi Folks I am studing yet (with fever, grasp and headache). I know I can do better, but first I should learn more about "dictionary comprehension syntax" in python 2.65 >>> dict1 = {'ab':[[1,2,3,'d3','d4',5],12],'ac':[[1,3,'78a','79b'],54],'ad': [[56,57,58,59],34], 'ax': [[56,57,58,59],34]} >>> dict2 = {'ab':[[22,2,'a0','42s','c4','d3'],12],'ab':[[2,4,50,42,'c4'],12],'ac':[[1,3,'79b',45,65,'er4'],54],'ae': [[56,57,58,59],34],'ax':[[9],34]} >>> >>> # Arnaud Delobelle ... def intersectList(iterables): ... nexts = [iter(iterable).next for iterable in iterables] ... v = [next() for next in nexts] ... while True: ... for i in xrange(1, len(v)): ... while v[0] > v[i]: ... v[i] = nexts[i]() ... if v[0] < v[i]: break ... else: ... yield v[0] ... v[0] = nexts[0]() ... >>> def intersect(s1, s2): ... d = {} ... e = {} ... r1 = filter(s1.has_key, s2.keys()) ... for x in r1: ... d[x] = list(intersectList([s1[x][0],s2[x][0]])) ... if len(d[x]) > 0: ... e[x] = d[x] ... return e ... >>> intersect(dict1,dict2) {'ac': [1, 3, '79b'], 'ab': [2]} >>> Best Regards Mario On 10 nov, 07:51, Paul Rudin wrote: > Lawrence D'Oliveiro writes: > > In message , Terry Reedy > > wrote: > > >> To echo John Nagle's point, if you want non-masochist volunteers to read > >> your code, write something readable like: > > >> dict1 = {'ab': [[1,2,3,'d3','d4',5], 12], > >> ? ? ? ? ? 'ac': [[1,3,'78a','79b'], 54], > >> ? ? ? ? ? 'ad': [[56,57,58,59], 34], > >> ? ? ? ? ? 'ax': [[56,57,58,59], 34]} > > > How come Python itself doesn?t display things that way? > > try: pprint.pprint(dict1) From danmcleran at yahoo.com Wed Nov 10 15:19:28 2010 From: danmcleran at yahoo.com (danmcleran at yahoo.com) Date: Wed, 10 Nov 2010 12:19:28 -0800 (PST) Subject: A matter of queues, tasks and multiprocessing References: Message-ID: <9e6f2dcc-7d15-4162-b3e9-9ef77a0b8980@n30g2000vbb.googlegroups.com> If you are using Python 2.6 or greater, look into the multiprocessing module. It may contain 90% of what you need. From clp2 at rebertia.com Wed Nov 10 15:26:20 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 10 Nov 2010 12:26:20 -0800 Subject: Feed subscription IM bot In-Reply-To: <74b044f0-0188-4adf-af86-635cca338846@o15g2000prh.googlegroups.com> References: <74b044f0-0188-4adf-af86-635cca338846@o15g2000prh.googlegroups.com> Message-ID: On Wed, Nov 10, 2010 at 6:49 AM, alexander wrote: > Hi, > > ? Can anyone help on this? http://stackoverflow.com/questions/1901828/best-python-xmpp-jabber-client-library http://www.djangoproject.com/ Come back when you have a much less nebulous question. And try googling first next time. Regards, Chris > ********************************************************************************************************************/ > > > ?The project should either be hosted online and usable from there, or > can be run locally. Complete ource code should be delivered along with > a brief readme for features. It should take about about 1-2 hours to > complete. > ?Basic requirements: Build a Python driven IM bot with the following > features > ?* A user can add the bot to his/her Google talk/jabber friends list. > ?* The user types the words "sub [feed_url]" to the bot to begin > subscribing to the feed at the specified feed_url ([feed_url] is the > placeholder for the actual feed url. e.g. http://myweb.com/feed) > * The user types the words "unsub [feed_url]" to stop subscribing to > the feed > * The bot scans the feed at a specified time interval, and sends new > contents to the subscribing user > Additional credits: > * Additional bot commands: "ls", "pause [feed_url]", " > resume[feed_url]", "grep [feed_url] [keywords]", whatever you think is > useful and fun, even not feed subscription related > * A web interface for reading/managing subscriptions > * Beautiful, extensible and scalable architecture > ?Requirements: > ?* Python 2.5 > ?* Robust and graceful error handling > ?* Robust unicode handling > > / > ************************************************************************************************************/ > > Thanks From robert.kern at gmail.com Wed Nov 10 15:27:50 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 10 Nov 2010 14:27:50 -0600 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: On 11/10/10 3:50 AM, Lawrence D'Oliveiro wrote: > In message, Jon > Dufresne wrote: > >> On Mon, Nov 8, 2010 at 11:35 PM, Lawrence D'Oliveiro ... > > I see that you published my unobfuscated e-mail address on USENET for all to > see. I obfuscated it for a reason, to keep the spammers away. I'm assuming > this was a momentary lapse of judgement, for which I expect an apology. > Otherwise, it becomes grounds for an abuse complaint to your ISP. I don't see any obfuscated email address at all in your own posts. I only see your full, unobfuscated e-mail address that you list on your web page. You are leaking the information, not Jon. -- 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 emile at fenx.com Wed Nov 10 15:33:02 2010 From: emile at fenx.com (Emile van Sebille) Date: Wed, 10 Nov 2010 12:33:02 -0800 Subject: How to read the Python tutorial? In-Reply-To: References: <59c26dd2-529f-4a4a-8f48-1ee5f35b068f@t7g2000vbj.googlegroups.com> <6b2d39f4-c9d9-4e77-9bb7-60e26dc334ee@j9g2000vbl.googlegroups.com> Message-ID: On 11/10/2010 8:19 AM rantingrick said... > I would start at the loop and figure out what is going on from there > with some print statements and the functions i showed you. Debugging > is a large part of any programming project. We all do it everyday. So > the sooner you learn the better. If you have a specific question feel > free to ask, but general debug issues are better solved yourself. > > A few more indispensable functions are dir() and help() All good info -- I'd add that you should learn and become comfortable with: import pdb; pdb.set_trace() to test running code. Emile From emile at fenx.com Wed Nov 10 15:35:51 2010 From: emile at fenx.com (Emile van Sebille) Date: Wed, 10 Nov 2010 12:35:51 -0800 Subject: multiple discontinued ranges In-Reply-To: <3250c9df-deeb-4610-93f2-93ba4b1568e4@p1g2000yqm.googlegroups.com> References: <7xy691w151.fsf@ruckus.brouhaha.com> <3250c9df-deeb-4610-93f2-93ba4b1568e4@p1g2000yqm.googlegroups.com> Message-ID: On 11/10/2010 9:34 AM xoff said... > On 10 nov, 18:15, Paul Rubin wrote: >> potentially lots of storage (you should use xrange instead). On the >> other hand you could just concatenate the lists with +, but I wouldn't >> advise that. > > I am curious, why wouldn't you advise something like this: > for i in chain(range(3,7) + range(17,23)): I'd assume because concatenation is generally considered expensive. If you were to do it, you'd likely drop the chain and write: for i in range(3,7) + range(17,23): Emile From ian.g.kelly at gmail.com Wed Nov 10 15:38:49 2010 From: ian.g.kelly at gmail.com (Ian) Date: Wed, 10 Nov 2010 12:38:49 -0800 (PST) Subject: DTD Parsing References: <4e7a49ec-1816-46e5-bc51-9f7c88f4d025@37g2000prx.googlegroups.com> <06071410-4684-4169-b1f8-0783e34f9062@f16g2000prj.googlegroups.com> Message-ID: On Nov 10, 1:05?am, r0g wrote: > > That's five whole lines of code. Why go to all that trouble when you can > > just do this: > > > import config > > Heh, mainly because I figure the config module will have a lot more > options than I have use for right now and therefore the docs will take > me longer to read than I will save by not just typing in the above ;) I think you misunderstand me. There is no config module and there are no docs to read. It's just the configuration file itself written as a Python script, containing arbitrary settings like: SESSION_TIMEOUT = 900 or: DOMAIN_OBJECTS = [ ObjectType1( option1 = 'foo', option2 = 'bar', ), ObjectType2( option1 = 'foo', option2 = 'baz', option3 = 42, ), ... ] Cheers, Ian From emile at fenx.com Wed Nov 10 15:40:07 2010 From: emile at fenx.com (Emile van Sebille) Date: Wed, 10 Nov 2010 12:40:07 -0800 Subject: Feed subscription IM bot In-Reply-To: <74b044f0-0188-4adf-af86-635cca338846@o15g2000prh.googlegroups.com> References: <74b044f0-0188-4adf-af86-635cca338846@o15g2000prh.googlegroups.com> Message-ID: On 11/10/2010 6:49 AM alexander said... > Hi, > > Can anyone help on this? > > / Probably most of us, but as it's obviously homework, and expected to take you 1-2 hours for the level class you're taking, and that it's now six hours later, why not post where you're at and we can help you wrap things up? Emile From moura.mario at gmail.com Wed Nov 10 15:42:53 2010 From: moura.mario at gmail.com (macm) Date: Wed, 10 Nov 2010 12:42:53 -0800 (PST) Subject: Learning Pyhton - Functional Programming - How intersect/difference two dict with dict/values? fast! References: <4d71519e-a232-427f-b4e0-5bae90fc4acb@n32g2000prc.googlegroups.com> <4cd9b16d$0$1640$742ec2ed@news.sonic.net> <87tyjpy0a3.fsf@rudin.co.uk> <7158677e-8b26-40ec-83a4-c46143e3ec3d@q18g2000vbm.googlegroups.com> Message-ID: <7e450af4-f5c0-406a-af6c-1e1caa224cef@o2g2000vbh.googlegroups.com> ... and this works! >>> def intersect(s1, s2): ... d = {} ... e = {} ... r1 = filter(s1.has_key, s2.keys()) ... for x in r1: ... d[x]= filter(lambda z:z in s1[x][0],s2[x][0]) ... if len(d[x]) > 0: ... e[x] = d[x] ... return e ... >>> intersect(dict1,dict2) {'ac': [1, 3, '79b'], 'ab': [2]} >>> but how I pass d[x] and make the filter? >>> result = [filter(lambda z:z in dict1[x][0],dict2[x][0]) for x in filter(dict1.has_key, dict2.keys())] >>> result [[], [1, 3, '79b'], [2]] >>> but should be {'ac': [1, 3, '79b'], 'ab': [2]} Best Regards Mario On 10 nov, 18:14, macm wrote: > Hi Folks > > I am studing yet (with fever, grasp and headache). > > I know I can do better, but first I should learn more about > "dictionary comprehension syntax" in python 2.65 > > >>> dict1 = {'ab':[[1,2,3,'d3','d4',5],12],'ac':[[1,3,'78a','79b'],54],'ad': [[56,57,58,59],34], 'ax': [[56,57,58,59],34]} > >>> dict2 = {'ab':[[22,2,'a0','42s','c4','d3'],12],'ab':[[2,4,50,42,'c4'],12],'ac':[[1,3,'79b',45,65,'er4'],54],'ae': [[56,57,58,59],34],'ax':[[9],34]} > > >>> # Arnaud Delobelle > > ... def intersectList(iterables): > ... ? ? nexts = [iter(iterable).next for iterable in iterables] > ... ? ? v = [next() for next in nexts] > ... ? ? while True: > ... ? ? ? ? for i in xrange(1, len(v)): > ... ? ? ? ? ? ? while v[0] > v[i]: > ... ? ? ? ? ? ? ? ? v[i] = nexts[i]() > ... ? ? ? ? ? ? if v[0] < v[i]: break > ... ? ? ? ? else: > ... ? ? ? ? ? ? yield v[0] > ... ? ? ? ? v[0] = nexts[0]() > ...>>> defintersect(s1, s2): > > ... ? ? d = {} > ... ? ? e = {} > ... ? ? r1 = filter(s1.has_key, s2.keys()) > ... ? ? for x in r1: > ... ? ? ? ? d[x] = list(intersectList([s1[x][0],s2[x][0]])) > ... ? ? ? ? if len(d[x]) > 0: > ... ? ? ? ? ? ? e[x] = d[x] > ... ? ? return e > ...>>>intersect(dict1,dict2) > > {'ac': [1, 3, '79b'], 'ab': [2]} > > > > Best Regards > > Mario > > On 10 nov, 07:51, Paul Rudin wrote: > > > Lawrence D'Oliveiro writes: > > > In message , Terry Reedy > > > wrote: > > > >> To echo John Nagle's point, if you want non-masochist volunteers to read > > >> your code, write something readable like: > > > >> dict1 = {'ab': [[1,2,3,'d3','d4',5], 12], > > >> ? ? ? ? ? 'ac': [[1,3,'78a','79b'], 54], > > >> ? ? ? ? ? 'ad': [[56,57,58,59], 34], > > >> ? ? ? ? ? 'ax': [[56,57,58,59], 34]} > > > > How come Python itself doesn?t display things that way? > > > try: pprint.pprint(dict1) > > From duane.kaufman at gmail.com Wed Nov 10 15:44:38 2010 From: duane.kaufman at gmail.com (TheSeeker) Date: Wed, 10 Nov 2010 12:44:38 -0800 (PST) Subject: Deditor 0.2.2 References: <6cdb5dd1-1868-4a6e-8b59-5b871f8d412e@42g2000prt.googlegroups.com> <613e4abc-329b-4ab3-8349-b3ec047cb747@r14g2000yqa.googlegroups.com> <470b7ee0-b109-4bb6-afa0-391baf02033e@35g2000prt.googlegroups.com> <84d92b8c-4592-4883-a8c4-929d93ff1138@j2g2000yqf.googlegroups.com> Message-ID: <10b9ba99-b27b-4366-a031-8731e5c095be@k11g2000vbf.googlegroups.com> On Nov 10, 7:51?am, Kruptein wrote: > On Nov 10, 12:49?pm, TheSeeker wrote: > > > > > > > > > > > On Nov 9, 10:04?am, Kruptein wrote: > > > > On Nov 8, 3:01?pm, Jean-Michel Pichavant > > > wrote: > > > > > TheSeeker wrote: > > > > > On Nov 6, 7:06 am, Kruptein wrote: > > > > > >> Hey, > > > > > >> I released version 0.2.2 of my pythonic text-editor ?Deditor. > > > > >> It adds the use of projects, a project is a set of files which you can > > > > >> open all at once to make development much faster and easier. > > > > > >> For more information visit launchpad:http://launchpad.net/deditor > > > > > >> I also uploaded a video to introduce you to deditor:http://www.youtube.com/watch?v=hS8xBu-39VI > > > > >> (note: youtube is still processing the file so you might have to wait > > > > >> a bit to see it) > > > > > > Hi, > > > > > I might have missed this, but it seems deditor requires Python above > > > > > 2.5? > > > > > > It would be nice to mention the requirements on the home page > > > > > somewhere. > > > > > > Thanks, > > > > > Duane > > > > > I already point that on the last release. You should really just > > > > consider writing the requirements (python & wx). > > > > > JM > > > > I'm going todo that right now! I alswyas forget it :p > > > Hi, > > > In addition, on Debian Lenny, with Python 2.5: > > > deditor.py:429: Warning: 'with' will become a reserved keyword in > > Python 2.6 > > Traceback (most recent call last): > > ? File "", line 1, in > > ? File "deditor.py", line 429 > > ? ? with open(cf,"wb") as configf: > > ? ? ? ? ? ? ^ > > SyntaxError: invalid syntax > > > So I don't think Python 2.5 works . > > > Thanks, > > Duane > > that's possible, I was only able to test it with version 2.7, I'm > going to change the dependencies then. thanks to point that out, 2.6 > should work though? > > and the windows wxpython version and the linux version are different > which causes some stupid bugs... :s Hi, Unfortunately, the wxPython bug precludes me seeing if Python 2.6 works (in Windows, at least). Maybe someone else can answer whether Python 2.6 works. Duane From python at mrabarnett.plus.com Wed Nov 10 15:50:00 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 10 Nov 2010 20:50:00 +0000 Subject: How to read the Python tutorial? In-Reply-To: <59c26dd2-529f-4a4a-8f48-1ee5f35b068f@t7g2000vbj.googlegroups.com> References: <59c26dd2-529f-4a4a-8f48-1ee5f35b068f@t7g2000vbj.googlegroups.com> Message-ID: <4CDB0578.1070700@mrabarnett.plus.com> On 10/11/2010 15:13, Zeynel wrote: > For instance, when the tutorial has http://docs.python.org/release/2.6/library/datetime.html > > class datetime.datetime > A combination of a date and a time. Attributes: year, month, day, > hour, minute, second, microsecond, and tzinfo. > > What does this mean? How do I use it? > > For instance, I have a DateTimeProperty mDate that I get from a query > in Google App Engine. This mDate has value > > mDATE = 2010-11-10 14:35:22.863000 > > But when I try > > datetime.datetime.mDATE.toordinal()) > > I get AttributeError. > > If I try something like > > td = mDATE.seconds > > in GAE development server I get > > AttributeError: 'datetime.datetime' object has no attribute 'seconds' > > What am I doing wrong? And how to understand this stuff so that I can > start using the language instead of trying to figure out types. Thanks > for your help. > If you lookup 'datetime' in Python's documentation you'll find that the attribute is called 'second'. From python at mrabarnett.plus.com Wed Nov 10 15:51:21 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 10 Nov 2010 20:51:21 +0000 Subject: multiple discontinued ranges In-Reply-To: <3250c9df-deeb-4610-93f2-93ba4b1568e4@p1g2000yqm.googlegroups.com> References: <7xy691w151.fsf@ruckus.brouhaha.com> <3250c9df-deeb-4610-93f2-93ba4b1568e4@p1g2000yqm.googlegroups.com> Message-ID: <4CDB05C9.6020400@mrabarnett.plus.com> On 10/11/2010 17:34, xoff wrote: > On 10 nov, 18:15, Paul Rubin wrote: >> you could use itertools.chain: >> >> from itertools import chain >> >> for i in chain(range(3,7), range(17,23)): >> ... >> >> I'm assuming you're using python 3. In python 2 each of those ranges >> expands immediately to a list, so on the one hand they're consuming >> potentially lots of storage (you should use xrange instead). On the >> other hand you could just concatenate the lists with +, but I wouldn't >> advise that. > > I am curious, why wouldn't you advise something like this: > for i in chain(range(3,7) + range(17,23)): > In Python 3 'range' is a generator, like 'xrange' in Python 2. From tjreedy at udel.edu Wed Nov 10 15:55:32 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 10 Nov 2010 15:55:32 -0500 Subject: How to read the Python tutorial? In-Reply-To: <59c26dd2-529f-4a4a-8f48-1ee5f35b068f@t7g2000vbj.googlegroups.com> References: <59c26dd2-529f-4a4a-8f48-1ee5f35b068f@t7g2000vbj.googlegroups.com> Message-ID: On 11/10/2010 10:13 AM, Zeynel wrote: > For instance, when the tutorial has http://docs.python.org/release/2.6/library/datetime.html > > class datetime.datetime > A combination of a date and a time. Attributes: year, month, day, > hour, minute, second, microsecond, and tzinfo. Note 'second' singular, as with other attributes. > td = mDATE.seconds You added a 's' to 'second', so > in GAE development server I get > AttributeError: 'datetime.datetime' object has no attribute 'seconds' -- Terry Jan Reedy From ethan at stoneleaf.us Wed Nov 10 15:57:24 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 10 Nov 2010 12:57:24 -0800 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: <4CDB0734.1050503@stoneleaf.us> Lawrence D'Oliveiro wrote: > In message , Jon > Dufresne wrote: > >> On Mon, Nov 8, 2010 at 11:35 PM, Lawrence D'Oliveiro ... > > I see that you published my unobfuscated e-mail address on USENET for all to > see. I obfuscated it for a reason, to keep the spammers away. I'm assuming > this was a momentary lapse of judgement, for which I expect an apology. > Otherwise, it becomes grounds for an abuse complaint to your ISP. Dumb question: Where did you obfuscate it? All I see is (apparently) the real one. Hoping-to-learn-something'ly yours, ~Ethan~ From clp2 at rebertia.com Wed Nov 10 16:04:44 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 10 Nov 2010 13:04:44 -0800 Subject: Curses Programming In-Reply-To: References: Message-ID: On Wed, Nov 10, 2010 at 6:42 AM, alexander wrote: > Subject: Curses Programming This has nothing whatsoever to do with the (n)curses library or even console programming. Lying in your subject line does not help gain you goodwill. > Hi, all > > ? ? Here is the test. Plz help..... If you want homework help, show that you've at least made /some/ sort of attempt, and ask a *specific* question regarding what part is giving you trouble. Otherwise, you're liable to be ignored with prejudice. Usage of expressions like "Plz" doesn't help your case either. Regards, Chris From emile at fenx.com Wed Nov 10 16:19:39 2010 From: emile at fenx.com (Emile van Sebille) Date: Wed, 10 Nov 2010 13:19:39 -0800 Subject: Enumeration of strings and export of the constants In-Reply-To: <4CDA9A4E.1050106@mm-sol.com> References: <4CDA9A4E.1050106@mm-sol.com> Message-ID: On 11/10/2010 5:12 AM lnenov said... > Hi, > > I need to enumerate a couple hundred strings to constants and export > them to another module(s) globals. Do they really need to be globals? Why not a constants in an object/container that would neither pollute the global namespace nor risk being shadowed by subsequent inadvertent name conflict? > In the mean time I want to keep my module's namespace as clear as I can > and I don't want to use "import *" later. > > Here is the code I intend to use: > > test.py > 1 class Apinamespace(): > 2 @staticmethod > 3 def import_to(destination): > 4 > 5 for name, number in Apinamespace.__dict__.items(): > 6 if (name.startswith('__') and name.endswith('__')) or name == > "import_to": # :) > 7 pass > 8 else: > 9 setattr(destination, name, number) > 10 > 11 class Enumerate(): > 12 def __init__(self, names, start = 0, step = 1): > 13 enumerate_to = Apinamespace > 14 > 15 for number, name in self.enumerate(names, start, step): > 16 setattr(enumerate_to, name, number) > 17 > 18 def enumerate(self, names, start = 0, step = 1): > 19 for index in range(len(names)): > 20 yield (start, names[index]) > 21 start += step > 22 > 23 example_names = ['Foo','Bar','Free', 'Beer'] > 24 example_names2 = ['Foo_me_too', 'Bar_me_too', 'Free_me_too', > 'Beer_me_too'] > 25 Enumerate(example_names) > 26 Enumerate(example_names2, 4, 2) > > This works like a charm: > >>> import sys, test > >>> thismodule = sys.modules[__name__] > >>> test.Apinamespace.import_to(thismodule) > >>> Beer > 3 > >>> Beer_me_too > 10 > > Is there a better and more common way to do this? Yes -- don't. It'd generally indicate what's been called 'a bad smell' Emile > Do you know of a way to see the module in/from which a function was > called without using traceback and frames? (I want to remove the > argument from Apinamespace.import_me) > And can line 6 be replaced by something less evil. > > Thanks for any suggestions. > > Lyudmil > > > From hpj at urpla.net Wed Nov 10 16:20:07 2010 From: hpj at urpla.net (Hans-Peter Jansen) Date: Wed, 10 Nov 2010 22:20:07 +0100 Subject: ANN: PyQt v4.8.1 Released In-Reply-To: References: Message-ID: <201011102220.08040.hpj@urpla.net> Am Monday 08 November 2010 02:26:51 schrieb Robert Kern: > On 2010-11-07 18:53 , Lawrence D'Oliveiro wrote: > > In message, Robert > > Kern > > > > wrote: > >> Everyone here knew exactly what he meant. > > > > But if you don?t banana the right tomato, everybody could be grapefruit, > > right? > > > > You know what I mean. > > And as I reiterated in the part that you snipped, he is not using > "commercial" as a synonym for "proprietary". It is the license that he > sells commercially. ..with a pretty affordable price, I may add. I don't understand all the fuzz about some obvious formulation. It it a concern only for those who want to _sell_ their _products_ based on PyQt and consequently don't want to reveal their source code. Pete (Not being afflicted in any way with Riverbankcomputing, other than being a satisfied commercial licencee). From usenet-nospam at seebs.net Wed Nov 10 16:21:06 2010 From: usenet-nospam at seebs.net (Seebs) Date: 10 Nov 2010 21:21:06 GMT Subject: Silly newbie question - Caret character (^) References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> Message-ID: On 2010-11-10, Terry Reedy wrote: > I was referring to Schildt using gets() all the time and thereby > teaching new C generations to do he same. Ahh, yes. I am told that the current plan is to kill it in C1X. I would shed no tears. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From no.email at nospam.invalid Wed Nov 10 16:24:32 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 10 Nov 2010 13:24:32 -0800 Subject: multiple discontinued ranges References: <7xy691w151.fsf@ruckus.brouhaha.com> <3250c9df-deeb-4610-93f2-93ba4b1568e4@p1g2000yqm.googlegroups.com> Message-ID: <7xbp5wx46n.fsf@ruckus.brouhaha.com> xoff writes: > I am curious, why wouldn't you advise something like this: > for i in chain(range(3,7) + range(17,23)): First of all, the outer chain does nothing. Second, concatenating the two lists creates a new list, consuming storage and taking time copying all the elements. Third, if there are n lists instead of two, I think the copying time is O(n**2) in the number of lists because there are n-1 separate copy operations and they keep getting larger. From oly at digitaloctave.com Wed Nov 10 16:38:32 2010 From: oly at digitaloctave.com (Oliver Marks) Date: Wed, 10 Nov 2010 21:38:32 +0000 Subject: Embedded python issue with gtk Message-ID: <1289425112.18057.6.camel@leela> I have already emailed about this issue, but have still not got any where. I have reduced the plugin down to its bare minimum it simple loads the the python interpreter and imports gtk library. If i do this outside the embedded python it imports and i can use the gtk library, so why does it not work when embedded i am on ubuntu 10.10 64bit if its a specific issue on this platform. the code is below or you can get the code with the build system from the link below, obviously to see the error you need to load the plugin into geany. I am guessing this is a linking issue just hoping someone can point me in the right direction. http://ubuntuone.com/p/OhA/ #include /* For Python itself. This MUST come first. */ #include "geany.h" /* for the GeanyApp data type */ #include "geanyplugin.h" /* for the GeanyApp data type */ #include "plugindata.h" /* this defines the plugin API */ #define PLUGIN_NAME _("Geany Python Test") PLUGIN_VERSION_CHECK(GEANY_API_VERSION) /* All plugins must set name, description, version and author. */ PLUGIN_SET_INFO(PLUGIN_NAME, _("Test Python plugin."), _(VERSION), _("Test Author")) /* initialise the plugin */ void plugin_init(GeanyData *data){ printf("Loading the test Python module.\n"); Py_Initialize(); /* Start the Python interpreter. */ PyRun_SimpleString("import gtk"); } /* Cleanup the plugin when required */ void plugin_cleanup(void){ Py_Finalize(); } This is the error i get on loading of the plugin. Traceback (most recent call last): File "", line 1, in File "/usr/lib/pymodules/python2.6/gtk-2.0/gtk/__init__.py", line 30, in import gobject as _gobject File "/usr/lib/pymodules/python2.6/gtk-2.0/gobject/__init__.py", line 26, in from glib import spawn_async, idle_add, timeout_add, timeout_add_seconds, \ File "/usr/lib/pymodules/python2.6/gtk-2.0/glib/__init__.py", line 22, in from glib._glib import * ImportError: /usr/lib/libpyglib-2.0-python2.6.so.0: undefined symbol: PyExc_ImportError From hniksic at xemacs.org Wed Nov 10 16:52:13 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Wed, 10 Nov 2010 22:52:13 +0100 Subject: Is Eval *always* Evil? References: Message-ID: <87wrok4zjm.fsf@xemacs.org> Simon Mullis writes: > If "eval" is not the way forward, are there any suggestions for > another way to do this? ast.literal_eval might be the thing for you. From ian.g.kelly at gmail.com Wed Nov 10 16:54:08 2010 From: ian.g.kelly at gmail.com (Ian) Date: Wed, 10 Nov 2010 13:54:08 -0800 (PST) Subject: How to read the Python tutorial? References: <59c26dd2-529f-4a4a-8f48-1ee5f35b068f@t7g2000vbj.googlegroups.com> Message-ID: <128980d1-283d-4017-a137-1eca4291f806@k30g2000vbn.googlegroups.com> On Nov 10, 8:13?am, Zeynel wrote: > But when I try > > datetime.datetime.mDATE.toordinal()) > > I get AttributeError. Others have already explained why "mDATE.seconds" does not work, but I wanted to touch on this as well. The above fails because "mDATE" is not an attribute of the "datetime.datetime" class, which is to be expected since you've merely defined it as a local variable. If you want to call the "toordinal" method of mDATE, just do this: mDATE.toordinal() or this: datetime.datetime.toordinal(mDATE) But in most cases the first version is preferred. As an aside, your capitalization scheme would drive me insane. I suggest reading PEP 8, the Python style guide, and following the recommendations there. Also, it is not customary in Python to prefix attribute names with the string "m" or "m_" as it is in C++. Because Python does not do implicit attribute lookup, it is always clear from context whether a name refers to an attribute or not, and so the "m" is superfluous. Cheers, Ian From robert.kern at gmail.com Wed Nov 10 17:01:07 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 10 Nov 2010 16:01:07 -0600 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: On 11/10/10 2:27 PM, Robert Kern wrote: > On 11/10/10 3:50 AM, Lawrence D'Oliveiro wrote: >> In message, Jon >> Dufresne wrote: >> >>> On Mon, Nov 8, 2010 at 11:35 PM, Lawrence D'Oliveiro ... >> >> I see that you published my unobfuscated e-mail address on USENET for all to >> see. I obfuscated it for a reason, to keep the spammers away. I'm assuming >> this was a momentary lapse of judgement, for which I expect an apology. >> Otherwise, it becomes grounds for an abuse complaint to your ISP. > > I don't see any obfuscated email address at all in your own posts. I only see > your full, unobfuscated e-mail address that you list on your web page. You are > leaking the information, not Jon. FWIW, I am reading this via GMane using Thunderbird. Perhaps something along the way is unobfuscating your email address. -- 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 msarro at gmail.com Wed Nov 10 17:46:15 2010 From: msarro at gmail.com (Matty Sarro) Date: Wed, 10 Nov 2010 17:46:15 -0500 Subject: Looping through files in a directory Message-ID: Short story - I have a few thousand files in a directory I need to parse through. Is there a simple way to loop through files? I'd like to avoid writing a python script that can parse 1 file, and have to call it a few thousand times from a bash script. Any input or pointers to functions that'd help would be very much appreciated. Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Wed Nov 10 17:53:54 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 10 Nov 2010 23:53:54 +0100 Subject: DTD Parsing In-Reply-To: References: <4e7a49ec-1816-46e5-bc51-9f7c88f4d025@37g2000prx.googlegroups.com> <06071410-4684-4169-b1f8-0783e34f9062@f16g2000prj.googlegroups.com> Message-ID: Felipe Bastos Nunes, 10.11.2010 13:34: > Does any, libxml2 or lxml, collect children like jdom does in java? > List children = myRoot.getChildren(); Bah, that's *so* Java. ;) ElementTree and lxml.etree do it like this: children = list(myRoot) lxml also supports XPath and lots of other helpful stuff. Stefan From emile at fenx.com Wed Nov 10 17:56:45 2010 From: emile at fenx.com (Emile van Sebille) Date: Wed, 10 Nov 2010 14:56:45 -0800 Subject: Questions: While And List Comprehension In-Reply-To: References: Message-ID: On 11/10/2010 4:36 AM Felipe Vinturini said... > Hi Folks, > > I am quite new to python and I don't have a lot of experience with it yet. > > I have two simple questions: > > 1. Is there a way to limit the number of times a list comprehension will > execute? E.g. I want to read from input only 5 values, so I would like > something like (the values between # # are what I want): > =================================================================================== > COUNT = 0 > print [ v for v in sys.stdin.readlines() *# *IF COUNT< 5* #* ] ## Increment > COUNT somewhere Easiest would be print [ v for v in sys.stdin.readlines()[:5] ] but that still reads the entire sys.stdin (whatever it may be...) > =================================================================================== > > 2.* *I would like to know another way, a more pythonic way, to write the > following: > =================================================================================== > import sys > > def Z(iNumber): > sum=0 > while (iNumber>=5): > iNumber=iNumber/5 > sum = sum + iNumber > print sum > > def factorialCountZeros2(): > sysStdinReadLine = sys.stdin.readline > numValues = int(sysStdinReadLine()) > [ Z(int(sysStdinReadLine())) for x in xrange(numValues) ] > > if __name__ == '__main__': > factorialCountZeros2() > =================================================================================== > To be more specific, I would like to know about the Z function, is there a > way to rewrite that while with list comprehension? Well, you could use def X(iNumber): print sum([iNumber/(5**ii) for ii in range(1,2*int(len("%s" % iNumber)))]) but the range selection is rather arbitrary. Emile > > This code is to solve the CodeChef problem: > http://www.codechef.com/problems/FCTRL/ (I am still in the easy part) and it > executed in 2.5 secs, I would like to know if there is something else I can > improve performance. > > Thanks for your attention! > > Regards, > Felipe. > > From prologic at shortcircuit.net.au Wed Nov 10 17:59:25 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 11 Nov 2010 08:59:25 +1000 Subject: Curses Programming In-Reply-To: References: Message-ID: On Thu, Nov 11, 2010 at 12:42 AM, alexander wrote: > Could any give a hand? Assignment ? Homework ? cheers James -- -- James Mills -- -- "Problems are solved by method" From prologic at shortcircuit.net.au Wed Nov 10 18:01:37 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 11 Nov 2010 09:01:37 +1000 Subject: Questions: While And List Comprehension In-Reply-To: References: Message-ID: On Wed, Nov 10, 2010 at 10:36 PM, Felipe Vinturini wrote: > 1. Is there a way to limit the number of times a list comprehension will > execute??E.g. I want to read from input only 5 values, so I would like > something like (the values between # # are what I want): > =================================================================================== > COUNT = 0 > print [ v for v in sys.stdin.readlines() # IF COUNT < 5 # ] ## Increment > COUNT somewhere > =================================================================================== print [v for v in sys.stdin.readlines()[:5]] cheers James -- -- James Mills -- -- "Problems are solved by method" From ldo at geek-central.gen.new_zealand Wed Nov 10 18:07:17 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 11 Nov 2010 12:07:17 +1300 Subject: Development Vs Release References: <201011100749474192-nomail@thisaddresscom> Message-ID: In message <201011100749474192-nomail at thisaddresscom>, Sven wrote: > I don't like the idea of flags inside the code as they can often get > missed when developers release their code, ending up with released > versions that import modules from the developer's working directory. I have used a flag, together with a custom installation script that knows how to edit that flag in each source file depending on whether it?s being installed for testing or production use. From lists at cheimes.de Wed Nov 10 18:14:36 2010 From: lists at cheimes.de (Christian Heimes) Date: Thu, 11 Nov 2010 00:14:36 +0100 Subject: Is Eval *always* Evil? In-Reply-To: References: Message-ID: Am 10.11.2010 18:56, schrieb Simon Mullis: Yes, eval is evil, may lead to security issues and it's unnecessary slow, too. > # In the meantime - and as a proof of concept - I'm using a dict instead. > > xpathlib = { > "houses" : r'[ y.tag for y in x.xpath("//houses/*") ]', > "names" : r'[ y.text for y in x.xpath("//houses/name") ]', > "footwear_type" : r'[ y.tag for y in > x.xpath("//cupboard/bottom_shelf/*") ]', > "shoes" : r'[ y.text for y in > x.xpath("//cupboard/bottom_shelf/shoes/*") ]', > "interface_types" : r'[ y.text[:2] for y in > x.xpath("//interface/name") ]', > } You have two possibilities here: * either learn more XPath. You can do everything with XPath as well, for example "//houses/name/text()" * use lambdas instead, for example "names" : lambda x: [y.text for y in x.xpath("//houses/name")] Christian From lists at cheimes.de Wed Nov 10 18:18:41 2010 From: lists at cheimes.de (Christian Heimes) Date: Thu, 11 Nov 2010 00:18:41 +0100 Subject: DTD Parsing In-Reply-To: <06071410-4684-4169-b1f8-0783e34f9062@f16g2000prj.googlegroups.com> References: <4e7a49ec-1816-46e5-bc51-9f7c88f4d025@37g2000prx.googlegroups.com> <06071410-4684-4169-b1f8-0783e34f9062@f16g2000prj.googlegroups.com> Message-ID: Am 10.11.2010 04:36, schrieb Asun Friere: > Yes but configuration files are not necessarily meant to be edited by > humans either! Yeah, you are right. I'm sorry but every time I read XML and configuration in one sentence, I see the horror of TomCat or Shibboleth XML configs popping up. From ian.g.kelly at gmail.com Wed Nov 10 18:30:01 2010 From: ian.g.kelly at gmail.com (Ian) Date: Wed, 10 Nov 2010 15:30:01 -0800 (PST) Subject: Enumeration of strings and export of the constants References: Message-ID: On Nov 10, 6:12?am, lnenov wrote: > Is there a better and more common way to do this? from itertools import count, izip class APINamespace(object): def __init__(self): self._named_values = [] def enumerate(self, names, start=0, step=1): self._named_values.extend(izip(names, count(start, step))) def import_to(self, destination): for name, number in self._named_values: setattr(destination, name, number) Note the "step" parameter of itertools.count requires Python 2.7 or 3.1. > And can line 6 be replaced by something less evil. Yes, by putting the names to be imported into their own container as I've done above, instead of polluting the class dictionary with them. Cheers, Ian From arnodel at gmail.com Wed Nov 10 18:35:28 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Wed, 10 Nov 2010 23:35:28 +0000 Subject: Am I The Only One Who Keeps Reading =?utf-8?B?4oCcTnVtcHk=?= =?utf-8?B?4oCd?= as =?utf-8?B?4oCcTnVtcHR54oCdPw==?= References: <940162c6-b61a-4bb7-9965-6e155716cda8@n30g2000vbb.googlegroups.com> Message-ID: <87hbfoycov.fsf@gmail.com> rantingrick writes: >[...] it's "Num-pee" for me. If the "py" is appended i use "x-pee" and >if it is pre i use "pie- x". So pypy is "pie-pee", not "pie-pie" or "pee-pee". With that edifying thought, I'm off to bed. -- Arnaud From steve at holdenweb.com Wed Nov 10 18:36:24 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 10 Nov 2010 18:36:24 -0500 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: On 11/10/2010 4:50 AM, Lawrence D'Oliveiro wrote: > In message , Jon > Dufresne wrote: > >> On Mon, Nov 8, 2010 at 11:35 PM, Lawrence D'Oliveiro ... > > I see that you published my unobfuscated e-mail address on USENET for all to > see. I obfuscated it for a reason, to keep the spammers away. I'm assuming > this was a momentary lapse of judgement, for which I expect an apology. > Otherwise, it becomes grounds for an abuse complaint to your ISP. > Lawrence: Please stop making yourself look ridiculous with these requests. Accidents happen, and it does little or no good to draw people's attention to it. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From prologic at shortcircuit.net.au Wed Nov 10 19:14:42 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 11 Nov 2010 10:14:42 +1000 Subject: Looping through files in a directory In-Reply-To: References: Message-ID: On Thu, Nov 11, 2010 at 8:46 AM, Matty Sarro wrote: > Short story - I have a few thousand files in a directory I need to parse > through. Is there a simple way to loop through files? I'd like to avoid > writing a python script that can parse 1 file, and have to call it a few > thousand times from a bash script. Any input or pointers to functions that'd > help would be very much appreciated. Thanks! os.walk or os.listdir cheers James -- -- James Mills -- -- "Problems are solved by method" From steve at holdenweb.com Wed Nov 10 19:17:34 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 10 Nov 2010 19:17:34 -0500 Subject: Looping through files in a directory In-Reply-To: References: Message-ID: On 11/10/2010 5:46 PM, Matty Sarro wrote: > Short story - I have a few thousand files in a directory I need to parse > through. Is there a simple way to loop through files? I'd like to avoid > writing a python script that can parse 1 file, and have to call it a few > thousand times from a bash script. Any input or pointers to functions > that'd help would be very much appreciated. Thanks! > from glob import glob for filename in glob("*"): # do something with filename regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From prologic at shortcircuit.net.au Wed Nov 10 19:29:04 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 11 Nov 2010 10:29:04 +1000 Subject: Questions: While And List Comprehension In-Reply-To: References: Message-ID: On Thu, Nov 11, 2010 at 8:56 AM, Emile van Sebille wrote: > Easiest would be print [ v for v in sys.stdin.readlines()[:5] ] but that > still reads the entire sys.stdin (whatever it may be...) Here's a way of doing the same thing without consuming the entire stream (sys.stdin): #!/usr/bin/env python import sys print [v for v in list(line for line in sys.stdin)[:5]] This uses a generator expression to read from stdin, converts this to a list (only getting the first 5 items). cheers James -- -- James Mills -- -- "Problems are solved by method" From clp2 at rebertia.com Wed Nov 10 19:43:10 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 10 Nov 2010 16:43:10 -0800 Subject: Looping through files in a directory In-Reply-To: References: Message-ID: On Wed, Nov 10, 2010 at 2:46 PM, Matty Sarro wrote: > Short story - I have a few thousand files in a directory I need to parse > through. Is there a simple way to loop through files? I'd like to avoid > writing a python script that can parse 1 file, and have to call it a few > thousand times from a bash script. Any input or pointers to functions that'd > help would be very much appreciated. Thanks! http://docs.python.org/library/os.html#os.listdir http://docs.python.org/library/os.html#os.walk Cheers, Chris -- http://blog.rebertia.com From emile at fenx.com Wed Nov 10 19:46:56 2010 From: emile at fenx.com (Emile van Sebille) Date: Wed, 10 Nov 2010 16:46:56 -0800 Subject: Looping through files in a directory In-Reply-To: References: Message-ID: On 11/10/2010 2:46 PM Matty Sarro said... > Short story - I have a few thousand files in a directory I need to parse > through. Is there a simple way to loop through files? I'd like to avoid > writing a python script that can parse 1 file, and have to call it a few > thousand times from a bash script. Any input or pointers to functions that'd > help would be very much appreciated. Thanks! > > glob works pretty well. Emile From steve at holdenweb.com Wed Nov 10 19:57:29 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 10 Nov 2010 19:57:29 -0500 Subject: Questions: While And List Comprehension In-Reply-To: References: Message-ID: On 11/10/2010 6:01 PM, James Mills wrote: > On Wed, Nov 10, 2010 at 10:36 PM, Felipe Vinturini > wrote: >> 1. Is there a way to limit the number of times a list comprehension will >> execute? E.g. I want to read from input only 5 values, so I would like >> something like (the values between # # are what I want): >> =================================================================================== >> COUNT = 0 >> print [ v for v in sys.stdin.readlines() # IF COUNT < 5 # ] ## Increment >> COUNT somewhere >> =================================================================================== > > print [v for v in sys.stdin.readlines()[:5]] > how about print [sys.stdin.readline() for i in range(5)] At least that won't consume the whole file. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From wuwei23 at gmail.com Wed Nov 10 19:58:06 2010 From: wuwei23 at gmail.com (alex23) Date: Wed, 10 Nov 2010 16:58:06 -0800 (PST) Subject: Commercial or Famous Applicattions.? References: Message-ID: Martin Gregorie wrote: > Now, if ESR had fixed fetchmail [...] Did you try submitting patches? From wuwei23 at gmail.com Wed Nov 10 20:01:52 2010 From: wuwei23 at gmail.com (alex23) Date: Wed, 10 Nov 2010 17:01:52 -0800 (PST) Subject: Questions: While And List Comprehension References: Message-ID: Steve Holden wrote: > how about print [sys.stdin.readline() for i in range(5)] > > At least that won't consume the whole file. +1 on this approach. Clear and obvious and not reliant on any library modules other than sys. itertools, what WAS I thinking? :) From python.list at tim.thechases.com Wed Nov 10 20:24:22 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 10 Nov 2010 19:24:22 -0600 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: <4CDB45C6.7030309@tim.thechases.com> On 11/10/10 03:50, Lawrence D'Oliveiro wrote: > In message, Jon > Dufresne wrote: > >> Lawrence D'Oliveiro wrote: > > I see that you published my unobfuscated e-mail address on USENET for all to > see. I obfuscated it for a reason, to keep the spammers away. I'm assuming > this was a momentary lapse of judgement, for which I expect an apology. > Otherwise, it becomes grounds for an abuse complaint to your ISP. Amusingly, as others have noted, you replied with an unobfuscated email address. However, I suspect that if you file a complaint with Jon's ISP, they'll laugh at your complaint just like my ISP did when you complained to them[1]. My ISP contact's response pretty much boiled down to "yeah, I was pretty certain he was just being a tool, but I wanted to follow up to make sure" and sharing a laugh with me at your expense. Try spending your time learning to really obfuscate or finding a tool to better handle spam, instead of wasting your time (even if it's just firing off the same idiotic email template) being a tool about it. -tkc [1] http://www.mail-archive.com/python-list at python.org/msg287766.html From python.list at tim.thechases.com Wed Nov 10 20:28:15 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 10 Nov 2010 19:28:15 -0600 Subject: Looping through files in a directory In-Reply-To: References: Message-ID: <4CDB46AF.7070405@tim.thechases.com> On 11/10/10 16:46, Matty Sarro wrote: > Short story - I have a few thousand files in a directory I > need to parse through. Is there a simple way to loop through > files? I'd like to avoid writing a python script that can > parse 1 file, and have to call it a few thousand times from a > bash script. Any input or pointers to functions that'd help > would be very much appreciated. Sounds like you're reaching for os.listdir() import os TARGET = '/path/to/wherever' for fname in os.listdir(TARGET): process_file(os.path.join(TARGET, fname)) or possibly glob.glob() from glob import glob for fname in glob(os.path.join(TARGET, '*.txt')): process_file(fname) -tkc From python at mrabarnett.plus.com Wed Nov 10 20:38:49 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 11 Nov 2010 01:38:49 +0000 Subject: Questions: While And List Comprehension In-Reply-To: References: Message-ID: <4CDB4929.4010006@mrabarnett.plus.com> On 11/11/2010 00:29, James Mills wrote: > On Thu, Nov 11, 2010 at 8:56 AM, Emile van Sebille wrote: >> Easiest would be print [ v for v in sys.stdin.readlines()[:5] ] but that >> still reads the entire sys.stdin (whatever it may be...) > > Here's a way of doing the same thing without consuming the entire > stream (sys.stdin): > > #!/usr/bin/env python > > import sys > print [v for v in list(line for line in sys.stdin)[:5]] > > This uses a generator expression to read from stdin, converts this to > a list (only getting the first 5 items). > 'list' will exhaust the input, then the slicing will return at most 5 lines. From clp2 at rebertia.com Wed Nov 10 21:18:09 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 10 Nov 2010 18:18:09 -0800 Subject: Questions: While And List Comprehension In-Reply-To: <4CDB4929.4010006@mrabarnett.plus.com> References: <4CDB4929.4010006@mrabarnett.plus.com> Message-ID: On Wed, Nov 10, 2010 at 5:38 PM, MRAB wrote: > On 11/11/2010 00:29, James Mills wrote: >> On Thu, Nov 11, 2010 at 8:56 AM, Emile van Sebille ?wrote: >>> Easiest would be print [ v for v in sys.stdin.readlines()[:5] ] but that >>> still reads the entire sys.stdin (whatever it may be...) >> >> Here's a way of doing the same thing without consuming the entire >> stream (sys.stdin): >> >> #!/usr/bin/env python >> >> import sys >> print [v for v in list(line for line in sys.stdin)[:5]] >> >> This uses a generator expression to read from stdin, converts this to >> a list (only getting the first 5 items). >> > 'list' will exhaust the input, then the slicing will return at most 5 > lines. Also, the list comprehension and generator expression are both the identity versions thereof, so a shorter equivalent version of the erroneous code would be simply: print list(sys.stdin)[:5] Cheers, Chris From robert.kern at gmail.com Wed Nov 10 21:39:52 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 10 Nov 2010 20:39:52 -0600 Subject: Is Eval *always* Evil? In-Reply-To: References: Message-ID: On 2010-11-10 17:14 , Christian Heimes wrote: > Am 10.11.2010 18:56, schrieb Simon Mullis: > > Yes, eval is evil, may lead to security issues and it's unnecessary > slow, too. > >> # In the meantime - and as a proof of concept - I'm using a dict instead. >> >> xpathlib = { >> "houses" : r'[ y.tag for y in x.xpath("//houses/*") ]', >> "names" : r'[ y.text for y in x.xpath("//houses/name") ]', >> "footwear_type" : r'[ y.tag for y in >> x.xpath("//cupboard/bottom_shelf/*") ]', >> "shoes" : r'[ y.text for y in >> x.xpath("//cupboard/bottom_shelf/shoes/*") ]', >> "interface_types" : r'[ y.text[:2] for y in >> x.xpath("//interface/name") ]', >> } > > You have two possibilities here: > > * either learn more XPath. You can do everything with XPath as well, > for example "//houses/name/text()" > > * use lambdas instead, for example "names" : lambda x: [y.text for y in > x.xpath("//houses/name")] Well, the key reason he is using strings is so that he can easily slap on a Django admin UI to allow certain users to add new expressions. lambdas don't help with that. -- 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 Wed Nov 10 21:40:11 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 10 Nov 2010 20:40:11 -0600 Subject: Is Eval *always* Evil? In-Reply-To: <87wrok4zjm.fsf@xemacs.org> References: <87wrok4zjm.fsf@xemacs.org> Message-ID: On 2010-11-10 15:52 , Hrvoje Niksic wrote: > Simon Mullis writes: > >> If "eval" is not the way forward, are there any suggestions for >> another way to do this? > > ast.literal_eval might be the thing for you. No, that doesn't work since he needs to call methods. -- 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 ldo at geek-central.gen.new_zealand Wed Nov 10 21:54:38 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 11 Nov 2010 15:54:38 +1300 Subject: Silly newbie question - Caret character (^) References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> Message-ID: In message , Seebs wrote: > On 2010-11-10, Terry Reedy wrote: > >> I was referring to Schildt using gets() all the time and thereby >> teaching new C generations to do he same. > > Ahh, yes. > > I am told that the current plan is to kill it in C1X. I would shed no > tears. Another function that should be deprecated is strncat?I myself was caught out misunderstanding it recently. What purpose does it serve? From ldo at geek-central.gen.new_zealand Wed Nov 10 21:55:51 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 11 Nov 2010 15:55:51 +1300 Subject: Is Eval *always* Evil? References: Message-ID: In message , Robert Kern wrote: > Well, the key reason he is using strings is so that he can easily slap on > a Django admin UI to allow certain users to add new expressions. lambdas > don't help with that. Provded you can trust the users who are allowed to add such expressions, it?s probably all right. From ldo at geek-central.gen.new_zealand Wed Nov 10 22:02:31 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 11 Nov 2010 16:02:31 +1300 Subject: DTD Parsing References: <4e7a49ec-1816-46e5-bc51-9f7c88f4d025@37g2000prx.googlegroups.com> Message-ID: In message , Christian Heimes wrote: > Don't repeat the mistakes of others and use XML as a configuration > language. XML isn't meant to be edited by humans. My principle is: anything automatically generated by machine is not fit for viewing or editing by humans. There?s nothing special about XML in this regard. I have successfully got a nontechnical client to put together XML control files to drive some software I wrote for him. He used KXMLEditor (part of KDE 3.x, seems to be defunct nowadays), and of course he always started with an existing example and modified that. But it wasn?t too long before he was regularly doing it without needing to ask me questions. From steve at holdenweb.com Wed Nov 10 22:02:51 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 10 Nov 2010 22:02:51 -0500 Subject: Questions: While And List Comprehension In-Reply-To: References: Message-ID: On 11/10/2010 7:29 PM, James Mills wrote: > On Thu, Nov 11, 2010 at 8:56 AM, Emile van Sebille wrote: >> Easiest would be print [ v for v in sys.stdin.readlines()[:5] ] but that >> still reads the entire sys.stdin (whatever it may be...) > > Here's a way of doing the same thing without consuming the entire > stream (sys.stdin): > > #!/usr/bin/env python > > import sys > print [v for v in list(line for line in sys.stdin)[:5]] > > This uses a generator expression to read from stdin, converts this to > a list (only getting the first 5 items). > A generator expression slicing only accesses as many elements as it needs to? But surely list(line for line in sys.stdin) will be evaluated before the indexing is applied? I'd have thought that would have exhausted the input file. >>> f = open("/tmp/data", "w") >>> for i in 'one two three four five six seven eight nine ten'.split(): ... f.write("%s\n" % i) ... >>> f.close() >>> f = open("/tmp/data") >>> print [v for v in list(line for line in f)[:5]] ['one\n', 'two\n', 'three\n', 'four\n', 'five\n'] >>> f.next() Traceback (most recent call last): File "", line 1, in StopIteration >>> This suggests that you are mistaken about not exhausting the source. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From ldo at geek-central.gen.new_zealand Wed Nov 10 22:04:15 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 11 Nov 2010 16:04:15 +1300 Subject: DTD Parsing References: <4e7a49ec-1816-46e5-bc51-9f7c88f4d025@37g2000prx.googlegroups.com> <06071410-4684-4169-b1f8-0783e34f9062@f16g2000prj.googlegroups.com> Message-ID: In message , Christian Heimes wrote: > I'm sorry but every time I read XML and configuration in one sentence, I > see the horror of TomCat or Shibboleth XML configs popping up. Tomcat I know is written in Java; let me guess?Shibboleth is too? From ldo at geek-central.gen.new_zealand Wed Nov 10 22:07:45 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 11 Nov 2010 16:07:45 +1300 Subject: DTD Parsing References: <4e7a49ec-1816-46e5-bc51-9f7c88f4d025@37g2000prx.googlegroups.com> <06071410-4684-4169-b1f8-0783e34f9062@f16g2000prj.googlegroups.com> Message-ID: In message , Ian Kelly wrote: > On 11/9/2010 11:14 PM, r0g wrote: >> >> config = {} >> for line in (open("config.txt", 'r')): >> if len(line) > 0 and line[0] <> "#": >> param, value = line.rstrip().split("=",1) >> config[param] = value > > That's five whole lines of code. Why go to all that trouble when you > can just do this: > > import config Not a good idea. Because if there any mistakes in the config, you would like to print useful explanatory error messages to help the writer of the config file figure out what they?ve done wrong, rather than relying on them to understand Python exception tracebacks. Also your config validation rules may not map easily to Python language rules. From ian.g.kelly at gmail.com Wed Nov 10 22:10:24 2010 From: ian.g.kelly at gmail.com (Ian) Date: Wed, 10 Nov 2010 19:10:24 -0800 (PST) Subject: Questions: While And List Comprehension References: Message-ID: <4a556852-a1f8-41bf-8df6-56397ef7fd8e@c39g2000yqi.googlegroups.com> On 11/10/2010 4:36 AM Felipe Vinturini said... > 2.* *I would like to know another way, a more pythonic way, to write the > following: > =================================================================================== > import sys > > def Z(iNumber): > ? ? ?sum=0 > ? ? ?while (iNumber>=5): > ? ? ? ? ?iNumber=iNumber/5 > ? ? ? ? ?sum = sum + iNumber > ? ? ?print sum > > def factorialCountZeros2(): > ? ? ?sysStdinReadLine = sys.stdin.readline > ? ? ?numValues = int(sysStdinReadLine()) > ? ? ?[ Z(int(sysStdinReadLine())) for x in xrange(numValues) ] > > if __name__ == '__main__': > ? ? ?factorialCountZeros2() > =================================================================================== > To be more specific, I would like to know about the Z function, is there a > way to rewrite that while with list comprehension? Probably not in a way that's more efficient than what you're already doing. One thing you should do is to use the // operator instead of /. Apart from being more portable (/ no longer does integer division in Python 3), it's also significantly faster: $ python -m timeit "12 / 5" 10000000 loops, best of 3: 0.0711 usec per loop $ python -m timeit "12 // 5" 10000000 loops, best of 3: 0.028 usec per loop Also, don't use a list comprehension for your looping construct in factorialCountZeros2(). The list comprehension has to build up a list containing all the None objects returned by the Z() method, which wastes time and space. Because of that, it would be faster just to write it out the for loop. Besides the speed improvement, it's also bad style to use a list comprehension for a loop where you're only interested in the side effects. Another thing to consider is that function calls are expensive. Your Z() function gets called once for every line of input, which could add up. While it will make the code a bit less readable (CodeChef is definitely not the place to go if you want to learn to write *clear* code), you might see some improvement if you wrap that function into the factorialCountZeros2() function. Finally, one thing that really tends to help a lot in these puzzles is to do all your input at once and all your output at once. I/O is crazy expensive, but you can cut a lot of that out by minimizing the number of reads and writes that you have to do. After the first readline, you can do something like "input = sys.stdin.read().strip().split('\n')" to pull everything into a single list, then iterate over the list instead of stdin. For output, append all your results to a list instead of printing them immediately, then use '\n'.join() to generate something suitable for printing. Cheers, Ian P.S. CodeChef and SPOJ both have the psyco module available. If you just can't seem to get a problem solved in the time limit, you can always turn it on for a major speed boost. It's more fun to try to solve the problems without it, though. From prologic at shortcircuit.net.au Wed Nov 10 22:46:16 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 11 Nov 2010 13:46:16 +1000 Subject: Questions: While And List Comprehension In-Reply-To: <4CDB4929.4010006@mrabarnett.plus.com> References: <4CDB4929.4010006@mrabarnett.plus.com> Message-ID: On Thu, Nov 11, 2010 at 11:38 AM, MRAB wrote: > 'list' will exhaust the input, then the slicing will return at most 5 > lines. Hmm you're right :) -- -- James Mills -- -- "Problems are solved by method" From prologic at shortcircuit.net.au Wed Nov 10 22:48:07 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 11 Nov 2010 13:48:07 +1000 Subject: Questions: While And List Comprehension In-Reply-To: References: Message-ID: On Thu, Nov 11, 2010 at 1:02 PM, Steve Holden wrote: > This suggests that you are mistaken about not exhausting the source. Yeah I was mistaken. Oh well :) I was thinking of a generator-based solution and got lost in the implementation! -- -- James Mills -- -- "Problems are solved by method" From prologic at shortcircuit.net.au Wed Nov 10 22:53:21 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 11 Nov 2010 13:53:21 +1000 Subject: Questions: While And List Comprehension In-Reply-To: References: Message-ID: On Thu, Nov 11, 2010 at 11:01 AM, alex23 wrote: > +1 on this approach. Clear and obvious and not reliant on any library > modules other than sys. > > itertools, what WAS I thinking? :) maybe: import sys from itertools import islice print [v for v in islice((line for line in sys.stdin), 0, 5)] ? -- -- James Mills -- -- "Problems are solved by method" From " " at libero.it Wed Nov 10 23:14:05 2010 From: " " at libero.it (not1xor1 (Alessandro)) Date: Thu, 11 Nov 2010 04:14:05 GMT Subject: subclassing str In-Reply-To: References: <5dLBo.1024$w8.406@twister2.libero.it> Message-ID: Il 09/11/2010 03:18, Lawrence D'Oliveiro ha scritto: > How exactly does > > a.f(b, c) > > save time over > > f(a, b, c) unfortunately in real world you have: objId = objId.method(args) vs. objId = moduleName.method(objId, args) I know you can use "from moduleName import *", but IMHO that produces code much harder to manage and extend -- bye !(!1|1) From jon.dufresne at gmail.com Wed Nov 10 23:18:16 2010 From: jon.dufresne at gmail.com (Jon Dufresne) Date: Wed, 10 Nov 2010 20:18:16 -0800 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: On Wed, Nov 10, 2010 at 1:50 AM, Lawrence D'Oliveiro wrote: > In message , Jon > Dufresne wrote: > >> On Mon, Nov 8, 2010 at 11:35 PM, Lawrence D'Oliveiro ... > > I see that you published my unobfuscated e-mail address on USENET for all to > see. I obfuscated it for a reason, to keep the spammers away. I'm assuming > this was a momentary lapse of judgement, for which I expect an apology. > Otherwise, it becomes grounds for an abuse complaint to your ISP. > Is this for real? I did a "replay all" to respond to your post. What are you suggesting? I don't see anything that looks like an obfuscated email. Jon From aioe.org at technicalbloke.com Wed Nov 10 23:22:38 2010 From: aioe.org at technicalbloke.com (r0g) Date: Thu, 11 Nov 2010 04:22:38 +0000 Subject: Class extension confusion :( References: Message-ID: On 10/11/10 09:52, Peter Otten wrote: > r0g wrote: > >> I have a subclass of BaseHHTPRequestHandler which uses a dictonary >> "paths" and a function "api_call" which are defined in the main >> namespace of the module. I'd rather I was able to pass these object to >> the constructor and store them as data attributes "self.paths" and >> "self.api_call" but I'm not sure how to do that properly. My >> understanding is that one may extend a constructor by defining it's >> __init__ method, calling the parents constructor and then adding ones >> own attributes to taste. What I don't understand is where or how I am >> supposed to get these extra constructor arguments into the class given >> that I don't instantiate it myself, it is seemingly instantiated by >> HTTPServer class that I pass it to e.g. >> >> httpd = HTTPServer(server_address, PlainAJAXRequestHandler) >> >> I wondered if I ought to instantiate an instance of >> PlainAJAXRequestHandler, set the attributes (either manually or by >> extending it's constructor) and pass that to HTTPServer but I figured it >> expects a class not an instance as it probably wants to spawn one >> instance for each request so that would be a non starter. Might I need >> to subclass HTTPServer, find the bit that instantiates the request >> handler and override that so it passes it's constructor more parameters? >> Right now I'm pretty confused, can somebody please tell me how I might >> accomplish this, what I'm failing to grasp or point me to the docs that >> explain it - I've spent the last hour or two plowing through docs to no >> avail, I guess it's a case of keyword ignorance on my part! Code >> follows... > > Try passing a factory function instead of a class. Untested: > > from functools import partial > > class PlainAJAXRequestHandler(BaseHTTPRequestHandler): > def __init__(self, api_call, paths, *args, **kw): > BaseHTTPRequestHandler.__init__(self, *args, **kw) > self.api_call = api_call > self.paths = paths > > paths = ... > api_call = ... > > httpd = HTTPServer( > server_address, > partial(PlainAJAXRequestHandler, paths, api_call)) > Great, that looks ideal Peter, thanks very much :) One more question quick question if you have time... I actually subclass the class in question later on to provide an SSL secured connection, is it possible (or even advisable) to do the following to spare me having to modify the derived classes init (and any subsequent classes' inits) too?... PlainAJAXRequestHandler = partial(PlainAJAXRequestHandler, paths, api_call)) ^??? Remap name to new extended class class SecureAJAXRequestHandler(PlainAJAXRequestHandler): def setup(self): self.connection = self.request self.rfile = socket._fileobject(self.request, "rb", self.rbufsize) self.wfile = socket._fileobject(self.request, "wb", self.wbufsize) ^??? therefore no init needed? Cheers, Roger From clp2 at rebertia.com Wed Nov 10 23:29:59 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 10 Nov 2010 20:29:59 -0800 Subject: subclassing str In-Reply-To: References: <5dLBo.1024$w8.406@twister2.libero.it> Message-ID: On Wed, Nov 10, 2010 at 8:14 PM, not1xor1 (Alessandro) <" "@libero.it> wrote: > Il 09/11/2010 03:18, Lawrence D'Oliveiro ha scritto: > >> How exactly does >> >> ? ?a.f(b, c) >> >> save time over >> >> ? ? f(a, b, c) > > unfortunately in real world you have: > > objId = objId.method(args) > > vs. > > objId = moduleName.method(objId, args) > > I know you can use "from moduleName import *", but IMHO that produces code > much harder to manage and extend So just don't use the form with the asterisk. Explicitly list the members you wish to import from the module (`from moduleName import meth1, meth2`). That way, you don't have to specify the module name on every invocation, but the origin of the functions is still made explicit. Cheers, Chris -- http://blog.rebertia.com From robert.kern at gmail.com Wed Nov 10 23:31:25 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 10 Nov 2010 22:31:25 -0600 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: On 2010-11-10 22:18 , Jon Dufresne wrote: > On Wed, Nov 10, 2010 at 1:50 AM, Lawrence D'Oliveiro > wrote: >> In message, Jon >> Dufresne wrote: >> >>> On Mon, Nov 8, 2010 at 11:35 PM, Lawrence D'Oliveiro ... >> >> I see that you published my unobfuscated e-mail address on USENET for all to >> see. I obfuscated it for a reason, to keep the spammers away. I'm assuming >> this was a momentary lapse of judgement, for which I expect an apology. >> Otherwise, it becomes grounds for an abuse complaint to your ISP. >> > > Is this for real? I did a "replay all" to respond to your post. What > are you suggesting? I don't see anything that looks like an obfuscated > email. To be fair, I think Lawrence is *trying* to obfuscate his email address. You can see it in the python-list archives. http://mail.python.org/pipermail/python-list/2010-November/1260153.html However, somewhere between him and you (and me!), it gets unobfuscated. You did nothing wrong, even if you accept Lawrence's premise that deliberately unobfuscating someone's email address is apology-worthy. Personally, I don't. -- 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 steve at holdenweb.com Wed Nov 10 23:49:56 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 10 Nov 2010 23:49:56 -0500 Subject: DTD Parsing In-Reply-To: References: <4e7a49ec-1816-46e5-bc51-9f7c88f4d025@37g2000prx.googlegroups.com> <06071410-4684-4169-b1f8-0783e34f9062@f16g2000prj.googlegroups.com> Message-ID: On 11/10/2010 10:07 PM, Lawrence D'Oliveiro wrote: > In message , Ian Kelly > wrote: > >> > On 11/9/2010 11:14 PM, r0g wrote: >>> >> >>> >> config = {} >>> >> for line in (open("config.txt", 'r')): >>> >> if len(line) > 0 and line[0] <> "#": >>> >> param, value = line.rstrip().split("=",1) >>> >> config[param] = value >> > >> > That's five whole lines of code. Why go to all that trouble when you >> > can just do this: >> > >> > import config > Not a good idea. [...] Sure, you wouldn't want users editing imported Python files, it would be leaving your program hostage to all the things an ignorant or malevolent user might do. But practical for, for example, experimental work. I seem to remember that the major server project in "Python Web Programming" has all configurable modules importing a common Config module, though in my own defense that *was* almost ten years ago now. (That wasn't intended to be a production server though it ran sporadically on a computer in my basement for several years and produced a traceback occasionally). regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From aioe.org at technicalbloke.com Thu Nov 11 00:02:45 2010 From: aioe.org at technicalbloke.com (r0g) Date: Thu, 11 Nov 2010 05:02:45 +0000 Subject: How to test if a module exists? References: <87d3qdibzg.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On 10/11/10 12:45, Mark Wooding wrote: > r0g writes: > >> You use your main address on USENET rather than a junk one!? Obfuscated or >> not that's either brave or foolhardy! > > I use my real email address. I also have an aggressive spam filter. > But I don't think that much of my comes from Usenet harvesters any more, > to be honest. > > -- [mdw] Really? I get a metric butt-ton of spam every day to this address. Right now it simply filtered by address straight into my recycle bin, I suppose if it ever becomes burdensome or starts to choke my bandwidth I'll tell my mailserver to bounce it :) Roger From rantingrick at gmail.com Thu Nov 11 00:05:41 2010 From: rantingrick at gmail.com (rantingrick) Date: Wed, 10 Nov 2010 21:05:41 -0800 (PST) Subject: Questions: While And List Comprehension References: Message-ID: <54412a44-2321-4e62-96b8-fa08882f8845@k3g2000vbp.googlegroups.com> On Nov 10, 4:56?pm, Emile van Sebille wrote: > On 11/10/2010 4:36 AM Felipe Vinturini said... > > > Hi Folks, > > > I am quite new to python and I don't have a lot of experience with it yet. > > > I have two simple questions: > > > 1. Is there a way to limit the number of times a list comprehension will > > execute? E.g. I want to read from input only 5 values, so I would like > > something like (the values between # # are what I want): Hey all you guys could be mistaken. It looks like the OP is trying to implement some sort of ghetto database. And he may NOT necessarily want the FIRST five lines of the file. He said (and i quote) "the values /between/ # and #". Where # and # are starting and ending of a range -- not necessarily the starting of the input file! However we really need the OP to clear up these questions! From prologic at shortcircuit.net.au Thu Nov 11 00:18:43 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 11 Nov 2010 15:18:43 +1000 Subject: Questions: While And List Comprehension In-Reply-To: <54412a44-2321-4e62-96b8-fa08882f8845@k3g2000vbp.googlegroups.com> References: <54412a44-2321-4e62-96b8-fa08882f8845@k3g2000vbp.googlegroups.com> Message-ID: On Thu, Nov 11, 2010 at 3:05 PM, rantingrick wrote: > Hey all you guys could be mistaken. It looks like the OP is trying to > implement some sort of ghetto database. And he may NOT necessarily > want the FIRST five lines of the file. He said (and i quote) "the > values /between/ # and #". Where # and # are starting and ending of a > range -- not necessarily the starting of the input file! However we > really need the OP to clear up these questions! Valid point Rick. And yes my earlier post was very wrong :/ My follow-up (after realizing my mistake) might be better (using islice). cheers James -- -- James Mills -- -- "Problems are solved by method" From aioe.org at technicalbloke.com Thu Nov 11 00:20:23 2010 From: aioe.org at technicalbloke.com (r0g) Date: Thu, 11 Nov 2010 05:20:23 +0000 Subject: Curses Programming References: Message-ID: On 10/11/10 14:42, alexander wrote: > Hi, all > > Here is the test. Plz help..... > > / > ***************************************************************************************************************************************************/ > If you use the new image search of Google, you will find that the > result images are layouted in a way that each row has the same height, > but contains different number of images dependents the width-height > ratio of each image. The goal is to make each row of images having > approximately same total width. Just try search any image > inimages.google.com, you will get the idea. > If you're the programmer designing this page, what algorithm would you > use to select images for each row? > Input: > The input of the program is a plain text file, each line in the file > containg 2 numbers, describing the width and height of an image > e.g. > 800 600 > 640 400 > 720 1280 > ... > Goal: > Design an algorithm to put those images into a number of rows, each > row is 150 pixel height and 1200 pixel wide. You could scale images > proportionally to the same height. You need make sure the images are > aligned as closely as possbile to the row boundary. > Output: > The indexes of the images you would put on each row followed by blank > line. > e.g. > 0 > 1 > 2 > According to the input file example, this output means image-0 (800 x > 600) and image-1 (640 x 400) is put on the first row and image-2 (720 > x 1280) is put on the second row. > Constraint: > Assuming, the input file contains less than 100 lines. Your algorithm > should finish within 5 secs on a standard laptop. > > / > **********************************************************************************************************************************************/ > > Could any give a hand? > Thanks a lot > Alex Alex, At least try thinking about how you would solve the problem - that is after all the whole point of the exercise i.e. to think up an algorithm, not to code it in python. That part is your homework and nobody here will do it for you. Also, if you don't enjoy solving this kind of problem it's possible you are studying the wrong subject. If you can think of a basic strategy to solve the above problem and can explain it in fairly plain english then I'm sure some people here will be happy to a) improve it and b) Help you if you are struggling to translate your concept into working python code. Even then, it being a homework assignment you can't expect people to just give it to you on a plate. Expect homework assistance to be at least slightly oblique, it's for your own good. If you don't have to do any thinking yourself then you're not going to learn much either and next week you'll be right back where you were, pestering some other poor forum. Good luck with it! Roger. From timr at probo.com Thu Nov 11 00:23:54 2010 From: timr at probo.com (Tim Roberts) Date: Wed, 10 Nov 2010 21:23:54 -0800 Subject: udp sockets with python References: Message-ID: Mag Gam wrote: > >I am measuring the round trip time using tcpdump. The C version is >giving me around 80 microseconds (average) and the python is giving me >close to 300 microseconds (average). If you need the performance of a compiled language, then it's probably not appropriate to use an interpreter. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From aioe.org at technicalbloke.com Thu Nov 11 00:54:10 2010 From: aioe.org at technicalbloke.com (r0g) Date: Thu, 11 Nov 2010 05:54:10 +0000 Subject: DTD Parsing References: <4e7a49ec-1816-46e5-bc51-9f7c88f4d025@37g2000prx.googlegroups.com> <06071410-4684-4169-b1f8-0783e34f9062@f16g2000prj.googlegroups.com> Message-ID: On 10/11/10 20:38, Ian wrote: > On Nov 10, 1:05 am, r0g wrote: >>> That's five whole lines of code. Why go to all that trouble when you can >>> just do this: >> >>> import config >> >> Heh, mainly because I figure the config module will have a lot more >> options than I have use for right now and therefore the docs will take >> me longer to read than I will save by not just typing in the above ;) > > I think you misunderstand me. There is no config module and there are > no docs to read. It's just the configuration file itself written as a > Python script, containing arbitrary settings like: So you're not talking about this then?... http://www.red-dove.com/config-doc/ I see. You're suggesting writing config files IN the language you're already writing in? Indeed that's what I do in many situations, it has the advantage of working in any scripting language (I do the same in PHP fairly often, as do several big projects like Drupal) and of course it spares you a bit of code. However, if your config file it's meant to be distributed / editable by end users you don't necessarily want them to need a full understanding of python syntax to do it. Also, actually parsing config files (rather than just importing namespaces) gives you an opportunity to deal with any syntax errors on a case by case basis i.e. skip, fail, issue warning etc. Just importing code gives you a kind of 100% consistency or death situation and while that might be exactly what you want many times there may be situations where you want a bit more fine grained control! Roger From aioe.org at technicalbloke.com Thu Nov 11 01:04:54 2010 From: aioe.org at technicalbloke.com (r0g) Date: Thu, 11 Nov 2010 06:04:54 +0000 Subject: Questions: While And List Comprehension References: Message-ID: On 10/11/10 22:56, Emile van Sebille wrote: > On 11/10/2010 4:36 AM Felipe Vinturini said... >> Hi Folks, >> >> I am quite new to python and I don't have a lot of experience with it >> yet. >> >> I have two simple questions: >> >> 1. Is there a way to limit the number of times a list comprehension will >> execute? E.g. I want to read from input only 5 values, so I would like >> something like (the values between # # are what I want): >> =================================================================================== >> >> COUNT = 0 >> print [ v for v in sys.stdin.readlines() *# *IF COUNT< 5* #* ] ## >> Increment >> COUNT somewhere > > Easiest would be print [ v for v in sys.stdin.readlines()[:5] ] but that > still reads the entire sys.stdin (whatever it may be...) > Use readline() + a counter instead... print [sys.stdin.readline() for x in xrange(0,5)] Roger From aioe.org at technicalbloke.com Thu Nov 11 01:08:24 2010 From: aioe.org at technicalbloke.com (r0g) Date: Thu, 11 Nov 2010 06:08:24 +0000 Subject: DTD Parsing References: <4e7a49ec-1816-46e5-bc51-9f7c88f4d025@37g2000prx.googlegroups.com> <06071410-4684-4169-b1f8-0783e34f9062@f16g2000prj.googlegroups.com> Message-ID: On 10/11/10 23:18, Christian Heimes wrote: > Am 10.11.2010 04:36, schrieb Asun Friere: >> Yes but configuration files are not necessarily meant to be edited by >> humans either! > > Yeah, you are right. I'm sorry but every time I read XML and > configuration in one sentence, I see the horror of TomCat or Shibboleth > XML configs popping up. > There are XML editors these days you know? I hear some of them even do schema checking :) Roger From aioe.org at technicalbloke.com Thu Nov 11 01:11:17 2010 From: aioe.org at technicalbloke.com (r0g) Date: Thu, 11 Nov 2010 06:11:17 +0000 Subject: Looping through files in a directory References: Message-ID: On 11/11/10 00:17, Steve Holden wrote: > On 11/10/2010 5:46 PM, Matty Sarro wrote: >> Short story - I have a few thousand files in a directory I need to parse >> through. Is there a simple way to loop through files? I'd like to avoid >> writing a python script that can parse 1 file, and have to call it a few >> thousand times from a bash script. Any input or pointers to functions >> that'd help would be very much appreciated. Thanks! >> > from glob import glob > for filename in glob("*"): > # do something with filename > > regards > Steve Ooo, that's nice, would that work on non *nix platforms too? Roger From clp2 at rebertia.com Thu Nov 11 01:23:05 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 10 Nov 2010 22:23:05 -0800 Subject: Looping through files in a directory In-Reply-To: References: Message-ID: On Wed, Nov 10, 2010 at 10:11 PM, r0g wrote: > On 11/11/10 00:17, Steve Holden wrote: >> On 11/10/2010 5:46 PM, Matty Sarro wrote: >>> >>> Short story - I have a few thousand files in a directory I need to parse >>> through. Is there a simple way to loop through files? I'd like to avoid >>> writing a python script that can parse 1 file, and have to call it a few >>> thousand times from a bash script. Any input or pointers to functions >>> that'd help would be very much appreciated. Thanks! >>> >> from glob import glob >> for filename in glob("*"): >> ? # do something with filename >> >> regards >> ?Steve > > Ooo, that's nice, would that work on non *nix platforms too? Well, yeah; note the lack of any "Availability:" restriction note in the module's docs. http://docs.python.org/library/glob.html Cheers, Chris From aioe.org at technicalbloke.com Thu Nov 11 01:25:31 2010 From: aioe.org at technicalbloke.com (r0g) Date: Thu, 11 Nov 2010 06:25:31 +0000 Subject: Looping through files in a directory References: Message-ID: On 11/11/10 06:23, Chris Rebert wrote: > On Wed, Nov 10, 2010 at 10:11 PM, r0g wrote: >> On 11/11/10 00:17, Steve Holden wrote: >>> On 11/10/2010 5:46 PM, Matty Sarro wrote: >>>> >>>> Short story - I have a few thousand files in a directory I need to parse >>>> through. Is there a simple way to loop through files? I'd like to avoid >>>> writing a python script that can parse 1 file, and have to call it a few >>>> thousand times from a bash script. Any input or pointers to functions >>>> that'd help would be very much appreciated. Thanks! >>>> >>> from glob import glob >>> for filename in glob("*"): >>> # do something with filename >>> >>> regards >>> Steve >> >> Ooo, that's nice, would that work on non *nix platforms too? > > Well, yeah; note the lack of any "Availability:" restriction note in > the module's docs. > http://docs.python.org/library/glob.html > > Cheers, > Chris Ahh, I see (or rather I don't). I'm afraid I have a habit of missing things that aren't there, my bad. Roger From hniksic at xemacs.org Thu Nov 11 02:24:54 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Thu, 11 Nov 2010 08:24:54 +0100 Subject: Is Eval *always* Evil? References: <87wrok4zjm.fsf@xemacs.org> Message-ID: <87sjz84915.fsf@xemacs.org> Robert Kern writes: > On 2010-11-10 15:52 , Hrvoje Niksic wrote: >> Simon Mullis writes: >> >>> If "eval" is not the way forward, are there any suggestions for >>> another way to do this? >> >> ast.literal_eval might be the thing for you. > > No, that doesn't work since he needs to call methods. You're right; I misread the post. From __peter__ at web.de Thu Nov 11 03:01:00 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 11 Nov 2010 09:01 +0100 Subject: Class extension confusion :( References: Message-ID: r0g wrote: > On 10/11/10 09:52, Peter Otten wrote: >> r0g wrote: >> >>> I have a subclass of BaseHHTPRequestHandler which uses a dictonary >>> "paths" and a function "api_call" which are defined in the main >>> namespace of the module. I'd rather I was able to pass these object to >>> the constructor and store them as data attributes "self.paths" and >>> "self.api_call" but I'm not sure how to do that properly. My >>> understanding is that one may extend a constructor by defining it's >>> __init__ method, calling the parents constructor and then adding ones >>> own attributes to taste. What I don't understand is where or how I am >>> supposed to get these extra constructor arguments into the class given >>> that I don't instantiate it myself, it is seemingly instantiated by >>> HTTPServer class that I pass it to e.g. >>> >>> httpd = HTTPServer(server_address, PlainAJAXRequestHandler) >>> >>> I wondered if I ought to instantiate an instance of >>> PlainAJAXRequestHandler, set the attributes (either manually or by >>> extending it's constructor) and pass that to HTTPServer but I figured it >>> expects a class not an instance as it probably wants to spawn one >>> instance for each request so that would be a non starter. Might I need >>> to subclass HTTPServer, find the bit that instantiates the request >>> handler and override that so it passes it's constructor more parameters? >>> Right now I'm pretty confused, can somebody please tell me how I might >>> accomplish this, what I'm failing to grasp or point me to the docs that >>> explain it - I've spent the last hour or two plowing through docs to no >>> avail, I guess it's a case of keyword ignorance on my part! Code >>> follows... >> >> Try passing a factory function instead of a class. Untested: >> >> from functools import partial >> >> class PlainAJAXRequestHandler(BaseHTTPRequestHandler): >> def __init__(self, api_call, paths, *args, **kw): >> BaseHTTPRequestHandler.__init__(self, *args, **kw) >> self.api_call = api_call >> self.paths = paths >> >> paths = ... >> api_call = ... >> >> httpd = HTTPServer( >> server_address, >> partial(PlainAJAXRequestHandler, paths, api_call)) >> > > > Great, that looks ideal Peter, thanks very much :) > > One more question quick question if you have time... I actually subclass > the class in question later on to provide an SSL secured connection, is > it possible (or even advisable) to do the following to spare me having > to modify the derived classes init (and any subsequent classes' inits) > too?... > > PlainAJAXRequestHandler = partial(PlainAJAXRequestHandler, paths, > api_call)) > > ^??? Remap name to new extended class > > class SecureAJAXRequestHandler(PlainAJAXRequestHandler): That's not possible; you are trying to subclass a function. What you can do (again untested): def make_handler_class(paths, api_call): class MyHandler(BaseHTTPRequestHandler): paths = paths api_call = staticmethod(api_call) return MyHandler PlainAJAXRequestHandler = make_handler_class(paths, api_call) class SecureAJAXRequestHandler(PlainAJAXRequestHandler): ... Peter From nagle at animats.com Thu Nov 11 03:07:53 2010 From: nagle at animats.com (John Nagle) Date: Thu, 11 Nov 2010 00:07:53 -0800 Subject: Is Eval *always* Evil? In-Reply-To: References: Message-ID: <4cdba45a$0$1599$742ec2ed@news.sonic.net> On 11/10/2010 6:39 PM, Robert Kern wrote: > On 2010-11-10 17:14 , Christian Heimes wrote: >> Am 10.11.2010 18:56, schrieb Simon Mullis: >> >> Yes, eval is evil, may lead to security issues and it's unnecessary >> slow, too. If you have to use "eval", use the 2 or 3 argument form with a "globals" and "locals" dictionary. This lists the variables and functions that "eval" can see and touch. The Python documentation for this is not very good: "If the globals dictionary is present and lacks ?__builtins__?, the current globals are copied into globals before expression is parsed. This means that expression normally has full access to the standard __builtin__ module and restricted environments are propagated." What this means is that you have to put in "__builtins__" to PREVENT all built-ins from being imported. See http://lybniz2.sourceforge.net/safeeval.html for something readable on how to use "eval" safely. John Nagle From __peter__ at web.de Thu Nov 11 03:10:21 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 11 Nov 2010 09:10:21 +0100 Subject: Questions: While And List Comprehension References: Message-ID: James Mills wrote: > On Thu, Nov 11, 2010 at 11:01 AM, alex23 wrote: >> +1 on this approach. Clear and obvious and not reliant on any library >> modules other than sys. >> >> itertools, what WAS I thinking? :) > > maybe: > > import sys > from itertools import islice > > print [v for v in islice((line for line in sys.stdin), 0, 5)] (line for line in sys.stdin) and sys.stdin are equivalent as are [v for v in items] and list(items) So print list(islice(sys.stdin, 5)) Peter From paul.nospam at rudin.co.uk Thu Nov 11 03:11:42 2010 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Thu, 11 Nov 2010 08:11:42 +0000 Subject: Is Eval *always* Evil? References: Message-ID: <87mxpgwa81.fsf@rudin.co.uk> Robert Kern writes: > On 2010-11-10 17:14 , Christian Heimes wrote: >> Am 10.11.2010 18:56, schrieb Simon Mullis: >> >> Yes, eval is evil, may lead to security issues and it's unnecessary >> slow, too. Still - it is used in the standard library... From xrgtn at umc.com.ua Thu Nov 11 03:36:02 2010 From: xrgtn at umc.com.ua (Alexander Gattin) Date: Thu, 11 Nov 2010 10:36:02 +0200 Subject: How convert list to nested dictionary? In-Reply-To: <44817c9a-647b-4bed-9162-faf0fb5313bc@f20g2000yqi.googlegroups.com> References: <940876cd-2546-4673-aef4-ba11b4156287@fv1g2000vbb.googlegroups.com> <44817c9a-647b-4bed-9162-faf0fb5313bc@f20g2000yqi.googlegroups.com> Message-ID: <20101111083602.GA3982@xrgtn-q40> Hello, On Thu, Nov 04, 2010 at 02:10:12PM -0700, macm wrote: > > > How convert list to nested dictionary? > > > > >>>> l > > > ['k1', 'k2', 'k3', 'k4', 'k5'] > > >>>> result > > > {'k1': {'k2': {'k3': {'k4': {'k5': {}}}}}} > > http://www.amk.ca/python/writing/functional so, why didn't you try python's reduce? IMO this is trivial: > >>> l > ['k1', 'k2', 'k3', 'k4', 'k5'] > >>> reduce(lambda x,y: {y:x}, l.__reversed__()) > {'k1': {'k2': {'k3': {'k4': 'k5'}}}} > >>> reduce(lambda x,y: {y:x}, l.__reversed__(), dict()) > {'k1': {'k2': {'k3': {'k4': {'k5': {}}}}}} > >>> second reduce uses empty dict for seed. -- With best regards, xrgtn From aioe.org at technicalbloke.com Thu Nov 11 03:56:58 2010 From: aioe.org at technicalbloke.com (r0g) Date: Thu, 11 Nov 2010 08:56:58 +0000 Subject: Class extension confusion :( References: Message-ID: On 10/11/10 09:52, Peter Otten wrote: > class PlainAJAXRequestHandler(BaseHTTPRequestHandler): > def __init__(self, api_call, paths, *args, **kw): > BaseHTTPRequestHandler.__init__(self, *args, **kw) > self.api_call = api_call > self.paths = paths Hmm, the plot thickens! I always thought you had to call the parent constructor first (as above) when extending a constructor (not that I've had occasion to do that in a long time), but it turns out when I do this the lines below it never get executed and when I move them above that line they seem to work fine so it appears I was wrong about that. I've tried typing many variants of "python class extend constructor" into google over the last few days but I'm damned if I can find the docs explaining this. I'm sure I found them several years back when I first too up python, maybe by google-fu is on the wane! Anyway, that's not my main question, this is... The extra names that I pass to functools.partial seem to be bound permanently into the namespace of my class now i.e. I can reference them as 'api_call' and 'paths' anywhere in the classes' methods as opposed to having to assign them in the constructor and reference them as 'self.api_call' and 'self.paths'. I'm not 100% how that's working but in practical terms it suggests to two lines assigning those names to data attributes are redundant as I can access them anywhere anyway. Indeed, I've commented them out and my app still seems to work fine so... Question A) Are there any good reasons why I shouldn't just do that? (other than B!) Question B) The only reason I can think of so far is that I don't have a clear picture of how those names came to end up in that scope, it seems very convenient but I'm worried it's black magic of some sort! Could anyone explain or point me to the right docs please? Please shout if you would like to see the source. Thanks muchly :) Roger. From simon at mullis.co.uk Thu Nov 11 04:16:30 2010 From: simon at mullis.co.uk (Simon Mullis) Date: Thu, 11 Nov 2010 10:16:30 +0100 Subject: Is Eval *always* Evil? In-Reply-To: <4cdba45a$0$1599$742ec2ed@news.sonic.net> References: <4cdba45a$0$1599$742ec2ed@news.sonic.net> Message-ID: On 11 November 2010 09:07, John Nagle wrote: >>> Am 10.11.2010 18:56, schrieb Simon Mullis: >>> Yes, eval is evil, may lead to security issues and it's unnecessary >>> slow, too. > > ? If you have to use "eval", use the 2 or 3 argument form with a > "globals" and "locals" dictionary. ?This lists the variables > and functions that "eval" can see and touch. > > ? The Python documentation for this is not very good: > "If the globals dictionary is present and lacks ?__builtins__?, the current > globals are copied into globals before expression is parsed. This means that > expression ?normally has full access to the standard __builtin__ ?module and > restricted environments are propagated." > > ? What this means is that you have to put in "__builtins__" to > PREVENT all built-ins from being imported. Aren't I already doing this? >>> result = eval(xpath_command, {"__builtins__":[]},{"x": x}) SM From __peter__ at web.de Thu Nov 11 04:34:22 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 11 Nov 2010 10:34:22 +0100 Subject: Class extension confusion :( References: Message-ID: r0g wrote: > On 10/11/10 09:52, Peter Otten wrote: >> class PlainAJAXRequestHandler(BaseHTTPRequestHandler): >> def __init__(self, api_call, paths, *args, **kw): >> BaseHTTPRequestHandler.__init__(self, *args, **kw) >> self.api_call = api_call >> self.paths = paths > > > Hmm, the plot thickens! I always thought you had to call the parent > constructor first (as above) when extending a constructor (not that I've > had occasion to do that in a long time), but it turns out when I do this > the lines below it never get executed and when I move them above that > line they seem to work fine so it appears I was wrong about that. I've I didn't believe you until I had a look into the source. The meat is in SocketServer.py: class BaseRequestHandler: [snip] def __init__(self, request, client_address, server): self.request = request self.client_address = client_address self.server = server try: self.setup() self.handle() self.finish() finally: sys.exc_traceback = None # Help garbage collection def setup(self): pass def handle(self): pass def finish(self): pass As you can see this doesn't use __init__() just to set up the instance, it makes it the only method that is called by client code. That's an unusual design decision, to say the least. > tried typing many variants of "python class extend constructor" into > google over the last few days but I'm damned if I can find the docs > explaining this. I'm sure I found them several years back when I first > too up python, maybe by google-fu is on the wane! > > Anyway, that's not my main question, this is... The extra names that I > pass to functools.partial seem to be bound permanently into the > namespace of my class now i.e. I can reference them as 'api_call' and > 'paths' anywhere in the classes' methods as opposed to having to assign > them in the constructor and reference them as 'self.api_call' and > 'self.paths'. I'm not 100% how that's working but in practical terms it > suggests to two lines assigning those names to data attributes are > redundant as I can access them anywhere anyway. Indeed, I've commented > them out and my app still seems to work fine so... > > Question A) Are there any good reasons why I shouldn't just do that? > (other than B!) No. Use either class B(A): path = ... or class B(A): def __init__(self, path, *args, **kw): self.path = path A.__init__(self, *args, **kw) not both. > Question B) The only reason I can think of so far is that I don't have a > clear picture of how those names came to end up in that scope, it seems > very convenient but I'm worried it's black magic of some sort! Could > anyone explain or point me to the right docs please? Python looks for attributes in the instance first, and then in the class as a fallback. You only need to put them in the instance if you expect that you want a different value for every instance. Peter From felipe.vinturini at gmail.com Thu Nov 11 04:37:12 2010 From: felipe.vinturini at gmail.com (Felipe Vinturini) Date: Thu, 11 Nov 2010 07:37:12 -0200 Subject: Questions: While And List Comprehension In-Reply-To: References: Message-ID: On Thu, Nov 11, 2010 at 6:10 AM, Peter Otten <__peter__ at web.de> wrote: > James Mills wrote: > > > On Thu, Nov 11, 2010 at 11:01 AM, alex23 wrote: > >> +1 on this approach. Clear and obvious and not reliant on any library > >> modules other than sys. > >> > >> itertools, what WAS I thinking? :) > > > > maybe: > > > > import sys > > from itertools import islice > > > > print [v for v in islice((line for line in sys.stdin), 0, 5)] > > (line for line in sys.stdin) > > and sys.stdin are equivalent as are > > [v for v in items] > > and list(items) > > So > > print list(islice(sys.stdin, 5)) > > Peter > -- > http://mail.python.org/mailman/listinfo/python-list > Hello Folks, You are great! Thanks for the suggestions! With the values between # #, I meant I would like to limit the values sys.stdin.readlines() read (but I think there is no way to do it); instead of reading the entire input, limit it to read only 5 entries. I knew about readline(), but when checking it with cProfile each readline() needs a function call and with readlines() it is only one. I think that depending on input, readline() calls may have a higher cost. Check below: My test file: TestFile.txt ===================================================== 1 2 3 4 5 6 7 8 9 10 ===================================================== My test code: simpleReadLines.py ===================================================== import sys import cProfile def simpleTestLimitRLS(tLimit): sysStdinReadLines = sys.stdin.readlines allValues = [ int(v) for v in sysStdinReadLines() ] print allValues[:tLimit] def simpleTestLimitRL(tLimit): sysStdinReadLine = sys.stdin.readline print [ sysStdinReadLine() for x in xrange(0,5) ] if __name__ == '__main__': cProfile.run("simpleTestLimitRL(5)") cProfile.run("simpleTestLimitRLS(5)") ===================================================== Test result: ===================================================== >type TestFile.txt | python simpleReadLines.py ['1\n', '2\n', '3\n', '4\n', '5\n'] 8 function calls in 0.004 CPU seconds Ordered by: standard name ncalls tottime percall cumtime percall filename:lineno(function) 1 0.000 0.000 0.004 0.004 :1() 1 0.004 0.004 0.004 0.004 simpleReadLines.py:13(simpleTestLimitRL) 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects} 5 0.000 0.000 0.000 0.000 {method 'readline' of 'file' objects} [6, 7, 8, 9, 10] 4 function calls in 0.003 CPU seconds Ordered by: standard name ncalls tottime percall cumtime percall filename:lineno(function) 1 0.000 0.000 0.003 0.003 :1() 1 0.003 0.003 0.003 0.003 simpleReadLines.py:8(simpleTestLimitRLS) 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects} 1 0.000 0.000 0.000 0.000 {method 'readlines' of 'file' objects} ===================================================== If I change the execution order to: 1. simpleTestLimitRLS(5) 2. simpleTestLimitRL(5) Of course, python returns an error because all the input has been consumed by readlines(). Again, thanks for your attention and suggestions. Regards, Felipe. -------------- next part -------------- An HTML attachment was scrubbed... URL: From prologic at shortcircuit.net.au Thu Nov 11 04:49:27 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 11 Nov 2010 19:49:27 +1000 Subject: Questions: While And List Comprehension In-Reply-To: References: Message-ID: On Thu, Nov 11, 2010 at 6:10 PM, Peter Otten <__peter__ at web.de> wrote: > (line for line in sys.stdin) > > and sys.stdin are equivalent as are > > [v for v in items] > > and list(items) > > So > > print list(islice(sys.stdin, 5)) I was being a little verbose ... But I like your simplification :) cheers James -- -- James Mills -- -- "Problems are solved by method" From lnenov at mm-sol.com Thu Nov 11 04:49:50 2010 From: lnenov at mm-sol.com (lnenov) Date: Thu, 11 Nov 2010 11:49:50 +0200 Subject: Enumeration of strings and export of the constants In-Reply-To: References: Message-ID: <4CDBBC3E.5070906@mm-sol.com> On 11/11/2010 01:30 AM, Ian wrote: > On Nov 10, 6:12 am, lnenov wrote: >> Is there a better and more common way to do this? > from itertools import count, izip > > class APINamespace(object): > > def __init__(self): > self._named_values = [] > > def enumerate(self, names, start=0, step=1): > self._named_values.extend(izip(names, count(start, step))) > > def import_to(self, destination): > for name, number in self._named_values: > setattr(destination, name, number) > > Note the "step" parameter of itertools.count requires Python 2.7 or > 3.1. > >> And can line 6 be replaced by something less evil. > Yes, by putting the names to be imported into their own container as > I've done above, instead of polluting the class dictionary with them. Thanks a lot. It was my initial idea to pull something like that but for some mysterious reason i failed miserably. Thanks again. ~Lyudmil > Cheers, > Ian From xrgtn at yandex.ru Thu Nov 11 04:51:33 2010 From: xrgtn at yandex.ru (Alexander Gattin) Date: Thu, 11 Nov 2010 11:51:33 +0200 Subject: Learning Pyhton - Functional Programming - How intersect/difference two dict with dict/values? fast! In-Reply-To: <4d71519e-a232-427f-b4e0-5bae90fc4acb@n32g2000prc.googlegroups.com> References: <4d71519e-a232-427f-b4e0-5bae90fc4acb@n32g2000prc.googlegroups.com> Message-ID: <20101111095133.GA5707@xrgtn-q40> Hello, On Tue, Nov 09, 2010 at 09:32:17AM -0800, macm wrote: > dict1 = {'ab':[[1,2,3,'d3','d4',5],12],'ac':[[1,3,'78a','79b'], > 54],'ad': [[56,57,58,59],34], 'ax': [[56,57,58,59],34]} > dict2 = {'ab':[[22,2,'a0','42s','c4','d3'],12],'ab':[[2,4,50,42,'c4'], > 12],'ac':[[1,3,'79b',45,65,'er4'],54],'ae': [[56,57,58,59],34],'ax': > [[9],34]} You have a problem here: key 'ab' is listed twice in dict2 and only its second value is then visible: [[2,4,50,42,'c4'], 12], so that I couldn't get the desired {'ac':[1,3,'79b'], 'ab':[2,'d3']} intersection. So, after I've found the problem, the desired functional-style code emerges: > >>> dict(filter(lambda t: t[1], > ... map(lambda k: (k, filter(lambda v: v in dict2[k][0], dict1[k][0])), > ... filter(dict2.has_key, dict1.iterkeys())) > ... ) > ... ) > {'ac': [1, 3, '79b'], 'ab': [2, 'd3']} > >>> -- With best regards, xrgtn From lnenov at mm-sol.com Thu Nov 11 04:52:52 2010 From: lnenov at mm-sol.com (lnenov) Date: Thu, 11 Nov 2010 11:52:52 +0200 Subject: Enumeration of strings and export of the constants In-Reply-To: References: <4CDA9A4E.1050106@mm-sol.com> Message-ID: <4CDBBCF4.4010006@mm-sol.com> On 11/10/2010 11:19 PM, Emile van Sebille wrote: > On 11/10/2010 5:12 AM lnenov said... >> Hi, >> >> I need to enumerate a couple hundred strings to constants and export >> them to another module(s) globals. > > Do they really need to be globals? Why not a constants in an > object/container that would neither pollute the global namespace nor > risk being shadowed by subsequent inadvertent name conflict? It is ment for testing purposes and would be used mainly in interactive mode. This would save some typing : ) ~Lyudmil From xrgtn at yandex.ru Thu Nov 11 05:04:12 2010 From: xrgtn at yandex.ru (Alexander Gattin) Date: Thu, 11 Nov 2010 12:04:12 +0200 Subject: Learning Pyhton - Functional Programming - How intersect/difference two dict with dict/values? fast! In-Reply-To: <20101111095133.GA5707@xrgtn-q40> References: <4d71519e-a232-427f-b4e0-5bae90fc4acb@n32g2000prc.googlegroups.com> <20101111095133.GA5707@xrgtn-q40> Message-ID: <20101111100412.GA8627@xrgtn-q40> On Thu, Nov 11, 2010 at 11:51:33AM +0200, Alexander Gattin wrote: > functional-style code emerges: > > > >>> dict(filter(lambda t: t[1], > > ... map(lambda k: (k, filter(lambda v: v in dict2[k][0], dict1[k][0])), > > ... filter(dict2.has_key, dict1.iterkeys())) > > ... ) > > ... ) Sorry, the indentation for the above code is plain wrong. I'm not accustomed to lisp-indenting, and only have managed to produce the next version below: > >>> dict(filter(lambda t: t[1], > ... map(lambda k: (k, filter(lambda v: v in dict2[k][0], > ... dict1[k][0] > ... ) > ... ), > ... filter(dict2.has_key, dict1.iterkeys()) > ... ) > ... ) > ... ) > {'ac': [1, 3, '79b'], 'ab': [2, 'd3']} > >>> -- With best regards, xrgtn From cbrown at cbrownsystems.com Thu Nov 11 05:37:52 2010 From: cbrown at cbrownsystems.com (cbrown at cbrownsystems.com) Date: Thu, 11 Nov 2010 02:37:52 -0800 (PST) Subject: multiple discontinued ranges References: Message-ID: <3627e745-e45e-4b2c-8899-ca09c1d5a84b@n32g2000pre.googlegroups.com> On Nov 10, 10:02 am, Mel wrote: > xoff wrote: > > I was wondering what the best method was in Python programming for 2 > > discontinued ranges. e.g. I want to use the range 3 to 7 and 17 to 23. > > Am I obliged to use 2 for loops defining the 2 ranges like this: > > > for i in range (3,7): > > do bla > > for i in range (7,17): > > do bla > > > or is there a more clever way to do this? > > One horribly clever way is to concoct a 9-th order polynomial to return > 3,4,5,6,17,18,19,20,21,22 for input values 0,1,2,3,4,5,6,7,8,9. > And one would want one with integer coefficients... truly horribly clever! A good example of complex is better than complicated... > The reasonable way is to use two loops as you've done. If the pattern of > discontinuous ranges is really important in your application, you'd perhaps > want to package it up (not tested): > > def important_range (): > for x in xrange (3, 7): > yield x > for x in xrange (17,23): > yield x > Reasonable; but DRY: don't repeat yourself. IMNSHO, better would be: ... def important_range (): ... for x in [xrange (3, 7), xrange (17,23)]: ... for y in x: ... yield y because face it, you're probably going to add to that list of ranges anyway, so you should anticipate it (and there's no cost if you don't end up adding to it). To extend that notion, I would imagine that itertools.chain is already basically defined as: ... def chain(*args): ... for x in args: ... for y in x: ... yield y so important_range() can then be simply defined as: ... def important_range: ... return chain(xrange (3, 7), xrange (17,23)) Cheers - Chas > to be used elsewhere as > > for v in important_range(): > # use v ... > > Mel. From mdw at distorted.org.uk Thu Nov 11 06:28:27 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 11 Nov 2010 11:28:27 +0000 Subject: How to test if a module exists? References: <87d3qdibzg.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <87vd44gkv8.fsf.mdw@metalzone.distorted.org.uk> r0g writes: > Really? I get a metric butt-ton of spam every day to this address. I'm sure I get sent a lot of spam (though I don't know for sure -- see below). But I don't think much of it comes from Usenet harvesters any more. > Right now it simply filtered by address straight into my recycle bin, > I suppose if it ever becomes burdensome or starts to choke my > bandwidth I'll tell my mailserver to bounce it :) Don't do that. Get your mailserver to /reject/ spam during SMTP with a 5xx code. Bouncing spam is really bad because it implicitly assumes that the envelope sender address is good. Spam rarely has a valid envelope sender. If you're lucky, the envelope sender is simply invalid, and you'll end up with a double-bounce when your mailserver finds out. If you're unlucky, the envelope sender is a /valid/ address from the spammer's list and some innocent victim will end up receiving your bounce (this is called `backscatter'). -- [mdw] From moura.mario at gmail.com Thu Nov 11 06:28:45 2010 From: moura.mario at gmail.com (macm) Date: Thu, 11 Nov 2010 03:28:45 -0800 (PST) Subject: Open Multiples Files at same time with multiprocessing - How "declare" dynamically the var? Message-ID: Hi Folks My approach to open multiples files at same time is: def openFiles(self,file,q): fp = open(file, 'rb') fp.seek(0) fcontent = fp.read() fp.close() q.put(fcontent) return def testOpen(self): L = ['file1.txt','file2.txt','file3.txt','file4.txt','file5.txt'] d1 = [] for x in L: z=L.index(x) q = Queue() m = Process(target=self.openFiles, args=(x,q,)) m.start() d1.append(q.get()) # <= This get is locking ? It is mean: "wait m.start(), like m.join()??" print list(d1) return Is the best way? Is q.get() locking the loop? I feel that q.get() is locking so I would like to "declare" dynamically the var q{z} in python? is it possible? How? def testOpen(self): L = ['file1.txt','file2.txt','file3.txt','file4.txt','file5.txt'] d1 = [] for x in L: z=L.index(x) q{z} = Queue() m{z} = Process(target=self.openFiles, args=(x,q{z},)) m{z}.start() for x in L: z=L.index(x) d1.append(q{z}.get()) # <= So now I am sure that q{z}.get() isn't lock print list(d1) return I tried use list but didn't work look below one shot. Best Regards macm I tried : def testOpen(self): L = ['file1.txt','file2.txt', 'file3.txt','file4.txt', 'file5.txt'] d1 = [] q = [] m = [] for x in L: z=L.index(x) q.insert(z, Queue()) m.insert(z,Process(target=self.openFiles, args=(x,q[z]))) m[z].start() # Now I am sure. Isnt lock for x in L: z=L.index(x) d1.append(q[z].get()) print list(d1) return From ndbecker2 at gmail.com Thu Nov 11 06:36:28 2010 From: ndbecker2 at gmail.com (Neal Becker) Date: Thu, 11 Nov 2010 06:36:28 -0500 Subject: strange problem with multiprocessing Message-ID: Any idea what this could be about? Traceback (most recent call last): File "run-tests-10111104.py", line 48, in results = pool.map (run_test, cases) File "/usr/lib64/python2.7/multiprocessing/pool.py", line 199, in map return self.map_async(func, iterable, chunksize).get() File "/usr/lib64/python2.7/multiprocessing/pool.py", line 491, in get raise self._value ValueError: cannot convert float NaN to integer From martin at address-in-sig.invalid Thu Nov 11 07:15:04 2010 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Thu, 11 Nov 2010 12:15:04 +0000 (UTC) Subject: Commercial or Famous Applicattions.? References: Message-ID: On Wed, 10 Nov 2010 16:58:06 -0800, alex23 wrote: > Martin Gregorie wrote: >> Now, if ESR had fixed fetchmail [...] > > Did you try submitting patches? Nope. I'd already seen comments that bug reports etc. are ignored and tried getmail. Since that does the needful, why should I bother? -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From usenet at solar-empire.de Thu Nov 11 07:29:59 2010 From: usenet at solar-empire.de (Marc Christiansen) Date: Thu, 11 Nov 2010 13:29:59 +0100 Subject: strange problem with multiprocessing References: Message-ID: <774tq7-t5j.ln1@pluto.solar-empire.de> Neal Becker wrote: > Any idea what this could be about? > > Traceback (most recent call last): > File "run-tests-10111104.py", line 48, in > results = pool.map (run_test, cases) > File "/usr/lib64/python2.7/multiprocessing/pool.py", line 199, in map > return self.map_async(func, iterable, chunksize).get() > File "/usr/lib64/python2.7/multiprocessing/pool.py", line 491, in get > raise self._value > ValueError: cannot convert float NaN to integer > The ValueError comes from run_test. It contains an int(x), where x == float('nan'). Does cases maybe contain a NaN? Ciao Marc From manu3d at gmail.com Thu Nov 11 09:04:33 2010 From: manu3d at gmail.com (Emanuele D'Arrigo) Date: Thu, 11 Nov 2010 06:04:33 -0800 (PST) Subject: A matter of queues, tasks and multiprocessing References: <9e6f2dcc-7d15-4162-b3e9-9ef77a0b8980@n30g2000vbb.googlegroups.com> Message-ID: <41980a52-5bf3-4212-a0f4-a9968c2eb523@i17g2000vbq.googlegroups.com> On Nov 10, 9:19?pm, "danmcle... at yahoo.com" wrote: > If you are using Python 2.6 or greater, look into the multiprocessing > module. It may contain 90% of what you need. Thank you Dan, indeed the multi-processing module has been my first port of call and indeed it has all the basic ingredients. What I'm looking for is an higher-level architecture built on the multi- processing and the multi-threading modules. Thanks again! Manu From mail at timgolden.me.uk Thu Nov 11 09:13:34 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 11 Nov 2010 14:13:34 +0000 Subject: A matter of queues, tasks and multiprocessing In-Reply-To: <41980a52-5bf3-4212-a0f4-a9968c2eb523@i17g2000vbq.googlegroups.com> References: <9e6f2dcc-7d15-4162-b3e9-9ef77a0b8980@n30g2000vbb.googlegroups.com> <41980a52-5bf3-4212-a0f4-a9968c2eb523@i17g2000vbq.googlegroups.com> Message-ID: <4CDBFA0E.4060001@timgolden.me.uk> On 11/11/2010 14:04, Emanuele D'Arrigo wrote: > On Nov 10, 9:19 pm, "danmcle... at yahoo.com" > wrote: >> If you are using Python 2.6 or greater, look into the multiprocessing >> module. It may contain 90% of what you need. > > Thank you Dan, indeed the multi-processing module has been my first > port of call and indeed it has all the basic ingredients. What I'm > looking for is an higher-level architecture built on the multi- > processing and the multi-threading modules. Try Celery http://ask.github.com/celery/getting-started/introduction.html TJG From stef.mientki at gmail.com Thu Nov 11 09:22:57 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Thu, 11 Nov 2010 15:22:57 +0100 Subject: is there an Python equivalent for the PHP super globals like $_POST, $_COOKIE ? Message-ID: <4CDBFC41.6080404@gmail.com> hello, finally got Python running at my server. Now I would like to replace the PHP server scripts with Python ( for easier maintenance). But I can't find how th get to PHP's equivalent of $_Post and $_Cookie ? Google finds lots of links, but I can't find the answer. thanks, Stef Mientki From cdalten at gmail.com Thu Nov 11 10:07:32 2010 From: cdalten at gmail.com (chad) Date: Thu, 11 Nov 2010 07:07:32 -0800 (PST) Subject: How do I skip over multiple words in a file? Message-ID: Let's say that I have an article. What I want to do is read in this file and have the program skip over ever instance of the words "the", "and", "or", and "but". What would be the general strategy for attacking a problem like this? From tartley at tartley.com Thu Nov 11 10:15:03 2010 From: tartley at tartley.com (Jonathan Hartley) Date: Thu, 11 Nov 2010 07:15:03 -0800 (PST) Subject: Ways of accessing this mailing list? References: <87lj5ahzd9.fsf@benfinney.id.au> Message-ID: On Nov 3, 9:27?pm, Ben Finney wrote: > Grant Edwards writes: > > On 2010-11-02, John Bond wrote: > > > My normal inbox is getting unmanageable, and I think I need to find > > > a new way of following this and other lists. > > > Point an NNTP client at new.gmane.org. > > Ditto, but the correct hostname is ?news.gmane.org?. > Hey. I'm was trying this, and got stuck for a while. I have found 'gmane.comp.python.devel', which looks great for lurking, along with many other entries under gmane.comp.python.*. But I couldn't find *this* list (comp.lang.python) for ages, despite scrutinising possible aliases. For anyone else in the same boat, you are looking for gmane.comp.python.general. Jonathan From python.list at tim.thechases.com Thu Nov 11 10:48:54 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 11 Nov 2010 09:48:54 -0600 Subject: How do I skip over multiple words in a file? In-Reply-To: References: Message-ID: <4CDC1066.9050400@tim.thechases.com> On 11/11/10 09:07, chad wrote: > Let's say that I have an article. What I want to do is read in > this file and have the program skip over ever instance of the > words "the", "and", "or", and "but". What would be the > general strategy for attacking a problem like this? I'd keep a file of "stop words", read them into a set (normalizing case in the process). Then, as I skim over each word in my target file, check if the case-normalized version of the word is in your stop-words and skipping if it is. It might look something like this: def normalize_word(s): return s.strip().upper() stop_words = set( normalize_word(word) for word in file('stop_words.txt') ) for line in file('data.txt'): for word in line.split(): if normalize_word(word) in stop_words: continue process(word) -tkc From calderone.jeanpaul at gmail.com Thu Nov 11 11:03:21 2010 From: calderone.jeanpaul at gmail.com (Jean-Paul Calderone) Date: Thu, 11 Nov 2010 08:03:21 -0800 (PST) Subject: udp sockets with python References: Message-ID: On Nov 10, 9:23?pm, Tim Roberts wrote: > Mag Gam wrote: > > >I am measuring the round trip time using tcpdump. The C version is > >giving me around 80 microseconds (average) and the python is giving me > >close to 300 microseconds (average). > > If you need the performance of a compiled language, then it's probably not > appropriate to use an interpreter. Ridiculous. From fuglyducky at gmail.com Thu Nov 11 11:09:23 2010 From: fuglyducky at gmail.com (fuglyducky) Date: Thu, 11 Nov 2010 08:09:23 -0800 (PST) Subject: Looping through files in a directory References: Message-ID: <636b05ca-5c24-40de-9000-babc0723943f@29g2000prb.googlegroups.com> On Nov 10, 4:14?pm, James Mills wrote: > On Thu, Nov 11, 2010 at 8:46 AM, Matty Sarro wrote: > > Short story - I have a few thousand files in a directory I need to parse > > through. Is there a simple way to loop through files? I'd like to avoid > > writing a python script that can parse 1 file, and have to call it a few > > thousand times from a bash script. Any input or pointers to functions that'd > > help would be very much appreciated. Thanks! > > os.walk or os.listdir > > cheers > James > > -- > -- James Mills > -- > -- "Problems are solved by method" I was able to do something similar like this... ############################ rootPath = 'T:/' pattern = '*.xml' for root, dirs, files in os.walk(rootPath): for filename in fnmatch.filter(files, pattern): full_path = (os.path.join(root, filename)) print(full_path) ############################ From ian.g.kelly at gmail.com Thu Nov 11 11:30:57 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 11 Nov 2010 09:30:57 -0700 Subject: Open Multiples Files at same time with multiprocessing - How "declare" dynamically the var? In-Reply-To: References: Message-ID: On 11/11/2010 4:28 AM, macm wrote: > def openFiles(self,file,q): > fp = open(file, 'rb') > fp.seek(0) The seek is unnecessary; the file will already be at position 0 after it is opened. > def testOpen(self): > L = > ['file1.txt','file2.txt','file3.txt','file4.txt','file5.txt'] > d1 = [] > for x in L: > z=L.index(x) "for z, x in enumerate(L):" > q = Queue() > m = Process(target=self.openFiles, args=(x,q,)) > m.start() > d1.append(q.get()) #<= This get is locking ? It is mean: > "wait m.start(), like m.join()??" It can't get an item from the queue until an item has been put in the queue to get, so it waits for the process m to put something there. It does not do an implicit m.join() however. > I tried use list but didn't work look below one shot. "It didn't work" is not very useful for helping you debug. Be specific. What were you expecting, and what did you get instead? If there was a traceback, copy and paste it. Cheers, Ian From olivier.scalbert at algosyn.com Thu Nov 11 11:58:28 2010 From: olivier.scalbert at algosyn.com (Olivier Scalbert) Date: Thu, 11 Nov 2010 17:58:28 +0100 Subject: Question on using urllib Message-ID: <4cdc20b4$0$14249$ba620e4c@news.skynet.be> Hello all, Sorry if this question is not 100% python related, it is also related to http or html ... Everything takes place in this page: http://www.infometeo.be/klanten/KYC/campage2mega.php With the following program, I can download the 2 small meteo images, without any problem: import urllib urllib.urlretrieve("http://www.infometeo.be/wwweather/currentimage.php?icao=EBFN", "meteo1.jpg") urllib.urlretrieve("http://www.meteokust.be/metstatgr.php?s=zb", "meteo2.jpg") But I would like to download the main background picture. By looking inside the html page, it seems it's url is: http://www.infometeo.be/img.php?iid=1057 ...
... Warning, the iid may vary depending time ... I try to download it with python: urllib.urlretrieve("http://www.infometeo.be/img.php?iid=1057", "picture.jpg") But then I receive only 2 bytes: CR LF I think. If I use this url with my browser (firefox), I also get nothing (a blank page). If I go back to the main page with the firebug plugin activated, I can change the iid directly inside the html code with firebug, and then, even previous pictures can be displayed ... So I am a bit lost ... Any help would be very appreciate !! Thanks, Olivier From fetchinson at googlemail.com Thu Nov 11 12:24:12 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Thu, 11 Nov 2010 18:24:12 +0100 Subject: ANN: PyGUI 2.3 In-Reply-To: <4CCA99F3.4060106@canterbury.ac.nz> References: <4CCA99F3.4060106@canterbury.ac.nz> Message-ID: >> The problem is that some part of the application gets installed to >> >> /home/fetchinson/.local/lib/python2.6/site-packages/GUI >> >> and some other parts get installed to >> >> /home/fetchinson/.local/lib/python/site-packages/GUI > > Which parts get installed in which places, exactly? This gets installed to /home/fetchinson/.local/lib/python/GUI : Generic Gtk __init__.py __init__.pyc Version.py Version.pyc _where.py _where.pyc And this gets installed to /home/fetchinson/.local/lib/python2.6/site-packages/GUI : Resources > I'm puzzled, because I can't see anything in the setup.py > that could result in things getting split up like this. > I'm wondering whether there is some breakage in distutils. I honestly have no idea :) Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From __peter__ at web.de Thu Nov 11 12:37:27 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 11 Nov 2010 18:37:27 +0100 Subject: Question on using urllib References: <4cdc20b4$0$14249$ba620e4c@news.skynet.be> Message-ID: Olivier Scalbert wrote: > Sorry if this question is not 100% python related, it is also related to > http or html ... > > Everything takes place in this page: > http://www.infometeo.be/klanten/KYC/campage2mega.php > > With the following program, I can download the 2 small meteo images, > without any problem: > > import urllib > > urllib.urlretrieve("http://www.infometeo.be/wwweather/currentimage.php?icao=EBFN", > "meteo1.jpg") > urllib.urlretrieve("http://www.meteokust.be/metstatgr.php?s=zb", > "meteo2.jpg") > > But I would like to download the main background picture. > > By looking inside the html page, it seems it's url is: > http://www.infometeo.be/img.php?iid=1057 > I try to download it with python: > urllib.urlretrieve("http://www.infometeo.be/img.php?iid=1057", > "picture.jpg") The problem is indeed not Python-related. The provider of the images doesn't like what you're trying to do and verifies the referer, i. e. that the page you claim to be coming from is acceptable. Here's one way to satisfy that check: >>> from urllib2 import Request, urlopen >>> r = Request("http://www.infometeo.be/img.php?iid=1057", headers=dict(Referer="http://www.infometeo.be/img.php?iid=1057")) >>> img = urlopen(r).read() >>> with open("tmp.jpg", "w") as f: f.write(img) ... >>> Now if you are using that workaround a lot he may come up with more sophisticated techniques. So dont ;) Peter From steve at holdenweb.com Thu Nov 11 13:01:01 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 11 Nov 2010 13:01:01 -0500 Subject: is there an Python equivalent for the PHP super globals like $_POST, $_COOKIE ? In-Reply-To: <4CDBFC41.6080404@gmail.com> References: <4CDBFC41.6080404@gmail.com> Message-ID: On 11/11/2010 9:22 AM, Stef Mientki wrote: > hello, > > finally got Python running at my server. > > Now I would like to replace the PHP server scripts with Python ( for easier maintenance). > > But I can't find how th get to PHP's equivalent of $_Post and $_Cookie ? > Google finds lots of links, but I can't find the answer. > > thanks, > Stef Mientki Stef: Moving from one language to anther is not just a matter of transliterating the code. Of you try that you will end up with a messy code base that looks like PHP written in Python. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From rantingrick at gmail.com Thu Nov 11 13:07:51 2010 From: rantingrick at gmail.com (rantingrick) Date: Thu, 11 Nov 2010 10:07:51 -0800 (PST) Subject: =?windows-1252?Q?Re=3A_Am_I_The_Only_One_Who_Keeps_Reading_=93Numpy=94_?= =?windows-1252?Q?as_=93Numpty=94=3F?= References: <940162c6-b61a-4bb7-9965-6e155716cda8@n30g2000vbb.googlegroups.com> <87hbfoycov.fsf@gmail.com> Message-ID: On Nov 10, 5:35?pm, Arnaud Delobelle wrote: > So pypy is "pie-pee", not "pie-pie" or "pee-pee". ?With that edifying > thought, I'm off to bed. :) Good catch! Actually i've always thought of pypi as pie-pie and Scipy as cy-pie. Num-pie does not work for me. Maybe some linguist could chime in and explain these odd tendencies...? From olivier.scalbert at algosyn.com Thu Nov 11 13:15:19 2010 From: olivier.scalbert at algosyn.com (Olivier Scalbert) Date: Thu, 11 Nov 2010 19:15:19 +0100 Subject: Question on using urllib In-Reply-To: References: <4cdc20b4$0$14249$ba620e4c@news.skynet.be> Message-ID: <4cdc32b8$0$14247$ba620e4c@news.skynet.be> On 11/11/2010 06:37 PM, Peter Otten wrote: > The problem is indeed not Python-related. The provider of the images doesn't > like what you're trying to do and verifies the referer, i. e. that the page > you claim to be coming from is acceptable. Here's one way to satisfy that > check: > >>>> from urllib2 import Request, urlopen >>>> r = Request("http://www.infometeo.be/img.php?iid=1057", > headers=dict(Referer="http://www.infometeo.be/img.php?iid=1057")) >>>> img = urlopen(r).read() >>>> with open("tmp.jpg", "w") as f: f.write(img) > ... >>>> > > Now if you are using that workaround a lot he may come up with more > sophisticated techniques. So dont ;) > > Peter Thanks Peter, it works perfectly ! At 60 fps I can even make a video ... ;-) Olivier From stef.mientki at gmail.com Thu Nov 11 13:20:03 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Thu, 11 Nov 2010 19:20:03 +0100 Subject: is there an Python equivalent for the PHP super globals like $_POST, $_COOKIE ? In-Reply-To: References: <4CDBFC41.6080404@gmail.com> Message-ID: <4CDC33D3.9060308@gmail.com> On 11-11-2010 19:01, Steve Holden wrote: > On 11/11/2010 9:22 AM, Stef Mientki wrote: >> hello, >> >> finally got Python running at my server. >> >> Now I would like to replace the PHP server scripts with Python ( for easier maintenance). >> >> But I can't find how th get to PHP's equivalent of $_Post and $_Cookie ? >> Google finds lots of links, but I can't find the answer. >> >> thanks, >> Stef Mientki > Stef: > > Moving from one language to anther is not just a matter of > transliterating the code. Of you try that you will end up with a messy > code base that looks like PHP written in Python. Steve I agree with you, but replacing a number of 3 to 10 lines of code scripts won't create a mess ;-) cheers, Stef > regards > Steve From usenet-nospam at seebs.net Thu Nov 11 13:22:05 2010 From: usenet-nospam at seebs.net (Seebs) Date: 11 Nov 2010 18:22:05 GMT Subject: Silly newbie question - Caret character (^) References: <4cd4da94$0$30004$c3e8da3$5496439d@news.astraweb.com> <11A0F261-1BF4-4C35-83FA-C47BF968D150@semanchuk.com> Message-ID: (Note followups, this has stopped being very Pythony.) On 2010-11-11, Lawrence D'Oliveiro wrote: > Another function that should be deprecated is strncat???I myself was caught > out misunderstanding it recently. What purpose does it serve? I'm wondering if you're thinking of strncpy(), which is the famously bogus one. strncat() just has a fencepost error -- given a limit N, it will write at most N+1 characters. strncpy(), however, pads with null bytes if the source string isn't long enough, and does not null terminate if there isn't room to. This behavior is nearly always undesireable. However, if you were building a filesystem in which file path names were given exactly sixteen bytes of space in the directory entry, and you didn't want to truncate them to 15 bytes, you might write precisely this behavior. So that's what we got. I don't know whether anyone's gotten buy-in from the standards people for strlcpy()/strlcat(), but I really hope so. Me, I just use snprintf with a %s format instead of str*cpy(). -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From nagle at animats.com Thu Nov 11 13:32:46 2010 From: nagle at animats.com (John Nagle) Date: Thu, 11 Nov 2010 10:32:46 -0800 Subject: os.tmpfile() vs. tempfile.TemporaryFile() Message-ID: <4cdc36cf$0$1665$742ec2ed@news.sonic.net> Is there any reason to prefer "tempfile.TemporaryFile()" over "os.tmpfile()"? Both create a nameless temporary file that will be deleted on close. John Nagle From david_v_wright at yahoo.com Thu Nov 11 13:36:51 2010 From: david_v_wright at yahoo.com (david wright) Date: Thu, 11 Nov 2010 10:36:51 -0800 (PST) Subject: is there an Python equivalent for the PHP super globals like $_POST, $_COOKIE ? In-Reply-To: <4CDC33D3.9060308@gmail.com> References: <4CDBFC41.6080404@gmail.com> <4CDC33D3.9060308@gmail.com> Message-ID: <641264.37067.qm@web31810.mail.mud.yahoo.com> ________________________________ From: Stef Mientki To: python-list at python.org Sent: Thu, November 11, 2010 10:20:03 AM Subject: Re: is there an Python equivalent for the PHP super globals like $_POST, $_COOKIE ? On 11-11-2010 19:01, Steve Holden wrote: > On 11/11/2010 9:22 AM, Stef Mientki wrote: >> hello, >> >> finally got Python running at my server. >> >> Now I would like to replace the PHP server scripts with Python ( for easier >>maintenance). >> >> But I can't find how th get to PHP's equivalent of $_Post and $_Cookie ? >> Google finds lots of links, but I can't find the answer. >> >> thanks, >> Stef Mientki > Stef: > > Moving from one language to anther is not just a matter of > transliterating the code. Of you try that you will end up with a messy > code base that looks like PHP written in Python. - Steve I agree with you, - but replacing a number of 3 to 10 lines of code scripts won't create a mess ;-) So, assuming you want the 'straight ahead' (i.e. no framework, like Django) your looking at vanilla CGI programming. form = cgi.FieldStorage() # parse query string, handles decoding and GET and POST print "

name:", form["name"].value http://docs.python.org/library/cgi.html Enjoy! :) David -------------- next part -------------- An HTML attachment was scrubbed... URL: From danmcleran at yahoo.com Thu Nov 11 13:38:32 2010 From: danmcleran at yahoo.com (danmcleran at yahoo.com) Date: Thu, 11 Nov 2010 10:38:32 -0800 (PST) Subject: os.tmpfile() vs. tempfile.TemporaryFile() References: <4cdc36cf$0$1665$742ec2ed@news.sonic.net> Message-ID: On Nov 11, 11:32?am, John Nagle wrote: > ? ?Is there any reason to prefer "tempfile.TemporaryFile()" > over "os.tmpfile()"? ?Both create a nameless temporary file > that will be deleted on close. > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? John Nagle tempfile.TemporaryFile has more options, e.g. file prefix, suffix, dir location, mode, and buf size. if you don't care about any of that, then it probably makes no difference. From aotto1968 at users.berlios.de Thu Nov 11 13:51:38 2010 From: aotto1968 at users.berlios.de (Andreas Otto) Date: Thu, 11 Nov 2010 19:51:38 +0100 Subject: ANNOUNCE: NHI1-0.9, PLMK-1.7 und libmsgque-4.7 Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Dear User, ANNOUNCE: Major Feature Release ==================================== libmsgque: Application-Server-Toolkit for C, C++, JAVA, C#, TCL, PERL, PHP, PYTHON, RUBY, VB.NET PLMK: Programming-Language-Microkernel NHI1: Non-Human-Intelligence #1 LINKS ===== ChangeLog: > http://nhi1.berlios.de/theLink/changelog.htm libmsgque including PHP documentation: > http://nhi1.berlios.de/theLink/index.htm NHI1: > http://nhi1.berlios.de/ DOWNLOAD: > http://developer.berlios.de/projects/nhi1/ PHP man pages: > reference: msgqueforphpref.n > tutorial: msgqueforphptut.n SUMMARY ======= This version adds the ability to: * PHP language support. * a new interface of the "ProcessEvent" function and the "startAs" configuration option. * terminate an application from a callback with the "ErrorSetEXIT" function. The PHP language is characterized by an extensive but undocumented C API. The number of features combined with a growing and moving language made the extension programming difficult and lengthy. The successful PHP extension shows the flexibility and adaptability of NHI1. mfg Andreas Otto (aotto1968) -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.15 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org/ iQEcBAEBAgAGBQJM3Ds6AAoJEGTcPijNG3/ATywH/iguN1+96sp2RGzIz6N3I8mx tw4YO6ac8NPT+Ztm+IXYbGlkyb2Z/3UwES7aZunYy7DK/kJBh7VBbZNGGWZlRTvm w02uMa4dTCBye8tNkQ8dRAxjshe9taM1+54Z4k1EsFmIXOMi8bbdDuAPk2i8xGRu vJIFC6ubIx93Sjgodcr/AIGRskjutpF29+uoaSMz+8UrTxnSoJxq8VvgWR/+MXfZ UOb8GutVV6bGI/ylE/NgLpxvE1LUMNgMS0QzHgQHSu4E/8tW3Oyzt6FU68k51n8+ OTJaFYC7o1W9VwSoc/HNHPhVmECYONW40pRrf2P0llqiKElBAd23g1/h83iblqo= =5U+w -----END PGP SIGNATURE----- From stef.mientki at gmail.com Thu Nov 11 13:56:07 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Thu, 11 Nov 2010 19:56:07 +0100 Subject: is there an Python equivalent for the PHP super globals like $_POST, $_COOKIE ? In-Reply-To: <641264.37067.qm@web31810.mail.mud.yahoo.com> References: <4CDBFC41.6080404@gmail.com> <4CDC33D3.9060308@gmail.com> <641264.37067.qm@web31810.mail.mud.yahoo.com> Message-ID: <4CDC3C47.3050303@gmail.com> On 11-11-2010 19:36, david wright wrote: > > ---------------------------------------------------------------------------------------------------- > *From:* Stef Mientki > *To:* python-list at python.org > *Sent:* Thu, November 11, 2010 10:20:03 AM > *Subject:* Re: is there an Python equivalent for the PHP super globals like $_POST, $_COOKIE ? > > On 11-11-2010 19:01, Steve Holden wrote: > > On 11/11/2010 9:22 AM, Stef Mientki wrote: > >> hello, > >> > >> finally got Python running at my server. > >> > >> Now I would like to replace the PHP server scripts with Python ( for easier maintenance). > >> > >> But I can't find how th get to PHP's equivalent of $_Post and $_Cookie ? > >> Google finds lots of links, but I can't find the answer. > >> > >> thanks, > >> Stef Mientki > > Stef: > > > > Moving from one language to anther is not just a matter of > > transliterating the code. Of you try that you will end up with a messy > > code base that looks like PHP written in Python. > - Steve I agree with you, > - but replacing a number of 3 to 10 lines of code scripts won't create a mess ;-) > > So, assuming you want the 'straight ahead' (i.e. no framework, like Django) your looking > at vanilla CGI programming. > > form = cgi.FieldStorage() # parse query string, handles decoding and GET and POST > > print "

name:", form["name"].value > > http://docs.python.org/library/cgi.html thanks David, looks that was what I was looking for, I'll investigate all the properties of Fieldstorage. thanks, Stef > Enjoy! :) > David > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From aioe.org at technicalbloke.com Thu Nov 11 14:34:23 2010 From: aioe.org at technicalbloke.com (r0g) Date: Thu, 11 Nov 2010 19:34:23 +0000 Subject: Class extension confusion :( References: Message-ID: On 11/11/10 09:34, Peter Otten wrote: > r0g wrote: > >> Question B) The only reason I can think of so far is that I don't have a >> clear picture of how those names came to end up in that scope, it seems >> very convenient but I'm worried it's black magic of some sort! Could >> anyone explain or point me to the right docs please? > > Python looks for attributes in the instance first, and then in the class as > a fallback. You only need to put them in the instance if you expect that you > want a different value for every instance. > > Peter > Thanks Peter, I think I understand now, I'll quickly explain my picture of things though so you or some other denizens of the mighty comp.lang.python can correct me if I'm wrong!... I can access the parameters I pass to __init__ within the classes' methods without using self. as these methods are run within the constructor itself and are therefore within it's local scope. That also explains why I had to call the constructor _after_ creating the new data attributes to have them be included. My initial belief that one has to call the parent constructor as the first action in the extended constructor is not technically valid, in most cases it can be called at any point but in situations like the above it can mess things up so I ought to put it at the end of my constructors for it to always work. Are there any drawbacks to calling it last or is that how it is supposed to work? The BaseHTTPRequestHandler seemed curiously constructed to me at first too but I think I can see why now... as it's a handler it's only ever meant to be a transient thing and it requires no external parameters (unless you're me!) as it's always called by HTTPServer which has all the info necessary so there's be no sense requiring users to create an instance then call a method to get the servers response, you may as well just bundle it all into one. Also as it might be called hundreds or thousands of times in quick succession it would be important to have it finish and get garbage collected. I also see that I ought to at least assign these extended params to data attributes and access them via self. like I would normally do as I can't guarantee that implementation of BaseHTTPREquestHandler will remain constant over time. If I understand correctly it may also be possible (and more efficient) to use setattr() to inject the parameters I want into the class as class attributes before use, rather than assigning them to data attributes every time I instantiate an new instance. Actually looking at the code from BaseRequestHandler it seems I may have overlooked the proper way of associating a callback function anyway. It looks like I should just define self.handle() in my subclass so that's one less parameter to worry about, although I think I may still need to use the factory function method you showed me to get the "paths" dictionary in there. Thanks so much for all your help, I really appreciate it and, assuming I'm not totally wrong about all of the above, I find it reassuring that I'm not going mad! Cheers, Roger. From aioe.org at technicalbloke.com Thu Nov 11 14:45:28 2010 From: aioe.org at technicalbloke.com (r0g) Date: Thu, 11 Nov 2010 19:45:28 +0000 Subject: How to test if a module exists? References: <87d3qdibzg.fsf.mdw@metalzone.distorted.org.uk> <87vd44gkv8.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On 11/11/10 11:28, Mark Wooding wrote: > r0g writes: > >> Really? I get a metric butt-ton of spam every day to this address. > > I'm sure I get sent a lot of spam (though I don't know for sure -- see > below). But I don't think much of it comes from Usenet harvesters any > more. > >> Right now it simply filtered by address straight into my recycle bin, >> I suppose if it ever becomes burdensome or starts to choke my >> bandwidth I'll tell my mailserver to bounce it :) > > Don't do that. Get your mailserver to /reject/ spam during SMTP with a > 5xx code. Bouncing spam is really bad because it implicitly assumes > that the envelope sender address is good. Spam rarely has a valid > envelope sender. If you're lucky, the envelope sender is simply > invalid, and you'll end up with a double-bounce when your mailserver > finds out. If you're unlucky, the envelope sender is a /valid/ address > from the spammer's list and some innocent victim will end up receiving > your bounce (this is called `backscatter'). > > -- [mdw] Whoops, I forgot 'bounce' has a clear meaning in the world email, I meant reject. Having suffered plenty of backscatter back in the day I wouldn't want to wish that on anyone. Thankfully I haven't had any of that in a few years now. I guess a lot more people are using Domainkeys and SPF these days. Roger From ldo at geek-central.gen.new_zealand Thu Nov 11 14:49:18 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 12 Nov 2010 08:49:18 +1300 Subject: How to test if a module exists? References: Message-ID: In message , Jon Dufresne wrote: > On Wed, Nov 10, 2010 at 1:50 AM, Lawrence D'Oliveiro wrote: > >> In message , Jon >> Dufresne wrote: >> >>> On Mon, Nov 8, 2010 at 11:35 PM, Lawrence D'Oliveiro ... >> >> I see that you published my unobfuscated e-mail address on USENET for all >> to see. I obfuscated it for a reason, to keep the spammers away. I'm >> assuming this was a momentary lapse of judgement, for which I expect an >> apology. Otherwise, it becomes grounds for an abuse complaint to your >> ISP. >> > > Is this for real? I did a "replay all" to respond to your post. What > are you suggesting? I don't see anything that looks like an obfuscated > email. Tell me what you see here, for example . From aioe.org at technicalbloke.com Thu Nov 11 15:02:05 2010 From: aioe.org at technicalbloke.com (r0g) Date: Thu, 11 Nov 2010 20:02:05 +0000 Subject: is there an Python equivalent for the PHP super globals like $_POST, $_COOKIE ? References: Message-ID: On 11/11/10 14:22, Stef Mientki wrote: > hello, > > finally got Python running at my server. > > Now I would like to replace the PHP server scripts with Python ( for easier maintenance). > > But I can't find how th get to PHP's equivalent of $_Post and $_Cookie ? > Google finds lots of links, but I can't find the answer. > > thanks, > Stef Mientki PHP only tends to be run one way, the mod_php Apache module. There's several ways run python in conjunction with a webserver like apache: mod_wsgi, mod_python, CGI and FastCGI. I've never really looked into this way of doing things but I guess the details are going to vary depending on which one you use. It's also not uncommon for python to actually BE the webserver too, there's lots of webserver modules for python, cherrypy is fairly simple and well regarded. Often you can proxy these through Apache to get the benefits of both although again, that's not an approach I've used so I can't really advise you further. Roger. From ryszard.czerminski at gmail.com Thu Nov 11 15:08:55 2010 From: ryszard.czerminski at gmail.com (=?ISO-8859-2?Q?Ryszard_Czermi=F1ski?=) Date: Thu, 11 Nov 2010 15:08:55 -0500 Subject: please subscribe me to the list Message-ID: Thanks! Ryszard From aioe.org at technicalbloke.com Thu Nov 11 15:12:54 2010 From: aioe.org at technicalbloke.com (r0g) Date: Thu, 11 Nov 2010 20:12:54 +0000 Subject: How do I skip over multiple words in a file? References: Message-ID: On 11/11/10 15:07, chad wrote: > Let's say that I have an article. What I want to do is read in this > file and have the program skip over ever instance of the words "the", > "and", "or", and "but". What would be the general strategy for > attacking a problem like this? If your files are not too big I'd simply read them into a string and do a string replace for each word you want to skip. If you want case insensitivity use re.replace() instead of the default string.replace() method. Neither are elegant or all that efficient but both are very easy. If your use case requires something high performance then best keep looking :) Roger. From aioe.org at technicalbloke.com Thu Nov 11 15:14:52 2010 From: aioe.org at technicalbloke.com (r0g) Date: Thu, 11 Nov 2010 20:14:52 +0000 Subject: udp sockets with python References: Message-ID: On 11/11/10 16:03, Jean-Paul Calderone wrote: > On Nov 10, 9:23 pm, Tim Roberts wrote: >> Mag Gam wrote: >> >>> I am measuring the round trip time using tcpdump. The C version is >>> giving me around 80 microseconds (average) and the python is giving me >>> close to 300 microseconds (average). >> >> If you need the performance of a compiled language, then it's probably not >> appropriate to use an interpreter. > > Ridiculous. Terse! From aioe.org at technicalbloke.com Thu Nov 11 15:23:12 2010 From: aioe.org at technicalbloke.com (r0g) Date: Thu, 11 Nov 2010 20:23:12 +0000 Subject: is there an Python equivalent for the PHP super globals like $_POST, $_COOKIE ? References: <4CDBFC41.6080404@gmail.com> Message-ID: On 11/11/10 18:01, Steve Holden wrote: > On 11/11/2010 9:22 AM, Stef Mientki wrote: >> hello, >> >> finally got Python running at my server. >> >> Now I would like to replace the PHP server scripts with Python ( for easier maintenance). >> >> But I can't find how th get to PHP's equivalent of $_Post and $_Cookie ? >> Google finds lots of links, but I can't find the answer. >> >> thanks, >> Stef Mientki > > Stef: > > Moving from one language to anther is not just a matter of > transliterating the code. Of you try that you will end up with a messy > code base that looks like PHP written in Python. > > regards > Steve Come on Steve, I thought your role is to encourage / cheerlead here ;D While you're absolutely right when it comes to complex apps and sites I get the impression he's only talking about your common or garden short admin scripts. I might be wrong though. Roger From paul.watson at tungsten-consulting.com Thu Nov 11 15:24:28 2010 From: paul.watson at tungsten-consulting.com (Paul Watson) Date: Thu, 11 Nov 2010 13:24:28 -0700 Subject: is there an Python equivalent for the PHP super globals like $_POST, $_COOKIE ? In-Reply-To: References: <4CDBFC41.6080404@gmail.com> Message-ID: <4CDC50FC.60702@gmail.com> On 2010-11-11 11:20, Stef Mientki wrote: > On 11-11-2010 19:01, Steve Holden wrote: >> On 11/11/2010 9:22 AM, Stef Mientki wrote: >>> hello, >>> >>> finally got Python running at my server. >>> >>> Now I would like to replace the PHP server scripts with Python ( for easier maintenance). >>> >>> But I can't find how th get to PHP's equivalent of $_Post and $_Cookie ? >>> Google finds lots of links, but I can't find the answer. >>> >>> thanks, >>> Stef Mientki >> Stef: >> >> Moving from one language to anther is not just a matter of >> transliterating the code. Of you try that you will end up with a messy >> code base that looks like PHP written in Python. > Steve I agree with you, > but replacing a number of 3 to 10 lines of code scripts won't create a mess ;-) > > cheers, > Stef >> regards >> Steve > If there is no automated process to do the translation, then it should be avoided. It is an opportunity for chaos to ensue. From paul.hermeneutic at gmail.com Thu Nov 11 15:24:28 2010 From: paul.hermeneutic at gmail.com (Paul Watson) Date: Thu, 11 Nov 2010 13:24:28 -0700 Subject: is there an Python equivalent for the PHP super globals like $_POST, $_COOKIE ? In-Reply-To: References: <4CDBFC41.6080404@gmail.com> Message-ID: <4CDC50FC.60702@gmail.com> On 2010-11-11 11:20, Stef Mientki wrote: > On 11-11-2010 19:01, Steve Holden wrote: >> On 11/11/2010 9:22 AM, Stef Mientki wrote: >>> hello, >>> >>> finally got Python running at my server. >>> >>> Now I would like to replace the PHP server scripts with Python ( for easier maintenance). >>> >>> But I can't find how th get to PHP's equivalent of $_Post and $_Cookie ? >>> Google finds lots of links, but I can't find the answer. >>> >>> thanks, >>> Stef Mientki >> Stef: >> >> Moving from one language to anther is not just a matter of >> transliterating the code. Of you try that you will end up with a messy >> code base that looks like PHP written in Python. > Steve I agree with you, > but replacing a number of 3 to 10 lines of code scripts won't create a mess ;-) > > cheers, > Stef >> regards >> Steve > If there is no automated process to do the translation, then it should be avoided. It is an opportunity for chaos to ensue. From python at mrabarnett.plus.com Thu Nov 11 15:25:46 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 11 Nov 2010 20:25:46 +0000 Subject: please subscribe me to the list In-Reply-To: References: Message-ID: <4CDC514A.8030803@mrabarnett.plus.com> On 11/11/2010 20:08, Ryszard Czermi?ski wrote: > Thanks! > Ryszard What don't you do it yourself? Go to: http://mail.python.org/mailman/listinfo/python-list From ldo at geek-central.gen.new_zealand Thu Nov 11 15:26:51 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 12 Nov 2010 09:26:51 +1300 Subject: How to test if a module exists? References: Message-ID: In message , Tim Chase wrote: > Amusingly, as others have noted, you replied with an unobfuscated > email address. This would seem to be an independent, true record of what members of python-list would see of my posting, would it not? You would agree that it shows my e- mail address as obfuscated, would you not? So if you claim to be seeing an unobfuscated e-mail address for my posting on python-list, you would be lying, would you not? From phd at phd.pp.ru Thu Nov 11 15:26:57 2010 From: phd at phd.pp.ru (Oleg Broytman) Date: Thu, 11 Nov 2010 23:26:57 +0300 Subject: Torrent VFS for Midnight Commander Message-ID: <20101111202657.GA2613@phd.pp.ru> Torrent Virtual FileSystem for Midnight Commander WHAT IS IT View files, directories and meta information from a torrent metafile in Midnight Commander. WHAT'S NEW in version 1.0.0 (2010-11-11) Initial release. WHERE TO GET Master site: http://phd.pp.ru/Software/mc/ Mirrors: http://phd.by.ru/Software/mc/ http://phd.webhost.ru/Software/mc/ AUTHOR Oleg Broytman COPYRIGHT Copyright (C) 2010 PhiloSoft Design LICENSE GPL Oleg. -- Oleg Broytman http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From bnbowman at gmail.com Thu Nov 11 15:28:38 2010 From: bnbowman at gmail.com (Brett Bowman) Date: Thu, 11 Nov 2010 12:28:38 -0800 Subject: Copy Protected PDFs and PIL Message-ID: I'm trying to parse some basic details and a thumbnail from ~12,000 PDFs for my company, but a few hundred of them are copy protected. To make matters worse, I can't seem to trap the error it causes: whenever it happens PIL throws a "FATAL PDF disallows copying" message and dies. An automated way to snap a picture of the PDFs would be ideal, but I'd settle for a way to skip over them without crashing my program. Any tips? Brett Bowman Bioinformatics Associate Cibus LLC -------------- next part -------------- An HTML attachment was scrubbed... URL: From paul.hermeneutic at gmail.com Thu Nov 11 15:33:21 2010 From: paul.hermeneutic at gmail.com (Paul Watson) Date: Thu, 11 Nov 2010 13:33:21 -0700 Subject: How do I skip over multiple words in a file? In-Reply-To: References: Message-ID: <8k328sFjltU1@mid.individual.net> On 2010-11-11 08:07, chad wrote: > Let's say that I have an article. What I want to do is read in this > file and have the program skip over ever instance of the words "the", > "and", "or", and "but". What would be the general strategy for > attacking a problem like this? I realize that you may need or want to do this in Python. This would be trivial in an awk script. From python.list at tim.thechases.com Thu Nov 11 15:38:29 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 11 Nov 2010 14:38:29 -0600 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: <4CDC5445.20000@tim.thechases.com> On 11/11/10 13:49, Lawrence D'Oliveiro wrote: >> Is this for real? I did a "replay all" to respond to your post. What >> are you suggesting? I don't see anything that looks like an obfuscated >> email. > > Tell me what you see here, for example > . How about we look at an excerpt of the message you just sent: =============================== From: Lawrence D'Oliveiro Newsgroups: gmane.comp.python.general Subject: Re: How to test if a module exists? Date: Fri, 12 Nov 2010 08:49:18 +1300 [snip] >>> On Mon, Nov 8, 2010 at 11:35 PM, Lawrence D'Oliveiro ... >> >> I see that you published my unobfuscated e-mail address on >> USENET for all to see. I obfuscated it for a reason, to >> keep the spammers away. I'm assuming this was a momentary >> lapse of judgement, for which I expect anapology. Otherwise, >> it becomes grounds for an abuse complaint to your ISP. ================================ Gee...your unobfuscated email addresses FROM YOU. How about you apologize for blaming your own sins on others and then demanding THEIR apologies? When your own incompetence is at fault, demanding an apology just makes you look like an even bigger fool. And using a pre-authored email just amplifies your numskullery. And besides, your addle-pated folly has now exposed your email address to the big bad intarwebs. Once exposed, it doesn't really matter if anybody else exposes it because you yourself are to blame for letting the horse out of the barn. -tkc From no.email at nospam.invalid Thu Nov 11 15:41:01 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 11 Nov 2010 12:41:01 -0800 Subject: How do I skip over multiple words in a file? References: Message-ID: <7xhbfntwyq.fsf@ruckus.brouhaha.com> chad writes: > Let's say that I have an article. What I want to do is read in this > file and have the program skip over ever instance of the words "the", > "and", "or", and "but". What would be the general strategy for > attacking a problem like this? Something like (untested): stopwords = set (('and', 'or', 'but')) def goodwords(): for line in file: for w in line.split(): if w.lower() not in stopwords: yield w Removing punctuation is left as an exercise. From steve at holdenweb.com Thu Nov 11 15:42:23 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 11 Nov 2010 15:42:23 -0500 Subject: is there an Python equivalent for the PHP super globals like $_POST, $_COOKIE ? In-Reply-To: References: <4CDBFC41.6080404@gmail.com> Message-ID: On 11/11/2010 3:23 PM, r0g wrote: > On 11/11/10 18:01, Steve Holden wrote: >> On 11/11/2010 9:22 AM, Stef Mientki wrote: >>> hello, >>> >>> finally got Python running at my server. >>> >>> Now I would like to replace the PHP server scripts with Python ( for >>> easier maintenance). >>> >>> But I can't find how th get to PHP's equivalent of $_Post and $_Cookie ? >>> Google finds lots of links, but I can't find the answer. >>> >>> thanks, >>> Stef Mientki >> >> Stef: >> >> Moving from one language to anther is not just a matter of >> transliterating the code. Of you try that you will end up with a messy >> code base that looks like PHP written in Python. >> >> regards >> Steve > > Come on Steve, I thought your role is to encourage / cheerlead here ;D > > While you're absolutely right when it comes to complex apps and sites I > get the impression he's only talking about your common or garden short > admin scripts. I might be wrong though. > > Roger I'm quite happy to encourage, but I do find it necessary to interject a warning from time to time. I was pretty sure someone with PHP knowledge would come to the rescue. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From philip at semanchuk.com Thu Nov 11 15:54:36 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Thu, 11 Nov 2010 15:54:36 -0500 Subject: Copy Protected PDFs and PIL In-Reply-To: References: Message-ID: On Nov 11, 2010, at 3:28 PM, Brett Bowman wrote: > I'm trying to parse some basic details and a thumbnail from ~12,000 PDFs for > my company, but a few hundred of them are copy protected. To make matters > worse, I can't seem to trap the error it causes: whenever it happens PIL > throws a "FATAL PDF disallows copying" message and dies. An automated way > to snap a picture of the PDFs would be ideal, but I'd settle for a way to > skip over them without crashing my program. > > Any tips? What operating system? From steve at holdenweb.com Thu Nov 11 16:00:08 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 11 Nov 2010 16:00:08 -0500 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: On 11/11/2010 3:26 PM, Lawrence D'Oliveiro wrote: > In message , Tim Chase > wrote: > >> Amusingly, as others have noted, you replied with an unobfuscated >> email address. > > This > > would seem to be an independent, true record of what members of python-list > would see of my posting, would it not? You would agree that it shows my e- > mail address as obfuscated, would you not? So if you claim to be seeing an > unobfuscated e-mail address for my posting on python-list, you would be > lying, would you not? I still await some insight (which, of course, you are under no obligation to provide) about just why you perceive these innocent mistakes to be great wrongs that need righting. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From ethan at stoneleaf.us Thu Nov 11 16:00:39 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 11 Nov 2010 13:00:39 -0800 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: <4CDC5977.8010306@stoneleaf.us> Lawrence D'Oliveiro wrote: > In message , Tim Chase > wrote: > >> Amusingly, as others have noted, you replied with an unobfuscated >> email address. > > This > > would seem to be an independent, true record of what members of python-list > would see of my posting, would it not? You would agree that it shows my e- > mail address as obfuscated, would you not? So if you claim to be seeing an > unobfuscated e-mail address for my posting on python-list, you would be > lying, would you not? I'm using Thunderbird, and the headers, which I see very plainly while reading postings, says : Lawrence D'Oliveiro . That's what I see. ~Ethan~ From steve at holdenweb.com Thu Nov 11 16:01:19 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 11 Nov 2010 16:01:19 -0500 Subject: Copy Protected PDFs and PIL In-Reply-To: References: Message-ID: On 11/11/2010 3:28 PM, Brett Bowman wrote: > I'm trying to parse some basic details and a thumbnail from ~12,000 PDFs > for my company, but a few hundred of them are copy protected. To make > matters worse, I can't seem to trap the error it causes: whenever it > happens PIL throws a "FATAL PDF disallows copying" message and dies. An > automated way to snap a picture of the PDFs would be ideal, but I'd > settle for a way to skip over them without crashing my program. > > Any tips? > Well, you might consider letting us know whether the program gives a traceback or whether it's a PIL crash, for a start. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From python at mrabarnett.plus.com Thu Nov 11 16:03:44 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 11 Nov 2010 21:03:44 +0000 Subject: Copy Protected PDFs and PIL In-Reply-To: References: Message-ID: <4CDC5A30.8050406@mrabarnett.plus.com> On 11/11/2010 20:28, Brett Bowman wrote: > I'm trying to parse some basic details and a thumbnail from ~12,000 PDFs > for my company, but a few hundred of them are copy protected. To make > matters worse, I can't seem to trap the error it causes: whenever it > happens PIL throws a "FATAL PDF disallows copying" message and dies. An > automated way to snap a picture of the PDFs would be ideal, but I'd > settle for a way to skip over them without crashing my program. > > Any tips? > You could try it in a worker thread; it might kill only the worker. From aioe.org at technicalbloke.com Thu Nov 11 16:07:19 2010 From: aioe.org at technicalbloke.com (r0g) Date: Thu, 11 Nov 2010 21:07:19 +0000 Subject: How to test if a module exists? References: Message-ID: On 11/11/10 20:26, Lawrence D'Oliveiro wrote: > In message, Tim Chase > wrote: > >> Amusingly, as others have noted, you replied with an unobfuscated >> email address. > > This > > would seem to be an independent, true record of what members of python-list > would see of my posting, would it not? You would agree that it shows my e- > mail address as obfuscated, would you not? So if you claim to be seeing an > unobfuscated e-mail address for my posting on python-list, you would be > lying, would you not? Lawrence, this is getting old fast, just suck it up and move along. Roger From ian.g.kelly at gmail.com Thu Nov 11 16:10:37 2010 From: ian.g.kelly at gmail.com (Ian) Date: Thu, 11 Nov 2010 13:10:37 -0800 (PST) Subject: How to test if a module exists? References: Message-ID: <1d28ab93-fcaa-4c42-8bfc-4bc6de967f5d@37g2000prx.googlegroups.com> On Nov 11, 1:26?pm, Lawrence D'Oliveiro wrote: > In message , Tim Chase > wrote: > > > Amusingly, as others have noted, you replied with an unobfuscated > > email address. > > This > > would seem to be an independent, true record of what members of python-list > would see of my posting, would it not? You would agree that it shows my e- > mail address as obfuscated, would you not? Soifyou claim to be seeing an > unobfuscated e-mail address for my posting on python-list, you would be > lying, would you not? I also see the unobfuscated email address when reading your messages from python-list. The only place I see the obfuscated .new_zealand email address is when I click "View profile" in Google Groups -- but in that case the address is already truncated, so it hardly matters. From nberg at atmos.ucla.edu Thu Nov 11 16:16:12 2010 From: nberg at atmos.ucla.edu (Neil Berg) Date: Thu, 11 Nov 2010 13:16:12 -0800 Subject: returning results from function Message-ID: Hi Python community, In a main script, I pass the year (yr), month (mo), day (dy) and hour(hr) into the utc_to_local function (pasted below) which converts that date and time into local standard time. I am passing several dates and times into this function and would like to work with the "returned" loc_y/m/d/h values, but no output is visibly seen when I run the main script. I want the "return" command to just return the values to me in the main script so I can work with them! Any help is appreciated. Thanks in advance, Neil _________ Mac OS X 10.6.4 Python 2.6 _________ from datetime import datetime from pytz import timezone import pytz def utc_to_local(yr,mo,dy,hr): fmt = '%Y-%m-%d %H %Z' utc = pytz.utc local = pytz.timezone("US/Pacific") utc_dt = datetime(yr,mo,dy,hr, tzinfo=utc) loc_dt = utc_dt.astimezone(local) # local date YY-MM-DD HR TZ #print utc_dt.strftime(fmt), " = ", loc_dt.strftime(fmt) loc_y = loc_dt.year # local year loc_m = loc_dt.month # local month loc_d = loc_dt.day # local day loc_h = loc_dt.hour # local hour return loc_y, loc_m, loc_d, loc_h From emile at fenx.com Thu Nov 11 16:17:39 2010 From: emile at fenx.com (Emile van Sebille) Date: Thu, 11 Nov 2010 13:17:39 -0800 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: I'm using thunderbird via gmane and see the sender shown as ldo at geek-central.gen.nz -- so, no lies -- you've been self-outed. Emile From aioe.org at technicalbloke.com Thu Nov 11 16:17:56 2010 From: aioe.org at technicalbloke.com (r0g) Date: Thu, 11 Nov 2010 21:17:56 +0000 Subject: Class extension confusion :( References: Message-ID: On 11/11/10 19:34, r0g wrote: > On 11/11/10 09:34, Peter Otten wrote: >> r0g wrote: > If I understand correctly it may also be possible > (and more efficient) to use setattr() to inject the parameters I want > into the class as class attributes before use, rather than assigning > them to data attributes every time I instantiate an new instance. Ah, it's even simpler than that, turns out I've been significantly overcomplicating things, I can just set the class attributes by calling classname.attributename = whatever once at the start of my script. The one thing I might need to change as the server runs is the paths dictionary but dicts are mutable so that's no problem and I don't need to inject any data into the instances at all. I'm guessing I can subclass that easily now too - happy days! Well, far from wasted time it's been a very educational diversion, cheers :) Roger. From stefan.sonnenberg at pythonmeister.com Thu Nov 11 16:18:14 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Thu, 11 Nov 2010 22:18:14 +0100 Subject: How do I skip over multiple words in a file? In-Reply-To: <8k328sFjltU1@mid.individual.net> References: <8k328sFjltU1@mid.individual.net> Message-ID: <4CDC5D96.60707@pythonmeister.com> Am 11.11.2010 21:33, schrieb Paul Watson: > On 2010-11-11 08:07, chad wrote: >> Let's say that I have an article. What I want to do is read in this >> file and have the program skip over ever instance of the words "the", >> "and", "or", and "but". What would be the general strategy for >> attacking a problem like this? > > I realize that you may need or want to do this in Python. This would > be trivial in an awk script. There are several ways to do this. skip = ('and','or','but') all=[] [[all.append(w) for w in l.split() if w not in skip] for l in open('some.txt').readlines()] print all If some.txt contains your original question, it returns this: ["Let's", 'say', 'that', 'I', 'have', 'an', 'article.', 'What', 'I', 'want', 'to ', 'do', 'is', 'read', 'in', 'this', 'file', 'have', 'the', 'program', 'skip', ' over', 'ever', 'instance', 'of', 'the', 'words', '"the",', '"and",', '"or",', '" but".', 'What', 'would', 'be', 'the', 'general', 'strategy', 'for', 'attacking', 'a', 'problem', 'like', 'this?'] But this _one_ way to get there. Faster solutions could be based on a regex: import re skip = ('and','or','but') all = re.compile('(\w+)') print [w for w in all.findall(open('some.txt').read()) if w not in skip] this gives this result (you loose some punctuation etc): ['Let', 's', 'say', 'that', 'I', 'have', 'an', 'article', 'What', 'I', 'want', ' to', 'do', 'is', 'read', 'in', 'this', 'file', 'have', 'the', 'program', 'skip', 'over', 'ever', 'instance', 'of', 'the', 'words', 'the', 'What', 'would', 'be', 'the', 'general', 'strategy', 'for', 'attacking', 'a', 'problem', 'like', 'this '] But there are some many ways to do it ... -------------- next part -------------- A non-text attachment was scrubbed... Name: stefan_sonnenberg.vcf Type: text/x-vcard Size: 223 bytes Desc: not available URL: From python at mrabarnett.plus.com Thu Nov 11 16:23:08 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 11 Nov 2010 21:23:08 +0000 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: <4CDC5EBC.4030706@mrabarnett.plus.com> On 11/11/2010 20:26, Lawrence D'Oliveiro wrote: > In message, Tim Chase > wrote: > >> Amusingly, as others have noted, you replied with an unobfuscated >> email address. > > This > > would seem to be an independent, true record of what members of python-list > would see of my posting, would it not? You would agree that it shows my e- > mail address as obfuscated, would you not? So if you claim to be seeing an > unobfuscated e-mail address for my posting on python-list, you would be > lying, would you not? Lawrence, I receive posts from this list via email and I can tell you that the post referred to above arrived in my inbox with an unobfuscated email address, so what both you and I see in that webpage is not necessarily the same as what arrives by email. Looking back I can tell you that your post (give or take an hour for DST) at 3 Nov 2010 07:52 "Re: functions, list, default parameters" was the last to arrive with an obfuscated address; the next one at 3 Nov 2010 22:40 "Re: Allowing comments after the line continuation backslash" and _all_ the subsequent ones arrived with an _unobfuscated_ email address. From emile at fenx.com Thu Nov 11 16:24:15 2010 From: emile at fenx.com (Emile van Sebille) Date: Thu, 11 Nov 2010 13:24:15 -0800 Subject: Copy Protected PDFs and PIL In-Reply-To: References: Message-ID: On 11/11/2010 12:28 PM Brett Bowman said... > I'm trying to parse some basic details and a thumbnail from ~12,000 PDFs for > my company, but a few hundred of them are copy protected. To make matters > worse, I can't seem to trap the error it causes: whenever it happens PIL > throws a "FATAL PDF disallows copying" message and dies. An automated way > to snap a picture of the PDFs would be ideal, but I'd settle for a way to > skip over them without crashing my program. > > Any tips? try / except around the relevant code? Emile From bnbowman at gmail.com Thu Nov 11 16:26:03 2010 From: bnbowman at gmail.com (Brett Bowman) Date: Thu, 11 Nov 2010 13:26:03 -0800 Subject: Copy Protected PDFs and PIL In-Reply-To: References: Message-ID: Windows currently, though I also have a Linux box running Ubuntu if need be. On Thu, Nov 11, 2010 at 12:28 PM, Brett Bowman wrote: > I'm trying to parse some basic details and a thumbnail from ~12,000 PDFs > for my company, but a few hundred of them are copy protected. To make > matters worse, I can't seem to trap the error it causes: whenever it happens > PIL throws a "FATAL PDF disallows copying" message and dies. An automated > way to snap a picture of the PDFs would be ideal, but I'd settle for a way > to skip over them without crashing my program. > > Any tips? > > Brett Bowman > Bioinformatics Associate > Cibus LLC > -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Thu Nov 11 16:28:48 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 11 Nov 2010 15:28:48 -0600 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: <4CDC6010.80707@tim.thechases.com> On 11/11/10 14:26, Lawrence D'Oliveiro wrote: > In message, Tim Chase > wrote: > >> Amusingly, as others have noted, you replied with an unobfuscated >> email address. > > This > > would seem to be an independent, true record of what members of python-list > would see of my posting, would it not? You would agree that it shows my e- > mail address as obfuscated, would you not? So if you claim to be seeing an > unobfuscated e-mail address for my posting on python-list, you would be > lying, would you not? You're welcome to point to something on the web that doesn't show all the raw headers as a reason to accuse me of lying. However if you want the raw headers as they show up here (via Gmane's NNTP) see below or go visit Gmane with your NNTP client of choice or see on their web interface[1] that it has .nz as your TLD. Said leakage comes from you. Or perhaps Gmane lies as much as I do... ;-) -tkc [1] http://article.gmane.org/gmane.comp.python.general/678520/ Path: news.gmane.org!not-for-mail From: Lawrence D'Oliveiro Newsgroups: gmane.comp.python.general Subject: Re: How to test if a module exists? Date: Fri, 12 Nov 2010 09:26:51 +1300 Organization: Geek Central Lines: 13 Approved: news at gmane.org Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1289508625 22893 80.91.229.12 (11 Nov 2010 20:50:25 GMT) X-Complaints-To: usenet at dough.gmane.org NNTP-Posting-Date: Thu, 11 Nov 2010 20:50:25 +0000 (UTC) To: python-list at python.org Original-X-From: python-list-bounces+python-python-list=m.gmane.org at python.org Thu Nov 11 21:50:21 2010 Return-path: Envelope-to: python-python-list at m.gmane.org Original-Received: from mail.python.org ([82.94.164.166]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PGe67-0004p0-27 for python-python-list at m.gmane.org; Thu, 11 Nov 2010 21:50:19 +0100 Original-Received: from albatross.python.org (localhost [127.0.0.1]) by mail.python.org (Postfix) with ESMTP id D1573EE991 for ; Thu, 11 Nov 2010 21:50:18 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=python.org; s=200901; t=1289508618; bh=Qq3BZxpd6aw/1Vw+oG675AEz9lJPB9M4gIz6CavHT5U=; h=From:Subject:Date:Message-ID:References:Mime-Version:To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: Content-Type:Content-Transfer-Encoding:Sender; b=sDyLoQWAR3KEW7xHY7kclTb+Tz+2/gsxIIvmxInTSLNkDVQPqkK1nKZIm3tmUxEL8 Y5lcejoI2VRwfUD1CBNHKOpr/yN1bPmohX5pRZh4H0I+WqcLWmFyCIMFG9QfD0NJku gh0+wcaMH6VkD5qHehXP2nf5Lrg0yJ+BbkJ0DDok= Original-Path: news.xs4all.nl!newsspool.news.xs4all.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!feeder.news-service.com!news.glorb.com!newsfeeds.ihug.co.nz!lust.ihug.co.nz!ihug.co.nz!not-for-mail Original-Newsgroups: comp.lang.python Original-Followup-To: comp.lang.python Original-Lines: 13 Original-NNTP-Posting-Host: 118-93-131-51.dsl.dyn.ihug.co.nz Original-X-Trace: lust.ihug.co.nz 1289507211 26631 118.93.131.51 (11 Nov 2010 20:26:51 GMT) Original-X-Complaints-To: abuse at ihug.co.nz Original-NNTP-Posting-Date: Thu, 11 Nov 2010 20:26:51 +0000 (UTC) User-Agent: KNode/4.4.6 Original-Xref: news.xs4all.nl comp.lang.python:648868 X-BeenThere: python-list at python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: python-list-bounces+python-python-list=m.gmane.org at python.org Errors-To: python-list-bounces+python-python-list=m.gmane.org at python.org Xref: news.gmane.org gmane.comp.python.general:678700 Archived-At: In message , Tim Chase wrote: > Amusingly, as others have noted, you replied with an unobfuscated > email address. This would seem to be an independent, true record of what members of python-list would see of my posting, would it not? You would agree that it shows my e- mail address as obfuscated, would you not? So if you claim to be seeing an unobfuscated e-mail address for my posting on python-list, you would be lying, would you not? From ethan at stoneleaf.us Thu Nov 11 16:42:13 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 11 Nov 2010 13:42:13 -0800 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: <4CDC6335.9090301@stoneleaf.us> Lawrence D'Oliveiro wrote: > In message , Tim Chase > wrote: > >> Amusingly, as others have noted, you replied with an unobfuscated >> email address. > > This > > would seem to be an independent, true record of what members of python-list > would see of my posting, would it not? No, I would not -- it is not what I use, and it is not what I see. ~Ethan~ From ldo at geek-central.gen.new_zealand Thu Nov 11 16:53:39 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 12 Nov 2010 10:53:39 +1300 Subject: How to test if a module exists? References: Message-ID: In message , MRAB wrote: > ... the next one at 3 Nov 2010 22:40 "Re: Allowing comments after the line > continuation backslash" and _all_ the subsequent ones arrived with an > _unobfuscated_ email address. You mean from this one on ? From crebert at ucsd.edu Thu Nov 11 16:54:58 2010 From: crebert at ucsd.edu (Chris Rebert) Date: Thu, 11 Nov 2010 13:54:58 -0800 Subject: returning results from function In-Reply-To: References: Message-ID: On Thu, Nov 11, 2010 at 1:16 PM, Neil Berg wrote: > Hi Python community, > > In a main script, I pass the year (yr), month (mo), day (dy) and hour(hr) into the utc_to_local function (pasted below) which converts that date and time into local standard time. ?I am passing several dates and times into this function and would like to work with the "returned" loc_y/m/d/h values, > but no output is visibly seen when I run the main script. Does the main script print() the returned values? Python doesn't output stuff unless you explicitly ask it to (except when you're using the REPL). Show us your main script, or at least the part of it where utc_to_local() is called. >?I want the "return" command to just return the values to me in the main script so I can work with them! It already does that. The problem must lie with the caller (i.e. the main script). Cheers, Chris -- http://blog.rebertia.com From davea at ieee.org Thu Nov 11 17:01:27 2010 From: davea at ieee.org (Dave Angel) Date: Thu, 11 Nov 2010 17:01:27 -0500 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: <4CDC67B7.2030103@ieee.org> On 2:59 PM, Lawrence D'Oliveiro wrote: > In message, Tim Chase > wrote: > >> Amusingly, as others have noted, you replied with an unobfuscated >> email address. > This > > would seem to be an independent, true record of what members of python-list > would see of my posting, would it not? You would agree that it shows my e- > mail address as obfuscated, would you not? So if you claim to be seeing an > unobfuscated e-mail address for my posting on python-list, you would be > lying, would you not? > On the link you specify, your email address has the word 'at' in it. I subscribe to this list by email, in digest form. And your email address here has a real "@" in it. Don't be so free to call people liars when they're reporting what they actually see. If you get this message directly, you can look at the TO: list. I just did a reply-all without editing anything. DaveA From stefan.sonnenberg at pythonmeister.com Thu Nov 11 17:10:28 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Thu, 11 Nov 2010 23:10:28 +0100 Subject: returning results from function In-Reply-To: References: Message-ID: <4CDC69D4.8040105@pythonmeister.com> Am 11.11.2010 22:16, schrieb Neil Berg: > Hi Python community, > > In a main script, I pass the year (yr), month (mo), day (dy) and hour(hr) into the utc_to_local function (pasted below) which converts that date and time into local standard time. I am passing several dates and times into this function and would like to work with the "returned" loc_y/m/d/h values, but no output is visibly seen when I run the main script. I want the "return" command to just return the values to me in the main script so I can work with them! Any help is appreciated. > > Thanks in advance, > Neil > > _________ > Mac OS X 10.6.4 > Python 2.6 > _________ > > from datetime import datetime > from pytz import timezone > import pytz > > def utc_to_local(yr,mo,dy,hr): > fmt = '%Y-%m-%d %H %Z' > utc = pytz.utc > local = pytz.timezone("US/Pacific") > utc_dt = datetime(yr,mo,dy,hr, tzinfo=utc) > loc_dt = utc_dt.astimezone(local) # local date YY-MM-DD HR TZ > #print utc_dt.strftime(fmt), " = ", loc_dt.strftime(fmt) > > loc_y = loc_dt.year # local year > loc_m = loc_dt.month # local month > loc_d = loc_dt.day # local day > loc_h = loc_dt.hour # local hour > > return loc_y, loc_m, loc_d, loc_h > Could you please be so nice and share the relevant parts of your main script with us ? -------------- next part -------------- A non-text attachment was scrubbed... Name: stefan_sonnenberg.vcf Type: text/x-vcard Size: 223 bytes Desc: not available URL: From bmjames at gmail.com Thu Nov 11 17:46:06 2010 From: bmjames at gmail.com (Ben James) Date: Thu, 11 Nov 2010 22:46:06 +0000 Subject: Am I The Only One Who Keeps Reading =?UTF-8?B?4oCcTnVtcHnigJ0=?= =?UTF-8?B?IGFzIOKAnE51bXB0eeKAnT8=?= References: Message-ID: On 10/11/2010 06:53, Lawrence D'Oliveiro wrote: > Sorry... I read it as "numpty" all the time! From python at mrabarnett.plus.com Thu Nov 11 17:54:17 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 11 Nov 2010 22:54:17 +0000 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: <4CDC7419.3010707@mrabarnett.plus.com> On 11/11/2010 21:53, Lawrence D'Oliveiro wrote: > In message, MRAB wrote: > >> ... the next one at 3 Nov 2010 22:40 "Re: Allowing comments after the line >> continuation backslash" and _all_ the subsequent ones arrived with an >> _unobfuscated_ email address. > > You mean from this one on > ? Yes. From ethan at stoneleaf.us Thu Nov 11 17:55:15 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 11 Nov 2010 14:55:15 -0800 Subject: How to test if a module exists? In-Reply-To: <4CDC67B7.2030103@ieee.org> References: <4CDC67B7.2030103@ieee.org> Message-ID: <4CDC7453.5010907@stoneleaf.us> Dave Angel wrote: > On 2:59 PM, Lawrence D'Oliveiro wrote: >> In message, Tim Chase >> wrote: >> >>> Amusingly, as others have noted, you replied with an unobfuscated >>> email address. >> This >> >> would seem to be an independent, true record of what members of >> python-list >> would see of my posting, would it not? You would agree that it shows >> my e- >> mail address as obfuscated, would you not? So if you claim to be >> seeing an >> unobfuscated e-mail address for my posting on python-list, you would be >> lying, would you not? >> > > On the link you specify, your email address has the word 'at' in it. > > I subscribe to this list by email, in digest form. And your email > address here has a real "@" in it. Don't be so free to call people > liars when they're reporting what they actually see. > > If you get this message directly, you can look at the TO: list. I just > did a reply-all without editing anything. > > DaveA > Interesting -- Lawrence's email address is showing the .new_zealand in your To headers, and that's what came up just now when I replied to all; but when I reply to something directly from Lawrence, it has the .nz instead. ~Ethan~ -- For those interested, I'm using Thunderbird on Windows boxen. From mdw at distorted.org.uk Thu Nov 11 17:55:26 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 11 Nov 2010 22:55:26 +0000 Subject: How to test if a module exists? References: Message-ID: <87mxpfjwrl.fsf.mdw@metalzone.distorted.org.uk> Lawrence D'Oliveiro writes: > In message , MRAB wrote: > > > ... the next one at 3 Nov 2010 22:40 "Re: Allowing comments after the line > > continuation backslash" and _all_ the subsequent ones arrived with an > > _unobfuscated_ email address. > > You mean from this one on > ? No. More like http://article.gmane.org/gmane.comp.python.general/677953 We'll accept your apologies now. -- [mdw] From nberg at atmos.ucla.edu Thu Nov 11 17:57:27 2010 From: nberg at atmos.ucla.edu (Neil Berg) Date: Thu, 11 Nov 2010 14:57:27 -0800 Subject: returning results from function In-Reply-To: References: Message-ID: <18BC12D7-80A2-46AD-8DE2-9D4B7C5F7A2E@atmos.ucla.edu> My main script reads in monthly netCDF files that record variables each hour for that month. The length of all time variables is equal to the number of hours per month. Using January 1995, for example, time_y is a 1d array of the integer 1995 repeated 744 times, time_m is a 1d array of the integer 1 repeated 744 times, time_d is a 1d array that ranges from 1 to 31, and time_h is a 1d array that cycles from 0 23. The part that calls upon utc_to_local() is: time_y = ncfile.variables['time_y'][:] # (time,int) [yrs] time_m = ncfile.variables['time_m'][:] # (time,int) [mnths] time_d = ncfile.variables['time_d'][:] # (time,int) [days] time_h = ncfile.variables['time_h'][:] # (time,float) [hrs] ntim =len(time_h) for tim_idx in range(0,ntim): local_date = utc_to_local(time_y[tim_idx],time_m[tim_idx],time_d[tim_idx],int(time_h[tim_idx])) ***Here is where I'd like to see the returned values so I can create new arrays that store them ***** Hope this makes sense. Thanks, Neil On Nov 11, 2010, at 1:54 PM, Chris Rebert wrote: > On Thu, Nov 11, 2010 at 1:16 PM, Neil Berg wrote: >> Hi Python community, >> >> In a main script, I pass the year (yr), month (mo), day (dy) and hour(hr) into the utc_to_local function (pasted below) which converts that date and time into local standard time. I am passing several dates and times into this function and would like to work with the "returned" loc_y/m/d/h values, >> but no output is visibly seen when I run the main script. > > Does the main script print() the returned values? Python doesn't > output stuff unless you explicitly ask it to (except when you're using > the REPL). Show us your main script, or at least the part of it where > utc_to_local() is called. > >> I want the "return" command to just return the values to me in the main script so I can work with them! > > It already does that. The problem must lie with the caller (i.e. the > main script). > > Cheers, > Chris > -- > http://blog.rebertia.com From emile at fenx.com Thu Nov 11 18:00:01 2010 From: emile at fenx.com (Emile van Sebille) Date: Thu, 11 Nov 2010 15:00:01 -0800 Subject: How to test if a module exists? In-Reply-To: <4CDC67B7.2030103@ieee.org> References: <4CDC67B7.2030103@ieee.org> Message-ID: On 11/11/2010 2:01 PM Dave Angel said... > I subscribe to this list by email, in digest form. And your email > address here has a real "@" in it. Don't be so free to call people liars > when they're reporting what they actually see. > > If you get this message directly, you can look at the TO: list. I just > did a reply-all without editing anything. Which I see on my end now as copying to: ldo at geek-central.gen.new_zealand so it didn't go directly as it happens... Emile From steve at holdenweb.com Thu Nov 11 18:00:18 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 11 Nov 2010 15:00:18 -0800 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: On 11/11/2010 1:53 PM, Lawrence D'Oliveiro wrote: > In message , MRAB wrote: > >> ... the next one at 3 Nov 2010 22:40 "Re: Allowing comments after the line >> continuation backslash" and _all_ the subsequent ones arrived with an >> _unobfuscated_ email address. > > You mean from this one on > ? Here's a screen capture from Thunderbird. Anything else you need? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ -------------- next part -------------- A non-text attachment was scrubbed... Name: doliviero.png Type: image/png Size: 7027 bytes Desc: not available URL: From crebert at ucsd.edu Thu Nov 11 18:29:40 2010 From: crebert at ucsd.edu (Chris Rebert) Date: Thu, 11 Nov 2010 15:29:40 -0800 Subject: returning results from function In-Reply-To: <18BC12D7-80A2-46AD-8DE2-9D4B7C5F7A2E@atmos.ucla.edu> References: <18BC12D7-80A2-46AD-8DE2-9D4B7C5F7A2E@atmos.ucla.edu> Message-ID: > On Nov 11, 2010, at 1:54 PM, Chris Rebert wrote: >> On Thu, Nov 11, 2010 at 1:16 PM, Neil Berg wrote: >>> Hi Python community, >>> >>> In a main script, I pass the year (yr), month (mo), day (dy) and hour(hr) into the utc_to_local function (pasted below) which converts that date and time into local standard time. ?I am passing several dates and times into this function and would like to work with the "returned" loc_y/m/d/h values, >>> but no output is visibly seen when I run the main script. >> >> Does the main script print() the returned values? Python doesn't >> output stuff unless you explicitly ask it to (except when you're using >> the REPL). Show us your main script, or at least the part of it where >> utc_to_local() is called. >> >>> ?I want the "return" command to just return the values to me in the main script so I can work with them! >> >> It already does that. The problem must lie with the caller (i.e. the >> main script). On Thu, Nov 11, 2010 at 2:57 PM, Neil Berg wrote: > My main script reads in monthly netCDF files that record variables each hour for that month. ?The length of all time variables is equal to the number of hours per month. ?Using January 1995, for example, time_y is a 1d array of the integer 1995 repeated 744 times, time_m is a 1d array of the integer 1 repeated 744 times, time_d is a 1d array that ranges from 1 to 31, and time_h is a 1d array that cycles from 0 23. ?The part that calls upon utc_to_local() is: > > time_y = ncfile.variables['time_y'][:] # (time,int) [yrs] > time_m = ncfile.variables['time_m'][:] # (time,int) [mnths] > time_d = ncfile.variables['time_d'][:] # (time,int) [days] > time_h = ncfile.variables['time_h'][:] ? ?# (time,float) [hrs] > ntim =len(time_h) > for tim_idx in range(0,ntim): > ? ? ? ?local_date = utc_to_local(time_y[tim_idx],time_m[tim_idx],time_d[tim_idx],int(time_h[tim_idx])) > ? ? ? ?***Here is where I'd like to see the returned values so I can create new arrays that store them ***** Add: print(local_date) Or if you want to be fancy: print("%.4d-%.2d-%.2d %.2d" % local_date) Cheers, Chris -- http://blog.rebertia.com From robert.kern at gmail.com Thu Nov 11 18:35:59 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 11 Nov 2010 17:35:59 -0600 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: On 2010-11-11 14:26 , Lawrence D'Oliveiro wrote: > In message, Tim Chase > wrote: > >> Amusingly, as others have noted, you replied with an unobfuscated >> email address. > > This > > would seem to be an independent, true record of what members of python-list > would see of my posting, would it not? You would agree that it shows my e- > mail address as obfuscated, would you not? So if you claim to be seeing an > unobfuscated e-mail address for my posting on python-list, you would be > lying, would you not? This is what I see, reading from GMane using Thunderbird: http://imgur.com/Dg1Xr Face it: your post gets passed through a variety of systems outside of your control or the other readers here. Somewhere along the line, your email address is getting unobfuscated. The people replying are simply replying with what their email/NNTP clients show them. -- 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 usenet-nospam at seebs.net Thu Nov 11 18:40:00 2010 From: usenet-nospam at seebs.net (Seebs) Date: 11 Nov 2010 23:40:00 GMT Subject: How to test if a module exists? References: Message-ID: On 2010-11-11, Lawrence D'Oliveiro wrote: > In message , Tim Chase > wrote: >> Amusingly, as others have noted, you replied with an unobfuscated >> email address. > This > > would seem to be an independent, true record of what members of python-list > would see of my posting, would it not? It might or might not be. Not all of us are "members of python-list". I'm reading this on Usenet. (Where the only distinction I see is that the country name is spelled out.) > You would agree that it shows my e- > mail address as obfuscated, would you not? I don't know whether that counts as obfuscated. > So if you claim to be seeing an > unobfuscated e-mail address for my posting on python-list, you would be > lying, would you not? I have found that, in general, the chances that someone is lying are very low. The chances are much higher that they are mistaken, or that I have misunderstood their claim. Or for that matter, that there's Something Strange Going On. Say, someone's got a Usenet provider that Helpfully Fixes things, or someone set up an aliasing thing in a Very Clever newsreader some time back so they could reply to your posts and didn't notice it was then performing the same aliasing when displaying the group, or... Usually, with people who aren't obvious frothing kooks, I tend to view "lying" as being an extremely unusual explanation. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Thu Nov 11 18:41:44 2010 From: usenet-nospam at seebs.net (Seebs) Date: 11 Nov 2010 23:41:44 GMT Subject: How to test if a module exists? References: Message-ID: On 2010-11-11, Lawrence D'Oliveiro wrote: > In message , MRAB wrote: >> ... the next one at 3 Nov 2010 22:40 "Re: Allowing comments after the line >> continuation backslash" and _all_ the subsequent ones arrived with an >> _unobfuscated_ email address. > You mean from this one on >? Just as a data point: I'm using comp.lang.python via NNTP from Megabitz, reader is SLRN, and I still see ".gen.new_zealand". Sounds to me like some source may be "helpfully fixing" the address as it forwards things. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From robert.kern at gmail.com Thu Nov 11 18:42:35 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 11 Nov 2010 17:42:35 -0600 Subject: Copy Protected PDFs and PIL In-Reply-To: References: Message-ID: On 2010-11-11 14:28 , Brett Bowman wrote: > I'm trying to parse some basic details and a thumbnail from ~12,000 PDFs for my > company, but a few hundred of them are copy protected. To make matters worse, I > can't seem to trap the error it causes: whenever it happens PIL throws a "FATAL > PDF disallows copying" message and dies. An automated way to snap a picture of > the PDFs would be ideal, but I'd settle for a way to skip over them without > crashing my program. > > Any tips? I don't think PIL reads PDF files at all. Are you sure that the error comes from PIL and not some other piece of software? I would be very surprised if PIL simply crashed with such an error message. That is not a situation where a well-behaved Python library like PIL would abort without a catchable traceback. -- 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 usenet-nospam at seebs.net Thu Nov 11 18:43:49 2010 From: usenet-nospam at seebs.net (Seebs) Date: 11 Nov 2010 23:43:49 GMT Subject: How to test if a module exists? References: Message-ID: On 2010-11-11, Tim Chase wrote: >=============================== > From: Lawrence D'Oliveiro > Newsgroups: gmane.comp.python.general Oh, interesting. > Gee...your unobfuscated email addresses FROM YOU. No, from gmane. Out here in comp.lang.python (no gmane), it's obfuscated. So it sounds like there is an entity other than Lawrence deobfuscating the addresses, but it's not a specific poster here. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From aioe.org at technicalbloke.com Thu Nov 11 18:52:30 2010 From: aioe.org at technicalbloke.com (r0g) Date: Thu, 11 Nov 2010 23:52:30 +0000 Subject: How to test if a module exists? References: Message-ID: On 11/11/10 21:53, Lawrence D'Oliveiro wrote: > In message, MRAB wrote: > >> ... the next one at 3 Nov 2010 22:40 "Re: Allowing comments after the line >> continuation backslash" and _all_ the subsequent ones arrived with an >> _unobfuscated_ email address. > > You mean from this one on > ? Lawrence if you keep this up it won't be long til somebody writes a script to spam your precious bloody email address across every damn message board on the internet. All you are doing now is drawing further attention to it and causing it to be reposted over and over again, it's not a secret, you're being obnoxious and you deserve every shred of spam you get as a result. Roger From ldo at geek-central.gen.new_zealand Thu Nov 11 19:20:47 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 12 Nov 2010 13:20:47 +1300 Subject: How to test if a module exists? References: Message-ID: I have just received an admission from Barry Warsaw that a hack was done on python-list specifically to deal with bounces caused by a list member trying to reply to my obfuscated e-mail address. I have asked him to undo that hack. If he likes, he can filter out that (obfuscated) address of mine completely, I don?t mind, since I can always read replies to my postings here on USENET. The important point, as far as I?m concerned, is that I do NOT want to see my unobfuscated address appear on USENET. As for those who persisted in posting my address after being warned of this, I?m still deciding what to do. From simon at mullis.co.uk Thu Nov 11 19:24:56 2010 From: simon at mullis.co.uk (Simon Mullis) Date: Fri, 12 Nov 2010 01:24:56 +0100 Subject: parse date/time from a log entry with only strftime (and no regexen) In-Reply-To: <23d7e1bb0902050250k60cceb46jf7c1149f0b1e024@mail.gmail.com> References: <23d7e1bb0902030552j6a12dcbcy428c9ede8419fb7b@mail.gmail.com> <7e3602b0-57c0-4d9e-8c8d-fb0a5b00108d@d36g2000prf.googlegroups.com> <23d7e1bb0902050250k60cceb46jf7c1149f0b1e024@mail.gmail.com> Message-ID: This was a long time ago.... But just in case anyone googling ever has the same question, this is what I did (last year). The user just needs to supply a strftime formatted string, such as "%A, %e %b %h:%M" and this Class figures out the regex to use on the log entries... class RegexBuilder(object): """This class is used to create the regex from the strftime string. So, we pass it a strftime string and it returns a regex with capture groups.""" lookup_table = { '%a' : r"(\w{3})", # locale's abbrev day name '%A' : r"(\w{6,8})", # locale's full day name '%b' : r"(\w{3})", # abbrev month name '%B' : r"(\w{4,9})", # full month name '%d' : r"(3[0-1]|[1-2]\d|0[1-9]|[1-9]|[1-9])", # day of month '%e' : r"([1-9]|[1-3][0-9])", # day of month, no leader '%H' : r"(2[0-3]|[0-1]\d|\d)", # Hour (24h clock) '%I' : r"(1[0-2]|0[1-9]|[1-9])", # Hour (12h clock) '%j' : r"(36[0-6]|3[0-5]\d|[1-2]\d\d|0[1-9]\d|00[1-9]\ |[1-9]\d|0[1-9]|[1-9])", # Day of year '%m' : r"(1[0-2]|0[1-9]|[1-9])", # Month as decimal '%M' : r"([0-5]\d|\d)", # Minute '%S' : r"(6[0-1]|[0-5]\d|\d)", # Second '%U' : r"(5[0-3]|[0-4]\d|\d)", # Week of year (Sun = 0) '%w' : r"([0-6])", # Weekday (Sun = 0) '%W' : r"(5[0-3]|[0-5]\d|\d)", # Week of year (Mon = 0) '%y' : r"(\d{2})", # Year (no century) '%Y' : r"(\d{4})", # Year with 4 digits '%p' : r"(AM|PM)", '%P' : r"(am|pm)", '%f' : r"(\d+)", # TODO: microseconds. Only in Py 2.6+ } # Format of the keys in the table above strftime_re = r'%\w' def __init__(self, date_format): r = re.compile(RegexBuilder.strftime_re) self.created_re = r.sub(self._lookup, date_format) def _lookup(self, match): """ Regex lookup...""" return RegexBuilder.lookup_table[match.group()] > 2009/2/3 andrew cooke >> >> > > ValueError: unconverted data remains: ?this is the remainder of the >> > > log >> > > line >> > > that I do not care about >> >> you could catch the ValueError and split at the ':' in the .args >> attribute to find the extra data. ?you could then find the extra data >> in the original string, use the index to remove it, and re-parse the >> time. >> >> ugly, but should work. >> andrew >> -- >> http://mail.python.org/mailman/listinfo/python-list > > > > -- > Simon Mullis > _________________ > simon at mullis.co.uk > From ethan at stoneleaf.us Thu Nov 11 19:51:38 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 11 Nov 2010 16:51:38 -0800 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: <4CDC8F9A.9030603@stoneleaf.us> Lawrence D'Oliveiro wrote: > The important point, as far as > I?m concerned, is that I do NOT want to see my unobfuscated address appear > on USENET. You sure did a lousy job of obfuscating for someone so concerned about it. > As for those who persisted in posting my address after being warned of this, > I?m still deciding what to do. You can be such an ass sometimes. ~Ethan~ From invalid at invalid.invalid Thu Nov 11 19:55:22 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 12 Nov 2010 00:55:22 +0000 (UTC) Subject: How to test if a module exists? References: Message-ID: On 2010-11-12, Lawrence D'Oliveiro wrote: > As for those who persisted in posting my address after being warned of this, > I'm still deciding what to do. Plonk. -- Grant From steve at holdenweb.com Thu Nov 11 20:19:36 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 11 Nov 2010 17:19:36 -0800 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: <4CDC9628.4000500@holdenweb.com> On 11/11/2010 4:55 PM, Grant Edwards wrote: > On 2010-11-12, Lawrence D'Oliveiro wrote: > >> As for those who persisted in posting my address after being warned of this, >> I'm still deciding what to do. > > Plonk. > Don't you mean >> On 2010-11-12, Lawrence D'Oliveiro wrote: ? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From roy at panix.com Thu Nov 11 20:25:19 2010 From: roy at panix.com (Roy Smith) Date: Thu, 11 Nov 2010 20:25:19 -0500 Subject: is there an Python equivalent for the PHP super globals like $_POST, $_COOKIE ? References: Message-ID: In article , r0g wrote: > On 11/11/10 14:22, Stef Mientki wrote: >> I can't find how th get to PHP's equivalent of $_Post and $_Cookie ? PHP is mostly a one-trick pony. It's meant to be run as a web scripting language with Apache (or, I suppose, something else) on the front end. As a result, a lot of web-specific things like $_Post and $_Cookie are built into the language. Python is intended to be more general purpose, so things which are built in to other languages usually can be found in library modules. In this case, you probably want to look at the SimpleHTTPServer module. You may also want to look at any of several web application frameworks such as Django, Pylons, etc. I'm guessing these are overkill for the sorts of things you want to do, but they're worth at least browsing to get some idea of what's out there. For what it's worth, I've pretty much avoided PHP for all these years. My latest gig, however, has had me doing PHP for the past 3 months or so. The more I learn about PHP, the more I want to go running in the other direction. From nberg at atmos.ucla.edu Thu Nov 11 20:26:34 2010 From: nberg at atmos.ucla.edu (Neil Berg) Date: Thu, 11 Nov 2010 17:26:34 -0800 Subject: neglecting daylight savings Message-ID: <29FB1B84-3F33-48F6-AF25-DAF7EE24433D@atmos.ucla.edu> Hi Python community, I am trying to convert UTC to PST and want to neglect daylight savings even for the days that are in PDT, not PST. I simply want every UTC date to be pushed back by 8 hours and not worry about the days when the difference is really -7 due to daylight savings. I have written a function called utc_to_local (pasted below) that reads in the UTC year, month, day, and hour from a main code and returns that value in local standard time. The problem is that I can't figure out how to "turn off" the automatic daylight savings switch that appears be built in to somewhere. Here is some sample output showing the daylight savings switch on April 2, 1995 at 2am local time, which I would like to override. 1995-04-02 08 UTC = 1995-04-02 00 PST 1995-04-02 09 UTC = 1995-04-02 01 PST 1995-04-02 10 UTC = 1995-04-02 03 PDT 1995-04-02 11 UTC = 1995-04-02 04 PDT I want the third line of the output to read "1995-04-02 02" PST, the fourth to read "1995-04-02 03", etc. ___________________________ from datetime import datetime from pytz import timezone import pytz def utc_to_local(yr,mo,dy,hr): fmt = '%Y-%m-%d %H %Z' utc = pytz.utc pacific = pytz.timezone("America/Los_Angeles") utc_dt = datetime(yr,mo,dy,hr, tzinfo=utc) loc_dt = utc_dt.astimezone(pacific) # local date YY-MM-DD HR TZ print utc_dt.strftime(fmt), "=", loc_dt.strftime(fmt) loc_y = loc_dt.year # local year loc_m = loc_dt.month # local month loc_d = loc_dt.day # local day loc_h = loc_dt.hour # local hour return loc_y, loc_m, loc_d, loc_h _____________________________ Python 2.6 Mac OS X 10.6.4 _____________________________ Any help is much appreciated. Thank you in advance, Neil Berg From python.list at tim.thechases.com Thu Nov 11 20:32:19 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 11 Nov 2010 19:32:19 -0600 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: <4CDC9923.2070303@tim.thechases.com> On 11/11/10 18:20, Lawrence D'Oliveiro wrote: > As for those who persisted in posting my address after being > warned of this, I?m still deciding what to do. I've got a hint: 1) You can pursue it with various ISPs. If you choose the latter, I can fairly confidently say that any provider, upon reviewing the emails in question & seeing that your own posts hit the web unobfuscated, will laugh at you and consider your complaints a blathering annoyance spawned by your ineptitude. Mine did when you griped to them. They'll do it again. 2) you can take the advice of just about everybody in this thread and surrender the issue, finding better ways to deal with it than publicly displaying your nincompoopery. Several constructive suggestions have been given, and I'll add a few: find a better spam filter (I use Thunderbird's); use list-specific mailing addresses; use a truly obfuscated email such as "nobody at nowhere.invalid"; read via a spam-filtering source (gmane did a pretty good job until fairly recently); use a white-list for senders you actually care to read (I suspect I won't make the cut...no skin off my back). -tkc From emile at fenx.com Thu Nov 11 20:34:39 2010 From: emile at fenx.com (Emile van Sebille) Date: Thu, 11 Nov 2010 17:34:39 -0800 Subject: How to test if a module exists? In-Reply-To: References: Message-ID: On 11/11/2010 4:20 PM Lawrence D'Oliveiro said... > I have just received an admission from Barry Warsaw that a hack was done on > python-list specifically to deal with bounces caused by a list member trying > to reply to my obfuscated e-mail address. > > I have asked him to undo that hack. If he likes, he can filter out that > (obfuscated) address of mine completely, I don?t mind, since I can always > read replies to my postings here on USENET. The important point, as far as > I?m concerned, is that I do NOT want to see my unobfuscated address appear > on USENET. > > As for those who persisted in posting my address after being warned of this, > I?m still deciding what to do. Well, you got you're work cut out for you. Google says... Results 1 - 10 of about 17,300 for ldo at geek-central.gen.***** Emile From ben+python at benfinney.id.au Thu Nov 11 20:35:21 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 12 Nov 2010 12:35:21 +1100 Subject: neglecting daylight savings References: Message-ID: <87k4kjb9ye.fsf@benfinney.id.au> Neil Berg writes: > I am trying to convert UTC to PST and want to neglect daylight savings > even for the days that are in PDT, not PST. Then you don't want ?PST?. That name entails all the rules of the time zone. If that's not what you want, don't ask timezone libraries for it. Similarly for the timezone named ?America/Los_Angeles?; if you ask for that you are explicitly asking for all the time changes that zone entails. If you don't want it, don't ask for it. If you want exactly the same offset all the time, regardless of government DST silliness, ask for it: ?UTC-8?, for example, or whatever the fixed offset from UTC you want. -- \ ?Outside of a dog, a book is man's best friend. Inside of a | `\ dog, it's too dark to read.? ?Groucho Marx | _o__) | Ben Finney From emile at fenx.com Thu Nov 11 20:41:11 2010 From: emile at fenx.com (Emile van Sebille) Date: Thu, 11 Nov 2010 17:41:11 -0800 Subject: neglecting daylight savings In-Reply-To: <29FB1B84-3F33-48F6-AF25-DAF7EE24433D@atmos.ucla.edu> References: <29FB1B84-3F33-48F6-AF25-DAF7EE24433D@atmos.ucla.edu> Message-ID: On 11/11/2010 5:26 PM Neil Berg said... > Hi Python community, > > I am trying to convert UTC to PST and want to neglect daylight savings even for the days that are in PDT, not PST. IIRC, that what Arizona time is. Why not use it instead of attempting to redefine PST? Emile From martin at address-in-sig.invalid Thu Nov 11 21:38:28 2010 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Fri, 12 Nov 2010 02:38:28 +0000 (UTC) Subject: is there an Python equivalent for the PHP super globals like $_POST, $_COOKIE ? References: <4CDBFC41.6080404@gmail.com> Message-ID: On Thu, 11 Nov 2010 13:01:01 -0500, Steve Holden wrote: > Moving from one language to anther is not just a matter of > transliterating the code. Of you try that you will end up with a messy > code base that looks like PHP written in Python. > "The determined Real Programmer can write Fortran programs in any language." - from "Real Programmers don't use Pascal". -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From usenet-nospam at seebs.net Thu Nov 11 22:03:00 2010 From: usenet-nospam at seebs.net (Seebs) Date: 12 Nov 2010 03:03:00 GMT Subject: How to test if a module exists? References: Message-ID: On 2010-11-12, Lawrence D'Oliveiro wrote: > I have just received an admission from Barry Warsaw that a hack was done on > python-list specifically to deal with bounces caused by a list member trying > to reply to my obfuscated e-mail address. That's... Fascinating. But it does mean that the people who were reporting seeing it were, in fact, merely accurately reporting on what they saw. > As for those who persisted in posting my address after being warned of this, > I???m still deciding what to do. I would suggest, very strongly: Nothing. 1. Genie, bottle, out. 2. At least some were quoting your posts to show what they looked like, which is hardly a great abuse. Look... You're dealing with humans. Walk up to a human holding something. Say "smell this, it smells like ass!". Watch them smell it, and then react with shock if it smells bad. Tell them something is too hot to touch safely, and they will touch it to see whether this is true. You told them that your posts were under an obfuscated address, so they quoted the address they saw and said "you mean this one?" None of the people in question were the ones who decided to de-obfuscate the address. None of them had, prior to your announcement, any way to know that de-obfuscation was even occurring, and from all the evidence available to them, the most reasonable inference would have been that you were mistaken about how your posting software was configured. When I offered the speculative notion that some gateway somewhere was deobfuscating this address, I didn't think it was *likely*, merely "more likely than people lying". As a matter of fact, that you jumped directly to the accusation that other people were lying suggests strongly that you the possibility that this was happening *did not even occur to you*. I put it to you that if the possibility is implausible and unusual enough that it did not even *occur* to you to consider it until multiple people had pointed to multiple citations, it is likely that it *also* did not occur to the various other participants. All they could see was posts by you, showing a particular email address, in which you claimed that it was very rude for people other than you to include that email address in posts. I would also suggest a more general observation: Had you approached this with less hostility, I suspect you would have gotten more cooperative responses, rather than indignation. People accused of doing a thing that they very definitely did not do are not going to be inclined to respond in a helpful manner. Had your post said something like: I notice that in your post, my address is no longer obfuscated. I much prefer that my address be obfuscated on Usenet, and when I send it out, it usually is; see for instance this source (link to python-list) showing that my message had an obfuscated address when it reached python-list. ... I think you would have gotten more helpful responses, and we might have more quickly tracked down that it was apparently specific to some of the many mirrors of this traffic. Finally, last but not least: Since the gmane.* archives have that address, and web crawlers are orders of magnitude more common and more active than usenet crawlers, I would consider the question thoroughly academic at this point. The address is out there. Further use of it on Usenet is unlikely to have a statistically measurable impact. Just as a side note: I have an unobfuscated address in both my signature and my From line. This address is live, it delivers to me, and so on. Yes, I get spam to it. Of the last 26,061 spams I've gotten, it's produced a grand total of 239. So, under 1% of my incoming spam. You can measure the interval during which I cared about that, but if you try to represent it as seconds using 32-bit floating point, it'll turn into 0 because it's under FLOAT_EPSILON. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From lists at asd-group.com Thu Nov 11 23:48:29 2010 From: lists at asd-group.com (John Bond) Date: Fri, 12 Nov 2010 04:48:29 +0000 Subject: Extending Thunderbird mail client with Python Message-ID: <4CDCC71D.6050805@asd-group.com> Anyone have any experience with this, ideally using Python 3? I'd like to sync my Thunderbird contacts with various things including my mobile phone. Of course, I want to do it with Python! I've seen some stuff around, eg. an XPI that provides Python bindings to the Mozilla XPCOM APIs (through which I imagine you can access Thunderbird data like its contacts database), but it doesn't seem maintained or ported to Python 3. Cheers, JB From ldo at geek-central.gen.new_zealand Thu Nov 11 23:53:42 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 12 Nov 2010 17:53:42 +1300 Subject: How to test if a module exists? References: Message-ID: I have asked for my messages to be filtered from being distributed to python-list. As far as I?m concerned, the lot of you can bloody piss off. From iamforufriends at gmail.com Thu Nov 11 23:56:19 2010 From: iamforufriends at gmail.com (fun for u all) Date: Thu, 11 Nov 2010 20:56:19 -0800 (PST) Subject: HAI WANT TO MEET FRIENDS FOR REAL FUN, CLICK FRIENDS-4-FUN Message-ID: <6d2d0754-4eb8-4e9b-9ad1-58d1ab1d595f@j29g2000prf.googlegroups.com> HAI WANT TO MEET FRIENDS FOR REAL FUN, CLICK FRIENDS-4-FUN HAI WANT TO MEET FRIENDS FOR REAL FUN, CLICK FRIENDS-4-FUN http://tinyurl.com/friend-4-fun or http://goo.gl/1bour or http://tinyurl.com/friend-4-fun1 From iamforufriends at gmail.com Thu Nov 11 23:56:23 2010 From: iamforufriends at gmail.com (fun for u all) Date: Thu, 11 Nov 2010 20:56:23 -0800 (PST) Subject: HAI WANT TO MEET FRIENDS FOR REAL FUN, CLICK FRIENDS-4-FUN Message-ID: <32fd9d96-3d73-4a33-8a7d-833722745979@i4g2000pro.googlegroups.com> HAI WANT TO MEET FRIENDS FOR REAL FUN, CLICK FRIENDS-4-FUN HAI WANT TO MEET FRIENDS FOR REAL FUN, CLICK FRIENDS-4-FUN http://tinyurl.com/friend-4-fun or http://goo.gl/1bour or http://tinyurl.com/friend-4-fun1 From ldo at geek-central.gen.new_zealand Fri Nov 12 00:58:11 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 12 Nov 2010 18:58:11 +1300 Subject: subprocess.Popen deadlocks References: <2cf9a225-7d1c-4490-8a62-807e79bdd06a@n30g2000vbb.googlegroups.com> Message-ID: In message <2cf9a225-7d1c-4490-8a62-807e79bdd06a at n30g2000vbb.googlegroups.com>, eraserix wrote: > I try to control several process from a python script. Each process is > started from a thread, the threads just wait() for the child to exit > and can then be joined. Main waits for SIGINT. After it received the > signal, it will send a signal to the processes spawned by the threads > and then join() the threads (which should terminate after their > process exits) Threading is always likely to be a source of bugs, whether in your code or the Python library. In this case, your threads don?t even seem to be doing anything useful. Why not skip all the threads and just spawn all the processes in your main loop? Then after getting the SIGINT, send that signal to all your processes, and then do a bunch of os.waitpid calls to clean them all up. From wuwei23 at gmail.com Fri Nov 12 01:43:31 2010 From: wuwei23 at gmail.com (alex23) Date: Thu, 11 Nov 2010 22:43:31 -0800 (PST) Subject: How to test if a module exists? References: Message-ID: On Nov 12, 2:53?pm, Lawrence D'Oliveiro wrote: > I have asked for my messages to be filtered from being distributed to > python-list. As far as I?m concerned, the lot of you can bloody piss off. Oh Lawrence, the feeling is mutual. At least then we'd be spared your constant indignation at Windows. From pythonisland at gmail.com Fri Nov 12 03:38:04 2010 From: pythonisland at gmail.com (ChunLai Zhu) Date: Fri, 12 Nov 2010 16:38:04 +0800 Subject: What is the information I can get? Message-ID: * Hello,I have knew the python mail list neamed python-list at python.org,I want to know what is the information I can get from the mail list?Thank you!* -- *=:-)* *Keep Stupid,Keep Thirsty!* -------------- next part -------------- An HTML attachment was scrubbed... URL: From pavlovevidence at gmail.com Fri Nov 12 03:46:06 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 12 Nov 2010 00:46:06 -0800 (PST) Subject: os.tmpfile() vs. tempfile.TemporaryFile() References: <4cdc36cf$0$1665$742ec2ed@news.sonic.net> Message-ID: On Nov 11, 10:32?am, John Nagle wrote: > ? ?Is there any reason to prefer "tempfile.TemporaryFile()" > over "os.tmpfile()"? ?Both create a nameless temporary file > that will be deleted on close. os.tmpfile calls your OS's tmpfile system call. tempfile.TemporaryFile creates the temporary file itself. So, if you trust your OS more than Python, use os.tempfile. I-only-use-tempfile-module-ly yr's, Carl Banks From stefan_ml at behnel.de Fri Nov 12 03:47:21 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 12 Nov 2010 09:47:21 +0100 Subject: Am I The Only One Who Keeps Reading =?UTF-8?B?4oCcTnVtcHnigJ0=?= =?UTF-8?B?IGFzIOKAnE51bXB0eeKAnT8=?= In-Reply-To: References: <940162c6-b61a-4bb7-9965-6e155716cda8@n30g2000vbb.googlegroups.com> <87hbfoycov.fsf@gmail.com> Message-ID: rantingrick, 11.11.2010 19:07: > On Nov 10, 5:35 pm, Arnaud Delobelle wrote: > >> So pypy is "pie-pee", not "pie-pie" or "pee-pee". With that edifying >> thought, I'm off to bed. > > > :) Good catch! > > Actually i've always thought of pypi as pie-pie and Scipy as cy-pie. > Num-pie does not work for me. Maybe some linguist could chime in and > explain these odd tendencies...? Ah, that's just English. Never mind. http://www.mipmip.org/tidbits/pronunciation.shtml Stefan From pythonisland at gmail.com Fri Nov 12 03:57:41 2010 From: pythonisland at gmail.com (ChunLai Zhu) Date: Fri, 12 Nov 2010 16:57:41 +0800 Subject: How can I read the information? Message-ID: Hi, I'm learning the python program language.I get someinformation from the python-list,but I felt boring to read a text-information ,so how can I read the python-list's FAQs quickly? Thank you! -- *=:-)* *Keep Stupid,Keep Thirsty!* -------------- next part -------------- An HTML attachment was scrubbed... URL: From research at johnohagan.com Fri Nov 12 04:47:26 2010 From: research at johnohagan.com (John O'Hagan) Date: Fri, 12 Nov 2010 09:47:26 +0000 Subject: Sending changed parameters into nested generators Message-ID: <201011120947.27356.research@johnohagan.com> I have a generator function which takes as arguments another generator and a dictionary of other generators like this: def modgen(gen, gendict): for item in gen(): for k, v in gendict: do_something_called_k(item, v.next()) yield item I want to control the output of this generator by sending in new values to the generators in gendict. I have done this using a list in a simple generator like: def loop(lis): while True: for item in lis: yield item and write: lis[:] = [new_value] to see the output of modgen() change. However, I want to be able to use other modgen() instances as values in gendict, each with a gendict of its own, which in turn may contain modgen() instances, and so on recursively. The recursion stops wherever a simple generator like loop() is encountered. To this end I've made nested dictionaries like this example: {'a':[1,2,3], 'b':{'a':[4,5,6]}, 'c':{'a':{'a':[7,8,9], 'b':{'c':[10]}}}} and used a recursive function to convert them to the gendict I'm after like this: def iterized(dic): itdic = {} for k, v in dic.items(): if isinstance(v, dict): itval = iterized(v) itdic[k] = maingen(itval) else: itdic[k] = loop(v) return itdic Then I can write: recdic = {nested:dictionary} gendict = iterized(recdict) mygen = modgen(gen, gendict) The problem is that the gendict looks like this: {'a': , 'b': , 'c': } so I have no direct access from there to the sub-generators. I have tried using a deep update function on the original nested dictionary, but this only works if I change the contents of a list, not if I want to, say, change a node from a list to a dictionary or vice versa, because in that case I'm not operating on the same object the generator is using. If anyone's still reading :) , how can I send new values to arbitrary sub- generators? Thanks, john From girish.cfc at gmail.com Fri Nov 12 06:15:56 2010 From: girish.cfc at gmail.com (Girish) Date: Fri, 12 Nov 2010 03:15:56 -0800 (PST) Subject: COM ERROR Message-ID: Hello All, I have an issue while accessing COM API of an application. I got following error when I tried to run following command: win32com.client.Dispatch() File "C:\Python25\Lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx) File "C:\Python25\Lib\site-packages\win32com\client\dynamic.py", line 98, in _GetGoodDispatchAndUserName return (_GetGoodDispatch(IDispatch, clsctx), userName) File "C:\Python25\Lib\site-packages\win32com\client\dynamic.py", line 78, in _GetGoodDispatch IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch) com_error: (-2147024882, 'Not enough storage is available to complete this operation.', None, None) Your help would be appreciated. Thanks, Girish. From iamforufriends at gmail.com Fri Nov 12 07:22:01 2010 From: iamforufriends at gmail.com (fun for u all) Date: Fri, 12 Nov 2010 04:22:01 -0800 (PST) Subject: HAI WANT TO MEET FRIENDS FOR REAL FUN, CLICK FRIENDS-4-FUN Message-ID: HAI WANT TO MEET FRIENDS FOR REAL FUN, CLICK FRIENDS-4-FUN http://tinyurl.com/friend-4-fun or http://goo.gl/1bour or http://tinyurl.com/friend-4-fun1 From ndbecker2 at gmail.com Fri Nov 12 08:05:52 2010 From: ndbecker2 at gmail.com (Neal Becker) Date: Fri, 12 Nov 2010 08:05:52 -0500 Subject: argparse '--' not working? Message-ID: It is a 'standard' behaviour that a lone '--' terminates options. argparse says: If you have positional arguments that must begin with '-' and don?t look like negative numbers, you can insert the pseudo-argument '--' which tells parse_args that everything after that is a positional argument: But it doesn't seem to work: import argparse parser = argparse.ArgumentParser() parser.add_argument ('--submit', '-s', action='store_true') parser.add_argument ('--list', '-l', action='store_true') opt = parser.parse_args() ./queue --submit -- test1.py -n usage: queue [-h] [--submit] [--list] queue: error: unrecognized arguments: -- test1.py -n From __peter__ at web.de Fri Nov 12 08:31:51 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 12 Nov 2010 14:31:51 +0100 Subject: argparse '--' not working? References: Message-ID: Neal Becker wrote: > It is a 'standard' behaviour that a lone '--' terminates options. > argparse says: > > If you have positional arguments that must begin with '-' and don?t look > like negative numbers, you can insert the pseudo-argument '--' which tells > parse_args that everything after that is a positional argument: /If/ you have positonal arguments... > But it doesn't seem to work: > > import argparse > > parser = argparse.ArgumentParser() > parser.add_argument ('--submit', '-s', action='store_true') > parser.add_argument ('--list', '-l', action='store_true') > opt = parser.parse_args() > > ./queue --submit -- test1.py -n > usage: queue [-h] [--submit] [--list] > queue: error: unrecognized arguments: -- test1.py -n Unlike optparse in argparse you must declare positional arguments, too: >>> import argparse >>> parser = argparse.ArgumentParser() >>> parser.add_argument("-s", action="store_true") [snip] >>> parser.add_argument("whatever", nargs="*") [snip] >>> parser.parse_args(["-s", "yadda"]) Namespace(s=True, whatever=['yadda']) >>> parser.parse_args(["--", "-s", "yadda"]) Namespace(s=False, whatever=['-s', 'yadda']) Peter From johann.spies at gmail.com Fri Nov 12 08:32:56 2010 From: johann.spies at gmail.com (Johann Spies) Date: Fri, 12 Nov 2010 15:32:56 +0200 Subject: http-headers for soappy Message-ID: How do I pass the following header Header name: Cookie Header value: [SID="the session identifier"] to SOAP.HeaderHandler(): class HeaderHandler: # Initially fail out if there are any problems. def __init__(self, header, attrs): for i in header.__dict__.keys(): if i[0] == "_": continue d = getattr(header, i) try: fault = int(attrs[id(d)][(NS.ENV, 'mustUnderstand')]) except: fault = 0 if fault: raise faultType, ("%s:MustUnderstand" % NS.ENV_T, "Required Header Misunderstood", "%s" % i) Regards Johann -- May grace and peace be yours in abundance through the full knowledge of God and of Jesus our Lord! His divine power has given us everything we need for life and godliness through the full knowledge of the one who called us by his own glory and excellence. 2 Pet. 1:2b,3a -------------- next part -------------- An HTML attachment was scrubbed... URL: From neilc at norwich.edu Fri Nov 12 08:54:39 2010 From: neilc at norwich.edu (Neil Cerutti) Date: 12 Nov 2010 13:54:39 GMT Subject: is there an Python equivalent for the PHP super globals like $_POST, $_COOKIE ? References: <4CDBFC41.6080404@gmail.com> Message-ID: <8k4v8vFhiiU5@mid.individual.net> On 2010-11-12, Martin Gregorie wrote: > On Thu, 11 Nov 2010 13:01:01 -0500, Steve Holden wrote: > >> Moving from one language to anther is not just a matter of >> transliterating the code. Of you try that you will end up with a messy >> code base that looks like PHP written in Python. > > "The determined Real Programmer can write Fortran programs in > any language." They probably won't run quite as as fast, though. -- Neil Cerutti From greentackle at gmail.com Fri Nov 12 09:12:19 2010 From: greentackle at gmail.com (Micah Carrick) Date: Fri, 12 Nov 2010 06:12:19 -0800 Subject: Use company name for module Message-ID: My company is working on releasing some of our code as open-source python modules. I don't want my "foo" module conflicting with other modules called "foo" on PyPi or github or a user's system. Is there anything wrong, from a conventions standpoint, with having modules like company.foo and company.bar even if foo and bar are not necessarily related other than being released by us? I really don't like the cryptic module names or things like foo2 and the like. -- Micah Carrick - http://www.micahcarrick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From manu3d at gmail.com Fri Nov 12 09:18:52 2010 From: manu3d at gmail.com (Emanuele D'Arrigo) Date: Fri, 12 Nov 2010 06:18:52 -0800 (PST) Subject: A matter of queues, tasks and multiprocessing References: <9e6f2dcc-7d15-4162-b3e9-9ef77a0b8980@n30g2000vbb.googlegroups.com> <41980a52-5bf3-4212-a0f4-a9968c2eb523@i17g2000vbq.googlegroups.com> Message-ID: On Nov 11, 3:13?pm, Tim Golden wrote: > Try Celery > > ? ?http://ask.github.com/celery/getting-started/introduction.html Thank you Tim, looks very interesting! Manu From eraserix at gmail.com Fri Nov 12 09:28:45 2010 From: eraserix at gmail.com (eraserix) Date: Fri, 12 Nov 2010 06:28:45 -0800 (PST) Subject: subprocess.Popen deadlocks References: <2cf9a225-7d1c-4490-8a62-807e79bdd06a@n30g2000vbb.googlegroups.com> Message-ID: <165f506f-f5d2-4ae5-b80a-1c445423274c@n24g2000prj.googlegroups.com> On Nov 12, 6:58?am, Lawrence D'Oliveiro wrote: > In message > <2cf9a225-7d1c-4490-8a62-807e79bdd... at n30g2000vbb.googlegroups.com>, > > Why not skip all the threads and just spawn all the processes in your main > loop? Then after getting the SIGINT, send that signal to all your processes, > and then do a bunch of os.waitpid calls to clean them all up. Thanks for the hint. You are right, the problem could be solved singlethreaded by doing some sort of polling (my description simplified things a bit) avoiding the multithreading problems altogether. I had another look at the subprocesses module and discovered the actual bug. I describe it in issue 10394. Christoph From data.2 at rediff.com Fri Nov 12 10:20:41 2010 From: data.2 at rediff.com (gaurav) Date: Fri, 12 Nov 2010 07:20:41 -0800 (PST) Subject: Careers at your place. Message-ID: <707f1f3a-7191-4c11-8cb5-f492bf5f3e95@j29g2000prf.googlegroups.com> Your desirable careers. Railroad employers, opportunities in only on the site for government, banking and data entry. http://rojgars.webs.com/Railwayjobs.htm http://rojgars1.webs.com/gov.htm Local careers in Management work. More careers in Management. http://managementjobs.webs.com/pm.htm & http://topcareer.webs.com/humanresourcemgmt.htm From robert.kern at gmail.com Fri Nov 12 10:50:46 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 12 Nov 2010 09:50:46 -0600 Subject: Use company name for module In-Reply-To: References: Message-ID: On 11/12/10 8:12 AM, Micah Carrick wrote: > My company is working on releasing some of our code as open-source python > modules. I don't want my "foo" module conflicting with other modules called > "foo" on PyPi or github or a user's system. Is there anything wrong, from a > conventions standpoint, with having modules like company.foo and company.bar > even if foo and bar are not necessarily related other than being released by us? > I really don't like the cryptic module names or things like foo2 and the like. Yes, using namespace packages. You need to use `distribute` in your setup.py in order to accomplish this. http://pypi.python.org/pypi/distribute/ http://packages.python.org/distribute/setuptools.html#namespace-packages -- 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 ian.g.kelly at gmail.com Fri Nov 12 11:36:23 2010 From: ian.g.kelly at gmail.com (Ian) Date: Fri, 12 Nov 2010 08:36:23 -0800 (PST) Subject: Sending changed parameters into nested generators References: Message-ID: <44041b0d-e86a-4044-8077-2d8a1af6966c@r31g2000prg.googlegroups.com> On Nov 12, 2:47?am, "John O'Hagan" wrote: > I have tried using a deep update function on the original nested dictionary, > but this only works if I ?change the contents of a list, not if I want to, > say, change a node from a list to a dictionary or vice versa, because in that > case I'm not operating on the same object the generator is using. > > If anyone's still reading :) , how can I send new values to arbitrary sub- > generators? I think you're focusing too heavily on generators. Just because a nifty language construct exists doesn't mean that it's the right thing to use in all situations. It sounds to me that what you really want are objects with .next() methods and externally visible state -- i.e. iterators. Or it might be that coroutines are what you're really after, although I think they would be difficult to manage in the way that you are doing. You can view the docs on the pythonic approach to coroutines at: http://docs.python.org/whatsnew/2.5.html#pep-342-new-generator-features Cheers, Ian From mygogo2011 at gmail.com Fri Nov 12 12:57:29 2010 From: mygogo2011 at gmail.com (PHP.CCC) Date: Fri, 12 Nov 2010 09:57:29 -0800 (PST) Subject: === LOAN AND INTERNSHIP PROGRAM === Message-ID: <0c9b9ae3-ce25-4b70-94d0-bb97aa02e810@i4g2000pro.googlegroups.com> === LOAN AND INTERNSHIP PROGRAM === European Union (EU) allows for the free movement of goods between Italy and other member states: Austria, Belgium, Bulgaria, Cyprus, Czech Republic, Denmark, Estonia, Finland, France, Germany, Greece, Hungary, Ireland, Latvia, Lithuania, Luxembourg, Malta, Netherlands, Poland, Portugal, Romania, Slovakia, Slovenia, Sweden, and United Kingdom. The European Union has numerous bilateral and multilateral agreements, such as the Agreement on Textiles and Clothing (formerly the Multi-Fiber Agreement), PECO countries Agreement, Israel Agreement, Turkey Agreement, Baltic Sea countries Agreement. http://to.ly/81Qj From arnodel at gmail.com Fri Nov 12 13:09:21 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Fri, 12 Nov 2010 18:09:21 +0000 Subject: Sending changed parameters into nested generators References: Message-ID: <87d3qaxvla.fsf@gmail.com> "John O'Hagan" writes: > I have a generator function which takes as arguments another generator and a > dictionary of other generators like this: > > def modgen(gen, gendict): > for item in gen(): > for k, v in gendict: > do_something_called_k(item, v.next()) > yield item > > I want to control the output of this generator by sending in new values to the > generators in gendict. I have done this using a list in a simple generator > like: > > def loop(lis): > while True: > for item in lis: > yield item > > and write: > > lis[:] = [new_value] > > to see the output of modgen() change. > > However, I want to be able to use other modgen() instances as values in > gendict, each with a gendict of its own, which in turn may contain modgen() > instances, and so on recursively. The recursion stops wherever a simple > generator like loop() is encountered. > > To this end I've made nested dictionaries like this example: > > {'a':[1,2,3], 'b':{'a':[4,5,6]}, 'c':{'a':{'a':[7,8,9], 'b':{'c':[10]}}}} > > and used a recursive function to convert them to the gendict I'm after like > this: > > def iterized(dic): > itdic = {} > for k, v in dic.items(): > if isinstance(v, dict): > itval = iterized(v) > itdic[k] = maingen(itval) > else: > itdic[k] = loop(v) > return itdic > > Then I can write: > > recdic = {nested:dictionary} > gendict = iterized(recdict) > mygen = modgen(gen, gendict) > > The problem is that the gendict looks like this: > > {'a': , 'b': 0x8841464>, 'c': } > > so I have no direct access from there to the sub-generators. > > I have tried using a deep update function on the original nested dictionary, > but this only works if I change the contents of a list, not if I want to, > say, change a node from a list to a dictionary or vice versa, because in that > case I'm not operating on the same object the generator is using. > > If anyone's still reading :) , how can I send new values to arbitrary sub- > generators? > > Thanks, > > john Try instead: def loop(d, k): while True: for x in d[k]: yield x def iterized(dic): itdic = {} for k, v in dic.items(): if isinstance(v, dict): itval = iterized(v) itdic[k] = maingen(itval) else: itdic[k] = loop(dic, k) return itdic Untested. -- Arnaud From jarausch at igpm.rwth-aachen.de Fri Nov 12 13:32:24 2010 From: jarausch at igpm.rwth-aachen.de (Helmut Jarausch) Date: 12 Nov 2010 18:32:24 GMT Subject: importing site fails - why? Message-ID: <8k5fhoFd8sU1@mid.dfncis.de> Hi, as often before, I've cloned a working system (GenToo) onto another machine. There, from a livecd and chroot to the cloned root partition python -v import site fails with the following error Python 2.6.6 (r266:84292, Oct 13 2010, 09:06:24) [GCC 4.4.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. dlopen("/usr/lib64/python2.6/lib-dynload/readline.so", 2); import readline # dynamically loaded from /usr/lib64/python2.6/lib- dynload/readline.so >>> import site # /usr/lib64/python2.6/site.pyc matches /usr/lib64/python2.6/site.py import site # precompiled from /usr/lib64/python2.6/site.pyc Traceback (most recent call last): File "", line 1, in File "/usr/lib64/python2.6/site.py", line 526, in main() File "/usr/lib64/python2.6/site.py", line 509, in main known_paths = addsitepackages(known_paths) File "/usr/lib64/python2.6/site.py", line 289, in addsitepackages addsitedir(sitedir, known_paths) File "/usr/lib64/python2.6/site.py", line 185, in addsitedir addpackage(sitedir, name, known_paths) File "/usr/lib64/python2.6/site.py", line 159, in addpackage if not dircase in known_paths and os.path.exists(dir): File "/usr/lib64/python2.6/genericpath.py", line 18, in exists st = os.stat(path) TypeError: stat() argument 1 must be encoded string without NULL bytes, not str >>>? I'm puzzled and I'd appreciate any hints to the reason for this failure. Many thanks, Helmut. From stefan.sonnenberg at pythonmeister.com Fri Nov 12 13:42:46 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Fri, 12 Nov 2010 19:42:46 +0100 Subject: importing site fails - why? In-Reply-To: <8k5fhoFd8sU1@mid.dfncis.de> References: <8k5fhoFd8sU1@mid.dfncis.de> Message-ID: <4CDD8AA6.30704@pythonmeister.com> Am 12.11.2010 19:32, schrieb Helmut Jarausch: > Hi, > > as often before, I've cloned a working system (GenToo) onto another > machine. There, from a livecd and chroot to the cloned root partition > > python -v > import site > > fails with the following error > Python 2.6.6 (r266:84292, Oct 13 2010, 09:06:24) > [GCC 4.4.4] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > dlopen("/usr/lib64/python2.6/lib-dynload/readline.so", 2); > import readline # dynamically loaded from /usr/lib64/python2.6/lib- > dynload/readline.so >>>> import site > # /usr/lib64/python2.6/site.pyc matches /usr/lib64/python2.6/site.py > import site # precompiled from /usr/lib64/python2.6/site.pyc > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib64/python2.6/site.py", line 526, in > main() > File "/usr/lib64/python2.6/site.py", line 509, in main > known_paths = addsitepackages(known_paths) > File "/usr/lib64/python2.6/site.py", line 289, in addsitepackages > addsitedir(sitedir, known_paths) > File "/usr/lib64/python2.6/site.py", line 185, in addsitedir > addpackage(sitedir, name, known_paths) > File "/usr/lib64/python2.6/site.py", line 159, in addpackage > if not dircase in known_paths and os.path.exists(dir): > File "/usr/lib64/python2.6/genericpath.py", line 18, in exists > st = os.stat(path) > TypeError: stat() argument 1 must be encoded string without NULL bytes, > not str >>>> ? > I'm puzzled and I'd appreciate any hints to the reason for this failure. > > Many thanks, > Helmut. You gave the answer yourself. Chrooting does not automatically mean your SO cache is where it should be for the target system. Perhaps your livecd is newer/older than the target system or simply the python in live environment is not (most likely) compiled as the one in the target system. That is _one_ reason I stoped using gentoo and switched to debian/ubuntu. -------------- next part -------------- A non-text attachment was scrubbed... Name: stefan_sonnenberg.vcf Type: text/x-vcard Size: 232 bytes Desc: not available URL: From celiadoug at mchsi.com Fri Nov 12 14:05:38 2010 From: celiadoug at mchsi.com (Doug Stell) Date: Fri, 12 Nov 2010 12:05:38 -0700 Subject: Supporting Python 2.x and 3.x on a PC Message-ID: I support multiple projects, some of which will remain on Python 2.x and some of which want to use Python 3.1.2. While I have installed both on my Windows PC, only the last installed version can be used. I do not have admin rights on the machine, so altering registry settings is not an option. Any guidance on how I can select between the versions? Thanks From stefan.sonnenberg at pythonmeister.com Fri Nov 12 14:23:42 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Fri, 12 Nov 2010 20:23:42 +0100 Subject: Supporting Python 2.x and 3.x on a PC In-Reply-To: References: Message-ID: <4CDD943E.30909@pythonmeister.com> Am 12.11.2010 20:05, schrieb Doug Stell: > I support multiple projects, some of which will remain on Python 2.x > and some of which want to use Python 3.1.2. While I have installed > both on my Windows PC, only the last installed version can be used. I > do not have admin rights on the machine, so altering registry settings > is not an option. Any guidance on how I can select between the > versions? > > Thanks " only the last installed version can be used" What does that mean ? I have several versions installed, and switch between them only by taking the desired interpreter. C:\Python26\python.exe gives a 2.6 python C:\Python27\python.exe gives a 2.7 python If I only start python on windows shell, the latter is run. If I just do this: SET PATH=C:\Python26;%PATH% entering just "python" on the cmd prompt gives me a 2.6 python. Hope this helps. -------------- next part -------------- A non-text attachment was scrubbed... Name: stefan_sonnenberg.vcf Type: text/x-vcard Size: 223 bytes Desc: not available URL: From jarausch at igpm.rwth-aachen.de Fri Nov 12 14:24:26 2010 From: jarausch at igpm.rwth-aachen.de (Helmut Jarausch) Date: 12 Nov 2010 19:24:26 GMT Subject: importing site fails - why? References: <8k5fhoFd8sU1@mid.dfncis.de> Message-ID: <8k5ijaFd8sU2@mid.dfncis.de> On Fri, 12 Nov 2010 19:42:46 +0100, Stefan Sonnenberg-Carstens wrote: > Am 12.11.2010 19:32, schrieb Helmut Jarausch: >> Hi, >> >> as often before, I've cloned a working system (GenToo) onto another >> machine. There, from a livecd and chroot to the cloned root partition >> >> python -v >> import site >> >> fails with the following error >> Python 2.6.6 (r266:84292, Oct 13 2010, 09:06:24) [GCC 4.4.4] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. >> dlopen("/usr/lib64/python2.6/lib-dynload/readline.so", 2); import >> readline # dynamically loaded from /usr/lib64/python2.6/lib- >> dynload/readline.so >>>>> import site >> # /usr/lib64/python2.6/site.pyc matches /usr/lib64/python2.6/site.py >> import site # precompiled from /usr/lib64/python2.6/site.pyc Traceback >> (most recent call last): >> File "", line 1, in >> File "/usr/lib64/python2.6/site.py", line 526, in >> main() >> File "/usr/lib64/python2.6/site.py", line 509, in main >> known_paths = addsitepackages(known_paths) >> File "/usr/lib64/python2.6/site.py", line 289, in addsitepackages >> addsitedir(sitedir, known_paths) >> File "/usr/lib64/python2.6/site.py", line 185, in addsitedir >> addpackage(sitedir, name, known_paths) >> File "/usr/lib64/python2.6/site.py", line 159, in addpackage >> if not dircase in known_paths and os.path.exists(dir): >> File "/usr/lib64/python2.6/genericpath.py", line 18, in exists >> st = os.stat(path) >> TypeError: stat() argument 1 must be encoded string without NULL bytes, >> not str >>>>> ? >> I'm puzzled and I'd appreciate any hints to the reason for this >> failure. >> >> Many thanks, >> Helmut. > You gave the answer yourself. > Chrooting does not automatically mean your SO cache is where it should > be for the target system. > Perhaps your livecd is newer/older than the target system or simply the > python in live environment > is not (most likely) compiled as the one in the target system. > It has been working dozens of time! Are you saying, an ldconfig would rectify the situation? Unfortunately, I can only test it on monday. Thanks, Helmut. -- Helmut Jarausch Lehrstuhl fuer Numerische Mathematik RWTH - Aachen University D 52056 Aachen, Germany From stefan.sonnenberg at pythonmeister.com Fri Nov 12 14:35:11 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Fri, 12 Nov 2010 20:35:11 +0100 Subject: importing site fails - why? In-Reply-To: <8k5ijaFd8sU2@mid.dfncis.de> References: <8k5fhoFd8sU1@mid.dfncis.de> <8k5ijaFd8sU2@mid.dfncis.de> Message-ID: <4CDD96EF.20603@pythonmeister.com> Am 12.11.2010 20:24, schrieb Helmut Jarausch: > On Fri, 12 Nov 2010 19:42:46 +0100, Stefan Sonnenberg-Carstens wrote: > >> Am 12.11.2010 19:32, schrieb Helmut Jarausch: >>> Hi, >>> >>> as often before, I've cloned a working system (GenToo) onto another >>> machine. There, from a livecd and chroot to the cloned root partition >>> >>> python -v >>> import site >>> >>> fails with the following error >>> Python 2.6.6 (r266:84292, Oct 13 2010, 09:06:24) [GCC 4.4.4] on linux2 >>> Type "help", "copyright", "credits" or "license" for more information. >>> dlopen("/usr/lib64/python2.6/lib-dynload/readline.so", 2); import >>> readline # dynamically loaded from /usr/lib64/python2.6/lib- >>> dynload/readline.so >>>>>> import site >>> # /usr/lib64/python2.6/site.pyc matches /usr/lib64/python2.6/site.py >>> import site # precompiled from /usr/lib64/python2.6/site.pyc Traceback >>> (most recent call last): >>> File "", line 1, in >>> File "/usr/lib64/python2.6/site.py", line 526, in >>> main() >>> File "/usr/lib64/python2.6/site.py", line 509, in main >>> known_paths = addsitepackages(known_paths) >>> File "/usr/lib64/python2.6/site.py", line 289, in addsitepackages >>> addsitedir(sitedir, known_paths) >>> File "/usr/lib64/python2.6/site.py", line 185, in addsitedir >>> addpackage(sitedir, name, known_paths) >>> File "/usr/lib64/python2.6/site.py", line 159, in addpackage >>> if not dircase in known_paths and os.path.exists(dir): >>> File "/usr/lib64/python2.6/genericpath.py", line 18, in exists >>> st = os.stat(path) >>> TypeError: stat() argument 1 must be encoded string without NULL bytes, >>> not str >>>>>> ? >>> I'm puzzled and I'd appreciate any hints to the reason for this >>> failure. >>> >>> Many thanks, >>> Helmut. >> You gave the answer yourself. >> Chrooting does not automatically mean your SO cache is where it should >> be for the target system. >> Perhaps your livecd is newer/older than the target system or simply the >> python in live environment >> is not (most likely) compiled as the one in the target system. >> > It has been working dozens of time! > Are you saying, an ldconfig would rectify the situation? > > Unfortunately, I can only test it on monday. > > Thanks, > Helmut. > > > > > It works as long as the so files are close enough in the way they were built, the symbols they expose and the versions they have. calling ldconfig _can_ help, but this is not for sure. You can of course try to call ldd /usr/bin/python (or where it lives) and ldd /usr/lib64/python2.6/lib-dynload/readline.so to see if there is something abviously wrong. -------------- next part -------------- A non-text attachment was scrubbed... Name: stefan_sonnenberg.vcf Type: text/x-vcard Size: 232 bytes Desc: not available URL: From kern.ra at gmail.com Fri Nov 12 14:49:08 2010 From: kern.ra at gmail.com (Becky Kern) Date: Fri, 12 Nov 2010 14:49:08 -0500 Subject: Newbie question about "import arcgisscripting" Message-ID: Hi, I'm a brand new Python 2.7 user, attempting to use it to convert a raster file to an ASCII file. I used ArcGis9.3 to create the raster file. My code begins with the line >>import arcgisscripting However, Python gives an error message "ImportError: DLL load failed: The specified module could not be found." I found arcgisscripting in a list of available modules in the Python help menu. How do I successfully import the module? Thanks, Becky -------------- next part -------------- An HTML attachment was scrubbed... URL: From bnbowman at gmail.com Fri Nov 12 15:00:55 2010 From: bnbowman at gmail.com (Brett Bowman) Date: Fri, 12 Nov 2010 12:00:55 -0800 Subject: Copy Protected PDFs and PIL In-Reply-To: References: Message-ID: To answer various question: MRAB - I've tried worker threads, and it kills the thread only and not the program as a whole. I could use that as a work-around, but I would prefer something more direct, in case other problems arise. Steve Holden - A traceback sounds like a great idea, but I don't know how to go about it, or know what is involved. Could you suggest a tutorial I could follow? Emile van Sebille - a Try/Except block was the first thing I tried, and it still dies with a fatal error, even if I use a generic Except Robert Kern - A whoops, good catch. I meant to say gfx and swftools. I'm using PIL to modify the images once I get a PNG from swftools, and I mis-spoke. The code in question is: import gfx print "1" doc = gfx.open("pdf", MY_FILE) print "2" page1 = doc.getPage(1) print "3" g_img = gfx.ImageList() print "4" g_img.startpage(a_page.width,a_page.height) print "5" a_page.render(g_img) print "6" g_img.endpage() print "7" g_img.save(TEMP_PNG) which prints the following: 1 2 3 4 5 FATAL PDF disallows copying Any help or suggestions would be appreciated. /b/ On Thu, Nov 11, 2010 at 12:28 PM, Brett Bowman wrote: > I'm trying to parse some basic details and a thumbnail from ~12,000 PDFs > for my company, but a few hundred of them are copy protected. To make > matters worse, I can't seem to trap the error it causes: whenever it happens > PIL throws a "FATAL PDF disallows copying" message and dies. An automated > way to snap a picture of the PDFs would be ideal, but I'd settle for a way > to skip over them without crashing my program. > > Any tips? > > Brett Bowman > Bioinformatics Associate > Cibus LLC > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nagle at animats.com Fri Nov 12 15:18:07 2010 From: nagle at animats.com (John Nagle) Date: Fri, 12 Nov 2010 12:18:07 -0800 Subject: A matter of queues, tasks and multiprocessing In-Reply-To: References: Message-ID: <4cdda0fe$0$1609$742ec2ed@news.sonic.net> On 11/10/2010 9:25 AM, Emanuele D'Arrigo wrote: > Greetings everybody, > > I've tried to come up with this message for a couple of weeks now and > it doesn't look like I'm getting any clearer in my thoughts so I > decided that it's probably best to take the plunge and ask you guys to > kindly throw me a rope... > > What I'm trying to come up with is some kind of simple, dynamically > scalable, domain-agnostic, multi-processor capable, tasking system. > Maybe I'm already giving myself too many constraints here, i.e. it > might all be possible except... the "simple" part. No, the problem is vagueness. We can't tell from your description what you want to do. A real-time desktop application? Warehouse-scale computing? Your own "cloud"? Incidentally, bear in mind that once you scale beyond tens of machines, error detection and recovery starts to dominate the problem. John Nagle From nagle at animats.com Fri Nov 12 15:25:21 2010 From: nagle at animats.com (John Nagle) Date: Fri, 12 Nov 2010 12:25:21 -0800 Subject: A matter of queues, tasks and multiprocessing In-Reply-To: <4cdda0fe$0$1609$742ec2ed@news.sonic.net> References: <4cdda0fe$0$1609$742ec2ed@news.sonic.net> Message-ID: <4cdda2b0$0$1656$742ec2ed@news.sonic.net> On 11/12/2010 12:18 PM, John Nagle wrote: > On 11/10/2010 9:25 AM, Emanuele D'Arrigo wrote: >> Greetings everybody, >> >> I've tried to come up with this message for a couple of weeks now and >> it doesn't look like I'm getting any clearer in my thoughts so I >> decided that it's probably best to take the plunge and ask you guys to >> kindly throw me a rope... >> >> What I'm trying to come up with is some kind of simple, dynamically >> scalable, domain-agnostic, multi-processor capable, tasking system. >> Maybe I'm already giving myself too many constraints here, i.e. it >> might all be possible except... the "simple" part. > > No, the problem is vagueness. We can't tell from your description > what you want to do. A real-time desktop application? Warehouse-scale > computing? Your own "cloud"? > > Incidentally, bear in mind that once you scale beyond tens of > machines, error detection and recovery starts to dominate > the problem. > > John Nagle Here's how Google does it: http://www.stanford.edu/class/ee380/Abstracts/101110-slides.pdf John Nagle From robert.kern at gmail.com Fri Nov 12 15:30:06 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 12 Nov 2010 14:30:06 -0600 Subject: Copy Protected PDFs and PIL Message-ID: On 11/12/10 2:00 PM, Brett Bowman wrote: > A whoops, good catch. I meant to say gfx and swftools. I'm using PIL to > modify the images once I get a PNG from swftools, and I mis-spoke. There is nothing you can do to catch the error. swftools is not written to be used as a Python library, so it aborts the process when it runs into problems instead of raising an exception. Tough luck. I recommend using the pyPdf library to attempt to see if the PDF is copy-protected first. Then use gfx to render the PDF to an image. http://pybrary.net/pyPdf/ -- 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 emile at fenx.com Fri Nov 12 15:43:59 2010 From: emile at fenx.com (Emile van Sebille) Date: Fri, 12 Nov 2010 12:43:59 -0800 Subject: Copy Protected PDFs and PIL In-Reply-To: References: Message-ID: On 11/12/2010 12:00 PM Brett Bowman said... > FATAL PDF disallows copying I ran into something like this about six months ago. IIRC, I was able to detect this setting (using reportlab I think), but a quick look to rediscover what I did specifically didn't yield anything useful. I'm pretty sure if I had the time I'd get back to what I found last time. YMMV, Emile From steve at holdenweb.com Fri Nov 12 15:54:01 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 12 Nov 2010 12:54:01 -0800 Subject: Copy Protected PDFs and PIL In-Reply-To: References: Message-ID: On 11/12/2010 12:00 PM, Brett Bowman wrote: > Steve Holden - > A traceback sounds like a great idea, but I don't know how to go about > it, or know what is involved. Could you suggest a tutorial I could follow? > The traceback is the listing of modules and line numbers that you normally get when a Python program fails. But it sounds like you may not be getting a traceback, which could indicate problems arising in some extension module (extension modules are written in compiled languages like C but called from Python in the normal way). So I don't think a tutorial would help in this specific case, and any tutorial worth its salt will tell you what a traceback is. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From python at rcn.com Fri Nov 12 16:24:09 2010 From: python at rcn.com (Raymond Hettinger) Date: Fri, 12 Nov 2010 13:24:09 -0800 (PST) Subject: Is a 32-bit build faster than a 64-bit build Message-ID: <7a628beb-5f36-4cc0-8e38-fa81de268722@s11g2000prs.googlegroups.com> Has anyone here benchmarked a 32-bit Python versus a 64-bit Python for Django or some other webserver? My hypotheses is that for apps not needing the 64-bit address space, the 32-bit version has better memory utilization and hence better cache performance. If so, then switching python versions may enable a single server to handle a greater traffic load. Has anyone here tried that? Raymond From stefan.sonnenberg at pythonmeister.com Fri Nov 12 16:39:34 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Fri, 12 Nov 2010 22:39:34 +0100 Subject: Is a 32-bit build faster than a 64-bit build In-Reply-To: <7a628beb-5f36-4cc0-8e38-fa81de268722@s11g2000prs.googlegroups.com> References: <7a628beb-5f36-4cc0-8e38-fa81de268722@s11g2000prs.googlegroups.com> Message-ID: <4CDDB416.9070507@pythonmeister.com> Am 12.11.2010 22:24, schrieb Raymond Hettinger: > My hypotheses is that for apps not needing the 64-bit address space, > the 32-bit version has better memory utilization and hence better > cache performance. If so, then switching python versions may enable a > single server to handle a greater traffic load. Has anyone here tried > that? In most cases (all?) I have seen did the performance not differ when compared between running python scripts in 32 or 64 bit env. But that is not true for compiled code. Just take your script and do some benchmarking. In germany we say: probieren geht ?ber studieren. Don't study - try it. An ex-post explanation will show at hand, I promise :-) -------------- next part -------------- A non-text attachment was scrubbed... Name: stefan_sonnenberg.vcf Type: text/x-vcard Size: 223 bytes Desc: not available URL: From stefan_ml at behnel.de Fri Nov 12 17:00:25 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 12 Nov 2010 23:00:25 +0100 Subject: Is a 32-bit build faster than a 64-bit build In-Reply-To: <7a628beb-5f36-4cc0-8e38-fa81de268722@s11g2000prs.googlegroups.com> References: <7a628beb-5f36-4cc0-8e38-fa81de268722@s11g2000prs.googlegroups.com> Message-ID: Raymond Hettinger, 12.11.2010 22:24: > Has anyone here benchmarked a 32-bit Python versus a 64-bit Python for > Django or some other webserver? > > My hypotheses is that for apps not needing the 64-bit address space, > the 32-bit version has better memory utilization and hence better > cache performance. OTOH, x86_64 has more registers and allows faster compiler flags for default installations (e.g. there is no x86_64 processor without MMX and SSE). So, if you don't compile your software yourself (including OS kernel and libraries, e.g. OpenSSL), it will likely run faster on 64bits simply due to the better compiler optimisations. There are good reasons for both being able to run faster depending on the specific code, so benchmarking is basically all you can do. Stefan From gburdell1 at gmail.com Fri Nov 12 17:03:33 2010 From: gburdell1 at gmail.com (George Burdell) Date: Fri, 12 Nov 2010 14:03:33 -0800 (PST) Subject: Newbie question about python garbage collection when keeping only a reference to an object's member Message-ID: My understanding is that any object which is not pointed to by any variable will be automatically deleted. What if I create a class object, but only keep a reference to one of its members, and not a reference to the object itself? What goes on internally in Python? Does Python retain the whole object, or does it just keep a copy of the referenced member? For example, if I have def myclass: def __init__(self): self.x = [1,2,3] self.y = [4,5,6] x = myclass().x This works, and I correctly get x = [1,2,3]. But what happened to the myclass() object initially created, and the member "y"? From robert.kern at gmail.com Fri Nov 12 17:12:23 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 12 Nov 2010 16:12:23 -0600 Subject: Newbie question about python garbage collection when keeping only a reference to an object's member In-Reply-To: References: Message-ID: On 11/12/10 4:03 PM, George Burdell wrote: > My understanding is that any object which is not pointed to by any > variable will be automatically deleted. What if I create a class > object, but only keep a reference to one of its members, and not a > reference to the object itself? What goes on internally in Python? > Does Python retain the whole object, or does it just keep a copy of > the referenced member? > > For example, if I have > > def myclass: > def __init__(self): > self.x = [1,2,3] > self.y = [4,5,6] > x = myclass().x > > This works, and I correctly get x = [1,2,3]. But what happened to the > myclass() object initially created, and the member "y"? They get deleted. -- 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 steve at holdenweb.com Fri Nov 12 17:18:44 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 12 Nov 2010 14:18:44 -0800 Subject: Newbie question about python garbage collection when keeping only a reference to an object's member In-Reply-To: References: Message-ID: On 11/12/2010 2:03 PM, George Burdell wrote: > My understanding is that any object which is not pointed to by any > variable will be automatically deleted. What if I create a class > object, but only keep a reference to one of its members, and not a > reference to the object itself? What goes on internally in Python? > Does Python retain the whole object, or does it just keep a copy of > the referenced member? > > For example, if I have > > def myclass: > def __init__(self): > self.x = [1,2,3] > self.y = [4,5,6] > x = myclass().x > > This works, and I correctly get x = [1,2,3]. But what happened to the > myclass() object initially created, and the member "y"? The myclass() call created a myclass instance (which contains a reference to a newly created list, which therefore has a refcount of 1). Attribute access to that instance then returns a second reference to the list, which is bound to the name x in the current local namespace (or the module global namespace if this is top-level code). The binding results in a reference count of two for the list. The instance, having no outstanding references, is then garbage-collected, which means that the objects referenced by its namespace have their reference counts decremented for each reference. So the destruction of the myclass instance reduces the reference count of the list [1, 2, 3] to one, and that of the list [4, 5, 6] to zero (which causes *it* to be garbage collected). And you are left with a local variable x that references a list whose current contents are [1, 2, 3]. Remember, the new values aren't created in local namespace. They are created in a shared area of memory (often referred to as the "heap"), so it's quite easy to "keep objects alive" that were created inside functions - just make sure you hold on to references outside the functions, and you are fine. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From emile at fenx.com Fri Nov 12 17:20:17 2010 From: emile at fenx.com (Emile van Sebille) Date: Fri, 12 Nov 2010 14:20:17 -0800 Subject: Newbie question about python garbage collection when keeping only a reference to an object's member In-Reply-To: References: Message-ID: On 11/12/2010 2:03 PM George Burdell said... > My understanding is that any object which is not pointed to by any > variable will be automatically deleted. What if I create a class > object, but only keep a reference to one of its members, and not a > reference to the object itself? What goes on internally in Python? > Does Python retain the whole object, or does it just keep a copy of > the referenced member? > > For example, if I have > > def myclass: class myclass: > def __init__(self): > self.x = [1,2,3] > self.y = [4,5,6] > x = myclass().x > > This works, and I correctly get x = [1,2,3]. But what happened to the > myclass() object initially created, and the member "y"? Garbage collect(ed|able) It only existed (was referenceable) while instantiated and can be gc'd one no longer referenced. Emile From steve at REMOVE-THIS-cybersource.com.au Fri Nov 12 18:51:44 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 12 Nov 2010 23:51:44 GMT Subject: How to test if a module exists? References: Message-ID: <4cddd310$0$29992$c3e8da3$5496439d@news.astraweb.com> On Thu, 11 Nov 2010 16:51:38 -0800, Ethan Furman wrote: > Lawrence D'Oliveiro wrote: >> As for those who persisted in posting my address after being warned of >> this, I?m still deciding what to do. > > You can be such an ass sometimes. "Sometimes"? -- Steven From bblais at bryant.edu Fri Nov 12 19:24:50 2010 From: bblais at bryant.edu (Brian Blais) Date: Fri, 12 Nov 2010 19:24:50 -0500 Subject: drawing with the mouse with turtle Message-ID: I'd like to draw on a turtle canvas, but use the mouse to direct the turtle. I don't see a good way of getting the mouse coordinates and the button state. I tried to do something like this: import turtle def gothere(event): print event.x print event.y turtle.goto(event.x,event.y) turtle.reset() turtle.speed(0) c=turtle.getcanvas() c.bind("", gothere) turtle.pendown() but this seemed to draw in the wrong place (like the coordinates were wrong). Is there a good way to do this? thanks, bb -- Brian Blais bblais at bryant.edu http://web.bryant.edu/~bblais http://bblais.blogspot.com/ From steve at holdenweb.com Fri Nov 12 19:26:51 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 12 Nov 2010 16:26:51 -0800 Subject: How to test if a module exists? In-Reply-To: <4cddd310$0$29992$c3e8da3$5496439d@news.astraweb.com> References: <4cddd310$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 11/12/2010 3:51 PM, Steven D'Aprano wrote: > On Thu, 11 Nov 2010 16:51:38 -0800, Ethan Furman wrote: > >> Lawrence D'Oliveiro wrote: > >>> As for those who persisted in posting my address after being warned of >>> this, I?m still deciding what to do. >> >> You can be such an ass sometimes. > > "Sometimes"? > OK, that's probably enough. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at REMOVE-THIS-cybersource.com.au Fri Nov 12 20:05:42 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 13 Nov 2010 01:05:42 GMT Subject: drawing with the mouse with turtle References: Message-ID: <4cdde466$0$29992$c3e8da3$5496439d@news.astraweb.com> On Fri, 12 Nov 2010 19:24:50 -0500, Brian Blais wrote: > I'd like to draw on a turtle canvas, but use the mouse to direct the > turtle. I don't see a good way of getting the mouse coordinates and the > button state. I think the right way to do that is by creating an event handler to the turtle. These docs are for Python 2.7 turtle, but they may be applicable to older versions as well: http://docs.python.org/library/turtle.html#turtle.ondrag I quote: >>> turtle.ondrag(turtle.goto) Subsequently, clicking and dragging the Turtle will move it across the screen thereby producing handdrawings (if pen is down). That's probably all you need to do. -- Steven From martin.kaspar at campus-24.com Fri Nov 12 20:21:04 2010 From: martin.kaspar at campus-24.com (Martin Kaspar) Date: Fri, 12 Nov 2010 17:21:04 -0800 (PST) Subject: need some debug-infos on a simple regex Message-ID: hello dear list! i'm very new to programming and self teaching myself. I'm having a problem with a little project. I'm trying to preform an fetch-process, but every time i try it i runs into errors. i have read the Python-documents for more than ten hours now! And i have several books here - but they do not help at the moment. This code runs like a charme!! import urllib import urlparse import re url = "http://search.cpan.org/author/?W" html = urllib.urlopen(url).read() for lk, capname, name in re.findall('(.*?)
(.*?)', html): alk = urlparse.urljoin(url, lk) data = { 'url':alk, 'name':name, 'cname':capname } phtml = urllib.urlopen(alk).read() memail = re.search('', phtml) if memail: data['email'] = memail.group(1) print data Note the above mentioned code runs very very good. All is nice. Now i want to apply it on a new target. I can learn alot with this ...Let us say on this swiss-site:educa.ch: What is aimed: I want to adopt it on a new target to learn mor about regex and to do some homework - (working as a teacher - and collecting some data bout colleagues) How should we fetch the sites - that is the problem..i want to learn while applying the code...What is necessary to apply the example on the target!? the target: http://www.educa.ch/dyn/79362.asp?action=search But the code (see below) does not run - i tried several things to debug - can yozu help me!? BTW - should i fetch the pages and load them into an array or should i loop over the http://www.educa.ch/dyn/79376.asp?id=2635 http://www.educa.ch/dyn/79376.asp?id=3493 and so on... see the code that does not work!? import urllib import urlparse import re url = "http://www.educa.ch/dyn/" html = urllib.urlopen("http://www.educa.ch/dyn/79362.asp? action=search").read() for capname, lk in re.findall('
]+>([^<] +).*?', phtml) if memail: data['email'] = memail.group(1) print data Look forward to get some starting points... thx matze From bblais at bryant.edu Fri Nov 12 20:48:34 2010 From: bblais at bryant.edu (Brian Blais) Date: Fri, 12 Nov 2010 20:48:34 -0500 Subject: drawing with the mouse with turtle In-Reply-To: <4cdde466$0$29992$c3e8da3$5496439d@news.astraweb.com> References: <4cdde466$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Nov 12, 2010, at 8:05 PM, Steven D'Aprano wrote: > On Fri, 12 Nov 2010 19:24:50 -0500, Brian Blais wrote: > >> I'd like to draw on a turtle canvas, but use the mouse to direct the >> turtle. I don't see a good way of getting the mouse coordinates and the >> button state. > > I think the right way to do that is by creating an event handler to the > turtle. These docs are for Python 2.7 turtle, but they may be applicable > to older versions as well: > > http://docs.python.org/library/turtle.html#turtle.ondrag > > I quote: > >>>> turtle.ondrag(turtle.goto) > > Subsequently, clicking and dragging the Turtle will move it > across the screen thereby producing handdrawings (if pen is down). > > > That's probably all you need to do. that's what I tried first, with no luck. I am on 2.6 on Mac OSX (Enthought distribution). The following code: import turtle turtle.reset() turtle.speed(0) turtle.ondrag(turtle.goto) turtle.pendown() running it in ipython brings up a window, but clicking, dragging, or anything like that doesn't move the turtle or draw anything. running it in just plain python brings up the window, but it instantly closes. I added: turtle.mainloop() which keeps the window open, but the clicking or dragging still doesn't move the turtle or update the window in any way. bb -- Brian Blais bblais at bryant.edu http://web.bryant.edu/~bblais http://bblais.blogspot.com/ From martin at address-in-sig.invalid Fri Nov 12 20:51:01 2010 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Sat, 13 Nov 2010 01:51:01 +0000 (UTC) Subject: need some debug-infos on a simple regex References: Message-ID: On Fri, 12 Nov 2010 17:21:04 -0800, Martin Kaspar wrote: > hello dear list! > > i'm very new to programming and self teaching myself. I'm having a > problem with a little project. > This doesn't directly help with your problem, but the tool at this URL: http://www.solmetra.com/scripts/regex/ may be useful when you're experimenting with regexes or testing them. Perl regexes are similar enough to Python regexes for this tool to be useful here. Without examples of text that the regex is intended to match its difficult to say more. -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From research at johnohagan.com Fri Nov 12 21:39:59 2010 From: research at johnohagan.com (John O'Hagan) Date: Sat, 13 Nov 2010 02:39:59 +0000 Subject: Sending changed parameters into nested generators In-Reply-To: <44041b0d-e86a-4044-8077-2d8a1af6966c@r31g2000prg.googlegroups.com> References: <44041b0d-e86a-4044-8077-2d8a1af6966c@r31g2000prg.googlegroups.com> Message-ID: <201011130240.00394.research@johnohagan.com> On Fri, 12 Nov 2010, Ian wrote: > On Nov 12, 2:47 am, "John O'Hagan" wrote: > > I have tried using a deep update function on the original nested > > dictionary, but this only works if I change the contents of a list, not > > if I want to, say, change a node from a list to a dictionary or vice > > versa, because in that case I'm not operating on the same object the > > generator is using. > > > > If anyone's still reading :) , how can I send new values to arbitrary > > sub- generators? > > I think you're focusing too heavily on generators. Just because a > nifty language construct exists doesn't mean that it's the right thing > to use in all situations. It sounds to me that what you really want > are objects with .next() methods and externally visible state -- i.e. > iterators. Oddly enough I had just begun to replace some of the generator routines in the real program with iterator classes, but it didn't occur to me that they could solve the nesting problem. I guess I could access the parameters of nested iterators like: MyIter().param.iterator.param and so on? I'll try it, thanks. Although if it can be done with built-in functionality... > Or it might be that coroutines are what you're really after, although > I think they would be difficult to manage in the way that you are > doing. From the rather slight docs on these features, it seems they are tailor-made for what I'm doing (in fact my exact solution is described there as "hackish"!), but so far I can't see how they could solve my nesting problem. [...] Thanks, John From python at mrabarnett.plus.com Fri Nov 12 21:54:14 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 13 Nov 2010 02:54:14 +0000 Subject: need some debug-infos on a simple regex In-Reply-To: References: Message-ID: <4CDDFDD6.2010809@mrabarnett.plus.com> On 13/11/2010 01:21, Martin Kaspar wrote: > hello dear list! > > i'm very new to programming and self teaching myself. I'm having a > problem with a little project. > > I'm trying to preform an fetch-process, but every time i try it i runs > into errors. > i have read the Python-documents for more than ten hours now! And i > have several books here > - but they do not help at the moment. This code runs like a charme!! > > > import urllib > import urlparse > import re > > url = "http://search.cpan.org/author/?W" > html = urllib.urlopen(url).read() > for lk, capname, name in re.findall(' href="(/~.*?/)">(.*?)
(.*?)', html): > alk = urlparse.urljoin(url, lk) > > data = { 'url':alk, 'name':name, 'cname':capname } > > phtml = urllib.urlopen(alk).read() > memail = re.search('', phtml) > if memail: > data['email'] = memail.group(1) > > print data > > Note the above mentioned code runs very very good. All is nice. Now i > want to apply it on a new target. I can learn alot with this ...Let us > say on this swiss-site:educa.ch: > > What is aimed: I want to adopt it on a new target to learn mor about > regex and to do some homework - (working as a teacher - and > collecting some data bout colleagues) How should we fetch the sites - > that is the problem..i want to learn while applying the > code...What is necessary to apply the example on the target!? > > the target: http://www.educa.ch/dyn/79362.asp?action=search > > But the code (see below) does not run - i tried several things to > debug - can yozu help me!? > BTW - should i fetch the pages and load them into an array or should i > loop over the > > http://www.educa.ch/dyn/79376.asp?id=2635 > http://www.educa.ch/dyn/79376.asp?id=3493 > and so on... > > see the code that does not work!? > > import urllib > import urlparse > import re > > url = "http://www.educa.ch/dyn/" > html = urllib.urlopen("http://www.educa.ch/dyn/79362.asp? > action=search").read() > for capname, lk in re.findall('
]+>([^<] > +).*?', phtml) > if memail: > data['email'] = memail.group(1) > > print data > > Look forward to get some starting points... > Don't just say "does not run" or "does not work". That's not very helpful. It's like saying "My car doesn't work. How should I fix it?". :-) When writing regexes it's recommended that you use raw string literals. Your first regex contains 'asp?', which is saying that 'p' is optional. I think you meant 'asp\?'. Also, '.' will match any character except '\n'. If want to match an actual '.' then use '\.'. Your second regex contains a closing parenthesis ')' but no opening parenthesis '('. From g.rodola at gmail.com Fri Nov 12 22:19:08 2010 From: g.rodola at gmail.com (=?ISO-8859-1?Q?Giampaolo_Rodol=E0?=) Date: Sat, 13 Nov 2010 04:19:08 +0100 Subject: ANN: psutil 0.2.0 released Message-ID: Hi, I'm pleased to announce the 0.2.0 release of psutil: http://code.google.com/p/psutil === About === psutil is a module providing an interface for retrieving information on running processes and system utilization (CPU, memory) in a portable way by using Python, implementing many functionalities offered by command line tools like ps, top, kill, lsof and netstat. It currently supports Linux, Windows, OS X and FreeBSD both 32-bit and 64-bit with Python versions from 2.4 to 3.2 by using a unique code base. === Major enhancements === * per-process open files * per-process TCP/UPD connections * per-process children * per-process executable name * per-process number of threads * per-process send_signal() and terminate() methods * system cached and buffer memory * support for Windows 64-bit (XP, Vista, 7) and Windows 2000 * mingw compiler support === Links === * Home page: http://code.google.com/p/psutil * Mailing list: http://groups.google.com/group/psutil/topics * Source tarball: http://psutil.googlecode.com/files/psutil-0.2.0.tar.gz * Windows Installer (Python 2.7): http://psutil.googlecode.com/files/psutil-0.2.0.win32-py2.7.exe * Api Reference: http://code.google.com/p/psutil/wiki/Documentation --- Giampaolo Rodola' http://code.google.com/p/pyftpdlib http://code.google.com/p/psutil/ From steve at REMOVE-THIS-cybersource.com.au Fri Nov 12 23:43:48 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 13 Nov 2010 04:43:48 GMT Subject: Sending changed parameters into nested generators References: Message-ID: <4cde1784$0$29992$c3e8da3$5496439d@news.astraweb.com> On Fri, 12 Nov 2010 09:47:26 +0000, John O'Hagan wrote: > I have a generator function which takes as arguments another generator > and a dictionary of other generators like this: > > def modgen(gen, gendict): > for item in gen(): > for k, v in gendict: > do_something_called_k(item, v.next()) > yield item [snip] > If anyone's still reading :) , how can I send new values to arbitrary > sub- generators? I have a headache after reading your problem :( I think it's a good time to point you at the Zen, particularly these five maxims: Beautiful is better than ugly. Simple is better than complex. Complex is better than complicated. Flat is better than nested. If the implementation is hard to explain, it's a bad idea. I'm afraid that your nested generators inside another generator idea fails all of those... it's not elegant (beautiful), it's complicated, it's nested, and the implementation is hard to explain. You could probably replace generators with full-blown iterators, but I wonder what you're trying to accomplish that is so complicated that it needs such complexity to solve it. What are you actually trying to accomplish? Can you give a simple example of what practical task you hope to perform? I suspect there's probably a more elegant way to solve the problem. -- Steven From mygogo2011 at gmail.com Sat Nov 13 00:00:50 2010 From: mygogo2011 at gmail.com (PHP.CCC) Date: Fri, 12 Nov 2010 21:00:50 -0800 (PST) Subject: Air Drop Pro iPhone Game Review Message-ID: <3b947859-c66d-49a1-ba37-3ef26c783123@b19g2000prj.googlegroups.com> Air Drop Pro iPhone Game Review AirDrop Pro is is based on the aid delivery service within the third world etc. So we should all know what to expect from this iPhone and iPod Touch game. The format of the games goes like this a plane flies in a straight line through the screen from either left to right or right to left. You have to touch the screen to release the package from the plane which has a parachute attached. click here >>> http://bit.ly/a6575w From steve at holdenweb.com Sat Nov 13 00:50:12 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 12 Nov 2010 21:50:12 -0800 Subject: need some debug-infos on a simple regex In-Reply-To: References: Message-ID: On 11/12/2010 5:51 PM, Martin Gregorie wrote: > On Fri, 12 Nov 2010 17:21:04 -0800, Martin Kaspar wrote: > >> hello dear list! >> >> i'm very new to programming and self teaching myself. I'm having a >> problem with a little project. >> > This doesn't directly help with your problem, but the tool at this URL: > http://www.solmetra.com/scripts/regex/ > > may be useful when you're experimenting with regexes or testing them. > Perl regexes are similar enough to Python regexes for this tool to be > useful here. > > Without examples of text that the regex is intended to match its > difficult to say more. > > Or you could look at the Kodos tool, which is written in Python and will tell you exactly what a Python pattern will and will not match. http://kodos.sourceforge.net/ regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From research at johnohagan.com Sat Nov 13 01:52:00 2010 From: research at johnohagan.com (John O'Hagan) Date: Sat, 13 Nov 2010 06:52:00 +0000 Subject: Sending changed parameters into nested generators In-Reply-To: <4cde1784$0$29992$c3e8da3$5496439d@news.astraweb.com> References: <4cde1784$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: <201011130652.01523.research@johnohagan.com> On Sat, 13 Nov 2010, Steven D'Aprano wrote: > On Fri, 12 Nov 2010 09:47:26 +0000, John O'Hagan wrote: > > I have a generator function which takes as arguments another generator > > and a dictionary of other generators like this: > > > > def modgen(gen, gendict): > > for item in gen(): > > for k, v in gendict: > > do_something_called_k(item, v.next()) > > > > yield item > > [snip] > > > If anyone's still reading :) , how can I send new values to arbitrary > > sub- generators? > > I have a headache after reading your problem :( > > I think it's a good time to point you at the Zen, particularly these five > maxims: > > Beautiful is better than ugly. > Simple is better than complex. > Complex is better than complicated. > Flat is better than nested. > If the implementation is hard to explain, it's a bad idea. > > > I'm afraid that your nested generators inside another generator idea > fails all of those... it's not elegant (beautiful), it's complicated, > it's nested, and the implementation is hard to explain. > > You could probably replace generators with full-blown iterators, but I > wonder what you're trying to accomplish that is so complicated that it > needs such complexity to solve it. What are you actually trying to > accomplish? Can you give a simple example of what practical task you hope > to perform? I suspect there's probably a more elegant way to solve the > problem. I hope there is! The project not practical but artistic; it's a real-time musical composition program. A (simplified) description: one module contains number-list generating functions, others contain functions designed to filter and modify the number lists produced, according to various parameters. Each such stream of number lists is assigned a musical meaning (e.g. pitch, rhythm, volume, etc) and they are combined to produce representations of musical phrases, which are sent to a backend which plays the music as it is produced, and makes PDF scores. Each such "instrument" runs as a separate thread, so several can play together in a coordinated fashion. All the compositional interest lies in the selection of number-list generators and how their output is modified. For example, if I say "Play every third note up an octave" it's not very interesting, compared to "Play every nth note up an interval of m", where n and m vary according to some pattern. It gets even more interesting when that pattern is a function of x and y, which also vary according to another pattern, and so on. To that end, I have each parameter of each modifier set by another generator, such that the value may change with each iteration. This may continue recursively, until at some level we give a parameter a simple value. That's all working, but I also want it to be interactive. Each thread opens a terminal where new options can be entered, but so far it only works, as I mentioned, for changing the values in a top-level mutable object. I agree that as a piece of code this is complicated, nested and hard to explain, but I don't agree that it's ugly. In fact, it was my existing interest in a "patterns within patterns" style of composition that got me learning python in the first place, as the patterns got too hard to keep track of manually. I'm not attached to using nested generators, and would be happy with any solution which enables me to do what I've described. It seems to me that the concept is inherently nested, but I'd be glad to be proved wrong. Regards, John From snehaparitala at gmail.com Sat Nov 13 03:50:27 2010 From: snehaparitala at gmail.com (sms) Date: Sat, 13 Nov 2010 00:50:27 -0800 (PST) Subject: hello Message-ID: http://infoukhotels.blogspot.com/ From nad at acm.org Sat Nov 13 05:03:03 2010 From: nad at acm.org (Ned Deily) Date: Sat, 13 Nov 2010 02:03:03 -0800 Subject: IDLE debugger questions References: <04a3c943-5aee-4248-9cb3-60ea424108cb@j4g2000prm.googlegroups.com> Message-ID: In article , Roger Davis wrote: > Thanks for that info, Ned, I can now get the sys.argv[] list I need, > that's a big help! However, is there any other way to set a breakpoint > in idle that will work on Mac OS X, maybe entering a manual command > somewhere with a specified line number? Inability to set a breakpoint > is an absolute showstopper for me, the code I am trying to debug loops > way too much to be manually steppable in a human time frame. Sorry about the long delay in replying. It turns out that IDLE's breakpoint facility is currently unusable on OS X when Python Tkinter is built with Aqua Tk, the default on OS X. The reason: IDLE implements the Set and Clear Breakpoints menu options through a context popup menu but the popup menus don't work with Aqua Tk. On other systems, the popup menus are bound to the Right mouse button. But on OS X, there's no guarantee that there is more than one button (the Left) and, even if there is, the button bindings are different for Aqua Tk. The net effect is that you can't make the popup menus appear with or without a three-button mouse or equivalent. As far as I can tell, this has been an issue ever since Python started using Aqua Tk on OS X instead of X11 Tk, many releases ago. I've opened an issue for the problem and supplied a patch to have IDLE use Control-Click for popups on OS X as is common in other applications. http://bugs.python.org/issue10404 Thanks for calling this problem to our attention! -- Ned Deily, nad at acm.org From iamforufriends at gmail.com Sat Nov 13 05:41:27 2010 From: iamforufriends at gmail.com (naughty girl) Date: Sat, 13 Nov 2010 02:41:27 -0800 (PST) Subject: NAUGHTY GIRL, WANNA NAUGHTY WITH ME, COME ON... Message-ID: NAUGHTY GIRL, WANNA NAUGHTY WITH ME, COME ON... FREE GOLD MEMBER FOR FEMALE PROFILE http://goo.gl/1bour http://goo.gl/1bour http://goo.gl/1bour http://goo.gl/1bour http://goo.gl/1bour http://goo.gl/1bour http://goo.gl/1bour From bblais at bryant.edu Sat Nov 13 06:22:59 2010 From: bblais at bryant.edu (Brian Blais) Date: Sat, 13 Nov 2010 06:22:59 -0500 Subject: drawing with the mouse with turtle In-Reply-To: References: <4cdde466$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5983D120-1DFA-47C2-8CA1-769A6BDCD5CD@bryant.edu> On Nov 13, 2010, at 1:31 AM, Dennis Lee Bieber wrote: > On Fri, 12 Nov 2010 20:48:34 -0500, Brian Blais > declaimed the following in gmane.comp.python.general: > >> turtle.ondrag(turtle.goto) >> turtle.pendown() >> >> > I'm not familiar with the turtle module but... would it make more > sense to drop the pen before dragging the turtle around? > > """ > Subsequently, clicking and dragging the Turtle will move it across the > screen thereby producing handdrawings (if pen is down). > """ > > "if pen is down" <=== > there is no change by changing the order, but I didn't expect one. since ondrag is binding a callback, which is only called when the event happens, I figure that the pen has to be down when the callback happens, not when the binding occurs. since the pen is down (and never lifted), when I start dragging the mouse around after that it should work...but doesn't seem to. thanks, bb -- Brian Blais bblais at bryant.edu http://web.bryant.edu/~bblais http://bblais.blogspot.com/ From solipsis at pitrou.net Sat Nov 13 07:28:58 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Sat, 13 Nov 2010 13:28:58 +0100 Subject: Is a 32-bit build faster than a 64-bit build References: <7a628beb-5f36-4cc0-8e38-fa81de268722@s11g2000prs.googlegroups.com> Message-ID: <20101113132858.31fc5c35@pitrou.net> On Fri, 12 Nov 2010 13:24:09 -0800 (PST) Raymond Hettinger wrote: > Has anyone here benchmarked a 32-bit Python versus a 64-bit Python for > Django or some other webserver? > > My hypotheses is that for apps not needing the 64-bit address space, > the 32-bit version has better memory utilization and hence better > cache performance. If so, then switching python versions may enable a > single server to handle a greater traffic load. Has anyone here tried > that? On micro-benchmarks, x86-64 is always faster by about 10-30% compared to x86, simply because of the extended register set and other additional niceties. On a benchmark stressing the memory system a little more such as dcbench-py3k.py in http://bugs.python.org/issue9520, the 64-bit build is still faster until the tested data structure (a large dict) overwhelms the 2MB last-level cache in my CPU, after which the 32-bit build becomes 10% faster for the same numbers of elements: To be clear, here are the figures in 64-bit mode: 10000 words ( 9092 keys), 2893621 inserts/s, 13426069 lookups/s, 86 bytes/key (0.8MB) 20000 words ( 17699 keys), 3206654 inserts/s, 12338002 lookups/s, 44 bytes/key (0.8MB) 40000 words ( 34490 keys), 2613517 inserts/s, 7643726 lookups/s, 91 bytes/key (3.0MB) 80000 words ( 67148 keys), 2579562 inserts/s, 4872069 lookups/s, 46 bytes/key (3.0MB) 160000 words ( 130897 keys), 2377487 inserts/s, 5765316 lookups/s, 48 bytes/key (6.0MB) 320000 words ( 254233 keys), 2119978 inserts/s, 5003979 lookups/s, 49 bytes/key (12.0MB) 640000 words ( 493191 keys), 1965413 inserts/s, 4640743 lookups/s, 51 bytes/key (24.0MB) 1280000 words ( 956820 keys), 1854546 inserts/s, 4338543 lookups/s, 52 bytes/key (48.0MB) And here are the figures in 32-bit mode: 10000 words ( 9092 keys), 2250163 inserts/s, 9487229 lookups/s, 43 bytes/key (0.4MB) 20000 words ( 17699 keys), 2543235 inserts/s, 7653839 lookups/s, 22 bytes/key (0.4MB) 40000 words ( 34490 keys), 2360162 inserts/s, 8851543 lookups/s, 45 bytes/key (1.5MB) 80000 words ( 67148 keys), 2415169 inserts/s, 8581037 lookups/s, 23 bytes/key (1.5MB) 160000 words ( 130897 keys), 2203071 inserts/s, 6914732 lookups/s, 24 bytes/key (3.0MB) 320000 words ( 254233 keys), 2005980 inserts/s, 5670133 lookups/s, 24 bytes/key (6.0MB) 640000 words ( 493191 keys), 1856385 inserts/s, 4929790 lookups/s, 25 bytes/key (12.0MB) 1280000 words ( 956820 keys), 1746364 inserts/s, 4530747 lookups/s, 26 bytes/key (24.0MB) However, it's not obvious to me that a program like "Django or some other webserver" would have really bad cache locality. Even if the total working set is larger than the CPU cache, there can still be quite a good cache efficiency if a large fraction of CPU time is spent on small datasets. By the way, I've been experimenting with denser dicts and with linear probing (in the hope that it will improve cache efficiency and spatial locality in real applications), and there doesn't seem to be adverse consequences on micro-benchmarks. Do you think I should upload a patch? Regards Antoine. From affdfsdfdsfsd at b.com Sat Nov 13 08:46:29 2010 From: affdfsdfdsfsd at b.com (Tracubik) Date: 13 Nov 2010 13:46:29 GMT Subject: strange behavor.... Message-ID: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> hi all, i've this on python 2.6.6: >>> def change_integer(int_value): ... int_value = 10 ... ... def change_list(list): ... list[0] = 10 ... ... a = 1 ... l = [1,1,1] ... ... change_integer(a) ... change_list(l) ... ... print a ... print l 1 [10, 1, 1] why the integer value doesn't change while the list value do? in Pascal i can choose the behavour of parametres, how this work on Python? also a link could be appreciated Thanks in advance Nico From wuwei23 at gmail.com Sat Nov 13 08:50:40 2010 From: wuwei23 at gmail.com (alex23) Date: Sat, 13 Nov 2010 05:50:40 -0800 (PST) Subject: strange behavor.... References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> Message-ID: <880c7343-896d-4262-87e6-096dd54f948a@i32g2000pri.googlegroups.com> Tracubik wrote: > why the integer value doesn't change while the list value do? http://effbot.org/pyfaq/why-are-default-values-shared-between-objects.htm From beliavsky at aol.com Sat Nov 13 08:52:26 2010 From: beliavsky at aol.com (Beliavsky) Date: Sat, 13 Nov 2010 05:52:26 -0800 (PST) Subject: scipy code runs in empty directory, not another Message-ID: After installing numpy, scipy, and matplotlib for python 2.6 and running the code from http://www.scipy.org/Cookbook/OptimizationDemo1 (stored as xoptimize.py) in a directory with other python codes, I got the error messages C:\python\code\mycode>python xoptimize.py Traceback (most recent call last): File "xoptimize.py", line 3, in from pylab import * File "c:\python26\lib\site-packages\pylab.py", line 1, in from matplotlib.pylab import * File "c:\python26\lib\site-packages\matplotlib\__init__.py", line 133, in import sys, os, tempfile File "c:\python26\lib\tempfile.py", line 34, in from random import Random as _Random File "C:\python\code\mycode\random.py", line 1, in from RandomArray import standard_normal File "C:\python\code\mycode\RandomArray.py", line 1, in import ranlib ImportError: No module named ranlib When I create a new directory, copy xoptimize.py there, and run, the program works. Can someone explain why other files are "interfering" in the first case? Thanks. From bblais at bryant.edu Sat Nov 13 09:10:41 2010 From: bblais at bryant.edu (Brian Blais) Date: Sat, 13 Nov 2010 09:10:41 -0500 Subject: drawing with the mouse with turtle...solved? In-Reply-To: References: <4cdde466$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: <02F35119-461B-4FE4-B082-A5274B5998A4@bryant.edu> On Nov 12, 2010, at 8:48 PM, Brian Blais wrote: > > On Nov 12, 2010, at 8:05 PM, Steven D'Aprano wrote: > >> On Fri, 12 Nov 2010 19:24:50 -0500, Brian Blais wrote: >> >>> I'd like to draw on a turtle canvas, but use the mouse to direct the >>> turtle. I don't see a good way of getting the mouse coordinates and the >>> button state. >> >> I think the right way to do that is by creating an event handler to the >> turtle. These docs are for Python 2.7 turtle, but they may be applicable >> to older versions as well: >> >> http://docs.python.org/library/turtle.html#turtle.ondrag >> >> I quote: >> >>>>> turtle.ondrag(turtle.goto) >> >> Subsequently, clicking and dragging the Turtle will move it >> across the screen thereby producing handdrawings (if pen is down). >> >> >> That's probably all you need to do. > > > that's what I tried first, with no luck. I am on 2.6 on Mac OSX (Enthought distribution). The following code: > > > import turtle > > turtle.reset() > turtle.speed(0) > turtle.ondrag(turtle.goto) > turtle.pendown() > > running it in ipython brings up a window, but clicking, dragging, or anything like that doesn't move the turtle or draw anything. running it in just plain python brings up the window, but it instantly closes. I added: turtle.mainloop() > > which keeps the window open, but the clicking or dragging still doesn't move the turtle or update the window in any way. > Here is code that "works", with at least one small oddity: import turtle def gothere(event): turtle.penup() turtle.goto(event.x-360,340-event.y) turtle.pendown() def movearound(event): turtle.goto(event.x-360,340-event.y) def release(event): turtle.penup() def reset(event): turtle.clear() turtle.reset() turtle.speed(0) c=turtle.getcanvas() c.bind("", gothere) c.bind("", movearound) c.bind("", release) c.bind("",reset) s=turtle.Screen() s.listen() the oddity is that the coordinate transformations, x-360 and 340-y, are done by eye and do not seem to be related to any of the coordinate values I could find. my screen size is 300x400, the x and y canvas scales are 1 and 1, but if I try to transform with those numbers the mouse is clearly off. any ideas? bb -- Brian Blais bblais at bryant.edu http://web.bryant.edu/~bblais http://bblais.blogspot.com/ From chris.gonnerman at newcenturycomputers.net Sat Nov 13 09:12:05 2010 From: chris.gonnerman at newcenturycomputers.net (Chris Gonnerman) Date: Sat, 13 Nov 2010 08:12:05 -0600 Subject: [Python] scipy code runs in empty directory, not another In-Reply-To: References: Message-ID: <4CDE9CB5.3060208@newcenturycomputers.net> On 11/13/2010 07:52 AM, Beliavsky wrote: > After installing numpy, scipy, and matplotlib for python 2.6 and > running the code from http://www.scipy.org/Cookbook/OptimizationDemo1 > (stored as xoptimize.py) in a directory with other python codes, I got > the error messages > > C:\python\code\mycode>python xoptimize.py > Traceback (most recent call last): > File "xoptimize.py", line 3, in > from pylab import * > File "c:\python26\lib\site-packages\pylab.py", line 1, in > from matplotlib.pylab import * > File "c:\python26\lib\site-packages\matplotlib\__init__.py", line > 133, in > import sys, os, tempfile > File "c:\python26\lib\tempfile.py", line 34, in > from random import Random as _Random > File "C:\python\code\mycode\random.py", line 1, in > from RandomArray import standard_normal > File "C:\python\code\mycode\RandomArray.py", line 1, in > import ranlib > ImportError: No module named ranlib > > When I create a new directory, copy xoptimize.py there, and run, the > program works. Can someone explain why other files are "interfering" > in the first case? Thanks. You'd need to post a list of the files in the directory before we'd have any idea why this is happening. -- Chris. From deets at web.de Sat Nov 13 09:14:12 2010 From: deets at web.de (Diez B. Roggisch) Date: Sat, 13 Nov 2010 15:14:12 +0100 Subject: strange behavor.... References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <880c7343-896d-4262-87e6-096dd54f948a@i32g2000pri.googlegroups.com> Message-ID: alex23 writes: > Tracubik wrote: >> why the integer value doesn't change while the list value do? > > http://effbot.org/pyfaq/why-are-default-values-shared-between-objects.htm Not the issue here. The reason the OP sees a difference that there is only one way to pass parameters in python. There have been wars waged about the right name to call them. What's happening is that in the function, the parameter names are bound to the objects the caller passed in. But these names only exist in the scope of the function. So re-binding that name by doing e.g. a = 2 does not change the binding in the callers context. So because of this, no change happens in change_integer. Because there is no change to the integer itself. Actually, you can't even change an integer in pyhon. They are immutable. a = 2 a += 10 will make a point to the integer-object with the value 12. But the "old" 2 and 10 still exist. And that's where the differency in change_list is in. That gets passed a reference to a _mutable_ object, a list. And if you mutatet that list, you end up with a changed object in the callers context as well. Diez From deets at web.de Sat Nov 13 09:15:51 2010 From: deets at web.de (Diez B. Roggisch) Date: Sat, 13 Nov 2010 15:15:51 +0100 Subject: scipy code runs in empty directory, not another References: Message-ID: Beliavsky writes: > After installing numpy, scipy, and matplotlib for python 2.6 and > running the code from http://www.scipy.org/Cookbook/OptimizationDemo1 > (stored as xoptimize.py) in a directory with other python codes, I got > the error messages > > C:\python\code\mycode>python xoptimize.py > Traceback (most recent call last): > File "xoptimize.py", line 3, in > from pylab import * > File "c:\python26\lib\site-packages\pylab.py", line 1, in > from matplotlib.pylab import * > File "c:\python26\lib\site-packages\matplotlib\__init__.py", line > 133, in > import sys, os, tempfile > File "c:\python26\lib\tempfile.py", line 34, in > from random import Random as _Random > File "C:\python\code\mycode\random.py", line 1, in > from RandomArray import standard_normal > File "C:\python\code\mycode\RandomArray.py", line 1, in > import ranlib > ImportError: No module named ranlib > > When I create a new directory, copy xoptimize.py there, and run, the > program works. Can someone explain why other files are "interfering" > in the first case? Thanks. Because you probably have a file named the same way as some pyhon or matplotlib module, and that shadows the "real" one. Try copying more and more files into your new directory to find the culprit. Diez From benjamin.kaplan at case.edu Sat Nov 13 09:27:37 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sat, 13 Nov 2010 09:27:37 -0500 Subject: [Python] scipy code runs in empty directory, not another In-Reply-To: <4CDE9CB5.3060208@newcenturycomputers.net> References: <4CDE9CB5.3060208@newcenturycomputers.net> Message-ID: On Saturday, November 13, 2010, Chris Gonnerman wrote: > On 11/13/2010 07:52 AM, Beliavsky wrote: > > After installing numpy, scipy, and matplotlib for python 2.6 and > running the code from http://www.scipy.org/Cookbook/OptimizationDemo1 > (stored as xoptimize.py) in a directory with other python codes, I got > the error messages > > C:\python\code\mycode>python xoptimize.py > Traceback (most recent call last): > ? File "xoptimize.py", line 3, in > ? ? from pylab import * > ? File "c:\python26\lib\site-packages\pylab.py", line 1, in > ? ? from matplotlib.pylab import * > ? File "c:\python26\lib\site-packages\matplotlib\__init__.py", line > 133, in > ? ? import sys, os, tempfile > ? File "c:\python26\lib\tempfile.py", line 34, in > ? ? from random import Random as _Random > ? File "C:\python\code\mycode\random.py", line 1, in > ? ? from RandomArray import standard_normal > ? File "C:\python\code\mycode\RandomArray.py", line 1, in > ? ? import ranlib > ImportError: No module named ranlib > > When I create a new directory, copy xoptimize.py there, and run, the > program works. Can someone explain why other files are "interfering" > in the first case? Thanks. > > You'd need to post a list of the files in the directory before we'd have any idea why this is happening. No he doesn't. We can get that from the traceback. Bekiavsky, there's a file called random.py in your folder. Python doesn't treat the standard library fila any differently than it does your own files. It searches the path for the first file called "random" that it sees and it imports that. Since it finds your file first, that's the one it imports. The failure you're seeing is actually in your code-you're trying to import a module that shouldn't exist. In > > -- Chris. > > -- > http://mail.python.org/mailman/listinfo/python-list > From subhakolkata1234 at gmail.com Sat Nov 13 09:39:25 2010 From: subhakolkata1234 at gmail.com (joy99) Date: Sat, 13 Nov 2010 06:39:25 -0800 (PST) Subject: Some Machine Learning related questions Message-ID: <22c10f1d-ded5-46b3-bf7b-74492f12ca64@w38g2000pri.googlegroups.com> Dear Group, Hope every one is fine. I am trying to put some questions. I am developing some tool boxes for support vector machine (SVM) and hidden markov model (HMM). For HMM I was following the tutorial by Leeds University Computer Science Department, available online in HTML format, and for SVM I was following a book on Neural Networks by Simon Haykin. After comprehending them, I thought to cross check my knowledge with the original works. I referred to 1989 Rabiner paper for HMM and SVM society's tutorial for SVM. Here, I am getting some confusions. I am looking for a forum, especially an active forum, like this one (I searched for few in Google, but all seem to be very lazy), where I can post these questions. I felt this room consists of very expert people and I visit it often moreover it is very active -everytime I posed some question people solved it very nicely. If any one can suggest a solution to my queries taking his/her valuable time, I would be grateful enough. Thanks in advance. Apology if it is an unrelated question of the forum. Wishing you all a happy winter. Best Regards, Subhabrata. From mdw at distorted.org.uk Sat Nov 13 11:29:19 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Sat, 13 Nov 2010 16:29:19 +0000 Subject: strange behavor.... References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> Message-ID: <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> Tracubik writes: > >>> def change_integer(int_value): > ... int_value = 10 > ... > ... def change_list(list): > ... list[0] = 10 [...] > why the integer value doesn't change while the list value do? Because in the first case you changed a variable local to the function, and that variable was lost when the function returned; and in the second case, you modified the list value that was passed to the function. > in Pascal i can choose the behavour of parametres, how this work on > Python? You must learn to distinguish two notions to understand how this works in Python: the notions are /assigning a value to a variable/, and /mutating a value/. The former is what simple assignment `foo = ...' does: it makes the variable store a different value. Assigning a value to a function argument /never/ affects the caller in Python. It's simply not possible to write a `swap' function in Python. The latter means that a value itself changes but the relevant variables continue to store the same values. Alas, Python is actually slightly confusing here, since the same notation `=' sometimes means assignment and sometimes means mutation. You can tell which is which by looking at the left hand side: if it's a simple variable name, the variable is assigned a new value; if it's something more complicated (e.g., indexing (`foo[0]'), or attribute selection (`foo.bar') then some mutation is (probably) going to happen: these kinds of assignment are translated into method calls, so what actually happens is up to the object in question. It gets worse: compound assignment -- statements like `foo += ...' -- might either be mutation or assignment. What happens if the current value of `foo' has the an appropriate method is that the method is called, and probably mutates the value of foo; otherwise Python treats the statement as if it had been `foo = foo + (...)'. Returning, sort of, to the point: if you want to write a function which causes side-effects on its caller, then you have[1] to do it by mutating the caller's argument values. So you could write an awful `swap' function like def awful_swap(x, y): x[0], y[0] = y[0], x[0] and then you have to call it as xx = [x] yy = [y] awful_swap(xx, yy) x = xx[0] y = yy[0] but there's no good reason to actually do such a thing in Python when you can write x, y = y, x anyway. In Pascal, one tends to use `var' parameters to work around the fact that Pascal functions can only return a single value. This is true in Python too, but it isn't anywhere near as annoying because Python makes it easy (a) to combine multiple values together into a tuple (`return x, y, z') and (b) to pick tuples apart into their components again at the other end (`a, b, c = some_function()'). If you have a number of values which you find that you're combining and splitting apart repeatedly then maybe you're better off putting them together in a class with some appropriate operations. [1] In general; if the called function happens to be lexically enclosed in its caller, then it can play with its caller's variables directly -- well, in Python 3, anyway. -- [mdw] From davea at ieee.org Sat Nov 13 11:41:59 2010 From: davea at ieee.org (Dave Angel) Date: Sat, 13 Nov 2010 11:41:59 -0500 Subject: scipy code runs in empty directory, not another In-Reply-To: References: Message-ID: <4CDEBFD7.7040902@ieee.org> On 2:59 PM, Beliavsky wrote: > After installing numpy, scipy, and matplotlib for python 2.6 and > running the code from http://www.scipy.org/Cookbook/OptimizationDemo1 > (stored as xoptimize.py) in a directory with other python codes, I got > the error messages > > C:\python\code\mycode>python xoptimize.py > Traceback (most recent call last): > File "xoptimize.py", line 3, in > from pylab import * > File "c:\python26\lib\site-packages\pylab.py", line 1, in > from matplotlib.pylab import * > File "c:\python26\lib\site-packages\matplotlib\__init__.py", line > 133, in > import sys, os, tempfile > File "c:\python26\lib\tempfile.py", line 34, in > from random import Random as _Random > File "C:\python\code\mycode\random.py", line 1, in > from RandomArray import standard_normal > File "C:\python\code\mycode\RandomArray.py", line 1, in > import ranlib > ImportError: No module named ranlib > > When I create a new directory, copy xoptimize.py there, and run, the > program works. Can someone explain why other files are "interfering" > in the first case? Thanks. > You have a file random.py in your code directory, which is shadowing the system random library. DaveA From ra.ravi.rav at gmail.com Sat Nov 13 11:54:54 2010 From: ra.ravi.rav at gmail.com (Ravi) Date: Sat, 13 Nov 2010 08:54:54 -0800 (PST) Subject: sqlite3 doesn't raise exception if database is not present/inaccessible Message-ID: <0bed5b60-1985-4145-b084-346a5428e42d@i4g2000pro.googlegroups.com> try this: import sqlite3 con = sqlite3.connect("any string here") and there is no error reported. You will get an error you do some operations on the database which is confusing. I think sqlite3 should change this behavior. From usernet at ilthio.net Sat Nov 13 12:17:22 2010 From: usernet at ilthio.net (Tim Harig) Date: Sat, 13 Nov 2010 17:17:22 +0000 (UTC) Subject: sqlite3 doesn't raise exception if database is not present/inaccessible References: <0bed5b60-1985-4145-b084-346a5428e42d@i4g2000pro.googlegroups.com> Message-ID: On 2010-11-13, Ravi wrote: > import sqlite3 > con = sqlite3.connect("any string here") That is a property of the sqlite database itself. It always opens the database requested; even if it has to create a new database to do so. > and there is no error reported. You will get an error you do some If you are conserned about it, check that the database contains the schema that you were expecting before trying any other operations on it. > operations on the database which is confusing. I think sqlite3 should > change this behavior. If you believe that, you should talk to the sqlite3 people since this is a property of the database rather then a Python issue. From python at mrabarnett.plus.com Sat Nov 13 12:19:36 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 13 Nov 2010 17:19:36 +0000 Subject: sqlite3 doesn't raise exception if database is not present/inaccessible In-Reply-To: <0bed5b60-1985-4145-b084-346a5428e42d@i4g2000pro.googlegroups.com> References: <0bed5b60-1985-4145-b084-346a5428e42d@i4g2000pro.googlegroups.com> Message-ID: <4CDEC8A8.4090507@mrabarnett.plus.com> On 13/11/2010 16:54, Ravi wrote: > try this: > > import sqlite3 > con = sqlite3.connect("any string here") > > and there is no error reported. You will get an error you do some > operations on the database which is confusing. I think sqlite3 should > change this behavior. That will open an existing database or create a new one. If it raised an exception then how would you create a new database? From vlastimil.brom at gmail.com Sat Nov 13 12:55:35 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sat, 13 Nov 2010 18:55:35 +0100 Subject: regenerating unicodedata for py2.7 using py3 makeunicodedata.py? Message-ID: Hi all, I'd like to ask about a surprising possibility I found while investigating the new unicode 6.0 standard for use in python. As python 2 series won't be updated in this regard ( http://bugs.python.org/issue10400 ), I tried my "poor man's approach" of compiling the needed pyd file with the recent unicode data (cf. the older post http://mail.python.org/pipermail/python-list/2010-March/1240002.html ) While checking the changed format, i found to my big surprise, that it is possible to generate the header files using the py3 makeunicodedata.py which has already been updated for Unicode 6.0; this is even much more comfortable than the previous versions, as the needed data are downloaded automatically. http://svn.python.org/view/python/branches/py3k/Tools/unicode/makeunicodedata.py?view=markup&pathrev=85371 It turned out, that the resulting headers are accepted by MS Visual C++ Express along with the py2.7 source files and that the generated unicodedata.pyd seems to be working work at least in the cases I tested sofar. Is this intended or even guaranteed for these generated files to be compatible across py2.7 and py3, or am I going to be bitten by some less obvious issues later? The newly added ranges and characters are available, only in the CJK Unified Ideographs Extension D the character names are not present (while categories are), but this appears to be the same in the original unicodedadata with 5.2 on CJK Unified Ideographs Extension C. >>> unicodedata.unidata_version '6.0.0' >>> unicodedata.name(u"\U0002B740") # 0x2B740-0x2B81F; CJK Unified Ideographs Extension D # unicode 6.0 addition Traceback (most recent call last): File "", line 1, in ValueError: no such name >>> unicodedata.category(u"\U0002B740") 'Lo' >>> ########################### >>> unicodedata.unidata_version '5.2.0' >>> unicodedata.name(u"\U0002A700") # 0x2A700-0x2B73F; CJK Unified Ideographs Extension C Traceback (most recent call last): File "", line 1, in ValueError: no such name >>> unicodedata.category(u"\U0002A700") 'Lo' >>> Could please anybody confirm, whether this way of updating the unicodedata for 2.7 is generaly viable or point out possible problem this may lead to? Many thanks in advance, Vlastimil Brom From azeynel1 at gmail.com Sat Nov 13 13:53:56 2010 From: azeynel1 at gmail.com (Zeynel) Date: Sat, 13 Nov 2010 10:53:56 -0800 (PST) Subject: Is it possible to break a string literal into multiple lines? Message-ID: <3d0fefad-1152-4740-a164-b3803ce8eea6@29g2000prb.googlegroups.com> I have string formatting line in Google App Engine webframe webapp: self.response.out.write("%s:
mWEIGHT: %s
mDATE0_integer: %s
mCOUNT: %s
" % (result.mUNIQUE, result.mWEIGHT, mDATE0_integer, result.mCOUNT,)) I would like to be able to write it as self.response.out.write("%s:
mWEIGHT: %s
mDATE0_integer: %s
mCOUNT: %s
" % (result.mUNIQUE, result.mWEIGHT, mDATE0_integer, result.mCOUNT,)) But neither \ or enclosing the string in parens let me break the string literal enclosed in "" Is this possible? From jjposner at optimum.net Sat Nov 13 13:55:53 2010 From: jjposner at optimum.net (John Posner) Date: Sat, 13 Nov 2010 13:55:53 -0500 Subject: Question on Django and Django Book Message-ID: <4CDEDF39.1030805@optimum.net> I've started working, as a tech writer, for a Spanish software configuration management company. And I'm investigating the idea of releasing a user manual in the form of a wiki that supports paragraph-by-paragraph commenting. I looked at Django Book [1][2], but it's not clear to me how much of a Django wrangler I'd need to be to create and maintain a book that works the same way. It's not even clear to me if the technology supporting Django Book is available, maintained, etc. Also, maybe there's a non-Django solution that I haven't come across in my Googling. I'd appreciate guidance in any direction! Tx, John [1] http://www.djangobook.com/about/comments/ [2] http://www.djangobook.com/en/2.0/chapter12/ From tjreedy at udel.edu Sat Nov 13 14:00:39 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 13 Nov 2010 14:00:39 -0500 Subject: scipy code runs in empty directory, not another In-Reply-To: <4CDEBFD7.7040902@ieee.org> References: <4CDEBFD7.7040902@ieee.org> Message-ID: On 11/13/2010 11:41 AM, Dave Angel wrote: > On 2:59 PM, Beliavsky wrote: >> After installing numpy, scipy, and matplotlib for python 2.6 and >> running the code from http://www.scipy.org/Cookbook/OptimizationDemo1 >> (stored as xoptimize.py) in a directory with other python codes, I got >> the error messages >> >> C:\python\code\mycode>python xoptimize.py >> Traceback (most recent call last): >> File "xoptimize.py", line 3, in Learn to read tracebacks. They are your debugging friend. >> from pylab import * xoptimize imports pylab >> File "c:\python26\lib\site-packages\pylab.py", line 1, in >> from matplotlib.pylab import * pylab imports matplotlib >> File "c:\python26\lib\site-packages\matplotlib\__init__.py", line >> 133, in >> import sys, os, tempfile matplotlib imports tempfile (to get a plot destination) >> File "c:\python26\lib\tempfile.py", line 34, in >> from random import Random as _Random tempfile import random (to make a 'random' tempfile name) >> File "C:\python\code\mycode\random.py", line 1, in Look carefully at the above line. It should have been: File "C:\python26\lib\random.py ... Ignore the remaining error cascade. >> When I create a new directory, copy xoptimize.py there, and run, the >> program works. Can someone explain why other files are "interfering" >> in the first case? Thanks. >> > You have a file random.py in your code directory, which is shadowing the > system random library. As you can see in the traceback. -- Terry Jan Reedy From python at mrabarnett.plus.com Sat Nov 13 14:08:36 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 13 Nov 2010 19:08:36 +0000 Subject: Is it possible to break a string literal into multiple lines? In-Reply-To: <3d0fefad-1152-4740-a164-b3803ce8eea6@29g2000prb.googlegroups.com> References: <3d0fefad-1152-4740-a164-b3803ce8eea6@29g2000prb.googlegroups.com> Message-ID: <4CDEE234.5000802@mrabarnett.plus.com> On 13/11/2010 18:53, Zeynel wrote: > I have string formatting line in Google App Engine webframe webapp: > > self.response.out.write("%s:
mWEIGHT: %s
> mDATE0_integer: %s
mCOUNT: %s
" % (result.mUNIQUE, > result.mWEIGHT, mDATE0_integer, result.mCOUNT,)) > > I would like to be able to write it as > > self.response.out.write("%s:
> mWEIGHT: %s
> mDATE0_integer: %s
> mCOUNT: %s
" > % > (result.mUNIQUE, > > result.mWEIGHT, > > mDATE0_integer, > > result.mCOUNT,)) > > But neither \ or enclosing the string in parens let me break the > string literal enclosed in "" Is this possible? Use triple-quoted strings: self.response.out.write("""%s:
mWEIGHT: %s
mDATE0_integer: %s
mCOUNT: %s
""" (result.mUNIQUE, result.mWEIGHT, mDATE0_integer, result.mCOUNT,)) From cbrown at cbrownsystems.com Sat Nov 13 14:11:43 2010 From: cbrown at cbrownsystems.com (cbrown at cbrownsystems.com) Date: Sat, 13 Nov 2010 11:11:43 -0800 (PST) Subject: IDLE debugger questions References: <04a3c943-5aee-4248-9cb3-60ea424108cb@j4g2000prm.googlegroups.com> Message-ID: <25e32077-ccb1-488c-89c1-52d81372355e@r31g2000prg.googlegroups.com> On Oct 23, 7:29?am, Roger Davis wrote: > Are there any Python debuggers with a decent GUI out there at all that > will work on a Mac with the following features: (i) ability to pass in > a sys.srgv[] list that the program would otherwise see without the > debugger, (ii) display local variables, (iii) single-step through the > source code, and (iv) set a breakpoint? I think I can live without > anything else for the moment. > I'm very happy using the Eclipse IDE (available for Mac, PC and 'Nix) with the pydev plug-in. It's free, well supported and well behaved, and has all the debugging features you name and then some. It's also a modern code editor with code-hinting, syntax highlighting, etc. The only downside of Eclipse to me is its 'workspace' and 'project' metaphors for file organization; which take a bit of getting used to, particularly if you're used to just editing in a text editor, and then running in Idle or a command line. I still usually also have Idle open as well so I can test little code snippets quickly and easily; but mostly I work in Eclipse. Cheers - Chas From python.list at tim.thechases.com Sat Nov 13 14:14:27 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 13 Nov 2010 13:14:27 -0600 Subject: Is it possible to break a string literal into multiple lines? In-Reply-To: <3d0fefad-1152-4740-a164-b3803ce8eea6@29g2000prb.googlegroups.com> References: <3d0fefad-1152-4740-a164-b3803ce8eea6@29g2000prb.googlegroups.com> Message-ID: <4CDEE393.1000603@tim.thechases.com> On 11/13/2010 12:53 PM, Zeynel wrote: > I have string formatting line in Google App Engine webframe webapp: > > self.response.out.write("%s:
mWEIGHT: %s
> mDATE0_integer: %s
mCOUNT: %s
" % (result.mUNIQUE, > result.mWEIGHT, mDATE0_integer, result.mCOUNT,)) > > I would like to be able to write it as > > self.response.out.write("%s:
> mWEIGHT: %s
> mDATE0_integer: %s
> mCOUNT: %s
" > % > (result.mUNIQUE, > > result.mWEIGHT, > > mDATE0_integer, > > result.mCOUNT,)) > > But neither \ or enclosing the string in parens let me break the > string literal enclosed in "" Is this possible? Use python's triple-quoted strings: self.response.out.write("""%s:
mWEIGHT: %s ... ...
""") Or alternatively, you can do something like self.response.out.write( "%s:br />" "mWEIGHT: %s ..." ... "...
" ) (that excludes newlines and leading whitespace in the string that gets written, but you can modify the string contents to include them if you need/want) -tkc From tjreedy at udel.edu Sat Nov 13 14:19:19 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 13 Nov 2010 14:19:19 -0500 Subject: strange behavor.... In-Reply-To: <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On 11/13/2010 11:29 AM, Mark Wooding wrote: > Alas, Python is actually slightly confusing here, since the same > notation `=' sometimes means assignment and sometimes means mutation. I disagree somewhat. An object is mutated by an internal assignment. "ll[0] = 1" assigns 1 to the 0 slot of ll. "o.a = 1" assigns 1 to the 'a' attribute of o. This which might be implemented by assigning 1 to the 'a' slot of o.__dict__, just as "a=1" might be implemented by assigning 1 to the 'a' slot of a namespace dict. Assignment *always* binds an object to a target. Names are just one possible target. And, of course, assignment always mutates something -- a set of associations -- even if the 'something' is not a Python object itself. So '=' always means assignment/binding by mutation. The question is what gets bound to what in what set of associations. The rest of your post helps clarify that. -- Terry Jan Reedy From azeynel1 at gmail.com Sat Nov 13 14:35:48 2010 From: azeynel1 at gmail.com (Zeynel) Date: Sat, 13 Nov 2010 11:35:48 -0800 (PST) Subject: Is it possible to break a string literal into multiple lines? References: <3d0fefad-1152-4740-a164-b3803ce8eea6@29g2000prb.googlegroups.com> Message-ID: <2250d5a4-57b2-4dc0-bd84-b9cbcd9dab4f@b25g2000vbz.googlegroups.com> Tim Chase and MRAB: Thanks!! On Nov 13, 2:14?pm, Tim Chase wrote: > On 11/13/2010 12:53 PM, Zeynel wrote: > > > > > > > > > > > I have string formatting line in Google App Engine webframe webapp: > > > self.response.out.write("%s:
?mWEIGHT: %s
> > mDATE0_integer: %s
?mCOUNT: %s
" % (result.mUNIQUE, > > result.mWEIGHT, mDATE0_integer, result.mCOUNT,)) > > > I would like to be able to write it as > > > self.response.out.write("%s:
> > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?mWEIGHT: %s
> > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?mDATE0_integer: %s
> > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? mCOUNT: %s
" > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?% > > (result.mUNIQUE, > > > result.mWEIGHT, > > > mDATE0_integer, > > > result.mCOUNT,)) > > > But neither \ or enclosing the string in parens let me break the > > string literal enclosed in "" Is this possible? > > Use python's triple-quoted strings: > > ? ?self.response.out.write("""%s:
> ? ? ? ? mWEIGHT: %s ... > ? ? ? ? ...
""") > > Or alternatively, you can do something like > > ? ?self.response.out.write( > ? ? ?"%s:br />" > ? ? ?"mWEIGHT: %s ..." > ? ? ?... > ? ? ?"...
" > ? ? ?) > > (that excludes newlines and leading whitespace in the string that > gets written, but you can modify the string contents to include > them if you need/want) > > -tkc From dmitrey.kroshko at scipy.org Sat Nov 13 14:41:09 2010 From: dmitrey.kroshko at scipy.org (dmitrey) Date: Sat, 13 Nov 2010 11:41:09 -0800 (PST) Subject: namespace issue, Python vs numpy min/max problem Message-ID: <66c318f3-a659-40ec-ad17-74133639d573@h21g2000vbh.googlegroups.com> hi all, I have the following problem: I have overloaded "max" function in my module (FuncDesigner); it works like following: if some data in arguments is of type "oofun" then my function works, elseware numpy.max() is used. Now the problem: suppose someone writes from FuncDesigner import * ... a = max(0,1) so it calls FuncDesigner, it calls numpy.max and result is 0 (because in numpy it means "max of array with single element 0 along 1st axis"). But if user has not imported numpy then he expected calling ordinary Python max and thus result to be "1". Is there any way to get rid of the problem (somehow automatically determine which func should be used - numpy or Python max)? The same issue with "min", but they are equivalent, of course. From dmitrey.kroshko at scipy.org Sat Nov 13 14:55:21 2010 From: dmitrey.kroshko at scipy.org (dmitrey) Date: Sat, 13 Nov 2010 11:55:21 -0800 (PST) Subject: namespace issue, Python vs numpy min/max problem References: <66c318f3-a659-40ec-ad17-74133639d573@h21g2000vbh.googlegroups.com> Message-ID: <549a97c2-32ac-4b62-87fc-53f19657e293@w18g2000vbe.googlegroups.com> Well, I think I have found an appropriate solution. Regards, D. From mdw at distorted.org.uk Sat Nov 13 15:01:42 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Sat, 13 Nov 2010 20:01:42 +0000 Subject: strange behavor.... References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <87tyjlhu1l.fsf.mdw@metalzone.distorted.org.uk> Terry Reedy writes: > On 11/13/2010 11:29 AM, Mark Wooding wrote: > > > Alas, Python is actually slightly confusing here, since the same > > notation `=' sometimes means assignment and sometimes means mutation. > > I disagree somewhat. An object is mutated by an internal assignment. Some object types are primitive, provided by the runtime system; there are no `internal' variables to be assigned in these cases. (It is possible in principle in Python 3 to implement all of the compound data types using only assignment and closures.) > "ll[0] = 1" assigns 1 to the 0 slot of ll. > "o.a = 1" assigns 1 to the 'a' attribute of o. > This which might be implemented by assigning 1 to the 'a' slot of o.__dict__, > just as "a=1" might be implemented by assigning 1 to the 'a' slot of a > namespace dict. There's a qualitative difference here: simple assignment has semantics defined by the language and provided by the implementation, and can therefore be understood in isolation, using only lexically apparent information; whereas the complex assignments are implemented by invoking methods on the objects mentioned on the left hand side. The objects in question may choose not to implement some other semantics, so the runtime behaviour might not be determinable even in principle without actually executing the program. (Compound assignment has the same problem writ large.) > Assignment *always* binds an object to a target. No! Assignment /never/ binds. There is syntactic confusion here too, since Python interprets a simple assignment in a function body -- in the absence of a declaration such as `global' to the contrary -- as indicating that the variable in question should be bound to a fresh variable on entry to the function. But assignment itself doesn't perform binding. (This is a persistent error in the Python community; or, less charitably, the Python community gratuitously uses the word in a different sense from the wider programming-language-theory community. See Lisp literature passim, for example.) There's a two step mapping: names -> storage locations -> values. Binding affects the left hand part of the mapping; assignment affects the right hand part. -- [mdw] From bmjames at gmail.com Sat Nov 13 15:02:14 2010 From: bmjames at gmail.com (Ben James) Date: Sat, 13 Nov 2010 20:02:14 +0000 Subject: namespace issue, Python vs numpy min/max problem References: <66c318f3-a659-40ec-ad17-74133639d573@h21g2000vbh.googlegroups.com> <549a97c2-32ac-4b62-87fc-53f19657e293@w18g2000vbe.googlegroups.com> Message-ID: On 13/11/2010 19:55, dmitrey wrote: > Well, I think I have found an appropriate solution. > Regards, D. Hi Dmitrey, Would you mind briefly describing your solution? Thanks, Ben From ra.ravi.rav at gmail.com Sat Nov 13 15:07:09 2010 From: ra.ravi.rav at gmail.com (Ravi) Date: Sat, 13 Nov 2010 12:07:09 -0800 (PST) Subject: sqlite3 doesn't raise exception if database is not present/inaccessible References: <0bed5b60-1985-4145-b084-346a5428e42d@i4g2000pro.googlegroups.com> Message-ID: <6415c33b-af1e-48f6-8d9a-efd7b8981ae9@y2g2000prf.googlegroups.com> I understand it now. Thanks for the responses. From clp2 at rebertia.com Sat Nov 13 15:44:58 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 13 Nov 2010 12:44:58 -0800 Subject: strange behavor.... In-Reply-To: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> Message-ID: On Sat, Nov 13, 2010 at 5:46 AM, Tracubik wrote: > hi all, > i've this on python 2.6.6: > >>>> def change_integer(int_value): > ... ? ? int_value = 10 > ... > ... def change_list(list): > ... ? ? list[0] = 10 > ... > ... a = 1 > ... l = [1,1,1] > ... > ... change_integer(a) > ... change_list(l) > ... > ... print a > ... print l > 1 > [10, 1, 1] > > why the integer value doesn't change while the list value do? > in Pascal i can choose the behavour of parametres, how this work on Python? > also a link could be appreciated http://effbot.org/zone/call-by-object.htm Cheers, Chris From tjreedy at udel.edu Sat Nov 13 15:52:46 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 13 Nov 2010 15:52:46 -0500 Subject: namespace issue, Python vs numpy min/max problem In-Reply-To: <66c318f3-a659-40ec-ad17-74133639d573@h21g2000vbh.googlegroups.com> References: <66c318f3-a659-40ec-ad17-74133639d573@h21g2000vbh.googlegroups.com> Message-ID: On 11/13/2010 2:41 PM, dmitrey wrote: > hi all, > I have the following problem: > I have overloaded "max" function in my module (FuncDesigner); it works > like following: > if some data in arguments is of type "oofun" then my function works, > elseware numpy.max() is used. > > Now the problem: > suppose someone writes > from FuncDesigner import * Noone should do that unless your module is **explicitly** designed to be *-imported and you docuement that so that they know it is OK. Now you know why * import is generally discouraged ;-). -- Terry Jan Reedy From davea at ieee.org Sat Nov 13 15:54:31 2010 From: davea at ieee.org (Dave Angel) Date: Sat, 13 Nov 2010 15:54:31 -0500 Subject: strange behavor.... In-Reply-To: <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <4CDEFB07.6070702@ieee.org> On 2:59 PM, Mark Wooding wrote: > Tracubik writes: > >>>>> def change_integer(int_value): >> ... int_value = 10 >> ... >> > > Alas, Python is actually slightly confusing here, since the same > notation `=' sometimes means assignment and sometimes means mutation. > You can tell which is which by looking at the left hand side: if it's a > simple variable name, the variable is assigned a new value; if it's > something more complicated (e.g., indexing (`foo[0]'), or attribute > selection (`foo.bar') then some mutation is (probably) going to happen: No, an (=) assignment is always an assignment. It changes the item on the left hand side to refer to a new object. But if the item on the left hand side is not a simple variable, then generally only part of its contents refers to a new object, rather than the variable itself. For example, mylist[4] = "abc" is assigning a new object to a member of the list, but does not make a new list, replacing the whole list. Your other points, such as about the augmented assignment, are quite useful, however. DaveA From drsalists at gmail.com Sat Nov 13 16:27:36 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Sat, 13 Nov 2010 13:27:36 -0800 Subject: strange behavor.... In-Reply-To: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> Message-ID: On Sat, Nov 13, 2010 at 5:46 AM, Tracubik wrote: > hi all, > i've this on python 2.6.6: > > >>> def change_integer(int_value): > ... int_value = 10 > ... > ... def change_list(list): > ... list[0] = 10 > ... > ... a = 1 > ... l = [1,1,1] > ... > ... change_integer(a) > ... change_list(l) > ... > ... print a > ... print l > 1 > [10, 1, 1] > > why the integer value doesn't change while the list value do? > in Pascal i can choose the behavour of parametres, how this work on Python? > also a link could be appreciated > > Thanks in advance > Nico > -- > http://mail.python.org/mailman/listinfo/python-list > $ cat python-argument-passing #!/usr/bin/python def assign_int(x): print 'id(x) is %d' % id(x) x = 5 # x is now a totally different integer, which won't be reflected in # the caller, because id(x) has changed print 'id(x) is %d' % id(x) def assign_list(list_): # list_ is initially a copy of the reference to list_1 print 'id(list_) is %d' % id(list_) list_ = [ 'a', 'b', 'c' ] # list_ is no a reference to a totally different list, as indicated # by the change in id(). This too won't be reflected in the caller, # because id(list_) has changed print 'id(list_) is %d' % id(list_) def assign_list_element(list_): # list_ is initially a copy of the reference to list_2 print 'id(list_) is %d' % id(list_) list_[1] = 101 # list_ is still a copy of the reference to list_2 - we only changed # one thing in that list, not the list itself. This _will_ be reflected # in the caller, because we're still talking about the same list. print 'id(list_) is %d' % id(list_) x = 1 list_1 = [ 1, 2, 3 ] list_2 = [ 4, 5, 6 ] assign_int(x) print 'x after assign_int(x): %d' % x print assign_list(list_1) print 'list_1 after assign_list(list_1): %s' % list_1 print assign_list_element(list_2) print 'list_1 after assign_list_element(list_2): %s' % list_2 print print 'The author likes to think of all this as pass by value - but' print "when we pass a simple type like an int or float, we're passing" print "the object itself, while for collections of things we're still" print "passing the object itself, but that object _contains_ other things" print "which can easily be changed from the caller's perspective as well." benchbox-dstromberg:~/src/python-var-passing i686-pc-linux-gnu 10388 - above cmd done 2010 Sat Nov 13 01:26 PM $ ./python-argument-passing id(x) is 157519248 id(x) is 157519200 x after assign_int(x): 1 id(list_) is 3077596300 id(list_) is 3077683052 list_1 after assign_list(list_1): [1, 2, 3] id(list_) is 3077682092 id(list_) is 3077682092 list_1 after assign_list_element(list_2): [4, 101, 6] The author likes to think of all this as pass by value - but when we pass a simple type like an int or float, we're passing the object itself, while for collections of things we're still passing the object itself, but that object _contains_ other things which can easily be changed from the caller's perspective as well. benchbox-dstromberg:~/src/python-var-passing i686-pc-linux-gnu 10388 - above cmd done 2010 Sat Nov 13 01:26 PM HTH :) -------------- next part -------------- An HTML attachment was scrubbed... URL: From arnodel at gmail.com Sat Nov 13 16:35:09 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Sat, 13 Nov 2010 21:35:09 +0000 Subject: strange behavor.... References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> <87tyjlhu1l.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <87hbfk29gy.fsf@gmail.com> mdw at distorted.org.uk (Mark Wooding) writes: > Assignment /never/ binds. There is syntactic confusion here too, > since Python interprets a simple assignment in a function body -- in > the absence of a declaration such as `global' to the contrary -- as > indicating that the variable in question should be bound to a fresh > variable on entry to the function. But assignment itself doesn't > perform binding. (This is a persistent error in the Python community; > or, less charitably, the Python community gratuitously uses the word > in a different sense from the wider programming-language-theory > community. See Lisp literature passim, for example.) > > There's a two step mapping: names -> storage locations -> values. > Binding affects the left hand part of the mapping; assignment affects > the right hand part. I'm not sure the notion of "storage location" is useful in Python. I think I understand Python programs correctly using only the notions of "name" and "value" (or object). After execution of the statement: a = 1 The name "a" is bound to the object 1, which means that from then on "a" evaluates to 1. There is no need to know more. As you point out, statements like: a[3] = 1 a.b = 1 are different because they are really function calls, i.e. a.__setitem__(3, 1) a.__setattr__("b", 1) so there is not necessarily any "assigning" or "binding" involved. It is simply a widely followed convention that after the function call: a.__setitem__(3, 1) the function call: a.__getitem__(3) should return 1. Augmented assignment is a different kettle of fish altogether, and IMHO it is the one that confuses things a lot. -- Arnaud From steve at REMOVE-THIS-cybersource.com.au Sat Nov 13 16:38:46 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 13 Nov 2010 21:38:46 GMT Subject: strange behavor.... References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <880c7343-896d-4262-87e6-096dd54f948a@i32g2000pri.googlegroups.com> Message-ID: <4cdf0566$0$29990$c3e8da3$5496439d@news.astraweb.com> On Sat, 13 Nov 2010 05:50:40 -0800, alex23 wrote: > Tracubik wrote: >> why the integer value doesn't change while the list value do? > > http://effbot.org/pyfaq/why-are-default-values-shared-between- objects.htm Right website, wrong page :) http://effbot.org/zone/call-by-object.htm See also Wikipedia's page on parameter passing conventions: http://en.wikipedia.org/wiki/Evaluation_strategy -- Steven From mdw at distorted.org.uk Sat Nov 13 16:42:03 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Sat, 13 Nov 2010 21:42:03 +0000 Subject: strange behavor.... References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <87pqu8j3ys.fsf.mdw@metalzone.distorted.org.uk> Dave Angel writes: > No, an (=) assignment is always an assignment. No. In `foo[0] = bar' it's a method call in disguise. > It changes the item on the left hand side to refer to a new object. Not necessarily. It could do anything at all depending on the type of the recipient object. -- [mdw] From singhvanesa at gmail.com Sat Nov 13 16:52:57 2010 From: singhvanesa at gmail.com (Vanesa Singh) Date: Sat, 13 Nov 2010 13:52:57 -0800 (PST) Subject: want to start your own revenue generation site? Message-ID: <21b74914-5276-4ac3-8d61-3fb243694738@n24g2000prj.googlegroups.com> If you are willing to convert your groups into websites and want to earn huge revenue through your group network- do contact us- we have great service for group owners who has high number of members and messages. Start your own sms, joke, stories, news, jobs website and earn huge from your group user base and articles. We are dedicated php, ajax and open source programmers working in delhi, India. Looking for projects all over the world we can work on any projects in any regional language. We are looking for projects to work upon. If your company, hospital, school, college, non-profits need good interactive website and stores do contact us for services. We have special reduced prices for all non-profits. with warm regards nitin at nitinnaresh.com +91-8800302311 From chris.p.clark at ba.com Sat Nov 13 17:02:21 2010 From: chris.p.clark at ba.com (chris.p.clark at ba.com) Date: Sat, 13 Nov 2010 22:02:21 +0000 Subject: I am away Message-ID: I will be out of the office starting 12/11/2010 and will not return until 16/11/2010. contact Narinder Kumar 0208 738 8871 (narinder.kumar at ba.com) Ian Sherrington (88149) matthew page 0208 738 3519 (matthew.page at ba.com) Greg Lakin 0208 738 3469 (greg.t.lakin at ba.com) Christopher Bristow 208 738 6933 (chris.bristow at ba.com) -- This message is private and confidential and may also be legally privileged. If you have received this message in error, please email it back to the sender and immediately permanently delete it from your computer system. Please do not read, print, re-transmit, store or act in reliance on it or any attachments. British Airways may monitor email traffic data and also the content of emails, where permitted by law, for the purposes of security and staff training and in order to prevent or detect unauthorised use of the British Airways email system. Virus checking of emails (including attachments) is the responsibility of the recipient. British Airways Plc is a public limited company registered in England and Wales. Registered number: 1777777. Registered office: Waterside, PO Box 365, Harmondsworth, West Drayton, Middlesex, England, UB7 0GB. Additional terms and conditions are available on our website: www.ba.com From mdw at distorted.org.uk Sat Nov 13 17:22:00 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Sat, 13 Nov 2010 22:22:00 +0000 Subject: strange behavor.... References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> <87tyjlhu1l.fsf.mdw@metalzone.distorted.org.uk> <87hbfk29gy.fsf@gmail.com> Message-ID: <87hbfkj247.fsf.mdw@metalzone.distorted.org.uk> Arnaud Delobelle writes: > mdw at distorted.org.uk (Mark Wooding) writes: > > > Assignment /never/ binds. There is syntactic confusion here too, > > since Python interprets a simple assignment in a function body -- in > > the absence of a declaration such as `global' to the contrary -- as > > indicating that the variable in question should be bound to a fresh > > variable on entry to the function. But assignment itself doesn't > > perform binding. (This is a persistent error in the Python community; > > or, less charitably, the Python community gratuitously uses the word > > in a different sense from the wider programming-language-theory > > community. See Lisp literature passim, for example.) > > > > There's a two step mapping: names -> storage locations -> values. > > Binding affects the left hand part of the mapping; assignment affects > > the right hand part. > > I'm not sure the notion of "storage location" is useful in Python. We'll see. > I think I understand Python programs correctly using only the notions > of "name" and "value" (or object). Challenge: explain the following code using only those concepts. def foo(): l = [] for i in xrange(10): (lambda j: l.append((lambda: i, lambda: j)))(i) print [(f(), g()) for f, g in l] I explain this as follows. * Python's `for' loop works by assignment. The name `i' remains bound to the same storage location throughout; this binding is established on entry to the function. Since `i' is not rebound in any function lexically enclosed in `foo', every occurrence of `lambda: i' refers to this same storage location. At the end of the loop, this storage location contains the value 9. * The name `j' is rebound repeatedly: in each iteration of the `for' loop, the function `lambda j: ...' is invoked, binding `j' to a fresh storage location into which the value of `i' at the time is stored. Since the function `lambda: j' is lexically enclosed within this function, the name `j' refers to a different storage location in each of these functions, these storage locations are initialized with distinct values 0 up to 9, and they are never changed. * Therefore each `lambda: i' function, when called after the loop, outputs the same value 9; and each `lambda: j' function, when called after the loop, outputs a distinct value. -- [mdw] From steve at REMOVE-THIS-cybersource.com.au Sat Nov 13 17:32:39 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 13 Nov 2010 22:32:39 GMT Subject: strange behavor.... References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> <87tyjlhu1l.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <4cdf1206$0$29990$c3e8da3$5496439d@news.astraweb.com> On Sat, 13 Nov 2010 20:01:42 +0000, Mark Wooding wrote: > Terry Reedy writes: > >> On 11/13/2010 11:29 AM, Mark Wooding wrote: >> >> > Alas, Python is actually slightly confusing here, since the same >> > notation `=' sometimes means assignment and sometimes means mutation. >> >> I disagree somewhat. An object is mutated by an internal assignment. > > Some object types are primitive, provided by the runtime system; there > are no `internal' variables to be assigned in these cases. You seem to be making up your own terminology here, or at least using terminology that isn't normally used in the languages I'm used to. In OO languages such as Python, Java, and (I believe) Ruby, it is conventional to distinguish between objects and "primitives". Primitives are implemented as low-level C-like variables. In that sense, Python has no primitives. Ints, floats, etc. (which are primitives in Java) are full-blown objects in Python. If you mean "primitive" in the sense of "built-in", your conclusion is wrong. Such "primitive" types include dicts and lists, which are sophisticated container objects with internal "variables" to be assigned to: alist[0] = None assigns the value None to the first position in the list. Just because these "variables" aren't *named* variables doesn't mean they don't vary, or that they can't be assigned to. If you mean "primitive" in some other sense, I'm afraid I can't guess what you mean. >> "ll[0] = 1" assigns 1 to the 0 slot of ll. "o.a = 1" assigns 1 to the >> 'a' attribute of o. This which might be implemented by assigning 1 to >> the 'a' slot of o.__dict__, just as "a=1" might be implemented by >> assigning 1 to the 'a' slot of a namespace dict. > > There's a qualitative difference here: simple assignment has semantics > defined by the language and provided by the implementation, and can > therefore be understood in isolation, using only lexically apparent > information; whereas the complex assignments are implemented by invoking > methods on the objects mentioned on the left hand side. Again, you're using unfamiliar terminology. "Simple" and "complex" assignment -- I can guess you mean "name binding" = simple and "any other reference binding" = complex in Python terminology: name = value # simple assignment dict[key] = value # complex assignment obj.attr = value # complex The thing is, the semantics of assigning to built-in components are equally defined by the language as the semantics of name binding. If x is a built-in list or dict, the semantics of: x[something] = value is written in stone and part of the language semantics. Whether that is implemented by a method or not is an irrelevant implementation detail, but for what little it's worth, I believe the CPython implementation is written in a fully procedural fashion, with no methods in sight. One can write: [0, 1, 2, 3, 4][2] = 5 and the language semantics tell you *exactly* what will happen: the value of the list in position 2 will be unbound and the object 5 will be bound in its place. Who cares whether the *implementation* happens to be written as a C function or a Java method, or something else? You are right to point out that for arbitrary types: x[2] = 5 need not be an assignment, since if x is not a built-in x.__setitem__ will be called, and it may do anything it likes. By contrast, name binding: x = 5 *never* calls a method on any object, and therefore is fully defined by the language semantics. The distinction between the two count as an important proviso to the discussion: x[2] = 5 is only an assignment if the type of x is non-pathological and not broken. But putting aside such pathological cases, I don't think you can justify distinguishing between "simple" and "complex" assignment. Names are only one type of reference in Python, not the only one, and assignments other than name-binding can be fully understood from the language semantics *provided you know the type is a built-in*. >> Assignment *always* binds an object to a target. > > No! Assignment /never/ binds. A shocking claim that requires more explanation. If it doesn't bind, what does it do? > There is syntactic confusion here too, > since Python interprets a simple assignment in a function body -- in the > absence of a declaration such as `global' to the contrary -- as > indicating that the variable in question should be bound to a fresh > variable on entry to the function. Well, there seems to be some confusion here, but I don't think it's ours... local variables in functions aren't bound on *entry* to the function. How could they be? They are bound *when the assignment is executed*, which may be never -- hence it is possible to get an UnboundLocalError exception, if you try to retrieve the value of a local which hasn't yet had a value bound to it. > But assignment itself doesn't > perform binding. (This is a persistent error in the Python community; > or, less charitably, the Python community gratuitously uses the word in > a different sense from the wider programming-language-theory community. > See Lisp literature passim, for example.) *Less* charitably? I'm sorry, you think that being *wrong* is better than being *different*? That's not a moral judgment I can agree with. > There's a two step mapping: names -> storage locations -> values. > Binding affects the left hand part of the mapping; assignment affects > the right hand part. That gratuitously conflates the implementation ("storage locations") with the interface. Objects in Python have no storage location, they float in the aether, free to move if the implementation chooses to move them... the CPython implementation doesn't, but some other implementation might do so, but either way *you can't tell the difference* from Python. There is nothing you can write in pure Python that can tell whether the storage location of an object has changed, or even whether "storage location" is a well-defined concept. Nothing in the semantics of Python demand that objects must be implemented as single contiguous blocks of data with a well-defined location. If you can think of an alternative, you're free to write an implementation that uses it. The closest you can come is that CPython exposes the memory location as the id(), but that's not a language promise: Jython and IronPython do not. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Nov 13 17:38:46 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 13 Nov 2010 22:38:46 GMT Subject: namespace issue, Python vs numpy min/max problem References: <66c318f3-a659-40ec-ad17-74133639d573@h21g2000vbh.googlegroups.com> Message-ID: <4cdf1376$0$29990$c3e8da3$5496439d@news.astraweb.com> On Sat, 13 Nov 2010 11:41:09 -0800, dmitrey wrote: > hi all, > I have the following problem: > I have overloaded "max" function in my module (FuncDesigner); it works > like following: > if some data in arguments is of type "oofun" then my function works, > elseware numpy.max() is used. > > Now the problem: > suppose someone writes > from FuncDesigner import * > ... > a = max(0,1) > > so it calls FuncDesigner, it calls numpy.max and result is 0 (because in > numpy it means "max of array with single element 0 along 1st axis"). > But if user has not imported numpy then he expected calling ordinary > Python max and thus result to be "1". That's not your problem, that's the caller's problem. He shouldn't be calling import * unless he wants to import everything in your module directly into his namespace. If the caller said to you: "After executing len = x, I can't access the built-in len function any more, can you change x so that it magically tells when I want the built- in behaviour and does that?" you'd probably tell him to get lost. Doing import * is no different. It only becomes your problem if you have advised people that the right way to use your module is with import *. > Is there any way to get rid of the problem (somehow automatically > determine which func should be used - numpy or Python max)? The same > issue with "min", but they are equivalent, of course. Automatically? No. -- Steven From martin at v.loewis.de Sat Nov 13 17:40:34 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Sat, 13 Nov 2010 23:40:34 +0100 Subject: regenerating unicodedata for py2.7 using py3 makeunicodedata.py? In-Reply-To: References: Message-ID: > Is this intended or even guaranteed for these generated files to be > compatible across py2.7 and py3, or am I going to be bitten by some > less obvious issues later? It works because the generated files are just arrays of structures, and these structures are the same in 2.7 and 3.2. However, there is no guarantee about this property: you will need to check for changes to unicodedata.c to see whether they may affect compatibility. Regards, Martin From steve at REMOVE-THIS-cybersource.com.au Sat Nov 13 17:46:17 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 13 Nov 2010 22:46:17 GMT Subject: strange behavor.... References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> <87pqu8j3ys.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <4cdf1538$0$29990$c3e8da3$5496439d@news.astraweb.com> On Sat, 13 Nov 2010 21:42:03 +0000, Mark Wooding wrote: > Dave Angel writes: > >> No, an (=) assignment is always an assignment. > > No. In `foo[0] = bar' it's a method call in disguise. How does that imply that can't also be an assignment? Of course, you're correct that it's not *necessarily* an assignment, if the type of foo is a pathological or broken class that does weird things on __setitem__. We tend to gloss over that in discussions, in the same way that we gloss over the fact that: len([1,2,3]) does not necessarily return 3, but could in fact do *anything*, depending on whether or not len is still the built-in function or not. I don't think it helps to overload newbies struggling with the basics with such pathological cases though. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Nov 13 17:52:52 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 13 Nov 2010 22:52:52 GMT Subject: strange behavor.... References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <4cdf16c4$0$29990$c3e8da3$5496439d@news.astraweb.com> On Sat, 13 Nov 2010 14:37:44 -0800, Dennis Lee Bieber wrote: > On Sat, 13 Nov 2010 16:29:19 +0000, mdw at distorted.org.uk (Mark Wooding) > declaimed the following in gmane.comp.python.general: > > >> to a function argument /never/ affects the caller in Python. It's >> simply not possible to write a `swap' function in Python. The latter >> means that a value itself changes but the relevant variables continue >> to store the same values. >> > I disagree (borrowing FORTRAN and Ada terms)... > > You can not write a "swap" PROCEDURE in Python... PROCEDUREs do not > return values except via side-effects on the arguments. FUNCTIONs > however, do return values as the function result... Ha, excellent point! But in fairness, in context he was talking about a function that operates purely by side-effects -- what Pascal, Fortran or Ada would call a procedure. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Nov 13 17:55:16 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 13 Nov 2010 22:55:16 GMT Subject: drawing with the mouse with turtle References: <4cdde466$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4cdf1754$0$29990$c3e8da3$5496439d@news.astraweb.com> On Sat, 13 Nov 2010 06:22:59 -0500, Brian Blais wrote: > there is no change by changing the order, but I didn't expect one. > since ondrag is binding a callback, which is only called when the event > happens, I figure that the pen has to be down when the callback happens, > not when the binding occurs. since the pen is down (and never lifted), > when I start dragging the mouse around after that it should work...but > doesn't seem to. Can you tell if your callback is being called at all? In other words, can you distinguish between these? * the callback isn't being called; * the callback is being called, but nothing is being drawn. -- Steven From benjamin at python.org Sat Nov 13 18:08:10 2010 From: benjamin at python.org (Benjamin Peterson) Date: Sat, 13 Nov 2010 17:08:10 -0600 Subject: [RELEASED] Python 3.1.3 release candidate 1 Message-ID: On behalf of the Python development team, I'm gladsome to announce a release candidate of the third bugfix release for the Python 3.1 series, Python 3.1.3. This bug fix release fixes numerous issues found in 3.1.2. Please try it with your packages and report any bugs you find. The final of 3.1.3 is scheduled to be released in two weeks. The Python 3.1 version series focuses on the stabilization and optimization of the features and changes that Python 3.0 introduced. For example, the new I/O system has been rewritten in C for speed. File system APIs that use unicode strings now handle paths with undecodable bytes in them. Other features include an ordered dictionary implementation, a condensed syntax for nested with statements, and support for ttk Tile in Tkinter. For a more extensive list of changes in 3.1, see http://doc.python.org/3.1/whatsnew/3.1.html or Misc/NEWS in the Python distribution. To download Python 3.1.3 visit: http://www.python.org/download/releases/3.1.3/ A list of changes in 3.1.3 can be found here: http://svn.python.org/projects/python/tags/r313rc1/Misc/NEWS The 3.1 documentation can be found at: http://docs.python.org/3.1 Bugs can always be reported to: http://bugs.python.org Enjoy! -- Benjamin Peterson Release Manager benjamin at python.org (on behalf of the entire python-dev team and 3.1.3's contributors) From steve at REMOVE-THIS-cybersource.com.au Sat Nov 13 18:09:18 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 13 Nov 2010 23:09:18 GMT Subject: drawing with the mouse with turtle...solved? References: <4cdde466$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4cdf1a9e$0$29990$c3e8da3$5496439d@news.astraweb.com> On Sat, 13 Nov 2010 09:10:41 -0500, Brian Blais wrote: > Here is code that "works", with at least one small oddity: > > import turtle > > def gothere(event): > turtle.penup() > turtle.goto(event.x-360,340-event.y) > turtle.pendown() > > def movearound(event): > turtle.goto(event.x-360,340-event.y) [...] > the oddity is that the coordinate transformations, x-360 and 340-y, are > done by eye and do not seem to be related to any of the coordinate > values I could find. my screen size is 300x400, the x and y canvas > scales are 1 and 1, but if I try to transform with those numbers the > mouse is clearly off. Have you set the coordinates of the screen? screen.setworldcoordinates What do turtle.window_height() and turtle.window_width() return? -- Steven From benjamin at python.org Sat Nov 13 18:12:22 2010 From: benjamin at python.org (Benjamin Peterson) Date: Sat, 13 Nov 2010 17:12:22 -0600 Subject: [RELEASED] Python 2.7.1 release candidate 1 Message-ID: On behalf of the Python development team, I'm chuffed to announce the a release candidate of Python 2.7.1. Please test the release candidate with your packages and report any bugs you find. 2.7.1 final is scheduled in two weeks. 2.7 includes many features that were first released in Python 3.1. The faster io module, the new nested with statement syntax, improved float repr, set literals, dictionary views, and the memoryview object have been backported from 3.1. Other features include an ordered dictionary implementation, unittests improvements, a new sysconfig module, auto-numbering of fields in the str/unicode format method, and support for ttk Tile in Tkinter. For a more extensive list of changes in 2.7, see http://doc.python.org/dev/whatsnew/2.7.html or Misc/NEWS in the Python distribution. To download Python 2.7.1 visit: http://www.python.org/download/releases/2.7.1/ The 2.7.1 changelog is at: http://svn.python.org/projects/python/tags/r271rc1/Misc/NEWS 2.7 documentation can be found at: http://docs.python.org/2.7/ This is a testing release, so we encourage developers to test it with their applications and libraries. Please report any bugs you find, so they can be fixed in the final release. The bug tracker is at: http://bugs.python.org/ Enjoy! -- Benjamin Peterson Release Manager benjamin at python.org (on behalf of the entire python-dev team and 2.7.1's contributors) From arnodel at gmail.com Sat Nov 13 18:14:22 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Sat, 13 Nov 2010 23:14:22 +0000 Subject: strange behavor.... References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> <87tyjlhu1l.fsf.mdw@metalzone.distorted.org.uk> <87hbfk29gy.fsf@gmail.com> <87hbfkj247.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <87d3q824vl.fsf@gmail.com> mdw at distorted.org.uk (Mark Wooding) writes: > Arnaud Delobelle writes: >> I think I understand Python programs correctly using only the notions >> of "name" and "value" (or object). > > Challenge: explain the following code using only those concepts. > > def foo(): > l = [] > for i in xrange(10): > (lambda j: l.append((lambda: i, lambda: j)))(i) > print [(f(), g()) for f, g in l] > > I explain this as follows. > > * Python's `for' loop works by assignment. The name `i' remains bound > to the same storage location throughout; this binding is established > on entry to the function. Since `i' is not rebound in any function > lexically enclosed in `foo', every occurrence of `lambda: i' refers > to this same storage location. At the end of the loop, this storage > location contains the value 9. I don't need "storage locations". All occurences of the name "i" in the code above belong the the namespace local to the function "foo". > * The name `j' is rebound repeatedly: in each iteration of the `for' > loop, the function `lambda j: ...' is invoked, binding `j' to a > fresh storage location into which the value of `i' at the time is > stored. Since the function `lambda: j' is lexically enclosed within > this function, the name `j' refers to a different storage location > in each of these functions, these storage locations are initialized > with distinct values 0 up to 9, and they are never changed. I don't need "storage locations" to explain this. At each iteration a new lambda function (with a new local namespace) is created and the name "j" belongs to the namespace which is local to the lambda being created. Upon call of the lambda, "j" is bound to the current value of "i". So at each iteration, assignment to "j" is performed in a different namespace. You can argue that I use the notion of "namespace" to explain what you do with "storage locations". However, even with the notion of storage location, you *still* need the notion of namespace to understand Python (see the "lexically enclosed within this function" above). So I still maintain that "storage location" is a superfluous notion in Python. To put it another way, when you say: Two occurences of the name "a" are bound to the same storage location I say: Two occurences of the name "a" belong to the same namespace These are equivalent models (in the sense that they will interpret Python code in the same way), but in order to find out whether two occurences of a name are bound to the same storage location, you need to check whether the names belong to the same namespace! -- Arnaud From mdw at distorted.org.uk Sat Nov 13 18:28:36 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Sat, 13 Nov 2010 23:28:36 +0000 Subject: strange behavor.... References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> <87tyjlhu1l.fsf.mdw@metalzone.distorted.org.uk> <4cdf1206$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: <877hggiz17.fsf.mdw@metalzone.distorted.org.uk> Steven D'Aprano writes: > On Sat, 13 Nov 2010 20:01:42 +0000, Mark Wooding wrote: > > Some object types are primitive, provided by the runtime system; > > there are no `internal' variables to be assigned in these cases. > > You seem to be making up your own terminology here, or at least using > terminology that isn't normally used in the languages I'm used to. I was attempting to define possibly unfamiliar terms as I went along. Did you not notice? > If you mean "primitive" in the sense of "built-in", your conclusion is > wrong. Such "primitive" types include dicts and lists, Yes, those are precisely the ones I was thinking of. > which are sophisticated container objects with internal "variables" to > be assigned to: They have internal state. I don't think that internal state consists of (Python) variables, though. This is why I brought up the possibility of a pure Python implementation, maintaining its state by assigning to variables captured using closures. > > There's a qualitative difference here: simple assignment has semantics > > defined by the language and provided by the implementation, and can > > therefore be understood in isolation, using only lexically apparent > > information; whereas the complex assignments are implemented by invoking > > methods on the objects mentioned on the left hand side. > > Again, you're using unfamiliar terminology. I'm sorry. I thought I defined those terms recently. (It appears not. Sorry.) I meant to refer to assignments in which the target is an identifier (to use the actual terminology from the manual). > "Simple" and "complex" assignment -- I can guess you mean "name > binding" = simple and "any other reference binding" = complex in > Python terminology: Again: assignment is not binding. See the explanation below. > The thing is, the semantics of assigning to built-in components are > equally defined by the language as the semantics of name binding. Did you read what I said? > You are right to point out that for arbitrary types: > > x[2] = 5 > > need not be an assignment, Good. This was /precisely/ what I was pointing out: determining /whether/ the value named by an identifier inhabits one of the built-in types is, in general, hard. > The distinction between the two count as an important proviso to the > discussion: x[2] = 5 is only an assignment if the type of x is > non-pathological and not broken. The latter is not an assignment: it's a disguised method call. > But putting aside such pathological cases, I don't think you can justify > distinguishing between "simple" and "complex" assignment. To conflate them is to confuse two different levels of meaning. Simple assignments occur because the language is hard-wired that way; complex assignments are disguised method calls which often mutate values. > Names are only one type of reference in Python, not the only one, and > assignments other than name-binding can be fully understood from the > language semantics *provided you know the type is a built-in*. > >> Assignment *always* binds an object to a target. > > > > No! Assignment /never/ binds. > > A shocking claim that requires more explanation. If it doesn't bind, > what does it do? Duh! It assigns. You're not usually this slow. Fortunately I explain below. > > There is syntactic confusion here too, since Python interprets a > > simple assignment in a function body -- in the absence of a > > declaration such as `global' to the contrary -- as indicating that > > the variable in question should be bound to a fresh variable on > > entry to the function. > > Well, there seems to be some confusion here, but I don't think it's > ours... local variables in functions aren't bound on *entry* to the > function. How could they be? They are bound *when the assignment is > executed*, which may be never -- hence it is possible to get an > UnboundLocalError exception, if you try to retrieve the value of a local > which hasn't yet had a value bound to it. The exception name perpetuates the misunderstanding, alas; but it's traditional, from Lisp, to say that a variable is `unbound' if it contains no value. > > But assignment itself doesn't perform binding. (This is a > > persistent error in the Python community; or, less charitably, the > > Python community gratuitously uses the word in a different sense > > from the wider programming-language-theory community. See Lisp > > literature passim, for example.) > > *Less* charitably? I'm sorry, you think that being *wrong* is better > than being *different*? That's not a moral judgment I can agree with. Being wrong is perhaps justifiable, and is rectifiable by learning. Being gratuitously different in such a case is to intentionally do a disservice to those coming from or going to other communities where they encounter more conventional uses for the terms in question. > > There's a two step mapping: names -> storage locations -> values. > > Binding affects the left hand part of the mapping; assignment affects > > the right hand part. > > That gratuitously conflates the implementation ("storage locations") There isn't a common term for that concept. I chose `storage location' because it's the term I remember seeing in the denotational semantics for Scheme. The phrase `bound to fresh locations' occurs frequently elsewhere in the Scheme report. It seemed apt. Choose some other term if you please; I merely wanted a term to describe a concept. > with the interface. Objects in Python have no storage location, And now you're confusing `storage locations' (whatever you choose to call them) with values (or `objects'), when my point was precisely that the two are different. > There is nothing you can write in pure Python that can tell whether the > storage location of an object has changed Indeed. Several locations may contain the same value. I remembered that the term `reference' was controversial so I avoided using it. ;-) > or even whether "storage location" is a well-defined concept. I disagree; though it can be a little subtle. Consider: def make_cell(x): def s(y): nonlocal x; x = y return lambda: x, s def copy_cell(c): g, s = c return lambda: g(), lambda y: s(y) Given two such cells (g, s) and (gg, ss), we can determine whether they use the same storage location or not, despite possibly having been constructed using copy_cell, perhaps one from the other, or perhaps (indirectly) from a common proper ancestor. def same_location_p(g, s, gg, ss): fresh = object() old = g() try: s(fresh) return gg() is fresh finally: s(old) Because of `copy_cell' you can't use `id' to solve this problem (at least not without doing serious poking about inside code objects). > Nothing in the semantics of Python demand that objects must be > implemented as single contiguous blocks of data with a well-defined > location. Indeed. I didn't claim otherwise. > The closest you can come is that CPython exposes the memory location > as the id(), but that's not a language promise: Jython and IronPython > do not. No. `id' reveals object identity. The clue is in the name. -- [mdw] From mdw at distorted.org.uk Sat Nov 13 18:32:50 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Sat, 13 Nov 2010 23:32:50 +0000 Subject: strange behavor.... References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <8739r4iyu5.fsf.mdw@metalzone.distorted.org.uk> Dennis Lee Bieber writes: > def swapFunc(a, b): > return b, a That's not what a `swap' function should do. > > Alas, Python is actually slightly confusing here, since the same > > notation `=' sometimes means assignment and sometimes means mutation. > > "=" means just one thing, a rebinding of some identifier to a > different object. Names aren't bound to objects. See elsewhere. > Or, in more general, "=" rebinds the fully qualified name to a > different object, which has the result of mutating a partially qualified > name (a name whose suffix has be removed). Names aren't mutated at all. Values (or, synonymously, objects) are mutated. -- [mdw] From mdw at distorted.org.uk Sat Nov 13 18:40:36 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Sat, 13 Nov 2010 23:40:36 +0000 Subject: strange behavor.... References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> <87pqu8j3ys.fsf.mdw@metalzone.distorted.org.uk> <4cdf1538$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87y68whjwr.fsf.mdw@metalzone.distorted.org.uk> Steven D'Aprano writes: > On Sat, 13 Nov 2010 21:42:03 +0000, Mark Wooding wrote: > > > Dave Angel writes: > > > >> No, an (=) assignment is always an assignment. > > > > No. In `foo[0] = bar' it's a method call in disguise. > > How does that imply that can't also be an assignment? Is `splat(34)' an assignment? If so, I think the term's meaning is grievously diluted. I'd rather say that `splat(34)' might mutate a value, or have side effects, and reserve the term `assignment' for the job of explaining how variables work. That seems pretty tricky, because we're arguing about it a lot, so I think we need sharply defined concepts so that we don't get more confused than we have to be. > Of course, you're correct that it's not *necessarily* an assignment, [...] > I don't think it helps to overload newbies struggling with the basics > with such pathological cases though. I think that we're better off giving `newbies' a conceptual framework which is robust, so that they can understand pathological situations when they occur. -- [mdw] From vlastimil.brom at gmail.com Sat Nov 13 19:10:47 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sun, 14 Nov 2010 01:10:47 +0100 Subject: regenerating unicodedata for py2.7 using py3 makeunicodedata.py? In-Reply-To: References: Message-ID: 2010/11/13 Martin v. Loewis : >> Is this intended or even guaranteed for these generated files to be >> compatible across py2.7 and py3, or am I going to be bitten by some >> less obvious issues later? > > It works because the generated files are just arrays of structures, > and these structures are the same in 2.7 and 3.2. However, there is > no guarantee about this property: you will need to check for changes > to unicodedata.c to see whether they may affect compatibility. > > Regards, > Martin > -- > http://mail.python.org/mailman/listinfo/python-list > Thanks for the confirmation Martin! Do you think, it the mentioned omission of the character names of some CJK ranges in unicodedata intended, or should it be reported to the tracker? Regards, Vlastimil Brom From robert.kern at gmail.com Sat Nov 13 19:13:02 2010 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 13 Nov 2010 18:13:02 -0600 Subject: Some Machine Learning related questions In-Reply-To: <22c10f1d-ded5-46b3-bf7b-74492f12ca64@w38g2000pri.googlegroups.com> References: <22c10f1d-ded5-46b3-bf7b-74492f12ca64@w38g2000pri.googlegroups.com> Message-ID: On 2010-11-13 08:39 , joy99 wrote: > I am looking for a forum, especially an active forum, like this one (I > searched for few in Google, but all seem to be very lazy), where I can > post these questions. http://stats.stackexchange.com/ -- 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 steve at REMOVE-THIS-cybersource.com.au Sat Nov 13 21:07:57 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 14 Nov 2010 02:07:57 GMT Subject: strange behavor.... References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> <87tyjlhu1l.fsf.mdw@metalzone.distorted.org.uk> <87hbfk29gy.fsf@gmail.com> <87hbfkj247.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <4cdf447d$0$29990$c3e8da3$5496439d@news.astraweb.com> On Sat, 13 Nov 2010 22:22:00 +0000, Mark Wooding wrote: > Challenge: explain the following code using only those concepts. ("those concepts" being name and value/object) > def foo(): > l = [] > for i in xrange(10): > (lambda j: l.append((lambda: i, lambda: j)))(i) > print [(f(), g()) for f, g in l] >>> foo() [(9, 0), (9, 1), (9, 2), (9, 3), (9, 4), (9, 5), (9, 6), (9, 7), (9, 8), (9, 9)] Here's a slightly less condensed version that demonstrates the same behaviour, but may be slightly easier to understand: def spam(): a = [] b = [] for i in xrange(5): a.append(lambda: i) b.append(lambda i=i: i) print [f() for f in a] print [f() for f in b] Anyway, here goes... In your function foo, the name "i" is bound to the objects 0, 1, 2, ... 9 sequentially, each time around the for-loop. Inside the loop, a function object is created and then called: (lambda j: l.append((lambda: i, lambda: j)))(i) (Aside: this depends on scoping rules that were introduced quite late in Python's history -- prior to version 2.2, this wouldn't work at all.) The "outer" lambda: lambda j: l.append(...) has a name in the function namespace (a "local variable") called "j". On entry to this function, this j is bound to the same object which is bound to i *at the time that the function is called*. That is, each of the sequence of "outer" lambdas get a distinct j = 0, 1, 2, ... What does these outer lambdas do? They create two more function objects, which I will label "A" and "B": A:: lambda: i B:: lambda: j and places those function objects in a tuple and appends the tuple to the list. What do these "inner" functions do? They have no local variable of their own -- they refer only the i and j of their enclosing scope, namely the "outer" lambda that created them. Note that there isn't actually a single A and a single B, there is a whole series of them... we might label them A0, A1, A2, ... etc. None of the function A0, A1, A2, ... have any local variable i. When you call them, Python looks in the enclosing scopes for a variable i. It doesn't find one in the "outer" lambda, so it next searches the namespace of foo, where it finds the name i bound to the object 9. Hence the inner lambdas Ai always return 9, since 9 is the value of i when the function is called. Functions B0, B1, B2, ... similarly have no local variable j. When you call any of the Bs, Python looks in the enclosing scopes for a variable j. However, in this case it *does* find one, in the "outer" lambda, where the name j has been bound to some object which was determined at the time "outer" was called, namely the value of i *at the time*, and hence 0, 1, 2, ... depending on which specific function you're looking at. Hence the inner lambda Bi returns the value of i *at the time it was defined*. > I explain this as follows. > > * Python's `for' loop works by assignment. The name `i' remains bound > to the same storage location throughout; This is not necessarily true. It's true for CPython, where function locals are implemented as fixed slots in the function object; since the slot doesn't move relative to the function, and the function doesn't move relative to the heap, the name i is in a fixed storage location for the life of foo. But that's not necessarily the case for all implementations -- locals could be stored in a data structure that moves data around (say, a red-black tree), or objects could be free to move in the heap, or both. -- Steven From subhakolkata1234 at gmail.com Sat Nov 13 21:35:52 2010 From: subhakolkata1234 at gmail.com (joy99) Date: Sat, 13 Nov 2010 18:35:52 -0800 (PST) Subject: Some Machine Learning related questions References: <22c10f1d-ded5-46b3-bf7b-74492f12ca64@w38g2000pri.googlegroups.com> Message-ID: <56ce2ba4-00d1-41f7-9d1a-92366703728c@w38g2000pri.googlegroups.com> On Nov 13, 7:39?pm, joy99 wrote: > Dear Group, > > Hope every one is fine. > > I am trying to put some questions. > > I am developing some tool boxes for support vector machine (SVM) and > hidden markov model (HMM). > For HMM I was following the tutorial by Leeds University Computer > Science Department, available online in HTML format, and for SVM I was > following a book on Neural Networks by Simon Haykin. > > After comprehending them, I thought to cross check my knowledge with > the original works. I referred to 1989 Rabiner paper for HMM and SVM > society's tutorial for SVM. > > Here, I am getting some confusions. > > I am looking for a forum, especially an active forum, like this one (I > searched for few in Google, but all seem to be very lazy), where I can > post these questions. > > I felt this room consists of very expert people and I visit it often > moreover it is very active -everytime I posed some question people > solved it very nicely. > > If any one can suggest a solution to my queries taking his/her > valuable time, I would be grateful enough. > > Thanks in advance. > > Apology if it is an unrelated question of the forum. > > Wishing you all a happy winter. > > Best Regards, > Subhabrata. Thanx Robert, It seems a good site. Wishing You A Happy Day Ahead, Best Regards, Subhabrata. From wuwei23 at gmail.com Sat Nov 13 22:20:20 2010 From: wuwei23 at gmail.com (alex23) Date: Sat, 13 Nov 2010 19:20:20 -0800 (PST) Subject: strange behavor.... References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <880c7343-896d-4262-87e6-096dd54f948a@i32g2000pri.googlegroups.com> <4cdf0566$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Right website, wrong page :) > > http://effbot.org/zone/call-by-object.htm D'oh. Thanks for the catch :) From tundra at tundraware.com Sat Nov 13 23:05:57 2010 From: tundra at tundraware.com (Tim Daneliuk) Date: Sat, 13 Nov 2010 22:05:57 -0600 Subject: Looking For Tutorial Comparison Of sh - perl - python Message-ID: <3q34r7-m9s2.ln1@ozzie.tundraware.com> I am putting together a comparison & intro to each of sh, perl, python with a view towards addressing: - What is each language naturally good for - What are their respective strengths and weaknesses - How do they differ paradigmatically Audience is non-programming sysadmins, many of whom are trying to improve their scripting skills. I have written extensive sh and python, considerably less perl. Before I attack this myself, has anyone done something along these lines I could piggyback upon? TIA, -- ---------------------------------------------------------------------------- Tim Daneliuk tundra at tundraware.com PGP Key: http://www.tundraware.com/PGP/ From snehaparitala at gmail.com Sun Nov 14 01:30:51 2010 From: snehaparitala at gmail.com (sms) Date: Sat, 13 Nov 2010 22:30:51 -0800 (PST) Subject: hi Message-ID: <98dfc937-a055-4209-9a5f-e5b42b57beb7@n32g2000pre.googlegroups.com> http://infohivaids.blogspot.com/ From steve at REMOVE-THIS-cybersource.com.au Sun Nov 14 02:35:46 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 14 Nov 2010 07:35:46 GMT Subject: ANN: stats0.1.1a calculator statistics for Python Message-ID: <4cdf9152$0$29990$c3e8da3$5496439d@news.astraweb.com> I am pleased to announce the second public release of stats for Python, and the first targeted at Python 3.x. http://pypi.python.org/pypi/stats stats is a pure-Python module providing basic statistics functions similar to those found on scientific calculators. It has over 40 statistics functions, including: Univariate statistics: * arithmetic, harmonic, geometric and quadratic means * median, mode, midrange, trimean * mean of angular quantities * running and weighted averages * quartiles, hinges and quantiles * variance and standard deviation (sample and population) * average deviation and median average deviation (MAD) * skew and kurtosis * standard error of the mean Multivariate statistics: * Pearson's correlation coefficient * Q-correlation coefficient * covariance (sample and population) * linear regression * sums Sxx, Syy and Sxy and others. This is an unstable alpha release of the software. Feedback and contributions are welcome. -- Steven D'Aprano From arnodel at gmail.com Sun Nov 14 03:15:27 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Sun, 14 Nov 2010 08:15:27 +0000 Subject: strange behavor.... References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> <87tyjlhu1l.fsf.mdw@metalzone.distorted.org.uk> <87hbfk29gy.fsf@gmail.com> <87hbfkj247.fsf.mdw@metalzone.distorted.org.uk> <87d3q824vl.fsf@gmail.com> Message-ID: <878w0w1fts.fsf@gmail.com> Dennis Lee Bieber writes: > On Sat, 13 Nov 2010 23:14:22 +0000, Arnaud Delobelle > declaimed the following in gmane.comp.python.general: > > >> Two occurences of the name "a" belong to the same namespace >> > Pardon? By definition, any given namespace can have only one > occurence of any given name... Well, yes, but I'm talking about occurences *in code*. In the following code: def foo(): a = 1 a = 2 the name "a" occurs twice, both occurences belong to the same namespace. -- Arnaud From franck at ditter.org Sun Nov 14 04:03:56 2010 From: franck at ditter.org (Franck Ditter) Date: Sun, 14 Nov 2010 10:03:56 +0100 Subject: Noob question on 2 vs 3 Python releases Message-ID: Pardon my noobness (?) but why is there a 2.x and 3.x development teams working concurrently in Python ? I hardly saw that in other languages. Which one should I choose to start with, to cope with the future ? Isn't 3.x supposed to extend 2.y ? This situation is very strange... Thanks for your explanations... franck From clp2 at rebertia.com Sun Nov 14 04:11:20 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 14 Nov 2010 01:11:20 -0800 Subject: Noob question on 2 vs 3 Python releases In-Reply-To: References: Message-ID: On Sun, Nov 14, 2010 at 1:03 AM, Franck Ditter wrote: > Pardon my noobness (?) but why is there a 2.x and 3.x development > teams working concurrently in Python ? I hardly saw that in other > languages. You haven't heard of the infamous Perl 6? > Which one should I choose to start with, to cope with > the future ? Read http://wiki.python.org/moin/Python2orPython3 > Isn't 3.x supposed to extend 2.y ? Not just extend. It also makes some *backwards-incompatible* removals and revisions, hence the different major version number. Cheers, Chris -- http://blog.rebertia.com From xrgtn at yandex.ru Sun Nov 14 05:00:48 2010 From: xrgtn at yandex.ru (Alexander Gattin) Date: Sun, 14 Nov 2010 12:00:48 +0200 Subject: Copy Protected PDFs and PIL In-Reply-To: References: Message-ID: <20101114100048.GA3999@xrgtn-q40> Hello, On Fri, Nov 12, 2010 at 12:00:55PM -0800, Brett Bowman wrote: > MRAB - > I've tried worker threads, and it kills the > thread only and not the program as a whole. I > could use that as a work-around, but I would > prefer something more direct, in case other > problems arise. Looks like the gfx module doesn't raise an exception but terminates the thread instead (strange that not the whole process -- I'd use strace/truss/tusc to see what happens). So running gfx's render() tasks in separate threads or processes may be your only workaround. BTW, when your child process dies it's good idea to find out the cause of its death. So you can check its: * exitcode/WTERMSIG/WCOREDUMP * stderr/stdout (if you run it through popen*()) * your own IPS, like e.g. child process sending some short message over the pipe/socket that describes what it's about to do (like in your example below): > import gfx > print "1" > doc = gfx.open("pdf", MY_FILE) > print "2" > page1 = doc.getPage(1) > print "3" > g_img = gfx.ImageList() > print "4" > g_img.startpage(a_page.width,a_page.height) > print "5" > a_page.render(g_img) > print "6" > g_img.endpage() > print "7" > g_img.save(TEMP_PNG) > > which prints the following: > > 1 > 2 > 3 > 4 > 5 This way a parent process can tell that its child most has died during a_page.render(g_img)... -- With best regards, xrgtn From iamforufriends at gmail.com Sun Nov 14 07:34:28 2010 From: iamforufriends at gmail.com (naughty girl) Date: Sun, 14 Nov 2010 04:34:28 -0800 (PST) Subject: NAUGHTY GIRL, WANNA NAUGHTY WITH ME, COME ON...really free... Message-ID: <4f404880-63a3-487c-af90-4e812cb7a7b1@37g2000prx.googlegroups.com> NAUGHTY GIRL, WANNA NAUGHTY WITH ME, COME ON...really free... FREE GOLD MEMBER FOR FEMALE PROFILE, registar with female gender for free access http://goo.gl/1bour http://www.benaughty.com/aff.php?a_aid=27340f40&a_bid=17a6530c From martin at address-in-sig.invalid Sun Nov 14 08:00:47 2010 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Sun, 14 Nov 2010 13:00:47 +0000 (UTC) Subject: Looking For Tutorial Comparison Of sh - perl - python References: <3q34r7-m9s2.ln1@ozzie.tundraware.com> Message-ID: On Sat, 13 Nov 2010 22:05:57 -0600, Tim Daneliuk wrote: > I am putting together a comparison & intro to each of sh, perl, python > with a view towards addressing: > Add awk / gawk to that list. IME its often the easiest and most concise way to process a text file, e.g. a log file, while applying different processing rules depending on line content and/or generating summaries. > Before I attack this myself, has anyone done > something along these lines I could piggyback upon? > I haven't seen such a comparison, but that doesn't meant that they don't exist. -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From news1234 at free.fr Sun Nov 14 08:12:48 2010 From: news1234 at free.fr (News123) Date: Sun, 14 Nov 2010 14:12:48 +0100 Subject: how to identify currently running threads QTHreads Message-ID: <4cdfe050$0$10182$426a34cc@news.free.fr> Hi I'm working with several persons on a PyQT python application. This application is using threads / QThreads in several places. When trying to quit the application it doesn't stop. I assume one thread / QThread did not stop. (wasn't declared as daemon thread) Is there a simple way in Python to identify all active Threads / QThreads when trying, such that I can locate the thread, itls related python code and fix it? Thanks for any suggestions. From ph.ton.sharma at gmail.com Sun Nov 14 09:48:38 2010 From: ph.ton.sharma at gmail.com (ton ph) Date: Sun, 14 Nov 2010 20:18:38 +0530 Subject: Help: Guide needed in trying to delete/flush the content of a fifo file. Message-ID: Hi python geeks, I have problem which i have been trying to find out for the past some days, i have a device which feeds info to my fifo continuosly, and a thread of mine reads the fifo continuosly. Now when i change a parameter in the device, it sends me different values. Now my problem is that , i want to get rid of the contents of my previous info which is present in my buffer of the fifo.So i want to flush the fifo content when my device starts sending different info .... i am implementing writing and reading the fifo using two different threads. Please someone guide me solving my problem. I highly apologise everyone in case my post is not so clear... Thanks everyone in advance. -------------- next part -------------- An HTML attachment was scrubbed... URL: From scott.stephens.j at gmail.com Sun Nov 14 09:51:49 2010 From: scott.stephens.j at gmail.com (otenki) Date: Sun, 14 Nov 2010 06:51:49 -0800 (PST) Subject: another newbie question Message-ID: Hello Pythonistas! I'm trying to get floating point division to work; I'm using Python 2.6.5. When I enter 'from _future_ import division' at the command line, I get the ImportError, no module named _future_. How can I rectify this? Sorry for this basic question, but I don't know where else to turn. Thanks, Scott From nitinpawar432 at gmail.com Sun Nov 14 10:00:09 2010 From: nitinpawar432 at gmail.com (Nitin Pawar) Date: Sun, 14 Nov 2010 20:30:09 +0530 Subject: another newbie question In-Reply-To: References: Message-ID: >From the error, you are importing wrong module which actually does not exists try importing something from maths On Sun, Nov 14, 2010 at 8:21 PM, otenki wrote: > Hello Pythonistas! > I'm trying to get floating point division to work; I'm using Python > 2.6.5. When I enter 'from _future_ import division' at the command > line, I get the ImportError, no module named _future_. How can I > rectify this? > Sorry for this basic question, but I don't know where else to turn. > Thanks, > Scott > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -------------- next part -------------- An HTML attachment was scrubbed... URL: From tim at westpark-club.org.uk Sun Nov 14 10:01:15 2010 From: tim at westpark-club.org.uk (Tim Golden) Date: Sun, 14 Nov 2010 15:01:15 +0000 Subject: another newbie question In-Reply-To: References: Message-ID: <4CDFF9BB.4020504@westpark-club.org.uk> On 14/11/2010 3:00 PM, Nitin Pawar wrote: >> I'm trying to get floating point division to work; I'm using Python >> 2.6.5. When I enter 'from _future_ import division' at the command >> line, I get the ImportError, no module named _future_. How can I >> rectify this? That should be two underscores, not one: from __future__ import division TJG From __peter__ at web.de Sun Nov 14 10:03:23 2010 From: __peter__ at web.de (Peter Otten) Date: Sun, 14 Nov 2010 16:03:23 +0100 Subject: another newbie question References: Message-ID: otenki wrote: > Hello Pythonistas! > I'm trying to get floating point division to work; I'm using Python > 2.6.5. When I enter 'from _future_ import division' at the command > line, I get the ImportError, no module named _future_. How can I > rectify this? You need two leading/trailing underscores, not one: >>> 1/2 0 >>> from __future__ import division >>> 1/2 0.5 From bouncingcats at gmail.com Sun Nov 14 10:09:47 2010 From: bouncingcats at gmail.com (David) Date: Mon, 15 Nov 2010 02:09:47 +1100 Subject: another newbie question In-Reply-To: References: Message-ID: On 15/11/2010, otenki wrote: > When I enter 'from _future_ import division' at the command > line, I get the ImportError, no module named _future_. The module name is "__future__" Notice that there are 2 underscore characters before the word "future" and 2 after it. This is a common convention in python. From scott.stephens.j at gmail.com Sun Nov 14 10:17:11 2010 From: scott.stephens.j at gmail.com (otenki) Date: Sun, 14 Nov 2010 07:17:11 -0800 (PST) Subject: another newbie question References: Message-ID: <42686808-8148-47f3-8cd2-abb553c3df38@o11g2000prf.googlegroups.com> On Nov 14, 10:09?am, David wrote: > On 15/11/2010, otenki wrote: > > > When I enter 'from _future_ import division' at the command > > line, I get the ImportError, no module named _future_. > > The module name is "__future__" > > Notice that there are 2 underscore characters before the word "future" > and 2 after it. This is a common convention in python. Thanks to all for your quick responses to my newbie question. It is much appreciated!!! Scott From gol.sexy.gol7 at gmail.com Sun Nov 14 10:58:43 2010 From: gol.sexy.gol7 at gmail.com (SEXY) Date: Sun, 14 Nov 2010 07:58:43 -0800 (PST) Subject: =?UTF-8?B?2KrYudmA2KLYsdmBICDYqNmE2YrYotix2K/ZiA==?= Message-ID: <2074de3d-64b0-410a-af59-064d6d5bf9b2@z22g2000pri.googlegroups.com> http://gamezer.com.billiards.downbux.net/play-1/?id=1150 From azeynel1 at gmail.com Sun Nov 14 11:14:21 2010 From: azeynel1 at gmail.com (Zeynel) Date: Sun, 14 Nov 2010 08:14:21 -0800 (PST) Subject: Why datetime module is so complicated? Message-ID: <10fb6248-cc3e-433d-89c8-4620ddf673cb@v12g2000vbh.googlegroups.com> It's about a week now I've been trying to convert a datetime object to seconds since epoch; the object is set to current time by class Rep() in Google App Engine: class Rep(db.Model): ... mCOUNT = db.IntegerProperty() mDATE0 = db.DateTimeProperty(auto_now_add=True) mWEIGHT = db.FloatProperty() I want to divide mDATE0 by the integer mCOUNT. I asked the same question here previously and also at stackoverflow. So far, I still cannot make it work. I would greatly appreciate if someone who is an expert in datetime operation in Python could help me understand this issue. Thank you. Latest question in Stackoverlow with link to my original question there: http://stackoverflow.com/questions/4178125/datetime-and-utctimetuple Previous discussions at comp.lang.python: http://groups.google.com/group/comp.lang.python/browse_frm/thread/ac9a2c89bed67869/28c7c7b8d48f3805?hl=en#28c7c7b8d48f3805 http://groups.google.com/group/comp.lang.python/browse_frm/thread/a5aeb6c40ae08450/fd9b42e0c403380e?hl=en#fd9b42e0c403380e From emile at fenx.com Sun Nov 14 11:29:16 2010 From: emile at fenx.com (Emile van Sebille) Date: Sun, 14 Nov 2010 08:29:16 -0800 Subject: strange behavor.... In-Reply-To: <877hggiz17.fsf.mdw@metalzone.distorted.org.uk> References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> <87tyjlhu1l.fsf.mdw@metalzone.distorted.org.uk> <4cdf1206$0$29990$c3e8da3$5496439d@news.astraweb.com> <877hggiz17.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On 11/13/2010 3:28 PM Mark Wooding said... > Steven D'Aprano writes: > >> On Sat, 13 Nov 2010 20:01:42 +0000, Mark Wooding wrote: >>> Some object types are primitive, provided by the runtime system; >>> there are no `internal' variables to be assigned in these cases. >> >> You seem to be making up your own terminology here, or at least using >> terminology that isn't normally used in the languages I'm used to. > > I was attempting to define possibly unfamiliar terms as I went along. > Did you not notice? > You both make valid points when viewed from the specific writer's perspective. I think you're speaking past each other because Steven and others are explaining terms in their common python context in an attempt to have Mark understand and use them similarly, which is of most benefit to our community. Mark on the other hand is attempting to make sense of our common terms in light of similarly termed constructs from his experience, which of course we all have done and do as we continue to learn, but with an apparent effort to change our common usage. Mark says "The latter is not an assignment: it's a disguised method call." We all know that _everything_ is a disguised method call and we call the disguised method call that resembles a statement where the LHS is separated from the RHS by a single equals sign assignment. In the long run, Mark can choose to either further and complete his understanding and adopt python's commonly understood terminology; or continue to point to how in other languages the usage of terms also used in python conflicts with the established meaning of those terms as implemented in python. The difference between "developing contributor" and "trolling" turns on when this acceptance starts. My .02. Emile From aahz at pythoncraft.com Sun Nov 14 11:32:38 2010 From: aahz at pythoncraft.com (Aahz) Date: 14 Nov 2010 08:32:38 -0800 Subject: how to identify currently running threads QTHreads References: <4cdfe050$0$10182$426a34cc@news.free.fr> Message-ID: In article <4cdfe050$0$10182$426a34cc at news.free.fr>, News123 wrote: > >Is there a simple way in Python to identify all active Threads / >QThreads when trying, such that I can locate the thread, itls related >python code and fix it? threading.enumerate() or sys._current_frames() -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Look, it's your affair if you want to play with five people, but don't go calling it doubles." --John Cleese anticipates Usenet From roy at panix.com Sun Nov 14 11:40:56 2010 From: roy at panix.com (Roy Smith) Date: Sun, 14 Nov 2010 11:40:56 -0500 Subject: another newbie question References: Message-ID: In article , David wrote: > On 15/11/2010, otenki wrote: > > When I enter 'from _future_ import division' at the command > > line, I get the ImportError, no module named _future_. > > The module name is "__future__" > > Notice that there are 2 underscore characters before the word "future" > and 2 after it. This is a common convention in python. I suppose the double-underscore convention was a questionable choice, given how many fixed width fonts make it difficult to discern the gap between them. In fact, in most fonts, it's an intentional design goal that they run together (think of it as a sort of recurisive ligature). That being said, it is what it is, and isn't changing. I'm really picky about what font I use for coding. For years, I've stuck to Apple's Monaco, antialised. In the latest version of the OS (Snow Leopard), they added a new font called Menio. When I first looked at it, I couldn't tell the difference, and decided to stick with Monaco. I just opened up TextEdit and tried looking at __ (double underscore) in various fonts. Lo and behold, you can see the gap in Monaco, and the two run completely together in Menio. I'm still searching for as nice a font to use on Linux. Then, there are people who try to program in proportional fonts. The mind boggles. For a (thankfully short) while some years ago, people were publishing programming books with the code samples in proportional fonts. Blech. From deets at web.de Sun Nov 14 11:53:42 2010 From: deets at web.de (Diez B. Roggisch) Date: Sun, 14 Nov 2010 17:53:42 +0100 Subject: Why datetime module is so complicated? References: <10fb6248-cc3e-433d-89c8-4620ddf673cb@v12g2000vbh.googlegroups.com> Message-ID: Zeynel writes: > It's about a week now I've been trying to convert a datetime object to > seconds since epoch; the object is set to current time by class Rep() > in Google App Engine: > > class Rep(db.Model): > ... > mCOUNT = db.IntegerProperty() > mDATE0 = db.DateTimeProperty(auto_now_add=True) > mWEIGHT = db.FloatProperty() > > I want to divide mDATE0 by the integer mCOUNT. I asked the same > question here previously and also at stackoverflow. So far, I still > cannot make it work. I would greatly appreciate if someone who is an > expert in datetime operation in Python could help me understand this > issue. Thank you. >>> from datetime import * >>> d = datetime.now() >>> dir(d) ['__add__', '__class__', '__delattr__', '__doc__', '__eq__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__ne__', '__new__', '__radd__', '__reduce__', '__reduce_ex__', '__repr__', '__rsub__', '__setattr__', '__str__', '__sub__', 'astimezone', 'combine', 'ctime', 'date', 'day', 'dst', 'fromordinal', 'fromtimestamp', 'hour', 'isocalendar', 'isoformat', 'isoweekday', 'max', 'microsecond', 'min', 'minute', 'month', 'now', 'replace', 'resolution', 'second', 'strftime', 'strptime', 'time', 'timetuple', 'timetz', 'today', 'toordinal', 'tzinfo', 'tzname', 'utcfromtimestamp', 'utcnow', 'utcoffset', 'utctimetuple', 'weekday', 'year'] >>> d.time() datetime.time(17, 50, 54, 778159) >>> d.ctime() 'Sun Nov 14 17:50:54 2010' >>> d.time >>> d.timetuple() (2010, 11, 14, 17, 50, 54, 6, 318, -1) >>> import time >>> dir(time) ['__doc__', '__file__', '__name__', 'accept2dyear', 'altzone', 'asctime', 'clock', 'ctime', 'daylight', 'gmtime', 'localtime', 'mktime', 'sleep', 'strftime', 'strptime', 'struct_time', 'time', 'timezone', 'tzname', 'tzset'] >>> help(time.mktime) >>> time.mktime(d.timetuple()) 1289753454.0 >>> Not that hard. Diez From nfdisco at gmail.com Sun Nov 14 11:58:42 2010 From: nfdisco at gmail.com (ernest) Date: Sun, 14 Nov 2010 08:58:42 -0800 (PST) Subject: raise Exception or raise Exception() Message-ID: <1b51a22c-a9ec-4d58-8dc5-ddb62628fc0f@w21g2000vby.googlegroups.com> I have seen both forms and I'm not sure if they're both correct, or one is right and the other wrong. In practical terms, the two of them seem to have the same effect. Cheers, Ernest From vlastimil.brom at gmail.com Sun Nov 14 11:59:50 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sun, 14 Nov 2010 17:59:50 +0100 Subject: Why datetime module is so complicated? In-Reply-To: <10fb6248-cc3e-433d-89c8-4620ddf673cb@v12g2000vbh.googlegroups.com> References: <10fb6248-cc3e-433d-89c8-4620ddf673cb@v12g2000vbh.googlegroups.com> Message-ID: 2010/11/14 Zeynel : > It's about a week now I've been trying to convert a datetime object to > seconds since epoch; the object is set to current time by class Rep() > in Google App Engine: > > class Rep(db.Model): > ? ?... > ? ?mCOUNT = db.IntegerProperty() > ? ?mDATE0 = db.DateTimeProperty(auto_now_add=True) > ? ?mWEIGHT = db.FloatProperty() > > I want to divide mDATE0 by the integer mCOUNT. I asked the same > question here previously and also at stackoverflow. So far, I still > cannot make it work. I would greatly appreciate if someone who is an > expert in datetime operation in Python could help me understand this > issue. Thank you. > > Latest question in Stackoverlow with link to my original question > there: http://stackoverflow.com/questions/4178125/datetime-and-utctimetuple > > Previous discussions at comp.lang.python: > > http://groups.google.com/group/comp.lang.python/browse_frm/thread/ac9a2c89bed67869/28c7c7b8d48f3805?hl=en#28c7c7b8d48f3805 > > http://groups.google.com/group/comp.lang.python/browse_frm/thread/a5aeb6c40ae08450/fd9b42e0c403380e?hl=en#fd9b42e0c403380e > -- > http://mail.python.org/mailman/listinfo/python-list > Hi, just a try, as it is not completely clear to me, what you are trying to achieve, as I don't have experiences with the mentioned framework. It seems to me, that you can only reasonably divide timedeltas, not the absolute timestamps, it might be something like the following: >>> april_1st=datetime.datetime(2010, 4, 1, 11, 55, 00) >>> may_1st=datetime.datetime(2010, 5, 1, 11, 54, 03, 123456) >>> delta_dates = may_1st - april_1st >>> delta_in_secs = delta_dates.total_seconds() >>> delta_in_secs 2591943.123456 >>> delta_in_secs / 5.2 498450.60066461534 >>> hth, vbr From clp2 at rebertia.com Sun Nov 14 13:14:47 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 14 Nov 2010 10:14:47 -0800 Subject: raise Exception or raise Exception() In-Reply-To: <1b51a22c-a9ec-4d58-8dc5-ddb62628fc0f@w21g2000vby.googlegroups.com> References: <1b51a22c-a9ec-4d58-8dc5-ddb62628fc0f@w21g2000vby.googlegroups.com> Message-ID: On Sun, Nov 14, 2010 at 8:58 AM, ernest wrote: > I have seen both forms and I'm not sure if they're > both correct, or one is right and the other wrong. They're both acceptable (although obviously you should always raise a more specific error than Exception). `raise SomeException` is in fact equivalent to `raise SomeException()`. Providing an error message is always advisable though, so really in most cases you ought to `raise SomeException("Informative error message")` Cheers, Chris -- http://blog.rebertia.com From mammique at garbure.org Sun Nov 14 13:50:54 2010 From: mammique at garbure.org (Camille Harang) Date: Sun, 14 Nov 2010 19:50:54 +0100 Subject: subprocess pipe Message-ID: Hi all, I'm having a problem with subprocess.Popen. It seems that its unable to capture the pg_dump's standard inputs & outputs in a non-shell mode: from subprocess import Popen, PIPE # fire pg_dump in order to read data from the file object pgsql.stdout pgsql = Popen(['/usr/bin/pg_dump', '--host', 'localhost', '--password', '--username', 'mammique'], stdin=PIPE, stderr=PIPE, stdout=PIPE, shell=True) # pg_dump prompts for password so I inject it in stdin. pgsql.stdin.write('MY_PASSWORD' + '\n') In the shell mode (shell=True) pipes works but the args (username, etc.) are omitted. If I turn to shell=False the arguments are passed to pg_dump but subprocess.Popen is no longer able to capture the standard inputs & outputs, the password prompt appears on the TTY instead and doesn't take the input written in stdin. It seems that subprocess.Popen has only this problem with pg_dump, other interactive command lines seems to be correctly handled. Any lead? Thanks, Camille. From python at mrabarnett.plus.com Sun Nov 14 13:55:55 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 14 Nov 2010 18:55:55 +0000 Subject: Help: Guide needed in trying to delete/flush the content of a fifo file. In-Reply-To: References: Message-ID: <4CE030BB.20500@mrabarnett.plus.com> On 14/11/2010 14:48, ton ph wrote: > Hi python geeks, > I have problem which i have been trying to find out for the past > some days, i have a device which feeds info to my fifo continuosly, and > a thread of mine reads the > fifo continuosly. Now when i change a parameter in the device, it sends > me different values. Now my problem is that , i want to get rid of the > contents of my previous info which > is present in my buffer of the fifo.So i want to flush the fifo content > when my device starts sending different info .... i am implementing > writing and reading the fifo using two different threads. > Please someone guide me solving my problem. > I highly apologise everyone in case my post is not so clear... > Thanks everyone in advance. > When the info changes, the thread which is putting items into the fifo could flush it just by getting items from it (using a non-blocking get) until it's empty. From python at mrabarnett.plus.com Sun Nov 14 13:59:33 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 14 Nov 2010 18:59:33 +0000 Subject: another newbie question In-Reply-To: References: Message-ID: <4CE03195.9010800@mrabarnett.plus.com> On 14/11/2010 16:40, Roy Smith wrote: > In article, > David wrote: > >> On 15/11/2010, otenki wrote: >>> When I enter 'from _future_ import division' at the command >>> line, I get the ImportError, no module named _future_. >> >> The module name is "__future__" >> >> Notice that there are 2 underscore characters before the word "future" >> and 2 after it. This is a common convention in python. > > I suppose the double-underscore convention was a questionable choice, > given how many fixed width fonts make it difficult to discern the gap > between them. In fact, in most fonts, it's an intentional design goal > that they run together (think of it as a sort of recurisive ligature). > That being said, it is what it is, and isn't changing. > [snip] Guido chose double underscores because CPython is written in C and that's what C uses. It's true that with hindsight it was a mistake... From micah at greentackle.com Sun Nov 14 14:00:18 2010 From: micah at greentackle.com (Micah Carrick) Date: Sun, 14 Nov 2010 11:00:18 -0800 Subject: Objects versus dictionaries Message-ID: I'm writing a little API that other people will use. There are up to 3 "objects" that get passed around. One of them has some validation methods, the other two simply store data and probably won't have any validation or other methods. I only made them objects so that they are syntactically (is that a word?) similar the other object rather than using dictionaries. I figure it also better allows for changes in the future. Any thoughts on the pros/cons of using my own objects over a dictionary objects? # this is what I have now... stuff = Stuff(foo="foo", bar="bar") if stuff.is_valid(): cust = Customer(name="John", email="foo at bar.com") order = Order(order_id=1234, amount=12.99) SomeObject.some_method(stuff, cust, order) # this would also work... stuff = Stuff(foo="foo", bar="bar") if stuff.is_valid(): cust = { 'name': "John", 'email': "foo at bar.com" } order = { 'order_id': 1234, 'amount': 12.99 } SomeObject.some_method(stuff, cust, order) -- Micah Carrick -------------- next part -------------- An HTML attachment was scrubbed... URL: From kern.ra at gmail.com Sun Nov 14 14:07:40 2010 From: kern.ra at gmail.com (Becky Kern) Date: Sun, 14 Nov 2010 14:07:40 -0500 Subject: [Beginner question] Raster to ASCII Message-ID: Hi users, I'm using Python 2.5 (in concert with ArcGIS 9.3) to convert a raster to an ASCII file. I used the code (listed below) several weeks ago to successfully do the conversion, but when I tried to replicate it a few days ago, I got an error message. import arcgisscripting gp = arcgisscripting.create(9.3) InRaster = "C:/data/raster1" OutAsciiFile = "C:/data/raster2ascii.asc" gp.RasterToASCII_conversion(InRaster, OutAsciiFile) The error message: arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid. raster1 does not exist. My file path has not changed so I don't understand why Python can no longer recognize my raster file. Any ideas? -------------- next part -------------- An HTML attachment was scrubbed... URL: From artur.siekielski at gmail.com Sun Nov 14 14:08:08 2010 From: artur.siekielski at gmail.com (Artur Siekielski) Date: Sun, 14 Nov 2010 11:08:08 -0800 (PST) Subject: Getting references to objects without incrementing reference counters Message-ID: <8c98a453-3303-4509-be39-1a26084f573a@o11g2000prf.googlegroups.com> Hi. I'm using CPython 2.7 and Linux. In order to make parallel computations on a large list of objects I want to use multiple processes (by using multiprocessing module). In the first step I fill the list with objects and then I fork() my worker processes that do the job. This should work optimally in the aspect of memory usage because Linux implements copy-on-write in forked processes. So I should have only one physical list of objects (the worker processes don't change the objects on the list). The problem is that after a short time children processes are using more and more memory (they don't create new objects - they only read objects from the list and write computation result to the database). After investigation I concluded the source of this must be incrementing of a reference counter when getting an object from the list. It changes only one int but OS must copy the whole memory page to the child process. I reimplemented the function for getting the element (from the file listobject.c) but omitting the PY_INCREF call and it solved my problems with increasing memory. The questions is: are there any better ways to have a real read-only list (in terms of memory representation of objects)? My solution is of course not safe. I thought about weakrefs but it seems they cannot be used here because getting a real reference from a weakref increases a reference counter. Maybe another option would be to store reference counters not in objects, but in a separate array to minimize number of memory pages they occupy... From clp2 at rebertia.com Sun Nov 14 14:15:53 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 14 Nov 2010 11:15:53 -0800 Subject: subprocess pipe In-Reply-To: References: Message-ID: On Sun, Nov 14, 2010 at 10:50 AM, Camille Harang wrote: > Hi all, > > I'm having a problem with subprocess.Popen. It seems that its unable to > capture the pg_dump's standard inputs & outputs in a non-shell mode: > > from subprocess import Popen, PIPE > > # fire pg_dump in order to read data from the file object pgsql.stdout > pgsql = Popen(['/usr/bin/pg_dump', > ? ? ? ? ? ? ? '--host', 'localhost', > ? ? ? ? ? ? ? '--password', > ? ? ? ? ? ? ? '--username', > ? ? ? ? ? ? ? 'mammique'], > ? ? ? ? ? ? ?stdin=PIPE, > ? ? ? ? ? ? ?stderr=PIPE, > ? ? ? ? ? ? ?stdout=PIPE, > ? ? ? ? ? ? ?shell=True) > > # pg_dump prompts for password so I inject it in stdin. > pgsql.stdin.write('MY_PASSWORD' + '\n') > > In the shell mode (shell=True) pipes works but the args (username, etc.) > are omitted. If I turn to shell=False the arguments are passed to > pg_dump but subprocess.Popen is no longer able to capture the standard > inputs & outputs, the password prompt appears on the TTY instead and > doesn't take the input written in stdin. It seems that subprocess.Popen > has only this problem with pg_dump, other interactive command lines > seems to be correctly handled. > > Any lead? Quoting http://docs.python.org/library/subprocess.html , emphasis mine: """ On Unix, with shell=True: [...] If args is a sequence, ***the first item*** specifies the command string, and any additional items will be treated as additional arguments ***to the shell itself***. """ So if you're using shell=True, pass a single string rather than a tokenized list. That is to say: command = "/usr/bin/pg_dump --host localhost --password --username mammique" pgsql = Popen(command, stdin=PIPE, stderr=PIPE, stdout=PIPE, shell=True) Cheers, Chris -- http://blog.rebertia.com From clp2 at rebertia.com Sun Nov 14 14:20:48 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 14 Nov 2010 11:20:48 -0800 Subject: Objects versus dictionaries In-Reply-To: References: Message-ID: On Sun, Nov 14, 2010 at 11:00 AM, Micah Carrick wrote: > I'm writing a little API that other people will use. There are up to 3 > "objects" that get passed around. One of them has some validation methods, > the other two simply store data and probably won't have any validation or > other methods. I only made them objects so that they are syntactically (is > that a word?) similar the other object rather than using dictionaries. I > figure it also better allows for changes in the future. > > Any thoughts on the pros/cons of using my own objects over a dictionary > objects? Objects are definitely nicer to work with syntactically, and they help make your program's types more explicit. Rather than coding the "data holder" classes manually, consider using namedtuples instead: http://docs.python.org/library/collections.html#collections.namedtuple Cheers, Chris -- http://blog.rebertia.com From mammique at yooook.net Sun Nov 14 14:25:30 2010 From: mammique at yooook.net (Camille Harang) Date: Sun, 14 Nov 2010 20:25:30 +0100 Subject: subprocess pipe In-Reply-To: References: Message-ID: <4CE037AA.1050309@yooook.net> Hi Chris, thanks for your reply. Chris Rebert a ?crit : > Quoting http://docs.python.org/library/subprocess.html , emphasis mine: > """ > On Unix, with shell=True: [...] If args is a sequence, ***the first > item*** specifies the command string, and any additional items will be > treated as additional arguments ***to the shell itself***. > """ Yes, I read that, that's why I'd like to avoid shell=True, but if I do shall=False subprocess.Popen is no longer able to catch the standard inputs & outputs of pg_dump (but it does on other commands that has a prompt, e.g. 'passwd') That's the problem :-/ Regards, Camille. -- The Good, the Bad and the Ugly under Creative Commons! https://yooook.net/r/lp1 From hidura at gmail.com Sun Nov 14 14:34:40 2010 From: hidura at gmail.com (Hidura) Date: Sun, 14 Nov 2010 15:34:40 -0400 Subject: Objects versus dictionaries In-Reply-To: References: Message-ID: Use *kargs to pass all the informatio that you need if u want in the future extended this will be usefull 2010/11/14, Micah Carrick : > I'm writing a little API that other people will use. There are up to 3 > "objects" that get passed around. One of them has some validation methods, > the other two simply store data and probably won't have any validation or > other methods. I only made them objects so that they are syntactically (is > that a word?) similar the other object rather than using dictionaries. I > figure it also better allows for changes in the future. > > Any thoughts on the pros/cons of using my own objects over a dictionary > objects? > > # this is what I have now... > stuff = Stuff(foo="foo", bar="bar") > if stuff.is_valid(): > cust = Customer(name="John", email="foo at bar.com") > order = Order(order_id=1234, amount=12.99) > SomeObject.some_method(stuff, cust, order) > > # this would also work... > stuff = Stuff(foo="foo", bar="bar") > if stuff.is_valid(): > cust = { 'name': "John", 'email': "foo at bar.com" } > order = { 'order_id': 1234, 'amount': 12.99 } > SomeObject.some_method(stuff, cust, order) > > -- > Micah Carrick > -- Enviado desde mi dispositivo m?vil Diego I. Hidalgo D. From python at mrabarnett.plus.com Sun Nov 14 14:38:59 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 14 Nov 2010 19:38:59 +0000 Subject: [Beginner question] Raster to ASCII In-Reply-To: References: Message-ID: <4CE03AD3.9040506@mrabarnett.plus.com> On 14/11/2010 19:07, Becky Kern wrote: > Hi users, > I'm using Python 2.5 (in concert with ArcGIS 9.3) to convert a raster to > an ASCII file. I used the code (listed below) several weeks ago to > successfully do the conversion, but when I tried to replicate it a few > days ago, I got an error message. > import arcgisscripting > gp = arcgisscripting.create(9.3) > InRaster = "C:/data/raster1" > OutAsciiFile = "C:/data/raster2ascii.asc" > gp.RasterToASCII_conversion(InRaster, OutAsciiFile) > The error message: > arcgisscripting.ExecuteError: Failed to execute. Parameters are not > valid. raster1 does not exist. > My file path has not changed so I don't understand why Python can no > longer recognize my raster file. Any ideas? > Just to make sure, does os.path.isfile(InRaster) return True? From python.list at tim.thechases.com Sun Nov 14 14:45:20 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 14 Nov 2010 13:45:20 -0600 Subject: [Beginner question] Raster to ASCII In-Reply-To: References: Message-ID: <4CE03C50.2000900@tim.thechases.com> On 11/14/2010 01:07 PM, Becky Kern wrote: > import arcgisscripting > gp = arcgisscripting.create(9.3) > InRaster = "C:/data/raster1" > OutAsciiFile = "C:/data/raster2ascii.asc" > gp.RasterToASCII_conversion(InRaster, OutAsciiFile) > > The error message: > > arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid. > raster1 does not exist. While I can't speak specifically to arcgisscripting, having no experience with it, the error _sounds_ like the InRaster file isn't found. It's the only reference to "raster1" in your code and the error points directly at "raster1". My suspicion is that you're missing an extension...something like InRaster = "C:/data/raster1.rst" with whatever the corresponding extension is. Alternatively, it's pointing at directory named "raster1" instead of a file. -tkc From usernet at ilthio.net Sun Nov 14 14:47:55 2010 From: usernet at ilthio.net (Tim Harig) Date: Sun, 14 Nov 2010 19:47:55 +0000 (UTC) Subject: subprocess pipe References: Message-ID: On 2010-11-14, Camille Harang wrote: > # pg_dump prompts for password so I inject it in stdin. > pgsql.stdin.write('MY_PASSWORD' + '\n') For security reasons, some programs use direct access to the TTY system for password entry rather then reading from stdin. Most of these programs provide another access mechanism that can be used for authentication (ie public keys or storing the password in a permission restricted configuration file. From usernet at ilthio.net Sun Nov 14 14:51:40 2010 From: usernet at ilthio.net (Tim Harig) Date: Sun, 14 Nov 2010 19:51:40 +0000 (UTC) Subject: subprocess pipe References: Message-ID: On 2010-11-14, Tim Harig wrote: > On 2010-11-14, Camille Harang wrote: >> # pg_dump prompts for password so I inject it in stdin. >> pgsql.stdin.write('MY_PASSWORD' + '\n') > > For security reasons, some programs use direct access to the TTY system > for password entry rather then reading from stdin. Most of these programs > provide another access mechanism that can be used for authentication > (ie public keys or storing the password in a permission restricted > configuration file.[) for scripts. .pgpass ? From roy at panix.com Sun Nov 14 15:14:00 2010 From: roy at panix.com (Roy Smith) Date: Sun, 14 Nov 2010 15:14:00 -0500 Subject: raise Exception or raise Exception() References: <1b51a22c-a9ec-4d58-8dc5-ddb62628fc0f@w21g2000vby.googlegroups.com> Message-ID: In article , Chris Rebert wrote: > On Sun, Nov 14, 2010 at 8:58 AM, ernest wrote: > > I have seen both forms and I'm not sure if they're > > both correct, or one is right and the other wrong. > > They're both acceptable (although obviously you should always raise a > more specific error than Exception). > `raise SomeException` is in fact equivalent to `raise SomeException()`. I've always found this rather disconcerting and unpythonic. Sure, it saves a couple of keystrokes here and there, but it also adds confusion such as Ernest's. It reminds me of Perl's letting you omit the parentheses on function calls. From mammique at garbure.org Sun Nov 14 15:16:22 2010 From: mammique at garbure.org (Camille Harang) Date: Sun, 14 Nov 2010 21:16:22 +0100 Subject: subprocess pipe In-Reply-To: References: Message-ID: <4CE04396.1010108@garbure.org> Tim Harig a ?crit : > On 2010-11-14, Camille Harang wrote: >> # pg_dump prompts for password so I inject it in stdin. >> pgsql.stdin.write('MY_PASSWORD' + '\n') > > For security reasons, some programs use direct access to the TTY system > for password entry rather then reading from stdin. Most of these programs > provide another access mechanism that can be used for authentication > (ie public keys or storing the password in a permission restricted > configuration file. Ha, indeed, I suspected that pg_dump didn't behave normally, security matters might be an explanation, I'll dig in that way, thanks a lot. Regards, Camille. From mammique at garbure.org Sun Nov 14 15:16:37 2010 From: mammique at garbure.org (Camille Harang) Date: Sun, 14 Nov 2010 21:16:37 +0100 Subject: subprocess pipe In-Reply-To: References: Message-ID: <4CE043A5.4070405@garbure.org> Tim Harig a ?crit : > On 2010-11-14, Camille Harang wrote: >> # pg_dump prompts for password so I inject it in stdin. >> pgsql.stdin.write('MY_PASSWORD' + '\n') > > For security reasons, some programs use direct access to the TTY system > for password entry rather then reading from stdin. Most of these programs > provide another access mechanism that can be used for authentication > (ie public keys or storing the password in a permission restricted > configuration file. Ha, indeed, I suspected that pg_dump didn't behave normally, security matters might be an explanation, I'll dig in that way, thanks a lot. Regards, Camille. From mammique at garbure.org Sun Nov 14 15:16:37 2010 From: mammique at garbure.org (Camille Harang) Date: Sun, 14 Nov 2010 21:16:37 +0100 Subject: subprocess pipe In-Reply-To: References: Message-ID: <4CE043A5.4070405@garbure.org> Tim Harig a ?crit : > On 2010-11-14, Camille Harang wrote: >> # pg_dump prompts for password so I inject it in stdin. >> pgsql.stdin.write('MY_PASSWORD' + '\n') > > For security reasons, some programs use direct access to the TTY system > for password entry rather then reading from stdin. Most of these programs > provide another access mechanism that can be used for authentication > (ie public keys or storing the password in a permission restricted > configuration file. Ha, indeed, I suspected that pg_dump didn't behave normally, security matters might be an explanation, I'll dig in that way, thanks a lot. Regards, Camille. From steve at holdenweb.com Sun Nov 14 15:23:03 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 14 Nov 2010 12:23:03 -0800 Subject: strange behavor.... In-Reply-To: References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> <87tyjlhu1l.fsf.mdw@metalzone.distorted.org.uk> <4cdf1206$0$29990$c3e8da3$5496439d@news.astraweb.com> <877hggiz17.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On 11/14/2010 8:29 AM, Emile van Sebille wrote: [...] > We all know that _everything_ is a disguised method call and we call the > disguised method call that resembles a statement where the LHS is > separated from the RHS by a single equals sign assignment. I think your elided attempt to reconcile the opposing viewpoints on this thread is creditworthy. We should not allow our wish to resolve conflicting viewpoints blind us to reality, however. What method of a does the statement a = something call? I ask in genuine ignorance, and in the knowledge that you may indeed be able to point me to such a method. I would prefer to think of a = something and lst[i] = something as in some sense different, because I see names as referencing locations in a namespace. Perhaps you can help to unify my perceptions. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From rschroev_nospam_ml at fastmail.fm Sun Nov 14 15:44:45 2010 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Sun, 14 Nov 2010 21:44:45 +0100 Subject: strange behavor.... In-Reply-To: References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> <87tyjlhu1l.fsf.mdw@metalzone.distorted.org.uk> <4cdf1206$0$29990$c3e8da3$5496439d@news.astraweb.com> <877hggiz17.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <1TXDo.79784$r35.72278@newsfe14.ams2> Op 2010-11-14 21:23, Steve Holden schreef: > What method of a does the statement > > a = something > > call? I ask in genuine ignorance, and in the knowledge that you may > indeed be able to point me to such a method. It wouldn't call a method of a. I'm not an expert in these matters, but I would think it would call a method in a's namespace. For example, if 'a' lives in module 'foo', I would think that a = something # from within module foo and foo.a = something # outside of module foo are equivalent. But chances are my conceptions are wrong. -- The saddest aspect of life right now is that science gathers knowledge faster than society gathers wisdom. -- Isaac Asimov Roel Schroeven From calderone.jeanpaul at gmail.com Sun Nov 14 16:04:17 2010 From: calderone.jeanpaul at gmail.com (Jean-Paul Calderone) Date: Sun, 14 Nov 2010 13:04:17 -0800 (PST) Subject: Getting references to objects without incrementing reference counters References: <8c98a453-3303-4509-be39-1a26084f573a@o11g2000prf.googlegroups.com> Message-ID: <8063c457-98bf-4add-a1c7-38b01848cbe3@w21g2000vby.googlegroups.com> On Nov 14, 11:08?am, Artur Siekielski wrote: > Hi. > I'm using CPython 2.7 and Linux. In order to make parallel > computations on a large list of objects I want to use multiple > processes (by using multiprocessing module). In the first step I fill > the list with objects and then I fork() my worker processes that do > the job. > > This should work optimally in the aspect of memory usage because Linux > implements copy-on-write in forked processes. So I should have only > one physical list of objects (the worker processes don't change the > objects on the list). The problem is that after a short time children > processes are using more and more memory (they don't create new > objects - they only read objects from the list and write computation > result to the database). > > After investigation I concluded the source of this must be > incrementing of a reference counter when getting an object from the > list. It changes only one int but OS must copy the whole memory page > to the child process. I reimplemented the function for getting the > element (from the file listobject.c) but omitting the PY_INCREF call > and it solved my problems with increasing memory. > > The questions is: are there any better ways to have a real read-only > list (in terms of memory representation of objects)? My solution is of > course not safe. I thought about weakrefs but it seems they cannot be > used here because getting a real reference from a weakref increases a > reference counter. Maybe another option would be to store reference > counters not in objects, but in a separate array to minimize number of > memory pages they occupy... It might be interesting to try with Jython or PyPy. Neither of these Python runtimes uses reference counting at all. Jean-Paul From emile at fenx.com Sun Nov 14 16:18:53 2010 From: emile at fenx.com (Emile van Sebille) Date: Sun, 14 Nov 2010 13:18:53 -0800 Subject: strange behavor.... In-Reply-To: References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> <87tyjlhu1l.fsf.mdw@metalzone.distorted.org.uk> <4cdf1206$0$29990$c3e8da3$5496439d@news.astraweb.com> <877hggiz17.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On 11/14/2010 12:23 PM Steve Holden said... > On 11/14/2010 8:29 AM, Emile van Sebille wrote: > [...] >> We all know that _everything_ is a disguised method call and we call the >> disguised method call that resembles a statement where the LHS is >> separated from the RHS by a single equals sign assignment. > > I think your elided attempt to reconcile the opposing viewpoints on this > thread is creditworthy. We should not allow our wish to resolve > conflicting viewpoints blind us to reality, however. What method of a > does the statement > > a = something Contrivance, but all the same: >>> class Test: ... def __del__(self): ... global a ... a = 10 ... >>> a = Test() >>> ... here's your a = something, which also lends credence to Mark's argument that you can't easily tell... >>> a = 9 >>> >>> print a 10 >>> I'd also suggest that long before magic methods like __radd__ and such were added, that the expectation that everything _could_ be a magic method was there, and that those methods of next best benefit were added as time and interest permitted. That _all_ those possible methods are not yet implemented I leave to the developers. :) I was mainly trying to point out that until a common vernacular is accepted by those engaging in a discussion misconceptions are inevitable, and that learning how those terms are applied within a context is necessary for advancement. A numpy matrix is not Neo's Matrix and arguing that it should be or that python's use is "wrong" doesn't really get anyone anywhere. Emile From steve at REMOVE-THIS-cybersource.com.au Sun Nov 14 17:00:28 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 14 Nov 2010 22:00:28 GMT Subject: strange behavor.... References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> <87tyjlhu1l.fsf.mdw@metalzone.distorted.org.uk> <4cdf1206$0$29990$c3e8da3$5496439d@news.astraweb.com> <877hggiz17.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <4ce05bfc$0$29990$c3e8da3$5496439d@news.astraweb.com> On Sun, 14 Nov 2010 12:23:03 -0800, Steve Holden wrote: > What method of a does the statement > > a = something > > call? I ask in genuine ignorance, and in the knowledge that you may > indeed be able to point me to such a method. I know the question wasn't directed at me, but here's my 2 cents worth: It doesn't; Mark has correctly identified that difference between what he calls "simple assignment" (and the rest of us call "name binding"), and "complex assignment" (assignment to something other than a name). This is a design choice of Python -- objects don't know what names (if any) they are bound to, so Python doesn't call a method on the object "something". Nor does it call an method on the object currently bound to the name "a" but about to be unbound -- what would be the point? And of course, the name "a" might not yet be bound to anything, in which case there is nothing on the left hand side to call. On the other hand, in the global scope, "a = something" *may* call globals().__setitem__('a', 'something'), although it's quite possible that Python may optimize that in some fashion and avoid the method call. But even if it did call the method, unless you can replace globals() with a custom dict that did something "interesting" on assignment, that's merely an implementation detail. And CPython, if not other implementations, don't call anything analogous inside functions: locals() is not a real dictionary and no method is called. We (well, I *wink*) agree with Mark that name binding is different; we only disagree whether that difference is *conceptually* important enough to change 15 or 20 years of Python terminology to suit his Lisp sensibilities. > I would prefer to think of > > a = something > > and > > lst[i] = something > > as in some sense different, because I see names as referencing locations > in a namespace. Perhaps you can help to unify my perceptions. Names in namespaces reference *objects* -- that the objects happen to have fixed locations in the heap (their memory location) is an implementation detail. You know, some day in my Copious Spare Time, I'm going to write my own Python implementation using handles to objects instead of pointers, just so I can point to an implementation where objects are free to move in memory and don't have a fixed location :) -- Steven From arnodel at gmail.com Sun Nov 14 17:25:48 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Sun, 14 Nov 2010 22:25:48 +0000 Subject: strange behavor.... References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> <87tyjlhu1l.fsf.mdw@metalzone.distorted.org.uk> <4cdf1206$0$29990$c3e8da3$5496439d@news.astraweb.com> <877hggiz17.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <874obj1r0z.fsf@gmail.com> Steve Holden writes: > On 11/14/2010 8:29 AM, Emile van Sebille wrote: > [...] >> We all know that _everything_ is a disguised method call and we call the >> disguised method call that resembles a statement where the LHS is >> separated from the RHS by a single equals sign assignment. > > I think your elided attempt to reconcile the opposing viewpoints on this > thread is creditworthy. We should not allow our wish to resolve > conflicting viewpoints blind us to reality, however. What method of a > does the statement > > a = something > > call? I ask in genuine ignorance, and in the knowledge that you may > indeed be able to point me to such a method. If "a = something" is compiled to "STORE_NAME" and the statement is executed in a context where locals() is a custom dictionary then it is possible that the statement will call the custom __setitem__ method of the locals: >>> class mydict(dict): ... def __setitem__(self, key, val): ... print "assigning %r to %r" % (val, key) ... super(mydict, self).__setitem__(key, val) ... >>> d = mydict() >>> exec "a=2" in d assigning 2 to 'a' >>> d['a'] 2 But note that: >>> exec "global a; a = 3" in d >>> d['a'] 3 So even if the globals() dictionary is custom, its __setitem__ method is *not* called. Below is a summary of what methods are called depending on the opcode executed: OPCODE Assignment type Method call =============== =============== =============================================== STORE_SLICE a[?:?] = b calls a.__setslice__(...) or a.__setitem__(...) STORE_SUBSCR a[x] = b calls a.__setitem__(x, b) STORE_ATTR a.x = b calls a.__setattr__("x", b) STORE_NAME a = b calls locals().__setitem__("a", b) STORE_GLOBAL a = b calls dict.__setitem__(globals(), "a", b) STORE_FAST a = b doesn't call any method STORE_DEREF a = b doesn't call any method So you can see that a[...] = b and a.x = b *always* call a method that can be overriden, whereas a = b *almost* never does. The only exception is when the opcode "STORE_NAME" is executed. I'm not sure when something gets compiled to "STORE_NAME", but I can't think of many examples apart from when one uses the "exec" statement. Perhaps someone can enlighten me here. > > I would prefer to think of > > a = something > > and > > lst[i] = something > > as in some sense different, because I see names as referencing locations > in a namespace. Perhaps you can help to unify my perceptions. I think that you are correct, with the "STORE_NAME" caveat. -- Arnaud From drsalists at gmail.com Sun Nov 14 17:31:48 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Sun, 14 Nov 2010 14:31:48 -0800 Subject: Looking For Tutorial Comparison Of sh - perl - python In-Reply-To: References: <3q34r7-m9s2.ln1@ozzie.tundraware.com> Message-ID: On Sun, Nov 14, 2010 at 5:00 AM, Martin Gregorie wrote: > On Sat, 13 Nov 2010 22:05:57 -0600, Tim Daneliuk wrote: > > > I am putting together a comparison & intro to each of sh, perl, python > > with a view towards addressing: > > > Add awk / gawk to that list. IME its often the easiest and most concise > way to process a text file, e.g. a log file, while applying different > processing rules depending on line content and/or generating summaries. > > > Before I attack this myself, has anyone done > > something along these lines I could piggyback upon? > > > I haven't seen such a comparison, but that doesn't meant that they don't > exist. > The perl people might not agree (they seem to frown on the idea of exec'ing anything external, at least when you do it from shell), but I see sh/ksh/bash programming as Including awk, sed, tr and grep, among other tools - and I see that as a Good Thing (tm). As I see it, this keeps POSIX shell proper quite a bit leaner, and very interestingly, makes it very naturally parallelisable. Another cool thing about POSIX shell programming, is that with shell functions, you can have internal extensions (shell functions) and external extensions (shell scripts), with exactly the same syntax in the way they are called, and almost exactly the same syntax in the way they are defined; it almost doesn't matter in which way something was implemented (until you involve subshells). POSIX shell does have its issues though - mostly the proliferation of #!$% noise in the builtins. I hope you'll include something about the fact that POSIX shell is white space sensitive - albeit in a different way from Python. Oh, also, the perl people tend to want to slam POSIX shell for not being portable; I think it is, really, you just need a small amount of information about how to do it. The usual example that gets trotted out is that to suppress a newline you have to say "echo -n fred" in BSD-ish shells, and "echo 'fred\c'" in SysV-ish shells - but: 1) Almost all sh/ksh/bash implementations do -n now. 2) Even if that weren't the case, you could always portably say "echo fred | tr -d '\012'". HTH -------------- next part -------------- An HTML attachment was scrubbed... URL: From jbiquez at icsmx.com Sun Nov 14 17:32:24 2010 From: jbiquez at icsmx.com (Jorge Biquez) Date: Sun, 14 Nov 2010 16:32:24 -0600 Subject: What was your strategy? Message-ID: <201011142240.oAEMecu2054270@krusty.intranet.com.mx> Hello all. Quick question. I know some of you are with Python since started, some other maybe later. I was wondering if you can share what was the strategy you followed to master Python (Yes I know I have to work hard study and practice a lot). I mean did you use special books, special sites, a plan to learn each subject in a special way. I would like to know, if possible, comments specially from some of you who in the past had other languages, frameworks and platforms and left (almost) all of them and stayed with Python. Thanks in advance Jorge Biquez From news1234 at free.fr Sun Nov 14 17:50:08 2010 From: news1234 at free.fr (News123) Date: Sun, 14 Nov 2010 23:50:08 +0100 Subject: how to identify currently running threads QTHreads In-Reply-To: References: <4cdfe050$0$10182$426a34cc@news.free.fr> Message-ID: <4ce067a0$0$3692$426a74cc@news.free.fr> On 11/14/2010 05:32 PM, Aahz wrote: > In article <4cdfe050$0$10182$426a34cc at news.free.fr>, > News123 wrote: >> > >> >Is there a simple way in Python to identify all active Threads / >> >QThreads when trying, such that I can locate the thread, itls related >> >python code and fix it? > threading.enumerate() or sys._current_frames() Thanks a lot From usenet-nospam at seebs.net Sun Nov 14 17:59:23 2010 From: usenet-nospam at seebs.net (Seebs) Date: 14 Nov 2010 22:59:23 GMT Subject: What was your strategy? References: Message-ID: On 2010-11-14, Jorge Biquez wrote: > I was wondering if you can share what was the strategy you followed > to master Python (Yes I know I have to work hard study and practice a > lot). I mean did you use special books, special sites, a plan to > learn each subject in a special way. I would like to know, if > possible, comments specially from some of you who in the past had > other languages, frameworks and platforms and left (almost) all of > them and stayed with Python. I've been learning Python the same way I learn any language; get a book, read it over lunch for a few days, start typing, ask people how to improve my code once I have some. This information is almost certainly useless to you, though, unless you've already learned at least six or seven programming languages. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From drsalists at gmail.com Sun Nov 14 18:08:18 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Sun, 14 Nov 2010 15:08:18 -0800 Subject: Objects versus dictionaries In-Reply-To: References: Message-ID: On Sun, Nov 14, 2010 at 11:20 AM, Chris Rebert wrote: > On Sun, Nov 14, 2010 at 11:00 AM, Micah Carrick > wrote: > > I'm writing a little API that other people will use. There are up to 3 > > "objects" that get passed around. One of them has some validation > methods, > > the other two simply store data and probably won't have any validation or > > other methods. I only made them objects so that they are syntactically > (is > > that a word?) similar the other object rather than using dictionaries. I > > figure it also better allows for changes in the future. > > > > Any thoughts on the pros/cons of using my own objects over a dictionary > > objects? > > Objects are definitely nicer to work with syntactically, and they help > make your program's types more explicit. > Rather than coding the "data holder" classes manually, consider using > namedtuples instead: > http://docs.python.org/library/collections.html#collections.namedtuple > namedtuples are nice, but I don't think pylint understands how to look inside them as well as it understands how to look inside class instances. pylint isn't for everyone, but I find it very useful in producing sturdy python code with few surprises at runtime. -------------- next part -------------- An HTML attachment was scrubbed... URL: From james.harris.1 at googlemail.com Sun Nov 14 18:21:02 2010 From: james.harris.1 at googlemail.com (James Harris) Date: Sun, 14 Nov 2010 15:21:02 -0800 (PST) Subject: What was your strategy? References: Message-ID: <0e852728-1c38-40e3-a7b6-356254e4f038@a9g2000pro.googlegroups.com> On Nov 14, 10:32?pm, Jorge Biquez wrote: > Hello all. > Quick question. I know some of you are with Python since started, > some other maybe later. > > I was wondering if you can share what was the strategy you followed > to master Python (Yes I know I have to work hard study and practice a > lot). I mean did you use special books, special sites, a plan to > learn each subject in a special way. I would like to know, if > possible, comments specially from some of you who in the past had > other languages, frameworks and platforms and left (almost) all of > them and stayed with Python. IMHO there's no one solution. What works for a person depends on how that person learns. Options: books, online free course lecture videos, class instruction, preexisting code, supplied documentation, online tutorials etc. I find it useful to have at least two sources, e.g. two books, as each author brings a slightly different approach and often make different assumptions (and make different mistakes). Comparing two or more makes it easier to see through the differences. But make sure each is reputable in its own right. For example, I used: Learning Python, and Python in a Nutshell (and WxPython in action for the GUI stuff). I'd recommend at least the Nutshell book as a reference. If books work for you check Amazon or similar for feedback of others. James From bnbowman at gmail.com Sun Nov 14 18:30:38 2010 From: bnbowman at gmail.com (Brett Bowman) Date: Sun, 14 Nov 2010 15:30:38 -0800 Subject: Fixing PDF EOF Errors with PyPDF Message-ID: Hey all, I'm trying to read a library of my company's PDFs, but about a third of them can't be opened. PyPDF (v1.12) spits out this error: pyPdf.utils.PdfReadError: EOF marker not found I searched for the answer via google, but all I found was this link: http://lindaocta.com/?tag=pypdf. She suggests fixing the problem by appending an EOF marker like so: def fixPdf(pdfFile): try: fileOpen = file(pdfFile, "a") fileOpen.write("%%EOF") fileOpen.close() return "Fixed" except Exception, e: return "Unable to open file: %s with error: %s" % (pdfFile, str(e)) Which appears to successfully append all of the files, as the exception is never triggered and "Fixed" always returned, but subsequent attempts to open the files all failed. Yet all of those files can be open successfully with Adobe Acrobat Reader. Is this code inorrect or is there some other way to correct this error? Or does the code depend on the system? (I'm using Windows XP, but I believe the author was using a *nix) Sincerely, Brett Bowman -------------- next part -------------- An HTML attachment was scrubbed... URL: From greg.ewing at canterbury.ac.nz Sun Nov 14 18:37:09 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 15 Nov 2010 12:37:09 +1300 Subject: namespace issue, Python vs numpy min/max problem In-Reply-To: <4cdf1376$0$29990$c3e8da3$5496439d@news.astraweb.com> References: <66c318f3-a659-40ec-ad17-74133639d573@h21g2000vbh.googlegroups.com> <4cdf1376$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8kba57Flm7U1@mid.individual.net> Steven D'Aprano wrote: > It > only becomes your problem if you have advised people that the right way > to use your module is with import *. And if you're advising people to do that, it would be an extremely good idea to give your functions different names so that they don't conflict with the builtin min and max. -- Greg From drsalists at gmail.com Sun Nov 14 18:41:07 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Sun, 14 Nov 2010 15:41:07 -0800 Subject: Getting references to objects without incrementing reference counters In-Reply-To: <8c98a453-3303-4509-be39-1a26084f573a@o11g2000prf.googlegroups.com> References: <8c98a453-3303-4509-be39-1a26084f573a@o11g2000prf.googlegroups.com> Message-ID: On Sun, Nov 14, 2010 at 11:08 AM, Artur Siekielski < artur.siekielski at gmail.com> wrote: > Hi. > I'm using CPython 2.7 and Linux. In order to make parallel > computations on a large list of objects I want to use multiple > processes (by using multiprocessing module). In the first step I fill > the list with objects and then I fork() my worker processes that do > the job. > You could try http://docs.python.org/library/multiprocessing.html#multiprocessing.Array to put the data in shared memory. Copy on write is great, but not a panacea, and not optimal in any sense of the word I'm accustomed to. Like you said it depends on page boundaries, and also it can kind of fall apart if a shared library wasn't built as position independent code due to all the address fixups. And it's mostly code that gets shared - data tends to diverge. Supposedly at one time Sun was able to drastically reduce the memory requirements of Solaris by grouping related variables (things that were likely to be needed at the same time) into the same pages of memory. Is it possible you're just seeing a heap grow that isn't getting garbage collected as often as you expect? Normal computation in Python creates objects without free'ing them all that often. HTH -------------- next part -------------- An HTML attachment was scrubbed... URL: From stef.mientki at gmail.com Sun Nov 14 18:49:02 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Mon, 15 Nov 2010 00:49:02 +0100 Subject: What was your strategy? In-Reply-To: <201011142240.oAEMecu2054270@krusty.intranet.com.mx> References: <201011142240.oAEMecu2054270@krusty.intranet.com.mx> Message-ID: <4CE0756E.5090502@gmail.com> On 14-11-2010 23:32, Jorge Biquez wrote: > Hello all. > Quick question. I know some of you are with Python since started, some other maybe later. > > I was wondering if you can share what was the strategy you followed to master Python (Yes I know I > have to work hard study and practice a lot). I mean did you use special books, special sites, a > plan to learn each subject in a special way. I would like to know, if possible, comments specially > from some of you who in the past had other languages, frameworks and platforms and left (almost) > all of them and stayed with Python. > > Thanks in advance > > Jorge Biquez > I think you have to start with determining a goal, some kind of application you want or like to create. Learning to program without a goal (which good well be school assignments) is in my opinion fruitless. Secondly you've to decide if the application will be an old fashion desktop application or a modern web application, or maybe even, it should start as a desktop application and should be easily be converted to a webappplication in the future. (btw I mainly write desktop applications ;-) When you've a goal and a global scope, you can find the right tools: language (Python of course), IDE, framework, etc. cheers, Stef Mientki From ben+python at benfinney.id.au Sun Nov 14 18:53:24 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 15 Nov 2010 10:53:24 +1100 Subject: What was your strategy? References: Message-ID: <877hgfbgy3.fsf@benfinney.id.au> Jorge Biquez writes: > I was wondering if you can share what was the strategy you followed to > master Python (Yes I know I have to work hard study and practice a > lot). I mean did you use special books, special sites, a plan to learn > each subject in a special way. I find that my strategy with learning Python was similar to strategies for learning a natural language: * Use it, as often as feasible. Keep practicing. * Use it, as often as feasible, for real problems. The kind of problems that I actually need a solution to will motivate me to learn when a contrived exercise would not. * Additionally, seek out areas of the language I'm not actively using and learn them too. This pretty much means I'll need contrived exercises, but it guards against staying in a rut of the familiar. * Use it, as much as feasible, in public. Put my inevitable errors on display where they can be discovered and suggestions can be made for improvement. This has the not inconsiderable benefit of encouraging humility also. Those all worked well when I learn a natural language, and they work well for learning a programming language. After all, a programming language is a constructed language for human-to-human communication. It happens to have the additional constraint of communicating with computers as a side goal :-) -- \ ?Spam will be a thing of the past in two years' time.? ?Bill | `\ Gates, 2004-01-24 | _o__) | Ben Finney From jdoe at usenetlove.invalid Sun Nov 14 19:00:57 2010 From: jdoe at usenetlove.invalid (John Doe) Date: 15 Nov 2010 00:00:57 GMT Subject: Komodo 6, why "Workspace Restore" after every restart? Message-ID: <4ce07839$0$17214$c3e8da3$eb767761@news.astraweb.com> Does Komodo have to be shut down individually every time I want to restart Windows XP? Is there some way to eliminate the persistent Workspace Restore error after every restart? I have tried setting it to restore files without asking, but that does not seem to work. Thanks. From deets at web.de Sun Nov 14 19:03:02 2010 From: deets at web.de (Diez B. Roggisch) Date: Mon, 15 Nov 2010 01:03:02 +0100 Subject: Getting references to objects without incrementing reference counters References: <8c98a453-3303-4509-be39-1a26084f573a@o11g2000prf.googlegroups.com> Message-ID: Artur Siekielski writes: > Hi. > I'm using CPython 2.7 and Linux. In order to make parallel > computations on a large list of objects I want to use multiple > processes (by using multiprocessing module). In the first step I fill > the list with objects and then I fork() my worker processes that do > the job. > > This should work optimally in the aspect of memory usage because Linux > implements copy-on-write in forked processes. So I should have only > one physical list of objects (the worker processes don't change the > objects on the list). The problem is that after a short time children > processes are using more and more memory (they don't create new > objects - they only read objects from the list and write computation > result to the database). > > After investigation I concluded the source of this must be > incrementing of a reference counter when getting an object from the > list. It changes only one int but OS must copy the whole memory page > to the child process. I reimplemented the function for getting the > element (from the file listobject.c) but omitting the PY_INCREF call > and it solved my problems with increasing memory. > > The questions is: are there any better ways to have a real read-only > list (in terms of memory representation of objects)? My solution is of > course not safe. I thought about weakrefs but it seems they cannot be > used here because getting a real reference from a weakref increases a > reference counter. Maybe another option would be to store reference > counters not in objects, but in a separate array to minimize number of > memory pages they occupy... You don't say what data you share, and if all of it is needed for each child. So it's hard to suggest optimizations. And AFAIK there is no built-in way of doing what you want. It's complex and error-prone. Maybe mmap + (struct|pickle) help, if what you need can be formulated in a way that traversing the whole data piecewise by explicitly marshaling-demarshaling data? Diez From python at mrabarnett.plus.com Sun Nov 14 19:16:36 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 15 Nov 2010 00:16:36 +0000 Subject: What was your strategy? In-Reply-To: <877hgfbgy3.fsf@benfinney.id.au> References: <877hgfbgy3.fsf@benfinney.id.au> Message-ID: <4CE07BE4.7010707@mrabarnett.plus.com> On 14/11/2010 23:53, Ben Finney wrote: > Jorge Biquez writes: > >> I was wondering if you can share what was the strategy you followed to >> master Python (Yes I know I have to work hard study and practice a >> lot). I mean did you use special books, special sites, a plan to learn >> each subject in a special way. > > I find that my strategy with learning Python was similar to strategies > for learning a natural language: > > * Use it, as often as feasible. Keep practicing. > > * Use it, as often as feasible, for real problems. The kind of problems > that I actually need a solution to will motivate me to learn when a > contrived exercise would not. > > * Additionally, seek out areas of the language I'm not actively using > and learn them too. This pretty much means I'll need contrived > exercises, but it guards against staying in a rut of the familiar. > > * Use it, as much as feasible, in public. Put my inevitable errors on > display where they can be discovered and suggestions can be made for > improvement. This has the not inconsiderable benefit of encouraging > humility also. > I'd also say: don't fight the language, but follow its idioms, and listen to advice from those who know it better, because there's usually a good reason why something is done this way and not that way. It will all make sense in the end. :-) > Those all worked well when I learn a natural language, and they work > well for learning a programming language. > > After all, a programming language is a constructed language for > human-to-human communication. It happens to have the additional > constraint of communicating with computers as a side goal :-) > From data.2 at rediff.com Sun Nov 14 19:26:21 2010 From: data.2 at rediff.com (gaurav) Date: Sun, 14 Nov 2010 16:26:21 -0800 (PST) Subject: Cash your skill in Management careers. Message-ID: <326e2393-25eb-42f4-8845-76bb83bd4089@v28g2000prn.googlegroups.com> Careers in Management work. Careers for your future. http://managementjobs.webs.com/hrm.htm http://topcareer.webs.com/businessmanagement.htm Fresh coming up complete government career, computer jobs. http://rojgars1.webs.com/gov.htm http://printmediajobs.webs.com/fl.htm From herrxandor at gmail.com Sun Nov 14 20:04:38 2010 From: herrxandor at gmail.com (Martin Caum) Date: Sun, 14 Nov 2010 17:04:38 -0800 (PST) Subject: QT window closes immediately Message-ID: <141ef269-de70-4ce1-b4ff-bfb0f58ee9d2@k14g2000pre.googlegroups.com> I am attempting to open a window on mouse activity which works, but the window fails to stay open. I set it to terminate when the escape key is pressed even when the program is not currently selected. This works fine. Originally I had it create the window only with a right click, but when I noticed the window closed immediately I set it to any mouse activity for easier debugging. My script is as follows: [code] import pythoncom, pyHook import sys import win32api from PyQt4 import QtGui, QtCore class WindowObject(QtGui.QWidget): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.setWindowTitle('Window') self.resize(50, 250) def OnKeyboardEvent(event): if event.KeyID == 27: win32api.PostQuitMessage() return 1 def OnMouseEvent(event): x = event.Position[0] y = event.Position[1] createWindow(x, y) return 1 def createWindow(x, y): menu = WindowObject() menu.move(x, y) menu.show() hm = pyHook.HookManager() hm.MouseAll = OnMouseEvent hm.KeyDown = OnKeyboardEvent hm.HookMouse() hm.HookKeyboard() app = QtGui.QApplication(sys.argv) pythoncom.PumpMessages()[/code] I'm fairly certain that this is due to my lack of understanding in the PumpMessages command and the HookManager. Any advice? From no.email at nospam.invalid Sun Nov 14 20:37:34 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 14 Nov 2010 17:37:34 -0800 Subject: What was your strategy? References: Message-ID: <7xzktbcqox.fsf@ruckus.brouhaha.com> Jorge Biquez writes: > I was wondering if you can share what was the strategy you followed to > master Python (Yes I know I have to work hard study and practice a lot). 1. Read the tutorial http://docs.python.org/tutorial/ 2. Start writing code, and encounter various issues as usually happens. 3. Refer to the other reference manuals, web search, and ask questions in the newsgroup as you run into issues. 4. After a while you'll have hit most of the usual issues and learned how to deal with them, and how to find resolution for new issues that might come up. That's about as close to mastery as one normally reaches in this world. Python is a pretty easy language if you have a reasonable programming background when you first start with it. I think the way it's currently organized, it may not be so great for self-study if you're not already a programmer. > I mean did you use special books, special sites, Nah. From rustompmody at gmail.com Sun Nov 14 21:24:17 2010 From: rustompmody at gmail.com (rustom) Date: Sun, 14 Nov 2010 18:24:17 -0800 (PST) Subject: What was your strategy? References: <7xzktbcqox.fsf@ruckus.brouhaha.com> Message-ID: <3701a7aa-7bae-440e-b663-a39549de6699@x4g2000pre.googlegroups.com> Jorge Biquez writes: > I was wondering if you can share what was the strategy you followed to > master Python (Yes I know I have to work hard study and practice a lot). One of the basic mistakes that folks (kids?) studying a language do is to study *only* the language. I guess the mistake happens more in the Java, VB type languages than in python but the mistake is pervasive nevertheless. (Its particularly dangerous with C++ which you can study without mastering for a lifetime) Python is obviously simpler/cleaner etc but still the mistake persists of studying past the point of diminishing returns. Specifically, an intelligent person who has a background of other languages can get the minimal,basic hang in a a day (not so intelligent and inexperienced may be a week or two). After that you need to study OTHER things. Here is such a list 1. "python" 2. IDE (emacs+python-mode in my case, but whatever you use, learn to use it) - debugger - introspection - ipython looks promising 3. CS - algorithms - data structures - 'theory:' FSM, complexity, computability limits, O notation etc 4. Operating Systems How python fits into the OS you are using 5. Paradigms - scripting - functional - oo 6. 'Advanced' Stuff - TDD - Profiling - C interfacing ... The difficult part is studying this stuff independent of python and then making the bridge. eg. 75% of (typical) data-structure books deal with things like 'linked-lists' -- useless in python-- but the remaining 25% you need. From wuwei23 at gmail.com Sun Nov 14 23:03:36 2010 From: wuwei23 at gmail.com (alex23) Date: Sun, 14 Nov 2010 20:03:36 -0800 (PST) Subject: Komodo 6, why "Workspace Restore" after every restart? References: <4ce07839$0$17214$c3e8da3$eb767761@news.astraweb.com> Message-ID: <428b98ca-72bf-4e3b-ad8a-dafe2fc4d553@v28g2000prn.googlegroups.com> On Nov 15, 10:00?am, John Doe wrote: > Does Komodo have to be shut down individually every time I want to > restart Windows XP? Is there some way to eliminate the persistent > Workspace Restore error after every restart? I have tried setting it > to restore files without asking, but that does not seem to work. You'd be better served asking this on the Komodo forums: http://community.activestate.com/forums/komodo-support From brf256 at gmail.com Sun Nov 14 23:09:46 2010 From: brf256 at gmail.com (brf256 at gmail.com) Date: Mon, 15 Nov 2010 04:09:46 +0000 Subject: What was your strategy? Message-ID: <118175645-1289794186-cardhu_decombobulator_blackberry.rim.net-1855251157-@bda480.bisx.prod.on.blackberry> I used "a non programmers tutorial to python" by Josh coglatti. Its a free wikibook too. Then I carried on to "the guide to python". Hope this helps and good luck! - Braden Faulkner - Braden Faulkner From robert.kern at gmail.com Sun Nov 14 23:46:47 2010 From: robert.kern at gmail.com (Robert Kern) Date: Sun, 14 Nov 2010 22:46:47 -0600 Subject: namespace issue, Python vs numpy min/max problem In-Reply-To: <8kba57Flm7U1@mid.individual.net> References: <66c318f3-a659-40ec-ad17-74133639d573@h21g2000vbh.googlegroups.com> <4cdf1376$0$29990$c3e8da3$5496439d@news.astraweb.com> <8kba57Flm7U1@mid.individual.net> Message-ID: On 2010-11-14 17:37 , Gregory Ewing wrote: > Steven D'Aprano wrote: >> It only becomes your problem if you have advised people that the right way to >> use your module is with import *. > > And if you're advising people to do that, it would be an > extremely good idea to give your functions different names > so that they don't conflict with the builtin min and max. And we (the numpy devs) explicitly advise people *against* that. -- 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 drsalists at gmail.com Sun Nov 14 23:47:48 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Sun, 14 Nov 2010 20:47:48 -0800 Subject: Noob question on 2 vs 3 Python releases In-Reply-To: References: Message-ID: On Sun, Nov 14, 2010 at 1:03 AM, Franck Ditter wrote: > Pardon my noobness (?) but why is there a 2.x and 3.x development > teams working concurrently in Python ? I hardly saw that in other > languages. Which one should I choose to start with, to cope with > the future ? Isn't 3.x supposed to extend 2.y ? > This situation is very strange... > Thanks for your explanations... > > franck > -- > http://mail.python.org/mailman/listinfo/python-list > Actually, has there ever been a language with a substantial userbase that didn't ever have two (or more) versions at the same time? C has, C++ has, FORTRAN has, perl has, java has... I believe user migrations are just kind of part of being a computer language. That's a significant part of why code doesn't maintain itself. -------------- next part -------------- An HTML attachment was scrubbed... URL: From jdoe at usenetlove.invalid Mon Nov 15 00:08:53 2010 From: jdoe at usenetlove.invalid (John Doe) Date: 15 Nov 2010 05:08:53 GMT Subject: Komodo 6, why "Workspace Restore" after every restart? References: <4ce07839$0$17214$c3e8da3$eb767761@news.astraweb.com> <428b98ca-72bf-4e3b-ad8a-dafe2fc4d553@v28g2000prn.googlegroups.com> Message-ID: <4ce0c065$0$23246$c3e8da3$a9097924@news.astraweb.com> alex23 wrote: > John Doe wrote: >> Does Komodo have to be shut down individually every time I want >> to restart Windows XP? Is there some way to eliminate the >> persistent Workspace Restore error after every restart? I have >> tried setting it to restore files without asking, but that does >> not seem to work. > > You'd be better served asking this on the Komodo forums: UseNet would be better off if Google Groups didn't exist, IMO. -- > http://community.activestate.com/forums/komodo-support > > see also googled groups > Path: news.astraweb.com!border5.newsrouter.astraweb.com!news-out.readnews.com!transit3.readnews.com!postnews.google.com!v28g2000prn.googlegroups.com!not-for-mail > From: alex23 > Newsgroups: comp.lang.python > Subject: Re: Komodo 6, why "Workspace Restore" after every restart? > Date: Sun, 14 Nov 2010 20:03:36 -0800 (PST) > Organization: http://groups.google.com > Lines: 8 > Message-ID: <428b98ca-72bf-4e3b-ad8a-dafe2fc4d553 v28g2000prn.googlegroups.com> > References: <4ce07839$0$17214$c3e8da3$eb767761 news.astraweb.com> > NNTP-Posting-Host: 130.102.44.25 > Mime-Version: 1.0 > Content-Type: text/plain; charset=ISO-8859-1 > Content-Transfer-Encoding: quoted-printable > X-Trace: posting.google.com 1289793817 25517 127.0.0.1 (15 Nov 2010 04:03:37 GMT) > X-Complaints-To: groups-abuse google.com > NNTP-Posting-Date: Mon, 15 Nov 2010 04:03:37 +0000 (UTC) > Complaints-To: groups-abuse google.com > Injection-Info: v28g2000prn.googlegroups.com; posting-host=130.102.44.25; posting-account=rYyWJQoAAACVJO77HvcyJfa3TnGYCqK_ > User-Agent: G2/1.0 > X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.2.4) Gecko/20100611 Firefox/3.6.4,gzip(gfe) > From wuwei23 at gmail.com Mon Nov 15 00:44:35 2010 From: wuwei23 at gmail.com (alex23) Date: Sun, 14 Nov 2010 21:44:35 -0800 (PST) Subject: Komodo 6, why "Workspace Restore" after every restart? References: <4ce07839$0$17214$c3e8da3$eb767761@news.astraweb.com> <428b98ca-72bf-4e3b-ad8a-dafe2fc4d553@v28g2000prn.googlegroups.com> <4ce0c065$0$23246$c3e8da3$a9097924@news.astraweb.com> Message-ID: <6ae54329-c652-4a59-b0e2-4c2038f58d5a@x4g2000pre.googlegroups.com> John Doe wrote: > UseNet would be better off if Google Groups didn't exist, IMO. I'm sorry, are you cranky because you didn't get the answer you wanted when you posted in a less relevant forum? Why do you think comp.lang.python is more appropriate than the Komodo forums? What does Google Groups have to do with this issue? From lambdadmitry at gmail.com Mon Nov 15 01:39:05 2010 From: lambdadmitry at gmail.com (Dmitry Groshev) Date: Sun, 14 Nov 2010 22:39:05 -0800 (PST) Subject: Some syntactic sugar proposals Message-ID: Here are some proposals. They are quite useful at my opinion and I'm interested for suggestions. It's all about some common patterns. First of all: how many times do you write something like t = foo() t = t if pred(t) else default_value ? Of course we can write it as t = foo() if pred(foo()) else default_value but here we have 2 foo() calls instead of one. Why can't we write just something like this: t = foo() if pred(it) else default_value where "it" means "foo() value"? Second, I saw a lot of questions about using dot notation for a "object-like" dictionaries and a lot of solutions like this: class dotdict(dict): def __getattr__(self, attr): return self.get(attr, None) __setattr__= dict.__setitem__ __delattr__= dict.__delitem__ why there isn't something like this in a standart library? And the third. The more I use python the more I see how "natural" it can be. By "natural" I mean the statements like this: [x.strip() for x in reversed(foo)] which looks almost like a natural language. But there is some pitfalls: if x in range(a, b): #wrong! it feels so natural to check it that way, but we have to write if a <= x <= b I understand that it's not a big deal, but it would be awesome to have some optimisations - it's clearly possible to detect things like that "wrong" one and fix it in a bytecode. x in range optimisation dot dict access foo() if foo() else bar() From lambdadmitry at gmail.com Mon Nov 15 01:40:42 2010 From: lambdadmitry at gmail.com (Dmitry Groshev) Date: Sun, 14 Nov 2010 22:40:42 -0800 (PST) Subject: Some syntactic sugar proposals References: Message-ID: On Nov 15, 9:39?am, Dmitry Groshev wrote: > Here are some proposals. They are quite useful at my opinion and I'm > interested for suggestions. It's all about some common patterns. > First of all: how many times do you write something like > ? ? t = foo() > ? ? t = t if pred(t) else default_value > ? Of course we can write it as > ? ? t = foo() if pred(foo()) else default_value > but here we have 2 foo() calls instead of one. Why can't we write just > something like this: > ? ? t = foo() if pred(it) else default_value > where "it" means "foo() value"? > Second, I saw a lot of questions about using dot notation for a > "object-like" dictionaries and a lot of solutions like this: > ? ? class dotdict(dict): > ? ? ? ? def __getattr__(self, attr): > ? ? ? ? ? ? return self.get(attr, None) > ? ? ? ? __setattr__= dict.__setitem__ > ? ? ? ? __delattr__= dict.__delitem__ > why there isn't something like this in a standart library? > And the third. The more I use python the more I see how "natural" it > can be. By "natural" I mean the statements like this: > ? ? [x.strip() for x in reversed(foo)] > which looks almost like a natural language. But there is some > pitfalls: > ? ? if x in range(a, b): #wrong! > it feels so natural to check it that way, but we have to write > ? ? if a <= x <= b > I understand that it's not a big deal, but it would be awesome to have > some optimisations - it's clearly possible to detect things like that > "wrong" one and fix it in a bytecode. > > x in range optimisation > dot dict access > foo() if foo() else bar() Oh, I'm sorry. I forgot to delete my little notes at the bottom of message. From clp2 at rebertia.com Mon Nov 15 01:48:04 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 14 Nov 2010 22:48:04 -0800 Subject: Some syntactic sugar proposals In-Reply-To: References: Message-ID: On Sun, Nov 14, 2010 at 10:39 PM, Dmitry Groshev wrote: > Here are some proposals. They are quite useful at my opinion and I'm > interested for suggestions. It's all about some common patterns. > Second, I saw a lot of questions about using dot notation for a > "object-like" dictionaries and a lot of solutions like this: > ? ?class dotdict(dict): > ? ? ? ?def __getattr__(self, attr): > ? ? ? ? ? ?return self.get(attr, None) > ? ? ? ?__setattr__= dict.__setitem__ > ? ? ? ?__delattr__= dict.__delitem__ > why there isn't something like this in a standart library? There is: http://docs.python.org/library/collections.html#collections.namedtuple The "bunch" recipe is also fairly well-known; I suppose one could argue whether it's std-lib-worthy: http://code.activestate.com/recipes/52308-the-simple-but-handy-collector-of-a-bunch-of-named/ Cheers, Chris From lambdadmitry at gmail.com Mon Nov 15 01:53:33 2010 From: lambdadmitry at gmail.com (Dmitry Groshev) Date: Sun, 14 Nov 2010 22:53:33 -0800 (PST) Subject: Some syntactic sugar proposals References: Message-ID: On Nov 15, 9:48?am, Chris Rebert wrote: > On Sun, Nov 14, 2010 at 10:39 PM, Dmitry Groshev wrote: > > Here are some proposals. They are quite useful at my opinion and I'm > > interested for suggestions. It's all about some common patterns. > > > Second, I saw a lot of questions about using dot notation for a > > "object-like" dictionaries and a lot of solutions like this: > > ? ?class dotdict(dict): > > ? ? ? ?def __getattr__(self, attr): > > ? ? ? ? ? ?return self.get(attr, None) > > ? ? ? ?__setattr__= dict.__setitem__ > > ? ? ? ?__delattr__= dict.__delitem__ > > why there isn't something like this in a standart library? > > There is:http://docs.python.org/library/collections.html#collections.namedtuple > > The "bunch" recipe is also fairly well-known; I suppose one could > argue whether it's std-lib-worthy:http://code.activestate.com/recipes/52308-the-simple-but-handy-collec... > > Cheers, > Chris namedtuple is not a "drop-in" replacement like this "dotdict" thing - you first need to create a new namedtuple instance. As for me it's a bit too complicated. From wuwei23 at gmail.com Mon Nov 15 02:30:30 2010 From: wuwei23 at gmail.com (alex23) Date: Sun, 14 Nov 2010 23:30:30 -0800 (PST) Subject: Some syntactic sugar proposals References: Message-ID: <4ac1734d-fffb-4fdc-be42-27812a174b97@i32g2000pri.googlegroups.com> On Nov 15, 4:39?pm, Dmitry Groshev wrote: > First of all: how many times do you write something like > ? ? t = foo() > ? ? t = t if pred(t) else default_value > ? Of course we can write it as > ? ? t = foo() if pred(foo()) else default_value > but here we have 2 foo() calls instead of one. Why can't we write just > something like this: > ? ? t = foo() if pred(it) else default_value > where "it" means "foo() value"? Could you provide an actual use case for this. This seems weird to me: you're creating an object, testing the object, then possibly throwing it away and using a default instead. Are you sure you can't restructure your code as such: t = foo(x) if else default > Second, I saw a lot of questions about using dot notation for a > "object-like" dictionaries and a lot of solutions like this: > ? ? class dotdict(dict): > ? ? ? ? def __getattr__(self, attr): > ? ? ? ? ? ? return self.get(attr, None) > ? ? ? ? __setattr__= dict.__setitem__ > ? ? ? ? __delattr__= dict.__delitem__ > why there isn't something like this in a standart library? Personally, I like keeping object attribute references separate from dictionary item references. If you're someone who doesn't mind muddying that distinction, then - as you've discovered - it's a simple addition to your own code. > ? ? if x in range(a, b): #wrong! Only in Python 3.x, it's perfectly valid in Python 2.x. To achieve the same in Python 3.x, try: if x in list(range(a, b,)): # BUT SEE MY COMMENT BELOW > it feels so natural to check it that way, but we have to write > ? ? if a <= x <= b > I understand that it's not a big deal, but it would be awesome to have > some optimisations - it's clearly possible to detect things like that > "wrong" one and fix it in a bytecode. This seems more like a pessimisation to me: your range version constructs a list just to do a single container check. That's a _lot_ more cumbersome than two simple comparisons chained together. From wuwei23 at gmail.com Mon Nov 15 02:31:45 2010 From: wuwei23 at gmail.com (alex23) Date: Sun, 14 Nov 2010 23:31:45 -0800 (PST) Subject: Some syntactic sugar proposals References: <4ac1734d-fffb-4fdc-be42-27812a174b97@i32g2000pri.googlegroups.com> Message-ID: <62c29144-d2bf-4f30-88c9-e726f62b5dc2@k14g2000pre.googlegroups.com> On Nov 15, 5:30?pm, alex23 wrote: > ? ?t = foo(x) if else default This should read 'test' instead of 'text', sorry. From lambdadmitry at gmail.com Mon Nov 15 02:50:33 2010 From: lambdadmitry at gmail.com (Dmitry Groshev) Date: Sun, 14 Nov 2010 23:50:33 -0800 (PST) Subject: Some syntactic sugar proposals References: <4ac1734d-fffb-4fdc-be42-27812a174b97@i32g2000pri.googlegroups.com> Message-ID: On Nov 15, 10:30?am, alex23 wrote: > On Nov 15, 4:39?pm, Dmitry Groshev wrote: > > > First of all: how many times do you write something like > > ? ? t = foo() > > ? ? t = t if pred(t) else default_value > > ? Of course we can write it as > > ? ? t = foo() if pred(foo()) else default_value > > but here we have 2 foo() calls instead of one. Why can't we write just > > something like this: > > ? ? t = foo() if pred(it) else default_value > > where "it" means "foo() value"? > > Could you provide an actual use case for this. This seems weird to me: > you're creating an object, testing the object, then possibly throwing > it away and using a default instead. Are you sure you can't > restructure your code as such: > > ? ?t = foo(x) if else default Sure. Let's pretend you have some string foo and compiled regular expression bar. Naive code: t = bar.findall(foo) if len(t) < 3: t = [] Code with proposed syntactic sugar: t = bar.findall(foo) if len(it) > 2 else [] > > Second, I saw a lot of questions about using dot notation for a > > "object-like" dictionaries and a lot of solutions like this: > > ? ? class dotdict(dict): > > ? ? ? ? def __getattr__(self, attr): > > ? ? ? ? ? ? return self.get(attr, None) > > ? ? ? ? __setattr__= dict.__setitem__ > > ? ? ? ? __delattr__= dict.__delitem__ > > why there isn't something like this in a standart library? > > Personally, I like keeping object attribute references separate from > dictionary item references. Your Python doesn't - dot notation is just a sugar for __dict__ lookup with default metaclass. > This seems more like a pessimisation to me: your range version > constructs a list just to do a single container check. That's a _lot_ > more cumbersome than two simple comparisons chained together. By "wrong" I meant exactly this. I told about "compiler" optimisation of statements like this so it would not construct a list. From jdoe at usenetlove.invalid Mon Nov 15 03:08:25 2010 From: jdoe at usenetlove.invalid (John Doe) Date: 15 Nov 2010 08:08:25 GMT Subject: Komodo 6, why "Workspace Restore" after every restart? References: <4ce07839$0$17214$c3e8da3$eb767761@news.astraweb.com> <428b98ca-72bf-4e3b-ad8a-dafe2fc4d553@v28g2000prn.googlegroups.com> <4ce0c065$0$23246$c3e8da3$a9097924@news.astraweb.com> <6ae54329-c652-4a59-b0e2-4c2038f58d5a@x4g2000pre.googlegroups.com> Message-ID: <4ce0ea79$0$29271$c3e8da3$88b277c5@news.astraweb.com> alex23 wrote: > John Doe wrote: >> UseNet would be better off if Google Groups didn't exist, IMO. > > I'm sorry, are you cranky because you didn't get the answer you > wanted when you posted in a less relevant forum? Do you realize the harm your filthy news server is doing to UseNet? Many regulars here block all of those who post through Google Groups. That is because your stinking news server spams UseNet like no other ever has. > Why do you think comp.lang.python is more appropriate than the > Komodo forums? Because I prefer posting to UseNet. Komodo is a popular subject here. > What does Google Groups have to do with this issue? Google Groups spews a massive amount of sewage onto UseNet everyday. Google Groups is your news server. You should be ashamed, and I want to help. From nobody at nowhere.com Mon Nov 15 03:08:26 2010 From: nobody at nowhere.com (Nobody) Date: Mon, 15 Nov 2010 08:08:26 +0000 Subject: subprocess pipe References: Message-ID: On Sun, 14 Nov 2010 19:47:55 +0000, Tim Harig wrote: > On 2010-11-14, Camille Harang wrote: >> # pg_dump prompts for password so I inject it in stdin. >> pgsql.stdin.write('MY_PASSWORD' + '\n') > > For security reasons, some programs use direct access to the TTY system > for password entry rather then reading from stdin. Indeed, the getpass() function exists[1] for this purpose: The getpass() function opens /dev/tty (the controlling terminal of the process), outputs the string prompt, turns off echoing, reads one line (the "password"), restores the terminal state and closes /dev/tty again. [1] Or existed. It was dropped from the Unix standard in POSIX.1-2001, but most systems still provide it. From wuwei23 at gmail.com Mon Nov 15 03:42:36 2010 From: wuwei23 at gmail.com (alex23) Date: Mon, 15 Nov 2010 00:42:36 -0800 (PST) Subject: Komodo 6, why "Workspace Restore" after every restart? References: <4ce07839$0$17214$c3e8da3$eb767761@news.astraweb.com> <428b98ca-72bf-4e3b-ad8a-dafe2fc4d553@v28g2000prn.googlegroups.com> <4ce0c065$0$23246$c3e8da3$a9097924@news.astraweb.com> <6ae54329-c652-4a59-b0e2-4c2038f58d5a@x4g2000pre.googlegroups.com> <4ce0ea79$0$29271$c3e8da3$88b277c5@news.astraweb.com> Message-ID: <15016ae4-b341-4f4e-ac84-62fe7f93f217@g20g2000prg.googlegroups.com> John Doe wrote: > Google Groups spews a massive amount of sewage onto UseNet > everyday. Google Groups is your news server. You should be > ashamed, and I want to help. Get over yourself. From jarausch at igpm.rwth-aachen.de Mon Nov 15 03:46:17 2010 From: jarausch at igpm.rwth-aachen.de (Helmut Jarausch) Date: 15 Nov 2010 08:46:17 GMT Subject: import site fails - Please Help Message-ID: <8kcaapF44bU1@mid.dfncis.de> Hi, I'm completely puzzled and I hope someone can shed some light on it. After cloning a running system, booting the new machine from a rescue CD, chroot to the new root partition, I get the following strange error from python upon startup python -v > import site failed .... st= os.stat(path) stat() argument 1 must be encoded string without NULL bytes, not str So, what's broken? How can I get out what 'path' contained at this moment? Many thanks for your help, Helmut. From wuwei23 at gmail.com Mon Nov 15 04:03:55 2010 From: wuwei23 at gmail.com (alex23) Date: Mon, 15 Nov 2010 01:03:55 -0800 (PST) Subject: Some syntactic sugar proposals References: <4ac1734d-fffb-4fdc-be42-27812a174b97@i32g2000pri.googlegroups.com> Message-ID: On Nov 15, 5:50?pm, Dmitry Groshev wrote: > On Nov 15, 10:30?am, alex23 wrote: > > Personally, I like keeping object attribute references separate from > > dictionary item references. > > Your Python doesn't - dot notation is just a sugar for __dict__ lookup > with default metaclass. That's a gross oversimplification that tends towards wrong: >>> class C(object): ... def __init__(self): ... self._x = None ... @property ... def x(self): return self._x ... @x.setter ... def x(self, val): self._x = val ... >>> c = C() >>> c.x = 1 >>> c.x 1 >>> c.__dict__['x'] Traceback (most recent call last): File "", line 1, in KeyError: 'x' But my concern has _nothing_ to do with the implementation detail of how objects hold attributes, it's solely over the clarity that comes from being able to visually tell that something is an object vs a dictionary. > > This seems more like a pessimisation to me: your range version > > constructs a list just to do a single container check. That's a _lot_ > > more cumbersome than two simple comparisons chained together. > > By "wrong" I meant exactly this. I told about "compiler" optimisation > of statements like this so it would not construct a list. So you want this: if x in range(1,10): ...to effectively emit the same bytecode as a chained comparison while this: for x in range(1,10): ...produces a list/generator? Never going to happen. "Special cases aren't special enough to break the rules." The standard form for chained comparisons can handle far more complex expressions which your 'in' version could not: 0 <= min <= max <= 100 From jdoe at usenetlove.invalid Mon Nov 15 04:04:08 2010 From: jdoe at usenetlove.invalid (John Doe) Date: 15 Nov 2010 09:04:08 GMT Subject: Komodo 6, why "Workspace Restore" after every restart? References: <4ce07839$0$17214$c3e8da3$eb767761@news.astraweb.com> <428b98ca-72bf-4e3b-ad8a-dafe2fc4d553@v28g2000prn.googlegroups.com> <4ce0c065$0$23246$c3e8da3$a9097924@news.astraweb.com> <6ae54329-c652-4a59-b0e2-4c2038f58d5a@x4g2000pre.googlegroups.com> <4ce0ea79$0$29271$c3e8da3$88b277c5@news.astraweb.com> <15016ae4-b341-4f4e-ac84-62fe7f93f217@g20g2000prg.googlegroups.com> Message-ID: <4ce0f788$0$30018$c3e8da3$76a7c58f@news.astraweb.com> alex23 wrote: > John Doe wrote: >> Google Groups spews a massive amount of sewage onto UseNet >> everyday. Google Groups is your news server. You should be >> ashamed > > Get over yourself. You too, and stop using the spammers den while you are at it. -- See also googled groups > Path: news.astraweb.com!border5.newsrouter.astraweb.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!postnews.google.com!g20g2000prg.googlegroups.com!not-for-mail > From: alex23 > Newsgroups: comp.lang.python > Subject: Re: Komodo 6, why "Workspace Restore" after every restart? > Date: Mon, 15 Nov 2010 00:42:36 -0800 (PST) > Organization: http://groups.google.com > Lines: 6 > Message-ID: <15016ae4-b341-4f4e-ac84-62fe7f93f217 g20g2000prg.googlegroups.com> > References: <4ce07839$0$17214$c3e8da3$eb767761 news.astraweb.com> <428b98ca-72bf-4e3b-ad8a-dafe2fc4d553 v28g2000prn.googlegroups.com> <4ce0c065$0$23246$c3e8da3$a9097924 news.astraweb.com> <6ae54329-c652-4a59-b0e2-4c2038f58d5a x4g2000pre.googlegroups.com> <4ce0ea79$0$29271$c3e8da3$88b277c5 news.astraweb.com> > NNTP-Posting-Host: 115.64.196.128 > Mime-Version: 1.0 > Content-Type: text/plain; charset=ISO-8859-1 > X-Trace: posting.google.com 1289810556 23916 127.0.0.1 (15 Nov 2010 08:42:36 GMT) > X-Complaints-To: groups-abuse google.com > NNTP-Posting-Date: Mon, 15 Nov 2010 08:42:36 +0000 (UTC) > Complaints-To: groups-abuse google.com > Injection-Info: g20g2000prg.googlegroups.com; posting-host=115.64.196.128; posting-account=rYyWJQoAAACVJO77HvcyJfa3TnGYCqK_ > User-Agent: G2/1.0 > X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.12 (KHTML, like Gecko) Chrome/9.0.576.0 Safari/534.12,gzip(gfe) > From lambdadmitry at gmail.com Mon Nov 15 04:27:02 2010 From: lambdadmitry at gmail.com (Dmitry Groshev) Date: Mon, 15 Nov 2010 01:27:02 -0800 (PST) Subject: Some syntactic sugar proposals References: <4ac1734d-fffb-4fdc-be42-27812a174b97@i32g2000pri.googlegroups.com> Message-ID: <3f1c77d1-b3b4-4f34-b61c-1598dba3517a@e20g2000vbn.googlegroups.com> On Nov 15, 12:03?pm, alex23 wrote: > On Nov 15, 5:50?pm, Dmitry Groshev wrote: > > > On Nov 15, 10:30?am, alex23 wrote: > > > Personally, I like keeping object attribute references separate from > > > dictionary item references. > > > Your Python doesn't - dot notation is just a sugar for __dict__ lookup > > with default metaclass. > > That's a gross oversimplification that tends towards wrong: > > >>> class C(object): > > ... ? def __init__(self): > ... ? ? self._x = None > ... ? @property > ... ? def x(self): return self._x > ... ? @x.setter > ... ? def x(self, val): self._x = val > ...>>> c = C() > >>> c.x = 1 > >>> c.x > 1 > >>> c.__dict__['x'] > > Traceback (most recent call last): > ? File "", line 1, in > KeyError: 'x' > > But my concern has _nothing_ to do with the implementation detail of > how objects hold attributes, it's solely over the clarity that comes > from being able to visually tell that something is an object vs a > dictionary. Oh, now I understand you. But this "dotdict" (or "bunch") things don't break anything. You still need to use it explicitly and it is very useful if you need to serialize some JSON data about some entities. s = """[{"name": "Jhon Doe", "age": "12"}, {"name": "Alice", "age": "23"}]""" t = map(dotdict, json.loads(s)) t[0] #{'age': '12', 'name': 'Jhon Doe'} t[0].age #'12' Of course you can do this with namedtuple, but in fact this isn't a tuple at all. It's a list of entities. > > > This seems more like a pessimisation to me: your range version > > > constructs a list just to do a single container check. That's a _lot_ > > > more cumbersome than two simple comparisons chained together. > > > By "wrong" I meant exactly this. I told about "compiler" optimisation > > of statements like this so it would not construct a list. > > So you want this: > > ? if x in range(1,10): > > ...to effectively emit the same bytecode as a chained comparison while > this: > > ? for x in range(1,10): > > ...produces a list/generator? > > Never going to happen. "Special cases aren't special enough to break > the rules." The standard form for chained comparisons can handle far > more complex expressions which your 'in' version could not: 0 <= min > <= max <= 100 I know about chained comparisons, thanks. It's not about them. It's about bytecode optimisation. But maybe you are right about "Special cases aren't special enough to break the rules". I kinda forgot that :) From aioe.org at technicalbloke.com Mon Nov 15 05:09:31 2010 From: aioe.org at technicalbloke.com (r0g) Date: Mon, 15 Nov 2010 10:09:31 +0000 Subject: is there an Python equivalent for the PHP super globals like $_POST, $_COOKIE ? References: Message-ID: On 12/11/10 01:25, Roy Smith wrote: > In article, > r0g wrote: > >> On 11/11/10 14:22, Stef Mientki wrote: >>> I can't find how th get to PHP's equivalent of $_Post and $_Cookie ? > > PHP is mostly a one-trick pony. It's meant to be run as a web scripting > language with Apache (or, I suppose, something else) on the front end. > As a result, a lot of web-specific things like $_Post and $_Cookie are > built into the language. > > Python is intended to be more general purpose, so things which are built > in to other languages usually can be found in library modules. In this > case, you probably want to look at the SimpleHTTPServer module. > Actually when they say "Simple" they really mean it. The the SimpleHTTPServer module doesn't parse form data at all. It's pretty easy to get that using the urlparse module though... def do_GET(self): getvars = urlparse.parse_qs( self.path ) field1 = getvars[ "username" ][0] field2 = getvars[ "password" ][0] if authenticate( field1, filed2 ): self.send_response(200) self.send_header("Content-type", "text/html") self.end_headers() self.wfile.write( "welcome" ) else: self.send_response(404) self.end_headers() return This may be lower level than you want really and does involve permanently running a daemon on your server as opposed to the PHP way of doing things (having Apache interpret PHP on a page by page basis). > My latest gig, however, has had me doing PHP for the past 3 months or > so. That's terrible, you have my fullest sympathy in these difficult times. Roger From mdw at distorted.org.uk Mon Nov 15 05:52:31 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Mon, 15 Nov 2010 10:52:31 +0000 Subject: strange behavor.... References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> <87tyjlhu1l.fsf.mdw@metalzone.distorted.org.uk> <87hbfk29gy.fsf@gmail.com> <87hbfkj247.fsf.mdw@metalzone.distorted.org.uk> <4cdf447d$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87lj4uhn9s.fsf.mdw@metalzone.distorted.org.uk> Steven D'Aprano writes: > > def foo(): > > l = [] > > for i in xrange(10): > > (lambda j: l.append((lambda: i, lambda: j)))(i) > > print [(f(), g()) for f, g in l] > > Here's a slightly less condensed version that demonstrates the same > behaviour, but may be slightly easier to understand: The output is the same but the reasons for it are different: > def spam(): > a = [] > b = [] > for i in xrange(5): > a.append(lambda: i) > b.append(lambda i=i: i) Here, you've replaced lambda-binding by a default argument value. > print [f() for f in a] > print [f() for f in b] > > In your function foo, the name "i" is bound to the objects 0, 1, 2, ... 9 > sequentially, each time around the for-loop. Inside the loop, a function > object is created and then called: > > (lambda j: l.append((lambda: i, lambda: j)))(i) > > (Aside: this depends on scoping rules that were introduced quite late in > Python's history -- prior to version 2.2, this wouldn't work at all.) Indeed. The default-argument trick above was used to simulate it. Not coincidentally, it was around version 2.2 that Python became interesting to me... > The "outer" lambda: > > lambda j: l.append(...) > > has a name in the function namespace (a "local variable") called "j". On > entry to this function, this j is bound to the same object which is bound > to i *at the time that the function is called*. That is, each of the > sequence of "outer" lambdas get a distinct j = 0, 1, 2, ... Ahh. You've invented a new concept of localness instead, which is equivalent to the usual notion of binding. > None of the function A0, A1, A2, ... have any local variable i. i.e., i is free in the An functions and in the outer lambda... > Functions B0, B1, B2, ... similarly have no local variable j. When you > call any of the Bs, Python looks in the enclosing scopes for a variable > j. However, in this case it *does* find one, in the "outer" lambda, ... but j is bound in the outer lambda. This is not new terminology: it goes back to lambda calculus: a variable x occurs free in a term T if * T is x; * T is U V where x occurs free in U or V; or * T is lambda y.U where y is not x and x occurs free in U. If x occurs free in T then it occurs bound in lambda x.T. See also SICP. > > * Python's `for' loop works by assignment. The name `i' remains bound > > to the same storage location throughout; > > This is not necessarily true. It's true for CPython, where function > locals are implemented as fixed slots in the function object; since the > slot doesn't move relative to the function, and the function doesn't move > relative to the heap, the name i is in a fixed storage location for the > life of foo. But that's not necessarily the case for all implementations > -- locals could be stored in a data structure that moves data around > (say, a red-black tree), or objects could be free to move in the heap, or > both. Don't be silly. In a tree, the `location' would be the tree node containing the corresponding key. You're working at the wrong level of abstraction. -- [mdw] From ph.ton.sharma at gmail.com Mon Nov 15 06:03:57 2010 From: ph.ton.sharma at gmail.com (Ton) Date: Mon, 15 Nov 2010 03:03:57 -0800 (PST) Subject: Help: Guide needed in trying to delete/flush the content of a fifo file. References: Message-ID: <1c7f7feb-ff95-404b-9628-458922360908@j12g2000prm.googlegroups.com> On Nov 14, 11:55?pm, MRAB wrote: > On 14/11/2010 14:48, ton ph wrote:> Hi python geeks, > > ? ?I have ?problem which i have been trying to find out for the past > > some days, i have a device which feeds info to my fifo continuosly, and > > a thread of mine reads the > > fifo continuosly. Now when i change a parameter in the device, it sends > > me different values. Now my problem is that , i want to get rid of the > > contents of my previous info which > > is present in my buffer of the fifo.So i want to flush the fifo content > > when my device starts sending different info .... i am implementing > > writing and reading the fifo ?using two different threads. > > Please someone guide me solving my problem. > > I highly apologise everyone in case my post is not so clear... > > Thanks everyone in advance. > > When the info changes, the thread which is putting items into the fifo > could flush it just by getting items from it (using a non-blocking get) > until it's empty. Hi Mrab, Thanks for your immediate reply , can you please guide me with any tool or library function which i can flush my fifo content .. i use os.mkfifo() to make the fifo. Or is there any other way i could do this ... Thanks From mdw at distorted.org.uk Mon Nov 15 06:07:12 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Mon, 15 Nov 2010 11:07:12 +0000 Subject: strange behavor.... References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> <87tyjlhu1l.fsf.mdw@metalzone.distorted.org.uk> <4cdf1206$0$29990$c3e8da3$5496439d@news.astraweb.com> <877hggiz17.fsf.mdw@metalzone.distorted.org.uk> <874obj1r0z.fsf@gmail.com> Message-ID: <87hbfihmlb.fsf.mdw@metalzone.distorted.org.uk> Arnaud Delobelle writes: > >>> exec "a=2" in d > assigning 2 to 'a' > >>> d['a'] > 2 > > >>> exec "global a; a = 3" in d > >>> d['a'] > 3 Oooh, now isn't that an interesting wrinkle? I've been careful (without drawing attention) to restrict my arguments to variables inside functions, largely because Python's global scopes work completely differently. (Python's global scopes work similarly to traditional Lisp and Scheme, which isn't at all objectionable, but it's not the only way of managing global scopes. Queinnec's Lisp In Small Pieces describes others.) > So even if the globals() dictionary is custom, its __setitem__ method is > *not* called. Fascinating. Thank you. -- [mdw] From hniksic at xemacs.org Mon Nov 15 06:10:29 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Mon, 15 Nov 2010 12:10:29 +0100 Subject: Some syntactic sugar proposals References: Message-ID: <87oc9q266y.fsf@xemacs.org> Dmitry Groshev writes: > which looks almost like a natural language. But there is some > pitfalls: > if x in range(a, b): #wrong! > it feels so natural to check it that way, but we have to write > if a <= x <= b For the record, you have to write: if a <= x < b: Ranges are open on the ending side. From chrmic at gmx.de Mon Nov 15 06:24:40 2010 From: chrmic at gmx.de (Christoph Michalke) Date: Mon, 15 Nov 2010 12:24:40 +0100 Subject: distutils, cygwin, ' not a regular file Message-ID: <20101115112440.193500@gmx.net> In-Reply-To: <8faqj0FnoeU1 at mid.individual.net> References: <8faqj0FnoeU1 at mid.individual.net> In message <8faqj0FnoeU1 at mid.individual.net>, on Tue, 14 Sep 2010 20:50:04 -0600, Wed Sep 15 04:50:04 2010, Paul Watson wrote: > $ python setup.py sdist > [...] > reading manifest file 'MANIFEST' > [...] > ' not a regular file -- skipping > ' not a regular file -- skipping > ' not a regular file -- skipping In distutils/command/sdist.py in make_release_tree() I find log.warn("'%s' not a regular file -- skipping" % file) Therefore 2 apostrophes should appear in your setup.py sdist output. But you are seeing only one, therefore the file names in your file list probably contain a "\r" (carriage return). You seem to get your file list from a MANIFEST file, and probably this MANIFEST file was checked in on Windows with CR LF line endings and now you are reading it in cygwin (or in any Unix like environment) and you are getting a file name "sample.py\r" instead of "sample.py". The file "sample.py" exists and is a regular file. But the file "sample.py\r" does not exist and is therefore especially not a regular file. HTH, regards Christoph -- GMX DSL Doppel-Flat ab 19,99 €/mtl.! Jetzt auch mit gratis Notebook-Flat! http://portal.gmx.net/de/go/dsl From mdw at distorted.org.uk Mon Nov 15 07:28:46 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Mon, 15 Nov 2010 12:28:46 +0000 Subject: Some syntactic sugar proposals References: Message-ID: <87zktag48x.fsf.mdw@metalzone.distorted.org.uk> Dmitry Groshev writes: > First of all: how many times do you write something like > t = foo() > t = t if pred(t) else default_value > ? Of course we can write it as > t = foo() if pred(foo()) else default_value > but here we have 2 foo() calls instead of one. Why can't we write just > something like this: > t = foo() if pred(it) else default_value > where "it" means "foo() value"? How about t = (lambda y: y if pred(y) else default_value)(foo(x)) You could even package the lambda into a named function if you get bored of typing or your aesthetic senses are offended. > And the third. The more I use python the more I see how "natural" it > can be. By "natural" I mean the statements like this: > [x.strip() for x in reversed(foo)] > which looks almost like a natural language. But there is some > pitfalls: > if x in range(a, b): #wrong! > it feels so natural to check it that way, but we have to write > if a <= x <= b This, I think, is your error. The test `x in range(a, b)' means the same as `a <= x < b' (only in Python 2 it builds a list and then throws it away again). Such half-open intervals turn out to be what you want most of the time, and I think you'll avoid many bugs if you embrace them rather than trying to cling to the fully-closed intervals above. Python very definitely made the right decision to use half-open intervals pervasively, e.g., for `rangeand 'in sequence slicing. It's a bad idea to fight against it. Advantages of half-open intervals [a, b): * The number of elements is exactly b - a; closed intervals contain an extra element which is often forgotten. * They compose and split nicely: if a <= c <= b then [a, b) is exactly the disjoint union of [a, c) and [c, b). * Sums over these intervals are often better behaved; indeed, there's a rather pretty analogy between sums on half-open intervals and definite integrals which is lost if you use closed intervals. (The above two observations are special cases of this one.) See Concrete Mathematics (Graham, Knuth, Patashnik) for more on this. * It's easy to express an empty interval. You can't do that if you work entirely with closed intervals, but empty sets are an important boundary case and it's annoying to have to handle them separately. -- [mdw] From santosh.srinivas at gmail.com Mon Nov 15 07:38:25 2010 From: santosh.srinivas at gmail.com (Santosh Srinivas) Date: Mon, 15 Nov 2010 12:38:25 -0000 Subject: DDE using Python Message-ID: <4ce129b9.1c988e0a.4142.5ae0@mx.google.com> Hello Group, I want to connect to an application on my desktop that I understand provides access to few topics and data via DDE. But, I don't know the topic names. Is there any way that I can connect and find out what the available options are? Thanks. S From python.list at tim.thechases.com Mon Nov 15 07:46:59 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 15 Nov 2010 06:46:59 -0600 Subject: Some syntactic sugar proposals In-Reply-To: References: Message-ID: <4CE12BC3.80404@tim.thechases.com> On 11/15/2010 12:39 AM, Dmitry Groshev wrote: > x in range optimisation I've often thought this would make a nice O(1)-test lookup on an xrange() generator. I don't have strong use-cases for it, but a bit of well-tested code in the standard library would save me from doing the math (along with its potential fenceposting and sign errors) the couple times I've reached for it. Using the x in list(xrange(...)) # or "range()" depending your version ends up with an O(n) lookup, though I suppose one could create a set() for O(1) lookups, but that still requires O(N) storage (where a mathematical lookup would involve O(1) storage *and* time) > foo() if foo() else bar() This is usually indicative that you need to cache the object...something like etcc = expensive_to_calculate_constructor() result = foo(etcc) if test(etcc) else bar() That way, you cache the potentially-expensive calculation, indicate to other readers-of-your-code that it's potentially-expensive, and enforce the use of that cache to ensure that you don't duplicate the expensive op. -tkc From neilc at norwich.edu Mon Nov 15 08:14:28 2010 From: neilc at norwich.edu (Neil Cerutti) Date: 15 Nov 2010 13:14:28 GMT Subject: another newbie question References: Message-ID: <8kcq1kFo4gU8@mid.individual.net> On 2010-11-14, Roy Smith wrote: > Then, there are people who try to program in proportional > fonts. The mind boggles. For a (thankfully short) while some > years ago, people were publishing programming books with the > code samples in proportional fonts. Blech. I kinda like it, but as a Vim user I can't partake. -- Neil Cerutti From artur.siekielski at gmail.com Mon Nov 15 08:54:56 2010 From: artur.siekielski at gmail.com (Artur Siekielski) Date: Mon, 15 Nov 2010 05:54:56 -0800 (PST) Subject: Getting references to objects without incrementing reference counters References: <8c98a453-3303-4509-be39-1a26084f573a@o11g2000prf.googlegroups.com> <8063c457-98bf-4add-a1c7-38b01848cbe3@w21g2000vby.googlegroups.com> Message-ID: <4feaf76f-2533-4776-95a3-d312be76ddb0@d20g2000yqg.googlegroups.com> On Nov 14, 10:04?pm, Jean-Paul Calderone wrote: > It might be interesting to try with Jython or PyPy. ?Neither of these > Python runtimes uses reference counting at all. I have to use CPython because of C extensions I use (and because I use Python 2.7 features). From roy at panix.com Mon Nov 15 09:00:05 2010 From: roy at panix.com (Roy Smith) Date: Mon, 15 Nov 2010 09:00:05 -0500 Subject: is there an Python equivalent for the PHP super globals like $_POST, $_COOKIE ? References: Message-ID: In article , r0g wrote: > > My latest gig, however, has had me doing PHP for the past 3 months or > > so. > > That's terrible, you have my fullest sympathy in these difficult times. Actually, in a sick sort of way, it's fun. We regularly have PHP bashing sessions in the office when somebody discovers yet another depraved piece of language mis-design and we all get a good laugh out of it. No all languages afford you the opportunity for this kind of entertainment. It's also quite educational. You can learn a lot about language design by observing the mistakes that can be made. From artur.siekielski at gmail.com Mon Nov 15 09:13:15 2010 From: artur.siekielski at gmail.com (Artur Siekielski) Date: Mon, 15 Nov 2010 06:13:15 -0800 (PST) Subject: Getting references to objects without incrementing reference counters References: <8c98a453-3303-4509-be39-1a26084f573a@o11g2000prf.googlegroups.com> Message-ID: <0afcca4a-13b7-42ab-aea5-86b4324708e3@p1g2000yqm.googlegroups.com> On Nov 15, 1:03?am, de... at web.de (Diez B. Roggisch) wrote: > You don't say what data you share, and if all of it is needed for each > child. So it's hard to suggest optimizations. Here is an example of such a problem I'm dealing with now: I'm building large index of words in memory, it takes 50% of RAM. After building it I want to enable querying it using multiple processors enabling fast handling of multiple clients at once (communication is done with sockets). So I create the index in the parent process and than fork children that handle client queries. But after a short time only traversing the index by children makes them use much memory, resulting shortly in Out Of Memory Errors. > And AFAIK there is no > built-in way of doing what you want. It's complex and error-prone. Having read-only objects is complex and error-prone? > Maybe mmap + (struct|pickle) help, if what you need can be formulated in a way > that traversing the whole data piecewise by explicitly > marshaling-demarshaling data? In case of this word index it is impossible... And probably would be too slow. Using mmap and mapping the object structure into structs should probably work... From michele.simionato at gmail.com Mon Nov 15 09:36:12 2010 From: michele.simionato at gmail.com (Michele Simionato) Date: Mon, 15 Nov 2010 06:36:12 -0800 (PST) Subject: STARTTLS extension not supported by server Message-ID: <6e4c8009-7d17-4d04-91dd-75e834b9cde0@o14g2000yqe.googlegroups.com> I have a CentOS machine with Python 2.4 and I wanted to install Python 2.7 on it. The installation went fine but now I have a problem with a script sending email via TLS authentication. If I do something like import smtplib smtpO = smtplib.SMTP() smtpO.ehlo() smtpO.starttls() I get the following error: Traceback (most recent call last): File "y.py", line 5, in smtpO.starttls() File "/home/rcare/lib/python2.7/smtplib.py", line 614, in starttls raise SMTPException("STARTTLS extension not supported by server.") smtplib.SMTPException: STARTTLS extension not supported by server. Notice that this not a problem of the SMTP server, since with Python 2.4 the script is connecting to the SMTP server just fine. At first I thought the problem was with the ssl support, I recompiled the module, but I still get the same error. Do you have any suggestion to be debug the issue and to figure out where the problem is? TIA, Michele Simionato From a_jtim at bellsouth.net Mon Nov 15 10:20:52 2010 From: a_jtim at bellsouth.net (Tim Arnold) Date: Mon, 15 Nov 2010 07:20:52 -0800 (PST) Subject: remote server and effective uid Message-ID: Hi, I have a remote server on a FreeBSD box with clients connecting from linux, all running python2.7. I've setup the remote server as an inetd service (currently running as 'nobody'). Both client and server have access to the same file systems. How can I enable the server process to write into the client's directories? If I change the inetd service to run as 'root', I guess that would work, but then the client couldn't remove the files put there after the request. I could ditch the whole server process and wrap client requests with rsh calls, but is there a way I can switch the effective uid of the server process without asking clients to login? Or is there a better way to solve the problem? thanks, --Tim Arnold From invalid at invalid.invalid Mon Nov 15 10:24:43 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 15 Nov 2010 15:24:43 +0000 (UTC) Subject: What was your strategy? References: <7xzktbcqox.fsf@ruckus.brouhaha.com> Message-ID: On 2010-11-15, Paul Rubin wrote: > Python is a pretty easy language if you have a reasonable programming > background when you first start with it. I think the way it's currently > organized, it may not be so great for self-study if you're not already a > programmer. The way what is organized? You think the language itself is organized poorly for self-study? -- Grant Edwards grant.b.edwards Yow! I wonder if I could at ever get started in the gmail.com credit world? From usernet at ilthio.net Mon Nov 15 10:41:01 2010 From: usernet at ilthio.net (Tim Harig) Date: Mon, 15 Nov 2010 15:41:01 +0000 (UTC) Subject: remote server and effective uid References: Message-ID: On 2010-11-15, Tim Arnold wrote: > How can I enable the server process to write into the client's > directories? > If I change the inetd service to run as 'root', I guess that would > work, but then the client couldn't remove the files put there after > the request. Python provides os.setuid() and os.seteuid() which wrap the system functions. See you systems man pages for these functions for more information. From deets at web.de Mon Nov 15 10:42:56 2010 From: deets at web.de (Diez B. Roggisch) Date: Mon, 15 Nov 2010 16:42:56 +0100 Subject: Getting references to objects without incrementing reference counters References: <8c98a453-3303-4509-be39-1a26084f573a@o11g2000prf.googlegroups.com> <0afcca4a-13b7-42ab-aea5-86b4324708e3@p1g2000yqm.googlegroups.com> Message-ID: <87pqu6zj7j.fsf@web.de> Artur Siekielski writes: > On Nov 15, 1:03?am, de... at web.de (Diez B. Roggisch) wrote: >> You don't say what data you share, and if all of it is needed for each >> child. So it's hard to suggest optimizations. > > Here is an example of such a problem I'm dealing with now: I'm > building large index of words in memory, it takes 50% of RAM. After > building it I want to enable querying it using multiple processors > enabling fast handling of multiple clients at once (communication is > done with sockets). So I create the index in the parent process and > than fork children that handle client queries. But after a short time > only traversing the index by children makes them use much memory, > resulting shortly in Out Of Memory Errors. > >> And AFAIK there is no >> built-in way of doing what you want. It's complex and error-prone. > > Having read-only objects is complex and error-prone? Yes. Python has no built-in semantics for that. You can't declare an object to be read-only. And if one wanted to implement that, you'd have to make sure the object consists only of read-only attributes itself. And circumvene a great deal of the dynamic features in python (which you don't need for this usecase, but still are there) Diez From kern.ra at gmail.com Mon Nov 15 11:06:45 2010 From: kern.ra at gmail.com (Becky Kern) Date: Mon, 15 Nov 2010 11:06:45 -0500 Subject: [Beginner question] Error when converting raster to ASCII Message-ID: Hi again users, This is in response to my post from 11/14/2010 (see below) >* Hi users, *>* I'm using Python 2.5 (in concert with ArcGIS 9.3) to convert a raster to *>* an ASCII file. I used the code (listed below) several weeks ago to *>* successfully do the conversion, but when I tried to replicate it a few *>* days ago, I got an error message. *>* import arcgisscripting *>* gp = arcgisscripting.create(9.3) *>* InRaster = "C:/data/raster1" *>* OutAsciiFile = "C:/data/raster2ascii.asc" *>* gp.RasterToASCII_conversion(InRaster, OutAsciiFile) *>* The error message: *>* arcgisscripting.ExecuteError: Failed to execute. Parameters are not *>* valid. raster1 does not exist. *>* My file path has not changed so I don't understand why Python can no *>* longer recognize my raster file. Any ideas? *>* * MRAB responded: Just to make sure, does os.path.isfile(InRaster) return True? When I tried os.path.isfile(InRaster), I received the following error message: "NameError: name 'os' is not defined" Does this shed any light on why my raster to ASCII conversion isn't working? Thanks again. -------------- next part -------------- An HTML attachment was scrubbed... URL: From calderone.jeanpaul at gmail.com Mon Nov 15 11:28:52 2010 From: calderone.jeanpaul at gmail.com (Jean-Paul Calderone) Date: Mon, 15 Nov 2010 08:28:52 -0800 (PST) Subject: Getting references to objects without incrementing reference counters References: <8c98a453-3303-4509-be39-1a26084f573a@o11g2000prf.googlegroups.com> <0afcca4a-13b7-42ab-aea5-86b4324708e3@p1g2000yqm.googlegroups.com> <87pqu6zj7j.fsf@web.de> Message-ID: On Nov 15, 10:42?am, de... at web.de (Diez B. Roggisch) wrote: > And circumvene a great deal of the dynamic features in python > (which you don't need for this usecase, but still are there) > Great as the features might be, when you don't need them, it's clearly a bad thing to have them drag you down. Fortunately the PyPy team is making great progress in implementing a runtime that transparently sheds those dynamic features when running a program that doesn't take advantage of them. Jean-Paul From old_road_farm at verizon.net Mon Nov 15 11:31:52 2010 From: old_road_farm at verizon.net (octopusgrabbus) Date: Mon, 15 Nov 2010 08:31:52 -0800 (PST) Subject: Modifying Element In For List Message-ID: <01e04b27-c523-40b7-b9cb-8288823de8fa@p11g2000vbn.googlegroups.com> My question concerns elementary list and pass by reference: I've written a function which is passed a list that contains rows read from a csv file. The function traverses csv_rows, row by row, and inspects the first element in each row. The function tests for '', and if true, replaces that with a 0. I've used the standard Python for syntax for this. def cleanMeterID(csv_rows, bad_meter_id_count): d = drIdx() row_number = 0 for row in csv_rows: if False == is_number(row[d.MeterID]): csv_rows[row_number][d.MeterID] = 0 row_number = row_number + 1 bad_meter_id_count[0]= bad_meter_id_count[0] + 1 print("Received ", bad_meter_id_count[0], " bad meter ids") I believe the logic show above is flawed, because I am not modifying elements in the original csv_rows list. I would modify this to use an index to traverse the list like idx=None for idx in range(0, len(csv_rows), 1): if False == is_number(row[d.MeterID]): csv_rows[row_number][d.MeterID] = 0 row_number = row_number + 1 bad_meter_id_count[0]= bad_meter_id_count[0] + 1 Is this correct? Thank you. From benjamin.kaplan at case.edu Mon Nov 15 11:36:46 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 15 Nov 2010 11:36:46 -0500 Subject: [Beginner question] Error when converting raster to ASCII In-Reply-To: References: Message-ID: On Monday, November 15, 2010, Becky Kern wrote: > Hi again users, > > This is in response to my post from 11/14/2010 (see below) > >> Hi users, >> I'm using Python 2.5 (in concert with ArcGIS 9.3) to convert a raster to >> an ASCII file. I used the code (listed below) several weeks ago to >> successfully do the conversion, but when I tried to replicate it a few >> days ago, I got an error message. >> import arcgisscripting >> gp = arcgisscripting.create(9.3) >> InRaster = "C:/data/raster1" >> OutAsciiFile = "C:/data/raster2ascii.asc" >> gp.RasterToASCII_conversion(InRaster, OutAsciiFile) >> The error message: >> arcgisscripting.ExecuteError: Failed to execute. Parameters are not >> valid. raster1 does not exist. >> My file path has not changed so I don't understand why Python can no >> longer recognize my raster file. Any ideas? >> > > MRAB responded: > Just to make sure, does os.path.isfile(InRaster) return True? > > When I tried os.path.isfile(InRaster), I received the following error message: > "NameError: name 'os' is not defined" you need to import os.path > > Does this shed any light on why my raster to ASCII conversion isn't working? > > Thanks again. > > From edreamleo at gmail.com Mon Nov 15 12:06:01 2010 From: edreamleo at gmail.com (Edward K. Ream) Date: Mon, 15 Nov 2010 09:06:01 -0800 (PST) Subject: Leo 4.8 rc1 released Message-ID: <330ee46d-4894-409d-ab4b-af517fb95dec@k30g2000vbn.googlegroups.com> Leo 4.8 release candidate 1 is now available at: http://sourceforge.net/project/showfiles.php?group_id=3458&package_id=29106 Leo is a text editor, data organizer, project manager and much more. See: http://webpages.charter.net/edreamleo/intro.html The highlights of Leo 4.8: -------------------------- - Leo now uses the simplest possible sentinel lines in external files. External files with sentinels now look like Emacs org-mode files. - Leo Qt gui now supports Drag and Drop. This was one of the most frequently requested features. - Improved abbreviation commands. You now define abbreviations in Leo settings nodes, not external files. - @url nodes may contain url's in body text. This allows headlines to contain summaries: very useful. - Leo now uses PyEnchant to check spelling. - Leo can now open multiple files from the command line. - Leo's ancient Tangle and Untangle commands are now deprecated. This will help newbies how to learn Leo. - Leo now shows "Resurrected" and "Recovered" nodes. These protect data and show how data have changed. These fix several long-standing data-related problems. - A new "screenshots" plugin for creating slide shows with Leo. I used this plugin to create Leo's introductory slide shows. - Improved autocompletion: Ctrl-space starts a one-time completion. - A better installer. - Many bug fixes. Links: ------ Leo: http://webpages.charter.net/edreamleo/front.html Forum: http://groups.google.com/group/leo-editor Download: http://sourceforge.net/project/showfiles.php?group_id=3458 Bzr: http://code.launchpad.net/leo-editor/ Quotes: http://webpages.charter.net/edreamleo/testimonials.html Edward K. Ream November 15, 2010 From duncan.booth at invalid.invalid Mon Nov 15 12:27:46 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 15 Nov 2010 17:27:46 GMT Subject: Modifying Element In For List References: <01e04b27-c523-40b7-b9cb-8288823de8fa@p11g2000vbn.googlegroups.com> Message-ID: octopusgrabbus wrote: > I've written a function which is passed a list that contains rows read > from a csv file. The function traverses csv_rows, row by row, and > inspects the first element in each row. The function tests for '', and > if true, replaces that with a 0. > > I've used the standard Python for syntax for this. > > def cleanMeterID(csv_rows, bad_meter_id_count): > d = drIdx() > > row_number = 0 > > for row in csv_rows: > if False == is_number(row[d.MeterID]): > csv_rows[row_number][d.MeterID] = 0 > row_number = row_number + 1 > bad_meter_id_count[0]= bad_meter_id_count[0] + 1 > > print("Received ", bad_meter_id_count[0], " bad meter ids") > > I believe the logic show above is flawed, because I am not modifying > elements in the original csv_rows list. You have a reference to the row, so just modify it directly. Other points: bad_meter_id_count should just be a return value: that messing about with a list is just plain nasty. Comparing directly against True or False is error prone: a value in Python can be false without actually being equal to False. def cleanMeterID(csv_rows): d = drIdx() count = 0 for row in csv_rows: if not is_number(row[d.MeterID]): # or even: if row[d.MeterID]=='': row[d.MeterID] = 0 count += 1 print("Received {} bad meter ids".format(count)) return count -- Duncan Booth http://kupuguy.blogspot.com From artur.siekielski at gmail.com Mon Nov 15 12:30:16 2010 From: artur.siekielski at gmail.com (Artur Siekielski) Date: Mon, 15 Nov 2010 09:30:16 -0800 (PST) Subject: Getting references to objects without incrementing reference counters References: <8c98a453-3303-4509-be39-1a26084f573a@o11g2000prf.googlegroups.com> <0afcca4a-13b7-42ab-aea5-86b4324708e3@p1g2000yqm.googlegroups.com> <87pqu6zj7j.fsf@web.de> Message-ID: On Nov 15, 5:28?pm, Jean-Paul Calderone wrote: > On Nov 15, 10:42?am, de... at web.de (Diez B. Roggisch) wrote: > > > And circumvene a great deal of the dynamic features in python > > (which you don't need for this usecase, but still are there) > > Great as the features might be, when you don't need them, it's clearly > a bad thing to have them drag you down. ?Fortunately the PyPy team is > making great progress in implementing a runtime that transparently > sheds > those dynamic features when running a program that doesn't take > advantage > of them. In case of PyPy such design - forks() + relying on copy-on-write - I think will not work at all, because PyPy GC moves objects so they will not stay in the same memory pages. Or if they are not modified they will stay at the same memory address? CPython's simple runtime (no real GC) makes reasoning about memory- level structures easy, so I was hoping that copy-on-write will work here. Anyway for my usecase using unsafe_listget (implemented by me - doesn't increment reference count) does the job. From tjreedy at udel.edu Mon Nov 15 13:17:45 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 15 Nov 2010 13:17:45 -0500 Subject: Some syntactic sugar proposals In-Reply-To: References: Message-ID: On 11/15/2010 1:39 AM, Dmitry Groshev wrote: > Here are some proposals. They are quite useful at my opinion and I'm > interested for suggestions. It's all about some common patterns. > First of all: how many times do you write something like > t = foo() > t = t if pred(t) else default_value Never. t=t unbinds and rebinds 't' to the same object. A waste. Only rebind if needed. if not pred(t): t = default_value > ? Of course we can write it as > t = foo() if pred(foo()) else default_value > but here we have 2 foo() calls instead of one. Why can't we write just > something like this: > t = foo() if pred(it) else default_value > where "it" means "foo() value"? Too magical. I agree with most other comments. -- Terry Jan Reedy From bblais at bryant.edu Mon Nov 15 13:49:34 2010 From: bblais at bryant.edu (Brian Blais) Date: Mon, 15 Nov 2010 13:49:34 -0500 Subject: Some syntactic sugar proposals In-Reply-To: References: Message-ID: <7BD5C86C-CDFD-4FBE-8AB7-A6C30AF9587F@bryant.edu> On Nov 15, 2010, at 1:39 AM, Dmitry Groshev wrote: > if x in range(a, b): #wrong! > it feels so natural to check it that way, but we have to write > if a <= x <= b > I understand that it's not a big deal, but it would be awesome to have > some optimisations - it's clearly possible to detect things like that > "wrong" one and fix it in a bytecode. I don't think anyone has pointed this out, but these are *not* the same thing. observe: x=3 if x in range(1,10): print "yay!" if 1<=x<10: print "yay too!" x=3.2 if x in range(1,10): print "yay!" if 1<=x<10: print "yay too!" output: yay! yay too! yay too! bb -- Brian Blais bblais at bryant.edu http://web.bryant.edu/~bblais http://bblais.blogspot.com/ From a_jtim at bellsouth.net Mon Nov 15 14:19:37 2010 From: a_jtim at bellsouth.net (Tim Arnold) Date: Mon, 15 Nov 2010 11:19:37 -0800 (PST) Subject: remote server and effective uid References: Message-ID: On Nov 15, 10:41?am, Tim Harig wrote: > On 2010-11-15, Tim Arnold wrote: > > > How can I enable the server process to write into the client's > > directories? > > If I change the inetd service to run as 'root', I guess that would > > work, but then the client couldn't remove the files put there after > > the request. > > Python provides os.setuid() and os.seteuid() which wrap the system > functions. ?See you systems man pages for these functions for more > information. Thanks -- that was a lot easier than I thought it was going to be. pass the client's uid in the message to the server like so argstring, local_dir, uid = message.split(':') os.seteuid(int(uid)) thanks again, --Tim From no.email at nospam.invalid Mon Nov 15 14:25:12 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 15 Nov 2010 11:25:12 -0800 Subject: STARTTLS extension not supported by server References: <6e4c8009-7d17-4d04-91dd-75e834b9cde0@o14g2000yqe.googlegroups.com> Message-ID: <7xtyjie6ef.fsf@ruckus.brouhaha.com> Michele Simionato writes: > Notice that this not a problem of the SMTP server, since with Python > 2.4 the script is connecting to the SMTP server Um, my guess is that 2.4 didn't attempt to use TLS at all, and your 2.7 installation doesn't have the TLS libraries installed or they're not configured where Python can find them. From bostjan.mejak at gmail.com Mon Nov 15 14:53:07 2010 From: bostjan.mejak at gmail.com (=?UTF-8?Q?Bo=C5=A1tjan_Mejak?=) Date: Mon, 15 Nov 2010 20:53:07 +0100 Subject: HTMLWindow or HtmlWindow or perhaps HTMLwindo Message-ID: Hello, I am wondering which of the 3 class names are prefered by PEP-8? class HTMLWindow(...) class HtmlWindow(...) class HTMLwindow(...) Thank you for your answer in advance. From krister.svanlund at gmail.com Mon Nov 15 15:09:41 2010 From: krister.svanlund at gmail.com (Krister Svanlund) Date: Mon, 15 Nov 2010 21:09:41 +0100 Subject: HTMLWindow or HtmlWindow or perhaps HTMLwindo In-Reply-To: References: Message-ID: """ CapitalizedWords (or CapWords, or CamelCase -- so named because of the bumpy look of its letters[4]). This is also sometimes known as StudlyCaps. Note: When using abbreviations in CapWords, capitalize all the letters of the abbreviation. Thus HTTPServerError is better than HttpServerError. """ On Mon, Nov 15, 2010 at 8:53 PM, Bo?tjan Mejak wrote: > Hello, I am wondering which of the 3 class names are prefered by PEP-8? > > class HTMLWindow(...) > > class HtmlWindow(...) > > class HTMLwindow(...) > > > Thank you for your answer in advance. > -- > http://mail.python.org/mailman/listinfo/python-list > From bmjames at gmail.com Mon Nov 15 15:09:58 2010 From: bmjames at gmail.com (Ben James) Date: Mon, 15 Nov 2010 20:09:58 +0000 Subject: HTMLWindow or HtmlWindow or perhaps HTMLwindo References: Message-ID: On 15/11/2010 19:53, Bo?tjan Mejak wrote: > Hello, I am wondering which of the 3 class names are prefered by PEP-8? > > class HTMLWindow(...) > > class HtmlWindow(...) > > class HTMLwindow(...) > > > Thank you for your answer in advance. PEP 8 says: Note: When using abbreviations in CapWords, capitalize all the letters of the abbreviation. Thus HTTPServerError is better than HttpServerError. So, to apply that to your example, PEP 8 recommends HTMLWindow. From kern.ra at gmail.com Mon Nov 15 15:14:56 2010 From: kern.ra at gmail.com (Becky Kern) Date: Mon, 15 Nov 2010 15:14:56 -0500 Subject: Solution to: [Beginner question] Raster to ASCII conversion Message-ID: Hi users, Found a solution to my Raster to ASCII conversion problem, so I thought I'd post. My raster was created in ArcGIS 9.3 as an ESRI GRID (folder with associated info folder). I needed to use the ListRasters method (see http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?id=958&pid=905&topicname=ListRasters_method) to get Python to recognize it as a raster. My functioning code is posted below. >>import arcgisscripting >>gp = arcgisscripting.create(9.3) >>gp.workspace = "C:\Users\Lab User\Desktop\BKern\Blackwater\PVA\Scenario 1\Nov 15" >>rasters = gp.ListRasters("","ALL") >>for raster in rasters: print raster ... scen1_11_15 >>InRaster = "scen1_11_15" >>OutasciiFile = "C:\Users\Lab User\Desktop\BKern\Blackwater\PVA\Scenario 1\Nov 15\scen1.asc" >>gp.RasterToASCII_conversion(InRaster, OutasciiFile) -------------- next part -------------- An HTML attachment was scrubbed... URL: From ndbecker2 at gmail.com Mon Nov 15 15:15:08 2010 From: ndbecker2 at gmail.com (Neal Becker) Date: Mon, 15 Nov 2010 15:15:08 -0500 Subject: question on ConfigParser defaults Message-ID: import ConfigParser # New instance with 'bar' and 'baz' defaulting to 'Life' and 'hard' each config = ConfigParser.SafeConfigParser({'bar': 'Life', 'baz': 'hard'}) config.read('example.cfg') print config.get('Section1', 'foo') # -> "Python is fun!" config.remove_option('Section1', 'bar') config.remove_option('Section1', 'baz') print config.get('Section1', 'foo') # -> "Life is hard!" -------------- I'm confused. ConfigParser insists that all settings live in some 'section'. At least, settings read from a config file have to have some [section]. What section is associated with the defaults set by the constructor? In the above example, there is no reference to 'Section1' in the constructor, yet we refer to 'Section1' later to retrieve the values? From krister.svanlund at gmail.com Mon Nov 15 15:22:23 2010 From: krister.svanlund at gmail.com (Krister Svanlund) Date: Mon, 15 Nov 2010 21:22:23 +0100 Subject: HTMLWindow or HtmlWindow or perhaps HTMLwindo In-Reply-To: References: Message-ID: On Mon, Nov 15, 2010 at 9:09 PM, Ben James wrote: > On 15/11/2010 19:53, Bo?tjan Mejak wrote: >> >> Hello, I am wondering which of the 3 class names are prefered by PEP-8? >> >> class HTMLWindow(...) >> >> class HtmlWindow(...) >> >> class HTMLwindow(...) >> >> >> Thank you for your answer in advance. > > PEP 8 says: > > ? ?Note: When using abbreviations in CapWords, capitalize all the > ? ?letters of the abbreviation. ?Thus HTTPServerError is better than > ? ?HttpServerError. > > So, to apply that to your example, PEP 8 recommends HTMLWindow. > -- > http://mail.python.org/mailman/listinfo/python-list > Yeah, since HTML is an abbreviation it's the exact recommendation to use... :) From python at mrabarnett.plus.com Mon Nov 15 15:37:00 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 15 Nov 2010 20:37:00 +0000 Subject: Solution to: [Beginner question] Raster to ASCII conversion In-Reply-To: References: Message-ID: <4CE199EC.6080001@mrabarnett.plus.com> On 15/11/2010 20:14, Becky Kern wrote: > Hi users, > Found a solution to my Raster to ASCII conversion problem, so I thought > I'd post. > My raster was created in ArcGIS 9.3 as an ESRI GRID (folder with > associated info folder). I needed to use the ListRasters method (see > http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?id=958&pid=905&topicname=ListRasters_method > ) to > get Python to recognize it as a raster. My functioning code is posted below. > >>import arcgisscripting > >>gp = arcgisscripting.create(9.3) > >>gp.workspace = "C:\Users\Lab > User\Desktop\BKern\Blackwater\PVA\Scenario 1\Nov 15" > >>rasters = gp.ListRasters("","ALL") > >>for raster in rasters: print raster > ... > scen1_11_15 > >>InRaster = "scen1_11_15" > >>OutasciiFile = "C:\Users\Lab > User\Desktop\BKern\Blackwater\PVA\Scenario 1\Nov 15\scen1.asc" > >>gp.RasterToASCII_conversion(InRaster, OutasciiFile) > Be careful when using string literals containing backslashes. It's recommended that you use raw strings: gp.workspace = r"C:\Users\Lab User\Desktop\BKern\Blackwater\PVA\Scenario 1\Nov 15" OutasciiFile = r"C:\Users\Lab User\Desktop\BKern\Blackwater\PVA\Scenario 1\Nov 15\scen1.asc" You were lucky that none of the backslashes started an escape sequence. If you were using Python 3 then it would've complained about \U and \N. From nagle at animats.com Mon Nov 15 15:44:05 2010 From: nagle at animats.com (John Nagle) Date: Mon, 15 Nov 2010 12:44:05 -0800 Subject: Some syntactic sugar proposals In-Reply-To: <4ac1734d-fffb-4fdc-be42-27812a174b97@i32g2000pri.googlegroups.com> References: <4ac1734d-fffb-4fdc-be42-27812a174b97@i32g2000pri.googlegroups.com> Message-ID: <4ce19ba5$0$1676$742ec2ed@news.sonic.net> On 11/14/2010 11:30 PM, alex23 wrote: > On Nov 15, 4:39 pm, Dmitry Groshev wrote: >> First of all: how many times do you write something like > >> Second, I saw a lot of questions about using dot notation for a >> "object-like" dictionaries and a lot of solutions like this: >> class dotdict(dict): >> def __getattr__(self, attr): >> return self.get(attr, None) >> __setattr__= dict.__setitem__ >> __delattr__= dict.__delitem__ >> why there isn't something like this in a standart library? > > Personally, I like keeping object attribute references separate from > dictionary item references. Right. This isn't JavaScript. If you need a "dict", use a "dict". Don't use attributes as named storage. It leads to problems. Functions and various built-in objects are in the attribute namespace, and this can lead to name clashes. Maybe security holes, if the attribute keys come from external input. There are also some restrictions on the syntax of attribute names, restrictions "dict" does not have. Remember, you can inherit from "dict", which allows you to write obj['abc'] which is almost as short as obj.abc but safer. John Nagle From python at mrabarnett.plus.com Mon Nov 15 15:47:09 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 15 Nov 2010 20:47:09 +0000 Subject: Help: Guide needed in trying to delete/flush the content of a fifo file. In-Reply-To: <1c7f7feb-ff95-404b-9628-458922360908@j12g2000prm.googlegroups.com> References: <1c7f7feb-ff95-404b-9628-458922360908@j12g2000prm.googlegroups.com> Message-ID: <4CE19C4D.2030403@mrabarnett.plus.com> On 15/11/2010 11:03, Ton wrote: > On Nov 14, 11:55 pm, MRAB wrote: >> On 14/11/2010 14:48, ton ph wrote:> Hi python geeks, >>> I have problem which i have been trying to find out for the past >>> some days, i have a device which feeds info to my fifo continuosly, and >>> a thread of mine reads the >>> fifo continuosly. Now when i change a parameter in the device, it sends >>> me different values. Now my problem is that , i want to get rid of the >>> contents of my previous info which >>> is present in my buffer of the fifo.So i want to flush the fifo content >>> when my device starts sending different info .... i am implementing >>> writing and reading the fifo using two different threads. >>> Please someone guide me solving my problem. >>> I highly apologise everyone in case my post is not so clear... >>> Thanks everyone in advance. >> >> When the info changes, the thread which is putting items into the fifo >> could flush it just by getting items from it (using a non-blocking get) >> until it's empty. > > Hi Mrab, > Thanks for your immediate reply , can you please guide me with any > tool or library function which i can flush my fifo content .. i use > os.mkfifo() to make the fifo. Or is there any other way i could do > this ... > Thanks Ah, you're using pipes; I thought you might've been using a queue. I don't know of a way of flushing a pipe. I wonder whether it's a good idea for the producer to keep filling the fifo, because the consumer know how 'old' the info is when it arrives, and there's your problem of discarding stale info. Perhaps the producer should wait until the consumer has sent an acknowledgement before sending more info. From nagle at animats.com Mon Nov 15 16:06:45 2010 From: nagle at animats.com (John Nagle) Date: Mon, 15 Nov 2010 13:06:45 -0800 Subject: Getting references to objects without incrementing reference counters In-Reply-To: <8c98a453-3303-4509-be39-1a26084f573a@o11g2000prf.googlegroups.com> References: <8c98a453-3303-4509-be39-1a26084f573a@o11g2000prf.googlegroups.com> Message-ID: <4ce1a0f5$0$1633$742ec2ed@news.sonic.net> On 11/14/2010 11:08 AM, Artur Siekielski wrote: > Hi. > I'm using CPython 2.7 and Linux. In order to make parallel > computations on a large list of objects I want to use multiple > processes (by using multiprocessing module). In the first step I fill > the list with objects and then I fork() my worker processes that do > the job. > > This should work optimally in the aspect of memory usage because Linux > implements copy-on-write in forked processes. There used to be a memory leak when using Pickle to talk to subprocesses. See what I wrote at "http://groups.google.com/group/comp.lang.python/browse_thread/thread/3f8b999c25af263a%22" The Pickle module has an optimization scheme and cache which requires that both sender and receiver keep a reference to each object transmitted. Cache clearing wasn't well worked out for Pickle object reuse, and the receive end had a memory leak. Did that get fixed? John Nagle From eric.promislow at gmail.com Mon Nov 15 16:15:48 2010 From: eric.promislow at gmail.com (Eric Promislow) Date: Mon, 15 Nov 2010 13:15:48 -0800 (PST) Subject: Komodo 6, why "Workspace Restore" after every restart? References: <4ce07839$0$17214$c3e8da3$eb767761@news.astraweb.com> <428b98ca-72bf-4e3b-ad8a-dafe2fc4d553@v28g2000prn.googlegroups.com> <4ce0c065$0$23246$c3e8da3$a9097924@news.astraweb.com> <6ae54329-c652-4a59-b0e2-4c2038f58d5a@x4g2000pre.googlegroups.com> <4ce0ea79$0$29271$c3e8da3$88b277c5@news.astraweb.com> <15016ae4-b341-4f4e-ac84-62fe7f93f217@g20g2000prg.googlegroups.com> <4ce0f788$0$30018$c3e8da3$76a7c58f@news.astraweb.com> Message-ID: <2f84eafd-f7fb-48a5-bd23-3e6a311ae99d@37g2000prx.googlegroups.com> Komodo always asks you if you want to restore the last workspace when it wasn't shut down cleanly the previous time. The reason for this is that it's possible Komodo ended up in a state where it's hung due to a particular workspace configuration. This question lets you bring up Komodo in a possibly sane configuration instead. Is this the best thing to do? Wouldn't it be better to manually remove a couple of config files, and restart Komodo in a basic but sane configuration? You could make a good case for that, and may I suggest that http://community.activestate.com/forums/komodo-discussion would be a better place to continue this particular discussion? Thanks for bringing up the issue though. Eric Promislow Komodo Developer From usernet at ilthio.net Mon Nov 15 16:26:02 2010 From: usernet at ilthio.net (Tim Harig) Date: Mon, 15 Nov 2010 21:26:02 +0000 (UTC) Subject: remote server and effective uid References: Message-ID: On 2010-11-15, Tim Arnold wrote: > On Nov 15, 10:41?am, Tim Harig wrote: >> On 2010-11-15, Tim Arnold wrote: >> >> > How can I enable the server process to write into the client's >> > directories? >> > If I change the inetd service to run as 'root', I guess that would >> > work, but then the client couldn't remove the files put there after >> > the request. >> >> Python provides os.setuid() and os.seteuid() which wrap the system >> functions. ?See you systems man pages for these functions for more >> information. > > Thanks -- that was a lot easier than I thought it was going to be. > pass the client's uid in the message to the server like so > > argstring, local_dir, uid = message.split(':') > os.seteuid(int(uid)) I am not sure exactly what you are doing; but, I would advise great caution as messing this up could easily open your system to exploitation. Be very sure that you know what you are doing. From nagle at animats.com Mon Nov 15 17:42:43 2010 From: nagle at animats.com (John Nagle) Date: Mon, 15 Nov 2010 14:42:43 -0800 Subject: What was your strategy? In-Reply-To: References: Message-ID: <4ce1b772$0$1663$742ec2ed@news.sonic.net> On 11/14/2010 2:59 PM, Seebs wrote: > On 2010-11-14, Jorge Biquez wrote: >> I was wondering if you can share what was the strategy you followed >> to master Python (Yes I know I have to work hard study and practice a >> lot). I mean did you use special books, special sites, a plan to >> learn each subject in a special way. I would like to know, if >> possible, comments specially from some of you who in the past had >> other languages, frameworks and platforms and left (almost) all of >> them and stayed with Python. > > I've been learning Python the same way I learn any language; get a > book, read it over lunch for a few days, start typing, ask people > how to improve my code once I have some. > > This information is almost certainly useless to you, though, unless > you've already learned at least six or seven programming languages. Right. I just read over the language description and the reference manual. Python is a memory-safe late-binding declaration-free naive interpreter with classes that uses indentation for nesting level and reference counting for allocation. If those are all familiar concepts from other languages, Python is trivial. Python is actually rather easy to learn. It doesn't have the storage management problems of C and C++, the awful syntax of Perl, the object-as-copy semantics of Javascript, or the mess of stacked libraries of Java. John Nagle From aahz at pythoncraft.com Mon Nov 15 17:52:52 2010 From: aahz at pythoncraft.com (Aahz) Date: 15 Nov 2010 14:52:52 -0800 Subject: OO and game design questions References: <2630c899-96b2-4f83-9081-764b80d76650@h7g2000yqn.googlegroups.com> Message-ID: In article , Martin Gregorie wrote: >On Tue, 19 Oct 2010 19:49:20 -0400, Dave Angel wrote: >> >> Thanks, that is what I was trying to say. In the same sense that >> emptying a list makes it quite small, if it's a general purpose object, >> you just want to remove all the attributes. > >I think a 'place' (to generalise it) is quite a small object in any case. >All it needs to contain is a few lists: >- a list of exits, which in some implementations might be simply > references to other places, but might usefully be objects with > two sides, each having an appearance and a link to the place > where that side appears. >- a list of fixed objects which only serve to describe the place. >- a list of mobile objects that actors can pick up and move >- a list of actors who happen to be there. > >plus a describePlace() method and add(), remove() and getItem() methods >for each list. It may be possible to use a single list for all types of >object, in which case the object itself would be very small indeed. Maybe you want a rule-based approach: http://eblong.com/zarf/essays/rule-based-if/ -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Look, it's your affair if you want to play with five people, but don't go calling it doubles." --John Cleese anticipates Usenet From cs at zip.com.au Mon Nov 15 20:30:06 2010 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 16 Nov 2010 12:30:06 +1100 Subject: Help: Guide needed in trying to delete/flush the content of a fifo file. In-Reply-To: <4CE19C4D.2030403@mrabarnett.plus.com> References: <4CE19C4D.2030403@mrabarnett.plus.com> Message-ID: <20101116013006.GA15879@cskk.homeip.net> On 15Nov2010 20:47, MRAB wrote: | On 15/11/2010 11:03, Ton wrote: | >Hi Mrab, | > Thanks for your immediate reply , can you please guide me with any | >tool or library function which i can flush my fifo content .. i use | >os.mkfifo() to make the fifo. Or is there any other way i could do | >this ... | >Thanks | | Ah, you're using pipes; I thought you might've been using a queue. I | don't know of a way of flushing a pipe. I think the nearest thing you can do is empty it with a read(). On many systems (AFAIR) a stat of a pipe returns the amount of buffered data, so you could go (untested - some of the following method names will probably be wrong, too) something like: buffered = os.fstat(fifo.fileno()) if buffered > 0: fifo.read(buffered) Of course it is all a bit racy, as data may arrive after the stat, but arbitrarily "flush"ing the pipe has equivalent problems. | I wonder whether it's a good idea for the producer to keep filling the | fifo, because the consumer know how 'old' the info is when it arrives, | and there's your problem of discarding stale info. Perhaps the producer | should wait until the consumer has sent an acknowledgement before | sending more info. I agree with this statement. -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ In the end, winning is the only safety. - Kerr Avon From jdoe at usenetlove.invalid Mon Nov 15 21:31:23 2010 From: jdoe at usenetlove.invalid (John Doe) Date: 16 Nov 2010 02:31:23 GMT Subject: Komodo 6, why "Workspace Restore" after every restart? References: <4ce07839$0$17214$c3e8da3$eb767761@news.astraweb.com> <428b98ca-72bf-4e3b-ad8a-dafe2fc4d553@v28g2000prn.googlegroups.com> <4ce0c065$0$23246$c3e8da3$a9097924@news.astraweb.com> <6ae54329-c652-4a59-b0e2-4c2038f58d5a@x4g2000pre.googlegroups.com> <4ce0ea79$0$29271$c3e8da3$88b277c5@news.astraweb.com> <15016ae4-b341-4f4e-ac84-62fe7f93f217@g20g2000prg.googlegroups.com> <4ce0f788$0$30018$c3e8da3$76a7c58f@news.astraweb.com> <2f84eafd-f7fb-48a5-bd23-3e6a311ae99d@37g2000prx.googlegroups.com> Message-ID: <4ce1ecfa$0$30001$c3e8da3$76a7c58f@news.astraweb.com> Eric Promislow wrote: > Komodo always asks you if you want to restore the last workspace > when it wasn't shut down cleanly the previous time. Why is shutting down in Windows XP more difficult for version 6? The only thing I have open is a single small Python file. Apparently version 6 is unable to handle the ordinary shutdown command it gets from Windows. Or maybe there is some setting that can correct the problem. Version 5 shutdown just fine when Windows was restarted. -- > > The reason for this is that it's possible Komodo ended up in a state > where > it's hung due to a particular workspace configuration. This question > lets > you bring up Komodo in a possibly sane configuration instead. > > Is this the best thing to do? Wouldn't it be better to manually > remove a > couple of config files, and restart Komodo in a basic but sane > configuration? > You could make a good case for that, and may I suggest that > http://community.activestate.com/forums/komodo-discussion would be a > better place to continue this particular discussion? > > Thanks for bringing up the issue though. > > Eric Promislow > Komodo Developer > > see also googled groups > Path: news.astraweb.com!border1.newsrouter.astraweb.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!postnews.google.com!37g2000prx.googlegroups.com!not-for-mail > From: Eric Promislow > Newsgroups: comp.lang.python > Subject: Re: Komodo 6, why "Workspace Restore" after every restart? > Date: Mon, 15 Nov 2010 13:15:48 -0800 (PST) > Organization: http://groups.google.com > Lines: 22 > Message-ID: <2f84eafd-f7fb-48a5-bd23-3e6a311ae99d 37g2000prx.googlegroups.com> > References: <4ce07839$0$17214$c3e8da3$eb767761 news.astraweb.com> <428b98ca-72bf-4e3b-ad8a-dafe2fc4d553 v28g2000prn.googlegroups.com> <4ce0c065$0$23246$c3e8da3$a9097924 news.astraweb.com> <6ae54329-c652-4a59-b0e2-4c2038f58d5a x4g2000pre.googlegroups.com> <4ce0ea79$0$29271$c3e8da3$88b277c5 news.astraweb.com> <15016ae4-b341-4f4e-ac84-62fe7f93f217 g20g2000prg.googlegroups.com> <4ce0f788$0$30018$c3e8da3$76a7c58f news.astraweb.com> > NNTP-Posting-Host: 204.244.102.2 > Mime-Version: 1.0 > Content-Type: text/plain; charset=ISO-8859-1 > X-Trace: posting.google.com 1289855748 13278 127.0.0.1 (15 Nov 2010 21:15:48 GMT) > X-Complaints-To: groups-abuse google.com > NNTP-Posting-Date: Mon, 15 Nov 2010 21:15:48 +0000 (UTC) > Complaints-To: groups-abuse google.com > Injection-Info: 37g2000prx.googlegroups.com; posting-host=204.244.102.2; posting-account=AeH9QwoAAABhC1IaTOmk_lG2sf4IeBZX > User-Agent: G2/1.0 > X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2.11) Gecko/20101012 Firefox/3.6.11 (.NET CLR 3.5.30729),gzip(gfe) > From steve-REMOVE-THIS at cybersource.com.au Tue Nov 16 00:17:37 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 16 Nov 2010 05:17:37 GMT Subject: Modifying Element In For List References: <01e04b27-c523-40b7-b9cb-8288823de8fa@p11g2000vbn.googlegroups.com> Message-ID: <4ce213f0$0$29983$c3e8da3$5496439d@news.astraweb.com> On Mon, 15 Nov 2010 08:31:52 -0800, octopusgrabbus wrote: > My question concerns elementary list and pass by reference: What does pass-by-reference have to do with Python? Python doesn't use pass-by-reference... if you think it does, you have misunderstood something. Hint: if you think Python has pass-by-reference, please write a procedure that takes two generic arguments, and swaps their values, like so: a = 1 b = 2 swap(a, b) assert a == 2 assert b == 1 This is the canonical test for pass by reference semantics. > I've written a function which is passed a list that contains rows read > from a csv file. What are the rows? Lists? Tuples? Something else? > The function traverses csv_rows, row by row, and > inspects the first element in each row. The function tests for '', and > if true, replaces that with a 0. > > I've used the standard Python for syntax for this. As opposed to C++ syntax or Lisp syntax? You can't write Python code without using Python syntax, so I'm not sure what you mean here. > def cleanMeterID(csv_rows, bad_meter_id_count): > d = drIdx() > > row_number = 0 > > for row in csv_rows: > if False == is_number(row[d.MeterID]): > csv_rows[row_number][d.MeterID] = 0 > row_number = row_number + 1 > bad_meter_id_count[0]= bad_meter_id_count[0] + 1 > > print("Received ", bad_meter_id_count[0], " bad meter ids") > > I believe the logic show above is flawed, because I am not modifying > elements in the original csv_rows list. Are you sure about that? What happens when you try it? > I would modify this to use an > index to traverse the list like This is nearly always the wrong solution in Python. -- Steven From steve-REMOVE-THIS at cybersource.com.au Tue Nov 16 00:26:08 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 16 Nov 2010 05:26:08 GMT Subject: Some syntactic sugar proposals References: Message-ID: <4ce215f0$0$29983$c3e8da3$5496439d@news.astraweb.com> On Sun, 14 Nov 2010 22:39:05 -0800, Dmitry Groshev wrote: > Here are some proposals. They are quite useful at my opinion and I'm > interested for suggestions. It's all about some common patterns. First > of all: how many times do you write something like > t = foo() > t = t if pred(t) else default_value > ? Hardly ever. Not often enough to need special syntax for it. Of course we can write it as > t = foo() if pred(foo()) else default_value > but here we have 2 foo() calls instead of one. Why can't we write just > something like this: > t = foo() if pred(it) else default_value > where "it" means "foo() value"? t = foo()+bar()+baz() if pred(it) else baz()-foo()-bar() What does "it" mean here? > Second, I saw a lot of questions about using dot notation for a > "object-like" dictionaries and a lot of solutions like this: > class dotdict(dict): > def __getattr__(self, attr): > return self.get(attr, None) > __setattr__= dict.__setitem__ > __delattr__= dict.__delitem__ > why there isn't something like this in a standart library? Because dot notation for dictionaries is not something we should encourage. > And the > third. The more I use python the more I see how "natural" it can be. By > "natural" I mean the statements like this: > [x.strip() for x in reversed(foo)] > which looks almost like a natural language. But there is some pitfalls: > if x in range(a, b): #wrong! Why do you say it's wrong? It's perfectly correct: 1 in range(1, 10) => returns True 1.5 in range(1, 10) => returns False 5 in range(1, 10) => returns True 10 in range(1, 10) => returns False exactly as I expect for element testing in a half-open interval. So where's the problem? If you want interval testing, you need to perform an interval test, not an element test. > it feels so natural to check it that way, but we have to write > if a <= x <= b > I understand that it's not a big deal, but it would be awesome to have > some optimisations - it's clearly possible to detect things like that > "wrong" one and fix it in a bytecode. If I write: x in range(1, 10) how do you expect the compiler to read my mind and know if I want the half-open interval or the closed interval? -- Steven From ian.g.kelly at gmail.com Tue Nov 16 00:40:00 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 15 Nov 2010 22:40:00 -0700 Subject: Some syntactic sugar proposals In-Reply-To: <4ce215f0$0$29983$c3e8da3$5496439d@news.astraweb.com> References: <4ce215f0$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 11/15/2010 10:26 PM, Steven D'Aprano wrote: > t = foo()+bar()+baz() if pred(it) else baz()-foo()-bar() > > What does "it" mean here? "it" would mean the result of the expression foo()+bar()+baz(). What else could it mean? There are valid objections to the proposal, but the intended semantics seem perfectly clear. Cheers, Ian From mback1 at live.se Tue Nov 16 00:45:38 2010 From: mback1 at live.se (Mikael B) Date: Tue, 16 Nov 2010 06:45:38 +0100 Subject: Leo 4.8 rc1 released In-Reply-To: <330ee46d-4894-409d-ab4b-af517fb95dec@k30g2000vbn.googlegroups.com> References: <330ee46d-4894-409d-ab4b-af517fb95dec@k30g2000vbn.googlegroups.com> Message-ID: > From: edreamleo at gmail.com > Subject: Leo 4.8 rc1 released > Date: Mon, 15 Nov 2010 09:06:01 -0800 > To: python-list at python.org > > Leo 4.8 release candidate 1 is now available at: > http://sourceforge.net/project/showfiles.php?group_id=3458&package_id=29106 > > Leo is a text editor, data organizer, project manager and much more. > See: > http://webpages.charter.net/edreamleo/intro.html I tried to install Leo on ubuntu 10.10 with python 2.6.6 prax at prax-MS-7327:~/H?mtningar/Leo-4.8-rc1/leo/scripts$ sudo python LinixInstall.py ***** Installing Leo to /usr/lib/leo... ***** Creating Leo startup script -> /usr/bin/leo ***** Leo installed successfully - type 'leo filename.leo' to use it. prax at prax-MS-7327:~$ leo test.leo python: can't open file '/usr/lib/leo/leo.py': [Errno 2] No such file or directory What to do now? /Mikael -------------- next part -------------- An HTML attachment was scrubbed... URL: From ph.ton.sharma at gmail.com Tue Nov 16 01:52:02 2010 From: ph.ton.sharma at gmail.com (Ton) Date: Mon, 15 Nov 2010 22:52:02 -0800 (PST) Subject: Help: Guide needed in trying to delete/flush the content of a fifo file. References: <1c7f7feb-ff95-404b-9628-458922360908@j12g2000prm.googlegroups.com> Message-ID: On Nov 16, 1:47?am, MRAB wrote: > On 15/11/2010 11:03, Ton wrote: > > > > > On Nov 14, 11:55 pm, MRAB ?wrote: > >> On 14/11/2010 14:48, ton ph wrote:> ?Hi python geeks, > >>> ? ? I have ?problem which i have been trying to find out for the past > >>> some days, i have a device which feeds info to my fifo continuosly, and > >>> a thread of mine reads the > >>> fifo continuosly. Now when i change a parameter in the device, it sends > >>> me different values. Now my problem is that , i want to get rid of the > >>> contents of my previous info which > >>> is present in my buffer of the fifo.So i want to flush the fifo content > >>> when my device starts sending different info .... i am implementing > >>> writing and reading the fifo ?using two different threads. > >>> Please someone guide me solving my problem. > >>> I highly apologise everyone in case my post is not so clear... > >>> Thanks everyone in advance. > > >> When the info changes, the thread which is putting items into the fifo > >> could flush it just by getting items from it (using a non-blocking get) > >> until it's empty. > > > Hi Mrab, > > ? Thanks for your immediate reply , can you please guide me with any > > tool or library function which i can flush my fifo content .. i use > > os.mkfifo() to make the fifo. Or is there any other way i could do > > this ... > > Thanks > > Ah, you're using pipes; I thought you might've been using a queue. I > don't know of a way of flushing a pipe. > > I wonder whether it's a good idea for the producer to keep filling the > fifo, because the consumer know how 'old' the info is when it arrives, > and there's your problem of discarding stale info. Perhaps the producer > should wait until the consumer has sent an acknowledgement before > sending more info. Thanks Mrab, the problem now is that the producer continously dumps the information and since i am implementing the producer using the subprocess as like this cmd = ['my files'] proc = subprocess.Popen(cmd, shell=True, bufsize=0, stdout=subprocess.PIPE, stderr=subprocess.STDOUT ) while flag == True: line = proc.stdout.read() Now what i want is to synchronise the problem of actual info the device is sending and the proper reading as the device is sending and not about reading the previous old info in the fifo... hope i have made clearer my prob. even i have tried proc.stdout.flush(), to flush the previous old info in the fifo. Thnks From hniksic at xemacs.org Tue Nov 16 04:03:44 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Tue, 16 Nov 2010 10:03:44 +0100 Subject: strange behavor.... References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> <87tyjlhu1l.fsf.mdw@metalzone.distorted.org.uk> <4cdf1206$0$29990$c3e8da3$5496439d@news.astraweb.com> <877hggiz17.fsf.mdw@metalzone.distorted.org.uk> <874obj1r0z.fsf@gmail.com> <87hbfihmlb.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <878w0t1vyn.fsf@xemacs.org> mdw at distorted.org.uk (Mark Wooding) writes: >> So even if the globals() dictionary is custom, its __setitem__ method is >> *not* called. > > Fascinating. Thank you. In case it's not obvious, that is because CPython assumes the type for many of its internal or semi-internal structures, and calls the appropriate functions, such as dict.__setitem__ (PyDict_SetItem in C) directly. So python doesn't break the encapsulation of dict itself, it just takes the liberty to assume that globals() is a non-subclassed dict, at least as far as __setitem__ is concerned. From steve at REMOVE-THIS-cybersource.com.au Tue Nov 16 05:42:39 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 16 Nov 2010 10:42:39 GMT Subject: Some syntactic sugar proposals References: <4ce215f0$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4ce2601e$0$30001$c3e8da3$5496439d@news.astraweb.com> On Mon, 15 Nov 2010 22:40:00 -0700, Ian Kelly wrote: > On 11/15/2010 10:26 PM, Steven D'Aprano wrote: >> t = foo()+bar()+baz() if pred(it) else baz()-foo()-bar() >> >> What does "it" mean here? > > "it" would mean the result of the expression foo()+bar()+baz(). What > else could it mean? It could mean the last expression, baz(). Or the entire compound expression, foo()+bar()+baz(). > There are valid objections to the proposal, but the > intended semantics seem perfectly clear. Fair point, my example was terrible and didn't show the point that was clear in my head. Mea culpa. How about this instead? t = foo()+it if pred(it) else bar() Should that be a SyntaxError, or is `it` a variable that holds its value from statement to statement? t = it t = (foo() if pred(it) else bar()) if cond(it) else baz() For what it's worth, Apple's defunct Hypertalk language had a couple of syntax elements very much like that. Hypertalk had a special variable, "it", which you used like this: get the number of cards put it into field "Card number" I trust I don't have to explain this? :) Hypertalk also had a special function, "the result", which worked something like this: ask "This is a dialog box. Please type your answer here:" put the result into field "Your answer" (or you could use "result()" instead). Both of these worked quite well with Hypertalk, particularly with it's focus on non-programmers, but they were designed into the language from the beginning. In Python they would be the proverbial round peg in a square hole. BTW, I frequently use "it" for iterators, and making "it" a reserved word would break a lot of my code. This would make me quite peeved. -- Steven From artur.siekielski at gmail.com Tue Nov 16 06:44:14 2010 From: artur.siekielski at gmail.com (Artur Siekielski) Date: Tue, 16 Nov 2010 03:44:14 -0800 (PST) Subject: Getting references to objects without incrementing reference counters References: <8c98a453-3303-4509-be39-1a26084f573a@o11g2000prf.googlegroups.com> <4ce1a0f5$0$1633$742ec2ed@news.sonic.net> Message-ID: On Nov 15, 10:06?pm, John Nagle wrote: > On 11/14/2010 11:08 AM, Artur Siekielski wrote: > > > Hi. > > I'm using CPython 2.7 and Linux. In order to make parallel > > computations on a large list of objects I want to use multiple > > processes (by using multiprocessing module). In the first step I fill > > the list with objects and then I fork() my worker processes that do > > the job. > > > This should work optimally in the aspect of memory usage because Linux > > implements copy-on-write in forked processes. > > ? ? There used to be a memory leak when using Pickle to talk > to subprocesses. ?See what I wrote at It's something different - I'm not using serialization at all - I have full Python objects "copied" into child processes :). From georg at python.org Tue Nov 16 09:05:51 2010 From: georg at python.org (Georg Brandl) Date: Tue, 16 Nov 2010 15:05:51 +0100 Subject: [RELEASED] Python 3.2 alpha 4 Message-ID: <4CE28FBF.9020200@python.org> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On behalf of the Python development team, I'm happy to announce the fourth and (this time really) final alpha preview release of Python 3.2. Python 3.2 is a continuation of the efforts to improve and stabilize the Python 3.x line. Since the final release of Python 2.7, the 2.x line will only receive bugfixes, and new features are developed for 3.x only. Since PEP 3003, the Moratorium on Language Changes, is in effect, there are no changes in Python's syntax and built-in types in Python 3.2. Development efforts concentrated on the standard library and support for porting code to Python 3. Highlights are: * numerous improvements to the unittest module * PEP 3147, support for .pyc repository directories * PEP 3149, support for version tagged dynamic libraries * an overhauled GIL implementation that reduces contention * many consistency and behavior fixes for numeric operations * countless fixes regarding string/unicode issues; among them full support for a bytes environment (filenames, environment variables) * a sysconfig module to access configuration information * a pure-Python implementation of the datetime module * additions to the shutil module, among them archive file support * improvements to pdb, the Python debugger For an extensive list of changes in 3.2, see Misc/NEWS in the Python distribution. To download Python 3.2 visit: http://www.python.org/download/releases/3.2/ 3.2 documentation can be found at: http://docs.python.org/3.2/ Please consider trying Python 3.2 with your code and reporting any bugs you may notice to: http://bugs.python.org/ Enjoy! - -- Georg Brandl, Release Manager georg at python.org (on behalf of the entire python-dev team and 3.2's contributors) -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.16 (GNU/Linux) iEYEARECAAYFAkzij74ACgkQN9GcIYhpnLCbtwCgi4whRruM0Oi6yfgjVclYErFa OJcAn0U8UBBsQBFyGcnKJRbls6B+guQ2 =Vuqf -----END PGP SIGNATURE----- From arnodel at gmail.com Tue Nov 16 09:12:52 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Tue, 16 Nov 2010 14:12:52 +0000 Subject: strange behavor.... References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> <87tyjlhu1l.fsf.mdw@metalzone.distorted.org.uk> <4cdf1206$0$29990$c3e8da3$5496439d@news.astraweb.com> <877hggiz17.fsf.mdw@metalzone.distorted.org.uk> <874obj1r0z.fsf@gmail.com> <87hbfihmlb.fsf.mdw@metalzone.distorted.org.uk> <878w0t1vyn.fsf@xemacs.org> Message-ID: <87tyjhxspn.fsf@gmail.com> Hrvoje Niksic writes: > mdw at distorted.org.uk (Mark Wooding) writes: > >>> So even if the globals() dictionary is custom, its __setitem__ method is >>> *not* called. >> >> Fascinating. Thank you. > > In case it's not obvious, that is because CPython assumes the type for > many of its internal or semi-internal structures, and calls the > appropriate functions, such as dict.__setitem__ (PyDict_SetItem in C) > directly. So python doesn't break the encapsulation of dict itself, it > just takes the liberty to assume that globals() is a non-subclassed > dict, at least as far as __setitem__ is concerned. But it doesn't make this assumption for locals(). -- Arnaud From steve at holdenweb.com Tue Nov 16 09:29:06 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 16 Nov 2010 09:29:06 -0500 Subject: strange behavor.... In-Reply-To: <87tyjhxspn.fsf@gmail.com> References: <4cde96b5$0$13468$4fafbaef@reader2.news.tin.it> <8739r5jig0.fsf.mdw@metalzone.distorted.org.uk> <87tyjlhu1l.fsf.mdw@metalzone.distorted.org.uk> <4cdf1206$0$29990$c3e8da3$5496439d@news.astraweb.com> <877hggiz17.fsf.mdw@metalzone.distorted.org.uk> <874obj1r0z.fsf@gmail.com> <87hbfihmlb.fsf.mdw@metalzone.distorted.org.uk> <878w0t1vyn.fsf@xemacs.org> <87tyjhxspn.fsf@gmail.com> Message-ID: On 11/16/2010 9:12 AM, Arnaud Delobelle wrote: > Hrvoje Niksic writes: > >> mdw at distorted.org.uk (Mark Wooding) writes: >> >>>> So even if the globals() dictionary is custom, its __setitem__ method is >>>> *not* called. >>> >>> Fascinating. Thank you. >> >> In case it's not obvious, that is because CPython assumes the type for >> many of its internal or semi-internal structures, and calls the >> appropriate functions, such as dict.__setitem__ (PyDict_SetItem in C) >> directly. So python doesn't break the encapsulation of dict itself, it >> just takes the liberty to assume that globals() is a non-subclassed >> dict, at least as far as __setitem__ is concerned. > > But it doesn't make this assumption for locals(). > That's because it reserves the right to optimize local storage without extending the mapping to allowing item setting. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From ian.g.kelly at gmail.com Tue Nov 16 11:16:52 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 16 Nov 2010 09:16:52 -0700 Subject: Some syntactic sugar proposals In-Reply-To: <4ce2601e$0$30001$c3e8da3$5496439d@news.astraweb.com> References: <4ce215f0$0$29983$c3e8da3$5496439d@news.astraweb.com> <4ce2601e$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 11/16/2010 3:42 AM, Steven D'Aprano wrote: > On Mon, 15 Nov 2010 22:40:00 -0700, Ian Kelly wrote: > >> On 11/15/2010 10:26 PM, Steven D'Aprano wrote: >>> t = foo()+bar()+baz() if pred(it) else baz()-foo()-bar() >>> >>> What does "it" mean here? >> >> "it" would mean the result of the expression foo()+bar()+baz(). What >> else could it mean? > > It could mean the last expression, baz(). Or the entire compound > expression, foo()+bar()+baz(). Unless the precedence rules were to change, the three expressions in the example that are operated on by the ternary are these: 1. foo()+bar()+baz() 2. pred(it) 3. baz()-foo()-bar() So the antecedent would have to be one of those in order to make any sense at all, and obviously the only choice of those that would be useful is the first one. >> There are valid objections to the proposal, but the >> intended semantics seem perfectly clear. > > Fair point, my example was terrible and didn't show the point that was > clear in my head. Mea culpa. How about this instead? > > t = foo()+it if pred(it) else bar() > > Should that be a SyntaxError, or is `it` a variable that holds its value > from statement to statement? SyntaxError. Implementing this without making 'it' a keyword would be very sloppy, IMO. Another option would be to use a special variable named '__', similar to the variable '_' that the REPL uses to store the result of the last command. This might break some existing code, but probably not very much. Mostly it would just be confusing. > t = (foo() if pred(it) else bar()) if cond(it) else baz() More problematic: t = foo() if pred(bar() if pred2(it) else str(it)) else bar() Does the first 'it' belong to the inner or outer ternary? Probably the inner one. What about the second 'it'? > BTW, I frequently use "it" for iterators, and making "it" a reserved word > would break a lot of my code. This would make me quite peeved. I do the same, and yes, it would make upgrading a real pain. Cheers, Ian From gelonida at gmail.com Tue Nov 16 11:39:05 2010 From: gelonida at gmail.com (gelonida) Date: Tue, 16 Nov 2010 08:39:05 -0800 (PST) Subject: first attempt with pybluez on XP fail Message-ID: <5bc1ca02-c2c0-432e-acaf-9da9fc99054b@v20g2000yqb.googlegroups.com> Hi, Wanted to write a first simple example with pybluez and offer a serial connection service with a given name. What I tried (being inspired by http://people.csail.mit.edu/albert/bluez-intro/x290.html ) is: server_sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM ) port = bluetooth.PORT_ANY # original example used get_available_port() # buy this seems obsolete server_sock.bind(("",port)) server_sock.listen(1) print "listening on port %d" % port loc_host, loc_port = server_sock.getsockname() print "HOST", loc_host, "PORT??", loc_port uuid = "1e0ca4ea-299d-4335-93eb-27fcfe7fa848" bluetooth.advertise_service( server_sock, "FooBar Service", uuid ) The error message, that I get is: listening on port 0 HOST XX:XX:XX:XX:XX:XX PORT?? 1 Traceback (most recent call last): File "XXX\bt_01.py", line 94, in cmd(args) File "XXX\bt_01.py", line 71, in srvr srvr = BTSerService() File "XXX\bt_01.py", line 51, in __init__ bluetooth.advertise_service( server_sock, "FooBar Service", uuid ) File "C:\Python26\lib\site-packages\bluetooth\msbt.py", line 173, in advertise _service sock._sdp_handle = bt.set_service_raw (sock._raw_sdp_record, True) IOError: An invalid argument was supplied. What might I be doing wrong? I got rid of the obsolete get_available_port() and wonder what else might have changed? Thanks a lot for your help. From rde at audaxis.com Tue Nov 16 11:47:21 2010 From: rde at audaxis.com (Romaric DEFAUX) Date: Tue, 16 Nov 2010 17:47:21 +0100 Subject: Pickle in a POST/GET request give EOFError Message-ID: <4CE2B599.7050504@audaxis.com> Hi everybody ! First time I write to this mailing list :) I started writing in python last week, that's probably why I can't understand the following problem... I create a list called web_site_list. This list contain dictionaries called web_site. And some values in this dictionaries are list too. I do that in a function and I return this : return pickle.dumps(web_site_list) This is working fine :) If I do : print "%s" % pickle.loads(system.get_web_site_list()) I've got the right stuffs. For example it returns : [{'documentroot_size': '120', 'servername': '---default---', 'client': 'undefined', 'documentroot': '/var/www/', 'client_contact': 'undefined', 'serveralias': []}] I send this to a web service. I send it like that : #I put it in params def system_updateweb_site(server, login, password): params = {} params['login'] = login params['password'] = password params['action'] = 'updateweb_site' params['servername'] = get_servername() params['hosted_web_site'] = get_web_site_list() return call_system_ws(server, params) #Here's how I send it (I tried in GET and POST) def call_system_ws(host, params): query_string = urllib.urlencode(params) #GET # f = urllib.urlopen("http://%s/ws?%s" % (host, query_string)) #POST f = urllib.urlopen("http://%s/ws" % (host), query_string) result = f.readline().strip() if result == 'ERROR': msg = f.readline().strip() return (False, msg) return (True, result) On the server side : if action == 'updateweb_site': if not (fields.has_key('servername') and fields.has_key('hosted_web_site')): raise WSError('missing parameter : servername or hosted_web_site') log ('ERROR : missing parameter : servername or hosted_web_site') else: servername=g.db.escape_string(fields['servername']) hosted_web_site=g.db.escape_string(fields['hosted_web_site']) output = systemserver.updateweb_site(cursor, servername, hosted_web_site) In systemserver.py : def updateweb_site(cursor, host, hosted_web_site): web_site_list = pickle.loads(hosted_web_site) return "%s" % (web_site_list) I catch this error :* *: args = () message = '' Why ? If I just print hosted_web_site, I get this on my web page : (lp0\n(dp1\nS\'documentroot_size\'\np2\nS\'120\'\np3\nsS\'servername\'\np4\nS\'default\'\np5\nsS\'client\'\np6\nS\'undefined\'\np7\nsS\'documentroot\'\np8\nS\'/var/www/\'\np9\nsS\'client_contact\'\np10\ng7\nsS\'serveralias\'\np11\n(lp12\nsa. It's the "pickled view" of [{'documentroot_size': '120', 'servername': '---default---', 'client': 'undefined', 'documentroot': '/var/www/', 'client_contact': 'undefined', 'serveralias': []}] Can someone help me please ? I spend my afternoon to google to try to find a solution... Thanks in advance !!! Romaric Defaux -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 5361 bytes Desc: S/MIME Cryptographic Signature URL: From list at qtrac.plus.com Tue Nov 16 12:23:51 2010 From: list at qtrac.plus.com (Mark Summerfield) Date: Tue, 16 Nov 2010 17:23:51 +0000 Subject: [Python-Dev] [RELEASED] Python 3.2 alpha 3 In-Reply-To: <4CB45754.10600@python.org> References: <4CB45754.10600@python.org> Message-ID: <20101116172351.38238f15@dino> Hi Georg, On Tue, 12 Oct 2010 14:40:52 +0200 Georg Brandl wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On behalf of the Python development team, I'm happy to announce the > third and final alpha preview release of Python 3.2. [snip] I built & ran Py3.2a4's tests & they were fine for me on Debian testing 64-bit. I also tested all the Python 3 book's examples and with one exception---due to (3) below---they all work fine:-) I think it might be worth mentioning in What's New: (1) In "Other Language Changes", the second item about str() might benefit from a note; perhaps: "This change may break doctests that compare floats. (For example, in older Python 3's str(math.pi) produces '3.14159265359'.) (2) In "New, Improved, and Deprecated Modules", it still has "XXX mention argparse". Maybe replace with: "A new option parsing module, argparse, has been added. This module is more flexible and pragmatic than the deprecated optparse module it supercedes." After all, the module's own documentation is sufficient for the details and "argparse" is a link to it. (3) There is no mention of a subtle change in ElementTree. In older Python 3's xml.etree.ElementTree.parse() would raise an xml.parsers.expat.ExpatError if the parse failed; in 3.2a4 it seems to raise xml.etree.ElementTree.ParseError instead. This is much nicer but could probably do with a mention since it can break things (with an "During handling of the above exception, another exception occurred" error). Perhaps in the "New, Improved, and Deprecated Modules" you might add: "The xml.etree.ElementTree now raises an xml.etree.ElementTree.ParseError when a parse fails; previously it raised a xml.parsers.expat.ExpatError." It would also be nice to mention this in the ElementTree module's documentation for the parse() function. -- Mark Summerfield, Qtrac Ltd, www.qtrac.eu C++, Python, Qt, PyQt - training and consultancy "Programming in Python 3" - ISBN 0321680561 http://www.qtrac.eu/py3book.html From tim.arnold at sas.com Tue Nov 16 12:37:37 2010 From: tim.arnold at sas.com (Tim Arnold) Date: Tue, 16 Nov 2010 12:37:37 -0500 Subject: remote server and effective uid References: Message-ID: "Tim Harig" wrote in message news:ibs8h9$jmq$1 at speranza.aioe.org... > On 2010-11-15, Tim Arnold wrote: >> On Nov 15, 10:41 am, Tim Harig wrote: >>> On 2010-11-15, Tim Arnold wrote: >>> >>> > How can I enable the server process to write into the client's >>> > directories? >>> > If I change the inetd service to run as 'root', I guess that would >>> > work, but then the client couldn't remove the files put there after >>> > the request. >>> >>> Python provides os.setuid() and os.seteuid() which wrap the system >>> functions. See you systems man pages for these functions for more >>> information. >> >> Thanks -- that was a lot easier than I thought it was going to be. >> pass the client's uid in the message to the server like so >> >> argstring, local_dir, uid = message.split(':') >> os.seteuid(int(uid)) > > I am not sure exactly what you are doing; but, I would advise great > caution as messing this up could easily open your system to exploitation. > Be very sure that you know what you are doing. I can see how that looks dangerous, but I think it's okay. I have inetd listening on a port and whatever it receives, it passes on to that line above "argstring, local_dir, uid message.split(':'). The argstring is parsed using 'argparse' the resulting list of args is passed to a Python class that can only do work for a specific set of args. I can't think of a way someone could pass in an evil argstring that could do anything but fail. Thanks for your reply, and if you still think it's dangerous please let me know. --Tim From iamforufriends at gmail.com Tue Nov 16 13:26:52 2010 From: iamforufriends at gmail.com (real dating with hot girl) Date: Tue, 16 Nov 2010 10:26:52 -0800 (PST) Subject: ***REAL DATING WITH HOT REAL GIRL FOR FREE...*** Message-ID: ***REAL DATING WITH HOT REAL GIRL FOR FREE...*** http://is.gd/he5WZ OR http://x2c.eu/4z OR http://tinyurl.com/friend-4-fun1 From Marc-Andre.Belzile at autodesk.com Tue Nov 16 13:36:24 2010 From: Marc-Andre.Belzile at autodesk.com (Marc-Andre Belzile) Date: Tue, 16 Nov 2010 18:36:24 +0000 Subject: Python OGL package Message-ID: Hi list, could someone recommend a good python ogl package (open source is preferred) ? I found these ones so far: http://pyopengl.sourceforge.net/ http://wiki.wxpython.org/wxOGL thanks -mab -------------- next part -------------- An HTML attachment was scrubbed... URL: From andre.roberge at gmail.com Tue Nov 16 13:45:00 2010 From: andre.roberge at gmail.com (=?ISO-8859-1?Q?Andr=E9?=) Date: Tue, 16 Nov 2010 10:45:00 -0800 (PST) Subject: Some syntactic sugar proposals References: Message-ID: <2e60b1d0-d95e-47ad-b251-58a417931487@o2g2000vbh.googlegroups.com> On Nov 15, 2:39?am, Dmitry Groshev wrote: > Here are some proposals. They are quite useful at my opinion and I'm > interested for suggestions. It's all about some common patterns. > First of all: how many times do you write something like > ? ? t = foo() > ? ? t = t if pred(t) else default_value Never! [snip] > And the third. The more I use python the more I see how "natural" it > can be. By "natural" I mean the statements like this: > ? ? [x.strip() for x in reversed(foo)] > which looks almost like a natural language. But there is some > pitfalls: > ? ? if x in range(a, b): #wrong! This is true only if x is an integer such that a <= x < b > it feels so natural to check it that way, but we have to write > ? ? if a <= x <= b This is true if x is an integer OR a float. Two very different cases, deserving of different notation. Andr? From raymond.activestate at gmail.com Tue Nov 16 14:09:49 2010 From: raymond.activestate at gmail.com (Raymond Hettinger) Date: Tue, 16 Nov 2010 11:09:49 -0800 (PST) Subject: [RELEASED] Python 3.2 alpha 3 References: <4CB45754.10600@python.org> Message-ID: <1510ba5f-a2ff-422d-9a69-23c9ba523bcb@v12g2000vbh.googlegroups.com> On Nov 16, 9:23?am, Mark Summerfield wrote: > I think it might be worth mentioning in What's New: FWIW, I'll be updating the What's New document for the Beta. Raymond From python at mrabarnett.plus.com Tue Nov 16 14:13:23 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 16 Nov 2010 19:13:23 +0000 Subject: Help: Guide needed in trying to delete/flush the content of a fifo file. In-Reply-To: References: <1c7f7feb-ff95-404b-9628-458922360908@j12g2000prm.googlegroups.com> Message-ID: <4CE2D7D3.8040203@mrabarnett.plus.com> On 16/11/2010 06:52, Ton wrote: > On Nov 16, 1:47 am, MRAB wrote: >> On 15/11/2010 11:03, Ton wrote: >> >> >> >>> On Nov 14, 11:55 pm, MRAB wrote: >>>> On 14/11/2010 14:48, ton ph wrote:> Hi python geeks, >>>>> I have problem which i have been trying to find out for the past >>>>> some days, i have a device which feeds info to my fifo continuosly, and >>>>> a thread of mine reads the >>>>> fifo continuosly. Now when i change a parameter in the device, it sends >>>>> me different values. Now my problem is that , i want to get rid of the >>>>> contents of my previous info which >>>>> is present in my buffer of the fifo.So i want to flush the fifo content >>>>> when my device starts sending different info .... i am implementing >>>>> writing and reading the fifo using two different threads. >>>>> Please someone guide me solving my problem. >>>>> I highly apologise everyone in case my post is not so clear... >>>>> Thanks everyone in advance. >> >>>> When the info changes, the thread which is putting items into the fifo >>>> could flush it just by getting items from it (using a non-blocking get) >>>> until it's empty. >> >>> Hi Mrab, >>> Thanks for your immediate reply , can you please guide me with any >>> tool or library function which i can flush my fifo content .. i use >>> os.mkfifo() to make the fifo. Or is there any other way i could do >>> this ... >>> Thanks >> >> Ah, you're using pipes; I thought you might've been using a queue. I >> don't know of a way of flushing a pipe. >> >> I wonder whether it's a good idea for the producer to keep filling the >> fifo, because the consumer know how 'old' the info is when it arrives, >> and there's your problem of discarding stale info. Perhaps the producer >> should wait until the consumer has sent an acknowledgement before >> sending more info. > > Thanks Mrab, > the problem now is that the producer continously dumps the > information and since i am implementing the producer using the > subprocess as like this > > cmd = ['my files'] > proc = subprocess.Popen(cmd, shell=True, bufsize=0, > stdout=subprocess.PIPE, stderr=subprocess.STDOUT ) > > while flag == True: > line = proc.stdout.read() > > Now what i want is to synchronise the problem of actual info the > device is sending and the proper reading as the device is sending and > not about reading the previous old info in the fifo... hope i have > made clearer my prob. even i have tried proc.stdout.flush(), to flush > the previous old info in the fifo. Thnks Use two pipes, one each way. The consumer could use send a message to the producer requesting an update, which the producer could send back via the other pipe. From pecora at anvil.nrl.navy.mil Tue Nov 16 14:22:08 2010 From: pecora at anvil.nrl.navy.mil (Lou Pecora) Date: Tue, 16 Nov 2010 14:22:08 -0500 Subject: What was your strategy? References: <201011142240.oAEMecu2054270@krusty.intranet.com.mx> Message-ID: In article , Dennis Lee Bieber wrote: > On Sun, 14 Nov 2010 16:32:24 -0600, Jorge Biquez > declaimed the following in gmane.comp.python.general: > > > I was wondering if you can share what was the strategy you followed > > to master Python (Yes I know I have to work hard study and practice a > > lot). I mean did you use special books, special sites, a plan to > > I picked up the first edition "Programming Python" (and a now > forgotten competitor book) since the Amiga was mentioned... I'll jump in and recommend the book "Python in a Nutshell" by Martelli. It may be a little dated now, but it covers many Python topics in good detail without becoming a bloated reference. Nicely written. It's still the first book I reach for after 6 years of Python coding and it rarely disappoints. -- -- Lou Pecora From ndbecker2 at gmail.com Tue Nov 16 14:35:01 2010 From: ndbecker2 at gmail.com (Neal Becker) Date: Tue, 16 Nov 2010 14:35:01 -0500 Subject: argparse subparser problem Message-ID: I want to have subparsers, but I also want to be able to say: myprogram --version and get the version # --------------------------- import argparse def stop(): pass parser = argparse.ArgumentParser() parser.add_argument ('--version', action='store_true') subparsers = parser.add_subparsers() parser_stop = subparsers.add_parser ('stop') parser_stop.add_argument ('stop', action='store_true') parser_stop.set_defaults (func=stop) opt = parser.parse_args (['--version']) ------------------------------ python test_p1.py usage: test_p1.py [-h] [--version] {stop} ... test_p1.py: error: too few arguments From steve at holdenweb.com Tue Nov 16 14:37:16 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 16 Nov 2010 14:37:16 -0500 Subject: What was your strategy? In-Reply-To: References: <201011142240.oAEMecu2054270@krusty.intranet.com.mx> Message-ID: On 11/16/2010 2:22 PM, Lou Pecora wrote: > I'll jump in and recommend the book "Python in a Nutshell" by Martelli. > It may be a little dated now, but it covers many Python topics in good > detail without becoming a bloated reference. Nicely written. It's still > the first book I reach for after 6 years of Python coding and it rarely > disappoints. +1 It's encyclopedic. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From fuglyducky at gmail.com Tue Nov 16 15:00:12 2010 From: fuglyducky at gmail.com (fuglyducky) Date: Tue, 16 Nov 2010 12:00:12 -0800 (PST) Subject: SQLite3 and lastrowid Message-ID: <2d87112c-e776-41ea-838a-5e165e478052@e20g2000vbn.googlegroups.com> I am fairly new to Python (no development experience) and brand new to using sqlite through Python. With that said, I created a database with two tables. The first has about 30,000 rows of static data. The second has 9 rows of static data. Before I added the second table I could simply run 'print(cursor.lastrowid)' and it would give me the id number. However, with two tables I am unable to do this. Does anyone know if there is a way to reference one table or another to get lastrowid? Thanks!!! From gelonida at gmail.com Tue Nov 16 15:31:15 2010 From: gelonida at gmail.com (Gelonida) Date: Tue, 16 Nov 2010 21:31:15 +0100 Subject: first attempts with pybluez on Win XP fail Message-ID: Hi, My post from Google groups doesn't sem to get through. SO here once more posted from gmane. Wanted to write a first simple example with pybluez and offer a serial connection service with a given name. What I tried (being inspired by http://people.csail.mit.edu/albert/bluez-intro/x290.html ) is: server_sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM ) port = bluetooth.PORT_ANY # original example used get_available_port() # buy this seems obsolete server_sock.bind(("",port)) server_sock.listen(1) print "listening on port %d" % port loc_host, loc_port = server_sock.getsockname() print "HOST", loc_host, "PORT??", loc_port uuid = "1e0ca4ea-299d-4335-93eb-27fcfe7fa848" bluetooth.advertise_service( server_sock, "FooBar Service", uuid ) The error message, that I get is: listening on port 0 HOST XX:XX:XX:XX:XX:XX PORT?? 1 Traceback (most recent call last): File "XXX\bt_01.py", line 94, in cmd(args) File "XXX\bt_01.py", line 71, in srvr srvr = BTSerService() File "XXX\bt_01.py", line 51, in __init__ bluetooth.advertise_service( server_sock, "FooBar Service", uuid ) File "C:\Python26\lib\site-packages\bluetooth\msbt.py", line 173, in advertise _service sock._sdp_handle = bt.set_service_raw (sock._raw_sdp_record, True) IOError: An invalid argument was supplied. What might I be doing wrong? I got rid of the obsolete get_available_port() and wonder what else might have changed? Thanks a lot for your help. From hansyin at gmail.com Tue Nov 16 15:38:56 2010 From: hansyin at gmail.com (Hans) Date: Tue, 16 Nov 2010 12:38:56 -0800 (PST) Subject: how to use socket to get packet which destination ip is not local? Message-ID: <21df438f-9869-4818-bc59-752702e2a203@j1g2000vbl.googlegroups.com> Hi, Maybe it's a very simple question. I'm trying to write a dhcpclient code with python. The dhcpclient does not have ip address at the very beginning, it sends out dhcpdiscover and then server sends back dhcpoffer. the dhcpoffer will use assigned ip as destination ip, but that ip is not client's local ip yet. How can I make my socket to receive that packet? I tried socket bind to 0.0.0.0, but it only binds to any local ip, not any ip which may not be local. therefore the socket cannot get that dhcp offer packet even I can use wireshark to see that packet did come to this pc. How to solve it? Thanks in advance. Rgds, Hans From pedroigor91 at gmail.com Tue Nov 16 15:51:07 2010 From: pedroigor91 at gmail.com (pedro igor sampaio avelino) Date: Tue, 16 Nov 2010 12:51:07 -0800 (PST) Subject: Help in language development Message-ID: <6fb7a013-cee1-4c77-9b96-d5494a5dda98@j25g2000yqa.googlegroups.com> Hello, my name Pedro Igor, I am a student and develop applications in python for 1 year. I enrolled in the group to contribute in developing this wonderful language that helps me both in day-to-day, but I'm going through some difficulties because they do not know where to start, can someone please give me some steps so that I can contribute at once development for all, where do I start, if the documentation or a book. I know that most people have more important issues to address in other posts but assistance does not cost anything. Graciously From ian.g.kelly at gmail.com Tue Nov 16 15:54:37 2010 From: ian.g.kelly at gmail.com (Ian) Date: Tue, 16 Nov 2010 12:54:37 -0800 (PST) Subject: SQLite3 and lastrowid References: <2d87112c-e776-41ea-838a-5e165e478052@e20g2000vbn.googlegroups.com> Message-ID: <713377d1-b9e2-4da1-a56a-c4f042f6e3e4@g2g2000vbe.googlegroups.com> On Nov 16, 1:00?pm, fuglyducky wrote: > Before I added the second table I could simply run > 'print(cursor.lastrowid)' and it would give me the id number. However, > with two tables I am unable to do this. It would help if you would show the code where you're trying to do this. Without your actual code to look at, we can't tell you why it doesn't work. > Does anyone know if there is a way to reference one table or another > to get lastrowid? cursor.lastrowid is always in reference to the last query executed by the cursor, not in reference to a table. If you don't capture the value, and then you execute another query on the same cursor, the previous value of cursor.lastrowid no longer exists. If you need it now, then either you should have captured it when you had the chance, or you should not have executed another query on the same cursor. But perhaps this is not what you're actually trying to do. I can't tell, because I haven't seen the code. Cheers, Ian From m.g.bode at web.de Tue Nov 16 15:55:25 2010 From: m.g.bode at web.de (Michael Bode) Date: Tue, 16 Nov 2010 21:55:25 +0100 Subject: How to implement a callback COM object in Python Message-ID: Hi, I'm trying to write a COM client to a COM server which controls a power meter. The COM server fires events that should be handled by the client. The docs state that I have to supply a class which implements the IFM2DeviceEvents interface. I need some instructions on how to translate the VB sample code to Python: Option Explicit Implements IFM2DeviceEvents Private m_CallbackEvent As String Private m_CallbackMessage As String Private m_DeviceIndex As Integer Private m_SerialNumber As String Private m_ZeroDeviceTimeoutCounter As Integer ' Methods Private Sub IFM2DeviceEvents_DisplayErrorToClient() frmTest.DisplayErrorMessage m_CallbackMessage End Sub Private Sub IFM2DeviceEvents_NotifyData(ByVal CallbackData As IFM2DeviceEvents) frmTest.NotifyData CallbackData End Sub Private Sub IFM2DeviceEvents_NotifyDeviceStatus(ByVal CallbackData As IFM2DeviceEvents, ByVal DevicesList As cFM2Devices) frmTest.NotifyDeviceStatus CallbackData, DevicesList End Sub Private Sub IFM2DeviceEvents_DisplayZeroDeviceProgressToClient() frmTest.DisplayZeroDeviceProgress m_CallbackMessage, m_ZeroDeviceTimeoutCounter End Sub ' Read/write properties Private Property Let IFM2DeviceEvents_CallbackEvent(ByVal RHS As String) m_CallbackEvent = RHS End Property Private Property Get IFM2DeviceEvents_CallbackEvent() As String IFM2DeviceEvents_CallbackEvent = m_CallbackEvent End Property ... From python at mrabarnett.plus.com Tue Nov 16 15:57:55 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 16 Nov 2010 20:57:55 +0000 Subject: how to use socket to get packet which destination ip is not local? In-Reply-To: <21df438f-9869-4818-bc59-752702e2a203@j1g2000vbl.googlegroups.com> References: <21df438f-9869-4818-bc59-752702e2a203@j1g2000vbl.googlegroups.com> Message-ID: <4CE2F053.7010509@mrabarnett.plus.com> On 16/11/2010 20:38, Hans wrote: > Hi, > > Maybe it's a very simple question. I'm trying to write a dhcpclient > code with python. The dhcpclient does not have ip address at the very > beginning, it sends out dhcpdiscover and then server sends back > dhcpoffer. the dhcpoffer will use assigned ip as destination ip, but > that ip is not client's local ip yet. How can I make my socket to > receive that packet? > > I tried socket bind to 0.0.0.0, but it only binds to any local ip, not > any ip which may not be local. therefore the socket cannot get that > dhcp offer packet even I can use wireshark to see that packet did come > to this pc. > > How to solve it? Thanks in advance. > Have you read this: http://en.wikipedia.org/wiki/Dynamic_Host_Configuration_Protocol From felipe.bastosn at gmail.com Tue Nov 16 16:02:02 2010 From: felipe.bastosn at gmail.com (Felipe Bastos Nunes) Date: Tue, 16 Nov 2010 19:02:02 -0200 Subject: Help in language development In-Reply-To: <6fb7a013-cee1-4c77-9b96-d5494a5dda98@j25g2000yqa.googlegroups.com> References: <6fb7a013-cee1-4c77-9b96-d5494a5dda98@j25g2000yqa.googlegroups.com> Message-ID: [Portuguese talking, excuse me guys] Pedro, voc?s podem dar um olhada no bug tracking, e estudar os c?digos pra encontrar solu??es. 2010/11/16 pedro igor sampaio avelino > Hello, my name Pedro Igor, I am a student and develop applications in > python for 1 year. I enrolled in the group to contribute in developing > this wonderful language that helps me both in day-to-day, but I'm > going through some difficulties because they do not know where to > start, can someone please give me some steps so that I can contribute > at once development for all, where do I start, if the documentation or > a book. I know that most people have more important issues to address > in other posts but assistance does not cost anything. > > Graciously > -- > http://mail.python.org/mailman/listinfo/python-list > -- Felipe Bastos Nunes -------------- next part -------------- An HTML attachment was scrubbed... URL: From fuglyducky at gmail.com Tue Nov 16 16:08:15 2010 From: fuglyducky at gmail.com (fuglyducky) Date: Tue, 16 Nov 2010 13:08:15 -0800 (PST) Subject: SQLite3 and lastrowid References: <2d87112c-e776-41ea-838a-5e165e478052@e20g2000vbn.googlegroups.com> <713377d1-b9e2-4da1-a56a-c4f042f6e3e4@g2g2000vbe.googlegroups.com> Message-ID: On Nov 16, 12:54?pm, Ian wrote: > On Nov 16, 1:00?pm, fuglyducky wrote: > > > Before I added the second table I could simply run > > 'print(cursor.lastrowid)' and it would give me the id number. However, > > with two tables I am unable to do this. > > It would help if you would show the code where you're trying to do > this. ?Without your actual code to look at, we can't tell you why it > doesn't work. > > > Does anyone know if there is a way to reference one table or another > > to get lastrowid? > > cursor.lastrowid is always in reference to the last query executed by > the cursor, not in reference to a table. ?If you don't capture the > value, and then you execute another query on the same cursor, the > previous value of cursor.lastrowid no longer exists. ?If you need it > now, then either you should have captured it when you had the chance, > or you should not have executed another query on the same cursor. > > But perhaps this is not what you're actually trying to do. ?I can't > tell, because I haven't seen the code. > > Cheers, > Ian Thanks for the input. Sorry...I should have included the code...it's just a simple query... ##################################################### import sqlite3 import random db_connect = sqlite3.connect('test.db') cursor = db_connect.cursor() print(cursor.lastrowid) # Choose random index from DB - need to understand lastrowid #row_count = cursor.lastrowid #random_row = random.randrange(0, row_count) cursor.execute("SELECT * FROM table1 WHERE id = 2002") print(cursor.fetchmany()) #for row in cursor: # print(row) db_connect.commit() cursor.close() ##################################################### From dan at catfolks.net Tue Nov 16 16:12:14 2010 From: dan at catfolks.net (Dan M) Date: Tue, 16 Nov 2010 15:12:14 -0600 Subject: SQLite3 and lastrowid References: <2d87112c-e776-41ea-838a-5e165e478052@e20g2000vbn.googlegroups.com> <713377d1-b9e2-4da1-a56a-c4f042f6e3e4@g2g2000vbe.googlegroups.com> Message-ID: On Tue, 16 Nov 2010 13:08:15 -0800, fuglyducky wrote: > On Nov 16, 12:54?pm, Ian wrote: >> On Nov 16, 1:00?pm, fuglyducky wrote: >> >> > Before I added the second table I could simply run >> > 'print(cursor.lastrowid)' and it would give me the id number. >> > However, with two tables I am unable to do this. >> >> It would help if you would show the code where you're trying to do >> this. ?Without your actual code to look at, we can't tell you why it >> doesn't work. >> >> > Does anyone know if there is a way to reference one table or another >> > to get lastrowid? >> >> cursor.lastrowid is always in reference to the last query executed by >> the cursor, not in reference to a table. ?If you don't capture the >> value, and then you execute another query on the same cursor, the >> previous value of cursor.lastrowid no longer exists. ?If you need it >> now, then either you should have captured it when you had the chance, >> or you should not have executed another query on the same cursor. >> >> But perhaps this is not what you're actually trying to do. ?I can't >> tell, because I haven't seen the code. >> >> Cheers, >> Ian > > Thanks for the input. Sorry...I should have included the code...it's > just a simple query... > > ##################################################### > > import sqlite3 > import random > > db_connect = sqlite3.connect('test.db') cursor = db_connect.cursor() > > print(cursor.lastrowid) > > # Choose random index from DB - need to understand lastrowid #row_count > = cursor.lastrowid > #random_row = random.randrange(0, row_count) > > cursor.execute("SELECT * FROM table1 WHERE id = 2002") > print(cursor.fetchmany()) Perhaps insert here: cursor.execute("SELECT count() from table2") table2lastRow = cursor.lastrowid() > > #for row in cursor: > # print(row) > > > db_connect.commit() > cursor.close() > > ##################################################### From fred.sells at adventistcare.org Tue Nov 16 16:48:02 2010 From: fred.sells at adventistcare.org (Sells, Fred) Date: Tue, 16 Nov 2010 16:48:02 -0500 Subject: What was your strategy? In-Reply-To: <201011142240.oAEMecu2054270@krusty.intranet.com.mx> References: <201011142240.oAEMecu2054270@krusty.intranet.com.mx> Message-ID: It helps to try to solve a real (to you) problem, that way you discover what you don't know. If your code ends up nested 3 levels or your methods are more than 10 lines, ask for help. -----Original Message----- From: python-list-bounces+frsells=adventistcare.org at python.org [mailto:python-list-bounces+frsells=adventistcare.org at python.org] On Behalf Of Jorge Biquez Sent: Sunday, November 14, 2010 5:32 PM To: python-list at python.org Subject: What was your strategy? Hello all. Quick question. I know some of you are with Python since started, some other maybe later. I was wondering if you can share what was the strategy you followed to master Python (Yes I know I have to work hard study and practice a lot). I mean did you use special books, special sites, a plan to learn each subject in a special way. I would like to know, if possible, comments specially from some of you who in the past had other languages, frameworks and platforms and left (almost) all of them and stayed with Python. Thanks in advance Jorge Biquez -- http://mail.python.org/mailman/listinfo/python-list From ian.g.kelly at gmail.com Tue Nov 16 16:52:42 2010 From: ian.g.kelly at gmail.com (Ian) Date: Tue, 16 Nov 2010 13:52:42 -0800 (PST) Subject: SQLite3 and lastrowid References: <2d87112c-e776-41ea-838a-5e165e478052@e20g2000vbn.googlegroups.com> <713377d1-b9e2-4da1-a56a-c4f042f6e3e4@g2g2000vbe.googlegroups.com> Message-ID: <2ec7c0d8-4105-452d-88e3-01050c4c567f@v12g2000vbh.googlegroups.com> On Nov 16, 2:08?pm, fuglyducky wrote: > db_connect = sqlite3.connect('test.db') > cursor = db_connect.cursor() > > print(cursor.lastrowid) At this point you haven't executed a query yet, so there is no meaningful value that cursor.lastrowid can take. > # Choose random index from DB - need to understand lastrowid > #row_count = cursor.lastrowid > #random_row = random.randrange(0, row_count) This is wrong. The lastrowid is not the number of rows in the table. It's the row-id of the row that was inserted (if any) by the last query executed by the cursor. In the case of sqlite3, I think the row- id is just the primary key if it's an integer (but in general the row- id is database-dependent), so you *might* be able to get away with it if you always let it autoincrement when inserting, never delete any rows, and never change their primary keys. But it's unreliable and only available immediately after an insert, so don't do it that way. The proper way to get the number of rows is to use the COUNT aggregate function, e.g., "SELECT COUNT(*) FROM TABLE1", which will return a single row with a single column containing the number of rows in table1. Cheers, Ian From bostjan.mejak at gmail.com Tue Nov 16 16:56:05 2010 From: bostjan.mejak at gmail.com (=?UTF-8?Q?Bo=C5=A1tjan_Mejak?=) Date: Tue, 16 Nov 2010 22:56:05 +0100 Subject: Raw Unicode docstring Message-ID: Hello, how does one write a raw unicode docstring? If I have backslashes in the docstring, I must tuck an 'r' in front of it, like this: r"""This is a raw docstring.""" If I have foreign letters in the docstring, I must tuck a 'u' in front of it, like this: u"""This is a Unicode docstring.""" What if I have foreign characters *and* backslashes in my docstring? How to write the docstring then? ru"""My raw unicode docstring.""" or ur"""My unicode docstring.""" Please answer my question, although it may sound like a noobish one. Thanks. From contact at xavierho.com Tue Nov 16 17:02:59 2010 From: contact at xavierho.com (Xavier Ho) Date: Wed, 17 Nov 2010 08:02:59 +1000 Subject: Python OGL package In-Reply-To: References: Message-ID: Also try Pyglet, in combination of PyOpenGL. Cheers, Xav On 17 November 2010 04:36, Marc-Andre Belzile < Marc-Andre.Belzile at autodesk.com> wrote: > Hi list, > > > > could someone recommend a good python ogl package (open source is > preferred) ? I found these ones so far: > > > > http://pyopengl.sourceforge.net/ > > http://wiki.wxpython.org/wxOGL > > > > thanks > > > > -mab > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From aahz at pythoncraft.com Tue Nov 16 17:16:10 2010 From: aahz at pythoncraft.com (Aahz) Date: 16 Nov 2010 14:16:10 -0800 Subject: Komodo 6, why "Workspace Restore" after every restart? References: <4ce07839$0$17214$c3e8da3$eb767761@news.astraweb.com> <4ce0ea79$0$29271$c3e8da3$88b277c5@news.astraweb.com> <15016ae4-b341-4f4e-ac84-62fe7f93f217@g20g2000prg.googlegroups.com> <4ce0f788$0$30018$c3e8da3$76a7c58f@news.astraweb.com> Message-ID: [overquoting follows to prove my point] Someone who claims to care as much as you do about Usenet ought to have better quoting habits. You should be ashamed of yourself. In article <4ce0f788$0$30018$c3e8da3$76a7c58f at news.astraweb.com>, John Doe wrote: >alex23 wrote: > >> John Doe wrote: > >>> Google Groups spews a massive amount of sewage onto UseNet >>> everyday. Google Groups is your news server. You should be >>> ashamed >> >> Get over yourself. > >You too, and stop using the spammers den while you are at it. >-- > > > > > > > > > > > > > > > > >See also googled groups >> Path: news.astraweb.com!border5.newsrouter.astraweb.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!postnews.google.com!g20g2000prg.googlegroups.com!not-for-mail >> From: alex23 >> Newsgroups: comp.lang.python >> Subject: Re: Komodo 6, why "Workspace Restore" after every restart? >> Date: Mon, 15 Nov 2010 00:42:36 -0800 (PST) >> Organization: http://groups.google.com >> Lines: 6 >> Message-ID: <15016ae4-b341-4f4e-ac84-62fe7f93f217 g20g2000prg.googlegroups.com> >> References: <4ce07839$0$17214$c3e8da3$eb767761 news.astraweb.com> <428b98ca-72bf-4e3b-ad8a-dafe2fc4d553 v28g2000prn.googlegroups.com> <4ce0c065$0$23246$c3e8da3$a9097924 news.astraweb.com> <6ae54329-c652-4a59-b0e2-4c2038f58d5a x4g2000pre.googlegroups.com> <4ce0ea79$0$29271$c3e8da3$88b277c5 news.astraweb.com> >> NNTP-Posting-Host: 115.64.196.128 >> Mime-Version: 1.0 >> Content-Type: text/plain; charset=ISO-8859-1 >> X-Trace: posting.google.com 1289810556 23916 127.0.0.1 (15 Nov 2010 08:42:36 GMT) >> X-Complaints-To: groups-abuse google.com >> NNTP-Posting-Date: Mon, 15 Nov 2010 08:42:36 +0000 (UTC) >> Complaints-To: groups-abuse google.com >> Injection-Info: g20g2000prg.googlegroups.com; posting-host=115.64.196.128; posting-account=rYyWJQoAAACVJO77HvcyJfa3TnGYCqK_ >> User-Agent: G2/1.0 >> X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.12 (KHTML, like Gecko) Chrome/9.0.576.0 Safari/534.12,gzip(gfe) >> -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Look, it's your affair if you want to play with five people, but don't go calling it doubles." --John Cleese anticipates Usenet From python at mrabarnett.plus.com Tue Nov 16 17:22:40 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 16 Nov 2010 22:22:40 +0000 Subject: Raw Unicode docstring In-Reply-To: References: Message-ID: <4CE30430.3020909@mrabarnett.plus.com> On 16/11/2010 21:56, Bo?tjan Mejak wrote: > Hello, > > how does one write a raw unicode docstring? If I have backslashes in > the docstring, I must tuck an 'r' in front of it, like this: > r"""This is a raw docstring.""" > > If I have foreign letters in the docstring, I must tuck a 'u' in front > of it, like this: > u"""This is a Unicode docstring.""" > > What if I have foreign characters *and* backslashes in my docstring? > How to write the docstring then? > ru"""My raw unicode docstring.""" > or > ur"""My unicode docstring.""" > > Please answer my question, although it may sound like a noobish one. Thanks. Why not try them both and see what happens? From robert.kern at gmail.com Tue Nov 16 17:26:18 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 16 Nov 2010 16:26:18 -0600 Subject: Raw Unicode docstring In-Reply-To: References: Message-ID: On 11/16/10 3:56 PM, Bo?tjan Mejak wrote: > Hello, > > how does one write a raw unicode docstring? If I have backslashes in > the docstring, I must tuck an 'r' in front of it, like this: > r"""This is a raw docstring.""" > > If I have foreign letters in the docstring, I must tuck a 'u' in front > of it, like this: > u"""This is a Unicode docstring.""" > > What if I have foreign characters *and* backslashes in my docstring? I would just use a double-backslash u'\\' for each backslash that is supposed to be in the actual string. -- 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 lorena.aspiroz at gmail.com Tue Nov 16 17:30:58 2010 From: lorena.aspiroz at gmail.com (laspi) Date: Tue, 16 Nov 2010 14:30:58 -0800 (PST) Subject: Is Unladen Swallow dead? Message-ID: <2e1a4d02-1e8a-4d31-95da-f33aaf90578c@30g2000yql.googlegroups.com> There has been little or no activity at all in this project in the last months, and the last comments on their mailing list seem to conrfim that it's future is uncertain. It's also very strange the lack of updates, news or discussions, specially considering that the merging plan has been approved. Or it hasn't? From ladasky at my-deja.com Tue Nov 16 17:32:19 2010 From: ladasky at my-deja.com (John Ladasky) Date: Tue, 16 Nov 2010 14:32:19 -0800 (PST) Subject: Some syntactic sugar proposals References: <4ac1734d-fffb-4fdc-be42-27812a174b97@i32g2000pri.googlegroups.com> Message-ID: <3a859762-8123-44f9-8ce8-0997746de19e@o34g2000vbi.googlegroups.com> On Nov 14, 11:30?pm, alex23 wrote: > On Nov 15, 4:39?pm, Dmitry Groshev wrote: > > > ? ? if x in range(a, b): #wrong! > > Only in Python 3.x, it's perfectly valid in Python 2.x. To achieve the > same in Python 3.x, try: > > ? ? if x in list(range(a, b,)): # BUT SEE MY COMMENT BELOW > > > it feels so natural to check it that way, but we have to write > > ? ? if a <= x <= b > > I understand that it's not a big deal, but it would be awesome to have > > some optimisations - it's clearly possible to detect things like that > > "wrong" one and fix it in a bytecode. > > This seems more like a pessimisation to me: your range version > constructs a list just to do a single container check. That's a _lot_ > more cumbersome than two simple comparisons chained together. Also: testing for the membership of x in a set is NOT the same thing as testing using inequality operators. The inequality operators will return True for any FLOATING-POINT value within the range (a...b), but the set test will only return True for set members. From tjreedy at udel.edu Tue Nov 16 17:33:14 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 16 Nov 2010 17:33:14 -0500 Subject: Raw Unicode docstring In-Reply-To: References: Message-ID: On 11/16/2010 4:56 PM, Bo?tjan Mejak wrote: > Hello, > > how does one write a raw unicode docstring? If I have backslashes in > the docstring, I must tuck an 'r' in front of it, like this: > r"""This is a raw docstring.""" You only need (and want that) if you want '\' to be taken literally. And even if you do, '\\' will put one '\' in the string, so raw mode is never needed; it is only a convenience when one needs lots of literal backslashes. > If I have foreign letters in the docstring, I must tuck a 'u' in front > of it, like this: > u"""This is a Unicode docstring.""" > > What if I have foreign characters *and* backslashes in my docstring? > How to write the docstring then? > ru"""My raw unicode docstring.""" > or > ur"""My unicode docstring.""" > > Please answer my question, although it may sound like a noobish one. Thanks. You could look in the manual, which has been improved in this regard for 2.7.1. Or you could try both and see which gives a syntax error ;=). That would have been faster than posting this. -- Terry Jan Reedy From alex.kapps at web.de Tue Nov 16 17:34:09 2010 From: alex.kapps at web.de (Alexander Kapps) Date: Tue, 16 Nov 2010 23:34:09 +0100 Subject: Raw Unicode docstring In-Reply-To: References: Message-ID: <4CE306E1.7050000@web.de> On 16.11.2010 22:56, Bo?tjan Mejak wrote: > Hello, > > how does one write a raw unicode docstring? If I have backslashes in > the docstring, I must tuck an 'r' in front of it, like this: > r"""This is a raw docstring.""" > > If I have foreign letters in the docstring, I must tuck a 'u' in front > of it, like this: > u"""This is a Unicode docstring.""" > > What if I have foreign characters *and* backslashes in my docstring? > How to write the docstring then? > ru"""My raw unicode docstring.""" > or > ur"""My unicode docstring.""" > > Please answer my question, although it may sound like a noobish one. Thanks. One of Python's main strength is it's brilliant interactive mode, where you can easily try things out (Hint: Try ipython for an even better interactive experience) 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. >>> ru"Schei?t\nderB?r\nim Wald?" File "", line 1 ru"Schei?t\nderB?r\nim Wald?" ^ SyntaxError: invalid syntax >>> ur"Schei?t\nderB?r\nim Wald?" u'Schei\xdft\\nderB\xe4r\\nim Wald?' >>> Looks like ur"" works fine. From drsalists at gmail.com Tue Nov 16 18:40:50 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 16 Nov 2010 15:40:50 -0800 Subject: Is Unladen Swallow dead? In-Reply-To: <2e1a4d02-1e8a-4d31-95da-f33aaf90578c@30g2000yql.googlegroups.com> References: <2e1a4d02-1e8a-4d31-95da-f33aaf90578c@30g2000yql.googlegroups.com> Message-ID: I'm not a contributor to the U-S project, but I have been monitoring alternative python implementations' progress some, and seem to be adding something to pypy all of a sudden. I think unladen swallow has produced performance improvements, and they are likely to be merged into cpython 3.3. However, the improvements are not quite as substantial as were hoped for, and pypy seems to be getting some steam behind it. With pypy looking likely to even be able to provide source-level compatibility with C extension modules, the need for unladen swallow is perhaps somewhat lessened. At the outset, the U-S people looked at pypy and got the impression it was years from being a fast alternative to cpython for production code, but it sounds like pypy's coming along nicely now. Then again, the pypy people don't seem to feel that C extensions are going to perform that well in pypy (it sounds like an issue of initialization overhead and infeasibility of JIT compiling C extensions). I've been testing some of my own code in cpython 2.6, cpython 3.1 and pypy 1.3; with this specific program pypy seems to be about 4x faster than cpython 2.6, and almost that much faster than cpython 3.1 (I have the same - albeit unfinished - code running on all 3). This code is I/O intensive and somewhat math-intensive. On Tue, Nov 16, 2010 at 2:30 PM, laspi wrote: > There has been little or no activity at all in this project in the > last months, and the last comments on their mailing list seem to > conrfim that it's future is uncertain. > It's also very strange the lack of updates, news or discussions, > specially considering that the merging plan has been approved. Or it > hasn't? > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From fuglyducky at gmail.com Tue Nov 16 18:48:33 2010 From: fuglyducky at gmail.com (fuglyducky) Date: Tue, 16 Nov 2010 15:48:33 -0800 (PST) Subject: SQLite3 and lastrowid References: <2d87112c-e776-41ea-838a-5e165e478052@e20g2000vbn.googlegroups.com> <713377d1-b9e2-4da1-a56a-c4f042f6e3e4@g2g2000vbe.googlegroups.com> <2ec7c0d8-4105-452d-88e3-01050c4c567f@v12g2000vbh.googlegroups.com> Message-ID: <3c741e3a-ba55-4401-9cf0-9fc1e730dc4e@g2g2000vbe.googlegroups.com> On Nov 16, 1:52?pm, Ian wrote: > On Nov 16, 2:08?pm, fuglyducky wrote: > > > db_connect = sqlite3.connect('test.db') > > cursor = db_connect.cursor() > > > print(cursor.lastrowid) > > At this point you haven't executed a query yet, so there is no > meaningful value that cursor.lastrowid can take. > > > # Choose random index from DB - need to understand lastrowid > > #row_count = cursor.lastrowid > > #random_row = random.randrange(0, row_count) > > This is wrong. ?The lastrowid is not the number of rows in the table. > It's the row-id of the row that was inserted (if any) by the last > query executed by the cursor. ?In the case of sqlite3, I think the row- > id is just the primary key if it's an integer (but in general the row- > id is database-dependent), so you *might* be able to get away with it > if you always let it autoincrement when inserting, never delete any > rows, and never change their primary keys. ?But it's unreliable and > only available immediately after an insert, so don't do it that way. > > The proper way to get the number of rows is to use the COUNT aggregate > function, e.g., "SELECT COUNT(*) FROM TABLE1", which will return a > single row with a single column containing the number of rows in > table1. > > Cheers, > Ian Ahhh...great...thanks for the info! I'll do the row count then!!! From research at johnohagan.com Tue Nov 16 19:33:19 2010 From: research at johnohagan.com (John O'Hagan) Date: Wed, 17 Nov 2010 00:33:19 +0000 Subject: argparse subparser problem In-Reply-To: References: Message-ID: <201011170033.20177.research@johnohagan.com> On Tue, 16 Nov 2010, Neal Becker wrote: > I want to have subparsers, but I also want to be able to say: > > myprogram --version > and get the version # > > --------------------------- [...] AFAIK, it is not possible ATM to have optional subparsers with argparse: http://code.google.com/p/argparse/issues/detail?id=47 To do something like what you want, I've done my own pre-parsing of the command-line to separate out sub-options, and then sent them to multiple separate top-level ArgumentParser instances. Regards, john From bill at kingofmarketing.net Tue Nov 16 19:45:26 2010 From: bill at kingofmarketing.net (Bill Fishbaugher) Date: Tue, 16 Nov 2010 18:45:26 -0600 Subject: I have a question about JavaFit Message-ID: Hello, I was searching online to find more info about JavaFit and I came across your information. Can you tell me, are you still involved with JavaFit? If you are, how are things going for you? Please let me know. Sincerely, Bill From deets at web.de Tue Nov 16 19:54:16 2010 From: deets at web.de (Diez B. Roggisch) Date: Wed, 17 Nov 2010 01:54:16 +0100 Subject: QT window closes immediately References: <141ef269-de70-4ce1-b4ff-bfb0f58ee9d2@k14g2000pre.googlegroups.com> Message-ID: Martin Caum writes: > I am attempting to open a window on mouse activity which works, but > the window fails to stay open. > I set it to terminate when the escape key is pressed even when the > program is not currently selected. This works fine. Originally I had > it create the window only with a right click, but when I noticed the > window closed immediately I set it to any mouse activity for easier > debugging. My script is as follows: > [code] > import pythoncom, pyHook > import sys > import win32api > from PyQt4 import QtGui, QtCore > > class WindowObject(QtGui.QWidget): > def __init__(self, parent=None): > QtGui.QWidget.__init__(self, parent) > self.setWindowTitle('Window') > self.resize(50, 250) > > def OnKeyboardEvent(event): > if event.KeyID == 27: > win32api.PostQuitMessage() > return 1 > > def OnMouseEvent(event): > x = event.Position[0] > y = event.Position[1] > createWindow(x, y) > return 1 > > def createWindow(x, y): > menu = WindowObject() > menu.move(x, y) > menu.show() > > hm = pyHook.HookManager() > hm.MouseAll = OnMouseEvent > hm.KeyDown = OnKeyboardEvent > hm.HookMouse() > hm.HookKeyboard() > > app = QtGui.QApplication(sys.argv) > pythoncom.PumpMessages()[/code] > I'm fairly certain that this is due to my lack of understanding in the > PumpMessages command and the HookManager. Any advice? 1) Keep a reference to your window-object. I can only guess (PyQt not being a regular topic when hacking for me.. .sadly), but GC can interfere with these kind of things. 2) what is the win32 stuff about? Qt should abstract from that. 3) if in doubt, as on the PyQt mailing list. Diez From news1234 at free.fr Tue Nov 16 20:19:53 2010 From: news1234 at free.fr (News123) Date: Wed, 17 Nov 2010 02:19:53 +0100 Subject: QT window closes immediately In-Reply-To: <141ef269-de70-4ce1-b4ff-bfb0f58ee9d2@k14g2000pre.googlegroups.com> References: <141ef269-de70-4ce1-b4ff-bfb0f58ee9d2@k14g2000pre.googlegroups.com> Message-ID: <4ce32db9$0$22875$426a74cc@news.free.fr> On 11/15/2010 02:04 AM, Martin Caum wrote: > I am attempting to open a window on mouse activity which works, but > the window fails to stay open. > I set it to terminate when the escape key is pressed even when the > program is not currently selected. This works fine. Originally I had > it create the window only with a right click, but when I noticed the > window closed immediately I set it to any mouse activity for easier > debugging. My script is as follows: > [code] > import pythoncom, pyHook > import sys > import win32api > from PyQt4 import QtGui, QtCore > > class WindowObject(QtGui.QWidget): > def __init__(self, parent=None): > QtGui.QWidget.__init__(self, parent) > self.setWindowTitle('Window') > self.resize(50, 250) > > def OnKeyboardEvent(event): > if event.KeyID == 27: > win32api.PostQuitMessage() > return 1 > > def OnMouseEvent(event): > x = event.Position[0] > y = event.Position[1] > createWindow(x, y) > return 1 > > def createWindow(x, y): > menu = WindowObject() > menu.move(x, y) > menu.show() > > hm = pyHook.HookManager() > hm.MouseAll = OnMouseEvent > hm.KeyDown = OnKeyboardEvent > hm.HookMouse() > hm.HookKeyboard() > > app = QtGui.QApplication(sys.argv) > pythoncom.PumpMessages()[/code] > I'm fairly certain that this is due to my lack of understanding in the > PumpMessages command and the HookManager. Any advice? Shouldn't every QT application have an event loop. I would have expecte a call to app._exec() as you need already pumpMessages() fro the COM interface, I assume you had to use the threading or multiprocessing module as well. From bnbowman at gmail.com Tue Nov 16 20:37:10 2010 From: bnbowman at gmail.com (Brett Bowman) Date: Tue, 16 Nov 2010 17:37:10 -0800 Subject: Cannot Remove File: Device or resource busy Message-ID: I'm spawning a subprocess to fix some formating errors with a library of PDFs with pdftk: try: sp = subprocess.Popen('pdftk.exe "%s" output %s' % (pdfFile, outputFile)) sp.wait() del sp except Exception, e: return "Unable to open file: %s with error: %s" % (pdfFile, str(e)) And then I test the result: try: pdf_handle = open(outputFile, "rb") pdf_pypdf = PdfFileReader(pdf_handle) del pdf_pypdf del pdf_handle except Exception, e: return "Unable to open file: %s with error: %s" % (outputFile, str(e)) Both of which appear to work. But when I try to delete the original pdfFile, I get an error message saying that the file is still in use. if I use: sp = subprocess.Popen('rm "%s"' % pdfFile) sp.wait() I get the message - the standard error message from rm and if I use: cwd = os.getcwd() os.remove(cwd + "\\" + pdfFile) I get "WindowsError: [Error 32]" saying much the same thing. What am I missing? Any suggestions would be appreciated. Details: Python 2.6 Windows XP Sincerely, Brett Bowman -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Tue Nov 16 21:25:34 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 17 Nov 2010 02:25:34 +0000 Subject: Cannot Remove File: Device or resource busy In-Reply-To: References: Message-ID: <4CE33D1E.2040108@mrabarnett.plus.com> On 17/11/2010 01:37, Brett Bowman wrote: > I'm spawning a subprocess to fix some formating errors with a library of > PDFs with pdftk: > try: > sp = subprocess.Popen('pdftk.exe "%s" output %s' % (pdfFile, > outputFile)) > sp.wait() > del sp > except Exception, e: > return "Unable to open file: %s with error: %s" % (pdfFile, str(e)) > > And then I test the result: > try: > pdf_handle = open(outputFile, "rb") > pdf_pypdf = PdfFileReader(pdf_handle) > del pdf_pypdf > del pdf_handle > except Exception, e: > return "Unable to open file: %s with error: %s" % (outputFile, > str(e)) > > Both of which appear to work. But when I try to delete the original > pdfFile, I get an error message saying that the file is still in use. > > if I use: > sp = subprocess.Popen('rm "%s"' % pdfFile) > sp.wait() > I get the message - the standard error message from rm > > and if I use: > cwd = os.getcwd() > os.remove(cwd + "\\" + pdfFile) > I get "WindowsError: [Error 32]" saying much the same thing. > > What am I missing? Any suggestions would be appreciated. > > Details: > Python 2.6 > Windows XP > Try Process Explorer, available from Microsoft at: http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx and use Find. That will tell you what has it open. From rbd at hawaii.edu Tue Nov 16 21:33:52 2010 From: rbd at hawaii.edu (Roger Davis) Date: Tue, 16 Nov 2010 18:33:52 -0800 (PST) Subject: strange subprocess behavior when calling ps Message-ID: <55f26d5c-aba9-4892-9e2c-1caa9988e7fe@v23g2000vbi.googlegroups.com> Hi all, I have encountered a strange problem with some code I am writing to search the system process list for certain running processes. I am using subprocess.Popen() to call '/bin/ps -e'. When I save my code to the file pid.py (whose first line is #!/usr/bin/python) and run it with the command % ./pid.py it works perfectly fine, retrieving lines from my pipe to the /bin/ps output which look exactly as if I had typed the command '/bin/ps -e' myself into a shell window. Here is a sample line from that output: 1891 ttys000 0:00.12 -tcsh Now for the weird part -- when I run this code using the command % python pid.py I get entirely different output. It only prints out a very few processes instead of the entire table, and each line also has lots of environment variable values displayed. Here is the line from that output which corresponds to the line immediately above: 1891 s000 S+ 0:00.12 -tcsh PATH=/usr/bin:/bin:/usr/sbin:/sbin TMPDIR=/var/folders/3e/3e-TyTQIG-aOa4x37pbTbk++-H6/-Tmp-/ SHELL=/bin/ tcsh HOME=/Users/hmrgsoft USER=hmrgsoft LOGNAME=hmrgsoft DISPLAY=/tmp/ launch-c1YZNr/org.x:0 SSH_AUTH_SOCK=/tmp/launch-AJ9xbl/Listeners Apple_PubSub_Socket_Render=/tmp/launch-BsRx5Y/Render COMMAND_MODE=unix2003 __CF_USER_TEXT_ENCODING=0x532:0:0 TERM_PROGRAM=Apple_Terminal TERM_PROGRAM_VERSION=273 LANG=en_US.UTF-8 TERM=xterm-color It's like it's calling up an entirely different ps, or passing it different command arguments. In both cases, however, I am explicitly calling /bin/ps with the same -e argument, and there appear to be no other ps commands on my system, neither do I appear to have any ps builtin command in any shell. I am running 2.6.6 under MacOS 10.6.4 on a MacBook Pro Intel. I have appended the code below. I am running both commands directly in a Terminal window running tcsh. Can anyone explain this? Thanks! Roger Davis ##### code follows #!/usr/bin/python import sys import subprocess def main(): psargs= ["/bin/ps", "-e"] try: ps= subprocess.Popen(psargs, stdout=subprocess.PIPE, close_fds=True) psout= ps.communicate()[0] pslines= psout.splitlines() for line in pslines: print "%s" % line except KeyboardInterrupt: print "Keyboard interrupt received -- terminating." sys.stdout.flush() sys.exit(-1) except: print "%s: unexpected error in generation of system process list" % prognm sys.stdout.flush() sys.exit(-1) main() From prologic at shortcircuit.net.au Tue Nov 16 21:44:57 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 17 Nov 2010 12:44:57 +1000 Subject: strange subprocess behavior when calling ps In-Reply-To: <55f26d5c-aba9-4892-9e2c-1caa9988e7fe@v23g2000vbi.googlegroups.com> References: <55f26d5c-aba9-4892-9e2c-1caa9988e7fe@v23g2000vbi.googlegroups.com> Message-ID: On Wed, Nov 17, 2010 at 12:33 PM, Roger Davis wrote: > Hi all, > > I have encountered a strange problem with some code I am writing to > search the system process list for certain running processes. I am > using subprocess.Popen() to call '/bin/ps -e'. When I save my code to > the file pid.py (whose first line is #!/usr/bin/python) and run it > with the command > > % ./pid.py > > it works perfectly fine, retrieving lines from my pipe to the /bin/ps > output which look exactly as if I had typed the command '/bin/ps -e' > myself into a shell window. Here is a sample line from that output: > > ?1891 ttys000 ? ?0:00.12 -tcsh > > Now for the weird part -- when I run this code using the command > > % python pid.py > > I get entirely different output. It only prints out a very few > processes instead of the entire table, and each line also has lots of > environment variable values displayed. Here is the line from that > output which corresponds to the line immediately above: > > ?1891 s000 ?S+ ? ? 0:00.12 -tcsh PATH=/usr/bin:/bin:/usr/sbin:/sbin > TMPDIR=/var/folders/3e/3e-TyTQIG-aOa4x37pbTbk++-H6/-Tmp-/ SHELL=/bin/ > tcsh HOME=/Users/hmrgsoft USER=hmrgsoft LOGNAME=hmrgsoft DISPLAY=/tmp/ > launch-c1YZNr/org.x:0 SSH_AUTH_SOCK=/tmp/launch-AJ9xbl/Listeners > Apple_PubSub_Socket_Render=/tmp/launch-BsRx5Y/Render > COMMAND_MODE=unix2003 __CF_USER_TEXT_ENCODING=0x532:0:0 > TERM_PROGRAM=Apple_Terminal TERM_PROGRAM_VERSION=273 LANG=en_US.UTF-8 > TERM=xterm-color > > It's like it's calling up an entirely different ps, or passing it > different command arguments. In both cases, however, I am explicitly > calling /bin/ps with the same -e argument, and there appear to be no > other ps commands on my system, neither do I appear to have any ps > builtin command in any shell. > > I am running 2.6.6 under MacOS 10.6.4 on a MacBook Pro Intel. I have > appended the code below. I am running both commands directly in a > Terminal window running tcsh. > > Can anyone explain this? Thanks! > > Roger Davis > > ##### code follows > > #!/usr/bin/python > import sys > import subprocess > > def main(): > > ? ? ? ?psargs= ["/bin/ps", "-e"] > ? ? ? ?try: > ? ? ? ? ? ? ? ?ps= subprocess.Popen(psargs, stdout=subprocess.PIPE, close_fds=True) > ? ? ? ? ? ? ? ?psout= ps.communicate()[0] > ? ? ? ? ? ? ? ?pslines= psout.splitlines() > ? ? ? ? ? ? ? ?for line in pslines: > ? ? ? ? ? ? ? ? ? ? ? ?print "%s" % line > ? ? ? ?except KeyboardInterrupt: > ? ? ? ? ? ? ? ?print "Keyboard interrupt received -- terminating." > ? ? ? ? ? ? ? ?sys.stdout.flush() > ? ? ? ? ? ? ? ?sys.exit(-1) > ? ? ? ?except: > ? ? ? ? ? ? ? ?print "%s: unexpected error in generation of system process list" % > prognm > ? ? ? ? ? ? ? ?sys.stdout.flush() > ? ? ? ? ? ? ? ?sys.exit(-1) > > main() Roger, why not use the nicely written and documented psutil module ? http://pypi.python.org/pypi/psutil/0.2.0 http://code.google.com/p/psutil/ cheers James -- -- James Mills -- -- "Problems are solved by method" From crebert at ucsd.edu Tue Nov 16 22:13:16 2010 From: crebert at ucsd.edu (Chris Rebert) Date: Tue, 16 Nov 2010 19:13:16 -0800 Subject: strange subprocess behavior when calling ps In-Reply-To: <55f26d5c-aba9-4892-9e2c-1caa9988e7fe@v23g2000vbi.googlegroups.com> References: <55f26d5c-aba9-4892-9e2c-1caa9988e7fe@v23g2000vbi.googlegroups.com> Message-ID: On Tue, Nov 16, 2010 at 6:33 PM, Roger Davis wrote: > Hi all, > > I have encountered a strange problem with some code I am writing to > search the system process list for certain running processes. I am > using subprocess.Popen() to call '/bin/ps -e'. When I save my code to > the file pid.py (whose first line is #!/usr/bin/python) and run it > with the command > > % ./pid.py > > it works perfectly fine, retrieving lines from my pipe to the /bin/ps > output which look exactly as if I had typed the command '/bin/ps -e' > myself into a shell window. Here is a sample line from that output: > > ?1891 ttys000 ? ?0:00.12 -tcsh > > Now for the weird part -- when I run this code using the command > > % python pid.py > > I get entirely different output. It only prints out a very few > processes instead of the entire table, and each line also has lots of > environment variable values displayed. > It's like it's calling up an entirely different ps, or passing it > different command arguments. In both cases, however, I am explicitly > calling /bin/ps with the same -e argument, and there appear to be no > other ps commands on my system, neither do I appear to have any ps > builtin command in any shell. > > I am running 2.6.6 under MacOS 10.6.4 on a MacBook Pro Intel. I have > appended the code below. I am running both commands directly in a > Terminal window running tcsh. > > Can anyone explain this? Thanks! > ##### code follows > > #!/usr/bin/python Have you checked whether those commands are running under the same Python? What output do you get from tcsh for the following?: which python python -V /usr/bin/python -V ls -l /usr/bin/python Also, did you upgrade your system Python or something? I'm running Mac OS 10.6.5 and the built-in /usr/bin/python is v2.6.1, so I find the implied claim that your /usr/bin/python is v2.6.6 to be rather bizarre. I am unable to reproduce your problem with either my v2.6.1 system Python or my v2.6.6 Python from Fink. Cheers, Chris -- http://blog.rebertia.com From rbd at hawaii.edu Tue Nov 16 23:05:17 2010 From: rbd at hawaii.edu (Roger Davis) Date: Tue, 16 Nov 2010 20:05:17 -0800 (PST) Subject: strange subprocess behavior when calling ps References: <55f26d5c-aba9-4892-9e2c-1caa9988e7fe@v23g2000vbi.googlegroups.com> Message-ID: <7bca95cc-5213-4a54-960c-de12d1e308fe@a30g2000vbt.googlegroups.com> Thanks, Chris, you're at least on the right track. I did upgrade from python.org and the python in my shell PATH is /Library/Frameworks/ Python.framework/Versions/2.6/bin/python: % python Python 2.6.6 (r266:84374, Aug 31 2010, 11:00:51) [GCC 4.0.1 (Apple Inc. build 5493)] on darwin /usr/bin/python is the Apple-distributed 2.6.1: % /usr/bin/python Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29) [GCC 4.2.1 (Apple Inc. build 5646)] on darwin This still doesn't explain the behavior to me, however. In either case python is supposed to be forking a child process with a specific executable (/bin/ps) and a specific argument list (-e) and reading that command's output lines. Why should those output lines be different whether I use 2.6.1, 2.6.6 or 8.9.10 for that matter? In fact, this makes the problem that much worse -- the newer python 2.6.6 is the one producing the incorrect output. Changing the first line of the script to read #!/Library/Frameworks/Python.framework/Versions/2.6/bin/python does not help, it still prints out the wrong output whether I do % ./pid.py or % /Library/Frameworks/Python.framework/Versions/2.6/bin/python ./ pid.py Any ideas? Thanks! From hansyin at gmail.com Tue Nov 16 23:14:51 2010 From: hansyin at gmail.com (Hans) Date: Tue, 16 Nov 2010 20:14:51 -0800 (PST) Subject: how to use socket to get packet which destination ip is not local? References: <21df438f-9869-4818-bc59-752702e2a203@j1g2000vbl.googlegroups.com> Message-ID: <52c44aed-6810-40da-82fe-a5d3da800c7d@w18g2000vbe.googlegroups.com> On Nov 16, 12:57?pm, MRAB wrote: > On 16/11/2010 20:38, Hans wrote: > > > Hi, > > > Maybe it's a very simple question. I'm trying to write a dhcpclient > > code with python. The dhcpclient does not have ip address at the very > > beginning, it sends out dhcpdiscover and then server sends back > > dhcpoffer. the dhcpoffer will use assigned ip as destination ip, but > > that ip is not client's local ip yet. How can I make my socket to > > receive that packet? > > > I tried socket bind to 0.0.0.0, but it only binds to any local ip, not > > any ip which may not be local. therefore the socket cannot get that > > dhcp offer packet even I can use wireshark to see that packet did come > > to this pc. > > > How to solve it? Thanks in advance. > > Have you read this: > > ? ? ?http://en.wikipedia.org/wiki/Dynamic_Host_Configuration_Protocol Thanks for the response. Yes, I read it. it tells me how dhcp works. But I cannot find answer for my question, dhcp response may be unicast or broadcast depends on the flag in request. my question is how to use socket to read that response. In my test, sniffer already shows server sends back an offer response(unicast in my case), but because the dst- ip in response is not local ip, then my socket cannot read it. Can you help? thank you very much! From rbd at hawaii.edu Tue Nov 16 23:15:16 2010 From: rbd at hawaii.edu (Roger Davis) Date: Tue, 16 Nov 2010 20:15:16 -0800 (PST) Subject: strange subprocess behavior when calling ps References: <55f26d5c-aba9-4892-9e2c-1caa9988e7fe@v23g2000vbi.googlegroups.com> <7bca95cc-5213-4a54-960c-de12d1e308fe@a30g2000vbt.googlegroups.com> Message-ID: Hi James, Thanks for the pointer to psutil. I actually did look around on python.org before coding this up to see if there was such a package available but there is not, at least not where I'm looking -- on the other hand, I can't find my car keys most of the time. I would really like to restrict my code dependencies to the standard Python distribution (if there actually is such a thing, I'm new to the language). Of course, that's assuming that I can actually get my code to work in that fashion. If I can't get to the bottom of this issue and figure out why my existing code does not work I will investigate psutil further. Thanks! Roger From nad at acm.org Tue Nov 16 23:18:02 2010 From: nad at acm.org (Ned Deily) Date: Tue, 16 Nov 2010 20:18:02 -0800 Subject: strange subprocess behavior when calling ps References: <55f26d5c-aba9-4892-9e2c-1caa9988e7fe@v23g2000vbi.googlegroups.com> Message-ID: In article <55f26d5c-aba9-4892-9e2c-1caa9988e7fe at v23g2000vbi.googlegroups.com>, Roger Davis wrote: > I have encountered a strange problem with some code I am writing to > search the system process list for certain running processes. I am > using subprocess.Popen() to call '/bin/ps -e'. When I save my code to > the file pid.py (whose first line is #!/usr/bin/python) and run it > with the command > > % ./pid.py > > it works perfectly fine, retrieving lines from my pipe to the /bin/ps > output which look exactly as if I had typed the command '/bin/ps -e' > myself into a shell window. Here is a sample line from that output: > > 1891 ttys000 0:00.12 -tcsh > > Now for the weird part -- when I run this code using the command > > % python pid.py > > I get entirely different output. It only prints out a very few > processes instead of the entire table, and each line also has lots of > environment variable values displayed. Here is the line from that > output which corresponds to the line immediately above: > > 1891 s000 S+ 0:00.12 -tcsh PATH=/usr/bin:/bin:/usr/sbin:/sbin > TMPDIR=/var/folders/3e/3e-TyTQIG-aOa4x37pbTbk++-H6/-Tmp-/ SHELL=/bin/ > tcsh HOME=/Users/hmrgsoft USER=hmrgsoft LOGNAME=hmrgsoft DISPLAY=/tmp/ > launch-c1YZNr/org.x:0 SSH_AUTH_SOCK=/tmp/launch-AJ9xbl/Listeners > Apple_PubSub_Socket_Render=/tmp/launch-BsRx5Y/Render > COMMAND_MODE=unix2003 __CF_USER_TEXT_ENCODING=0x532:0:0 > TERM_PROGRAM=Apple_Terminal TERM_PROGRAM_VERSION=273 LANG=en_US.UTF-8 > TERM=xterm-color > > It's like it's calling up an entirely different ps, or passing it > different command arguments. In both cases, however, I am explicitly > calling /bin/ps with the same -e argument, and there appear to be no > other ps commands on my system, neither do I appear to have any ps > builtin command in any shell. > > I am running 2.6.6 under MacOS 10.6.4 on a MacBook Pro Intel. I have > appended the code below. I am running both commands directly in a > Terminal window running tcsh. See "man compat". What you are seeing is the difference between ps(1) output in "legacy" mode, attempting to duplicate the old, non-POSIX behavior from 10.3 days, or "unix2003" mode. Terminal login sessions are normally automatically started with the COMMAND_MODE environment variable set: $ echo $COMMAND_MODE unix2003 Adding an "env={"COMMAND_MODE": "unix2003"}" argument to your subprocess Popen call should do the trick. -- Ned Deily, nad at acm.org From midnacc at gmail.com Tue Nov 16 23:36:06 2010 From: midnacc at gmail.com (c_c) Date: Wed, 17 Nov 2010 12:36:06 +0800 Subject: how to use socket to get packet which destination ip is not local? In-Reply-To: <4CE2F053.7010509@mrabarnett.plus.com> References: <21df438f-9869-4818-bc59-752702e2a203@j1g2000vbl.googlegroups.com> <4CE2F053.7010509@mrabarnett.plus.com> Message-ID: libpcap On Wed, Nov 17, 2010 at 4:57 AM, MRAB wrote: > On 16/11/2010 20:38, Hans wrote: > >> Hi, >> >> Maybe it's a very simple question. I'm trying to write a dhcpclient >> code with python. The dhcpclient does not have ip address at the very >> beginning, it sends out dhcpdiscover and then server sends back >> dhcpoffer. the dhcpoffer will use assigned ip as destination ip, but >> that ip is not client's local ip yet. How can I make my socket to >> receive that packet? >> >> I tried socket bind to 0.0.0.0, but it only binds to any local ip, not >> any ip which may not be local. therefore the socket cannot get that >> dhcp offer packet even I can use wireshark to see that packet did come >> to this pc. >> >> How to solve it? Thanks in advance. >> >> Have you read this: > > http://en.wikipedia.org/wiki/Dynamic_Host_Configuration_Protocol > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From sjmachin at lexicon.net Wed Nov 17 00:14:33 2010 From: sjmachin at lexicon.net (John Machin) Date: Tue, 16 Nov 2010 21:14:33 -0800 (PST) Subject: Raw Unicode docstring References: Message-ID: <4a1c5b98-8bf2-4525-b26f-a30b3dcbd6e1@e20g2000vbn.googlegroups.com> On Nov 17, 9:34?am, Alexander Kapps wrote: > ?>>> ur"Schei?t\nderB?r\nim Wald?" Nicht ohne eine Genehmigung von der Umwelt Erhaltung Abteilung. From justpark78 at gmail.com Wed Nov 17 00:26:19 2010 From: justpark78 at gmail.com (justin) Date: Tue, 16 Nov 2010 21:26:19 -0800 (PST) Subject: How can I catch segmentation fault in python? Message-ID: Hi all, I am calling a program written in C inside Python using ctypes, and it seems that sometimes the program in C crashes while it's being used in Python. Even under the circumstances, I want to get the Python program going by handling the segmentation fault. I've already searched the Internet, but couldn't get the right answer to catch them. Could any of you please let me know how to deal with this and catch the segmentation fault in Python? Thanks, Justin. From drsalists at gmail.com Wed Nov 17 00:59:27 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 16 Nov 2010 21:59:27 -0800 Subject: remote server and effective uid In-Reply-To: References: Message-ID: On Tue, Nov 16, 2010 at 9:37 AM, Tim Arnold wrote: > "Tim Harig" wrote in message > news:ibs8h9$jmq$1 at speranza.aioe.org... > > On 2010-11-15, Tim Arnold wrote: > >> On Nov 15, 10:41 am, Tim Harig wrote: > >>> On 2010-11-15, Tim Arnold wrote: > >>> > >>> > How can I enable the server process to write into the client's > >>> > directories? > >>> > If I change the inetd service to run as 'root', I guess that would > >>> > work, but then the client couldn't remove the files put there after > >>> > the request. > >>> > >>> Python provides os.setuid() and os.seteuid() which wrap the system > >>> functions. See you systems man pages for these functions for more > >>> information. > >> > >> Thanks -- that was a lot easier than I thought it was going to be. > >> pass the client's uid in the message to the server like so > >> > >> argstring, local_dir, uid = message.split(':') > >> os.seteuid(int(uid)) > > > > I am not sure exactly what you are doing; but, I would advise great > > caution as messing this up could easily open your system to exploitation. > > Be very sure that you know what you are doing. > > I can see how that looks dangerous, but I think it's okay. I have inetd > listening on a port and whatever it receives, it passes on to that line > above "argstring, local_dir, uid message.split(':'). The argstring is > parsed using 'argparse' the resulting list of args is passed to a Python > class that can only do work for a specific set of args. I can't think of a > way someone could pass in an evil argstring that could do anything but > fail. > > Thanks for your reply, and if you still think it's dangerous please let me > know. > What if an attacker passes something other than their own uid across a socket to your inetd-launched process? EG, what if they pass a 0 (for root) instead of getuid()? It might be fine in your case, but in many cases, it's a problem. -------------- next part -------------- An HTML attachment was scrubbed... URL: From swapnil.st at gmail.com Wed Nov 17 01:15:14 2010 From: swapnil.st at gmail.com (swapnil) Date: Tue, 16 Nov 2010 22:15:14 -0800 (PST) Subject: How can I catch segmentation fault in python? References: Message-ID: On Nov 17, 10:26?am, justin wrote: > Hi all, > > I am calling a program written in C inside Python using ctypes, > and it seems that sometimes the program in C crashes while it's being > used in Python. > Even under the circumstances, I want to get the Python program going > by handling the segmentation fault. > > I've already searched the Internet, but couldn't get the right answer > to catch them. > Could any of you please let me know how to deal with this and catch > the segmentation fault in Python? > > Thanks, > Justin. Segmentation fault isn't exactly an exception that you can catch. It usually means something has gone horribly wrong, like dereferencing invalid pointer, trying to access memory out of process's range. Since if you run out of memory Python simply raises MemoryError exception, which you can catch. So that is not the case for segmentation fault. From swapnil.st at gmail.com Wed Nov 17 01:24:51 2010 From: swapnil.st at gmail.com (swapnil) Date: Tue, 16 Nov 2010 22:24:51 -0800 (PST) Subject: Is Unladen Swallow dead? References: <2e1a4d02-1e8a-4d31-95da-f33aaf90578c@30g2000yql.googlegroups.com> Message-ID: <8b0b044c-34a8-4747-b68f-f4cb56882f6f@e26g2000vbz.googlegroups.com> On Nov 17, 3:30?am, laspi wrote: > There has been little or no activity at all in this project in the > last months, and the last comments on their mailing list seem to > conrfim that it's future is uncertain. > It's also very strange the lack of updates, news or discussions, > specially considering that the merging plan has been approved. Or it > hasn't? AFAIK, the merging plan was approved by Guido early this year. I guess Google is expecting the community to drive the project from here on. That was the whole idea for merging it to mainline. From my last conversation with Collin, they are targeting Python 3.3 From rbd at hawaii.edu Wed Nov 17 01:47:09 2010 From: rbd at hawaii.edu (Roger Davis) Date: Tue, 16 Nov 2010 22:47:09 -0800 (PST) Subject: strange subprocess behavior when calling ps References: <55f26d5c-aba9-4892-9e2c-1caa9988e7fe@v23g2000vbi.googlegroups.com> Message-ID: <61496525-afab-4d19-a7e9-e61fb46e03ef@n30g2000vbb.googlegroups.com> Thanks, Ned! That really helps to explain what is going on. Now, just a couple more questions and I think I will know all I need to know. First, I *still* don't quite understand why this happens with my 2.6.6 interpreter but not my 2.6.1, and why another of the respondents to this thread (Chris) could not duplicate this problem with his own 2.6.6 environment. Is there something defective with my Python environment having to do with the 2.6.6 upgrade I installed directly from python.org? (Chris used Fink, apparently.) If so, how can I clean it up? I do have an easier time believing that this is a mangled installation issue now that the problem has essentially been reduced to the handling of an environment variable which I can well imagine could be easily garbled somewhere in a version mismatch scenario. Second, I do need to make this work on multiple platforms, primarily Linux in addition to the Mac but also with a potential variety of Python releases on both MacOS and Linux. I'm not sure if Linux will object to this COMMAND_MODE business, I guess I'll just have to try and see what happens. Any thoughts on that? Finally, to split hairs a bit concerning your suggested solution, I have a question about the additional env={'COMMAND_MODE': 'unix2003'} argument. This works for me, but my reading of the subprocess documentation leads me to believe that this will actually wipe out the entire environment that would otherwise be inherited from the parent and replace it with that single setting. I don't think this has any ill effects here with regard to ps, at least none I can detect at the moment, but wouldn't a perhaps safer solution be to do os.environ['COMMAND_MODE']= 'unix2003' prior to the Popen() to instead augment/correct the existing environment which will then later be inherited by the child, assuming no explicit env= optional argument is used? This also works for me, and I think I'm more inclined to go this route unless you can think of a good reason not to do so. Thanks very much for your help! From clp2 at rebertia.com Wed Nov 17 02:01:05 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 16 Nov 2010 23:01:05 -0800 Subject: How can I catch segmentation fault in python? In-Reply-To: References: Message-ID: On Tue, Nov 16, 2010 at 9:26 PM, justin wrote: > Hi all, > > I am calling a program written in C inside Python using ctypes, > and it seems that sometimes the program in C crashes while it's being > used in Python. > Even under the circumstances, I want to get the Python program going > by handling the segmentation fault. > > I've already searched the Internet, but couldn't get the right answer > to catch them. > Could any of you please let me know how to deal with this and catch > the segmentation fault in Python? You can't "catch" it. It's not a mere Exception, it's a fatal error that effectively crashes the interpreter itself. At best, you could perhaps use the `multiprocessing` or `subprocess` modules to segregate the part of your program that uses ctypes and then try and recover when you detect that the subprocess has crashed. Instead, if possible, fix the C program and/or ensure that there's not an error in your ctypes interfacing code. Cheers, Chris -- http://blog.rebertia.com From nagle at animats.com Wed Nov 17 02:02:11 2010 From: nagle at animats.com (John Nagle) Date: Tue, 16 Nov 2010 23:02:11 -0800 Subject: Is Unladen Swallow dead? In-Reply-To: <8b0b044c-34a8-4747-b68f-f4cb56882f6f@e26g2000vbz.googlegroups.com> References: <2e1a4d02-1e8a-4d31-95da-f33aaf90578c@30g2000yql.googlegroups.com> <8b0b044c-34a8-4747-b68f-f4cb56882f6f@e26g2000vbz.googlegroups.com> Message-ID: <4ce37e01$0$1666$742ec2ed@news.sonic.net> On 11/16/2010 10:24 PM, swapnil wrote: > On Nov 17, 3:30 am, laspi wrote: >> There has been little or no activity at all in this project in the >> last months, and the last comments on their mailing list seem to >> conrfim that it's future is uncertain. >> It's also very strange the lack of updates, news or discussions, >> specially considering that the merging plan has been approved. Or it >> hasn't? > > AFAIK, the merging plan was approved by Guido early this year. I guess > Google is expecting the community to drive the project from here on. > That was the whole idea for merging it to mainline. From my last > conversation with Collin, they are targeting Python 3.3 I think it's dead. They're a year behind on quarterly releases. The last release was Q3 2009. The project failed to achieve its stated goal of a 5x speedup. Not even close. More like 1.5x (http://www.python.org/dev/peps/pep-3146) The Google blog at "http://groups.google.com/group/unladen-swallow/browse_thread/thread/f2011129c4414d04" says, as of November 8, 2010: "Jeffrey and I have been pulled on to other projects of higher importance to Google. Unfortunately, no-one from the Python open-source community has been interested in picking up the merger work, and since none of the original team is still full-time on the project, it's moving very slowly. Finishing up the merger into the py3k-jit branch is a high priority for me this quarter, but what happens then is an open question." So Google has pulled the plug on Unladen Swallow. It looks like they underestimated the difficulty of speeding up the CPython model. The performance improvement achieved was so low that cluttering up CPython with a JIT system and LLVM probably is a lose. John Nagle From nagle at animats.com Wed Nov 17 02:06:01 2010 From: nagle at animats.com (John Nagle) Date: Tue, 16 Nov 2010 23:06:01 -0800 Subject: How can I catch segmentation fault in python? In-Reply-To: References: Message-ID: <4ce37ee7$0$1666$742ec2ed@news.sonic.net> On 11/16/2010 10:15 PM, swapnil wrote: > On Nov 17, 10:26 am, justin wrote: >> Hi all, >> >> I am calling a program written in C inside Python using ctypes, >> and it seems that sometimes the program in C crashes while it's being >> used in Python. >> Even under the circumstances, I want to get the Python program going >> by handling the segmentation fault. >> >> I've already searched the Internet, but couldn't get the right answer >> to catch them. >> Could any of you please let me know how to deal with this and catch >> the segmentation fault in Python? >> >> Thanks, >> Justin. > > Segmentation fault isn't exactly an exception that you can catch. It > usually means something has gone horribly wrong, like dereferencing > invalid pointer, trying to access memory out of process's range. Since > if you run out of memory Python simply raises MemoryError exception, > which you can catch. So that is not the case for segmentation fault. Either fix the program so it doesn't crash,or run the offending module and the C code in a subprocess. John Nagle From matlab.dude at mbnet.fi Wed Nov 17 03:04:11 2010 From: matlab.dude at mbnet.fi (MATLABdude) Date: Wed, 17 Nov 2010 00:04:11 -0800 (PST) Subject: MATLAB to Python? Message-ID: <74f276c3-38a4-4df0-af39-7b1f2a81472e@c39g2000yqi.googlegroups.com> Hi! Can you, please, try to help me with Python? I try to convert a MATLAB program to Python. Here are the MATLAB codes: http://pastebin.com/eJetYizv http://pastebin.com/0eXTVfyN Here is my Python code: http://pastebin.com/jCPdLHx7 What is wrong with my Python code? The program doesn't produce quite the same lambdas as the MATLAB program does. My code probably has lots of errors because I'm just learning the basics about Python. Thanks for all the help! From bnbowman at gmail.com Wed Nov 17 03:16:29 2010 From: bnbowman at gmail.com (Brett Bowman) Date: Wed, 17 Nov 2010 00:16:29 -0800 Subject: Cannot Remove File: Device or resource busy In-Reply-To: References: Message-ID: Good ideas, but I've tried them already: -No del command, or replacing it with a set-to-null, neither solve my file access problem. -PdfFileReader has no close() function, and causes an error. Weird, but true. -pdf_handle.close() on the other hand, fails to solve the problem. On Tue, Nov 16, 2010 at 11:25 PM, Dennis Lee Bieber wrote: > On Tue, 16 Nov 2010 17:37:10 -0800, Brett Bowman > declaimed the following in gmane.comp.python.general: > > > > > And then I test the result: > > try: > > pdf_handle = open(outputFile, "rb") > > pdf_pypdf = PdfFileReader(pdf_handle) > > del pdf_pypdf > > del pdf_handle > > except Exception, e: > > return "Unable to open file: %s with error: %s" % (outputFile, > > str(e)) > > > You seem enamored of "del", which is something I've only used for > special purposes, and even then rarely -- binding a null object to the > name is just as effective for most uses. > > While the common Python does garbage collect objects when the > reference count goes to zero, there is no real guarantee of this. > > I'd replace that > del pdf_handle > whit > pdf_handle.close() > > -- > Wulfraed Dennis Lee Bieber AF6VN > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Wed Nov 17 03:38:49 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 17 Nov 2010 09:38:49 +0100 Subject: MATLAB to Python? References: <74f276c3-38a4-4df0-af39-7b1f2a81472e@c39g2000yqi.googlegroups.com> Message-ID: MATLABdude wrote: > Can you, please, try to help me with Python? I try to convert a MATLAB > program to Python. > > Here are the MATLAB codes: > http://pastebin.com/eJetYizv > http://pastebin.com/0eXTVfyN > > Here is my Python code: > http://pastebin.com/jCPdLHx7 That is too much code for me, in a problem domain I'm not familiar with. > What is wrong with my Python code? The program doesn't produce quite > the same lambdas as the MATLAB program does. My code probably has lots > of errors because I'm just learning the basics about Python. If no-one fixes it for you I suggest that you break the code in smaller functions (at most ten lines) that you can test separately. That should make it easier to spot the misbehaving parts of your calculation. If you come back then with one of these, the matlab equivalent, sample input and expected output a significantly larger number of people can and may be willing to help. Peter From pavlovevidence at gmail.com Wed Nov 17 03:46:47 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 17 Nov 2010 00:46:47 -0800 (PST) Subject: MATLAB to Python? References: <74f276c3-38a4-4df0-af39-7b1f2a81472e@c39g2000yqi.googlegroups.com> Message-ID: <9c9107ca-2727-4389-b939-edae6a2e03ca@26g2000yqv.googlegroups.com> On Nov 17, 12:04?am, MATLABdude wrote: > Hi! > > Can you, please, try to help me with Python? I try to convert a MATLAB > program to Python. > > Here are the MATLAB codes:http://pastebin.com/eJetYizvhttp://pastebin.com/0eXTVfyN > > Here is my Python code:http://pastebin.com/jCPdLHx7 > > What is wrong with my Python code? The program doesn't produce quite > the same lambdas as the MATLAB program does. My code probably has lots > of errors because I'm just learning the basics about Python. > > Thanks for all the help! I was about to say it was a pretty good looking piece of code, and probably if anything is wrong it's a typo somewhere. But then my eye caught something at the last minute: xx = range(-kappa, h, kappa+1) Looks like you're treating range arguments as (start,step,stop), same order as in Matlab. In Python it's (start,stop,step), so you should be using this: xx = range(-kappa,kappa+1,h) Other than that, you might jus have to pepper your scripts with prints and disps to catch the exact point where the discrepancy occurs. Carl Banks From arnodel at gmail.com Wed Nov 17 03:53:20 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Wed, 17 Nov 2010 08:53:20 +0000 Subject: MATLAB to Python? References: <74f276c3-38a4-4df0-af39-7b1f2a81472e@c39g2000yqi.googlegroups.com> Message-ID: <878w0s2uwv.fsf@gmail.com> MATLABdude writes: > Hi! > > Can you, please, try to help me with Python? I try to convert a MATLAB > program to Python. > > Here are the MATLAB codes: > http://pastebin.com/eJetYizv > http://pastebin.com/0eXTVfyN > > Here is my Python code: > http://pastebin.com/jCPdLHx7 > > What is wrong with my Python code? The program doesn't produce quite > the same lambdas as the MATLAB program does. My code probably has lots > of errors because I'm just learning the basics about Python. > > Thanks for all the help! I don't understand what's going on in your code, but line 81 you have: xx = range(-kappa, h, kappa+1) I guess that the step is supposed to be h, so you should write: xx = range(-kappa, kappa+1, h) -- Arnaud From swapnil.st at gmail.com Wed Nov 17 03:53:56 2010 From: swapnil.st at gmail.com (swapnil) Date: Wed, 17 Nov 2010 00:53:56 -0800 (PST) Subject: import site fails - Please Help References: <8kcaapF44bU1@mid.dfncis.de> Message-ID: <8c8b2bf7-9fd8-466c-9306-06aa56448772@j2g2000yqf.googlegroups.com> On Nov 15, 1:46?pm, Helmut Jarausch wrote: > Hi, I'm completely puzzled and I hope someone > can shed some light on it. > > After cloning a running system, booting the new machine from a rescue CD, > chroot to the new root partition, I get the following strange error > from python upon startup > > python -v> import site failed > > .... > st= os.stat(path) > stat() argument 1 must be encoded string without NULL bytes, not str > > So, what's broken? How can I get out what 'path' contained at this > moment? > > Many thanks for your help, > Helmut. Perhaps its not able to locate the libraries. Try using http://docs.python.org/using/cmdline.html#envvar-PYTHONPATH and http://docs.python.org/using/cmdline.html#envvar-PYTHONHOME From nad at acm.org Wed Nov 17 04:19:09 2010 From: nad at acm.org (Ned Deily) Date: Wed, 17 Nov 2010 01:19:09 -0800 Subject: strange subprocess behavior when calling ps References: <55f26d5c-aba9-4892-9e2c-1caa9988e7fe@v23g2000vbi.googlegroups.com> <61496525-afab-4d19-a7e9-e61fb46e03ef@n30g2000vbb.googlegroups.com> Message-ID: In article <61496525-afab-4d19-a7e9-e61fb46e03ef at n30g2000vbb.googlegroups.com>, Roger Davis wrote: > First, I *still* don't quite understand why this happens with my 2.6.6 > interpreter but not my 2.6.1, and why another of the respondents to > this thread (Chris) could not duplicate this problem with his own > 2.6.6 environment. Is there something defective with my Python > environment having to do with the 2.6.6 upgrade I installed directly > from python.org? (Chris used Fink, apparently.) If so, how can I clean > it up? I do have an easier time believing that this is a mangled > installation issue now that the problem has essentially been reduced > to the handling of an environment variable which I can well imagine > could be easily garbled somewhere in a version mismatch scenario. Interesting. It appears that OS X 10.6 takes into account the deployment target of the executable. Prior to 2.7, all recent python.org installed Pythons have been built with MACOSX_DEPLOYMENT_TARGET = 10.3, allowing the same build to work on all releases from 10.3.9 on. So, when you launch a script with the python.org interpreter (with a 10.3 deployment target), OS X automatically sets COMMAND_MODE to 'legacy'. The Apple-supplied Python 2.6.1 in OS X 10.6 is built with a deployment target of 10.6, so it gets a COMMAND_MODE of 'unix2003'. And, as far as I can tell, OS X 10.5 honors COMMAND_MODE but does not automatically set it or tailor it like 10.6 does. Live and learn! > Second, I do need to make this work on multiple platforms, primarily > Linux in addition to the Mac but also with a potential variety of > Python releases on both MacOS and Linux. I'm not sure if Linux will > object to this COMMAND_MODE business, I guess I'll just have to try > and see what happens. Any thoughts on that? As far as I know, COMMAND_MODE has no special meaning on other platforms so it should be ignored anywhere but on OS X. If you want to be extra cautious, you could test for 'sys.platform == 'darwin'. > Finally, to split hairs a bit concerning your suggested solution, I > have a question about the additional env={'COMMAND_MODE': 'unix2003'} > argument. This works for me, but my reading of the subprocess > documentation leads me to believe that this will actually wipe out the > entire environment that would otherwise be inherited from the parent > and replace it with that single setting. I don't think this has any > ill effects here with regard to ps, at least none I can detect at the > moment, but wouldn't a perhaps safer solution be to do > > os.environ['COMMAND_MODE']= 'unix2003' > > prior to the Popen() to instead augment/correct the existing > environment which will then later be inherited by the child, assuming > no explicit env= optional argument is used? This also works for me, > and I think I'm more inclined to go this route unless you can think of > a good reason not to do so. That analysis seems correct. So it comes down to whether there are any environment variable settings the user could make that would positively or negatively affect the operation of your script. -- Ned Deily, nad at acm.org From swapnil.st at gmail.com Wed Nov 17 04:39:08 2010 From: swapnil.st at gmail.com (swapnil) Date: Wed, 17 Nov 2010 01:39:08 -0800 (PST) Subject: In-process interpreters Message-ID: <7091619d-f6a4-4cd7-bd0d-4d10a1daf03f@y37g2000vbl.googlegroups.com> Hi, Please refer my post on Python-ideas list http://mail.python.org/pipermail/python-ideas/2010-November/008666.html and provide feedback if any. From jeanmichel at sequans.com Wed Nov 17 05:34:42 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 17 Nov 2010 11:34:42 +0100 Subject: strange subprocess behavior when calling ps In-Reply-To: <55f26d5c-aba9-4892-9e2c-1caa9988e7fe@v23g2000vbi.googlegroups.com> References: <55f26d5c-aba9-4892-9e2c-1caa9988e7fe@v23g2000vbi.googlegroups.com> Message-ID: <4CE3AFC2.4020209@sequans.com> Roger Davis wrote: > Hi all, > [snip] > Roger Davis > > ##### code follows > > #!/usr/bin/python > import sys > import subprocess > > def main(): > > psargs= ["/bin/ps", "-e"] > try: > ps= subprocess.Popen(psargs, stdout=subprocess.PIPE, close_fds=True) > psout= ps.communicate()[0] > pslines= psout.splitlines() > for line in pslines: > print "%s" % line > except KeyboardInterrupt: > print "Keyboard interrupt received -- terminating." > sys.stdout.flush() > sys.exit(-1) > except: > print "%s: unexpected error in generation of system process list" % > prognm > sys.stdout.flush() > sys.exit(-1) > > main() > Completely off topic but I think the try clause could be rewritten that way: try: ps= subprocess.Popen(psargs, stdout=subprocess.PIPE, close_fds=True) psout= ps.communicate()[0] pslines= psout.splitlines() for line in pslines: print "%s" % line except KeyboardInterrupt: print "Keyboard interrupt received -- terminating." finally: sys.stdout.flush() Don't use bare except clause, you're masking syntax errors for instance, which will be flagged as 'unexpected error in generation ...". In a more general manner, if something unexpected happens it's better to just let the exception raise uncought. If you want to handle some errors, meaning you're kindof expecting them then add a explicit clause (like you did with KeyboardInterrupt). JM PS : "except Exception :" will catch most of the exceptions (all inheriting from that class). It's better than using a bare "except :" clause. (Exception won't catch SyntaxError) From lipun4u at gmail.com Wed Nov 17 06:48:39 2010 From: lipun4u at gmail.com (asit) Date: Wed, 17 Nov 2010 03:48:39 -0800 (PST) Subject: urllib2 error Message-ID: <17eed640-7375-4b15-b124-5e012af33e79@y23g2000yqd.googlegroups.com> I have this piece of code import urllib2 proc_url = 'http://www.nse-india.com/content/historical/EQUITIES/2001/ JAN/cm01JAN2001bhav.csv.zip' print 'processing....', proc_url req = urllib2.Request(proc_url) res = urllib2.urlopen(req) when i run this...following error comes Traceback (most recent call last): File "C:/Python26/reqnse.py", line 92, in res = urllib2.urlopen(req) File "C:\Python26\lib\urllib2.py", line 124, in urlopen return _opener.open(url, data, timeout) File "C:\Python26\lib\urllib2.py", line 395, in open response = meth(req, response) File "C:\Python26\lib\urllib2.py", line 508, in http_response 'http', request, response, code, msg, hdrs) File "C:\Python26\lib\urllib2.py", line 433, in error return self._call_chain(*args) File "C:\Python26\lib\urllib2.py", line 367, in _call_chain result = func(*args) File "C:\Python26\lib\urllib2.py", line 516, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) HTTPError: HTTP Error 403: Forbidden would anyone help me why ?? From kushal.kumaran+python at gmail.com Wed Nov 17 07:01:26 2010 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Wed, 17 Nov 2010 17:31:26 +0530 Subject: urllib2 error In-Reply-To: <17eed640-7375-4b15-b124-5e012af33e79@y23g2000yqd.googlegroups.com> References: <17eed640-7375-4b15-b124-5e012af33e79@y23g2000yqd.googlegroups.com> Message-ID: On Wed, Nov 17, 2010 at 5:18 PM, asit wrote: > I have this piece of code > > import urllib2 > > proc_url = 'http://www.nse-india.com/content/historical/EQUITIES/2001/ > JAN/cm01JAN2001bhav.csv.zip' > print 'processing....', proc_url > req = urllib2.Request(proc_url) > res = urllib2.urlopen(req) > > when i run this...following error comes > > Traceback (most recent call last): > > HTTPError: HTTP Error 403: Forbidden > The web server is probably trying to forbid downloads using automated tools by examining the user agent header (downloading using wget also fails, for example). You can work around that by setting the User-Agent header to the same value as a browser that works. The urllib2 documentation covers how to set headers in requests. -- regards, kushal From lipun4u at gmail.com Wed Nov 17 07:18:53 2010 From: lipun4u at gmail.com (asit dhal) Date: Wed, 17 Nov 2010 17:48:53 +0530 Subject: urllib2 error In-Reply-To: References: <17eed640-7375-4b15-b124-5e012af33e79@y23g2000yqd.googlegroups.com> Message-ID: On Wed, Nov 17, 2010 at 5:31 PM, Kushal Kumaran wrote: > On Wed, Nov 17, 2010 at 5:18 PM, asit wrote: >> I have this piece of code >> >> import urllib2 >> >> proc_url = 'http://www.nse-india.com/content/historical/EQUITIES/2001/ >> JAN/cm01JAN2001bhav.csv.zip' >> print 'processing....', proc_url >> req = urllib2.Request(proc_url) >> res = urllib2.urlopen(req) >> >> when i run this...following error comes >> >> Traceback (most recent call last): >> >> HTTPError: HTTP Error 403: Forbidden >> > > The web server is probably trying to forbid downloads using automated > tools by examining the user agent header (downloading using wget also > fails, for example). ?You can work around that by setting the > User-Agent header to the same value as a browser that works. > > The urllib2 documentation covers how to set headers in requests. > > -- > regards, > kushal > -- Regards, Asit Kumar Dhal TCS, Mumbai blog: http://asitdhal.blogspot.com/ Thanx...it worked From lists at cheimes.de Wed Nov 17 08:17:24 2010 From: lists at cheimes.de (Christian Heimes) Date: Wed, 17 Nov 2010 14:17:24 +0100 Subject: Cannot Remove File: Device or resource busy In-Reply-To: References: Message-ID: Am 17.11.2010 09:16, schrieb Brett Bowman: > Good ideas, but I've tried them already: > -No del command, or replacing it with a set-to-null, neither solve my file > access problem. > -PdfFileReader has no close() function, and causes an error. Weird, but > true. > -pdf_handle.close() on the other hand, fails to solve the problem. You have to close the file explicitly, for example with a proper with block. with open(outputFile, "rb") as fh: pdf_pypdf = PdfFileReader(fh) # process the PDF file here Christian From nadiasvertex at gmail.com Wed Nov 17 09:01:58 2010 From: nadiasvertex at gmail.com (Christopher) Date: Wed, 17 Nov 2010 06:01:58 -0800 (PST) Subject: Some syntactic sugar proposals References: Message-ID: > ? Of course we can write it as > ? ? t = foo() if pred(foo()) else default_value > but here we have 2 foo() calls instead of one. Why can't we write just > something like this: > ? ? t = foo() if pred(it) else default_value > where "it" means "foo() value"? i don't like magic names. what about: t = foo() as v if pred(v) else default_value From justpark78 at gmail.com Wed Nov 17 09:28:36 2010 From: justpark78 at gmail.com (justin) Date: Wed, 17 Nov 2010 06:28:36 -0800 (PST) Subject: How can I catch segmentation fault in python? References: <4ce37ee7$0$1666$742ec2ed@news.sonic.net> Message-ID: <45ccbf6c-5cc7-422e-88ba-bb4615fe31d5@k5g2000vbn.googlegroups.com> On Nov 17, 1:06?am, John Nagle wrote: > On 11/16/2010 10:15 PM, swapnil wrote: > > > > > > > On Nov 17, 10:26 am, justin ?wrote: > >> Hi all, > > >> I am calling a program written in C inside Python using ctypes, > >> and it seems that sometimes the program in C crashes while it's being > >> used in Python. > >> Even under the circumstances, I want to get the Python program going > >> by handling the segmentation fault. > > >> I've already searched the Internet, but couldn't get the right answer > >> to catch them. > >> Could any of you please let me know how to deal with this and catch > >> the segmentation fault in Python? > > >> Thanks, > >> Justin. > > > Segmentation fault isn't exactly an exception that you can catch. It > > usually means something has gone horribly wrong, like dereferencing > > invalid pointer, trying to access memory out of process's range. Since > > if you run out of memory Python simply raises MemoryError exception, > > which you can catch. So that is not the case for segmentation fault. > > ? ? Either fix the program so it doesn't crash,or run the offending > module and the C code in a subprocess. > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? John Nagle Thanks guys for this fast replies, Turns out that it is a fact that segmentation fault is not what I can deal with in programming level. But the problem is that the code is not mine, and it takes over a day for me to get the point where the segmentation fault occurred. Plus, it seems that the point is not deterministic Still, I think I should at least try to figure out exactly at which point the segmentation fault occurs, and think where to go from there according to your kind advice. Again many thanks, Justin. From rde at audaxis.com Wed Nov 17 09:44:49 2010 From: rde at audaxis.com (Romaric DEFAUX) Date: Wed, 17 Nov 2010 15:44:49 +0100 Subject: Pickle in a POST/GET request give EOFError In-Reply-To: <4CE2B599.7050504@audaxis.com> References: <4CE2B599.7050504@audaxis.com> Message-ID: <4CE3EA61.2090707@audaxis.com> Le 16/11/2010 17:47, Romaric DEFAUX a ?crit : > Hi everybody ! > > First time I write to this mailing list :) > I started writing in python last week, that's probably why I can't > understand the following problem... > > > I create a list called web_site_list. > This list contain dictionaries called web_site. > And some values in this dictionaries are list too. > > I do that in a function and I return this : > return pickle.dumps(web_site_list) > > This is working fine :) > > If I do : > print "%s" % pickle.loads(system.get_web_site_list()) > > I've got the right stuffs. For example it returns : > [{'documentroot_size': '120', 'servername': '---default---', 'client': > 'undefined', 'documentroot': '/var/www/', 'client_contact': > 'undefined', 'serveralias': []}] > > I send this to a web service. I send it like that : > #I put it in params > def system_updateweb_site(server, login, password): > params = {} > params['login'] = login > params['password'] = password > params['action'] = 'updateweb_site' > params['servername'] = get_servername() > params['hosted_web_site'] = get_web_site_list() > return call_system_ws(server, params) > > #Here's how I send it (I tried in GET and POST) > def call_system_ws(host, params): > query_string = urllib.urlencode(params) > #GET > # f = urllib.urlopen("http://%s/ws?%s" % (host, query_string)) > #POST > f = urllib.urlopen("http://%s/ws" % (host), query_string) > result = f.readline().strip() > if result == 'ERROR': > msg = f.readline().strip() > return (False, msg) > return (True, result) > > > On the server side : > if action == 'updateweb_site': > if not (fields.has_key('servername') > and fields.has_key('hosted_web_site')): > raise WSError('missing > parameter : servername or hosted_web_site') > log ('ERROR : missing > parameter : servername or hosted_web_site') > else: > > servername=g.db.escape_string(fields['servername']) > > hosted_web_site=g.db.escape_string(fields['hosted_web_site']) > output = > systemserver.updateweb_site(cursor, servername, hosted_web_site) > > In systemserver.py : > def updateweb_site(cursor, host, hosted_web_site): > web_site_list = pickle.loads(hosted_web_site) > return "%s" % (web_site_list) > > I catch this error :* > > *: > > args = () > message = '' > > Why ? > > If I just print hosted_web_site, I get this on my web page : > > (lp0\n(dp1\nS\'documentroot_size\'\np2\nS\'120\'\np3\nsS\'servername\'\np4\nS\'default\'\np5\nsS\'client\'\np6\nS\'undefined\'\np7\nsS\'documentroot\'\np8\nS\'/var/www/\'\np9\nsS\'client_contact\'\np10\ng7\nsS\'serveralias\'\np11\n(lp12\nsa. > > > It's the "pickled view" of > [{'documentroot_size': '120', 'servername': '---default---', 'client': > 'undefined', 'documentroot': '/var/www/', 'client_contact': > 'undefined', 'serveralias': []}] > > Can someone help me please ? I spend my afternoon to google to try to > find a solution... > > > Thanks in advance !!! > > Romaric Defaux > After entirely rewrite my code to not use Web service but socket (a real client/server program) I finally found the problem... And it's not linked to the POST or GET method... It's because of that : g.db.escape_string(fields['hosted_web_site']) (escape_string is the function in MySQLdb library) It escapes the simple quote of the pickled object, and break it... It's good to know, NEVER escape a pickled object :) Romaric Defaux -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 5361 bytes Desc: S/MIME Cryptographic Signature URL: From mwilson at the-wire.com Wed Nov 17 10:18:51 2010 From: mwilson at the-wire.com (Mel) Date: Wed, 17 Nov 2010 10:18:51 -0500 Subject: Some syntactic sugar proposals References: Message-ID: Christopher wrote: >> ? Of course we can write it as >> t = foo() if pred(foo()) else default_value >> but here we have 2 foo() calls instead of one. Why can't we write just >> something like this: >> t = foo() if pred(it) else default_value >> where "it" means "foo() value"? > > i don't like magic names. what about: > > t = foo() as v if pred(v) else default_value !! so: assignment inside an expression. Mel. From usenot at geekmail.INVALID Wed Nov 17 10:24:33 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Wed, 17 Nov 2010 10:24:33 -0500 Subject: Some syntactic sugar proposals References: Message-ID: <20101117102433.28926da4@geekmail.INVALID> On Wed, 17 Nov 2010 10:18:51 -0500 Mel wrote: > Christopher wrote: > > >> ? Of course we can write it as > >> t = foo() if pred(foo()) else default_value > >> but here we have 2 foo() calls instead of one. Why can't we write > >> just something like this: > >> t = foo() if pred(it) else default_value > >> where "it" means "foo() value"? > > > > i don't like magic names. what about: > > > > t = foo() as v if pred(v) else default_value > > !! so: assignment inside an expression. > I like the idea of having an "as ... if" construct, though. :) /W -- To reach me via email, replace INVALID with the country code of my home country. But if you spam me, I'll be one sour Kraut. From wolfgang at rohdewald.de Wed Nov 17 10:37:45 2010 From: wolfgang at rohdewald.de (Wolfgang Rohdewald) Date: Wed, 17 Nov 2010 16:37:45 +0100 Subject: How can I catch segmentation fault in python? In-Reply-To: <45ccbf6c-5cc7-422e-88ba-bb4615fe31d5@k5g2000vbn.googlegroups.com> References: <4ce37ee7$0$1666$742ec2ed@news.sonic.net> <45ccbf6c-5cc7-422e-88ba-bb4615fe31d5@k5g2000vbn.googlegroups.com> Message-ID: <201011171637.45610.wolfgang@rohdewald.de> On Mittwoch 17 November 2010, justin wrote: > But the problem is that the code is not mine, and it takes > over a day for me to get the point where the segmentation > fault occurred. Plus, it seems that the point is not > deterministic > > Still, I think I should at least try to figure out exactly at > which point the segmentation fault occurs, and think where to > go from there according to your kind advice. try valgrind -- mit freundlichen Gr?ssen with my best greetings Wolfgang Rohdewald dipl. Informatik Ing. ETH Rohdewald Systemberatung Karauschenstieg 4 D 21640 Horneburg Tel.: 04163 826 819 Fax: 04163 826 828 Internet: http://www.rohdewald.de From jldunn2000 at gmail.com Wed Nov 17 10:41:54 2010 From: jldunn2000 at gmail.com (loial) Date: Wed, 17 Nov 2010 07:41:54 -0800 (PST) Subject: Oracle jdbc sql select for update in python Message-ID: <8048ca20-914a-4ea4-8f9f-7c516cea962a@z19g2000yqb.googlegroups.com> I want to do a select from...for update in python, update the selected row and then commit; However cannot seem to get it to work...the update statement seems to be waiting because the row is locked. Presumably oracle thinks the update is another transaction. How can I get this to work? What statements do I need to ensure Oracle treats this as one transaction? From wolfgang at rohdewald.de Wed Nov 17 10:47:16 2010 From: wolfgang at rohdewald.de (Wolfgang Rohdewald) Date: Wed, 17 Nov 2010 16:47:16 +0100 Subject: How can I catch segmentation fault in python? In-Reply-To: <201011171637.45610.wolfgang@rohdewald.de> References: <45ccbf6c-5cc7-422e-88ba-bb4615fe31d5@k5g2000vbn.googlegroups.com> <201011171637.45610.wolfgang@rohdewald.de> Message-ID: <201011171647.16464.wolfgang@rohdewald.de> On Mittwoch 17 November 2010, Wolfgang Rohdewald wrote: > On Mittwoch 17 November 2010, justin wrote: > > But the problem is that the code is not mine, and it takes > > over a day for me to get the point where the segmentation > > fault occurred. Plus, it seems that the point is not > > deterministic > > > > Still, I think I should at least try to figure out exactly > > at which point the segmentation fault occurs, and think > > where to go from there according to your kind advice. > > try valgrind hit the send button too fast... even if the segmentation fault only happens after a long time valgrind might find problems much sooner, and fixing them might remove the segmentation fault. -- Wolfgang From justpark78 at gmail.com Wed Nov 17 11:00:28 2010 From: justpark78 at gmail.com (justin) Date: Wed, 17 Nov 2010 08:00:28 -0800 (PST) Subject: How can I catch segmentation fault in python? References: <45ccbf6c-5cc7-422e-88ba-bb4615fe31d5@k5g2000vbn.googlegroups.com> <201011171637.45610.wolfgang@rohdewald.de> Message-ID: Just checked what is valgrind, sounds promising. Let me try that. Thanks a lot, Justin. On Nov 17, 9:47?am, Wolfgang Rohdewald wrote: > On Mittwoch 17 November 2010, Wolfgang Rohdewald wrote: > > > On Mittwoch 17 November 2010, justin wrote: > > > But the problem is that the code is not mine, and it takes > > > over a day for me to get the point where the segmentation > > > fault occurred. Plus, it seems that the point is not > > > deterministic > > > > Still, I think I should at least try to figure out exactly > > > at which point the segmentation fault occurs, and think > > > where to go from there according to your kind advice. > > > try valgrind > > hit the send button too fast... > > even if the segmentation fault only happens after a long time > valgrind might find problems much sooner, and fixing them > might remove the segmentation fault. > > -- > Wolfgang From mdw at distorted.org.uk Wed Nov 17 11:08:04 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 17 Nov 2010 16:08:04 +0000 Subject: how to use socket to get packet which destination ip is not local? References: <21df438f-9869-4818-bc59-752702e2a203@j1g2000vbl.googlegroups.com> Message-ID: <87r5ekexwb.fsf.mdw@metalzone.distorted.org.uk> Hans writes: > I tried socket bind to 0.0.0.0, but it only binds to any local ip, not > any ip which may not be local. therefore the socket cannot get that > dhcp offer packet even I can use wireshark to see that packet did come > to this pc. You must use a raw socket for this. Raw sockets are fiddly, not very portable, and require privilege. Sorry. -- [mdw] From virbento at gmail.com Wed Nov 17 11:20:34 2010 From: virbento at gmail.com (=?ISO-8859-1?Q?Virg=EDlio_Bento?=) Date: Wed, 17 Nov 2010 16:20:34 +0000 Subject: pySerial Vs 2 Serial Ports Message-ID: Dear all, I Have two modules communicating by Bluetooth. Basically I want to rotate two vector using the accelerometer data. I read the data using pyserial like this: ############################################### ser1 = serial.Serial(port='COM6',baudrate=19200) if ser1.isOpen(): print "Comm 1 is open" ser2 = serial.Serial(port='COM43',baudrate=19200) if ser2.isOpen(): print "Comm 2 is open" ############################################### And then retirieve the raw data in a while loop like this: while True: line1 = ser2.readline() line2 = ser1.readline() ... My problem is the following... when I read from only one module, all goes smooth, but when i try to read from the two modules, the second one that i read retrieves the data with a huge delay. In terms of debug, I tried to run two independent scripts, each one opening and retrieving data from one COM port and there isn't any delay, only when i read the two COM's in the same script i get the delay. Any Clue? Thanks in Advance. Best Regards. -------------- next part -------------- An HTML attachment was scrubbed... URL: From mdw at distorted.org.uk Wed Nov 17 11:31:40 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 17 Nov 2010 16:31:40 +0000 Subject: Some syntactic sugar proposals References: Message-ID: <87mxp7gbdf.fsf.mdw@metalzone.distorted.org.uk> Christopher writes: > i don't like magic names. what about: > > t = foo() as v if pred(v) else default_value This is an improvement on `it'; anaphorics are useful in their place, but they don't seem to fit well with Python. But I don't think that's the big problem with this proposal. The real problem is that it completely changes the evaluation rule for the conditional expression. (The evaluation rule is already pretty screwy: Python is consistently left-to-right -- except here.) Evaluating a conditional expression starts in the middle, by evaluating the condition. If the condition is true, then it evaluates the consequent (to the left); otherwise it evaluates the alternative (to the right). Screwy, but tolerable. The proposal is to evaluate the /consequent/, stash it somewhere, evaluate the condition, and then either output the consequent which we evaluated earlier or the alternative which we must evaluate now. Of course, the implementation must be able to tell which of these evaluation rules to apply. The marker to look for is either `it' (original anaphoric proposal -- this is the real reason why `it' should be a reserved word: its presence radically alters the evaluation rule, so it ought to be a clear syntactic marker) or `as' (as suggested above). Elsewhere in the language, `as' is pretty consistent in what it does: it provides a name for a thing described elsewhere (a `with' context object, or an imported thing) -- but nothing else. It certainly doesn't suggest a change in the way anything else is evaluated. 1/x if x != 0 else None works for any numeric x; it'd be really surprising to me if 1/x as hunoz if x != 0 else None didn't. -1 on this one. -- [mdw] From rbotting at csusb.edu Wed Nov 17 11:32:16 2010 From: rbotting at csusb.edu (RJB) Date: Wed, 17 Nov 2010 08:32:16 -0800 (PST) Subject: Raw Unicode docstring References: Message-ID: <731150d2-929e-4683-8241-fe001e5aaeed@k13g2000vbq.googlegroups.com> On Nov 16, 1:56?pm, Bo?tjan Mejak wrote: > Hello, > > how does one write a raw unicode docstring? If I have backslashes in > the docstring, I must tuck an 'r' in front of it, like this: > r"""This is a raw docstring.""" > > If I have foreign letters in the docstring, I must tuck a 'u' in front > of it, like this: > u"""This is a Unicode docstring.""" > > What if I have foreign characters *and* backslashes in my docstring? > How to write the docstring then? > ru"""My raw unicode docstring.""" > or > ur"""My unicode docstring.""" > > Please answer my question, although it may sound like a noobish one. Thanks. Check out http://cse.csusb.edu/dick/samples/python.syntax.html#stringprefix which lists alternate string prefixes. Does any bodyy know if "ur" and "UR" mean the same thing? From ktenney at gmail.com Wed Nov 17 12:46:11 2010 From: ktenney at gmail.com (Kent Tenney) Date: Wed, 17 Nov 2010 11:46:11 -0600 Subject: Sqlalchemy access to Firefox's places.sqlite Message-ID: Howdy, Lazy, wanting to access Firefox's places.sqlite via Sqlalchemy. How about this: Sqlite Manager -> places.sqlite -> Export Wizard -> table name sqlite_manager this produces file sqlite_manager.sql which looks like: BEGIN TRANSACTION; INSERT INTO "sqlite_master" VALUES('table','moz_bookmarks','moz_bookmarks', 2,'CREATE TABLE moz_bookmarks (id INTEGER PRIMARY KEY,type INTEGER, fk INTEGER DEFAULT NULL, parent INTEGER, position INTEGER, title LONGVARCHAR, keyword_id INTEGER, folder_type TEXT, dateAdded INTEGER, lastModified INTEGER)'); INSERT INTO "sqlite_master" VALUES('index','moz_bookmarks_itemindex', 'moz_bookmarks',3,'CREATE INDEX moz_bookmarks_itemindex ON moz_bookmarks (fk, type)'); ... Is there an easy way to go from this sql to Sqlalchemy code? Thanks, Kent From steve at holdenweb.com Wed Nov 17 13:07:42 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 17 Nov 2010 13:07:42 -0500 Subject: Raw Unicode docstring In-Reply-To: <731150d2-929e-4683-8241-fe001e5aaeed@k13g2000vbq.googlegroups.com> References: <731150d2-929e-4683-8241-fe001e5aaeed@k13g2000vbq.googlegroups.com> Message-ID: On 11/17/2010 11:32 AM, RJB wrote: > On Nov 16, 1:56 pm, Bo?tjan Mejak wrote: >> Hello, >> >> how does one write a raw unicode docstring? If I have backslashes in >> the docstring, I must tuck an 'r' in front of it, like this: >> r"""This is a raw docstring.""" >> >> If I have foreign letters in the docstring, I must tuck a 'u' in front >> of it, like this: >> u"""This is a Unicode docstring.""" >> >> What if I have foreign characters *and* backslashes in my docstring? >> How to write the docstring then? >> ru"""My raw unicode docstring.""" >> or >> ur"""My unicode docstring.""" >> >> Please answer my question, although it may sound like a noobish one. Thanks. > > Check out > http://cse.csusb.edu/dick/samples/python.syntax.html#stringprefix > which lists alternate string prefixes. > > Does any bodyy know if "ur" and "UR" mean the same thing? Yes, they do. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From python at mrabarnett.plus.com Wed Nov 17 13:15:28 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 17 Nov 2010 18:15:28 +0000 Subject: Raw Unicode docstring In-Reply-To: <731150d2-929e-4683-8241-fe001e5aaeed@k13g2000vbq.googlegroups.com> References: <731150d2-929e-4683-8241-fe001e5aaeed@k13g2000vbq.googlegroups.com> Message-ID: <4CE41BC0.2060702@mrabarnett.plus.com> On 17/11/2010 16:32, RJB wrote: > On Nov 16, 1:56 pm, Bo?tjan Mejak wrote: >> Hello, >> >> how does one write a raw unicode docstring? If I have backslashes in >> the docstring, I must tuck an 'r' in front of it, like this: >> r"""This is a raw docstring.""" >> >> If I have foreign letters in the docstring, I must tuck a 'u' in front >> of it, like this: >> u"""This is a Unicode docstring.""" >> >> What if I have foreign characters *and* backslashes in my docstring? >> How to write the docstring then? >> ru"""My raw unicode docstring.""" >> or >> ur"""My unicode docstring.""" >> >> Please answer my question, although it may sound like a noobish one. Thanks. > > Check out > http://cse.csusb.edu/dick/samples/python.syntax.html#stringprefix > which lists alternate string prefixes. > > Does any bodyy know if "ur" and "UR" mean the same thing? I've tried them. It looks like the answer is yes. From awilliam at whitemice.org Wed Nov 17 13:16:43 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Wed, 17 Nov 2010 13:16:43 -0500 Subject: Pickle in a POST/GET request give EOFError In-Reply-To: <4CE3EA61.2090707@audaxis.com> References: <4CE2B599.7050504@audaxis.com> <4CE3EA61.2090707@audaxis.com> Message-ID: <1290017803.3934.0.camel@linux-yu4c.site> On Wed, 2010-11-17 at 15:44 +0100, Romaric DEFAUX wrote: > After entirely rewrite my code to not use Web service but socket (a real > client/server program) I finally found the problem... And it's not > linked to the POST or GET method... > It's because of that : > g.db.escape_string(fields['hosted_web_site']) > (escape_string is the function in MySQLdb library) > It escapes the simple quote of the pickled object, and break it... > It's good to know, NEVER escape a pickled object :) If you are worried about the binary-ness of the pickle string you can base64 encode it (using the base64 module). -- Adam Tauno Williams From bostjan.mejak at gmail.com Wed Nov 17 13:38:18 2010 From: bostjan.mejak at gmail.com (=?UTF-8?Q?Bo=C5=A1tjan_Mejak?=) Date: Wed, 17 Nov 2010 19:38:18 +0100 Subject: Program, Application, and Software Message-ID: What is the difference between a program, an application, and software? From clp2 at rebertia.com Wed Nov 17 13:45:04 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 17 Nov 2010 10:45:04 -0800 Subject: Program, Application, and Software In-Reply-To: References: Message-ID: On Wed, Nov 17, 2010 at 10:38 AM, Bo?tjan Mejak wrote: > What is the difference between a program, an application, and software? (1) This has nothing at all to do with (wx)Python specifically. (2) Did you try consulting Wikipedia?: http://en.wikipedia.org/wiki/Computer_program http://en.wikipedia.org/wiki/Application_software http://en.wikipedia.org/wiki/Computer_software Or did you find the articles somehow lacking or something? Regards, Chris From rbd at hawaii.edu Wed Nov 17 14:29:34 2010 From: rbd at hawaii.edu (Roger Davis) Date: Wed, 17 Nov 2010 11:29:34 -0800 (PST) Subject: strange subprocess behavior when calling ps References: <55f26d5c-aba9-4892-9e2c-1caa9988e7fe@v23g2000vbi.googlegroups.com> Message-ID: <1ed38051-9c8b-4ae8-9a88-9833209d2775@h21g2000vbh.googlegroups.com> > Completely off topic but I think the try clause could be rewritten that way: > ... > Don't use bare except clause, you're masking syntax errors for instance, > which will be flagged as 'unexpected error in generation ...". > In a more general manner, if something unexpected happens it's better to > just let the exception raise uncought. If you want to handle some > errors, meaning you're kindof expecting them then add a explicit clause > (like you did with KeyboardInterrupt). > > JM > > PS : "except Exception :" will catch most of the exceptions (all > inheriting from that class). It's better than using a bare "except :" > clause. (Exception won't catch SyntaxError) Thanks for the suggestion JM, it is off-topic and, although I will first just say that the exception mechanism is *not* one of the reasons I use Python (and stop there with regard to the whole exception mechanism and various usage strategies in general), I do have a few specific questions about a couple of your statements if you don't mind following up. First, inserting a syntax error into my existing code does not hide a SyntaxError exception as you have stated: % cat pid.py #!/usr/bin/python import os import sys import subprocess def main(): psargs= ["/bin/ps", "-e"] try: ps= subprocess.Popen(psargs, stdout=subprocess.PIPE, close_fds=True) psout= ps.communicate()[0] pslines= psout.splitlines() if pslines not good Python talky-talk for line in pslines: print "%s" % line except KeyboardInterrupt: print "Keyboard interrupt received -- terminating." sys.stdout.flush() sys.exit(-1) except: print "%s: unexpected error in generation of system process list" % prognm sys.stdout.flush() sys.exit(-1) main() % ./pid.py File "./pid.py", line 14 if pslines not good Python talky-talk ^ SyntaxError: invalid syntax It appears that the interpreter is catching the syntax error before the code is even executed. Second, python.org's exception hierarchy documentation (Section 6.1 at http://docs.python.org/library/exceptions.html) shows all exception types except SystemExit, KeyboardInterrupt and GeneratorExit as being descendants of Exception. This includes SyntaxError, a child of StandardError which is itself a child of Exception. So, if I say 'except Exception:' then isn't that clause going to process any child exception type of Exception (including SyntaxError) that I haven't already covered in a separate except clause? (Except of course that my interpreter doesn't seem to treat a syntax error as any kind of exception at all!) Finally, and this does not apply to your comments in particular, in researching around about exception handling I often see the usage except Exception, e: suggested, but can't for the life of me figure out what the heck the ', e' part does. Can anybody explain what this means and why it might be desirable (or not)? Thanks! From ph.ton.sharma at gmail.com Wed Nov 17 14:29:54 2010 From: ph.ton.sharma at gmail.com (Ton) Date: Wed, 17 Nov 2010 11:29:54 -0800 (PST) Subject: Help: Guide needed in trying to delete/flush the content of a fifo file. References: <1c7f7feb-ff95-404b-9628-458922360908@j12g2000prm.googlegroups.com> Message-ID: Thanks Mrab ... the way of how to use the pipe for the producer as well as the consumer is a bit confusing to me. As i am using the subprocess for both the producer and the consumer as above. Can you please explain me further using a bit of pseudocode. Thanks for ur concern. In Nov 17, 12:13?am, MRAB wrote: > On 16/11/2010 06:52, Ton wrote: > > > > > On Nov 16, 1:47 am, MRAB ?wrote: > >> On 15/11/2010 11:03, Ton wrote: > > >>> On Nov 14, 11:55 pm, MRAB ? ?wrote: > >>>> On 14/11/2010 14:48, ton ph wrote:> ? ?Hi python geeks, > >>>>> ? ? ?I have ?problem which i have been trying to find out for the past > >>>>> some days, i have a device which feeds info to my fifo continuosly, and > >>>>> a thread of mine reads the > >>>>> fifo continuosly. Now when i change a parameter in the device, it sends > >>>>> me different values. Now my problem is that , i want to get rid of the > >>>>> contents of my previous info which > >>>>> is present in my buffer of the fifo.So i want to flush the fifo content > >>>>> when my device starts sending different info .... i am implementing > >>>>> writing and reading the fifo ?using two different threads. > >>>>> Please someone guide me solving my problem. > >>>>> I highly apologise everyone in case my post is not so clear... > >>>>> Thanks everyone in advance. > > >>>> When the info changes, the thread which is putting items into the fifo > >>>> could flush it just by getting items from it (using a non-blocking get) > >>>> until it's empty. > > >>> Hi Mrab, > >>> ? ?Thanks for your immediate reply , can you please guide me with any > >>> tool or library function which i can flush my fifo content .. i use > >>> os.mkfifo() to make the fifo. Or is there any other way i could do > >>> this ... > >>> Thanks > > >> Ah, you're using pipes; I thought you might've been using a queue. I > >> don't know of a way of flushing a pipe. > > >> I wonder whether it's a good idea for the producer to keep filling the > >> fifo, because the consumer know how 'old' the info is when it arrives, > >> and there's your problem of discarding stale info. Perhaps the producer > >> should wait until the consumer has sent an acknowledgement before > >> sending more info. > > > Thanks Mrab, > > ? ?the problem now is that the producer continously dumps the > > information and since i am implementing the producer using the > > subprocess as like this > > > cmd = ['my files'] > > proc = subprocess.Popen(cmd, shell=True, bufsize=0, > > stdout=subprocess.PIPE, stderr=subprocess.STDOUT ) > > > while flag == True: > > ? ? ? line = proc.stdout.read() > > > Now what i want is to synchronise the problem of actual info the > > device is sending and the proper reading as the device is sending and > > not about reading the previous old info in the fifo... hope i have > > made clearer my prob. even i have tried proc.stdout.flush(), to flush > > the previous old info in the fifo. Thnks > > Use two pipes, one each way. The consumer could use send a message to > the producer requesting an update, which the producer could send back > via the other pipe. Thanks marab for your immediate reply. But how actually i go for using pipes in the producer and consumer is a bit doubtful . can you please explain with a pseudocode ... as in my case both producer and consumer are executed using the subprocess as my previous post.... Thanks From rbd at hawaii.edu Wed Nov 17 14:31:49 2010 From: rbd at hawaii.edu (Roger Davis) Date: Wed, 17 Nov 2010 11:31:49 -0800 (PST) Subject: strange subprocess behavior when calling ps References: <55f26d5c-aba9-4892-9e2c-1caa9988e7fe@v23g2000vbi.googlegroups.com> <61496525-afab-4d19-a7e9-e61fb46e03ef@n30g2000vbb.googlegroups.com> Message-ID: <858e1965-1f27-4d36-9f54-271e9ad8dca3@a12g2000vbc.googlegroups.com> On Nov 16, 11:19?pm, Ned Deily wrote: > Interesting. ?It appears that OS X 10.6 takes into account the ... Thanks very much for your thorough explanation, Ned! I think I've got what I need now. Roger From crebert at ucsd.edu Wed Nov 17 14:43:14 2010 From: crebert at ucsd.edu (Chris Rebert) Date: Wed, 17 Nov 2010 11:43:14 -0800 Subject: strange subprocess behavior when calling ps In-Reply-To: <1ed38051-9c8b-4ae8-9a88-9833209d2775@h21g2000vbh.googlegroups.com> References: <55f26d5c-aba9-4892-9e2c-1caa9988e7fe@v23g2000vbi.googlegroups.com> <1ed38051-9c8b-4ae8-9a88-9833209d2775@h21g2000vbh.googlegroups.com> Message-ID: On Wed, Nov 17, 2010 at 11:29 AM, Roger Davis wrote: >> Completely off topic but I think the try clause could be rewritten that way: >> ... >> Don't use bare except clause, you're masking syntax errors for instance, >> which will be flagged as 'unexpected error in generation ...". >> In a more general manner, if something unexpected happens it's better to >> just let the exception raise uncought. If you want to handle some >> errors, meaning you're kindof expecting them then add a explicit clause >> (like you did with KeyboardInterrupt). >> >> JM >> >> PS : "except Exception :" will catch most of the exceptions (all >> inheriting from that class). It's better than using a bare "except :" >> clause. (Exception won't catch SyntaxError) > > Thanks for the suggestion JM, it is off-topic and, although I will > first just say that the exception mechanism is *not* one of the > reasons I use Python (and stop there with regard to the whole > exception mechanism and various usage strategies in general), I do > have a few specific questions about a couple of your statements if you > don't mind following up. > > First, inserting a syntax error into my existing code does not hide a > SyntaxError exception as you have stated: > % ./pid.py > ?File "./pid.py", line 14 > ? ?if pslines not good Python talky-talk > ? ? ? ? ? ? ? ? ? ? ?^ > SyntaxError: invalid syntax > > It appears that the interpreter is catching the syntax error before > the code is even executed. Now try: # junk.py @#$%^& gibberish @#$%^ # main.py import junk You'll get a run-time SyntaxError. > Finally, and this does not apply to your comments in particular, in > researching around about exception handling I often see the usage > > ? except Exception, e: > > suggested, but can't for the life of me figure out what the heck the > ', e' part does. Can anybody explain what this means and why it might > be desirable (or not)? That's how `except Exception as e` used to be spelled. The exception object will be bound to the variable `e`, allowing you to inspect it further. For example, one might use that form of `except` with an I/O-related exception to be able to check its `errno` attribute in order to handle the error properly. If you're just catching a generic Exception, said form of `except` is less useful. Cheers, Chris -- http://blog.rebertia.com From ladasky at my-deja.com Wed Nov 17 15:49:17 2010 From: ladasky at my-deja.com (John Ladasky) Date: Wed, 17 Nov 2010 12:49:17 -0800 (PST) Subject: Is Unladen Swallow dead? References: <2e1a4d02-1e8a-4d31-95da-f33aaf90578c@30g2000yql.googlegroups.com> Message-ID: On Nov 16, 2:30?pm, laspi wrote: >Is Unladen Swallow dead? No, it's just resting. From rbd at hawaii.edu Wed Nov 17 16:19:50 2010 From: rbd at hawaii.edu (Roger Davis) Date: Wed, 17 Nov 2010 13:19:50 -0800 (PST) Subject: strange subprocess behavior when calling ps References: <55f26d5c-aba9-4892-9e2c-1caa9988e7fe@v23g2000vbi.googlegroups.com> <1ed38051-9c8b-4ae8-9a88-9833209d2775@h21g2000vbh.googlegroups.com> Message-ID: <34b1ad2e-eb79-43dd-b2f5-59f220edd902@j9g2000vbl.googlegroups.com> Thanks for the clarification on exceptions, Chris! Roger From huisky at gmail.com Wed Nov 17 16:45:58 2010 From: huisky at gmail.com (huisky) Date: Wed, 17 Nov 2010 13:45:58 -0800 (PST) Subject: How to read such file and sumarize the data? Message-ID: Say I have following log file, which records the code usage. I want to read this file and do the summarize how much total CPU time consumed for each user. Is Python able to do so or say easy to achieve this?, anybody can give me some hints, appricate very much! Example log file. ************************************************************************************** LSTC license server version 224 started at Sun Dec 6 18:56:48 2009 using configuration file /usr/local/lstc/server_data xyz 15424 at trofast3.marin.ntnu.no LS-DYNA_971 NCPU=1 started Sun Dec 6 18:57:40 15424 at trofast3.marin.ntnu.no completed Sun Dec 6 19:42:55 xyz 15500 at trofast3.marin.ntnu.no LS-DYNA_971 NCPU=2 started Sun Dec 6 20:17:02 15500 at trofast3.marin.ntnu.no completed Sun Dec 6 20:26:03 xyz 18291 at trofast2.marin.ntnu.no LS-DYNA_971 NCPU=1 started Sun Dec 6 21:01:17 18291 at trofast2.marin.ntnu.no completed Sun Dec 6 21:01:28 tanhoi 552 at iimt-tanhoi-w.ivt.ntnu.no LS-DYNA_971 NCPU=1 started Mon Dec 7 09:31:00 552 at iimt-tanhoi-w.ivt.ntnu.no presumed dead Mon Dec 7 10:36:48 sabril 18863 at trofast2.marin.ntnu.no LS-DYNA_971 NCPU=2 started Mon Dec 7 13:14:47 18863 at trofast2.marin.ntnu.no completed Mon Dec 7 13:24:07 sabril 18937 at trofast2.marin.ntnu.no LS-DYNA_971 NCPU=2 started Mon Dec 7 14:21:34 sabril 18969 at trofast2.marin.ntnu.no LS-DYNA_971 NCPU=2 started Mon Dec 7 14:28:42 18969 at trofast2.marin.ntnu.no killed Mon Dec 7 14:31:48 18937 at trofast2.marin.ntnu.no killed Mon Dec 7 14:32:06 From nagle at animats.com Wed Nov 17 17:09:59 2010 From: nagle at animats.com (John Nagle) Date: Wed, 17 Nov 2010 14:09:59 -0800 Subject: Is Unladen Swallow dead? In-Reply-To: References: <2e1a4d02-1e8a-4d31-95da-f33aaf90578c@30g2000yql.googlegroups.com> Message-ID: <4ce452c5$0$1638$742ec2ed@news.sonic.net> On 11/17/2010 12:49 PM, John Ladasky wrote: > On Nov 16, 2:30 pm, laspi wrote: >> Is Unladen Swallow dead? > > No, it's just resting. For those who don't get that, The Monty Python reference: "http://www.mtholyoke.edu/~ebarnes/python/dead-parrot.htm" Owner: Oh yes, the, uh, the Norwegian Blue...What's,uh...What's wrong with it? Mr. Praline: I'll tell you what's wrong with it, my lad. 'E's dead, that's what's wrong with it! Owner: No, no, 'e's uh,...he's resting. Mr. Praline: Look, matey, I know a dead parrot when I see one, and I'm looking at one right now. Owner: No no he's not dead, he's, he's restin'! Remarkable bird, the Norwegian Blue, idn'it, ay? Beautiful plumage! Mr. Praline: The plumage don't enter into it. It's stone dead. Owner: Nononono, no, no! 'E's resting! Mr. Praline: All right then, if he's restin', I'll wake him up! (shouting at the cage) 'Ello, Mister Polly Parrot! I've got a lovely fresh cuttle fish for you if you show... (owner hits the cage) Owner: There, he moved! Mr. Praline: No, he didn't, that was you hitting the cage! Owner: I never!! Mr. Praline: Yes, you did! Owner: I never, never did anything... Mr. Praline: (yelling and hitting the cage repeatedly) 'ELLO POLLY!!!!! Testing! Testing! Testing! Testing! This is your nine o'clock alarm call! (Takes parrot out of the cage and thumps its head on the counter. Throws it up in the air and watches it plummet to the floor.) Mr. Praline: Now that's what I call a dead parrot. (There's more, but you get the idea.) John Nagle From philip at semanchuk.com Wed Nov 17 17:30:21 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 17 Nov 2010 17:30:21 -0500 Subject: Is Unladen Swallow dead? In-Reply-To: <4ce452c5$0$1638$742ec2ed@news.sonic.net> References: <2e1a4d02-1e8a-4d31-95da-f33aaf90578c@30g2000yql.googlegroups.com> <4ce452c5$0$1638$742ec2ed@news.sonic.net> Message-ID: <6843D43E-3586-4D9D-9C70-8B1452734323@semanchuk.com> On Nov 17, 2010, at 5:09 PM, John Nagle wrote: > On 11/17/2010 12:49 PM, John Ladasky wrote: >> On Nov 16, 2:30 pm, laspi wrote: >>> Is Unladen Swallow dead? >> >> No, it's just resting. > > For those who don't get that, The Monty Python reference: > "http://www.mtholyoke.edu/~ebarnes/python/dead-parrot.htm" A link to the source material: http://www.youtube.com/user/montypython?blend=1&ob=4#p/c/6FD5A97331C1B802/0/npjOSLCR2hE -- Cheers Philip From python at mrabarnett.plus.com Wed Nov 17 17:32:38 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 17 Nov 2010 22:32:38 +0000 Subject: How to read such file and sumarize the data? In-Reply-To: References: Message-ID: <4CE45806.7080803@mrabarnett.plus.com> On 17/11/2010 21:45, huisky wrote: > Say I have following log file, which records the code usage. > I want to read this file and do the summarize how much total CPU time > consumed for each user. > Is Python able to do so or say easy to achieve this?, anybody can give > me some hints, appricate very much! > > > Example log file. > ************************************************************************************** > LSTC license server version 224 started at Sun Dec 6 18:56:48 2009 > using configuration file /usr/local/lstc/server_data > xyz 15424 at trofast3.marin.ntnu.no LS-DYNA_971 NCPU=1 started Sun Dec 6 > 18:57:40 > 15424 at trofast3.marin.ntnu.no completed Sun Dec 6 19:42:55 > xyz 15500 at trofast3.marin.ntnu.no LS-DYNA_971 NCPU=2 started Sun Dec 6 > 20:17:02 > 15500 at trofast3.marin.ntnu.no completed Sun Dec 6 20:26:03 > xyz 18291 at trofast2.marin.ntnu.no LS-DYNA_971 NCPU=1 started Sun Dec 6 > 21:01:17 > 18291 at trofast2.marin.ntnu.no completed Sun Dec 6 21:01:28 > tanhoi 552 at iimt-tanhoi-w.ivt.ntnu.no LS-DYNA_971 NCPU=1 started Mon > Dec 7 09:31:00 > 552 at iimt-tanhoi-w.ivt.ntnu.no presumed dead Mon Dec 7 10:36:48 > sabril 18863 at trofast2.marin.ntnu.no LS-DYNA_971 NCPU=2 started Mon > Dec 7 13:14:47 > 18863 at trofast2.marin.ntnu.no completed Mon Dec 7 13:24:07 > sabril 18937 at trofast2.marin.ntnu.no LS-DYNA_971 NCPU=2 started Mon > Dec 7 14:21:34 > sabril 18969 at trofast2.marin.ntnu.no LS-DYNA_971 NCPU=2 started Mon > Dec 7 14:28:42 > 18969 at trofast2.marin.ntnu.no killed Mon Dec 7 14:31:48 > 18937 at trofast2.marin.ntnu.no killed Mon Dec 7 14:32:06 Here's how I would probably do it: Use 2 dicts, one for the start time of each user, and the other for the total elapsed time of each user. For each line extract the user name, date/time and whether the user is starting, finishing, etc. When a user starts, save the info in the first dict, and when a user finishes, calculate the elapsed time and add it to the total for that user. The date/time can be parsed by the time or datetime module. From usernet at ilthio.net Wed Nov 17 17:38:53 2010 From: usernet at ilthio.net (Tim Harig) Date: Wed, 17 Nov 2010 22:38:53 +0000 (UTC) Subject: How to read such file and sumarize the data? References: Message-ID: On 2010-11-17, huisky wrote: > I want to read this file and do the summarize how much total CPU time > consumed for each user. > Is Python able to do so or say easy to achieve this?, anybody can give > me some hints, appricate very much! The question is, is the information you want available in the data. > Example log file. > ************************************************************************************** > LSTC license server version 224 started at Sun Dec 6 18:56:48 2009 > using configuration file /usr/local/lstc/server_data > xyz 15424 at trofast3.marin.ntnu.no LS-DYNA_971 NCPU=1 started Sun Dec 6 > 18:57:40 > 15424 at trofast3.marin.ntnu.no completed Sun Dec 6 19:42:55 > xyz 15500 at trofast3.marin.ntnu.no LS-DYNA_971 NCPU=2 started Sun Dec 6 > 20:17:02 > 15500 at trofast3.marin.ntnu.no completed Sun Dec 6 20:26:03 > xyz 18291 at trofast2.marin.ntnu.no LS-DYNA_971 NCPU=1 started Sun Dec 6 > 21:01:17 > 18291 at trofast2.marin.ntnu.no completed Sun Dec 6 21:01:28 > tanhoi 552 at iimt-tanhoi-w.ivt.ntnu.no LS-DYNA_971 NCPU=1 started Mon > Dec 7 09:31:00 > 552 at iimt-tanhoi-w.ivt.ntnu.no presumed dead Mon Dec 7 10:36:48 > sabril 18863 at trofast2.marin.ntnu.no LS-DYNA_971 NCPU=2 started Mon > Dec 7 13:14:47 > 18863 at trofast2.marin.ntnu.no completed Mon Dec 7 13:24:07 > sabril 18937 at trofast2.marin.ntnu.no LS-DYNA_971 NCPU=2 started Mon > Dec 7 14:21:34 > sabril 18969 at trofast2.marin.ntnu.no LS-DYNA_971 NCPU=2 started Mon > Dec 7 14:28:42 > 18969 at trofast2.marin.ntnu.no killed Mon Dec 7 14:31:48 > 18937 at trofast2.marin.ntnu.no killed Mon Dec 7 14:32:06 I see starts, completes, kills, and presumed deads. The question is can the starts be matched to the completes and kills either from the numbers before @ or from a combination of the address and NCPU. You will need to figure out whether or not you want to count the presumed deads in your calculations. Assuming that the starts and stops can be corrilated, it is a simple matter of finding the pairs and using the datetime module to find the difference in time between them. From usernet at ilthio.net Wed Nov 17 17:49:43 2010 From: usernet at ilthio.net (Tim Harig) Date: Wed, 17 Nov 2010 22:49:43 +0000 (UTC) Subject: How to read such file and sumarize the data? References: Message-ID: On 2010-11-17, MRAB wrote: > When a user starts, save the info in the first dict, and when a user > finishes, calculate the elapsed time and add it to the total for that > user. Perhaps you know more about the structure of this data. It seems to me that a user might have more then a single job(?) running at once. I therefore made the assumption that each start must be matched to its coorisponding stop. From alex.kapps at web.de Wed Nov 17 17:51:01 2010 From: alex.kapps at web.de (Alexander Kapps) Date: Wed, 17 Nov 2010 23:51:01 +0100 Subject: Is Unladen Swallow dead? In-Reply-To: <4ce452c5$0$1638$742ec2ed@news.sonic.net> References: <2e1a4d02-1e8a-4d31-95da-f33aaf90578c@30g2000yql.googlegroups.com> <4ce452c5$0$1638$742ec2ed@news.sonic.net> Message-ID: <4CE45C55.2030802@web.de> On 17.11.2010 23:09, John Nagle wrote: > On 11/17/2010 12:49 PM, John Ladasky wrote: >> On Nov 16, 2:30 pm, laspi wrote: >>> Is Unladen Swallow dead? >> >> No, it's just resting. > > For those who don't get that, The Monty Python reference: > "http://www.mtholyoke.edu/~ebarnes/python/dead-parrot.htm" Thank you John for making my light enough Wallet even lighter, now I have to go and buy the original English version. Seems the German translation sucks (misses a lot) and my copy lacks the original dub. Damned. :-) From steve at holdenweb.com Wed Nov 17 18:10:23 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 17 Nov 2010 18:10:23 -0500 Subject: How to read such file and sumarize the data? In-Reply-To: References: Message-ID: On 11/17/2010 4:45 PM, huisky wrote: > Say I have following log file, which records the code usage. > I want to read this file and do the summarize how much total CPU time > consumed for each user. > Is Python able to do so or say easy to achieve this?, anybody can give > me some hints, appricate very much! > > > Example log file. > ************************************************************************************** I'm assuming the following (unquoted) data is in file "data.txt": > LSTC license server version 224 started at Sun Dec 6 18:56:48 2009 > using configuration file /usr/local/lstc/server_data > xyz 15424 at trofast3.marin.ntnu.no LS-DYNA_971 NCPU=1 started Sun Dec 6 > 18:57:40 > 15424 at trofast3.marin.ntnu.no completed Sun Dec 6 19:42:55 > xyz 15500 at trofast3.marin.ntnu.no LS-DYNA_971 NCPU=2 started Sun Dec 6 > 20:17:02 > 15500 at trofast3.marin.ntnu.no completed Sun Dec 6 20:26:03 > xyz 18291 at trofast2.marin.ntnu.no LS-DYNA_971 NCPU=1 started Sun Dec 6 > 21:01:17 > 18291 at trofast2.marin.ntnu.no completed Sun Dec 6 21:01:28 > tanhoi 552 at iimt-tanhoi-w.ivt.ntnu.no LS-DYNA_971 NCPU=1 started Mon > Dec 7 09:31:00 > 552 at iimt-tanhoi-w.ivt.ntnu.no presumed dead Mon Dec 7 10:36:48 > sabril 18863 at trofast2.marin.ntnu.no LS-DYNA_971 NCPU=2 started Mon > Dec 7 13:14:47 > 18863 at trofast2.marin.ntnu.no completed Mon Dec 7 13:24:07 > sabril 18937 at trofast2.marin.ntnu.no LS-DYNA_971 NCPU=2 started Mon > Dec 7 14:21:34 > sabril 18969 at trofast2.marin.ntnu.no LS-DYNA_971 NCPU=2 started Mon > Dec 7 14:28:42 > 18969 at trofast2.marin.ntnu.no killed Mon Dec 7 14:31:48 > 18937 at trofast2.marin.ntnu.no killed Mon Dec 7 14:32:06 The line wrapping being wrong shouldn't affect the logic. $ cat data.py lines = open("data.txt").readlines() from collections import defaultdict c = defaultdict(int) for line in lines: ls = line.split() if len(ls) > 3 and ls[3].startswith("NCPU="): amt = int(ls[3][5:]) c[ls[0]] += amt for key, value in c.items(): print key, ":", value $ python data.py xyz : 4 tanhoi : 1 sabril : 6 regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From alex.kapps at web.de Wed Nov 17 18:10:56 2010 From: alex.kapps at web.de (Alexander Kapps) Date: Thu, 18 Nov 2010 00:10:56 +0100 Subject: Program, Application, and Software In-Reply-To: References: Message-ID: <4CE46100.4040402@web.de> On 17.11.2010 19:38, Bo?tjan Mejak wrote: > What is the difference between a program, an application, and software? Program: A sequence of one or more instructions (even 'print "hello"' is a valid Python program) Application: Usually a large(er), complex program Software: The parts of a computer that you *can't* kick. From alex.kapps at web.de Wed Nov 17 18:14:46 2010 From: alex.kapps at web.de (Alexander Kapps) Date: Thu, 18 Nov 2010 00:14:46 +0100 Subject: Raw Unicode docstring In-Reply-To: <4a1c5b98-8bf2-4525-b26f-a30b3dcbd6e1@e20g2000vbn.googlegroups.com> References: <4a1c5b98-8bf2-4525-b26f-a30b3dcbd6e1@e20g2000vbn.googlegroups.com> Message-ID: <4CE461E6.8060305@web.de> On 17.11.2010 06:14, John Machin wrote: > On Nov 17, 9:34 am, Alexander Kapps wrote: > >> >>> ur"Schei?t\nderB?r\nim Wald?" > > Nicht ohne eine Genehmigung von der Umwelt Erhaltung Abteilung. The typical response around here is "Ja, aber nur wenn er Klopapier dabei hat." :-D From cs at zip.com.au Wed Nov 17 18:16:28 2010 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 18 Nov 2010 10:16:28 +1100 Subject: strange subprocess behavior when calling ps In-Reply-To: References: Message-ID: <20101117231628.GA12910@cskk.homeip.net> On 16Nov2010 20:18, Ned Deily wrote: | In article | <55f26d5c-aba9-4892-9e2c-1caa9988e7fe at v23g2000vbi.googlegroups.com>, | Roger Davis wrote: | > I am running 2.6.6 under MacOS 10.6.4 on a MacBook Pro Intel. I have | > appended the code below. I am running both commands directly in a | > Terminal window running tcsh. | | See "man compat". What you are seeing is the difference between ps(1) | output in "legacy" mode, attempting to duplicate the old, non-POSIX | behavior from 10.3 days, or "unix2003" mode. Terminal login sessions | are normally automatically started with the COMMAND_MODE environment | variable set: | | $ echo $COMMAND_MODE | unix2003 | | Adding an "env={"COMMAND_MODE": "unix2003"}" argument to your subprocess | Popen call should do the trick. For an added datum, my machine (MacOSX 10.6.5 Intel Macbook Air) says "legacy" instead of "unix2003". -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ I understand a fury in your words, but not your words. - William Shakespeare From nospam at panda.com Wed Nov 17 18:18:44 2010 From: nospam at panda.com (Mark Crispin) Date: Wed, 17 Nov 2010 15:18:44 -0800 Subject: simple(?) Python C module question Message-ID: This is something that ought to be simple, but going through the documentation hasn't come up with the answer. Hopefully someone can answer it faster than I can figure it out from the documentation. I am using Python 2.6 for a project. I do not have a choice in the matter, so telling me to use Python 3.1 is not helpful. [I already wasted a while learning that Python 2.x and Python 3.x are very different, and documentation for the one is lies for the other........] I know relatively little about Python, but am experienced in other OO languages. The OO jargon I'll use in this question is as is used in SmallTalk or perhaps Objective-C (just in case Python uses other jargon). I have a Python module written in C that interfaces with an external C library. Basically, the project is to make it possible to use that library from Python scripts. If you know who I am, you can guess which library. :) I have gotten as far as writing the module, and I can call methods in the module that call the library and do the intended thing. So far, so good. However, I now need to write a method that creates what the library calls a "stream", and I need method calls to work on that stream. The obvious way to do this in any other OO language is to have an object that holds the stream from the library in an instance variable (which actually will be constant for that object instance), and has various object methods for operating on that stream. I assume that the object methods are defined by a PyMethodDef table, just as they are for the module. But how do I: [1] define the object [2] create an instance of the object with the stream and methods [3] hook the object's destruction to a library stream-close function Python does NOT need to look at the stream in any way. Ideally, the object is just a blob that only has method calls. This ought to be simple, and not even require me to know much Python since basically the task is just this module and a few very basic Python scripts to use it. Other people will be writing the real scripts. Of course, I could just have the open method return the stream pointer as a big int, and have module methods that take the stream pointer as their first argument, just as in C code. If I did that, the project would have been done by now. But the result wouldn't be very OO or Pythonish; and more to the point other people will have to use it. I hate when people inflict quick, dirty, stupid, ugly, lazy programmer abominations on me; and so I feel obligated to do it right rather than inflict an abomination on others... :) Thanks in advance for any pointers and/or help. -- Mark -- http://panda.com/mrc Democracy is two wolves and a sheep deciding what to eat for lunch. Liberty is a well-armed sheep contesting the vote. From invalid at invalid.invalid Wed Nov 17 18:35:54 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 17 Nov 2010 23:35:54 +0000 (UTC) Subject: simple(?) Python C module question References: Message-ID: On 2010-11-17, Mark Crispin wrote: Hey, it's the IMAP guy! Get 'im! > I have a Python module written in C that interfaces with an external > C library. Basically, the project is to make it possible to use that > library from Python scripts. If you know who I am, you can guess > which library. :) Have you looked at ctypes? It's not suitable for all libraries, but it can often obviate the need to write any C code: http://docs.python.org/release/2.6.6/library/ctypes.html#module-ctypes -- Grant Edwards grant.b.edwards Yow! I wonder if I should at put myself in ESCROW!! gmail.com From python at mrabarnett.plus.com Wed Nov 17 18:37:23 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 17 Nov 2010 23:37:23 +0000 Subject: How to read such file and sumarize the data? In-Reply-To: References: Message-ID: <4CE46733.6010008@mrabarnett.plus.com> On 17/11/2010 22:49, Tim Harig wrote: > On 2010-11-17, MRAB wrote: >> When a user starts, save the info in the first dict, and when a user >> finishes, calculate the elapsed time and add it to the total for that >> user. > > Perhaps you know more about the structure of this data. It seems to me > that a user might have more then a single job(?) running at once. I > therefore made the assumption that each start must be matched to its > coorisponding stop. I did make certain assumptions. It's up to the OP to adapt it to the actual problem accordingly. :-) From martin at address-in-sig.invalid Wed Nov 17 18:38:58 2010 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Wed, 17 Nov 2010 23:38:58 +0000 (UTC) Subject: How to read such file and sumarize the data? References: Message-ID: On Wed, 17 Nov 2010 13:45:58 -0800, huisky wrote: > Say I have following log file, which records the code usage. I want to > read this file and do the summarize how much total CPU time consumed for > each user. > Two points you should think about: - I don't think you can extract CPU time from this log: you can get the process elapsed time and the number of CPUs each run has used, but you can't calculate CPU time from those values since you don't know how the process spent waiting for i/o etc. - is the first (numeric) part of the first field on the line a process id? If it is, you can match start and stop messages on the value of the first field provided that this value can never be shared by two processes that are both running. If you can get simultaneous duplicates, then you're out of luck because you'll never be able to match up start and stop lines. > Is Python able to do so or say easy to achieve this?, anybody can give > me some hints, appricate very much! > Sure. There are two approaches possible: - sort the log on the first two fields and then process it with Python knowing that start and stop lines will be adjacent - use the first field as the key to an array and put the start time and CPU count in that element. When a matching stop line is found you, retrieve the array element, calculate and output or total the usage figure for that run and delete the array element. -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From robert.kern at gmail.com Wed Nov 17 18:39:43 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 17 Nov 2010 17:39:43 -0600 Subject: Is Unladen Swallow dead? In-Reply-To: <4CE45C55.2030802@web.de> References: <2e1a4d02-1e8a-4d31-95da-f33aaf90578c@30g2000yql.googlegroups.com> <4ce452c5$0$1638$742ec2ed@news.sonic.net> <4CE45C55.2030802@web.de> Message-ID: On 11/17/10 4:51 PM, Alexander Kapps wrote: > On 17.11.2010 23:09, John Nagle wrote: >> On 11/17/2010 12:49 PM, John Ladasky wrote: >>> On Nov 16, 2:30 pm, laspi wrote: >>>> Is Unladen Swallow dead? >>> >>> No, it's just resting. >> >> For those who don't get that, The Monty Python reference: >> "http://www.mtholyoke.edu/~ebarnes/python/dead-parrot.htm" > > Thank you John for making my light enough Wallet even lighter, now I have to go > and buy the original English version. Seems the German translation sucks (misses > a lot) and my copy lacks the original dub. They're all (legitimately) on Youtube now. http://www.youtube.com/watch?v=npjOSLCR2hE -- 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 martin at address-in-sig.invalid Wed Nov 17 18:43:27 2010 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Wed, 17 Nov 2010 23:43:27 +0000 (UTC) Subject: Is Unladen Swallow dead? References: <2e1a4d02-1e8a-4d31-95da-f33aaf90578c@30g2000yql.googlegroups.com> <4ce452c5$0$1638$742ec2ed@news.sonic.net> Message-ID: On Wed, 17 Nov 2010 23:51:01 +0100, Alexander Kapps wrote: > On 17.11.2010 23:09, John Nagle wrote: >> On 11/17/2010 12:49 PM, John Ladasky wrote: >>> On Nov 16, 2:30 pm, laspi wrote: >>>> Is Unladen Swallow dead? >>> >>> No, it's just resting. >> >> For those who don't get that, The Monty Python reference: >> "http://www.mtholyoke.edu/~ebarnes/python/dead-parrot.htm" > > Thank you John for making my light enough Wallet even lighter, now I > have to go and buy the original English version. Seems the German > translation sucks (misses a lot) and my copy lacks the original dub. > While you're at it, pick up the video of "Monty Python and the Holy Grail". the project name, Unladen Swallow, is a reference to the film. -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From gelonida at gmail.com Wed Nov 17 18:50:06 2010 From: gelonida at gmail.com (Gelonida) Date: Thu, 18 Nov 2010 00:50:06 +0100 Subject: first attempts with pybluez on Linux fail as well Message-ID: Hi, Wanted to write a first simple example with pybluez and offer a serial connection service with a given name. What I tried (being inspired by http://people.csail.mit.edu/albert/bluez-intro/x290.html ) is: server_sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM ) port = bluetooth.PORT_ANY # original example used get_available_port() # buy this seems obsolete server_sock.bind(("",port)) server_sock.listen(1) print "listening on port %d" % port loc_host, loc_port = server_sock.getsockname() print "HOST", loc_host, "PORT??", loc_port uuid = "1e0ca4ea-299d-4335-93eb-27fcfe7fa848" bluetooth.advertise_service( server_sock, "FooBar Service", uuid ) Unde Linux the file does not produce an error message, but When I use another PC to look for services I do NOT see the service "FooBar Service" What might I be doing wrong? Are there any special requirements on the buetooth dongle / bluetooth stack to make abov example work? Thanks a lot for your help. From clp2 at rebertia.com Wed Nov 17 18:57:21 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 17 Nov 2010 15:57:21 -0800 Subject: simple(?) Python C module question In-Reply-To: References: Message-ID: On Wed, Nov 17, 2010 at 3:18 PM, Mark Crispin wrote: > I have a Python module written in C that interfaces with an external C > library. ?Basically, the project is to make it possible to use that library > from Python scripts. ?If you know who I am, you can guess which library. ?:) > > I have gotten as far as writing the module, and I can call methods in the > module that call the library and do the intended thing. ?So far, so good. > > However, I now need to write a method that creates what the library calls a > "stream", and I need method calls to work on that stream. > > The obvious way to do this in any other OO language is to have an object > that holds the stream from the library in an instance variable (which > actually will be constant for that object instance), and has various object > methods for operating on that stream. > > I assume that the object methods are defined by a PyMethodDef table, just as > they are for the module. ?But how do I: > ?[1] define the object > ?[2] create an instance of the object with the stream and methods > ?[3] hook the object's destruction to a library stream-close function > > Python does NOT need to look at the stream in any way. ?Ideally, the object > is just a blob that only has method calls. > Of course, I could just have the open method return the stream pointer as a > big int, and have module methods that take the stream pointer as their first > argument, just as in C code. ?If I did that, the project would have been > done by now. ?But the result wouldn't be very OO or Pythonish; and more to > the point other people will have to use it. ?I hate when people inflict > quick, dirty, stupid, ugly, lazy programmer abominations on me; and so I > feel obligated to do it right rather than inflict an abomination on > others... ?:) > > Thanks in advance for any pointers and/or help. Definitely not a direct answer to your questions, but you might consider using SWIG (http://www.swig.org/Doc1.3/Python.html ); haven't used it myself, but I've generally heard good things about it. Ironically, from the docs, it seems the C modules it generates approximately use your "abomination" approach (except the pointer is at least stored as an opaque object rather than an int); however, importantly, it also generates a .py module with appropriate nice wrapper classes to wrap the function calls as much more natural method calls. So, directly using your "abomination" approach and then manually writing a wrapper class in Python itself is also another option. Cheers, Chris -- http://blog.rebertia.com From davidreynon at gmail.com Wed Nov 17 19:02:05 2010 From: davidreynon at gmail.com (dave) Date: Wed, 17 Nov 2010 16:02:05 -0800 (PST) Subject: Using Python and Connecting to MySQL remotely WITHOUT MySQL installed on local computer Message-ID: http://sourceforge.net/projects/mysql-python/ Using this package, WITHOUT having MySQL installed on my Mac OS X, how can I use python to connect to a remote MySQL server? All of the tutorials mention having to download MySQL! From mdw at distorted.org.uk Wed Nov 17 19:18:44 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 18 Nov 2010 00:18:44 +0000 Subject: simple(?) Python C module question References: Message-ID: <87tyjfeb6j.fsf.mdw@metalzone.distorted.org.uk> Mark Crispin writes: > I have a Python module written in C that interfaces with an external C > library. Basically, the project is to make it possible to use that > library from Python scripts. If you know who I am, you can guess > which library. :) You have your very own Wikipedia page, so others probably needn't guess. > However, I now need to write a method that creates what the library calls a > "stream", and I need method calls to work on that stream. > > The obvious way to do this in any other OO language is to have an > object that holds the stream from the library in an instance variable > (which actually will be constant for that object instance), and has > various object methods for operating on that stream. Yeah, that's pretty much the way it works in Python, though it's a bit more tedious. (I suppose it's too late to suggest using Cython now. It makes this sort of thing much less unpleasant.) > I assume that the object methods are defined by a PyMethodDef table, > just as they are for the module. But how do I: > [1] define the object You need two things here: a C structure to represent the innards of your custom Python type, and a Python type block (a PyTypeObject) providing everything the Python interpreter needs to know about it. The C structure can be pretty much whatever you like, as long as it begins with the macro PyObject_HEAD: typedef struct thingy { PyObject_HEAD /* your stuff here; maybe: */ stream *s; } thingy; The PyTypeObject is big and boring to fill in but you can probably leave most of it null. The structure is described in the Python API manual, but I think you'll need to fill in: * a name for the type (qualified by your module's name; tp_name); * the object size (sizeof(thingy); tp_basicsize); * a deallocation function (tp_dealloc); * some flags (you probably want Py_TPFLAGS_DEFAULT and maybe Py_TPFLAGS_BASETYPE if you don't mind people making subclasses; tp_flags); * a string to be shown to the user if he asks for help about your type (tp_doc); * a pointer to a methods table (tp_methods); * a pointer to a table of attribute getters and setters (if you want to expose stuff as attributes rather than methods; tp_getset); * an allocator (probably PyType_GenericAlloc; tp_alloc); and * a function to construct a new instance (to be called when Python tries to construct an object by calling the type -- leave it null if you construct instances in some other way; tp_new). You might also want to implement the tp_str function to provide useful information about your object's state (e.g., for debugging scripts). There are some standard protocols which might be useful to implement; it doesn't sound like your streams would benefit from behaving like numbers or sequences, but maybe they might be iterable. You attach methods on the type by mentioning them in the PyMethodDef table you set in tp_methods; they get a pointer to the recipient object (a `thingy' as above) so they can find the underlying stream if they want. Getters and setters are pretty similar, but have a simpler interface because they don't need to mess with argument parsing.. > [2] create an instance of the object with the stream and methods If you want Python programs to be able to make streams by saying stream = mumble.stream(...) or whatever then you'll need to implement tp_new: this is pretty much like a standard method, except it gets a pointer to a PyTypeObject to tell it what kind of type to make. (The constructor may be called to construct a subclass of your type.) Parse the arguments and check that they're plausible; then make a new skeleton instance by t = (thingy *)ty->tp_alloc(ty, 0); (where ty is the type pointer you received), fill in your bits, and return (PyObject *)t. Otherwise, well, you go through the same procedure with tp_alloc, only you know which type you want statically. > [3] hook the object's destruction to a library stream-close function This is the tp_dealloc function. It should free up any of your resources, and then say obj->ob_type->tp_free(obj); Python will have arranged for this function to exist if you left tp_free as a null pointer. > Python does NOT need to look at the stream in any way. Ideally, the > object is just a blob that only has method calls. That's what you get anyway, if you use the C API. If you want Python programs to be able to poke about inside your objects, you have to let them explicitly, and that means writing code. > This ought to be simple, and not even require me to know much Python > since basically the task is just this module and a few very basic > Python scripts to use it. Other people will be writing the real > scripts. It doesn't require you to know any Python at all. It /does/ require a certain familiarity with the implementation, though. > Of course, I could just have the open method return the stream pointer > as a big int, and have module methods that take the stream pointer as > their first argument, just as in C code. I don't think Python programmers would thank you for this kind of obviously unsafe implementation; so you already have my gratitude for trying to do the job properly. I know that it's somewhat tedious. And consider giving Cython a look. -- [mdw] From usernet at ilthio.net Wed Nov 17 19:21:54 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 18 Nov 2010 00:21:54 +0000 (UTC) Subject: Using Python and Connecting to MySQL remotely WITHOUT MySQL installed on local computer References: Message-ID: On 2010-11-18, dave wrote: > http://sourceforge.net/projects/mysql-python/ > > Using this package, WITHOUT having MySQL installed on my Mac OS X, how > can I use python to connect to a remote MySQL server? > > All of the tutorials mention having to download MySQL! You don't have to install all of MySQL, just the client libraries. I would assume that almost every MySQL connector uses these libraries; but, you might see if the MySQL-ODBC connector will work without them. It is a long shot. Your last option would be to recreate your own connector without using the MySQL client libraries. I am not really sure what the purpose of reinventing this wheel would be. From nospam at panda.com Wed Nov 17 19:25:54 2010 From: nospam at panda.com (Mark Crispin) Date: Wed, 17 Nov 2010 16:25:54 -0800 Subject: simple(?) Python C module question In-Reply-To: References: Message-ID: On Wed, 17 Nov 2010, Grant Edwards posted: > Hey, it's the IMAP guy! Get 'im! Busted! :p Alright, here's the full story. As may be obvious to some, the module is to be a Python interface into c-client. What may not be obvious is that this is for QA automation. The consumers of this module will know Python but not necessarily C and certainly not c-client. Right now the module is called cclient but that will certainly change. So, I have methods such as cclient.create that in my module look like: static PyObject *cclient_create(PyObject *self, PyObject *args) { char *mailbox; PyObject *ret = NULL; if(PyArg_ParseTuple(args, "s", &mailbox)) ret = Py_BuildValue("i", mail_create(NULL, mailbox)); return ret; } and indeed within Python cclient.create("testbox") creates "testbox" as expected. A bunch of other methods are the same. Now, however, I need cclient.open, and expect to do something like: static PyObject *cclient_create(PyObject *self, PyObject *args) { char *mailbox; MAILSTREAM *stream; PyObject *ret = NULL; if(PyArg_ParseTuple(args, "s", &mailbox) && (stream = mail_open(NULL, mailbox, 0))) { ret = ???; // set ret to a "cclient stream" object that has "stream" as // an instance variable, and a method table, presumably via // PyMethodDef, for this "cclient stream" object. } return ret; } So, if in Python, I do something like: stream = cclient.open("testbox") print stream.uid(1) I expect that to call an method like static PyObject *cclient_create(PyObject *self, PyObject *args) { long sequence; MAILSTREAM *stream = ???; // get stream from self PyObject *ret = NULL; if(PyArg_ParseTuple(args, "l", &sequence)) ret = Py_BuildValue("i", mail_uid(stream, sequence)); return ret; } So, basically, what I'm missing are the two "???" things above, plus how to make this "cclient stream" object call mail_close(stream). In SmallTalk or Objective C, the method table would be defined as part of a factory object that has a "new" factory method that in my case would take "stream" as an argument and set it as the instance method. Then to get the stream, I'd do something like stream = [self getStream]; > Have you looked at ctypes? It's not suitable for all libraries, but > it can often obviate the need to write any C code: > http://docs.python.org/release/2.6.6/library/ctypes.html#module-ctypes Hmm. I don't think that it helps, especially as I don't really want to make the consumers of this module know anything about c-client or its calling conventions. Thanks for any clues... -- Mark -- http://panda.com/mrc Democracy is two wolves and a sheep deciding what to eat for lunch. Liberty is a well-armed sheep contesting the vote. From debatem1 at gmail.com Wed Nov 17 19:28:39 2010 From: debatem1 at gmail.com (geremy condra) Date: Wed, 17 Nov 2010 16:28:39 -0800 Subject: simple(?) Python C module question In-Reply-To: References: Message-ID: On Wed, Nov 17, 2010 at 3:35 PM, Grant Edwards wrote: > On 2010-11-17, Mark Crispin wrote: > > Hey, it's the IMAP guy! ?Get 'im! > >> I have a Python module written in C that interfaces with an external >> C library. ?Basically, the project is to make it possible to use that >> library from Python scripts. ?If you know who I am, you can guess >> which library. ?:) > > Have you looked at ctypes? ?It's not suitable for all libraries, but > it can often obviate the need to write any C code: > > ?http://docs.python.org/release/2.6.6/library/ctypes.html#module-ctypes This. You may also want to check out [0] and [1], which use ctypes and generally make short work of writing C bindings. For a more complete example, see [2]. Geremy Condra [0]: http://code.activestate.com/recipes/576731-c-function-decorator/ [1]: http://code.activestate.com/recipes/576734-c-struct-decorator/ [2]: http://gitorious.org/evpy From ben+python at benfinney.id.au Wed Nov 17 19:28:50 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 18 Nov 2010 11:28:50 +1100 Subject: Program, Application, and Software References: Message-ID: <87hbffa30d.fsf@benfinney.id.au> Alexander Kapps writes: > On 17.11.2010 19:38, Bo?tjan Mejak wrote: > > What is the difference between a program, an application, and > > software? Alexander's guide is good. Some notes from a native speaker of English: > Program: A sequence of one or more instructions (even 'print "hello"' > is a valid Python program) Some like to sub-divide ?script? as a type of program; I don't see the point, and refer to such things as programs. > Application: Usually a large(er), complex program An application might also be several programs working together, along with the non-program software they use to do their jobs: e.g. ?LibreOffice is an application consisting of many programs, data sets, libraries, images, document templates, and other software?. > Software: The parts of a computer that you *can't* kick. It's worth noting a common error of non-native English users: ?software? is an uncountable noun, like ?hardware?. This is unlike ?program? and ?application?, both of which are countable. So it makes no more sense to speak of ?a software? than ?a clothing?; both are wrong. If you want to refer to countable items, ?a software work? is acceptable if you want to refer generically to a work of digitally-stored information. Otherwise be more precise: a software work might be ?a document?, ?an image?, ?an audio recording?, ?a program?, ?a database?, et cetera. Hope that helps. -- \ ?It's my belief we developed language because of our deep inner | `\ need to complain.? ?Jane Wagner, via Lily Tomlin | _o__) | Ben Finney From mdw at distorted.org.uk Wed Nov 17 19:39:33 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 18 Nov 2010 00:39:33 +0000 Subject: Program, Application, and Software References: Message-ID: <87pqu3ea7u.fsf.mdw@metalzone.distorted.org.uk> Alexander Kapps writes: > Application: Usually a large(er), complex program I'd say that an `application' is specifically a program intended for direct human use. Other things are servers, daemons and utilities. But I might just be weird. -- [mdw] From nospam at panda.com Wed Nov 17 19:45:38 2010 From: nospam at panda.com (Mark Crispin) Date: Wed, 17 Nov 2010 16:45:38 -0800 Subject: simple(?) Python C module question In-Reply-To: <87tyjfeb6j.fsf.mdw@metalzone.distorted.org.uk> References: <87tyjfeb6j.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On Thu, 18 Nov 2010, Mark Wooding posted: > [snip] Whoo-hoo! That's exactly what I was looking for. If we ever meet in person, I owe you a beer, sir. And by that I mean real beer (from what we call a "microbrew"), not Budweiser... :) -- Mark -- http://panda.com/mrc Democracy is two wolves and a sheep deciding what to eat for lunch. Liberty is a well-armed sheep contesting the vote. From python.list at tim.thechases.com Wed Nov 17 19:49:56 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 17 Nov 2010 18:49:56 -0600 Subject: Program, Application, and Software In-Reply-To: <4CE46100.4040402@web.de> References: <4CE46100.4040402@web.de> Message-ID: <4CE47834.2030702@tim.thechases.com> On 11/17/2010 05:10 PM, Alexander Kapps wrote: > On 17.11.2010 19:38, Bo?tjan Mejak wrote: >> What is the difference between a program, an application, and software? > > Software: The parts of a computer that you *can't* kick. Programmer: the part that usually gets kicked... -tkc From tjreedy at udel.edu Wed Nov 17 19:51:56 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 17 Nov 2010 19:51:56 -0500 Subject: How to read such file and sumarize the data? In-Reply-To: References: Message-ID: On 11/17/2010 6:10 PM, Steve Holden wrote: > $ cat data.py > lines = open("data.txt").readlines() Since you iterate through the file just once, there is no reason I can think of to make a complete in-memory copy. That would be a problem with a multi-gigabyte log file ;=). In 3.x at least, open files are line iterators and one would just need lines = open("data.txt") > from collections import defaultdict > c = defaultdict(int) > for line in lines: > ls = line.split() > if len(ls)> 3 and ls[3].startswith("NCPU="): > amt = int(ls[3][5:]) > c[ls[0]] += amt > for key, value in c.items(): > print key, ":", value > > > $ python data.py > xyz : 4 > tanhoi : 1 > sabril : 6 > > regards > Steve -- Terry Jan Reedy From python at mrabarnett.plus.com Wed Nov 17 20:16:34 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 18 Nov 2010 01:16:34 +0000 Subject: Program, Application, and Software In-Reply-To: <87hbffa30d.fsf@benfinney.id.au> References: <87hbffa30d.fsf@benfinney.id.au> Message-ID: <4CE47E72.7070802@mrabarnett.plus.com> On 18/11/2010 00:28, Ben Finney wrote: > Alexander Kapps writes: > >> On 17.11.2010 19:38, Bo?tjan Mejak wrote: >>> What is the difference between a program, an application, and >>> software? > > Alexander's guide is good. Some notes from a native speaker of English: > >> Program: A sequence of one or more instructions (even 'print "hello"' >> is a valid Python program) > > Some like to sub-divide ?script? as a type of program; I don't see the > point, and refer to such things as programs. > [snip] I'd probably say that a "script" is a program which is normally not interactive: you just set it up, start it, and let it do its work (a "batch script", for example). It's also written in a language primarily designed for convenience rather than speed (Want to manipulate large chunks of text? Fine! :-)). From steve at holdenweb.com Wed Nov 17 21:14:03 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 17 Nov 2010 21:14:03 -0500 Subject: How to read such file and sumarize the data? In-Reply-To: References: Message-ID: On 11/17/2010 7:51 PM, Terry Reedy wrote: > On 11/17/2010 6:10 PM, Steve Holden wrote: > >> $ cat data.py >> lines = open("data.txt").readlines() > > Since you iterate through the file just once, there is no reason I can > think of to make a complete in-memory copy. That would be a problem with > a multi-gigabyte log file ;=). In 3.x at least, open files are line > iterators and one would just need > You are indeed perfectly correct. Thank you. Probably old-ingrained habits showing through. Open files have been line iterators since 2.2, I believe. regards Steve > lines = open("data.txt") > >> from collections import defaultdict >> c = defaultdict(int) >> for line in lines: >> ls = line.split() >> if len(ls)> 3 and ls[3].startswith("NCPU="): >> amt = int(ls[3][5:]) >> c[ls[0]] += amt >> for key, value in c.items(): >> print key, ":", value >> >> >> $ python data.py >> xyz : 4 >> tanhoi : 1 >> sabril : 6 >> >> regards >> Steve > > -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Wed Nov 17 21:24:22 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 17 Nov 2010 21:24:22 -0500 Subject: Using Python and Connecting to MySQL remotely WITHOUT MySQL installed on local computer In-Reply-To: References: Message-ID: On 11/17/2010 7:21 PM, Tim Harig wrote: > On 2010-11-18, dave wrote: >> http://sourceforge.net/projects/mysql-python/ >> >> Using this package, WITHOUT having MySQL installed on my Mac OS X, how >> can I use python to connect to a remote MySQL server? >> >> All of the tutorials mention having to download MySQL! > > You don't have to install all of MySQL, just the client libraries. I would > assume that almost every MySQL connector uses these libraries; but, you > might see if the MySQL-ODBC connector will work without them. It is a long > shot. Your last option would be to recreate your own connector without > using the MySQL client libraries. I am not really sure what the purpose of > reinventing this wheel would be. I believe that the coming trend is to implement the MySQL client protocol directly in Python, thereby obviating the need for any MySQL client installation on the machine hosting the Python code. The pymysql project at http://code.google.com/p/pymysql/ is one such solution, aimed at satisfying Python 3 users without the need to port existing low-level client code. As an irrelevance might I also add that the trend for built-in extension modules is to require a reference implementation in Python to ease the task of those wishing to port the language and get as much functionality (albeit at some performance in cost) available as early in the porting cycle as possible. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From cs at zip.com.au Wed Nov 17 21:58:49 2010 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 18 Nov 2010 13:58:49 +1100 Subject: returning results from function In-Reply-To: References: Message-ID: <20101118025849.GA17150@cskk.homeip.net> On 11Nov2010 15:29, Chris Rebert wrote: | > On Nov 11, 2010, at 1:54 PM, Chris Rebert wrote: | >> On Thu, Nov 11, 2010 at 1:16 PM, Neil Berg wrote: | >> time_y = ncfile.variables['time_y'][:] # (time,int) [yrs] | >> time_m = ncfile.variables['time_m'][:] # (time,int) [mnths] | >> time_d = ncfile.variables['time_d'][:] # (time,int) [days] | >> time_h = ncfile.variables['time_h'][:] ? ?# (time,float) [hrs] | >> ntim =len(time_h) | >> for tim_idx in range(0,ntim): | >> ? ? ? ?local_date = utc_to_local(time_y[tim_idx],time_m[tim_idx],time_d[tim_idx],int(time_h[tim_idx])) | >> ? ? ? ?***Here is where I'd like to see the returned values so I can create new arrays that store them ***** | | Add: | print(local_date) | Or if you want to be fancy: | print("%.4d-%.2d-%.2d %.2d" % local_date) It's worth noting that if you know the number of return arguments you can do this: locyr, locmm, locdd, lochh = itc_to_local(.......) and then easily use the individual values. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Admit Nothing. Blame Everyone. Be Bitter. - Matt Hopkins, DoD #1197, From usernet at ilthio.net Wed Nov 17 22:19:16 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 18 Nov 2010 03:19:16 +0000 (UTC) Subject: Using Python and Connecting to MySQL remotely WITHOUT MySQL installed on local computer References: Message-ID: On 2010-11-18, Steve Holden wrote: > On 11/17/2010 7:21 PM, Tim Harig wrote: >> On 2010-11-18, dave wrote: >>> http://sourceforge.net/projects/mysql-python/ >>> >>> Using this package, WITHOUT having MySQL installed on my Mac OS X, how >>> can I use python to connect to a remote MySQL server? >>> >>> All of the tutorials mention having to download MySQL! >> >> You don't have to install all of MySQL, just the client libraries. I would >> assume that almost every MySQL connector uses these libraries; but, you >> might see if the MySQL-ODBC connector will work without them. It is a long >> shot. Your last option would be to recreate your own connector without >> using the MySQL client libraries. I am not really sure what the purpose of >> reinventing this wheel would be. > > I believe that the coming trend is to implement the MySQL client > protocol directly in Python, thereby obviating the need for any MySQL > client installation on the machine hosting the Python code. One of the advantages to using the MySQL supplied library is that if the line protocol changes the connector automatically inherits the work already done by MySQL for the price of a stable API (yes, I am aware that the MySQL API *has* changed through the years). That could be very relevant in the near future as the probject settles its stable forks. > The pymysql project at http://code.google.com/p/pymysql/ is one such > solution, aimed at satisfying Python 3 users without the need to port > existing low-level client code. That still looks like alpha code. Would you be willing to make a statement as to its stability? From tundra at tundraware.com Wed Nov 17 22:39:44 2010 From: tundra at tundraware.com (Tim Daneliuk) Date: Wed, 17 Nov 2010 21:39:44 -0600 Subject: [ANN]: 'tren' Cross-Platform Batch Renaming Tool, Version 1.239 Released Message-ID: <0pjer7-5ag1.ln1@ozzie.tundraware.com> 'tren' Version 1.239 is now released and available for download at: http://www.tundraware.com/Software/tren The last public release was 1.217. --------------------------------------------------------------------- What's New In This Release? --------------------------- This release fixes several critical bugs and adds a number of new features. Existing users are urged to upgrade at their earliest opportunity: FIXED: Backups weren't being improperly named. FIXED: Changed TREN envvar processing to properly parse quoting. FIXED: Each renaming target must either be something that exists or a wildcard that expands to something that exists. Formerly, nonexistent renaming targets were silently ignored. NEW: Debug now shows the incremental change to each file name as each renaming request is applied left-to-right. Use -dq to see this more clearly. NEW: The environment variable TRENINCL is now supported. This allows you to specify a path to search when looking for include files. NEW: Implemented /NAMESOFAR/ renaming token. NEW: Added -e type case conversion option - new kind of renaming request. c - Capitalize l - Lower s - Swap case t - Title -> Char's followiing non-alpha are capitalized u - Upper NEW: Added -T option to allow user to "target" a substring of the full filename for renaming OTHER: Documentation additions and updates including clarification of old features, description of new features, and improved table-of-contents for PDF and PS document formats. What Is 'tren'? ------------------ 'tren' is a general purpose file and directory renaming tool. Unlike commands like 'mv', 'tren' is particularly well suited for renaming *batches* of files and/or directories with a single command line invocation. 'tren' eliminates the tedium of having to script simpler tools to provide higher-level renaming capabilities. 'tren' is also adept at renaming only *part of an existing file or directory name* either based on a literal string or a regular expression pattern. You can replace any single, group, or all instances of a given string in a file or directory name. 'tren' implements the idea of a *renaming token*. These are special names you can embed in your renaming requests that represent things like the file's original name, its length, date of creation, and so on. There are even renaming tokens that will substitute the content of any environment variable or the results of running a program from a shell back into the new file name. 'tren' can automatically generate *sequences* of file names based on their dates, lengths, times within a given date, and so on. In fact, sequences can be generated on the basis of any of the file's 'stat' information. Sequence "numbers" can be ascending or descending and the count can start at any initial value. Counting can take place in one of several internally defined counting "alphabets" (decimal, hex, octal, alpha, etc.) OR you can define your own counting alphabet. This allows you to create sequences in any base (2 or higher please :) using any symbol set for the count. 'tren' is written in pure Python and requires Python version 2.6.x or later. It is known to run on various Unix-like variants (FreeBSD, Linux, MacOS X) as well as Windows. It will also take advantage of 'win32all' Python extensions on a Windows system, if they are present. --------------------------------------------------------------------- Complete details of all fixes, changes, and new features can be found in the WHATSNEW.txt and documentation files included in the distribution. A FreeBSD port has been submitted as well. From tjreedy at udel.edu Wed Nov 17 22:42:06 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 17 Nov 2010 22:42:06 -0500 Subject: simple(?) Python C module question In-Reply-To: References: Message-ID: On 11/17/2010 7:25 PM, Mark Crispin wrote: >> Have you looked at ctypes? It's not suitable for all libraries, but >> it can often obviate the need to write any C code: >> http://docs.python.org/release/2.6.6/library/ctypes.html#module-ctypes > > Hmm. I don't think that it helps, especially as I don't really want to > make the consumers of this module know anything about c-client or its > calling conventions. For the record, a C library wrapper written in Python with cytpes is nearly indistinguishable to users from an equivalent wrapper written in C. However, given that you are more comfortable with C than Python and have gotten the info you need, stick with that. -- Terry Jan Reedy From noydb00 at gmail.com Wed Nov 17 22:47:58 2010 From: noydb00 at gmail.com (noydb) Date: Wed, 17 Nov 2010 19:47:58 -0800 (PST) Subject: How to run an EXE, with argument, capture output value Message-ID: <37037d15-63da-4f37-9508-bdcfff034670@s4g2000yql.googlegroups.com> Hello All, I would appreciate some guidance on this. I'm a newbe, sorry if I sound dumb - I kind of am on this stuff! I have an executable that I want to run within python code. The exe requires an input text file, the user to click a 'compute' button, and then the exe calculates several output values, one of which I want to capture into a variable. Can I use Python to supply the input file, execute the exe and capture the output value, like such that the exe really doesn't need to be 'seen'? Or, would the user still have to click the 'compute' button? Any code snippets or guidance would be very much appreciated. I have found that import os os.system('C:\xTool\stats_hall.exe') will run the exe. And, maybe these execl/execle/execlp/etc functions might be what I need for adding in the argument, but documentation seems to indicate that these do not return output. ?? Thanks much. From steve at holdenweb.com Wed Nov 17 23:19:49 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 17 Nov 2010 23:19:49 -0500 Subject: Using Python and Connecting to MySQL remotely WITHOUT MySQL installed on local computer In-Reply-To: References: Message-ID: On 11/17/2010 10:19 PM, Tim Harig wrote: > On 2010-11-18, Steve Holden wrote: >> On 11/17/2010 7:21 PM, Tim Harig wrote: >>> On 2010-11-18, dave wrote: >>>> http://sourceforge.net/projects/mysql-python/ >>>> >>>> Using this package, WITHOUT having MySQL installed on my Mac OS X, how >>>> can I use python to connect to a remote MySQL server? >>>> >>>> All of the tutorials mention having to download MySQL! >>> >>> You don't have to install all of MySQL, just the client libraries. I would >>> assume that almost every MySQL connector uses these libraries; but, you >>> might see if the MySQL-ODBC connector will work without them. It is a long >>> shot. Your last option would be to recreate your own connector without >>> using the MySQL client libraries. I am not really sure what the purpose of >>> reinventing this wheel would be. >> >> I believe that the coming trend is to implement the MySQL client >> protocol directly in Python, thereby obviating the need for any MySQL >> client installation on the machine hosting the Python code. > > One of the advantages to using the MySQL supplied library is that if the > line protocol changes the connector automatically inherits the work already > done by MySQL for the price of a stable API (yes, I am aware that the MySQL > API *has* changed through the years). That could be very relevant in the > near future as the probject settles its stable forks. > >> The pymysql project at http://code.google.com/p/pymysql/ is one such >> solution, aimed at satisfying Python 3 users without the need to port >> existing low-level client code. > > That still looks like alpha code. Would you be willing to make a statement > as to its stability? No, that was purely an example. I am, however, using MySQL Connector/Python https://launchpad.net/myconnpy in a series of commercial Python 3 classes. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From sxn02 at yahoo.com Wed Nov 17 23:21:06 2010 From: sxn02 at yahoo.com (Sorin Schwimmer) Date: Wed, 17 Nov 2010 20:21:06 -0800 (PST) Subject: String multi-replace Message-ID: <114148.34295.qm@web56007.mail.re3.yahoo.com> Hi All, I have to eliminate diacritics in a fairly large file. Inspired by http://code.activestate.com/recipes/81330/, I came up with the following code: #! /usr/bin/env python import re nodia={chr(196)+chr(130):'A', # mamaliga chr(195)+chr(130):'A', # A^ chr(195)+chr(142):'I', # I^ chr(195)+chr(150):'O', # OE chr(195)+chr(156):'U', # UE chr(195)+chr(139):'A', # AE chr(197)+chr(158):'S', chr(197)+chr(162):'T', chr(196)+chr(131):'a', # mamaliga chr(195)+chr(162):'a', # a^ chr(195)+chr(174):'i', # i^ chr(195)+chr(182):'o', # oe chr(195)+chr(188):'u', # ue chr(195)+chr(164):'a', # ae chr(197)+chr(159):'s', chr(197)+chr(163):'t' } name="R\xc3\xa2\xc5\x9fca" regex = re.compile("(%s)" % "|".join(map(re.escape, nodia.keys()))) print regex.sub(lambda mo: dict[mo.string[mo.start():mo.end()]], name) But it won't work; I end up with: Traceback (most recent call last): File "multirep.py", line 25, in print regex.sub(lambda mo: dict[mo.string[mo.start():mo.end()]], name) File "multirep.py", line 25, in print regex.sub(lambda mo: dict[mo.string[mo.start():mo.end()]], name) TypeError: 'type' object is not subscriptable What am I doing wrong? Thanks for your advice, SxN From benjamin.kaplan at case.edu Wed Nov 17 23:30:12 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 17 Nov 2010 23:30:12 -0500 Subject: String multi-replace In-Reply-To: <114148.34295.qm@web56007.mail.re3.yahoo.com> References: <114148.34295.qm@web56007.mail.re3.yahoo.com> Message-ID: On Wed, Nov 17, 2010 at 11:21 PM, Sorin Schwimmer wrote: > Hi All, > > I have to eliminate diacritics in a fairly large file. > > Inspired by http://code.activestate.com/recipes/81330/, I came up with the following code: > > #! /usr/bin/env python > > import re > > nodia={chr(196)+chr(130):'A', # mamaliga > ? ? ? chr(195)+chr(130):'A', # A^ > ? ? ? chr(195)+chr(142):'I', # I^ > ? ? ? chr(195)+chr(150):'O', # OE > ? ? ? chr(195)+chr(156):'U', # UE > ? ? ? chr(195)+chr(139):'A', # AE > ? ? ? chr(197)+chr(158):'S', > ? ? ? chr(197)+chr(162):'T', > ? ? ? chr(196)+chr(131):'a', # mamaliga > ? ? ? chr(195)+chr(162):'a', # a^ > ? ? ? chr(195)+chr(174):'i', # i^ > ? ? ? chr(195)+chr(182):'o', # oe > ? ? ? chr(195)+chr(188):'u', # ue > ? ? ? chr(195)+chr(164):'a', # ae > ? ? ? chr(197)+chr(159):'s', > ? ? ? chr(197)+chr(163):'t' > ? ? ?} > name="R\xc3\xa2\xc5\x9fca" > > regex = re.compile("(%s)" % "|".join(map(re.escape, nodia.keys()))) > print regex.sub(lambda mo: dict[mo.string[mo.start():mo.end()]], name) > > But it won't work; I end up with: > > Traceback (most recent call last): > ?File "multirep.py", line 25, in > ? ?print regex.sub(lambda mo: dict[mo.string[mo.start():mo.end()]], name) > ?File "multirep.py", line 25, in > ? ?print regex.sub(lambda mo: dict[mo.string[mo.start():mo.end()]], name) > TypeError: 'type' object is not subscriptable > > What am I doing wrong? > > Thanks for your advice, > SxN > dict is a type, not a dict. Your dict is called nodia. I'm guess that's what you meant to use. > > -- > http://mail.python.org/mailman/listinfo/python-list > From drsalists at gmail.com Wed Nov 17 23:37:47 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 17 Nov 2010 20:37:47 -0800 Subject: simple(?) Python C module question In-Reply-To: References: Message-ID: On Wed, Nov 17, 2010 at 7:42 PM, Terry Reedy wrote: > On 11/17/2010 7:25 PM, Mark Crispin wrote: > > Have you looked at ctypes? It's not suitable for all libraries, but >>> it can often obviate the need to write any C code: >>> http://docs.python.org/release/2.6.6/library/ctypes.html#module-ctypes >>> >> >> Hmm. I don't think that it helps, especially as I don't really want to >> make the consumers of this module know anything about c-client or its >> calling conventions. >> > > For the record, a C library wrapper written in Python with cytpes is nearly > indistinguishable to users from an equivalent wrapper written in C. However, > given that you are more comfortable with C than Python and have gotten the > info you need, stick with that. > ...except when you go to recompile a C extension module, if a dependency has changed its API, the C compiler will at least output a warning at the relevant spot. ctypes code is likely to be rather less friendly about it - the word "segfault" comes to mind. I'd say that the 3 main options for C <-> Python interop are: 1) ctypes (nice for light use and if you only need python, not that well type checked, probably the best bet if you're targeting python implementations other than CPython alone) 2) swig (nice if you plan to expose your C API to lots of languages) 3) cython (nice if you only need python, and want to more or less freely intermix normal python with C symbols using a very python-like syntax and with speed near that of C) -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve-REMOVE-THIS at cybersource.com.au Wed Nov 17 23:39:11 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 18 Nov 2010 04:39:11 GMT Subject: Help in language development References: <6fb7a013-cee1-4c77-9b96-d5494a5dda98@j25g2000yqa.googlegroups.com> Message-ID: <4ce4adef$0$29981$c3e8da3$5496439d@news.astraweb.com> Hello Pedro Igor, On Tue, 16 Nov 2010 12:51:07 -0800, pedro igor sampaio avelino wrote: > Hello, my name Pedro Igor, I am a student and develop applications in > python for 1 year. I enrolled in the group to contribute in developing > this wonderful language that helps me both in day-to-day, but I'm going > through some difficulties because they do not know where to start, can > someone please give me some steps so that I can contribute at once > development for all, where do I start, if the documentation or a book. I > know that most people have more important issues to address in other > posts but assistance does not cost anything. If you are interested in helping others, you can start here, on this newsgroup or mailing list. When other people ask questions, try to give the answer yourself. Or you could go to the Python wiki and contribute: http://wiki.python.org/moin/ Or go to the bug tracker, and look for bugs you can work on. Be aware though that the standard for having patches accepted is quite high. http://bugs.python.org/ -- Steven From clp2 at rebertia.com Wed Nov 17 23:45:49 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 17 Nov 2010 20:45:49 -0800 Subject: String multi-replace In-Reply-To: <114148.34295.qm@web56007.mail.re3.yahoo.com> References: <114148.34295.qm@web56007.mail.re3.yahoo.com> Message-ID: On Wed, Nov 17, 2010 at 8:21 PM, Sorin Schwimmer wrote: > Hi All, > > I have to eliminate diacritics in a fairly large file. > > Inspired by http://code.activestate.com/recipes/81330/, I came up with the following code: > > #! /usr/bin/env python > > import re > > nodia={chr(196)+chr(130):'A', # mamaliga > ? ? ? chr(195)+chr(130):'A', # A^ > ? ? ? chr(195)+chr(142):'I', # I^ > ? ? ? chr(195)+chr(150):'O', # OE > ? ? ? chr(195)+chr(156):'U', # UE > ? ? ? chr(195)+chr(139):'A', # AE > ? ? ? chr(197)+chr(158):'S', > ? ? ? chr(197)+chr(162):'T', > ? ? ? chr(196)+chr(131):'a', # mamaliga > ? ? ? chr(195)+chr(162):'a', # a^ > ? ? ? chr(195)+chr(174):'i', # i^ > ? ? ? chr(195)+chr(182):'o', # oe > ? ? ? chr(195)+chr(188):'u', # ue > ? ? ? chr(195)+chr(164):'a', # ae > ? ? ? chr(197)+chr(159):'s', > ? ? ? chr(197)+chr(163):'t' > ? ? ?} > name="R\xc3\xa2\xc5\x9fca" > > regex = re.compile("(%s)" % "|".join(map(re.escape, nodia.keys()))) > print regex.sub(lambda mo: dict[mo.string[mo.start():mo.end()]], name) Have you considered using string.maketrans() and str.translate() instead? It's simpler and likely faster than generating+using regexes like that. http://docs.python.org/library/string.html#string.maketrans Cheers, Chris -- Cue someone quoting Zawinski. http://blog.rebertia.com From steve-REMOVE-THIS at cybersource.com.au Wed Nov 17 23:49:07 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 18 Nov 2010 04:49:07 GMT Subject: Some syntactic sugar proposals References: <87mxp7gbdf.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <4ce4b043$0$29981$c3e8da3$5496439d@news.astraweb.com> On Wed, 17 Nov 2010 16:31:40 +0000, Mark Wooding wrote: > But I don't think that's the big problem with this proposal. The real > problem is that it completely changes the evaluation rule for the > conditional expression. (The evaluation rule is already pretty screwy: > Python is consistently left-to-right -- except here.) Not quite... >>> 1+2*3 7 >>> (1+2)*3 9 But other than that, I agree with your analysis for why Python should not be changed to allow: t = foo() as v if pred(v) else default_value Not everything needs to be a one liner. If you need this, do it the old- fashioned way: t = foo() if not pred(t): t = default_value -- Steven From steve-REMOVE-THIS at cybersource.com.au Thu Nov 18 00:10:03 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 18 Nov 2010 05:10:03 GMT Subject: String multi-replace References: Message-ID: <4ce4b52b$0$29981$c3e8da3$5496439d@news.astraweb.com> On Wed, 17 Nov 2010 20:21:06 -0800, Sorin Schwimmer wrote: > Hi All, > > I have to eliminate diacritics in a fairly large file. What's "fairly large"? Large to you is probably not large to your computer. Anything less than a few dozen megabytes is small enough to be read entirely into memory. > Inspired by http://code.activestate.com/recipes/81330/, I came up with > the following code: If all you are doing is replacing single characters, then there's no need for the 80lb sledgehammer of regular expressions when all you need is a delicate tack hammer. Instead of this: * read the file as bytes * search for pairs of bytes like chr(195)+chr(130) using a regex * replace them with single bytes like 'A' do this: * read the file as a Unicode * search for characters like ? * replace them with single characters like A using unicode.translate() (or str.translate() in Python 3.x) The only gotcha is that you need to know (or guess) the encoding to read the file correctly. -- Steven From sxn02 at yahoo.com Thu Nov 18 00:12:31 2010 From: sxn02 at yahoo.com (Sorin Schwimmer) Date: Wed, 17 Nov 2010 21:12:31 -0800 (PST) Subject: String multi-replace Message-ID: <912885.5637.qm@web56006.mail.re3.yahoo.com> Thanks for your answers. Benjamin Kaplan: of course dict is a type... silly me! I'll blame it on the time (it's midnight here). Chris Rebert: I'll have a look. Thank you both, SxN From usernet at ilthio.net Thu Nov 18 00:24:45 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 18 Nov 2010 05:24:45 +0000 (UTC) Subject: How to run an EXE, with argument, capture output value References: <37037d15-63da-4f37-9508-bdcfff034670@s4g2000yql.googlegroups.com> Message-ID: On 2010-11-18, noydb wrote: > I have an executable that I want to run within python code. The exe > requires an input text file, the user to click a 'compute' button, and > then the exe calculates several output values, one of which I want to > capture into a variable. Can I use Python to supply the input file, > execute the exe and capture the output value, like such that the exe > really doesn't need to be 'seen'? Or, would the user still have to > click the 'compute' button? > > Any code snippets or guidance would be very much appreciated. I have > found that > > import os > os.system('C:\xTool\stats_hall.exe') > > will run the exe. And, maybe these execl/execle/execlp/etc functions > might be what I need for adding in the argument, but documentation > seems to indicate that these do not return output. ?? If you are not already, I would highly suggest using Python3 with the subprocess module: http://docs.python.org/py3k/library/subprocess.html It puts everything in one place and supercedes the exec* functions which where a PITA. You can 95% of what you need simply using subprocess.Popen(). There are several examples from this group in the past few days; but, the process looks something like this: Python 3.1.2 (r312:79147, Oct 9 2010, 00:16:06) [GCC 4.4.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import subprocess >>> pig = subprocess.Popen(["/usr/games/pig"], stdin=subprocess.PIPE) >>> result = pig.communicate(input=b"This is sample text.\n") Isthay isway amplesay exttay. >>> From sxn02 at yahoo.com Thu Nov 18 00:29:33 2010 From: sxn02 at yahoo.com (Sorin Schwimmer) Date: Wed, 17 Nov 2010 21:29:33 -0800 (PST) Subject: String multi-replace Message-ID: <379297.48105.qm@web56003.mail.re3.yahoo.com> Steven D'Aprano: the original file is 139MB (that's the typical size for it). Eliminating diacritics is just a little toping on the cake; the processing is something else. Thanks anyway for your suggestion, SxN PS Perhaps I should have mention that I'm on Python 2.7 From usernet at ilthio.net Thu Nov 18 00:36:59 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 18 Nov 2010 05:36:59 +0000 (UTC) Subject: How to run an EXE, with argument, capture output value References: <37037d15-63da-4f37-9508-bdcfff034670@s4g2000yql.googlegroups.com> Message-ID: On 2010-11-18, Tim Harig wrote: > On 2010-11-18, noydb wrote: >> I have an executable that I want to run within python code. The exe >> requires an input text file, the user to click a 'compute' button, and >> then the exe calculates several output values, one of which I want to >> capture into a variable. Can I use Python to supply the input file, >> execute the exe and capture the output value, like such that the exe ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Sorry, I missed the second part, it's time for me to go to bed. >> really doesn't need to be 'seen'? Or, would the user still have to >> click the 'compute' button? > > Python 3.1.2 (r312:79147, Oct 9 2010, 00:16:06) > [GCC 4.4.4] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import subprocess > >>> pig = subprocess.Popen(["/usr/games/pig"], stdin=subprocess.PIPE) > >>> result = pig.communicate(input=b"This is sample text.\n") > Isthay isway amplesay exttay. > >>> With capturing the output, it looks like: >>> pig = subprocess.Popen(["/usr/games/pig"], stdin=subprocess.PIPE, >>> stdout=subprocess.PIPE) >>> result = pig.communicate(input=b"This is sample text.\n")[0] >>> result b'Isthay isway amplesay exttay.\n' >>> You can also get the return code if you need it: >>> pig.returncode 0 From pmilin at gmail.com Thu Nov 18 02:54:08 2010 From: pmilin at gmail.com (neocortex) Date: Wed, 17 Nov 2010 23:54:08 -0800 (PST) Subject: Does Pygoogle allows for advanced search options? Message-ID: Hello All, Can anyone help me with the Pygoogle: from pygoogle import pygoogle word = u'something' request_word = word.encode('utf-8') request = ('%s+site:.edu' % request_word) g = pygoogle(request) g.get_result_count() Now, I realized that domain restriction works (site:.edu etc.), but I would like to be able to control for language too. Is that possible with the Pygoogle? If not, how can I make that happen? Thanks! PM From cbrown at cbrownsystems.com Thu Nov 18 03:03:05 2010 From: cbrown at cbrownsystems.com (cbrown at cbrownsystems.com) Date: Thu, 18 Nov 2010 00:03:05 -0800 (PST) Subject: Sending changed parameters into nested generators References: <4cde1784$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Nov 12, 10:52 pm, "John O'Hagan" wrote: > On Sat, 13 Nov 2010, Steven D'Aprano wrote: > > On Fri, 12 Nov 2010 09:47:26 +0000, John O'Hagan wrote: > > > I have a generator function which takes as arguments another generator > > > and a dictionary of other generators like this: > > > > def modgen(gen, gendict): > > > for item in gen(): > > > for k, v in gendict: > > > do_something_called_k(item, v.next()) > > > > yield item > > > [snip] > > > > If anyone's still reading :) , how can I send new values to arbitrary > > > sub- generators? > > > I have a headache after reading your problem :( > > > I think it's a good time to point you at the Zen, particularly these five > > maxims: > > > Beautiful is better than ugly. > > Simple is better than complex. > > Complex is better than complicated. > > Flat is better than nested. > > If the implementation is hard to explain, it's a bad idea. > > > I'm afraid that your nested generators inside another generator idea > > fails all of those... it's not elegant (beautiful), it's complicated, > > it's nested, and the implementation is hard to explain. > > > You could probably replace generators with full-blown iterators, but I > > wonder what you're trying to accomplish that is so complicated that it > > needs such complexity to solve it. What are you actually trying to > > accomplish? Can you give a simple example of what practical task you hope > > to perform? I suspect there's probably a more elegant way to solve the > > problem. > > I hope there is! > > The project not practical but artistic; it's a real-time musical composition > program. > > A (simplified) description: one module contains number-list generating > functions, others contain functions designed to filter and modify the number > lists produced, according to various parameters. Each such stream of number > lists is assigned a musical meaning (e.g. pitch, rhythm, volume, etc) and they > are combined to produce representations of musical phrases, which are sent to > a backend which plays the music as it is produced, and makes PDF scores. Each > such "instrument" runs as a separate thread, so several can play together in a > coordinated fashion. > > All the compositional interest lies in the selection of number-list generators > and how their output is modified. For example, if I say "Play every third note > up an octave" it's not very interesting, compared to "Play every nth note up > an interval of m", where n and m vary according to some pattern. It gets even > more interesting when that pattern is a function of x and y, which also vary > according to another pattern, and so on. > > To that end, I have each parameter of each modifier set by another generator, > such that the value may change with each iteration. This may continue > recursively, until at some level we give a parameter a simple value. > > That's all working, but I also want it to be interactive. Each thread opens a > terminal where new options can be entered, but so far it only works, as I > mentioned, for changing the values in a top-level mutable object. > I might first suggest this, although I have some caveats to add: def genfilter(evaluator, **param_sources): while True: params = {} for param, gen in param_sources.iteritems(): params[param] = gen.next() yield evaluator(**params) You can then do things like: >>> def concat(in1, in2): >>> return str(in1)+"|"+str(in2) >>> a = (i for i in range(1,5)) # generator based on a list >>> b = (2*i for i in xrange(1,5)) # 'pure' generator >>> c = genfilter(concat, in1=a, in2=b) >>> for x in c: >>> print x 1|2 2|4 3}6 4|8 or, more relevant to your original question regarding modifying things mid-stream: >>> class Mult(): >>> def __init__(self, multiplier): >>> self.mulitplier = multiplier >>> def multi(self, val): >>> return val*self.multiplier >>> >>> m = Mult(2) >>> a = (i for i in range(1,10)) >>> b = (i for i in range(1,10)) >>> c = genfilter(m.multi, val=b) >>> d = genfilter(concat, in1=a, in2=c) >>> d.next() 1|2 >>> d.next() 2|4 >>> m.multiplier = 3 >>> d.next() 3|9 Obviously more complex and useful examples could be made, but hopefully you get the idea: don't focus on modifying the generators, instead modify the action of the functions which take the generators as inputs. But a real problem with this whole strategy is that a generator's next() function is called every time it is evaluated. If the relationship between your various generators forms a rooted tree, that's not a problem, but I would think the relationships form a directed acyclic graph, and in that case, you end up 'double incrementing' nodes in a way you don't want: >>> m = Mult(2) >>> a = (i for i in range(1,10)) >>> b = genfilter(m.multi, val=a) >>> c = genfilter(concat, in1=a, in2=b) >>> for x in c: >>> print x 1|4 3|8 5|12 7|16 And that's not an unnatural situation for your application: you might have a generator that produces a note, and then three other distinct genfilters that you want to use to create three instruments which form a chord based on that note. With the above pattern (and also your original pattern) you would end up invoking the note generator three times; and I think you don't really want that. To solve that problem, you need a somewhat more complex solution: a class that ensures that each previous stage is only invoked once per 'pass'. I've got an idea for that, if that is of interest. Cheers - Chas From clp2 at rebertia.com Thu Nov 18 03:28:03 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 18 Nov 2010 00:28:03 -0800 Subject: Does Pygoogle allows for advanced search options? In-Reply-To: References: Message-ID: On Wed, Nov 17, 2010 at 11:54 PM, neocortex wrote: > Hello All, > Can anyone help me with the Pygoogle: > from pygoogle import pygoogle You're apparently talking about http://code.google.com/p/pygoogle/ rather than http://pygoogle.sourceforge.net/ ; the former appears to have "borrowed" the latter's name without permission. Oi! > word = u'something' > request_word = word.encode('utf-8') > request = ('%s+site:.edu' % request_word) > g = pygoogle(request) > g.get_result_count() > > Now, I realized that domain restriction works (site:.edu etc.), but I > would like to be able to control for language too. Is that possible > with the Pygoogle? If not, how can I make that happen? The library doesn't seem to have built-in support for filtering by language (and Google lacks a search query-string-based operator for that), but it looks like you could implement that feature by adding an "lr" parameter with an appropriate value to the query `args` dictionary. See the "lr?" entry under "Web Search Specific Arguments" on http://code.google.com/apis/websearch/docs/reference.html , and lines 68 & 102 of pygoogle.py. Cheers, Chris -- Research for random person => too much idle time http://blog.rebertia.com From rde at audaxis.com Thu Nov 18 03:29:00 2010 From: rde at audaxis.com (Romaric DEFAUX) Date: Thu, 18 Nov 2010 09:29:00 +0100 Subject: Pickle in a POST/GET request give EOFError In-Reply-To: References: <4CE2B599.7050504@audaxis.com> <4CE3EA61.2090707@audaxis.com> Message-ID: <4CE4E3CC.8080801@audaxis.com> Le 17/11/2010 18:52, geremy condra a ?crit : > On Wed, Nov 17, 2010 at 6:44 AM, Romaric DEFAUX wrote: > >> Le 16/11/2010 17:47, Romaric DEFAUX a ?crit : >> >>> Hi everybody ! >>> >>> First time I write to this mailing list :) >>> I started writing in python last week, that's probably why I can't >>> understand the following problem... >>> >>> >>> I create a list called web_site_list. >>> This list contain dictionaries called web_site. >>> And some values in this dictionaries are list too. >>> >>> I do that in a function and I return this : >>> return pickle.dumps(web_site_list) >>> >>> This is working fine :) >>> >>> If I do : >>> print "%s" % pickle.loads(system.get_web_site_list()) >>> >>> I've got the right stuffs. For example it returns : >>> [{'documentroot_size': '120', 'servername': '---default---', 'client': >>> 'undefined', 'documentroot': '/var/www/', 'client_contact': 'undefined', >>> 'serveralias': []}] >>> >>> I send this to a web service. I send it like that : >>> #I put it in params >>> def system_updateweb_site(server, login, password): >>> params = {} >>> params['login'] = login >>> params['password'] = password >>> params['action'] = 'updateweb_site' >>> params['servername'] = get_servername() >>> params['hosted_web_site'] = get_web_site_list() >>> return call_system_ws(server, params) >>> >>> #Here's how I send it (I tried in GET and POST) >>> def call_system_ws(host, params): >>> query_string = urllib.urlencode(params) >>> #GET >>> # f = urllib.urlopen("http://%s/ws?%s" % (host, query_string)) >>> #POST >>> f = urllib.urlopen("http://%s/ws" % (host), query_string) >>> result = f.readline().strip() >>> if result == 'ERROR': >>> msg = f.readline().strip() >>> return (False, msg) >>> return (True, result) >>> >>> >>> On the server side : >>> if action == 'updateweb_site': >>> if not (fields.has_key('servername') and >>> fields.has_key('hosted_web_site')): >>> raise WSError('missing parameter : >>> servername or hosted_web_site') >>> log ('ERROR : missing parameter : >>> servername or hosted_web_site') >>> else: >>> >>> servername=g.db.escape_string(fields['servername']) >>> >>> hosted_web_site=g.db.escape_string(fields['hosted_web_site']) >>> output = >>> systemserver.updateweb_site(cursor, servername, hosted_web_site) >>> >>> In systemserver.py : >>> def updateweb_site(cursor, host, hosted_web_site): >>> web_site_list = pickle.loads(hosted_web_site) >>> return "%s" % (web_site_list) >>> >>> I catch this error :* >>> >>> *: >>> >>> args = () >>> message = '' >>> >>> Why ? >>> >>> If I just print hosted_web_site, I get this on my web page : >>> >>> >>> (lp0\n(dp1\nS\'documentroot_size\'\np2\nS\'120\'\np3\nsS\'servername\'\np4\nS\'default\'\np5\nsS\'client\'\np6\nS\'undefined\'\np7\nsS\'documentroot\'\np8\nS\'/var/www/\'\np9\nsS\'client_contact\'\np10\ng7\nsS\'serveralias\'\np11\n(lp12\nsa. >>> >>> It's the "pickled view" of >>> [{'documentroot_size': '120', 'servername': '---default---', 'client': >>> 'undefined', 'documentroot': '/var/www/', 'client_contact': 'undefined', >>> 'serveralias': []}] >>> >>> Can someone help me please ? I spend my afternoon to google to try to find >>> a solution... >>> >>> >>> Thanks in advance !!! >>> >>> Romaric Defaux >>> >>> >> After entirely rewrite my code to not use Web service but socket (a real >> client/server program) I finally found the problem... And it's not linked to >> the POST or GET method... >> It's because of that : >> g.db.escape_string(fields['hosted_web_site']) >> (escape_string is the function in MySQLdb library) >> It escapes the simple quote of the pickled object, and break it... >> >> It's good to know, NEVER escape a pickled object :) >> >> Romaric Defaux >> > I'm not sure I understand what you're doing here, but I trust you've > read about and understand the security problems with pickle? > > Geremy Condra > I read quickly the security problems with pickle. But I don't feel concern about that because I run my program in a private network, not over internet. And now I use socket to communicate on a non-standard port, not anymore web service on the 80 port. If I plan to run it through wan, I will encrypt datas for sure with SSL or something like that :) Romaric Defaux -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 5361 bytes Desc: S/MIME Cryptographic Signature URL: From michael.ricordeau at gmail.com Thu Nov 18 03:43:47 2010 From: michael.ricordeau at gmail.com (Michael Ricordeau) Date: Thu, 18 Nov 2010 09:43:47 +0100 Subject: Pickle in a POST/GET request give EOFError In-Reply-To: <4CE4E3CC.8080801@audaxis.com> References: <4CE2B599.7050504@audaxis.com> <4CE3EA61.2090707@audaxis.com> <4CE4E3CC.8080801@audaxis.com> Message-ID: <20101118094347.53a0980a@moriz.interne> Hi, you can use json for passing list and dict . Pickle is dangerous . Instead of pickle.loads/pickle.dumps use json.loads and json.dumps (using stdlib json in python >= 2.6 or simplejson in python < 2.6) Regards Le Thu, 18 Nov 2010 09:29:00 +0100, Romaric DEFAUX a ?crit : > Le 17/11/2010 18:52, geremy condra a ?crit : > > On Wed, Nov 17, 2010 at 6:44 AM, Romaric DEFAUX wrote: > > > >> Le 16/11/2010 17:47, Romaric DEFAUX a ?crit : > >> > >>> Hi everybody ! > >>> > >>> First time I write to this mailing list :) > >>> I started writing in python last week, that's probably why I can't > >>> understand the following problem... > >>> > >>> > >>> I create a list called web_site_list. > >>> This list contain dictionaries called web_site. > >>> And some values in this dictionaries are list too. > >>> > >>> I do that in a function and I return this : > >>> return pickle.dumps(web_site_list) > >>> > >>> This is working fine :) > >>> > >>> If I do : > >>> print "%s" % pickle.loads(system.get_web_site_list()) > >>> > >>> I've got the right stuffs. For example it returns : > >>> [{'documentroot_size': '120', 'servername': '---default---', 'client': > >>> 'undefined', 'documentroot': '/var/www/', 'client_contact': 'undefined', > >>> 'serveralias': []}] > >>> > >>> I send this to a web service. I send it like that : > >>> #I put it in params > >>> def system_updateweb_site(server, login, password): > >>> params = {} > >>> params['login'] = login > >>> params['password'] = password > >>> params['action'] = 'updateweb_site' > >>> params['servername'] = get_servername() > >>> params['hosted_web_site'] = get_web_site_list() > >>> return call_system_ws(server, params) > >>> > >>> #Here's how I send it (I tried in GET and POST) > >>> def call_system_ws(host, params): > >>> query_string = urllib.urlencode(params) > >>> #GET > >>> # f = urllib.urlopen("http://%s/ws?%s" % (host, query_string)) > >>> #POST > >>> f = urllib.urlopen("http://%s/ws" % (host), query_string) > >>> result = f.readline().strip() > >>> if result == 'ERROR': > >>> msg = f.readline().strip() > >>> return (False, msg) > >>> return (True, result) > >>> > >>> > >>> On the server side : > >>> if action == 'updateweb_site': > >>> if not (fields.has_key('servername') and > >>> fields.has_key('hosted_web_site')): > >>> raise WSError('missing parameter : > >>> servername or hosted_web_site') > >>> log ('ERROR : missing parameter : > >>> servername or hosted_web_site') > >>> else: > >>> > >>> servername=g.db.escape_string(fields['servername']) > >>> > >>> hosted_web_site=g.db.escape_string(fields['hosted_web_site']) > >>> output = > >>> systemserver.updateweb_site(cursor, servername, hosted_web_site) > >>> > >>> In systemserver.py : > >>> def updateweb_site(cursor, host, hosted_web_site): > >>> web_site_list = pickle.loads(hosted_web_site) > >>> return "%s" % (web_site_list) > >>> > >>> I catch this error :* > >>> > >>> *: > >>> > >>> args = () > >>> message = '' > >>> > >>> Why ? > >>> > >>> If I just print hosted_web_site, I get this on my web page : > >>> > >>> > >>> (lp0\n(dp1\nS\'documentroot_size\'\np2\nS\'120\'\np3\nsS\'servername\'\np4\nS\'default\'\np5\nsS\'client\'\np6\nS\'undefined\'\np7\nsS\'documentroot\'\np8\nS\'/var/www/\'\np9\nsS\'client_contact\'\np10\ng7\nsS\'serveralias\'\np11\n(lp12\nsa. > >>> > >>> It's the "pickled view" of > >>> [{'documentroot_size': '120', 'servername': '---default---', 'client': > >>> 'undefined', 'documentroot': '/var/www/', 'client_contact': 'undefined', > >>> 'serveralias': []}] > >>> > >>> Can someone help me please ? I spend my afternoon to google to try to find > >>> a solution... > >>> > >>> > >>> Thanks in advance !!! > >>> > >>> Romaric Defaux > >>> > >>> > >> After entirely rewrite my code to not use Web service but socket (a real > >> client/server program) I finally found the problem... And it's not linked to > >> the POST or GET method... > >> It's because of that : > >> g.db.escape_string(fields['hosted_web_site']) > >> (escape_string is the function in MySQLdb library) > >> It escapes the simple quote of the pickled object, and break it... > >> > >> It's good to know, NEVER escape a pickled object :) > >> > >> Romaric Defaux > >> > > I'm not sure I understand what you're doing here, but I trust you've > > read about and understand the security problems with pickle? > > > > Geremy Condra > > > I read quickly the security problems with pickle. But I don't feel > concern about that because I run my program in a private network, not > over internet. And now I use socket to communicate on a non-standard > port, not anymore web service on the 80 port. If I plan to run it > through wan, I will encrypt datas for sure with SSL or something like > that :) > > Romaric Defaux > From huisky at gmail.com Thu Nov 18 03:54:06 2010 From: huisky at gmail.com (huisky) Date: Thu, 18 Nov 2010 00:54:06 -0800 (PST) Subject: How to read such file and sumarize the data? References: Message-ID: thank you Martin. You are right. But the elapsed time is also okay for me. And i would like to assume that the total CPU time equals to the number of CPUs multiply the elapsed time. As to the number you mentioned, it is the 'process id', so it will be no problem to identify each job. Huiksy On Nov 18, 12:38?am, Martin Gregorie wrote: > On Wed, 17 Nov 2010 13:45:58 -0800, huisky wrote: > > Say I have following log file, which records the code usage. I want to > > read this file and do the summarize how much total CPU time consumed for > > each user. > > Two points you should think about: > > - I don't think you can extract CPU time from this log: you can get > ? the process elapsed time and the number of CPUs each run has used, > ? but you can't calculate CPU time from those values since you don't > ? know how the process spent waiting for i/o etc. > > - is the first (numeric) part of the first field on the line a process id? > ? If it is, you can match start and stop messages on the value of the > ? first field provided that this value can never be shared by two > ? processes that are both running. If you can get simultaneous > ? duplicates, then you're out of luck because you'll never be able to > ? match up start and stop lines. > > > Is Python able to do so or say easy to achieve this?, anybody can give > > me some hints, appricate very much! > > Sure. There are two approaches possible: > - sort the log on the first two fields and then process it with Python > ? knowing that start and stop lines will be adjacent > > - use the first field as the key to an array and put the start time > ? and CPU count in that element. When a matching stop line is found > ? you, retrieve the array element, calculate and output or total the > ? usage figure for that run and delete the array element. > > -- > martin@ ? | Martin Gregorie > gregorie. | Essex, UK > org ? ? ? | From casevh at gmail.com Thu Nov 18 03:55:51 2010 From: casevh at gmail.com (casevh) Date: Thu, 18 Nov 2010 00:55:51 -0800 (PST) Subject: ANN: GMPY 1.14 and GMPY2 alpha1 released Message-ID: Everyone, I'm pleased to annouce the release of both a new production and experimental release of GMPY. GMPY is a wrapper for the MPIR or GMP multiple-precision arithmetic library. The experimental release (GMPY2) now includes support for the MPFR floating-point library. GMPY is available for download from: http://code.google.com/p/gmpy/ Production release ------------------ GMPY 1.14 is the updated stable release. A memory leak was fixed so it is highly recommended that all user upgrade to this version. In addition to a few other bug fixes, GMPY 1.14 is compatible with the changes to the hashing code in Python 3.2a4. The 64-bit Windows installer for Python 3.2 should only be used with 3.2a4 and later. Even though my primary development focus has shifted to GMPY2 (see below), GMPY 1.X will continue to receive bug and compatibility fixes. Experimental release -------------------- To simplify the codebase, allow for changes in the API, and support simultaneous installation, the development version has been renamed to GMPY2. The following is list of changes in GMPY2: In 2.0.0a0 ---------- * support for a mutable integer type "xmpz" * removal of random number functions * "xmpz" supports slices for setting/clearing bits * some methods have been renamed (scan1 -> bit_scan1) * support for Python prior to 2.6 has been removed * support for all division modes has been added * ceiling - round to +Infinity * floor - round to -Infinity * truncate - round to zero * 2exp - division by a power of 2 * support is_even() and is_odd() In 2.0.0a1 ---------- * support for the MPFR floating point library If you use GMPY regularly, please test GMPY2. There have been several requests asking for a mutable integer and I am curious if there are real-world performance improvements. Please report any issues! casevh From huisky at gmail.com Thu Nov 18 03:56:08 2010 From: huisky at gmail.com (huisky) Date: Thu, 18 Nov 2010 00:56:08 -0800 (PST) Subject: How to read such file and sumarize the data? References: Message-ID: the number before @ is the process id in the linux server and it is identical. So i do NOT think distinguish each job's starting and ending time is difficult in this case. Huisky On Nov 17, 11:38?pm, Tim Harig wrote: > On 2010-11-17, huisky wrote: > > > I want to read this file and do the summarize how much total CPU time > > consumed for each user. > > Is Python able to do so or say easy to achieve this?, anybody can give > > me some hints, appricate very much! > > The question is, is the information you want available in the data. > > > > > Example log file. > > ************************************************************************************** > > LSTC license server version 224 started at Sun Dec ?6 18:56:48 2009 > > using configuration file /usr/local/lstc/server_data > > xyz 15... at trofast3.marin.ntnu.no LS-DYNA_971 NCPU=1 started Sun Dec ?6 > > 18:57:40 > > 15... at trofast3.marin.ntnu.no completed Sun Dec ?6 19:42:55 > > xyz 15... at trofast3.marin.ntnu.no LS-DYNA_971 NCPU=2 started Sun Dec ?6 > > 20:17:02 > > 15... at trofast3.marin.ntnu.no completed Sun Dec ?6 20:26:03 > > xyz 18... at trofast2.marin.ntnu.no LS-DYNA_971 NCPU=1 started Sun Dec ?6 > > 21:01:17 > > 18... at trofast2.marin.ntnu.no completed Sun Dec ?6 21:01:28 > > tanhoi 5... at iimt-tanhoi-w.ivt.ntnu.no LS-DYNA_971 NCPU=1 started Mon > > Dec ?7 09:31:00 > > 5... at iimt-tanhoi-w.ivt.ntnu.no presumed dead Mon Dec ?7 10:36:48 > > sabril 18... at trofast2.marin.ntnu.no LS-DYNA_971 NCPU=2 started Mon > > Dec ?7 13:14:47 > > 18... at trofast2.marin.ntnu.no completed Mon Dec ?7 13:24:07 > > sabril 18... at trofast2.marin.ntnu.no LS-DYNA_971 NCPU=2 started Mon > > Dec ?7 14:21:34 > > sabril 18... at trofast2.marin.ntnu.no LS-DYNA_971 NCPU=2 started Mon > > Dec ?7 14:28:42 > > 18... at trofast2.marin.ntnu.no killed Mon Dec ?7 14:31:48 > > 18... at trofast2.marin.ntnu.no killed Mon Dec ?7 14:32:06 > > I see starts, completes, kills, and presumed deads. ?The question is can > the starts be matched to the completes and kills either from the numbers > before @ or from a combination of the address and NCPU. ?You will need to > figure out whether or not you want to count the presumed deads in your > calculations. > > Assuming that the starts and stops can be corrilated, it is a simple matter > of finding the pairs and using the datetime module to find the difference > in time between them. From huisky at gmail.com Thu Nov 18 04:13:47 2010 From: huisky at gmail.com (huisky) Date: Thu, 18 Nov 2010 01:13:47 -0800 (PST) Subject: How to read such file and sumarize the data? References: Message-ID: <16e5b5e2-9b5c-4533-ac17-5e828367df9b@r29g2000yqj.googlegroups.com> Thank you very much for your reply. I think you just count the total number of NCPU used for each user. And it does NOT show how much time used for each user. Huisky On Nov 18, 12:10?am, Steve Holden wrote: > On 11/17/2010 4:45 PM, huisky wrote:> Say I have following log file, which records the code usage. > > I want to read this file and do the summarize how much total CPU time > > consumed for each user. > > Is Python able to do so or say easy to achieve this?, anybody can give > > me some hints, appricate very much! > > > Example log file. > > ************************************************************************************** > > I'm assuming the following (unquoted) data is in file "data.txt": > > > > > LSTC license server version 224 started at Sun Dec ?6 18:56:48 2009 > > using configuration file /usr/local/lstc/server_data > > xyz 15... at trofast3.marin.ntnu.no LS-DYNA_971 NCPU=1 started Sun Dec ?6 > > 18:57:40 > > 15... at trofast3.marin.ntnu.no completed Sun Dec ?6 19:42:55 > > xyz 15... at trofast3.marin.ntnu.no LS-DYNA_971 NCPU=2 started Sun Dec ?6 > > 20:17:02 > > 15... at trofast3.marin.ntnu.no completed Sun Dec ?6 20:26:03 > > xyz 18... at trofast2.marin.ntnu.no LS-DYNA_971 NCPU=1 started Sun Dec ?6 > > 21:01:17 > > 18... at trofast2.marin.ntnu.no completed Sun Dec ?6 21:01:28 > > tanhoi 5... at iimt-tanhoi-w.ivt.ntnu.no LS-DYNA_971 NCPU=1 started Mon > > Dec ?7 09:31:00 > > 5... at iimt-tanhoi-w.ivt.ntnu.no presumed dead Mon Dec ?7 10:36:48 > > sabril 18... at trofast2.marin.ntnu.no LS-DYNA_971 NCPU=2 started Mon > > Dec ?7 13:14:47 > > 18... at trofast2.marin.ntnu.no completed Mon Dec ?7 13:24:07 > > sabril 18... at trofast2.marin.ntnu.no LS-DYNA_971 NCPU=2 started Mon > > Dec ?7 14:21:34 > > sabril 18... at trofast2.marin.ntnu.no LS-DYNA_971 NCPU=2 started Mon > > Dec ?7 14:28:42 > > 18... at trofast2.marin.ntnu.no killed Mon Dec ?7 14:31:48 > > 18... at trofast2.marin.ntnu.no killed Mon Dec ?7 14:32:06 > > The line wrapping being wrong shouldn't affect the logic. > > $ cat data.py > lines = open("data.txt").readlines() > from collections import defaultdict > c = defaultdict(int) > for line in lines: > ? ? ls = line.split() > ? ? if len(ls) > 3 and ls[3].startswith("NCPU="): > ? ? ? ? amt = int(ls[3][5:]) > ? ? ? ? c[ls[0]] += amt > for key, value in c.items(): > ? ? print key, ":", value > > $ python data.py > xyz : 4 > tanhoi : 1 > sabril : 6 > > regards > ?Steve > -- > Steve Holden ? ? ? ? ? +1 571 484 6266 ? +1 800 494 3119 > PyCon 2011 Atlanta March 9-17 ? ? ?http://us.pycon.org/ > See Python Video! ? ? ?http://python.mirocommunity.org/ > Holden Web LLC ? ? ? ? ? ? ? ?http://www.holdenweb.com/ From rde at audaxis.com Thu Nov 18 04:19:27 2010 From: rde at audaxis.com (Romaric DEFAUX) Date: Thu, 18 Nov 2010 10:19:27 +0100 Subject: Pickle in a POST/GET request give EOFError In-Reply-To: <20101118094347.53a0980a@moriz.interne> References: <4CE2B599.7050504@audaxis.com> <4CE3EA61.2090707@audaxis.com> <4CE4E3CC.8080801@audaxis.com> <20101118094347.53a0980a@moriz.interne> Message-ID: <4CE4EF9F.2050803@audaxis.com> Thanks for the tip, I'll do that :) Le 18/11/2010 09:43, Michael Ricordeau a ?crit : > Hi, > > you can use json for passing list and dict . > Pickle is dangerous . > > Instead of pickle.loads/pickle.dumps use json.loads and json.dumps > (using stdlib json in python>= 2.6 or simplejson in python< 2.6) > > Regards > > > > Le Thu, 18 Nov 2010 09:29:00 +0100, > Romaric DEFAUX a ?crit : > > >> Le 17/11/2010 18:52, geremy condra a ?crit : >> >>> On Wed, Nov 17, 2010 at 6:44 AM, Romaric DEFAUX wrote: >>> >>> >>>> Le 16/11/2010 17:47, Romaric DEFAUX a ?crit : >>>> >>>> >>>>> Hi everybody ! >>>>> >>>>> First time I write to this mailing list :) >>>>> I started writing in python last week, that's probably why I can't >>>>> understand the following problem... >>>>> >>>>> >>>>> I create a list called web_site_list. >>>>> This list contain dictionaries called web_site. >>>>> And some values in this dictionaries are list too. >>>>> >>>>> I do that in a function and I return this : >>>>> return pickle.dumps(web_site_list) >>>>> >>>>> This is working fine :) >>>>> >>>>> If I do : >>>>> print "%s" % pickle.loads(system.get_web_site_list()) >>>>> >>>>> I've got the right stuffs. For example it returns : >>>>> [{'documentroot_size': '120', 'servername': '---default---', 'client': >>>>> 'undefined', 'documentroot': '/var/www/', 'client_contact': 'undefined', >>>>> 'serveralias': []}] >>>>> >>>>> I send this to a web service. I send it like that : >>>>> #I put it in params >>>>> def system_updateweb_site(server, login, password): >>>>> params = {} >>>>> params['login'] = login >>>>> params['password'] = password >>>>> params['action'] = 'updateweb_site' >>>>> params['servername'] = get_servername() >>>>> params['hosted_web_site'] = get_web_site_list() >>>>> return call_system_ws(server, params) >>>>> >>>>> #Here's how I send it (I tried in GET and POST) >>>>> def call_system_ws(host, params): >>>>> query_string = urllib.urlencode(params) >>>>> #GET >>>>> # f = urllib.urlopen("http://%s/ws?%s" % (host, query_string)) >>>>> #POST >>>>> f = urllib.urlopen("http://%s/ws" % (host), query_string) >>>>> result = f.readline().strip() >>>>> if result == 'ERROR': >>>>> msg = f.readline().strip() >>>>> return (False, msg) >>>>> return (True, result) >>>>> >>>>> >>>>> On the server side : >>>>> if action == 'updateweb_site': >>>>> if not (fields.has_key('servername') and >>>>> fields.has_key('hosted_web_site')): >>>>> raise WSError('missing parameter : >>>>> servername or hosted_web_site') >>>>> log ('ERROR : missing parameter : >>>>> servername or hosted_web_site') >>>>> else: >>>>> >>>>> servername=g.db.escape_string(fields['servername']) >>>>> >>>>> hosted_web_site=g.db.escape_string(fields['hosted_web_site']) >>>>> output = >>>>> systemserver.updateweb_site(cursor, servername, hosted_web_site) >>>>> >>>>> In systemserver.py : >>>>> def updateweb_site(cursor, host, hosted_web_site): >>>>> web_site_list = pickle.loads(hosted_web_site) >>>>> return "%s" % (web_site_list) >>>>> >>>>> I catch this error :* >>>>> >>>>> *: >>>>> >>>>> args = () >>>>> message = '' >>>>> >>>>> Why ? >>>>> >>>>> If I just print hosted_web_site, I get this on my web page : >>>>> >>>>> >>>>> (lp0\n(dp1\nS\'documentroot_size\'\np2\nS\'120\'\np3\nsS\'servername\'\np4\nS\'default\'\np5\nsS\'client\'\np6\nS\'undefined\'\np7\nsS\'documentroot\'\np8\nS\'/var/www/\'\np9\nsS\'client_contact\'\np10\ng7\nsS\'serveralias\'\np11\n(lp12\nsa. >>>>> >>>>> It's the "pickled view" of >>>>> [{'documentroot_size': '120', 'servername': '---default---', 'client': >>>>> 'undefined', 'documentroot': '/var/www/', 'client_contact': 'undefined', >>>>> 'serveralias': []}] >>>>> >>>>> Can someone help me please ? I spend my afternoon to google to try to find >>>>> a solution... >>>>> >>>>> >>>>> Thanks in advance !!! >>>>> >>>>> Romaric Defaux >>>>> >>>>> >>>>> >>>> After entirely rewrite my code to not use Web service but socket (a real >>>> client/server program) I finally found the problem... And it's not linked to >>>> the POST or GET method... >>>> It's because of that : >>>> g.db.escape_string(fields['hosted_web_site']) >>>> (escape_string is the function in MySQLdb library) >>>> It escapes the simple quote of the pickled object, and break it... >>>> >>>> It's good to know, NEVER escape a pickled object :) >>>> >>>> Romaric Defaux >>>> >>>> >>> I'm not sure I understand what you're doing here, but I trust you've >>> read about and understand the security problems with pickle? >>> >>> Geremy Condra >>> >>> >> I read quickly the security problems with pickle. But I don't feel >> concern about that because I run my program in a private network, not >> over internet. And now I use socket to communicate on a non-standard >> port, not anymore web service on the 80 port. If I plan to run it >> through wan, I will encrypt datas for sure with SSL or something like >> that :) >> >> Romaric Defaux >> >> -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 5361 bytes Desc: S/MIME Cryptographic Signature URL: From mdw at distorted.org.uk Thu Nov 18 04:32:23 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 18 Nov 2010 09:32:23 +0000 Subject: Some syntactic sugar proposals References: <87mxp7gbdf.fsf.mdw@metalzone.distorted.org.uk> <4ce4b043$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87d3q3dljs.fsf.mdw@metalzone.distorted.org.uk> Steven D'Aprano writes: > On Wed, 17 Nov 2010 16:31:40 +0000, Mark Wooding wrote: > > > But I don't think that's the big problem with this proposal. The real > > problem is that it completely changes the evaluation rule for the > > conditional expression. (The evaluation rule is already pretty screwy: > > Python is consistently left-to-right -- except here.) > > Not quite... > > >>> 1+2*3 > 7 > >>> (1+2)*3 > 9 You're wrong. Python evaluates these left-to-right, as I said. Parentheses override operator associativity; they don't affect evaluation order at all. Consider: def say(x): print 'seen %s' % x return x print say(1) + say(2) * say(3) print (say(1) + say(2)) * say(3) Run this program and you get seen 1 seen 2 seen 3 7 seen 1 seen 2 seen 3 9 So definitely left-to-right. Translating into reverse-Polish, say with Dijkstra's shunting-yard algorithm, is enlightening: you get 1 2 3 * + for the first and 1 2 + 3 * for the second. This preserves evaluation order; indeed, this is a general property of the shunting-yard algorithm. Finally, I quote from the language reference (5.13 of the 2.5 version), just to show that (this time, at least) I'm not trying to impose unfamiliar terminology, and that Python is defined to behave like this and I'm not relying on implementation-specific details. Alas, it also highlights a genuine inconsistency, but one which might be considered tolerable. : 5.13 Evaluation order : ===================== : : Python evaluates expressions from left to right. Notice that while : evaluating an assignment, the right-hand side is evaluated before the : left-hand side. : : In the following lines, expressions will be evaluated in the : arithmetic order of their suffixes: : : expr1, expr2, expr3, expr4 : (expr1, expr2, expr3, expr4) : {expr1: expr2, expr3: expr4} : expr1 + expr2 * (expr3 - expr4) : func(expr1, expr2, *expr3, **expr4) : expr3, expr4 = expr1, expr2 So the above example is /explicitly/ dealt with in the language reference, if only you'd cared to look. > Not everything needs to be a one liner. If you need this, do it the old- > fashioned way: > > t = foo() > if not pred(t): t = default_value I already explained how to write it as a one-liner: t = (lambda y: y if pred(y) else default_value)(foo()) -- [mdw] From __peter__ at web.de Thu Nov 18 04:39:23 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 18 Nov 2010 10:39:23 +0100 Subject: String multi-replace References: Message-ID: Sorin Schwimmer wrote: > I have to eliminate diacritics in a fairly large file. > > Inspired by http://code.activestate.com/recipes/81330/, I came up with the > following code: Here's the unicode.translate()-based approach spelt out: http://effbot.org/zone/unicode-convert.htm Peter From clp2 at rebertia.com Thu Nov 18 05:05:13 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 18 Nov 2010 02:05:13 -0800 Subject: I have a question about JavaFit In-Reply-To: References: Message-ID: "We" are a technical discussion maillinglist. About a computer programming language. Named Python. An unrelated computer programming language which happens to be named "Java" also exists, but is not this mailinglist's topic of discussion. Some computer programmers personally consume a lot of coffee, but aside from that, as a group, this maillinglist's members have nothing to do with "Javalution Coffee Company" or their "JavaFit" coffee products. To put it simply, you're barking up entirely the wrong tree. How exactly were you led to believe that python-list at python.org had anything to do with JavaFit in the first place? Regards, Chris, random maillinglist subscriber On Tue, Nov 16, 2010 at 4:45 PM, Bill Fishbaugher wrote: > Hello, > > I was searching online to find more info about JavaFit and I came across your information. > > Can you tell me, are you still involved with JavaFit? If you are, how are things going for you? > > Please let me know. > > Sincerely, > Bill From rde at audaxis.com Thu Nov 18 05:22:30 2010 From: rde at audaxis.com (Romaric DEFAUX) Date: Thu, 18 Nov 2010 11:22:30 +0100 Subject: Pickle in a POST/GET request give EOFError In-Reply-To: <20101118094347.53a0980a@moriz.interne> References: <4CE2B599.7050504@audaxis.com> <4CE3EA61.2090707@audaxis.com> <4CE4E3CC.8080801@audaxis.com> <20101118094347.53a0980a@moriz.interne> Message-ID: <4CE4FE66.20904@audaxis.com> Hi again, I try simplejson, but I have a problem. (I just replace pickle everywhere by simplejson) Here's a test I did : # python Python 2.5.2 (r252:60911, Jan 20 2010, 21:48:48) [GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu3)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import simplejson >>> disk_list = [] >>> disk = {} >>> disk['name'] = "disk1" >>> disk['size'] = "52428800" >>> disk_list.append(disk) >>> print disk_list [{'name': 'disk1', 'size': '52428800'}] >>> disk = {} >>> disk['name'] = "disk2" >>> disk['size'] = "647648" >>> disk_list.append(disk) >>> print disk_list [{'name': 'disk1', 'size': '52428800'}, {'name': 'disk2', 'size': '647648'}] >>> disk_list_json = simplejson.dumps(disk_list) >>> print disk_list_json [{"name": "disk1", "size": "52428800"}, {"name": "disk2", "size": "647648"}] >>> disk_list2 = simplejson.loads(disk_list_json) >>> print disk_list2 [{u'name': u'disk1', u'size': u'52428800'}, {u'name': u'disk2', u'size': u'647648'}] >>> print repr(disk_list_json) '[{"name": "disk1", "size": "52428800"}, {"name": "disk2", "size": "647648"}]' Explanation : I "dumps" with json a list of dictionnaries into disk_list_json. When I "loads" it, I don't get my list of dictionnaries like before (see disk_list2). It adds "u" letter everywhere. Why ? Thanks for help ! Romaric Defaux Le 18/11/2010 09:43, Michael Ricordeau a ?crit : > Hi, > > you can use json for passing list and dict . > Pickle is dangerous . > > Instead of pickle.loads/pickle.dumps use json.loads and json.dumps > (using stdlib json in python>= 2.6 or simplejson in python< 2.6) > > Regards > > > > Le Thu, 18 Nov 2010 09:29:00 +0100, > Romaric DEFAUX a ?crit : > > >> Le 17/11/2010 18:52, geremy condra a ?crit : >> >>> On Wed, Nov 17, 2010 at 6:44 AM, Romaric DEFAUX wrote: >>> >>> >>>> Le 16/11/2010 17:47, Romaric DEFAUX a ?crit : >>>> >>>> >>>>> Hi everybody ! >>>>> >>>>> First time I write to this mailing list :) >>>>> I started writing in python last week, that's probably why I can't >>>>> understand the following problem... >>>>> >>>>> >>>>> I create a list called web_site_list. >>>>> This list contain dictionaries called web_site. >>>>> And some values in this dictionaries are list too. >>>>> >>>>> I do that in a function and I return this : >>>>> return pickle.dumps(web_site_list) >>>>> >>>>> This is working fine :) >>>>> >>>>> If I do : >>>>> print "%s" % pickle.loads(system.get_web_site_list()) >>>>> >>>>> I've got the right stuffs. For example it returns : >>>>> [{'documentroot_size': '120', 'servername': '---default---', 'client': >>>>> 'undefined', 'documentroot': '/var/www/', 'client_contact': 'undefined', >>>>> 'serveralias': []}] >>>>> >>>>> I send this to a web service. I send it like that : >>>>> #I put it in params >>>>> def system_updateweb_site(server, login, password): >>>>> params = {} >>>>> params['login'] = login >>>>> params['password'] = password >>>>> params['action'] = 'updateweb_site' >>>>> params['servername'] = get_servername() >>>>> params['hosted_web_site'] = get_web_site_list() >>>>> return call_system_ws(server, params) >>>>> >>>>> #Here's how I send it (I tried in GET and POST) >>>>> def call_system_ws(host, params): >>>>> query_string = urllib.urlencode(params) >>>>> #GET >>>>> # f = urllib.urlopen("http://%s/ws?%s" % (host, query_string)) >>>>> #POST >>>>> f = urllib.urlopen("http://%s/ws" % (host), query_string) >>>>> result = f.readline().strip() >>>>> if result == 'ERROR': >>>>> msg = f.readline().strip() >>>>> return (False, msg) >>>>> return (True, result) >>>>> >>>>> >>>>> On the server side : >>>>> if action == 'updateweb_site': >>>>> if not (fields.has_key('servername') and >>>>> fields.has_key('hosted_web_site')): >>>>> raise WSError('missing parameter : >>>>> servername or hosted_web_site') >>>>> log ('ERROR : missing parameter : >>>>> servername or hosted_web_site') >>>>> else: >>>>> >>>>> servername=g.db.escape_string(fields['servername']) >>>>> >>>>> hosted_web_site=g.db.escape_string(fields['hosted_web_site']) >>>>> output = >>>>> systemserver.updateweb_site(cursor, servername, hosted_web_site) >>>>> >>>>> In systemserver.py : >>>>> def updateweb_site(cursor, host, hosted_web_site): >>>>> web_site_list = pickle.loads(hosted_web_site) >>>>> return "%s" % (web_site_list) >>>>> >>>>> I catch this error :* >>>>> >>>>> *: >>>>> >>>>> args = () >>>>> message = '' >>>>> >>>>> Why ? >>>>> >>>>> If I just print hosted_web_site, I get this on my web page : >>>>> >>>>> >>>>> (lp0\n(dp1\nS\'documentroot_size\'\np2\nS\'120\'\np3\nsS\'servername\'\np4\nS\'default\'\np5\nsS\'client\'\np6\nS\'undefined\'\np7\nsS\'documentroot\'\np8\nS\'/var/www/\'\np9\nsS\'client_contact\'\np10\ng7\nsS\'serveralias\'\np11\n(lp12\nsa. >>>>> >>>>> It's the "pickled view" of >>>>> [{'documentroot_size': '120', 'servername': '---default---', 'client': >>>>> 'undefined', 'documentroot': '/var/www/', 'client_contact': 'undefined', >>>>> 'serveralias': []}] >>>>> >>>>> Can someone help me please ? I spend my afternoon to google to try to find >>>>> a solution... >>>>> >>>>> >>>>> Thanks in advance !!! >>>>> >>>>> Romaric Defaux >>>>> >>>>> >>>>> >>>> After entirely rewrite my code to not use Web service but socket (a real >>>> client/server program) I finally found the problem... And it's not linked to >>>> the POST or GET method... >>>> It's because of that : >>>> g.db.escape_string(fields['hosted_web_site']) >>>> (escape_string is the function in MySQLdb library) >>>> It escapes the simple quote of the pickled object, and break it... >>>> >>>> It's good to know, NEVER escape a pickled object :) >>>> >>>> Romaric Defaux >>>> >>>> >>> I'm not sure I understand what you're doing here, but I trust you've >>> read about and understand the security problems with pickle? >>> >>> Geremy Condra >>> >>> >> I read quickly the security problems with pickle. But I don't feel >> concern about that because I run my program in a private network, not >> over internet. And now I use socket to communicate on a non-standard >> port, not anymore web service on the 80 port. If I plan to run it >> through wan, I will encrypt datas for sure with SSL or something like >> that :) >> >> Romaric Defaux >> >> -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 5361 bytes Desc: S/MIME Cryptographic Signature URL: From michael.ricordeau at gmail.com Thu Nov 18 05:26:00 2010 From: michael.ricordeau at gmail.com (Michael Ricordeau) Date: Thu, 18 Nov 2010 11:26:00 +0100 Subject: Pickle in a POST/GET request give EOFError In-Reply-To: <4CE4FE66.20904@audaxis.com> References: <4CE2B599.7050504@audaxis.com> <4CE3EA61.2090707@audaxis.com> <4CE4E3CC.8080801@audaxis.com> <20101118094347.53a0980a@moriz.interne> <4CE4FE66.20904@audaxis.com> Message-ID: <20101118112600.4ea01146@moriz.interne> When loading from json datas with simplejson, strings are unicode . Le Thu, 18 Nov 2010 11:22:30 +0100, Romaric DEFAUX a ?crit : > Hi again, > > I try simplejson, but I have a problem. (I just replace pickle > everywhere by simplejson) > > Here's a test I did : > # python > Python 2.5.2 (r252:60911, Jan 20 2010, 21:48:48) > [GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu3)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import simplejson > >>> disk_list = [] > >>> disk = {} > >>> disk['name'] = "disk1" > >>> disk['size'] = "52428800" > >>> disk_list.append(disk) > >>> print disk_list > [{'name': 'disk1', 'size': '52428800'}] > >>> disk = {} > >>> disk['name'] = "disk2" > >>> disk['size'] = "647648" > >>> disk_list.append(disk) > >>> print disk_list > [{'name': 'disk1', 'size': '52428800'}, {'name': 'disk2', 'size': '647648'}] > >>> disk_list_json = simplejson.dumps(disk_list) > >>> print disk_list_json > [{"name": "disk1", "size": "52428800"}, {"name": "disk2", "size": "647648"}] > >>> disk_list2 = simplejson.loads(disk_list_json) > >>> print disk_list2 > [{u'name': u'disk1', u'size': u'52428800'}, {u'name': u'disk2', u'size': > u'647648'}] > >>> print repr(disk_list_json) > '[{"name": "disk1", "size": "52428800"}, {"name": "disk2", "size": > "647648"}]' > > Explanation : > I "dumps" with json a list of dictionnaries into disk_list_json. > When I "loads" it, I don't get my list of dictionnaries like before (see > disk_list2). It adds "u" letter everywhere. > Why ? > Thanks for help ! > > Romaric Defaux > > Le 18/11/2010 09:43, Michael Ricordeau a ?crit : > > Hi, > > > > you can use json for passing list and dict . > > Pickle is dangerous . > > > > Instead of pickle.loads/pickle.dumps use json.loads and json.dumps > > (using stdlib json in python>= 2.6 or simplejson in python< 2.6) > > > > Regards > > > > > > > > Le Thu, 18 Nov 2010 09:29:00 +0100, > > Romaric DEFAUX a ?crit : > > > > > >> Le 17/11/2010 18:52, geremy condra a ?crit : > >> > >>> On Wed, Nov 17, 2010 at 6:44 AM, Romaric DEFAUX wrote: > >>> > >>> > >>>> Le 16/11/2010 17:47, Romaric DEFAUX a ?crit : > >>>> > >>>> > >>>>> Hi everybody ! > >>>>> > >>>>> First time I write to this mailing list :) > >>>>> I started writing in python last week, that's probably why I can't > >>>>> understand the following problem... > >>>>> > >>>>> > >>>>> I create a list called web_site_list. > >>>>> This list contain dictionaries called web_site. > >>>>> And some values in this dictionaries are list too. > >>>>> > >>>>> I do that in a function and I return this : > >>>>> return pickle.dumps(web_site_list) > >>>>> > >>>>> This is working fine :) > >>>>> > >>>>> If I do : > >>>>> print "%s" % pickle.loads(system.get_web_site_list()) > >>>>> > >>>>> I've got the right stuffs. For example it returns : > >>>>> [{'documentroot_size': '120', 'servername': '---default---', 'client': > >>>>> 'undefined', 'documentroot': '/var/www/', 'client_contact': 'undefined', > >>>>> 'serveralias': []}] > >>>>> > >>>>> I send this to a web service. I send it like that : > >>>>> #I put it in params > >>>>> def system_updateweb_site(server, login, password): > >>>>> params = {} > >>>>> params['login'] = login > >>>>> params['password'] = password > >>>>> params['action'] = 'updateweb_site' > >>>>> params['servername'] = get_servername() > >>>>> params['hosted_web_site'] = get_web_site_list() > >>>>> return call_system_ws(server, params) > >>>>> > >>>>> #Here's how I send it (I tried in GET and POST) > >>>>> def call_system_ws(host, params): > >>>>> query_string = urllib.urlencode(params) > >>>>> #GET > >>>>> # f = urllib.urlopen("http://%s/ws?%s" % (host, query_string)) > >>>>> #POST > >>>>> f = urllib.urlopen("http://%s/ws" % (host), query_string) > >>>>> result = f.readline().strip() > >>>>> if result == 'ERROR': > >>>>> msg = f.readline().strip() > >>>>> return (False, msg) > >>>>> return (True, result) > >>>>> > >>>>> > >>>>> On the server side : > >>>>> if action == 'updateweb_site': > >>>>> if not (fields.has_key('servername') and > >>>>> fields.has_key('hosted_web_site')): > >>>>> raise WSError('missing parameter : > >>>>> servername or hosted_web_site') > >>>>> log ('ERROR : missing parameter : > >>>>> servername or hosted_web_site') > >>>>> else: > >>>>> > >>>>> servername=g.db.escape_string(fields['servername']) > >>>>> > >>>>> hosted_web_site=g.db.escape_string(fields['hosted_web_site']) > >>>>> output = > >>>>> systemserver.updateweb_site(cursor, servername, hosted_web_site) > >>>>> > >>>>> In systemserver.py : > >>>>> def updateweb_site(cursor, host, hosted_web_site): > >>>>> web_site_list = pickle.loads(hosted_web_site) > >>>>> return "%s" % (web_site_list) > >>>>> > >>>>> I catch this error :* > >>>>> > >>>>> *: > >>>>> > >>>>> args = () > >>>>> message = '' > >>>>> > >>>>> Why ? > >>>>> > >>>>> If I just print hosted_web_site, I get this on my web page : > >>>>> > >>>>> > >>>>> (lp0\n(dp1\nS\'documentroot_size\'\np2\nS\'120\'\np3\nsS\'servername\'\np4\nS\'default\'\np5\nsS\'client\'\np6\nS\'undefined\'\np7\nsS\'documentroot\'\np8\nS\'/var/www/\'\np9\nsS\'client_contact\'\np10\ng7\nsS\'serveralias\'\np11\n(lp12\nsa. > >>>>> > >>>>> It's the "pickled view" of > >>>>> [{'documentroot_size': '120', 'servername': '---default---', 'client': > >>>>> 'undefined', 'documentroot': '/var/www/', 'client_contact': 'undefined', > >>>>> 'serveralias': []}] > >>>>> > >>>>> Can someone help me please ? I spend my afternoon to google to try to find > >>>>> a solution... > >>>>> > >>>>> > >>>>> Thanks in advance !!! > >>>>> > >>>>> Romaric Defaux > >>>>> > >>>>> > >>>>> > >>>> After entirely rewrite my code to not use Web service but socket (a real > >>>> client/server program) I finally found the problem... And it's not linked to > >>>> the POST or GET method... > >>>> It's because of that : > >>>> g.db.escape_string(fields['hosted_web_site']) > >>>> (escape_string is the function in MySQLdb library) > >>>> It escapes the simple quote of the pickled object, and break it... > >>>> > >>>> It's good to know, NEVER escape a pickled object :) > >>>> > >>>> Romaric Defaux > >>>> > >>>> > >>> I'm not sure I understand what you're doing here, but I trust you've > >>> read about and understand the security problems with pickle? > >>> > >>> Geremy Condra > >>> > >>> > >> I read quickly the security problems with pickle. But I don't feel > >> concern about that because I run my program in a private network, not > >> over internet. And now I use socket to communicate on a non-standard > >> port, not anymore web service on the 80 port. If I plan to run it > >> through wan, I will encrypt datas for sure with SSL or something like > >> that :) > >> > >> Romaric Defaux > >> > >> > > From jeanmichel at sequans.com Thu Nov 18 05:50:39 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 18 Nov 2010 11:50:39 +0100 Subject: strange subprocess behavior when calling ps In-Reply-To: <1ed38051-9c8b-4ae8-9a88-9833209d2775@h21g2000vbh.googlegroups.com> References: <55f26d5c-aba9-4892-9e2c-1caa9988e7fe@v23g2000vbi.googlegroups.com> <1ed38051-9c8b-4ae8-9a88-9833209d2775@h21g2000vbh.googlegroups.com> Message-ID: <4CE504FF.2080709@sequans.com> Roger Davis wrote: >> Completely off topic but I think the try clause could be rewritten that way: >> ... >> Don't use bare except clause, you're masking syntax errors for instance, >> which will be flagged as 'unexpected error in generation ...". >> In a more general manner, if something unexpected happens it's better to >> just let the exception raise uncought. If you want to handle some >> errors, meaning you're kindof expecting them then add a explicit clause >> (like you did with KeyboardInterrupt). >> >> JM >> >> PS : "except Exception :" will catch most of the exceptions (all >> inheriting from that class). It's better than using a bare "except :" >> clause. (Exception won't catch SyntaxError) >> > > Thanks for the suggestion JM, it is off-topic and, although I will > first just say that the exception mechanism is *not* one of the > reasons I use Python (and stop there with regard to the whole > exception mechanism and various usage strategies in general), I do > have a few specific questions about a couple of your statements if you > don't mind following up. > > First, inserting a syntax error into my existing code does not hide a > SyntaxError exception as you have stated: > > % cat pid.py > #!/usr/bin/python > import os > import sys > import subprocess > > def main(): > > psargs= ["/bin/ps", "-e"] > try: > ps= subprocess.Popen(psargs, stdout=subprocess.PIPE, close_fds=True) > psout= ps.communicate()[0] > pslines= psout.splitlines() > if pslines not good Python talky-talk > for line in pslines: > print "%s" % line > except KeyboardInterrupt: > print "Keyboard interrupt received -- terminating." > sys.stdout.flush() > sys.exit(-1) > except: > print "%s: unexpected error in generation of system process list" % > prognm > sys.stdout.flush() > sys.exit(-1) > > main() > > % ./pid.py > File "./pid.py", line 14 > if pslines not good Python talky-talk > ^ > SyntaxError: invalid syntax > > It appears that the interpreter is catching the syntax error before > the code is even executed. > > That's right, 'cause my example is approximative. You would need to import that file. A better example would be to fire a NameError exception. In the above code of fix the syntax error, but replace "for line in pslines" by "for line in psLines". note the typo, very common mistake. Then see how the error is hidden by your handler. > Second, python.org's exception hierarchy documentation (Section 6.1 at > http://docs.python.org/library/exceptions.html) shows all exception > types except SystemExit, KeyboardInterrupt and GeneratorExit as being > descendants of Exception. This includes SyntaxError, a child of > StandardError which is itself a child of Exception. So, if I say > 'except Exception:' then isn't that clause going to process any child > exception type of Exception (including SyntaxError) that I haven't > already covered in a separate except clause? You're absolutely right. Using Exception is bad, using bare except is even worse. Exception is slightly better than except because you can at least get the exception instance that has been raised, print it in your handler, so you don't loose information (well, with a bare except you can still inspect some sys objects to get info about the last exception but it's a bit hackish). > (Except of course that my > interpreter doesn't seem to treat a syntax error as any kind of > exception at all!) > > Finally, and this does not apply to your comments in particular, in > researching around about exception handling I often see the usage > > except Exception, e: > > suggested, but can't for the life of me figure out what the heck the > ', e' part does. Can anybody explain what this means and why it might > be desirable (or not)? > > Thanks! > > > Exception is the class, e is an instance of that class that has been actually fired, it contains informations, most of the time a message. This syntax has changed in python 3 I think, that would mean that you're right to be confused, this python 2 syntax is ... strange... import sys # what if someone writes sys.hihi ? try: raise AttributeError("sys object has no attribute 'hihi'") except Exception, e: print e.args print e.__class__ print e.message print e.__doc__ output: ("sys object has no attribute 'hihi'",) sys object has no attribute 'hihi' Attribute not found. Apart from all these details, just keep in mind this golden rule: - Don't use bare except clause. And you'll be fine. JM From jeanmichel at sequans.com Thu Nov 18 06:02:04 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 18 Nov 2010 12:02:04 +0100 Subject: How to run an EXE, with argument, capture output value In-Reply-To: References: <37037d15-63da-4f37-9508-bdcfff034670@s4g2000yql.googlegroups.com> Message-ID: <4CE507AC.1030006@sequans.com> Tim Harig wrote: > On 2010-11-18, noydb wrote: > >> I have an executable that I want to run within python code. The exe >> requires an input text file, the user to click a 'compute' button, and >> then the exe calculates several output values, one of which I want to >> capture into a variable. Can I use Python to supply the input file, >> execute the exe and capture the output value, like such that the exe >> really doesn't need to be 'seen'? Or, would the user still have to >> click the 'compute' button? >> >> Any code snippets or guidance would be very much appreciated. I have >> found that >> >> import os >> os.system('C:\xTool\stats_hall.exe') >> >> will run the exe. And, maybe these execl/execle/execlp/etc functions >> might be what I need for adding in the argument, but documentation >> seems to indicate that these do not return output. ?? >> > > If you are not already, I would highly suggest using Python3 with the > subprocess module: > > http://docs.python.org/py3k/library/subprocess.html > > It puts everything in one place and supercedes the exec* functions which > where a PITA. You can 95% of what you need simply using > subprocess.Popen(). There are several examples from this group in the past > few days; but, the process looks something like this: > > Python 3.1.2 (r312:79147, Oct 9 2010, 00:16:06) > [GCC 4.4.4] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import subprocess > >>> pig = subprocess.Popen(["/usr/games/pig"], stdin=subprocess.PIPE) > >>> result = pig.communicate(input=b"This is sample text.\n") > Isthay isway amplesay exttay. > >>> > Suggesting subprocess is a good idea, *highly* suggesting python3 is questionable. The above code works in python 2. Many libraries (those included batteries) have not been ported yet to python 3. Py3 is a better core language than py2, but for now, less featured. JM From rde at audaxis.com Thu Nov 18 06:23:01 2010 From: rde at audaxis.com (Romaric DEFAUX) Date: Thu, 18 Nov 2010 12:23:01 +0100 Subject: Pickle in a POST/GET request give EOFError In-Reply-To: <20101118112600.4ea01146@moriz.interne> References: <4CE2B599.7050504@audaxis.com> <4CE3EA61.2090707@audaxis.com> <4CE4E3CC.8080801@audaxis.com> <20101118094347.53a0980a@moriz.interne> <4CE4FE66.20904@audaxis.com> <20101118112600.4ea01146@moriz.interne> Message-ID: <4CE50C95.4090407@audaxis.com> Sorry for this stupid question, but how can I convert unicode to string. I ask that because I hit an error (perhaps a bug) in mod_wsgi, and that crash the apache process : TypeError: sequence of string values expected, value of type unicode found RuntimeError: generator ignored GeneratorExit child pid 16211 exit signal Segmentation fault (11) Romaric Defaux Le 18/11/2010 11:26, Michael Ricordeau a ?crit : > When loading from json datas with simplejson, strings are unicode . > > > Le Thu, 18 Nov 2010 11:22:30 +0100, > Romaric DEFAUX a ?crit : > > >> Hi again, >> >> I try simplejson, but I have a problem. (I just replace pickle >> everywhere by simplejson) >> >> Here's a test I did : >> # python >> Python 2.5.2 (r252:60911, Jan 20 2010, 21:48:48) >> [GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu3)] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. >> >>> import simplejson >> >>> disk_list = [] >> >>> disk = {} >> >>> disk['name'] = "disk1" >> >>> disk['size'] = "52428800" >> >>> disk_list.append(disk) >> >>> print disk_list >> [{'name': 'disk1', 'size': '52428800'}] >> >>> disk = {} >> >>> disk['name'] = "disk2" >> >>> disk['size'] = "647648" >> >>> disk_list.append(disk) >> >>> print disk_list >> [{'name': 'disk1', 'size': '52428800'}, {'name': 'disk2', 'size': '647648'}] >> >>> disk_list_json = simplejson.dumps(disk_list) >> >>> print disk_list_json >> [{"name": "disk1", "size": "52428800"}, {"name": "disk2", "size": "647648"}] >> >>> disk_list2 = simplejson.loads(disk_list_json) >> >>> print disk_list2 >> [{u'name': u'disk1', u'size': u'52428800'}, {u'name': u'disk2', u'size': >> u'647648'}] >> >>> print repr(disk_list_json) >> '[{"name": "disk1", "size": "52428800"}, {"name": "disk2", "size": >> "647648"}]' >> >> Explanation : >> I "dumps" with json a list of dictionnaries into disk_list_json. >> When I "loads" it, I don't get my list of dictionnaries like before (see >> disk_list2). It adds "u" letter everywhere. >> Why ? >> Thanks for help ! >> >> Romaric Defaux >> >> Le 18/11/2010 09:43, Michael Ricordeau a ?crit : >> >>> Hi, >>> >>> you can use json for passing list and dict . >>> Pickle is dangerous . >>> >>> Instead of pickle.loads/pickle.dumps use json.loads and json.dumps >>> (using stdlib json in python>= 2.6 or simplejson in python< 2.6) >>> >>> Regards >>> >>> >>> >>> Le Thu, 18 Nov 2010 09:29:00 +0100, >>> Romaric DEFAUX a ?crit : >>> >>> >>> >>>> Le 17/11/2010 18:52, geremy condra a ?crit : >>>> >>>> >>>>> On Wed, Nov 17, 2010 at 6:44 AM, Romaric DEFAUX wrote: >>>>> >>>>> >>>>> >>>>>> Le 16/11/2010 17:47, Romaric DEFAUX a ?crit : >>>>>> >>>>>> >>>>>> >>>>>>> Hi everybody ! >>>>>>> >>>>>>> First time I write to this mailing list :) >>>>>>> I started writing in python last week, that's probably why I can't >>>>>>> understand the following problem... >>>>>>> >>>>>>> >>>>>>> I create a list called web_site_list. >>>>>>> This list contain dictionaries called web_site. >>>>>>> And some values in this dictionaries are list too. >>>>>>> >>>>>>> I do that in a function and I return this : >>>>>>> return pickle.dumps(web_site_list) >>>>>>> >>>>>>> This is working fine :) >>>>>>> >>>>>>> If I do : >>>>>>> print "%s" % pickle.loads(system.get_web_site_list()) >>>>>>> >>>>>>> I've got the right stuffs. For example it returns : >>>>>>> [{'documentroot_size': '120', 'servername': '---default---', 'client': >>>>>>> 'undefined', 'documentroot': '/var/www/', 'client_contact': 'undefined', >>>>>>> 'serveralias': []}] >>>>>>> >>>>>>> I send this to a web service. I send it like that : >>>>>>> #I put it in params >>>>>>> def system_updateweb_site(server, login, password): >>>>>>> params = {} >>>>>>> params['login'] = login >>>>>>> params['password'] = password >>>>>>> params['action'] = 'updateweb_site' >>>>>>> params['servername'] = get_servername() >>>>>>> params['hosted_web_site'] = get_web_site_list() >>>>>>> return call_system_ws(server, params) >>>>>>> >>>>>>> #Here's how I send it (I tried in GET and POST) >>>>>>> def call_system_ws(host, params): >>>>>>> query_string = urllib.urlencode(params) >>>>>>> #GET >>>>>>> # f = urllib.urlopen("http://%s/ws?%s" % (host, query_string)) >>>>>>> #POST >>>>>>> f = urllib.urlopen("http://%s/ws" % (host), query_string) >>>>>>> result = f.readline().strip() >>>>>>> if result == 'ERROR': >>>>>>> msg = f.readline().strip() >>>>>>> return (False, msg) >>>>>>> return (True, result) >>>>>>> >>>>>>> >>>>>>> On the server side : >>>>>>> if action == 'updateweb_site': >>>>>>> if not (fields.has_key('servername') and >>>>>>> fields.has_key('hosted_web_site')): >>>>>>> raise WSError('missing parameter : >>>>>>> servername or hosted_web_site') >>>>>>> log ('ERROR : missing parameter : >>>>>>> servername or hosted_web_site') >>>>>>> else: >>>>>>> >>>>>>> servername=g.db.escape_string(fields['servername']) >>>>>>> >>>>>>> hosted_web_site=g.db.escape_string(fields['hosted_web_site']) >>>>>>> output = >>>>>>> systemserver.updateweb_site(cursor, servername, hosted_web_site) >>>>>>> >>>>>>> In systemserver.py : >>>>>>> def updateweb_site(cursor, host, hosted_web_site): >>>>>>> web_site_list = pickle.loads(hosted_web_site) >>>>>>> return "%s" % (web_site_list) >>>>>>> >>>>>>> I catch this error :* >>>>>>> >>>>>>> *: >>>>>>> >>>>>>> args = () >>>>>>> message = '' >>>>>>> >>>>>>> Why ? >>>>>>> >>>>>>> If I just print hosted_web_site, I get this on my web page : >>>>>>> >>>>>>> >>>>>>> (lp0\n(dp1\nS\'documentroot_size\'\np2\nS\'120\'\np3\nsS\'servername\'\np4\nS\'default\'\np5\nsS\'client\'\np6\nS\'undefined\'\np7\nsS\'documentroot\'\np8\nS\'/var/www/\'\np9\nsS\'client_contact\'\np10\ng7\nsS\'serveralias\'\np11\n(lp12\nsa. >>>>>>> >>>>>>> It's the "pickled view" of >>>>>>> [{'documentroot_size': '120', 'servername': '---default---', 'client': >>>>>>> 'undefined', 'documentroot': '/var/www/', 'client_contact': 'undefined', >>>>>>> 'serveralias': []}] >>>>>>> >>>>>>> Can someone help me please ? I spend my afternoon to google to try to find >>>>>>> a solution... >>>>>>> >>>>>>> >>>>>>> Thanks in advance !!! >>>>>>> >>>>>>> Romaric Defaux >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>> After entirely rewrite my code to not use Web service but socket (a real >>>>>> client/server program) I finally found the problem... And it's not linked to >>>>>> the POST or GET method... >>>>>> It's because of that : >>>>>> g.db.escape_string(fields['hosted_web_site']) >>>>>> (escape_string is the function in MySQLdb library) >>>>>> It escapes the simple quote of the pickled object, and break it... >>>>>> >>>>>> It's good to know, NEVER escape a pickled object :) >>>>>> >>>>>> Romaric Defaux >>>>>> >>>>>> >>>>>> >>>>> I'm not sure I understand what you're doing here, but I trust you've >>>>> read about and understand the security problems with pickle? >>>>> >>>>> Geremy Condra >>>>> >>>>> >>>>> >>>> I read quickly the security problems with pickle. But I don't feel >>>> concern about that because I run my program in a private network, not >>>> over internet. And now I use socket to communicate on a non-standard >>>> port, not anymore web service on the 80 port. If I plan to run it >>>> through wan, I will encrypt datas for sure with SSL or something like >>>> that :) >>>> >>>> Romaric Defaux >>>> >>>> >>>> >> >> -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 5361 bytes Desc: S/MIME Cryptographic Signature URL: From pmilin at gmail.com Thu Nov 18 06:26:14 2010 From: pmilin at gmail.com (neocortex) Date: Thu, 18 Nov 2010 03:26:14 -0800 (PST) Subject: Does Pygoogle allows for advanced search options? References: Message-ID: <706ff3ad-66b4-4cdb-a68f-bf0a079c2dc1@32g2000yqz.googlegroups.com> > The library doesn't seem to have built-in support for filtering by > language (and Google lacks a search query-string-based operator for > that), but it looks like you could implement that feature by adding an > "lr" parameter with an appropriate value to the query `args` > dictionary. See the "lr?" entry under "Web Search Specific Arguments" > onhttp://code.google.com/apis/websearch/docs/reference.html, and > lines 68 & 102 of pygoogle.py. >From those lines, it can be concluded that lr=lang_?? is not supported, unfortunately. And, when I execute, I get an error. Is there any other way to get Google search from Python? I really need only number of hits. Best, PM From rde at audaxis.com Thu Nov 18 06:27:32 2010 From: rde at audaxis.com (Romaric DEFAUX) Date: Thu, 18 Nov 2010 12:27:32 +0100 Subject: Pickle in a POST/GET request give EOFError In-Reply-To: <4CE50C95.4090407@audaxis.com> References: <4CE2B599.7050504@audaxis.com> <4CE3EA61.2090707@audaxis.com> <4CE4E3CC.8080801@audaxis.com> <20101118094347.53a0980a@moriz.interne> <4CE4FE66.20904@audaxis.com> <20101118112600.4ea01146@moriz.interne> <4CE50C95.4090407@audaxis.com> Message-ID: <4CE50DA4.50806@audaxis.com> Hi answer to myself :) With str(unicode_string) ! Le 18/11/2010 12:23, Romaric DEFAUX a ?crit : > Sorry for this stupid question, but how can I convert unicode to string. > I ask that because I hit an error (perhaps a bug) in mod_wsgi, and > that crash the apache process : > > TypeError: sequence of string values expected, value of type unicode > found > RuntimeError: generator ignored GeneratorExit > child pid 16211 exit signal Segmentation fault (11) > > Romaric Defaux > > Le 18/11/2010 11:26, Michael Ricordeau a ?crit : >> When loading from json datas with simplejson, strings are unicode . >> >> >> Le Thu, 18 Nov 2010 11:22:30 +0100, >> Romaric DEFAUX a ?crit : >> >>> Hi again, >>> >>> I try simplejson, but I have a problem. (I just replace pickle >>> everywhere by simplejson) >>> >>> Here's a test I did : >>> # python >>> Python 2.5.2 (r252:60911, Jan 20 2010, 21:48:48) >>> [GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu3)] on linux2 >>> Type "help", "copyright", "credits" or "license" for more information. >>> >>> import simplejson >>> >>> disk_list = [] >>> >>> disk = {} >>> >>> disk['name'] = "disk1" >>> >>> disk['size'] = "52428800" >>> >>> disk_list.append(disk) >>> >>> print disk_list >>> [{'name': 'disk1', 'size': '52428800'}] >>> >>> disk = {} >>> >>> disk['name'] = "disk2" >>> >>> disk['size'] = "647648" >>> >>> disk_list.append(disk) >>> >>> print disk_list >>> [{'name': 'disk1', 'size': '52428800'}, {'name': 'disk2', 'size': >>> '647648'}] >>> >>> disk_list_json = simplejson.dumps(disk_list) >>> >>> print disk_list_json >>> [{"name": "disk1", "size": "52428800"}, {"name": "disk2", "size": >>> "647648"}] >>> >>> disk_list2 = simplejson.loads(disk_list_json) >>> >>> print disk_list2 >>> [{u'name': u'disk1', u'size': u'52428800'}, {u'name': u'disk2', >>> u'size': >>> u'647648'}] >>> >>> print repr(disk_list_json) >>> '[{"name": "disk1", "size": "52428800"}, {"name": "disk2", "size": >>> "647648"}]' >>> >>> Explanation : >>> I "dumps" with json a list of dictionnaries into disk_list_json. >>> When I "loads" it, I don't get my list of dictionnaries like before >>> (see >>> disk_list2). It adds "u" letter everywhere. >>> Why ? >>> Thanks for help ! >>> >>> Romaric Defaux >>> >>> Le 18/11/2010 09:43, Michael Ricordeau a ?crit : >>>> Hi, >>>> >>>> you can use json for passing list and dict . >>>> Pickle is dangerous . >>>> >>>> Instead of pickle.loads/pickle.dumps use json.loads and json.dumps >>>> (using stdlib json in python>= 2.6 or simplejson in python< 2.6) >>>> >>>> Regards >>>> >>>> >>>> >>>> Le Thu, 18 Nov 2010 09:29:00 +0100, >>>> Romaric DEFAUX a ?crit : >>>> >>>> >>>>> Le 17/11/2010 18:52, geremy condra a ?crit : >>>>> >>>>>> On Wed, Nov 17, 2010 at 6:44 AM, Romaric >>>>>> DEFAUX wrote: >>>>>> >>>>>> >>>>>>> Le 16/11/2010 17:47, Romaric DEFAUX a ?crit : >>>>>>> >>>>>>> >>>>>>>> Hi everybody ! >>>>>>>> >>>>>>>> First time I write to this mailing list :) >>>>>>>> I started writing in python last week, that's probably why I can't >>>>>>>> understand the following problem... >>>>>>>> >>>>>>>> >>>>>>>> I create a list called web_site_list. >>>>>>>> This list contain dictionaries called web_site. >>>>>>>> And some values in this dictionaries are list too. >>>>>>>> >>>>>>>> I do that in a function and I return this : >>>>>>>> return pickle.dumps(web_site_list) >>>>>>>> >>>>>>>> This is working fine :) >>>>>>>> >>>>>>>> If I do : >>>>>>>> print "%s" % pickle.loads(system.get_web_site_list()) >>>>>>>> >>>>>>>> I've got the right stuffs. For example it returns : >>>>>>>> [{'documentroot_size': '120', 'servername': '---default---', >>>>>>>> 'client': >>>>>>>> 'undefined', 'documentroot': '/var/www/', 'client_contact': >>>>>>>> 'undefined', >>>>>>>> 'serveralias': []}] >>>>>>>> >>>>>>>> I send this to a web service. I send it like that : >>>>>>>> #I put it in params >>>>>>>> def system_updateweb_site(server, login, password): >>>>>>>> params = {} >>>>>>>> params['login'] = login >>>>>>>> params['password'] = password >>>>>>>> params['action'] = 'updateweb_site' >>>>>>>> params['servername'] = get_servername() >>>>>>>> params['hosted_web_site'] = get_web_site_list() >>>>>>>> return call_system_ws(server, params) >>>>>>>> >>>>>>>> #Here's how I send it (I tried in GET and POST) >>>>>>>> def call_system_ws(host, params): >>>>>>>> query_string = urllib.urlencode(params) >>>>>>>> #GET >>>>>>>> # f = urllib.urlopen("http://%s/ws?%s" % (host, >>>>>>>> query_string)) >>>>>>>> #POST >>>>>>>> f = urllib.urlopen("http://%s/ws" % (host), >>>>>>>> query_string) >>>>>>>> result = f.readline().strip() >>>>>>>> if result == 'ERROR': >>>>>>>> msg = f.readline().strip() >>>>>>>> return (False, msg) >>>>>>>> return (True, result) >>>>>>>> >>>>>>>> >>>>>>>> On the server side : >>>>>>>> if action == 'updateweb_site': >>>>>>>> if not >>>>>>>> (fields.has_key('servername') and >>>>>>>> fields.has_key('hosted_web_site')): >>>>>>>> raise >>>>>>>> WSError('missing parameter : >>>>>>>> servername or hosted_web_site') >>>>>>>> log ('ERROR : missing >>>>>>>> parameter : >>>>>>>> servername or hosted_web_site') >>>>>>>> else: >>>>>>>> >>>>>>>> servername=g.db.escape_string(fields['servername']) >>>>>>>> >>>>>>>> hosted_web_site=g.db.escape_string(fields['hosted_web_site']) >>>>>>>> output = >>>>>>>> systemserver.updateweb_site(cursor, servername, hosted_web_site) >>>>>>>> >>>>>>>> In systemserver.py : >>>>>>>> def updateweb_site(cursor, host, hosted_web_site): >>>>>>>> web_site_list = pickle.loads(hosted_web_site) >>>>>>>> return "%s" % (web_site_list) >>>>>>>> >>>>>>>> I catch this error :* >>>>>>>> >>>>>>>> *: >>>>>>>> >>>>>>>> args = () >>>>>>>> message = '' >>>>>>>> >>>>>>>> Why ? >>>>>>>> >>>>>>>> If I just print hosted_web_site, I get this on my web page : >>>>>>>> >>>>>>>> >>>>>>>> (lp0\n(dp1\nS\'documentroot_size\'\np2\nS\'120\'\np3\nsS\'servername\'\np4\nS\'default\'\np5\nsS\'client\'\np6\nS\'undefined\'\np7\nsS\'documentroot\'\np8\nS\'/var/www/\'\np9\nsS\'client_contact\'\np10\ng7\nsS\'serveralias\'\np11\n(lp12\nsa. >>>>>>>> >>>>>>>> >>>>>>>> It's the "pickled view" of >>>>>>>> [{'documentroot_size': '120', 'servername': '---default---', >>>>>>>> 'client': >>>>>>>> 'undefined', 'documentroot': '/var/www/', 'client_contact': >>>>>>>> 'undefined', >>>>>>>> 'serveralias': []}] >>>>>>>> >>>>>>>> Can someone help me please ? I spend my afternoon to google to >>>>>>>> try to find >>>>>>>> a solution... >>>>>>>> >>>>>>>> >>>>>>>> Thanks in advance !!! >>>>>>>> >>>>>>>> Romaric Defaux >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>> After entirely rewrite my code to not use Web service but socket >>>>>>> (a real >>>>>>> client/server program) I finally found the problem... And it's >>>>>>> not linked to >>>>>>> the POST or GET method... >>>>>>> It's because of that : >>>>>>> g.db.escape_string(fields['hosted_web_site']) >>>>>>> (escape_string is the function in MySQLdb library) >>>>>>> It escapes the simple quote of the pickled object, and break it... >>>>>>> >>>>>>> It's good to know, NEVER escape a pickled object :) >>>>>>> >>>>>>> Romaric Defaux >>>>>>> >>>>>>> >>>>>> I'm not sure I understand what you're doing here, but I trust you've >>>>>> read about and understand the security problems with pickle? >>>>>> >>>>>> Geremy Condra >>>>>> >>>>>> >>>>> I read quickly the security problems with pickle. But I don't feel >>>>> concern about that because I run my program in a private network, not >>>>> over internet. And now I use socket to communicate on a non-standard >>>>> port, not anymore web service on the 80 port. If I plan to run it >>>>> through wan, I will encrypt datas for sure with SSL or something like >>>>> that :) >>>>> >>>>> Romaric Defaux >>>>> >>>>> >>> > -- Romaric Defaux Administrateur Syst?mes et R?seaux Audaxis +33.820 00 70 70 -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 5361 bytes Desc: S/MIME Cryptographic Signature URL: From python at mrabarnett.plus.com Thu Nov 18 06:41:40 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 18 Nov 2010 11:41:40 +0000 Subject: String multi-replace In-Reply-To: References: <114148.34295.qm@web56007.mail.re3.yahoo.com> Message-ID: <4CE510F4.9020209@mrabarnett.plus.com> On 18/11/2010 04:30, Benjamin Kaplan wrote: > On Wed, Nov 17, 2010 at 11:21 PM, Sorin Schwimmer wrote: >> Hi All, >> >> I have to eliminate diacritics in a fairly large file. >> >> Inspired by http://code.activestate.com/recipes/81330/, I came up with the following code: >> >> #! /usr/bin/env python >> >> import re >> >> nodia={chr(196)+chr(130):'A', # mamaliga >> chr(195)+chr(130):'A', # A^ >> chr(195)+chr(142):'I', # I^ >> chr(195)+chr(150):'O', # OE >> chr(195)+chr(156):'U', # UE >> chr(195)+chr(139):'A', # AE >> chr(197)+chr(158):'S', >> chr(197)+chr(162):'T', >> chr(196)+chr(131):'a', # mamaliga >> chr(195)+chr(162):'a', # a^ >> chr(195)+chr(174):'i', # i^ >> chr(195)+chr(182):'o', # oe >> chr(195)+chr(188):'u', # ue >> chr(195)+chr(164):'a', # ae >> chr(197)+chr(159):'s', >> chr(197)+chr(163):'t' >> } >> name="R\xc3\xa2\xc5\x9fca" >> >> regex = re.compile("(%s)" % "|".join(map(re.escape, nodia.keys()))) >> print regex.sub(lambda mo: dict[mo.string[mo.start():mo.end()]], name) >> >> But it won't work; I end up with: >> >> Traceback (most recent call last): >> File "multirep.py", line 25, in >> print regex.sub(lambda mo: dict[mo.string[mo.start():mo.end()]], name) >> File "multirep.py", line 25, in >> print regex.sub(lambda mo: dict[mo.string[mo.start():mo.end()]], name) >> TypeError: 'type' object is not subscriptable >> >> What am I doing wrong? >> >> Thanks for your advice, >> SxN >> > > dict is a type, not a dict. Your dict is called nodia. I'm guess > that's what you meant to use. > Could I also suggest that you use: mo.group() instead of: mo.string[mo.start():mo.end()] From trylks at gmail.com Thu Nov 18 06:46:07 2010 From: trylks at gmail.com (trylks) Date: Thu, 18 Nov 2010 12:46:07 +0100 Subject: with HTTPConnection as conn: Message-ID: Hi! Would it be possible to use a with statement with an HTTPConnection object? I know it is not possible at this moment, it doesn't implement an __exit__ method, at least in version 3.1.1. I was wondering if the __exit__ method should do something more than conn.close(), something really hard or impossible, or if there are more requisites to use the with statement beside of implementing that method. So far it seems easy, useful and not done yet, so I'm probably mistaken about something, and wondering what may that be. Thank you. From clp2 at rebertia.com Thu Nov 18 06:53:31 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 18 Nov 2010 03:53:31 -0800 Subject: with HTTPConnection as conn: In-Reply-To: References: Message-ID: On Thu, Nov 18, 2010 at 3:46 AM, trylks wrote: > Hi! > > Would it be possible to use a with statement with an HTTPConnection object? Yes, via http://docs.python.org/library/contextlib.html#contextlib.closing from httplib import HTTPConnection from contextlib import closing with closing(HTTPConnection(...)) as conn: # do whatever # connection now closed Cheers, Chris -- http://blog.rebertia.com From grigory.v.p at gmail.com Thu Nov 18 07:03:57 2010 From: grigory.v.p at gmail.com (Grigory Petrov) Date: Thu, 18 Nov 2010 15:03:57 +0300 Subject: =?windows-1252?Q?How_to_correctly_pass_=93pointer=2Dto=2Dpointer=94_into_?= =?windows-1252?Q?DLL_via_ctypes=3F?= Message-ID: Hello. I have a DLL that allocates memory and returns it. Function in DLL is like this: void Foo( unsigned char** ppMem, int* pSize ) { ? * pSize = 4; ? * ppMem = malloc( * pSize ); ? for( int i = 0; i < * pSize; i ++ ) (* pMem)[ i ] = i; } Also, i have a python code that access this function from my DLL: from ctypes import * Foo = windll.mydll.Foo Foo.argtypes = [ POINTER( POINTER( c_ubyte ) ), POINTER( c_int ) ] mem = POINTER( c_ubyte )() size = c_int( 0 ) Foo( byref( mem ), byref( size ) ] print size, mem[ 0 ], mem[ 1 ], mem[ 2 ], mem[ 3 ] I'm expecting that?print?will show "4 0 1 2 3" but it shows "4 221 221 221 221" O_O. Any hints what i'm doing wrong? From matlab.dude at mbnet.fi Thu Nov 18 07:16:57 2010 From: matlab.dude at mbnet.fi (MATLABdude) Date: Thu, 18 Nov 2010 04:16:57 -0800 (PST) Subject: MATLAB to Python? References: <74f276c3-38a4-4df0-af39-7b1f2a81472e@c39g2000yqi.googlegroups.com> Message-ID: <40274408-8ae7-4500-983c-54714cf674d6@y23g2000yqd.googlegroups.com> On Nov 17, 10:04?am, MATLABdude wrote: Thanks guys! I still have some problems. I made the code somewhat simpler by dropping off some parts of it (xx, f). Now my Python code calculates 8 different values for lambda. The problem is that I don't know where the minus sign comes from. Also the values themselves are not identical compared to the values of the MATLAB program. nonhomog.py | nonhomog.m -0.774244159818 | 0.9976 -0.823595831818 | 0.9969 -0.774374006419 | 0.5464 -1.0 | -54.3440 -0.774244172803 | 0.9976 -0.774244289666 | 0.9976 -0.823595831818 | 0.9969 -1.0 | 0.9674 The new Python code can be found here: http://pastebin.com/c1UvtXxu From bc at freeuk.com Thu Nov 18 07:24:22 2010 From: bc at freeuk.com (BartC) Date: Thu, 18 Nov 2010 12:24:22 -0000 Subject: Is Unladen Swallow dead? In-Reply-To: <4ce37e01$0$1666$742ec2ed@news.sonic.net> References: <2e1a4d02-1e8a-4d31-95da-f33aaf90578c@30g2000yql.googlegroups.com> <8b0b044c-34a8-4747-b68f-f4cb56882f6f@e26g2000vbz.googlegroups.com> <4ce37e01$0$1666$742ec2ed@news.sonic.net> Message-ID: "John Nagle" wrote in message news:4ce37e01$0$1666$742ec2ed at news.sonic.net... > On 11/16/2010 10:24 PM, swapnil wrote: >> AFAIK, the merging plan was approved by Guido early this year. I guess >> Google is expecting the community to drive the project from here on. >> That was the whole idea for merging it to mainline. From my last >> conversation with Collin, they are targeting Python 3.3 > > I think it's dead. They're a year behind on quarterly releases. > The last release was Q3 2009. The project failed to achieve its > stated goal of a 5x speedup. Not even close. More like 1.5x > (http://www.python.org/dev/peps/pep-3146) There must have been good reasons to predict a 5x increase. But why did it take so long to find out the approach wasn't going anywhere? Assuming the 5x speedup was shown to be viable (ie. performing the same benchmarks, on the same data, can be done that quickly in any other language, and allowing for the overheads associated with Python's dynamic nature), then what went wrong? (I've had a look at the benchmarks, with a view to trying some on other languages, and they seem an extraordinarily difficult bunch to work with.) > The Google blog at > "http://groups.google.com/group/unladen-swallow/browse_thread/thread/f2011129c4414d04" > says, as of November 8, 2010: > So Google has pulled the plug on Unladen Swallow. It looks > like they underestimated the difficulty of speeding up the CPython > model. The performance improvement achieved was so low > that cluttering up CPython with a JIT system and LLVM probably is > a lose. LLVM. Ok, that explains a lot. (LLVM is a huge, complex system). -- Bartc From nomail at thisaddress.com Thu Nov 18 08:02:06 2010 From: nomail at thisaddress.com (Sven) Date: Thu, 18 Nov 2010 08:02:06 -0500 Subject: argparse subparser problem References: Message-ID: <2010111808020643145-nomail@thisaddresscom> On 2010-11-16 14:35:01 -0500, Neal Becker said: > I want to have subparsers, but I also want to be able to say: > > myprogram --version > and get the version # Would it not be possible to print the version number and then exit the program before building the subparser? > --------------------------- > > import argparse > > def stop(): > pass > > parser = argparse.ArgumentParser() > parser.add_argument ('--version', action='store_true') # if --version print version # sys.exit(0) > subparsers = parser.add_subparsers() > > parser_stop = subparsers.add_parser ('stop') > parser_stop.add_argument ('stop', action='store_true') > parser_stop.set_defaults (func=stop) > > > opt = parser.parse_args (['--version']) > ------------------------------ -- ./Sven From python at mrabarnett.plus.com Thu Nov 18 08:07:13 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 18 Nov 2010 13:07:13 +0000 Subject: MATLAB to Python? In-Reply-To: <40274408-8ae7-4500-983c-54714cf674d6@y23g2000yqd.googlegroups.com> References: <74f276c3-38a4-4df0-af39-7b1f2a81472e@c39g2000yqi.googlegroups.com> <40274408-8ae7-4500-983c-54714cf674d6@y23g2000yqd.googlegroups.com> Message-ID: <4CE52501.1080208@mrabarnett.plus.com> On 18/11/2010 12:16, MATLABdude wrote: > On Nov 17, 10:04 am, MATLABdude wrote: > > Thanks guys! > > I still have some problems. I made the code somewhat simpler by > dropping off some parts of it (xx, f). > > Now my Python code calculates 8 different values for lambda. The > problem is that I don't know where the minus sign comes from. Also the > values themselves are not identical compared to the values of the > MATLAB program. > nonhomog.py | nonhomog.m > -0.774244159818 | 0.9976 > -0.823595831818 | 0.9969 > -0.774374006419 | 0.5464 > -1.0 | -54.3440 > -0.774244172803 | 0.9976 > -0.774244289666 | 0.9976 > -0.823595831818 | 0.9969 > -1.0 | 0.9674 > > The new Python code can be found here: http://pastebin.com/c1UvtXxu Don't use: from math import * from numpy import * from scipy import * because you'll never be sure where a name comes from! Also, check for accidental integer division. (In Python 2 integer / integer returns integer.) From awilliam at whitemice.org Thu Nov 18 08:24:37 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Thu, 18 Nov 2010 08:24:37 -0500 Subject: Pickle in a POST/GET request give EOFError In-Reply-To: <4CE4FE66.20904@audaxis.com> References: <4CE2B599.7050504@audaxis.com> <4CE3EA61.2090707@audaxis.com> <4CE4E3CC.8080801@audaxis.com> <20101118094347.53a0980a@moriz.interne> <4CE4FE66.20904@audaxis.com> Message-ID: <1290086677.8819.2.camel@linux-yu4c.site> On Thu, 2010-11-18 at 11:22 +0100, Romaric DEFAUX wrote: > Hi again, > I try simplejson, but I have a problem. (I just replace pickle > everywhere by simplejson) > Explanation : > I "dumps" with json a list of dictionnaries into disk_list_json. > When I "loads" it, I don't get my list of dictionnaries like before (see > disk_list2). It adds "u" letter everywhere. Correct; I strongly disagree with the assertion to use JSON over Pickle. Pickle is superior for serialization - JSON does not preserve type. Use Pickle when possible. JSON is best for communicating simple data to stupid clients [web browsers]. JSON doesn't know about dates, it doesn't know about string vs. unicode, etc... -- Adam Tauno Williams From pecora at anvil.nrl.navy.mil Thu Nov 18 09:05:59 2010 From: pecora at anvil.nrl.navy.mil (Lou Pecora) Date: Thu, 18 Nov 2010 09:05:59 -0500 Subject: What was your strategy? References: <201011142240.oAEMecu2054270@krusty.intranet.com.mx> Message-ID: In article , Steve Holden wrote: > On 11/16/2010 2:22 PM, Lou Pecora wrote: > > I'll jump in and recommend the book "Python in a Nutshell" by Martelli. > > It may be a little dated now, but it covers many Python topics in good > > detail without becoming a bloated reference. Nicely written. It's still > > the first book I reach for after 6 years of Python coding and it rarely > > disappoints. > > +1 > > It's encyclopedic. Indeed. I hope Martelli updates it. I'd buy another copy right away. -- -- Lou Pecora From davea at ieee.org Thu Nov 18 09:19:22 2010 From: davea at ieee.org (Dave Angel) Date: Thu, 18 Nov 2010 09:19:22 -0500 Subject: String multi-replace In-Reply-To: <379297.48105.qm@web56003.mail.re3.yahoo.com> References: <379297.48105.qm@web56003.mail.re3.yahoo.com> Message-ID: <4CE535EA.7040309@ieee.org> On 2:59 PM, Sorin Schwimmer wrote: > Steven D'Aprano: the original file is 139MB (that's the typical size for it). Eliminating diacritics is just a little toping on the cake; the processing is something else. > > Thanks anyway for your suggestion, > SxN > > PS Perhaps I should have mention that I'm on Python 2.7 > > In the message you were replying to, Steven had a much more important suggestion to make than the size one, and you apparently didn't notice it. Chris made a similar implication. I'll try a third time. The file is obviously encoded, and you know the encoding. Judging from the first entry in your table, it's in utf-8. If so, then your approach is all wrong. Treating it as a pile of bytes, and replacing pairs is likely to get you in trouble, since it's quite possible that you may get a match with the last byte of one character and the first byte of another one. If you substitute such a match, you'll make a hash of the whole region, and quite likely end up with a byte stream that is no longer even utf-8. Fortunately, you can solve that problem, and simplify your code greatly in the bargain, by doing something like what was suggested by Steven. Change your map of encoded bytes into unicode_nodia, using decode("utf-8") on the keys, and u"" on the values Read in each line of the file, decode it to the unicode it represents, and do a simple translate once it's valid unicode. Assuming the line is in utf-8, use uni = line.decode("utf-8") newuni = uni.trans(unicode_nodia) newutf8 = newuni.encode("utf-8") incidentally, to see what a given byte pair in your table is, you can do something like: import unicodedata a = chr(196)+chr(130) unicodedata.name(a.decode("utf-8")) 'LATIN CAPITAL LETTER A WITH BREVE' DaveA From martin at address-in-sig.invalid Thu Nov 18 09:21:47 2010 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Thu, 18 Nov 2010 14:21:47 +0000 (UTC) Subject: Program, Application, and Software References: <87hbffa30d.fsf@benfinney.id.au> Message-ID: On Thu, 18 Nov 2010 01:16:34 +0000, MRAB wrote: > I'd probably say that a "script" is a program which is normally not > interactive: you just set it up, start it, and let it do its work (a > "batch script", for example). It's also written in a language primarily > designed for convenience rather than speed (Want to manipulate large > chunks of text? Fine! :-)). > I use 'script' to refer to programs written in languages that don't have a separate compile phase which must be run before the program can be executed. IOW Python and Perl programs are scripts aloing with programs written as awk, Javascript and bash scripts. -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From brf256 at gmail.com Thu Nov 18 09:25:40 2010 From: brf256 at gmail.com (brf256 at gmail.com) Date: Thu, 18 Nov 2010 14:25:40 +0000 Subject: What was your strategy? In-Reply-To: References: <201011142240.oAEMecu2054270@krusty.intranet.com.mx> Message-ID: <1011767245-1290090337-cardhu_decombobulator_blackberry.rim.net-1654248048-@bda480.bisx.prod.on.blackberry> +2 I also agree. - Braden Faulkner -----Original Message----- From: Lou Pecora Sender: python-list-bounces+brf256=gmail.com at python.org Date: Thu, 18 Nov 2010 09:05:59 To: Subject: Re: What was your strategy? In article , Steve Holden wrote: > On 11/16/2010 2:22 PM, Lou Pecora wrote: > > I'll jump in and recommend the book "Python in a Nutshell" by Martelli. > > It may be a little dated now, but it covers many Python topics in good > > detail without becoming a bloated reference. Nicely written. It's still > > the first book I reach for after 6 years of Python coding and it rarely > > disappoints. > > +1 > > It's encyclopedic. Indeed. I hope Martelli updates it. I'd buy another copy right away. -- -- Lou Pecora -- http://mail.python.org/mailman/listinfo/python-list From btricha at gmail.com Thu Nov 18 09:58:21 2010 From: btricha at gmail.com (Bryan Richardson) Date: Thu, 18 Nov 2010 07:58:21 -0700 Subject: Twisted on Windows Message-ID: Hello All, First off I must say that Twisted is a very nice event driven I/O package indeed. Thanks to all the developers who have contributed to it, as it's made my life much easier. Now for my question... I have a custom server application, and I have it structured as such: MyServerApp/ <-- root directory ? ?server.py foo/ __init__.py factory.py In my server.py file, which is a Twistd config file that can be executed with twistd -ny server.py, I have the following import line: from foo.factory import MyServerFactory When I run 'twistd -ny server.py' on my Linux machine from within the root MyServerApp directory, all works as expected. However, when I try to do the same thing on a Windows machine using the twistd script that gets installed, I get an error saying that foo.factory cannot be found. However, if I modify my server.py file on Windows to just create the factory and start the reactor, I can run it just fine with 'python server.py' even though it still has the import line for MyServerFactory. Bottom line is, on Windows, the python executable can find my custom module in a sub directory but the twistd script cannot. Any ideas why this is? -- Thanks! Bryan From solipsis at pitrou.net Thu Nov 18 10:01:25 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Thu, 18 Nov 2010 16:01:25 +0100 Subject: with HTTPConnection as conn: References: Message-ID: <20101118160125.3de403aa@pitrou.net> On Thu, 18 Nov 2010 12:46:07 +0100 trylks wrote: > Hi! > > Would it be possible to use a with statement with an HTTPConnection object? > > I know it is not possible at this moment, it doesn't implement an > __exit__ method, at least in version 3.1.1. I was wondering if the > __exit__ method should do something more than conn.close(), something > really hard or impossible, or if there are more requisites to use the > with statement beside of implementing that method. So far it seems > easy, useful and not done yet, so I'm probably mistaken about > something, and wondering what may that be. It's possibly one of those things that haven't been implemented simply because no one thought about it yet, or bothered enough to do it. In other words, you can open a feature request at http://bugs.python.org, and even provide a patch. Regards Antoine. From rbd at soest.hawaii.edu Thu Nov 18 10:35:42 2010 From: rbd at soest.hawaii.edu (Roger Davis) Date: Thu, 18 Nov 2010 05:35:42 -1000 (HST) Subject: strange subprocess behavior when calling ps In-Reply-To: <801_1290077447_4CE50505_801_399_1_4CE504FF.2080709@sequans.com> References: <55f26d5c-aba9-4892-9e2c-1caa9988e7fe@v23g2000vbi.googlegroups.com> <1ed38051-9c8b-4ae8-9a88-9833209d2775@h21g2000vbh.googlegroups.com> <801_1290077447_4CE50505_801_399_1_4CE504FF.2080709@sequans.com> Message-ID: Hi JM, Thank you very much for your followup explanation! Roger From invalid at invalid.invalid Thu Nov 18 10:41:51 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 18 Nov 2010 15:41:51 +0000 (UTC) Subject: Program, Application, and Software References: <87hbffa30d.fsf@benfinney.id.au> Message-ID: On 2010-11-18, Martin Gregorie wrote: > On Thu, 18 Nov 2010 01:16:34 +0000, MRAB wrote: > >> I'd probably say that a "script" is a program which is normally not >> interactive: you just set it up, start it, and let it do its work (a >> "batch script", for example). It's also written in a language primarily >> designed for convenience rather than speed (Want to manipulate large >> chunks of text? Fine! :-)). >> > I use 'script' to refer to programs written in languages that don't have > a separate compile phase which must be run before the program can be > executed. IOW Python and Perl programs are scripts aloing with programs > written as awk, Javascript and bash scripts. I use 'script' to refer to programs that are used to automate things that would otherwise be done by a person typing commands. IOW, what I write using Python aren't scripts. They're programs. -- Grant Edwards grant.b.edwards Yow! All of life is a blur at of Republicans and meat! gmail.com From hniksic at xemacs.org Thu Nov 18 10:55:00 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Thu, 18 Nov 2010 16:55:00 +0100 Subject: with HTTPConnection as conn: References: Message-ID: <87hbfebp9n.fsf@xemacs.org> Antoine Pitrou writes: > On Thu, 18 Nov 2010 12:46:07 +0100 > trylks wrote: >> Hi! >> >> Would it be possible to use a with statement with an HTTPConnection object? >> >> I know it is not possible at this moment, it doesn't implement an >> __exit__ method, at least in version 3.1.1. I was wondering if the >> __exit__ method should do something more than conn.close(), something >> really hard or impossible, or if there are more requisites to use the >> with statement beside of implementing that method. So far it seems >> easy, useful and not done yet, so I'm probably mistaken about >> something, and wondering what may that be. > > It's possibly one of those things that haven't been implemented simply > because no one thought about it yet, or bothered enough to do it. Also, contextlib.closing is readily available: with contextlib.closing(HTTPConnection(...)) as conn: ... From martin at address-in-sig.invalid Thu Nov 18 11:05:51 2010 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Thu, 18 Nov 2010 16:05:51 +0000 (UTC) Subject: Program, Application, and Software References: <87hbffa30d.fsf@benfinney.id.au> Message-ID: On Thu, 18 Nov 2010 15:41:51 +0000, Grant Edwards wrote: > On 2010-11-18, Martin Gregorie wrote: >> On Thu, 18 Nov 2010 01:16:34 +0000, MRAB wrote: >> >>> I'd probably say that a "script" is a program which is normally not >>> interactive: you just set it up, start it, and let it do its work (a >>> "batch script", for example). It's also written in a language >>> primarily designed for convenience rather than speed (Want to >>> manipulate large chunks of text? Fine! :-)). >>> >> I use 'script' to refer to programs written in languages that don't >> have a separate compile phase which must be run before the program can >> be executed. IOW Python and Perl programs are scripts aloing with >> programs written as awk, Javascript and bash scripts. > > I use 'script' to refer to programs that are used to automate things > that would otherwise be done by a person typing commands. > Its a long-standing UNIXism - it applies to any language implementation where you can add "#!/path/to/interpreter" as the first line of the source file, make the file executable with chmod and run it by treating the file name as a command. > IOW, what I write using Python aren't scripts. They're programs. > Anything with one or more executable lines is a program: #!/usr/bin/python print "\nHello, Python World\n" -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From fetchinson at googlemail.com Thu Nov 18 11:27:43 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Thu, 18 Nov 2010 17:27:43 +0100 Subject: what's the precision of fractions.Fraction? Message-ID: I do a recursive evaluation of an expression involving fractions and unsurprisingly the numerator and denominator grows pretty quickly. After 10-20 iterations the number of digits in the numerator and denominator (as integers) reaches 80-100. And I'm wondering until what point I can trust the result since I'm using fractions.Fraction for the whole procedure. Are Fraction's infinite precision? Or will I get some sort of an exception if python is not able to represent the numerator and/or denominator as integers? http://www.python.org/dev/peps/pep-3141/ was not very helpful in this regard nor was http://docs.python.org/library/fractions.html Any ideas? Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From ben at wbpsystems.com Thu Nov 18 11:48:11 2010 From: ben at wbpsystems.com (tazz_ben) Date: Thu, 18 Nov 2010 08:48:11 -0800 (PST) Subject: Distribution of Python Scripts Message-ID: Hi Folks - I'm an experienced programmer, but this is my first app with python, so I apologize for any stupidity on my part. So I've written/still working on a command line tool written in Python. It talks to a web service, so there really isn't anything in it that is dependent on a particular os. My goal is to distribute the script as a tool to my users so they can use it (they are on multiple platforms), the vast majority are not programmers. So, I'm looking for a way to distribute the app that takes care of details like them having python installed, or having an older version etc. From reading some docs it sounds like "Squeeze" did exactly this back in the day, but it is ancient and I'm writing in 2.7. Just to be clear I could care less if they see the source code, my goal is all around ease of use. I would love to have one distribution file for all platforms, but I can live with making three if that's the only option. So, what's my options. From calderone.jeanpaul at gmail.com Thu Nov 18 11:52:39 2010 From: calderone.jeanpaul at gmail.com (Jean-Paul Calderone) Date: Thu, 18 Nov 2010 08:52:39 -0800 (PST) Subject: Twisted on Windows References: Message-ID: <1463cdde-3095-426b-af2f-efa2c556e8f0@i41g2000vbn.googlegroups.com> On Nov 18, 9:58?am, Bryan Richardson wrote: > Hello All, > > First off I must say that Twisted is a very nice event driven I/O > package indeed. Thanks to all the developers who have contributed to > it, as it's made my life much easier. > > Now for my question... > > I have a custom server application, and I have it structured as such: > > MyServerApp/ <-- root directory > ? ?server.py > ? ?foo/ > ? ? ? __init__.py > ? ? ? factory.py > > In my server.py file, which is a Twistd config file that can be > executed with twistd -ny server.py, I have the following import line: > > from foo.factory import MyServerFactory > > When I run 'twistd -ny server.py' on my Linux machine from within the > root MyServerApp directory, all works as expected. However, when I try > to do the same thing on a Windows machine using the twistd script that > gets installed, I get an error saying that foo.factory cannot be > found. However, if I modify my server.py file on Windows to just > create the factory and start the reactor, I can run it just fine with > 'python server.py' even though it still has the import line for > MyServerFactory. > > Bottom line is, on Windows, the python executable can find my custom > module in a sub directory but the twistd script cannot. Any ideas why > this is? > When you run a .py file, python adds the directory containing that .py file to the front of sys.path. So when you run server.py, MyServerApp/ is added to sys.path and the foo package can be found. This happens on Linux and Windows. When you run twistd, the ".py file" you're running is /usr/bin/twistd or C:\Python26\Scripts\twistd or something else along those lines. So Python adds /usr/bin or C:\Python26\Scripts to sys.path. This doesn't help you find the foo package at all. On Linux, when not running as root, twistd adds the current working directory to sys.path. So if your working directory is MyServerApp, then the foo package can be found. When running as root, or when running on Windows, twistd does not add the working directory to sys.path. So with all that in mind, the solution should be pretty clear - just set PYTHONPATH to include MyServerApp. This variation of twistd behavior is pretty confusing, and I think a future version may drop the sys.path manipulation entirely, so that it behaves consistently in all configurations. Jean-Paul From ian.g.kelly at gmail.com Thu Nov 18 12:13:25 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 18 Nov 2010 10:13:25 -0700 Subject: what's the precision of fractions.Fraction? In-Reply-To: References: Message-ID: On Thu, Nov 18, 2010 at 9:27 AM, Daniel Fetchinson < fetchinson at googlemail.com> wrote: > I do a recursive evaluation of an expression involving fractions and > unsurprisingly the numerator and denominator grows pretty quickly. > After 10-20 iterations the number of digits in the numerator and > denominator (as integers) reaches 80-100. And I'm wondering until what > point I can trust the result since I'm using fractions.Fraction for > the whole procedure. Are Fraction's infinite precision? Or will I get > some sort of an exception if python is not able to represent the > numerator and/or denominator as integers? > Since fractions are represented as a pair of integers, and since python integers have unlimited precision, I would guess that fractions also have unlimited precision. You could check the code if you want to be absolutely sure. Cheers, Ian -------------- next part -------------- An HTML attachment was scrubbed... URL: From drsalists at gmail.com Thu Nov 18 12:45:08 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Thu, 18 Nov 2010 09:45:08 -0800 Subject: Is Unladen Swallow dead? In-Reply-To: References: <2e1a4d02-1e8a-4d31-95da-f33aaf90578c@30g2000yql.googlegroups.com> <8b0b044c-34a8-4747-b68f-f4cb56882f6f@e26g2000vbz.googlegroups.com> <4ce37e01$0$1666$742ec2ed@news.sonic.net> Message-ID: On Thu, Nov 18, 2010 at 4:24 AM, BartC wrote: > "John Nagle" wrote in message > news:4ce37e01$0$1666$742ec2ed at news.sonic.net... > > On 11/16/2010 10:24 PM, swapnil wrote: >> > > AFAIK, the merging plan was approved by Guido early this year. I guess >>> Google is expecting the community to drive the project from here on. >>> That was the whole idea for merging it to mainline. From my last >>> conversation with Collin, they are targeting Python 3.3 >>> >> >> I think it's dead. They're a year behind on quarterly releases. >> The last release was Q3 2009. The project failed to achieve its >> stated goal of a 5x speedup. Not even close. More like 1.5x >> (http://www.python.org/dev/peps/pep-3146) >> > > There must have been good reasons to predict a 5x increase. But why did it > take so long to find out the approach wasn't going anywhere? > It's not that it wasn't going anywhere. Improvements were accomplished. Also, LLVM needed to be modified more than a little bit for the purpose. Also, the developers were constrained a bit by the need to preserve compatibility with some pretty weird code - like methods being replaced mid-loop. It's not a small project. -------------- next part -------------- An HTML attachment was scrubbed... URL: From martin at v.loewis.de Thu Nov 18 12:45:55 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Thu, 18 Nov 2010 18:45:55 +0100 Subject: regenerating unicodedata for py2.7 using py3 makeunicodedata.py? In-Reply-To: References: Message-ID: <4CE56653.8020201@v.loewis.de> > Thanks for the confirmation Martin! > > Do you think, it the mentioned omission of the character names of some > CJK ranges in unicodedata intended, or should it be reported to the > tracker? It's certainly a bug. So a bug report would be appreciated, but much more so a patch. Ideally, the patch would either be completely forward-compatible (should the CJK ranges change in future Unicode versions), or at least have a safe-guard to detect that the data file is getting out of sync with the C implementation. Regards, Martin From martin at v.loewis.de Thu Nov 18 12:45:55 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Thu, 18 Nov 2010 18:45:55 +0100 Subject: regenerating unicodedata for py2.7 using py3 makeunicodedata.py? In-Reply-To: References: Message-ID: <4CE56653.8020201@v.loewis.de> > Thanks for the confirmation Martin! > > Do you think, it the mentioned omission of the character names of some > CJK ranges in unicodedata intended, or should it be reported to the > tracker? It's certainly a bug. So a bug report would be appreciated, but much more so a patch. Ideally, the patch would either be completely forward-compatible (should the CJK ranges change in future Unicode versions), or at least have a safe-guard to detect that the data file is getting out of sync with the C implementation. Regards, Martin From brf256 at gmail.com Thu Nov 18 12:50:58 2010 From: brf256 at gmail.com (brf256 at gmail.com) Date: Thu, 18 Nov 2010 17:50:58 +0000 Subject: Is Unladen Swallow dead? Message-ID: <1778189007-1290102660-cardhu_decombobulator_blackberry.rim.net-1230079009-@bda480.bisx.prod.on.blackberry> I do hope that it isn't dead but it unfortunately seems that way? - Braden Faulkner From no.email at nospam.invalid Thu Nov 18 13:09:24 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 18 Nov 2010 10:09:24 -0800 Subject: What was your strategy? References: <201011142240.oAEMecu2054270@krusty.intranet.com.mx> Message-ID: <7xr5ei1p2j.fsf@ruckus.brouhaha.com> Lou Pecora writes: >> > I'll jump in and recommend the book "Python in a Nutshell" by Martelli. >> It's encyclopedic. > Indeed. I hope Martelli updates it. I'd buy another copy right away. It's a great book but not a starting point for beginners. It's definitely worth having for more advanced users. From fetchinson at googlemail.com Thu Nov 18 13:17:51 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Thu, 18 Nov 2010 19:17:51 +0100 Subject: what's the precision of fractions.Fraction? In-Reply-To: References: Message-ID: >> I do a recursive evaluation of an expression involving fractions and >> unsurprisingly the numerator and denominator grows pretty quickly. >> After 10-20 iterations the number of digits in the numerator and >> denominator (as integers) reaches 80-100. And I'm wondering until what >> point I can trust the result since I'm using fractions.Fraction for >> the whole procedure. Are Fraction's infinite precision? Or will I get >> some sort of an exception if python is not able to represent the >> numerator and/or denominator as integers? > > Since fractions are represented as a pair of integers, and since python > integers have unlimited precision, I would guess that fractions also have > unlimited precision. You could check the code if you want to be absolutely > sure. Sounds reasonable, thanks a lot, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From nagle at animats.com Thu Nov 18 13:31:15 2010 From: nagle at animats.com (John Nagle) Date: Thu, 18 Nov 2010 10:31:15 -0800 Subject: Is Unladen Swallow dead? In-Reply-To: References: <2e1a4d02-1e8a-4d31-95da-f33aaf90578c@30g2000yql.googlegroups.com> <8b0b044c-34a8-4747-b68f-f4cb56882f6f@e26g2000vbz.googlegroups.com> <4ce37e01$0$1666$742ec2ed@news.sonic.net> Message-ID: <4ce570ff$0$1617$742ec2ed@news.sonic.net> On 11/18/2010 4:24 AM, BartC wrote: > "John Nagle" wrote in message > news:4ce37e01$0$1666$742ec2ed at news.sonic.net... >> On 11/16/2010 10:24 PM, swapnil wrote: > >>> AFAIK, the merging plan was approved by Guido early this year. I >>> guess Google is expecting the community to drive the project >>> from here on. That was the whole idea for merging it to mainline. >>> From my last conversation with Collin, they are targeting Python >>> 3.3 >> >> I think it's dead. They're a year behind on quarterly releases. >> The last release was Q3 2009. The project failed to achieve its >> stated goal of a 5x speedup. Not even close. More like 1.5x >> (http://www.python.org/dev/peps/pep-3146) > > There must have been good reasons to predict a 5x increase. For Java, adding a JIT improved performance by much more than that. Hard-code compilers for LISP have done much better than 5x. The best Java and LISP compilers approach the speed of C, while CPython is generally considered to be roughly 60 times slower than C. So 5x probably looked like a conservative goal. For Google, a company which buys servers by the acre, a 5x speedup would have a big payoff. > Assuming the 5x speedup was shown to be viable (ie. performing the > same benchmarks, on the same data, can be done that quickly in any > other language, and allowing for the overheads associated with > Python's dynamic nature), then what went wrong? Python is defined by what a naive interpreter with late binding and dynamic name lookups, like CPython, can easily implement. Simply emulating the semantics of CPython with generated code doesn't help all that much. Because you can "monkey patch" Python objects from outside the class, a local compiler, like a JIT, can't turn name lookups into hard bindings. Nor can it make reliable decisions about the types of objects. That adds a sizable performance penalty. Short of global program analysis, the compiler can't tell when code for the hard cases needs to be generated. So the hard-case code, where you figure out at run-time, for ever use of "+", whether "+" is addition or concatenation, has to be generated every time. Making that decision is far slower than doing an add. Shed Skin, which analyzes the entire program, including libraries, on every compilation, can figure out the types of objects and generate much faster code. Shed Skin has some heavy restrictions, many of which could be lifted if more work went into that effort. That's one approach that might work. I've referred to this problem as "gratuitous hidden dynamism". Most things which could be changed dynamically in a Python program usually aren't. This has been pointed out many times by many people. There's even a PhD thesis on the topic. Without a few restrictions, so that a compiler can at least tell when support for the hard cases is needed, Python cannot be compiled well. John Nagle From stefan.sonnenberg at pythonmeister.com Thu Nov 18 14:08:00 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Thu, 18 Nov 2010 20:08:00 +0100 Subject: what's the precision of fractions.Fraction? In-Reply-To: References: Message-ID: <4CE57990.2020706@pythonmeister.com> Am 18.11.2010 17:27, schrieb Daniel Fetchinson: > I do a recursive evaluation of an expression involving fractions and > unsurprisingly the numerator and denominator grows pretty quickly. > After 10-20 iterations the number of digits in the numerator and > denominator (as integers) reaches 80-100. And I'm wondering until what > point I can trust the result since I'm using fractions.Fraction for > the whole procedure. Are Fraction's infinite precision? Or will I get > some sort of an exception if python is not able to represent the > numerator and/or denominator as integers? > > http://www.python.org/dev/peps/pep-3141/ was not very helpful in this > regard nor was http://docs.python.org/library/fractions.html > > Any ideas? > > Cheers, > Daniel > I'm not sure what you really want to know. Fractions are, by their math definition, of unlimited precision. For example, PI/2 is accurate (with endless precision as PI is a trancendent number), but 3.1415926/2 (the decimal representation) is not. So is fraction.Fraction(1,3) of unlimited precision, thus giving this: from fractions import Fraction >>> one_tenth=Fraction(1,10) >>> a = one_tenth+one_tenth >>> a Fraction(1, 5) >>> a = one_tenth+one_tenth+one_tenth >>> a Fraction(3, 10) now compare to standard floats: >>> one_tenth=1.0/10 >>> a = one_tenth+one_tenth >>> a 0.2 >>> a = one_tenth+one_tenth+one_tenth >>> a 0.30000000000000004 (this error is caused by the internal representation of floats as binary numbers, see No. 14 in Python tut). I think you really want to know, how large numerator/denominator can be. As python has bignum support (type=long), the only limit is the one your virtual memory system offers, which is almost always approx. the amount of ram. If you need it really *precise*, cast your Fractions into type Decimal: >>> from decimal import Decimal >>> one_tenth=Fraction(1,10) >>> three_tenth = one_tenth*3 >>> d = Decimal(three_tenth.numerator)/Decimal(three_tenth.denominator) >>> d Decimal('0.3') The operator '/' (__div__) is properly over-written. You can even tweak the precision getcontext().prec by setting it to a higher value. Cheers -------------- next part -------------- A non-text attachment was scrubbed... Name: stefan_sonnenberg.vcf Type: text/x-vcard Size: 223 bytes Desc: not available URL: From bmjames at gmail.com Thu Nov 18 14:13:10 2010 From: bmjames at gmail.com (Ben James) Date: Thu, 18 Nov 2010 19:13:10 +0000 Subject: Is Unladen Swallow dead? References: Message-ID: On 18/11/2010 17:50, brf256 at gmail.com wrote: > I do hope that it isn't dead but it unfortunately seems that way? > > - Braden Faulkner > It looks like we'll have to get used to a laden one. Maybe if we had two, and a strand of creeper... From bmjames at gmail.com Thu Nov 18 14:17:07 2010 From: bmjames at gmail.com (Ben James) Date: Thu, 18 Nov 2010 19:17:07 +0000 Subject: I have a question about JavaFit References: Message-ID: On 18/11/2010 10:05, Chris Rebert wrote: > "We" are a technical discussion maillinglist. About a computer > programming language. Named Python. > An unrelated computer programming language which happens to be named > "Java" also exists, but is not this mailinglist's topic of discussion. > Some computer programmers personally consume a lot of coffee, but > aside from that, as a group, this maillinglist's members have nothing > to do with "Javalution Coffee Company" or their "JavaFit" coffee > products. > To put it simply, you're barking up entirely the wrong tree. > How exactly were you led to believe that python-list at python.org had > anything to do with JavaFit in the first place? > > Regards, > Chris, random maillinglist subscriber > > On Tue, Nov 16, 2010 at 4:45 PM, Bill Fishbaugher > wrote: >> Hello, >> >> I was searching online to find more info about JavaFit and I came across your information. >> >> Can you tell me, are you still involved with JavaFit? If you are, how are things going for you? >> >> Please let me know. >> >> Sincerely, >> Bill Is a JavaFit what you have when you drink waaaaaay too much coffee? From stefan.sonnenberg at pythonmeister.com Thu Nov 18 14:40:47 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Thu, 18 Nov 2010 20:40:47 +0100 Subject: I have a question about JavaFit In-Reply-To: References: Message-ID: <4CE5813F.8080001@pythonmeister.com> Am 18.11.2010 20:17, schrieb Ben James: > On 18/11/2010 10:05, Chris Rebert wrote: >> "We" are a technical discussion maillinglist. About a computer >> programming language. Named Python. >> An unrelated computer programming language which happens to be named >> "Java" also exists, but is not this mailinglist's topic of discussion. >> Some computer programmers personally consume a lot of coffee, but >> aside from that, as a group, this maillinglist's members have nothing >> to do with "Javalution Coffee Company" or their "JavaFit" coffee >> products. >> To put it simply, you're barking up entirely the wrong tree. >> How exactly were you led to believe that python-list at python.org had >> anything to do with JavaFit in the first place? >> >> Regards, >> Chris, random maillinglist subscriber >> >> On Tue, Nov 16, 2010 at 4:45 PM, Bill Fishbaugher >> wrote: >>> Hello, >>> >>> I was searching online to find more info about JavaFit and I came >>> across your information. >>> >>> Can you tell me, are you still involved with JavaFit? If you are, >>> how are things going for you? >>> >>> Please let me know. >>> >>> Sincerely, >>> Bill > > Is a JavaFit what you have when you drink waaaaaay too much coffee? Java FIT : Java Framework for integrated testing http://fit.c2.com/ Last update to site Oct 2007 There seems (ed) to be a python port. Status unknown. I guess what bill is looking for is test driven development. This thingy seems really strange. -------------- next part -------------- A non-text attachment was scrubbed... Name: stefan_sonnenberg.vcf Type: text/x-vcard Size: 223 bytes Desc: not available URL: From jenn.duerr at gmail.com Thu Nov 18 15:15:03 2010 From: jenn.duerr at gmail.com (noydb) Date: Thu, 18 Nov 2010 12:15:03 -0800 (PST) Subject: How to run an EXE, with argument, capture output value References: <37037d15-63da-4f37-9508-bdcfff034670@s4g2000yql.googlegroups.com> Message-ID: <70d6c9a7-8ba9-420d-822a-0ba71888e4f4@v20g2000yqb.googlegroups.com> I will use 2.5. I tried your suggestion, with this code import subprocess pig = subprocess.Popen(["C:\Halls\hallbig2.exe"], stdin=subprocess.PIPE, stdout=subprocess.PIPE) result = pig.communicate(input='C:\Halls\Input\Ea39j.txt')[-1] #I need to capture the, what I think is the, last output print result print pig.returncode >> None >> 0 So the tuple is empty. ?? The exe executes fine and returns output in th exe tool itself. The python script seems to execute fine, no errors, '...returned exit code 0'. Any ideas/suggestions? From dutche at gmail.com Thu Nov 18 15:20:44 2010 From: dutche at gmail.com (dutche) Date: Thu, 18 Nov 2010 12:20:44 -0800 (PST) Subject: Changing the EAX register with Python Message-ID: Hi folks, I have a unusual question here. How can I change the value of EAX register under python under Linux?? As paimei does under Windows. My project is to have a python program that loads a C program and sets a breakpoint at some address, and then with this breakpoint I change the EAX register and then continue the program execution. With Windows and paimei I did that, but under Linux I don't know yet. Any ideas? Thank you From btricha at gmail.com Thu Nov 18 15:55:47 2010 From: btricha at gmail.com (Bryan Richardson) Date: Thu, 18 Nov 2010 13:55:47 -0700 Subject: Twisted on Windows In-Reply-To: <1463cdde-3095-426b-af2f-efa2c556e8f0@i41g2000vbn.googlegroups.com> References: <1463cdde-3095-426b-af2f-efa2c556e8f0@i41g2000vbn.googlegroups.com> Message-ID: Thanks Jean-Paul, I added the following to my server.py file and things work perfectly on both Windows and Linux now. sys.path.insert(0, os.getcwd()) On Thu, Nov 18, 2010 at 9:52 AM, Jean-Paul Calderone wrote: > On Nov 18, 9:58?am, Bryan Richardson wrote: >> Hello All, >> >> First off I must say that Twisted is a very nice event driven I/O >> package indeed. Thanks to all the developers who have contributed to >> it, as it's made my life much easier. >> >> Now for my question... >> >> I have a custom server application, and I have it structured as such: >> >> MyServerApp/ <-- root directory >> ? ?server.py >> ? ?foo/ >> ? ? ? __init__.py >> ? ? ? factory.py >> >> In my server.py file, which is a Twistd config file that can be >> executed with twistd -ny server.py, I have the following import line: >> >> from foo.factory import MyServerFactory >> >> When I run 'twistd -ny server.py' on my Linux machine from within the >> root MyServerApp directory, all works as expected. However, when I try >> to do the same thing on a Windows machine using the twistd script that >> gets installed, I get an error saying that foo.factory cannot be >> found. However, if I modify my server.py file on Windows to just >> create the factory and start the reactor, I can run it just fine with >> 'python server.py' even though it still has the import line for >> MyServerFactory. >> >> Bottom line is, on Windows, the python executable can find my custom >> module in a sub directory but the twistd script cannot. Any ideas why >> this is? >> > > When you run a .py file, python adds the directory containing that .py > file to the front of sys.path. ?So when you run server.py, > MyServerApp/ > is added to sys.path and the foo package can be found. ?This happens > on > Linux and Windows. > > When you run twistd, the ".py file" you're running is /usr/bin/twistd > or C:\Python26\Scripts\twistd or something else along those lines. ?So > Python adds /usr/bin or C:\Python26\Scripts to sys.path. ?This doesn't > help you find the foo package at all. > > On Linux, when not running as root, twistd adds the current working > directory to sys.path. ?So if your working directory is MyServerApp, > then the foo package can be found. > > When running as root, or when running on Windows, twistd does not add > the working directory to sys.path. > > So with all that in mind, the solution should be pretty clear - just > set PYTHONPATH to include MyServerApp. > > This variation of twistd behavior is pretty confusing, and I think a > future version may drop the sys.path manipulation entirely, so that > it behaves consistently in all configurations. > > Jean-Paul > -- > http://mail.python.org/mailman/listinfo/python-list > From tjreedy at udel.edu Thu Nov 18 16:31:40 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 18 Nov 2010 16:31:40 -0500 Subject: what's the precision of fractions.Fraction? In-Reply-To: References: Message-ID: On 11/18/2010 11:27 AM, Daniel Fetchinson wrote: > I do a recursive evaluation of an expression involving fractions and > unsurprisingly the numerator and denominator grows pretty quickly. > After 10-20 iterations the number of digits in the numerator and > denominator (as integers) reaches 80-100. And I'm wondering until what > point I can trust the result since I'm using fractions.Fraction for > the whole procedure. Are Fraction's infinite precision? 'Unbounded' (except by memory) would be be more accurate. > Or will I get > some sort of an exception if python is not able to represent the > numerator and/or denominator as integers? I believe you could eventually get MemoryError. But you might get tired of waiting first. I tried i=0 n=2 while True: print(i) n *= n i += 1 The 30th doubling (I believe to a billion bit or 128 megabyte number, on a gigabyte machine) took a few minutes and I killed the program after that as it tried to page everything else out to disk. -- Terry Jan Reedy From anthra.norell at bluewin.ch Thu Nov 18 16:38:09 2010 From: anthra.norell at bluewin.ch (Frederic Rentsch) Date: Thu, 18 Nov 2010 22:38:09 +0100 Subject: String multi-replace In-Reply-To: <912885.5637.qm@web56006.mail.re3.yahoo.com> References: <912885.5637.qm@web56006.mail.re3.yahoo.com> Message-ID: <1290116289.2902.81.camel@hatchbox-one> On Wed, 2010-11-17 at 21:12 -0800, Sorin Schwimmer wrote: > Thanks for your answers. > > Benjamin Kaplan: of course dict is a type... silly me! I'll blame it on the time (it's midnight here). > > Chris Rebert: I'll have a look. > > Thank you both, > SxN > > Forgive me if this is off the track. I haven't followed the thread. I do have a little module that I believe does what you attempted to do: multiple substitutions using a regular expression that joins a bunch of targets with '|' in between. Whether or not you risk unintended translations as Dave Angel pointed out where the two characters or one of your targets join coincidentally you will have to determine. If so you can't use this approach. If, on the other hand, your format is safe it'll work just fine. Use like this: >>> import translator >>> t = translator.Translator (nodia.items ()) >>> t (name) # Your example 'Rasca' Frederic -------------- next part -------------- A non-text attachment was scrubbed... Name: translator.py Type: text/x-python Size: 4276 bytes Desc: not available URL: From usernet at ilthio.net Thu Nov 18 17:22:35 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 18 Nov 2010 22:22:35 +0000 (UTC) Subject: How to run an EXE, with argument, capture output value References: <37037d15-63da-4f37-9508-bdcfff034670@s4g2000yql.googlegroups.com> <70d6c9a7-8ba9-420d-822a-0ba71888e4f4@v20g2000yqb.googlegroups.com> Message-ID: On 2010-11-18, noydb wrote: > import subprocess > pig = subprocess.Popen(["C:\Halls\hallbig2.exe"], > stdin=subprocess.PIPE, stdout=subprocess.PIPE) > result = pig.communicate(input='C:\Halls\Input\Ea39j.txt')[-1] #I need > to capture the, what I think is the, last output >From the subprocess documentation: [62]communicate() returns a tuple (stdoutdata, stderrdata). Note that if you want to send data to the process's stdin, you need to create the Popen object with stdin=PIPE. Similarly, to get anything other than None in the result tuple, you need to give stdout=PIPE and/or stderr=PIPE too. By using index [-1] you are accessing the processes stderr stream. I am not really sure why you changed it. It doesn't give you the last output. Index 0 gives you *all* of stdout and index 1 gives you *all* of stderr, period. If you wish to further disect the output to get say the last line, then you will need to parse it separately. > print result > print pig.returncode >>> None >>> 0 > > So the tuple is empty. ?? The exe executes fine and returns output in > th exe tool itself. The python script seems to execute fine, no > errors, '...returned exit code 0'. Any ideas/suggestions? No the tuple contains two items (stdout, stderr). The first is what the program printed to its stdout stream (which is most likely the output you see if you run the command at a terminal/console). The second is what it printed to its stderr stream which is a channel used for out of band data such as error or status messages. In this case, it is None, because you did open stderr as a subprocess.PIPE. From stefan.sonnenberg at pythonmeister.com Thu Nov 18 17:24:10 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Thu, 18 Nov 2010 23:24:10 +0100 Subject: Changing the EAX register with Python In-Reply-To: References: Message-ID: <4CE5A78A.1010809@pythonmeister.com> Am 18.11.2010 21:20, schrieb dutche: > Hi folks, I have a unusual question here. > > How can I change the value of EAX register under python under Linux?? > As paimei does under Windows. > > My project is to have a python program that loads a C program and sets > a breakpoint at some address, and then with this breakpoint I change > the EAX register and then continue the program execution. > > With Windows and paimei I did that, but under Linux I don't know yet. > > Any ideas? > > Thank you You asked for it: from ctypes import * import time import os cdll.LoadLibrary('libc.so.6') libc = CDLL('libc.so.6') PTRACE_TRACEME = 0 PTRACE_GETREGS = 12 PTRACE_SETREGS = 13 PTRACE_SYSCALL = 24 SYS_WRITE = 4 SYS_IOCTL = 54 class user_regs_struct(Structure): _fields_ = [ ('ebx',c_ulong), ('ecx',c_ulong), ('edx',c_ulong), ('esi',c_ulong), ('edi',c_ulong), ('ebp',c_ulong), ('eax',c_ulong), ('xds',c_ulong), ('xes',c_ulong), ('xfs',c_ulong), ('xgs',c_ulong), ('orig_eax',c_ulong), ('eip',c_ulong), ('xcs',c_ulong), ('eflags',c_ulong), ('esp',c_ulong), ('xss',c_ulong), ] child = os.fork() if child == 0: libc.ptrace(PTRACE_TRACEME,0,None,None) os.execl('/bin/ls','ls') else: while True: pid,status = os.wait() if status != 0: reg = pointer(user_regs_struct()) libc.ptrace(PTRACE_GETREGS,pid,None,reg) if reg.contents.orig_eax == SYS_IOCTL: print 'IOCTL ebx,ecx = 0x%0x,0x%0x' % (reg.contents.ebx,reg.contents.ecx) # replace IOCTL with SYS_WRITE reg.contents.orig_eax = SYS_WRITE libc.ptrace(PTRACE_SETREGS,pid,None,reg) libc.ptrace(PTRACE_SYSCALL,pid,None,None) else: os._exit(0) -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: debug.py URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: stefan_sonnenberg.vcf Type: text/x-vcard Size: 223 bytes Desc: not available URL: From bryan.wheelock at gmail.com Thu Nov 18 17:31:19 2010 From: bryan.wheelock at gmail.com (Bryan Wheelock) Date: Thu, 18 Nov 2010 17:31:19 -0500 Subject: Why is pdb messing with STDIN? I can't step through my code, or enter any data accurately. Message-ID: I'm baffled by the behavior of pdb as I attempt to debug a Twill test. I'm trying to step through socket.get_fqdn() and my key entries are garbled. I prefer to use ipdb, but the STDOUT gets messed up and printed at the end of the ipdb session. That defeats the purpose of a debugger. So I'm using pdb. Here is the code: def v1endpoint(self, port): """Return an OpenID 1.1 OpenIDServiceEndpoint for the server.""" import pdb; pdb.set_trace() base = "http://%s:%s" % (socket.getfqdn('127.0.0.1'), port) ep = OpenIDServiceEndpoint() ep.claimed_id = base + "/id/bob" ep.server_url = base + "/openidserver" ep.type_uris = [OPENID_1_1_TYPE] return ep Here is the behavior: ---------------------------------------------------------------------- Ran 2 tests in 0.029s FAILED (errors=2) Destroying test database 'default'... > /Users/Bryan/work/osqa/forum/tests.py(96)v1endpoint() -> base = "http://%s:%s" % (socket.getfqdn('127.0.0.1'), port) (Pdb) > /Users/Bryan/work/osqa/forum/tests.py(96)v1endpoint() -> base = "http://%s:%s" % (socket.getfqdn('127.0.0.1'), port) ######################################## # I enter 's' + return no character is displayed (Pdb) --Call-- > /usr/local/lib/python2.7/socket.py(124)getfqdn() -> def getfqdn(name=''): ######################################## # I enter 's' + return no character is displayed (Pdb) > /usr/local/lib/python2.7/socket.py(133)getfqdn() -> name = name.strip() ######################################## # I enter 's' + return no character is displayed (Pdb) ######################################## # I enter 's' + return no character is displayed (Pdb) *** NameError: name 'ss' is not defined ######################################## # I enter 'l' + return ; it's displayed but not the inputed data aparently (Pdb) l*** NameError: name 'ss' is not defined ######################################## # I enter 'l' + return ; it's displayed but not the inputed data aparently (Pdb) s *** NameError: name 'ls' is not defined ######################################## # I enter 'name' + return ; it's displayed but not the inputed data aparently (Pdb) ne None of the pdb commands work. Characters are added or not added. It's driving me nuts. I'm using Python 2.7 on osX-10.5.8 What is going on? I've never seen anything like this. thanks, Bryan -------------- next part -------------- An HTML attachment was scrubbed... URL: From drsalists at gmail.com Thu Nov 18 17:33:12 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Thu, 18 Nov 2010 14:33:12 -0800 Subject: Changing the EAX register with Python In-Reply-To: References: Message-ID: Here's -a- way to try - not necessarily the best way: 1) Write a little gcc .c with inline assembler, to make your EAX change 2) Call it from CPython using ctypes However, by the time you return from the code that makes your change and resume execution in the CPython interpreter, EAX may well have been changed to something new. Accumulators don't often hold the same value for very long. On Thu, Nov 18, 2010 at 12:20 PM, dutche wrote: > Hi folks, I have a unusual question here. > > How can I change the value of EAX register under python under Linux?? > As paimei does under Windows. > > My project is to have a python program that loads a C program and sets > a breakpoint at some address, and then with this breakpoint I change > the EAX register and then continue the program execution. > > With Windows and paimei I did that, but under Linux I don't know yet. > > Any ideas? > > Thank you > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From usernet at ilthio.net Thu Nov 18 17:36:51 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 18 Nov 2010 22:36:51 +0000 (UTC) Subject: How to run an EXE, with argument, capture output value References: <37037d15-63da-4f37-9508-bdcfff034670@s4g2000yql.googlegroups.com> Message-ID: On 2010-11-18, Jean-Michel Pichavant wrote: > Tim Harig wrote: >> If you are not already, I would highly suggest using Python3 with the ^^^^ >> subprocess module: > Suggesting subprocess is a good idea, *highly* suggesting python3 is > questionable. The above code works in python 2. Many libraries (those > included batteries) have not been ported yet to python 3. > Py3 is a better core language than py2, but for now, less featured. I didn't, and I don't, recommend Python3 over Python2 for just any purpose.I recommended Python3's subprocess module over the Python2's subprocess module if that is indeed possible. I happen to be one of those that feels this transition was terribly mis-handled and that there should have been provisions to allow both versions to either be maintained together or to allow modules from both versions to work together. I don't really have a huge preference for either version; but, having to deal with both of them has given the project a black eye. From noydb00 at gmail.com Thu Nov 18 17:54:23 2010 From: noydb00 at gmail.com (noydb) Date: Thu, 18 Nov 2010 14:54:23 -0800 (PST) Subject: How to run an EXE, with argument, capture output value References: <37037d15-63da-4f37-9508-bdcfff034670@s4g2000yql.googlegroups.com> <70d6c9a7-8ba9-420d-822a-0ba71888e4f4@v20g2000yqb.googlegroups.com> Message-ID: <71e489bd-429d-4814-9a0c-6b5f875b3780@30g2000yql.googlegroups.com> On Nov 18, 5:22?pm, Tim Harig wrote: > On 2010-11-18, noydb wrote: > > > import subprocess > > pig = subprocess.Popen(["C:\Halls\hallbig2.exe"], > > stdin=subprocess.PIPE, stdout=subprocess.PIPE) > > result = pig.communicate(input='C:\Halls\Input\Ea39j.txt')[-1] #I need > > to capture the, what I think is the, last output > > From the subprocess documentation: > > ? ? ? ? ? ?[62]communicate() returns a tuple (stdoutdata, stderrdata). > ? ? ? ? ? ?Note that if you want to send data to the process's stdin, > ? ? ? ? ? ?you need to create the Popen object with stdin=PIPE. Similarly, > ? ? ? ? ? ?to get anything other than None in the result tuple, you need > ? ? ? ? ? ?to give stdout=PIPE and/or stderr=PIPE too. > > By using index [-1] you are accessing the processes stderr stream. ?I am > not really sure why you changed it. ?It doesn't give you the last output. > Index 0 gives you *all* of stdout and index 1 gives you *all* of stderr, > period. ?If you wish to further disect the output to get say the last line, > then you will need to parse it separately. Okay, I see now. I did run it to start with 0 -- still same result no matter if 0 or -1. So, what is result (stdout, using [0]) in this case? (yes, i know I sound dumb - programming is not my background, obviously). A list, tuple??? How do you access stdout (or is it stdoutdata?) results? I have tried, get errors with all attempts. The exe gui returns several statistical values uopn inputing a text file (containing numerous lines of ) and clicking compute - I want just one of the values. > > > print result > > print pig.returncode > >>> None > >>> 0 > > > So the tuple is empty. ?? ?The exe executes fine and returns output in > > th exe tool itself. ?The python script seems to execute fine, no > > errors, '...returned exit code 0'. ?Any ideas/suggestions? > > No the tuple contains two items (stdout, stderr). ?The first is what the > program printed to its stdout stream (which is most likely the output you > see if you run the command at a terminal/console). ?The second is what it printed to its > stderr stream which is a channel used for out of band data such as error or > status messages. ?In this case, it is None, because you did open stderr as a > subprocess.PIPE. From calderone.jeanpaul at gmail.com Thu Nov 18 17:59:49 2010 From: calderone.jeanpaul at gmail.com (Jean-Paul Calderone) Date: Thu, 18 Nov 2010 14:59:49 -0800 (PST) Subject: Is Unladen Swallow dead? References: <2e1a4d02-1e8a-4d31-95da-f33aaf90578c@30g2000yql.googlegroups.com> <8b0b044c-34a8-4747-b68f-f4cb56882f6f@e26g2000vbz.googlegroups.com> <4ce37e01$0$1666$742ec2ed@news.sonic.net> <4ce570ff$0$1617$742ec2ed@news.sonic.net> Message-ID: <3c722259-f8f0-49af-b62a-4ee1f8c5e7cc@d8g2000yqf.googlegroups.com> On Nov 18, 1:31?pm, John Nagle wrote: > On 11/18/2010 4:24 AM, BartC wrote: > > > > > > > > > > > "John Nagle" wrote in message > >news:4ce37e01$0$1666$742ec2ed at news.sonic.net... > >> On 11/16/2010 10:24 PM, swapnil wrote: > > >>> AFAIK, the merging plan was approved by Guido early this year. I > >>> guess Google is expecting the community to drive the project > >>> from here on. That was the whole idea for merging it to mainline. > >>> From my last conversation with Collin, they are targeting Python > >>> 3.3 > > >> I think it's dead. They're a year behind on quarterly releases. > >> The last release was Q3 2009. The project failed to achieve its > >> stated goal of a 5x speedup. Not even close. More like 1.5x > >> (http://www.python.org/dev/peps/pep-3146) > > > There must have been good reasons to predict a 5x increase. > > ? ? ?For Java, adding a JIT improved performance by much more than that. > Hard-code compilers for LISP have done much better than 5x. ?The > best Java and LISP compilers approach the speed of C, while CPython > is generally considered to be roughly 60 times slower than C. ?So > 5x probably looked like a conservative goal. ?For Google, a company > which buys servers by the acre, a 5x speedup would have a big payoff. > > > Assuming the 5x speedup was shown to be viable (ie. performing the > > same benchmarks, on the same data, can be done that quickly in any > > other language, and allowing for the overheads associated with > > Python's dynamic nature), then what went wrong? > > ? ? ? Python is defined by what a naive interpreter with late binding > and dynamic name lookups, like CPython, can easily implement. ?Simply > emulating the semantics of CPython with generated code doesn't help > all that much. > > ? ? ? Because you can "monkey patch" Python objects from outside the > class, a local compiler, like a JIT, can't turn name lookups into hard > bindings. ?Nor can it make reliable decisions about the types of > objects. ?That adds a sizable performance penalty. Short of global > program analysis, the compiler can't tell when code for the hard cases > needs to be generated. ?So the hard-case code, where you figure out at > run-time, for ever use of "+", whether "+" is addition or concatenation, > has to be generated every time. ?Making that decision is far slower > than doing an add. > This isn't completely accurate. It *is* possible to write a JIT compiler for a Python runtime which has fast path code for the common case, the case where the meaning of "+" doesn't change between every opcode. PyPy has produced some pretty good results with this approach. For those who haven't seen it yet, http://speed.pypy.org/ has some graphs which reflect fairly well on PyPy's performance for benchmarks that are not entirely dissimilar to real world code. Jean-Paul From eric.frederich at gmail.com Thu Nov 18 18:12:30 2010 From: eric.frederich at gmail.com (Eric Frederich) Date: Thu, 18 Nov 2010 18:12:30 -0500 Subject: Extension on Windows Message-ID: Hello, I am trying to create an extension on Windows and I may be over my head but I have made it pretty far. I am trying to create bindings for some libraries which require me to use Visual Studio 2005. I set up the spammodule example and in VS set the output file to be a .pyd file. When I copy that .pyd file into site-packages I can use it just fine and call system('dir'). Now when I created a 2nd function to wrap a library function I get the following. ImportError: DLL load failed: The specified module could not be found. I added the correct additional include directories and specified the correct .lib file to get it to compile fine without any errors. What is going on here? I tried running python with -vvv and got no meaningful info... it just fails. What else do I need to do? Thanks, ~Eric From usernet at ilthio.net Thu Nov 18 18:16:05 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 18 Nov 2010 23:16:05 +0000 (UTC) Subject: How to run an EXE, with argument, capture output value References: <37037d15-63da-4f37-9508-bdcfff034670@s4g2000yql.googlegroups.com> <70d6c9a7-8ba9-420d-822a-0ba71888e4f4@v20g2000yqb.googlegroups.com> <71e489bd-429d-4814-9a0c-6b5f875b3780@30g2000yql.googlegroups.com> Message-ID: On 2010-11-18, noydb wrote: > On Nov 18, 5:22?pm, Tim Harig wrote: >> On 2010-11-18, noydb wrote: > Okay, I see now. I did run it to start with 0 -- still same result no > matter if 0 or -1. > So, what is result (stdout, using [0]) in this case? (yes, i know I > sound dumb - programming is not my background, obviously). A list, Nope, this one is my fault, I never should have posted being so tired. I was reading posts after being unable to sleep and missed something important about what you said. Sorry about the confusion. > tuple??? How do you access stdout (or is it stdoutdata?) results? I > have tried, get errors with all attempts. The exe gui returns several GUI!!!! Ewwwww. I missed that part. GUIs, on Windows, do not have the standard streams. GUIs are in general, ugly to automate through the GUI itself. I would be much better if the program can be run with command line options, text interface, or if provides an automation object through COM or .Net. As workaround, if you run Python through Windows Script Host, you can open the program with WshShell and automate it, by sending it the keystrokes as you perform the action by typing, with SendKeys() From noydb00 at gmail.com Thu Nov 18 18:20:57 2010 From: noydb00 at gmail.com (noydb) Date: Thu, 18 Nov 2010 15:20:57 -0800 (PST) Subject: How to run an EXE, with argument, capture output value References: <37037d15-63da-4f37-9508-bdcfff034670@s4g2000yql.googlegroups.com> <70d6c9a7-8ba9-420d-822a-0ba71888e4f4@v20g2000yqb.googlegroups.com> <71e489bd-429d-4814-9a0c-6b5f875b3780@30g2000yql.googlegroups.com> Message-ID: <850908d0-26d4-45a5-86bc-855445fde0bf@a37g2000yqi.googlegroups.com> On Nov 18, 5:54?pm, noydb wrote: > On Nov 18, 5:22?pm, Tim Harig wrote: > > > > > > > On 2010-11-18, noydb wrote: > > > > import subprocess > > > pig = subprocess.Popen(["C:\Halls\hallbig2.exe"], > > > stdin=subprocess.PIPE, stdout=subprocess.PIPE) > > > result = pig.communicate(input='C:\Halls\Input\Ea39j.txt')[-1] #I need > > > to capture the, what I think is the, last output > > > From the subprocess documentation: > > > ? ? ? ? ? ?[62]communicate() returns a tuple (stdoutdata, stderrdata). > > ? ? ? ? ? ?Note that if you want to send data to the process's stdin, > > ? ? ? ? ? ?you need to create the Popen object with stdin=PIPE. Similarly, > > ? ? ? ? ? ?to get anything other than None in the result tuple, you need > > ? ? ? ? ? ?to give stdout=PIPE and/or stderr=PIPE too. > > > By using index [-1] you are accessing the processes stderr stream. ?I am > > not really sure why you changed it. ?It doesn't give you the last output. > > Index 0 gives you *all* of stdout and index 1 gives you *all* of stderr, > > period. ?If you wish to further disect the output to get say the last line, > > then you will need to parse it separately. > > Okay, I see now. ?I did run it to start with 0 -- still same result no > matter if 0 or -1. > So, what is result (stdout, using [0]) in this case? ?(yes, i know I > sound dumb - programming is not my background, obviously). ?A list, > tuple??? ?How do you access stdout (or is it stdoutdata?) results? ?I > have tried, get errors with all attempts. ?The exe gui returns several > statistical values uopn inputing a text file (containing numerous > lines of ) and clicking compute - I want just one > of the values. > > > > > > > > print result > > > print pig.returncode > > >>> None > > >>> 0 > > > > So the tuple is empty. ?? ?The exe executes fine and returns output in > > > th exe tool itself. ?The python script seems to execute fine, no > > > errors, '...returned exit code 0'. ?Any ideas/suggestions? > > > No the tuple contains two items (stdout, stderr). ?The first is what the > > program printed to its stdout stream (which is most likely the output you > > see if you run the command at a terminal/console). ?The second is what it printed to its > > stderr stream which is a channel used for out of band data such as error or > > status messages. ?In this case, it is None, because you did open stderr as a > > subprocess.PIPE.- Hide quoted text - > > - Show quoted text -- Hide quoted text - > > - Show quoted text - stdout is a file object From noydb00 at gmail.com Thu Nov 18 18:28:18 2010 From: noydb00 at gmail.com (noydb) Date: Thu, 18 Nov 2010 15:28:18 -0800 (PST) Subject: How to run an EXE, with argument, capture output value References: <37037d15-63da-4f37-9508-bdcfff034670@s4g2000yql.googlegroups.com> <70d6c9a7-8ba9-420d-822a-0ba71888e4f4@v20g2000yqb.googlegroups.com> <71e489bd-429d-4814-9a0c-6b5f875b3780@30g2000yql.googlegroups.com> <850908d0-26d4-45a5-86bc-855445fde0bf@a37g2000yqi.googlegroups.com> Message-ID: <0594c8c1-e13c-4057-9ff5-783ad97fd0a2@l17g2000yqe.googlegroups.com> On Nov 18, 6:20?pm, noydb wrote: > On Nov 18, 5:54?pm, noydb wrote: > > > > > > > On Nov 18, 5:22?pm, Tim Harig wrote: > > > > On 2010-11-18, noydb wrote: > > > > > import subprocess > > > > pig = subprocess.Popen(["C:\Halls\hallbig2.exe"], > > > > stdin=subprocess.PIPE, stdout=subprocess.PIPE) > > > > result = pig.communicate(input='C:\Halls\Input\Ea39j.txt')[-1] #I need > > > > to capture the, what I think is the, last output > > > > From the subprocess documentation: > > > > ? ? ? ? ? ?[62]communicate() returns a tuple (stdoutdata, stderrdata). > > > ? ? ? ? ? ?Note that if you want to send data to the process's stdin, > > > ? ? ? ? ? ?you need to create the Popen object with stdin=PIPE. Similarly, > > > ? ? ? ? ? ?to get anything other than None in the result tuple, you need > > > ? ? ? ? ? ?to give stdout=PIPE and/or stderr=PIPE too. > > > > By using index [-1] you are accessing the processes stderr stream. ?I am > > > not really sure why you changed it. ?It doesn't give you the last output. > > > Index 0 gives you *all* of stdout and index 1 gives you *all* of stderr, > > > period. ?If you wish to further disect the output to get say the last line, > > > then you will need to parse it separately. > > > Okay, I see now. ?I did run it to start with 0 -- still same result no > > matter if 0 or -1. > > So, what is result (stdout, using [0]) in this case? ?(yes, i know I > > sound dumb - programming is not my background, obviously). ?A list, > > tuple??? ?How do you access stdout (or is it stdoutdata?) results? ?I > > have tried, get errors with all attempts. ?The exe gui returns several > > statistical values uopn inputing a text file (containing numerous > > lines of ) and clicking compute - I want just one > > of the values. > > > > > print result > > > > print pig.returncode > > > >>> None > > > >>> 0 > > > > > So the tuple is empty. ?? ?The exe executes fine and returns output in > > > > th exe tool itself. ?The python script seems to execute fine, no > > > > errors, '...returned exit code 0'. ?Any ideas/suggestions? > > > > No the tuple contains two items (stdout, stderr). ?The first is what the > > > program printed to its stdout stream (which is most likely the output you > > > see if you run the command at a terminal/console). ?The second is what it printed to its > > > stderr stream which is a channel used for out of band data such as error or > > > status messages. ?In this case, it is None, because you did open stderr as a > > > subprocess.PIPE.- Hide quoted text - > > > - Show quoted text -- Hide quoted text - > > > - Show quoted text - > > stdout is a file object- Hide quoted text - > > - Show quoted text - if I do >>> print pig.communicate() ('', None) Doesn't that mean it is empty? From steve at REMOVE-THIS-cybersource.com.au Thu Nov 18 19:07:05 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Nov 2010 00:07:05 GMT Subject: Program, Application, and Software References: <87hbffa30d.fsf@benfinney.id.au> Message-ID: <4ce5bfa9$0$29966$c3e8da3$5496439d@news.astraweb.com> On Thu, 18 Nov 2010 14:21:47 +0000, Martin Gregorie wrote: > I use 'script' to refer to programs written in languages that don't have > a separate compile phase which must be run before the program can be > executed. IOW Python and Perl programs are scripts aloing with programs > written as awk, Javascript and bash scripts. You're mistaken then about Python, because it does have a separate compilation phase that runs before the program can be executed. Where do you think the .pyc files come from, and what did you think the compile() function did? It just happens automatically, rather than manually. For that matter, what about languages with JIT compilers, like Java or, yes, Python? CPython itself has no built-in JIT, but PyPy does, and Psyco is an optimizing JIT compiler for CPython on some hardware. I think the difference between "scripts" and "programs" is about as meaningful as the difference between "mountains" and "hills" -- there clearly is a difference between *this specific* hill and *that specific* mountain, but any general distinction between hills and mountains is arbitrary and artificial. Maybe, once upon a time, there was a meaningful distinction to be made between purely interpreted languages and purely compiled languages. But today, when "interpreted" languages have a compilation phase, and "compiled" languages have the equivalent of eval() and do their compilation at runtime, such a distinction is now fairly arbitrary. Better questions are: * Does the program compile to native machine code or byte code? * How efficient is the machine code, or the virtual machine that executes the byte code? What do you mean by "efficient"? * Is there an integrated parse-compile-execute cycle, or does the developer have to perform them individually? * To what degree is the syntax of the language aimed at rapid development and/or runtime efficiency? Harder questions to ask, and answer, than "Is that language for writing scripts or programs or applications?", but the answers are far more meaningful. -- Steven From steve at REMOVE-THIS-cybersource.com.au Thu Nov 18 19:09:37 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Nov 2010 00:09:37 GMT Subject: Some syntactic sugar proposals References: <87mxp7gbdf.fsf.mdw@metalzone.distorted.org.uk> <4ce4b043$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d3q3dljs.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <4ce5c041$0$29966$c3e8da3$5496439d@news.astraweb.com> On Thu, 18 Nov 2010 09:32:23 +0000, Mark Wooding wrote: [...] > You're wrong. Python evaluates these left-to-right, as I said. > Parentheses override operator associativity; they don't affect > evaluation order at all. Fair enough. I concede your point. [...] >> Not everything needs to be a one liner. If you need this, do it the >> old- fashioned way: >> >> t = foo() >> if not pred(t): t = default_value > > I already explained how to write it as a one-liner: > > t = (lambda y: y if pred(y) else default_value)(foo()) I didn't say it couldn't be written as a one-liner. I suggested that it was better not to. The costs of the one-liner are: * reduced readability; * requires an increased level of knowledge of the reader ("what's lambda do?"); * runtime inefficiency (you create a function object, only to use it once then throw it away). The advantages? * one fewer line of code. In my experience, the obsessiveness in which some people look for one- liners is far from helpful, and goes against the spirit of Python. This isn't Perl :) -- Steven From python at mrabarnett.plus.com Thu Nov 18 19:26:41 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 19 Nov 2010 00:26:41 +0000 Subject: Program, Application, and Software In-Reply-To: <4ce5bfa9$0$29966$c3e8da3$5496439d@news.astraweb.com> References: <87hbffa30d.fsf@benfinney.id.au> <4ce5bfa9$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4CE5C441.1020209@mrabarnett.plus.com> On 19/11/2010 00:07, Steven D'Aprano wrote: > On Thu, 18 Nov 2010 14:21:47 +0000, Martin Gregorie wrote: > >> I use 'script' to refer to programs written in languages that don't have >> a separate compile phase which must be run before the program can be >> executed. IOW Python and Perl programs are scripts aloing with programs >> written as awk, Javascript and bash scripts. > > You're mistaken then about Python, because it does have a separate > compilation phase that runs before the program can be executed. Where do > you think the .pyc files come from, and what did you think the compile() > function did? It just happens automatically, rather than manually. > [snip] I think what he means is that you don't need explicitly to compile and then run. From alex.kapps at web.de Thu Nov 18 19:43:28 2010 From: alex.kapps at web.de (Alexander Kapps) Date: Fri, 19 Nov 2010 01:43:28 +0100 Subject: Program, Application, and Software In-Reply-To: <4CE5C441.1020209@mrabarnett.plus.com> References: <87hbffa30d.fsf@benfinney.id.au> <4ce5bfa9$0$29966$c3e8da3$5496439d@news.astraweb.com> <4CE5C441.1020209@mrabarnett.plus.com> Message-ID: <4CE5C830.4000700@web.de> On 19.11.2010 01:26, MRAB wrote: > On 19/11/2010 00:07, Steven D'Aprano wrote: >> On Thu, 18 Nov 2010 14:21:47 +0000, Martin Gregorie wrote: >> >>> I use 'script' to refer to programs written in languages that don't have >>> a separate compile phase which must be run before the program can be >>> executed. IOW Python and Perl programs are scripts aloing with programs >>> written as awk, Javascript and bash scripts. >> >> You're mistaken then about Python, because it does have a separate >> compilation phase that runs before the program can be executed. Where do >> you think the .pyc files come from, and what did you think the compile() >> function did? It just happens automatically, rather than manually. >> > [snip] > I think what he means is that you don't need explicitly to compile and > then run. What difference does it make? Is 'print "Hello"' a program or a script? Are you saying, that it depends on whether you have to manually call some compiler? From martin at address-in-sig.invalid Thu Nov 18 19:57:42 2010 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Fri, 19 Nov 2010 00:57:42 +0000 (UTC) Subject: Program, Application, and Software References: <87hbffa30d.fsf@benfinney.id.au> <4ce5bfa9$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, 19 Nov 2010 00:07:05 +0000, Steven D'Aprano wrote: > On Thu, 18 Nov 2010 14:21:47 +0000, Martin Gregorie wrote: > >> I use 'script' to refer to programs written in languages that don't >> have a separate compile phase which must be run before the program can >> be executed. IOW Python and Perl programs are scripts aloing with >> programs written as awk, Javascript and bash scripts. > > > You're mistaken then about Python, because it does have a separate > compilation phase that runs before the program can be executed. Where do > you think the .pyc files come from, and what did you think the compile() > function did? It just happens automatically, rather than manually. > Notice my mention of the hash-bang line? That makes it quite clear that I did not mean what you're reading into "separate compile phase which must be run" because hash-bang means you can feed source into the run-time execution system, and also means that by definition the source contains or references everything a program needs to run and that the source code translation step, if there is one, is fast enough for the time it takes to be negligible. Those aren't necessarily the case with a separate compilation step. .pyc files are an optional extra: in a *nix environment they are not produced if you use a hash-bang line to execute the source file: they only appear if you run the source with a "python file.py" command. -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From SSharma84 at slb.com Thu Nov 18 20:30:21 2010 From: SSharma84 at slb.com (Sachin Kumar Sharma) Date: Fri, 19 Nov 2010 01:30:21 +0000 Subject: Advise for numerical programming content (New python user) Message-ID: <75C2FED246299A478280FA1470EDA4430A966005@NL0230MBX06N2.DIR.slb.com> Python Users, I am an average Fortran user. I am new to python and I am currently evaluating options and functionalities of numerical programming and related 2d and 3d graphic outputs with python. Kindly share your experience in scientific programming with python like how do you like it, comparison with Fortran and C++. Which version of python + numpy+scipy are compatible with each other or if any other numerical analysis package is available (I am working on windows environment.) Does graphic output like maps, histogram, crossplot, tornado charts is good enough with basic installation or needs some additional packages? Your feedback is valuable for me to start. Thanks & Regards Sachin ************************************************************************ Sachin Kumar Sharma Senior Geoscientist -------------- next part -------------- An HTML attachment was scrubbed... URL: From mdw at distorted.org.uk Thu Nov 18 20:35:55 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Fri, 19 Nov 2010 01:35:55 +0000 Subject: Is Unladen Swallow dead? References: <2e1a4d02-1e8a-4d31-95da-f33aaf90578c@30g2000yql.googlegroups.com> <8b0b044c-34a8-4747-b68f-f4cb56882f6f@e26g2000vbz.googlegroups.com> <4ce37e01$0$1666$742ec2ed@news.sonic.net> <4ce570ff$0$1617$742ec2ed@news.sonic.net> Message-ID: <87vd3uccxw.fsf.mdw@metalzone.distorted.org.uk> John Nagle writes: > Python is defined by what a naive interpreter with late binding > and dynamic name lookups, like CPython, can easily implement. Simply > emulating the semantics of CPython with generated code doesn't help > all that much. Indeed. > Because you can "monkey patch" Python objects from outside the > class, a local compiler, like a JIT, can't turn name lookups into hard > bindings. Nor can it make reliable decisions about the types of > objects. But it /can/ make guesses. A dynamic runtime doesn't have to predict everything right in advance; it only has to predict most things sort of well enough, and fix up the things it got wrong before anyone notices. For example, A Python compiler could inline a function call if it makes a note to recompile the calling function if the called function is modified. Most functions aren't redefined, so this is probably a pretty good guess. > That adds a sizable performance penalty. Short of global program > analysis, the compiler can't tell when code for the hard cases needs > to be generated. The right approach is to guess that things are going to be done the easy way, and then detect when the guess is wrong. > So the hard-case code, where you figure out at run-time, for ever use > of "+", whether "+" is addition or concatenation, has to be generated > every time. Making that decision is far slower than doing an add. There's an old trick here called `inline caching'. The first time a function is called, compile it so as to assume that types of things are as you found this time: inline simple methods, and so on. Insert some quick type checks at the top: is this going to work next time? If not, take a trap back into the compiler. The traditional approach is to replace the mispredictions with full dispatches (`monomorphic inline caching'); the clever approach tolerates a few different types, dispatching to optimized code for each (`polymorphic inline caching'), unless there are just too many decision points and you give up. There are time/space tradeoffs to be made here too. Fortunately, you don't have to compile everything super-optimized from the get-go: you can dynamically identify the inner loops which need special attention, and get the compiler to really stare hard at them. The rest of the program might plausibly be left interpreted much of the time for all anyone will care. > I've referred to this problem as "gratuitous hidden dynamism". > Most things which could be changed dynamically in a Python program > usually aren't. This is one of the crucial observations for making a dynamic language go fast; the other is that you still have the compiler around if you guessed wrong. An aggressively dynamic runtime has two enormous advantages over batch compilers such as are traditionally used for C: it gets the entire program in one go, and it gets to see the real live data that the program's meant to run against. Given that, I'd expect it to be able to /beat/ a batch compiler in terms of performance. > This has been pointed out many times by many people. There's > even a PhD thesis on the topic. Without a few restrictions, so > that a compiler can at least tell when support for the hard cases > is needed, Python cannot be compiled well. This assumes static compilation. It's the wrong approach for a dynamic language like Python. -- [mdw] From phlip2005 at gmail.com Thu Nov 18 20:45:04 2010 From: phlip2005 at gmail.com (Phlip) Date: Thu, 18 Nov 2010 17:45:04 -0800 (PST) Subject: Bunch 2.0 - a dict with a default Message-ID: <58298828-d882-45f8-a396-b8f164d49570@g7g2000vbl.googlegroups.com> Pythonistas: If everyone likes this post, then the code is a "snippet" for community edification. Otherwise, it's a question: How to do this kind of thing better? I want a dict() variant that passes these test cases: map = Map() assert not(map.has_key('_default')) map = Map(yo='dude') assert map['yo'] == 'dude' assert map.yo == 'dude' assert None == map['whatever'] assert not(map.has_key('_default')) map = Map(yo='dude', _default='q') assert 'q' == map['whatever'] assert not(map.has_key('_default')) That's like Bunch, but with a default value. (That makes code with excess if statements less likely.) So here's the implementation: def Map(*args, **kwargs): value = kwargs.get('_default', None) if kwargs.has_key('_default'): del kwargs['_default'] class _DefMap(dict): def __init__(self, *a, **kw): dict.__init__(self, *a, **kw) self.__dict__ = self def __getitem__(self, key): if not self.has_key(key): self[key] = value return dict.__getitem__(self, key) return _DefMap(*args, **kwargs) -- Phlip http://bit.ly/ZeekLand From mdw at distorted.org.uk Thu Nov 18 20:53:13 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Fri, 19 Nov 2010 01:53:13 +0000 Subject: Some syntactic sugar proposals References: <87mxp7gbdf.fsf.mdw@metalzone.distorted.org.uk> <4ce4b043$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d3q3dljs.fsf.mdw@metalzone.distorted.org.uk> <4ce5c041$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87r5eicc52.fsf.mdw@metalzone.distorted.org.uk> Steven D'Aprano writes: > >> Not everything needs to be a one liner. If you need this, do it the > >> old- fashioned way: > >> > >> t = foo() > >> if not pred(t): t = default_value > > > > I already explained how to write it as a one-liner: > > > > t = (lambda y: y if pred(y) else default_value)(foo()) > > I didn't say it couldn't be written as a one-liner. I suggested that it > was better not to. Ahh. I misunderstood the first sentence above as dismissing the possibility. Sorry. I agree that it's not a /nice/ one-liner. ;-) > The costs of the one-liner are: > > * reduced readability; > * requires an increased level of knowledge of the reader ("what's lambda > do?"); > * runtime inefficiency (you create a function object, only to use it once > then throw it away). This last can be obviated by a clever compiler (which, in our case, we have not got). The second could be considered an advantage: it's educational! > The advantages? > > * one fewer line of code. > > In my experience, the obsessiveness in which some people look for one- > liners is far from helpful, and goes against the spirit of Python. This > isn't Perl :) Oh, I agree completely. On the other hand, it's just /fun/. Python is a fun language and using its features in playfully unusual ways is enjoyable; like a good pun in a natural language. Just as puns aren't always appropriate in written language, playful code isn't always appropriate either; but that doesn't mean it's never appropriate. (Java has no sense of humour. C++ does have, but it's a bit weird.) -- [mdw] From ckaynor at zindagigames.com Thu Nov 18 20:55:39 2010 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Thu, 18 Nov 2010 17:55:39 -0800 Subject: Bunch 2.0 - a dict with a default In-Reply-To: <58298828-d882-45f8-a396-b8f164d49570@g7g2000vbl.googlegroups.com> References: <58298828-d882-45f8-a396-b8f164d49570@g7g2000vbl.googlegroups.com> Message-ID: You may want to look at the collections.defaultdict class. It takes in a factory function for default values. You can also implement your class by overriding the __missing__ method of the dict class, rather than overriding the __getitem__. Both were added in Python 2.5 according to the documentation. Chris On Thu, Nov 18, 2010 at 5:45 PM, Phlip wrote: > Pythonistas: > > If everyone likes this post, then the code is a "snippet" for > community edification. Otherwise, it's a question: How to do this kind > of thing better? > > I want a dict() variant that passes these test cases: > > map = Map() > assert not(map.has_key('_default')) > > map = Map(yo='dude') > assert map['yo'] == 'dude' > assert map.yo == 'dude' > assert None == map['whatever'] > assert not(map.has_key('_default')) > > map = Map(yo='dude', _default='q') > assert 'q' == map['whatever'] > assert not(map.has_key('_default')) > > That's like Bunch, but with a default value. (That makes code with > excess if statements less likely.) > > So here's the implementation: > > def Map(*args, **kwargs): > value = kwargs.get('_default', None) > if kwargs.has_key('_default'): del kwargs['_default'] > > class _DefMap(dict): > def __init__(self, *a, **kw): > dict.__init__(self, *a, **kw) > self.__dict__ = self > > def __getitem__(self, key): > if not self.has_key(key): self[key] = value > return dict.__getitem__(self, key) > > return _DefMap(*args, **kwargs) > > -- > Phlip > http://bit.ly/ZeekLand > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mdw at distorted.org.uk Thu Nov 18 21:05:10 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Fri, 19 Nov 2010 02:05:10 +0000 Subject: Program, Application, and Software References: <87hbffa30d.fsf@benfinney.id.au> <4ce5bfa9$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87mxp6cbl5.fsf.mdw@metalzone.distorted.org.uk> Steven D'Aprano writes: > On Thu, 18 Nov 2010 14:21:47 +0000, Martin Gregorie wrote: > > > I use 'script' to refer to programs written in languages that don't have > > a separate compile phase which must be run before the program can be > > executed. IOW Python and Perl programs are scripts aloing with programs > > written as awk, Javascript and bash scripts. > > You're mistaken then about Python, because it does have a separate > compilation phase that runs before the program can be executed. Where do > you think the .pyc files come from, and what did you think the compile() > function did? It just happens automatically, rather than manually. I think Martin meant that there's no /explicit/ compilation phase. As a case in point, tcc is an optimizing native-code compiler for C which is so fast at generating code that it has a mode which accepts an initial `#!' line in its input; the documentation refers to C `scripts'. Awk, Javascript and Perl have full compilation phases too, but they're hidden from the user; bash certainly builds a parse tree but I don't know whether it just walks that or has some other kind of internal representation. > Maybe, once upon a time, there was a meaningful distinction to be made > between purely interpreted languages and purely compiled languages. No, there never was; only between interpreting and compiling implementations. > But today, when "interpreted" languages have a compilation phase, and > "compiled" languages have the equivalent of eval() and do their > compilation at runtime, such a distinction is now fairly arbitrary. > Better questions are: > > * Does the program compile to native machine code or byte code? > > * How efficient is the machine code, or the virtual machine that executes > the byte code? What do you mean by "efficient"? > > * Is there an integrated parse-compile-execute cycle, or does the > developer have to perform them individually? > > * To what degree is the syntax of the language aimed at rapid development > and/or runtime efficiency? > > Harder questions to ask, and answer, than "Is that language for writing > scripts or programs or applications?", but the answers are far more > meaningful. Maybe. I note that there are Lisp systems (plural!) which compile to native code (only -- with no interpreter at all), but fully support runtime `eval', batch compilation of source files, aggressive optimization for speed and/or space, and so on. So I think that some of the above questions, at least, present false dichotomies: one doesn't have to choose one or the other; one can have cake and eat it too. Also some of the questions are about the language and some are about the implementation. It's important not to get the two confused. -- [mdw] From pavlovevidence at gmail.com Thu Nov 18 21:23:24 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 18 Nov 2010 18:23:24 -0800 (PST) Subject: Is Unladen Swallow dead? References: <2e1a4d02-1e8a-4d31-95da-f33aaf90578c@30g2000yql.googlegroups.com> <8b0b044c-34a8-4747-b68f-f4cb56882f6f@e26g2000vbz.googlegroups.com> <4ce37e01$0$1666$742ec2ed@news.sonic.net> <4ce570ff$0$1617$742ec2ed@news.sonic.net> <3c722259-f8f0-49af-b62a-4ee1f8c5e7cc@d8g2000yqf.googlegroups.com> Message-ID: <4f5a7118-bfbe-4a44-9cd2-94c8dbaa8169@e26g2000vbz.googlegroups.com> On Nov 18, 2:59?pm, Jean-Paul Calderone wrote: > On Nov 18, 1:31?pm, John Nagle wrote: > > > > > > > On 11/18/2010 4:24 AM, BartC wrote: > > > > "John Nagle" wrote in message > > >news:4ce37e01$0$1666$742ec2ed at news.sonic.net... > > >> On 11/16/2010 10:24 PM, swapnil wrote: > > > >>> AFAIK, the merging plan was approved by Guido early this year. I > > >>> guess Google is expecting the community to drive the project > > >>> from here on. That was the whole idea for merging it to mainline. > > >>> From my last conversation with Collin, they are targeting Python > > >>> 3.3 > > > >> I think it's dead. They're a year behind on quarterly releases. > > >> The last release was Q3 2009. The project failed to achieve its > > >> stated goal of a 5x speedup. Not even close. More like 1.5x > > >> (http://www.python.org/dev/peps/pep-3146) > > > > There must have been good reasons to predict a 5x increase. > > > ? ? ?For Java, adding a JIT improved performance by much more than that. > > Hard-code compilers for LISP have done much better than 5x. ?The > > best Java and LISP compilers approach the speed of C, while CPython > > is generally considered to be roughly 60 times slower than C. ?So > > 5x probably looked like a conservative goal. ?For Google, a company > > which buys servers by the acre, a 5x speedup would have a big payoff. > > > > Assuming the 5x speedup was shown to be viable (ie. performing the > > > same benchmarks, on the same data, can be done that quickly in any > > > other language, and allowing for the overheads associated with > > > Python's dynamic nature), then what went wrong? > > > ? ? ? Python is defined by what a naive interpreter with late binding > > and dynamic name lookups, like CPython, can easily implement. ?Simply > > emulating the semantics of CPython with generated code doesn't help > > all that much. > > > ? ? ? Because you can "monkey patch" Python objects from outside the > > class, a local compiler, like a JIT, can't turn name lookups into hard > > bindings. ?Nor can it make reliable decisions about the types of > > objects. ?That adds a sizable performance penalty. Short of global > > program analysis, the compiler can't tell when code for the hard cases > > needs to be generated. ?So the hard-case code, where you figure out at > > run-time, for ever use of "+", whether "+" is addition or concatenation, > > has to be generated every time. ?Making that decision is far slower > > than doing an add. > > This isn't completely accurate. ?It *is* possible to write a JIT > compiler > for a Python runtime which has fast path code for the common case, the > case > where the meaning of "+" doesn't change between every opcode. ?PyPy > has > produced some pretty good results with this approach. Right. The key is to be able to dispatch on the type of object once for a given chunk of code, which is possible if you do some kind of flow path analysis on the function/chunk. PyPy is starting to look much better of late, I kind of thought their first approach was wrong (or at least too much) but they seem to have pushed though it. Carl Banks From tjreedy at udel.edu Thu Nov 18 21:54:42 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 18 Nov 2010 21:54:42 -0500 Subject: Program, Application, and Software In-Reply-To: <87mxp6cbl5.fsf.mdw@metalzone.distorted.org.uk> References: <87hbffa30d.fsf@benfinney.id.au> <4ce5bfa9$0$29966$c3e8da3$5496439d@news.astraweb.com> <87mxp6cbl5.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On 11/18/2010 9:05 PM, Mark Wooding wrote: >> Maybe, once upon a time, there was a meaningful distinction to be made >> between purely interpreted languages and purely compiled languages. > > No, there never was; only between interpreting and compiling > implementations. Right. I remember using a C *interpreter* about 25 years ago on Unix. And on Windows, as I remember, the Borland TurboC system let one compile, link, and run with one command. A language is just a language, not an implementation. -- Terry Jan Reedy From steve at holdenweb.com Thu Nov 18 21:55:49 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 18 Nov 2010 21:55:49 -0500 Subject: Distribution of Python Scripts In-Reply-To: References: Message-ID: On 11/18/2010 11:48 AM, tazz_ben wrote: > Hi Folks - > > I'm an experienced programmer, but this is my first app with python, > so I apologize for any stupidity on my part. So I've written/still > working on a command line tool written in Python. It talks to a web > service, so there really isn't anything in it that is dependent on a > particular os. My goal is to distribute the script as a tool to my > users so they can use it (they are on multiple platforms), the vast > majority are not programmers. > > So, I'm looking for a way to distribute the app that takes care of > details like them having python installed, or having an older version > etc. From reading some docs it sounds like "Squeeze" did exactly this > back in the day, but it is ancient and I'm writing in 2.7. Just to > be clear I could care less if they see the source code, my goal is all > around ease of use. I would love to have one distribution file for > all platforms, but I can live with making three if that's the only > option. > > So, what's my options. The only one I could find was cxFreeze: http://cx-freeze.sourceforge.net/ regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From nagle at animats.com Thu Nov 18 22:57:44 2010 From: nagle at animats.com (John Nagle) Date: Thu, 18 Nov 2010 19:57:44 -0800 Subject: Is Unladen Swallow dead? In-Reply-To: <87vd3uccxw.fsf.mdw@metalzone.distorted.org.uk> References: <2e1a4d02-1e8a-4d31-95da-f33aaf90578c@30g2000yql.googlegroups.com> <8b0b044c-34a8-4747-b68f-f4cb56882f6f@e26g2000vbz.googlegroups.com> <4ce37e01$0$1666$742ec2ed@news.sonic.net> <4ce570ff$0$1617$742ec2ed@news.sonic.net> <87vd3uccxw.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <4ce5f5c4$0$1592$742ec2ed@news.sonic.net> On 11/18/2010 5:35 PM, Mark Wooding wrote: > John Nagle writes: > >> Python is defined by what a naive interpreter with late binding >> and dynamic name lookups, like CPython, can easily implement. Simply >> emulating the semantics of CPython with generated code doesn't help >> all that much. > > Indeed. > >> Because you can "monkey patch" Python objects from outside the >> class, a local compiler, like a JIT, can't turn name lookups into hard >> bindings. Nor can it make reliable decisions about the types of >> objects. > > But it /can/ make guesses. A dynamic runtime doesn't have to predict > everything right in advance; it only has to predict most things sort of > well enough, and fix up the things it got wrong before anyone notices. > For example, A Python compiler could inline a function call if it makes > a note to recompile the calling function if the called function is > modified. Most functions aren't redefined, so this is probably a pretty > good guess. > >> That adds a sizable performance penalty. Short of global program >> analysis, the compiler can't tell when code for the hard cases needs >> to be generated. > > The right approach is to guess that things are going to be done the easy > way, and then detect when the guess is wrong. That's been done successfully for Self and JavaScript. It's not easy. See this talk on JaegerMonkey: http://blog.cdleary.com/2010/09/picing-on-javascript-for-fun-and-profit/ The effort needed to do that for Javascript is justified by the size of the installed base. The Unladen Swallow people had plans to go in that direction, but they underestimated the size of the job. John Nagle From aahz at pythoncraft.com Thu Nov 18 23:04:28 2010 From: aahz at pythoncraft.com (Aahz) Date: 18 Nov 2010 20:04:28 -0800 Subject: Python has a "really hidden encapsulation"? References: <87iq0vpaw3.fsf@gmail.com> <5286c48b-0567-4e13-bfbc-aaaeab0a6438@v20g2000yqb.googlegroups.com> <87fwvw214g.fsf@gmail.com> Message-ID: In article <87fwvw214g.fsf at gmail.com>, Arnaud Delobelle wrote: > >Are you referring to the fact that in Python, if an attribute is a >property, the __dict__ lookup on the instance is not performed? As in: > >>>> class A: >... @property >... def x(self): return 42 >... >>>> a = A() >>>> a.__dict__['x'] = 24 >>>> a.x >42 >>>> a.__dict__['x'] >24 > >This is documented, but I actually don't know the reason for it. Because otherwise you would be able to overwrite the property with a value. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Look, it's your affair if you want to play with five people, but don't go calling it doubles." --John Cleese anticipates Usenet From steve at holdenweb.com Thu Nov 18 23:19:19 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 18 Nov 2010 23:19:19 -0500 Subject: Program, Application, and Software In-Reply-To: References: <87hbffa30d.fsf@benfinney.id.au> <4ce5bfa9$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 11/18/2010 7:57 PM, Martin Gregorie wrote: [...] > .pyc files are an optional extra: in a *nix environment they are not > produced if you use a hash-bang line to execute the source file: they > only appear if you run the source with a "python file.py" command. > Close, but no cigar. They are only created (assuming file permissions permit) when the module is *imported*. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From rtomek at ceti.com.pl Thu Nov 18 23:23:29 2010 From: rtomek at ceti.com.pl (Tomasz Rola) Date: Fri, 19 Nov 2010 05:23:29 +0100 Subject: What was your strategy? In-Reply-To: <7xzktbcqox.fsf@ruckus.brouhaha.com> References: <7xzktbcqox.fsf@ruckus.brouhaha.com> Message-ID: On Sun, 14 Nov 2010, Paul Rubin wrote: > Jorge Biquez writes: > > I was wondering if you can share what was the strategy you followed to > > master Python (Yes I know I have to work hard study and practice a lot). > > 1. Read the tutorial http://docs.python.org/tutorial/ > 2. Start writing code, and encounter various issues as usually happens. > 3. Refer to the other reference manuals, web search, and ask questions > in the newsgroup as you run into issues. > 4. After a while you'll have hit most of the usual issues and learned > how to deal with them, and how to find resolution for new issues that > might come up. That's about as close to mastery as one normally > reaches in this world. > > Python is a pretty easy language if you have a reasonable programming > background when you first start with it. I think the way it's currently > organized, it may not be so great for self-study if you're not already a > programmer. > > > I mean did you use special books, special sites, > > Nah. Wow, exactly same strategy by me. Do you think it should be GPLed, by chance ;-) ? I find this way of learning to be a bit hard (it must have helped that I was no beginner), but somehow none other option came to my head when I was approaching Python some years ago. I guess I'm not a good follower of various written "rules of engagement". So, after tutorial I jumped over the standard Python docs (module index, plus library & language references) until I found whatever was needed at the moment. So choice of strategy depends on choice maker. BTW, I think it was very important in my case to have specific program in mind, begging me to write it in Python. So learning was more exciting thanks to this. I came to Python from some other languages, of which only C retains it's value to me nowadays. I consider myself kind of departed from Pythonland, in search of some other, maybe better alternatives - but it is quite possible Python will join C. I'm undecided, as I've not tried 3.x yet. As a side note, I'm not quite sure Python is good for beginners. Yes, it is very simple and easy to grasp. And yes, it is a bit too simple, maybe? So a beginner learns to think in terms of nails and hammers, but may never hear of screwdrivers in his programing life. I may be wrong but, thinking of it, I feel it was good I have been exposed to Pascal and C (and few other things) long before Python. I would advise Python to casual/Sunday programers, knowing there is big chance they will never learn more than this, so Python is their best option IMHO. But in case of "serious"/"serial" ;-) programing, I would save Python for second or third language. I mean, I perceive it as rather "one way to do it" language and forcing this "one way" on unformed programer doesn't look good. No offence. See? I'm still here. 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 steve at REMOVE-THIS-cybersource.com.au Thu Nov 18 23:26:28 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Nov 2010 04:26:28 GMT Subject: what's the precision of fractions.Fraction? References: Message-ID: <4ce5fc73$0$29966$c3e8da3$5496439d@news.astraweb.com> On Thu, 18 Nov 2010 20:08:00 +0100, Stefan Sonnenberg-Carstens wrote: > If you need it really *precise*, cast your Fractions into type Decimal: It's actually the opposite. Decimal has many advantages, but being "really precise" is not one of them. It suffers the exact same issues re precision and round-off as binary floating point. It is easy to demonstrate that there are numbers which cannot be represented precisely as Decimals no matter how many decimal places you use, but can be represented exactly as Fractions. Fraction can exactly represent every Decimal, but Decimal cannot represent exactly every Fraction. We're not talking about weird edge cases either, but simple numbers that you're likely to come across every day: >>> from decimal import Decimal >>> one_ninth = Decimal(1)/Decimal(9) >>> two_thirds = Decimal(2)/Decimal(3) >>> one_ninth*6 == two_thirds False >>> from fractions import Fraction >>> one_ninth = Fraction(1, 9) >>> two_thirds = Fraction(2, 3) >>> one_ninth*6 == two_thirds True Still not convinced? >>> f = Fraction(1) + Fraction(1, 10**100000) >>> f != 1 True (which is virtually instantaneous, by the way) compared to the *much* slower: >>> d = Decimal(1) + Decimal(1)/Decimal(10**100000) >>> d != 1 False Yes, I could try to set the Decimal context to 100,000 decimal places -- and just as easily defeat it again by adding one more to the exponent. In my opinion, the Fraction module is one of the least appreciated and underused modules in the standard library -- and I include myself in that. It really is a joy, and I don't use it anywhere near enough. -- Steven From steve at REMOVE-THIS-cybersource.com.au Thu Nov 18 23:30:30 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Nov 2010 04:30:30 GMT Subject: Program, Application, and Software References: <87hbffa30d.fsf@benfinney.id.au> <4ce5bfa9$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4ce5fd65$0$29966$c3e8da3$5496439d@news.astraweb.com> On Fri, 19 Nov 2010 00:26:41 +0000, MRAB wrote: > On 19/11/2010 00:07, Steven D'Aprano wrote: >> On Thu, 18 Nov 2010 14:21:47 +0000, Martin Gregorie wrote: >> >>> I use 'script' to refer to programs written in languages that don't >>> have a separate compile phase which must be run before the program can >>> be executed. IOW Python and Perl programs are scripts aloing with >>> programs written as awk, Javascript and bash scripts. >> >> You're mistaken then about Python, because it does have a separate >> compilation phase that runs before the program can be executed. Where >> do you think the .pyc files come from, and what did you think the >> compile() function did? It just happens automatically, rather than >> manually. >> > [snip] > I think what he means is that you don't need explicitly to compile and > then run. So if I write a small shell script to act as a wrapper around the usual compile/execute cycle of (say) C, my C programs turn into scripts, but if I ignore the wrapper and run the compile/execute commands manually, they turn back into not-scripts? -- Steven From tdldev at gmail.com Fri Nov 19 00:39:23 2010 From: tdldev at gmail.com (Verde Denim) Date: Fri, 19 Nov 2010 00:39:23 -0500 Subject: dpkt Message-ID: Hi I'm looking to find some help working with dpkt. As you probably know, there really isn't any documentation, and not being astute at Python as of yet leaves me with a lot of gaps. Is there anyone here that can point me in a direction toward writing some test code for parsing gre packets? Thanks for the input; I appreciate the help. Jack -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan.sonnenberg at pythonmeister.com Fri Nov 19 01:26:25 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Fri, 19 Nov 2010 07:26:25 +0100 Subject: dpkt In-Reply-To: References: Message-ID: <4CE61891.2070601@pythonmeister.com> Am 19.11.2010 06:39, schrieb Verde Denim: > Hi > I'm looking to find some help working with dpkt. As you probably know, > there really isn't any documentation, and not being astute at Python > as of yet leaves me with a lot of gaps. > Is there anyone here that can point me in a direction toward writing > some test code for parsing gre packets? > > Thanks for the input; I appreciate the help. > > Jack There is. It is inside the code (not the obvious way). http://www.monkey.org/~dugsong/dpkt/pydoc/public/dpkt-module.html (May be outdated) -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: stefan_sonnenberg.vcf Type: text/x-vcard Size: 223 bytes Desc: not available URL: From timr at probo.com Fri Nov 19 02:17:00 2010 From: timr at probo.com (Tim Roberts) Date: Thu, 18 Nov 2010 23:17:00 -0800 Subject: Changing the EAX register with Python References: Message-ID: dutche wrote: > >Hi folks, I have a unusual question here. > >How can I change the value of EAX register under python under Linux?? >As paimei does under Windows. > >My project is to have a python program that loads a C program and sets >a breakpoint at some address, and then with this breakpoint I change >the EAX register and then continue the program execution. > >With Windows and paimei I did that, but under Linux I don't know yet. You will need to find a Linux application equivalent to PaiMei. Your question is not "how can I change EAX", your question is "where can I find a Linux debugger that can be controlled from Python?" I don't know the answer to that. gdb is quite powerful, and you can certainly control it by connecting to its stdin and stdout connections. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From stefan.sonnenberg at pythonmeister.com Fri Nov 19 03:28:48 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Fri, 19 Nov 2010 09:28:48 +0100 Subject: Changing the EAX register with Python In-Reply-To: References: Message-ID: Hi, just read my mail :-) You can just build an debugger in python yourself. The script I posted should give you an idea. Am Fr, 19.11.2010, 08:17 schrieb Tim Roberts: > dutche wrote: >> >>Hi folks, I have a unusual question here. >> >>How can I change the value of EAX register under python under Linux?? >>As paimei does under Windows. >> >>My project is to have a python program that loads a C program and sets >>a breakpoint at some address, and then with this breakpoint I change >>the EAX register and then continue the program execution. >> >>With Windows and paimei I did that, but under Linux I don't know yet. > > You will need to find a Linux application equivalent to PaiMei. Your > question is not "how can I change EAX", your question is "where can I find > a Linux debugger that can be controlled from Python?" > > I don't know the answer to that. gdb is quite powerful, and you can > certainly control it by connecting to its stdin and stdout connections. > -- > Tim Roberts, timr at probo.com > Providenza & Boekelheide, Inc. > -- > http://mail.python.org/mailman/listinfo/python-list > > -- MfG, Stefan Sonnenberg-Carstens IT Architect From greg.ewing at canterbury.ac.nz Fri Nov 19 03:48:58 2010 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Fri, 19 Nov 2010 21:48:58 +1300 Subject: ANN: PyGUI 2.3.1 Message-ID: PyGUI 2.3.1 is available: http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/ This version incorporates a modification that I hope will improve the behaviour of ScrollableViews on Windows with pywin32 builds later than 212. (There are still problems with it, though. If the Scrollable View doesn't fill all of its containing window, the scroll bars get repositioned incorrectly when the window is resized. This appears to be entirely MFC's doing. I really will have to get away from using CView altogether.) This version also fixes a problem on Windows whereby dismissing a modal dialog with the Return key could spuriously activate a button in another window. What is PyGUI? -------------- PyGUI is a cross-platform GUI toolkit designed to be lightweight and have a highly Pythonic API. -- Gregory Ewing greg.ewing at canterbury.ac.nz http://www.cosc.canterbury.ac.nz/greg.ewing/ From jeanmichel at sequans.com Fri Nov 19 05:43:26 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 19 Nov 2010 11:43:26 +0100 Subject: Distribution of Python Scripts In-Reply-To: References: Message-ID: <4CE654CE.6030705@sequans.com> tazz_ben wrote: > Hi Folks - > > I'm an experienced programmer, but this is my first app with python, > so I apologize for any stupidity on my part. So I've written/still > working on a command line tool written in Python. It talks to a web > service, so there really isn't anything in it that is dependent on a > particular os. My goal is to distribute the script as a tool to my > users so they can use it (they are on multiple platforms), the vast > majority are not programmers. > > So, I'm looking for a way to distribute the app that takes care of > details like them having python installed, or having an older version > etc. From reading some docs it sounds like "Squeeze" did exactly this > back in the day, but it is ancient and I'm writing in 2.7. Just to > be clear I could care less if they see the source code, my goal is all > around ease of use. I would love to have one distribution file for > all platforms, but I can live with making three if that's the only > option. > > So, what's my options. > I've never done that before. So maybe I will give you a very bad idea, but if so, I'm confident that ppl in this list will scream about it :) You can ship your app with python (the executable) and the module you're using as local modules. Let's assume you are importing sys and os: myApp/python.exe myApp/myScript.py myApp/os/__init__.py -> actually the whole package myApp/sys/__init__.py If you see what I mean. by running python.exe myScript.py ... That should work. You'll have to include every single module you are using. Only python.exe would required to be platform specific. Maybe that's a terrible thing to do... :D JM From xrgtn at yandex.ru Fri Nov 19 06:14:34 2010 From: xrgtn at yandex.ru (Alexander Gattin) Date: Fri, 19 Nov 2010 13:14:34 +0200 Subject: SQLite3 and lastrowid In-Reply-To: <2ec7c0d8-4105-452d-88e3-01050c4c567f@v12g2000vbh.googlegroups.com> References: <2d87112c-e776-41ea-838a-5e165e478052@e20g2000vbn.googlegroups.com> <713377d1-b9e2-4da1-a56a-c4f042f6e3e4@g2g2000vbe.googlegroups.com> <2ec7c0d8-4105-452d-88e3-01050c4c567f@v12g2000vbh.googlegroups.com> Message-ID: <20101119111434.GF31233@xrgtn-q40> Hello, On Tue, Nov 16, 2010 at 01:52:42PM -0800, Ian wrote: > The proper way to get the number of rows is to > use the COUNT aggregate function, e.g., "SELECT > COUNT(*) FROM TABLE1", which will return a > single row with a single column containing the > number of rows in table1. It's better to select count(1) instead of count(*). The latter may skip rows consisting entirely of NULLs IIRC. -- With best regards, xrgtn From iamforufriends at gmail.com Fri Nov 19 06:24:44 2010 From: iamforufriends at gmail.com (DATE@COUPLES) Date: Fri, 19 Nov 2010 03:24:44 -0800 (PST) Subject: HI ALL, COUPLE R INVITING U FOR HOT DATING FOR FREE.... PLZ WELCOME(ABOVE 18YEARS ONLY) Message-ID: HI ALL, COUPLE R INVITING U FOR HOT DATING FOR FREE.... PLZ WELCOME(ABOVE 18YEARS ONLY) http://x2c.eu/58 http://x2c.eu/58 http://x2c.eu/58 http://x2c.eu/58 http://x2c.eu/58 http://x2c.eu/58 http://x2c.eu/58 http://x2c.eu/58 From xrgtn at yandex.ru Fri Nov 19 06:28:53 2010 From: xrgtn at yandex.ru (Alexander Gattin) Date: Fri, 19 Nov 2010 13:28:53 +0200 Subject: SQLite3 and lastrowid In-Reply-To: <20101119111434.GF31233@xrgtn-q40> References: <2d87112c-e776-41ea-838a-5e165e478052@e20g2000vbn.googlegroups.com> <713377d1-b9e2-4da1-a56a-c4f042f6e3e4@g2g2000vbe.googlegroups.com> <2ec7c0d8-4105-452d-88e3-01050c4c567f@v12g2000vbh.googlegroups.com> <20101119111434.GF31233@xrgtn-q40> Message-ID: <20101119112853.GG31233@xrgtn-q40> On Fri, Nov 19, 2010 at 01:14:34PM +0200, Alexander Gattin wrote: > On Tue, Nov 16, 2010 at 01:52:42PM -0800, Ian > wrote: > > The proper way to get the number of rows is to > > use the COUNT aggregate function, e.g., "SELECT > > COUNT(*) FROM TABLE1", which will return a > > single row with a single column containing the > > number of rows in table1. > > It's better to select count(1) instead of > count(*). The latter may skip rows consisting > entirely of NULLs IIRC. sorry, I'm wrong -- count(*) behaves the same way as count(1) does: sqlite> create table t (x number, y char); sqlite> insert into t(x,y) values(1,'a'); sqlite> insert into t(x,y) values(2,NULL); sqlite> insert into t(x,y) values(NULL,'c'); sqlite> insert into t(x,y) values(NULL,NULL); sqlite> insert into t(x,y) values(NULL,NULL); sqlite> select count(1),count(*),count(x),count(y) from t; 5|5|2|2 sqlite> P.S. Surprise -- it's true even for Oracle SQL... -- With best regards, xrgtn (+380501102966/+380636177128/xrgtn at jabber.kiev.ua) From alain at dpt-info.u-strasbg.fr Fri Nov 19 06:32:19 2010 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Fri, 19 Nov 2010 12:32:19 +0100 Subject: SQLite3 and lastrowid References: <2d87112c-e776-41ea-838a-5e165e478052@e20g2000vbn.googlegroups.com> <713377d1-b9e2-4da1-a56a-c4f042f6e3e4@g2g2000vbe.googlegroups.com> <2ec7c0d8-4105-452d-88e3-01050c4c567f@v12g2000vbh.googlegroups.com> Message-ID: <87r5ehblbw.fsf@dpt-info.u-strasbg.fr> Alexander Gattin writes: >> The proper way to get the number of rows is to >> use the COUNT aggregate function, e.g., "SELECT >> COUNT(*) FROM TABLE1", which will return a >> single row with a single column containing the >> number of rows in table1. > > It's better to select count(1) instead of > count(*). The latter may skip rows consisting > entirely of NULLs IIRC. Wrong: count(anyname) ignores NULL, whereas count(*) does not. -- Alain. From xrgtn at yandex.ru Fri Nov 19 06:47:49 2010 From: xrgtn at yandex.ru (Alexander Gattin) Date: Fri, 19 Nov 2010 13:47:49 +0200 Subject: strange subprocess behavior when calling ps In-Reply-To: References: <55f26d5c-aba9-4892-9e2c-1caa9988e7fe@v23g2000vbi.googlegroups.com> <61496525-afab-4d19-a7e9-e61fb46e03ef@n30g2000vbb.googlegroups.com> Message-ID: <20101119114748.GH31233@xrgtn-q40> Hello, On Wed, Nov 17, 2010 at 01:19:09AM -0800, Ned Deily wrote: > As far as I know, COMMAND_MODE has no special > meaning on other platforms UNIX_STD=2003 on HP-UX if anyone's interested... -- With best regards, xrgtn From xrgtn at umc.com.ua Fri Nov 19 07:00:44 2010 From: xrgtn at umc.com.ua (Alexander Gattin) Date: Fri, 19 Nov 2010 14:00:44 +0200 Subject: SQLite3 and lastrowid In-Reply-To: <87r5ehblbw.fsf@dpt-info.u-strasbg.fr> References: <2d87112c-e776-41ea-838a-5e165e478052@e20g2000vbn.googlegroups.com> <713377d1-b9e2-4da1-a56a-c4f042f6e3e4@g2g2000vbe.googlegroups.com> <2ec7c0d8-4105-452d-88e3-01050c4c567f@v12g2000vbh.googlegroups.com> <87r5ehblbw.fsf@dpt-info.u-strasbg.fr> Message-ID: <20101119120044.GI31233@xrgtn-q40> Hello, On Fri, Nov 19, 2010 at 12:32:19PM +0100, Alain Ketterlin wrote: > Alexander Gattin writes: > > It's better to select count(1) instead of > > count(*). The latter may skip rows consisting > > entirely of NULLs IIRC. > > Wrong: count(anyname) ignores NULL, whereas count(*) does not. I'm using count(1), which is a count over constant non-NULL expression (1). It doesn't ignore NULLs or duplicate rows, as my attempts with Oracle 10g, 8g and sqlite3 show. -- With best regards, xrgtn From wolfgang at rohdewald.de Fri Nov 19 07:03:14 2010 From: wolfgang at rohdewald.de (Wolfgang Rohdewald) Date: Fri, 19 Nov 2010 13:03:14 +0100 Subject: SQLite3 and lastrowid In-Reply-To: <20101119111434.GF31233@xrgtn-q40> References: <2d87112c-e776-41ea-838a-5e165e478052@e20g2000vbn.googlegroups.com> <2ec7c0d8-4105-452d-88e3-01050c4c567f@v12g2000vbh.googlegroups.com> <20101119111434.GF31233@xrgtn-q40> Message-ID: <201011191303.14984.wolfgang@rohdewald.de> On Freitag 19 November 2010, Alexander Gattin wrote: > It's better to select count(1) instead of > count(*). The latter may skip rows consisting > entirely of NULLs IIRC. in some data bases count(1) is said to be faster than count(*), I believe -- Wolfgang From alain at dpt-info.u-strasbg.fr Fri Nov 19 07:23:40 2010 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Fri, 19 Nov 2010 13:23:40 +0100 Subject: SQLite3 and lastrowid References: <2d87112c-e776-41ea-838a-5e165e478052@e20g2000vbn.googlegroups.com> <713377d1-b9e2-4da1-a56a-c4f042f6e3e4@g2g2000vbe.googlegroups.com> <2ec7c0d8-4105-452d-88e3-01050c4c567f@v12g2000vbh.googlegroups.com> <87r5ehblbw.fsf@dpt-info.u-strasbg.fr> Message-ID: <87k4k9biyb.fsf@dpt-info.u-strasbg.fr> Alexander Gattin writes: > On Fri, Nov 19, 2010 at 12:32:19PM +0100, Alain > Ketterlin wrote: >> Alexander Gattin writes: >> > It's better to select count(1) instead of >> > count(*). The latter may skip rows consisting >> > entirely of NULLs IIRC. >> >> Wrong: count(anyname) ignores NULL, whereas count(*) does not. > > I'm using count(1), which is a count over constant > non-NULL expression (1). It doesn't ignore NULLs > or duplicate rows, as my attempts with Oracle 10g, > 8g and sqlite3 show. I'm not saying anything about count(1) (which works like count(*) as you explain, even though I see no point in using 1, since *'s hehavior is well-defined). What was wrong in your first message is that count(*) ignores NULL (granted, you've corrected your mistake in a later message, which I didn't see before posting). -- Alain. From ulrich.eckhardt at dominolaser.com Fri Nov 19 07:28:37 2010 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Fri, 19 Nov 2010 13:28:37 +0100 Subject: Extension on Windows References: Message-ID: Eric Frederich wrote: > I am trying to create an extension on Windows and I may be over my > head but I have made it pretty far. > > I am trying to create bindings for some libraries which require me to > use Visual Studio 2005. > > I set up the spammodule example and in VS set the output file to be a .pyd > file. When I copy that .pyd file into site-packages I can use it just fine > and call system('dir'). A ".pyd" is a ".dll", just with a different extension. That means that you can use all tools for DLLs on those, too, like e.g. dependencywalker[1] in order to check for missing dependent DLLs. If the name of the PYD is "foo.pyd", Python looks for a function "foo_init" (or "init_foo") which it calls in order to register the contained code. If this is missing or has the wrong name, Python won't load it. That means that you can't rename the file without touching its content! > Now when I created a 2nd function to wrap a library function I get the > following. > > ImportError: DLL load failed: The specified module could not be found. This can mean that the module itself couldn't be loaded or that one of the DLLs it depends on couldn't be found. Use dependencywalker to check. > I added the correct additional include directories and specified the > correct .lib file to get it to compile fine without any errors. That may be so, but it won't make the system pick up the DLL from whichever location you installed it to. > What is going on here? I tried running python with -vvv and got no > meaningful info... it just fails. Python tries to load the DLL and only gets told by the system that "the DLL failed to load", but not which one. I'm afraid Python can't do any better, since it doesn't have any better info itself. Uli [1] http://dependencywalker.com -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From deets at web.de Fri Nov 19 07:39:14 2010 From: deets at web.de (Diez B. Roggisch) Date: Fri, 19 Nov 2010 13:39:14 +0100 Subject: How to correctly pass =?utf-8?Q?=E2=80=9Cpointer-to-pointer?= =?utf-8?Q?=E2=80=9D?= into DLL via ctypes? References: Message-ID: Grigory Petrov writes: > Hello. > > I have a DLL that allocates memory and returns it. Function in DLL is like this: > > void Foo( unsigned char** ppMem, int* pSize ) > { > ? * pSize = 4; > ? * ppMem = malloc( * pSize ); > ? for( int i = 0; i < * pSize; i ++ ) (* pMem)[ i ] = i; > } > > Also, i have a python code that access this function from my DLL: > > from ctypes import * > Foo = windll.mydll.Foo > Foo.argtypes = [ POINTER( POINTER( c_ubyte ) ), POINTER( c_int ) ] > mem = POINTER( c_ubyte )() > size = c_int( 0 ) > Foo( byref( mem ), byref( size ) ] > print size, mem[ 0 ], mem[ 1 ], mem[ 2 ], mem[ 3 ] > > I'm expecting that?print?will show "4 0 1 2 3" but it shows "4 221 221 > 221 221" O_O. Any hints what i'm doing wrong? After correcting quite a few obvious errors in your code, it worked just fine for me. So I guess what you think you test is not what you test. --- test.py from ctypes import * foo = cdll.LoadLibrary("/Users/deets/projects/GH28/kinect/kinect/c/foo/libtest.dylib").foo foo.argtypes = [ POINTER( POINTER( c_ubyte ) ), POINTER( c_int ) ] mem = POINTER( c_ubyte )() size = c_int( 0 ) foo( byref( mem ), byref( size ) ) print size, mem[ 0 ], mem[ 1 ], mem[ 2 ], mem[ 3 ] --- --- test.c void foo( unsigned char** ppMem, int* pSize ) { int i; * pSize = 4; * ppMem = malloc( * pSize ); for( i = 0; i < * pSize; i ++ ) (* ppMem)[ i ] = i; } --- --- CMakeLists.txt cmake_minimum_required (VERSION 2.6) project (Test) add_library(test SHARED test.c) --- -- Diez From xrgtn at yandex.ru Fri Nov 19 07:39:54 2010 From: xrgtn at yandex.ru (Alexander Gattin) Date: Fri, 19 Nov 2010 14:39:54 +0200 Subject: SQLite3 and lastrowid In-Reply-To: <201011191303.14984.wolfgang@rohdewald.de> References: <2d87112c-e776-41ea-838a-5e165e478052@e20g2000vbn.googlegroups.com> <2ec7c0d8-4105-452d-88e3-01050c4c567f@v12g2000vbh.googlegroups.com> <20101119111434.GF31233@xrgtn-q40> <201011191303.14984.wolfgang@rohdewald.de> Message-ID: <20101119123954.GA3078@xrgtn-q40> Hello, On Fri, Nov 19, 2010 at 01:03:14PM +0100, Wolfgang Rohdewald wrote: > On Freitag 19 November 2010, Alexander Gattin wrote: > > It's better to select count(1) instead of > > count(*). not true, > > The latter may skip rows consisting > > entirely of NULLs IIRC. not true either. I've heard that count(1) is preferred to count(*) but forgot why. Your post reveals the truth about my belief: > in some data bases count(1) is said to be faster > than count(*), I believe And as it turns out this isn't true anymore on modern databases (count(1) and count(*) behave exactly the same). And quite surprisingly, on old ones count(*) was faster than count(1): > 'Oracle Performance Tuning', second edition, > O'Reilly & Associates, Inc, page 175. It says: > > "Contrary to popular belief COUNT(*) is faster > than COUNT(1). If the rows are returned via an > index, counting the indexed column - for example, > COUNT(EMP_NO) is faster still. The optimizer > realizes from the existence of the index that the > column must also exist (non-null). We tested the > following statements on several different > computers and found that COUNT(*) consistently > runs between 15% and 20% faster than COUNT(1) and > that COUNT(INDEXED_COLUMN) is 5% faster again." // http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1156151916789 P.S. sorry for starting this discussion. -- With best regards, xrgtn From eric.frederich at gmail.com Fri Nov 19 07:42:20 2010 From: eric.frederich at gmail.com (Eric Frederich) Date: Fri, 19 Nov 2010 07:42:20 -0500 Subject: Extension on Windows In-Reply-To: References: Message-ID: On Fri, Nov 19, 2010 at 7:28 AM, Ulrich Eckhardt wrote: >> Now when I created a 2nd function to wrap a library function I get the >> following. >> >> ImportError: DLL load failed: The specified module could not be found. > > This can mean that the module itself couldn't be loaded or that one of the > DLLs it depends on couldn't be found. Use dependencywalker to check. What do I do when I find these dependencies? Do I put them in some environment variable? Do I put them in site-packages along with the .pyd file, or in some other directory? From cournape at gmail.com Fri Nov 19 07:43:44 2010 From: cournape at gmail.com (David Cournapeau) Date: Fri, 19 Nov 2010 21:43:44 +0900 Subject: Changing the EAX register with Python In-Reply-To: References: Message-ID: On Fri, Nov 19, 2010 at 4:17 PM, Tim Roberts wrote: > dutche wrote: >> >>Hi folks, I have a unusual question here. >> >>How can I change the value of EAX register under python under Linux?? >>As paimei does under Windows. >> >>My project is to have a python program that loads a C program and sets >>a breakpoint at some address, and then with this breakpoint I change >>the EAX register and then continue the program execution. >> >>With Windows and paimei I did that, but under Linux I don't know yet. > > You will need to find a Linux application equivalent to PaiMei. ?Your > question is not "how can I change EAX", your question is "where can I find > a Linux debugger that can be controlled from Python?" Well, gdb may just be the tool you are looking for: since version 7.0 at least, you can script gdb using python, http://sourceware.org/gdb/wiki/PythonGdb cheers, David From grigory.v.p at gmail.com Fri Nov 19 07:57:03 2010 From: grigory.v.p at gmail.com (Grigory Petrov) Date: Fri, 19 Nov 2010 15:57:03 +0300 Subject: =?windows-1252?Q?Re=3A_How_to_correctly_pass_=93pointer=2Dto=2Dpointer=94_i?= =?windows-1252?Q?nto_DLL_via_ctypes=3F?= In-Reply-To: References: Message-ID: Thank you a lot! I have stripped down my production code to the sample - and it worked. Bug was in another part of my code where free() was called for the memory in question. On Fri, Nov 19, 2010 at 3:39 PM, Diez B. Roggisch wrote: > Grigory Petrov writes: > >> Hello. >> >> I have a DLL that allocates memory and returns it. Function in DLL is like this: >> >> void Foo( unsigned char** ppMem, int* pSize ) >> { >> ? * pSize = 4; >> ? * ppMem = malloc( * pSize ); >> ? for( int i = 0; i < * pSize; i ++ ) (* pMem)[ i ] = i; >> } >> >> Also, i have a python code that access this function from my DLL: >> >> from ctypes import * >> Foo = windll.mydll.Foo >> Foo.argtypes = [ POINTER( POINTER( c_ubyte ) ), POINTER( c_int ) ] >> mem = POINTER( c_ubyte )() >> size = c_int( 0 ) >> Foo( byref( mem ), byref( size ) ] >> print size, mem[ 0 ], mem[ 1 ], mem[ 2 ], mem[ 3 ] >> >> I'm expecting that?print?will show "4 0 1 2 3" but it shows "4 221 221 >> 221 221" O_O. Any hints what i'm doing wrong? > > After correcting quite a few obvious errors in your code, it worked just > fine for me. So I guess what you think you test is not what you test. > > --- test.py > from ctypes import * > > foo = cdll.LoadLibrary("/Users/deets/projects/GH28/kinect/kinect/c/foo/libtest.dylib").foo > foo.argtypes = [ POINTER( POINTER( c_ubyte ) ), POINTER( c_int ) ] > mem = POINTER( c_ubyte )() > size = c_int( 0 ) > foo( byref( mem ), byref( size ) ) > print size, mem[ 0 ], mem[ 1 ], mem[ 2 ], mem[ 3 ] > --- > > --- test.c > void foo( unsigned char** ppMem, int* pSize ) > { > ?int i; > ?* pSize = 4; > ?* ppMem = malloc( * pSize ); > ?for( i = 0; i < * pSize; i ++ ) (* ppMem)[ i ] = i; > } > --- > > --- CMakeLists.txt > cmake_minimum_required (VERSION 2.6) > project (Test) > add_library(test SHARED test.c) > --- > > -- > Diez > -- > http://mail.python.org/mailman/listinfo/python-list > From dutche at gmail.com Fri Nov 19 08:08:37 2010 From: dutche at gmail.com (dutche) Date: Fri, 19 Nov 2010 05:08:37 -0800 (PST) Subject: Changing the EAX register with Python References: Message-ID: <2b1e6b5d-b8da-4892-8d47-60751540cfb2@a12g2000vbc.googlegroups.com> Well, I think using ptrace is really the best way, at least what I have found on Google told me that. Stefan, your answer will fit perfectlly for me, it was what I'm searching. Thank you On Nov 19, 10:43?am, David Cournapeau wrote: > On Fri, Nov 19, 2010 at 4:17 PM, Tim Roberts wrote: > > dutche wrote: > > >>Hi folks, I have a unusual question here. > > >>How can I change the value of EAX register under python under Linux?? > >>As paimei does under Windows. > > >>My project is to have a python program that loads a C program and sets > >>a breakpoint at some address, and then with this breakpoint I change > >>the EAX register and then continue the program execution. > > >>With Windows and paimei I did that, but under Linux I don't know yet. > > > You will need to find a Linux application equivalent to PaiMei. ?Your > > question is not "how can I change EAX", your question is "where can I find > > a Linux debugger that can be controlled from Python?" > > Well, gdb may just be the tool you are looking for: since version 7.0 > at least, you can script gdb using python, > > http://sourceware.org/gdb/wiki/PythonGdb > > cheers, > > David From ulrich.eckhardt at dominolaser.com Fri Nov 19 08:12:49 2010 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Fri, 19 Nov 2010 14:12:49 +0100 Subject: Extension on Windows References: Message-ID: Eric Frederich wrote: > Do I put them [DLL dependencies] in some environment variable? > Do I put them in site-packages along with the .pyd file, or in some > other directory? Take a look at the LoadLibrary() docs: http://msdn.microsoft.com/en-us/library/ms684175(VS.85).aspx These further lead on to: http://msdn.microsoft.com/en-us/library/ms682586(v=VS.85).aspx which details in what order different places are searched for DLLs. If you put the DLL in the same directory as your PYD, it should work. This is not the most elegant solution though, see above for more info. Cheers! Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From martin at address-in-sig.invalid Fri Nov 19 09:22:32 2010 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Fri, 19 Nov 2010 14:22:32 +0000 (UTC) Subject: Program, Application, and Software References: <87hbffa30d.fsf@benfinney.id.au> <4ce5bfa9$0$29966$c3e8da3$5496439d@news.astraweb.com> <4CE5C441.1020209@mrabarnett.plus.com> Message-ID: On Fri, 19 Nov 2010 01:43:28 +0100, Alexander Kapps wrote: > What difference does it make? Is 'print "Hello"' a program or a script? > Are you saying, that it depends on whether you have to manually call > some compiler? Thats the way the term 'script' is usually used in the UNIX/Linux world. In that environment you'd call awk and Perl scripting languages but C and Java are known as compiled languages. The size of the source isn't relevant: if you can mark a source file as executable and simply run it its a 'script' while if it needs a separate preparatory step to generate a separate executable its just a source file for a compiled language. The distinction doesn't seem to be used in a Windows environment. Indeed, it doesn't make sense there since executables are limited to .BAR or .CMD files, which are directly interpreted by the command processor, and .EXE or .COM files, which must be compiled before they can be run. AFAIK there's no way you can mark anything else, such as an awk, Perl or Python source file, as executable since there is no 'executable' attribute in any Windows filing system. -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From pruebauno at latinmail.com Fri Nov 19 09:25:12 2010 From: pruebauno at latinmail.com (nn) Date: Fri, 19 Nov 2010 06:25:12 -0800 (PST) Subject: Bunch 2.0 - a dict with a default References: <58298828-d882-45f8-a396-b8f164d49570@g7g2000vbl.googlegroups.com> Message-ID: <26dfa5db-de55-46fd-95d9-5cc3f5ea6b94@d20g2000yqg.googlegroups.com> On Nov 18, 8:45?pm, Phlip wrote: > Pythonistas: > > If everyone likes this post, then the code is a "snippet" for > community edification. Otherwise, it's a question: How to do this kind > of thing better? > > I want a dict() variant that passes these test cases: > > ? ? ? ? map = Map() > ? ? ? ? assert not(map.has_key('_default')) > > ? ? ? ? map = Map(yo='dude') > ? ? ? ? assert map['yo'] == 'dude' > ? ? ? ? assert map.yo == 'dude' > ? ? ? ? assert None == map['whatever'] > ? ? ? ? assert not(map.has_key('_default')) > > ? ? ? ? map = Map(yo='dude', _default='q') > ? ? ? ? assert 'q' == map['whatever'] > ? ? ? ? assert not(map.has_key('_default')) > > That's like Bunch, but with a default value. (That makes code with > excess if statements less likely.) > > So here's the implementation: > > def Map(*args, **kwargs): > ? ? value = kwargs.get('_default', None) > ? ? if kwargs.has_key('_default'): ?del kwargs['_default'] > > ? ? class _DefMap(dict): > ? ? ? ? def __init__(self, *a, **kw): > ? ? ? ? ? ? dict.__init__(self, *a, **kw) > ? ? ? ? ? ? self.__dict__ = self > > ? ? ? ? def __getitem__(self, key): > ? ? ? ? ? ? if not self.has_key(key): ?self[key] = value > ? ? ? ? ? ? return dict.__getitem__(self, key) > > ? ? return _DefMap(*args, **kwargs) > > -- > ? Phlip > ?http://bit.ly/ZeekLand Looks like some combination of defaultdict and namedtuple. From vlastimil.brom at gmail.com Fri Nov 19 09:49:21 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Fri, 19 Nov 2010 15:49:21 +0100 Subject: regenerating unicodedata for py2.7 using py3 makeunicodedata.py? In-Reply-To: <4CE56653.8020201@v.loewis.de> References: <4CE56653.8020201@v.loewis.de> Message-ID: 2010/11/18 Martin v. Loewis : > >> Thanks for the confirmation Martin! >> >> Do you think, it the mentioned omission of the character names of some >> CJK ranges in unicodedata intended, or should it be reported to the >> tracker? > > It's certainly a bug. So a bug report would be appreciated, but much > more so a patch. Ideally, the patch would either be completely > forward-compatible (should the CJK ranges change in future Unicode > versions), > or at least have a safe-guard to detect that the data file is getting > out of sync with the C implementation. > > Regards, > Martin > Thanks, I just created a bug ticket: http://bugs.python.org/issue10459 The omissions of character names seem to be: ? (0x9fbc) - ? (0x9fcb) (CJK Unified Ideographs [19968-40959] [0x4e00-0x9fff]) ? (0x2a700) - ? (0x2b734) (CJK Unified Ideographs Extension C [173824-177983] [0x2a700-0x2b73f]) ? (0x2b740) - ? (0x2b81d) (CJK Unified Ideographs Extension D [177984-178207] [0x2b740-0x2b81f]) (Also the unprintable ASCII controls, Surrogates and Private use area, where the missing names are probably ok.) Unfortunately, I am not able to provide a patch, mainly because of unicodadate being C code. A while ago I considered writing some unicodedata enhancements in python, which would support the ranges and script names, full category names etc., but sofar the direct programatic lookups in the online unicode docs and with some simple processing also do work sufficiently... Regards, Vlastimil Brom From noydb00 at gmail.com Fri Nov 19 09:52:01 2010 From: noydb00 at gmail.com (noydb) Date: Fri, 19 Nov 2010 06:52:01 -0800 (PST) Subject: How to run an EXE, with argument, capture output value References: <37037d15-63da-4f37-9508-bdcfff034670@s4g2000yql.googlegroups.com> <70d6c9a7-8ba9-420d-822a-0ba71888e4f4@v20g2000yqb.googlegroups.com> <71e489bd-429d-4814-9a0c-6b5f875b3780@30g2000yql.googlegroups.com> <850908d0-26d4-45a5-86bc-855445fde0bf@a37g2000yqi.googlegroups.com> <0594c8c1-e13c-4057-9ff5-783ad97fd0a2@l17g2000yqe.googlegroups.com> Message-ID: <47c956e0-8739-4f30-aa63-8ca5b9549afa@s5g2000yqm.googlegroups.com> Any other help? I am guessing not, just wanted to try one more time. Could really use help, please!! From eric.frederich at gmail.com Fri Nov 19 10:15:53 2010 From: eric.frederich at gmail.com (Eric Frederich) Date: Fri, 19 Nov 2010 10:15:53 -0500 Subject: Extension on Windows In-Reply-To: References: Message-ID: On Fri, Nov 19, 2010 at 8:12 AM, Ulrich Eckhardt wrote: > Eric Frederich wrote: >> Do I put them [DLL dependencies] in some environment variable? >> Do I put them in site-packages along with the .pyd file, or in some >> other directory? > > Take a look at the LoadLibrary() docs: > ?http://msdn.microsoft.com/en-us/library/ms684175(VS.85).aspx > > These further lead on to: > ?http://msdn.microsoft.com/en-us/library/ms682586(v=VS.85).aspx > which details in what order different places are searched for DLLs. > > If you put the DLL in the same directory as your PYD, it should work. This > is not the most elegant solution though, see above for more info. > Well... I used the tool and found missing dependencies and just copied them into site-packages. There were two. Then when I put those two in there and ran dependencywalker again, I had 6 more missing. I found all of these dependencies in a "bin" directory of the program which I'm trying to create bindings for. The one I couldn't find was MSVCR80.DLL but my python module imported fine so maybe its not a big deal (actually, if I throw one of their dll files into dependency walker it shows the same thing). This was just with me wrapping one (very basic) routine. I would imagine as I wrap more and more, I'd need more and more dll files. I think rather than copying .dll files around, I'll just put my .pyd file in their 'bin' directory and set PYTHONPATH environment variable. Things are starting to look promising. I now have to deal with other issues (coming up in a new python-list thread). Thanks a bunch Ulri. From dimos_anastasiou at yahoo.com Fri Nov 19 10:21:32 2010 From: dimos_anastasiou at yahoo.com (Dimos) Date: Fri, 19 Nov 2010 07:21:32 -0800 (PST) Subject: Weibull distr. random number generation Message-ID: <614418.61927.qm@web111714.mail.gq1.yahoo.com> Dear Python list subscribers, Sorry of this has been covered already...This is a newbie question about actual scripting/syntax. I would like to use the random module, and if I understand well the Random class, to create 1300 decimal numbers in python, by providing the 2 Weibull parameters (b,c). How this can be done??? import random print random random.weibullvariate(b,c) How can I set the population size n=1300 in decimals? Best, Dimos From josef.frank at gmx.li Fri Nov 19 10:29:12 2010 From: josef.frank at gmx.li (Josef Frank) Date: Fri, 19 Nov 2010 16:29:12 +0100 Subject: Program, Application, and Software In-Reply-To: References: <87hbffa30d.fsf@benfinney.id.au> <4ce5bfa9$0$29966$c3e8da3$5496439d@news.astraweb.com> <4CE5C441.1020209@mrabarnett.plus.com> Message-ID: Am 19.11.2010 15:22, schrieb Martin Gregorie: > On Fri, 19 Nov 2010 01:43:28 +0100, Alexander Kapps wrote: > >> What difference does it make? Is 'print "Hello"' a program or a script? >> Are you saying, that it depends on whether you have to manually call >> some compiler? > > Thats the way the term 'script' is usually used in the UNIX/Linux world. > > In that environment you'd call awk and Perl scripting languages but C and > Java are known as compiled languages. The size of the source isn't > relevant: if you can mark a source file as executable and simply run it > its a 'script' while if it needs a separate preparatory step to generate > a separate executable its just a source file for a compiled language. > > The distinction doesn't seem to be used in a Windows environment. Indeed, > it doesn't make sense there since executables are limited to .BAR or .CMD > files, which are directly interpreted by the command processor, and .EXE > or .COM files, which must be compiled before they can be run. AFAIK > there's no way you can mark anything else, such as an awk, Perl or Python > source file, as executable since there is no 'executable' attribute in > any Windows filing system. > Not in the file system, but in the environment it is definitely possible. One might try http://www.google.de/search?q=pathext or just have a look at http://wiki.tcl.tk/1785 (the respective filetype has to be associated with it's interpreter however for this method to work.) Josef From rbotting at csusb.edu Fri Nov 19 10:29:59 2010 From: rbotting at csusb.edu (RJB) Date: Fri, 19 Nov 2010 07:29:59 -0800 (PST) Subject: what's the precision of fractions.Fraction? References: <4ce5fc73$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: Does Fractions remove common factors the way it should? If it does and you want to find the closest fraction with a smaller denominator i think tou'll need some number theory and continued fractions. RJB On Nov 18, 8:26?pm, Steven D'Aprano wrote: > On Thu, 18 Nov 2010 20:08:00 +0100, Stefan Sonnenberg-Carstens wrote: > > If you need it really *precise*, cast your Fractions into type Decimal: > > It's actually the opposite. Decimal has many advantages, but being > "really precise" is not one of them. It suffers the exact same issues re > precision and round-off as binary floating point. > > It is easy to demonstrate that there are numbers which cannot be > represented precisely as Decimals no matter how many decimal places you > use, but can be represented exactly as Fractions. Fraction can exactly > represent every Decimal, but Decimal cannot represent exactly every > Fraction. > > We're not talking about weird edge cases either, but simple numbers that > you're likely to come across every day: > > >>> from decimal import Decimal > >>> one_ninth = Decimal(1)/Decimal(9) > >>> two_thirds = Decimal(2)/Decimal(3) > >>> one_ninth*6 == two_thirds > > False > > >>> from fractions import Fraction > >>> one_ninth = Fraction(1, 9) > >>> two_thirds = Fraction(2, 3) > >>> one_ninth*6 == two_thirds > > True > > Still not convinced? > > >>> f = Fraction(1) + Fraction(1, 10**100000) > >>> f != 1 > > True > > (which is virtually instantaneous, by the way) > > compared to the *much* slower: > > >>> d = Decimal(1) + Decimal(1)/Decimal(10**100000) > >>> d != 1 > > False > > Yes, I could try to set the Decimal context to 100,000 decimal places -- > and just as easily defeat it again by adding one more to the exponent. > > In my opinion, the Fraction module is one of the least appreciated and > underused modules in the standard library -- and I include myself in > that. It really is a joy, and I don't use it anywhere near enough. > > -- > Steven From robert.kern at gmail.com Fri Nov 19 10:42:50 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 19 Nov 2010 09:42:50 -0600 Subject: Changing the EAX register with Python In-Reply-To: <2b1e6b5d-b8da-4892-8d47-60751540cfb2@a12g2000vbc.googlegroups.com> References: <2b1e6b5d-b8da-4892-8d47-60751540cfb2@a12g2000vbc.googlegroups.com> Message-ID: On 11/19/10 7:08 AM, dutche wrote: > Well, I think using ptrace is really the best way, at least what I > have found on Google told me that. You may also want to look into pinktrace for another wrapper around ptrace. I haven't used it myself, but it's worth looking into. http://dev.exherbo.org/~alip/pinktrace/ -- 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 pecora at anvil.nrl.navy.mil Fri Nov 19 10:55:28 2010 From: pecora at anvil.nrl.navy.mil (Lou Pecora) Date: Fri, 19 Nov 2010 10:55:28 -0500 Subject: What was your strategy? References: <201011142240.oAEMecu2054270@krusty.intranet.com.mx> <7xr5ei1p2j.fsf@ruckus.brouhaha.com> Message-ID: In article <7xr5ei1p2j.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > Lou Pecora writes: > >> > I'll jump in and recommend the book "Python in a Nutshell" by Martelli. > >> It's encyclopedic. > > Indeed. I hope Martelli updates it. I'd buy another copy right away. > > It's a great book but not a starting point for beginners. It's > definitely worth having for more advanced users. I would beg to differ. I used it from the start of my Python learning curve and was greatly helped by it. For me it gave explanations at just the right level with paths to more detail if you wanted. I found it helpful from the beginning. I would recommended others to at least look at it. You might be helped right away and it's a good addition to any Python programmer's library. -- -- Lou Pecora From eric.frederich at gmail.com Fri Nov 19 11:05:10 2010 From: eric.frederich at gmail.com (Eric Frederich) Date: Fri, 19 Nov 2010 11:05:10 -0500 Subject: Round Trip: C to Python to C Module Message-ID: I have a proprietary software PropSoft that I need to extend. They support extensions written in C that can link against PropLib to interact with the system. I have a Python C module that wraps a couple PropLib functions that I call PyProp. >From an interactive Python shell I can import PyProp and call a function. None of these functions really do anything outside the context of being logged into the PropSoft software; so all the functions fail when running from Python alone. To my amazement, I was able to run PyRun_SimpleString("import PyProp\nPyProp.some_function()") without setting PYTHONPATH or anything. How this works, I don't know and I don't really care (at the moment anyway). The problem I'm having now is how do I return things from my Python script back to C? Ultimately I won't be hard coding python inside of PyRun_SimpleString but loading the script from a file. So, how do I return values back to C? Python functions return values but running a python script?... doesn't that just have an exit status? Is there a mechanism for doing this? Thanks in advance, ~Eric From invalid at invalid.invalid Fri Nov 19 11:32:21 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 19 Nov 2010 16:32:21 +0000 (UTC) Subject: Changing the EAX register with Python References: Message-ID: On 2010-11-19, Tim Roberts wrote: > dutche wrote: >> My project is to have a python program that loads a C program and >> sets a breakpoint at some address, and then with this breakpoint I >> change the EAX register and then continue the program execution. > You will need to find a Linux application equivalent to PaiMei. Your > question is not "how can I change EAX", your question is "where can I > find a Linux debugger that can be controlled from Python?" > > I don't know the answer to that. gdb is quite powerful, and you can > certainly control it by connecting to its stdin and stdout > connections. If you're going to do that, you want to run gdb in "machine interface" mode, which makes it a lot easier to talk to programatically. I've not done it in Python, but it's easy enough in C, so in Python it ought to be trivial: http://sourceware.org/gdb/current/onlinedocs/gdb/GDB_002fMI.html#GDB_002fMI If you don't want to write code to talk the gdb/mi "command language", then another option is to use a library like libmigdb: http://sourceforge.net/projects/libmigdb/ You can probably call the library functions using cytpes: http://docs.python.org/library/ctypes.html -- Grant Edwards grant.b.edwards Yow! Psychoanalysis?? at I thought this was a nude gmail.com rap session!!! From steve at holdenweb.com Fri Nov 19 11:46:32 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 19 Nov 2010 11:46:32 -0500 Subject: What was your strategy? In-Reply-To: References: <201011142240.oAEMecu2054270@krusty.intranet.com.mx> <7xr5ei1p2j.fsf@ruckus.brouhaha.com> Message-ID: On 11/19/2010 10:55 AM, Lou Pecora wrote: > In article <7xr5ei1p2j.fsf at ruckus.brouhaha.com>, > Paul Rubin wrote: > >> Lou Pecora writes: >>>>> I'll jump in and recommend the book "Python in a Nutshell" by Martelli. >>>> It's encyclopedic. >>> Indeed. I hope Martelli updates it. I'd buy another copy right away. >> >> It's a great book but not a starting point for beginners. It's >> definitely worth having for more advanced users. > > I would beg to differ. I used it from the start of my Python learning > curve and was greatly helped by it. For me it gave explanations at just > the right level with paths to more detail if you wanted. I found it > helpful from the beginning. I would recommended others to at least look > at it. You might be helped right away and it's a good addition to any > Python programmer's library. > I'd say "Nushell" is a great book for experienced programmers, whether in Python or other languages. It's definitely not something I would recommend for a programming noob. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From malaclypse2 at gmail.com Fri Nov 19 11:52:21 2010 From: malaclypse2 at gmail.com (Jerry Hill) Date: Fri, 19 Nov 2010 11:52:21 -0500 Subject: How to run an EXE, with argument, capture output value In-Reply-To: <47c956e0-8739-4f30-aa63-8ca5b9549afa@s5g2000yqm.googlegroups.com> References: <37037d15-63da-4f37-9508-bdcfff034670@s4g2000yql.googlegroups.com> <70d6c9a7-8ba9-420d-822a-0ba71888e4f4@v20g2000yqb.googlegroups.com> <71e489bd-429d-4814-9a0c-6b5f875b3780@30g2000yql.googlegroups.com> <850908d0-26d4-45a5-86bc-855445fde0bf@a37g2000yqi.googlegroups.com> <0594c8c1-e13c-4057-9ff5-783ad97fd0a2@l17g2000yqe.googlegroups.com> <47c956e0-8739-4f30-aa63-8ca5b9549afa@s5g2000yqm.googlegroups.com> Message-ID: On Fri, Nov 19, 2010 at 9:52 AM, noydb wrote: > Any other help? ?I am guessing not, just wanted to try one more time. > Could really use help, please!! You'll need to give us more information about the program you're trying to automate. It originally sounded like you just needed to run a console program, where it's usually fairly easy to run and capture the output with the subprocess module. Now it sounds like you're trying to automate a GUI that requires user interaction. That's quite a bit more complicated. When you run "stats_hall.exe", what do you get on the screen? What, exactly, are the steps a normal user would need to perform to do what you want to automate? After the values you're interested in are computed, where do they show up? Is this program publically available someplace? I've generally had good luck doing simple GUI automation with pywinauto. The homepage appears to be: http://pywinauto.pbworks.com which has installation instructions and a FAQ. You might also find this demo useful: http://showmedo.com/videotutorials/video?name=UsingpyWinAutoToControlAWindowsApplication -- Jerry From steve at holdenweb.com Fri Nov 19 11:53:01 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 19 Nov 2010 11:53:01 -0500 Subject: Program, Application, and Software In-Reply-To: References: <87hbffa30d.fsf@benfinney.id.au> <4ce5bfa9$0$29966$c3e8da3$5496439d@news.astraweb.com> <4CE5C441.1020209@mrabarnett.plus.com> Message-ID: On 11/19/2010 9:22 AM, Martin Gregorie wrote: [...] > Indeed, > it doesn't make sense there since executables are limited to .BAR or .CMD > files, which are directly interpreted by the command processor, and .EXE > or .COM files, which must be compiled before they can be run. AFAIK > there's no way you can mark anything else, such as an awk, Perl or Python > source file, as executable since there is no 'executable' attribute in > any Windows filing system. Under Windows you use the PATHEXT mechanism to mark an extension as executable. Then finding a file with that extension on the PATH will trigger it to be run by the registered interpreter. As far as I know, anyway. By default on my Vista system I see PATHEXT contains C:\Users\sholden\workspace\Python3_Lesson3\src>echo %PATHEXT% .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From dfnsonfsduifb at gmx.de Fri Nov 19 12:17:43 2010 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Fri, 19 Nov 2010 18:17:43 +0100 Subject: Modifying Element In For List In-Reply-To: References: <01e04b27-c523-40b7-b9cb-8288823de8fa@p11g2000vbn.googlegroups.com> Message-ID: <8knpmqFda9U1@mid.dfncis.de> Am 15.11.2010 18:27, schrieb Duncan Booth: > Comparing directly against True or False is error prone: a value in > Python can be false without actually being equal to False. Well, you can always use "is" instead of "==", which makes a comparison to True or False perfectly safe. 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 steve at holdenweb.com Fri Nov 19 12:31:47 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 19 Nov 2010 12:31:47 -0500 Subject: Modifying Element In For List In-Reply-To: <8knpmqFda9U1@mid.dfncis.de> References: <01e04b27-c523-40b7-b9cb-8288823de8fa@p11g2000vbn.googlegroups.com> <8knpmqFda9U1@mid.dfncis.de> Message-ID: On 11/19/2010 12:17 PM, Johannes Bauer wrote: > Am 15.11.2010 18:27, schrieb Duncan Booth: > >> Comparing directly against True or False is error prone: a value in >> Python can be false without actually being equal to False. > > Well, you can always use "is" instead of "==", which makes a comparison > to True or False perfectly safe. > But it's still the wrong thing to do. if condition==True: and if condition is True: should both be replaced (under most circumstances) by if condition: regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From ppearson at nowhere.invalid Fri Nov 19 13:20:47 2010 From: ppearson at nowhere.invalid (Peter Pearson) Date: 19 Nov 2010 18:20:47 GMT Subject: what's the precision of fractions.Fraction? References: <4ce5fc73$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8kntfvFr8aU1@mid.individual.net> On Fri, 19 Nov 2010 07:29:59 -0800 (PST), RJB wrote: > Does Fractions remove common factors the way it should? > > If it does and you want to find the closest fraction with a smaller > denominator i think tou'll need some number theory and continued > fractions. No heroics required, finding the greatest common divisor is fast. And if this simple test is indicative, the fractions module reduces: >>> x = fractions.Fraction( 2**100, 3 ) >>> y = fractions.Fraction( 7, 2**101 ) >>> z = x * y >>> print x._numerator, x._denominator 1267650600228229401496703205376 3 >>> print y._numerator, y._denominator 7 2535301200456458802993406410752 >>> print z._numerator, z._denominator 7 6 -- To email me, substitute nowhere->spamcop, invalid->net. From usernet at ilthio.net Fri Nov 19 13:27:23 2010 From: usernet at ilthio.net (Tim Harig) Date: Fri, 19 Nov 2010 18:27:23 +0000 (UTC) Subject: How to run an EXE, with argument, capture output value References: <37037d15-63da-4f37-9508-bdcfff034670@s4g2000yql.googlegroups.com> Message-ID: C:\Documents and Settings\Tim Harig\My Documents\autoCalc>dir Volume in drive C has no label. Volume Serial Number is 30D9-35E0 Directory of C:\Documents and Settings\Tim Harig\My Documents\autoCalc 11/19/2010 12:20 PM

. 11/19/2010 12:20 PM .. 11/19/2010 12:19 PM 686 autoCalc.pys 1 File(s) 686 bytes 2 Dir(s) 16,343,552,000 bytes free C:\Documents and Settings\Tim Harig\My Documents\autoCalc>type autoCalc.pys # autoCalc.pys: The "pys" extension indicates that it should be run under # Windows Script Host # perform the calculation using Windows calculator keySequence = ['2', '{+}', '2', '=', '^c', '%{F4}'] WshShell = WScript.CreateObject("WScript.Shell") calculator = WshShell.Run("calc") WshShell.AppActivate("calc") WScript.Sleep(1000) for currentKey in keySequence: WshShell.SendKeys(currentKey) WScript.Sleep(100) # write the results to notepad and same as demo.txt keySequence = ['result: ', '^v', '^s', 'c:\\Documents and Settings\\Tim Harig\\My Documents\\autoCalc\\demo.txt', '~', '%{F4}'] notepad = WshShell.Run("notepad") WshShell.AppActivate("notepad") WScript.Sleep(1000) for currentKey in keySequence: WshShell.SendKeys(currentKey) WScript.Sleep(100) C:\Documents and Settings\Tim Harig\My Documents\autoCalc>cscript.exe autoCalc.pys Microsoft (R) Windows Script Host Version 5.7 Copyright (C) Microsoft Corporation. All rights reserved. Debugging extensions (axdebug) module does not exist - debugging is disabled.. C:\Documents and Settings\Tim Harig\My Documents\autoCalc>type demo.txt result: 4 C:\Documents and Settings\Tim Harig\My Documents\autoCalc> From deets at web.de Fri Nov 19 14:25:49 2010 From: deets at web.de (Diez B. Roggisch) Date: Fri, 19 Nov 2010 20:25:49 +0100 Subject: Round Trip: C to Python to C Module References: Message-ID: Eric Frederich writes: > I have a proprietary software PropSoft that I need to extend. > They support extensions written in C that can link against PropLib to > interact with the system. > > I have a Python C module that wraps a couple PropLib functions that I > call PyProp. >>From an interactive Python shell I can import PyProp and call a function. > None of these functions really do anything outside the context of > being logged into the PropSoft software; so all the functions fail > when running from Python alone. > > To my amazement, I was able to run PyRun_SimpleString("import > PyProp\nPyProp.some_function()") without setting PYTHONPATH or > anything. How this works, I don't know and I don't really care (at > the moment anyway). > > The problem I'm having now is how do I return things from my Python > script back to C? > Ultimately I won't be hard coding python inside of PyRun_SimpleString > but loading the script from a file. > So, how do I return values back to C? Python functions return values > but running a python script?... doesn't that just have an exit status? > Is there a mechanism for doing this? You write an extension in C that embeds a Python-interpreter. That interpreter then loads your script, and executes it. Let's say the PropSoft offers you three functions for a custom extension. void init(); int do_something(int); void cleanup(); Then you write a C-extension that contains these three function calls, and in init, you create a Python-interpreter and load your script. It should offer a "do_something_in_python" method that takes an int and returns one. In do_something, you invoke the aforementioned do_something_in_python function through the Python C-API as described. In cleanup, you do what the function name says. Possibly the use of elmer[1] makes the whole process easier. [1]: http://wiki.python.org/moin/elmer -- Diez From nulla.epistola at web.de Fri Nov 19 14:58:17 2010 From: nulla.epistola at web.de (Sibylle Koczian) Date: Fri, 19 Nov 2010 20:58:17 +0100 Subject: Module locale throws exception: unsupported locale setting Message-ID: Hello, on a german Windows installation I get problems with locale. If I run that module as a script from a command window this is the output: C:\Python31\Lib>locale.py Locale aliasing: Locale defaults as determined by getdefaultlocale(): ------------------------------------------------------------------------ Language: de_DE Encoding: cp1252 Locale settings on startup: ------------------------------------------------------------------------ LC_NUMERIC ... Language: (undefined) Encoding: (undefined) LC_MONETARY ... Language: (undefined) Encoding: (undefined) LC_COLLATE ... Language: (undefined) Encoding: (undefined) LC_CTYPE ... Language: (undefined) Encoding: (undefined) LC_TIME ... Language: (undefined) Encoding: (undefined) Locale settings after calling resetlocale(): ------------------------------------------------------------------------ Traceback (most recent call last): File "C:\Python31\Lib\locale.py", line 1798, in _print_locale() File "C:\Python31\Lib\locale.py", line 1761, in _print_locale resetlocale() File "C:\Python31\Lib\locale.py", line 537, in resetlocale _setlocale(category, _build_localename(getdefaultlocale())) locale.Error: unsupported locale setting C:\Python31\Lib> This is Windows 7, 64 bit, Python 3.1.2. Same behavior on another Windows machine with Python 2.7 (Windows XP, 32 bit). On Linux, using UTF-8 as system character set and Python 2.6, 2.6.5 or 3.1.2, no problems using locale, running the module as a script gives no exception but the expected output. So I suppose it's either an OS problem or connected with the encoding. I've looked into bugs.python.org, but found only vaguely similar issues. Should I open a new one? Thank you for help, Sibylle From nad at acm.org Fri Nov 19 15:27:49 2010 From: nad at acm.org (Ned Deily) Date: Fri, 19 Nov 2010 12:27:49 -0800 Subject: Module locale throws exception: unsupported locale setting References: Message-ID: In article , Sibylle Koczian wrote: > on a german Windows installation I get problems with locale. If I run > that module as a script from a command window this is the output: > > C:\Python31\Lib>locale.py > Locale aliasing: > > Locale defaults as determined by getdefaultlocale(): > ------------------------------------------------------------------------ > Language: de_DE > Encoding: cp1252 > > Locale settings on startup: > ------------------------------------------------------------------------ > LC_NUMERIC ... > Language: (undefined) > Encoding: (undefined) > > LC_MONETARY ... > Language: (undefined) > Encoding: (undefined) > > LC_COLLATE ... > Language: (undefined) > Encoding: (undefined) > > LC_CTYPE ... > Language: (undefined) > Encoding: (undefined) > > LC_TIME ... > Language: (undefined) > Encoding: (undefined) > > > Locale settings after calling resetlocale(): > ------------------------------------------------------------------------ > Traceback (most recent call last): > File "C:\Python31\Lib\locale.py", line 1798, in > _print_locale() > File "C:\Python31\Lib\locale.py", line 1761, in _print_locale > resetlocale() > File "C:\Python31\Lib\locale.py", line 537, in resetlocale > _setlocale(category, _build_localename(getdefaultlocale())) > locale.Error: unsupported locale setting > > C:\Python31\Lib> > > This is Windows 7, 64 bit, Python 3.1.2. Same behavior on another > Windows machine with Python 2.7 (Windows XP, 32 bit). > > On Linux, using UTF-8 as system character set and Python 2.6, 2.6.5 or > 3.1.2, no problems using locale, running the module as a script gives no > exception but the expected output. So I suppose it's either an OS > problem or connected with the encoding. > > I've looked into bugs.python.org, but found only vaguely similar issues. > Should I open a new one? There have been a lot of changes going into Python 3.2, currently in alpha testing, in the areas of encodings and how they affect the interfaces to/from the various platform operating systems Python 3 runs on. It would be very useful if you could try the same test with the most recent Python 3.2 alpha (http://www.python.org/download/releases/3.2/) and, if the problem persists there, open an issue about it. -- Ned Deily, nad at acm.org From stefaan.himpe at gmail.com Fri Nov 19 20:07:35 2010 From: stefaan.himpe at gmail.com (Stefaan Himpe) Date: Sat, 20 Nov 2010 02:07:35 +0100 Subject: Distribution of Python Scripts In-Reply-To: References: Message-ID: > So, what's my options. Maybe this page can give some inspiration? http://wiki.python.org/moin/deployment From data.2 at rediff.com Fri Nov 19 20:08:06 2010 From: data.2 at rediff.com (gaurav) Date: Fri, 19 Nov 2010 17:08:06 -0800 (PST) Subject: Earn in Management careers. Message-ID: <7e19c68f-792a-482a-ac9c-7d8fe85f1eb8@a30g2000vbt.googlegroups.com> On Management careers base, Earn monthly. Supporting Management careers. http://managementjobs.webs.com/pm.htm & http://topcareer.webs.com/humanresourcemgmt.htm Offers for job seekers Opportunities for you Make your career. http://rojgars1.webs.com/gov.htm http://rojgars.webs.com/bankingjobs.htm From razamatan_retral_net_ignore_com at mustafa.retral.net Fri Nov 19 20:58:19 2010 From: razamatan_retral_net_ignore_com at mustafa.retral.net (Jin Yi) Date: Fri, 19 Nov 2010 17:58:19 -0800 Subject: dict diff Message-ID: <20101120015819.GA1254@mustafa.retral.net> so i came up with a diff method to compare 2 dicts. i found it pretty useful so i thought i'd share it with everyone. you can see the doctest to check out suggested uses. since we can't modify built-ins, i demonstrated adding a diff method to OrderedDict to show how one could add it to your own mapping objects. the core logic is compatible with python2 and 3 (i've only tested using 2.6.5 and 3.1.2). the doctest is suited for python3 though. the interface is pretty straightforward. it would be awesome to have this sucker as a method on the builtin dict, but that'd take a pep, no? -- Jin Yi -------------- next part -------------- A non-text attachment was scrubbed... Name: diffdict.py Type: text/x-python Size: 2062 bytes Desc: not available URL: From razamatan_retral_net at nospam.com Fri Nov 19 20:58:19 2010 From: razamatan_retral_net at nospam.com (Jin Yi) Date: Fri, 19 Nov 2010 17:58:19 -0800 Subject: dict diff Message-ID: <20101120015819.GA1254@mustafa.retral.net> so i came up with a diff method to compare 2 dicts. i found it pretty useful so i thought i'd share it with everyone. you can see the doctest to check out suggested uses. since we can't modify built-ins, i demonstrated adding a diff method to OrderedDict to show how one could add it to your own mapping objects. the core logic is compatible with python2 and 3 (i've only tested using 2.6.5 and 3.1.2). the doctest is suited for python3 though. the interface is pretty straightforward. it would be awesome to have this sucker as a method on the builtin dict, but that'd take a pep, no? -- Jin Yi -------------- next part -------------- A non-text attachment was scrubbed... Name: diffdict.py Type: text/x-python Size: 2062 bytes Desc: not available URL: From noydb00 at gmail.com Fri Nov 19 21:39:29 2010 From: noydb00 at gmail.com (noydb) Date: Fri, 19 Nov 2010 18:39:29 -0800 (PST) Subject: How to run an EXE, with argument, capture output value References: <37037d15-63da-4f37-9508-bdcfff034670@s4g2000yql.googlegroups.com> Message-ID: <0ae3b271-9161-4b94-b11b-0d26e68d2596@j18g2000yqd.googlegroups.com> Thanks to Jerry Hill above who helped. This worked: from pywinauto.application import Application app = Application() app.start_(r'C:\temp\hallbig2.exe') app.Form1.Edit6.TypeKeys(r'C:\temp\input\Ea39j.txt') E_Value = "" while (E_Value == ""): app.Form1.Compute.Click() E_Value = app.Form1.Edit8.WindowText() print repr(E_Value) app.Kill_() From k.sahithi2862 at gmail.com Sat Nov 20 00:30:41 2010 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Fri, 19 Nov 2010 21:30:41 -0800 (PST) Subject: ONLY FOR YOUTH Message-ID: <511902d0-5674-4d11-bffa-bacfc5cb436f@s5g2000yqm.googlegroups.com> TRISHA IN A SPICY DRESS http://youth-shilpa.blogspot.com/2010/11/trisha.html SAKSHI IN A SEXY LOOK http://youth-shilpa.blogspot.com/2010/11/sakshi.html SEXY STUNNIG BEAUTY http://youth-shilpa.blogspot.com/2010/11/beauty.html NAMITHA IN A BEACH http://youth-shilpa.blogspot.com/2010/11/namitha.html HOT LIPKISSES BOLLYWOOD http://youth-shilpa.blogspot.com/2010/11/lipkiss.html SALMA HOT BOOBS SHOW http://youth-shilpa.blogspot.com/2010/11/salma-sexy-photo.html ANJELINA JOLIE SPICY PHOTO http://youth-shilpa.blogspot.com/2010/11/anjelinajolie.html From mback1 at live.se Sat Nov 20 00:53:57 2010 From: mback1 at live.se (Mikael B) Date: Sat, 20 Nov 2010 06:53:57 +0100 Subject: try to use unicode Message-ID: Hi. I'm learning python. python 2.6.6 on ubuntu 10.10 I'm swedish so I try to use unicode to get swedish characters. I've checked wikipedia. utf-8 is said to be an unicode encoding.. this is the test program: # -*- coding: utf-8 -*- import readline s=raw_input(u'M?nadsl?n:') and this is the output: Traceback (most recent call last): File "test_uni.py", line 5, in s=raw_input(u'M?nadsl?n:') UnicodeEncodeError: 'ascii' codec can't encode character u'\xe5' in position 1: ordinal not in range(128) I'm doing something wrong... Mikael -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Sat Nov 20 01:11:53 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 20 Nov 2010 01:11:53 -0500 Subject: dict diff In-Reply-To: <20101120015819.GA1254@mustafa.retral.net> References: <20101120015819.GA1254@mustafa.retral.net> Message-ID: On 11/19/2010 8:58 PM, Jin Yi wrote: > so i came up with a diff method to compare 2 dicts. i found it pretty > useful so i thought i'd share it with everyone. you can see the doctest > to check out suggested uses. since we can't modify built-ins, i > demonstrated adding a diff method to OrderedDict to show how one could > add it to your own mapping objects. > > the core logic is compatible with python2 and 3 (i've only tested using > 2.6.5 and 3.1.2). the doctest is suited for python3 though. > > > the interface is pretty straightforward. it would be awesome to have > this sucker as a method on the builtin dict, but that'd take a pep, no? > > > A PEP *and* some explanation of why you would want such an obscure piece of code built in to the dict object, yes. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From razamatan_retral_net at nospam.com Sat Nov 20 02:15:11 2010 From: razamatan_retral_net at nospam.com (Jin Yi) Date: Fri, 19 Nov 2010 23:15:11 -0800 Subject: dict diff In-Reply-To: References: <20101120015819.GA1254@mustafa.retral.net> Message-ID: <20101120071511.GA3207@mustafa.retral.net> i don't think this piece of code is obscure. i think the use case is there when you know that dicta != dictb, but you need to know where they're different. i wouldn't really care to have it on the dict since it's useful as an unbound method anyway. On Sat, Nov 20, 2010 at 01:11:53AM -0500, Steve Holden wrote: > On 11/19/2010 8:58 PM, Jin Yi wrote: > > so i came up with a diff method to compare 2 dicts. i found it pretty > > useful so i thought i'd share it with everyone. you can see the doctest > > to check out suggested uses. since we can't modify built-ins, i > > demonstrated adding a diff method to OrderedDict to show how one could > > add it to your own mapping objects. > > > > the core logic is compatible with python2 and 3 (i've only tested using > > 2.6.5 and 3.1.2). the doctest is suited for python3 though. > > > > > > the interface is pretty straightforward. it would be awesome to have > > this sucker as a method on the builtin dict, but that'd take a pep, no? > > > > > > > A PEP *and* some explanation of why you would want such an obscure piece > of code built in to the dict object, yes. > > regards > Steve > -- > Steve Holden +1 571 484 6266 +1 800 494 3119 > PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ > See Python Video! http://python.mirocommunity.org/ > Holden Web LLC http://www.holdenweb.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list From stefan.sonnenberg at pythonmeister.com Sat Nov 20 02:47:18 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Sat, 20 Nov 2010 08:47:18 +0100 Subject: try to use unicode In-Reply-To: References: Message-ID: <4CE77D06.1080108@pythonmeister.com> Am 20.11.2010 06:53, schrieb Mikael B: > Hi. > > I'm learning python. python 2.6.6 on ubuntu 10.10 I'm swedish so I try > to use > unicode to get swedish characters. I've checked wikipedia. > utf-8 is said to be an unicode encoding.. > > this is the test program: > > # -*- coding: utf-8 -*- > > import readline > > s=raw_input(u'M?nadsl?n:') > > and this is the output: > > Traceback (most recent call last): > File "test_uni.py", line 5, in > s=raw_input(u'M?nadsl?n:') > UnicodeEncodeError: 'ascii' codec can't encode character u'\xe5' in > position 1: ordinal not in range(128) > > I'm doing something wrong... > > Mikael > Your console is not unicode ready. Please take a look at the locale command and vars like LC_ALL, LC_LANG etc. -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: stefan_sonnenberg.vcf Type: text/x-vcard Size: 223 bytes Desc: not available URL: From mback1 at live.se Sat Nov 20 02:49:59 2010 From: mback1 at live.se (Mikael B) Date: Sat, 20 Nov 2010 08:49:59 +0100 Subject: try to use unicode In-Reply-To: <4CE77D06.1080108@pythonmeister.com> References: , <4CE77D06.1080108@pythonmeister.com> Message-ID: Date: Sat, 20 Nov 2010 08:47:18 +0100 From: stefan.sonnenberg at pythonmeister.com To: mback1 at live.se CC: python-list at python.org Subject: Re: try to use unicode Meddelandetext Am 20.11.2010 06:53, schrieb Mikael B: Hi. I'm learning python. python 2.6.6 on ubuntu 10.10 I'm swedish so I try to use unicode to get swedish characters. I've checked wikipedia. utf-8 is said to be an unicode encoding.. this is the test program: # -*- coding: utf-8 -*- import readline s=raw_input(u'M?nadsl?n:') and this is the output: Traceback (most recent call last): File "test_uni.py", line 5, in s=raw_input(u'M?nadsl?n:') UnicodeEncodeError: 'ascii' codec can't encode character u'\xe5' in position 1: ordinal not in range(128) I'm doing something wrong... Mikael Your console is not unicode ready. Please take a look at the locale command and vars like LC_ALL, LC_LANG etc. Aha... Ok,thank you -------------- next part -------------- An HTML attachment was scrubbed... URL: From maxim.mercury at gmail.com Sat Nov 20 03:28:08 2010 From: maxim.mercury at gmail.com (Maxim Mercury) Date: Sat, 20 Nov 2010 00:28:08 -0800 (PST) Subject: constructin trees in python Message-ID: <3c926050-5e27-4efb-bf76-dbd1f2412810@o14g2000yqe.googlegroups.com> Hi , Iam very much new to python. Iam trying to construct a xml dom tree using the builtin HTMLParser class (on data event callbacks). Iam maintaining the childs as a list of elements and whenver the sax parser encounters a tag i push it to a local stack, my basic logic is below. ************** def handle_starttag(self, tag, attrs): curElement=HTMLElement(tag.lower(), attrs); <------ (1) if(self.elementRoot == None): self.elementRoot = curElement else: self.elementStack[-1].childs.append(curElement) <------ (2) self.elementStack.append(curElement) ************** here is the definintion of htmlelement class HTMLElement: tag=None attrs={} data='' childs=[] the issue is the though new elements are pushed in the stack (1), whenever i append the child to the stack top all other elements in the stack is getting affected, i assume the same reference is used but is there a way to overcome this ? From __peter__ at web.de Sat Nov 20 04:03:49 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 20 Nov 2010 10:03:49 +0100 Subject: constructin trees in python References: <3c926050-5e27-4efb-bf76-dbd1f2412810@o14g2000yqe.googlegroups.com> Message-ID: Maxim Mercury wrote: > here is the definintion of htmlelement > > class HTMLElement: > tag=None > attrs={} > data='' > childs=[] > > the issue is the though new elements are pushed in the stack (1), > whenever i append the child to the stack top all other elements in the > stack is getting affected, i assume the same reference is used but is > there a way to overcome this ? In class A: some_list = [] defines a class attribute shared by all instances of A. To turn some_list into an instance attribute move the definition into the initializer: class A: def __init__(self): self.some_list = [] Note that this holds for every attribute, but you usually see it only for mutables like lists or dicts because in class A: x = "yadda" y = [] a = A() print a.x # yadda a.x = 42 print a.x # 42 del a.x print a.x # can you guess what happens? the class attribute is shadowed by the instance attribute whereas a.y.append(42) modifies the class attribute in place. # two more to check that you've understood the mechanism: a.y += ["ham"] # ? a.y = ["spam"] # ? Peter From arnodel at gmail.com Sat Nov 20 04:17:15 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Sat, 20 Nov 2010 09:17:15 +0000 Subject: what's the precision of fractions.Fraction? References: <4ce5fc73$0$29966$c3e8da3$5496439d@news.astraweb.com> <8kntfvFr8aU1@mid.individual.net> Message-ID: <87k4k88ick.fsf@gmail.com> Peter Pearson writes: > On Fri, 19 Nov 2010 07:29:59 -0800 (PST), RJB wrote: >> Does Fractions remove common factors the way it should? >> >> If it does and you want to find the closest fraction with a smaller >> denominator i think tou'll need some number theory and continued >> fractions. > > No heroics required, finding the greatest common divisor is fast. I think RJB was referring to e.g. finding the closest fraction to a certain fraction with a bounded denominator. -- Arnaud From pmilin at ff.uns.ac.rs Sat Nov 20 04:37:26 2010 From: pmilin at ff.uns.ac.rs (Petar Milin) Date: Sat, 20 Nov 2010 10:37:26 +0100 Subject: Is it possible to use Google's advanced search options? Message-ID: <4CE796D6.5070802@ff.uns.ac.rs> Hello! Can anyone help me with getting number of hits from Google, but with restricton on domain (e.g., .edu) and language (e.g., lang_de)? I have tried with the Pygoogle (from: http://code.google.com/p/pygoogle/ ): from pygoogle import pygoogle word = u'something' request_word = word.encode('utf-8') request = ('%s+site:.edu' % request_word) g = pygoogle(request) g.get_result_count() Now, I realized that domain restriction works, but language does not, since it cannot be specified in request like domain in example above. Please, help! Is this possible with the Pygoogle? If not, how can I make that happen? Thanks! PM -------------- next part -------------- An HTML attachment was scrubbed... URL: From dickinsm at gmail.com Sat Nov 20 04:46:33 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Sat, 20 Nov 2010 01:46:33 -0800 (PST) Subject: what's the precision of fractions.Fraction? References: <4ce5fc73$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <12372eb4-0c12-46fd-99d7-ee9b7b0ebde1@b25g2000vbz.googlegroups.com> On Nov 19, 3:29?pm, RJB wrote: > Does Fractions remove common factors the way it should? > > If it does and you want to find the closest fraction with a smaller > denominator i think tou'll need some number theory and continued > fractions. Or perhaps just use the existing Fraction.limit_denominator method (which does indeed use some number theory and continued fractions): >>> from fractions import Fraction >>> from math import pi >>> Fraction.from_float(pi).limit_denominator(1000) Fraction(355, 113) -- Mark From stefan.sonnenberg at pythonmeister.com Sat Nov 20 05:30:44 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Sat, 20 Nov 2010 11:30:44 +0100 Subject: Is it possible to use Google's advanced search options? In-Reply-To: <4CE796D6.5070802@ff.uns.ac.rs> References: <4CE796D6.5070802@ff.uns.ac.rs> Message-ID: <4CE7A354.8040908@pythonmeister.com> Am 20.11.2010 10:37, schrieb Petar Milin: > Hello! > Can anyone help me with getting number of hits from Google, but with > restricton on domain (e.g., .edu) and language (e.g., lang_de)? I have > tried with the Pygoogle (from: http://code.google.com/p/pygoogle/ > ): > > from pygoogle import pygoogle > word = u'something' > request_word = word.encode('utf-8') > request = ('%s+site:.edu' % request_word) > g = pygoogle(request) > g.get_result_count() > > > Now, I realized that domain restriction works, but language does not, > since it cannot be specified in request like domain in example above. > Please, help! Is this possible with the Pygoogle? If not, how can I > make that happen? > > Thanks! > PM > > See below word = u'something' request_word = word.encode('utf-8') request = ('%s site:.edu options lang:de' % request_word) g = pygoogle(request) g.get_result_count() -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: stefan_sonnenberg.vcf Type: text/x-vcard Size: 232 bytes Desc: not available URL: From as at sci.fi Sat Nov 20 06:04:51 2010 From: as at sci.fi (Anssi Saari) Date: Sat, 20 Nov 2010 13:04:51 +0200 Subject: another newbie question References: Message-ID: Roy Smith writes: > I'm still searching for as nice a font to use on Linux. Envy Code R is a lookalike, so maybe worth considering. I haven't tried actual Monaco on Linux, but apparently it's possible. Personally, I use -lfp-gamow-medium-r-*-*-7-*-*-*-*-*-*-* in Linux (Emacs). From hniksic at xemacs.org Sat Nov 20 06:53:25 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Sat, 20 Nov 2010 12:53:25 +0100 Subject: what's the precision of fractions.Fraction? References: <4ce5fc73$0$29966$c3e8da3$5496439d@news.astraweb.com> <12372eb4-0c12-46fd-99d7-ee9b7b0ebde1@b25g2000vbz.googlegroups.com> Message-ID: <87zkt41aa2.fsf@xemacs.org> Mark Dickinson writes: > On Nov 19, 3:29?pm, RJB wrote: >> Does Fractions remove common factors the way it should? >> >> If it does and you want to find the closest fraction with a smaller >> denominator i think tou'll need some number theory and continued >> fractions. > > Or perhaps just use the existing Fraction.limit_denominator method > (which does indeed use some number theory and continued fractions): > >>>> from fractions import Fraction >>>> from math import pi >>>> Fraction.from_float(pi).limit_denominator(1000) > Fraction(355, 113) People, this is exactly what http://xkcd.com/353/ is about. From steve at REMOVE-THIS-cybersource.com.au Sat Nov 20 07:00:16 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Nov 2010 12:00:16 GMT Subject: dict diff References: <20101120015819.GA1254@mustafa.retral.net> Message-ID: <4ce7b850$0$29991$c3e8da3$5496439d@news.astraweb.com> On Sat, 20 Nov 2010 01:11:53 -0500, Steve Holden wrote: > On 11/19/2010 8:58 PM, Jin Yi wrote: >> so i came up with a diff method to compare 2 dicts. [...] > A PEP *and* some explanation of why you would want such an obscure piece > of code built in to the dict object, yes. You've never wanted to see how two dicts differ, as well as the fact that they do? I frequently find myself wanting to see why two dicts that should be equal aren't, especially for testing and debugging. I use this function: def dict_diffs(a, b): """dict_diffs(adict, bdict) -> (amissing, bmissing, different) Returns sets (amissing, bmissing, different) such that: amissing = keys missing from adict compared to bdict bmissing = keys missing from bdict compared to adict different = keys in both adict and bdict but with different values >>> dict_diffs({1:0, 2:0, 3:0}, {1:1, 2:0, 4:0}) (set([4]), set([3]), set([1])) """ from collections import Mapping if not isinstance(a, Mapping) and isinstance(b, Mapping): raise TypeError('arguments must both be mappings') amissing, bmissing, different = set(), set(), set() for key, value in a.items(): if key not in b: bmissing.add(key) elif value != b[key]: different.add(key) for key, value in b.items(): if key not in a: amissing.add(key) return (amissing, bmissing, different) -- Steven From nulla.epistola at web.de Sat Nov 20 07:52:05 2010 From: nulla.epistola at web.de (Sibylle Koczian) Date: Sat, 20 Nov 2010 13:52:05 +0100 Subject: Module locale throws exception: unsupported locale setting In-Reply-To: References: Message-ID: Am 19.11.2010 21:27, schrieb Ned Deily: > > There have been a lot of changes going into Python 3.2, currently in > alpha testing, in the areas of encodings and how they affect the > interfaces to/from the various platform operating systems Python 3 runs > on. It would be very useful if you could try the same test with the > most recent Python 3.2 alpha > (http://www.python.org/download/releases/3.2/) and, if the problem > persists there, open an issue about it. > Done. No change with 3.2a4, so I opened issue 10466. Thank you, Sibylle From __peter__ at web.de Sat Nov 20 07:59:27 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 20 Nov 2010 13:59:27 +0100 Subject: what's the precision of fractions.Fraction? References: <4ce5fc73$0$29966$c3e8da3$5496439d@news.astraweb.com> <12372eb4-0c12-46fd-99d7-ee9b7b0ebde1@b25g2000vbz.googlegroups.com> <87zkt41aa2.fsf@xemacs.org> Message-ID: Hrvoje Niksic wrote: > Mark Dickinson writes: > >> On Nov 19, 3:29 pm, RJB wrote: >>> Does Fractions remove common factors the way it should? >>> >>> If it does and you want to find the closest fraction with a smaller >>> denominator i think tou'll need some number theory and continued >>> fractions. >> >> Or perhaps just use the existing Fraction.limit_denominator method >> (which does indeed use some number theory and continued fractions): >> >>>>> from fractions import Fraction >>>>> from math import pi >>>>> Fraction.from_float(pi).limit_denominator(1000) >> Fraction(355, 113) > > People, this is exactly what http://xkcd.com/353/ is about. I can't help thinking of http://xkcd.com/378/ with the punch line changed to "'course there's a python library function to do that" It's all butterflies from here on... Peter From maxim.mercury at gmail.com Sat Nov 20 08:05:17 2010 From: maxim.mercury at gmail.com (Maxim Mercury) Date: Sat, 20 Nov 2010 05:05:17 -0800 (PST) Subject: constructin trees in python References: <3c926050-5e27-4efb-bf76-dbd1f2412810@o14g2000yqe.googlegroups.com> Message-ID: On Nov 20, 2:03?pm, Peter Otten <__pete... at web.de> wrote: > Maxim Mercury wrote: > > here is the definintion of htmlelement > > > class HTMLElement: > > ? ? tag=None > > ? ? attrs={} > > ? ? data='' > > ? ? childs=[] > > > the issue is the though new elements are pushed in the stack (1), > > whenever i append the child to the stack top all other elements in the > > stack is getting affected, i assume the same reference is used but is > > there a way to overcome this ? > > In > > class A: > ? ?some_list = [] > > defines a class attribute shared by all instances of A. To turn some_list > into an instance attribute move the definition into the initializer: > > class A: > ? ? def __init__(self): > ? ? ? ? self.some_list = [] > > Note that this holds for every attribute, but you usually see it only for > mutables like lists or dicts because in > > class A: > ? ?x = "yadda" > ? ?y = [] > a = A() > print a.x # yadda > a.x = 42 > print a.x # 42 > del a.x > print a.x # can you guess what happens? > > the class attribute is shadowed by the instance attribute whereas > > a.y.append(42) > > modifies the class attribute in place. > > # two more to check that you've understood the mechanism: > a.y += ["ham"] # ? > a.y = ["spam"] # ? > > Peter Thanks a lot peter, that worked as i needed. Where can i find some good documentation which explains such behavior. From iamforufriends at gmail.com Sat Nov 20 09:54:19 2010 From: iamforufriends at gmail.com (DATE@COUPLES) Date: Sat, 20 Nov 2010 06:54:19 -0800 (PST) Subject: R U READY TO DATE WITH HOT COMMITED COUPLES.... Message-ID: <767035c6-bd6b-451a-9e00-124bb306c3db@d20g2000yqg.googlegroups.com> R U READY TO DATE WITH HOT COMMITED COUPLES.... JUST FOLLOW THE LINK... WE R WAITING.... http://adultfriendfinder.com/go/g1271112-ppc http://adultfriendfinder.com/go/g1271112-ppc http://adultfriendfinder.com/go/g1271112-ppc http://adultfriendfinder.com/go/g1271112-ppc From steve at REMOVE-THIS-cybersource.com.au Sat Nov 20 09:59:53 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Nov 2010 14:59:53 GMT Subject: Inserting class namespace into method scope Message-ID: <4ce7e269$0$29991$c3e8da3$5496439d@news.astraweb.com> I find myself having need of a class where the class scope is included in the scope of methods in the class. A simple example from Python 3.1: x = "outside" class Magic: x = "inside" def method(self): return x I would like Magic().method() to return "inside" rather than "outside". Now, I understand why this is not Python's usual behaviour, and I agree with those reasons -- this is NOT a complaint that Python's normal behaviour is to exclude the class namespace from the method's scope. I also understand that the usual way of getting this would be to return self.x or self.__class__.x from method, instead of x. Again, normally I would do this. But in this specific case I have reasons for wanting to avoid both of the normal behaviours. Do not judge me, please accept that I have a good reason for wanting this, or at least allow me to shoot myself in the foot this way *wink*. In Python 3, is there some way to get this unusual behaviour? -- Steven From mback1 at live.se Sat Nov 20 10:10:49 2010 From: mback1 at live.se (Mikael B) Date: Sat, 20 Nov 2010 16:10:49 +0100 Subject: try to use unicode In-Reply-To: References: , , <4CE77D06.1080108@pythonmeister.com>, Message-ID: From: mback1 at live.se To: python-list at python.org Subject: RE: try to use unicode Date: Sat, 20 Nov 2010 08:49:59 +0100 Date: Sat, 20 Nov 2010 08:47:18 +0100 From: stefan.sonnenberg at pythonmeister.com To: mback1 at live.se CC: python-list at python.org Subject: Re: try to use unicode Meddelandetext Am 20.11.2010 06:53, schrieb Mikael B: Hi. I'm learning python. python 2.6.6 on ubuntu 10.10 I'm swedish so I try to use unicode to get swedish characters. I've checked wikipedia. utf-8 is said to be an unicode encoding.. this is the test program: # -*- coding: utf-8 -*- import readline s=raw_input(u'M?nadsl?n:') and this is the output: Traceback (most recent call last): File "test_uni.py", line 5, in s=raw_input(u'M?nadsl?n:') UnicodeEncodeError: 'ascii' codec can't encode character u'\xe5' in position 1: ordinal not in range(128) I'm doing something wrong... Mikael Your console is not unicode ready. Please take a look at the locale command and vars like LC_ALL, LC_LANG etc. Aha... Ok,thank you ---------------- But I checked this out.. Gnome terminal is set to 'unicode utf-8 encoding' and locale command returns LANG=sv_SE.utf8 LC_CTYPE="sv_SE.utf8" LC_NUMERIC="sv_SE.utf8" LC_TIME="sv_SE.utf8" LC_COLLATE="sv_SE.utf8" LC_MONETARY="sv_SE.utf8" LC_MESSAGES="sv_SE.utf8" LC_PAPER="sv_SE.utf8" LC_NAME="sv_SE.utf8" LC_ADDRESS="sv_SE.utf8" LC_TELEPHONE="sv_SE.utf8" LC_MEASUREMENT="sv_SE.utf8" LC_IDENTIFICATION="sv_SE.utf8" LC_ALL= if I remove the u before strings its works.. it must be a 8-bit subset of utf-8? -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From duncan.booth at invalid.invalid Sat Nov 20 11:24:45 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 20 Nov 2010 16:24:45 GMT Subject: Inserting class namespace into method scope References: <4ce7e269$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > But in this specific case I have reasons for wanting to avoid both of > the normal behaviours. Do not judge me, please accept that I have a > good reason for wanting this, or at least allow me to shoot myself in > the foot this way *wink*. In Python 3, is there some way to get this > unusual behaviour? > Sounds more like you want a mercy killing rather than just shooting in the foot. However, if I had taken sufficient illegal substances to want to do this, I would decorate the function with an attribute to indicate that I want it messed up, and then use a metaclass to create a new function from the original one but with the class namespace in place of the __globals__ attribute. I think you need to do it in a metaclass because once the class is created you just have a dictproxy and you need a real dict as the globals argument to the function constructor. The limitations will be that the resulting method cannot access any globals and also any changes to the class namespace won't be visible inside the function (since the class's dictproxy is a copy of the dict). from types import FunctionType class WeirdClass(type): def __new__(cls, name, bases, classdict): for attrname, attribute in classdict.items(): if getattr(attribute, '_useclassglobals', False): classdict[attrname] = FunctionType(attribute.__code__, classdict, attribute.__name__, attribute.__defaults__, attribute.__closure__) result = type.__new__(cls, name, bases, classdict) return result def classglobals(f): f._useclassglobals = True return f x = "outside" class Magic(metaclass=WeirdClass): x = "inside" @classglobals def method(self): return x m = Magic() print(m.method()) # prints 'inside' Magic.x = "new value" print(m.method()) # still prints 'inside' -- Duncan Booth http://kupuguy.blogspot.com From gd.usenet at spamfence.net Sat Nov 20 11:45:32 2010 From: gd.usenet at spamfence.net (=?UTF-8?Q?G=C3=BCnther?= Dietrich) Date: Sat, 20 Nov 2010 17:45:32 +0100 Subject: Inserting class namespace into method scope References: <4ce7e269$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: >I find myself having need of a class where the class scope is included in >the scope of methods in the class. A simple example from Python 3.1: > >x = "outside" > >class Magic: > x = "inside" > def method(self): > return x > > >I would like Magic().method() to return "inside" rather than "outside". Try this instead: return self.x Best regards, G?nther From dickinsm at gmail.com Sat Nov 20 12:09:33 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Sat, 20 Nov 2010 09:09:33 -0800 (PST) Subject: Weibull distr. random number generation References: Message-ID: <71b9f476-087f-455e-a587-69cd812feea8@j9g2000vbl.googlegroups.com> On Nov 19, 3:21?pm, Dimos wrote: > I would like to use the random module, and if I understand well the Random class, to create ?1300 decimal numbers in python, by providing the 2 Weibull parameters (b,c). How this can be done??? > > import random > print random > random.weibullvariate(b,c) > How can I set the population size n=1300 in decimals? random.weibullvariate(b, c) generates a single sample from the specified Weibull distribution. If you want 1300 samples, you'd use this within a loop. For example, here's code to put 10 Weibull variates with scale parameter 12345.0 and shape parameter 6.0 into a list: >>> import random >>> samples = [] >>> for i in xrange(10): ... samples.append(random.weibullvariate(12345.0, 6.0)) ... >>> print samples [15553.186762792948, 14304.175032317309, 9015.5053691933044, 12585.469181732506, 9436.2677219460638, 13350.89758791281, 5687.4330250037565, 12172.747202474553, 9687.8685933610814, 11699.040541029028] A more experienced Python programmer might use a list comprehension to achieve the same effect in a single line: >>> samples = [random.weibullvariate(12345.0, 6.0) for _ in xrange(10)] >>> print samples [10355.396846416865, 14689.507803932587, 11491.850991569485, 14128.56397290655, 12592.739991974759, 9076.7752548878998, 11868.012238422616, 12016.784656753523, 14724.818462506191, 13253.477389116439] Is this the sort of thing you were looking for? -- Mark From emile at fenx.com Sat Nov 20 12:12:18 2010 From: emile at fenx.com (Emile van Sebille) Date: Sat, 20 Nov 2010 09:12:18 -0800 Subject: Inserting class namespace into method scope In-Reply-To: <4ce7e269$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4ce7e269$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 11/20/2010 6:59 AM Steven D'Aprano said... > I find myself having need of a class where the class scope is included in > the scope of methods in the class. A simple example from Python 3.1: > > x = "outside" > > class Magic: > x = "inside" > def method(self): > return x > > > I would like Magic().method() to return "inside" rather than "outside". > > Now, I understand why this is not Python's usual behaviour, and I agree > with those reasons -- this is NOT a complaint that Python's normal > behaviour is to exclude the class namespace from the method's scope. > > I also understand that the usual way of getting this would be to return > self.x or self.__class__.x from method, instead of x. Again, normally I > would do this. > > But in this specific case I have reasons for wanting to avoid both of the > normal behaviours. Do not judge me, please accept that I have a good > reason for wanting this, or at least allow me to shoot myself in the foot > this way *wink*. In Python 3, is there some way to get this unusual > behaviour? > As it's easy to return self.x but you're restricting that option, what kind of change options must you work within? Emile From stackslip at gmail.com Sat Nov 20 12:23:51 2010 From: stackslip at gmail.com (Slie) Date: Sat, 20 Nov 2010 08:23:51 -0900 Subject: another newbie question Message-ID: I really enjoyed it when I put the MacOsx font on my Ubuntu or any other. Anssi Saari wrote: >Roy Smith writes: > >> I'm still searching for as nice a font to use on Linux. > >Envy Code R is a lookalike, so maybe worth considering. I haven't >tried actual Monaco on Linux, but apparently it's possible. >Personally, I use -lfp-gamow-medium-r-*-*-7-*-*-*-*-*-*-* in Linux >(Emacs). >-- >http://mail.python.org/mailman/listinfo/python-list From parvini_navid at yahoo.com Sat Nov 20 12:37:38 2010 From: parvini_navid at yahoo.com (Navid Parvini) Date: Sat, 20 Nov 2010 09:37:38 -0800 (PST) Subject: Installing pysqlite on Win64 Message-ID: <903873.61971.qm@web51007.mail.re2.yahoo.com> Dear All, I want to install pysqlite on my Windows 64 bit machine. I have python 2.4.3 on it. Would you please let me know how can I do it? That is, I need to use the source file (i.e pysqlite-2.5.6.tar.gz) or there is an executable file to install. Thank you in advance. Regards, Navid -------------- next part -------------- An HTML attachment was scrubbed... URL: From victorsubervi at gmail.com Sat Nov 20 14:23:22 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Sat, 20 Nov 2010 15:23:22 -0400 Subject: Printing from Web Page Message-ID: Hi; I need to be able to print something from a Web page: not the entire page but what I specify. I am writing the page and the client is surfing to it. How do I do this? TIA, beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From pmilin at ff.uns.ac.rs Sat Nov 20 14:24:39 2010 From: pmilin at ff.uns.ac.rs (Petar Milin) Date: Sat, 20 Nov 2010 20:24:39 +0100 Subject: Python-list Digest, Vol 86, Issue 176 In-Reply-To: References: Message-ID: Thanks so much! However, 'options lang:de' does not exactly the same as would 'lr=lang_de'? Am I right? Since I need number of hits, I would like to have the best, most correct values! :-) Sincerely, PM On Sat, Nov 20, 2010 at 12:00 PM, wrote: > Send Python-list mailing list submissions to > ? ? ? ?python-list at python.org > > To subscribe or unsubscribe via the World Wide Web, visit > ? ? ? ?http://mail.python.org/mailman/listinfo/python-list > or, via email, send a message with subject or body 'help' to > ? ? ? ?python-list-request at python.org > > You can reach the person managing the list at > ? ? ? ?python-list-owner at python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Python-list digest..." > > Today's Topics: > > ? 1. Re: what's the precision of fractions.Fraction? (Mark Dickinson) > ? 2. Re: Is it possible to use Google's advanced search options? > ? ? ?(Stefan Sonnenberg-Carstens) > > > ---------- Forwarded message ---------- > From:?Mark Dickinson > To:?python-list at python.org > Date:?Sat, 20 Nov 2010 01:46:33 -0800 (PST) > Subject:?Re: what's the precision of fractions.Fraction? > On Nov 19, 3:29?pm, RJB wrote: >> Does Fractions remove common factors the way it should? >> >> If it does and you want to find the closest fraction with a smaller >> denominator i think tou'll need some number theory and continued >> fractions. > > Or perhaps just use the existing Fraction.limit_denominator method > (which does indeed use some number theory and continued fractions): > >>>> from fractions import Fraction >>>> from math import pi >>>> Fraction.from_float(pi).limit_denominator(1000) > Fraction(355, 113) > > -- > Mark > > > > ---------- Forwarded message ---------- > From:?Stefan Sonnenberg-Carstens > To:?python-list at python.org > Date:?Sat, 20 Nov 2010 11:30:44 +0100 > Subject:?Re: Is it possible to use Google's advanced search options? > Am 20.11.2010 10:37, schrieb Petar Milin: > > Hello! > Can anyone help me with getting number of hits from Google, but with restricton on domain (e.g., .edu) and language (e.g., lang_de)? I have tried with the Pygoogle (from: http://code.google.com/p/pygoogle/): > from pygoogle import pygoogle > word = u'something' > request_word = word.encode('utf-8') > request = ('%s+site:.edu' % request_word) > g = pygoogle(request) > g.get_result_count() > > Now, I realized that domain restriction works, but language does not, since it cannot be specified in request like domain in example above. > Please, help! Is this possible with the Pygoogle? If not, how can I make that happen? > > Thanks! > PM > > See below > > word = u'something' > request_word = word.encode('utf-8') > request = ('%s site:.edu options lang:de' % request_word) > g = pygoogle(request) > g.get_result_count() > -- > http://mail.python.org/mailman/listinfo/python-list > From stefan_ml at behnel.de Sat Nov 20 15:02:47 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 20 Nov 2010 21:02:47 +0100 Subject: Is Unladen Swallow dead? In-Reply-To: <87vd3uccxw.fsf.mdw@metalzone.distorted.org.uk> References: <2e1a4d02-1e8a-4d31-95da-f33aaf90578c@30g2000yql.googlegroups.com> <8b0b044c-34a8-4747-b68f-f4cb56882f6f@e26g2000vbz.googlegroups.com> <4ce37e01$0$1666$742ec2ed@news.sonic.net> <4ce570ff$0$1617$742ec2ed@news.sonic.net> <87vd3uccxw.fsf.mdw@metalzone.distorted.org.uk> Message-ID: Mark Wooding, 19.11.2010 02:35: > John Nagle writes: >> This has been pointed out many times by many people. There's >> even a PhD thesis on the topic. Without a few restrictions, so >> that a compiler can at least tell when support for the hard cases >> is needed, Python cannot be compiled well. > > This assumes static compilation. It's the wrong approach for a dynamic > language like Python. Cython does a pretty good job in that, though. It also optimistically optimises a couple of things even during static compilation, e.g. "x.append(y)" likely hints on "x" being a list, even if static analysis can't prove that. Stefan From razamatan_retral_net at nospam.com Sat Nov 20 15:33:55 2010 From: razamatan_retral_net at nospam.com (Jin Yi) Date: Sat, 20 Nov 2010 12:33:55 -0800 Subject: dict diff In-Reply-To: <4ce7b850$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <20101120015819.GA1254@mustafa.retral.net> <4ce7b850$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20101120203355.GA5403@mustafa.retral.net> right. i moved to a 2-value tuple return value basically to illustrate exactly where each dict is providing a different value. it turns out to be much easier to grok than the 3-value one since it's all there and lines up correctly with the inputs... On Sat, Nov 20, 2010 at 12:00:16PM +0000, Steven D'Aprano wrote: > On Sat, 20 Nov 2010 01:11:53 -0500, Steve Holden wrote: > > > On 11/19/2010 8:58 PM, Jin Yi wrote: > >> so i came up with a diff method to compare 2 dicts. > [...] > > A PEP *and* some explanation of why you would want such an obscure piece > > of code built in to the dict object, yes. > > You've never wanted to see how two dicts differ, as well as the fact that > they do? I frequently find myself wanting to see why two dicts that > should be equal aren't, especially for testing and debugging. > > I use this function: > > def dict_diffs(a, b): > """dict_diffs(adict, bdict) -> (amissing, bmissing, different) > > Returns sets (amissing, bmissing, different) such that: > > amissing = keys missing from adict compared to bdict > bmissing = keys missing from bdict compared to adict > different = keys in both adict and bdict but with different values > > >>> dict_diffs({1:0, 2:0, 3:0}, {1:1, 2:0, 4:0}) > (set([4]), set([3]), set([1])) > > """ > from collections import Mapping > if not isinstance(a, Mapping) and isinstance(b, Mapping): > raise TypeError('arguments must both be mappings') > amissing, bmissing, different = set(), set(), set() > for key, value in a.items(): > if key not in b: > bmissing.add(key) > elif value != b[key]: > different.add(key) > for key, value in b.items(): > if key not in a: > amissing.add(key) > return (amissing, bmissing, different) > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list -- I pops mah collah. (Busta Rhymes) Jin Yi -- http://www.retral.net/razamatan From clp2 at rebertia.com Sat Nov 20 16:34:55 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 20 Nov 2010 13:34:55 -0800 Subject: Does Pygoogle allows for advanced search options? In-Reply-To: <706ff3ad-66b4-4cdb-a68f-bf0a079c2dc1@32g2000yqz.googlegroups.com> References: <706ff3ad-66b4-4cdb-a68f-bf0a079c2dc1@32g2000yqz.googlegroups.com> Message-ID: On Thu, Nov 18, 2010 at 3:26 AM, neocortex wrote: >> The library doesn't seem to have built-in support for filtering by >> language (and Google lacks a search query-string-based operator for >> that), but it looks like you could implement that feature by adding an >> "lr" parameter with an appropriate value to the query `args` >> dictionary. See the "lr?" entry under "Web Search Specific Arguments" >> onhttp://code.google.com/apis/websearch/docs/reference.html, and >> lines 68 & 102 of pygoogle.py. > > From those lines, it can be concluded that lr=lang_?? is not > supported, unfortunately. Right; that's why I said "you could implement that feature". Pretty easily it would seem. > And, when I execute, I get an error. What exactly are you executing, and what's the exact error? Vagueness is the enemy of debugging. Regards, Chris -- http://blog.rebertia.com From ben+python at benfinney.id.au Sat Nov 20 16:59:30 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 21 Nov 2010 08:59:30 +1100 Subject: Inserting class namespace into method scope References: <4ce7e269$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87wro78xml.fsf@benfinney.id.au> Steven D'Aprano writes: > I also understand that the usual way of getting this would be to > return self.x or self.__class__.x from method, instead of x. Again, > normally I would do this. > > But in this specific case I have reasons for wanting to avoid both of > the normal behaviours. Do not judge me, please accept that I have a > good reason for wanting this [?] C'mon, Steven, you know the drill. If you want us to help you solve a problem, don't start with ?I want to use this behaviour that seems loony, and I won't say why?. Instead, help us by telling us what problem you're trying to solve. It's not good enough to simply say ?I can't do it the right way?, you need to let us in on what the problem actually is, otherwise we have to play twenty questions with ?okay, how about this? ?no, that's no good either for other unspecified reasons?. So: what problem are you trying to solve, and what are the constraints? -- \ ?The double standard that exempts religious activities from | `\ almost all standards of accountability should be dismantled | _o__) once and for all.? ?Daniel Dennett, 2010-01-12 | Ben Finney From aahz at pythoncraft.com Sat Nov 20 17:11:30 2010 From: aahz at pythoncraft.com (Aahz) Date: 20 Nov 2010 14:11:30 -0800 Subject: Where's the bug? (cPickle/thread edition) (was Re: How to optimize and monitor garbage collection?) References: Message-ID: In article , Steve Holden wrote: > >[aside: in general, if you think your program is not working because of >a bug in Python, look harder at your program]. Good advice, I certainly agree with you. But sometimes it's not so simple. Right now, my company is running up against a problem with CherryPy because cPickle.dumps() doesn't release the GIL. You could argue that it's our fault for using threads, and you could also argue that we're having problems because our server has heavy memory contention (a dumps() that takes a couple of seconds on a laptop takes more than thirty seconds on the server). Nevertheless, I think it's also arguably a bug that dumps() doesn't release the GIL. (cPickle.dump() *does* release the GIL.) (Fortunately, we're savvy enough that it's easy for us to just make a local copy of cPickle that releases the GIL. Much easier than finding the problem in the first place...) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Look, it's your affair if you want to play with five people, but don't go calling it doubles." --John Cleese anticipates Usenet From joralemonshelly at gmail.com Sat Nov 20 17:40:16 2010 From: joralemonshelly at gmail.com (Shel) Date: Sat, 20 Nov 2010 14:40:16 -0800 (PST) Subject: building a web interface Message-ID: Hello, I am pretty new to all this. I have some coding experience, and am currently most comfortable with Python. I also have database design experience with MS Access, and have just created my first mySQL db. So right now I have a mySQL db structure and some Python code. My end goal is to create a browser-based interactive fiction/game thing. My code is currently just using dummy data rather than pulling in data from the db, but I think/hope it won't be too big of a deal to interact with the db through Python (famous last words...). My main problem right now is how to do the web interface. I don't know much about web architecture, unfortunately. I think I need a CGI script? What I would really like is to find a GUI tool to design the interface that would have customizable templates or drag-and-drop elements or something, so I wouldn't have to code much by hand. Something easy, if such a tool exists. Also would prefer something that I would be able to install/use without having much access to the server where the site will be hosted (on a university server that I don't have control over). I don't fully understand how a lot of the tools I have been looking at work, but it seems like they're often things where you'd have to get an administrator to do stuff on the server (is that right?), which I would prefer to avoid. It looks like Django has some sort of standalone implementation, but I'm not clear on how that would work or how much of a learning curve there would be for using it. If anyone has any thoughts or suggestions, I would really appreciate it. Hope my questions make sense. I don't really know what I'm doing, so could be they're a bit silly. I apologize if that's the case, and please let me know if you need any additional informmation. Thanks, Shel From philip at semanchuk.com Sat Nov 20 17:57:45 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Sat, 20 Nov 2010 17:57:45 -0500 Subject: Installing pysqlite on Win64 In-Reply-To: <903873.61971.qm@web51007.mail.re2.yahoo.com> References: <903873.61971.qm@web51007.mail.re2.yahoo.com> Message-ID: On Nov 20, 2010, at 12:37 PM, Navid Parvini wrote: > Dear All, > > I want to install pysqlite on my Windows 64 bit machine. I have python 2.4.3 on it. > Would you please let me know how can I do it? > > That is, I need to use the source file (i.e pysqlite-2.5.6.tar.gz) or there is an executable file to install. Hi Navid, I'm not a Windows guy so I really can't recommend how to proceed with the specific question you asked. But if there's any way you could upgrade the machine to Python >= 2.5, your problem will go away because those versions of Python come with a built-in sqlite interface. That might be an easier approach for you. Good luck Philip From debatem1 at gmail.com Sat Nov 20 18:14:59 2010 From: debatem1 at gmail.com (geremy condra) Date: Sat, 20 Nov 2010 15:14:59 -0800 Subject: dict diff In-Reply-To: <4ce7b850$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <20101120015819.GA1254@mustafa.retral.net> <4ce7b850$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Nov 20, 2010 at 4:00 AM, Steven D'Aprano wrote: > On Sat, 20 Nov 2010 01:11:53 -0500, Steve Holden wrote: > >> On 11/19/2010 8:58 PM, Jin Yi wrote: >>> so i came up with a diff method to compare 2 dicts. > [...] >> A PEP *and* some explanation of why you would want such an obscure piece >> of code built in to the dict object, yes. > > You've never wanted to see how two dicts differ, as well as the fact that > they do? I frequently find myself wanting to see why two dicts that > should be equal aren't, especially for testing and debugging. > > I use this function: > > def dict_diffs(a, b): > ? ?"""dict_diffs(adict, bdict) -> (amissing, bmissing, different) > > ? ?Returns sets (amissing, bmissing, different) such that: > > ? ?amissing = keys missing from adict compared to bdict > ? ?bmissing = keys missing from bdict compared to adict > ? ?different = keys in both adict and bdict but with different values > > ? ?>>> dict_diffs({1:0, 2:0, 3:0}, {1:1, 2:0, 4:0}) > ? ?(set([4]), set([3]), set([1])) > > ? ?""" > ? ?from collections import Mapping > ? ?if not isinstance(a, Mapping) and isinstance(b, Mapping): > ? ? ? ?raise TypeError('arguments must both be mappings') > ? ?amissing, bmissing, different = set(), set(), set() > ? ?for key, value in a.items(): > ? ? ? ?if key not in b: > ? ? ? ? ? ?bmissing.add(key) > ? ? ? ?elif value != b[key]: > ? ? ? ? ? ?different.add(key) > ? ?for key, value in b.items(): > ? ? ? ?if key not in a: > ? ? ? ? ? ?amissing.add(key) > ? ?return (amissing, bmissing, different) Add me to this group. I frequently use some homebrew set operations on dictionaries. My (stupid) implementation: #! /usr/bin/env python3 class AugmentedDict(dict): def __and__(self, other): """Dictionary intersection operation""" return AugmentedDict(self.items() & other.items()) def __or__(self, other): """Dictionary union operation""" union = self.items() | other.items() merged_union = AugmentedDict(union) if len(union) != len(merged_union): err = 'Cannot take union of non-pairwise disjoint dictionaries' raise Exception(err) return merged_union def __sub__(self, other): """Dictionary difference operation""" return AugmentedDict(self.items() - other.items()) def __xor__(self, other): """Dictionary symmetric difference operation""" return AugmentedDict(self.items() ^ other.items()) if __name__ == "__main__": # demonstrate the behavior of AugmentedDict a = AugmentedDict({'a': 1, 'b': 2, 'c': 3}) b = AugmentedDict({'b': 2, 'c': 3}) c = AugmentedDict({'a': 1}) assert( (a|(b|c)) == (b|(a|c))) assert( (a&(b&c)) == (b&(a&c))) assert( (b&c) == (c&b)) assert( (a - b) == c) assert( (a ^ b) == ((a-b) | (b-a))) Truth be told, I was under the impression that this was actually going to be a part of dictionary behavior at some point, maybe I was thinking of the .items() behavior. Geremy Condra From navkirats at gmail.com Sat Nov 20 18:23:06 2010 From: navkirats at gmail.com (Navkirat Singh) Date: Sun, 21 Nov 2010 04:53:06 +0530 Subject: Persistent Database Cursors Message-ID: Hi Guys, I am having trouble with database cursors. I am using py-postgresql cursors to fetch data over HTTP. I want to be able to refer to the cursor over multiple HTTP requests. Any light on this matter would be of great help. Regards, Nav From goldtech at worldpost.com Sat Nov 20 19:08:51 2010 From: goldtech at worldpost.com (goldtech) Date: Sat, 20 Nov 2010 16:08:51 -0800 (PST) Subject: Installed modules from Synaptic in Ubuntu problem Message-ID: <6d4a1c46-fc21-40a2-84f9-0aff8ed1048c@a37g2000yqi.googlegroups.com> Hi, Using Ubuntu linux 9.04 and have python 2.6. I'm trying to add a module from the synaptic installer. It's ?Tidylib a wrapper for HTML Tidy. It installed with out a problem, when I do a $ help ('modules') I see a module called "tidy". But when I do an import tidy in a script I get an error... import tidy ImportError: No module named tidy How do I get this module working? Any help appreciated. also do I need a special path?: ~$ locate utidylib /usr/share/doc/python-utidylib /usr/share/doc/python-utidylib/README.Debian /usr/share/doc/python-utidylib/README.Debian-source /usr/share/doc/python-utidylib/README.txt /usr/share/doc/python-utidylib/changelog.Debian.gz /usr/share/doc/python-utidylib/copyright /usr/share/python-support/python-utidylib /usr/share/python-support/python-utidylib/tidy /usr/share/python-support/python-utidylib/uTidylib-0.2.egg-info /usr/share/python-support/python-utidylib/tidy/__init__.py /usr/share/python-support/python-utidylib/tidy/error.py /usr/share/python-support/python-utidylib/tidy/lib.py /usr/share/python-support/python-utidylib/tidy/test_tidy.py /var/cache/apt/archives/python-utidylib_0.2-3.2ubuntu1_all.deb /var/lib/dpkg/info/python-utidylib.list /var/lib/dpkg/info/python-utidylib.md5sums /var/lib/dpkg/info/python-utidylib.postinst /var/lib/dpkg/info/python-utidylib.prerm -- From martin at address-in-sig.invalid Sat Nov 20 19:10:19 2010 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Sun, 21 Nov 2010 00:10:19 +0000 (UTC) Subject: building a web interface References: Message-ID: On Sat, 20 Nov 2010 14:40:16 -0800, Shel wrote: > Hello, > > I am pretty new to all this. I have some coding experience, and am > currently most comfortable with Python. I also have database design > experience with MS Access, and have just created my first mySQL db. > > So right now I have a mySQL db structure and some Python code. My end > goal is to create a browser-based interactive fiction/game thing. My > code is currently just using dummy data rather than pulling in data from > the db, but I think/hope it won't be too big of a deal to interact with > the db through Python (famous last words...). > Wrong approach. If you're going to use a database, start with writing a program that puts your data into it alongside the program that reads and uses the data. Do it incrementally: if you are writing an adventure game a good place to start would be the 'place' table and the part of the game builder that adds/amends/removes a place from the database as well as enough of the game program to show the place description and use the doors to move from place to place. This way you'll have that working before you start adding weapons, monsters, etc. or try to implement fights. You'll also learn that writing place descriptions isn't as easy as it sounds: if there are several doors into a room the description must make sense no matter which way you come into it. Its quite hard at first to avoid descriptions like "Further into the forest. Its getting darker" which may be OK coming from a road but is pretty stupid if you're on your way out of the forest toward the road. http://www.kitebird.com/articles/pydbapi.html which tells you what you need to know about accessing SQL databases. > My main problem right now is how to do the web interface. I don't know > much about web architecture, unfortunately. I think I need a CGI script? > You're biting off quite a lot at once. It may be easier to first write a command line Python program and get it working in that form. Once you have the game/application logic working you can adapt it to run as a CGI script. Development and debugging will be easier that way. If you're not familiar with this style of adventure game, look here: http://www.rickadams.org/adventure/ You'll find various downloadable examples on the downloads page as DOS executables and in C or Fortran source code. Have a play with it to see what even this very basic user interaction can do - you'll have fun and learn useful stuff. > What I would really like is to find a GUI tool to design the interface > that would have customizable templates or drag-and-drop elements or > something, so I wouldn't have to code much by hand. Something easy, if > such a tool exists. > If you're doing a textual adventure of something like it a tool won't gain you much, since you only need a few skeleton web pages than your program can select and drop text or images into. > Also would prefer something that I would be able to install/use without > having much access to the server where the site will be hosted (on a > university server that I don't have control over). I don't fully > understand how a lot of the tools I have been looking at work, but it > seems like they're often things where you'd have to get an administrator > to do stuff on the server (is that right?), which I would prefer to > avoid. > CGI and Python should be OK providing the server has Python available and the admins will let you use CGI, but that's not a good development platform. You really need a web server you can start, stop and fiddle with once you get to the point of putting your code in a server. Running a simple local web server on your computer would be a better place to start: once its running you simply point your browser at localhost:80 and send it the URL of the initial page of your application. Search on "Python web server" for details of building or downloading a simple one. You'll also find stuff about interfacing Python programs to a web server. -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From stef.mientki at gmail.com Sat Nov 20 19:36:56 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Sun, 21 Nov 2010 01:36:56 +0100 Subject: building a web interface In-Reply-To: References: Message-ID: <4CE869A8.90209@gmail.com> On 20-11-2010 23:40, Shel wrote: > Hello, > > I am pretty new to all this. I have some coding experience, and am > currently most comfortable with Python. I also have database design > experience with MS Access, and have just created my first mySQL db. > > So right now I have a mySQL db structure and some Python code. My end > goal is to create a browser-based interactive fiction/game thing. My > code is currently just using dummy data rather than pulling in data > from the db, but I think/hope it won't be too big of a deal to > interact with the db through Python (famous last words...). > > My main problem right now is how to do the web interface. I don't know > much about web architecture, unfortunately. I think I need a CGI > script? > > What I would really like is to find a GUI tool to design the interface > that would have customizable templates or drag-and-drop elements or > something, so I wouldn't have to code much by hand. Something easy, if > such a tool exists. > > Also would prefer something that I would be able to install/use > without having much access to the server where the site will be hosted > (on a university server that I don't have control over). I don't fully > understand how a lot of the tools I have been looking at work, but it > seems like they're often things where you'd have to get an > administrator to do stuff on the server (is that right?), which I > would prefer to avoid. > > It looks like Django has some sort of standalone implementation, but > I'm not clear on how that would work or how much of a learning curve > there would be for using it. > > If anyone has any thoughts or suggestions, I would really appreciate > it. > > Hope my questions make sense. I don't really know what I'm doing, so > could be they're a bit silly. I apologize if that's the case, and > please let me know if you need any additional informmation. > > Thanks, > Shel you might take a look at web2py, it can be handled quit low level, runs perfectly on a the build python server, and you switch to almost any database at any time cheers, Stef From steve at REMOVE-THIS-cybersource.com.au Sat Nov 20 19:59:40 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 21 Nov 2010 00:59:40 GMT Subject: Inserting class namespace into method scope References: <4ce7e269$0$29991$c3e8da3$5496439d@news.astraweb.com> <87wro78xml.fsf@benfinney.id.au> Message-ID: <4ce86efc$0$29991$c3e8da3$5496439d@news.astraweb.com> On Sun, 21 Nov 2010 08:59:30 +1100, Ben Finney wrote: > C'mon, Steven, you know the drill. If you want us to help you solve a > problem, don't start with ?I want to use this behaviour that seems > loony, and I won't say why?. Instead, help us by telling us what problem > you're trying to solve. Well, I tried the TL;DR version. Now you have to read the full version. Inspired by the last maxim of the Zen: "Namespaces are one honking great idea -- let's do more of those!" I'm looking to apply this to my code. I have a bunch of related functions and objects which are private to a module, with a single public function that acts as the API to those functions. I'd like to have these private functions in a namespace, separate from the rest of the module. Ignore the fact that they are private functions -- I can deal with that by the usual naming convention. Focus on the "separate namespace" aspect. What I want is the ability to write this: create Namespace: def function(x): return x def func(y): return function("spam") + "'n'" + y dispatch = {1: func, 2: function} def another_func(z): return len(dispatch[2](z)) func("eggs") # raises NameError Namespace.func("eggs") # returns "spam'n'eggs" Namespace.dispatch[1]("cheese") # returns "spam'n'cheese" etc. But of course we can't do that. So other options include: (1) Give up the dream and just place the private functions in the global namespace like everyone else does. So much for the Zen. (2) Place them in a separate module, and import the module, similar to the way that the os module imports path. This is certainly possible, and it works well, but it splits code into two files when it should be in one. It pollutes the module namespace, and Guido has recently expressed mild objection to new code doing what os does. Or at least he suggested that we shouldn't *encourage* doing what os does. (3) Redesign my module to use a full package structure, and place the functions in a separate module in the package. It's overkill to have a package for just two namespaces (modules). (4) Use a class to hold the functions, instantiate the class to get an instance, and deal with the fact that functions in such an instance are automatically turned into methods. There are various ways of dealing with it, including the obvious: write the functions as methods. But this is too Java-like for my liking... I don't need the ability to make multiple instances with independent state, nor do I want to waste time turning it into a singleton or borg class. Worse, it complicates the dispatch table, because I have to deal with bound methods versus unbound methods, or staticmethod/classmethod descriptors... it gets *messy* and *ugly* real fast. (5) Use a class to hold the functions, but avoid instantiating it, so that the functions remain functions. I've done this, and it works great unless the functions need to refer to each other. So in the above example, Namespace.function("spam") is fine, but Namespace.func("eggs") is not. Simple solution: Namespace.func could internally call Namespace.function instead of just function. That's doable now, without any magic, but it feels less than ideal. (6) Do something with nested functions, although I'm not entirely sure what yet. See below. (7) Create a module on the fly, then populate it with the functions: Namespace = type(sys)('Namespace') def function(x): return x def func(y): return function("spam") + "'n'" + y dispatch = {1: func, 2: function} Namespace.function = function Namespace.func = func Namespace.dispatch = dispatch del function, func, dispatch (8) Something else. There's always something else. I've tried (1) through (5), with varying levels of success. (6) is next on my list to try. I haven't tried (7), and I don't think I will bother. It seriously breaks "Don't repeat yourself", and fails to visually set the Namespace functions apart from the global namespace. While I expect it will work, it's too ugly to consider. So I have considered many options, and will look at others, but right now I've set myself the task of exploring (5) and finding out whether or not there is any way to hammer the class namespace into what I want. Duncan suggested a way, but it's messy and fragile. TL;DR. See my first post :-P -- Steven From gnarlodious at gmail.com Sat Nov 20 20:19:06 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Sat, 20 Nov 2010 17:19:06 -0800 (PST) Subject: CGI FieldStorage instances? Message-ID: <1ec25d72-a99e-4fd9-9d50-1ac8c65812e9@z19g2000yqb.googlegroups.com> I'm having a hard time understanding this, can someone explain? Running a CGI with query string: ?action=Find&page=Data Script includes these lines: form=cgi.FieldStorage(keep_blank_values=1) print("Content-type:text/html\n\n") print(cgi.print_form(form)) Output: Form Contents: action: MiniFieldStorage('action', 'Find') page: MiniFieldStorage('page', 'Data') It looks like every variable in the query string instantiates a MiniFieldStorage with that value, is that the case? And if so, what sort of cool tricks could I do with that feature? Because so far I am doing CGI and it is a big old mess. Intercepting every variable is complicated and confusing. Is there an easier way? -- Gnarlie From joralemonshelly at gmail.com Sat Nov 20 20:20:53 2010 From: joralemonshelly at gmail.com (Shel) Date: Sat, 20 Nov 2010 17:20:53 -0800 (PST) Subject: building a web interface References: Message-ID: X-No-Archive:Thanks for your advice. Will take a look at rickadamsadventure.org. Although I am not actually creating an adventure game, I'm sure it will be helpful. Sorry I wasn't clear about the db part. Most of the data has already been written and/or generated and tested with the code. I do plan to finish all the database stuff before going to the front end, but am just thinking ahead about how to do the interface. On Nov 20, 4:10?pm, Martin Gregorie wrote: > On Sat, 20 Nov 2010 14:40:16 -0800, Shel wrote: > > Hello, > > > I am pretty new to all this. I have some coding experience, and am > > currently most comfortable with Python. ?I also have database design > > experience with MS Access, and have just created my first mySQL db. > > > So right now I have a mySQL db structure and some Python code. My end > > goal is to create a browser-based interactive fiction/game thing. My > > code is currently just using dummy data rather than pulling in data from > > the db, but I think/hope it won't be too big of a deal to interact with > > the db through Python (famous last words...). > > Wrong approach. If you're going to use a database, start with writing a > program that puts your data into it alongside the program that reads and > uses the data. Do it incrementally: if you are writing an adventure game > a good place to start would be the 'place' table and the part of the game > builder that adds/amends/removes a place from the database as well as > enough of the game program to show the place description and use the > doors to move from place to place. This way you'll have that working > before you start adding weapons, monsters, etc. or try to implement > fights. You'll also learn that writing place descriptions isn't as easy > as it sounds: if there are several doors into a room the description must > make sense no matter which way you come into it. Its quite hard at first > to avoid descriptions like "Further into the forest. Its getting darker" > which may be OK coming from a road but is pretty stupid if you're on your > way out of the forest toward the road. > > http://www.kitebird.com/articles/pydbapi.htmlwhich tells you what you > need to know about accessing SQL databases. > > > My main problem right now is how to do the web interface. I don't know > > much about web architecture, unfortunately. I think I need a CGI script? > > You're biting off quite a lot at once. It may be easier to first write a > command line Python program and get it working in that form. Once you > have the game/application logic working you can adapt it to run as a CGI > script. Development and debugging will be easier that way. > > If you're not familiar with this style of adventure game, look here:http://www.rickadams.org/adventure/You'll find various downloadable > examples on the downloads page as DOS executables and in C or Fortran > source code. Have a play with it to see what even this very basic user > interaction can do - you'll have fun and learn useful stuff. > > > What I would really like is to find a GUI tool to design the interface > > that would have customizable templates or drag-and-drop elements or > > something, so I wouldn't have to code much by hand. Something easy, if > > such a tool exists. > > If you're doing a textual adventure of something like it a tool won't > gain you much, since you only need a few skeleton web pages than your > program can select and drop text or images into. > > > Also would prefer something that I would be able to install/use without > > having much access to the server where the site will be hosted (on a > > university server that I don't have control over). I don't fully > > understand how a lot of the tools I have been looking at work, but it > > seems like they're often things where you'd have to get an administrator > > to do stuff on the server (is that right?), which I would prefer to > > avoid. > > CGI and Python should be OK providing the server has Python available and > the admins will let you use CGI, but that's not a good development > platform. > > You really need a web server you can start, stop and fiddle with once you > get to the point of putting your code in a server. Running a simple local > web server on your computer would be a better place to start: once its > running you simply point your browser at localhost:80 and send it the URL > of the initial page of your application. > > Search on "Python web server" for details of building or downloading a > simple one. You'll also find stuff about interfacing Python programs to a > web server. > > -- > martin@ ? | Martin Gregorie > gregorie. | Essex, UK > org ? ? ? | From ben+python at benfinney.id.au Sat Nov 20 20:33:09 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 21 Nov 2010 12:33:09 +1100 Subject: Inserting class namespace into method scope References: <4ce7e269$0$29991$c3e8da3$5496439d@news.astraweb.com> <87wro78xml.fsf@benfinney.id.au> <4ce86efc$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87sjyv8nqi.fsf@benfinney.id.au> Steven D'Aprano writes: > I have a bunch of related functions and objects which are private to a > module, with a single public function that acts as the API to those > functions. I'd like to have these private functions in a namespace, > separate from the rest of the module. Ignore the fact that they are > private functions -- I can deal with that by the usual naming > convention. Focus on the "separate namespace" aspect. > > What I want is the ability to write this: > > create Namespace: > def function(x): > return x > > def func(y): > return function("spam") + "'n'" + y > > dispatch = {1: func, 2: function} > > def another_func(z): > return len(dispatch[2](z)) Can you make it concrete, by naming the namespace something meaningful or arbitrary? It's as though you wanted to discuss a function, and named it ?function?. (Oh, you did that too :-) I'll assume an example of a namespace for the storage backends of a library, and that you want a namespace of ?storage?. If you can provide the actual use case that presents this problem to you, that would be best. Running with my contrived example, I take your option (2) below: use a private module as a private namespace. In the file ?_storage?: def backend_foo(x): return x def backend_bar(x): return backend_foo("spam") + "'n'" + x dispatch = {1: backend_bar, 2: backend_foo} > func("eggs") # raises NameError > Namespace.func("eggs") # returns "spam'n'eggs" > > Namespace.dispatch[1]("cheese") # returns "spam'n'cheese" import _storage backend_bar("eggs") # raises NameError _storage.backend_bar("eggs") # returns "spam'n'eggs" _storage.dispatch[1]("cheese") # returns "spam'n'cheese" > (2) Place them in a separate module, and import the module, similar to > the way that the os module imports path. This is certainly possible, > and it works well, but it splits code into two files when it should be > in one. Why should it be in one? If a separate module works well, there needs to be a good reason not to do it. > It pollutes the module namespace, and Guido has recently expressed > mild objection to new code doing what os does. Or at least he > suggested that we shouldn't *encourage* doing what os does. The single-leading-underscore naming convention makes it clear that the module is a private implementation detail, and signals to the reader that the module is not advisable for import except as part of that implementation. That refutes the charge of polluting the module namespace. As for Guido's opinion on the matter, for whatever it's worth, those interested are invited to read recent ?python-dev? discussions on APIs . In short, I think he agrees with my position above. > (3) Redesign my module to use a full package structure, and place the > functions in a separate module in the package. It's overkill to have a > package for just two namespaces (modules). I disagree strongly. Two modules is not too few for a package; it certainly isn't ?overkill?. Packages are quite lightweight for what they do. If they solve a problem well, I don't see why to discard them without a better reason. For all the other options you enumerated I am in agreement with your position. Thanks for making it more concrete so we know what problem we're supposed to be grappling. -- \ ?Nothing is more sacred than the facts.? ?Sam Harris, _The End | `\ of Faith_, 2004 | _o__) | Ben Finney From joralemonshelly at gmail.com Sat Nov 20 20:34:16 2010 From: joralemonshelly at gmail.com (Shel) Date: Sat, 20 Nov 2010 17:34:16 -0800 (PST) Subject: building a web interface References: Message-ID: Thanks for your help. I know that they have Python and mySQL. They have mySQL set up so that they just have to create the db, which they've already done and I've defined the tables and modified the data and whatnot, so that seems good. Not sure about mod-python v. mod-wsgi. Ah, the Django thing makes more sense to me now. I couldn't quite figure out what the heck they were talking about in the description of it. Shel On Nov 20, 4:19?pm, Dennis Lee Bieber wrote: > On Sat, 20 Nov 2010 14:40:16 -0800 (PST), Shel > declaimed the following in > gmane.comp.python.general: > > > What I would really like is to find a GUI tool to design the interface > > that would have customizable templates or drag-and-drop elements or > > something, so I wouldn't have to code much by hand. Something easy, if > > such a tool exists. > > ? ? ? ? In original pure HTML, such would be rather meaningless... Pure HTML > leaves the presentation (the rendering) of the page up to the user's > browser. Layout of one item against another is only relative (form field > 2 comes after form field 1). And I've seen some rather ugly pages > produced using so-called graphical design tools (like layers of > text because the tool isn't smart enough > to find and remove prior tag pairs when one changes intent... I've also > seen text ). > > ? ? ? ? Frames were one attempt at dividing a browser into regions in which > some stuff could stay constant while others are scrolled. > > ? ? ? ? Then you get the hoard that creates things like transparent GIF > files with a few pixels to create "spacing" elements... > > ? ? ? ? I tend to use an ancient copy of HomeSite 5 for HTML editing -- > though I don't do enough such to justify taking the time to define > things like Django's templating tags as standard types. I prefer to edit > in the original intent of HTML -- as a mark-up language which identifies > WHAT a construct is, but does not bother with HOW/WHERE that construct > is rendered. If I really need something looking more like a newspaper > layout I'd define a table and use combinations of row and column span to > "grid" the contents as desired -- and even that would still use > proportional spacing (90% of browser width, say) rather than absolute > pixels (845 pixels wide). > > > Also would prefer something that I would be able to install/use > > without having much access to the server where the site will be hosted > > (on a university server that I don't have control over). I don't fully > > understand how a lot of the tools I have been looking at work, but it > > seems like they're often things where you'd have to get an > > administrator to do stuff on the server (is that right?), which I > > would prefer to avoid. > > ? ? ? ? First step -- find out what toolset the server uses; Apache with > mod-python? mod-WSGI? Do they even have Python available? and if so, > what version (do they have MySQL available AND MySQLdb, and how much > control will they give you -- MySQL administration could be set up to > where they have to create the database AND table definitions, and all > you get is read/update/delete data privileges... Or they create the > database with no contents but your account has table manipulation > privileges within that database... Can you administer your database vie > direct login to the MySQL server, or do you have to go through some > web-based interface?). > > > It looks like Django has some sort of standalone implementation, but > > I'm not clear on how that would work or how much of a learning curve > > there would be for using it. > > ? ? ? ? The "standalone" is a development/debug server mode running on a > non-standard port number (HTTP is privileged port 80, these types of > development servers often run on ports 8080, 8081, etc. as one does not > need to be superuser to bind to the port number). It is not meant as a > production server. Instead one has the real server configured to run the > application (Django and similar are not simple stand-alone CGI scripts; > pages are _methods/functions_ within the application which generate the > page contents and return them to the server for delivery). > > -- > ? ? ? ? Wulfraed ? ? ? ? ? ? ? ? Dennis Lee Bieber ? ? ? ? AF6VN > ? ? ? ? wlfr... at ix.netcom.com ? ?HTTP://wlfraed.home.netcom.com/ From joralemonshelly at gmail.com Sat Nov 20 20:39:21 2010 From: joralemonshelly at gmail.com (Shel) Date: Sat, 20 Nov 2010 17:39:21 -0800 (PST) Subject: building a web interface References: Message-ID: Thanks for your help. I know that they have Python and mySQL. They have mySQL set up so that they just have to create the db, which they've already done and I've defined the tables and modified the data and whatnot, so that seems good. Not sure about mod-python v. mod-wsgi. Ah, the Django thing makes more sense to me now. I couldn't quite figure out what the heck they were talking about in the description of it. Shel On Nov 20, 4:19?pm, Dennis Lee Bieber wrote: > On Sat, 20 Nov 2010 14:40:16 -0800 (PST), Shel > declaimed the following in > gmane.comp.python.general: > > > What I would really like is to find a GUI tool to design the interface > > that would have customizable templates or drag-and-drop elements or > > something, so I wouldn't have to code much by hand. Something easy, if > > such a tool exists. > > ? ? ? ? In original pure HTML, such would be rather meaningless... Pure HTML > leaves the presentation (the rendering) of the page up to the user's > browser. Layout of one item against another is only relative (form field > 2 comes after form field 1). And I've seen some rather ugly pages > produced using so-called graphical design tools (like layers of > text because the tool isn't smart enough > to find and remove prior tag pairs when one changes intent... I've also > seen text ). > > ? ? ? ? Frames were one attempt at dividing a browser into regions in which > some stuff could stay constant while others are scrolled. > > ? ? ? ? Then you get the hoard that creates things like transparent GIF > files with a few pixels to create "spacing" elements... > > ? ? ? ? I tend to use an ancient copy of HomeSite 5 for HTML editing -- > though I don't do enough such to justify taking the time to define > things like Django's templating tags as standard types. I prefer to edit > in the original intent of HTML -- as a mark-up language which identifies > WHAT a construct is, but does not bother with HOW/WHERE that construct > is rendered. If I really need something looking more like a newspaper > layout I'd define a table and use combinations of row and column span to > "grid" the contents as desired -- and even that would still use > proportional spacing (90% of browser width, say) rather than absolute > pixels (845 pixels wide). > > > Also would prefer something that I would be able to install/use > > without having much access to the server where the site will be hosted > > (on a university server that I don't have control over). I don't fully > > understand how a lot of the tools I have been looking at work, but it > > seems like they're often things where you'd have to get an > > administrator to do stuff on the server (is that right?), which I > > would prefer to avoid. > > ? ? ? ? First step -- find out what toolset the server uses; Apache with > mod-python? mod-WSGI? Do they even have Python available? and if so, > what version (do they have MySQL available AND MySQLdb, and how much > control will they give you -- MySQL administration could be set up to > where they have to create the database AND table definitions, and all > you get is read/update/delete data privileges... Or they create the > database with no contents but your account has table manipulation > privileges within that database... Can you administer your database vie > direct login to the MySQL server, or do you have to go through some > web-based interface?). > > > It looks like Django has some sort of standalone implementation, but > > I'm not clear on how that would work or how much of a learning curve > > there would be for using it. > > ? ? ? ? The "standalone" is a development/debug server mode running on a > non-standard port number (HTTP is privileged port 80, these types of > development servers often run on ports 8080, 8081, etc. as one does not > need to be superuser to bind to the port number). It is not meant as a > production server. Instead one has the real server configured to run the > application (Django and similar are not simple stand-alone CGI scripts; > pages are _methods/functions_ within the application which generate the > page contents and return them to the server for delivery). > > -- > ? ? ? ? Wulfraed ? ? ? ? ? ? ? ? Dennis Lee Bieber ? ? ? ? AF6VN > ? ? ? ? wlfr... at ix.netcom.com ? ?HTTP://wlfraed.home.netcom.com/ From joralemonshelly at gmail.com Sat Nov 20 20:41:18 2010 From: joralemonshelly at gmail.com (Shel) Date: Sat, 20 Nov 2010 17:41:18 -0800 (PST) Subject: building a web interface References: Message-ID: <3313becc-6d5b-4cbc-8bfb-bc8252e6d2af@l8g2000yqh.googlegroups.com> This looks very promising. Thanks so much! Shel On Nov 20, 4:36?pm, Stef Mientki wrote: > On 20-11-2010 23:40, Shel wrote: > > > Hello, > > > I am pretty new to all this. I have some coding experience, and am > > currently most comfortable with Python. ?I also have database design > > experience with MS Access, and have just created my first mySQL db. > > > So right now I have a mySQL db structure and some Python code. My end > > goal is to create a browser-based interactive fiction/game thing. My > > code is currently just using dummy data rather than pulling in data > > from the db, but I think/hope it won't be too big of a deal to > > interact with the db through Python (famous last words...). > > > My main problem right now is how to do the web interface. I don't know > > much about web architecture, unfortunately. I think I need a CGI > > script? > > > What I would really like is to find a GUI tool to design the interface > > that would have customizable templates or drag-and-drop elements or > > something, so I wouldn't have to code much by hand. Something easy, if > > such a tool exists. > > > Also would prefer something that I would be able to install/use > > without having much access to the server where the site will be hosted > > (on a university server that I don't have control over). I don't fully > > understand how a lot of the tools I have been looking at work, but it > > seems like they're often things where you'd have to get an > > administrator to do stuff on the server (is that right?), which I > > would prefer to avoid. > > > It looks like Django has some sort of standalone implementation, but > > I'm not clear on how that would work or how much of a learning curve > > there would be for using it. > > > If anyone has any thoughts or suggestions, I would really appreciate > > it. > > > Hope my questions make sense. I don't really know what I'm doing, so > > could be they're a bit silly. I apologize if that's the case, and > > please let me know if you need any additional informmation. > > > Thanks, > > Shel > > you might take a look at web2py, > it can be handled quit low level, > runs perfectly on a the build python server, > and you switch to almost any database at any time > > cheers, > Stef From hidura at gmail.com Sat Nov 20 21:35:47 2010 From: hidura at gmail.com (Hidura) Date: Sat, 20 Nov 2010 22:35:47 -0400 Subject: Printing from Web Page In-Reply-To: References: Message-ID: Explain better what you try to do. 2010/11/20, Victor Subervi : > Hi; > I need to be able to print something from a Web page: not the entire page > but what I specify. I am writing the page and the client is surfing to it. > How do I do this? > TIA, > beno > -- Enviado desde mi dispositivo m?vil Diego I. Hidalgo D. From ian.g.kelly at gmail.com Sun Nov 21 00:50:14 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 20 Nov 2010 22:50:14 -0700 Subject: building a web interface In-Reply-To: References: Message-ID: On 11/20/2010 3:40 PM, Shel wrote: > So right now I have a mySQL db structure and some Python code. My end > goal is to create a browser-based interactive fiction/game thing. My > code is currently just using dummy data rather than pulling in data > from the db, but I think/hope it won't be too big of a deal to > interact with the db through Python (famous last words...). Suggestion: unless you're intent on reinventing the wheel, why not just set up your web interface as a thin front-end for an existing IF engine? An excellent starting point for this would be digging up the source for InfocomBot [1], an AIM bot that acts as a simple wrapper around Frotz [2]. My recollection of seeing the source once is that it was only around 50 or so lines of code. Doing it this way, 1) You don't have to write an IF engine from scratch. 2) If you wrap Frotz specifically, you can serve any Z-code game ever written, including (I think) all of the Infocom games. 3) You can create your game using powerful existing development tools, such as Inform [3]. Cheers, Ian [1] http://waxy.org/2004/03/infocombot_for/ [2] http://frotz.sourceforge.net/ [3] http://inform7.com/ From navkirats at gmail.com Sun Nov 21 01:08:09 2010 From: navkirats at gmail.com (Navkirat Singh) Date: Sun, 21 Nov 2010 11:38:09 +0530 Subject: Pickling a database cursor? Message-ID: <736F0BEA-6FCC-4BA0-954B-15D4556A40BA@gmail.com> Hi Guys, Is there any way to pickle a database cursor? I would like a persistent cursor over multiple HTTP requests. Any help would be awesome ! Nav From clp2 at rebertia.com Sun Nov 21 01:30:26 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 20 Nov 2010 22:30:26 -0800 Subject: Pickling a database cursor? In-Reply-To: <736F0BEA-6FCC-4BA0-954B-15D4556A40BA@gmail.com> References: <736F0BEA-6FCC-4BA0-954B-15D4556A40BA@gmail.com> Message-ID: On Sat, Nov 20, 2010 at 10:08 PM, Navkirat Singh wrote: > Hi Guys, > > Is there any way to pickle a database cursor? I would like a persistent cursor over multiple HTTP requests. Any help would be awesome ! You can't. It's like a file handle in that respect. Cheers, Chris -- http://blog.rebertia.com From lothiraldan at gmail.com Sun Nov 21 04:35:10 2010 From: lothiraldan at gmail.com (FELD Boris) Date: Sun, 21 Nov 2010 10:35:10 +0100 Subject: Printing from Web Page In-Reply-To: References: Message-ID: <911E277A512742F4A8C0CC8A4336505D@gmail.com> I think the best way to do this is using css with specific media type.Take a look at :?http://martybugs.net/articles/print.cgi --?FELD BorisSent with Sparrow On dimanche 21 novembre 2010 at 03:35, Hidura wrote: Explain better what you try to do.2010/11/20, Victor Subervi : Hi; I need to be able to print something from a Web page: not the entire page but what I specify. I am writing the page and the client is surfing to it. How do I do this? TIA, beno-- Enviado desde mi dispositivo m?vilDiego I. Hidalgo D.-- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From pmilin at ff.uns.ac.rs Sun Nov 21 04:57:29 2010 From: pmilin at ff.uns.ac.rs (Petar Milin) Date: Sun, 21 Nov 2010 10:57:29 +0100 Subject: Is it possible to use Google's advanced search options? In-Reply-To: <4CE82F25.3000805@pythonmeister.com> References: <4CE82F25.3000805@pythonmeister.com> Message-ID: <4CE8ED09.6070706@ff.uns.ac.rs> Hello! Thanks so much for the patched Pygoogle! Also, please, can you give me some more information about how to use google search api? I am a newbie in Python, and I still try to cope with it. Thanks to some experience in other programing languages, I think I progress well, but I am not a professional user/programer; quite far from that. Best, Petar On 20/11/10 21:27, Stefan Sonnenberg-Carstens wrote: > Am 20.11.2010 20:24, schrieb Petar Milin: >> Thanks so much! However, 'options lang:de' does not exactly the same >> as would 'lr=lang_de'? Am I right? > You're right. >> Since I need number of hits, I would like to have the best, most >> correct values! :-) >> >> Sincerely, >> PM >> >> On Sat, Nov 20, 2010 at 12:00 PM, >> wrote: > I took a look into pygoogle source code. > It does not send the 'lr' parameter to google.de (as it does not with > many more ...). > I patched it to enable the following (what you needed): > > >>> from pygoogle import pygoogle > >>> g = pygoogle('linux site:.edu') > >>> g.lr = 'lang_de' > >>> g.pages = 2 > >>> print 'German',g.get_result_count() > German 3910 > >>> g.lr = 'lang_en' > >>> print 'English',g.get_result_count() > English 1140000 > >>> g.lr = 'lang_cn' > >>> print 'Chinese',g.get_result_count() > Chinese 1210000 > >>> > > I have attached my patched version of pygoogle. > BTW: the google search api is very straight forware. > Perhaps it is easier to create a custom bot to do your queries. > Cheers, From pmilin at ff.uns.ac.rs Sun Nov 21 05:01:45 2010 From: pmilin at ff.uns.ac.rs (Petar Milin) Date: Sun, 21 Nov 2010 11:01:45 +0100 Subject: Does Pygoogle allows for advanced search options? In-Reply-To: References: <706ff3ad-66b4-4cdb-a68f-bf0a079c2dc1@32g2000yqz.googlegroups.com> Message-ID: <4CE8EE09.20202@ff.uns.ac.rs> On 20/11/10 22:34, Chris Rebert wrote: > On Thu, Nov 18, 2010 at 3:26 AM, neocortex wrote: > >>> The library doesn't seem to have built-in support for filtering by >>> language (and Google lacks a search query-string-based operator for >>> that), but it looks like you could implement that feature by adding an >>> "lr" parameter with an appropriate value to the query `args` >>> dictionary. See the "lr?" entry under "Web Search Specific Arguments" >>> onhttp://code.google.com/apis/websearch/docs/reference.html, and >>> lines 68& 102 of pygoogle.py. >>> >> From those lines, it can be concluded that lr=lang_?? is not >> supported, unfortunately. >> > Right; that's why I said "you could implement that feature". Pretty > easily it would seem. > Thanks for believing in me ( ;-) ), but I am a newbie in Python world, although with some experience in other prog. languages. So, if I read pygoogle.py well, I sould add lr parameter in init and then after lines 68 and 102? Thanks again! You guys here are very kind and helpful! Best, Petar From stefan.sonnenberg at pythonmeister.com Sun Nov 21 05:51:11 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Sun, 21 Nov 2010 11:51:11 +0100 Subject: Does Pygoogle allows for advanced search options? In-Reply-To: <4CE8EE09.20202@ff.uns.ac.rs> References: <706ff3ad-66b4-4cdb-a68f-bf0a079c2dc1@32g2000yqz.googlegroups.com> <4CE8EE09.20202@ff.uns.ac.rs> Message-ID: <4CE8F99F.9010806@pythonmeister.com> Am 21.11.2010 11:01, schrieb Petar Milin: > > On 20/11/10 22:34, Chris Rebert wrote: >> On Thu, Nov 18, 2010 at 3:26 AM, neocortex wrote: >>>> The library doesn't seem to have built-in support for filtering by >>>> language (and Google lacks a search query-string-based operator for >>>> that), but it looks like you could implement that feature by adding an >>>> "lr" parameter with an appropriate value to the query `args` >>>> dictionary. See the "lr?" entry under "Web Search Specific Arguments" >>>> onhttp://code.google.com/apis/websearch/docs/reference.html, and >>>> lines 68& 102 of pygoogle.py. >>> From those lines, it can be concluded that lr=lang_?? is not >>> supported, unfortunately. >> Right; that's why I said "you could implement that feature". Pretty >> easily it would seem. > Thanks for believing in me ( ;-) ), but I am a newbie in Python world, > although with some experience in other prog. languages. > So, if I read pygoogle.py well, I sould add lr parameter in init and > then after lines 68 and 102? Correct. I just did not read source code enough to realize the parameter is needed twice. You just could hack that out, too :-) Normally (what is normal, anyway ?) it's good practice to create an contructor (__init__) in python which has the most common options as keyword arguments and default values assigned, like so: class Foo: def __init__(self,lr='lang_en',url='http://some.of.this'): self.lr = lr self.url = url ... > > Thanks again! You guys here are very kind and helpful! > Best, > Petar > -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: pygoogle.py URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: stefan_sonnenberg.vcf Type: text/x-vcard Size: 223 bytes Desc: not available URL: From kokososo56 at yahoo.com Sun Nov 21 07:18:03 2010 From: kokososo56 at yahoo.com (soso) Date: Sun, 21 Nov 2010 04:18:03 -0800 (PST) Subject: Download the free and exclusive involvement of Bandon the world's first Internet Security Nod32 Antivirus 4.2.67.10 version of Business Edition Topics Encyclopedia Internet Security / Antivirus**** Message-ID: <2fba81c5-2b34-4064-8310-71e13c67ecce@f20g2000yqi.googlegroups.com> Download the free and exclusive involvement of Bandon the world's first Internet Security Nod32 Antivirus 4.2.67.10 version of Business Edition Topics Encyclopedia Internet Security / Antivirus Download from here http://prosoftantivirus.blogspot.com/2010/11/nod32-antivirus-426710-business-edition.html From martin at address-in-sig.invalid Sun Nov 21 07:51:01 2010 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Sun, 21 Nov 2010 12:51:01 +0000 (UTC) Subject: building a web interface References: Message-ID: On Sat, 20 Nov 2010 17:20:53 -0800, Shel wrote: > Sorry I wasn't clear about the db part. Most of the data has already > been written and/or generated and tested with the code. I do plan to > finish all the database stuff before going to the front end, but am just > thinking ahead about how to do the interface. > That sounds good. Sorry if I was repeating stuff you already know, but it wasn't obvious what you knew about care & feeding of an RDBMS. I'll just add two comments on databases: - Decompose the database design to 3NF form and make sure all prime and foreign keys have indexes. This is stuff that previous experience shows self-taught Access users don't do. Not doing it will bite you hard on performance as soon as the tables exceed a few rows in size. Fixing it later can force major changes to the programs as well. - If you haven't looked at it yet, find out about the EXPLAIN verb and what its output means. Use it on all queries that your online program issues and take notice of how rearranging the query and/or adding/changing indexes affects the cost of the query. Lower cost queries mean higher performance and hence faster response times. What I meant to add last night is that, if your application is to be used by more than a single user at a time a prime consideration is how you will recognise input received from each user and how you'll store their context between interactions with them in the same session and keep each session's context separate. The web server doesn't do this, so this managing session context is the application's responsibility. Common methods are to use a session cookie and/or to store session context in the database. -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From victorsubervi at gmail.com Sun Nov 21 09:03:45 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Sun, 21 Nov 2010 10:03:45 -0400 Subject: Printing from Web Page In-Reply-To: <911E277A512742F4A8C0CC8A4336505D@gmail.com> References: <911E277A512742F4A8C0CC8A4336505D@gmail.com> Message-ID: On Sun, Nov 21, 2010 at 5:35 AM, FELD Boris wrote: > I think the best way to do this is using css with specific media type. > Take a look at : http://martybugs.net/articles/print.cgi > Oh, man, this is perfect! Thanks! beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From ayaafarag at gmail.com Sun Nov 21 10:06:04 2010 From: ayaafarag at gmail.com (ayaa) Date: Sun, 21 Nov 2010 07:06:04 -0800 (PST) Subject: Questions about optmodel constraints Message-ID: <46188e2b-ff0f-41cd-a071-57c1eb4bbb52@k3g2000vbp.googlegroups.com> I have three questions: 1. If I have a variable that is stored in a data set and I want to formulate only one constraint (under optmodel) that is a function of all the data set's observations of this variable and a decision variable. Suppose the variable is a and x is the decision variable. My constraint is: [(maximum value of a) +x ] / [(minimum value of a) +x ] < maximum value of (a) / minimum value of (a), can you help me to include this constraint under optmodel? 2. If there is one scalar number that is a result of certain calculations and the it is stored in a dataset and I want to equate a constraint with this scalar, can you help me to do this? 3. If there is one scalar number that is a result of certain calculations and it is stored in a dataset and I want to include this scalar in "sum" operator. Suppose there are also two stored variables that are a and b, and x is a decision variable and the scalar is c, I want c to appear as in the following constraint: sum over i for [ c*(ai)^2 * bi/ (ai+x)] = 0.5 , can you help me to do this under optmodel? Thanks Ayaa From usenet at ffconsultancy.com Sun Nov 21 10:25:08 2010 From: usenet at ffconsultancy.com (Jon Harrop) Date: Sun, 21 Nov 2010 15:25:08 -0000 Subject: Scheme as a virtual machine? In-Reply-To: <20101014052650.510e8833@tritium.streitmacht.eu> References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com><20101014020136.6e85d70b@tritium.streitmacht.eu> <20101014052650.510e8833@tritium.streitmacht.eu> Message-ID: "Ertugrul S?ylemez" wrote in message news:20101014052650.510e8833 at tritium.streitmacht.eu... > That's nonsense. Actually namekuseijin is right. You really need to persevere and familiarize yourself with some of the other languages out there. Haskell is many things but simple is not one of them. If Haskell were half of the things you think it is, it would have more credible success stories. Cheers, Jon. From emile at fenx.com Sun Nov 21 12:16:14 2010 From: emile at fenx.com (Emile van Sebille) Date: Sun, 21 Nov 2010 09:16:14 -0800 Subject: Inserting class namespace into method scope In-Reply-To: <4ce86efc$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4ce7e269$0$29991$c3e8da3$5496439d@news.astraweb.com> <87wro78xml.fsf@benfinney.id.au> <4ce86efc$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 11/20/2010 4:59 PM Steven D'Aprano said... > On Sun, 21 Nov 2010 08:59:30 +1100, Ben Finney wrote: > >> C'mon, Steven, you know the drill. If you want us to help you solve a >> problem, don't start with ?I want to use this behaviour that seems >> loony, and I won't say why?. Instead, help us by telling us what problem >> you're trying to solve. > > Well, I tried the TL;DR version. Now you have to read the full version. > > Inspired by the last maxim of the Zen: > > "Namespaces are one honking great idea -- let's do more of those!" Hmm... while playing with various takes on globals and code blocks I came across this that may be of interest. http://www.voidspace.org.uk/python/articles/code_blocks.shtml Emile From aahz at pythoncraft.com Sun Nov 21 13:30:06 2010 From: aahz at pythoncraft.com (Aahz) Date: 21 Nov 2010 10:30:06 -0800 Subject: is list comprehension necessary? References: <4cc701e7$0$1606$742ec2ed@news.sonic.net> Message-ID: In article <4cc701e7$0$1606$742ec2ed at news.sonic.net>, John Nagle wrote: > >Python isn't a functional language. It has some minimal functional >capabilities, and there's a lobby that would like more. So far, that's >mostly been resisted. Attempts to allow multiline lambdas have been >averted. The weird "functional if" syntax additions were a cave-in to >the functional crowd, and may have been a mistake. Did you actually read the PEP explanation for *why* Guido decided to add conditional expressions? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Look, it's your affair if you want to play with five people, but don't go calling it doubles." --John Cleese anticipates Usenet From pmilin at ff.uns.ac.rs Sun Nov 21 14:35:03 2010 From: pmilin at ff.uns.ac.rs (Petar Milin) Date: Sun, 21 Nov 2010 20:35:03 +0100 Subject: Does Pygoogle allows for advanced search options? Message-ID: <4CE97467.7090308@ff.uns.ac.rs> Hello ALL! I am playing with the modified version of the Pygoogle (by Stefan). Interesting thing is that get_result_count() gives numbers/results different from those in Google. Has anyone checked this? Does anyone know why? Best, Petar From jakub.vysoky at gmail.com Sun Nov 21 14:39:33 2010 From: jakub.vysoky at gmail.com (kvbik) Date: Sun, 21 Nov 2010 11:39:33 -0800 (PST) Subject: multiple times subprocess fails on windows Message-ID: Hello, in a test suite in my project (called rvirtualenv [1]) I discovered a strange behaviour when calling from python a batch file which calles another python and this calles a shell command. [1] http://github.com/kvbik/rvirtualenv I know it sounds pretty strange, but I do this only because I am testing such specific tool (that has similar functionality like original virtualenv and there are things like activate.bat commands). I've uploaded some code snippet here: https://gist.github.com/709004/6ccc44d6aed5fe694bb2adbef2400bbea92998a1 If anyone could explain me this behaviour I would be more than happy, because right now it is the only failing test in my project ;). Thanks in advance, Jakub.. From nagle at animats.com Sun Nov 21 14:43:11 2010 From: nagle at animats.com (John Nagle) Date: Sun, 21 Nov 2010 11:43:11 -0800 Subject: Pickling a database cursor? In-Reply-To: References: <736F0BEA-6FCC-4BA0-954B-15D4556A40BA@gmail.com> Message-ID: <4ce97658$0$1669$742ec2ed@news.sonic.net> On 11/20/2010 10:30 PM, Chris Rebert wrote: > On Sat, Nov 20, 2010 at 10:08 PM, Navkirat Singh > wrote: >> Hi Guys, >> >> Is there any way to pickle a database cursor? I would like a >> persistent cursor over multiple HTTP requests. Any help would be >> awesome ! > > You can't. It's like a file handle in that respect. > > Cheers, Chris -- http://blog.rebertia.com I've seen several related questions on this from the same person. A few hints: I suspect that what you're trying to do is to display a sequence of records from a database in page-sized groups. There's a way to do that. In SQL, look into the OFFSET and LIMIT clauses. The idea is that if you want the first 10 entries, your SQL statement has OFFSET 0 and LIMIT 10. For the next 10, you use OFFSET 10 and LIMIT 10, and so on. For this to work, your SQL statement needs a ORDER BY clause, so the records come out in the same order each time. And you need to define an INDEX on the fields used in the ORDER BY clause, or the database engine has to sort the file every time, which is really slow. The usual way to do this with web pages is to use REST-type parameters in the URL. So you'll have a URL like http://www.example.com/cgi/getrecords.cgi?q=customerid&offset=0&limit=10 On the pages you return, you put URLs for "next page" (with a bigger offset) and "previous page" (with a smaller offset). That way, the user can move forwards and backwards through the pages. You have to read those parameters from the URL and put them into the SQL. (For OFFSET and LIMIT, you have to edit those parameters into the SQL string itself, because those numbers aren't placed in quotes. You can't use the second parameter to cursor.execute for this. So, when you fetch those parameters, convert them to numbers with "int(s)" before putting them into the SQL statement. Otherwise, you'll have an SQL injection vulnerability.) Page through some Google search results and watch how the URLs change. That's how Google does it. Don't use cookies for position information. The browser's "Back" button won't do what users expect if you do that. John Nagle From gtmacdonald at gmail.com Sun Nov 21 15:43:33 2010 From: gtmacdonald at gmail.com (Greg MacDonald) Date: Sun, 21 Nov 2010 12:43:33 -0800 Subject: Strange affinity side effect with multiprocessing. Message-ID: Hi Everyone, I'm having a strange problem with the multiprocessing package and Panda3D. Importing panda modules causes multiprocessing to only use one of my cores. I've created an example test case. It uses an infinite loop to ping the cores so you'll have to manually kill the python processes. So if I run the following I can see in my task manager that both cores are at 100%. Code: #from pandac.PandaModules import Point2 from multiprocessing import Pool def dummyWorker(a): while True: continue class DummyTester(object): def __init__(self): self.pool = Pool(2) def go(self): result = self.pool.map_async(dummyWorker, range(2)) result.get() if __name__ == "__main__": DummyTester().go() But if I uncomment out that one line there it only uses one of my cores. This is with a fresh download of panda 1.7.0 on windows xp, python 2.6, and intel core2 duo. I'm completely at a loss so any thoughts would be greatly appreciated. Thx. -Greg From stefan.sonnenberg at pythonmeister.com Sun Nov 21 15:45:26 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Sun, 21 Nov 2010 21:45:26 +0100 Subject: Does Pygoogle allows for advanced search options? In-Reply-To: <4CE97467.7090308@ff.uns.ac.rs> References: <4CE97467.7090308@ff.uns.ac.rs> Message-ID: <4CE984E6.1050605@pythonmeister.com> Am 21.11.2010 20:35, schrieb Petar Milin: > Hello ALL! > I am playing with the modified version of the Pygoogle (by Stefan). > Interesting thing is that get_result_count() gives numbers/results > different from those in Google. Has anyone checked this? Does anyone > know why? > > Best, > Petar > AFAIK there are several reports which point to the same observation; even time & location (requesting IP) seem to generate different results. -------------- next part -------------- A non-text attachment was scrubbed... Name: stefan_sonnenberg.vcf Type: text/x-vcard Size: 232 bytes Desc: not available URL: From pmilin at gmail.com Sun Nov 21 16:07:50 2010 From: pmilin at gmail.com (Petar Milin) Date: Sun, 21 Nov 2010 22:07:50 +0100 Subject: Does Pygoogle allows for advanced search options? In-Reply-To: <4CE984E6.1050605@pythonmeister.com> References: <4CE97467.7090308@ff.uns.ac.rs> <4CE984E6.1050605@pythonmeister.com> Message-ID: <1290373670.22702.6.camel@Nokia-N900-51-1> So, what can one do about this? There seems to be at least two aspects: (a) difference between browser-based and script-based (pygoogle in this case) query, and (b) difference in time and place, but possibly within the same query type. If so, how can we be sure? It would be interesting (at least to me) to check for the correlations between numbers. That would answer whether there is some/any consistency. Best, Petar ----- Original message ----- > Am 21.11.2010 20:35, schrieb Petar Milin: > > Hello ALL! > > I am playing with the modified version of the Pygoogle (by Stefan). > > Interesting thing is that get_result_count() gives numbers/results > > different from those in Google. Has anyone checked this? Does anyone > > know why? > > > > Best, > > Petar > > > AFAIK there are several reports which point to the same observation; > even time & location (requesting IP) seem to generate different results. > > ? stefan_sonnenberg.vcf -------------- next part -------------- An HTML attachment was scrubbed... URL: From joralemonshelly at gmail.com Sun Nov 21 18:03:49 2010 From: joralemonshelly at gmail.com (Shel) Date: Sun, 21 Nov 2010 15:03:49 -0800 (PST) Subject: building a web interface References: Message-ID: Definitely not looking to reinvent the wheel. Will check these out, thanks! Shel On Nov 20, 9:50?pm, Ian Kelly wrote: > On 11/20/2010 3:40 PM, Shel wrote: > > > So right now I have a mySQL db structure and some Python code. My end > > goal is to create a browser-based interactive fiction/game thing. My > > code is currently just using dummy data rather than pulling in data > > from the db, but I think/hope it won't be too big of a deal to > > interact with the db through Python (famous last words...). > > Suggestion: unless you're intent on reinventing the wheel, why not just > set up your web interface as a thin front-end for an existing IF engine? > ? An excellent starting point for this would be digging up the source > for InfocomBot [1], an AIM bot that acts as a simple wrapper around > Frotz [2]. ?My recollection of seeing the source once is that it was > only around 50 or so lines of code. ?Doing it this way, > > 1) You don't have to write an IF engine from scratch. > > 2) If you wrap Frotz specifically, you can serve any Z-code game ever > written, including (I think) all of the Infocom games. > > 3) You can create your game using powerful existing development tools, > such as Inform [3]. > > Cheers, > Ian > > [1]http://waxy.org/2004/03/infocombot_for/ > [2]http://frotz.sourceforge.net/ > [3]http://inform7.com/ From aaronasterling at gmail.com Sun Nov 21 18:04:55 2010 From: aaronasterling at gmail.com (Aaron Sterling) Date: Sun, 21 Nov 2010 15:04:55 -0800 (PST) Subject: constructin trees in python References: <3c926050-5e27-4efb-bf76-dbd1f2412810@o14g2000yqe.googlegroups.com> Message-ID: <973d6837-e84e-40c0-94a3-205efbe30a0f@g25g2000yqn.googlegroups.com> > Thanks a lot peter, that worked as i needed. Where can i find some > good documentation which explains such behavior. The reason for this behavior is the way python stores attributes. Both a class and an instance of a class have a __dict__ attribute which is a dictionary which stores attributes in name value pairs. Consider the following class. class A(object): a = 1 def __init__(self, b): self.b = b Inspecting A.__dict__, one will see that it looks like {'a': 1} with no reference to b. Instantiating with a = A(2), one will see that a.__dict__ is {'b': 2} with no reference to a. If one accesses a.b, then Python will first look in a.__dict__ and find 'b'. It will then return that value for a.b If one instead accesses a.a then Python will first look in a.__dict__ and not find an entry for 'a'. It will then look in type(a).__dict__ == A.__dict__, find 'a' and return it for a.a One can in fact use this behavior to shadow class attributes. If the __init__ function is changed to def __init__(self, a, b): self.a = a self.b = b then all instances of A will have their own instance attribute named a with whatever value is passed to __init__. They will still have a class level attribute named a with value 1 but Python will never see it because it will find an entry for a in some_instance.__dict__. If one executes del some_instance.a Then on that one instance, visibility for the class level a will be restored. In fact, one can always get the class level instance as type(some_instance).__dict__['a'] but that's a little awkward. The reason that this matters with mutable attributes and not with (often) with immutable attributes is that a statement of the form some_instance.some_mutable_attribute.append(foo) will reference the same class level attribute regardless of the instance it's called with. There's no assignment going on here. An existing binding is being looked up, and the resulting value (a list in this case) is having an attribute called on it. No new bindings are being created. A statement of the form some_instance.some_mutable_attribute = some_new_list Will not affect the class level attribute at all but will simply shadow it in the same manner as describe above. Once a name is bound to an immutable value, the only way to change the value that it points to is to rebind it. This means that any 'change' to a class level immutable value (accessed through attribute lookup on an instance) will simply shadow it on the instance upon which it is accessed. HTH From joralemonshelly at gmail.com Sun Nov 21 18:40:10 2010 From: joralemonshelly at gmail.com (Shel) Date: Sun, 21 Nov 2010 15:40:10 -0800 (PST) Subject: building a web interface References: Message-ID: <16bc6e60-ad98-4d81-9f20-23e9b52eea21@n30g2000vbb.googlegroups.com> No worries at all about repeating things. I wasn't clear, and I appreciate your going to the trouble of teaching me just about anything. Even things I think I know, I might not really know :-) Let's see... am okay with the relational design stuff. Thanks for the "EXPLAIN" verb. I am confused about multiple simultaneous users, which I would like to be able to accommodate. On the db side, I have a structure to store data for each user, and know a bit about selectively locking data, although I have not implemented that yet, so will see what happens. I don't really get how multiple users work in terms of pretty much everything else, like if the Python code is running on the server, then... well, I just don't know. Maybe I should try to get it running for multiple discrete users first, and then think about simultaneous users, or is that a bad way to go about things? Or maybe it will start to make more sense when I get into building the interface? Any info/suggestions are very welcome. Thanks again! Shel On Nov 21, 4:51?am, Martin Gregorie wrote: > On Sat, 20 Nov 2010 17:20:53 -0800, Shel wrote: > > Sorry I wasn't clear about the db part. ?Most of the data has already > > been written and/or generated and tested with the code. ?I do plan to > > finish all the database stuff before going to the front end, but am just > > thinking ahead about how to do the interface. > > That sounds good. Sorry if I was repeating stuff you already know, but it > wasn't obvious what you knew about care & feeding of an RDBMS. I'll just > add two comments on databases: > - Decompose the database design to 3NF form and make sure all prime > ? and foreign keys have indexes. This is stuff that previous experience > ? shows self-taught Access users don't do. Not doing it will bite you > ? hard on performance as soon as the tables exceed a few rows in size. > ? Fixing it later can force major changes to the programs as well. > > - If you haven't looked at it yet, find out about the EXPLAIN verb > ? and what its output means. Use it on all queries that your online > ? program issues and take notice of how rearranging the query and/or > ? adding/changing indexes affects the cost of the query. Lower cost > ? queries mean higher performance and hence faster response times. > > What I meant to add last night is that, if your application is to be used > by more than a single user at a time a prime consideration is how you > will recognise input received from each user and how you'll store their > context between interactions with them in the same session and keep each > session's context separate. The web server doesn't do this, so this > managing session context is the application's responsibility. Common > methods are to use a session cookie and/or to store session context in > the database. > > -- > martin@ ? | Martin Gregorie > gregorie. | Essex, UK > org ? ? ? | From joralemonshelly at gmail.com Sun Nov 21 18:42:09 2010 From: joralemonshelly at gmail.com (Shel) Date: Sun, 21 Nov 2010 15:42:09 -0800 (PST) Subject: building a web interface References: Message-ID: <6ae91df9-7a93-4d70-a60d-82973d7d6295@v23g2000vbi.googlegroups.com> Just want to say thanks again to everyone who responded to this post. You have all been really helpful. From irmen.NOSPAM at xs4all.nl Sun Nov 21 18:54:30 2010 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Mon, 22 Nov 2010 00:54:30 +0100 Subject: [ANN] Pyro 3.11 released Message-ID: <4ce9b13a$0$81485$e4fe514c@news.xs4all.nl> Hi, Pyro 3.11 has been released! Pyro is a an advanced and powerful Distributed Object Technology system written entirely in Python, that is designed to be very easy to use. Have a look at http://www.xs4all.nl/~irmen/pyro3/ for more information. Highlights of this release are: - improved compatibility with Jython - fixed some threading problems regarding proxy connections - fixed a threading issue that could break COM calls - persistent mode nameserver improved As always the detailed changes are in the change log chapter in the manual. More info and download link available in PyPI: http://pypi.python.org/pypi/Pyro/ Enjoy, Irmen de Jong From martin at address-in-sig.invalid Sun Nov 21 21:10:26 2010 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Mon, 22 Nov 2010 02:10:26 +0000 (UTC) Subject: building a web interface References: <16bc6e60-ad98-4d81-9f20-23e9b52eea21@n30g2000vbb.googlegroups.com> Message-ID: On Sun, 21 Nov 2010 15:40:10 -0800, Shel wrote: > I am confused about multiple simultaneous users, which I would like to > be able to accommodate. On the db side, I have a structure to store > data for each user, and know a bit about selectively locking data, > although I have not implemented that yet, so will see what happens. > I realise what I wrote last night wasn't all that clear. Terms: 'transaction' and 'session'. A web server 'transaction' consists of a request from a user that results in a page being sent to the user. That's it. It is an isolated action that does not depend in the web server knowing anything about the user because all the information it needs to decide which page to send was supplied when the user sent in the URL of the page. Now if the user clicks on a link on that page, his browser sends the URL in the link to the server, which in turn fishes out another page and sends it back to the user. As far as the server is concerned, there is no connection whatever between the two requests: either or both URLs could have been copied from a piece of paper for all it knows or cares. There is no concept of context or a session involved. A 'session' involves context. Think of what happens when you login to a computer. That starts a login session that has context: the computer now knows who you are and provides context by connecting you to your login directory and opening some work space which is used to remember which directory you're in, what commands you issued (so you can look at the history), etc. The session and its context persists until you log out. In what you're intending to do, a user will start a session by starting to use your program and that session will last until the user disconnects from the session. All the web server knows is that instead of finding a page on disk some place it passes your user's request to your program and sends its output, in the form of a web page, back to the user. It does this each time it receives a request from the user because all the user's requests contain the same URL - that of your program. The server does this without knowing there is such a thing as a session or that there is any context belonging to the user. The upshot is that your program has to keep track of all the active sessions and maintain context for each active session. It also needs a way to recognise and get rid of dead sessions because sessions don't always end cleanly: the line may go down or the user may forget he was using your program and turn his PC off. For instance, if the session context has a timestamp, you might delete it after, say, 20 hours of inactivity, or when the user logs on again. If the data is sensitive, you might also force a new logon after 10 minutes of inactivity. The database is as good a place as any for keeping session and context data - if its well structured the context may well form a single (large) row on one table, but you do need a unique key for it. That could even be the login name provided you're able to include it in every page you send to the user and can guarantee that the browser will send it back as part of the next request. A hidden field on the page will do this automatically. The basic program cycle will be: - receive a request - read the context for the session - use data in the request to carry out the requested action - write the updated context back to the database - create the output page and send it to the user though of course you need additional dialogue to deal with both valid and invalid logons and logoffs. > I don't really get how multiple users work in terms of pretty much > everything else, like if the Python code is running on the server, > then... well, I just don't know. > Hopefully the above made it a bit clearer. > Maybe I should try to get it running > for multiple discrete users first, and then think about simultaneous > users, or is that a bad way to go about things? Or maybe it will start > to make more sense when I get into building the interface? Any > info/suggestions are very welcome. > For bare desktop development I would split the program into three parts: 1) the program itself, written to run a single transaction each time its called. Inputs would be the bits of the users message it needs to act on and the current session context record. 2) a testing harness that accepts user input from the console, sends output back to the console and maintains a single session context record in memory: IOW it runs your program in single user mode. 3)the web server interface which retrieves the session context record, passes it and the input to your program and, after that has run, saves the session context record and passes the output to the web server for delivery to the user. This way both 2 and 3 can be developed against a really simple 'do almost nothing' version of 1 while that in turn can be developed and tested on your desktop using 2 and later be dropped into the web server with 3 as its interface. I have an in-house copy of Apache that I'd use to develop your type of program. Its used for all my website development so that nothing gets loaded onto my public sites until its been properly checked out here. You can do the same if you can find and install a really simple web server that would run on your PC together with a local copy of MySQL - of course! Given this setup you can use your usual web browser to talk to the local web server. If you can run all that you won't need 2 because you can have your simple web server and program running in a console window on your desktop PC while you hammer it from your web browser. -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From navasia at gmail.com Sun Nov 21 21:35:57 2010 From: navasia at gmail.com (navasia at gmail.com) Date: Sun, 21 Nov 2010 18:35:57 -0800 (PST) Subject: How to open html page in python resource file? ActiveX and Java script addEventListener? Options Message-ID: <615b0ae8-3350-4940-a79d-a3c5ff388362@k5g2000vbn.googlegroups.com> Hi friends, I have an interesting question. Is it possible to open HTML page from python resources (Sorry, I don't know how to use the resources) like we can open using Win32 from .rc files. Can that page contain references to scrips in the resource file? Another question is reagrding ActiveX on win32. ActiveX usually calls Java Script function to notify. In webpage we can add it using document.addeventlistener but those are not available using CallFunction method of ActiveX. But if we decided to use it directly (without web browser) then how can we register Listeners? There must be some way to specify the listeners. Thanks in Advance. From maxim.mercury at gmail.com Sun Nov 21 22:12:43 2010 From: maxim.mercury at gmail.com (Maxim Mercury) Date: Sun, 21 Nov 2010 19:12:43 -0800 (PST) Subject: strings getting unnecessarily cut in lstrip Message-ID: I was using the lstrip to trim the left occurance of a string, and it didnt seem to work for some cases. but when i investigated there does seem to be an issue with some combination of strings here is one case p1 = "abcd" p2 = 'def' # $abc sym = '_' str1 = p1 + sym + p2 str1 = str1.lstrip(p1+sym) print str1 # this prints ef instead of def can someone explain why this is happening ? From steve at holdenweb.com Sun Nov 21 22:26:49 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 21 Nov 2010 22:26:49 -0500 Subject: strings getting unnecessarily cut in lstrip In-Reply-To: References: Message-ID: On 11/21/2010 10:12 PM, Maxim Mercury wrote: > I was using the lstrip to trim the left occurance of a string, and it > didnt seem to work for some cases. but when i investigated there does > seem to be an issue with some combination of strings > here is one case > p1 = "abcd" > p2 = 'def' # $abc > sym = '_' > str1 = p1 + sym + p2 > str1 = str1.lstrip(p1+sym) > print str1 # this prints ef instead of > def > > can someone explain why this is happening ? It's happening because the argument specifies a set of characters, not a string. So the "d" of "def" is removed because there's a "d" in "abcd_". If you want to remove a string, try testing is with its .startswith() method and them removing the right number of characters. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From timr at probo.com Sun Nov 21 23:25:52 2010 From: timr at probo.com (Tim Roberts) Date: Sun, 21 Nov 2010 20:25:52 -0800 Subject: CGI FieldStorage instances? References: <1ec25d72-a99e-4fd9-9d50-1ac8c65812e9@z19g2000yqb.googlegroups.com> Message-ID: <6trje65kt71v00339psntb6srgr5qtls5c@4ax.com> Gnarlodious wrote: > >I'm having a hard time understanding this, can someone explain? > >Running a CGI with query string: > >?action=Find&page=Data > >Script includes these lines: > >form=cgi.FieldStorage(keep_blank_values=1) >print("Content-type:text/html\n\n") >print(cgi.print_form(form)) > >Output: > >Form Contents: > >action: >MiniFieldStorage('action', 'Find') >page: >MiniFieldStorage('page', 'Data') > >It looks like every variable in the query string instantiates a >MiniFieldStorage with that value, is that the case? Yes, unless it's a "file" type, then it is a full FieldStorage. >And if so, what >sort of cool tricks could I do with that feature? Because so far I am >doing CGI and it is a big old mess. Intercepting every variable is >complicated and confusing. Is there an easier way? Have you looked at the source code? That's the beauty of Python. It's all exposed for you. MiniFieldStorage has a .name attribute and a .value attribute. So, for example: print form['action'].value print form['page'].value If you're not sure whether the value will be specified: if 'action' in form: action = form['action'].value -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From es at ertes.de Sun Nov 21 23:38:53 2010 From: es at ertes.de (Ertugrul =?UTF-8?B?U8O2eWxlbWV6?=) Date: Mon, 22 Nov 2010 05:38:53 +0100 Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014020136.6e85d70b@tritium.streitmacht.eu> <20101014052650.510e8833@tritium.streitmacht.eu> Message-ID: <20101122053853.6ec5be33@tritium.streitmacht.eu> "Jon Harrop" wrote: > "Ertugrul S?ylemez" wrote in message > news:20101014052650.510e8833 at tritium.streitmacht.eu... > > > That's nonsense. > > Actually namekuseijin is right. You really need to persevere and > familiarize yourself with some of the other languages out > there. Haskell is many things but simple is not one of them. If > Haskell were half of the things you think it is, it would have more > credible success stories. Jon, I don't care about your opinion, because it's biased. If you were to advocate Haskell in any way, you would lose money. So you must fight it where possible. This makes all your postings about Haskell (and many other languages) meaningless and reading them a waste of time. Haskell is a simple language with a comparably small specification. It's not as simple as Common Lisp, but it's simple. Note that simple doesn't mean easy. Haskell is certainly more difficult to learn than other languages, which explains the low number of success stories. On the other hand, I'm doing rapid web development in it. After all there aren't many CL success stories either, but Paul Graham's story [1] speaks for itself. [1] http://www.paulgraham.com/avg.html Greets, Ertugrul -- nightmare = unsafePerformIO (getWrongWife >>= sex) http://ertes.de/ From steve at holdenweb.com Sun Nov 21 23:57:21 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 21 Nov 2010 23:57:21 -0500 Subject: Scheme as a virtual machine? In-Reply-To: <20101122053853.6ec5be33@tritium.streitmacht.eu> References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014020136.6e85d70b@tritium.streitmacht.eu> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> Message-ID: On 11/21/2010 11:38 PM, Ertugrul S?ylemez wrote: > "Jon Harrop" wrote: > >> "Ertugrul S?ylemez" wrote in message >> news:20101014052650.510e8833 at tritium.streitmacht.eu... >> >>> That's nonsense. >> >> Actually namekuseijin is right. You really need to persevere and >> familiarize yourself with some of the other languages out >> there. Haskell is many things but simple is not one of them. If >> Haskell were half of the things you think it is, it would have more >> credible success stories. > > Jon, I don't care about your opinion, because it's biased. If you were > to advocate Haskell in any way, you would lose money. So you must fight > it where possible. This makes all your postings about Haskell (and many > other languages) meaningless and reading them a waste of time. > > Haskell is a simple language with a comparably small specification. > It's not as simple as Common Lisp, but it's simple. Note that simple > doesn't mean easy. Haskell is certainly more difficult to learn than > other languages, which explains the low number of success stories. On > the other hand, I'm doing rapid web development in it. > > After all there aren't many CL success stories either, but Paul Graham's > story [1] speaks for itself. > > [1] http://www.paulgraham.com/avg.html > Perhaps we could take this thread to alt.small.minded.bickering now? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at REMOVE-THIS-cybersource.com.au Mon Nov 22 01:26:34 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 22 Nov 2010 06:26:34 GMT Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014020136.6e85d70b@tritium.streitmacht.eu> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> Message-ID: <4cea0d1a$0$29991$c3e8da3$5496439d@news.astraweb.com> On Sun, 21 Nov 2010 23:57:21 -0500, Steve Holden wrote: > Perhaps we could take this thread to alt.small.minded.bickering now? Alas, my ISP doesn't carry that newsgroup. Where else can I get my mindless off-topic bitching if not for cross-posts from comp.lang.scheme and comp.lang.functional? *wink* -- Steven From enleverLesX_XXmcX at XmclavXeauX.com.invalid Mon Nov 22 01:27:04 2010 From: enleverLesX_XXmcX at XmclavXeauX.com.invalid (Michel Claveau - MVP) Date: Mon, 22 Nov 2010 07:27:04 +0100 Subject: How to open html page in python resource file? ActiveX and Javascript addEventListener? Options References: <615b0ae8-3350-4940-a79d-a3c5ff388362@k5g2000vbn.googlegroups.com> Message-ID: <4cea0d39$0$7719$ba4acef3@reader.news.orange.fr> Hello! You will find (positive) answers in PyWin32 and his examples. @-salutations -- Michel Claveau From torriem at gmail.com Mon Nov 22 01:57:15 2010 From: torriem at gmail.com (Michael Torrie) Date: Sun, 21 Nov 2010 23:57:15 -0700 Subject: is list comprehension necessary? In-Reply-To: References: <2e4594a9-d39c-4bad-bf45-6204350f249d@k22g2000yqh.googlegroups.com> Message-ID: <4CEA144B.8070604@gmail.com> On 10/27/2010 05:37 AM, Roy Smith wrote: > I agree. I resisted LCs when they first came out, passing them off as > unnecessary, confusing, etc. Eventually, I came to be comfortable with > them and use them often. I do use LCs fairly often, but only then a for loop would be ugly or inefficient. In many cases, I find a normal for loop often is clearer. Basically I'm saying that you can over-use LCs. And sometimes LCs only serve to make code harder to read. Just because you can use an LC doesn't always mean you should. But of course that's just my opinion. From brian.mingus at Colorado.EDU Mon Nov 22 02:19:17 2010 From: brian.mingus at Colorado.EDU (Brian J Mingus) Date: Mon, 22 Nov 2010 00:19:17 -0700 Subject: is list comprehension necessary? In-Reply-To: References: Message-ID: On Tue, Oct 26, 2010 at 3:31 AM, Xah Lee wrote: > ... No, list comprehensions are not "nececessary", just like the plethora of expletives in the majority of your OPs on this list are not necessary. The question is are they useful, and the answer is the case of list comprehensions is obviously yes, whereas in the case of the expletives you love to spew everywhere the answer is no. Framing, young grasshopper. Framing. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dimos_anastasiou at yahoo.com Mon Nov 22 03:20:34 2010 From: dimos_anastasiou at yahoo.com (Dimos) Date: Mon, 22 Nov 2010 00:20:34 -0800 (PST) Subject: Weibull distr. random number generation In-Reply-To: <71b9f476-087f-455e-a587-69cd812feea8@j9g2000vbl.googlegroups.com> Message-ID: <504343.18748.qm@web111717.mail.gq1.yahoo.com> Hello Mark, Exactly, thanks very much! Dimos --- On Sat, 11/20/10, Mark Dickinson wrote: > From: Mark Dickinson > Subject: Re: Weibull distr. random number generation > To: python-list at python.org > Date: Saturday, November 20, 2010, 7:09 PM > On Nov 19, 3:21?pm, Dimos > wrote: > > I would like to use the random module, and if I > understand well the Random class, to create ?1300 decimal > numbers in python, by providing the 2 Weibull parameters > (b,c). How this can be done??? > > > > import random > > print random > > random.weibullvariate(b,c) > > How can I set the population size n=1300 in decimals? > > random.weibullvariate(b, c) generates a single sample from > the > specified Weibull distribution.? If you want 1300 > samples, you'd use > this within a loop.? For example, here's code to put > 10 Weibull > variates with scale parameter 12345.0 and shape parameter > 6.0 into a > list: > > >>> import random > >>> samples = [] > >>> for i in xrange(10): > ...? > ???samples.append(random.weibullvariate(12345.0, > 6.0)) > ... > >>> print samples > [15553.186762792948, 14304.175032317309, > 9015.5053691933044, > 12585.469181732506, 9436.2677219460638, 13350.89758791281, > 5687.4330250037565, 12172.747202474553, > 9687.8685933610814, > 11699.040541029028] > > A more experienced Python programmer might use a list > comprehension to > achieve the same effect in a single line: > > >>> samples = [random.weibullvariate(12345.0, 6.0) > for _ in xrange(10)] > >>> print samples > [10355.396846416865, 14689.507803932587, > 11491.850991569485, > 14128.56397290655, 12592.739991974759, 9076.7752548878998, > 11868.012238422616, 12016.784656753523, > 14724.818462506191, > 13253.477389116439] > > Is this the sort of thing you were looking for? > > -- > Mark > -- > http://mail.python.org/mailman/listinfo/python-list > From matlab.dude at mbnet.fi Mon Nov 22 03:47:50 2010 From: matlab.dude at mbnet.fi (MATLABdude) Date: Mon, 22 Nov 2010 00:47:50 -0800 (PST) Subject: MATLAB to Python? References: <74f276c3-38a4-4df0-af39-7b1f2a81472e@c39g2000yqi.googlegroups.com> <878w0s2uwv.fsf@gmail.com> Message-ID: <525ad586-d4fe-484a-9f9e-74b0e0fd78d4@s4g2000yql.googlegroups.com> On Nov 17, 10:53?am, Arnaud Delobelle wrote: > I guess that the step is supposed to be h, so you should write: > ? ? xx = range(-kappa, kappa+1, h) This is what I have in the source code: ---8<---8<---8<---8<--- h = 0.105069988414 xx = range(-kappa, kappa+1, h) ---8<---8<---8<---8<--- This is what Python says: ValueError: range() step argument must not be zero Can step not be a float value? From clp2 at rebertia.com Mon Nov 22 04:05:21 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 22 Nov 2010 01:05:21 -0800 Subject: MATLAB to Python? In-Reply-To: <525ad586-d4fe-484a-9f9e-74b0e0fd78d4@s4g2000yql.googlegroups.com> References: <74f276c3-38a4-4df0-af39-7b1f2a81472e@c39g2000yqi.googlegroups.com> <878w0s2uwv.fsf@gmail.com> <525ad586-d4fe-484a-9f9e-74b0e0fd78d4@s4g2000yql.googlegroups.com> Message-ID: On Mon, Nov 22, 2010 at 12:47 AM, MATLABdude wrote: > On Nov 17, 10:53?am, Arnaud Delobelle wrote: >> I guess that the step is supposed to be h, so you should write: >> ? ? xx = range(-kappa, kappa+1, h) > > This is what I have in the source code: > ---8<---8<---8<---8<--- > h = ?0.105069988414 > xx = range(-kappa, kappa+1, h) > ---8<---8<---8<---8<--- > > This is what Python says: ValueError: range() step argument must not > be zero > > Can step not be a float value? Correct. Note the DeprecationWarning which is also shown: __main__:1: DeprecationWarning: integer argument expected, got float There are too many subtleties with floating-point, so range() doesn't handle it; that way, you deal with the subtleties yourself, explicitly. Cheers, Chris -- http://blog.rebertia.com From __peter__ at web.de Mon Nov 22 04:11:27 2010 From: __peter__ at web.de (Peter Otten) Date: Mon, 22 Nov 2010 10:11:27 +0100 Subject: MATLAB to Python? References: <74f276c3-38a4-4df0-af39-7b1f2a81472e@c39g2000yqi.googlegroups.com> <878w0s2uwv.fsf@gmail.com> <525ad586-d4fe-484a-9f9e-74b0e0fd78d4@s4g2000yql.googlegroups.com> Message-ID: MATLABdude wrote: > On Nov 17, 10:53 am, Arnaud Delobelle wrote: >> I guess that the step is supposed to be h, so you should write: >> xx = range(-kappa, kappa+1, h) > > This is what I have in the source code: > ---8<---8<---8<---8<--- > h = 0.105069988414 > xx = range(-kappa, kappa+1, h) > ---8<---8<---8<---8<--- > > This is what Python says: ValueError: range() step argument must not > be zero > > Can step not be a float value? Indeed. Older Pythons will warn you and then try to convert the arguments to integers >>> range(1.0) __main__:1: DeprecationWarning: integer argument expected, got float [0] and in 2.7 or 3.x you'll get a type error: >>> range(1.0) Traceback (most recent call last): File "", line 1, in TypeError: range() integer end argument expected, got float. Try numpy.arange() instead: >>> numpy.arange(0, 1, .1) array([ 0. , 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]) From korn at freisingnet.de Mon Nov 22 04:54:46 2010 From: korn at freisingnet.de (Johannes Korn) Date: Mon, 22 Nov 2010 10:54:46 +0100 Subject: Reading bz2 file into numpy array Message-ID: <4cea3de7$0$6769$9b4e6d93@newsspool3.arcor-online.net> Hi, is there a convenient way to read bz2 files into a numpy array? I tried: from bz2 import * from numpy import * fd = BZ2File(filename, 'rb') read_data = fromfile(fd, float32) but BZ2File doesn't seem to produce a transparent filehandle. Kind regards! Johannes From __peter__ at web.de Mon Nov 22 05:37:22 2010 From: __peter__ at web.de (Peter Otten) Date: Mon, 22 Nov 2010 11:37:22 +0100 Subject: Reading bz2 file into numpy array References: <4cea3de7$0$6769$9b4e6d93@newsspool3.arcor-online.net> Message-ID: Johannes Korn wrote: > I tried: > > from bz2 import * > from numpy import * > fd = BZ2File(filename, 'rb') > read_data = fromfile(fd, float32) > > but BZ2File doesn't seem to produce a transparent filehandle. > is there a convenient way to read bz2 files into a numpy array? Try import numpy import bz2 filename = ... f = bz2.BZ2File(filename) data = numpy.fromstring(f.read(), numpy.float32) print data From jeanmichel at sequans.com Mon Nov 22 06:14:27 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 22 Nov 2010 12:14:27 +0100 Subject: building a web interface In-Reply-To: References: Message-ID: <4CEA5093.2070604@sequans.com> Shel wrote: > Hello, > > I am pretty new to all this. I have some coding experience, and am > currently most comfortable with Python. I also have database design > experience with MS Access, and have just created my first mySQL db. > > So right now I have a mySQL db structure and some Python code. My end > goal is to create a browser-based interactive fiction/game thing. My > code is currently just using dummy data rather than pulling in data > from the db, but I think/hope it won't be too big of a deal to > interact with the db through Python (famous last words...). > > My main problem right now is how to do the web interface. I don't know > much about web architecture, unfortunately. I think I need a CGI > script? > > What I would really like is to find a GUI tool to design the interface > that would have customizable templates or drag-and-drop elements or > something, so I wouldn't have to code much by hand. Something easy, if > such a tool exists. > > Also would prefer something that I would be able to install/use > without having much access to the server where the site will be hosted > (on a university server that I don't have control over). I don't fully > understand how a lot of the tools I have been looking at work, but it > seems like they're often things where you'd have to get an > administrator to do stuff on the server (is that right?), which I > would prefer to avoid. > > It looks like Django has some sort of standalone implementation, but > I'm not clear on how that would work or how much of a learning curve > there would be for using it. > > If anyone has any thoughts or suggestions, I would really appreciate > it. > > Hope my questions make sense. I don't really know what I'm doing, so > could be they're a bit silly. I apologize if that's the case, and > please let me know if you need any additional informmation. > > Thanks, > Shel > Django is quite popular, they claim to be easy to learn/use. That's for the web framework. You could use pyjamas for the web interface, looks like it works well with django. Hmm, writing python code only, sounds like a dream come true :D Note that I never used one of these, it just happened I had to look for possible solutions for a web application. JM From andreas.loescher at s2005.tu-chemnitz.de Mon Nov 22 06:21:42 2010 From: andreas.loescher at s2005.tu-chemnitz.de (Andreas =?ISO-8859-1?Q?L=F6scher?=) Date: Mon, 22 Nov 2010 12:21:42 +0100 Subject: Some syntactic sugar proposals In-Reply-To: Message-ID: <1290424902.6446.5.camel@laptop> > if x in range(a, b): #wrong! > it feels so natural to check it that way, but we have to write > if a <= x <= b > I understand that it's not a big deal, but it would be awesome to have > some optimisations - it's clearly possible to detect things like that > "wrong" one and fix it in a bytecode. You can implement it yourself: class between(object): def __init__(self, a,b): super(crang, self).__init__() self.a=a self.b=b def __contains__(self, value): return self.a <= value <= self.b >>> 12.45 in between(-100,100) true But do you need a < x < b a <= x < b a <= x <= b or a < x <= b ? Sure, you could set a new parameter for this, but the normal way is not broken at all. Best From bgraghu1987 at gmail.com Mon Nov 22 06:24:33 2010 From: bgraghu1987 at gmail.com (raghu bg) Date: Mon, 22 Nov 2010 16:54:33 +0530 Subject: Accepting a SAML 2 Assertion Message-ID: Hello, I am working on providing a SSO solution to a customer who acts as an identity provider. He already has IDP on his side to generate SAML 2 assertions with user first name , last name and time stamp as parameters. Our task is to accept this assertion which is signed, decrypt it and send it to the authenticator we already have. The authenticator validates the info and gives access to our application which is written using Python. Here we act as the *service provider.* I am new to SAML and have no idea how to integrate SAML to our current Python application. Can you help me on how to accept these assertion requests from the Idp and decrypt it at Service Provider end using Python. Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From jakub.vysoky at gmail.com Mon Nov 22 06:24:56 2010 From: jakub.vysoky at gmail.com (kvbik) Date: Mon, 22 Nov 2010 03:24:56 -0800 (PST) Subject: multiple times subprocess fails on windows References: Message-ID: <185efeee-71c3-4772-aa78-834208aedf59@k5g2000vbn.googlegroups.com> To be more specific, I have something like this in rvirtualenv itself (that's the pokus.py file): import os os.system("echo 128") I generate a batch file like this (that's the pokus.bat file): @echo off pokus.py And after that, I run the pokus.bat file from a test (that's the run.py file): from subprocess import Popen, PIPE p = Popen('pokus.bat', stdout=PIPE, stderr=PIPE, shell=True) stdout, stderr = p.communicate() print stdout.strip() And the problem is, that I don't receive the output of the os.system to the PIPE. Probable there is something different on windows stdout redirection, because similar stuff works on linux.. Thanks, Jakub. On Nov 21, 8:39?pm, kvbik wrote: > Hello, > > in a test suite in my project (called rvirtualenv [1]) I discovered a > strange behaviour when calling from python a batch file which calles > another python and this calles a shell command. > > [1]http://github.com/kvbik/rvirtualenv > > I know it sounds pretty strange, but I do this only because I am > testing such specific tool (that has similar functionality like > original virtualenv and there are things like activate.bat commands). > > I've uploaded some code snippet here: > > https://gist.github.com/709004/6ccc44d6aed5fe694bb2adbef2400bbea92998a1 > > If anyone could explain me this behaviour I would be more than happy, > because right now it is the only failing test in my project ;). > > Thanks in advance, Jakub.. From ulrich.eckhardt at dominolaser.com Mon Nov 22 06:38:10 2010 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Mon, 22 Nov 2010 12:38:10 +0100 Subject: unittests with different parameters Message-ID: Hi! I'm writing tests and I'm wondering how to achieve a few things most elegantly with Python's unittest module. Let's say I have two flags invert X and invert Y. Now, for testing these, I would write one test for each combination. What I have in the test case is something like this: def test_invert_flags(self): """test flags to invert coordinates""" tests = [((10, 20), INVERT_NONE, (10, 20)), ((10, 20), INVERT_X, (-10, 20)), ((10, 20), INVERT_Y, (10, -20))] for input, flags, expected in tests: res = do_invert(input, flags) self.assertEqual(res, expected, "%s caused wrong results" % (flags,)) So, what I do that I test the function 'do_invert' for different input combinations and verify the result. The ugly thing is that this will abort the whole test if one of the tests in the loop fails. So, my question is how do I avoid this? I know that I could write a common test function instead: def _test_invert_flags(self, input, flags, expected): res = do_invert(input, flags) self.assertEqual(res, expected) def test_invert_flags_non(self): """test not inverting coordinates""" self._test_invert_flags((10, 20), INVERT_NONE, (10, 20)) def test_invert_flags_x(self): """test inverting X coordinates""" self._test_invert_flags((10, 20), INVERT_X, (-10, 20)) def test_invert_flags_y(self): """test inverting Y coordinates""" self._test_invert_flags((10, 20), INVERT_Y, (10, -20)) What I don't like here is that this is unnecessarily verbose and that it basically repeats information. Also, I'd rather construct the error message from the data instead of maintaining it in different places, because manually keeping those in sync is another, errorprone burden. Any suggestions? Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From markhaniford at gmail.com Mon Nov 22 08:12:27 2010 From: markhaniford at gmail.com (MarkHaniford@gmail.com) Date: Mon, 22 Nov 2010 05:12:27 -0800 (PST) Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014020136.6e85d70b@tritium.streitmacht.eu> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> Message-ID: <08823dd4-588a-4729-a660-711e266c96b0@y23g2000yqd.googlegroups.com> On Nov 21, 10:38?pm, Ertugrul S?ylemez wrote: > "Jon Harrop" wrote: > > "Ertugrul S?ylemez" wrote in message > >news:20101014052650.510e8833 at tritium.streitmacht.eu... > > > > That's nonsense. > > > Actually namekuseijin is right. You really need to persevere and > > familiarize yourself with some of the other languages out > > there. Haskell is many things but simple is not one of them. If > > Haskell were half of the things you think it is, it would have more > > credible success stories. > > Jon, I don't care about your opinion, because it's biased. All opinions are biased. From chardster at gmail.com Mon Nov 22 08:43:35 2010 From: chardster at gmail.com (Richard Thomas) Date: Mon, 22 Nov 2010 05:43:35 -0800 (PST) Subject: unittests with different parameters References: Message-ID: On Nov 22, 11:38?am, Ulrich Eckhardt wrote: > Hi! > > I'm writing tests and I'm wondering how to achieve a few things most > elegantly with Python's unittest module. > > Let's say I have two flags invert X and invert Y. Now, for testing these, I > would write one test for each combination. What I have in the test case is > something like this: > > ? def test_invert_flags(self): > ? ? ? """test flags to invert coordinates""" > ? ? ? tests = [((10, 20), INVERT_NONE, (10, 20)), > ? ? ? ? ? ? ? ?((10, 20), INVERT_X, (-10, 20)), > ? ? ? ? ? ? ? ?((10, 20), INVERT_Y, (10, -20))] > ? ? ? for input, flags, expected in tests: > ? ? ? ? ? res = do_invert(input, flags) > ? ? ? ? ? self.assertEqual(res, expected, > ? ? ? ? ? ? ? ? ? ? ? ? ? ?"%s caused wrong results" % (flags,)) > > So, what I do that I test the function 'do_invert' for different input > combinations and verify the result. The ugly thing is that this will abort > the whole test if one of the tests in the loop fails. So, my question is > how do I avoid this? > > I know that I could write a common test function instead: > > ? def _test_invert_flags(self, input, flags, expected): > ? ? ? res = do_invert(input, flags) > ? ? ? self.assertEqual(res, expected) > > ? def test_invert_flags_non(self): > ? ? ? """test not inverting coordinates""" > ? ? ? self._test_invert_flags((10, 20), INVERT_NONE, (10, 20)) > > ? def test_invert_flags_x(self): > ? ? ? """test inverting X coordinates""" > ? ? ? self._test_invert_flags((10, 20), INVERT_X, (-10, 20)) > > ? def test_invert_flags_y(self): > ? ? ? """test inverting Y coordinates""" > ? ? ? self._test_invert_flags((10, 20), INVERT_Y, (10, -20)) > > What I don't like here is that this is unnecessarily verbose and that it > basically repeats information. Also, I'd rather construct the error message > from the data instead of maintaining it in different places, because > manually keeping those in sync is another, errorprone burden. > > Any suggestions? > > Uli > > -- > Domino Laser GmbH > Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 You could have a parameter to the test method and some custom TestLoader that knows what to do with it. See http://docs.python.org/library/unittest.html. I would venture that unit tests are verbose by their very nature; they are 100% redundant. The usual argument against unnecessary redundancy, that of ease of maintenance, really doesn't apply to unit tests. Anyway, good luck with your efforts. Chard. From roy at panix.com Mon Nov 22 09:11:12 2010 From: roy at panix.com (Roy Smith) Date: Mon, 22 Nov 2010 09:11:12 -0500 Subject: unittests with different parameters References: Message-ID: In article , Ulrich Eckhardt wrote: > def test_invert_flags(self): > """test flags to invert coordinates""" > tests = [((10, 20), INVERT_NONE, (10, 20)), > ((10, 20), INVERT_X, (-10, 20)), > ((10, 20), INVERT_Y, (10, -20))] > for input, flags, expected in tests: > res = do_invert(input, flags) > self.assertEqual(res, expected, > "%s caused wrong results" % (flags,)) > > So, what I do that I test the function 'do_invert' for different input > combinations and verify the result. The ugly thing is that this will abort > the whole test if one of the tests in the loop fails. So, my question is > how do I avoid this? Writing one test method per parameter combination, as you suggested, is a reasonable approach, especially if the number of combinations is reasonably small. Another might be to make your loop: failCount = 0 for input, flags, expected in tests: res = do_invert(input, flags) if res != expected: print "%s caused wrong results" % (flags,) failCount += 1 self.assertEqual(failCount, 0, "%d of them failed" % failCount) Yet another possibility is to leave it the way you originally wrote it and not worry about the fact that the loop aborts on the first failure. Let it fail, fix it, then re-run the test to find the next failure. Perhaps not as efficient as finding them all at once, but you're going to fix them one at a time anyway, so what does it matter? It may also turn out that all the failures are due to a single bug, so fixing one fixes them all. From anurag.chourasia at gmail.com Mon Nov 22 09:25:30 2010 From: anurag.chourasia at gmail.com (Anurag Chourasia) Date: Mon, 22 Nov 2010 19:55:30 +0530 Subject: Error Starting Python(Django) App using Apache+Mod_Wsgi Message-ID: All, I have a problem in starting my Python(Django) App using Apache and Mod_Wsgi I am using Django 1.2.3 and Python 2.6.6 running on Apache 2.2.17 with Mod_Wsgi 3.3 When I try to access the app from Web Browser, I am getting these errors. [Mon Nov 22 09:45:25 2010] [notice] Apache/2.2.17 (Unix) mod_wsgi/3.3 Python/2.6.6 configured -- resuming normal operations [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] mod_wsgi (pid=1273874): Target WSGI script '/u01/home/apli/wm/app/gdd/pyserver/ apache/django.wsgi' cannot be loaded as Python module. [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] mod_wsgi (pid=1273874): Exception occurred processing WSGI script '/u01/home/ apli/wm/app/gdd/pyserver/apache/django.wsgi'. [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] Traceback (most recent call last): [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] File "/u01/ home/apli/wm/app/gdd/pyserver/apache/django.wsgi", line 19, in [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] import django.core.handlers.wsgi [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] File "/usr/ local/lib/python2.6/site-packages/django/core/handlers/wsgi.py", line 1, in [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] from threading import Lock [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] File "/usr/ local/lib/python2.6/threading.py", line 13, in [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] from functools import wraps [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] File "/usr/ local/lib/python2.6/functools.py", line 10, in [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] from _functools import partial, reduce [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] ImportError: rtld: 0712-001 Symbol PyArg_UnpackTuple was referenced [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] from module /usr/local/lib/python2.6/lib-dynload/_functools.so(), but a runtime definition [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] of the symbol was not found. [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] rtld: 0712-001 Symbol PyCallable_Check was referenced [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] from module /usr/local/lib/python2.6/lib-dynload/_functools.so(), but a runtime definition [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] of the symbol was not found. [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] rtld: 0712-001 Symbol PyDict_Copy was referenced [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] from module /usr/local/lib/python2.6/lib-dynload/_functools.so(), but a runtime definition [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] of the symbol was not found. [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] rtld: 0712-001 Symbol PyDict_Merge was referenced [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] from module /usr/local/lib/python2.6/lib-dynload/_functools.so(), but a runtime definition [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] of the symbol was not found. [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] rtld: 0712-001 Symbol PyDict_New was referenced [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] from module /usr/local/lib/python2.6/lib-dynload/_functools.so(), but a runtime definition [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] of the symbol was not found. [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] rtld: 0712-001 Symbol PyErr_Occurred was referenced [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] from module /usr/local/lib/python2.6/lib-dynload/_functools.so(), but a runtime definition [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] of the symbol was not found. [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] rtld: 0712-001 Symbol PyErr_SetString was referenced [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] from module /usr/local/lib/python2.6/lib-dynload/_functools.so(), but a runtime definition [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] of the symbol was not found. [Mon Nov 22 09:45:43 2010] [error] [client 108.10.0.191] \t0509-021 Additional errors occurred but are not reported. I assume that those missing runtime definitions are supposed to be in the Python executable. Doing an nm on the first missing symbol reveals that it does exist. root [zibal]% nm /usr/local/bin/python | grep -i PyArg_UnpackTuple .PyArg_UnpackTuple T 268683204 524 PyArg_UnpackTuple D 537073500 PyArg_UnpackTuple d 537073500 12 PyArg_UnpackTuple:F-1 - 224 Please guide. Regards, Guddu -------------- next part -------------- An HTML attachment was scrubbed... URL: From ulrich.eckhardt at dominolaser.com Mon Nov 22 09:30:46 2010 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Mon, 22 Nov 2010 15:30:46 +0100 Subject: unittests with different parameters References: Message-ID: Roy Smith wrote: > Writing one test method per parameter combination, as you suggested, is > a reasonable approach, especially if the number of combinations is > reasonably small. The number of parameters and thus combinations are unfortunately rather large. Also, sometimes that data is not static but rather computed from a loop instead. There are a few optimised computations, where I compute the expected result with the slow but simple version, in those cases I want to check a whole range of inputs using a loop. I'm wondering, classes aren't as static as I'm still used to from C++, so creating the test functions dynamically with a loop outside the class declaration should be another possibility... > Yet another possibility is to leave it the way you originally wrote it > and not worry about the fact that the loop aborts on the first failure. > Let it fail, fix it, then re-run the test to find the next failure. > Perhaps not as efficient as finding them all at once, but you're going > to fix them one at a time anyway, so what does it matter? Imagine all tests that use INVERT_X fail, all others pass. What would your educated guess be where the code is wrong? ;) Thanks Roy! Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From ulrich.eckhardt at dominolaser.com Mon Nov 22 09:32:13 2010 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Mon, 22 Nov 2010 15:32:13 +0100 Subject: unittests with different parameters References: Message-ID: <4gbqr7-5rj.ln1@satorlaser.homedns.org> Richard Thomas wrote: [batch-programming different unit tests] > You could have a parameter to the test method and some custom > TestLoader that knows what to do with it. Interesting, thanks for this suggestion, I'll look into it! Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From raffaelcavallaro at pas.despam.s.il.vous.plait.mac.com Mon Nov 22 09:45:23 2010 From: raffaelcavallaro at pas.despam.s.il.vous.plait.mac.com (Raffael Cavallaro) Date: Mon, 22 Nov 2010 09:45:23 -0500 Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014020136.6e85d70b@tritium.streitmacht.eu> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> <08823dd4-588a-4729-a660-711e266c96b0@y23g2000yqd.googlegroups.com> Message-ID: On 2010-11-22 08:12:27 -0500, MarkHaniford at gmail.com said: > All opinions are biased. All opinions show some bias. Not all opinions represent what is usually called a "conflict of interest." Since JH makes his living selling tools and training for certain languages, he has a severe conflict of interest wrt asessing the value of various other languages. If these other languages are just as good or better than those he makes his living from, it would be very damaging to his livlihood for him to admit this fact. As a result, he is a completely unreliable source on the question. This is why judges must recuse themselves from both civil and criminal trials if they have some significant conflict of interest. The law recognizes that we cannot expect a fair judgement from someone who stands to profit significantly if the judgement goes one way or the other. Similarly, we cannot expect a fair judgement on the relative value of various language tools from a person whose livlihood depends on the audience choosing only those certain language tools that he sells services and training for. warmest regards, Ralph -- Raffael Cavallaro From roy at panix.com Mon Nov 22 09:47:44 2010 From: roy at panix.com (Roy Smith) Date: Mon, 22 Nov 2010 09:47:44 -0500 Subject: unittests with different parameters References: Message-ID: In article , Ulrich Eckhardt wrote: > > Yet another possibility is to leave it the way you originally wrote it > > and not worry about the fact that the loop aborts on the first failure. > > Let it fail, fix it, then re-run the test to find the next failure. > > Perhaps not as efficient as finding them all at once, but you're going > > to fix them one at a time anyway, so what does it matter? > > Imagine all tests that use INVERT_X fail, all others pass. What would your > educated guess be where the code is wrong? ;) Well, let me leave you with one last thought. There's really two kinds of tests -- acceptance tests, and diagnostic tests. I tend to write acceptance tests first. The idea is that if all the tests pass, I know my code works. When some test fails, that's when I start digging deeper and writing diagnostic tests, to help me figure out what went wrong. The worst test is a test which is never written because it's too hard to write. If it's easy to write a bunch of tests which verify correct operation but don't give a lot of clues about what went wrong, it might be worth doing that first and seeing what happens. If some of the tests fail, then invest the time to write more detailed tests which give you more information about each failure. From usenot at geekmail.INVALID Mon Nov 22 10:25:14 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Mon, 22 Nov 2010 10:25:14 -0500 Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014020136.6e85d70b@tritium.streitmacht.eu> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> <4cea0d1a$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20101122102514.59ec96d7@geekmail.INVALID> On 22 Nov 2010 06:26:34 GMT Steven D'Aprano wrote: > On Sun, 21 Nov 2010 23:57:21 -0500, Steve Holden wrote: > > > Perhaps we could take this thread to alt.small.minded.bickering now? > > Alas, my ISP doesn't carry that newsgroup. Where else can I get my > mindless off-topic bitching if not for cross-posts from > comp.lang.scheme and comp.lang.functional? > > *wink* > alt.off-topic *wink* /W -- To reach me via email, replace INVALID with the country code of my home country. But if you spam me, I'll be one sour Kraut. From tosters at gmail.com Mon Nov 22 10:46:47 2010 From: tosters at gmail.com (Roman Dolgiy) Date: Mon, 22 Nov 2010 07:46:47 -0800 (PST) Subject: Python recursively __getattribute__ Message-ID: Hello, I need to implement such behavior: obj.attr1.attr2.attr3 --> obj.attr1__attr2__attr3 It looks like I have to override obj's class __getattribute__ and also use python descriptors somehow. Any help will be much appreciated. http://stackoverflow.com/questions/4247036/python-recursively-getattribute From howard at brazee.net Mon Nov 22 10:57:41 2010 From: howard at brazee.net (Howard Brazee) Date: Mon, 22 Nov 2010 08:57:41 -0700 Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014020136.6e85d70b@tritium.streitmacht.eu> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> Message-ID: On Mon, 22 Nov 2010 05:38:53 +0100, Ertugrul S?ylemez wrote: >Haskell is a simple language with a comparably small specification. >It's not as simple as Common Lisp, but it's simple. Note that simple >doesn't mean easy. Haskell is certainly more difficult to learn than >other languages, which explains the low number of success stories. On >the other hand, I'm doing rapid web development in it. I wonder how much that difficulty is innate, and how much is due to learning other languages first. I'm an old time CoBOL programmer, and know of quite a few people who tried to learn OO-CoBOL without much luck. The way to learn it was to forget it - learn OO with some other language, then come back to it later. We had to divorce ourselves from the old paradigm first. -- "In no part of the constitution is more wisdom to be found, than in the clause which confides the question of war or peace to the legislature, and not to the executive department." - James Madison From usenot at geekmail.INVALID Mon Nov 22 11:04:41 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Mon, 22 Nov 2010 11:04:41 -0500 Subject: Python recursively __getattribute__ References: Message-ID: <20101122110441.267eb032@geekmail.INVALID> On Mon, 22 Nov 2010 07:46:47 -0800 (PST) Roman Dolgiy wrote: > Hello, > > I need to implement such behavior: > > obj.attr1.attr2.attr3 --> obj.attr1__attr2__attr3 > It looks like I have to override obj's class __getattribute__ and also > use python descriptors somehow. > > Any help will be much appreciated. > http://stackoverflow.com/questions/4247036/python-recursively-getattribute Why? No, really: Why? In that link you say that you need to do this to support legacy code. I still don't see how this would be necessary. If you need to support legacy code, doesn't that mean that the solution you're asking for already exists? I really think you should go into detail about why you need this. I'm certain that there's a better solution to your problem. ("Better" being one that is reasonably easy to implement and maintain.) /W -- To reach me via email, replace INVALID with the country code of my home country. But if you spam me, I'll be one sour Kraut. From toby at telegraphics.com.au Mon Nov 22 11:14:40 2010 From: toby at telegraphics.com.au (toby) Date: Mon, 22 Nov 2010 08:14:40 -0800 (PST) Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014020136.6e85d70b@tritium.streitmacht.eu> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> Message-ID: On Nov 22, 10:57?am, Howard Brazee wrote: > On Mon, 22 Nov 2010 05:38:53 +0100, Ertugrul S ylemez > wrote: > > >Haskell is a simple language with a comparably small specification. > >It's not as simple as Common Lisp, but it's simple. ?Note that simple > >doesn't mean easy. ?Haskell is certainly more difficult to learn than > >other languages, which explains the low number of success stories. ?On > >the other hand, I'm doing rapid web development in it. > > I wonder how much that difficulty is innate, and how much is due to > learning other languages first. This is a good (if familiar) observation. Teaching children (or young people with little exposure to computers) how to program in various paradigms could produce interesting primary evidence. Pity that this isn't examined widely and systematically. We could learn something about how to teach programming and design languages this way, don't you agree? The OLPC might do some interesting things in this area but it is still one set of tools. More interesting might be to compare outcomes across a range of different tools, paradigms, syntaxes, and teaching strategies. > I'm an old time CoBOL programmer, and know of quite a few people who > tried to learn OO-CoBOL without much luck. ? The way to learn it was > to forget it - learn OO with some other language, then come back to it > later. ? ?We had to divorce ourselves from the old paradigm first. ? ? > > -- > "In no part of the constitution is more wisdom to be found, > than in the clause which confides the question of war or peace > to the legislature, and not to the executive department." > > - James Madison From sunwei415 at gmail.com Mon Nov 22 11:23:05 2010 From: sunwei415 at gmail.com (Wei Sun) Date: Mon, 22 Nov 2010 16:23:05 GMT Subject: print line number and source filename References: Message-ID: <20101122112250usenet@eggheadcafe.com> Here is what you want for printing python source filename: print __file__ > On Tuesday, June 22, 2010 12:44 PM Peng Yu wrote: > I want to print filename and line number for debugging purpose. So far > I only find how to print the line number but not how to print > filename. > > import inspect > print inspect.currentframe().f_lineno > > I found inspect.getsourcefile(), but I have to supply a class name to > it. I have searched online, but I do not find how to print the source > filename. Would you please let me know? > > Also, always importing the inspect module and getting the frame and > accessing the lineno from the frame is not very convenient to type. Is > there a shorter way to access the line number (for example, in C++ and > perl, __LINE__ can be used to access line number, which is much more > convenient than the way that I found in python). > > -- > Regards, > Peng > Submitted via EggHeadCafe > Merging SharePoint List Data into Word Documents > http://www.eggheadcafe.com/tutorials/aspnet/6054abc5-c5fb-4e86-a352-afd0e8c4a7c6/merging-sharepoint-list-data-into-word-documents.aspx From tooscattered at gmail.com Mon Nov 22 11:25:34 2010 From: tooscattered at gmail.com (scattered) Date: Mon, 22 Nov 2010 08:25:34 -0800 (PST) Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014020136.6e85d70b@tritium.streitmacht.eu> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> <08823dd4-588a-4729-a660-711e266c96b0@y23g2000yqd.googlegroups.com> Message-ID: On Nov 22, 9:45?am, Raffael Cavallaro wrote: > On 2010-11-22 08:12:27 -0500, MarkHanif... at gmail.com said: > > > All opinions are biased. > > All opinions show some bias. Not all opinions represent what is usually > called a "conflict of interest." Since JH makes his living selling > tools and training for certain languages, he has a severe conflict of > interest wrt asessing the value of various other languages. If these > other languages are just as good or better than those he makes his > living from, it would be very damaging to his livlihood for him to > admit this fact. As a result, he is a completely unreliable source on > the question. > And you don't think that Jon Harrop could write a book about Haskell if he honestly came to think that it were a superior all-aroung language? The fact that he *didn't* mindlessly reject F# in favor of O'Caml when F# came out (despite the fact that at the time his company was deeply (exclusively?) invested in O'Caml and arguably had a vested interest in having F# fail to gain support) suggests that he is able to fairly evaluate the merits of other languages. Doubtless he has biases, but there is no reason to think that they are any greater than the bias of any programmer who has invested substantial amounts of time in becoming fluent in a particular language. > This is why judges must recuse themselves from both civil and criminal > trials if they have some significant conflict of interest. But an advocate isn't a judge. Nobody is handing down binding decisions here - they are just advocating their positions. It would be better to compare JH to a defense lawyer. You can't reject the defense's arguments just because the lawyer has a vested interest in the outcome of the trial. > the law recognizes that we cannot expect a fair judgement from someone who > stands to profit significantly if the judgement goes one way or the > other. Similarly, we cannot expect a fair judgement on the relative > value of various language tools from a person whose livlihood depends > on the audience choosing only those certain language tools that he > sells services and training for. > > warmest regards, > > Ralph > > -- > Raffael Cavallaro From tosters at gmail.com Mon Nov 22 11:41:49 2010 From: tosters at gmail.com (Roman Dolgiy) Date: Mon, 22 Nov 2010 08:41:49 -0800 (PST) Subject: Python recursively __getattribute__ References: <20101122110441.267eb032@geekmail.INVALID> Message-ID: <3f980023-665c-47fe-8bb6-78d24c8388e7@k30g2000vbn.googlegroups.com> On Nov 22, 6:04?pm, Andreas Waldenburger wrote: > On Mon, 22 Nov 2010 07:46:47 -0800 (PST) Roman Dolgiy wrote: > > > Hello, > > > I need to implement such behavior: > > > obj.attr1.attr2.attr3 --> obj.attr1__attr2__attr3 > > It looks like I have to override obj's class __getattribute__ and also > > use python descriptors somehow. > > > Any help will be much appreciated. > >http://stackoverflow.com/questions/4247036/python-recursively-getattr... > > Why? No, really: Why? > > In that link you say that you need to do this to support legacy code. I still don't see how this would be necessary. If you need to support legacy code, doesn't that mean that the solution you're asking for already exists? > > I really think you should go into detail about why you need this. I'm certain that there's a better solution to your problem. ("Better" being one that is reasonably easy to implement and maintain.) > > /W > > -- > To reach me via email, replace INVALID with the country code of my home > country. ?But if you spam me, I'll be one sour Kraut. I have a django project. obj is django-haystack's SearchResult instance, it contains a lot of de-normalized data (user__name, user__address) from django model, and I need to access it as result.user.name for compability reasons. From howard at brazee.net Mon Nov 22 11:47:37 2010 From: howard at brazee.net (Howard Brazee) Date: Mon, 22 Nov 2010 09:47:37 -0700 Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014020136.6e85d70b@tritium.streitmacht.eu> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> Message-ID: On Mon, 22 Nov 2010 08:14:40 -0800 (PST), toby wrote: >This is a good (if familiar) observation. Teaching children (or young >people with little exposure to computers) how to program in various >paradigms could produce interesting primary evidence. Pity that this >isn't examined widely and systematically. We could learn something >about how to teach programming and design languages this way, don't >you agree? I do. A study such as that would be more useful than how to teach languages - it could be useful in teaching other stuff as well. -- "In no part of the constitution is more wisdom to be found, than in the clause which confides the question of war or peace to the legislature, and not to the executive department." - James Madison From tkpapp at gmail.com Mon Nov 22 11:51:58 2010 From: tkpapp at gmail.com (Tamas K Papp) Date: 22 Nov 2010 16:51:58 GMT Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014020136.6e85d70b@tritium.streitmacht.eu> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> <08823dd4-588a-4729-a660-711e266c96b0@y23g2000yqd.googlegroups.com> Message-ID: <8kvldeF2e6U1@mid.individual.net> On Mon, 22 Nov 2010 08:25:34 -0800, scattered wrote: > On Nov 22, 9:45?am, Raffael Cavallaro > wrote: >> On 2010-11-22 08:12:27 -0500, MarkHanif... at gmail.com said: >> >> > All opinions are biased. >> >> All opinions show some bias. Not all opinions represent what is usually >> called a "conflict of interest." Since JH makes his living selling >> tools and training for certain languages, he has a severe conflict of >> interest wrt asessing the value of various other languages. If these >> other languages are just as good or better than those he makes his >> living from, it would be very damaging to his livlihood for him to >> admit this fact. As a result, he is a completely unreliable source on >> the question. >> >> > And you don't think that Jon Harrop could write a book about Haskell if > he honestly came to think that it were a superior all-aroung language? Until he writes one, it is useless to speculate about what he could or could not do. There are some pretty good books on Haskell, lots of excellent resources online, and the online community is very supportive. Writing a book which adds significant value to that would not be a trivial undertaking. Best, Tamas From usenot at geekmail.INVALID Mon Nov 22 12:00:42 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Mon, 22 Nov 2010 12:00:42 -0500 Subject: Python recursively __getattribute__ References: <20101122110441.267eb032@geekmail.INVALID> <3f980023-665c-47fe-8bb6-78d24c8388e7@k30g2000vbn.googlegroups.com> Message-ID: <20101122120042.706a2964@geekmail.INVALID> On Mon, 22 Nov 2010 08:41:49 -0800 (PST) Roman Dolgiy wrote: > On Nov 22, 6:04?pm, Andreas Waldenburger > wrote: > > On Mon, 22 Nov 2010 07:46:47 -0800 (PST) Roman Dolgiy > > wrote: > > > > > Hello, > > > > > I need to implement such behavior: > > > > > obj.attr1.attr2.attr3 --> obj.attr1__attr2__attr3 > > > It looks like I have to override obj's class __getattribute__ and > > > also use python descriptors somehow. > > > > > Any help will be much appreciated. > > >http://stackoverflow.com/questions/4247036/python-recursively-getattr... > > > > Why? No, really: Why? > > > > [...] > > I have a django project. > > obj is django-haystack's SearchResult instance, it contains a lot of > de-normalized data (user__name, user__address) from django model, and > I need to access it as result.user.name for compability reasons. I don't know anything about django, so I may be babbling nonsense. Caveat emptor. How about taking your "user__whatever" thingies and have a function emit customized result instances. For this you can just create a plain object subclass, say ResultElement. If these "user__whatever" thingies are strings (you haven't told), split them by "__" and create a new plain object for every level of attributes, attaching it to the previous level. You can probably make your life easier if you use defaultdicts first and then translate these to your object hierarchy. That's how I'd do it. I don't know if that helps you. If not, please provide more info. /W -- To reach me via email, replace INVALID with the country code of my home country. But if you spam me, I'll be one sour Kraut. From ian.g.kelly at gmail.com Mon Nov 22 12:08:34 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 22 Nov 2010 10:08:34 -0700 Subject: unittests with different parameters In-Reply-To: References: Message-ID: On 11/22/2010 4:38 AM, Ulrich Eckhardt wrote: > Let's say I have two flags invert X and invert Y. Now, for testing these, I > would write one test for each combination. What I have in the test case is > something like this: > > def test_invert_flags(self): > """test flags to invert coordinates""" > tests = [((10, 20), INVERT_NONE, (10, 20)), > ((10, 20), INVERT_X, (-10, 20)), > ((10, 20), INVERT_Y, (10, -20))] > for input, flags, expected in tests: > res = do_invert(input, flags) > self.assertEqual(res, expected, > "%s caused wrong results" % (flags,)) > > So, what I do that I test the function 'do_invert' for different input > combinations and verify the result. The ugly thing is that this will abort > the whole test if one of the tests in the loop fails. So, my question is > how do I avoid this? > > I know that I could write a common test function instead: > > def _test_invert_flags(self, input, flags, expected): > res = do_invert(input, flags) > self.assertEqual(res, expected) > > def test_invert_flags_non(self): > """test not inverting coordinates""" > self._test_invert_flags((10, 20), INVERT_NONE, (10, 20)) > > def test_invert_flags_x(self): > """test inverting X coordinates""" > self._test_invert_flags((10, 20), INVERT_X, (-10, 20)) > > def test_invert_flags_y(self): > """test inverting Y coordinates""" > self._test_invert_flags((10, 20), INVERT_Y, (10, -20)) > > What I don't like here is that this is unnecessarily verbose and that it > basically repeats information. The above code looks perfectly fine to me for testing. I think the question you should ask yourself is whether the different combinations you are testing represent tests of distinct behaviors, or tests of the same behavior on a variety of data. If the former case, as in the sample code you posted, then these should probably have separate tests anyway, so that you can easily see that both INVERT_X and INVERT_BOTH are failing, but INVERT_Y is not, which may be valuable diagnostic data. On the other hand, if your test is trying the INVERT_X behavior on nine different points, you probably don't need or want to see every individual point that fails. It's enough to know that INVERT_X is failing and to have a sample point where it fails. In that case I would say just run them in a loop and don't worry that it might exit early. > Also, I'd rather construct the error message > from the data instead of maintaining it in different places, because > manually keeping those in sync is another, errorprone burden. I'm not sure I follow the problem you're describing. If the factored out workhorse function receives the data to test, what prevents it from constructing an error message from that data? Cheers, Ian From namekuseijin at gmail.com Mon Nov 22 12:28:33 2010 From: namekuseijin at gmail.com (namekuseijin) Date: Mon, 22 Nov 2010 09:28:33 -0800 (PST) Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014020136.6e85d70b@tritium.streitmacht.eu> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> Message-ID: <9b520f64-0266-4977-b32a-5f089f7d189b@k13g2000vbq.googlegroups.com> On 22 nov, 14:47, Howard Brazee wrote: > On Mon, 22 Nov 2010 08:14:40 -0800 (PST), toby > > wrote: > >This is a good (if familiar) observation. Teaching children (or young > >people with little exposure to computers) how to program in various > >paradigms could produce interesting primary evidence. Pity that this > >isn't examined widely and systematically. We could learn something > >about how to teach programming and design languages this way, don't > >you agree? > > I do. > > A study such as that would be more useful than how to teach languages > - it could be useful in teaching other stuff as well. yes, pity most children are (used to be) taught Basic first. Also, with a study like this, it's likely some children would be taught some lame language and others would be taught some "industrial strength" language and still others would be taught some esoteric language. I'm not sure it'd prove as much as we are hoping for -- as they are all Turing equivalent and the kids would be able to eventually do the task asked for in any of them -- but I'm sure some of those children would be mentally hurt for all their life. Poor pioneers :p JH, nice to have you back! :) From markhaniford at gmail.com Mon Nov 22 12:32:08 2010 From: markhaniford at gmail.com (MarkHaniford@gmail.com) Date: Mon, 22 Nov 2010 09:32:08 -0800 (PST) Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014020136.6e85d70b@tritium.streitmacht.eu> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> <08823dd4-588a-4729-a660-711e266c96b0@y23g2000yqd.googlegroups.com> Message-ID: On Nov 22, 8:45?am, Raffael Cavallaro wrote: > On 2010-11-22 08:12:27 -0500, MarkHanif... at gmail.com said: > > > All opinions are biased. > > All opinions show some bias. Not all opinions represent what is usually > called a "conflict of interest." > Maybe, but in the case of regulars on newsgroups like c.l.l, there are "conflicts of interest" that either don't or don't indirectly have to do with profiting off the popularity or perception of a particular programming language. Harrop is annoying is the same way that "MatzLisp" guy is annoying on c.l.l. > warmest regards, > > Ralph > > -- > Raffael Cavallaro From toby at telegraphics.com.au Mon Nov 22 12:42:14 2010 From: toby at telegraphics.com.au (toby) Date: Mon, 22 Nov 2010 09:42:14 -0800 (PST) Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014020136.6e85d70b@tritium.streitmacht.eu> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> <9b520f64-0266-4977-b32a-5f089f7d189b@k13g2000vbq.googlegroups.com> Message-ID: <6ca96ca0-cacf-4f82-9c57-0331eae14e57@b25g2000vbz.googlegroups.com> On Nov 22, 12:28?pm, namekuseijin wrote: > On 22 nov, 14:47, Howard Brazee wrote: > > > On Mon, 22 Nov 2010 08:14:40 -0800 (PST), toby > > > wrote: > > >This is a good (if familiar) observation. Teaching children (or young > > >people with little exposure to computers) how to program in various > > >paradigms could produce interesting primary evidence. Pity that this > > >isn't examined widely and systematically. We could learn something > > >about how to teach programming and design languages this way, don't > > >you agree? > > > I do. > > > A study such as that would be more useful than how to teach languages > > - it could be useful in teaching other stuff as well. > > yes, pity most children are (used to be) taught Basic first. > > Also, with a study like this, it's likely some children would be > taught some lame language and others would be taught some "industrial > strength" language and still others would be taught some esoteric > language. This is not worse than the status quo, which does exactly that, but without paying attention to outcomes. What I am proposing is doing it systematically, with observation. Then we can learn something. >?I'm not sure it'd prove as much as we are hoping for -- as > they are all Turing equivalent and the kids would be able to > eventually do the task asked for in any of them -- but I'm sure some > of those children would be mentally hurt for all their life. ?Poor > pioneers :p > > JH, nice to have you back! :) From ulrich.eckhardt at dominolaser.com Mon Nov 22 12:56:14 2010 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Mon, 22 Nov 2010 18:56:14 +0100 Subject: unittests with different parameters References: Message-ID: Ian Kelly wrote: > On 11/22/2010 4:38 AM, Ulrich Eckhardt wrote: >> Also, I'd rather construct the error message from the data >> instead of maintaining it in different places, because >> manually keeping those in sync is another, errorprone burden. > > I'm not sure I follow the problem you're describing. If the factored > out workhorse function receives the data to test, what prevents it from > constructing an error message from that data? Sorry, unprecise description of what I want. If you define a test function and run the tests with "-v", the framework prints the first line of the docstring of that function followed by okay/fail/error, which is much friendlier to the reader than the exception dump afterwards. Using multiple very similar functions requires equally similar docstrings that repeat themselves. I'd prefer creating these from the input data. Thanks for your suggestion, Ian! Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From tjreedy at udel.edu Mon Nov 22 12:57:18 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 22 Nov 2010 12:57:18 -0500 Subject: Python recursively __getattribute__ In-Reply-To: References: Message-ID: On 11/22/2010 10:46 AM, Roman Dolgiy wrote: > Hello, > > I need to implement such behavior: > > obj.attr1.attr2.attr3 --> obj.attr1__attr2__attr3 obj.attr1.attr2.attr3 is parsed as ((obj.attr1).attr2).attr3, so this cannot work in general but only if attr1 and attr2 are known to not be 'final' names. > It looks like I have to override obj's class __getattribute__ and also > use python descriptors somehow. > > Any help will be much appreciated. > http://stackoverflow.com/questions/4247036/python-recursively-getattribute The code posted there by THC4k depened on such knowledge, which you gave there but not here. -- Terry Jan Reedy From ben+python at benfinney.id.au Mon Nov 22 15:15:41 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 23 Nov 2010 07:15:41 +1100 Subject: unittests with different parameters References: Message-ID: <87hbf9868i.fsf@benfinney.id.au> Ulrich Eckhardt writes: > Let's say I have two flags invert X and invert Y. Now, for testing these, I > would write one test for each combination. What I have in the test case is > something like this: > > def test_invert_flags(self): > """test flags to invert coordinates""" > tests = [((10, 20), INVERT_NONE, (10, 20)), > ((10, 20), INVERT_X, (-10, 20)), > ((10, 20), INVERT_Y, (10, -20))] > for input, flags, expected in tests: > res = do_invert(input, flags) > self.assertEqual(res, expected, > "%s caused wrong results" % (flags,)) The ?testscenarios? library is designed for just this reason . It takes a sequence of scenarios, each of which is a tuple just like in your example, and causes a separate test run and report for each one. -- \ ?If we listen only to those who are like us, we will squander | `\ the great opportunity before us: To live together peacefully in | _o__) a world of unresolved differences.? ?David Weinberger | Ben Finney From wxjmfauth at gmail.com Mon Nov 22 15:25:12 2010 From: wxjmfauth at gmail.com (jmfauth) Date: Mon, 22 Nov 2010 12:25:12 -0800 (PST) Subject: Need advices regarding the strings (str, unicode, coding) used as interface for an external library. Message-ID: <62db9e18-a62f-403f-ae49-cb1eb6a22599@k5g2000vbn.googlegroups.com> I'm planning to build an external lib. This lib will exchange a lot of strings between the lib and the "core Python code" of applications. I wish this lib to be modern, 100% unicode compliant. It will be developped for Python 2.7 and for Python 3. In an early phase, technically, it will be developed on Python 2.7 before Python 3, probably 3.2. Two options for the strings interface. a) Pure unicode, that means only type 'unicode' in Python 2.7 and only type 'str' in Python 3. Similar to the Python io module. b) Like a) plus ascii and utf-8 encoded type 'str' to keep some kind of retro compatibility. This lib will anyway work in a "unicode mode", so the ascii and the encoded utf-8 str's have to be converted into "unicode". I'm very comfortable with all this coding stuff and aware of the pros and cons of each solutions. My favourite solution is clearly on the a) side. Advices and comments are welcome. Thanks in advance. From tosters at gmail.com Mon Nov 22 15:44:15 2010 From: tosters at gmail.com (Roman Dolgiy) Date: Mon, 22 Nov 2010 12:44:15 -0800 (PST) Subject: Python recursively __getattribute__ References: Message-ID: On Nov 22, 7:57?pm, Terry Reedy wrote: > On 11/22/2010 10:46 AM, Roman Dolgiy wrote: > > > Hello, > > > I need to implement such behavior: > > > obj.attr1.attr2.attr3 --> ?obj.attr1__attr2__attr3 > > obj.attr1.attr2.attr3 is parsed as ((obj.attr1).attr2).attr3, > so this cannot work in general but only if attr1 and attr2 are known to > not be 'final' names. > > > It looks like I have to override obj's class __getattribute__ and also > > use python descriptors somehow. > > > Any help will be much appreciated. > >http://stackoverflow.com/questions/4247036/python-recursively-getattr... > > The code posted there by THC4k depened on such knowledge, which you gave > there but not here. > > -- > Terry Jan Reedy I need to support a lot of legacy code, with THC4k's approach I'll have to modify project's existing code to use obj.attr1.val instead of obj.attr1 but this is not suitable. From martin.lundberg at gmail.com Mon Nov 22 16:43:34 2010 From: martin.lundberg at gmail.com (Martin Lundberg) Date: Mon, 22 Nov 2010 13:43:34 -0800 (PST) Subject: Glob in python which supports the ** wildcard Message-ID: <0cc11320-1f8c-4063-857e-52c16f0bb688@j18g2000yqd.googlegroups.com> Hi, I want to be able to let the user enter paths like this: apps/name/**/*.js and then find all the matching files in apps/name and all its subdirectories. However I found out that Python's glob function doesn't support the recursive ** wildcard. Is there any 3rd party glob function which do support **? Regards, Martin Lundberg From stefan.sonnenberg at pythonmeister.com Mon Nov 22 17:05:16 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Mon, 22 Nov 2010 23:05:16 +0100 Subject: Glob in python which supports the ** wildcard In-Reply-To: <0cc11320-1f8c-4063-857e-52c16f0bb688@j18g2000yqd.googlegroups.com> References: <0cc11320-1f8c-4063-857e-52c16f0bb688@j18g2000yqd.googlegroups.com> Message-ID: <4CEAE91C.4060003@pythonmeister.com> Am 22.11.2010 22:43, schrieb Martin Lundberg: > Hi, > > I want to be able to let the user enter paths like this: > > apps/name/**/*.js > > and then find all the matching files in apps/name and all its > subdirectories. However I found out that Python's glob function > doesn't support the recursive ** wildcard. Is there any 3rd party glob > function which do support **? > > Regards, > > Martin Lundberg > os.walk() or os.path.walk() can be used. You need to traverse the file system. AFAIK there is no support for this. -------------- next part -------------- A non-text attachment was scrubbed... Name: stefan_sonnenberg.vcf Type: text/x-vcard Size: 223 bytes Desc: not available URL: From raffaelcavallaro at pas.despam.s.il.vous.plait.mac.com Mon Nov 22 17:12:21 2010 From: raffaelcavallaro at pas.despam.s.il.vous.plait.mac.com (Raffael Cavallaro) Date: Mon, 22 Nov 2010 17:12:21 -0500 Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014020136.6e85d70b@tritium.streitmacht.eu> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> <08823dd4-588a-4729-a660-711e266c96b0@y23g2000yqd.googlegroups.com> Message-ID: On 2010-11-22 11:25:34 -0500, scattered said: > And you don't think that [JH] could write a book about Haskell > if he honestly came to think that it were a superior all-aroung > language? Until he actually does, he has a financial interest in trash-talking Haskell. This makes anything he says about Haskell suspect. > The fact that he *didn't* mindlessly reject [musical note lang] in favor of > [Irish Ship Of The Desert] when [musical note lang] came out (despite > the fact that at the time his company > was deeply (exclusively?) invested in [Irish Ship Of The Desert] and > arguably had a vested > interest in having [musical note lang] fail to gain support) suggests > that he is able > to fairly evaluate the merits of other languages. No, it suggests that he saw that supporting the Irish Ship Of The Desert meant going up against Microsoft, so he jumped to the MS supported variant of the Donut Dromedary. You miss the fundamental point; having a financial interest in the outcome of a debate makes anything that person says an advertisement for his financial interests, not a fair assessment. > Doubtless he has > biases, but there is no reason to think that they are any greater than > the bias of any programmer who has invested substantial amounts of > time in becoming fluent in a particular language. Just the opposite. A person who makes his living by being paid to program in a language he has developed some expertise in (rather than selling books on it and training for it) has no financial interest in seeing others develop expertise in it - they would just represent competition. By contrast, one who sells training and books for a language profits directly when others take an interest in that language. Their financial interests are in fact opposite. JH profits when people take an interest in languages he sells training for; a working lisp programmer sees additional *competition* when someone else develops expertise in common lisp. > But an advocate isn't a judge. Nobody is handing down binding > decisions here - they are just advocating their positions. Now you're arguing our point; JH is an *advocate* with a clear conflict of interest which prevents him from presenting anything but the most one sided, and therefore largely useless, assessment. His writing should be seen as a paid advertisement, not as a fair treatment of programming languages. warmest regards, Ralph -- Raffael Cavallaro From kurt.alfred.mueller at sunrise.ch Mon Nov 22 17:54:14 2010 From: kurt.alfred.mueller at sunrise.ch (Kurt Mueller) Date: Mon, 22 Nov 2010 23:54:14 +0100 Subject: Glob in python which supports the ** wildcard In-Reply-To: <4CEAE91C.4060003@pythonmeister.com> References: <0cc11320-1f8c-4063-857e-52c16f0bb688@j18g2000yqd.googlegroups.com> <4CEAE91C.4060003@pythonmeister.com> Message-ID: <4F740F20-CEE1-4726-834D-7CB550243C15@gmail.com> Hi, Am 22.11.2010 um 23:05 schrieb Stefan Sonnenberg-Carstens: > Am 22.11.2010 22:43, schrieb Martin Lundberg: >> I want to be able to let the user enter paths like this: >> apps/name/**/*.js >> and then find all the matching files in apps/name and all its >> subdirectories. However I found out that Python's glob function >> doesn't support the recursive ** wildcard. Is there any 3rd party glob >> function which do support **? > os.walk() or os.path.walk() can be used. > You need to traverse the file system. > AFAIK there is no support for this. If you are a lucky Unix/Linux/MacOS user: --------------------------------------------------------------------------- #!/usr/bin/env python # find files import os cmd = 'find apps/name/ -type f -name "*.js" -print' # find is a standard Unix tool for filename in os.popen(cmd).readlines(): # run find command # do something with filename --------------------------------------------------------------------------- find is very powerful, really. Have anice day -- kurt.alfred.mueller at gmail.com From kurt.alfred.mueller at sunrise.ch Mon Nov 22 18:04:08 2010 From: kurt.alfred.mueller at sunrise.ch (Kurt Mueller) Date: Tue, 23 Nov 2010 00:04:08 +0100 Subject: Glob in python which supports the ** wildcard In-Reply-To: <4CEAE91C.4060003@pythonmeister.com> References: <0cc11320-1f8c-4063-857e-52c16f0bb688@j18g2000yqd.googlegroups.com> <4CEAE91C.4060003@pythonmeister.com> Message-ID: <0AF04369-15B2-4F65-8F79-89F3038DFE5F@gmail.com> HI, Am 22.11.2010 um 23:05 schrieb Stefan Sonnenberg-Carstens: > Am 22.11.2010 22:43, schrieb Martin Lundberg; >> >> I want to be able to let the user enter paths like this: >> apps/name/**/*.js >> and then find all the matching files in apps/name and all its >> subdirectories. However I found out that Python's glob function >> doesn't support the recursive ** wildcard. Is there any 3rd party glob >> function which do support **? >> > os.walk() or os.path.walk() can be used. > You need to traverse the file system. > AFAIK there is no support for this. Or python only: ---------------------------------------------------------- #!/usr/bin/env python import os, fnmatch # generator: def find_files(directory, pattern): for root, dirs, files in os.walk(directory): for basename in files: if fnmatch.fnmatch(basename, pattern): filename = os.path.join(root, basename) yield filename # process each file as it is found: for filename in find_files('apps/name', '*.js'): print 'found java source:', filename ---------------------------------------------------------- Found at http://stackoverflow.com/questions/2186525/use-a-glob-to-find-files-recursively-in-python Have a nice day -- kurt.alfred.mueller at gmail.com From tjreedy at udel.edu Mon Nov 22 19:11:40 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 22 Nov 2010 19:11:40 -0500 Subject: Need advices regarding the strings (str, unicode, coding) used as interface for an external library. In-Reply-To: <62db9e18-a62f-403f-ae49-cb1eb6a22599@k5g2000vbn.googlegroups.com> References: <62db9e18-a62f-403f-ae49-cb1eb6a22599@k5g2000vbn.googlegroups.com> Message-ID: On 11/22/2010 3:25 PM, jmfauth wrote: > I'm planning to build an external lib. This lib will exchange > a lot of strings between the lib and the "core Python code" > of applications. Are you planning to exchange indirectly via disk files or directly via memory buffers? This pretty much amounts to whether the library will interface with Python-only or with anything. Also, what OSes? If 'all', you need to be able to work with both 2 and 4 byte unicodes. -- Terry Jan Reedy From goldtech at worldpost.com Mon Nov 22 19:22:32 2010 From: goldtech at worldpost.com (goldtech) Date: Mon, 22 Nov 2010 16:22:32 -0800 (PST) Subject: How to install uTidylib, easy_install problem Message-ID: I'm using activepython 2.6 on XP. I am trying to install uTidylib 0.2 with easy_install. I like uTidylib more vs. newer modules.and want to use it. I get output below. How do I install it? I do see it in http://pypi.python.org/simple/uTidylib/ Thanks. C:\Documents and Settings\user1>easy_install uTidylib install_dir C:\Python26\Lib\site-packages\ Searching for uTidylib Reading http://pypi.python.org/simple/uTidylib/ Reading http://utidylib.sf.net No local packages or download links found for uTidylib error: Could not find suitable distribution for Requirement.parse('uTidylib') From martin at v.loewis.de Mon Nov 22 19:42:50 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Tue, 23 Nov 2010 01:42:50 +0100 Subject: Glob in python which supports the ** wildcard In-Reply-To: <0cc11320-1f8c-4063-857e-52c16f0bb688@j18g2000yqd.googlegroups.com> References: <0cc11320-1f8c-4063-857e-52c16f0bb688@j18g2000yqd.googlegroups.com> Message-ID: <4CEB0E0A.4030105@v.loewis.de> Am 22.11.2010 22:43, schrieb Martin Lundberg: > Hi, > > I want to be able to let the user enter paths like this: > > apps/name/**/*.js > > and then find all the matching files in apps/name and all its > subdirectories. However I found out that Python's glob function > doesn't support the recursive ** wildcard. Is there any 3rd party glob > function which do support **? mercurial.match supports apps/name/**.js (IIUC). mglob supports rec:*.js. Regards, Martin From sridharr at activestate.com Mon Nov 22 19:43:58 2010 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Mon, 22 Nov 2010 16:43:58 -0800 Subject: How to install uTidylib, easy_install problem In-Reply-To: References: Message-ID: On 2010-11-22, at 4:22 PM, goldtech wrote: > I'm using activepython 2.6 on XP. I am trying to install uTidylib 0.2 > with easy_install. I like uTidylib more vs. newer modules.and want to > use it. I get output below. How do I install it? I do see it in > http://pypi.python.org/simple/uTidylib/ > > Thanks. > > C:\Documents and Settings\user1>easy_install uTidylib > install_dir C:\Python26\Lib\site-packages\ > Searching for uTidylib > Reading http://pypi.python.org/simple/uTidylib/ > Reading http://utidylib.sf.net > No local packages or download links found for uTidylib > error: Could not find suitable distribution for > Requirement.parse('uTidylib') You could try using the Windows installer (uTidylib-0.2.1.win32.exe) from: http://developer.berlios.de/project/showfiles.php?group_id=1810 And perhaps also let Cory Dodt know that his 6-year old package entry has broken download link in it http://pypi.python.org/pypi/uTidylib/ There is not even a source release for 0.2.1. I'd be more than happy to make this available in PyPM once I can find at least the source release of 0.2.1 -srid From dilip1984me at gmail.com Mon Nov 22 20:26:00 2010 From: dilip1984me at gmail.com (dilip raghavan) Date: Mon, 22 Nov 2010 17:26:00 -0800 (PST) Subject: File Reading In Mac Message-ID: <66e4164c-e81d-4a65-b847-c5ef900fa14c@a37g2000yqi.googlegroups.com> Hello , I have been trying to read contents from a file in MAC. I wrote the code filename = "test.rtf" FileHandle = open(filename,'r') fileStr = FileHandle.read() print fileStr FileHandle.close() When I see the output I see a lot of junk. The junk is like a lot of question marks, the font information and other details of the file. The actual content is lost in the junk. I have tried other methods like readline but still I see the junk. I tried the asme code in windows and it worked correctly. Can any one tell me the reason and the solution for this. Thanks In advance. From ndbecker2 at gmail.com Mon Nov 22 20:33:08 2010 From: ndbecker2 at gmail.com (Neal Becker) Date: Mon, 22 Nov 2010 20:33:08 -0500 Subject: bug? mmap doesn't like 0-length files Message-ID: mmap.mmap (f.fileno(), 0, prot=mmap.PROT_READ) error: [Errno 22] Invalid argument According to http://docs.python.org/library/mmap.html, mmap on _windows_ doesn't accept 0-length file. But this was tested on linux. Is this a bug? I don't see anything in linux man-page about the underlying C mmap function not accepting 0-length files. From nad at acm.org Mon Nov 22 20:50:07 2010 From: nad at acm.org (Ned Deily) Date: Mon, 22 Nov 2010 17:50:07 -0800 Subject: File Reading In Mac References: <66e4164c-e81d-4a65-b847-c5ef900fa14c@a37g2000yqi.googlegroups.com> Message-ID: In article <66e4164c-e81d-4a65-b847-c5ef900fa14c at a37g2000yqi.googlegroups.com>, dilip raghavan wrote: > I have been trying to read contents from a file in MAC. > I wrote the code > > filename = "test.rtf" > FileHandle = open(filename,'r') > > fileStr = FileHandle.read() > print fileStr > FileHandle.close() > > When I see the output I see a lot of junk. The junk is like a lot of > question marks, the font information and other details of the file. > The actual content is lost in the junk. > > I have tried other methods like readline but still I see the junk. > I tried the asme code in windows and it worked correctly. > Can any one tell me the reason and the solution for this. With an extension of "rtf", the file is presumably a "Rich Text Format" file. http://en.wikipedia.org/wiki/Rich_Text_Format There are some Python packages out there for dealing with rtf format files. You might try rtf2xml to convert the file, preserving style attributes: http://pypi.python.org/pypi/rtf2xml/ Or look at the Mac OS X command line utility textutil (man 1 textutil) to convert the file to another format. Or use the OS X TextEdit.app. -- Ned Deily, nad at acm.org From icanbob at gmail.com Mon Nov 22 20:52:10 2010 From: icanbob at gmail.com (bobicanprogram) Date: Mon, 22 Nov 2010 17:52:10 -0800 (PST) Subject: Round Trip: C to Python to C Module References: Message-ID: <37aedfc0-f943-4401-b9f7-91fdeef9fe7e@j18g2000yqd.googlegroups.com> On Nov 19, 11:05 am, Eric Frederich wrote: > I have a proprietary software PropSoft that I need to extend. > They support extensions written in C that can link against PropLib to > interact with the system. > > I have a Python C module that wraps a couple PropLib functions that I > call PyProp.>From an interactive Python shell I can import PyProp and call a function. > > None of these functions really do anything outside the context of > being logged into the PropSoft software; so all the functions fail > when running from Python alone. > > To my amazement, I was able to run PyRun_SimpleString("import > PyProp\nPyProp.some_function()") without setting PYTHONPATH or > anything. How this works, I don't know and I don't really care (at > the moment anyway). > > The problem I'm having now is how do I return things from my Python > script back to C? > Ultimately I won't be hard coding python inside of PyRun_SimpleString > but loading the script from a file. > So, how do I return values back to C? Python functions return values > but running a python script?... doesn't that just have an exit status? > Is there a mechanism for doing this? > > Thanks in advance, > ~Eric If you find you can't make this work as planned, you might want to check out the SIMPL toolkit (http://www.icanprogram.com/06py/lesson1/ lesson1.html) for an alternative way to connect C programs to Python modules. bob From cs at zip.com.au Mon Nov 22 21:59:29 2010 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 23 Nov 2010 13:59:29 +1100 Subject: bug? mmap doesn't like 0-length files In-Reply-To: References: Message-ID: <20101123025929.GA27420@cskk.homeip.net> On 22Nov2010 20:33, Neal Becker wrote: | mmap.mmap (f.fileno(), 0, prot=mmap.PROT_READ) | error: [Errno 22] Invalid argument | | According to http://docs.python.org/library/mmap.html, mmap on _windows_ | doesn't accept 0-length file. But this was tested on linux. Is this a bug? | | I don't see anything in linux man-page about the underlying C mmap function | not accepting 0-length files. On a local Gentoo Linux box mmap(2) says in the ERRORS section: EINVAL We don't like addr, length, or offset (e.g., they are too large, or not aligned on a page boundary). EINVAL (since Linux 2.6.12) length was 0. EINVAL flags contained neither MAP_PRIVATE or MAP_SHARED, or contained both of these values. Sure looks like a length of 0 is disliked. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Carpe Daemon - Seize the Background Process - Paul Tomblin From cs at zip.com.au Mon Nov 22 22:00:59 2010 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 23 Nov 2010 14:00:59 +1100 Subject: bug? mmap doesn't like 0-length files In-Reply-To: <20101123025929.GA27420@cskk.homeip.net> References: <20101123025929.GA27420@cskk.homeip.net> Message-ID: <20101123030059.GA27628@cskk.homeip.net> On 23Nov2010 13:59, I wrote: | On 22Nov2010 20:33, Neal Becker wrote: | | mmap.mmap (f.fileno(), 0, prot=mmap.PROT_READ) | | error: [Errno 22] Invalid argument [...] | | I don't see anything in linux man-page about the underlying C mmap function | | not accepting 0-length files. It's worth noting that any time you get an errno error/exception then it is almost certainly the underlying OS interface that has rejected your request, not the python library. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Don't have awk? Use this simple sh emulation: #!/bin/sh echo 'Awk bailing out!' >&2 exit 2 - Tom Horsley From nobody at nowhere.com Mon Nov 22 22:39:02 2010 From: nobody at nowhere.com (Nobody) Date: Tue, 23 Nov 2010 03:39:02 +0000 Subject: Reading bz2 file into numpy array References: <4cea3de7$0$6769$9b4e6d93@newsspool3.arcor-online.net> Message-ID: On Mon, 22 Nov 2010 11:37:22 +0100, Peter Otten wrote: >> is there a convenient way to read bz2 files into a numpy array? > > Try > f = bz2.BZ2File(filename) > data = numpy.fromstring(f.read(), numpy.float32) That's going to hurt if the file is large. You might be better off either extracting to a temporary file, or creating a pipe with numpy.fromfile() reading the pipe and either a thread or subprocess decompressing the data into the pipe. E.g.: import os import threading class Pipe(threading.Thread): def __init__(self, f, blocksize = 65536): super(Pipe, self).__init__() self.f = f self.blocksize = blocksize rd, wr = os.pipe() self.rd = rd self.wr = wr self.daemon = True self.start() def run(self): while True: s = self.f.read(self.blocksize) if not s: break os.write(self.wr, s) os.close(self.wr) def make_real(f): return os.fdopen(Pipe(f).rd, 'rb') Given the number of situations where you need a "real" (OS-level) file handle or descriptor rather than a Python "file-like object", something like this should really be part of the standard library. From nobody at nowhere.com Mon Nov 22 22:42:55 2010 From: nobody at nowhere.com (Nobody) Date: Tue, 23 Nov 2010 03:42:55 +0000 Subject: bug? mmap doesn't like 0-length files References: Message-ID: On Mon, 22 Nov 2010 20:33:08 -0500, Neal Becker wrote: > I don't see anything in linux man-page about the underlying C mmap function > not accepting 0-length files. My mmap(2) manpage says: ERRORS ... EINVAL (since Linux 2.6.12) length was 0. From gnarlodious at gmail.com Mon Nov 22 23:40:44 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Mon, 22 Nov 2010 20:40:44 -0800 (PST) Subject: CGI FieldStorage instances? References: <1ec25d72-a99e-4fd9-9d50-1ac8c65812e9@z19g2000yqb.googlegroups.com> <6trje65kt71v00339psntb6srgr5qtls5c@4ax.com> Message-ID: <8b8a7842-6249-4c0f-ac97-61bd646b52af@k3g2000vbp.googlegroups.com> Let me rephrase the question. Say I have a query string like this: ?view=Data&item=9875 What I want to do is simply invoke process "view" with variable "Data". This would replace my existing query string mess which looks like this: if 'view' in form and 'item' in form: HTML=view(Data, item(9875)) so it just seems like it would be easier to encode the process in the query rather than filtering the query string. -- Gnarlie From matlab.dude at mbnet.fi Tue Nov 23 02:24:39 2010 From: matlab.dude at mbnet.fi (MATLABdude) Date: Mon, 22 Nov 2010 23:24:39 -0800 (PST) Subject: MATLAB to Python? References: <74f276c3-38a4-4df0-af39-7b1f2a81472e@c39g2000yqi.googlegroups.com> <878w0s2uwv.fsf@gmail.com> <525ad586-d4fe-484a-9f9e-74b0e0fd78d4@s4g2000yql.googlegroups.com> Message-ID: On Nov 22, 11:11?am, Peter Otten <__pete... at web.de> wrote: > Try numpy.arange() instead: > >>> numpy.arange(0, 1, .1) > array([ 0. , ?0.1, ?0.2, ?0.3, ?0.4, ?0.5, ?0.6, ?0.7, ?0.8, ?0.9]) Thanks! It worked. What's wrong with the following code? ---8<---8<---8<--- T0_orig = [5, 50, 500, 5000] for counter in T0_orig: T0 = (L**2)/(D*pi**2)*counter amax = T0/kappa alpha = (10**-6)*amax lambda_, xx, f = nonhomog_solver(kappa, alpha, nu, nx) V0 = sqrt( T0_orig*(m**-1) + pi**2 * D/(m*L**2)*lambda_ ) print "V0 = ", V0 print "" ---8<---8<---8<--- Python says: ---8<---8<---8<--- Traceback (most recent call last): File "nonhomog.py", line 159, in main() File "nonhomog.py", line 157, in main nonhomog(0.2) File "nonhomog.py", line 152, in nonhomog V0 = sqrt( T0_orig*(m**-1) + pi**2 * D/(m*L**2)*lambda_ ) TypeError: can't multiply sequence by non-int of type 'float' ---8<---8<---8<--- From arnodel at gmail.com Tue Nov 23 02:43:20 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Tue, 23 Nov 2010 07:43:20 +0000 Subject: MATLAB to Python? References: <74f276c3-38a4-4df0-af39-7b1f2a81472e@c39g2000yqi.googlegroups.com> <878w0s2uwv.fsf@gmail.com> <525ad586-d4fe-484a-9f9e-74b0e0fd78d4@s4g2000yql.googlegroups.com> Message-ID: <87fwus8oyv.fsf@gmail.com> MATLABdude writes: > On Nov 22, 11:11?am, Peter Otten <__pete... at web.de> wrote: >> Try numpy.arange() instead: >> >>> numpy.arange(0, 1, .1) >> array([ 0. , ?0.1, ?0.2, ?0.3, ?0.4, ?0.5, ?0.6, ?0.7, ?0.8, ?0.9]) > > Thanks! It worked. > > What's wrong with the following code? > ---8<---8<---8<--- > T0_orig = [5, 50, 500, 5000] > for counter in T0_orig: > T0 = (L**2)/(D*pi**2)*counter > amax = T0/kappa > alpha = (10**-6)*amax > lambda_, xx, f = nonhomog_solver(kappa, alpha, nu, nx) > V0 = sqrt( T0_orig*(m**-1) + pi**2 * D/(m*L**2)*lambda_ ) > print "V0 = ", V0 > print "" > ---8<---8<---8<--- > > Python says: > ---8<---8<---8<--- > Traceback (most recent call last): > File "nonhomog.py", line 159, in > main() > File "nonhomog.py", line 157, in main > nonhomog(0.2) > File "nonhomog.py", line 152, in nonhomog > V0 = sqrt( T0_orig*(m**-1) + pi**2 * D/(m*L**2)*lambda_ ) > TypeError: can't multiply sequence by non-int of type 'float' > ---8<---8<---8<--- T0_orig is a list and you are trying to multiply this list by a float (m**-1) -- Arnaud From matlab.dude at mbnet.fi Tue Nov 23 02:49:19 2010 From: matlab.dude at mbnet.fi (MATLABdude) Date: Mon, 22 Nov 2010 23:49:19 -0800 (PST) Subject: MATLAB to Python? References: <74f276c3-38a4-4df0-af39-7b1f2a81472e@c39g2000yqi.googlegroups.com> <878w0s2uwv.fsf@gmail.com> <525ad586-d4fe-484a-9f9e-74b0e0fd78d4@s4g2000yql.googlegroups.com> <87fwus8oyv.fsf@gmail.com> Message-ID: <0b801c71-3ccd-49ea-b281-90ab93a80d9d@l17g2000yqe.googlegroups.com> On Nov 23, 9:43?am, Arnaud Delobelle wrote: > T0_orig is a list and you are trying to multiply this list by a float > (m**-1) Yes, yes of course. Thanks! :) This works: ---8<---8<---8<--- T0_orig = [5, 50, 500, 5000] for counter in T0_orig: T0 = (L**2)/(D*pi**2)*counter amax = T0/kappa alpha = (10**-6)*amax lambda_, xx, f = nonhomog_solver(kappa, alpha, nu, nx) V0 = sqrt( counter*(m**-1) + pi**2 * D/(m*L**2)*lambda_ ) print "V0 = ", V0 print "" ---8<---8<---8<--- From simon at brunningonline.net Tue Nov 23 04:08:59 2010 From: simon at brunningonline.net (Simon Brunning) Date: Tue, 23 Nov 2010 09:08:59 +0000 Subject: Glob in python which supports the ** wildcard In-Reply-To: <0cc11320-1f8c-4063-857e-52c16f0bb688@j18g2000yqd.googlegroups.com> References: <0cc11320-1f8c-4063-857e-52c16f0bb688@j18g2000yqd.googlegroups.com> Message-ID: On 22 November 2010 21:43, Martin Lundberg wrote: > Hi, > > I want to be able to let the user enter paths like this: > > apps/name/**/*.js > > and then find all the matching files in apps/name and all its > subdirectories. However I found out that Python's glob function > doesn't support the recursive ** wildcard. Is there any 3rd party glob > function which do support **? This does roughly what you want: http://code.activestate.com/recipes/499305-locating-files-throughout-a-directory-tree/ -- Cheers, Simon B. From simon at brunningonline.net Tue Nov 23 04:40:00 2010 From: simon at brunningonline.net (Simon Brunning) Date: Tue, 23 Nov 2010 09:40:00 +0000 Subject: Glob in python which supports the ** wildcard In-Reply-To: References: <0cc11320-1f8c-4063-857e-52c16f0bb688@j18g2000yqd.googlegroups.com> Message-ID: On 23 November 2010 09:26, Martin Lundberg wrote: > It does not seem to support the ** wildcard? It will recursively seek > for files matching a pattern like *.js but it won't support > /var/name/**/*.js as root, will it? I did say roughly. ;-) You'd need to do: for filename in locate("*.js", "/var/name/"): print filename Adding support for ** is left as an exercise for the reader. -- Cheers, Simon B. From __peter__ at web.de Tue Nov 23 05:18:52 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 23 Nov 2010 11:18:52 +0100 Subject: Reading bz2 file into numpy array References: <4cea3de7$0$6769$9b4e6d93@newsspool3.arcor-online.net> Message-ID: Nobody wrote: > On Mon, 22 Nov 2010 11:37:22 +0100, Peter Otten wrote: > >>> is there a convenient way to read bz2 files into a numpy array? >> >> Try > >> f = bz2.BZ2File(filename) >> data = numpy.fromstring(f.read(), numpy.float32) > > That's going to hurt if the file is large. Yes, but memory usage will peak at about 2*sizeof(data), and most scripts need more data than just a single numpy.array. In short: the OP is unlikely to run into the problem. > You might be better off either extracting to a temporary file, or creating > a pipe with numpy.fromfile() reading the pipe and either a thread or > subprocess decompressing the data into the pipe. I like to keep it simple, so if available RAM turns out to be the limiting factor I think extracting the data into a temporary file is a good backup plan. Peter From ulrich.eckhardt at dominolaser.com Tue Nov 23 05:36:05 2010 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Tue, 23 Nov 2010 11:36:05 +0100 Subject: Making module content available in parent module Message-ID: Hi! Note up front: I'm using Python2.6 still, I guess with 2.7 test discovery, I could get better results easier, right? Now, my problem is I have a directory containing test scripts which I all want to run. I used to run them individually and manually, but want to avoid this overhead in the future. tests/ foo.py # defines TestFoo1 and TestFoo2 bar.py # defines TestBar1 and TestBar2 What I would like to do now is this: from tests import * unittest.main() In other words, import all test files and run them. This does import them, but it turns out that I end up with modules foo and bar, and the unittests inside those are not found. Am I approaching the test loading the wrong way? Cheers! Uli PS: I've been trying a few things here, and stumbled across another thing that could provide a solution. I can "from tests import *", but then all these modules will pollute my namespace. I can "import tests", but then neither of the submodules will be in "tests". I tried "import tests.*", but that doesn't work. Is there no way to import a whole package but with its namespace? -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From bruno.desthuilliers at gmail.com Tue Nov 23 05:40:39 2010 From: bruno.desthuilliers at gmail.com (bruno.desthuilliers at gmail.com) Date: Tue, 23 Nov 2010 02:40:39 -0800 (PST) Subject: Python recursively __getattribute__ References: Message-ID: <2e563fac-88e9-47d0-b44d-1b40f4572f70@i17g2000vbq.googlegroups.com> On 22 nov, 21:44, Roman Dolgiy wrote: >> http://stackoverflow.com/questions/4247036/python-recursively-getattr... > > I need to support a lot of legacy code, with THC4k's approach I'll > have to modify project's existing code to use obj.attr1.val instead of > obj.attr1 but this is not suitable. You should probably re-read THC4k's answer. His code works just fine AFAICT: """ # the proxy maps attribute access to another object class GetattrProxy(object): def __init__(self, proxied, prefix=None): self.proxied = proxied self.prefix = prefix def __getattr__(self, key): attr = (key if self.prefix is None else self.prefix + '__' + key) try: # if the proxied object has the attr return it return getattr(self.proxied, attr) except AttributeError: # else just return another proxy return GetattrProxy(self.proxied, attr) # the thing you want to wrap class Target(object): attr1__attr2__attr3 = 5 attr2 = "attr2" t = Target() proxy = GetattrProxy(t) print "proxy.attr1.attr2.attr3 : '%s'" % proxy.attr1.attr2.attr3 print "proxy.attr2 : '%s'" % proxy.attr2 """ From gh at gregor-horvath.com Tue Nov 23 05:58:06 2010 From: gh at gregor-horvath.com (Gregor Horvath) Date: Tue, 23 Nov 2010 11:58:06 +0100 Subject: Making module content available in parent module References: Message-ID: <20101123115806.21fca7b4@valun> Hi, On Tue, 23 Nov 2010 11:36:05 +0100 Ulrich Eckhardt wrote: > Now, my problem is I have a directory containing test scripts which I > all want to run. I used to run them individually and manually, but > want to avoid this overhead in the future. > > tests/ > foo.py # defines TestFoo1 and TestFoo2 > bar.py # defines TestBar1 and TestBar2 Nose does what you want: http://packages.python.org/nose/ -- Gregor From steve+comp.lang.python at pearwood.info Tue Nov 23 07:35:02 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 Nov 2010 12:35:02 GMT Subject: Making module content available in parent module References: Message-ID: <4cebb4f6$0$29966$c3e8da3$5496439d@news.astraweb.com> On Tue, 23 Nov 2010 11:36:05 +0100, Ulrich Eckhardt wrote: > tests/ > foo.py # defines TestFoo1 and TestFoo2 > bar.py # defines TestBar1 and TestBar2 > > What I would like to do now is this: > > from tests import * > unittest.main() > > In other words, import all test files and run them. This does import > them, but it turns out that I end up with modules foo and bar, and the > unittests inside those are not found. Given the directory structure you show, I find that hard to believe. You should get an ImportError, as there is no module or package called "tests". But suppose you turn tests into a proper package: tests/ __init__.py foo.py bar.py You could have __init__.py include these lines: from foo import * from bar import * Then later, when you do this: from tests import * it will pick up everything from foo and bar, and unittest.main() should run those tests as well. I think. Or you could just do: for module in (foo, bar): try: unittest.main(module) except SystemExit: pass > PS: I've been trying a few things here, and stumbled across another > thing that could provide a solution. I can "from tests import *", but > then all these modules will pollute my namespace. I can "import tests", > but then neither of the submodules will be in "tests". I tried "import > tests.*", but that doesn't work. Is there no way to import a whole > package but with its namespace? The package needs to know what submodules to make available. Put inside __init__.py: import foo import bar and then from outside the package, do this: import tests Now tests.foo and tests.bar will exist. -- Steven From tartley at tartley.com Tue Nov 23 09:00:43 2010 From: tartley at tartley.com (Jonathan Hartley) Date: Tue, 23 Nov 2010 06:00:43 -0800 (PST) Subject: unittests with different parameters References: Message-ID: <846d4dd9-1f6e-424b-b85a-0c497bba434e@c39g2000yqi.googlegroups.com> On Nov 22, 11:38?am, Ulrich Eckhardt wrote: > Hi! > > I'm writing tests and I'm wondering how to achieve a few things most > elegantly with Python's unittest module. > > Let's say I have two flags invert X and invert Y. Now, for testing these, I > would write one test for each combination. What I have in the test case is > something like this: > > ? def test_invert_flags(self): > ? ? ? """test flags to invert coordinates""" > ? ? ? tests = [((10, 20), INVERT_NONE, (10, 20)), > ? ? ? ? ? ? ? ?((10, 20), INVERT_X, (-10, 20)), > ? ? ? ? ? ? ? ?((10, 20), INVERT_Y, (10, -20))] > ? ? ? for input, flags, expected in tests: > ? ? ? ? ? res = do_invert(input, flags) > ? ? ? ? ? self.assertEqual(res, expected, > ? ? ? ? ? ? ? ? ? ? ? ? ? ?"%s caused wrong results" % (flags,)) > > So, what I do that I test the function 'do_invert' for different input > combinations and verify the result. The ugly thing is that this will abort > the whole test if one of the tests in the loop fails. So, my question is > how do I avoid this? > > I know that I could write a common test function instead: > > ? def _test_invert_flags(self, input, flags, expected): > ? ? ? res = do_invert(input, flags) > ? ? ? self.assertEqual(res, expected) > > ? def test_invert_flags_non(self): > ? ? ? """test not inverting coordinates""" > ? ? ? self._test_invert_flags((10, 20), INVERT_NONE, (10, 20)) > > ? def test_invert_flags_x(self): > ? ? ? """test inverting X coordinates""" > ? ? ? self._test_invert_flags((10, 20), INVERT_X, (-10, 20)) > > ? def test_invert_flags_y(self): > ? ? ? """test inverting Y coordinates""" > ? ? ? self._test_invert_flags((10, 20), INVERT_Y, (10, -20)) > > What I don't like here is that this is unnecessarily verbose and that it > basically repeats information. Also, I'd rather construct the error message > from the data instead of maintaining it in different places, because > manually keeping those in sync is another, errorprone burden. > > Any suggestions? > > Uli > > -- > Domino Laser GmbH > Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 The following is a bit ghastly, I'm not sure I'd recommend it, but if you are determined, you could try dynamically adding test methods to the test class. The following is untested - I suspect I have made a schoolboy error in attempting to make methods out of functions - but something like it might work: class MyTestClass(unittest.TestCase): pass testdata = [ (INPUTS, EXPECTED), (INPUTS, EXPECTED), (INPUTS, EXPECTED), ] for index, (input, expected) in enumerate(testdata): # the following sets an attribute on MyTestClass # the names of the attributes are 'test_1', 'test_2', etc # the value of the attributes is a test method that performs the assert setattr( MyTestClass, 'test_%d' % (index,), lambda s: s.assertEquals(METHOD_UNDER_TEST(*input), expected) ) From wxjmfauth at gmail.com Tue Nov 23 09:02:16 2010 From: wxjmfauth at gmail.com (jmfauth) Date: Tue, 23 Nov 2010 06:02:16 -0800 (PST) Subject: Need advices regarding the strings (str, unicode, coding) used as interface for an external library. References: <62db9e18-a62f-403f-ae49-cb1eb6a22599@k5g2000vbn.googlegroups.com> Message-ID: <7b910f46-2b26-443a-96a9-aa84c36ea502@a30g2000vbt.googlegroups.com> Thanks for the reply. Subject closed. From tosters at gmail.com Tue Nov 23 09:54:34 2010 From: tosters at gmail.com (Roman Dolgiy) Date: Tue, 23 Nov 2010 06:54:34 -0800 (PST) Subject: Python recursively __getattribute__ References: <2e563fac-88e9-47d0-b44d-1b40f4572f70@i17g2000vbq.googlegroups.com> Message-ID: <7f33b8a4-7246-476e-a524-e32cf7b09a96@w29g2000vba.googlegroups.com> Thanks to Andreas Waldenburger, THC4k (http://stackoverflow.com/ questions/4247036/python-recursively-getattribute) and others for their tips. I was able to find solution: class Null(object): def __repr__(self): return "" def __str__(self): return '' def __nonzero__(self): return False class ResultAttrFactory(type): _cache = {} @classmethod def prepare(cls, base, result): dict_ = ResultAttr.__dict__.copy() dict_.update({ '_ResultAttr__base': base, '_ResultAttr__result': result}) return ('ResultAttr', (base,), dict_) def __new__(cls, base, result): if (base, result) in cls._cache: type_ = cls._cache[(base, result)] else: type_ = super(ResultAttrFactory, cls).__new__( cls, *cls.prepare(base, result)) cls._cache[(base, result)] = type_ return type_ def __init__(cls, base, result): pass class ResultAttr: """Should be used only with ResultAttrFactory""" @staticmethod def __new__(cls, arg1, name): return cls.__base.__new__(cls, arg1) def __init__(self, arg1, name): self.__name = name super(self.__class__, self).__init__(arg1) def get_result_attr(self, name): if self.__result.is_denorm_attr(name): attr = getattr(self.__result, name, None) else: attr = getattr(self.__result, name) return attr def __getattr__(self, name): lookup_name = "%s__%s" % (self.__name, name) attr = self.get_result_attr(lookup_name) if type(attr).__name__ == 'ResultAttr': type_ = attr.__base elif attr is None: type_ = Null else: type_ = type(attr) result_attr = ResultAttrFactory( type_, self.__result)(attr, lookup_name) return result_attr class BaseResult(object): """ >>> class Result(BaseResult): ... def __init__(self, *args, **kwargs): ... self.x = 35 ... self.y = 5 ... self.y__a = 3 ... self.y__b = 'hello' ... self.y__c__x = [1, 2, 3] ... super(Result, self, *args, **kwargs) >>> r = Result() >>> r.x 35 >>> type(r.x) >>> r.y 5 >>> type(r.y) # doctest:+ELLIPSIS >>> r.y.a 3 >>> r.y.b 'hello' >>> r.y.c # Is there any way to raise AtrributeError here? >>> r.y.d Traceback (most recent call last): AttributeError: 'Result' object has no attribute 'y__d' >>> r.y.c.x [1, 2, 3] """ def is_denorm_attr(self, name): return bool([k for k in self.__dict__.keys() if "%s__" % name in k]) def __getattribute__(self, name): attr = super(BaseResult, self).__getattribute__(name) if name in ('__dict__', 'is_denorm_attr'): return attr if self.is_denorm_attr(name): return ResultAttrFactory(type(attr), self)(attr, name) else: return attr if __name__ == '__main__': import doctest doctest.testmod() https://gist.github.com/710977 The only problem is: >>> r.y.c Is there any way to raise AtrributeError here? Also is there any negative side effects of such method? From duggar at alum.mit.edu Tue Nov 23 10:08:12 2010 From: duggar at alum.mit.edu (Keith H Duggar) Date: Tue, 23 Nov 2010 07:08:12 -0800 (PST) Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014020136.6e85d70b@tritium.streitmacht.eu> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> <08823dd4-588a-4729-a660-711e266c96b0@y23g2000yqd.googlegroups.com> Message-ID: <396f8de7-ece5-4e9c-919b-886eb65ae14a@a30g2000vbt.googlegroups.com> On Nov 22, 5:12?pm, Raffael Cavallaro wrote: > On 2010-11-22 11:25:34 -0500, scattered said: > > > And you don't think that [JH] could write a book about Haskell > > if he honestly came to think that it were a superior all-aroung > > language? > > Until he actually does, he has a financial interest in trash-talking > Haskell. This makes anything he says about Haskell suspect. > > > ?The fact that he *didn't* mindlessly reject [musical note lang] in favor of > > [Irish Ship Of The Desert] when [musical note lang] came out (despite > > the fact that at the time his company > > was deeply (exclusively?) invested in [Irish Ship Of The Desert] and > > arguably had a vested > > interest in having [musical note lang] fail to gain support) suggests > > that he is able > > to fairly evaluate the merits of other languages. > > No, it suggests that he saw that supporting the Irish Ship Of The > Desert meant going up against Microsoft, so he jumped to the MS > supported variant of the Donut Dromedary. > > You miss the fundamental point; having a financial interest in the > outcome of a debate makes anything that person says an advertisement > for his financial interests, not a fair assessment. There is a well-known name for such illogical reasoning: ad hominem. When a person poses an /argument/, nothing personal outside of the /argument/ is relevant. Thus, your claim that "anything that person says ..." is not only obvious hyperbole it is also illogical. It is a common refuge of those who cannot support their position with fact and logic. On more than one occasion Jon Harrop has all but crushed Ertugrul in this very forum with /source code/; that is as objective as it gets. KHD From raffaelcavallaro at pas.despam.s.il.vous.plait.mac.com Tue Nov 23 10:34:22 2010 From: raffaelcavallaro at pas.despam.s.il.vous.plait.mac.com (Raffael Cavallaro) Date: Tue, 23 Nov 2010 10:34:22 -0500 Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014020136.6e85d70b@tritium.streitmacht.eu> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> <08823dd4-588a-4729-a660-711e266c96b0@y23g2000yqd.googlegroups.com> <396f8de7-ece5-4e9c-919b-886eb65ae14a@a30g2000vbt.googlegroups.com> Message-ID: On 2010-11-23 10:08:12 -0500, Keith H Duggar said: > There is a well-known name for such illogical reasoning: ad hominem. You don't understand ad hominem: "The ad hominem is a classic logical fallacy,[2] but it is not always fallacious. For in some instances, questions of personal conduct, character, motives, etc., are legitimate and relevant to the issue.[3]" Source: Sometimes the person's conduct and motives *are relevant* to the point under discussion. Financial conflict of interest is a perfect example where it *is* legitimate and relevant to explore a person's motives and conduct outside of the debate. In this case, JH's conduct outside of the debate (i.e., the fact that he earns his living by selling tools and training for a particular set of languages) and his motives (i.e., he is therefore financially motivated to present these languages in the best possible light and to trash-talk other languages), render his arguments in the debate inherently suspect. warmest regards, Ralph -- Raffael Cavallaro From ulrich.eckhardt at dominolaser.com Tue Nov 23 10:42:00 2010 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Tue, 23 Nov 2010 16:42:00 +0100 Subject: Making module content available in parent module References: <4cebb4f6$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Tue, 23 Nov 2010 11:36:05 +0100, Ulrich Eckhardt wrote: >> PS: I've been trying a few things here, and stumbled across another >> thing that could provide a solution. I can "from tests import *", but >> then all these modules will pollute my namespace. I can "import tests", >> but then neither of the submodules will be in "tests". I tried "import >> tests.*", but that doesn't work. Is there no way to import a whole >> package but with its namespace? > > The package needs to know what submodules to make available. Put inside > __init__.py: > > > import foo > import bar > > and then from outside the package, do this: > > import tests > > Now tests.foo and tests.bar will exist. I've been reading up on packages, but I didn't find anything like that in the documentation, all I found was the meaning of __all__. If I import the modules explicitly there, there's no need to define __all__, unless there are some I don't want to import there, right? Well, I'll try it and see. ;) Steven, thank you for this explanation! Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From duggar at alum.mit.edu Tue Nov 23 11:34:14 2010 From: duggar at alum.mit.edu (Keith H Duggar) Date: Tue, 23 Nov 2010 08:34:14 -0800 (PST) Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014020136.6e85d70b@tritium.streitmacht.eu> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> <08823dd4-588a-4729-a660-711e266c96b0@y23g2000yqd.googlegroups.com> <396f8de7-ece5-4e9c-919b-886eb65ae14a@a30g2000vbt.googlegroups.com> Message-ID: <967678a1-fc5d-4b61-86c5-79a298999582@p1g2000vbo.googlegroups.com> On Nov 23, 10:34?am, Raffael Cavallaro wrote: > On 2010-11-23 10:08:12 -0500, Keith H Duggar said: > > On Nov 22, 5:12?pm, Raffael Cavallaro wrote: > > > On 2010-11-22 11:25:34 -0500, scattered said: > > > > > > > And you don't think that [JH] could write a book about Haskell > > > > if he honestly came to think that it were a superior all-aroung > > > > language? > > > > > > Until he actually does, he has a financial interest in trash-talking > > > Haskell. This makes anything he says about Haskell suspect. > > > > > > > ?The fact that he *didn't* mindlessly reject [musical note lang] in favor of > > > > [Irish Ship Of The Desert] when [musical note lang] came out (despite > > > > the fact that at the time his company > > > > was deeply (exclusively?) invested in [Irish Ship Of The Desert] and > > > > arguably had a vested > > > > interest in having [musical note lang] fail to gain support) suggests > > > > that he is able > > > > to fairly evaluate the merits of other languages. > > > > > > No, it suggests that he saw that supporting the Irish Ship Of The > > > Desert meant going up against Microsoft, so he jumped to the MS > > > supported variant of the Donut Dromedary. > > > > > > You miss the fundamental point; having a financial interest in the > > > outcome of a debate makes anything that person says an advertisement > > > for his financial interests, not a fair assessment. > > > > There is a well-known name for such illogical reasoning: ad hominem. > > When a person poses an /argument/, nothing personal outside of the > > /argument/ is relevant. Thus, your claim that "anything that person > > says ..." is not only obvious hyperbole it is also illogical. > > > > It is a common refuge of those who cannot support their position > > with fact and logic. On more than one occasion Jon Harrop has all > > but crushed Ertugrul in this very forum with /source code/; that > > is as objective as it gets. > > You don't understand ad hominem: > > "The ad hominem is a classic logical fallacy,[2] but it is not always > fallacious. For in some instances, questions of personal conduct, > character, motives, etc., are legitimate and relevant to the issue.[3]" > > Source: > > Sometimes the person's conduct and motives *are relevant* to the point > under discussion. Financial conflict of interest is a perfect example > where it *is* legitimate and relevant to explore a person's motives and > conduct outside of the debate. > > In this case, JH's conduct outside of the debate (i.e., the fact that > he earns his living by selling tools and training for a particular set > of languages) and his motives (i.e., he is therefore financially > motivated to present these languages in the best possible light and to > trash-talk other languages), render his arguments in the debate > inherently suspect. You don't understand the implications of your own words: "having a financial interest in the outcome of a debate makes anything that person says an advertisement for his financial interests, not a fair assessment." is substantially different from "render his arguments in the debate inherently suspect." Do you understand how? Hint, see my comment regarding "hyperbole" and also consider the relationship between the qualifier "anything" and universal quantification. I think if you think a bit more carefully you will come to see how your original statement was indeed fallacious ad hominem. (And that specific example remains so regardless of which common approach to informal logic you take ie whether you choose one that is more or less sympathetic to ad hominem in general.) KHD From darcy at druid.net Tue Nov 23 11:42:29 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 23 Nov 2010 11:42:29 -0500 Subject: Scheme as a virtual machine? In-Reply-To: References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014020136.6e85d70b@tritium.streitmacht.eu> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> <08823dd4-588a-4729-a660-711e266c96b0@y23g2000yqd.googlegroups.com> <396f8de7-ece5-4e9c-919b-886eb65ae14a@a30g2000vbt.googlegroups.com> Message-ID: <20101123114229.69c6609e.darcy@druid.net> On Tue, 23 Nov 2010 10:34:22 -0500 Raffael Cavallaro wrote: > On 2010-11-23 10:08:12 -0500, Keith H Duggar said: > > There is a well-known name for such illogical reasoning: ad hominem. > You don't understand ad hominem: Perhaps you don't understand it. > "The ad hominem is a classic logical fallacy,[2] but it is not always > fallacious. For in some instances, questions of personal conduct, > character, motives, etc., are legitimate and relevant to the issue.[3]" So, explain how motive makes the logic wrong in this case then. > In this case, JH's conduct outside of the debate (i.e., the fact that > he earns his living by selling tools and training for a particular set > of languages) and his motives (i.e., he is therefore financially > motivated to present these languages in the best possible light and to > trash-talk other languages), render his arguments in the debate > inherently suspect. Fine. Suspect his arguments to the point that you examine them closely and then explain what you found erroneous in them. Don't just claim that we should dismiss them because of who made them. You know, it's just possible that Jon actually investigated Haskell before choosing to focus on CL. That would make his opinion carry more weight, not less. Remind me, how is this relevant to Python? -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From huisky at gmail.com Tue Nov 23 12:47:30 2010 From: huisky at gmail.com (huisky) Date: Tue, 23 Nov 2010 09:47:30 -0800 (PST) Subject: Time and date operation Message-ID: <1550b9d2-b8c4-48f1-be27-a3df3ad2eb3e@32g2000yqz.googlegroups.com> Hi everyone, Could you anybody shed lights to me? Say I have two dics. >>> cstart defaultdict(, {15424: ['Dec', '6', '18:57:40'], 552: ['Dec', '7', '09:31:00'], 15500: ['Dec', '6', '20:17:02'], 18863: ['Dec', '7', '13:14:47'], 18291: ['Dec', '6', '21:01:17'], 18969: ['Dec', '7', '14:28:42'], 18937: ['Dec', '7', '14:21:34']}) >>> ccompl defaultdict(, {15424: ['Dec', '6', '19:42:55'], 18291: ['Dec', '6', '21:01:28'], 15500: ['Dec', '6', '20:26:03'], 18863: ['Dec', '7', '13:24:07']}) and I need to calculate the difference time if the key value is the same in both dics. thanks in advance Huisky From clp2 at rebertia.com Tue Nov 23 13:11:33 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 23 Nov 2010 10:11:33 -0800 Subject: Time and date operation In-Reply-To: <1550b9d2-b8c4-48f1-be27-a3df3ad2eb3e@32g2000yqz.googlegroups.com> References: <1550b9d2-b8c4-48f1-be27-a3df3ad2eb3e@32g2000yqz.googlegroups.com> Message-ID: On Tue, Nov 23, 2010 at 9:47 AM, huisky wrote: > Hi everyone, > > Could you anybody shed lights to me? Say I have two dics. >>>> cstart > defaultdict(, {15424: ['Dec', '6', '18:57:40'], 552: > ['Dec', '7', '09:31:00'], 15500: ['Dec', '6', '20:17:02'], 18863: > ['Dec', '7', '13:14:47'], 18291: ['Dec', '6', '21:01:17'], 18969: > ['Dec', '7', '14:28:42'], 18937: ['Dec', '7', '14:21:34']}) >>>> ccompl > defaultdict(, {15424: ['Dec', '6', '19:42:55'], 18291: > ['Dec', '6', '21:01:28'], 15500: ['Dec', '6', '20:26:03'], 18863: > ['Dec', '7', '13:24:07']}) > > and I need to calculate the difference time if the key value is the > same in both dics. Create datetime.datetime objects. Subtract one from another and you'll get a datetime.timedelta object representing the difference between them. The fine manual: http://docs.python.org/library/datetime.html#datetime-objects Cheers, Chris -- http://blog.rebertia.com From clp2 at rebertia.com Tue Nov 23 13:50:19 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 23 Nov 2010 10:50:19 -0800 Subject: Time and date operation In-Reply-To: <002701cb8b3e$3c7c6690$b57533b0$@com> References: <1550b9d2-b8c4-48f1-be27-a3df3ad2eb3e@32g2000yqz.googlegroups.com> <002701cb8b3e$3c7c6690$b57533b0$@com> Message-ID: > -----Original Message----- > From: clp2 at rebertia.com [mailto: clp2 at rebertia.com] > Sent: 2010?11?23? 19:12 > To: huisky > Cc: python-list at python.org > Subject: Re: Time and date operation > > On Tue, Nov 23, 2010 at 9:47 AM, huisky wrote: >> Hi everyone, >> >> Could you anybody shed lights to me? Say I have two dics. >>>>> cstart >> defaultdict(, {15424: ['Dec', '6', '18:57:40'], 552: >> ['Dec', '7', '09:31:00'], 15500: ['Dec', '6', '20:17:02'], 18863: >> ['Dec', '7', '13:14:47'], 18291: ['Dec', '6', '21:01:17'], 18969: >> ['Dec', '7', '14:28:42'], 18937: ['Dec', '7', '14:21:34']}) >>>>> ccompl >> defaultdict(, {15424: ['Dec', '6', '19:42:55'], 18291: >> ['Dec', '6', '21:01:28'], 15500: ['Dec', '6', '20:26:03'], 18863: >> ['Dec', '7', '13:24:07']}) >> >> and I need to calculate the difference time if the key value is the >> same in both dics. > > Create datetime.datetime objects. Subtract one from another and you'll > get a datetime.timedelta object representing the difference between > them. > The fine manual: http://docs.python.org/library/datetime.html#datetime-objects > On Tue, Nov 23, 2010 at 10:42 AM, Huisky wrote: > Hi, > > Thanks. I'm wondering is datetime.datetime objects able to read 'Dec', for example? Yes. Use the %b format directive when calling datetime.datetime.strptime(). http://docs.python.org/library/datetime.html#datetime.datetime.strptime http://docs.python.org/library/time.html#time.strftime Cheers, Chris -- http://blog.rebertia.com From bnbowman at gmail.com Tue Nov 23 14:28:56 2010 From: bnbowman at gmail.com (Brett Bowman) Date: Tue, 23 Nov 2010 11:28:56 -0800 Subject: Subprocess Call works on Windows, but not Ubuntu Message-ID: I ran into an interesting problem trying to spawn a subprocess, so I thought I'd ask if the experts could explain it to me. I'm spawning a subprocess to run "pdf2txt.py", which is a tool that is distributed with PDFminer to do moderately advanced text-dumps of PDFs. Yet when I run the same code on my two dev machines - one Win XP, the other Ubuntu 10.04 or 10.10 - it only works on the former and not the later. And its not terribly complicated code. # Code Start sp_line = 'python pdf2txt.py -p 1 -o %s "%s"' % ('temp.out', pdf_filename) print sp_line sp = subprocess.Popen(sp_line) sp.wait() with open('temp.out', 'r') as pdf_handle: #Do stuff to read the file The output from the print statements reads: python pdf2txt.py -p 1 -o temp.out "Aarts et al (2009).pdf" That command works on both systems when copied directly to the command-line, and the python script it is a part of works on the Windows machine, but I can't the script to work on Ubuntu for the life of me. What am I missing? /b/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Tue Nov 23 14:37:05 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 23 Nov 2010 11:37:05 -0800 Subject: Subprocess Call works on Windows, but not Ubuntu In-Reply-To: References: Message-ID: On Tue, Nov 23, 2010 at 11:28 AM, Brett Bowman wrote: > I ran into an interesting problem trying to spawn a subprocess, so I thought > I'd ask if the experts could explain it to me. ?I'm spawning a subprocess to > run "pdf2txt.py", which is a tool that is distributed with PDFminer to do > moderately advanced text-dumps of PDFs. ?Yet when I run the same code on my > two dev machines - one Win XP, the other Ubuntu 10.04 or 10.10 - it only > works on the former and not the later. And its not terribly complicated > code. > # Code Start > sp_line = 'python pdf2txt.py -p 1 -o %s "%s"' % ('temp.out', pdf_filename) > print sp_line > sp = subprocess.Popen(sp_line) > python pdf2txt.py -p 1 -o temp.out "Aarts et al (2009).pdf" > That command works on both systems when copied directly to the command-line, > and the python script it is a part of works on the Windows machine, but I > can't the script to work on Ubuntu for the life of me. ?What am I missing? Quoting the docs (for the Nth time; emphasis added): """ On Unix, with shell=False (default): args should normally be a sequence. ***If a string is specified for args***, it will be used as the name or path of the program to execute; ***this will only work if the program is being given no arguments.*** """ http://docs.python.org/library/subprocess.html#subprocess.Popen Fixed version: sp_args = ['python', 'pdf2txt.py', '-p', '1', '-o', 'temp.out', pdf_filename] sp = subprocess.Popen(sp_args) Cheers, Chris -- http://blog.rebertia.com From burton at userful.com Tue Nov 23 14:53:25 2010 From: burton at userful.com (Burton Samograd) Date: Tue, 23 Nov 2010 12:53:25 -0700 Subject: Collect output to string Message-ID: Hello, I was wondering if there is any way in python to 'collect output to string' as in some lisps/schemes. Output being, printed output to the console using print. Thanks. -- Burton Samograd From clp2 at rebertia.com Tue Nov 23 15:02:47 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 23 Nov 2010 12:02:47 -0800 Subject: Collect output to string In-Reply-To: References: Message-ID: On Tue, Nov 23, 2010 at 11:53 AM, Burton Samograd wrote: > Hello, > > I was wondering if there is any way in python to 'collect output to > string' as in some lisps/schemes. ?Output being, printed output to the > console using print. Rebind sys.stdout to a StringIO object. http://docs.python.org/library/sys.html#sys.stdout http://docs.python.org/library/stringio.html Cheers, Chris -- http://blog.rebertia.com From bnbowman at gmail.com Tue Nov 23 15:31:25 2010 From: bnbowman at gmail.com (Brett Bowman) Date: Tue, 23 Nov 2010 12:31:25 -0800 Subject: Subprocess Call works on Windows, but not Ubuntu In-Reply-To: References: Message-ID: Ah, that fixed it. Thank you. On Tue, Nov 23, 2010 at 11:37 AM, Chris Rebert wrote: > On Tue, Nov 23, 2010 at 11:28 AM, Brett Bowman wrote: > > I ran into an interesting problem trying to spawn a subprocess, so I > thought > > I'd ask if the experts could explain it to me. I'm spawning a subprocess > to > > run "pdf2txt.py", which is a tool that is distributed with PDFminer to do > > moderately advanced text-dumps of PDFs. Yet when I run the same code on > my > > two dev machines - one Win XP, the other Ubuntu 10.04 or 10.10 - it only > > works on the former and not the later. And its not terribly complicated > > code. > > # Code Start > > sp_line = 'python pdf2txt.py -p 1 -o %s "%s"' % ('temp.out', > pdf_filename) > > print sp_line > > sp = subprocess.Popen(sp_line) > > > python pdf2txt.py -p 1 -o temp.out "Aarts et al (2009).pdf" > > That command works on both systems when copied directly to the > command-line, > > and the python script it is a part of works on the Windows machine, but I > > can't the script to work on Ubuntu for the life of me. What am I > missing? > > Quoting the docs (for the Nth time; emphasis added): > """ > On Unix, with shell=False (default): args should normally be a > sequence. ***If a string is specified for args***, it will be used as > the name or path of the program to execute; ***this will only work if > the program is being given no arguments.*** > """ http://docs.python.org/library/subprocess.html#subprocess.Popen > > Fixed version: > sp_args = ['python', 'pdf2txt.py', '-p', '1', '-o', 'temp.out', > pdf_filename] > sp = subprocess.Popen(sp_args) > > Cheers, > Chris > -- > http://blog.rebertia.com > -------------- next part -------------- An HTML attachment was scrubbed... URL: From burton at userful.com Tue Nov 23 15:59:02 2010 From: burton at userful.com (Burton Samograd) Date: Tue, 23 Nov 2010 13:59:02 -0700 Subject: Collect output to string References: Message-ID: Chris Rebert writes: > On Tue, Nov 23, 2010 at 11:53 AM, Burton Samograd wrote: >> Hello, >> >> I was wondering if there is any way in python to 'collect output to >> string' as in some lisps/schemes. ?Output being, printed output to the >> console using print. > > Rebind sys.stdout to a StringIO object. > http://docs.python.org/library/sys.html#sys.stdout > http://docs.python.org/library/stringio.html Thanks for the tip. Here's my function: def with_output_to_string(f, args): oldstdout = sys.stdout buffer = StringIO.StringIO() sys.stdout = buffer apply(f, args) sys.stdout = oldstdout return buffer.getvalue() Any way I could improve it? -- Burton Samograd From astar at spamcop.net Tue Nov 23 16:13:32 2010 From: astar at spamcop.net (astar) Date: Tue, 23 Nov 2010 13:13:32 -0800 (PST) Subject: progamming approach review, child processes Message-ID: <9bf2b0b6-1c34-40c6-b85f-27836d3b5f2d@o23g2000prh.googlegroups.com> So I have not done much with child processes before. I have an input of programs to be updated, a child process that does the compiles and links (with a log output to an individual file), and a process wait at the end. Except the child process can hang (at the moment, the problem that might show up is: waiting for input). At which point a convenience becomes a hinderance. As it happens the idea of doing the compiles in parallel is supported by the ports system I am working with. So I thought I could avoid the wait syntax, do a lot of children, save all the process hmm I am not sure what to call the pointers, and after a while interrogate the process information to see if all the children got done. At some point, I could think a child is hung and maybe do some useful reporting. Realize that this might be the next day because the compiles might take a while. Is this a reasonable approach? Thank you for your consideration. Possibly pointless information: openbsd 4.8 workstation, packages, but using the port system, want only to compile packages I have installed. There is a utility to tell me which packages are out of date. And I really know I could use pkg_add -u. I did some attachments of the programs, but I suppose they will get scrubbed.. python is I think 2.6.5? From ian.g.kelly at gmail.com Tue Nov 23 16:15:46 2010 From: ian.g.kelly at gmail.com (Ian) Date: Tue, 23 Nov 2010 13:15:46 -0800 (PST) Subject: Collect output to string References: Message-ID: <22e3a2c0-a85b-4d2a-8a4f-ebb719807467@y19g2000prb.googlegroups.com> On Nov 23, 1:59?pm, Burton Samograd wrote: > Thanks for the tip. ?Here's my function: > > def with_output_to_string(f, args): > ? ? ?oldstdout = sys.stdout > ? ? ?buffer = StringIO.StringIO() > ? ? ?sys.stdout = buffer > ? ? ?apply(f, args) > ? ? ?sys.stdout = oldstdout > ? ? ?return buffer.getvalue() > > Any way I could improve it? You should wrap the inner function call in a try-finally call to ensure that the old stdout gets restored even if f raises an exception. Also, the `apply` function is deprecated. Use `f(*args)` instead. The function as a whole would be a bit more Pythonic if written as a decorator IMO, but that's your call. Cheers, Ian From python at mrabarnett.plus.com Tue Nov 23 16:17:53 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 23 Nov 2010 21:17:53 +0000 Subject: Collect output to string In-Reply-To: References: Message-ID: <4CEC2F81.4030106@mrabarnett.plus.com> On 23/11/2010 20:59, Burton Samograd wrote: > Chris Rebert writes: > >> On Tue, Nov 23, 2010 at 11:53 AM, Burton Samograd wrote: >>> Hello, >>> >>> I was wondering if there is any way in python to 'collect output to >>> string' as in some lisps/schemes. Output being, printed output to the >>> console using print. >> >> Rebind sys.stdout to a StringIO object. >> http://docs.python.org/library/sys.html#sys.stdout >> http://docs.python.org/library/stringio.html > > Thanks for the tip. Here's my function: > > def with_output_to_string(f, args): > oldstdout = sys.stdout > buffer = StringIO.StringIO() > sys.stdout = buffer > apply(f, args) > sys.stdout = oldstdout > return buffer.getvalue() > > Any way I could improve it? > Use a try...finally block in an exception occurs: try: apply(f, args) finally: sys.stdout = oldstdout and possibly also replace the older: apply(f, args) with the newer: f(*args) You might also want to handle keyword arguments. From clp2 at rebertia.com Tue Nov 23 16:42:10 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 23 Nov 2010 13:42:10 -0800 Subject: Collect output to string In-Reply-To: <22e3a2c0-a85b-4d2a-8a4f-ebb719807467@y19g2000prb.googlegroups.com> References: <22e3a2c0-a85b-4d2a-8a4f-ebb719807467@y19g2000prb.googlegroups.com> Message-ID: On Tue, Nov 23, 2010 at 1:15 PM, Ian wrote: > On Nov 23, 1:59?pm, Burton Samograd wrote: >> Thanks for the tip. ?Here's my function: >> >> def with_output_to_string(f, args): >> ? ? ?oldstdout = sys.stdout >> ? ? ?buffer = StringIO.StringIO() >> ? ? ?sys.stdout = buffer >> ? ? ?apply(f, args) >> ? ? ?sys.stdout = oldstdout >> ? ? ?return buffer.getvalue() >> >> Any way I could improve it? > > You should wrap the inner function call in a try-finally call to > ensure that the old stdout gets restored even if f raises an > exception. > > Also, the `apply` function is deprecated. ?Use `f(*args)` instead. > > The function as a whole would be a bit more Pythonic if written as a > decorator IMO, but that's your call. A context manager could also be worth considering. http://docs.python.org/library/stdtypes.html#context-manager-types Cheers, Chris From tjreedy at udel.edu Tue Nov 23 18:22:41 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 23 Nov 2010 18:22:41 -0500 Subject: Collect output to string In-Reply-To: References: Message-ID: On 11/23/2010 3:02 PM, Chris Rebert wrote: > On Tue, Nov 23, 2010 at 11:53 AM, Burton Samograd wrote: >> Hello, >> >> I was wondering if there is any way in python to 'collect output to >> string' as in some lisps/schemes. Output being, printed output to the >> console using print. > > Rebind sys.stdout to a StringIO object. > http://docs.python.org/library/sys.html#sys.stdout > http://docs.python.org/library/stringio.html If you are using print or print(), you can redirect output to the StringIO object with >>sfile or file=sfile. I use the latter in a custom test function where I normally want output to the screen but occasionally want to capture test reports. -- Terry Jan Reedy From es at ertes.de Tue Nov 23 18:48:24 2010 From: es at ertes.de (Ertugrul =?UTF-8?B?U8O2eWxlbWV6?=) Date: Wed, 24 Nov 2010 00:48:24 +0100 Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014020136.6e85d70b@tritium.streitmacht.eu> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> <08823dd4-588a-4729-a660-711e266c96b0@y23g2000yqd.googlegroups.com> <396f8de7-ece5-4e9c-919b-886eb65ae14a@a30g2000vbt.googlegroups.com> Message-ID: <20101124004824.7ec98977@tritium.streitmacht.eu> Keith H Duggar wrote: > It is a common refuge of those who cannot support their position with > fact and logic. On more than one occasion Jon Harrop has all but > crushed Ertugrul in this very forum with /source code/; that is as > objective as it gets. Since Jon has financial reasons to invest time doing this and I don't, this is nowhere near "crushing" or "objective". It's simply meaningless. If someone pays me for writing proof code or coming up with challenges, then I will, and I assure you, I would give him a hard time, since I'm an experienced Haskell programmer, who uses it for many different, practical purposes in the real world outside of academia. And I stated explicitly many times that (without being paid) I don't feel like wasting time proving my point to Jon, who would just come up with new arbitrary arguments and challenges anyway, as he does all the time. Jon doesn't and cannot acknowledge valid arguments, so it would be an ongoing, pointless cycle. After all, he was the only one posing stupid challenges on me at all, deliberately constructing problems to be easy to solve in his languages. When I would challenge him, the picture would change, but I think, this is stupid and infantile enough not to do it. In fact, I've even done it once and proved my point that way (which, as always, he didn't acknowledge, but I don't care anymore). Greets, Ertugrul -- nightmare = unsafePerformIO (getWrongWife >>= sex) http://ertes.de/ From gnarlodious at gmail.com Tue Nov 23 21:01:49 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Tue, 23 Nov 2010 18:01:49 -0800 (PST) Subject: CGI FieldStorage instances? References: <1ec25d72-a99e-4fd9-9d50-1ac8c65812e9@z19g2000yqb.googlegroups.com> <6trje65kt71v00339psntb6srgr5qtls5c@4ax.com> <8b8a7842-6249-4c0f-ac97-61bd646b52af@k3g2000vbp.googlegroups.com> Message-ID: On Nov 22, 11:32?pm, Dennis Lee Bieber wrote: > ? ? ? ? Or upgrade to some modernistic framework wherein the application is > a monolithic program and the "name/" portion maps to methods/functions > within the application... Yes, that describes what I am looking for! Is there such a modernistic framework? Links? -- Gnarlie, K5ZN From ian.g.kelly at gmail.com Tue Nov 23 21:22:00 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 23 Nov 2010 19:22:00 -0700 Subject: CGI FieldStorage instances? In-Reply-To: References: <1ec25d72-a99e-4fd9-9d50-1ac8c65812e9@z19g2000yqb.googlegroups.com> <6trje65kt71v00339psntb6srgr5qtls5c@4ax.com> <8b8a7842-6249-4c0f-ac97-61bd646b52af@k3g2000vbp.googlegroups.com> Message-ID: On 11/23/2010 7:01 PM, Gnarlodious wrote: > On Nov 22, 11:32 pm, Dennis Lee Bieber wrote: > >> Or upgrade to some modernistic framework wherein the application is >> a monolithic program and the "name/" portion maps to methods/functions >> within the application... > > Yes, that describes what I am looking for! Is there such a modernistic > framework? Links? Try Django[1] or TurboGears[2]. [1] http://www.djangoproject.com/ [2] http://www.turbogears.org/ Cheers, Ian From stackslip at gmail.com Wed Nov 24 00:55:07 2010 From: stackslip at gmail.com (Garland Fulton) Date: Tue, 23 Nov 2010 20:55:07 -0900 Subject: Arrays Message-ID: Is there a way I can define an Array of and unknown size so I can add and remove to or from it? Are arrays immutable? -------------- next part -------------- An HTML attachment was scrubbed... URL: From iamforufriends at gmail.com Wed Nov 24 01:05:15 2010 From: iamforufriends at gmail.com (DATE@COUPLES) Date: Tue, 23 Nov 2010 22:05:15 -0800 (PST) Subject: BUEATYFUL CHEATING HOUSE WIVES FOR FREE DATING.... Message-ID: <5407e135-6073-4f99-a89e-49eed73ae344@n32g2000pre.googlegroups.com> BUEATYFUL CHEATING HOUSE WIVES FOR FREE DATING.... http://u3.co.za/m3 http://u3.co.za/m3 http://u3.co.za/m3 http://u3.co.za/m3 From ian.g.kelly at gmail.com Wed Nov 24 02:02:14 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 24 Nov 2010 00:02:14 -0700 Subject: Arrays In-Reply-To: References: Message-ID: On 11/23/2010 10:55 PM, Garland Fulton wrote: > Is there a way I can define an Array of and unknown size so I can add > and remove to or from it? Do you mean the arrays of the array module, or NumPy arrays, or something else entirely? In the first case, yes; arrays behave more or less like lists, but more efficiently and with type constraints. In the second case, I believe you have to explicitly resize the array in order to add new elements to it. > Are arrays immutable? No in either case. Cheers, Ian From gallium.arsenide at gmail.com Wed Nov 24 02:45:18 2010 From: gallium.arsenide at gmail.com (John Yeung) Date: Tue, 23 Nov 2010 23:45:18 -0800 (PST) Subject: Ensuring symmetry in difflib.SequenceMatcher Message-ID: <135c0dfc-c382-4dd3-bfaf-8d508e5e648b@j21g2000vba.googlegroups.com> I'm generally pleased with difflib.SequenceMatcher: It's probably not the best available string matcher out there, but it's in the standard library and I've seen worse in the wild. One thing that kind of bothers me is that it's sensitive to which argument you pick as "seq1" and which you pick as "seq2": Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import difflib >>> difflib.SequenceMatcher(None, 'BYRD', 'BRADY').ratio() 0.44444444444444442 >>> difflib.SequenceMatcher(None, 'BRADY', 'BYRD').ratio() 0.66666666666666663 >>> Is this a bug? I am guessing the algorithm is implemented correctly, and that it's just an inherent property of the algorithm used. It's certainly not what I'd call a desirably property. Are there any simple adjustments that can be made without sacrificing (too much) performance? John From caseyalice at adam.com.au Wed Nov 24 03:22:09 2010 From: caseyalice at adam.com.au (Adrian Casey) Date: Wed, 24 Nov 2010 17:52:09 +0930 Subject: pyqt4: multi-threaded database access Message-ID: <38ydnblHjISvVnHRnZ2dnUVZ_rydnZ2d@adnap.net.au> I have a PyQt4 multi-threaded application which accesses many hosts concurrently via ssh. I would like each thread to have access to a database so that it can look up details about the particular system it is connected to. The easy way is to have each thread create a connection to the database. However, this is wasteful and likely to exhaust the maximum number of connections the database (postgresql) allows. Instead, I would like to share a single database connection between all threads. In PyQt4, this is not possible since the database connection can only be used by the thread which created it. So, I'm thinking I'll create a thread to just handle database queries. The worker threads will communicate with the database thread using signals and slots. My question is, if I have 20 worker threads who have emitted a signal which results in a database query, how do I ensure that the query results are sent back to the originating thread? Ideas, examples anyone? Thanks. Adrian. From wolfgang at rohdewald.de Wed Nov 24 03:49:50 2010 From: wolfgang at rohdewald.de (Wolfgang Rohdewald) Date: Wed, 24 Nov 2010 09:49:50 +0100 Subject: Ensuring symmetry in difflib.SequenceMatcher In-Reply-To: <135c0dfc-c382-4dd3-bfaf-8d508e5e648b@j21g2000vba.googlegroups.com> References: <135c0dfc-c382-4dd3-bfaf-8d508e5e648b@j21g2000vba.googlegroups.com> Message-ID: <201011240949.50519.wolfgang@rohdewald.de> On Mittwoch 24 November 2010, John Yeung wrote: > Are there any > simple adjustments that can be made without sacrificing (too > much) performance? >>> difflib.SequenceMatcher(None,*sorted(('BYRD','BRADY'))).ratio() 0.66666666666666663 -- Wolfgang From whitequill.bj at gmail.com Wed Nov 24 04:02:37 2010 From: whitequill.bj at gmail.com (Bj Raz) Date: Wed, 24 Nov 2010 04:02:37 -0500 Subject: factorial of negative one (-1) In-Reply-To: References: <87r5f55qj5.fsf@xemacs.org> <87vd4gm3vb.fsf@xemacs.org> Message-ID: On Tue, Nov 2, 2010 at 12:57 PM, Terry Reedy wrote: > On 11/2/2010 6:11 AM, Hrvoje Niksic wrote: > > 1.1 .hex() >>>>> >>>> '0x1.199999999999ap+0' >> >> Here it is immediately obvious that the final digit of the infinite >> sequence "1.1999..." is rounded from 9 to a. Printing the number with >> any more digits would just reveal zeros, as expected. >> >> Does anyone know why Python doesn't accept hex float literals in source >> code? >> > > Assuming that the parser would have no problem with them: > 1. the format is relatively recent > 2. you can write float.fromhex('') > 3. it never occurred to anyone to do so > 4. literals are values supplied by the programmer; hex float values are > rare and when they do occur, they are usually the stored output of a > previous .hex() in Python or similar in other languages. > 5. too easy to confuse in quick reading with normal float literals > 6. the format is a bit weird and too esoteric for most programmers; they > should not be part of the basic syntax that everyone has to learn; someone > who reads float.fromhex(something) can look it up. > > -- > Terry Jan Reedy > > > -- > http://mail.python.org/mailman/listinfo/python-list > I have just realized that there is a program called PyNum that would be of great help to me, but I can't seem to figure out how to use it after installing, or how to build it with Python 2.7 -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Wed Nov 24 04:43:41 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 24 Nov 2010 10:43:41 +0100 Subject: Ensuring symmetry in difflib.SequenceMatcher References: <135c0dfc-c382-4dd3-bfaf-8d508e5e648b@j21g2000vba.googlegroups.com> Message-ID: John Yeung wrote: > I'm generally pleased with difflib.SequenceMatcher: It's probably not > the best available string matcher out there, but it's in the standard > library and I've seen worse in the wild. One thing that kind of > bothers me is that it's sensitive to which argument you pick as "seq1" > and which you pick as "seq2": > > Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit > (Intel)] on > win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> import difflib >>>> difflib.SequenceMatcher(None, 'BYRD', 'BRADY').ratio() > 0.44444444444444442 >>>> difflib.SequenceMatcher(None, 'BRADY', 'BYRD').ratio() > 0.66666666666666663 >>>> > > Is this a bug? I am guessing the algorithm is implemented correctly, > and that it's just an inherent property of the algorithm used. It's > certainly not what I'd call a desirably property. Are there any > simple adjustments that can be made without sacrificing (too much) > performance? def symmetric_ratio(a, b, S=difflib.SequenceMatcher): return (S(None, a, b).ratio() + S(None, b, a).ratio())/2.0 I'm expecting 50% performance loss ;) Seriously, have you tried to calculate the ratio with realistic data? Without looking into the source I would expect the two ratios to get more similar. Peter From xlizzard at 163.com Wed Nov 24 05:59:26 2010 From: xlizzard at 163.com (xlizzard) Date: Wed, 24 Nov 2010 18:59:26 +0800 (CST) Subject: I got a ImportError,help~! Message-ID: HI, I am a newer to python(my version is 3.1.2),recently I got a IDE named Eric(http://eric-ide.python-projects.org/index.html) to study and on this main page I downloaded a tutorial named "minibrowser". http://eric-ide.python-projects.org/tutorials/MiniBrowser/index.html But when I run this source ,I got the follow Error: Traceback (most recent call last): File "C:\minibrowser\minibrowser\minibrowser.py", line 3, in from ui.mainwindow import MainWindow File "C:\minibrowser\minibrowser\ui\mainwindow.py", line 10, in from Ui_mainwindow import Ui_MainWindow ImportError: No module named Ui_mainwindow I don't understand what's wrong?! The folder structure of the source just like this A.py+ -B.py -C.py A call B,B call C in the same folder ,and "not found"? Can anyone help me,thanks a lot~! -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: minibrowser.zip Type: application/x-zip-compressed Size: 3501 bytes Desc: not available URL: From stefan_ml at behnel.de Wed Nov 24 06:18:38 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 24 Nov 2010 12:18:38 +0100 Subject: Arrays In-Reply-To: References: Message-ID: Garland Fulton, 24.11.2010 06:55: > Is there a way I can define an Array of and unknown size so I can add and > remove to or from it? > > Are arrays immutable? Python has lists and tuples as basic data structures. Tuples are completely immutable, lists are completely mutable. If you want a container that has a fixed size but allows changing items, use a list and avoid calling .append() and .remove() to change items in favour of direct item assignments. If you want a completely mutable container, use a list and use it as you see fit. If you want a stack, a list will do. If you want a queue, a deque is a better option. In any case, if you tell us more about what you actually want to do, we can give better suggestions. Stefan From huisky at gmail.com Wed Nov 24 07:45:54 2010 From: huisky at gmail.com (huisky) Date: Wed, 24 Nov 2010 04:45:54 -0800 (PST) Subject: Read time and date from a text file Message-ID: <0a483e70-619d-4cb7-8fef-bf81b31295e5@j25g2000yqa.googlegroups.com> Hi, As a newbie, I posted my question here again. say i have two dics read from a text file by 'split'. >>> cstart defaultdict(, {15424: ['Dec', '6', '18:57:40'], 552: ['Dec', '7', '09:31:00'], 15500: ['Dec', '6', '20:17:02'], 18863: ['Dec', '7', '13:14:47'], 18291: ['Dec', '6', '21:01:17'], 18969: ['Dec', '7', '14:28:42'], 18937: ['Dec', '7', '14:21:34']}) >>> ccompl defaultdict(, {15424: ['Dec', '6', '19:42:55'], 18291: ['Dec', '6', '21:01:28'], 15500: ['Dec', '6', '20:26:03'], 18863: ['Dec', '7', '13:24:07']}) and I need to calculate the difference time if the key value is the same in both dics. Someone suggested me to use the module 'datetime', but I'm still wondering how to make it work. I mean how to assign ['Dec','6','21:01:17'] to a 'datetime' object and then do the datetime operation. >>>time=datetime.datetime(cstart[18291]) does NOT work. thanks in advance Huisky From fetchinson at googlemail.com Wed Nov 24 08:02:21 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Wed, 24 Nov 2010 14:02:21 +0100 Subject: inverse of a matrix with Fraction entries Message-ID: I guess this is a question to folks with some numpy background (but not necessarily). I'm using fractions.Fraction as entries in a matrix because I need to have very high precision and fractions.Fraction provides infinite precision (as I've learned from advice from this list). Now I need to calculate its inverse. Can numpy help in this regard? Can I tell numpy that the inverse matrix should also have entries in fractions.Fraction? Or numpy can only do floating point calculations? Probably it doesn't matter but the matrix has all components non-zero and is about a thousand by thousand in size. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From tjandacw at cox.net Wed Nov 24 08:05:23 2010 From: tjandacw at cox.net (Tim Williams) Date: Wed, 24 Nov 2010 05:05:23 -0800 (PST) Subject: Read time and date from a text file References: <0a483e70-619d-4cb7-8fef-bf81b31295e5@j25g2000yqa.googlegroups.com> Message-ID: <87f52439-6615-4be7-8f99-5820b41c0e09@s4g2000yql.googlegroups.com> On Nov 24, 7:45?am, huisky wrote: > Hi, > > As a newbie, I posted my question here again. > say i have two dics read from a text file by 'split'. > > >>> cstart > > defaultdict(, {15424: ['Dec', '6', '18:57:40'], 552: > ['Dec', '7', '09:31:00'], 15500: ['Dec', '6', '20:17:02'], 18863: > ['Dec', '7', '13:14:47'], 18291: ['Dec', '6', '21:01:17'], 18969: > ['Dec', '7', '14:28:42'], 18937: ['Dec', '7', '14:21:34']}) > > >>> ccompl > > defaultdict(, {15424: ['Dec', '6', '19:42:55'], 18291: > ['Dec', '6', '21:01:28'], 15500: ['Dec', '6', '20:26:03'], 18863: > ['Dec', '7', '13:24:07']}) > > and I need to calculate the difference time if the key value is the > same in both dics. > > Someone suggested me to use the module 'datetime', but I'm still > wondering how to make it work. > I mean how to assign ['Dec','6','21:01:17'] to a 'datetime' object and > then do the datetime operation. > > >>>time=datetime.datetime(cstart[18291]) ? ? ? does NOT work. > > thanks in advance > Huisky You can use datetime.datetime.strptime() to create a datetime object from a string representing a date >>> import datetime >>> datetime.datetime.strptime('Dec 7 13:24:07','%b %d %H:%M:%S') datetime.datetime(1900, 12, 7, 13, 24, 7) Of course, you need to put in the correct year. datetime.strptime(date_string, format) Return a datetime corresponding to date_string, parsed according to format. This is equivalent to datetime(*(time.strptime(date_string, format)[0:6])). ValueError is raised if the date_string and format can?t be parsed by time.strptime() or if it returns a value which isn?t a time tuple. From __peter__ at web.de Wed Nov 24 08:09:31 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 24 Nov 2010 14:09:31 +0100 Subject: Read time and date from a text file References: <0a483e70-619d-4cb7-8fef-bf81b31295e5@j25g2000yqa.googlegroups.com> Message-ID: huisky wrote: > As a newbie, I posted my question here again. > say i have two dics read from a text file by 'split'. Please don't start a new thread when you are still asking about the same topic. >>>> cstart > > defaultdict(, {15424: ['Dec', '6', '18:57:40'], 552: > ['Dec', '7', '09:31:00'], 15500: ['Dec', '6', '20:17:02'], 18863: > ['Dec', '7', '13:14:47'], 18291: ['Dec', '6', '21:01:17'], 18969: > ['Dec', '7', '14:28:42'], 18937: ['Dec', '7', '14:21:34']}) >>>> ccompl > > defaultdict(, {15424: ['Dec', '6', '19:42:55'], 18291: > ['Dec', '6', '21:01:28'], 15500: ['Dec', '6', '20:26:03'], 18863: > ['Dec', '7', '13:24:07']}) I think you should use a normal dict. A default value of 0 doesn't make much sense here. > and I need to calculate the difference time if the key value is the > same in both dics. > > Someone suggested me to use the module 'datetime', but I'm still > wondering how to make it work. > I mean how to assign ['Dec','6','21:01:17'] to a 'datetime' object and > then do the datetime operation. >>>>time=datetime.datetime(cstart[18291]) does NOT work. Chris Rebert also suggested that you use the strptime() method. To spell it out a bit: >>> s = " ".join(cstart[18291]) >>> s 'Dec 6 21:01:17' >>> datetime.datetime.strptime(s, "%b %d %H:%M:%S") datetime.datetime(1900, 12, 6, 21, 1, 17) You can learn about the format codes here: http://docs.python.org/library/time.html#time.strftime Note that strptime() assumes 1900 as the year which may lead to errors in leapyears and when start and completion time are in different years. Peter From huisky at gmail.com Wed Nov 24 08:17:11 2010 From: huisky at gmail.com (huisky) Date: Wed, 24 Nov 2010 05:17:11 -0800 (PST) Subject: Read time and date from a text file References: <0a483e70-619d-4cb7-8fef-bf81b31295e5@j25g2000yqa.googlegroups.com> Message-ID: <8b2ad59a-1bbb-4e15-b585-7d9900e60dbb@32g2000yqz.googlegroups.com> On Nov 24, 2:09?pm, Peter Otten <__pete... at web.de> wrote: > huisky wrote: > > As a newbie, I posted my question here again. > > say i have two dics read from a text file by 'split'. > > Please don't start a new thread when you are still asking about the same > topic. > > >>>> cstart > > > defaultdict(, {15424: ['Dec', '6', '18:57:40'], 552: > > ['Dec', '7', '09:31:00'], 15500: ['Dec', '6', '20:17:02'], 18863: > > ['Dec', '7', '13:14:47'], 18291: ['Dec', '6', '21:01:17'], 18969: > > ['Dec', '7', '14:28:42'], 18937: ['Dec', '7', '14:21:34']}) > >>>> ccompl > > > defaultdict(, {15424: ['Dec', '6', '19:42:55'], 18291: > > ['Dec', '6', '21:01:28'], 15500: ['Dec', '6', '20:26:03'], 18863: > > ['Dec', '7', '13:24:07']}) > > I think you should use a normal dict. A default value of 0 doesn't make much > sense here. > > > and I need to calculate the difference time if the key value is the > > same in both dics. > > > Someone suggested me to use the module 'datetime', but I'm still > > wondering how to make it work. > > I mean how to assign ['Dec','6','21:01:17'] to a 'datetime' object and > > then do the datetime operation. > >>>>time=datetime.datetime(cstart[18291]) ? ? ? does NOT work. > > Chris Rebert also suggested that you use the strptime() method. To spell it > out a bit: > > >>> s = " ".join(cstart[18291]) > >>> s > 'Dec 6 21:01:17' > >>> datetime.datetime.strptime(s, "%b %d %H:%M:%S") > > datetime.datetime(1900, 12, 6, 21, 1, 17) > > You can learn about the format codes here: > > http://docs.python.org/library/time.html#time.strftime > > Note that strptime() assumes 1900 as the year which may lead to errors in > leapyears and when start and completion time are in different years. > > Peter Thanks a lot, Peter. It helps a lot! I see the problem of year. But the question is the source file does NOT provide the year information. for instance if i have one record as ['Dec','6','21:01:17'], and the other as ['Jan','6','21:01:17'] these two records may be in different year. Will it be a problem to use the 'datetime' do the time difference calculation? regards Huisky Huisky From __peter__ at web.de Wed Nov 24 08:45:13 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 24 Nov 2010 14:45:13 +0100 Subject: Read time and date from a text file References: <0a483e70-619d-4cb7-8fef-bf81b31295e5@j25g2000yqa.googlegroups.com> <8b2ad59a-1bbb-4e15-b585-7d9900e60dbb@32g2000yqz.googlegroups.com> Message-ID: huisky wrote: > I see the problem of year. But the question is the source file does > NOT provide the year information. > for instance if i have one record as ['Dec','6','21:01:17'], and the > other as ['Jan','6','21:01:17'] > these two records may be in different year. Will it be a problem to > use the 'datetime' do the time difference calculation? You have a problem that is independent of Python. You have to guess the correct year to get the correct time interval. One approach would be to use the year from the file's timestamp, then calculate the differences, and whenever you get a negative interval add one year to the end date. This will still result in rare ValueErrors (Feb 29 in non-leapyears) and some silent miscalculations; I fear you'll have to live with that. Peter From ulrich.eckhardt at dominolaser.com Wed Nov 24 09:10:03 2010 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Wed, 24 Nov 2010 15:10:03 +0100 Subject: unittests with different parameters References: Message-ID: Short update on what I've settled for generating test functions for various input data: # test case with common test function class MyTest(unittest.TestCase): def _test_invert_flags(self, input, flags, expected): ? ? ? res = do_invert(input, flags) ? ? ? self.assertEqual(res, expected) # test definitions for the various invert flags tests = [((10, 20), INVERT_NONE, (10, 20)), ? ? ? ? ?((10, 20), INVERT_X, (-10, 20)), ? ? ? ? ?((10, 20), INVERT_Y, (10, -20))] # add test to the test case class for input, flags, expected in tests: def test(self): self._test_invert_flags(input, flags, expected) test.__doc__ = "testing invert flags %s" % flags setattr(MyTest, "test_invert_flags_%s" % flags, test) Yes, the names of the test functions would clash if I tested the same flags twice, in the real code that doesn't happen (enumerate is my friend!). Thanks all! Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From __peter__ at web.de Wed Nov 24 09:12:44 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 24 Nov 2010 15:12:44 +0100 Subject: inverse of a matrix with Fraction entries References: Message-ID: Daniel Fetchinson wrote: > I guess this is a question to folks with some numpy background (but > not necessarily). > > I'm using fractions.Fraction as entries in a matrix because I need to > have very high precision and fractions.Fraction provides infinite > precision (as I've learned from advice from this list). "Infinite" precision only for values that can be expressed as a fraction: >>> Fraction(2)**Fraction(1, 2) 1.4142135623730951 >>> type(_) > Now I need to > calculate its inverse. Can numpy help in this regard? Can I tell numpy > that the inverse matrix should also have entries in > fractions.Fraction? Or numpy can only do floating point calculations? I tried it, and numpy.linalg.inv() converted the Fraction values to float. If you aren't concerned about efficiency it should be easy to do it yourself, in pure python. You could also ask on the numpy mailing list. > Probably it doesn't matter but the matrix has all components non-zero > and is about a thousand by thousand in size. Hmm, where did you get that million of exact fractions from? If some real world data is involved the error introduced by the floating point calculation may be negligable in comparison with the initial measurement uncertainty. Peter From deets at web.de Wed Nov 24 09:25:46 2010 From: deets at web.de (Diez B. Roggisch) Date: Wed, 24 Nov 2010 15:25:46 +0100 Subject: pyqt4: multi-threaded database access References: <38ydnblHjISvVnHRnZ2dnUVZ_rydnZ2d@adnap.net.au> Message-ID: <87fwuqre6t.fsf@web.de> Adrian Casey writes: > I have a PyQt4 multi-threaded application which accesses many hosts > concurrently via ssh. I would like each thread to have access to a > database so that it can look up details about the particular system it > is connected to. > > The easy way is to have each thread create a connection to the database. > However, this is wasteful and likely to exhaust the maximum number of > connections the database (postgresql) allows. Instead, I would like to > share a single database connection between all threads. In PyQt4, this > is not possible since the database connection can only be used by the > thread which created it. > > So, I'm thinking I'll create a thread to just handle database queries. > The worker threads will communicate with the database thread using > signals and slots. > > My question is, if I have 20 worker threads who have emitted a signal > which results in a database query, how do I ensure that the query > results are sent back to the originating thread? > > Ideas, examples anyone? First of all, do you *know* it will exhaust the connections, or is that just some gut feeling? Because postgres can easily handle a few hundered connections, and unless you really are exhausting these, it's the easiest solution. The next advice would be to create a pool of connections (pure python, not Qt). Then you lose the "can only be used by the thread which created it" restriction. Of course you should only use a connection from within one thread at a time, but that shouldn't be an issue. So all you have to make sure is that you fetch & return the connections properly. I would use a context-manager for that: with connection_pooll as connection: do_some_queries(connection) HTH, Diez From gnarlodious at gmail.com Wed Nov 24 09:27:44 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Wed, 24 Nov 2010 06:27:44 -0800 (PST) Subject: CGI FieldStorage instances? References: <1ec25d72-a99e-4fd9-9d50-1ac8c65812e9@z19g2000yqb.googlegroups.com> <6trje65kt71v00339psntb6srgr5qtls5c@4ax.com> <8b8a7842-6249-4c0f-ac97-61bd646b52af@k3g2000vbp.googlegroups.com> Message-ID: <5e2d6196-7667-4bf4-b945-db1464c17453@p7g2000prb.googlegroups.com> On Nov 23, 7:22?pm, Ian Kelly wrote: > Try Django[1] or TurboGears[2]. > > [1]http://www.djangoproject.com/ > [2]http://www.turbogears.org/ Thanks, never understood what those programs were for. -- Gnarlie From benjamin.kaplan at case.edu Wed Nov 24 09:53:05 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 24 Nov 2010 09:53:05 -0500 Subject: I got a ImportError,help~! In-Reply-To: References: Message-ID: 2010/11/24 xlizzard : > HI, > I am a newer to python(my version is 3.1.2),recently I got a IDE named > Eric(http://eric-ide.python-projects.org/index.html) to study > and on this main page I downloaded a tutorial named "minibrowser". > http://eric-ide.python-projects.org/tutorials/MiniBrowser/index.html > But when I run this source ,I got the follow Error: > Traceback (most recent call last): > File "C:\minibrowser\minibrowser\minibrowser.py", line 3, in > from ui.mainwindow import MainWindow > File "C:\minibrowser\minibrowser\ui\mainwindow.py", line 10, in > from Ui_mainwindow import Ui_MainWindow > ImportError: No module named Ui_mainwindow > > I don't understand what's wrong?! > The folder structure of the source just like this > A.py+ > -B.py > -C.py > A call B,B call C in the same folder ,and "not found"? > Can anyone help me,thanks a lot~! > How is that a folder structure? Is A.py a folder? Also, you didn't give us enough information to help. If your files are called A.py, B.py, and C.py, then of course it can't find the Ui_MainWindow module (aside: modules are usually lowercase) > > ________________________________ > ??163/126???????iphone ipad???? > -- > http://mail.python.org/mailman/listinfo/python-list > > From ian.g.kelly at gmail.com Wed Nov 24 09:59:33 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 24 Nov 2010 07:59:33 -0700 Subject: I got a ImportError,help~! In-Reply-To: References: Message-ID: On 11/24/2010 3:59 AM, xlizzard wrote: > HI, > I am a newer to python(my version is 3.1.2),recently I got a IDE named > Eric(http://eric-ide.python-projects.org/index.html) to study > and on this main page I downloaded a tutorial named "**minibrowser". > http://eric-ide.python-projects.org/tutorials/MiniBrowser/index.html > But when I run this source ,I got the follow Error: > Traceback (most recent call last): > File "C:\minibrowser\minibrowser\minibrowser.py", line 3, in > from ui.mainwindow import MainWindow > File "C:\minibrowser\minibrowser\ui\mainwindow.py", line 10, in > from Ui_mainwindow import Ui_MainWindow > ImportError: No module named Ui_mainwindow > I don't understand what's wrong?! > The folder structure of the source just like this > A.py+ > -B.py > -C.py > A call B,B call C in the same folder ,and "not found"? > Can anyone help me,thanks a lot~! That tutorial was probably written for Python 2.X. In Python 3, it is no longer possible to do relative imports using that syntax. If you change the import line to read: from .Ui_mainwindow import Ui_MainWindow or better (making it an absolute import, which is preferred): from ui.mainwindow.Ui_mainwindow import Ui_MainWindow then Python will interpret it as a relative import, and it should work. There could still be other incompatibilities due to the version difference, however. Cheers, Ian From huisky at gmail.com Wed Nov 24 10:02:16 2010 From: huisky at gmail.com (huisky) Date: Wed, 24 Nov 2010 07:02:16 -0800 (PST) Subject: Read time and date from a text file References: <0a483e70-619d-4cb7-8fef-bf81b31295e5@j25g2000yqa.googlegroups.com> <8b2ad59a-1bbb-4e15-b585-7d9900e60dbb@32g2000yqz.googlegroups.com> Message-ID: On Nov 24, 2:45?pm, Peter Otten <__pete... at web.de> wrote: > huisky wrote: > > I see the problem of year. But the question is the source file does > > NOT provide the year information. > > for instance if i have one record as ['Dec','6','21:01:17'], and the > > other as ['Jan','6','21:01:17'] > > these two records may be in different year. Will it be a problem to > > use the 'datetime' do the time difference calculation? > > You have a problem that is independent of Python. You have to guess the > correct year to get the correct time interval. One approach would be to use > the year from the file's timestamp, then calculate the differences, and > whenever you get a negative interval add one year to the end date. > > This will still result in rare ValueErrors (Feb 29 in non-leapyears) and > some silent miscalculations; I fear you'll have to live with that. > > Peter I see, what i'm doing is only for personal usage. should be no problem at all. thanks a lot, Peter! From fetchinson at googlemail.com Wed Nov 24 10:10:54 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Wed, 24 Nov 2010 16:10:54 +0100 Subject: inverse of a matrix with Fraction entries In-Reply-To: References: Message-ID: >> I guess this is a question to folks with some numpy background (but >> not necessarily). >> >> I'm using fractions.Fraction as entries in a matrix because I need to >> have very high precision and fractions.Fraction provides infinite >> precision (as I've learned from advice from this list). > > "Infinite" precision only for values that can be expressed as a fraction: > >>>> Fraction(2)**Fraction(1, 2) > 1.4142135623730951 >>>> type(_) > True, but I only need to add, multiply and divide my fractions in order to end up with the entries in the matrix. >> Now I need to >> calculate its inverse. Can numpy help in this regard? Can I tell numpy >> that the inverse matrix should also have entries in >> fractions.Fraction? Or numpy can only do floating point calculations? > > I tried it, and numpy.linalg.inv() converted the Fraction values to float. > If you aren't concerned about efficiency it should be easy to do it > yourself, in pure python. If there is no other way, that's what I'll try to do. > You could also ask on the numpy mailing list. > >> Probably it doesn't matter but the matrix has all components non-zero >> and is about a thousand by thousand in size. > > Hmm, where did you get that million of exact fractions from? The million of exact fractions are coming from a recursion relation. This recursion relation only adds, multiplies and divides numbers so the end result is always a rational number. > If some real > world data is involved the error introduced by the floating point > calculation may be negligable in comparison with the initial measurement > uncertainty. It's a mathematical problem so no uncertainty is present in the initial values. And even if there was, if there are many orders of magnitude differences between the entries in the matrix floating point does not suffice for various things like eigenvalue calculation and stuff like that. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From korn at freisingnet.de Wed Nov 24 10:12:15 2010 From: korn at freisingnet.de (Johannes Korn) Date: Wed, 24 Nov 2010 16:12:15 +0100 Subject: extensive scatter plot Message-ID: <4ced2b4f$0$6771$9b4e6d93@newsspool3.arcor-online.net> Hi, I would like to produce a scatter plot with roughly 200 mio points. Because the points are so numerous I rather need a point density plot. I use numpy. Right now I loop over the individual data points and make a where query on a meshgrid. ind = where((x_grid == x_points[i]) & (y_grid == y_points[i]) ) counter_grid[ind] += 1 This is really slow. I'm sure there's a better solution already out there. Kind regards! From tom at t0mb.net Wed Nov 24 10:34:52 2010 From: tom at t0mb.net (Tom Boland) Date: Wed, 24 Nov 2010 15:34:52 +0000 Subject: efficient way of splitting a list in to lists where the sum of the values in each does not exceed n Message-ID: <4CED309C.8060500@t0mb.net> I'm trying to find a _nice_ way of taking a list of integers, and splitting them in to lists where the sum of the values does not exceed a threshold. for instance: l = [1, 2, 3, 4, 5, 6] n = 6 nl = [1,2,3], [4], [5], [6] I don't mind if it's done like playing blackjack/pontoon (the card game where you try not to exceed a total of 21), ie. going through the list sequentially, and splitting off the list as soon as the running total would exceed n. A way of efficiently making all lists as close to n as possible would be nice however. I have an algorithm, but it's very ugly. I don't want to paste it, as it's a bit more complicated than I have made out, and wouldn't make too much sense out of context. It's a very ugly blight on my code as well! I wonder if anyone out there has some crazy one-line list comprehension or idiomatic way of doing this beautifully :) Many thanks. Tom. -------------- next part -------------- An HTML attachment was scrubbed... URL: From robert.kern at gmail.com Wed Nov 24 11:02:29 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 24 Nov 2010 10:02:29 -0600 Subject: extensive scatter plot In-Reply-To: <4ced2b4f$0$6771$9b4e6d93@newsspool3.arcor-online.net> References: <4ced2b4f$0$6771$9b4e6d93@newsspool3.arcor-online.net> Message-ID: On 11/24/10 9:12 AM, Johannes Korn wrote: > Hi, > > I would like to produce a scatter plot with roughly 200 mio points. > Because the points are so numerous I rather need a point density plot. > > I use numpy. Right now I loop over the individual data points and make a > where query on a meshgrid. > > ind = where((x_grid == x_points[i])& (y_grid == y_points[i]) ) > counter_grid[ind] += 1 > > This is really slow. I'm sure there's a better solution already out there. > > Kind regards! You will want to ask numpy questions on the numpy mailing list: http://www.scipy.org/Mailing_Lists If you are using a particular plotting package like matplotlib, you will want to ask your plotting questions on their mailing lists. E.g. https://lists.sourceforge.net/lists/listinfo/matplotlib-users If you are doing your own plotting, you will want to use the numpy.histogram2d() function to make a 2D histogram that can be plotted using a colormapped image. If you are using matplotlib, try matplotlib.pyplot.hexbin(). http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.hexbin -- 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 ian.g.kelly at gmail.com Wed Nov 24 11:16:42 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 24 Nov 2010 09:16:42 -0700 Subject: efficient way of splitting a list in to lists where the sum of the values in each does not exceed n In-Reply-To: <4CED309C.8060500@t0mb.net> References: <4CED309C.8060500@t0mb.net> Message-ID: On Wed, Nov 24, 2010 at 8:34 AM, Tom Boland wrote: > I'm trying to find a _nice_ way of taking a list of integers, and splitting > them in to lists where the sum of the values does not exceed a threshold. > > for instance: > > l = [1, 2, 3, 4, 5, 6] > n = 6 > > nl = [1,2,3], [4], [5], [6] > > > I don't mind if it's done like playing blackjack/pontoon (the card game > where you try not to exceed a total of 21), ie. going through the list > sequentially, and splitting off the list as soon as the running total would > exceed n.? A way of efficiently making all lists as close to n as possible > would be nice however. You've described the bin-packing problem [1]. It's known to be NP-hard, so you won't find a solution that is both efficient and optimal, although the Wikipedia page mentions some polynomial-time approximate algorithms that you might want to take a look at. Cheers, Ian [1] http://en.wikipedia.org/wiki/Bin_packing_problem From __peter__ at web.de Wed Nov 24 11:27:53 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 24 Nov 2010 17:27:53 +0100 Subject: inverse of a matrix with Fraction entries References: Message-ID: Daniel Fetchinson wrote: >>> I guess this is a question to folks with some numpy background (but >>> not necessarily). >>> >>> I'm using fractions.Fraction as entries in a matrix because I need to >>> have very high precision and fractions.Fraction provides infinite >>> precision (as I've learned from advice from this list). >> >> "Infinite" precision only for values that can be expressed as a fraction: >> >>>>> Fraction(2)**Fraction(1, 2) >> 1.4142135623730951 >>>>> type(_) >> > > True, but I only need to add, multiply and divide my fractions in > order to end up with the entries in the matrix. > >>> Now I need to >>> calculate its inverse. Can numpy help in this regard? Can I tell numpy >>> that the inverse matrix should also have entries in >>> fractions.Fraction? Or numpy can only do floating point calculations? >> >> I tried it, and numpy.linalg.inv() converted the Fraction values to >> float. If you aren't concerned about efficiency it should be easy to do >> it yourself, in pure python. > > If there is no other way, that's what I'll try to do. > >> You could also ask on the numpy mailing list. >> >>> Probably it doesn't matter but the matrix has all components non-zero >>> and is about a thousand by thousand in size. >> >> Hmm, where did you get that million of exact fractions from? > > The million of exact fractions are coming from a recursion relation. > This recursion relation only adds, multiplies and divides numbers so > the end result is always a rational number. > >> If some real >> world data is involved the error introduced by the floating point >> calculation may be negligable in comparison with the initial measurement >> uncertainty. > > It's a mathematical problem so no uncertainty is present in the > initial values. And even if there was, if there are many orders of > magnitude differences between the entries in the matrix floating point > does not suffice for various things like eigenvalue calculation and > stuff like that. It may be worthwhile to have a look at http://www.sagemath.org/ sage: Matrix([[1,2],[3,4]])**-1 [ -2 1] [ 3/2 -1/2] sage: a = Matrix([[1,2],[3,4]]) sage: b = Matrix([[1,2],[3,4]])**-1 sage: a*b [1 0] [0 1] sage: type(b[1,1]) Peter From tom at t0mb.net Wed Nov 24 11:52:59 2010 From: tom at t0mb.net (Tom Boland) Date: Wed, 24 Nov 2010 16:52:59 +0000 Subject: efficient way of splitting a list in to lists where the sum of the values in each does not exceed n In-Reply-To: References: <4CED309C.8060500@t0mb.net> Message-ID: <4CED42EB.3010600@t0mb.net> Thanks for the reply Ian, I've looked in to the bin-packing problem in a general sense now, and I think my ugly algorithm is actually not too bad (although not too efficient either!) :) It was only for a quick job any how. Thanks again. Tom. On 24/11/10 16:16, Ian Kelly wrote: > On Wed, Nov 24, 2010 at 8:34 AM, Tom Boland wrote: > >> I'm trying to find a _nice_ way of taking a list of integers, and splitting >> them in to lists where the sum of the values does not exceed a threshold. >> >> for instance: >> >> l = [1, 2, 3, 4, 5, 6] >> n = 6 >> >> nl = [1,2,3], [4], [5], [6] >> >> >> I don't mind if it's done like playing blackjack/pontoon (the card game >> where you try not to exceed a total of 21), ie. going through the list >> sequentially, and splitting off the list as soon as the running total would >> exceed n. A way of efficiently making all lists as close to n as possible >> would be nice however. >> > You've described the bin-packing problem [1]. It's known to be > NP-hard, so you won't find a solution that is both efficient and > optimal, although the Wikipedia page mentions some polynomial-time > approximate algorithms that you might want to take a look at. > > Cheers, > Ian > > [1] http://en.wikipedia.org/wiki/Bin_packing_problem > From ppearson at nowhere.invalid Wed Nov 24 12:39:34 2010 From: ppearson at nowhere.invalid (Peter Pearson) Date: 24 Nov 2010 17:39:34 GMT Subject: inverse of a matrix with Fraction entries References: Message-ID: <8l50ulFhb4U1@mid.individual.net> On Wed, 24 Nov 2010 14:02:21 +0100, Daniel Fetchinson wrote: [snip] > I'm using fractions.Fraction as entries in a matrix because I need to > have very high precision and fractions.Fraction provides infinite > precision . . . [snip] > > Probably it doesn't matter but the matrix has all components non-zero > and is about a thousand by thousand in size. I wonder how big the numerators and denominators in those fractions are going to get during the matrix inversion. Would it be surprising if the elements of the inverse matrix had numerators and denominators a million times longer than the original matrix? -- To email me, substitute nowhere->spamcop, invalid->net. From robert.kern at gmail.com Wed Nov 24 12:58:07 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 24 Nov 2010 11:58:07 -0600 Subject: inverse of a matrix with Fraction entries In-Reply-To: References: Message-ID: On 11/24/10 9:10 AM, Daniel Fetchinson wrote: > It's a mathematical problem so no uncertainty is present in the > initial values. And even if there was, if there are many orders of > magnitude differences between the entries in the matrix floating point > does not suffice for various things like eigenvalue calculation and > stuff like that. Well, if you want to do eigenvalue calculations, you are going to have to start doing numerical approximations anyways. There is no analytical solution for matrices larger than 4x4. Sympy will do inverses of matrices over rationals for you, though: |4> from sympy import * |6> m = Matrix([[S(1)/2, S(1)/3], [S(1)/4, S(1)/5]]) |7> m [1/2, 1/3] [1/4, 1/5] |8> m.inv() [ 12, -20] [-15, 30] -- 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 fetchinson at googlemail.com Wed Nov 24 13:02:01 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Wed, 24 Nov 2010 19:02:01 +0100 Subject: inverse of a matrix with Fraction entries In-Reply-To: References: Message-ID: >>>> I guess this is a question to folks with some numpy background (but >>>> not necessarily). >>>> >>>> I'm using fractions.Fraction as entries in a matrix because I need to >>>> have very high precision and fractions.Fraction provides infinite >>>> precision (as I've learned from advice from this list). >>> >>> "Infinite" precision only for values that can be expressed as a fraction: >>> >>>>>> Fraction(2)**Fraction(1, 2) >>> 1.4142135623730951 >>>>>> type(_) >>> >> >> True, but I only need to add, multiply and divide my fractions in >> order to end up with the entries in the matrix. >> >>>> Now I need to >>>> calculate its inverse. Can numpy help in this regard? Can I tell numpy >>>> that the inverse matrix should also have entries in >>>> fractions.Fraction? Or numpy can only do floating point calculations? >>> >>> I tried it, and numpy.linalg.inv() converted the Fraction values to >>> float. If you aren't concerned about efficiency it should be easy to do >>> it yourself, in pure python. >> >> If there is no other way, that's what I'll try to do. >> >>> You could also ask on the numpy mailing list. >>> >>>> Probably it doesn't matter but the matrix has all components non-zero >>>> and is about a thousand by thousand in size. >>> >>> Hmm, where did you get that million of exact fractions from? >> >> The million of exact fractions are coming from a recursion relation. >> This recursion relation only adds, multiplies and divides numbers so >> the end result is always a rational number. >> >>> If some real >>> world data is involved the error introduced by the floating point >>> calculation may be negligable in comparison with the initial measurement >>> uncertainty. >> >> It's a mathematical problem so no uncertainty is present in the >> initial values. And even if there was, if there are many orders of >> magnitude differences between the entries in the matrix floating point >> does not suffice for various things like eigenvalue calculation and >> stuff like that. > > It may be worthwhile to have a look at http://www.sagemath.org/ > > sage: Matrix([[1,2],[3,4]])**-1 > > [ -2 1] > [ 3/2 -1/2] > sage: a = Matrix([[1,2],[3,4]]) > sage: b = Matrix([[1,2],[3,4]])**-1 > sage: a*b > > [1 0] > [0 1] > sage: type(b[1,1]) > This sounds like a good idea! Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From fetchinson at googlemail.com Wed Nov 24 13:07:32 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Wed, 24 Nov 2010 19:07:32 +0100 Subject: inverse of a matrix with Fraction entries In-Reply-To: <8l50ulFhb4U1@mid.individual.net> References: <8l50ulFhb4U1@mid.individual.net> Message-ID: >> I'm using fractions.Fraction as entries in a matrix because I need to >> have very high precision and fractions.Fraction provides infinite >> precision . . . >> >> Probably it doesn't matter but the matrix has all components non-zero >> and is about a thousand by thousand in size. > > I wonder how big the numerators and denominators in those > fractions are going to get during the matrix inversion. Would > it be surprising if the elements of the inverse matrix had > numerators and denominators a million times longer than the > original matrix? I've checked this with Maple for matrix size 150 x 150 and the numerators and denominators do get pretty long. But that's okay as long as it is kept exact. The whole story is that I have a matrix A and matrix B both of which have rational entries and they both have pretty crazy entries too. Their magnitude spans many orders of magnitude, but inverse(A)*B is an okay matrix and I can deal with it using floating point numbers. I only need this exact fraction business for inverse(A)*B (yes, a preconditioner would be useful :)) And I wouldn't want to write the whole matrix into a file, call Maple on it, parse the result, etc. So after all I might just code the inversion via Gauss elimination myself in a way that can deal with fractions, shouldn't be that hard. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From fetchinson at googlemail.com Wed Nov 24 13:10:10 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Wed, 24 Nov 2010 19:10:10 +0100 Subject: inverse of a matrix with Fraction entries In-Reply-To: References: Message-ID: >> It's a mathematical problem so no uncertainty is present in the >> initial values. And even if there was, if there are many orders of >> magnitude differences between the entries in the matrix floating point >> does not suffice for various things like eigenvalue calculation and >> stuff like that. > > Well, if you want to do eigenvalue calculations, you are going to have to > start > doing numerical approximations anyways. There is no analytical solution for > matrices larger than 4x4. Sure! (I didn't explain the whole thing yet, see the other reply where I actually do.) > Sympy will do inverses of matrices over rationals for you, though: > > |4> from sympy import * > > |6> m = Matrix([[S(1)/2, S(1)/3], [S(1)/4, S(1)/5]]) > > |7> m > [1/2, 1/3] > [1/4, 1/5] > > |8> m.inv() > [ 12, -20] > [-15, 30] Thanks a lot! This sounds like the simplest solution so far. I don't need to call Maple after all :) Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From raffaelcavallaro at pas.despam.s.il.vous.plait.mac.com Wed Nov 24 13:10:33 2010 From: raffaelcavallaro at pas.despam.s.il.vous.plait.mac.com (Raffael Cavallaro) Date: Wed, 24 Nov 2010 13:10:33 -0500 Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014020136.6e85d70b@tritium.streitmacht.eu> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> <08823dd4-588a-4729-a660-711e266c96b0@y23g2000yqd.googlegroups.com> <396f8de7-ece5-4e9c-919b-886eb65ae14a@a30g2000vbt.googlegroups.com> <967678a1-fc5d-4b61-86c5-79a298999582@p1g2000vbo.googlegroups.com> Message-ID: On 2010-11-23 11:34:14 -0500, Keith H Duggar said: > You don't understand the implications of your own words: > > "having a financial interest in the outcome of a debate makes > anything that person says an advertisement for his financial > interests, not a fair assessment." > > is substantially different from > > "render his arguments in the debate inherently suspect." They are substantially the same, your jesuitical nit-picking notwithstanding; JH is an untrustworthy source on matters relating to the languages he sells training for. warmest regards, Ralph -- Raffael Cavallaro From tinnews at isbd.co.uk Wed Nov 24 13:13:55 2010 From: tinnews at isbd.co.uk (tinnews at isbd.co.uk) Date: Wed, 24 Nov 2010 18:13:55 +0000 Subject: Problem with module 'evolution' after moving system Message-ID: <3810s7-bu5.ln1@chris.zbmc.eu> I have just moved my desktop system (running xubuntu 10.04) to new hardware. I have an almost trivial python program that uses the evolution module which no longer works and I'm having trouble working out why. The program is:- #!/usr/bin/python # # # # import evolution import sys addrs = evolution.ebook.open_addressbook('default') result = addrs.search(sys.argv[1]) print "Found ", len(result), " matches" if len(result) > 0: for nm in result: print nm.get_property('email-1'), "\t", nm.get_property('full-name') exit(0) else: exit(1) When I run it I get the error:- chris$ getEvoAddress.py zelma Traceback (most recent call last): File "/home/chris/bin/getEvoAddress.py", line 10, in addrs = evolution.ebook.open_addressbook('default') AttributeError: 'NoneType' object has no attribute 'open_addressbook' Using 'help' reveals basic information for evolution but reports "no documentation ...." for evolution.ebook. On the old system (exactly the same version of python, same OS, same everything just about) "help(evolution.ebook)" shows the expected documentation. So, what's wrong, is some python module missing that the evolution module needs? (It's quite likely that there are far more modules installed on the old system than the new one) -- Chris Green From whatsjacksemail at gmail.com Wed Nov 24 13:17:32 2010 From: whatsjacksemail at gmail.com (Jack Keegan) Date: Wed, 24 Nov 2010 18:17:32 +0000 Subject: unittests with different parameters In-Reply-To: References: Message-ID: Apologies if this is a bit off the wall but I've only just started getting into unit testing (in Python) this morning. Would generators help you in any way? You might be able to have a generator which would yield an attribute set combination each time it is called. I'm not sure if it would still stop at the first fail but I was reading this morning that the Py.test framework utilises generators, and is apparently compatible with the python unittest module. I could be wrong though... -------------- next part -------------- An HTML attachment was scrubbed... URL: From burton at userful.com Wed Nov 24 13:25:52 2010 From: burton at userful.com (Burton Samograd) Date: Wed, 24 Nov 2010 11:25:52 -0700 Subject: Collect output to string References: Message-ID: Terry Reedy writes: > On 11/23/2010 3:02 PM, Chris Rebert wrote: > If you are using print or print(), you can redirect output to the > StringIO object with >>sfile or file=sfile. I use the latter in a > custom test function where I normally want output to the screen but > occasionally want to capture test reports. Thanks for the info, but I was looking for a way to collect output without modifying the original function, similar to with-output-to-string in some schemes. -- Burton Samograd From robert.kern at gmail.com Wed Nov 24 13:30:44 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 24 Nov 2010 12:30:44 -0600 Subject: inverse of a matrix with Fraction entries In-Reply-To: References: <8l50ulFhb4U1@mid.individual.net> Message-ID: On 11/24/10 12:07 PM, Daniel Fetchinson wrote: > The whole story is that I have a matrix A and matrix B both of which > have rational entries and they both have pretty crazy entries too. > Their magnitude spans many orders of magnitude, but inverse(A)*B is an > okay matrix and I can deal with it using floating point numbers. I > only need this exact fraction business for inverse(A)*B (yes, a > preconditioner would be useful :)) > > And I wouldn't want to write the whole matrix into a file, call Maple > on it, parse the result, etc. > > So after all I might just code the inversion via Gauss elimination > myself in a way that can deal with fractions, shouldn't be that hard. +1000. This is almost always the right thing to do whether you have floats or rationals. -- 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 gerald.britton at gmail.com Wed Nov 24 13:46:35 2010 From: gerald.britton at gmail.com (Gerald Britton) Date: Wed, 24 Nov 2010 13:46:35 -0500 Subject: Style question for conditional execution Message-ID: Writing in Python gives me the luxury of choosing different paradigms for similar operations. Lately I've been thinking about a minor detail that peaked my interest and am curious what others think: Say that I have some function "f" that I will execute if some variable "v" evaluates true. Using a classical procedural approach, I might write: if v: f() I might, however, think more in a functional-programming direction. Then I might write: v and f() Interestingly, this second expression compiles smaller (though only by a little) in both Python 2.6 and 3.1, which I currently have installed. If I had thousands of such expressions, I could boast about a measurable difference but practically speaking, it is not significant. What I _am_ interested in, however, is feedback from a style perspective. What do the rest of you think about this? Have you used the second approach and, if so, what was your motivation? Is there a good/bad reason to choose one over the other? -- Gerald Britton From ed at leafe.com Wed Nov 24 14:10:23 2010 From: ed at leafe.com (Ed Leafe) Date: Wed, 24 Nov 2010 14:10:23 -0500 Subject: Style question for conditional execution In-Reply-To: References: Message-ID: On Nov 24, 2010, at 1:46 PM, Gerald Britton wrote: > Say that I have some function "f" that I will execute if some variable > "v" evaluates true. Using a classical procedural approach, I might > write: > > if v: > f() > > I might, however, think more in a functional-programming direction. > Then I might write: > > v and f() > > Interestingly, this second expression compiles smaller (though only by > a little) in both Python 2.6 and 3.1, which I currently have > installed. If I had thousands of such expressions, I could boast > about a measurable difference but practically speaking, it is not > significant. > > What I _am_ interested in, however, is feedback from a style perspective. > > What do the rest of you think about this? Readability is key. The first is instantly understandable; the second only if you are familiar with that particular programming construct. Explicit is better than implicit, so I'd go with the first form. -- Ed Leafe From ian.g.kelly at gmail.com Wed Nov 24 14:14:04 2010 From: ian.g.kelly at gmail.com (Ian) Date: Wed, 24 Nov 2010 11:14:04 -0800 (PST) Subject: Style question for conditional execution References: Message-ID: <98effb64-68a1-4532-a3e4-4629a555f8df@y31g2000vbt.googlegroups.com> On Nov 24, 11:46?am, Gerald Britton wrote: > Say that I have some function "f" that I will execute if some variable > "v" evaluates true. ?Using a classical procedural approach, I might > write: > > ? ? if v: > ? ? ? ? f() > > I might, however, think more in a functional-programming direction. > Then I might write: > > ? ? v and f() The idea that "if" is inherently procedural is mistaken. Functional programming emphasizes the use of functions (in the mathematical sense) over changes in state. Assuming that f has no side effects, either of the above could equally be viewed as functional. (Of course, the fact that the return value is simply discarded in both of the above cases suggests that f *does* have side effects, in which case neither of the above should be viewed as functional.) That said, the 'if' version is clearer, so I would nearly always go with that. The rare exception would be if I were genuinely interested in capturing the value of "v" if it evaluated false. I can't remember the last time that was the case. Cheers, Ian From howe.steven at gmail.com Wed Nov 24 14:40:41 2010 From: howe.steven at gmail.com (Steven Howe) Date: Wed, 24 Nov 2010 11:40:41 -0800 Subject: Style question for conditional execution In-Reply-To: References: Message-ID: <4CED6A39.8010607@gmail.com> Both paradigms are in the bash shell. Using a test switch (like -x for executiable) mixed with an && or ||. Example: [-x /usr/bin/firefox ] || exit I think it's very clear, to old hands, but not so much for a new or intermediate users. It certainly is the 'cleaner' form. Like the C style increment " x++ " or the insidious " x += 4 ". However I often found myself looking for places to use "x += 4" instead of just using the clear: "x = x + 4 ". Unless there is a significant compiler/executable improvement it just there to amuse yourself. The if v: f() structure is clearer. Which is the only reason to use indents, braces and the like. I suppose that's my vote/opinion. Given a choice between clean or clear, take clear. sph On 11/24/2010 10:46 AM, Gerald Britton wrote: > Writing in Python gives me the luxury of choosing different paradigms > for similar operations. Lately I've been thinking about a minor > detail that peaked my interest and am curious what others think: > > Say that I have some function "f" that I will execute if some variable > "v" evaluates true. Using a classical procedural approach, I might > write: > > if v: > f() > > I might, however, think more in a functional-programming direction. > Then I might write: > > v and f() > > Interestingly, this second expression compiles smaller (though only by > a little) in both Python 2.6 and 3.1, which I currently have > installed. If I had thousands of such expressions, I could boast > about a measurable difference but practically speaking, it is not > significant. > > What I _am_ interested in, however, is feedback from a style perspective. > > What do the rest of you think about this? > > Have you used the second approach and, if so, what was your motivation? > > Is there a good/bad reason to choose one over the other? > From python at rcn.com Wed Nov 24 15:08:04 2010 From: python at rcn.com (Raymond Hettinger) Date: Wed, 24 Nov 2010 12:08:04 -0800 (PST) Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance Message-ID: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> I'm writing-up more guidance on how to use super() and would like to point at some real-world Python examples of cooperative multiple inheritance. Google searches take me to old papers for C++ and Eiffel, but that don't seem to be relevant to most Python programmers (i.e. a WalkingMenu example where a submenu is both a Entry in a Menu and a Menu itself). Another published example is in a graphic library where some widgets inherit GraphicalFeature methods such as location, size and NestingGroupingFeatures such as finding parents, siblings, and children. I don't find either of those examples compelling because there is no particular reason that they would have to have overlapping method names. So far, the only situation I can find where method names necessarily overlap is for the basics like __init__(), close(), flush(), and save() where multiple parents need to have their own initialization and finalization. If you guys know of good examples, I would appreciate a link or a recap. Thanks, Raymond From mdw at distorted.org.uk Wed Nov 24 15:10:10 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 24 Nov 2010 20:10:10 +0000 Subject: inverse of a matrix with Fraction entries References: <8l50ulFhb4U1@mid.individual.net> Message-ID: <87y68izdnh.fsf.mdw@metalzone.distorted.org.uk> Daniel Fetchinson writes: > So after all I might just code the inversion via Gauss elimination > myself in a way that can deal with fractions, shouldn't be that hard. I wouldn't do it that way. Let M be your matrix. Work out the LCM l of the denominators, and multiply the matrix by that to make it an integer matrix N = l M. Then work out the determinant d of that integer matrix. Next, the big step: use Gaussian elimination to find a matrix A (the `adjugate matrix') such that A N = d I. This should be doable entirely using integer arithmetic, and I think without needing any divisions. Finally, we have l A M = d I, so (l/d A) M = I and l/d A is the inverse you seek. Does that make sense? -- [mdw] From arnodel at gmail.com Wed Nov 24 15:25:19 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Wed, 24 Nov 2010 20:25:19 +0000 Subject: Style question for conditional execution References: Message-ID: <87eiaafp00.fsf@gmail.com> Gerald Britton writes: > Writing in Python gives me the luxury of choosing different paradigms > for similar operations. Lately I've been thinking about a minor > detail that peaked my interest and am curious what others think: > > Say that I have some function "f" that I will execute if some variable > "v" evaluates true. Using a classical procedural approach, I might > write: > > if v: > f() > > I might, however, think more in a functional-programming direction. > Then I might write: > > v and f() > > Interestingly, this second expression compiles smaller (though only by > a little) in both Python 2.6 and 3.1, which I currently have > installed. If I had thousands of such expressions, I could boast > about a measurable difference but practically speaking, it is not > significant. > > What I _am_ interested in, however, is feedback from a style perspective. > > What do the rest of you think about this? > > Have you used the second approach and, if so, what was your motivation? > > Is there a good/bad reason to choose one over the other? I would use the if: form every time but it's interesting that the "JUMP_FORWARD 0" instruction below doesn't get optimised away. If it did, both forms would be the same compiled lengths. >>> def g(): ... if v: f() ... >>> dis.dis(g2) 2 0 LOAD_GLOBAL 0 (v) 3 POP_JUMP_IF_FALSE 16 6 LOAD_GLOBAL 1 (f) 9 CALL_FUNCTION 0 12 POP_TOP 13 JUMP_FORWARD 0 (to 16) >> 16 LOAD_CONST 0 (None) 19 RETURN_VALUE -- Arnaud From no.email at nospam.invalid Wed Nov 24 15:43:18 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 24 Nov 2010 12:43:18 -0800 Subject: Style question for conditional execution References: Message-ID: <7xtyj6o3kp.fsf@ruckus.brouhaha.com> Gerald Britton writes: > if v: > f() > > I might, however, think more in a functional-programming direction. > Then I might write: > > v and f() Python has conditional expressions. The above would be: f() if v else None using "and" is bug-prone. From anurag.chourasia at gmail.com Wed Nov 24 16:01:32 2010 From: anurag.chourasia at gmail.com (Anurag Chourasia) Date: Thu, 25 Nov 2010 02:31:32 +0530 Subject: collect2: library libpython2.6 not found while building extensions (--enable-shared) Message-ID: All, When I configure python to enable shared libraries, none of the extensions are getting built during the make step due to this error. building 'cStringIO' extension gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I. -I/u01/home/apli/wm/GDD/Python-2.6.6/./Include -I. -IInclude -I./Include -I/opt/freeware/include -I/opt/freeware/include/readline -I/opt/freeware/include/ncurses -I/usr/local/include -I/u01/home/apli/wm/GDD/Python-2.6.6/Include -I/u01/home/apli/wm/GDD/Python-2.6.6 -c /u01/home/apli/wm/GDD/Python-2.6.6/Modules/cStringIO.c -o build/temp.aix-5.3-2.6/u01/home/apli/wm/GDD/Python-2.6.6/Modules/cStringIO.o ./Modules/ld_so_aix gcc -pthread -bI:Modules/python.exp build/temp.aix-5.3-2.6/u01/home/apli/wm/GDD/Python-2.6.6/Modules/cStringIO.o -L/usr/local/lib *-lpython2.6* -o build/lib.aix-5.3-2.6/cStringIO.so *collect2: library libpython2.6 not found* building 'cPickle' extension gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I. -I/u01/home/apli/wm/GDD/Python-2.6.6/./Include -I. -IInclude -I./Include -I/opt/freeware/include -I/opt/freeware/include/readline -I/opt/freeware/include/ncurses -I/usr/local/include -I/u01/home/apli/wm/GDD/Python-2.6.6/Include -I/u01/home/apli/wm/GDD/Python-2.6.6 -c /u01/home/apli/wm/GDD/Python-2.6.6/Modules/cPickle.c -o build/temp.aix-5.3-2.6/u01/home/apli/wm/GDD/Python-2.6.6/Modules/cPickle.o ./Modules/ld_so_aix gcc -pthread -bI:Modules/python.exp build/temp.aix-5.3-2.6/u01/home/apli/wm/GDD/Python-2.6.6/Modules/cPickle.o -L/usr/local/lib *-lpython2.6* -o build/lib.aix-5.3-2.6/cPickle.so *collect2: library libpython2.6 not found* This is on AIX 5.3, GCC 4.2, Python 2.6.6 I can confirm that there is a libpython2.6.a file in the top level directory from where I am doing the configure/make etc Here are the options supplied to the configure command ./configure --enable-shared --disable-ipv6 --with-gcc=gcc CPPFLAGS="-I /opt/freeware/include -I /opt/freeware/include/readline -I /opt/freeware/include/ncurses" Please guide me in getting past this error. Thanks for your help on this. Regards, Anurag -------------- next part -------------- An HTML attachment was scrubbed... URL: From toby at telegraphics.com.au Wed Nov 24 16:19:49 2010 From: toby at telegraphics.com.au (toby) Date: Wed, 24 Nov 2010 13:19:49 -0800 (PST) Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014020136.6e85d70b@tritium.streitmacht.eu> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> <08823dd4-588a-4729-a660-711e266c96b0@y23g2000yqd.googlegroups.com> <396f8de7-ece5-4e9c-919b-886eb65ae14a@a30g2000vbt.googlegroups.com> <967678a1-fc5d-4b61-86c5-79a298999582@p1g2000vbo.googlegroups.com> Message-ID: <18cd9337-736b-427c-9cac-14c99056750a@p1g2000yqm.googlegroups.com> On Nov 24, 1:10?pm, Raffael Cavallaro wrote: > On 2010-11-23 11:34:14 -0500, Keith H Duggar said: > > > You don't understand the implications of your own words: > > > ? ?"having a financial interest in the outcome of a debate makes > > ? ?anything that person says an advertisement for his financial > > ? ?interests, not a fair assessment." > > > is substantially different from > > > ? ?"render his arguments in the debate inherently suspect." > > They are substantially the same, your jesuitical nit-picking > notwithstanding; JH is an untrustworthy source on matters relating to > the languages he sells training for. > And furthermore, he has cooties. --T > warmest regards, > > Ralph > > -- > Raffael Cavallaro From tinnews at isbd.co.uk Wed Nov 24 16:33:13 2010 From: tinnews at isbd.co.uk (tinnews at isbd.co.uk) Date: Wed, 24 Nov 2010 21:33:13 +0000 Subject: Problem with module 'evolution' after moving system References: <3810s7-bu5.ln1@chris.zbmc.eu> Message-ID: tinnews at isbd.co.uk wrote: [snip] > Using 'help' reveals basic information for evolution but reports "no > documentation ...." for evolution.ebook. On the old system (exactly > the same version of python, same OS, same everything just about) > "help(evolution.ebook)" shows the expected documentation. > > So, what's wrong, is some python module missing that the evolution > module needs? (It's quite likely that there are far more modules > installed on the old system than the new one) > A bit further trying to see what's wrong it seems that Python is failing to load .so libraries for some reason on the system where it doesn't work. The initialisation code in the evolution module has:- import ebook So, obviously this works on the old system but not on the new system. The ebook.so file is present on both systems in exactly the same place. -- Chris Green From agarwal1975 at gmail.com Wed Nov 24 16:41:56 2010 From: agarwal1975 at gmail.com (ashish) Date: Wed, 24 Nov 2010 13:41:56 -0800 (PST) Subject: No rule to make target `Parser/printgrammar.o' Message-ID: I'm trying to compile Python from source and get the same error on RedHat and Mac OS X. I did not pass any options to configure. The error occurs immediately. Redhat:~/Downloads/Python-2.7$ make gcc -pthread -c -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 - Wall -Wstrict-prototypes -I. -IInclude -I./Include -DPy_BUILD_CORE - o Modules/python.o ./Modules/python.c make: *** No rule to make target `Parser/printgrammar.o', needed by `Parser/pgen'. Stop. MacOSX:Python-2.7$ make gcc -c -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall - Wstrict-prototypes -I. -IInclude -I./Include -DPy_BUILD_CORE -o Modules/python.o ./Modules/python.c make: *** No rule to make target `Parser/printgrammar.o', needed by `Parser/pgen'. Stop. From tinnews at isbd.co.uk Wed Nov 24 16:54:18 2010 From: tinnews at isbd.co.uk (tinnews at isbd.co.uk) Date: Wed, 24 Nov 2010 21:54:18 +0000 Subject: Problem with module 'evolution' after moving system References: <3810s7-bu5.ln1@chris.zbmc.eu> Message-ID: tinnews at isbd.co.uk wrote: > tinnews at isbd.co.uk wrote: > [snip] > > > Using 'help' reveals basic information for evolution but reports "no > > documentation ...." for evolution.ebook. On the old system (exactly > > the same version of python, same OS, same everything just about) > > "help(evolution.ebook)" shows the expected documentation. > > > > So, what's wrong, is some python module missing that the evolution > > module needs? (It's quite likely that there are far more modules > > installed on the old system than the new one) > > > A bit further trying to see what's wrong it seems that Python is > failing to load .so libraries for some reason on the system where it > doesn't work. > > The initialisation code in the evolution module has:- > > import ebook > > So, obviously this works on the old system but not on the new system. > The ebook.so file is present on both systems in exactly the same place. > .... and I've finally found what was missing, I tried:- import evolution.ebook and it told me that 'import bonobo' was failing. A little searching and I found that python-gnome2 (which includes bonobo) was installed on the old system but not on the new one. Installing it has fixed my problem. -- Chris Green From sjmachin at lexicon.net Wed Nov 24 17:01:06 2010 From: sjmachin at lexicon.net (John Machin) Date: Wed, 24 Nov 2010 14:01:06 -0800 (PST) Subject: Ensuring symmetry in difflib.SequenceMatcher References: <135c0dfc-c382-4dd3-bfaf-8d508e5e648b@j21g2000vba.googlegroups.com> Message-ID: <89545b9a-8c97-41cd-a1f6-6b4439deda5c@y19g2000prb.googlegroups.com> On Nov 24, 8:43?pm, Peter Otten <__pete... at web.de> wrote: > John Yeung wrote: > > I'm generally pleased with difflib.SequenceMatcher: ?It's probably not > > the best available string matcher out there, but it's in the standard > > library and I've seen worse in the wild. ?One thing that kind of > > bothers me is that it's sensitive to which argument you pick as "seq1" > > and which you pick as "seq2": > > > Python 2.6.1 (r261:67517, Dec ?4 2008, 16:51:00) [MSC v.1500 32 bit > > (Intel)] on > > win32 > > Type "help", "copyright", "credits" or "license" for more information. > >>>> import difflib > >>>> difflib.SequenceMatcher(None, 'BYRD', 'BRADY').ratio() > > 0.44444444444444442 > >>>> difflib.SequenceMatcher(None, 'BRADY', 'BYRD').ratio() > > 0.66666666666666663 > > > Is this a bug? ?I am guessing the algorithm is implemented correctly, > > and that it's just an inherent property of the algorithm used. ?It's > > certainly not what I'd call a desirably property. ?Are there any > > simple adjustments that can be made without sacrificing (too much) > > performance? > > def symmetric_ratio(a, b, S=difflib.SequenceMatcher): > ? ? return (S(None, a, b).ratio() + S(None, b, a).ratio())/2.0 > > I'm expecting 50% performance loss ;) > > Seriously, have you tried to calculate the ratio with realistic data? > Without looking into the source I would expect the two ratios to get more > similar. > > Peter Surnames are extremely realistic data. The OP should consider using Levenshtein distance, which is "symmetric". A good (non-naive) implementation should be much faster than difflib. ratio = 1.0 - levenshtein(a, b) / float(max(len(a), len(b))) From saul.spatz at gmail.com Wed Nov 24 17:03:14 2010 From: saul.spatz at gmail.com (Saul Spatz) Date: Wed, 24 Nov 2010 14:03:14 -0800 (PST) Subject: PyQt Installation Problem on Windows Message-ID: <22cf97c9-ac22-4af1-8834-7ccb1828cc47@p1g2000yqm.googlegroups.com> Hi, I've been trying to install PyQt on Windows XP Pro so that I can try out eric ide. I used the binary windows installer for PyQt. I can run eric as administrator, but not with my ordinary user account. By running eric.bat with the --debug flag, I found that he crux of the problem is that if I type import PyQt4 in the python shell, it works for both users, but if I type import PyQt4.QtCore it works for the administrator, but the non-privileged account gets the message ImportError: DLL load failed: The specified module could not be found. In the file the file pyqtconfig.py from Python26\Lib\site-packages \PyQt4 I have the line 'pyqt_config_args': '--confirm-license -b C:\\Python26\\Lib\\site- packages\\PyQt4\\bin', I checked with a friend who uses eric, and his file does not have the --confirm-license parameter. As far as we can tell, we followed the same installation procedures. By the way, I have tried this with python 3.1 on the same machine with similar results. I've blown a whole day playing with this, so I'd really appreciate any help you can give me. From fetchinson at googlemail.com Wed Nov 24 17:08:32 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Wed, 24 Nov 2010 23:08:32 +0100 Subject: inverse of a matrix with Fraction entries In-Reply-To: <87y68izdnh.fsf.mdw@metalzone.distorted.org.uk> References: <8l50ulFhb4U1@mid.individual.net> <87y68izdnh.fsf.mdw@metalzone.distorted.org.uk> Message-ID: >> So after all I might just code the inversion via Gauss elimination >> myself in a way that can deal with fractions, shouldn't be that hard. > > I wouldn't do it that way. Let M be your matrix. Work out the LCM l of > the denominators, and multiply the matrix by that to make it an integer > matrix N = l M. Then work out the determinant d of that integer matrix. > Next, the big step: use Gaussian elimination to find a matrix A (the > `adjugate matrix') such that A N = d I. This should be doable entirely > using integer arithmetic, and I think without needing any divisions. > Finally, we have l A M = d I, so (l/d A) M = I and l/d A is the inverse > you seek. > > Does that make sense? Absolutely! But there is nothing wrong with working out the inverse directly using fractions.Fraction arithmetic, I'd think. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From hniksic at xemacs.org Wed Nov 24 17:09:25 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Wed, 24 Nov 2010 23:09:25 +0100 Subject: Collect output to string References: Message-ID: <87wro2gyqy.fsf@xemacs.org> Burton Samograd writes: > Terry Reedy writes: > >> On 11/23/2010 3:02 PM, Chris Rebert wrote: >> If you are using print or print(), you can redirect output to the >> StringIO object with >>sfile or file=sfile. I use the latter in a >> custom test function where I normally want output to the screen but >> occasionally want to capture test reports. > > Thanks for the info, but I was looking for a way to collect output > without modifying the original function, similar to > with-output-to-string in some schemes. Redirecting output like with-output-to-string does is achieved by assigning to sys.stdout. Using contextlib you can make it even closer to with-output-to-string by deploying the actual with statement. Unfortunately python's with cannot return a value, so you must expose the StringIO to the caller. The result is still quite nice: import sys, contextlib, cStringIO @contextlib.contextmanager def output_to_string(): oldout = sys.stdout sys.stdout = cStringIO.StringIO() try: yield sys.stdout finally: sys.stdout = oldout >>> with output_to_string() as out: ... print 'foo' ... print 'bar' ... >>> out.getvalue() 'foo\nbar\n' From robert.kern at gmail.com Wed Nov 24 17:54:56 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 24 Nov 2010 16:54:56 -0600 Subject: inverse of a matrix with Fraction entries In-Reply-To: References: <8l50ulFhb4U1@mid.individual.net> Message-ID: On 11/24/10 12:30 PM, Robert Kern wrote: > On 11/24/10 12:07 PM, Daniel Fetchinson wrote: > >> The whole story is that I have a matrix A and matrix B both of which >> have rational entries and they both have pretty crazy entries too. >> Their magnitude spans many orders of magnitude, but inverse(A)*B is an >> okay matrix and I can deal with it using floating point numbers. I >> only need this exact fraction business for inverse(A)*B (yes, a >> preconditioner would be useful :)) >> >> And I wouldn't want to write the whole matrix into a file, call Maple >> on it, parse the result, etc. >> >> So after all I might just code the inversion via Gauss elimination >> myself in a way that can deal with fractions, shouldn't be that hard. > > +1000. This is almost always the right thing to do whether you have floats or > rationals. By this I meant that you should using Gaussian elimination to *solve* the problem A^-1*B is the right thing to do rather than explicitly forming the inverse of A (no matter which algorithm you use). I hope that's what you meant too. -- 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 brendon.j.costa at gmail.com Wed Nov 24 17:58:56 2010 From: brendon.j.costa at gmail.com (Brendon) Date: Wed, 24 Nov 2010 14:58:56 -0800 (PST) Subject: Python dict as unicode Message-ID: <1045bf31-29f3-4886-bad0-c6025a74aca4@m20g2000prc.googlegroups.com> Hi all, I am trying to convert a dictionary to a unicode string and it fails with an exception. I am awfully surprised but searching the web has not turned up anything useful. I understand why the exception ocurrs, but am not sure why this is the default behaviour of python and if there is anything I can do to fix the problem. I have a python dictionary: d = { ......} It contains both primitive and complex objects. I want a unicode representation of that dict: s = unicode(d) Doing this I get an exception: UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 71: ordinal not in range(128) Now, it seems that unicode(d) is the same as unicode(str(d)). I was expecting there to be a __unicode__ method in the dictionary that in turn calls unicode() on each of the keys/values in the dict, but apparently not. Instead it seems to call the equivalent of str() on each key/value and then after adding them together, calls unicode() on the resulting string. Is this really the default behaviour? If so is there any way around it? I am using python 2.6.6 on a Linux system. From sohel807 at gmail.com Wed Nov 24 18:44:19 2010 From: sohel807 at gmail.com (Akand Islam) Date: Wed, 24 Nov 2010 15:44:19 -0800 (PST) Subject: Matlab equivalent syntax in Python Message-ID: <8317f18c-f2b2-4150-9bc0-e84d75e80de2@n32g2000pre.googlegroups.com> Can anyone please suggest me what will be the good way to use matlab equivalent of "profile clear, profile on, profile off, profile resume and profile viewer" in Python? Thanks in advance. From solipsis at pitrou.net Wed Nov 24 18:46:51 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Thu, 25 Nov 2010 00:46:51 +0100 Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> Message-ID: <20101125004651.3d6221a3@pitrou.net> On Wed, 24 Nov 2010 12:08:04 -0800 (PST) Raymond Hettinger wrote: > I'm writing-up more guidance on how to use super() and would like to > point at some real-world Python examples of cooperative multiple > inheritance. > > Google searches take me to old papers for C++ and Eiffel, but that > don't seem to be relevant to most Python programmers (i.e. a > WalkingMenu example where a submenu is both a Entry in a Menu and a > Menu itself). Another published example is in a graphic library where > some widgets inherit GraphicalFeature methods such as location, size > and NestingGroupingFeatures such as finding parents, siblings, and > children. I don't find either of those examples compelling because > there is no particular reason that they would have to have overlapping > method names. > > So far, the only situation I can find where method names necessarily > overlap is for the basics like __init__(), close(), flush(), and > save() where multiple parents need to have their own initialization > and finalization. > > If you guys know of good examples, I would appreciate a link or a > recap. I have never seen a good use of cooperative multiple inheritance in Python. My own experience trying to use it suggests me that I would have been better with independent "handler" classes (urllib2-style). Regards Antoine. From alan at baselinedata.co.uk Wed Nov 24 19:45:41 2010 From: alan at baselinedata.co.uk (Alan Harris-Reid) Date: Thu, 25 Nov 2010 00:45:41 +0000 Subject: SQLite date fields Message-ID: <4CEDB1B5.4040008@baselinedata.co.uk> Hi, I am having design problems with date storage/retrieval using Python and SQLite. I understand that a SQLite date column stores dates as text in ISO format (ie. '2010-05-25'). So when I display a British date (eg. on a web-page) I convert the date using datetime.datetime.strptime(mydate,'%Y-%m-%d').strftime('%d/%m/%Y'). However, when it comes to writing-back data to the table, SQLite is very forgiving and is quite happy to store '25/06/2003' in a date field, but this is not ideal because a) I could be left with a mixture of date formats in the same column, b) SQLite's date functions only work with ISO format. Therefore I need to convert the date string back to ISO format before committing, but then I would need a generic function which checks data about to be written in all date fields and converts to ISO if necessary. That sounds a bit tedious to me, but maybe it is inevitable. Are there simpler solutions? Would it be easier to change the date field to a 10-character field and store 'dd/mm/yyyy' throughout the table? This way no conversion is required when reading or writing from the table, and I could use datetime() functions if I needed to perform any date-arithmetic. How have other developers overcome this problem? Any help would be appreciated. For the record, I am using SQLite3 with Python 3.1. Alan From afriere at yahoo.co.uk Wed Nov 24 19:45:52 2010 From: afriere at yahoo.co.uk (Asun Friere) Date: Wed, 24 Nov 2010 16:45:52 -0800 (PST) Subject: Style question for conditional execution References: <7xtyj6o3kp.fsf@ruckus.brouhaha.com> Message-ID: On Nov 25, 7:43?am, Paul Rubin wrote: > Gerald Britton writes: > > ? ? if v: > > ? ? ? ? f() > > > I might, however, think more in a functional-programming direction. > > Then I might write: > > > ? ? v and f() > > Python has conditional expressions. ?The above would be: > > ? ? f() if v else None > > using "and" is bug-prone. Using 'and' is indeed bug-prone when used in combination with 'or' to achieve a ternary conditional op, as was done the pre PEP308 days, eg "val = cond and a or b" because of the possibility that 'a' was itself not true, (thus requiring the ugly 'val = (cond and [a] or [b])[0]'). But no such bug could occur with this particular idiom. What could possibly go wrong here? :) That being said, I agree with previous posters that "if cond : fn()" wins in terms of readability. From shearichard at gmail.com Wed Nov 24 20:57:56 2010 From: shearichard at gmail.com (shearichard) Date: Wed, 24 Nov 2010 17:57:56 -0800 (PST) Subject: Pypi (Cheeseshop) Score - derivation of ? Message-ID: <86979c80-0955-4ee8-b645-10097d45dd58@z9g2000pri.googlegroups.com> Hi - Anyone know how the score offered by Pypi is derived ? For instance in ... http://pypi.python.org/pypi?%3Aaction=search&term=spam&submit=search ... 'bud.nospam 1.0.1' has a score of 9 but 'pydspam 1.1.9' has a score of 7. Where are those numbers from and what do they mean ? Thanks R. From ben+python at benfinney.id.au Wed Nov 24 21:54:14 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 25 Nov 2010 13:54:14 +1100 Subject: Pypi (Cheeseshop) Score - derivation of ? References: <86979c80-0955-4ee8-b645-10097d45dd58@z9g2000pri.googlegroups.com> Message-ID: <87zksy6rl5.fsf@benfinney.id.au> shearichard writes: > Hi - Anyone know how the score offered by Pypi is derived ? Specifically, the score offered in response to a search query. > For instance in ... > > http://pypi.python.org/pypi?%3Aaction=search&term=spam&submit=search > > ... 'bud.nospam 1.0.1' has a score of 9 but 'pydspam 1.1.9' has a > score of 7. > > Where are those numbers from and what do they mean ? They are the relevance of the result to that particular search query. I don't know the scale of the score or how it's derived, but that's the intended meaning AFAIK. I think a better term than ?score? could be chosen; perhaps you could submit a bug report against PyPI. -- \ ?One of the most important things you learn from the internet | `\ is that there is no ?them? out there. It's just an awful lot of | _o__) ?us?.? ?Douglas Adams | Ben Finney From shearichard at gmail.com Wed Nov 24 22:46:47 2010 From: shearichard at gmail.com (shearichard) Date: Wed, 24 Nov 2010 19:46:47 -0800 (PST) Subject: Pypi (Cheeseshop) Score - derivation of ? References: <86979c80-0955-4ee8-b645-10097d45dd58@z9g2000pri.googlegroups.com> <87zksy6rl5.fsf@benfinney.id.au> Message-ID: <7528b863-2f10-491d-bf4a-a916eb72a6ad@t8g2000prh.googlegroups.com> On Nov 25, 3:54?pm, Ben Finney wrote: > shearichard writes: > > Hi - Anyone know how the score offered by Pypi is derived ? > > Specifically, the score offered in response to a search query. > > > For instance in ... > > >http://pypi.python.org/pypi?%3Aaction=search&term=spam&submit=search > > > ... 'bud.nospam 1.0.1' has a score of 9 but 'pydspam 1.1.9' has a > > score of 7. > > > Where are those numbers from and what do they mean ? > > They are the relevance of the result to that particular search query. I > don't know the scale of the score or how it's derived, but that's the > intended meaning AFAIK. > > I think a better term than ?score? could be chosen; perhaps you could > submit a bug report against PyPI. > OK that makes sense. I thought it was some comment on how 'good' the package in question was ! I will do as you say and submit a bug report to get the literal altered to something a little more self-explanatory. From wuwei23 at gmail.com Wed Nov 24 23:03:06 2010 From: wuwei23 at gmail.com (alex23) Date: Wed, 24 Nov 2010 20:03:06 -0800 (PST) Subject: Pypi (Cheeseshop) Score - derivation of ? References: <86979c80-0955-4ee8-b645-10097d45dd58@z9g2000pri.googlegroups.com> Message-ID: <30d136fe-5fc3-49aa-904d-c63b228e5d2c@n2g2000pre.googlegroups.com> On Nov 25, 11:57?am, shearichard wrote: > Hi - Anyone know how the score offered by Pypi is derived ? > > For instance in ... > > http://pypi.python.org/pypi?%3Aaction=search&term=spam&submit=search > > ... 'bud.nospam 1.0.1' has a score of 9 but 'pydspam 1.1.9' has a > score of 7. If you hover over the Score header in the results list, it says: Occurrence of search term weighted by field (name, summary, keywords, description, author, maintainer) I thought PyPI used to offer a 'kwality' score for packages, based on the presence of installers, doc files, tests etc. Does anyone know what happened to that? From phlip2005 at gmail.com Wed Nov 24 23:46:18 2010 From: phlip2005 at gmail.com (Phlip) Date: Wed, 24 Nov 2010 20:46:18 -0800 (PST) Subject: a regexp riddle: re.search(r'(?:(\w+), |and (\w+))+', 'whatever a, bbb, and c') =? ('a', 'bbb', 'c') Message-ID: <00a69232-7703-48ce-8a42-b28f24946680@i32g2000pri.googlegroups.com> HypoNt: I need to turn a human-readable list into a list(): print re.search(r'(?:(\w+), |and (\w+))+', 'whatever a, bbb, and c').groups() That currently returns ('c',). I'm trying to match "any word \w+ followed by a comma, or a final word preceded by and." The match returns 'a, bbb, and c', but the groups return ('bbb', 'c'). What do I type for .groups() to also get the 'a'? Please go easy on me (and no RTFM!), because I have only been using regular expressions for about 20 years... -- Phlip http://bit.ly/ZeekLand From alice at gothcandy.com Thu Nov 25 00:16:14 2010 From: alice at gothcandy.com (=?utf-8?Q?Alice_Bevan=E2=80=93McGregor?=) Date: Wed, 24 Nov 2010 21:16:14 -0800 Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> Message-ID: <201011242116145773-alice@gothcandycom> On 2010-11-24 12:08:04 -0800, Raymond Hettinger said: > I'm writing-up more guidance on how to use super() and would like to > point at some real-world Python examples of cooperative multiple > inheritance. The SocketServer module (http://docs.python.org/library/socketserver.html) uses cooperative multiple inheritance to implement threading / async using a ThreadingMixIn class and multi-processing using a ForkingMixIn class, which may not be as complicated a use case as you are looking for. One thing that caught me up was the attribute resolution order; it's a FIFO, with the first superclass being examined preferentially over later superclasses in the declaration. (Mixins go before the class they extend.) ? Alice. From tjreedy at udel.edu Thu Nov 25 00:42:55 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 25 Nov 2010 00:42:55 -0500 Subject: Python dict as unicode In-Reply-To: <1045bf31-29f3-4886-bad0-c6025a74aca4@m20g2000prc.googlegroups.com> References: <1045bf31-29f3-4886-bad0-c6025a74aca4@m20g2000prc.googlegroups.com> Message-ID: On 11/24/2010 5:58 PM, Brendon wrote: > Hi all, > > I am trying to convert a dictionary to a unicode string and it fails > with an exception. I am awfully surprised but searching the web has > not turned up anything useful. I understand why the exception ocurrs, > but am not sure why this is the default behaviour of python and if > there is anything I can do to fix the problem. > > I have a python dictionary: > d = { ......} > > It contains both primitive and complex objects. I want a unicode > representation of that dict: > s = unicode(d) > > Doing this I get an exception: > UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position > 71: ordinal not in range(128) > > Now, it seems that unicode(d) is the same as unicode(str(d)). I was > expecting there to be a __unicode__ method in the dictionary that in > turn calls unicode() on each of the keys/values in the dict, but > apparently not. Instead it seems to call the equivalent of str() on > each key/value and then after adding them together, calls unicode() on > the resulting string. > > Is this really the default behaviour? If so is there any way around > it? Use 3.x > I am using python 2.6.6 on a Linux system. -- Terry Jan Reedy From lkcl at lkcl.net Thu Nov 25 03:09:09 2010 From: lkcl at lkcl.net (Luke Kenneth Casson Leighton) Date: Thu, 25 Nov 2010 08:09:09 +0000 Subject: [ANN] PythonWebkit bindings for WebkitDFB Message-ID: WebkitDFB is an experimental port to allow the webkit web browser engine to use DirectFB (http://directfb.org). It is lightning-quick to start up (no large widget set to load), yet has the potential to provide full HTML5 functionality. The PythonWebkit project, http://www.gnu.org/software/pythonwebkit brings 300+ DOM objects and 2,000+ fully W3C-compliant python-based DOM functions to webkit, making python effectively a peer of javascript (doc.body.style, getElementsByTagName, appendChild, setTimeout, XMLHttpRequest, onclick etc.) These two projects have been brought together in the same source repository. If startup time and CPU usage is important (as it is on embedded systems) then please do consider helping with WebkitDFB by funding its ongoing development and/or helping Denis out. If startup time and CPU usage and _python_ are important... :) in this rather short announcement, it's easy to miss the significance: yes, webkit the web browser engine, directfb the direct framebuffer engine, and python the utterly cool and beautiful programming language have been combined into the same package and sentence. more information at http://www.gnu.org/software/pythonwebkit. l. From joralemonshelly at gmail.com Thu Nov 25 03:12:40 2010 From: joralemonshelly at gmail.com (Shel) Date: Thu, 25 Nov 2010 00:12:40 -0800 (PST) Subject: building a web interface References: <16bc6e60-ad98-4d81-9f20-23e9b52eea21@n30g2000vbb.googlegroups.com> Message-ID: <90335766-af85-4a9d-8a13-518b88014b5a@r31g2000prg.googlegroups.com> This is really great. I wish I could come up with some creative new ways to say thank you, but... thank you :-) Shel On Nov 21, 6:10?pm, Martin Gregorie wrote: > On Sun, 21 Nov 2010 15:40:10 -0800, Shel wrote: > > I am confused about multiple simultaneous users, which I would like to > > be able to accommodate. ?On the db side, I have a structure to store > > data for each user, and know a bit about selectively locking data, > > although I have not implemented that yet, so will see what happens. > > I realise what I wrote last night wasn't all that clear. Terms: > 'transaction' and 'session'. > > A web server 'transaction' consists of a request from a user that results > in a page being sent to the user. That's it. It is an isolated action > that does not depend in the web server knowing anything about the user > because all the information it needs to decide which page to send was > supplied when the user sent in the URL of the page. Now if the user > clicks on a link on that page, his browser sends the URL in the link to > the server, which in turn fishes out another page and sends it back to > the user. As far as the server is concerned, there is no connection > whatever between the two requests: either or both URLs could have been > copied from a piece of paper for all it knows or cares. There is no > concept of context or a session involved. > > A 'session' involves context. Think of what happens when you login to a > computer. That starts a login session that has context: the computer now > knows who you are and provides context by connecting you to your login > directory and opening some work space which is used to remember which > directory you're in, what commands you issued (so you can look at the > history), etc. The session and its context persists until you log out. > > In what you're intending to do, a user will start a session by starting > to use your program and that session will last until the user disconnects > from the session. All the web server knows is that instead of finding a > page on disk some place it passes your user's request to your program and > sends its output, in the form of a web page, back to the user. It does > this each time it receives a request from the user because all the user's > requests contain the same URL - that of your program. The server does > this without knowing there is such a thing as a session or that there is > any context belonging to the user. > > The upshot is that your program has to keep track of all the active > sessions and maintain context for each active session. It also needs a > way to recognise and get rid of dead sessions because sessions don't > always end cleanly: the line may go down or the user may forget he was > using your program and turn his PC off. For instance, if the session > context has a timestamp, you might delete it after, say, 20 hours of > inactivity, or when the user logs on again. If the data is sensitive, you > might also force a new logon after 10 minutes of inactivity. > > The database is as good a place as any for keeping session and context > data - if its well structured the context may well form a single (large) > row on one table, but you do need a unique key for it. That could even be > the login name provided you're able to include it in every page you send > to the user and can guarantee that the browser will send it back as part > of the next request. A hidden field on the page will do this > automatically. > > The basic program cycle will be: > > - receive a request > - read the context for the session > - use data in the request to carry out the requested action > - write the updated context back to the database > - create the output page and send it to the user > > though of course you need additional dialogue to deal with both valid and > invalid logons and logoffs. > > > I don't really get how multiple users work in terms of pretty much > > everything else, like if the Python code is running on the server, > > then... well, I just don't know. > > Hopefully the above made it a bit clearer. > > > ?Maybe I should try to get it running > > for multiple discrete users first, and then think about simultaneous > > users, or is that a bad way to go about things? ?Or maybe it will start > > to make more sense when I get into building the interface? ?Any > > info/suggestions are very welcome. > > For bare desktop development I would split the program into three parts: > > 1) the program itself, written to run a single transaction each time its > called. Inputs would be the bits of the users message it needs to act on > and the current session context record. > > 2) a testing harness that accepts user input from the console, sends > output back to the console and maintains a single session context record > in memory: IOW it runs your program in single user mode. > > 3)the web server interface which retrieves the session context record, > passes it and the input to your program and, after that has run, saves > the session context record and passes the output to the web server for > delivery to the user. > > This way both 2 and 3 can be developed against a really simple 'do almost > nothing' version of 1 while that in turn can be developed and tested on > your desktop using 2 and later be dropped into the web server with 3 as > its interface. > > I have an in-house copy of Apache that I'd use to develop your type of > program. Its used for all my website development so that nothing gets > loaded onto my public sites until its been properly checked out here. > You can do the same if you can find and install a really simple web > server that would run on your PC together with a local copy of MySQL - of > course! Given this setup you can use your usual web browser to talk to > the local web server. If you can run all that you won't need 2 because > you can have your simple web server and program running in a console > window on your desktop PC while you hammer it from your web browser. > > -- > martin@ ? | Martin Gregorie > gregorie. | Essex, UK > org ? ? ? | From alice at gothcandy.com Thu Nov 25 03:36:49 2010 From: alice at gothcandy.com (=?utf-8?Q?Alice_Bevan=E2=80=93McGregor?=) Date: Thu, 25 Nov 2010 00:36:49 -0800 Subject: building a web interface References: Message-ID: <2010112500364975026-alice@gothcandycom> Howdy! I'm mildly biased, being the author of the framework, but I can highly recommend WebCore for rapid prototyping of web applications; it has templating via numerous template engines, excellent JSON (AJAJ) support, and support for database back-ends via SQLAlchemy. It also has session support baked-in via a project called Beaker. Documentation is fairly complete, and I can be found camping in the #webcore IRC channel on irc.freenode.net at strange hours. If you can write a class, you can have a fully operational web application in a single file of ~8 lines or so. (Or you can create a complete easy-installable Python package with multiple modules.) For information, see: http://www.web-core.org/ As an interactive-fiction example: class RootController(web.core.Controller): def index(self): """This returns a template that uses JavaScript to call execute(). The JavaScript adds the result of execute() to the display.""" session = db.Session().save() return './templates/main.html', dict(session=session.id) def execute(self, session, statement): """Load our session and pass the input off to our interactive fiction library of choice. Return the result if all went well.""" session = db.Session.get(session) try: result = myiflib.execute(session, statement) except myiflib.ParseError: return 'json:', dict(status="failure", message="Error...") return 'json:', dict(status="success", message=result) ? Alice. From lanyjie at yahoo.com Thu Nov 25 04:12:38 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Thu, 25 Nov 2010 01:12:38 -0800 (PST) Subject: what a cheap rule Message-ID: <478343.25019.qm@web54204.mail.re2.yahoo.com> Sometimes the golden rule in Python of "explicit is better than implicit" is so cheap that it can be thrown away for the trouble of typing an empty tuple. Today when I am explaining that in Python 3, there are two ways to raise exceptions: raise Exception raise Exception() and that the first one is the same as the second one, as Python will add the missing pair of parenthesis. I felt their pain as they gasped. Before that, I have already explained to them this piece of code: try: raise SomeException() except SomeException: print('Got an exception here') by saying that the except-clause will match anything that belong to the SomeException class. Without knowing this secrete piece of information (that a pair of parenthesis is automatically provided), the following code would be hard to understand: try: raise SomeException except SomeException: print('Got an exception here') because the class object SomeException is not an instance of itself, so a not-so-crooked coder will not consider a match here. So, the explicit is better than implicit rule is thrown out of the window so cheaply, that it literally worth less than an empty tuple! Regards, Yingjie From martin at v.loewis.de Thu Nov 25 04:17:05 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Thu, 25 Nov 2010 10:17:05 +0100 Subject: Pypi (Cheeseshop) Score - derivation of ? In-Reply-To: <30d136fe-5fc3-49aa-904d-c63b228e5d2c@n2g2000pre.googlegroups.com> References: <86979c80-0955-4ee8-b645-10097d45dd58@z9g2000pri.googlegroups.com> <30d136fe-5fc3-49aa-904d-c63b228e5d2c@n2g2000pre.googlegroups.com> Message-ID: <4CEE2991.4050303@v.loewis.de> > Occurrence of search term weighted by field (name, summary, keywords, > description, author, maintainer) > > I thought PyPI used to offer a 'kwality' score for packages, based on > the presence of installers, doc files, tests etc. Does anyone know > what happened to that? There was indeed a kwalitee computation (cheesecake); it is unmaintained. It is a urban myth that this had any impact on search results. It never did. Regards, Martin From anurag.chourasia at gmail.com Thu Nov 25 04:24:15 2010 From: anurag.chourasia at gmail.com (Anurag Chourasia) Date: Thu, 25 Nov 2010 14:54:15 +0530 Subject: AIX 5.3 - Enabling Shared Library Support Vs Extensions Message-ID: All, When I configure python to enable shared libraries, none of the extensions are getting built during the make step due to this error. building 'cStringIO' extension gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I. -I/u01/home/apli/wm/GDD/Python-2.6.6/./Include -I. -IInclude -I./Include -I/opt/freeware/include -I/opt/freeware/include/readline -I/opt/freeware/include/ncurses -I/usr/local/include -I/u01/home/apli/wm/GDD/Python-2.6.6/Include -I/u01/home/apli/wm/GDD/Python-2.6.6 -c /u01/home/apli/wm/GDD/Python-2.6.6/Modules/cStringIO.c -o build/temp.aix-5.3-2.6/u01/home/apli/wm/GDD/Python-2.6.6/Modules/cStringIO.o ./Modules/ld_so_aix gcc -pthread -bI:Modules/python.exp build/temp.aix-5.3-2.6/u01/home/apli/wm/GDD/Python-2.6.6/Modules/cStringIO.o -L/usr/local/lib *-lpython2.6* -o build/lib.aix-5.3-2.6/cStringIO.so *collect2: library libpython2.6 not found* building 'cPickle' extension gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I. -I/u01/home/apli/wm/GDD/Python-2.6.6/./Include -I. -IInclude -I./Include -I/opt/freeware/include -I/opt/freeware/include/readline -I/opt/freeware/include/ncurses -I/usr/local/include -I/u01/home/apli/wm/GDD/Python-2.6.6/Include -I/u01/home/apli/wm/GDD/Python-2.6.6 -c /u01/home/apli/wm/GDD/Python-2.6.6/Modules/cPickle.c -o build/temp.aix-5.3-2.6/u01/home/apli/wm/GDD/Python-2.6.6/Modules/cPickle.o ./Modules/ld_so_aix gcc -pthread -bI:Modules/python.exp build/temp.aix-5.3-2.6/u01/home/apli/wm/GDD/Python-2.6.6/Modules/cPickle.o -L/usr/local/lib *-lpython2.6* -o build/lib.aix-5.3-2.6/cPickle.so *collect2: library libpython2.6 not found* This is on AIX 5.3, GCC 4.2, Python 2.6.6 I can confirm that there is a libpython2.6.a file in the top level directory from where I am doing the configure/make etc Here are the options supplied to the configure command ./configure --enable-shared --disable-ipv6 --with-gcc=gcc CPPFLAGS="-I /opt/freeware/include -I /opt/freeware/include/readline -I /opt/freeware/include/ncurses" Please guide me in getting past this error. Thanks for your help on this. Regards, Anurag -------------- next part -------------- An HTML attachment was scrubbed... URL: From a1chandan at gmail.com Thu Nov 25 04:43:21 2010 From: a1chandan at gmail.com (Geobird) Date: Thu, 25 Nov 2010 01:43:21 -0800 (PST) Subject: Processing file with lists. Message-ID: <93ec74ea-7cf1-4671-81f0-d71313d8736f@29g2000prb.googlegroups.com> I have a text file , having fields delimited by ; in the first line and all the way down is the data taken for those fields . Say FAMILY NAME;SPECIES/SUBSPECIES;GENUS NAME;SUBGENUS NAME;SPECIES NAME;SUBSPECIES NAME;AUTHORSHIP Acrididae;Acanthacris ruficornis (Fabricius, 1787);Acanthacris;;ruficornis;;(Fabricius, 1787) Acrididae;Acrida bicolor (Thunberg, 1815);Acrida;;bicolor;;(Thunberg, 1815) Acrididae;Acrida oxycephala (Pallas, 1771);Acrida;;oxycephala;; (Pallas, 1771) Acrididae;Acrida turrita (Linnaeus, 1758);Acrida;;turrita;;(Linnaeus, 1758) I want to know how could I process this file using ' lists ' , that could answer questions like . How many ? , Who did .. ? etc. I am a newbie , and would appreciate your help From lanyjie at yahoo.com Thu Nov 25 04:44:44 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Thu, 25 Nov 2010 01:44:44 -0800 (PST) Subject: a regexp riddle: re.search(r' In-Reply-To: <00a69232-7703-48ce-8a42-b28f24946680@i32g2000pri.googlegroups.com> Message-ID: <933864.19427.qm@web54204.mail.re2.yahoo.com> --- On Thu, 11/25/10, Phlip wrote: > From: Phlip > Subject: a regexp riddle: re.search(r' > To: python-list at python.org > Date: Thursday, November 25, 2010, 8:46 AM > HypoNt: > > I need to turn a human-readable list into a list(): > > ???print re.search(r'(?:(\w+), |and > (\w+))+', 'whatever a, bbb, and > c').groups() > > That currently returns ('c',). I'm trying to match "any > word \w+ > followed by a comma, or a final word preceded by and." > > The match returns 'a, bbb, and c', but the groups return > ('bbb', 'c'). > What do I type for .groups() to also get the 'a'? > First of all, the 'bbb' coresponds to the first capturing group and 'c' the second. But 'a' is forgotten be cause it was the first match of the first group, but there is a second match 'bbb'. Generally, a capturing group only remembers the last match. It also seems that your re may match this: 'and c', which does not seem to be your intention. So it may be more intuitively written as: r'(?:(\w+), )+and (\w+)' I'm not sure how to get it done in one step, but it would be easy to first get the whole match, then process it with: re.findall(r'(\w+)(?:,|$)', the_whole_match) cheers, Yingjie From alice at gothcandy.com Thu Nov 25 04:52:32 2010 From: alice at gothcandy.com (=?utf-8?Q?Alice_Bevan=E2=80=93McGregor?=) Date: Thu, 25 Nov 2010 01:52:32 -0800 Subject: Processing file with lists. References: <93ec74ea-7cf1-4671-81f0-d71313d8736f@29g2000prb.googlegroups.com> Message-ID: <2010112501523211833-alice@gothcandycom> You describe a two-part problem. The first, loading the data, is easily accomplished with the Python CSV module: http://docs.python.org/library/csv.html e.g.: reader = csv.reader(open('filename', 'rb'), delimiter=';', quotechar=None) In the above example, you can iterate over 'reader' in a for loop to read out each row. The values will be returned in a list. You could also use a DictReader to make the data more naturally accessible using name=value pairs. > I want to know how could I process this file using ' lists ' , > that could answer questions like . How many ? , Who did .. ? > etc. This isn't very clear, but if your dataset is small (< 1000 rows or so) you can fairly quickly read the data into RAM then run through the data with loops designed to pull out certain data, though it seems your data would need additional processing. (The authorship information should be split into two separate columns, for example.) An alternative would be to load the data into a relational database like MySQL or even SQLite (which offers in-memory databases), or an object database such as MongoDB which supports advanced querying using map/reduce. You'd have to examine the documentation on these different systems to see which would best fit your use case. I prefer Mongo as it is very easy to get data into and out of, supports SQL-like queries, and map/reduce is extremely powerful. ? Alice. From alice at gothcandy.com Thu Nov 25 05:00:11 2010 From: alice at gothcandy.com (=?utf-8?Q?Alice_Bevan=E2=80=93McGregor?=) Date: Thu, 25 Nov 2010 02:00:11 -0800 Subject: a regexp riddle: re.search(r'(?:(\w+), |and (\w+))+', 'whatever a, bbb, and c') =? ('a', 'bbb', 'c') References: <00a69232-7703-48ce-8a42-b28f24946680@i32g2000pri.googlegroups.com> Message-ID: <2010112502001129201-alice@gothcandycom> Accepting input from a human is frought with dangers and edge cases. ;) Some time ago I wrote a regular expression generator that creates regexen that can parse arbitrarily delimited text, supports quoting (to avoid accidentally separating two elements that should be treated as one), and works in both directions (text<->native). The code that generates the regex is heavily commented: https://github.com/pulp/marrow.util/blob/master/marrow/util/convert.py#L123-234 You should be able to use this as-is and simply handle the optional 'and' on the last element yourself. You can even create an instance of the class with the options you want then get the generated regular expression by running print(parser.pattern). Note that I have friends who use 'and' multiple times when describing lists of things. :P ? Alice. From alice at gothcandy.com Thu Nov 25 05:04:56 2010 From: alice at gothcandy.com (=?utf-8?Q?Alice_Bevan=E2=80=93McGregor?=) Date: Thu, 25 Nov 2010 02:04:56 -0800 Subject: a regexp riddle: re.search(r'(?:(\w+), |and (\w+))+', 'whatever a, bbb, and c') =? ('a', 'bbb', 'c') References: <00a69232-7703-48ce-8a42-b28f24946680@i32g2000pri.googlegroups.com> Message-ID: <2010112502045628565-alice@gothcandycom> Now that I think about it, and can be stripped using a callback function as the 'normalize' argument to my KeywordProcessor class: def normalize(value): value = value.strip() if value.startswith("and"): value = value[3:] return value parser = KeywordProcessor(',', normalize=normalize, result=list) ? Alice. From stefan-usenet at bytereef.org Thu Nov 25 05:11:17 2010 From: stefan-usenet at bytereef.org (Stefan Krah) Date: Thu, 25 Nov 2010 11:11:17 +0100 Subject: AIX 5.3 - Enabling Shared Library Support Vs Extensions In-Reply-To: References: Message-ID: <20101125101117.GA3437@yoda.bytereef.org> Anurag Chourasia wrote: > When I configure python to enable shared libraries, none of the extensions are getting built during the make step due to this error. > > building 'cStringIO' extension > gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall > -Wstrict-prototypes -I. -I/u01/home/apli/wm/GDD/Python-2.6.6/./Include -I. > -IInclude -I./Include -I/opt/freeware/include > -I/opt/freeware/include/readline -I/opt/freeware/include/ncurses > -I/usr/local/include -I/u01/home/apli/wm/GDD/Python-2.6.6/Include > -I/u01/home/apli/wm/GDD/Python-2.6.6 -c > /u01/home/apli/wm/GDD/Python-2.6.6/Modules/cStringIO.c -o > build/temp.aix-5.3-2.6/u01/home/apli/wm/GDD/Python-2.6.6/Modules/cStringIO.o > ./Modules/ld_so_aix gcc -pthread -bI:Modules/python.exp > build/temp.aix-5.3-2.6/u01/home/apli/wm/GDD/Python-2.6.6/Modules/cStringIO.o > -L/usr/local/lib *-lpython2.6* -o build/lib.aix-5.3-2.6/cStringIO.so ^^^^^^^^^^^^^^^^ Try these flags: -L. -L/usr/local/lib If this solves the problem and the issue is also present in Python-2.7, you should report a bug at http://bugs.python.org/ . Stefan Krah From lanyjie at yahoo.com Thu Nov 25 06:06:03 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Thu, 25 Nov 2010 03:06:03 -0800 (PST) Subject: tilted text in the turtle module Message-ID: <709508.49315.qm@web54207.mail.re2.yahoo.com> First of all, I'd like to express my deep gratidute to the author of this module, it is such a fun module to work with and to teach python as a first programming language. Secondly, I would like to request a feature if it is not too hard to achieve. Currently, you can only write texts horizontally, no matter what is the current orientation of the turtle pen. I wonder if it is possible to write text in any direction when we control the heading of the turtle? For example, the following code would write a vertically oriented text: setheading(90) #turtle facing up write("vertical text!") Thanks a lot! Yingjie From egarrulo at gmail.com Thu Nov 25 06:23:33 2010 From: egarrulo at gmail.com (Elena) Date: Thu, 25 Nov 2010 03:23:33 -0800 (PST) Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> Message-ID: <9059b217-e3a4-4e82-a9a1-a84aafef942d@s9g2000vby.googlegroups.com> On Oct 13, 9:09?pm, namekuseijin wrote: > On 11 out, 08:49, Oleg ?Parashchenko wrote: > > > > > Hello, > > > I'd like to try the idea that Scheme can be considered as a new > > portable assembler. We could code something in Scheme and then compile > > it to PHP or Python or Java or whatever. > > > Any suggestions and pointers to existing and related work are welcome. > > Thanks! > > > My current approach is to take an existing Scheme implementation and > > hijack into its backend. At this moment Scheme code is converted to > > some representation with a minimal set of bytecodes, and it should be > > quite easy to compile this representation to a target language. After > > some research, the main candidates are Gambit, Chicken and CPSCM: > > >http://uucode.com/blog/2010/09/28/r5rs-scheme-as-a-virtual-machine-i/... > > > If there is an interest in this work, I could publish progress > > reports. > > > -- > > Oleg Parashchenko ?olpa at http://uucode.com/http://uucode.com/blog/?XML, TeX, Python, Mac, Chess > > it may be assembler, too bad scheme libs are scattered around written > in far too many different flavors of assembler... > > It warms my heart though to realize that Scheme's usual small size and > footprint has allowed for many quality implementations targetting many > different backends, be it x86 assembly, C, javascript or .NET. ?Take > python and you have a slow c bytecode interpreter and a slow > bytecode .NET compiler. ?Take haskell and its so friggin' huge and > complex that its got its very own scary monolithic gcc. ?When you > think of it, Scheme is the one true high-level language with many > quality perfomant backends -- CL has a few scary compilers for native > code, but not one to java, .NET or javascript that I know of... Take R5RS Scheme and you get a language which doesn't allow you to get things done. Scheme is as far from Assembly as one language can be. Assembly exists to get things done, R5RS Scheme does not even allows you load native libraries of the underlying operating-system, does it? It's easy to stay small and clean when you don't have to dirty your hands with such crap as real-world applications development. From lanyjie at yahoo.com Thu Nov 25 06:32:54 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Thu, 25 Nov 2010 03:32:54 -0800 (PST) Subject: the buggy regex in Python Message-ID: <297677.64235.qm@web54207.mail.re2.yahoo.com> I know many experts will say I don't have understanding...but let me pay this up front as my tuition. Here are some puzzling results I have got (I am using Python 3, I suppose similar results for python 2). When I do the following, I got an exception: >>> re.findall('(d*)*', 'adb') >>> re.findall('((d)*)*', 'adb') When I do this, I am fine but the result is wrong: >>> re.findall('((.d.)*)*', 'adb') [('', 'adb'), ('', '')] Why is it wrong? The first mactch of groups: ('', 'adb') indicates the outer group ((.d.)*) captured the empty string, while the inner group (.d.) captured 'adb', so the outer group must have captured the empty string at the end of the provided string 'adb'. Once we have matched the final empty string '', there should be no more matches, but we got another match ('', '')!!! So, findall matched the empty string in the end of the string twice!!! Isn't this a bug? Yingjie From santiago.caracol at gmail.com Thu Nov 25 07:38:45 2010 From: santiago.caracol at gmail.com (Santiago Caracol) Date: Thu, 25 Nov 2010 04:38:45 -0800 (PST) Subject: do something every n seconds Message-ID: <1a7afe44-b320-4135-9b9d-6b99b6c809b6@p38g2000vbn.googlegroups.com> Hello, how can I do something (e.g. check if new files are in the working directory) every n seconds in Python? Santiago From alice at gothcandy.com Thu Nov 25 07:51:52 2010 From: alice at gothcandy.com (=?utf-8?Q?Alice_Bevan=E2=80=93McGregor?=) Date: Thu, 25 Nov 2010 04:51:52 -0800 Subject: do something every n seconds References: <1a7afe44-b320-4135-9b9d-6b99b6c809b6@p38g2000vbn.googlegroups.com> Message-ID: <2010112504515230363-alice@gothcandycom> > how can I do something (e.g. check if new files are in the working > directory) every n seconds in Python? The simplest method is executing time.sleep(n) within an infinite while loop. There are more elegant solutions: using coroutine frameworks, threaded task schedulers, etc. ? Alice. From no.email at nospam.invalid Thu Nov 25 07:57:44 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 25 Nov 2010 04:57:44 -0800 Subject: do something every n seconds References: <1a7afe44-b320-4135-9b9d-6b99b6c809b6@p38g2000vbn.googlegroups.com> Message-ID: <7x1v698ss7.fsf@ruckus.brouhaha.com> Santiago Caracol writes: > how can I do something (e.g. check if new files are in the working > directory) every n seconds in Python? Don't do it that way if you can help it. Use inotify or the equivalent instead. From stefan.sonnenberg at pythonmeister.com Thu Nov 25 08:20:35 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Thu, 25 Nov 2010 14:20:35 +0100 Subject: do something every n seconds In-Reply-To: <1a7afe44-b320-4135-9b9d-6b99b6c809b6@p38g2000vbn.googlegroups.com> References: <1a7afe44-b320-4135-9b9d-6b99b6c809b6@p38g2000vbn.googlegroups.com> Message-ID: <3b6743bee362727aeaed621874f54f01-EhVcX1lJRApWRxoDCzpQCEFddQZLVF5dQUBFCzBYWENGU1kWXlpwH1RcWzBeQ0wCWVNYQltQ-webmailer1@server05.webmailer.hosteurope.de> Windows or UNIX ? Am Do, 25.11.2010, 13:38 schrieb Santiago Caracol: > Hello, > > how can I do something (e.g. check if new files are in the working > directory) every n seconds in Python? > > Santiago > -- > http://mail.python.org/mailman/listinfo/python-list > > -- MfG, Stefan Sonnenberg-Carstens IT Architect From awilliam at whitemice.org Thu Nov 25 08:37:32 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Thu, 25 Nov 2010 08:37:32 -0500 Subject: do something every n seconds In-Reply-To: <1a7afe44-b320-4135-9b9d-6b99b6c809b6@p38g2000vbn.googlegroups.com> References: <1a7afe44-b320-4135-9b9d-6b99b6c809b6@p38g2000vbn.googlegroups.com> Message-ID: <1290692252.7849.0.camel@linux-yu4c.site> On Thu, 2010-11-25 at 04:38 -0800, Santiago Caracol wrote: > how can I do something (e.g. check if new files are in the working > directory) every n seconds in Python? Use the Python Advanced Scheduler in your application - it is a great little module. Then you've solved every 'scheduler' issue your application will ever have. -- Adam Tauno Williams LPIC-1, Novell CLA OpenGroupware, Cyrus IMAPd, Postfix, OpenLDAP, Samba From python at bdurham.com Thu Nov 25 09:21:16 2010 From: python at bdurham.com (python at bdurham.com) Date: Thu, 25 Nov 2010 09:21:16 -0500 Subject: a regexp riddle: re.search(r'(?:(\w+), |and (\w+))+', 'whatever a, bbb, and c') =? ('a', 'bbb', 'c') In-Reply-To: <00a69232-7703-48ce-8a42-b28f24946680@i32g2000pri.googlegroups.com> References: <00a69232-7703-48ce-8a42-b28f24946680@i32g2000pri.googlegroups.com> Message-ID: <1290694876.8561.1407151613@webmail.messagingengine.com> Phlip, > I'm trying to match "any word \w+ followed by a comma, or a final word preceded by and." Here's a non-regex solution that handles multi-word values and multiple instances of 'and' (as pointed out by Alice). The posted code could be simplified via list comprehension - I chose the more verbose method to illustrate the logic. def to_list( text ): text = text.replace( ' and ', ',' ) output = list() for item in text.split( ',' ): if item: output.append( item.strip() ) return output test = 'cat, dog, big fish, goat and puppy and horse' print to_list( test ) Outputs: ['cat', 'dog', 'big fish', 'goat', 'puppy', 'horse'] Malcolm From jeanmichel at sequans.com Thu Nov 25 09:40:49 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 25 Nov 2010 15:40:49 +0100 Subject: regexp matching end of line or comma Message-ID: <4CEE7571.2010401@sequans.com> Hy guys, I'm struggling matching patterns ending with a comma ',' or an end of line '$'. import re ex1 = 'sumthin,' ex2 = 'sumthin' m1 = re.match('(?P\S+),', ex1) m2 = re.match('(?P\S+)$', ex2) m3 = re.match('(?P\S+)[,$]', ex1) m4 = re.match('(?P\S+)[,$]', ex2) print m1, m2 print m3 print m4 <_sre.SRE_Match object at 0x8834de0> <_sre.SRE_Match object at 0x8834e20> <_sre.SRE_Match object at 0x8834e60> None My problem is that m4 is None while I'd like it to match ex2. Any clue ? JM From steve at holdenweb.com Thu Nov 25 09:54:36 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 25 Nov 2010 08:54:36 -0600 Subject: what a cheap rule In-Reply-To: <478343.25019.qm@web54204.mail.re2.yahoo.com> References: <478343.25019.qm@web54204.mail.re2.yahoo.com> Message-ID: On 11/25/2010 3:12 AM, Yingjie Lan wrote: > Sometimes the golden rule in Python of > "explicit is better than implicit" is > so cheap that it can be thrown away > for the trouble of typing an empty tuple. > I'm not sure that there *are* any golden rules. The "Zen of Python" is intended to be guidelines, not rigid rules intended to constrain your behavior but advice to help you write better code. > Today when I am explaining that in Python 3, > there are two ways to raise exceptions: > > raise Exception > > raise Exception() > > and that the first one is the same > as the second one, as Python will add the > missing pair of parenthesis. > In fact this is noting to do with Python 3 - the same is true of Python 2, so this isn't new: Python 2.6.5 (r265:79063, Jun 12 2010, 17:07:01) [GCC 4.3.4 20090804 (release) 1] on cygwin Type "help", "copyright", "credits" or "license" for more information. >>> raise KeyError Traceback (most recent call last): File "", line 1, in KeyError >>> raise KeyError("Here is the message") Traceback (most recent call last): File "", line 1, in KeyError: 'Here is the message' >>> > I felt their pain as they gasped. > Before that, I have already explained > to them this piece of code: > > try: raise SomeException() > except SomeException: > print('Got an exception here') > > by saying that the except-clause > will match anything > that belong to the SomeException class. > Or any of its subclasses ... > Without knowing this secrete > piece of information (that a > pair of parenthesis is automatically > provided), the following code > would be hard to understand: > > try: raise SomeException > except SomeException: > print('Got an exception here') > > because the class object SomeException > is not an instance of itself, so > a not-so-crooked coder will not > consider a match here. > It's a matter of understanding correctly how the interpreter operates (and the interactive interpreter session is the ideal place to investigate this). The 2.7 documentation for the raise statement says (and this is not new): """ If the first object is an instance, the type of the exception is the class of the instance, the instance itself is the value, and the second object must be None. If the first object is a class, it becomes the type of the exception. The second object is used to determine the exception value: If it is an instance of the class, the instance becomes the exception value. If the second object is a tuple, it is used as the argument list for the class constructor; if it is None, an empty argument list is used, and any other object is treated as a single argument to the constructor. The instance so created by calling the constructor is used as the exception value. """ So the interpreter doesn't really "automatically provide a pair of parentheses", but examines the exception object and instantiates it if it is a class. > So, the explicit is better than > implicit rule is thrown out of > the window so cheaply, > that it literally worth less > than an empty tuple! > Surely an exaggeration. In fact current best practice (which you should inform yourself of as best you can to help you in your teaching work - so you are to be congratulated for bringing this question to the list) is to always use explicit calls, with arguments specifying a tailored message. > Regards, > > Yingjie > > regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Thu Nov 25 10:00:59 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 25 Nov 2010 09:00:59 -0600 Subject: tilted text in the turtle module In-Reply-To: <709508.49315.qm@web54207.mail.re2.yahoo.com> References: <709508.49315.qm@web54207.mail.re2.yahoo.com> Message-ID: On 11/25/2010 5:06 AM, Yingjie Lan wrote: > First of all, I'd like to express my deep gratidute to the author of this module, it is such a fun module to work with and to teach python as a first programming language. > > Secondly, I would like to request a feature if it is not too hard to achieve. Currently, you can only write texts horizontally, no matter what is the current orientation of the turtle pen. I wonder if it is possible to write text in any direction when we control the heading of the turtle? For example, the following code would write a vertically oriented text: > > setheading(90) #turtle facing up > write("vertical text!") > > Thanks a lot! > Yingjie: This sounds like a good idea. To request a feature you should create an account (if you do not already have one) on bugs.python.org and create a new issue (assuming a search reveals that there is not already such an issue). You may find if you look at the module's code that you can imagine how to make the change. If not, the request will wait until some maintainer sees it and has time. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Thu Nov 25 10:05:49 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 25 Nov 2010 09:05:49 -0600 Subject: do something every n seconds In-Reply-To: <1a7afe44-b320-4135-9b9d-6b99b6c809b6@p38g2000vbn.googlegroups.com> References: <1a7afe44-b320-4135-9b9d-6b99b6c809b6@p38g2000vbn.googlegroups.com> Message-ID: On 11/25/2010 6:38 AM, Santiago Caracol wrote: > Hello, > > how can I do something (e.g. check if new files are in the working > directory) every n seconds in Python? > Look at the sched library, which was written to take care of requirements like this. Use time.sleep() as your delay function and time.time() as your time function. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Thu Nov 25 10:25:52 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 25 Nov 2010 09:25:52 -0600 Subject: a regexp riddle: re.search(r'(?:(\w+), |and (\w+))+', 'whatever a, bbb, and c') =? ('a', 'bbb', 'c') In-Reply-To: <00a69232-7703-48ce-8a42-b28f24946680@i32g2000pri.googlegroups.com> References: <00a69232-7703-48ce-8a42-b28f24946680@i32g2000pri.googlegroups.com> Message-ID: On 11/24/2010 10:46 PM, Phlip wrote: > HypoNt: > > I need to turn a human-readable list into a list(): > > print re.search(r'(?:(\w+), |and (\w+))+', 'whatever a, bbb, and > c').groups() > > That currently returns ('c',). I'm trying to match "any word \w+ > followed by a comma, or a final word preceded by and." > > The match returns 'a, bbb, and c', but the groups return ('bbb', 'c'). > What do I type for .groups() to also get the 'a'? > > Please go easy on me (and no RTFM!), because I have only been using > regular expressions for about 20 years... A kind of lazy way just uses a pattern for the separators to fuel a call to re.split(). I assume that " and " and " , " are both acceptable in any position: The best I've been able to do so far (due to split's annoying habit of including the matches of any groups in the pattern I have to throw away every second element) is: >>> re.split("\s*(,|and)?\s*", 'whatever a, bbb, and c')[::2] ['whatever', 'a', 'bbb', '', 'c'] That empty string is because of the ", and" which isn't recognise as a single delimiter. A parsing package might give you better results. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From python at mrabarnett.plus.com Thu Nov 25 10:54:55 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 25 Nov 2010 15:54:55 +0000 Subject: SQLite date fields In-Reply-To: <4CEDB1B5.4040008@baselinedata.co.uk> References: <4CEDB1B5.4040008@baselinedata.co.uk> Message-ID: <4CEE86CF.3010202@mrabarnett.plus.com> On 25/11/2010 00:45, Alan Harris-Reid wrote: > > Hi, > > I am having design problems with date storage/retrieval using Python and > SQLite. > > I understand that a SQLite date column stores dates as text in ISO > format (ie. '2010-05-25'). So when I display a British date (eg. on a > web-page) I convert the date using > datetime.datetime.strptime(mydate,'%Y-%m-%d').strftime('%d/%m/%Y'). > > However, when it comes to writing-back data to the table, SQLite is very > forgiving and is quite happy to store '25/06/2003' in a date field, but > this is not ideal because a) I could be left with a mixture of date > formats in the same column, b) SQLite's date functions only work with > ISO format. > Therefore I need to convert the date string back to ISO format before > committing, but then I would need a generic function which checks data > about to be written in all date fields and converts to ISO if necessary. > That sounds a bit tedious to me, but maybe it is inevitable. > > Are there simpler solutions? Would it be easier to change the date field > to a 10-character field and store 'dd/mm/yyyy' throughout the table? > This way no conversion is required when reading or writing from the > table, and I could use datetime() functions if I needed to perform any > date-arithmetic. > > How have other developers overcome this problem? Any help would be > appreciated. For the record, I am using SQLite3 with Python 3.1. > Even when storing a date as text, I always prefer to use ISO format because it makes sorting by date easier and there's less chance of confusion over UK vs US date format. From raffaelcavallaro at pas.despam.s.il.vous.plait.mac.com Thu Nov 25 10:56:09 2010 From: raffaelcavallaro at pas.despam.s.il.vous.plait.mac.com (Raffael Cavallaro) Date: Thu, 25 Nov 2010 10:56:09 -0500 Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014020136.6e85d70b@tritium.streitmacht.eu> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> <08823dd4-588a-4729-a660-711e266c96b0@y23g2000yqd.googlegroups.com> <396f8de7-ece5-4e9c-919b-886eb65ae14a@a30g2000vbt.googlegroups.com> <967678a1-fc5d-4b61-86c5-79a298999582@p1g2000vbo.googlegroups.com> <18cd9337-736b-427c-9cac-14c99056750a@p1g2000yqm.googlegroups.com> Message-ID: On 2010-11-24 16:19:49 -0500, toby said: > And furthermore, he has cooties. Once again, not all ad hominem arguments are ad hominem fallacies. Financial conflict of interest is a prime example of a perfectly valid ad hominem argument. People who parse patterns but not semantics are apt to fall into the error of believing that "ad hominem" automatically means "logically invalid." This is not the case. warmest regards, Ralph -- Raffael Cavallaro From sol2ray at gmail.com Thu Nov 25 11:02:49 2010 From: sol2ray at gmail.com (Sol Toure) Date: Thu, 25 Nov 2010 11:02:49 -0500 Subject: regexp matching end of line or comma In-Reply-To: <4CEE7571.2010401@sequans.com> References: <4CEE7571.2010401@sequans.com> Message-ID: Try this: '(?P\S+)(,|$)' On Thu, Nov 25, 2010 at 9:40 AM, Jean-Michel Pichavant < jeanmichel at sequans.com> wrote: > Hy guys, > > I'm struggling matching patterns ending with a comma ',' or an end of line > '$'. > > import re > > ex1 = 'sumthin,' > ex2 = 'sumthin' > m1 = re.match('(?P\S+),', ex1) > m2 = re.match('(?P\S+)$', ex2) > m3 = re.match('(?P\S+)[,$]', ex1) > m4 = re.match('(?P\S+)[,$]', ex2) > > print m1, m2 > print m3 > print m4 > > <_sre.SRE_Match object at 0x8834de0> <_sre.SRE_Match object at 0x8834e20> > <_sre.SRE_Match object at 0x8834e60> > None > > My problem is that m4 is None while I'd like it to match ex2. > > Any clue ? > > JM > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://www.afroblend.com African news as it happens. -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Thu Nov 25 11:06:45 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 25 Nov 2010 16:06:45 +0000 Subject: regexp matching end of line or comma In-Reply-To: <4CEE7571.2010401@sequans.com> References: <4CEE7571.2010401@sequans.com> Message-ID: <4CEE8995.9070305@mrabarnett.plus.com> On 25/11/2010 14:40, Jean-Michel Pichavant wrote: > Hy guys, > > I'm struggling matching patterns ending with a comma ',' or an end of > line '$'. > > import re > > ex1 = 'sumthin,' > ex2 = 'sumthin' > m1 = re.match('(?P\S+),', ex1) > m2 = re.match('(?P\S+)$', ex2) > m3 = re.match('(?P\S+)[,$]', ex1) > m4 = re.match('(?P\S+)[,$]', ex2) > > print m1, m2 > print m3 > print m4 > > <_sre.SRE_Match object at 0x8834de0> <_sre.SRE_Match object at 0x8834e20> > <_sre.SRE_Match object at 0x8834e60> > None > > My problem is that m4 is None while I'd like it to match ex2. > > Any clue ? > Within a character set '$' is a literal '$' and not end-of-string, just as '\b' is '\x08' and not word-boundary. Use a lookahead instead: >>> re.match('(?P\S+)(?=,|$)', ex1) <_sre.SRE_Match object at 0x01719FA0> >>> re.match('(?P\S+)(?=,|$)', ex2) <_sre.SRE_Match object at 0x016937E0> From namekuseijin at gmail.com Thu Nov 25 11:11:19 2010 From: namekuseijin at gmail.com (namekuseijin) Date: Thu, 25 Nov 2010 08:11:19 -0800 (PST) Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <9059b217-e3a4-4e82-a9a1-a84aafef942d@s9g2000vby.googlegroups.com> Message-ID: <518ff093-af28-4c09-b692-9e3b6e936ef7@i10g2000prd.googlegroups.com> On 25 nov, 09:23, Elena wrote: > On Oct 13, 9:09?pm, namekuseijin wrote: > > > > > > > On 11 out, 08:49, Oleg ?Parashchenko wrote: > > > > Hello, > > > > I'd like to try the idea that Scheme can be considered as a new > > > portable assembler. We could code something in Scheme and then compile > > > it to PHP or Python or Java or whatever. > > > > Any suggestions and pointers to existing and related work are welcome. > > > Thanks! > > > > My current approach is to take an existing Scheme implementation and > > > hijack into its backend. At this moment Scheme code is converted to > > > some representation with a minimal set of bytecodes, and it should be > > > quite easy to compile this representation to a target language. After > > > some research, the main candidates are Gambit, Chicken and CPSCM: > > > >http://uucode.com/blog/2010/09/28/r5rs-scheme-as-a-virtual-machine-i/... > > > > If there is an interest in this work, I could publish progress > > > reports. > > > > -- > > > Oleg Parashchenko ?olpa at http://uucode.com/http://uucode.com/blog/?XML, TeX, Python, Mac, Chess > > > it may be assembler, too bad scheme libs are scattered around written > > in far too many different flavors of assembler... > > > It warms my heart though to realize that Scheme's usual small size and > > footprint has allowed for many quality implementations targetting many > > different backends, be it x86 assembly, C, javascript or .NET. ?Take > > python and you have a slow c bytecode interpreter and a slow > > bytecode .NET compiler. ?Take haskell and its so friggin' huge and > > complex that its got its very own scary monolithic gcc. ?When you > > think of it, Scheme is the one true high-level language with many > > quality perfomant backends -- CL has a few scary compilers for native > > code, but not one to java, .NET or javascript that I know of... > > Take R5RS Scheme and you get a language which doesn't allow you to get > things done. > > Scheme is as far from Assembly as one language can be. ?Assembly > exists to get things done, R5RS Scheme does not even allows you load > native libraries of the underlying operating-system, does it? ?It's > easy to stay small and clean when you don't have to dirty your hands > with such crap as real-world applications development.- Ocultar texto das mensagens anteriores - assembly in the sense that it's what other languages could compile to. Like many are targetting javascript, the de facto assembly of the web... In any case, the original poster was advocating the opposite: to code in Scheme and compile it to more common backends, such as PHP or javascript... I misunderstood his point. But the flamewars that followed were far more entertaining anyway... :) From lanyjie at yahoo.com Thu Nov 25 11:15:21 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Thu, 25 Nov 2010 08:15:21 -0800 (PST) Subject: what a cheap rule In-Reply-To: Message-ID: <146414.53554.qm@web54206.mail.re2.yahoo.com> --- On Thu, 11/25/10, Steve Holden wrote: > > Sometimes the golden rule in Python of > > "explicit is better than implicit" is > > so cheap that it can be thrown away > > for the trouble of typing an empty tuple. > > > I'm not sure that there *are* any golden rules. The "Zen of > Python" is > intended to be guidelines, not rigid rules intended to > constrain your > behavior but advice to help you write better code. > > > Surely an exaggeration. In fact current best practice > (which you should > inform yourself of as best you can to help you in your > teaching work - > so you are to be congratulated for bringing this question > to the list) > is to always use explicit calls, with arguments specifying > a tailored > message. > > regards > Steve A very cogent message -- the end echos the start. :) I must say that I learned from you a new angle to think about this issue. On the other hand, I still feel that when allowing both ways colliding into the simpleness and bueaty of the language, we should consider to make a decision. Sure, this introduced quite a lot of complexity when the doc has to give a very long explanation of what is happening in order to justify it. As I am thinking about it, it seems two conflicting intuition of code comprehension are at work here: Intuition #1: as if you raise an exception type, and then match that type. It seems that no instances are involved here (Intuitively). See an example code here: try: raise KeyError except KeyError: pass Intuition #2: you raise an exception instance, and then match an instance by its type. See an example code here: try: raise KeyError() except KeyError as ke: pass Those two comprehensions are not compatible, and thus the one that promotes correct understanding should be encouraged, while the other should be discouraged, and maybe even be made iliegal. Regards, Yingjie From python at mrabarnett.plus.com Thu Nov 25 11:16:15 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 25 Nov 2010 16:16:15 +0000 Subject: a regexp riddle: re.search(r'(?:(\w+), |and (\w+))+', 'whatever a, bbb, and c') =? ('a', 'bbb', 'c') In-Reply-To: <00a69232-7703-48ce-8a42-b28f24946680@i32g2000pri.googlegroups.com> References: <00a69232-7703-48ce-8a42-b28f24946680@i32g2000pri.googlegroups.com> Message-ID: <4CEE8BCF.6030103@mrabarnett.plus.com> On 25/11/2010 04:46, Phlip wrote: > HypoNt: > > I need to turn a human-readable list into a list(): > > print re.search(r'(?:(\w+), |and (\w+))+', 'whatever a, bbb, and > c').groups() > > That currently returns ('c',). I'm trying to match "any word \w+ > followed by a comma, or a final word preceded by and." > > The match returns 'a, bbb, and c', but the groups return ('bbb', 'c'). > What do I type for .groups() to also get the 'a'? > > Please go easy on me (and no RTFM!), because I have only been using > regular expressions for about 20 years... > Try re.findall: >>> re.findall(r'(\w+), |and (\w+)', 'whatever a, bbb, and c') [('a', ''), ('bbb', ''), ('', 'c')] You can get a list of strings like this: >>> [x or y for x, y in re.findall(r'(\w+), |and (\w+)', 'whatever a, bbb, and c')] ['a', 'bbb', 'c'] From jeanmichel at sequans.com Thu Nov 25 11:26:34 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 25 Nov 2010 17:26:34 +0100 Subject: regexp matching end of line or comma In-Reply-To: <4CEE8995.9070305@mrabarnett.plus.com> References: <4CEE7571.2010401@sequans.com> <4CEE8995.9070305@mrabarnett.plus.com> Message-ID: <4CEE8E3A.3040707@sequans.com> MRAB wrote: > On 25/11/2010 14:40, Jean-Michel Pichavant wrote: >> Hy guys, >> >> I'm struggling matching patterns ending with a comma ',' or an end of >> line '$'. >> >> import re >> >> ex1 = 'sumthin,' >> ex2 = 'sumthin' >> m1 = re.match('(?P\S+),', ex1) >> m2 = re.match('(?P\S+)$', ex2) >> m3 = re.match('(?P\S+)[,$]', ex1) >> m4 = re.match('(?P\S+)[,$]', ex2) >> >> print m1, m2 >> print m3 >> print m4 >> >> <_sre.SRE_Match object at 0x8834de0> <_sre.SRE_Match object at >> 0x8834e20> >> <_sre.SRE_Match object at 0x8834e60> >> None >> >> My problem is that m4 is None while I'd like it to match ex2. >> >> Any clue ? >> > Within a character set '$' is a literal '$' and not end-of-string, just > as '\b' is '\x08' and not word-boundary. > > Use a lookahead instead: > > >>> re.match('(?P\S+)(?=,|$)', ex1) > <_sre.SRE_Match object at 0x01719FA0> > >>> re.match('(?P\S+)(?=,|$)', ex2) > <_sre.SRE_Match object at 0x016937E0> thanks, it works that way. By the way I don't get the difference between non capturing parentesis (?:) and lookahead parenthesis (?=): re.match('(?P\S+)(?:,|$)', ex2).groups() ('sumthin',) re.match('(?P\S+)(?=,|$)', ex2).groups() ('sumthin',) JM From python at mrabarnett.plus.com Thu Nov 25 11:30:12 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 25 Nov 2010 16:30:12 +0000 Subject: the buggy regex in Python In-Reply-To: <297677.64235.qm@web54207.mail.re2.yahoo.com> References: <297677.64235.qm@web54207.mail.re2.yahoo.com> Message-ID: <4CEE8F14.4030704@mrabarnett.plus.com> On 25/11/2010 11:32, Yingjie Lan wrote: > I know many experts will say I don't have understanding...but let me pay this up front as my tuition. > > Here are some puzzling results I have got (I am using Python 3, I suppose similar results for python 2). > > When I do the following, I got an exception: >>>> re.findall('(d*)*', 'adb') >>>> re.findall('((d)*)*', 'adb') > A repeated repeat can cause problems if what is repeated can match an empty string. The "re" module tries to protect itself by forbidding such a regex. The "regex" module (available from PyPI) accepts that regex and returns a result. > When I do this, I am fine but the result is wrong: >>>> re.findall('((.d.)*)*', 'adb') > [('', 'adb'), ('', '')] > > Why is it wrong? > > The first mactch of groups: > ('', 'adb') > indicates the outer group ((.d.)*) captured > the empty string, while the inner group (.d.) > captured 'adb', so the outer group must have > captured the empty string at the end of the > provided string 'adb'. > > Once we have matched the final empty string '', > there should be no more matches, but we got > another match ('', '')!!! > > So, findall matched the empty string in > the end of the string twice!!! > re.findall performs multiple searches, each starting where the previous one finished. The first match started at the start of the string and finished at its end. The second match started at that point (the end of the string) and found another match, ending at the end of the string. It tried to match a third time, but that failed because it would have matched an empty string again (it's not allowed to return 2 contiguous empty strings). > Isn't this a bug? > No, but it can be confusing at times! :-) From m_mommer at yahoo.com Thu Nov 25 11:30:12 2010 From: m_mommer at yahoo.com (Mario S. Mommer) Date: Thu, 25 Nov 2010 17:30:12 +0100 Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014020136.6e85d70b@tritium.streitmacht.eu> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> <08823dd4-588a-4729-a660-711e266c96b0@y23g2000yqd.googlegroups.com> <396f8de7-ece5-4e9c-919b-886eb65ae14a@a30g2000vbt.googlegroups.com> <967678a1-fc5d-4b61-86c5-79a298999582@p1g2000vbo.googlegroups.com> <18cd9337-736b-427c-9cac-14c99056750a@p1g2000yqm.googlegroups.com> Message-ID: <87vd3l8iy3.fsf@padme.localdomain> Raffael Cavallaro writes: > On 2010-11-24 16:19:49 -0500, toby said: > >> And furthermore, he has cooties. > > Once again, not all ad hominem arguments are ad hominem > fallacies. Financial conflict of interest is a prime example of a > perfectly valid ad hominem argument. It has limited validity. People are way more complicated than the simplistic "follow your own selfish egoistic interests to the letter without taking prisoners" model of human behavior that seems (unfortunately) so prevalent nowadays. > People who parse patterns but not semantics are apt to fall into the > error of believing that "ad hominem" automatically means "logically > invalid." This is not the case. In the realm of pure logic, ad hominems are logically invalid, period. However, if the question cannot be resolved by its own merits, simple logic has little to say, and you may include additional information in a sort-of Bayesian fashion. Saying that a conflict of interest means that nothing this person says makes any sense at all is in a way an admission that the subject of discussion is not very amenable to rational argument. From lanyjie at yahoo.com Thu Nov 25 11:44:51 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Thu, 25 Nov 2010 08:44:51 -0800 (PST) Subject: the buggy regex in Python In-Reply-To: <4CEE8F14.4030704@mrabarnett.plus.com> Message-ID: <120830.69127.qm@web54206.mail.re2.yahoo.com> --- On Thu, 11/25/10, MRAB wrote: > re.findall performs multiple searches, each starting where > the previous > one finished. The first match started at the start of the > string and > finished at its end. The second match started at that point > (the end of > the string) and found another match, ending at the end of > the string. > It tried to match a third time, but that failed because it > would have > matched an empty string again (it's not allowed to return 2 > contiguous > empty strings). > > > Isn't this a bug? > > > No, but it can be confusing at times! :-) > -- But the last empty string is matched twice -- so it is an overlapping. But findall is supposed not to return overlapping matches. So I think this does not live up to the documentation -- thus I still consider it a bug. Yingjie From lanyjie at yahoo.com Thu Nov 25 11:49:53 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Thu, 25 Nov 2010 08:49:53 -0800 (PST) Subject: tilted text in the turtle module In-Reply-To: Message-ID: <933894.81836.qm@web54207.mail.re2.yahoo.com> --- On Thu, 11/25/10, Steve Holden wrote: > From: Steve Holden > Subject: Re: tilted text in the turtle module > To: python-list at python.org > Date: Thursday, November 25, 2010, 7:00 PM > On 11/25/2010 5:06 AM, Yingjie Lan > wrote: > This sounds like a good idea. To request a feature you > should create an > account (if you do not already have one) on bugs.python.org > and create a > new issue (assuming a search reveals that there is not > already such an > issue). > Thanks I just did that. > You may find if you look at the module's code that you can > imagine how > to? make the change. If not, the request will wait > until some maintainer > sees it and has time. > I don't know much about tkinter, not sure if I can contribute. And even if I made a patch, then how to publish it? Regards, Yingjie From python at mrabarnett.plus.com Thu Nov 25 12:07:53 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 25 Nov 2010 17:07:53 +0000 Subject: regexp matching end of line or comma In-Reply-To: <4CEE8E3A.3040707@sequans.com> References: <4CEE7571.2010401@sequans.com> <4CEE8995.9070305@mrabarnett.plus.com> <4CEE8E3A.3040707@sequans.com> Message-ID: <4CEE97E9.5020508@mrabarnett.plus.com> On 25/11/2010 16:26, Jean-Michel Pichavant wrote: > MRAB wrote: >> On 25/11/2010 14:40, Jean-Michel Pichavant wrote: >>> Hy guys, >>> >>> I'm struggling matching patterns ending with a comma ',' or an end of >>> line '$'. >>> >>> import re >>> >>> ex1 = 'sumthin,' >>> ex2 = 'sumthin' >>> m1 = re.match('(?P\S+),', ex1) >>> m2 = re.match('(?P\S+)$', ex2) >>> m3 = re.match('(?P\S+)[,$]', ex1) >>> m4 = re.match('(?P\S+)[,$]', ex2) >>> >>> print m1, m2 >>> print m3 >>> print m4 >>> >>> <_sre.SRE_Match object at 0x8834de0> <_sre.SRE_Match object at >>> 0x8834e20> >>> <_sre.SRE_Match object at 0x8834e60> >>> None >>> >>> My problem is that m4 is None while I'd like it to match ex2. >>> >>> Any clue ? >>> >> Within a character set '$' is a literal '$' and not end-of-string, just >> as '\b' is '\x08' and not word-boundary. >> >> Use a lookahead instead: >> >> >>> re.match('(?P\S+)(?=,|$)', ex1) >> <_sre.SRE_Match object at 0x01719FA0> >> >>> re.match('(?P\S+)(?=,|$)', ex2) >> <_sre.SRE_Match object at 0x016937E0> > thanks, it works that way. > By the way I don't get the difference between non capturing parentesis > (?:) and lookahead parenthesis (?=): > > re.match('(?P\S+)(?:,|$)', ex2).groups() > ('sumthin',) > > re.match('(?P\S+)(?=,|$)', ex2).groups() > ('sumthin',) > A non-capturing parenthesis 'consumes' characters; a lookahead parenthesis doesn't, so another part of the regex can match it again. I suppose that in this instance it doesn't matter! From python at mrabarnett.plus.com Thu Nov 25 12:18:24 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 25 Nov 2010 17:18:24 +0000 Subject: the buggy regex in Python In-Reply-To: <120830.69127.qm@web54206.mail.re2.yahoo.com> References: <120830.69127.qm@web54206.mail.re2.yahoo.com> Message-ID: <4CEE9A60.1030807@mrabarnett.plus.com> On 25/11/2010 16:44, Yingjie Lan wrote: > --- On Thu, 11/25/10, MRAB wrote: >> re.findall performs multiple searches, each starting where >> the previous >> one finished. The first match started at the start of the >> string and >> finished at its end. The second match started at that point >> (the end of >> the string) and found another match, ending at the end of >> the string. >> It tried to match a third time, but that failed because it >> would have >> matched an empty string again (it's not allowed to return 2 >> contiguous >> empty strings). >> >>> Isn't this a bug? >>> >> No, but it can be confusing at times! :-) >> -- > > But the last empty string is matched twice -- so it is > an overlapping. But findall is supposed not to return > overlapping matches. So I think this does not live up > to the documentation -- thus I still consider it a bug. > Look at the spans: >>> for m in re.finditer('((.d.)*)*', 'adb'): print(m.span()) (0, 3) (3, 3) There's an non-empty match followed by an empty match. From steve at holdenweb.com Thu Nov 25 13:04:09 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 25 Nov 2010 12:04:09 -0600 Subject: what a cheap rule In-Reply-To: <146414.53554.qm@web54206.mail.re2.yahoo.com> References: <146414.53554.qm@web54206.mail.re2.yahoo.com> Message-ID: On 11/25/2010 10:15 AM, Yingjie Lan wrote: > As I am thinking about it, it seems two > conflicting intuition of code comprehension > are at work here: > > Intuition #1: as if you raise an exception > type, and then match that type. > It seems that no instances > are involved here (Intuitively). > See an example code here: > > try: raise KeyError > except KeyError: pass > > > Intuition #2: you raise an exception > instance, and then match an instance by > its type. See an example code here: > > try: raise KeyError() > except KeyError as ke: pass > > Those two comprehensions are not compatible, > and thus the one that promotes correct > understanding should be encouraged, > while the other should be discouraged, > and maybe even be made iliegal. I prefer to treat those two cases as unified, by observing that if what is raised in an exception class than an instance is created by calling it with no arguments. So matching is always by the instance's type - it's just that the instance creation can be implicit. I agree with you that explicit is better. Most of the syntactic variation you dislike is to allow existing code to continue to work. Some of it is removed in Python 3, when backwards compatibility could be ignored. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From srikrishnamohan at gmail.com Thu Nov 25 13:06:32 2010 From: srikrishnamohan at gmail.com (km) Date: Thu, 25 Nov 2010 23:36:32 +0530 Subject: do something every n seconds In-Reply-To: References: <1a7afe44-b320-4135-9b9d-6b99b6c809b6@p38g2000vbn.googlegroups.com> Message-ID: while True: time.sleep(10) print('hello python!') HTH, KM On Thu, Nov 25, 2010 at 8:35 PM, Steve Holden wrote: > On 11/25/2010 6:38 AM, Santiago Caracol wrote >> Hello, >> >> how can I do something (e.g. check if new files are in the working >> directory) every n seconds in Python? >> > Look at the sched library, which was written to take care of > requirements like this. Use time.sleep() as your delay function and > time.time() as your time function. > > regards > ?Steve > -- > Steve Holden ? ? ? ? ? +1 571 484 6266 ? +1 800 494 3119 > PyCon 2011 Atlanta March 9-17 ? ? ? http://us.pycon.org/ > See Python Video! ? ? ? http://python.mirocommunity.org/ > Holden Web LLC ? ? ? ? ? ? ? ? http://www.holdenweb.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > From steve at holdenweb.com Thu Nov 25 13:10:26 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 25 Nov 2010 12:10:26 -0600 Subject: tilted text in the turtle module In-Reply-To: <933894.81836.qm@web54207.mail.re2.yahoo.com> References: <933894.81836.qm@web54207.mail.re2.yahoo.com> Message-ID: On 11/25/2010 10:49 AM, Yingjie Lan wrote: > --- On Thu, 11/25/10, Steve Holden wrote: >> From: Steve Holden >> Subject: Re: tilted text in the turtle module >> To: python-list at python.org >> Date: Thursday, November 25, 2010, 7:00 PM >> On 11/25/2010 5:06 AM, Yingjie Lan >> wrote: >> This sounds like a good idea. To request a feature you >> should create an >> account (if you do not already have one) on bugs.python.org >> and create a >> new issue (assuming a search reveals that there is not >> already such an >> issue). >> > > Thanks I just did that. > >> You may find if you look at the module's code that you can >> imagine how >> to make the change. If not, the request will wait >> until some maintainer >> sees it and has time. >> > > I don't know much about tkinter, > not sure if I can contribute. > And even if I made a patch, > then how to publish it? > Once you have a patch, attach it to the issue as a file and try and get it reviewed by a developer for incorporation into a future release. Note that no Python 2.8 release is planned, so you would best concentrate your effort on the 3.x series. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From saul.spatz at gmail.com Thu Nov 25 13:32:17 2010 From: saul.spatz at gmail.com (Saul Spatz) Date: Thu, 25 Nov 2010 10:32:17 -0800 (PST) Subject: regexp matching end of line or comma References: Message-ID: <9293d6eb-7ea8-447f-999a-97d0a190a275@k30g2000vbn.googlegroups.com> On Nov 25, 8:40?am, Jean-Michel Pichavant wrote: > Hy guys, > > I'm struggling matching patterns ending with a comma ',' or an end of > line '$'. > > import re > > ex1 = 'sumthin,' > ex2 = 'sumthin' > m1 = re.match('(?P\S+),', ex1) > m2 = re.match('(?P\S+)$', ex2) > m3 = re.match('(?P\S+)[,$]', ex1) > m4 = re.match('(?P\S+)[,$]', ex2) > > print m1, m2 > print m3 > print m4 > > <_sre.SRE_Match object at 0x8834de0> <_sre.SRE_Match object at 0x8834e20> > <_sre.SRE_Match object at 0x8834e60> > None > > My problem is that m4 is None while I'd like it to match ex2. > > Any clue ? > > JM >From the Regular Expression Syntax documentation: Special characters are not active inside sets. For example, [akm$] will match any of the characters 'a', 'k', 'm', or '$'; so in m4, [,$] matches a comma or a literal dollar sign. From cmpython at gmail.com Thu Nov 25 13:35:12 2010 From: cmpython at gmail.com (CM) Date: Thu, 25 Nov 2010 10:35:12 -0800 (PST) Subject: SQLite date fields References: Message-ID: > However, when it comes to writing-back data to the table, SQLite is very > forgiving and is quite happy to store '25/06/2003' in a date field, but > this is not ideal because a) I could be left with a mixture of date > formats in the same column, ?b) SQLite's date functions only work with > ISO format. > Therefore I need to convert the date string back to ISO format before > committing, but then I would need a generic function which checks data > about to be written in all date fields and converts to ISO if > necessary. ?That sounds a bit tedious to me, but maybe it is inevitable. It doesn't strike me as particularly tedious if it is just the line: datetime.datetime.strptime(mydate,'%Y-%m-%d').strftime('%d/%m/%Y') > Are there simpler solutions? ?Would it be easier to change the date > field to a 10-character field and store 'dd/mm/yyyy' throughout the > table? ?This way no conversion is required when reading or writing from > the table, and I could use datetime() functions if I needed to perform > any date-arithmetic. Maybe I've misunderstood, but wouldn't you have to do the conversion to display the date anyway? It seems to me like, whichever approach you take, you will have to do a conversion. For that reason, isn't it better to leave the date fields in ISO so that you can take advantage of SQLite's date functions? Che > > How have other developers overcome this problem? ?Any help would be > appreciated. ?For the record, I am using SQLite3 with Python 3.1. > > Alan From namekuseijin at gmail.com Thu Nov 25 13:39:24 2010 From: namekuseijin at gmail.com (namekuseijin) Date: Thu, 25 Nov 2010 10:39:24 -0800 (PST) Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> <08823dd4-588a-4729-a660-711e266c96b0@y23g2000yqd.googlegroups.com> <396f8de7-ece5-4e9c-919b-886eb65ae14a@a30g2000vbt.googlegroups.com> <967678a1-fc5d-4b61-86c5-79a298999582@p1g2000vbo.googlegroups.com> <18cd9337-736b-427c-9cac-14c99056750a@p1g2000yqm.googlegroups.com> <87vd3l8iy3.fsf@padme.localdomain> Message-ID: On 25 nov, 14:30, m_mom... at yahoo.com (Mario S. Mommer) wrote: > Raffael Cavallaro > writes: > > > On 2010-11-24 16:19:49 -0500, toby said: > > >> And furthermore, he has cooties. > > > Once again, not all ad hominem arguments are ad hominem > > fallacies. Financial conflict of interest is a prime example of a > > perfectly valid ad hominem argument. > > It has limited validity. People are way more complicated than the > simplistic "follow your own selfish egoistic interests to the letter > without taking prisoners" model of human behavior that seems > (unfortunately) so prevalent nowadays. > > > People who parse patterns but not semantics are apt to fall into the > > error of believing that "ad hominem" automatically means "logically > > invalid." This is not the case. > > In the realm of pure logic, ad hominems are logically invalid, > period. However, if the question cannot be resolved by its own merits, > simple logic has little to say, and you may include additional > information in a sort-of Bayesian fashion. > > Saying that a conflict of interest means that nothing this person says > makes any sense at all is in a way an admission that the subject of > discussion is not very amenable to rational argument. I have to say I'm always amazed how ad hominens can generate quite strong responses to the point of making a lot of new faces (or mail accounts) suddenly appear... ;) From moura.mario at gmail.com Thu Nov 25 13:53:40 2010 From: moura.mario at gmail.com (macm) Date: Thu, 25 Nov 2010 10:53:40 -0800 (PST) Subject: Automatic Distutils generator Message-ID: Hi Folks I am trying run Distutils setup inside a script. The Docs dont tell me much and I cant find any examples. This script will generate shared libraries recursive to all files in a dir. ----------------------------- import os import sys from distutils.core import setup as d from distutils.extension import Extension from Cython.Distutils import build_ext fileList = [] rootdir = sys.argv[1] fileType = '.pyx' for root, subFolders, files in os.walk(rootdir): for file in files: if file[-4:] == fileType: fileList.append(os.path.join(root,file)) # But Here I want automatic Distutils generator # I want replace manual entry like this: # python setup.py build_ext --inplace d.setup(name = str(file) + '_Cython', ext_modules=[ Extension(file[:-4], [file]) ], cmdclass = {'build_ext': build_ext}) d.run_setup() print 'Files convert: \n' print fileList ---------------------------- Who can help me fix it? Best Regards Mario From phlip2005 at gmail.com Thu Nov 25 14:57:33 2010 From: phlip2005 at gmail.com (Phlip) Date: Thu, 25 Nov 2010 11:57:33 -0800 (PST) Subject: a regexp riddle: re.search(r'(?:(\w+), |and (\w+))+', 'whatever a, bbb, and c') =? ('a', 'bbb', 'c') References: <00a69232-7703-48ce-8a42-b28f24946680@i32g2000pri.googlegroups.com> Message-ID: > Accepting input from a human is fraught with dangers and edge cases. > Here's a non-regex solution Thanks all for playing! And as usual I forgot a critical detail: I'm writing a matcher for a Morelia /viridis/ Scenario step, so the matcher must be a single regexp. http://c2.com/cgi/wiki?MoreliaViridis I'm avoiding the current situation, where Morelia pulls out (.*), and the step handler "manually" splits that up with: flags = re.split(r', (?:and )?', flags) That means I already had a brute-force version. A regexp version is always better because, especially in Morelia, it validates input. (.*) is less specific than (\w+). So if the step says: Alice has crypto keys apple, barley, and flax Then the step handler could say (if this worked): def step_user_has_crypto_keys_(self, user, *keys): r'(\w+) has crypto keys (?:(\w+), )+and (\w+)' # assert that user with those keys here That does not work because "a capturing group only remembers the last match". This would appear to be an irritating 'feature' in Regexp. The total match is 'apple, barley, and flax', but the stored groups behave as if each () were a slot, so (\w+)+ would not store "more than one group". Unless there's a Regexp workaround to mean "arbitrary number of slots for each ()", then I /might/ go with this: got = re.findall(r'(?:(\w+), )?(?:(\w+), )?(?:(\w+), )?(?:(\w+), )? (?:(\w+), and )?(\w+)$', 'whatever a, bbb, and c') print got # [('a', '', '', '', 'bbb', 'c')] The trick is to simply paste in a high number of (?:(\w+), )? segments, assuming that nobody should plug in too many. Behavior Driven Development scenarios should be readable and not run-on. (Morelia has a table feature for when you actually need lots of arguments.) Next question: Does re.search() return a match object that I can get ('a', '', '', '', 'bbb', 'c') out of? The calls to groups() and such always return this crazy ('a', 2, 'bbb', 'c') thing that would disturb my user-programmers. -- Phlip From joralemonshelly at gmail.com Thu Nov 25 15:18:33 2010 From: joralemonshelly at gmail.com (Shel) Date: Thu, 25 Nov 2010 12:18:33 -0800 (PST) Subject: building a web interface References: <2010112500364975026-alice@gothcandycom> Message-ID: <487ba202-034e-4ebf-aed7-e248413bd90f@c17g2000prm.googlegroups.com> Will take a look after stuffing myself with turkey today (am in the US, where we give thanks by eating everything in sight). Thanks, Alice. Wait, did I just say "thanks"? Must go eat pie. On Nov 25, 12:36?am, Alice Bevan?McGregor wrote: > Howdy! > > I'm mildly biased, being the author of the framework, but I can highly > recommend WebCore for rapid prototyping of web applications; it has > templating via numerous template engines, excellent JSON (AJAJ) > support, and support for database back-ends via SQLAlchemy. ?It also > has session support baked-in via a project called Beaker. ? > Documentation is fairly complete, and I can be found camping in the > #webcore IRC channel on irc.freenode.net at strange hours. > > If you can write a class, you can have a fully operational web > application in a single file of ~8 lines or so. ?(Or you can create a > complete easy-installable Python package with multiple modules.) > > For information, see:http://www.web-core.org/ > > As an interactive-fiction example: > > class RootController(web.core.Controller): > ? ? def index(self): > ? ? ? ? """This returns a template that uses JavaScript to call execute(). > ? ? ? ? The JavaScript adds the result of execute() to the display.""" > ? ? ? ? session = db.Session().save() > ? ? ? ? return './templates/main.html', dict(session=session.id) > > ? ? def execute(self, session, statement): > ? ? ? ? """Load our session and pass the input off to our interactive > ? ? ? ? fiction library of choice. ?Return the result if all went well.""" > ? ? ? ? session = db.Session.get(session) > > ? ? ? ? try: > ? ? ? ? ? ? result = myiflib.execute(session, statement) > > ? ? ? ? except myiflib.ParseError: > ? ? ? ? ? ? return 'json:', dict(status="failure", message="Error...") > > ? ? ? ? return 'json:', dict(status="success", message=result) > > ?? Alice. From python at mrabarnett.plus.com Thu Nov 25 15:45:02 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 25 Nov 2010 20:45:02 +0000 Subject: a regexp riddle: re.search(r'(?:(\w+), |and (\w+))+', 'whatever a, bbb, and c') =? ('a', 'bbb', 'c') In-Reply-To: References: <00a69232-7703-48ce-8a42-b28f24946680@i32g2000pri.googlegroups.com> Message-ID: <4CEECACE.3000903@mrabarnett.plus.com> On 25/11/2010 19:57, Phlip wrote: >> Accepting input from a human is fraught with dangers and edge cases. > >> Here's a non-regex solution > > Thanks all for playing! And as usual I forgot a critical detail: > > I'm writing a matcher for a Morelia /viridis/ Scenario step, so the > matcher must be a single regexp. > > http://c2.com/cgi/wiki?MoreliaViridis > > I'm avoiding the current situation, where Morelia pulls out (.*), and > the step handler "manually" splits that up with: > > flags = re.split(r', (?:and )?', flags) > > That means I already had a brute-force version. A regexp version is > always better because, especially in Morelia, it validates input. (.*) > is less specific than (\w+). > > So if the step says: > > Alice has crypto keys apple, barley, and flax > > Then the step handler could say (if this worked): > > def step_user_has_crypto_keys_(self, user, *keys): > r'(\w+) has crypto keys (?:(\w+), )+and (\w+)' > > # assert that user with those keys here > [snip] You could do: def step_user_has_crypto_keys_(self, user, keys): r'(\w+) has crypto keys ((?:\w+, )+and \w+)' to validate and capture, and then split the keys string. From smallpox911 at gmail.com Thu Nov 25 15:56:47 2010 From: smallpox911 at gmail.com (small Pox) Date: Thu, 25 Nov 2010 12:56:47 -0800 (PST) Subject: a story of a top expert of Mathematica: Robby Villegas References: <67344004-75e9-478b-af99-e8188f799848@z9g2000pri.googlegroups.com> Message-ID: On Nov 25, 2:10?am, Xah Lee wrote: > On Nov 24, 2:02?pm, Xah Lee wrote: > > > just learned that one of my best friend, one of world's top expert of > > the Mathematica language, died, last month. > > > ? ?Robby Villegas Died (1968-2010)?http://xahlee.org/math/Robby_Villegas.html > > so, apparantly, he killed himself. > > not lisp related, but i thought it is interetsing to many here, > becuase Robby is very interested in computer languages, and share with > many of us being ubberly socially inept and frustrated. (he's not a > emacs users. Occationally uses vi. I think he's main editor is NEdit > (if he hasn't changed since 1990s). Yes he's a linux user. Became a > Redhat linux user as his main machine in late 1990s. You could find > many of his writings in comp.soft-sys.math.mathematica, but i believ > they all dates in the mid 1990s. He's a extremely keep-to-himself > guy.) He's also the first computer programer that i got to know in > real meat space, who hates Windows and Microsoft. > > ----------------------------------------------- > Robby's Goodbye Notes > > Apparantly, Robby killed himself. There's this memorial page posted by > Robby's friends on his site at: Source. Reading it, i came across > several Wolfram employees i remember having met, some i recognize as > Robby's good friends. In it, there's this post, apparantly Robby's > goodbye note. > > ? ? Robby via Christina Szabo Says: > ? ? October 7th, 2010 at 9:54 pm > > ? ? Robby wanted to ?give some explanation to people in general? and > asked > ? ? me to post this, which he wrote. -Christina > > ? ? Subject: the end is important in all things > > ? ? Robby Villegas October 2 at 7:17am > > ? ? Depression, and even more so, physical exhaustion, continues to > claim more and more of my life, to render a larger percentage of each > day either unusable, or a sloggin, dragging fight to keep myself > upright just to get through the basics of my day. On top of fatigue, a > few years ago I began to develop a tendency toward anxiety, which > gradually became more frequent and of faster onset, throwing a specter > of borderline panic attacks over many of my activities. Eventually, I > was taking partial doses of my prescription sleep medication > *preemptively* before simple activities like skating class, meeting > friends at a bar, going to a theater, or spending an evening studying > at a cafe. > > ? ? The sleep and exhaustion problems that forced me to suddenly quit > working in January 2007 have gradually worsened, and I have run out of > means at this point. > > ? ? More important than financial means, though: the ratio of quality > of life to pained struggling has passed a threshold. Eventually, I?ll > forget what it even felt like to be happy, the memories of what I was > will fade further, I won?t be able to appreciate any of the good parts > of life, and I?ll be bitter, not even a shadow of my self. > > ? ? This must not happen. For many years, I have felt that some day > I?d have to make that call that it?s time to go; that most of the good > stuff was past, and the proportion of hope and new joy to the pain and > effort that goes into rallying would fall too low I want to go out > while I can still reflect on the good things, and go out really > feeling and believing ?I lived.? > > ? ? Worse than the death of the body is the death of pieces of the > self while still alive, and the memories that provide conviction that > there was a lot worth being here for, while it lasted. > > ? ? In retrospect, I probably should have made this call last winter, > or at the very latest, early summer, given that the last few months > have had a marked dulling effect on me. But, two decades of fighting > depression, rallying through many dozens of life-hating and self- > hating episodes ranging from bad patches to truly close calls, and > being thankful I did each time I got a ?new lease on life? that was > followed by more of the worthwhile stuff of life ? two decades of that > makes it *intensely* difficult to make that final call. > > ? ? Albeit more weary and dull than I?ve ever been, I am thankful that > there?s enough left of me to look back (even with difficulty) and > appreciate all the good people, activities, and interests that made My > Life worth living during that time. So it is perhaps not too late to > exit while there?s a reasonable amount left of Me. > > ? ? Yours in truth, > ? ? Robby ?R. Scott? > > Not sure what to say. > > Robby has told me in around 2004 to 2005, our last big exchange, that > he has serious insomnia problems. But i don't recall any serious > depression. Actually, i remember now he has told me that he had > depression episodes, which i did too, and we chatted our experiences. > But i recall it's all past tense, and this chat was in 1995. > (depression is hard to define) But i didn't know it was getting to the > point of killing himself, but again, for certain type of persons who > are not emotionally responsive (i.e. cold, lone, type, who hide their > emotions or unable to express it), it could happen on any seemingly > good day. Robby is extremely sensitive to stress and pressure. He's > the type of nice guy who find it hard to say no, and when he actually > had to, it's after huge mental struggle. > > So i guess, for a personality as lone as me and Robby, i can't say i > feel particular regret or inappropriateness on Robby's act of killing > himself. He didn't feel worthwhile to live on, so he had to go. I > certainly wished things could be different, and wished that we'd have > communicated about his situation. I believe, if i told him of my > personal situation, he'd feel better. We certainly would have great > conversations about the pros and cons on methods of suicide, in fact i > believe we had such a conversation before. I missed a friend, who is > one of the greatest unsung expert of Mathematica, of which, i could > certainly use some help, and as a alley in the war on computer > languages. > > In the future, i'll dig up some of Robby's emails and post here. > > The world has 6.5 billions of people. Due to the incredible advances > of communication tech, especially the internet, we the masses get to > see all sort of weirdos and behaviors directly. (e.g. shown in shock > sites, 4chan, etc.) And, in the past 5 years, we greatly see many > suicides (on facebook et al), and in many cases, literally watched > thru online video someone killing himself. > > Am not sure where am going with this, but i guess let's open even more > communication. Legalize suicide. Stop censorship of all sorts except > things like how to make nuclear bomb. We don't like pain, and we don't > want to see our friends to choose to end their life. But we don't want > whatever problems that leads to that path. Hiding and banning is not > going to help. More open info, more communication, we can have more > understanding of us the human animals, and more happiness with us and > our friends. Maybe Robby had biologically rooted psychogical problems. > But am sure, whatever his suffering of depression, can be helped > better if whatever caused his stress, socially induced self-loathing, > closet inhibitions (such as gay people), parental or family problems, > can be reduced. Tolerate, and appreciate, your friends, co-workers, or > strangers, while they are alive. > > It's kinda sad that many of my math friends, died in recent years. > Perhaps it just means am getting old. > > ?Xah I find it COMPASSIONATE that WOLF RAM Research Incorporated after milking such a smart person did not give him safety cushion in his time of difficulty. This is in line with the corporate operational policy of bernard madoffs, roman polanskys, wolf rams, larry ellis islanders, and neocons. Even stalin cried and led the funerals of his comrades whom he had used his jewish doctors to kill. I urge everyone to read the great ebook, the sale and manufacture of saint einstein. postings like mine are needed to get the google censhorship crew to wake up and remove the porn postings barraged by CIA criminals. It is well known that they are targetting minorities with drugs and various marijuana and porn. Mathematica is LISP IN DISGUISE. Wolf Ram stole the idea from lisp. Its R-LISP. The guy who came up with R-LISP was also doing some physics calculations at Stanford. Wolf Ram was doing at Caltech. The fundamental object of Lisp is the cons cell or pair or list and with nesting. The fundamental object of Mathematica is table - really a cheap attempt to pretend NOVELTY. A table is atleast a pair. A symbol-value table of one row is a pair. THE GREATEST TRIBUTE THAT CAN BE GIVEN TO THIS PERSON IS TO MAKE SURE THAT HIS IDEAS DO NOT BECOME LOST AND BECOME THE MONOPOLY OF A SNAKEs OF A CORPORATIONs BUT BENEFIT THE HUMANITY AT LARGE. THE GREATEST TRIBUTE THAT CAN BE GIVEN TO THIS PERSON IS TO MAKE SURE THAT HIS IDEAS DO NOT BECOME LOST AND BECOME THE MONOPOLY OF A SNAKEs OF A CORPORATIONs BUT BENEFIT THE HUMANITY AT LARGE. THE GREATEST TRIBUTE THAT CAN BE GIVEN TO THIS PERSON IS TO MAKE SURE THAT HIS IDEAS DO NOT BECOME LOST AND BECOME THE MONOPOLY OF A SNAKEs OF A CORPORATIONs BUT BENEFIT THE HUMANITY AT LARGE. THE GREATEST TRIBUTE THAT CAN BE GIVEN TO THIS PERSON IS TO MAKE SURE THAT HIS IDEAS DO NOT BECOME LOST AND BECOME THE MONOPOLY OF A SNAKEs OF A CORPORATIONs BUT BENEFIT THE HUMANITY AT LARGE. publish them in the clearest manner in an accumulation for free. if they are clear then they wont take many pages, lot of effort. If they are published openly, they will get refined automatically and get added. Maybe a wikipedia article saying the fundamental ideas or an anonymous pdf posted on forums. or a wikileak doc. THE MANUFACTURE AND SALE OF SAINT EINSTEIN By Christopher Jon Bjerknes 2,825 page treatise on Einstein's plagiarism, Einstein's Zionism, history of Zionism, racism, Judaism, and more. The complete book The Manufacture and Sale of Saint Einstein in one 17 Mb. PDF file can be downloaded by clicking on this link: http://www.jewishracism.com/SaintEinstein.pdf From mdw at distorted.org.uk Thu Nov 25 15:56:54 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 25 Nov 2010 20:56:54 +0000 Subject: inverse of a matrix with Fraction entries References: <8l50ulFhb4U1@mid.individual.net> <87y68izdnh.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <878w0hyve1.fsf.mdw@metalzone.distorted.org.uk> Daniel Fetchinson writes: > > I wouldn't do it that way. Let M be your matrix. Work out the LCM l of > > the denominators, and multiply the matrix by that to make it an integer > > matrix N = l M. Then work out the determinant d of that integer matrix. > > Next, the big step: use Gaussian elimination to find a matrix A (the > > `adjugate matrix') such that A N = d I. This should be doable entirely > > using integer arithmetic, and I think without needing any divisions. > > Finally, we have l A M = d I, so (l/d A) M = I and l/d A is the inverse > > you seek. > > > > Does that make sense? > > Absolutely! But there is nothing wrong with working out the inverse > directly using fractions.Fraction arithmetic, I'd think. It'll work, certainly; but the Fraction implementation will have to do a buttload of GCD computations that it wouldn't need to do if you worked with plain integers. And GCDs are relatively hard, as arithmetical computations go: the usual algorithms require either a number of divisions (which are themselves rather costly) or a bitwise traversal of one of the operands. A million entries seems nontrivial for a matrix, and Gaussian elimination has cubic running time if I remember rightly; I suspect that the transformations I describe would reduce the running time by a fair amount. Of course, I might be drastically underestimating the performance of modern hardware -- I often do -- so this may not be especially relevant. Anyway, the possibility's there. -- [mdw] From fetchinson at googlemail.com Thu Nov 25 16:28:29 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Thu, 25 Nov 2010 22:28:29 +0100 Subject: inverse of a matrix with Fraction entries In-Reply-To: <878w0hyve1.fsf.mdw@metalzone.distorted.org.uk> References: <8l50ulFhb4U1@mid.individual.net> <87y68izdnh.fsf.mdw@metalzone.distorted.org.uk> <878w0hyve1.fsf.mdw@metalzone.distorted.org.uk> Message-ID: >> > I wouldn't do it that way. Let M be your matrix. Work out the LCM l of >> > the denominators, and multiply the matrix by that to make it an integer >> > matrix N = l M. Then work out the determinant d of that integer matrix. >> > Next, the big step: use Gaussian elimination to find a matrix A (the >> > `adjugate matrix') such that A N = d I. This should be doable entirely >> > using integer arithmetic, and I think without needing any divisions. >> > Finally, we have l A M = d I, so (l/d A) M = I and l/d A is the inverse >> > you seek. >> > >> > Does that make sense? >> >> Absolutely! But there is nothing wrong with working out the inverse >> directly using fractions.Fraction arithmetic, I'd think. > > It'll work, certainly; but the Fraction implementation will have to do a > buttload of GCD computations that it wouldn't need to do if you worked > with plain integers. And GCDs are relatively hard, as arithmetical > computations go: the usual algorithms require either a number of > divisions (which are themselves rather costly) or a bitwise traversal of > one of the operands. > > A million entries seems nontrivial for a matrix, and Gaussian > elimination has cubic running time if I remember rightly; I suspect that > the transformations I describe would reduce the running time by a fair > amount. Of course, I might be drastically underestimating the > performance of modern hardware -- I often do -- so this may not be > especially relevant. Anyway, the possibility's there. Okay, I see your point and I completely agree. Surely it will be faster to do it with integers, will give it a shot. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From raymond.activestate at gmail.com Thu Nov 25 17:40:41 2010 From: raymond.activestate at gmail.com (Raymond Hettinger) Date: Thu, 25 Nov 2010 14:40:41 -0800 (PST) Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> <201011242116145773-alice@gothcandycom> Message-ID: <52560c8d-bad6-422f-9c61-2c51e88006a2@z17g2000prz.googlegroups.com> On Nov 24, 9:16?pm, Alice Bevan?McGregor wrote: > On 2010-11-24 12:08:04 -0800, Raymond Hettinger said: > > > I'm writing-up more guidance on how to use super() and would like to > > point at some real-world Python examples of cooperative multiple > > inheritance. > > The SocketServer module > (http://docs.python.org/library/socketserver.html) uses cooperative > multiple inheritance to implement threading / async using a > ThreadingMixIn class and multi-processing using a ForkingMixIn class, > which may not be as complicated a use case as you are looking for. It is a great example of a style of using mixins, but isn't actually an example of Python's cooperative multiple inheritance. The code doesn't use super() and doesn't have a diamond problem. It's hard to write a best practices document for super() when the doesn't appear to be any practice at all :-) Raymond From hugol at fastmail.net Thu Nov 25 17:56:59 2010 From: hugol at fastmail.net (=?ISO-8859-1?Q?Hugo=20L=E9veill=E9?=) Date: Thu, 25 Nov 2010 17:56:59 -0500 Subject: Newbie subprocess question Message-ID: <1290725819.21008.1407210497@webmail.messagingengine.com> I'm starting various application using subprocess.Popen without any problem. The problem is with application inside "Program Files". It looks like subprocess is stopping the application string after "Program". I tried puting the programe name inside double quote like '"Program File*..."'. No luck. How can I start a app inside this folder ? Thanks -- Hugo L?veill? TD Compositing, Vision Globale hugol at fastmail.net From steve at holdenweb.com Thu Nov 25 18:08:02 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 25 Nov 2010 17:08:02 -0600 Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance In-Reply-To: <52560c8d-bad6-422f-9c61-2c51e88006a2@z17g2000prz.googlegroups.com> References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> <201011242116145773-alice@gothcandycom> <52560c8d-bad6-422f-9c61-2c51e88006a2@z17g2000prz.googlegroups.com> Message-ID: On 11/25/2010 4:40 PM, Raymond Hettinger wrote: > It's hard to write a best practices document for super() when > the doesn't appear to be any practice at all :-) > Sounds like the Python community have voted with their feet. I seem to remember that Alex Martelli's "Python in a Nutshell" contains a very thorough description of the new-style class system with an example showing the resolution of the diamond pattern. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From aahz at pythoncraft.com Thu Nov 25 18:13:16 2010 From: aahz at pythoncraft.com (Aahz) Date: 25 Nov 2010 15:13:16 -0800 Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> Message-ID: In article <89b6d53f-dcdc-4442-957f-1f4d29115a26 at n32g2000pre.googlegroups.com>, Raymond Hettinger wrote: > >I'm writing-up more guidance on how to use super() and would like to >point at some real-world Python examples of cooperative multiple >inheritance. My previous job used this rather heavily, but I can't provide you with code. I suspect we weren't the only people, but I have no clue how to locate samples. Were you searching code.google.com or something else? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Look, it's your affair if you want to play with five people, but don't go calling it doubles." --John Cleese anticipates Usenet From usernet at ilthio.net Thu Nov 25 18:18:38 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 25 Nov 2010 23:18:38 +0000 (UTC) Subject: Newbie subprocess question References: Message-ID: On 2010-11-25, Hugo L?veill? wrote: > I'm starting various application using subprocess.Popen without any > problem. The problem is with application inside "Program Files". It > looks like subprocess is stopping the application string after > "Program". I tried puting the programe name inside double quote like > '"Program File*..."'. No luck. Not sure you you are having issues. subprocess.Popen("C:\\Program Files\\Vim\\vim73\\gvim.exe") From coolaj86 at gmail.com Thu Nov 25 18:21:54 2010 From: coolaj86 at gmail.com (AJ ONeal) Date: Thu, 25 Nov 2010 16:21:54 -0700 Subject: MediaTags - exporting m4a, id3, exiv, etc as JSON (YAML) Message-ID: I'm sponsoring the development of cross-platform (C/C++) utilities for extracting a variety of media meta-data as JSON, including stream checksums and stream meta-data. git://github.com/coolaj86/mtags.git I'd like to get support for developing this, and I'm interested in the opinions of others who would use these tools. http://pledgie.com/campaigns/14039 The m4atags utility is now complete. Here's an example of the usage / output: http://coolaj86.info/articles/example-of-verbose-output-from-mediatags.html AJ ONeal -------------- next part -------------- An HTML attachment was scrubbed... URL: From stackslip at gmail.com Thu Nov 25 18:32:57 2010 From: stackslip at gmail.com (Slie) Date: Thu, 25 Nov 2010 14:32:57 -0900 Subject: =?utf-8?B?UmU6IEFycmF5cw==?= Message-ID: <4ceef22b.1a1c640a.442c.2e69@mx.google.com> I have an exercise im working on. I have an array of strings, and I would like to take each peace of the array and assign it to a new array so I can iterate over each of those pieces and replace the sting I want then put it back together. I hope that is not too confusing. This is how im trying to solve the problem. I have a program that takes in integers and it prints out the integers in bigger ones made up of asterisks. Im supposed to alter the program so so that instead of asterisks it prints them in bigger ones made up of the number itself. I am given arrays built to look like the numbers, already. ----- Reply message ----- From: "Stefan Behnel" Date: Wed, Nov 24, 2010 2:18 am Subject: Arrays To: Garland Fulton, 24.11.2010 06:55: > Is there a way I can define an Array of and unknown size so I can add and > remove to or from it? > > Are arrays immutable? Python has lists and tuples as basic data structures. Tuples are completely immutable, lists are completely mutable. If you want a container that has a fixed size but allows changing items, use a list and avoid calling .append() and .remove() to change items in favour of direct item assignments. If you want a completely mutable container, use a list and use it as you see fit. If you want a stack, a list will do. If you want a queue, a deque is a better option. In any case, if you tell us more about what you actually want to do, we can give better suggestions. Stefan -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From no.email at nospam.invalid Thu Nov 25 18:34:33 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 25 Nov 2010 15:34:33 -0800 Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> Message-ID: <7xsjyp2d12.fsf@ruckus.brouhaha.com> Raymond Hettinger writes: > I'm writing-up more guidance on how to use super() and would like to > point at some real-world Python examples of cooperative multiple > inheritance. I'd mention the SocketServer library, except I'm not sure what you mean by "cooperative", so I don't know if that counts. The few times I've tried to use multiple inheritance, I think it wasn't the right idea for what I was doing. It turns into a big mess quite easily. The classic example though is a window system, where you have a "window" class, and a "scroll bar" class, and a "drop-down menu" class, etc. and if you want a window with a scroll bar and a drop-down menu, you inherit from all three of those classes. They each have to support (e.g.) a "redraw" operation, so automatic method combination figures out what to call. I''ve mostly seen this stuff in connection with Lisp. If you look at a CLOS manual you can probably find examples. There are also some examples in the old CADR manual, using the MIT Flavors system which predated CLOS. That manual is online now: http://common-lisp.net/project/bknr/static/lmman/frontpage.html The object system is documented in this chapter: http://common-lisp.net/project/bknr/static/lmman/flavor.xml The paragraph about "defwrapper" gives a clear view into the machinery. From coolaj86 at gmail.com Thu Nov 25 18:34:49 2010 From: coolaj86 at gmail.com (AJ ONeal) Date: Thu, 25 Nov 2010 16:34:49 -0700 Subject: MediaTags - exporting m4a, id3, exiv, etc as JSON Message-ID: I'm sponsoring the development of cross-platform (C/C++) utilities for extracting a variety of media meta-data as JSON, including stream checksums and stream meta-data. git://github.com/coolaj86/mtags.git I'd like to get support for developing this, and I'm interested in the opinions of others who would use these tools. http://pledgie.com/campaigns/14039 The m4atags utility is now complete. Here's an example of the usage / output: http://coolaj86.info/articles/example-of-verbose-output-from-mediatags.html AJ ONeal -------------- next part -------------- An HTML attachment was scrubbed... URL: From nagle at animats.com Thu Nov 25 18:38:36 2010 From: nagle at animats.com (John Nagle) Date: Thu, 25 Nov 2010 15:38:36 -0800 Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance In-Reply-To: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> Message-ID: <4ceef381$0$1659$742ec2ed@news.sonic.net> On 11/24/2010 12:08 PM, Raymond Hettinger wrote: > I'm writing-up more guidance on how to use super() and would like to > point at some real-world Python examples of cooperative multiple > inheritance. > > Google searches take me to old papers for C++ and Eiffel, but that > don't seem to be relevant to most Python programmers (i.e. a > WalkingMenu example where a submenu is both a Entry in a Menu and a > Menu itself). Another published example is in a graphic library where > some widgets inherit GraphicalFeature methods such as location, size > and NestingGroupingFeatures such as finding parents, siblings, and > children. I don't find either of those examples compelling because > there is no particular reason that they would have to have overlapping > method names. > > So far, the only situation I can find where method names necessarily > overlap is for the basics like __init__(), close(), flush(), and > save() where multiple parents need to have their own initialization > and finalization. > > If you guys know of good examples, I would appreciate a link or a > recap. Multiple inheritance in Python is basically what fell out of CPython's internals, not a design. It's one of those areas where order of execution matters, and that wasn't well worked out. Allowing classes to form a directed acyclic graph isn't very useful. It just fell out of the semantics of a naive interpreter. Read "C3 method resolution order": http://www.python.org/download/releases/2.3/mro/ which is what you have to understand to use the awful cases properly. Originally, the semantics were just wrong. Now the awful cases have well-defined semantics, but aren't very useful. Part of the problem is the notion that if a base class is duplicated in the hierarchy, there's only one copy. So if you inherit from two classes, both of which inherit from "dict", there will be only one "dict" at the bottom. (I think.) This probably won't do what the authors of any of the classes involved expected. The author of the class which does the multiple inheritance might not even be aware that there's a clash further up in the hierarchy. This is one of those areas where all the code looks right locally, but it's wrong globally. Best practice for this is "don't do it." Some name clashes ought to simply be detected as errors, rather than being given such complex semantics. John Nagle From tjreedy at udel.edu Thu Nov 25 18:39:57 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 25 Nov 2010 18:39:57 -0500 Subject: what a cheap rule In-Reply-To: <478343.25019.qm@web54204.mail.re2.yahoo.com> References: <478343.25019.qm@web54204.mail.re2.yahoo.com> Message-ID: On 11/25/2010 4:12 AM, Yingjie Lan wrote: > Sometimes the golden rule in Python of > "explicit is better than implicit" is > so cheap that it can be thrown away > for the trouble of typing an empty tuple. > > Today when I am explaining that in Python 3, > there are two ways to raise exceptions: > > raise Exception > raise Exception() I agree with you that this is annoying. I think it is a holdover from the past. In Python 1/2, raise 'some string' also works, but that was disallowed in Py 3. A lot of things were cleaned up in Py 3, but not everything. -- Terry Jan Reedy From lanyjie at yahoo.com Thu Nov 25 18:58:41 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Thu, 25 Nov 2010 15:58:41 -0800 (PST) Subject: tilted text in the turtle module In-Reply-To: Message-ID: <892332.24723.qm@web54207.mail.re2.yahoo.com> --- On Thu, 11/25/10, Steve Holden wrote: > > And even if I made a patch, > > then how to publish it? > > > Once you have a patch, attach it to the issue as a file and > try and get > it reviewed by a developer for incorporation into a future > release. > > Note that no Python 2.8 release is planned, so you would > best > concentrate your effort on the 3.x series. > I see. I suppose one could post a message somewhere to get the attention? Thanks for the pointer. Regards, Yingjie From lanyjie at yahoo.com Thu Nov 25 19:05:46 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Thu, 25 Nov 2010 16:05:46 -0800 (PST) Subject: the buggy regex in Python In-Reply-To: <4CEE9A60.1030807@mrabarnett.plus.com> Message-ID: <100685.62538.qm@web54203.mail.re2.yahoo.com> --- On Thu, 11/25/10, MRAB wrote: > > > Look at the spans: > > >>> for m in re.finditer('((.d.)*)*', 'adb'): > ??? print(m.span()) > > ??? > (0, 3) > (3, 3) > > There's an non-empty match followed by an empty match. If you read my first post, it should be apparent that that the empty string in the end of the string is used twice -- thus an overlap. Yingjie From steve at holdenweb.com Thu Nov 25 19:16:51 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 25 Nov 2010 18:16:51 -0600 Subject: tilted text in the turtle module In-Reply-To: <892332.24723.qm@web54207.mail.re2.yahoo.com> References: <892332.24723.qm@web54207.mail.re2.yahoo.com> Message-ID: On 11/25/2010 5:58 PM, Yingjie Lan wrote: > --- On Thu, 11/25/10, Steve Holden wrote: >>> And even if I made a patch, >>> then how to publish it? >>> >> Once you have a patch, attach it to the issue as a file and >> try and get >> it reviewed by a developer for incorporation into a future >> release. >> >> Note that no Python 2.8 release is planned, so you would >> best >> concentrate your effort on the 3.x series. >> > > I see. I suppose one could post a message somewhere > to get the attention? > > Thanks for the pointer. > One would normally make a post on the python-dev list to get the attention of developers. If you want to *guarantee* that your issue gets attention then you can review five existing issues and advance them a little to help the development team. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From python at mrabarnett.plus.com Thu Nov 25 19:27:59 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 26 Nov 2010 00:27:59 +0000 Subject: Newbie subprocess question In-Reply-To: <1290725819.21008.1407210497@webmail.messagingengine.com> References: <1290725819.21008.1407210497@webmail.messagingengine.com> Message-ID: <4CEEFF0F.6020005@mrabarnett.plus.com> On 25/11/2010 22:56, Hugo L?veill? wrote: > I'm starting various application using subprocess.Popen without any > problem. The problem is with application inside "Program Files". It > looks like subprocess is stopping the application string after > "Program". I tried puting the programe name inside double quote like > '"Program File*..."'. No luck. > > How can I start a app inside this folder ? > Try passing the application path and its arguments (if any) as a list like this: subprocess.Popen([app_path, arg1, arg2]) From lanyjie at yahoo.com Thu Nov 25 19:50:54 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Thu, 25 Nov 2010 16:50:54 -0800 (PST) Subject: tilted text in the turtle module In-Reply-To: Message-ID: <924269.82196.qm@web54208.mail.re2.yahoo.com> --- On Fri, 11/26/10, Steve Holden wrote: > From: Steve Holden > Subject: Re: tilted text in the turtle module > To: python-list at python.org > Date: Friday, November 26, 2010, 4:16 AM > On 11/25/2010 5:58 PM, Yingjie Lan > wrote: > > --- On Thu, 11/25/10, Steve Holden > wrote: > >>> And even if I made a patch, > >>> then how to publish it? > >>> > >> Once you have a patch, attach it to the issue as a > file and > >> try and get > >> it reviewed by a developer for incorporation into > a future > >> release. > >> > >> Note that no Python 2.8 release is planned, so you > would > >> best > >> concentrate your effort on the 3.x series. > >> > > > > I see. I suppose one could post a message somewhere > > to get the attention? > > > > Thanks for the pointer. > > > One would normally make a post on the python-dev list to > get the > attention of developers. If you want to *guarantee* that > your issue gets > attention then you can review five existing issues and > advance them a > little to help the development team. > Sound advices. Many thanks! Yingjie From mdw at distorted.org.uk Thu Nov 25 20:00:44 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Fri, 26 Nov 2010 01:00:44 +0000 Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> <4ceef381$0$1659$742ec2ed@news.sonic.net> Message-ID: <87k4k0yk3n.fsf.mdw@metalzone.distorted.org.uk> John Nagle writes: > Multiple inheritance in Python is basically what fell out of > CPython's internals, not a design. It's one of those areas where > order of execution matters, and that wasn't well worked out. I'm not sure about the history, but this doesn't sound right to me. > Allowing classes to form a directed acyclic graph isn't very > useful. This is simply wrong. > It just fell out of the semantics of a naive interpreter. No: there's some essential work needed to make it happen. > Originally, the semantics were just wrong. Agreed. > Now the awful cases have well-defined semantics, but aren't very > useful. Disagree strongly. I think linearization is the only coherent approach to multiple inheritance, and the C3 linearization seems to have almost all of the necessary properties. I'm not quite sure what you mean by `awful' here: the old Python linearization rules were wrong even for very simple graphs (they failed to respect the superclass ordering properly). The CLOS, Dylan and C3 linearizations agree on most commonly occurring class graphs, including many graphs for which the old Python orderings disagreed; the exceptions are where CLOS or Dylan failed to be monotonic or to obey the extended precedence graph. The semantics are extremely useful in the hands of a careful designer. > Part of the problem is the notion that if a base class is duplicated > in the hierarchy, there's only one copy. This is a problem? No! Duplicating superclass state (as is done in C++ and, I believe, Eiffel) is incoherent. > So if you inherit from two classes, both of which inherit from "dict", > there will be only one "dict" at the bottom. (I think.) Yes. You end up (probably) with an enhanced dictionary which supports both protocols. This happens frequently, and is very useful. > This probably won't do what the authors of any of the classes involved > expected. The author of the class which does the multiple inheritance > might not even be aware that there's a clash further up in the > hierarchy. This is one of those areas where all the code looks right > locally, but it's wrong globally. This is only likely if there's a misdesign -- probably using inheritance where containership is required. > Best practice for this is "don't do it." Some name clashes ought > to simply be detected as errors, rather than being given such > complex semantics. It sounds like you've been scarred by experiences with C++'s dementedly inadequate object system, with its bizarre `repeated inheritance' rules and hopelessly primitive manual (static!) method combination -- possibly even to the extent of believing that they're in some way `right' or `necessary'. I'm sorry. You have my pity. Python's object system is different, and doesn't have those problems. You probably need a viewpoint shift to be able to think about it properly, but that won't happen if you continue to cling to the idea that C++'s approach is anything like a model of how to do it right. -- [mdw] From steve+comp.lang.python at pearwood.info Thu Nov 25 20:10:09 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Nov 2010 01:10:09 GMT Subject: what a cheap rule References: Message-ID: <4cef08f0$0$29974$c3e8da3$5496439d@news.astraweb.com> On Thu, 25 Nov 2010 08:15:21 -0800, Yingjie Lan wrote: > Intuition #1: as if you raise an exception type, and then match that > type. > It seems that no instances > are involved here (Intuitively). Your intuition is not my intuition, nor does it match what Python actually does. You can only go so far on *guessing* what a programming statement does, sometimes you need to actually read the Fine Manual. > See an example code here: > > try: raise KeyError > except KeyError: pass As the documentation states, this creates an instance of KeyError. raise evaluates the first expression as the exception object. It must be either a subclass or an instance of BaseException. If it is a class, the exception instance will be obtained when needed by instantiating the class with no arguments. http://docs.python.org/py3k/reference/simple_stmts.html#the-raise-statement So there is no semantic difference between "raise KeyError" and "raise KeyError()". Why should there be? What practical difference would you expect? If you do this: try: raise KeyError except KeyError as ke: print(ke) you will see that the value caught is an instance, not the class. > Intuition #2: you raise an exception > instance, and then match an instance by its type. See an example code > here: > > try: raise KeyError() > except KeyError as ke: pass Your intuition is wrong. Exceptions aren't matched by type, they are *always* matched by an isinstance() check, and that includes subclasses. >>> try: raise KeyError # with or without parentheses makes no difference ... except Exception as e: print(type(e)) ... > Those two comprehensions are not compatible, and thus the one that > promotes correct understanding should be encouraged, > while the other should be discouraged, and maybe even be made iliegal. You seem to have misunderstood both forms of the raise statement. Should we make exceptions illegal because you can't correctly guess what they do? -- Steven From lanyjie at yahoo.com Thu Nov 25 20:29:00 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Thu, 25 Nov 2010 17:29:00 -0800 (PST) Subject: what a cheap rule In-Reply-To: <4cef08f0$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: <420169.50181.qm@web54201.mail.re2.yahoo.com> --- On Fri, 11/26/10, Steven D'Aprano wrote: > From: Steven D'Aprano > Subject: Re: what a cheap rule > To: python-list at python.org > Date: Friday, November 26, 2010, 5:10 AM > On Thu, 25 Nov 2010 08:15:21 -0800, > Yingjie Lan wrote: > > You seem to have misunderstood both forms of the raise > statement. Should > we make exceptions illegal because you can't correctly > guess what they do? > > Though what you said about Python is right, I think somehow you missed my point a bit. Ideally, the language could be so 'natural' that it means what meets the eyes. Yingjie From steve+comp.lang.python at pearwood.info Thu Nov 25 20:30:23 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Nov 2010 01:30:23 GMT Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> <4ceef381$0$1659$742ec2ed@news.sonic.net> Message-ID: <4cef0daf$0$29974$c3e8da3$5496439d@news.astraweb.com> On Thu, 25 Nov 2010 15:38:36 -0800, John Nagle wrote: > Part of the problem is the notion that if a base class is duplicated in > the hierarchy, there's only one copy. Why is that a problem? I would expect it to be a problem if it showed up twice. > So if you inherit from two > classes, both of which inherit from "dict", there will be only one > "dict" at the bottom. (I think.) This probably won't do what the > authors of any of the classes involved expected. The author of the > class which does the multiple inheritance might not even be aware that > there's a clash further up in the hierarchy. This is one of those areas > where all the code looks right locally, but it's wrong globally. Why do you assume it is "wrong"? The whole point of the "complex semantics" that you are complaining about is to ensure that multiple inheritance does the right thing, rather than the wrong thing. You simply can't safely inherit from arbitrary classes without understanding them. This is equally true for single and multiple inheritance, but in multiple inheritance there are more places for things to go wrong. That is simply because the semantics of "inherit from classes A and B" are more complex than the semantics of "inherit from class A". The problem is that people expect multiple inheritance to "just work" mechanically, without giving any thought to the process. That it does often just work is a credit to the "complex semantics" that you are complaining about, but this lulls people into a false sense of security and makes it more surprising when it doesn't work. > Best practice for this is "don't do it." Some name clashes ought > to simply be detected as errors, rather than being given such complex > semantics. If that's the case, you would have to prohibit ALL multiple inheritance from new-style classes, because all new-style classes inherit from object. -- Steven From raymond.activestate at gmail.com Thu Nov 25 20:36:43 2010 From: raymond.activestate at gmail.com (Raymond Hettinger) Date: Thu, 25 Nov 2010 17:36:43 -0800 (PST) Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> <4ceef381$0$1659$742ec2ed@news.sonic.net> Message-ID: <5c92a83e-9de1-4a03-828c-2cce79ce5a30@v17g2000prc.googlegroups.com> On Nov 25, 3:38?pm, John Nagle wrote: > ? ? Multiple inheritance in Python is basically what fell out of > CPython's internals, not a design. ? Sorry to disagree. That is historically inaccurate. Guido designed super() on purpose. He took his cues from "Putting Metaclasses to Work" by Ira Forman and Scott Danforth. The method resolution order was based on yet another paper which showed the defects in the two earlier designs for multiple inheritance. It may not be great, but it sure wasn't an accident. > ? ? Best practice for this is "don't do it." ?Some name clashes ought > to simply be detected as errors, rather than being given such > complex semantics. That may well be true. If a coder has enough control over the classes to be make sure they use super() in a way that supports cooperative multiple inheritance, then they have enough control to just rename the methods to prevent name diamond shaped name clashes. OTOH, sometimes you don't have control over the names if they are magic methods or standard names like close(), save(), flush(), __init__(), etc. Raymond From raymond.activestate at gmail.com Thu Nov 25 20:41:50 2010 From: raymond.activestate at gmail.com (Raymond Hettinger) Date: Thu, 25 Nov 2010 17:41:50 -0800 (PST) Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> <7xsjyp2d12.fsf@ruckus.brouhaha.com> Message-ID: <2d8b3612-531c-467c-9ffd-9e5ff7ac2e1a@h17g2000pre.googlegroups.com> [Paul Rubin] > I'd mention the SocketServer library, except I'm not sure what you > mean by "cooperative", so I don't know if that counts. Cooperative multiple inheritance is a specific problem when there is a diamond diagram with the same method name needing to be called on multiple paths and each name should only be called exactly once. http://www.python.org/download/releases/2.2.3/descrintro/#cooperation Raymond From piadmin at nowhereland.invalid Thu Nov 25 20:58:03 2010 From: piadmin at nowhereland.invalid (piadmin) Date: Fri, 26 Nov 2010 01:58:03 GMT Subject: Preciseinfo collections updated http://preciseinfo.org Message-ID: All preciseinfo.org collections are updated. (Java, Javascript, C++ VC ATL STL, MFC VC, Python, Php) About collections: ------------------ Collections include two types of information: 1) Code examples (guaranteed to have articles with code on the subject of selected chapter, guaranteed to be relevant to that topic with > 90% certainty) 2) Expert articles Contain articles by writers with above average competence level. Internal search engine: ----------------------- All collections may be searched with a very powerfule internal search engine. It supports all standard search engine operations, including "OR" and a literal match (if you include multiple search words surrounded by quote chars (")). Also, phrase search is fully supported. Synonyms are supported. Except in programming languages synonyms are not that straightforward issue. Do not underestimate the power of INTERNAL search engine. It is a very powerful search engine. It will allow you to drill down the issue to the most precise degree. You can search on some language (Java, MFC, C++, etc.) Or you can search on a single chapter from some language. Or, you can search on ALL the languages and ALL the chapters. If and when you perform a search from some article, the default search condition is to search the chapter that article belongs to. But the search result box will show you what was found and will give you an option to change the scope of search. That is, to select some specific chapter from some collection, or to select ALL the chapters in that collection. If you click on Index link in the navbar, you will be shown the list of articles in that chapter. If you perform a search from the search box in the chapter index, the default search scope is to search that chapter. It is best to search using the internal search engine vs. standard search engines, such as Google. Because Google only has a small part of the collections indexed for whatever reason. But the internal search engine has every single article available in the collection indexed. So you have the "full scoop". Enjoy. From joe at goldthwaites.com Thu Nov 25 22:28:17 2010 From: joe at goldthwaites.com (Joe Goldthwaite) Date: Thu, 25 Nov 2010 20:28:17 -0700 Subject: Parsing markup. Message-ID: I'm attempting to parse some basic tagged markup. The output of the TinyMCE editor returns a string that looks something like this;

This is a paragraph with bold and italic elements in it

It can be made up of multiple lines separated by pagagraph tags.

I'm trying to render the paragraph into a bit mapped image. I need to parse it out into the various paragraph and bold/italic pieces. I'm not sure the best way to approach it. Elementree and lxml seem to want a full formatted page, not a small segment like this one. When I tried to feed a line similar to the above to lxml I got an error; "XMLSyntaxError: Extra content at the end of the document". -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Thu Nov 25 23:03:27 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 26 Nov 2010 04:03:27 +0000 Subject: Parsing markup. In-Reply-To: References: Message-ID: <4CEF318F.2090308@mrabarnett.plus.com> On 26/11/2010 03:28, Joe Goldthwaite wrote: > I?m attempting to parse some basic tagged markup. The output of the > TinyMCE editor returns a string that looks something like this; > >

This is a paragraph with bold and italic elements in > it

It can be made up of multiple lines separated by pagagraph > tags.

> > I?m trying to render the paragraph into a bit mapped image. I need > to parse it out into the various paragraph and bold/italic pieces. > I?m not sure the best way to approach it. Elementree and lxml seem > to want a full formatted page, not a small segment like this one. > When I tried to feed a line similar to the above to lxml I got an > error; ?XMLSyntaxError: Extra content at the end of the document?. > I'd probably use a regex: >>> import re >>> text = "

This is a paragraph with bold and italic elements in it

It can be made up of multiple lines separated by pagagraph tags.

" >>> re.findall(r"|[^<>]+", text) ['

', 'This is a paragraph with ', '', 'bold', '', ' and ', '', 'italic', '', ' elements in it', '

', '

', 'It can be made up of multiple lines separated by pagagraph tags.', '

'] From wuwei23 at gmail.com Thu Nov 25 23:31:19 2010 From: wuwei23 at gmail.com (alex23) Date: Thu, 25 Nov 2010 20:31:19 -0800 (PST) Subject: Pypi (Cheeseshop) Score - derivation of ? References: <86979c80-0955-4ee8-b645-10097d45dd58@z9g2000pri.googlegroups.com> <30d136fe-5fc3-49aa-904d-c63b228e5d2c@n2g2000pre.googlegroups.com> <4CEE2991.4050303@v.loewis.de> Message-ID: "Martin v. Loewis" wrote: > There was indeed a kwalitee computation (cheesecake); it is unmaintained. Ah yes, I couldn't remember the particular mispelling the project used :) From agoretoy at gmail.com Thu Nov 25 23:56:33 2010 From: agoretoy at gmail.com (alex goretoy) Date: Thu, 25 Nov 2010 22:56:33 -0600 Subject: class in c subclasses python classes, called in python Message-ID: I'm looking to create an application that uses c++ and python together. Currently my application is all python. But need to obfuscate some of the code. I am wanting to have c++ code so I can handle encryption with it and other tasks. But first I need it to subclass some python class objects. One task that I need to do is create a class in c++ that subclasses 3 python classes and calls the base class constructor as super would call in python. I need this in c++. How can I do this please? class ABC(a,b,c): def __init__(self, *args, **kwargs): super(ABC, self).__init__(*args, **kwargs) What I would like to know is how would I create a class in C or C++ that would: 1. create a class that subclasses 2 or more python classes 2. initializes the subclassed classes by calling the contructors like python's super would 3. import the class in python and call this class constructor with ABC(*args, **kwargs) is there a way to do this? Thanks in advance :) Thank you, -Alex Goretoy -------------- next part -------------- An HTML attachment was scrubbed... URL: From davea at ieee.org Fri Nov 26 00:06:19 2010 From: davea at ieee.org (Dave Angel) Date: Fri, 26 Nov 2010 00:06:19 -0500 Subject: Newbie subprocess question In-Reply-To: <1290725819.21008.1407210497@webmail.messagingengine.com> References: <1290725819.21008.1407210497@webmail.messagingengine.com> Message-ID: <4CEF404B.4040603@ieee.org> On 01/-10/-28163 02:59 PM, Hugo L?veill? wrote: > I'm starting various application using subprocess.Popen without any > problem. The problem is with application inside "Program Files". It > looks like subprocess is stopping the application string after > "Program". I tried puting the programe name inside double quote like > '"Program File*..."'. No luck. > > How can I start a app inside this folder ? > > Thanks > > How about you show us exactly what you are doing, and just what you mean by "no luck" ? You also should tell us what version of Python you're running, and mention that you're on Windows (presumably, but not necessarily). Perhaps you're using shell=True, perhaps you have an executable in the root directory called c:\program.exe, Perhaps you're passing arguments, but not putting them in separate list items. Who knows? DaveA From javier.collado at gmail.com Fri Nov 26 00:11:07 2010 From: javier.collado at gmail.com (Javier Collado) Date: Fri, 26 Nov 2010 06:11:07 +0100 Subject: Parsing markup. In-Reply-To: References: Message-ID: Hello, 2010/11/26 Joe Goldthwaite : > I?m attempting to parse some basic tagged markup. > >? Elementree and lxml seem to want a full formatted > page, not a small segment like this one. BeautifulSoup (http://www.crummy.com/software/BeautifulSoup/) could help in the parsing: >>> from BeautifulSoup import BeautifulSoup as Soup >>> s = Soup(text) >>> print s.prettify()

This is a paragraph with bold and italic elements in it

It can be made up of multiple lines separated by pagagraph tags.

>>> s.findAll('b') [bold] >>> s.findAll('i') [italic] >>> s.findAll('p') [

This is a paragraph with bold and italic elements in it

,

It can be made up of multiple lines separated by pagagraph tags.

] Best regards, Javier From timr at probo.com Fri Nov 26 01:37:33 2010 From: timr at probo.com (Tim Roberts) Date: Thu, 25 Nov 2010 22:37:33 -0800 Subject: Matlab equivalent syntax in Python References: <8317f18c-f2b2-4150-9bc0-e84d75e80de2@n32g2000pre.googlegroups.com> Message-ID: Akand Islam wrote: > >Can anyone please suggest me what will be the good way to use matlab >equivalent of "profile clear, profile on, profile off, profile resume >and profile viewer" in Python? Python has a number of ways of measuring elapsed time, including the "timeit" module and the "trace" module. There's nothing that will display the results in a pretty graph, so the answer depends on what you are after. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Fri Nov 26 01:45:05 2010 From: timr at probo.com (Tim Roberts) Date: Thu, 25 Nov 2010 22:45:05 -0800 Subject: SQLite date fields References: Message-ID: Alan Harris-Reid wrote: > >I am having design problems with date storage/retrieval using Python and >SQLite. > >I understand that a SQLite date column stores dates as text in ISO >format (ie. '2010-05-25'). Only if you store it that way. >So when I display a British date (eg. on a web-page) I convert the date >using datetime.datetime.strptime(mydate,'%Y-%m-%d').strftime('%d/%m/%Y'). > >However, when it comes to writing-back data to the table, SQLite is very >forgiving and is quite happy to store '25/06/2003' in a date field, SQLite is essentially typeless. ALL fields are stored as strings, with no interpretation. You can store whatever you want in any column. The column types are basically there to remind YOU how to handle the data. >How have other developers overcome this problem? By converting. SQLite's flexibility is cool, but it means you have to be smart about how you store the data. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From mftian at gmail.com Fri Nov 26 03:41:25 2010 From: mftian at gmail.com (Xie&Tian) Date: Fri, 26 Nov 2010 16:41:25 +0800 Subject: berkeley db in concurrent environment Message-ID: Hi list, I'm using bsddb.dbshelve in a conservative and concurrent environment (python version 2.4). I'm wondering if the dbshelve class methods are atomic. That is, if one process keeps writing data to one database file and another process keeps reading from it, will the reading process get incomplete(corrupted) data? Many thanks. Regards -- Luyun Xie ??? http://magefromhell.blogspot.com/ (http://blog.hellmage.info/) -------------- next part -------------- An HTML attachment was scrubbed... URL: From news1234 at free.fr Fri Nov 26 05:11:10 2010 From: news1234 at free.fr (News123) Date: Fri, 26 Nov 2010 11:11:10 +0100 Subject: Newbie subprocess question In-Reply-To: References: Message-ID: <4cef87be$0$20686$426a34cc@news.free.fr> On 11/26/2010 12:18 AM, Tim Harig wrote: > On 2010-11-25, Hugo L?veill? wrote: >> I'm starting various application using subprocess.Popen without any >> problem. The problem is with application inside "Program Files". It >> looks like subprocess is stopping the application string after >> "Program". I tried puting the programe name inside double quote like >> '"Program File*..."'. No luck. > > Not sure you you are having issues. > > subprocess.Popen("C:\\Program Files\\Vim\\vim73\\gvim.exe") Above line should work. In order to avoid the double backslashes (such, that you can just copy paste from the windows explorer or from a command line shell you could additionally prefix the string with r. subprocess.Popen(r"C:\Program Files\Vim\vim73\gvim.exe") copying and pasting reduces the risk of typos From DekuDekuplex at Yahoo.com Fri Nov 26 07:01:37 2010 From: DekuDekuplex at Yahoo.com (Benjamin L. Russell) Date: Fri, 26 Nov 2010 21:01:37 +0900 Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> <08823dd4-588a-4729-a660-711e266c96b0@y23g2000yqd.googlegroups.com> <396f8de7-ece5-4e9c-919b-886eb65ae14a@a30g2000vbt.googlegroups.com> <967678a1-fc5d-4b61-86c5-79a298999582@p1g2000vbo.googlegroups.com> <18cd9337-736b-427c-9cac-14c99056750a@p1g2000yqm.googlegroups.com> <87vd3l8iy3.fsf@padme.localdomain> Message-ID: namekuseijin writes: > I have to say I'm always amazed how ad hominens can generate quite > strong responses to the point of making a lot of new faces (or mail > accounts) suddenly appear... ;) Actually, I had just noticed that aspect as well. Is it just me, or does anybody else also think it rather curious how some of the new accounts all seem to share the same style of argument? Granted, I don't have anything the issue of arguing a point itself. However, it just seems rather unusual that many of the new faces all seem to share the same style of reasoning.... When I was a student at my college, one of the students once told me a secret about how a computer program ran by a professor for a course in introduction to systems programming checked to ensure that the students who were submitting homework assignments worked independently: the program counted the number of occurrences of each type of structure (for-loop, while-loop, if-then statement,etc.), and compared the counts for the types of structures among assignments between different students. The method was so effective that it was able to pinpoint one program among approximately thirty that was handed in by a student who had based his assignment on another program for the same assignment two years earlier, also among approximately thirty. A style of reasoning is like a fingerprint; it identifies the person making the argument. Of course, two people could have a very similar style of argument. However, the odds of this happening are less likely in a single thread. The odds of this happening are even less likely for three people in the thread. The odds of this happening are even less likely for three *new* people in the same thread at the same time.... -- Benjamin L. Russell -- Benjamin L. Russell / DekuDekuplex at Yahoo dot com http://dekudekuplex.wordpress.com/ Translator/Interpreter / Mobile: +011 81 80-3603-6725 "Furuike ya, kawazu tobikomu mizu no oto." -- Matsuo Basho^ From DekuDekuplex at Yahoo.com Fri Nov 26 07:14:15 2010 From: DekuDekuplex at Yahoo.com (Benjamin L. Russell) Date: Fri, 26 Nov 2010 21:14:15 +0900 Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> <08823dd4-588a-4729-a660-711e266c96b0@y23g2000yqd.googlegroups.com> <396f8de7-ece5-4e9c-919b-886eb65ae14a@a30g2000vbt.googlegroups.com> <967678a1-fc5d-4b61-86c5-79a298999582@p1g2000vbo.googlegroups.com> <18cd9337-736b-427c-9cac-14c99056750a@p1g2000yqm.googlegroups.com> <87vd3l8iy3.fsf@padme.localdomain> Message-ID: DekuDekuplex at Yahoo.com (Benjamin L. Russell) writes: > When I was a student at my college, one of the students once told me a > secret about how a computer program ran by a professor for a course in > introduction to systems programming checked to ensure that the students > who were submitting homework assignments worked independently: the > program counted the number of occurrences of each type of structure > (for-loop, while-loop, if-then statement,etc.), and compared the counts > for the types of structures among assignments between different > students. Minor typo corrections: 1) "computer program ran by" -> "computer program run by" 2) "if-then statement,etc." -> "if-then statement, etc." (missing period) Incidentally, regarding the programming assignment, the student who was caught by the structural similarity checking program reportedly received an e-mail message from the professor asking to explain the similarity. He never replied to that message, and subsequently received a grade of 0 for that assignment. -- Benjamin L. Russell -- Benjamin L. Russell / DekuDekuplex at Yahoo dot com http://dekudekuplex.wordpress.com/ Translator/Interpreter / Mobile: +011 81 80-3603-6725 "Furuike ya, kawazu tobikomu mizu no oto." -- Matsuo Basho^ From joncle at googlemail.com Fri Nov 26 07:58:29 2010 From: joncle at googlemail.com (Jon Clements) Date: Fri, 26 Nov 2010 04:58:29 -0800 (PST) Subject: Parsing markup. References: Message-ID: <9cb996fe-39b0-4780-bd56-5323b7269b0f@t8g2000prh.googlegroups.com> On Nov 26, 4:03?am, MRAB wrote: > On 26/11/2010 03:28, Joe Goldthwaite wrote: > ?> I?m attempting to parse some basic tagged markup. ?The output of the > ?> TinyMCE editor returns a string that looks something like this; > ?> > ?>

This is a paragraph with bold and italic elements in > ?> it

It can be made up of multiple lines separated by pagagraph > ?> tags.

> ?> > ?> I?m trying to render the paragraph into a bit mapped image. ?I need > ?> to parse it out into the various paragraph and bold/italic pieces. > ?> I?m not sure the best way to approach it. ?Elementree and lxml seem > ?> to want a full formatted page, not a small segment like this one. > ?> When I tried to feed a line similar to the above to lxml I got an > ?> error; ?XMLSyntaxError: Extra content at the end of the document?. > ?> lxml works fine for me - have you tried: from lxml import html text = "

This is a paragraph with bold and italic elements in it

It can be made up of multiple lines separated by pagagraph tags.

" tree = html.fromstring(text) print tree.findall('p') # should print [, ] hth Jon From smirnoffs at gmail.com Fri Nov 26 08:06:35 2010 From: smirnoffs at gmail.com (Sergey Smirnov) Date: Fri, 26 Nov 2010 15:06:35 +0200 Subject: How to parse a text block? Message-ID: Hi all. I have a lot of text blocks that looks like this one *** Layer 3 Message type: CP-Data Device: MS1 Time: 19:57:44.71 CP-User data length : 37 RPDU Message type indicator (MTI) : (1) RP-DATA The question is how to parse given text block into a dictionary that looks like the dictionary given below? {'Device':'MS1','Time':'Time: 19:57:44.71','CP-User data':{'length':'37','RPDU':{'Message type indicator (MTI)':'(1) RP-DATA'}}} Any other thoughts about reading that kind of text? Thanks, Sergey -------------- next part -------------- An HTML attachment was scrubbed... URL: From duncan.booth at invalid.invalid Fri Nov 26 08:20:01 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 26 Nov 2010 13:20:01 GMT Subject: SQLite date fields References: Message-ID: Tim Roberts wrote: >>However, when it comes to writing-back data to the table, SQLite is >>very forgiving and is quite happy to store '25/06/2003' in a date >>field, > > SQLite is essentially typeless. ALL fields are stored as strings, > with no interpretation. You can store whatever you want in any > column. The column types are basically there to remind YOU how to > handle the data. > Not all fields are stored as strings; they may also be stored as integer, floating point values or binary data. If you create a table with a column of type DATE or DATETIME then the column affinity is NUMERIC. See http://www.sqlite.org/datatype3.html It happens that Python stores datetime values in sqlite databases as text strings by default, but that means if you actually declare the column as DATE or DATETIME you are overriding the default type for each column. Not that it is normally noticeable but: >>> import sqlite3 >>> conn = sqlite3.connect('test.db') >>> c = conn.cursor() >>> c.execute('''CREATE TABLE t1 (d DATE, t TEXT);''') >>> from datetime import datetime >>> d = datetime.now() >>> c.execute('INSERT INTO t1 (d,t) VALUES (julianday(?),julianday(?))', (d, d)) >>> for row in c.execute('SELECT * FROM t1'): print(row) (2455527.0482040276, '2455527.04820403') >>> for row in c.execute("SELECT datetime(d), datetime(t) FROM t1"): print(row) ('2010-11-26 13:09:24', '2010-11-26 13:09:24') -- Duncan Booth http://kupuguy.blogspot.com From greywine at gmail.com Fri Nov 26 08:38:59 2010 From: greywine at gmail.com (greywine at gmail.com) Date: Fri, 26 Nov 2010 05:38:59 -0800 (PST) Subject: passing a tuple into a class function as a single argument Message-ID: <5c738442-e6f6-44b2-9442-f181ff512112@30g2000yql.googlegroups.com> Hi everyone, The following program doesn't work as expected: #Python 2.7 & wxPython 2.9 import wx class MyFrame(wx.Frame): """ We simply derive a new class of Frame. """ def __init__(self, parent, title): wx.Frame.__init__(self, parent, title=title, size=(200,100)) self.control = wx.TextCtrl(self, style=wx.TE_MULTILINE) self.Show(True) app = wx.App(False) size=(600,400) frame = MyFrame(None, 'Small editor') #frame = MyFrame(None, 'Small editor', (600,400)) app.MainLoop() If I use the default size=(200,100) it's just fine. But if I try it pass it a new size (600,400), I get the following error: Traceback (most recent call last): File "C:\Python27\wxpythoneasy1.py", line 13, in frame = MyFrame(None, 'Small editor',((600,400))) TypeError: __init__() takes exactly 3 arguments (4 given) It seems like it's begging to have it pass a different size than the default, but there doesn't seem to be a way to pass a tuple as a single argument. Any help would be appreciate. Thanks, John R. From mwilson at the-wire.com Fri Nov 26 08:53:21 2010 From: mwilson at the-wire.com (Mel) Date: Fri, 26 Nov 2010 08:53:21 -0500 Subject: passing a tuple into a class function as a single argument References: <5c738442-e6f6-44b2-9442-f181ff512112@30g2000yql.googlegroups.com> Message-ID: greywine at gmail.com wrote: > Hi everyone, > > The following program doesn't work as expected: > > > #Python 2.7 & wxPython 2.9 > > import wx > > class MyFrame(wx.Frame): > """ We simply derive a new class of Frame. """ > def __init__(self, parent, title): > wx.Frame.__init__(self, parent, title=title, size=(200,100)) > self.control = wx.TextCtrl(self, style=wx.TE_MULTILINE) > self.Show(True) > > app = wx.App(False) > size=(600,400) > frame = MyFrame(None, 'Small editor') > #frame = MyFrame(None, 'Small editor', (600,400)) > app.MainLoop() > > If I use the default size=(200,100) it's just fine. But if I try it > pass it a new size (600,400), I get the following error: > Traceback (most recent call last): > File "C:\Python27\wxpythoneasy1.py", line 13, in > frame = MyFrame(None, 'Small editor',((600,400))) > TypeError: __init__() takes exactly 3 arguments (4 given) > > It seems like it's begging to have it pass a different size than the > default, but there doesn't seem to be a way to pass a tuple as a > single argument. > > Any help would be appreciate. You have to tell __init__ what's coming. def __init__(self, parent, title, size): wx.Frame.__init__(self, parent, title=title, size=size) and so on. Mel. From fuzzyman at gmail.com Fri Nov 26 09:16:01 2010 From: fuzzyman at gmail.com (Fuzzyman) Date: Fri, 26 Nov 2010 06:16:01 -0800 (PST) Subject: what a cheap rule References: <4cef08f0$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: <71457b9a-2299-498d-bd5b-aef361011c5f@i10g2000prd.googlegroups.com> On Nov 26, 1:10?am, Steven D'Aprano wrote: > On Thu, 25 Nov 2010 08:15:21 -0800, Yingjie Lan wrote: > > Intuition #1: as if you raise an exception type, and then match that > > type. > > It seems that no instances > > are involved here (Intuitively). > > Your intuition is not my intuition, nor does it match what Python > actually does. You can only go so far on *guessing* what a programming > statement does, sometimes you need to actually read the Fine Manual. > > > See an example code here: > > > try: raise KeyError > > except KeyError: pass > > As the documentation states, this creates an instance of KeyError. > > ? ? raise evaluates the first expression as the exception object. > ? ? It must be either a subclass or an instance of BaseException. > ? ? If it is a class, the exception instance will be obtained when > ? ? needed by instantiating the class with no arguments. > > http://docs.python.org/py3k/reference/simple_stmts.html#the-raise-sta... > > So there is no semantic difference between "raise KeyError" and > "raise KeyError()". Why should there be? What practical difference would > you expect? > There *can* be a difference though. >>> raise UnicodeDecodeError Traceback (most recent call last): File "", line 1, in TypeError: function takes exactly 5 arguments (0 given) :-) > > You seem to have misunderstood both forms of the raise statement. Should > we make exceptions illegal because you can't correctly guess what they do? Sometimes people not being able to understand them is a good reason for making things illegal (or rather for not making them legal in the first place). I don't think it applies to this particular case though. All the best, Michael Foord -- http://www.voidspace.org.uk/ From python.list at tim.thechases.com Fri Nov 26 09:49:33 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 26 Nov 2010 08:49:33 -0600 Subject: SQLite date fields In-Reply-To: References: Message-ID: <4CEFC8FD.2050802@tim.thechases.com> On 11/26/2010 07:20 AM, Duncan Booth wrote: > Tim Roberts wrote: >> SQLite is essentially typeless. ALL fields are stored as >> strings, with no interpretation. You can store whatever you >> want in any column. The column types are basically there to >> remind YOU how to handle the data. >> > > Not all fields are stored as strings; they may also be stored > as integer, floating point values or binary data. Where the test gets funky: >>> import sqlite3 >>> conn = sqlite3.connect(':memory:') >>> c = conn.cursor() >>> c.execute('''CREATE TABLE t1 (d DATE, t TEXT, i INTEGER)''') >>> c.execute('''INSERT INTO t1 (d, t, i) VALUES ('foo', 'bar', 'baz')''') >>> c.execute('SELECT * FROM t1') >>> c.fetchall() [(u'foo', u'bar', u'baz')] Reminds me a bit of this [1] thread. -tkc [1] http://www.mail-archive.com/python-list at python.org/msg108200.html From michele.simionato at gmail.com Fri Nov 26 10:02:33 2010 From: michele.simionato at gmail.com (Michele Simionato) Date: Fri, 26 Nov 2010 07:02:33 -0800 (PST) Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> Message-ID: <926a28bb-8cab-4be7-b27b-00cfa76537f3@n2g2000pre.googlegroups.com> On Nov 24, 9:08?pm, Raymond Hettinger wrote: > So far, the only situation I can find where method names necessarily > overlap is for the basics like __init__(), close(), flush(), and > save() where multiple parents need to have their own initialization > and finalization. I do not know of other use cases either. Michele Simionato From user at compgroups.net/ Fri Nov 26 10:27:59 2010 From: user at compgroups.net/ (Oskar) Date: Fri, 26 Nov 2010 09:27:59 -0600 Subject: Help with suds: HTTP Error 401 References: Message-ID: I was having the same issue until I updated suds to the newest version. From edreamleo at gmail.com Fri Nov 26 11:04:19 2010 From: edreamleo at gmail.com (Edward K. Ream) Date: Fri, 26 Nov 2010 08:04:19 -0800 (PST) Subject: ANN: Leo 4.8 final Message-ID: Leo 4.8 final is now available at: http://sourceforge.net/project/showfiles.php?group_id=3458&package_id=29106 Leo is a text editor, data organizer, project manager and much more. See: http://webpages.charter.net/edreamleo/intro.html The highlights of Leo 4.8: -------------------------- - Leo now uses the simplest possible sentinel lines in external files. External files with sentinels now look like Emacs org-mode files. - Leo Qt gui now supports Drag and Drop. This was one of the most frequently requested features. - Improved abbreviation commands. You now define abbreviations in Leo settings nodes, not external files. - @url nodes may contain url's in body text. This allows headlines to contain summaries: very useful. - Leo now uses PyEnchant to check spelling. - Leo can now open multiple files from the command line. - Leo's ancient Tangle and Untangle commands are now deprecated. This will help newbies how to learn Leo. - Leo now shows "Resurrected" and "Recovered" nodes. These protect data and show how data have changed. These fix several long-standing data-related problems. - A new "screenshots" plugin for creating slide shows with Leo. I used this plugin to create Leo's introductory slide shows. - Improved autocompletion: Ctrl-space starts a one-time completion. - A better installer. - Many bug fixes. Links: ------ Leo: http://webpages.charter.net/edreamleo/front.html Forum: http://groups.google.com/group/leo-editor Download: http://sourceforge.net/project/showfiles.php?group_id=3458 Bzr: http://code.launchpad.net/leo-editor/ Quotes: http://webpages.charter.net/edreamleo/testimonials.html Edward K. Ream November 26, 2010 From hpj at urpla.net Fri Nov 26 11:52:26 2010 From: hpj at urpla.net (Hans-Peter Jansen) Date: Fri, 26 Nov 2010 17:52:26 +0100 Subject: PyQt Installation Problem on Windows In-Reply-To: <22cf97c9-ac22-4af1-8834-7ccb1828cc47@p1g2000yqm.googlegroups.com> References: <22cf97c9-ac22-4af1-8834-7ccb1828cc47@p1g2000yqm.googlegroups.com> Message-ID: <201011261752.26972.hpj@urpla.net> On Wednesday 24 November 2010, 23:03:14 Saul Spatz wrote: > Hi, > > I've been trying to install PyQt on Windows XP Pro so that I can try > out eric ide. I used the binary windows installer for PyQt. I can > run eric as administrator, but not with my ordinary user account. By > running eric.bat with the --debug flag, I found that he crux of the > problem is that if I type > > import PyQt4 > > in the python shell, it works for both users, but if I type > > import PyQt4.QtCore > > it works for the administrator, but the non-privileged account gets > the message > > ImportError: DLL load failed: The specified module could not be > found. My WinXP installations are always a bit lacking, since I do work 97% of my time in Linux (and 2% on MacOSX), but Python 2.6.6 and PyQt 4.7.7 do work fine here as a user win XP SP3/i586. Things like what you describe usually point to broken installations (remaining manual build artefacts, unfinished installs, incomplete deinstallations, ...). Just uninstall Python and PyQt, remove everything below your Python base path, and start over (a registry check/cleanup might be worth, too). > In the file the file pyqtconfig.py from Python26\Lib\site-packages > \PyQt4 I have the line > > 'pyqt_config_args': '--confirm-license -b C:\\Python26\\Lib\\site- > packages\\PyQt4\\bin', > > I checked with a friend who uses eric, and his file does not have the > --confirm-license parameter. As far as we can tell, we followed the > same installation procedures. This is unrelated, since it is only a detail in the build process, but points to differing versions. > By the way, I have tried this with python 3.1 on the same machine > with similar results. > > I've blown a whole day playing with this, so I'd really appreciate > any help you can give me. Pete From aahz at pythoncraft.com Fri Nov 26 11:58:31 2010 From: aahz at pythoncraft.com (Aahz) Date: 26 Nov 2010 08:58:31 -0800 Subject: playful coding problems for 10 year olds References: Message-ID: In article , Daniel Fetchinson wrote: > >My niece is interested in programming and python looks like a good >choice (she already wrote a couple of lines :)) She is 10 and I thought >it would be good to have a bunch of playful coding problems for her, >stuff that she could code herself maybe after some initial help. What other interests does she have? Might Python play a role? http://micheinnz.livejournal.com/1080735.html (Agent Weasel ended up making a presentation at the NZ PyCon.) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Think of it as evolution in action." --Tony Rand From gpodevij at gmail.com Fri Nov 26 12:46:01 2010 From: gpodevij at gmail.com (=?ISO-8859-1?Q?Ga=EBtan_Podevijn?=) Date: Fri, 26 Nov 2010 18:46:01 +0100 Subject: Kind of plugin system Message-ID: Hello, Here is my problem. I need to get some informations from files stored on my filesystem, Flickr and Picasa. So the idea is to create a class (for instance, "InformationsProvider") that provides common methods for those three sources, then, for each source, I create a class that inherits from "InformationsProvider" such as "InformationsLocalProvider", "InformationsFlickrProvider" and "InformationPicasaProvider". It is clearly needed because the method to get the informations is totally different for each source (the connection with flickr or picasa for exemple). However, I'd like, in the future, to be able to add new source and thus, just add a new class that implements the methods from Provider. The thing is, I'd like to add only one class, and that the rest of the application is able to use that class without really knowing how many class there are. I'd have something like : for each provider that exists: get the informations file and if I add a new .py that implements a new provider (say Delicious of GMail), the code above takes account of the new class. It must be "dynamic". Could you help me with that ? I hope I was clear enough. Thanks a lot, Ga?tan -------------- next part -------------- An HTML attachment was scrubbed... URL: From gslindstrom at gmail.com Fri Nov 26 13:13:25 2010 From: gslindstrom at gmail.com (Greg Lindstrom) Date: Fri, 26 Nov 2010 12:13:25 -0600 Subject: Dictionaries inside out Message-ID: I am working on a project where I'm using dictionaries to hold the translations to codes (i.e., {'1':'Cheddar','2':'Ice Hockey','IL':'Thermostat Broken'}). The bulk of the application requires me to translate codes to their meaning, but it would be nice to be able to translate a meaning back to the original code as well. This seems to me like it must be a common situation that has been addresses/solved by those smarter than me. Is there, dare I say, a design pattern for this problem? Is there a better way of approaching it other than making a set of dictionaries which "mirror" the originals? FWIW, I have approximately 50 tables ranging from 2 entries to over 100. Thanks, --greg -------------- next part -------------- An HTML attachment was scrubbed... URL: From burton at userful.com Fri Nov 26 13:15:11 2010 From: burton at userful.com (Burton Samograd) Date: Fri, 26 Nov 2010 11:15:11 -0700 Subject: Dictionaries inside out References: Message-ID: Greg Lindstrom writes: > I am working on a project where I'm using dictionaries to hold the > translations to codes (i.e., {'1':'Cheddar','2':'Ice > Hockey','IL':'Thermostat Broken'}).? The bulk of the application > requires me to translate codes to their meaning, but it would be nice > to be able to translate a meaning back to the original code as well.? > This seems to me like it must be a common situation that has been > addresses/solved by those smarter than me.? Is there, dare I say, a > design pattern for this problem?? Is there a better way of approaching > it other than making a set of dictionaries which "mirror" the > originals?? FWIW, I have approximately 50 tables ranging from 2 > entries to over 100. Looks like there might be some solutions here: http://stackoverflow.com/questions/483666/python-reverse-inverse-a-mapping -- Burton Samograd From casevh at gmail.com Fri Nov 26 13:31:32 2010 From: casevh at gmail.com (casevh) Date: Fri, 26 Nov 2010 10:31:32 -0800 (PST) Subject: inverse of a matrix with Fraction entries References: <8l50ulFhb4U1@mid.individual.net> <87y68izdnh.fsf.mdw@metalzone.distorted.org.uk> <878w0hyve1.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On Nov 25, 1:28?pm, Daniel Fetchinson wrote: > Okay, I see your point and I completely agree. > Surely it will be faster to do it with integers, will give it a shot. > > Cheers, > Daniel > > -- > Psss, psss, put it down! -http://www.cafepress.com/putitdown You may want to look at using GMPY. GMPY wraps the Gnu Multiple- precision library and includes support for rational arithmetic. I just tested a few calculations involving rational numbers with hundreds to thousands of digits and GMPY's mpq type was between 10x and 100x faster than fractions.Fractions. GMPY is availabe at http://code.google.com/p/gmpy/ casevh Disclaimer: I'm the current maintainer of GMPY. From iamforufriends at gmail.com Fri Nov 26 13:39:48 2010 From: iamforufriends at gmail.com (READY 4 DATE(WIFE WITH HUSBAND)) Date: Fri, 26 Nov 2010 10:39:48 -0800 (PST) Subject: WIFE WITH HUSBEND HERE FOR DATING... ANYBODY THERE..... Message-ID: WIFE WITH HUSBEND HERE FOR DATING... ANYBODY THERE..... http://u3.co.za/m8 http://u3.co.za/m8 http://u3.co.za/m8 http://u3.co.za/m8 From gpodevij at gmail.com Fri Nov 26 13:49:48 2010 From: gpodevij at gmail.com (=?ISO-8859-1?Q?Ga=EBtan_Podevijn?=) Date: Fri, 26 Nov 2010 19:49:48 +0100 Subject: Dictionaries inside out In-Reply-To: References: Message-ID: Found in Dive in Python 3 : >>> a_dict = {'a': 1, 'b': 2, 'c': 3} >>> {value:key for key, value in a_dict.items()} {1: 'a', 2: 'b', 3: 'c'} 2010/11/26 Burton Samograd > Greg Lindstrom writes: > > > I am working on a project where I'm using dictionaries to hold the > > translations to codes (i.e., {'1':'Cheddar','2':'Ice > > Hockey','IL':'Thermostat Broken'}). The bulk of the application > > requires me to translate codes to their meaning, but it would be nice > > to be able to translate a meaning back to the original code as well. > > This seems to me like it must be a common situation that has been > > addresses/solved by those smarter than me. Is there, dare I say, a > > design pattern for this problem? Is there a better way of approaching > > it other than making a set of dictionaries which "mirror" the > > originals? FWIW, I have approximately 50 tables ranging from 2 > > entries to over 100. > > Looks like there might be some solutions here: > > http://stackoverflow.com/questions/483666/python-reverse-inverse-a-mapping > > -- > Burton Samograd > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From aahz at pythoncraft.com Fri Nov 26 14:57:03 2010 From: aahz at pythoncraft.com (Aahz) Date: 26 Nov 2010 11:57:03 -0800 Subject: a regexp riddle: re.search(r'(?:(\w+), |and (\w+))+', 'whatever a, bbb, and c') =? ('a', 'bbb', 'c') References: <00a69232-7703-48ce-8a42-b28f24946680@i32g2000pri.googlegroups.com> Message-ID: In article , Phlip wrote: > >Thanks all for playing! And as usual I forgot a critical detail: > >I'm writing a matcher for a Morelia /viridis/ Scenario step, so the >matcher must be a single regexp. Why? (You're apparently the author of Morelia, but I don't really understand it.) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Think of it as evolution in action." --Tony Rand From nagle at animats.com Fri Nov 26 14:59:49 2010 From: nagle at animats.com (John Nagle) Date: Fri, 26 Nov 2010 11:59:49 -0800 Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance In-Reply-To: <5c92a83e-9de1-4a03-828c-2cce79ce5a30@v17g2000prc.googlegroups.com> References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> <4ceef381$0$1659$742ec2ed@news.sonic.net> <5c92a83e-9de1-4a03-828c-2cce79ce5a30@v17g2000prc.googlegroups.com> Message-ID: <4cf011b9$0$1619$742ec2ed@news.sonic.net> On 11/25/2010 5:36 PM, Raymond Hettinger wrote: > On Nov 25, 3:38 pm, John Nagle wrote: > >> Best practice for this is "don't do it." Some name clashes ought >> to simply be detected as errors, rather than being given such >> complex semantics. > > That may well be true. If a coder has enough control over the classes > to be make sure they use super() in a way that supports cooperative > multiple inheritance, then they have enough control to just > rename the methods to prevent name diamond shaped name clashes. > > OTOH, sometimes you don't have control over the names if they > are magic methods or standard names like close(), save(), flush(), > __init__(), etc. I'd argue that a better implementation would require that when there's a name clash, you have to specify the class containing the name. In other words, if A is a subclass of B, then B.foo() overrides A.foo(). But if C is a subclass of A and B, and there's an A.foo() and a B.foo(), calling self.foo() in C should be an error, because it's ambiguous. You should have to specify the parent class, using "super". The same issue applies in the other direction. If A and B are subclasses of D, and A.foo() and B.foo() are defined, and D calls self.foo(), that's an ambiguity and should be reported. This catches the case where two classed both inherit from, say "threading.thread", each expecting to have a private thread. Someone then inherits from both classes, getting totally unexpected results when one of the "run" methods is chosen somewhat arbitrarily. Detecting a clash requires machinery CPython's lookup machinery currently lacks. That's why I wrote that the current semantics fell out of the implementation. Again, this is a form of global bug - each class can appear internally correct, but the combination of them won't work as expected. This is the sort of thing which produces obscure bugs when the components come from different sources. Python has relatively few dark corners like this, but this is one of them. (Although, in practice, nobody seems to use this stuff, so it may not matter.) John Nagle From nagle at animats.com Fri Nov 26 15:54:12 2010 From: nagle at animats.com (John Nagle) Date: Fri, 26 Nov 2010 12:54:12 -0800 Subject: inverse of a matrix with Fraction entries In-Reply-To: References: <8l50ulFhb4U1@mid.individual.net> Message-ID: <4cf01e79$0$1592$742ec2ed@news.sonic.net> On 11/24/2010 10:30 AM, Robert Kern wrote: > On 11/24/10 12:07 PM, Daniel Fetchinson wrote: > >> The whole story is that I have a matrix A and matrix B both of which >> have rational entries and they both have pretty crazy entries too. >> Their magnitude spans many orders of magnitude, but inverse(A)*B is an >> okay matrix and I can deal with it using floating point numbers. I >> only need this exact fraction business for inverse(A)*B (yes, a >> preconditioner would be useful :)) >> >> And I wouldn't want to write the whole matrix into a file, call Maple >> on it, parse the result, etc. >> >> So after all I might just code the inversion via Gauss elimination >> myself in a way that can deal with fractions, shouldn't be that hard. > > +1000. This is almost always the right thing to do whether you have > floats or rationals. Right. Inverting a matrix of rationals works fine. There's even a standard use for that, in theorem proving. See G. Nelson and D. C. Oppen. Simplification by cooperating decision procedures. ACM Transactions on Programming Languages and Systems, 1(2):245?257, 1979. It turns out that theorem proving for problems in rational arithmetic which use only addition, subtraction, multiplication by constants, comparisons for equal, greater and less, and the boolean operators is completely decidable. (This covers most of what programs do, especially in the parts that affect control flow.) There's a neat algorithm for solving such problems; you either get "True" or a counterexample. The algorithm uses the simplex method from linear programming, but with rational arithmetic. But that's an exotic application. For ordinary number crunching, rational arithmetic is completely inappropriate. John Nagle From sohel807 at gmail.com Fri Nov 26 16:15:50 2010 From: sohel807 at gmail.com (Akand Islam) Date: Fri, 26 Nov 2010 13:15:50 -0800 (PST) Subject: Matlab equivalent syntax in Python References: <8317f18c-f2b2-4150-9bc0-e84d75e80de2@n32g2000pre.googlegroups.com> Message-ID: <99f8ef31-646e-4e9c-912d-e607389d5191@r31g2000prg.googlegroups.com> On Nov 26, 12:37?am, Tim Roberts wrote: > Akand Islam wrote: > > >Can anyone please suggest me what will be the good way to use matlab > >equivalent of "profile clear, profile on, profile off, profile resume > >and profile viewer" in Python? > > Python has a number of ways of measuring elapsed time, including the > "timeit" module and the "trace" module. ?There's nothing that will display > the results in a pretty graph, so the answer depends on what you are after. > -- > Tim Roberts, t... at probo.com > Providenza & Boekelheide, Inc. Dear Tim Roberts, Thanks for your posting. Like, here is the following Matlab codes which I am trying to transform into Python. Here you will find "profile clear, profile on, profile off, profile resume, profile viewer, and drawnow" syntaxes. So, what will be these equivalents in Python? Regards, Akand =============================================================================================================== function x = amg_solve(GUI_HANDLES); amg_globals; str=get(GUI_HANDLES.panelText,'String'); %Check the source of the problem specification if PROB_SRC==USER_SPEC_FD %if the user finite difference matrix is to be used str=strcat(str,sprintf('\n Initializing Problem to User Specifications ')); str=strcat(str,sprintf('\n USER: Please enter your input file name at the console...')); set(GUI_HANDLES.panelText,'String',str); drawnow; amg_usersetFD; %set up globals as the user has specified them elseif PROB_SRC==USER_SPEC_FEM %if the user finite element matrix is to be used str=strcat(str,sprintf('\n Initializing Problem to User Specifications ')); str=strcat(str,sprintf('\n USER: Please enter your input file name at the console...')); set(GUI_HANDLES.panelText,'String',str); drawnow; amg_usersetFEM; %set up globals as the user has specified them elseif PROB_SRC==EXAMPLE1 %if example 1 is called for str=strcat(str,sprintf('\n Initializing Problem to Poisson Example ')); set(GUI_HANDLES.panelText,'String',str); drawnow; amg_example1; %set up globals for example 1 end profile clear; if SETUP_OPT==AT_ONCE %if user wishes to find all coarse grids up front % see "restrict.m" for what happens otherwise str=strcat(str,sprintf('\n Calling Setup Algorithm to Determine Coarse Grids ')); set(GUI_HANDLES.panelText,'String',str); drawnow; if SHOW_PROFILE==YES profile on; end amg_setup(1); %call setup algorithm if SHOW_PROFILE==YES profile off; end end INIT_RESID = norm(RHS - (A(1).matrix * X_Guess)); %get initial residual str=strcat(str,sprintf('\n 2-Norm of Initial Residual is %d ', INIT_RESID)); set(GUI_HANDLES.panelText,'String',str); drawnow; x = X_Guess; cycleCount = 1; %count the number of AMG cycles executed while (cycleCount<=CYCLES) str=strcat(str,sprintf('\n Starting AMG Cycle Number %i... ', cycleCount)); set(GUI_HANDLES.panelText,'String',str); drawnow; if SHOW_PROFILE==YES profile resume; end x = amg_cycle(cycleCount,1,RHS,x); %execute as many AMG cycles if necessary if SHOW_PROFILE==YES profile off; end str=strcat(str,sprintf('\n 2-Norm of Residual after AMG Cycle Number %i is %d ', cycleCount, norm(RH2(cycleCount,1)))); set(GUI_HANDLES.panelText,'String',str); drawnow; cycleCount=cycleCount+1; %incriment cycle count end FINAL_RESID = norm(RHS - (A(1).matrix * x)); %get initial residual str=strcat(str,sprintf('\nFinished... ')); set(GUI_HANDLES.panelText,'String',str); drawnow; if SHOW_PROFILE==YES profile viewer; end ================================================================================================================================== From tjreedy at udel.edu Fri Nov 26 16:43:28 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 26 Nov 2010 16:43:28 -0500 Subject: Dictionaries inside out In-Reply-To: References: Message-ID: On 11/26/2010 1:13 PM, Greg Lindstrom wrote: > I am working on a project where I'm using dictionaries to hold the > translations to codes (i.e., {'1':'Cheddar','2':'Ice > Hockey','IL':'Thermostat Broken'}). The bulk of the application > requires me to translate codes to their meaning, but it would be nice to > be able to translate a meaning back to the original code as well. This > seems to me like it must be a common situation that has been > addresses/solved by those smarter than me. Is there, dare I say, a > design pattern for this problem? Is there a better way of approaching > it other than making a set of dictionaries which "mirror" the > originals? FWIW, I have approximately 50 tables ranging from 2 entries > to over 100. Making 50 inverse dictionaries is trivial. Depending on your need, you might instead consider one inverse dict that maps 'meaning' to (table,code) pairs (assuming that meanings are not unique across the 50 original tables. -- Terry Jan Reedy From cs at zip.com.au Fri Nov 26 16:50:33 2010 From: cs at zip.com.au (Cameron Simpson) Date: Sat, 27 Nov 2010 08:50:33 +1100 Subject: Matlab equivalent syntax in Python In-Reply-To: <99f8ef31-646e-4e9c-912d-e607389d5191@r31g2000prg.googlegroups.com> References: <99f8ef31-646e-4e9c-912d-e607389d5191@r31g2000prg.googlegroups.com> Message-ID: <20101126215033.GA26585@cskk.homeip.net> On 26Nov2010 13:15, Akand Islam wrote: | Thanks for your posting. Like, here is the following Matlab codes | which I am trying to transform into Python. Here you | will find "profile clear, profile on, profile off, profile resume, | profile viewer, and drawnow" syntaxes. So, what will be these | equivalents | in Python? I would start by looking at the "profile" python module: http://docs.python.org/library/profile.html#module-profile Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Their are thre mistakes in this sentence. - Rob Ray DoD#33333 From steve+comp.lang.python at pearwood.info Fri Nov 26 17:11:01 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Nov 2010 22:11:01 GMT Subject: inverse of a matrix with Fraction entries References: <8l50ulFhb4U1@mid.individual.net> <4cf01e79$0$1592$742ec2ed@news.sonic.net> Message-ID: <4cf03075$0$29994$c3e8da3$5496439d@news.astraweb.com> On Fri, 26 Nov 2010 12:54:12 -0800, John Nagle wrote: > For ordinary number crunching, > rational arithmetic is completely inappropriate. Why? -- Steven From ben+python at benfinney.id.au Fri Nov 26 17:18:21 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 27 Nov 2010 09:18:21 +1100 Subject: Dictionaries inside out References: Message-ID: <87ipzj7mqa.fsf@benfinney.id.au> (Replying to Greg, though his original message doesn't appear at Gmane.) > Greg Lindstrom writes: > > > I am working on a project where I'm using dictionaries to hold the > > translations to codes (i.e., {'1':'Cheddar','2':'Ice > > Hockey','IL':'Thermostat Broken'}).? The bulk of the application > > requires me to translate codes to their meaning, but it would be nice > > to be able to translate a meaning back to the original code as > > well.? If the dict is small and static, and you are sure that each value is unique, I would say simply create the reverse mapping:: desc_by_code = { '1': "Cheddar", '2': "Ice Hockey", 'IL': "Thermostat Broken", } code_by_desc = dict( (desc, code) for (code, desc) in codes_to_messages.items()) > > This seems to me like it must be a common situation that has been > > addresses/solved by those smarter than me.? Is there, dare I say, a > > design pattern for this problem? Yes, a relational database. That might be too much overhead though. > > Is there a better way of approaching > > it other than making a set of dictionaries which "mirror" the > > originals?? FWIW, I have approximately 50 tables ranging from 2 > > entries to over 100. You may have crossed the threshold where a relational database becomes more useful than a bunch of dicts. SQLite is built into Python, and can store its database in memory or in a single file. If the overhead of a database layer is too much, then creating the reverse mappings automatically (as above) is simple enough and works fine. -- \ ?The double standard that exempts religious activities from | `\ almost all standards of accountability should be dismantled | _o__) once and for all.? ?Daniel Dennett, 2010-01-12 | Ben Finney From tavares at fe.up.pt Fri Nov 26 17:54:30 2010 From: tavares at fe.up.pt (tavares at fe.up.pt) Date: Fri, 26 Nov 2010 14:54:30 -0800 (PST) Subject: =?windows-1252?Q?Symposium_=93Computational_Methods_in_Image_Analysis?= =?windows-1252?Q?=94_within_the_USNCCM_11_Congress_=96_Announce_=26_Call_for_Pa?= =?windows-1252?Q?pers?= Message-ID: <57aaabd1-5654-4915-86b9-fe73e0120989@q18g2000vbk.googlegroups.com> Dear Colleague, Within the 11th U.S. National Congress on Computational Mechanics (USNCCM 11 - www.usnccm.org), to be held in Minnesota, USA, in July 25-29, 2011, we are organizing the Symposium ?Computational methods in image analysis?. Examples of some topics that will be considered in the symposium ?Computational methods in image analysis? are: Image Analysis, Objects Modeling, Image Segmentation, Matching, Shape Reconstruction, Motion and Deformation Analysis, Objects Description and Registration, Medical imaging, Software Development for Image Analysis and Grid and High Performance Computing in Image Analysis. Due to your research activities in those fields, we would like to invite you to submit your work and participate in the Symposium ?Computational methods in image analysis?. For instructions and submission, please access to the conference website at: www.usnccm.org Please note that, when submitting your work you should select the Symposium ?2.1 - Computational Methods in Image Analysis?. Important dates: - Abstract submission: November 1, 2010 - January 31, 2011; - Student poster presentation submission: December 15, 2010 - January 31, 2011; - Notifications of abstract acceptance/rejection: February 28, 2011. Kind regards, Jo?o Manuel R. S. Tavares (University of Porto, Portugal, tavares at fe.up.pt) Renato Natal Jorge (University of Porto, Portugal, rnatal at fe.up.pt) Yongjie Zhang (Carnegie Mellon University, USA, jessicaz at andrew.cmu.edu) Dinggang Shen (UNC-CH School of Medicine, USA, dgshen at med.unc.edu) (Symposium organizers) From ben+python at benfinney.id.au Fri Nov 26 18:29:15 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 27 Nov 2010 10:29:15 +1100 Subject: Dictionaries inside out References: <87ipzj7mqa.fsf@benfinney.id.au> Message-ID: <87eia77jg4.fsf@benfinney.id.au> Ben Finney writes: > code_by_desc = dict( > (desc, code) for (code, desc) in codes_to_messages.items()) Bah, I fumbled an edit. Try this:: code_by_desc = dict( (desc, code) for (code, desc) in desc_by_code.items()) -- \ ?The reason we come up with new versions is not to fix bugs. | `\ It's absolutely not.? ?Bill Gates, 1995-10-23 | _o__) | Ben Finney From mdw at distorted.org.uk Fri Nov 26 19:21:58 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Sat, 27 Nov 2010 00:21:58 +0000 Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> <4ceef381$0$1659$742ec2ed@news.sonic.net> <5c92a83e-9de1-4a03-828c-2cce79ce5a30@v17g2000prc.googlegroups.com> <4cf011b9$0$1619$742ec2ed@news.sonic.net> Message-ID: <87y68fwr89.fsf.mdw@metalzone.distorted.org.uk> John Nagle writes: > I'd argue that a better implementation would require that when there's > a name clash, you have to specify the class containing the name. In > other words, if A is a subclass of B, then B.foo() overrides > A.foo(). But if C is a subclass of A and B, and there's an A.foo() and > a B.foo(), calling self.foo() in C should be an error, because it's > ambiguous. You should have to specify the parent class, using "super". How peculiar. `super' is /specifically/ for working out dynamically which superclass to delegate behaviour to, because working it out statically isn't possible in general. > The same issue applies in the other direction. If A and B are > subclasses of D, and A.foo() and B.foo() are defined, and D calls > self.foo(), that's an ambiguity and should be reported. No it isn't. It's downward delegation, which is an essential feature of object oriented design. > @This catches the case where two classed both inherit from, say > "threading.thread", each expecting to have a private thread. Why on earth would anyone do such a bizarre thing? If you want a private thread, then attach one as an attribute. Inheriting is simply madness. > Someone then inherits from both classes, getting totally unexpected > results when one of the "run" methods is chosen somewhat arbitrarily. But only because the original design was crazy. If you make a subclass of `thread' it's because you wanted a more specific kind of thread. If you subclass two other subclasses of `thread', it's because you wanted a very specific kind of thread which included the behaviour of those other two subclasses. > Detecting a clash requires machinery CPython's lookup machinery > currently lacks. What you see as a `clash' is more likely deliberate factoring of behaviour. Again, you seem to think that C++ is, for some reason, the `one true way'. It really isn't. Actually, it's a pretty poor way. But that's not the point: the point is that there are other ways, and if you stopped whining about how Python's object system might theoretically go wrong if you try to use it like it was C++ and started thinking about how to actually make effective use of the features it offers -- features which long predate Python, and have been thought about over many years, in languages such as Zetalisp, Common Lisp, Dylan, Scheme, and variants of Smalltalk -- you might got on much better. -- [mdw] From sohel807 at gmail.com Fri Nov 26 19:23:44 2010 From: sohel807 at gmail.com (Akand Islam) Date: Fri, 26 Nov 2010 16:23:44 -0800 (PST) Subject: Matlab equivalent syntax in Python References: <99f8ef31-646e-4e9c-912d-e607389d5191@r31g2000prg.googlegroups.com> Message-ID: <42086c34-43bd-44d8-a1e3-f220f62826b0@g19g2000yqg.googlegroups.com> On Nov 26, 3:50?pm, Cameron Simpson wrote: > On 26Nov2010 13:15, Akand Islam wrote: > | Thanks for your posting. Like, here is the following Matlab codes > | which I am trying to transform into Python. Here you > | will find "profile clear, profile on, profile off, profile resume, > | profile viewer, and drawnow" syntaxes. So, what will be these > | equivalents > | in Python? > > I would start by looking at the "profile" python module: > > ?http://docs.python.org/library/profile.html#module-profile > > Cheers, > -- > Cameron Simpson DoD#743http://www.cskk.ezoshosting.com/cs/ > > Their are thre mistakes in this sentence. > ? ? ? ? - Rob Ray DoD#33333 Dear Cameron Simpson, Thanks for co-operation. I have gone through the link, however, I am not much clear. Can you please show me some python syntaxes which contain Matlab like "profile on.., drawnow.." and so forth? Regards, Akand From alan at baselinedata.co.uk Fri Nov 26 20:39:02 2010 From: alan at baselinedata.co.uk (Alan Harris-Reid) Date: Sat, 27 Nov 2010 01:39:02 +0000 Subject: SQLite date fields In-Reply-To: References: Message-ID: <4CF06136.4020400@baselinedata.co.uk> To all those who have replied on this thread - many thanks. It looks as though I've got to look further into date objects, SQLite's native date functions, detect_types, etc.. Regards, Alan From casevh at gmail.com Fri Nov 26 22:21:47 2010 From: casevh at gmail.com (casevh) Date: Fri, 26 Nov 2010 19:21:47 -0800 (PST) Subject: inverse of a matrix with Fraction entries References: <8l50ulFhb4U1@mid.individual.net> <4cf01e79$0$1592$742ec2ed@news.sonic.net> <4cf03075$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4b430ffd-8184-46ac-981d-1f25c6b4d375@w29g2000vba.googlegroups.com> On Nov 26, 2:11?pm, Steven D'Aprano wrote: > On Fri, 26 Nov 2010 12:54:12 -0800, John Nagle wrote: > > For ordinary number crunching, > > rational arithmetic is completely inappropriate. > > Why? > > -- > Steven As you perform repeated calculations with rationals, the size of the values (usually) keep growing. (Where size is measured as the length of numerator and denominator.) The speed and memory requirements are no longer constant. I coded a quick matrix inversion function and measured running times using GMPY2 rational and floating point types. For the floating point tests, I used a precision of 1000 bits. With floating point values, the running time grew as n^3. With rational values, the running time grew as n^4*ln(n). On my system, inverting a 1000x1000 matrix with 1000-bit precision floating point would take about 30 minutes. Inverting the same matrix using rationals would take a month or longer and require much more memory. But the rational solution would be exact. casevh From bloom.dax at gmail.com Fri Nov 26 23:54:06 2010 From: bloom.dax at gmail.com (Dax Bloom) Date: Fri, 26 Nov 2010 20:54:06 -0800 (PST) Subject: Using Python for a demonstration in historical linguistics References: <5a85f233-d463-4ef5-a045-342b83873b13@32g2000yqz.googlegroups.com> Message-ID: <99bd3100-0782-4e44-b8f6-4de8b23c693f@c39g2000yqi.googlegroups.com> On Nov 6, 6:41?am, Vlastimil Brom wrote: > 2010/11/6 Dax Bloom : > > > > > > > Hello, > > > In the framework of a project on evolutionary linguistics I wish to > > have a program to process words and simulate the effect of sound > > shift, for instance following the Rask's-Grimm's rule. I look to have > > python take a dictionary file or a string input and replace the > > consonants in it with the Grimm rule equivalent. For example: > > b? ? b ? p ? f > > d? ? d ? t ? ? > > g? ? g ? k ? x > > g?? ? g? ? k? ? x? > > If the dictionary file has the word "Abe" I want the program to > > replace the letter b with f forming the word "Afe" and write the > > result in a tabular file. How easy is it to find the python functions > > to do that? > > > Best regards, > > > Dax Bloom > > -- > >http://mail.python.org/mailman/listinfo/python-list > > Hi, > I guess, the most difficult part would be, to select appropriate > words, to apply the simple rules on (in order not to get "problems" > with Verner's Law or other special rules). > You also normally wouldn't want to chain the changes like the above, > but to keep them separated > b? ? b; p ? f (ie. *b?r?ter- > ... brother and not *p-... (at least > without the High German consonant shift)). > of course, there are also vowel changes to be dealt with and many more > peculiarities ... > > As for implementation, I guess, the simplest way might be to use > regular expression replacements - re.sub(...) with a replace function > looking up the appropriate results in a dictionary. > maybe something along the lines: > > ######################################## > > Rask_Grimm_re = ur"[bdgptk]??" > Rask_Grimm_dct = {u"b":u"p", u"b?": u"b", u"t": u"?", } # ... > > def repl_fn(m): > ? ? return Rask_Grimm_dct.get(m.group(), m.group()) > > ie_txt = u" b?r?ter ... " > almost_germ_txt = re.sub(Rask_Grimm_re, repl_fn, ie_txt) > print u"%s >> %s" % (ie_txt, almost_germ_txt) # vowel changes etc. TBD > > ######################################## > > ?b?r?ter ... ?>> ?br??er ... > > hth, > ? vbr Hello, Thx to every one of you for the prompt response. Resuming the thread of November 5 on evolutionary linguistics, is there a way to refer to a sub-category of text like vowels or consonants? If not, is there a way to optimize the code by creating these sub-categories? I would need to arrange substitution rules into groups because there might be a whole lot more than the ones I mentioned in the example on Rask-Grimm rule; I would like each substitution to produce a new entry and not all substitutions to result in a single entry. I want to do things in two steps (or ?passes?) and apply to the results of the group 1 of rules the rules of group 2. I understand that it could be particularly useful for the study of phonology to have a dynamic analysis system with adjustable rules; in this branch of linguistics parts of a word like the nucleus or the codas are tagged with abbreviatory notations explaining ?phonological processes? with schemas; such historical mutations of language as the metathesis, the prothesis, the anaptyxis or fusional assimilation could be included among the rules that we mentioned for the substitution. It might require the replacing of certain letters with Greek notation in applying phonological processes. What function could tag syllables, the word nucleus and the codas? How easy is it to bridge this with a more visual environment where schematic analysis can be displayed with highlights and notations such as in the phonology textbooks? To outline the goals of the program: 1) Arranging rules for substitution into groups of rules 2) Applying substitutions to string input in logic of ?Multiple pass multiple replace? 3) Returning a string for each substitution 4) Making program environment visual When quoting parts of code can you please precise where to insert them in the code and what the variables mean? Best wishes, Dax Bloom From bloom.dax at gmail.com Sat Nov 27 01:58:04 2010 From: bloom.dax at gmail.com (Dax Bloom) Date: Fri, 26 Nov 2010 22:58:04 -0800 (PST) Subject: Using Python for a demonstration in historical linguistics References: <5a85f233-d463-4ef5-a045-342b83873b13@32g2000yqz.googlegroups.com> Message-ID: On Nov 6, 6:18?am, Peter Otten <__pete... at web.de> wrote: > Peter Otten wrote: > >>>> s = """ > > ... In the framework of a project onevolutionarylinguisticsI wish to > > ... have a program to process words and simulate the effect of sound > > ... shift, for instance following the Rask's-Grimm's rule. I look to have > > ... python take a dictionary file or a string input and replace the > > ... consonants in it with the Grimm rule equivalent. For example: > > ... """ > >>>> rules = ["bpf", ("d", "t", "th"), "gkx"] > >>>> for rule in rules: > > ... ? ? rule = rule[::-1] # go back in time > > ... ? ? for i in range(len(rule)-1): > > ... ? ? ? ? ? ? s = s.replace(rule[i], rule[i+1]) > > ... > > Warning: this simple-minded approach somewhat limits the possible rules. > E. g. it fails for > > a --> b > b --> a > > >>> "abba".replace("a", "b").replace("b", "a") > > 'aaaa' > > while unicode.translate() can deal with it: > > >>> u"abba".translate({ord(u"a"): u"b", ord(u"b"): u"a"}) > > u'baab' > > Or, if you are using Python 3.x as Steven suggested: > > >>> "abba".translate({ord("a"): "b", ord("b"): "a"}) > > 'baab' > > Peter Hi Peter, I read your interesting replies 20 days ago and after several exams and a university semester, I would like to address more fully your answers to my post. However could you please clarify some of the code inputs that you suggested and in what order to insert them in the script? >>>> s = """ > > ... In the framework of a project onevolutionarylinguisticsI wish to > > ... have a program to process words and simulate the effect of sound > > ... shift, for instance following the Rask's-Grimm's rule. I look to have > > ... python take a dictionary file or a string input and replace the > > ... consonants in it with the Grimm rule equivalent. For example: > > ... """ > >>>> rules = ["bpf", ("d", "t", "th"), "gkx"] > >>>> for rule in rules: > > ... ? ? rule = rule[::-1] # go back in time > > ... ? ? for i in range(len(rule)-1): > > ... ? ? ? ? ? ? s = s.replace(rule[i], rule[i+1]) > > ... Best regards, Dax Bloom From nagle at animats.com Sat Nov 27 02:24:30 2010 From: nagle at animats.com (John Nagle) Date: Fri, 26 Nov 2010 23:24:30 -0800 Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance In-Reply-To: <87y68fwr89.fsf.mdw@metalzone.distorted.org.uk> References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> <4ceef381$0$1659$742ec2ed@news.sonic.net> <5c92a83e-9de1-4a03-828c-2cce79ce5a30@v17g2000prc.googlegroups.com> <4cf011b9$0$1619$742ec2ed@news.sonic.net> <87y68fwr89.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <4cf0b232$0$1651$742ec2ed@news.sonic.net> On 11/26/2010 4:21 PM, Mark Wooding wrote: > John Nagle writes: > >> I'd argue that a better implementation would require that when there's >> a name clash, you have to specify the class containing the name. In >> other words, if A is a subclass of B, then B.foo() overrides >> A.foo(). But if C is a subclass of A and B, and there's an A.foo() and >> a B.foo(), calling self.foo() in C should be an error, because it's >> ambiguous. You should have to specify the parent class, using "super". > > How peculiar. `super' is /specifically/ for working out dynamically > which superclass to delegate behaviour to, because working it out > statically isn't possible in general. > >> The same issue applies in the other direction. If A and B are >> subclasses of D, and A.foo() and B.foo() are defined, and D calls >> self.foo(), that's an ambiguity and should be reported. > > No it isn't. It's downward delegation, which is an essential feature of > object oriented design. > >> @This catches the case where two classed both inherit from, say >> "threading.thread", each expecting to have a private thread. > > Why on earth would anyone do such a bizarre thing? If you want a > private thread, then attach one as an attribute. Inheriting is simply > madness. This must be from someone who hasn't used threads in Python. The usual way to write a thread in Python is to subclass "threading.thread". The subclass provides a "run" function, which will be called from the new thread. > If you > stopped whining about how Python's object system might theoretically go > wrong if you try to use it like it was C++ and started thinking about > how to actually make effective use of the features it offers -- features > which long predate Python, and have been thought about over many years, > in languages such as Zetalisp, Common Lisp, Dylan, Scheme, and variants > of Smalltalk -- you might got on much better. Ah, fanboys. Of those, I've written code in Common Lisp, Scheme, and Smalltalk. Most of the LISP variants really did objects very well; objects were an afterthought. Smalltalk went a bit too far in the other direction; the "everything is an object" mindset was overdoing it. Python is reasonably well balanced in the object area. Everything isn't an object. There are explicit classes, unlike the instance-copying model of Self and Javascript. However, multiple inheritance is something of a mess, as the original starter of this thread found when he tried to document how to use it. If you have real trouble writing documentation for a feature, it's usually because the feature is badly designed. John Nagle From user at compgroups.net/ Sat Nov 27 04:00:35 2010 From: user at compgroups.net/ (TuckerTherese) Date: Sat, 27 Nov 2010 03:00:35 -0600 Subject: Newbie question about python garbage collection when keeping only a reference to an object's member References: Message-ID: Some specialists tell that
loan help people to live their own way, because they are able to feel free to buy necessary things. Moreover, various banks offer small business loan for young and old people. From rainer.mansfeld at gmail.com Sat Nov 27 04:37:52 2010 From: rainer.mansfeld at gmail.com (Rainer Mansfeld) Date: Sat, 27 Nov 2010 10:37:52 +0100 Subject: Kind of plugin system In-Reply-To: References: Message-ID: <4CF0D170.9000504@gmail.com> Am 26.11.2010 18:46, schrieb Ga??tan Podevijn: > I need to get some informations from files stored on my filesystem, Flickr > and Picasa. So the idea is to create a class (for instance, > "InformationsProvider") that provides common methods for those three > sources, then, for each source, I create a class that inherits from > "InformationsProvider" such as "InformationsLocalProvider", > "InformationsFlickrProvider" and "InformationPicasaProvider". It is clearly > needed because the method to get the informations is totally different for > each source (the connection with flickr or picasa for exemple). > > However, I'd like, in the future, to be able to add new source and thus, > just add a new class that implements the methods from Provider. The thing > is, I'd like to add only one class, and that the rest of the application is > able to use that class without really knowing how many class there are. > > I'd have something like : > for each provider that exists: get the informations file > > and if I add a new .py that implements a new provider (say Delicious of > GMail), the code above takes account of the new class. It must be "dynamic". Hello Ga?tan, if all your classes are direct descendants of InformationsProvider you might get away with looping over InformationsProvider.__subclasses__(). See http://docs.python.org/library/stdtypes.html#class.__subclasses__ Greetings Rainer From iamforufriends at gmail.com Sat Nov 27 05:24:47 2010 From: iamforufriends at gmail.com (stella(adu^lt girl 4 ad^ults only)) Date: Sat, 27 Nov 2010 02:24:47 -0800 (PST) Subject: ad^ult girl is ready for fu^ck for free... Message-ID: <73c1390e-bce0-4760-922a-6306867fed2c@u9g2000pra.googlegroups.com> ad^ult girl is ready for fu^ck for free... http://x2c.eu/5c http://x2c.eu/5c http://x2c.eu/5c http://x2c.eu/5c http://x2c.eu/5c From mdw at distorted.org.uk Sat Nov 27 06:59:17 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Sat, 27 Nov 2010 11:59:17 +0000 Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> <4ceef381$0$1659$742ec2ed@news.sonic.net> <5c92a83e-9de1-4a03-828c-2cce79ce5a30@v17g2000prc.googlegroups.com> <4cf011b9$0$1619$742ec2ed@news.sonic.net> <87y68fwr89.fsf.mdw@metalzone.distorted.org.uk> <4cf0b232$0$1651$742ec2ed@news.sonic.net> Message-ID: <87d3prvuy2.fsf.mdw@metalzone.distorted.org.uk> John Nagle writes: > On 11/26/2010 4:21 PM, Mark Wooding wrote: > > John Nagle writes: > >> @This catches the case where two classed both inherit from, say > >> "threading.thread", each expecting to have a private thread. > > > > Why on earth would anyone do such a bizarre thing? If you want a > > private thread, then attach one as an attribute. Inheriting is simply > > madness. > > This must be from someone who hasn't used threads in Python. Wrong again. > The usual way to write a thread in Python is to subclass > "threading.thread". The subclass provides a "run" function, which > will be called from the new thread. Yes, it is. Does that conflict with what I wrote? No. If you want you class to have a private thread, make /another/ class to represent the behaviour of this private thread, and attach an instance of this to the first class. Or you can pass a closure or a bound method to the thread constructor. (That's probably cleaner, actually, but doesn't fit culturally.) > > If you stopped whining about how Python's object system might > > theoretically go wrong if you try to use it like it was C++ and > > started thinking about how to actually make effective use of the > > features it offers -- features which long predate Python, and have > > been thought about over many years, in languages such as Zetalisp, > > Common Lisp, Dylan, Scheme, and variants of Smalltalk -- you might > > got on much better. > > Ah, fanboys. Not exactly. I collect programming languages like some people collect postage stamps; it gives one a useful perspective. I mentioned those languages because they seem most historically relevant. Zetalisp's `Flavors' system introduced multiple inheritance; Common Lisp and Dylan fix the linearization properly (eventually culminating in the C3 linearization algorithm); Scheme has no standardized object system, but there are a number of -- mainly CLOS-like -- object systems available; and Smalltalk is both the classic dynamic object-oriented language and a single-dispatch contrast to the CLOS/Dylan generic-functions approach. > Of those, I've written code in Common Lisp, Scheme, and Smalltalk. > Most of the LISP variants really did objects very well; objects were > an afterthought. Smalltalk went a bit too far in the other direction; > the "everything is an object" mindset was overdoing it. CLOS actually does a remarkable integration job, bringing the existing types into the object system; but, yes, the seams are still visible, because you can't subclass some of the classes. > Python is reasonably well balanced in the object area. Everything > isn't an object. There are explicit classes, unlike the > instance-copying model of Self and Javascript. Is that a major win? Self's prototype-based approach seems quite capable of expressing anything you might want to express with classes, and a few other things besides. (The implementation works by attempting to deduce class structures dynamically, so there's an isomorphism here, of a sort, but the dynamism would make inventing classes on the fly rather inconvenient.) There's a significant difference between Javascript and Self, by the way: a Self object can have multiple `parent' slots, consequently with a form of multiple inheritance, while Javascript is limited to single inheritance (unless you fake it up). > However, multiple inheritance is something of a mess, as the original > starter of this thread found when he tried to document how to use it. Python's object system certainly isn't ideal. The main problem that I see is that dynamic delegation with `super' is hideously inconvenient to use, which means that programmers will tend towards C++'s static delegation instead. The Python object construction protocol (__new__ and __init__) is somewhat simplistic; constructing instances of multiply inherited classes in general requires a somewhat complicated dance with *args and **kw arguments -- and you lose the ability to reject unknown arguments -- which again leads to programmers taking shortcuts. Most of the rest of the object system seems pretty sound to me. > If you have real trouble writing documentation for a feature, it's > usually because the feature is badly designed. It might be that it was misunderstood. There seem to be two obvious ways of learning a programming language. One is to try and interpret its concepts in terms of concepts that you already understand. This works, but you end up having to `translate' between the new language; if the translation is imperfect then you'll be confused or frustrated. There's a constant temptation to force one's existing conceptual framework onto the new language -- to use it as if it worked just like something else one is more familiar with that doesn't quite work `right'. The new language is `broken Blub with funny syntax'. The other is to try to understand it on its own terms. This is the harder road that leads to mastery. -- [mdw] From mdw at distorted.org.uk Sat Nov 27 07:00:55 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Sat, 27 Nov 2010 12:00:55 +0000 Subject: inverse of a matrix with Fraction entries References: <8l50ulFhb4U1@mid.individual.net> <4cf01e79$0$1592$742ec2ed@news.sonic.net> <4cf03075$0$29994$c3e8da3$5496439d@news.astraweb.com> <4b430ffd-8184-46ac-981d-1f25c6b4d375@w29g2000vba.googlegroups.com> Message-ID: <878w0fvuvc.fsf.mdw@metalzone.distorted.org.uk> casevh writes: > I coded a quick matrix inversion function and measured running times > using GMPY2 rational and floating point types. For the floating point > tests, I used a precision of 1000 bits. With floating point values, > the running time grew as n^3. With rational values, the running time > grew as n^4*ln(n). Did you clear the denominators before you started? -- [mdw] From see at sig.for.address Sat Nov 27 07:42:32 2010 From: see at sig.for.address (Victor Eijkhout) Date: Sat, 27 Nov 2010 07:42:32 -0500 Subject: MATLAB to Python? References: <74f276c3-38a4-4df0-af39-7b1f2a81472e@c39g2000yqi.googlegroups.com> <40274408-8ae7-4500-983c-54714cf674d6@y23g2000yqd.googlegroups.com> Message-ID: <1jslup4.cqzxe31e28j3zN%see@sig.for.address> MATLABdude wrote: > Also the > values themselves are not identical compared to the values of the > MATLAB program. In numerical analysis there is no such thing as identical. If they differ by 1.e-10 I'd call it close enough. The difference comes from differing numerical methods. Victor. -- Victor Eijkhout -- eijkhout at tacc utexas edu From Marc-Andre.Belzile at autodesk.com Sat Nov 27 08:24:58 2010 From: Marc-Andre.Belzile at autodesk.com (Marc-Andre Belzile) Date: Sat, 27 Nov 2010 13:24:58 +0000 Subject: Kind of plugin system In-Reply-To: References: Message-ID: I guess you could just define an entry-point in your source provider files that would return a specific instance of an InformationProvider class. This entry-point would be called by your main app (maybe at startup time or during an update phase). There are plenty of articles on the web about python plugins that could help you out, such as this one: http://wehart.blogspot.com/2009/01/python-plugin-frameworks.html -mab From: python-list-bounces+marc-andre.belzile=autodesk.com at python.org [mailto:python-list-bounces+marc-andre.belzile=autodesk.com at python.org] On Behalf Of Ga?tan Podevijn Sent: Friday, November 26, 2010 12:46 PM To: python-list at python.org Subject: Kind of plugin system Hello, Here is my problem. I need to get some informations from files stored on my filesystem, Flickr and Picasa. So the idea is to create a class (for instance, "InformationsProvider") that provides common methods for those three sources, then, for each source, I create a class that inherits from "InformationsProvider" such as "InformationsLocalProvider", "InformationsFlickrProvider" and "InformationPicasaProvider". It is clearly needed because the method to get the informations is totally different for each source (the connection with flickr or picasa for exemple). However, I'd like, in the future, to be able to add new source and thus, just add a new class that implements the methods from Provider. The thing is, I'd like to add only one class, and that the rest of the application is able to use that class without really knowing how many class there are. I'd have something like : for each provider that exists: get the informations file and if I add a new .py that implements a new provider (say Delicious of GMail), the code above takes account of the new class. It must be "dynamic". Could you help me with that ? I hope I was clear enough. Thanks a lot, Ga?tan From vlastimil.brom at gmail.com Sat Nov 27 08:25:05 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sat, 27 Nov 2010 14:25:05 +0100 Subject: Using Python for a demonstration in historical linguistics In-Reply-To: <7593fb0d-2f2c-4a10-9ddd-3b35684b2da3@g19g2000yqg.googlegroups.com> References: <5a85f233-d463-4ef5-a045-342b83873b13@32g2000yqz.googlegroups.com> <7593fb0d-2f2c-4a10-9ddd-3b35684b2da3@g19g2000yqg.googlegroups.com> Message-ID: 2010/11/27 Dax Bloom : > On Nov 6, 6:41?am, Vlastimil Brom wrote: >> 2010/11/6 Dax Bloom : >> ... >> Rask_Grimm_re = ur"[bdgptk]??" >> Rask_Grimm_dct = {u"b":u"p", u"b?": u"b", u"t": u"?", } # ... >> >> def repl_fn(m): >> ? ? return Rask_Grimm_dct.get(m.group(), m.group()) >> >> ie_txt = u" b?r?ter ... " >> almost_germ_txt = re.sub(Rask_Grimm_re, repl_fn, ie_txt) >> print u"%s >> %s" % (ie_txt, almost_germ_txt) # vowel changes etc. TBD >> >> ######################################## >> >> ?b?r?ter ... ?>> ?br??er ... >> >> hth, >> ? vbr > ... > Hello Vlastimil, > > Could you please explain what the variables %s and % mean and how to > implement this part of the code in a working python program? I can't > fully appreciate Peter's quote on rules > > > Best regards, > > Dax Bloom > Hi, the mentioned part is called string interpolation; the last line is equivalent to print u"%s >> %s" % (ie_txt, almost_germ_txt) # vowel changes etc. TBD is equivalent to the simple string concatenation: print ie_txt+ u" >> " + almost_germ_txt see: http://docs.python.org/library/stdtypes.html#string-formatting-operations The values of the tuple (or eventually dict or another mapping) given after the modulo operator % are inserted at the respective positions (here %s) of the preceding string (or unicode); some more advanced adjustments or conversions are also possible here, which aren't needed in this simple case. (There is also another string formatting mechanism in the newer versions of python http://docs.python.org/library/string.html#formatstrings which may be more suitable for more complex tasks.) The implementation depends on the rest of your program and the input/output of the data, you wish to have (to be able to print the output with rather non-trivial characters, you will need the unicode enabled console (Idle is a basic one available with python). Otherwise the sample is self contained and should be runnable as is; you can add other needed items to Rask_Grimm_dct and all substrings matching Rask_Grimm_re will be replaced in one pass. You can also add a series of such replacements (re pattern and a dict of a ie: germ pairs), of course only for context-free changes. On the other hand, I have no simple idea how th deal with Verner's Law and the like (even if you passed the accents in the PIE forms); well besides a lexicographic approach, where you would have to identify the word stems to decide the changes to be applied. hth, vbr From peteRE at MpeteOzilla.Vco.ukE Sat Nov 27 10:18:46 2010 From: peteRE at MpeteOzilla.Vco.ukE (Peter Chant) Date: Sat, 27 Nov 2010 15:18:46 +0000 Subject: Convert QStingList to Python list Message-ID: The following code generates a QStringList: fileNames = QFileDialog.getOpenFileNames(None,"Chose raw file",".",) Printing it: print "Files selected "+QStringList(fileNames) Results in: TypeError: cannot concatenate 'str' and 'QStringList' objects Any idea how to convert a QStingList into a python list? pythonQtConv seems to come up in google but I've no idea how to import or invoke it. Thoughts? Pete -- http://www.petezilla.co.uk From __peter__ at web.de Sat Nov 27 10:57:07 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 27 Nov 2010 16:57:07 +0100 Subject: Convert QStingList to Python list References: Message-ID: Peter Chant wrote: > The following code generates a QStringList: > > fileNames = QFileDialog.getOpenFileNames(None,"Chose raw file",".",) > > Printing it: > > print "Files selected "+QStringList(fileNames) You say that fileNames already is a QStringList. Why are you trying to convert it to a QStringList then? Anyway, it wouldn't work with a python list either. > Results in: > > TypeError: cannot concatenate 'str' and 'QStringList' objects > > Any idea how to convert a QStingList into a python list? pythonQtConv > seems to come up in google but I've no idea how to import or invoke it. > > Thoughts? Try it out yourself in the interactive interpreter. Here's a sample session: >>> files = QStringList(["alpha.txt", "beta.txt"]) >>> print files >>> print list(files) [PyQt4.QtCore.QString(u'alpha.txt'), PyQt4.QtCore.QString(u'beta.txt')] >>> print [str(f) for f in files] ['alpha.txt', 'beta.txt'] >>> print "Selected files:", ", ".join(str(f) for f in files) Selected files: alpha.txt, beta.txt >>> files = QStringList([u"???.txt", "beta.txt"]) >>> print "Selected files:", ", ".join(str(f) for f in files) Selected files: Traceback (most recent call last): File "", line 1, in File "", line 1, in UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2: ordinal not in range(128) >>> print "Selected files:", ", ".join(unicode(f) for f in files) Selected files: ???.txt, beta.txt Peter From casevh at gmail.com Sat Nov 27 11:23:19 2010 From: casevh at gmail.com (casevh) Date: Sat, 27 Nov 2010 08:23:19 -0800 (PST) Subject: inverse of a matrix with Fraction entries References: <8l50ulFhb4U1@mid.individual.net> <4cf01e79$0$1592$742ec2ed@news.sonic.net> <4cf03075$0$29994$c3e8da3$5496439d@news.astraweb.com> <4b430ffd-8184-46ac-981d-1f25c6b4d375@w29g2000vba.googlegroups.com> <878w0fvuvc.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On Nov 27, 4:00?am, m... at distorted.org.uk (Mark Wooding) wrote: > casevh writes: > > I coded a quick matrix inversion function and measured running times > > using GMPY2 rational and floating point types. For the floating point > > tests, I used a precision of 1000 bits. With floating point values, > > the running time grew as n^3. With rational values, the running time > > grew as n^4*ln(n). > > Did you clear the denominators before you started? > > -- [mdw] No. It more of an exercise in illustrating the difference between arithmetic operations that have a constant running time versus those that have an n*ln(n) or worse running time. casevh From REMpeteOVE at petezilla.co.uk Sat Nov 27 11:38:51 2010 From: REMpeteOVE at petezilla.co.uk (Peter Chant) Date: Sat, 27 Nov 2010 16:38:51 +0000 Subject: Convert QStingList to Python list References: Message-ID: <8lcqimFubmU1@mid.individual.net> Peter Otten wrote: > > Try it out yourself in the interactive interpreter. Here's a sample > session: > Peter, thanks. I've got some way to go with python and have only just started looking at Qt, your help has been very useful. Pete -- http://www.petezilla.co.uk From raffaelcavallaro at pas.despam.s.il.vous.plait.mac.com Sat Nov 27 11:51:33 2010 From: raffaelcavallaro at pas.despam.s.il.vous.plait.mac.com (Raffael Cavallaro) Date: Sat, 27 Nov 2010 11:51:33 -0500 Subject: Scheme as a virtual machine? References: <0b9f0364-2db0-4ed3-8daa-55eec70e65fe@p26g2000yqb.googlegroups.com> <20101014020136.6e85d70b@tritium.streitmacht.eu> <20101014052650.510e8833@tritium.streitmacht.eu> <20101122053853.6ec5be33@tritium.streitmacht.eu> <08823dd4-588a-4729-a660-711e266c96b0@y23g2000yqd.googlegroups.com> <396f8de7-ece5-4e9c-919b-886eb65ae14a@a30g2000vbt.googlegroups.com> <967678a1-fc5d-4b61-86c5-79a298999582@p1g2000vbo.googlegroups.com> <18cd9337-736b-427c-9cac-14c99056750a@p1g2000yqm.googlegroups.com> <87vd3l8iy3.fsf@padme.localdomain> Message-ID: On 2010-11-25 11:30:12 -0500, Mario S. Mommer said: > In the realm of pure logic, ad hominems are logically invalid, > period. We don't live in the realm of pure logic (whatever that would mean - pretty sure no human beings exist in the realm of pure logic, so there is no homo hominis to make an ad hominem argument against in the land of pure logic...) Here in the real world, no amount of the rigid application of pure logic is going to substitute for the very necessary social skill of inferring the motives of a participant to a debate. Again, not all ad hominem arguments are ad hominem fallacies. JH has repeatedly trumpeted the virtues of languages whose adoption by others brings him financial gain, and repeatedly made pejorative statements about other languages in newsgroups for these other langauges, in a clear attempt to drum up clients for his training consultancy. Pure logic alone won't help you here; the ordinary human social skill of inferring a person's motives does. warmest regards, Ralph -- Raffael Cavallaro From anurag.chourasia at gmail.com Sat Nov 27 13:43:46 2010 From: anurag.chourasia at gmail.com (Anurag Chourasia) Date: Sun, 28 Nov 2010 00:13:46 +0530 Subject: AIX 5.3 - Enabling Shared Library Support Vs Extensions In-Reply-To: <20101125101117.GA3437@yoda.bytereef.org> References: <20101125101117.GA3437@yoda.bytereef.org> Message-ID: Hi Stefan, I followed your suggestion and configured LDFLAGS but the make step fails for another error now. My configuration options are as follows ./configure --enable-shared --disable-ipv6 --with-gcc=gcc CPPFLAGS="-I /opt/freeware/include -I /opt/freeware/include/readline -I /opt/freeware/include/ncurses" LDFLAGS="-L. -L/usr/local/lib" Below is the transcript from the make step. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ running build running build_ext ldd: /lib/libreadline.a: File is an archive. INFO: Can't locate Tcl/Tk libs and/or headers building '_struct' extension gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I. -I/u01/home/apli/wm/GDD/Python-2.6.6/./Include -I. -IInclude -I./Include -I/opt/freeware/include -I/opt/freeware/include/readline -I/opt/freeware/include/ncurses -I/usr/local/include -I/u01/home/apli/wm/GDD/Python-2.6.6/Include -I/u01/home/apli/wm/GDD/Python-2.6.6 -c /u01/home/apli/wm/GDD/Python-2.6.6/Modules/_struct.c -o build/temp.aix-5.3-2.6/u01/home/apli/wm/GDD/Python-2.6.6/Modules/_struct.o ./Modules/ld_so_aix gcc -pthread -bI:Modules/python.exp -L. -L/usr/local/lib build/temp.aix-5.3-2.6/u01/home/apli/wm/GDD/Python-2.6.6/Modules/_struct.o -L. -L/usr/local/lib -lpython2.6 -o build/lib.aix-5.3-2.6/_struct.so *Fatal Python error: Interpreter not initialized (version mismatch?)* *make: 1254-059 The signal code from the last command is 6.* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ The last command that i see above (ld_so_aix) seems to have completed as the file _struct.so exists after this command and hence I am not sure which step is failing. There is no other Python version on my machine. Please guide. On Thu, Nov 25, 2010 at 3:41 PM, Stefan Krah wrote: > Anurag Chourasia wrote: > > When I configure python to enable shared libraries, none of the > extensions are getting built during the make step due to this error. > > > > building 'cStringIO' extension > > gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall > > -Wstrict-prototypes -I. -I/u01/home/apli/wm/GDD/Python-2.6.6/./Include > -I. > > -IInclude -I./Include -I/opt/freeware/include > > -I/opt/freeware/include/readline -I/opt/freeware/include/ncurses > > -I/usr/local/include -I/u01/home/apli/wm/GDD/Python-2.6.6/Include > > -I/u01/home/apli/wm/GDD/Python-2.6.6 -c > > /u01/home/apli/wm/GDD/Python-2.6.6/Modules/cStringIO.c -o > > > build/temp.aix-5.3-2.6/u01/home/apli/wm/GDD/Python-2.6.6/Modules/cStringIO.o > > ./Modules/ld_so_aix gcc -pthread -bI:Modules/python.exp > > > build/temp.aix-5.3-2.6/u01/home/apli/wm/GDD/Python-2.6.6/Modules/cStringIO.o > > -L/usr/local/lib *-lpython2.6* -o build/lib.aix-5.3-2.6/cStringIO.so > ^^^^^^^^^^^^^^^^ > > Try these flags: -L. -L/usr/local/lib > > > If this solves the problem and the issue is also present in Python-2.7, > you should report a bug at http://bugs.python.org/ . > > > Stefan Krah > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From anurag.chourasia at gmail.com Sat Nov 27 13:45:44 2010 From: anurag.chourasia at gmail.com (Anurag Chourasia) Date: Sun, 28 Nov 2010 00:15:44 +0530 Subject: Python make fails with error "Fatal Python error: Interpreter not initialized (version mismatch?)" Message-ID: Hi All, During the make step of python, I am encountering a weird error. This is on AIX 5.3 using gcc as the compiler. My configuration options are as follows ./configure --enable-shared --disable-ipv6 --with-gcc=gcc CPPFLAGS="-I /opt/freeware/include -I /opt/freeware/include/readline -I /opt/freeware/include/ncurses" LDFLAGS="-L. -L/usr/local/lib" Below is the transcript from the make step. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ running build running build_ext ldd: /lib/libreadline.a: File is an archive. INFO: Can't locate Tcl/Tk libs and/or headers building '_struct' extension gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I. -I/u01/home/apli/wm/GDD/Python-2.6.6/./Include -I. -IInclude -I./Include -I/opt/freeware/include -I/opt/freeware/include/readline -I/opt/freeware/include/ncurses -I/usr/local/include -I/u01/home/apli/wm/GDD/Python-2.6.6/Include -I/u01/home/apli/wm/GDD/Python-2.6.6 -c /u01/home/apli/wm/GDD/Python-2.6.6/Modules/_struct.c -o build/temp.aix-5.3-2.6/u01/home/apli/wm/GDD/Python-2.6.6/Modules/_struct.o ./Modules/ld_so_aix gcc -pthread -bI:Modules/python.exp -L. -L/usr/local/lib build/temp.aix-5.3-2.6/u01/home/apli/wm/GDD/Python-2.6.6/Modules/_struct.o -L. -L/usr/local/lib -lpython2.6 -o build/lib.aix-5.3-2.6/_struct.so *Fatal Python error: Interpreter not initialized (version mismatch?)* *make: 1254-059 The signal code from the last command is 6.* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ The last command that i see above (ld_so_aix) seems to have completed as the file _struct.so exists after this command and hence I am not sure which step is failing. There is no other Python version on my machine. Please guide. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rambiusparkisanius at gmail.com Sat Nov 27 16:07:11 2010 From: rambiusparkisanius at gmail.com (rambius) Date: Sat, 27 Nov 2010 13:07:11 -0800 (PST) Subject: What's wrong with my logging configuration Message-ID: <48ac93bb-c16e-45b6-be3c-c68fb5d60cb0@t35g2000yqj.googlegroups.com> Hello, I am using python logging and as of today it stopped working. Here is my program: #!/usr/bin/env python import base64 import getpass import httplib import logging import logging.config import sys import urlparse logging.config.fileConfig('logging.config') logger = logging.getLogger(sys.argv[0]) def main(): from optparse import OptionParser usage = '%prog -u [options] ' parser = OptionParser(usage=usage) parser.add_option('-u', '--user', help='The user that will be authenticated') (options, args) = parser.parse_args() if len(args) != 1: logger.error('Please provide a url') sys.exit(1) url = args[0] if not options.user: logger.error('Please provide a user') sys.exit(2) password = getpass.getpass('Password: ') if __name__ == '__main__': main() Here is my logging.config: [loggers] keys=root [handlers] keys=console,file [formatters] keys=consolefmt,filefmt [formatter_consolefmt] format=%(name)-12s: %(levelname)-8s %(message)s class=logging.Formatter [formatter_filefmt] format=%(asctime)s %(name)-12s %(levelname)-8s %(message)s datefmt=%d/%m/%Y %H:%M:%S [handler_console] class=StreamHandler level=INFO formatter=consolefmt args=(sys.stdout,) [handler_file] class=FileHandler level=DEBUG formatter=filefmt args=('dav.log', 'a') [logger_root] level=NOTSET handlers=console,file Yesterday, it was working and I have not touched it - logging has been working for months. This morning it stopped working and I was debugging it for half a day and I am clueless. It does not the errors neither on the console nor in the log file. I will appreciate any help! Thank you in advance! Regards Rambius From rambiusparkisanius at gmail.com Sat Nov 27 16:11:55 2010 From: rambiusparkisanius at gmail.com (rambius) Date: Sat, 27 Nov 2010 13:11:55 -0800 (PST) Subject: What's wrong with my logging configuration References: <48ac93bb-c16e-45b6-be3c-c68fb5d60cb0@t35g2000yqj.googlegroups.com> Message-ID: On Nov 27, 4:07?pm, rambius wrote: > Hello, > > I am using python logging and as of today it stopped working. Here is > my program: > .... I forgot to give my environment: $ uname -a Darwin arielmac.lan 10.5.0 Darwin Kernel Version 10.5.0: Fri Nov 5 23:20:39 PDT 2010; root:xnu-1504.9.17~1/RELEASE_I386 i386 $ python -V Python 2.6.6 Regards Rambius From rambiusparkisanius at gmail.com Sat Nov 27 17:00:41 2010 From: rambiusparkisanius at gmail.com (rambius) Date: Sat, 27 Nov 2010 14:00:41 -0800 (PST) Subject: What's wrong with my logging configuration References: <48ac93bb-c16e-45b6-be3c-c68fb5d60cb0@t35g2000yqj.googlegroups.com> Message-ID: <067121ce-5ce3-480f-9d25-3cd20ac4fb26@r29g2000yqj.googlegroups.com> Hello, I was able to reproduce the problem with even a smaller program: #!/usr/bin/env python import logging import logging.config logging.config.fileConfig('logging.config') logger = logging.getLogger('test') def main(): logger.fatal('test1') import optparse logger.fatal('test2') if __name__ == '__main__': main() When I run this program the logger statement after 'import optparse' does not appear. The first logger statement before optparse does appear. Has anyone experienced similar behaviour? Regards Rambius From ben+python at benfinney.id.au Sat Nov 27 17:09:40 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 28 Nov 2010 09:09:40 +1100 Subject: What's wrong with my logging configuration References: <48ac93bb-c16e-45b6-be3c-c68fb5d60cb0@t35g2000yqj.googlegroups.com> <067121ce-5ce3-480f-9d25-3cd20ac4fb26@r29g2000yqj.googlegroups.com> Message-ID: <8739qm7717.fsf@benfinney.id.au> rambius writes: > When I run this program the logger statement after 'import optparse' > does not appear. The first logger statement before optparse does > appear. Has anyone experienced similar behaviour? I use the same config file (from your first message) and your shorter program, and I see this output: ===== test : CRITICAL test1 test : CRITICAL test2 ===== -- \ ?I have a large seashell collection, which I keep scattered on | `\ the beaches all over the world. Maybe you've seen it.? ?Steven | _o__) Wright | Ben Finney From rambiusparkisanius at gmail.com Sat Nov 27 17:25:32 2010 From: rambiusparkisanius at gmail.com (rambius) Date: Sat, 27 Nov 2010 14:25:32 -0800 (PST) Subject: What's wrong with my logging configuration References: <48ac93bb-c16e-45b6-be3c-c68fb5d60cb0@t35g2000yqj.googlegroups.com> <067121ce-5ce3-480f-9d25-3cd20ac4fb26@r29g2000yqj.googlegroups.com> <8739qm7717.fsf@benfinney.id.au> Message-ID: Hello Ben, On what environment did you try it? On Nov 27, 5:09?pm, Ben Finney wrote: > rambius writes: > > When I run this program the logger statement after 'import optparse' > > does not appear. The first logger statement before optparse does > > appear. Has anyone experienced similar behaviour? > > I use the same config file (from your first message) and your shorter > program, and I see this output: > > ===== > test ? ? ? ?: CRITICAL test1 > test ? ? ? ?: CRITICAL test2 > ===== > This is so strange. If I import optparse outside of main() it works. If I import it between the two logging statement, the second one does not appear. Regards Rambius From steve+comp.lang.python at pearwood.info Sat Nov 27 17:34:59 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 Nov 2010 22:34:59 GMT Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> <4ceef381$0$1659$742ec2ed@news.sonic.net> <5c92a83e-9de1-4a03-828c-2cce79ce5a30@v17g2000prc.googlegroups.com> <4cf011b9$0$1619$742ec2ed@news.sonic.net> <87y68fwr89.fsf.mdw@metalzone.distorted.org.uk> <4cf0b232$0$1651$742ec2ed@news.sonic.net> Message-ID: <4cf18792$0$29997$c3e8da3$5496439d@news.astraweb.com> On Fri, 26 Nov 2010 23:24:30 -0800, John Nagle wrote: > On 11/26/2010 4:21 PM, Mark Wooding wrote: [...] >>> @This catches the case where two classed both inherit from, say >>> "threading.thread", each expecting to have a private thread. >> >> Why on earth would anyone do such a bizarre thing? If you want a >> private thread, then attach one as an attribute. Inheriting is simply >> madness. > > This must be from someone who hasn't used threads in Python. > > The usual way to write a thread in Python is to subclass > "threading.thread". The subclass provides a "run" function, which will > be called from the new thread. Wanting a private thread, and writing a thread, are not the same. Of course you have to subclass threading.thread to write a thread. But if you want a private thread, there's no need to subclass thread just to get one. You would add a thread as an attribute, exactly as you would add a list or a dict or an int as an attribute if you wanted a private list or dict or int. Trying to juggle access from *multiple* classes to a *private* thread doesn't seem sensible, which was Mark's point. >> If you >> stopped whining about how Python's object system might theoretically go >> wrong if you try to use it like it was C++ and started thinking about >> how to actually make effective use of the features it offers -- >> features which long predate Python, and have been thought about over >> many years, in languages such as Zetalisp, Common Lisp, Dylan, Scheme, >> and variants of Smalltalk -- you might got on much better. > > Ah, fanboys. > > Of those, I've written code in Common Lisp, Scheme, and Smalltalk. > Most of the LISP variants really did objects very well; objects were an > afterthought. Describing something as an afterthought is normally meant as a pejorative. To say that Lisp "really did objects very well" *and* that they were afterthoughts seems like a contradiction. > Smalltalk went a bit too far in the other direction; the > "everything is an object" mindset was overdoing it. > > Python is reasonably well balanced in the object area. > Everything isn't an object. I don't understand what you mean by this. Can you give an example of a thing in Python that is not an object? > There are explicit classes, unlike the > instance-copying model of Self and Javascript. However, multiple > inheritance is something of a mess, as the original starter of this > thread found when he tried to document how to use it. > > If you have real trouble writing documentation for a feature, it's > usually because the feature is badly designed. The problem isn't writing documentation for the feature, but coming up with real-world use-cases. The documentation for super and the MRO is extensive and detailed. It's also complicated, because multiple inheritance is complicated. But it seems that multiple inheritance might not be that useful outside of a small number of cases. -- Steven From robert.kern at gmail.com Sat Nov 27 17:38:46 2010 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 27 Nov 2010 16:38:46 -0600 Subject: Matlab equivalent syntax in Python In-Reply-To: <42086c34-43bd-44d8-a1e3-f220f62826b0@g19g2000yqg.googlegroups.com> References: <99f8ef31-646e-4e9c-912d-e607389d5191@r31g2000prg.googlegroups.com> <42086c34-43bd-44d8-a1e3-f220f62826b0@g19g2000yqg.googlegroups.com> Message-ID: On 2010-11-26 18:23 , Akand Islam wrote: > On Nov 26, 3:50 pm, Cameron Simpson wrote: >> On 26Nov2010 13:15, Akand Islam wrote: >> | Thanks for your posting. Like, here is the following Matlab codes >> | which I am trying to transform into Python. Here you >> | will find "profile clear, profile on, profile off, profile resume, >> | profile viewer, and drawnow" syntaxes. So, what will be these >> | equivalents >> | in Python? >> >> I would start by looking at the "profile" python module: >> >> http://docs.python.org/library/profile.html#module-profile >> >> Cheers, >> -- >> Cameron Simpson DoD#743http://www.cskk.ezoshosting.com/cs/ >> >> Their are thre mistakes in this sentence. >> - Rob Ray DoD#33333 > > Dear Cameron Simpson, > Thanks for co-operation. I have gone through the link, however, I am > not much clear. Can you please show me some python syntaxes which > contain Matlab like "profile on.., drawnow.." and so forth? Perhaps you could explain what those MATLAB commands do. Not everyone here is familiar with MATLAB. For the most part, an API like "profile on; profile off" is inappropriate for the "profile" Python module. It profiles the times each function call takes, not each line. Turning it on and off doesn't make much sense. The API described in the above link is better for what it does. If you want to visualize the profile, you may want to try RunSnakeRun: http://www.vrplumber.com/programming/runsnakerun/ If you want line-by-line profiling, you may want to check out my package, line_profiler: http://pypi.python.org/pypi/line_profiler/ Again, we don't turn it on and off like you might do in MATLAB. Just follow the directions and give up trying to find a correspondence with the MATLAB commands. -- 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 macroasm at gmail.com Sat Nov 27 17:51:48 2010 From: macroasm at gmail.com (macroasm) Date: Sat, 27 Nov 2010 14:51:48 -0800 (PST) Subject: google group api with python Message-ID: <85a3bbf0-041f-4d67-b524-8d9db8327484@j25g2000yqa.googlegroups.com> hi. i want google group with send python. how do user api. From no.email at please.post Sat Nov 27 17:55:10 2010 From: no.email at please.post (kj) Date: Sat, 27 Nov 2010 22:55:10 +0000 (UTC) Subject: Comparing floats Message-ID: I'm defining a class (Spam) of objects that are characterized by three parameters, A, B, C, where A and C are n-tuples of floats and B is an n*n tuple-of-tuples of floats. I'm defining a limited multiplication for these objects, like this: Spam(A, B, C) * Spam(D, E, F) = Spam(A, dot(B, E), F) if and only if C == D. (Here dot(B, E) represents the matrix multiplication of B and E). In other words, this multiplication is defined only for the case where the last parameter of the first object is equal to first parameter of the second object. An exception should be thrown if one attempts to multiply two objects that fail to meet this requirement. Therefore, to implement this multiplication operation I need to have a way to verify that the float tuples C and D are "equal". Certainly, I want to do this in in a way that takes into account the fact machine computations with floats can produce small differences between numbers that are notionally the same. E.g. (in Python 2.6.1 at least): >>> 49.0 * (1.0/49.0) 0.99999999999999989 >>> 1.0 == 49.0 * (1.0/49.0) False The only approach I know of is to pick some arbitrary tolerance epsilon (e.g. 1e-6) and declare floats x and y equal iff the absolute value of x - y is less than epsilon. Does the Python standard library provide any better methods for performing such comparisons? I understand that, in Python 2.7 and 3.x >= 3.1, when the interactive shell displays a float it shows "the shortest decimal fraction that rounds correctly back to the true binary value". Is there a way to access this rounding functionality from code that must be able to run under version 2.6? (The idea would be to implement float comparison as a comparison of the rounded versions of floats.) Absent these possibilities, does Python provide any standard value of epsilon for this purpose? TIA! ~kj From steve+comp.lang.python at pearwood.info Sat Nov 27 18:08:02 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 Nov 2010 23:08:02 GMT Subject: inverse of a matrix with Fraction entries References: <8l50ulFhb4U1@mid.individual.net> <4cf01e79$0$1592$742ec2ed@news.sonic.net> <4cf03075$0$29994$c3e8da3$5496439d@news.astraweb.com> <4b430ffd-8184-46ac-981d-1f25c6b4d375@w29g2000vba.googlegroups.com> Message-ID: <4cf18f52$0$29997$c3e8da3$5496439d@news.astraweb.com> On Fri, 26 Nov 2010 19:21:47 -0800, casevh wrote: > On Nov 26, 2:11?pm, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> On Fri, 26 Nov 2010 12:54:12 -0800, John Nagle wrote: >> > For ordinary number crunching, >> > rational arithmetic is completely inappropriate. >> >> Why? >> >> -- >> Steven > As you perform repeated calculations with rationals, the size of the > values (usually) keep growing. (Where size is measured as the length of > numerator and denominator.) The speed and memory requirements are no > longer constant. You're not comparing apples with apples. You're comparing arbitrary precision calculations with fixed precision calculations. If you want fixed memory requirements, you should use fixed-precision rationals. Most rationals I know of have a method for limiting the denominator to a maximum value (even if not necessarily convenient). On the other hand, if you want infinite precision, there are floating point implementations that offer that too. How well do you think they perform relative to rationals? (Hint: what are the memory requirements for an infinite precision binary float equal to fraction(1, 3)? *wink*) Forth originally didn't offer floats, because there is nothing you can do with floats that can't be done slightly less conveniently but more accurately with a pair of integers treated as a rational. Floats, after all, *are* rationals, where the denominator is implied rather than explicit. I suspect that if rational arithmetic had been given half the attention that floating point arithmetic has been given, most of the performance difficulties would be significantly reduced. Perhaps not entirely eliminated, but I would expect that for a fixed precision calculation, we should have equivalent big-Oh behaviour, differing on the multiplicative factors. In any case, the real lesson of your benchmark is that infinite precision is quite costly, no matter how you implement it :) -- Steven From tjreedy at udel.edu Sat Nov 27 18:23:48 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 27 Nov 2010 18:23:48 -0500 Subject: Comparing floats In-Reply-To: References: Message-ID: On 11/27/2010 5:55 PM, kj wrote: > Therefore, to implement this multiplication operation I need to > have a way to verify that the float tuples C and D are "equal". I might try the average relative difference: sum(abs((i-j)/(i+j)) for i,j in zip(C,D))/n # assuming lengths constant > Certainly, I want to do this in in a way that takes into account > the fact machine computations with floats can produce small > differences between numbers that are notionally the same. The problem is that the appropriate value may depend on the application and the source of the floats. If they are measured to 3 decimal places, you need a large value. If they are calculated, you need much smaller. -- Terry Jan Reedy From rambiusparkisanius at gmail.com Sat Nov 27 18:33:24 2010 From: rambiusparkisanius at gmail.com (rambius) Date: Sat, 27 Nov 2010 15:33:24 -0800 (PST) Subject: What's wrong with my logging configuration References: <48ac93bb-c16e-45b6-be3c-c68fb5d60cb0@t35g2000yqj.googlegroups.com> <067121ce-5ce3-480f-9d25-3cd20ac4fb26@r29g2000yqj.googlegroups.com> <8739qm7717.fsf@benfinney.id.au> Message-ID: <8597a2f5-1c74-4799-b613-89656211cfed@f20g2000yqi.googlegroups.com> Hello, I found the culprit. Yesterday I added a file called copy.py. It clashed with the python built-in module copy and caused that nasty error. Regards Rambius From casevh at gmail.com Sat Nov 27 18:44:38 2010 From: casevh at gmail.com (casevh) Date: Sat, 27 Nov 2010 15:44:38 -0800 (PST) Subject: inverse of a matrix with Fraction entries References: <8l50ulFhb4U1@mid.individual.net> <4cf01e79$0$1592$742ec2ed@news.sonic.net> <4cf03075$0$29994$c3e8da3$5496439d@news.astraweb.com> <4b430ffd-8184-46ac-981d-1f25c6b4d375@w29g2000vba.googlegroups.com> <4cf18f52$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Nov 27, 3:08?pm, Steven D'Aprano wrote: > On Fri, 26 Nov 2010 19:21:47 -0800, casevh wrote: > > On Nov 26, 2:11?pm, Steven D'Aprano > +comp.lang.pyt... at pearwood.info> wrote: > >> On Fri, 26 Nov 2010 12:54:12 -0800, John Nagle wrote: > >> > For ordinary number crunching, > >> > rational arithmetic is completely inappropriate. > > >> Why? > > >> -- > >> Steven > > As you perform repeated calculations with rationals, the size of the > > values (usually) keep growing. (Where size is measured as the length of > > numerator and denominator.) The speed and memory requirements are no > > longer constant. > > You're not comparing apples with apples. You're comparing arbitrary > precision calculations with fixed precision calculations. If you want > fixed memory requirements, you should use fixed-precision rationals. Most > rationals I know of have a method for limiting the denominator to a > maximum value (even if not necessarily convenient). > > On the other hand, if you want infinite precision, there are floating > point implementations that offer that too. How well do you think they > perform relative to rationals? (Hint: what are the memory requirements > for an infinite precision binary float equal to fraction(1, 3)? *wink*) > > Forth originally didn't offer floats, because there is nothing you can do > with floats that can't be done slightly less conveniently but more > accurately with a pair of integers treated as a rational. Floats, after > all, *are* rationals, where the denominator is implied rather than > explicit. > > I suspect that if rational arithmetic had been given half the attention > that floating point arithmetic has been given, most of the performance > difficulties would be significantly reduced. Perhaps not entirely > eliminated, but I would expect that for a fixed precision calculation, we > should have equivalent big-Oh behaviour, differing on the multiplicative > factors. > > In any case, the real lesson of your benchmark is that infinite precision > is quite costly, no matter how you implement it :) > > -- > Steven I think most users are expecting infinite precision when they use rationals. Trying to explain limited precision rational arithmetic might be interesting. Knuth described "floating-slash" arithmetic that used a fixed number of bits for both the numerator and denominator and a rounding algorithm that prefers "simple" fractions versus more complex fractions. IIRC, the original paper was from the 1960s. casevh From arnodel at gmail.com Sat Nov 27 19:09:59 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Sun, 28 Nov 2010 00:09:59 +0000 Subject: Comparing floats References: Message-ID: <87d3pqtijs.fsf@gmail.com> Terry Reedy writes: > On 11/27/2010 5:55 PM, kj wrote: > >> Therefore, to implement this multiplication operation I need to >> have a way to verify that the float tuples C and D are "equal". > > I might try the average relative difference: > sum(abs((i-j)/(i+j)) for i,j in zip(C,D))/n # assuming lengths constant That'll throw an exception if i == -j. You could replace (i+j) with math.hypot(i, j) or abs(i)+abs(j) but it will still fail when i == j == 0. -- Arnaud From steve+comp.lang.python at pearwood.info Sat Nov 27 19:56:48 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 Nov 2010 00:56:48 GMT Subject: inverse of a matrix with Fraction entries References: <8l50ulFhb4U1@mid.individual.net> <4cf01e79$0$1592$742ec2ed@news.sonic.net> <4cf03075$0$29994$c3e8da3$5496439d@news.astraweb.com> <4b430ffd-8184-46ac-981d-1f25c6b4d375@w29g2000vba.googlegroups.com> <4cf18f52$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4cf1a8cf$0$29972$c3e8da3$5496439d@news.astraweb.com> On Sat, 27 Nov 2010 15:44:38 -0800, casevh wrote: > I think most users are expecting infinite precision when they use > rationals. Trying to explain limited precision rational arithmetic might > be interesting. Most users are expecting infinite precision decimals when they use floats, and get surprised and dismayed by things like these: >>> sum([0.1]*10) == 1 False >>> 0.1 + 1e50 + 0.1 - 1e50 0.0 >>> a, b, c = 0.1, 0.7, 0.3 >>> a*b + a*c == a*(b+c) False Trying to explain arithmetic on computers is interesting, no matter what you use. -- Steven From ben+python at benfinney.id.au Sat Nov 27 19:59:50 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 28 Nov 2010 11:59:50 +1100 Subject: What's wrong with my logging configuration References: <48ac93bb-c16e-45b6-be3c-c68fb5d60cb0@t35g2000yqj.googlegroups.com> <067121ce-5ce3-480f-9d25-3cd20ac4fb26@r29g2000yqj.googlegroups.com> <8739qm7717.fsf@benfinney.id.au> Message-ID: <87y68e5kl5.fsf@benfinney.id.au> rambius writes: > On what environment did you try it? I get the same results with both Python 2 and Python 3 on GNU+Linux: ===== $ python Python 2.6.6 (r266:84292, Oct 9 2010, 13:53:14) [?] $ python3 Python 3.1.3rc1 (r313rc1:86453, Nov 14 2010, 05:49:40) [?] ===== > This is so strange. If I import optparse outside of main() it works. > If I import it between the two logging statement, the second one does > not appear. Troubleshooting questions: Is there a rogue module in your project tree that, by being named the same as one of the standard library modules, shadows that module? Does the same problem behaviour occur if you import some other module in place of ?optparse?? Can you reduce the content of your ?logging.config? and still see the same problem behaviour (i.e. do you really have the minimum complete example yet)? What is the minimal config file that still results in the same behaviour for you? -- \ ?Welchen Teil von ?Gestalt? verstehen Sie nicht? [What part of | `\ ?gestalt? don't you understand?]? ?Karsten M. Self | _o__) | Ben Finney From ben+python at benfinney.id.au Sat Nov 27 20:13:40 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 28 Nov 2010 12:13:40 +1100 Subject: What's wrong with my logging configuration References: <48ac93bb-c16e-45b6-be3c-c68fb5d60cb0@t35g2000yqj.googlegroups.com> <067121ce-5ce3-480f-9d25-3cd20ac4fb26@r29g2000yqj.googlegroups.com> <8739qm7717.fsf@benfinney.id.au> <8597a2f5-1c74-4799-b613-89656211cfed@f20g2000yqi.googlegroups.com> Message-ID: <87tyj25jy3.fsf@benfinney.id.au> rambius writes: > I found the culprit. Yesterday I added a file called copy.py. It > clashed with the python built-in module copy and caused that nasty > error. You may be glad to know that newer versions of Python can distinguish absolute imports from relative imports, to address this very problem . -- \ ?I don't accept the currently fashionable assertion that any | `\ view is automatically as worthy of respect as any equal and | _o__) opposite view.? ?Douglas Adams | Ben Finney From steve+comp.lang.python at pearwood.info Sat Nov 27 20:19:31 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 Nov 2010 01:19:31 GMT Subject: Comparing floats References: Message-ID: <4cf1ae22$0$29997$c3e8da3$5496439d@news.astraweb.com> On Sat, 27 Nov 2010 22:55:10 +0000, kj wrote: [...] > Therefore, to implement this multiplication operation I need to have a > way to verify that the float tuples C and D are "equal". That C and D are tuples of floats is irrelevant. The problem boils down to testing floats for equality. It's easy to test two floats for equality, that's exactly what == does, but two floats which should be equal might not be due to calculation errors. To work around this, we loosen the definition of "equal" to give some allowance for rounding errors. Unfortunately, you need to decide what you mean by "two floats are equal", since that will depend on the semantics of your problem and data. There is no standard answer that applies everywhere. I suggest you leave it up to the user to decide what tolerance their data can support, and offer a sensible default for cases that they don't know or don't care. This might be useful for you, or at least give you some ideas: http://code.activestate.com/recipes/577124-approximately-equal/ [...] > The only approach I know of is to pick some arbitrary tolerance epsilon > (e.g. 1e-6) and declare floats x and y equal iff the absolute value of x > - y is less than epsilon. The four basic approaches are: (1) Is the absolute difference between the values <= some tolerance? (2) Is the relative difference between the values <= some tolerance? (3) Round the two values to a fixed number of decimal places, then compare for equality. This is a variation on (1) above. (4) How many differences in the least significant bits of the two values do we accept? > I understand that, in Python 2.7 and 3.x >= 3.1, when the interactive > shell displays a float it shows "the shortest decimal fraction that > rounds correctly back to the true binary value". Is there a way to > access this rounding functionality from code that must be able to run > under version 2.6? (The idea would be to implement float comparison as a > comparison of the rounded versions of floats.) How do you expect to access code in the Python 2.7 interpreter from Python 2.6? If you have 2.7 available, just use 2.7 :) It is a standard, royalty-free algorithm that you can find on the Internet somewhere. Worst case, you could copy it from the Python 2.7 source code, re-write it in Python if need be, and distribute it in your own application. But I don't think it will help you, since it isn't dealing with the fundamental problem that: * equality between two floats is well-defined, but not useful * equality given some tolerance is useful, but not well-defined (there is no tolerance that is always best, and there is no general way to decide whether absolute or relative error is more important) -- Steven From steve at holdenweb.com Sat Nov 27 21:13:24 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 27 Nov 2010 20:13:24 -0600 Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance In-Reply-To: <4cf18792$0$29997$c3e8da3$5496439d@news.astraweb.com> References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> <4ceef381$0$1659$742ec2ed@news.sonic.net> <5c92a83e-9de1-4a03-828c-2cce79ce5a30@v17g2000prc.googlegroups.com> <4cf011b9$0$1619$742ec2ed@news.sonic.net> <87y68fwr89.fsf.mdw@metalzone.distorted.org.uk> <4cf0b232$0$1651$742ec2ed@news.sonic.net> <4cf18792$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 11/27/2010 4:34 PM, Steven D'Aprano wrote: [...] > The problem isn't writing documentation for the feature, but coming up > with real-world use-cases. The documentation for super and the MRO is > extensive and detailed. It's also complicated, because multiple > inheritance is complicated. But it seems that multiple inheritance might > not be that useful outside of a small number of cases. It isn't. Even inheritance itself isn't as useful as it at first appears, and composition turns out in practice to be much more useful. That goes double for multiple inheritance. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From vithyam6 at gmail.com Sat Nov 27 21:44:55 2010 From: vithyam6 at gmail.com (cinema) Date: Sat, 27 Nov 2010 18:44:55 -0800 (PST) Subject: ANJELINA JOLIE - KATE WINSLET HOT PICTURES AND PROFILES HERE Message-ID: http://www.cinemaulagam.org http://www.cinemaulagam.org http://www.cinemaulagam.org http://www.cinemaulagam.org http://www.cinemaulagam.org From sohel807 at gmail.com Sat Nov 27 22:10:10 2010 From: sohel807 at gmail.com (Akand Islam) Date: Sat, 27 Nov 2010 19:10:10 -0800 (PST) Subject: Matlab equivalent syntax in Python References: <99f8ef31-646e-4e9c-912d-e607389d5191@r31g2000prg.googlegroups.com> <42086c34-43bd-44d8-a1e3-f220f62826b0@g19g2000yqg.googlegroups.com> Message-ID: On Nov 27, 4:38?pm, Robert Kern wrote: > On 2010-11-26 18:23 , Akand Islam wrote: > > > > > > > > > > > On Nov 26, 3:50 pm, Cameron Simpson ?wrote: > >> On 26Nov2010 13:15, Akand Islam ?wrote: > >> | Thanks for your posting. Like, here is the following Matlab codes > >> | which I am trying to transform into Python. Here you > >> | will find "profile clear, profile on, profile off, profile resume, > >> | profile viewer, and drawnow" syntaxes. So, what will be these > >> | equivalents > >> | in Python? > > >> I would start by looking at the "profile" python module: > > >> ?http://docs.python.org/library/profile.html#module-profile > > >> Cheers, > >> -- > >> Cameron Simpson ?DoD#743http://www.cskk.ezoshosting.com/cs/ > > >> Their are thre mistakes in this sentence. > >> ? ? ? ? ?- Rob Ray DoD#33333 > > > Dear Cameron Simpson, > > Thanks for co-operation. I have gone through the link, however, I am > > not much clear. Can you please show me some python syntaxes which > > contain Matlab like "profile on.., drawnow.." and so forth? > > Perhaps you could explain what those MATLAB commands do. Not everyone here is > familiar with MATLAB. For the most part, an API like "profile on; profile off" > is inappropriate for the "profile" Python module. It profiles the times each > function call takes, not each line. Turning it on and off doesn't make much > sense. The API described in the above link is better for what it does. > > If you want to visualize the profile, you may want to try RunSnakeRun: > > ? ?http://www.vrplumber.com/programming/runsnakerun/ > > If you want line-by-line profiling, you may want to check out my package, > line_profiler: > > ? ?http://pypi.python.org/pypi/line_profiler/ > > Again, we don't turn it on and off like you might do in MATLAB. Just follow the > directions and give up trying to find a correspondence with the MATLAB commands. > > -- > 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 Dear Robert Kern, I do appreciate your reply. Surely I will dig through your package. -- Akand From bhanu2srinivas at gmail.com Sat Nov 27 22:13:45 2010 From: bhanu2srinivas at gmail.com (bhanu) Date: Sat, 27 Nov 2010 19:13:45 -0800 (PST) Subject: earn 200-300% just launched new doubler 15 m ago join fast Message-ID: http://fast2double.com?bhanusri join 30$ get 5$ line bonus From benjamin at python.org Sat Nov 27 23:33:43 2010 From: benjamin at python.org (Benjamin Peterson) Date: Sat, 27 Nov 2010 22:33:43 -0600 Subject: [RELEASED] Python 2.7.1 Message-ID: On behalf of the Python development team, I'm happy as a clam to announce the immediate availability of Python 2.7.1. 2.7 includes many features that were first released in Python 3.1. The faster io module, the new nested with statement syntax, improved float repr, set literals, dictionary views, and the memoryview object have been backported from 3.1. Other features include an ordered dictionary implementation, unittests improvements, a new sysconfig module, auto-numbering of fields in the str/unicode format method, and support for ttk Tile in Tkinter. For a more extensive list of changes in 2.7, see http://doc.python.org/dev/whatsnew/2.7.html or Misc/NEWS in the Python distribution. To download Python 2.7.1 visit: http://www.python.org/download/releases/2.7.1/ The 2.7.1 changelog is at: http://svn.python.org/projects/python/tags/r271/Misc/NEWS 2.7 documentation can be found at: http://docs.python.org/2.7/ This is a production release. Please report any bugs you find to the bug tracker: http://bugs.python.org/ Enjoy! -- Benjamin Peterson Release Manager benjamin at python.org (on behalf of the entire python-dev team and 2.7.1's contributors) From benjamin at python.org Sat Nov 27 23:34:42 2010 From: benjamin at python.org (Benjamin Peterson) Date: Sat, 27 Nov 2010 22:34:42 -0600 Subject: [RELEASED] Python 3.1.3 Message-ID: On behalf of the Python development team, I'm happy as a lark to announce the third bugfix release for the Python 3.1 series, Python 3.1.3. This bug fix release features numerous bug fixes and documentation improvements over 3.1.2. The Python 3.1 version series focuses on the stabilization and optimization of the features and changes that Python 3.0 introduced. For example, the new I/O system has been rewritten in C for speed. File system APIs that use unicode strings now handle paths with undecodable bytes in them. Other features include an ordered dictionary implementation, a condensed syntax for nested with statements, and support for ttk Tile in Tkinter. For a more extensive list of changes in 3.1, see http://doc.python.org/3.1/whatsnew/3.1.html or Misc/NEWS in the Python distribution. This is a production release. To download Python 3.1.3 visit: http://www.python.org/download/releases/3.1.3/ A list of changes in 3.1.3 can be found here: http://svn.python.org/projects/python/tags/r313/Misc/NEWS The 3.1 documentation can be found at: http://docs.python.org/3.1 Bugs can always be reported to: http://bugs.python.org Enjoy! -- Benjamin Peterson Release Manager benjamin at python.org (on behalf of the entire python-dev team and 3.1.3's contributors) From chenxiangmei84 at gmail.com Sun Nov 28 02:56:30 2010 From: chenxiangmei84 at gmail.com (cntrade09) Date: Sat, 27 Nov 2010 23:56:30 -0800 (PST) Subject: Moncler Sheepskin&Feather short Down Jacket Discount Wholesale (http://www.moncler-saler.com//) Message-ID: <1eb27b3d-070f-4842-aa95-a6ff5bafbaee@k14g2000pra.googlegroups.com> Moncler long down coats brown Discount Wholesale (http://www.moncler -saler.com//) 2010 New! Moncler New Pop star Women down coat long brownDiscount Wholesale (http://www.moncler-saler.com//) Moncler 2010 Men Down cap Jacket Discount Wholesale (http://www.moncler-saler.com//) claire Down Moncler CoatsDiscount Wholesale (http://www.moncler- saler.com//) 09 Moncler Quincy WomenDiscount Wholesale (http://www.moncler- saler.com//) MONCLER - Angers belted quilt jacket Discount Wholesale (http://www.moncler-saler.com//) MONCLER - Bady quilted hooded jacket Black Discount Wholesale (http://www.moncler-saler.com//) Moncler 2010 Men Down Gray Jacket Discount Wholesale (http://www.moncler-saler.com//) Mel Hooded Parka Puffer blackDiscount Wholesale (http://www.moncler- saler.com//) MONCLER - Quilted jacket with hoodDiscount Wholesale (http://www.moncler-saler.com//) BADIA MONCLER very shinyDiscount Wholesale (http://www.moncler- saler.com//) Fashion Moncler Messina Women Down Jackets apricot Discount Wholesale (http://www.moncler-saler.com//) MONCLER - Bady quilted hooded jacket Blue Classic Monlcer purple Jackets MONCLER - Quilted jacket with hoody Moncler 2010 Men Down cap Jacket ncler 2010 Men Down Gray Jacket Moncler 2010 Men Down Jacket black Moncler Affton Jacket Discount Wholesale (http://www.moncler- saler.com//) Moncler BRANSON Down Jacket Grey Discount Wholesale (http://www.moncler-saler.com//) Moncler Branson Navy Jacket Black Discount Wholesale (http://www.moncler-saler.com//) Moncler Branson Navy Jacket Dark Bule Discount Wholesale (http://www.moncler-saler.com//) Moncler Branson Navy Jacket Red Moncler Bulgarie Jacket black Discount Wholesale (http://www.moncler- saler.com//) Moncler Chartreuse Down Jackets Grey Moncler Christmas Edition Down Jacket Black Discount Wholesale (http://www.moncler-saler.com//) Moncler Christmas Edition Down Jacket Red Discount Wholesale (http://www.moncler-saler.com//) Moncler Down Jacket Black Moncler Himalaya doudoune brillante veste taille Black Moncler Himalaya doudoune Down Jacket RedDiscount Wholesale (http://www.moncler-saler.com//) Moncler Himalaya DownJackets Blue Moncler KARAK Jackets Men purple Moncler long down coat dark blue Discount Wholesale (http://www.moncler-saler.com//) Moncler long down coats brown Discount Wholesale (http://www.moncler- saler.com//) Moncler Men Down-Hat Jacket$880.00 Save: 73% offMoncler Men Down-No Hat Jacket $238.00 Save: 70% off Discount Wholesale (http://www.moncler-saler.com//) Moncler Men Down-No Hat Jacket Discount Wholesale (http://www.moncler-saler.com//) Moncler Men Long Down Jacket Discount Wholesale (http://www.moncler- saler.com//) Moncler Opaque Sport Jacket Discount Wholesale (http://www.moncler- saler.com//) Moncler Sheepskin&Feather short Down Jacket Discount Wholesale (http://www.moncler-saler.com//) Moncler Sheepskin&Feather short Down Jacket Discount Wholesale (http://www.moncler-saler.com//) From __peter__ at web.de Sun Nov 28 03:37:34 2010 From: __peter__ at web.de (Peter Otten) Date: Sun, 28 Nov 2010 09:37:34 +0100 Subject: Comparing floats References: Message-ID: kj wrote: > I understand that, in Python 2.7 and 3.x >= 3.1, when the interactive > shell displays a float it shows "the shortest decimal fraction that > rounds correctly back to the true binary value". Is there a way > to access this rounding functionality from code that must be able > to run under version 2.6? (The idea would be to implement float > comparison as a comparison of the rounded versions of floats.) Doesn't float(str(x)) == x for all x imply that str(x) == str(y) if and only if x == y? If so, what would be the benefit of converting to string at all? From gpodevij at gmail.com Sun Nov 28 05:27:14 2010 From: gpodevij at gmail.com (=?ISO-8859-1?Q?Ga=EBtan_Podevijn?=) Date: Sun, 28 Nov 2010 11:27:14 +0100 Subject: Kind of plugin system In-Reply-To: References: Message-ID: Hello, Thank you both, I'll look at this in more depth ! Regards, Ga?tan 2010/11/27 Marc-Andre Belzile > I guess you could just define an entry-point in your source provider files > that would return a specific instance of an InformationProvider class. This > entry-point would be called by your main app (maybe at startup time or > during an update phase). > > There are plenty of articles on the web about python plugins that could > help you out, such as this one: > > http://wehart.blogspot.com/2009/01/python-plugin-frameworks.html > > -mab > > > > From: python-list-bounces+marc-andre.belzile=autodesk.com at python.org[mailto: > python-list-bounces+marc-andre.belzile > =autodesk.com at python.org] On Behalf Of Ga?tan Podevijn > Sent: Friday, November 26, 2010 12:46 PM > To: python-list at python.org > Subject: Kind of plugin system > > Hello, > > Here is my problem. > > I need to get some informations from files stored on my filesystem, Flickr > and Picasa. So the idea is to create a class (for instance, > "InformationsProvider") that provides common methods for those three > sources, then, for each source, I create a class that inherits from > "InformationsProvider" such as "InformationsLocalProvider", > "InformationsFlickrProvider" and "InformationPicasaProvider". It is clearly > needed because the method to get the informations is totally different for > each source (the connection with flickr or picasa for exemple). > > However, I'd like, in the future, to be able to add new source and thus, > just add a new class that implements the methods from Provider. The thing > is, I'd like to add only one class, and that the rest of the application is > able to use that class without really knowing how many class there are. > > I'd have something like : > for each provider that exists: get the informations file > > and if I add a new .py that implements a new provider (say Delicious of > GMail), the code above takes account of the new class. It must be "dynamic". > > Could you help me with that ? I hope I was clear enough. > > Thanks a lot, > > Ga?tan > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rustompmody at gmail.com Sun Nov 28 05:58:54 2010 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 28 Nov 2010 16:28:54 +0530 Subject: TDD in python Message-ID: Does anyone know of something like this for python? http://www.vimeo.com/13240481 From vriolk at gmail.com Sun Nov 28 07:36:26 2010 From: vriolk at gmail.com (coldpizza) Date: Sun, 28 Nov 2010 04:36:26 -0800 (PST) Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> Message-ID: <8b03c7fa-7751-4fc8-a518-caf3c9da515d@z9g2000yqz.googlegroups.com> On Nov 24, 11:08?pm, Raymond Hettinger wrote: > I'm writing-up more guidance on how to use super() and would like to > point at some real-world Python examples of cooperative multiple > inheritance. > > Google searches take me to old papers for C++ and Eiffel, but that > don't seem to be relevant to most Python programmers (i.e. a > WalkingMenu example where a submenu is both a Entry in a Menu and a > Menu itself). ?Another published example is in a graphic library where > some widgets inherit GraphicalFeature methods such as location, size > and NestingGroupingFeatures such as finding parents, siblings, and > children. ?I don't find either of those examples compelling because > there is no particular reason that they would have to have overlapping > method names. > > So far, the only situation I can find where method names necessarily > overlap is for the basics like __init__(), close(), flush(), and > save() where multiple parents need to have their own initialization > and finalization. > > If you guys know of good examples, I would appreciate a link or a > recap. > > Thanks, > > Raymond Did you try google code search? It is *not* the same as google code hosting. The site is http://www.google.com/codesearch and you can select Python in the 'language' dropdown. From mdw at distorted.org.uk Sun Nov 28 08:01:34 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Sun, 28 Nov 2010 13:01:34 +0000 Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> <4ceef381$0$1659$742ec2ed@news.sonic.net> <5c92a83e-9de1-4a03-828c-2cce79ce5a30@v17g2000prc.googlegroups.com> <4cf011b9$0$1619$742ec2ed@news.sonic.net> <87y68fwr89.fsf.mdw@metalzone.distorted.org.uk> <4cf0b232$0$1651$742ec2ed@news.sonic.net> <4cf18792$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87bp59vbyp.fsf.mdw@metalzone.distorted.org.uk> Steve Holden writes: > It isn't. Even inheritance itself isn't as useful as it at first > appears, and composition turns out in practice to be much more useful. > That goes double for multiple inheritance. Composition /with a convenient notation for delegation/ works fairly well. Indeed, this can be seen as the basis of Self. But downwards delegation -- where a superclass leaves part of its behaviour unspecified and requires (concrete) subclasses to fill in the resulting blanks -- is hard to express like this without some kind of means of identifying the original recipient of the delegated message. Once you've done that, there isn't much of a difference between a superclass and a component with implicit delegation. -- [mdw] From candide at free.invalid Sun Nov 28 09:08:45 2010 From: candide at free.invalid (candide) Date: Sun, 28 Nov 2010 15:08:45 +0100 Subject: Standard module implementation Message-ID: <4cf2626e$0$21696$426a34cc@news.free.fr> I was wondering if all the standard module are implemented in C. For instance, I can't find a C implementation for the minidom xml parser under Python 2.6. From benjamin.kaplan at case.edu Sun Nov 28 09:50:22 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sun, 28 Nov 2010 09:50:22 -0500 Subject: Standard module implementation In-Reply-To: <4cf2626e$0$21696$426a34cc@news.free.fr> References: <4cf2626e$0$21696$426a34cc@news.free.fr> Message-ID: On Sun, Nov 28, 2010 at 9:08 AM, candide wrote: > I was wondering if all the standard module are implemented in C. For > instance, I can't find a C implementation for the minidom xml parser under > Python 2.6. > -- No they aren't. A good chunk of the standard library is implemented in Python. Which is nice because Python the language isn't only implemented in C (CPython, the main implementation). It's also implemented in Java (Jython), C# (IronPython), and even in a restricted subset of Python itself (PyPy). From stefan_ml at behnel.de Sun Nov 28 09:52:45 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 28 Nov 2010 15:52:45 +0100 Subject: TDD in python In-Reply-To: References: Message-ID: Rustom Mody, 28.11.2010 11:58: > Does anyone know of something like this for python? > > http://www.vimeo.com/13240481 The page seems to require a recent version of the Flash player. Could you describe what exactly you are looking for? Stefan From news1234 at free.fr Sun Nov 28 10:05:47 2010 From: news1234 at free.fr (News123) Date: Sun, 28 Nov 2010 16:05:47 +0100 Subject: google group api with python In-Reply-To: <85a3bbf0-041f-4d67-b524-8d9db8327484@j25g2000yqa.googlegroups.com> References: <85a3bbf0-041f-4d67-b524-8d9db8327484@j25g2000yqa.googlegroups.com> Message-ID: <4cf26fcb$0$25464$426a34cc@news.free.fr> On 11/27/2010 11:51 PM, macroasm wrote: > hi. i want google group with send python. how do user api. Hi macroasm, You will probably increase tha amount of replies if you elaborate on your question. I personally do not really understand what you exactly asked for. From hejibo at gmail.com Sun Nov 28 10:06:40 2010 From: hejibo at gmail.com (He Jibo) Date: Sun, 28 Nov 2010 07:06:40 -0800 (PST) Subject: How do I get the URL of the active tab in Firefox/IE/Chrome? Message-ID: <5a3c7ec0-1a6c-411b-bee1-91f8245ce295@k22g2000yqh.googlegroups.com> Hi, I am writing a small program, which needs to get the URL of the active tab in either of firefox, internet exploerer or chrome. My need is similar as the one posted at, http://stackoverflow.com/questions/3631 ... -ie-chrome I did a lot of Googling, and get the following code. The following code can get the url of the first tab in internet explorer. My question is, how can I get the url of the current active tab? Thanks. ''' http://efreedom.com/Question/1-2555905/ ... Bar-Python http://blogs.msdn.com/b/oldnewthing/arc ... 35657.aspx http://mail.python.org/pipermail/python ... 02040.html http://code.activestate.com/recipes/302 ... lass-file/ ''' from win32com.client import Dispatch import win32api, win32con,win32gui SHELL = Dispatch("Shell.Application") def get_ie(shell): for win in shell.Windows(): # print win if win.Name == "Windows Internet Explorer": return win return None def main(): ie = get_ie(SHELL) if ie: print ie.LocationURL print ie.LocationName print ie.ReadyState print ie print ie.Document.title print ie.Document.location print ie.Document.forms # title = win32gui.GetWindowText(ie) # print title else: print "no ie window" if __name__ == '__main__': main() From vithyam6 at gmail.com Sun Nov 28 10:15:06 2010 From: vithyam6 at gmail.com (cinema) Date: Sun, 28 Nov 2010 07:15:06 -0800 (PST) Subject: HOLLYWOOD ACTRESS HOT PICTURES AND VIDEOS HERE Message-ID: http://www.cinemaulagam.org http://www.cinemaulagam.org http://www.cinemaulagam.org http://www.cinemaulagam.org http://www.cinemaulagam.org From news1234 at free.fr Sun Nov 28 10:22:33 2010 From: news1234 at free.fr (News123) Date: Sun, 28 Nov 2010 16:22:33 +0100 Subject: remote control firefox with python Message-ID: <4cf273b9$0$19685$426a74cc@news.free.fr> Hi, I wondered whether there is a simpe way to 'remote' control fire fox with python. With remote controlling I mean: - enter a url in the title bar and click on it - create a new tab - enter another url click on it - save the html document of this page - Probably the most difficult one: emulate a click or 'right click' on a certain button or link of the current page. - other interesting things would be to be able to enter the master password from a script - to enable disable proxy settings while running. The reason why I want to stay within Firefox and not use any other 'mechanize' frame work is, that the pages I want to automate might contain a lot of javascript for the construction of the actual page. Thanks in advance for any pointers ideas. From gnarlodious at gmail.com Sun Nov 28 10:35:18 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Sun, 28 Nov 2010 07:35:18 -0800 (PST) Subject: Python 3.1.3 References: Message-ID: <9ae5c47a-f5dd-4549-ac55-8527586f4f57@r14g2000prj.googlegroups.com> Don't know why, but in Terminal the uparrow now gives me: ^[[A which means I no longer have history scrolling. -- Gnarlie From perry at nomail.net.invalid Sun Nov 28 10:46:48 2010 From: perry at nomail.net.invalid (Perry Johnson) Date: Sun, 28 Nov 2010 15:46:48 +0000 (UTC) Subject: Subprocesses and Ctrl-C handling on windows Message-ID: I have a python script which spawns a subprocess that takes a few seconds to complete. If I hit Ctrl-C while the subprocess is executing, sometimes the python script and the subprocess end silently and I get back to the shell prompt and sometimes I get the KeyboardInterrupt exception. Is there any kind of method underneath this seemingly random behavior? From mohammed.php.developer at gmail.com Sun Nov 28 10:53:05 2010 From: mohammed.php.developer at gmail.com (mohammed_a_o) Date: Sun, 28 Nov 2010 07:53:05 -0800 (PST) Subject: send free sms to any mobile in the world Message-ID: <38b0b7e3-2807-4534-aeb9-ac10b8045bcd@l8g2000yqh.googlegroups.com> send free sms to any mobile in the world http://www.phpforweb.com/askany/sms.php?sms From stefan_ml at behnel.de Sun Nov 28 10:59:03 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 28 Nov 2010 16:59:03 +0100 Subject: Python 3.1.3 In-Reply-To: <9ae5c47a-f5dd-4549-ac55-8527586f4f57@r14g2000prj.googlegroups.com> References: <9ae5c47a-f5dd-4549-ac55-8527586f4f57@r14g2000prj.googlegroups.com> Message-ID: Gnarlodious, 28.11.2010 16:35: > Don't know why, but in Terminal the uparrow now gives me: > > ^[[A > > which means I no longer have history scrolling. You seem to be mailing from a Mac, is that the system you're having this problem with? Did you build Python yourself or use a provided binary? (and, if the latter, from where?) Stefan From gnarlodious at gmail.com Sun Nov 28 11:14:19 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Sun, 28 Nov 2010 08:14:19 -0800 (PST) Subject: Python 3.1.3 References: <9ae5c47a-f5dd-4549-ac55-8527586f4f57@r14g2000prj.googlegroups.com> Message-ID: <2b22dfa0-41d5-4047-8cfe-7a18e00e3760@o23g2000prh.googlegroups.com> Ah yes, sorry. This is Mac OSX 10.6.5, I did it build from the file at http://www.python.org/ftp/python/3.1.3/Python-3.1.3.tgz -- Gnarlie From roy at panix.com Sun Nov 28 11:27:36 2010 From: roy at panix.com (Roy Smith) Date: Sun, 28 Nov 2010 11:27:36 -0500 Subject: Python 3.1.3 References: <9ae5c47a-f5dd-4549-ac55-8527586f4f57@r14g2000prj.googlegroups.com> <2b22dfa0-41d5-4047-8cfe-7a18e00e3760@o23g2000prh.googlegroups.com> Message-ID: In article <2b22dfa0-41d5-4047-8cfe-7a18e00e3760 at o23g2000prh.googlegroups.com>, Gnarlodious wrote: > Ah yes, sorry. > This is Mac OSX 10.6.5, I did it build from the file at > http://www.python.org/ftp/python/3.1.3/Python-3.1.3.tgz > > -- Gnarlie I'm seeing the same behavior on a build I did of Python 3.2a4+ (py3k:86538, Nov 19 2010, 20:52:31) last week, also on 10.6.5. From the configure output, it looks like it found readline: py3k$ grep -i readline config.status D["HAVE_LIBREADLINE"]=" 1" but it's not acting like it. The Python 2.6.1 which came with the system works properly. From gnarlodious at gmail.com Sun Nov 28 11:36:56 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Sun, 28 Nov 2010 08:36:56 -0800 (PST) Subject: Python 3.1.3 References: <9ae5c47a-f5dd-4549-ac55-8527586f4f57@r14g2000prj.googlegroups.com> <2b22dfa0-41d5-4047-8cfe-7a18e00e3760@o23g2000prh.googlegroups.com> Message-ID: <53c154fa-e957-4266-ad12-eaf8c2ef3207@35g2000prt.googlegroups.com> Well I don't know what a readline is, but I upgraded from 3.1.1 and it was working fine. I might also add that the downarrow is also broken: ^[[B -- Gnarlie From nad at acm.org Sun Nov 28 11:48:36 2010 From: nad at acm.org (Ned Deily) Date: Sun, 28 Nov 2010 08:48:36 -0800 Subject: Python 3.1.3 References: <9ae5c47a-f5dd-4549-ac55-8527586f4f57@r14g2000prj.googlegroups.com> <2b22dfa0-41d5-4047-8cfe-7a18e00e3760@o23g2000prh.googlegroups.com> Message-ID: In article <2b22dfa0-41d5-4047-8cfe-7a18e00e3760 at o23g2000prh.googlegroups.com>, Gnarlodious wrote: > Ah yes, sorry. > This is Mac OSX 10.6.5, I did it build from the file at > http://www.python.org/ftp/python/3.1.3/Python-3.1.3.tgz For Python 3.1 on OS X, you'll need to supply a version of the GNU readline library, which is not supplied by Apple in OS X, during the build. Python 2.7 and 3.2 are able to make use of the BSD editline libedit which does comes with OS X. -- Ned Deily, nad at acm.org From nad at acm.org Sun Nov 28 12:03:00 2010 From: nad at acm.org (Ned Deily) Date: Sun, 28 Nov 2010 09:03:00 -0800 Subject: Python 3.1.3 References: <9ae5c47a-f5dd-4549-ac55-8527586f4f57@r14g2000prj.googlegroups.com> <2b22dfa0-41d5-4047-8cfe-7a18e00e3760@o23g2000prh.googlegroups.com> Message-ID: In article , Roy Smith wrote: > I'm seeing the same behavior on a build I did of > > Python 3.2a4+ (py3k:86538, Nov 19 2010, 20:52:31) > > last week, also on 10.6.5. From the configure output, it looks like it > found readline: > > py3k$ grep -i readline config.status > D["HAVE_LIBREADLINE"]=" 1" > > but it's not acting like it. The Python 2.6.1 which came with the > system works properly. As noted, Python 3.2 on OS X should link to the OS X copy of the BSD editline (libedit). You may have to adjust your PYTHONSTARTUP script to use the different commands. Here's a snippet from mine: try: import readline except ImportError: print("Module readline not available.") else: import rlcompleter if 'libedit' in readline.__doc__: readline.parse_and_bind("bind ^I rl_complete") else: readline.parse_and_bind("tab: complete") http://docs.python.org/py3k/library/readline.html Also, see: man 5 editrc BTW, python.org 3.2a4 installers for OS X are now available so you might not need to build your own: http://www.python.org/download/releases/3.2/ -- Ned Deily, nad at acm.org From usernet at ilthio.net Sun Nov 28 12:19:50 2010 From: usernet at ilthio.net (Tim Harig) Date: Sun, 28 Nov 2010 17:19:50 +0000 (UTC) Subject: remote control firefox with python References: <4cf273b9$0$19685$426a74cc@news.free.fr> Message-ID: On 2010-11-28, News123 wrote: > Thanks in advance for any pointers ideas. google XPCOM From dfgfh336 at gmail.com Sun Nov 28 12:24:23 2010 From: dfgfh336 at gmail.com (dgf dg) Date: Sun, 28 Nov 2010 09:24:23 -0800 (PST) Subject: nike jordan shoes coach, chane bag COOGI Message-ID: <804bee89-42b0-42b7-945f-cf932a59168d@s5g2000yqm.googlegroups.com> === http://www.stefsclothes.net === Handbags(Coach lv fendi d&g) $35 Tshirts (Polo ,ed hardy,lacoste) $16 Jean(True Religion,ed hardy,coogi) $30 Sunglasses(Oakey,coach,gucci,Armaini) $16 New era cap $15 Bikini (Ed hardy,polo) $25 ==== http://www.stefsclothes.net ==== From nagle at animats.com Sun Nov 28 13:40:14 2010 From: nagle at animats.com (John Nagle) Date: Sun, 28 Nov 2010 10:40:14 -0800 Subject: Getting current time zone in Python in tzinfo format not implemented Message-ID: <4cf2a211$0$1624$742ec2ed@news.sonic.net> Getting the local time zone in Python is rather difficult. As of 2008, two articles indicate that the current mechanisms totally suck: "Python and time zones part 2: The beast returns!": http://regebro.wordpress.com/2008/05/10/python-and-time-zones-part-2-the-beast-returns/ "Time zones in Python ? welcome to hell": http://blog.mfabrik.com/2008/06/30/relativity-of-time-shortcomings-in-python-datetime-and-workaround/ (Despite that article, there is a straightforward way to get that information in Windows: "GetDynamicTimeZoneInformation".) Did something useful ever get done about that? This ought to be in the "time" module for each platform. John Nagle From xi at gamma.dn.ua Sun Nov 28 14:22:54 2010 From: xi at gamma.dn.ua (Kirill Simonov) Date: Sun, 28 Nov 2010 14:22:54 -0500 Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance In-Reply-To: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> Message-ID: <4CF2AC0E.7030802@gamma.dn.ua> Hi Raymond, We've been using cooperative inheritance to implement stacked utilities such as WSGI middleware or connecting to a database. An example of a WSGI middleware stack: # Declare the interface and provide the default implementation. class WSGI(Utility): def __call__(self, environ, start_response): # The main WSGI application is implemented here. start_response("200 OK", [('Content-Type', 'text/plain')]) return ["Hello World!"] # GZip middleware (may be defined in a different module or a plugin) class GZIP(WSGI): # To indicate relative position in the middleware stack weights(100) def __call__(self, environ, start_response): # Call the next middleware in the stack to generate data. # Also, need to wrap start_response here... generator = super(GZIP, self).__call__(environ, start_response) # Pack the output... # Error handling middleware (defined in a different module or a plugin) class LogErrors(WSGI): weights(1000) def __call__(self, environ, start_response): # Call the next middleware in the stack, catch any errors. try: generator = super(LogErrors, self).__call__(environ, start_response) except: # Log errors... # Now glue them all together def wsgi(environ, start_response): wsgi = WSGI() # !!! return wsgi(environ, start_response) The trick here is that the constructor of `WSGI` (actually, `Utility.__new__()`) is overridden. Instead of producing a new instance of `WSGI` , it does the following: - use `__subclasses__()` to find all components of the utility; - order the components by their weights; - create a new class: `type(name, list_of_components, {})`; - return an instance of the class. Here is another example, database connection. # The interface, no default implementation. class Connect(Utility): def __init__(self, host, port, user, password, database): self.host = host self.port = port self.user = user self.password = password self.database = database def __call__(self): raise NotImplementedError() # Public API def connect(host, port, user, password, database): # Same trick here. connect = Connect(host, port, user, password, database) return connect() # PostgreSQL implementation (defined in a plugin) import psycopg2 class PGSQLConnect(Connect): def __call__(self): return psycopg2.connect(...) # Connection pooling (defined in a plugin) class Pooling(Connect): weights(100) def __call__(self): # Check if we could reuse an existing connection # ... # If no free connections available connection = super(Pooling, self).__call__() # Save it somewhere and return it... Note that utility instances are short-lived so any persistent state must be kept elsewhere. We also use the same pattern to implement Cecil/Diesel-style multimethods and general predicate dispatch, but that's probably outside the scope of your question. A public version of the code lives here: https://bitbucket.org/prometheus/htsql Unfortunately it doesn't exactly match my examples above: connection pooling and most of the wsgi middleware are still to be ported, `weights()` is missing, etc. Hope it helps. Thanks, Kirill On 11/24/2010 03:08 PM, Raymond Hettinger wrote: > I'm writing-up more guidance on how to use super() and would like to > point at some real-world Python examples of cooperative multiple > inheritance. > > Google searches take me to old papers for C++ and Eiffel, but that > don't seem to be relevant to most Python programmers (i.e. a > WalkingMenu example where a submenu is both a Entry in a Menu and a > Menu itself). Another published example is in a graphic library where > some widgets inherit GraphicalFeature methods such as location, size > and NestingGroupingFeatures such as finding parents, siblings, and > children. I don't find either of those examples compelling because > there is no particular reason that they would have to have overlapping > method names. > > So far, the only situation I can find where method names necessarily > overlap is for the basics like __init__(), close(), flush(), and > save() where multiple parents need to have their own initialization > and finalization. > > If you guys know of good examples, I would appreciate a link or a > recap. > > Thanks, > > > Raymond > From roy at panix.com Sun Nov 28 14:30:08 2010 From: roy at panix.com (Roy Smith) Date: Sun, 28 Nov 2010 14:30:08 -0500 Subject: Python 3.1.3 References: <9ae5c47a-f5dd-4549-ac55-8527586f4f57@r14g2000prj.googlegroups.com> <2b22dfa0-41d5-4047-8cfe-7a18e00e3760@o23g2000prh.googlegroups.com> <53c154fa-e957-4266-ad12-eaf8c2ef3207@35g2000prt.googlegroups.com> Message-ID: In article <53c154fa-e957-4266-ad12-eaf8c2ef3207 at 35g2000prt.googlegroups.com>, Gnarlodious wrote: > Well I don't know what a readline is, but I upgraded from 3.1.1 and it > was working fine. > > I might also add that the downarrow is also broken: ^[[B > > -- Gnarlie Readline is the (very cool) library which handles all the interactive line editing, including the up and down arrows. From tjreedy at udel.edu Sun Nov 28 14:30:24 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 28 Nov 2010 14:30:24 -0500 Subject: TDD in python In-Reply-To: References: Message-ID: On 11/28/2010 5:58 AM, Rustom Mody wrote: > Does anyone know of something like this for python? > > http://www.vimeo.com/13240481 "This is the first in a series of videos demonstrating TDD in C++ using the Eclipse CDT and CppUTest" TDD = Test-Driven Development is a development philosophy applicable to any language. It is not all that different from Hypothesis-Driven Science (HDS) (I just made that connection!) I suspect CppUTest is derived from Java JUnit (or whatever), as is Python's unittest. Python also has doctest and other public and private test frameworks and function. -- Terry Jan Reedy From perry at nomail.net.invalid Sun Nov 28 14:45:16 2010 From: perry at nomail.net.invalid (Perry Johnson) Date: Sun, 28 Nov 2010 19:45:16 +0000 (UTC) Subject: Subprocesses and Ctrl-C handling on windows References: Message-ID: On 2010-11-28, Perry Johnson wrote: > I have a python script which spawns a subprocess that takes a few > seconds to complete. If I hit Ctrl-C while the subprocess is > executing, sometimes the python script and the subprocess end silently > and I get back to the shell prompt and sometimes I get the > KeyboardInterrupt exception. Is there any kind of method underneath > this seemingly random behavior? False alarm, please disregard the quoted post. From ndparker at gmail.com Sun Nov 28 14:46:07 2010 From: ndparker at gmail.com (=?UTF-8?B?QW5kcsOp?= Malo) Date: Sun, 28 Nov 2010 20:46:07 +0100 Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> <4ceef381$0$1659$742ec2ed@news.sonic.net> <5c92a83e-9de1-4a03-828c-2cce79ce5a30@v17g2000prc.googlegroups.com> <4cf011b9$0$1619$742ec2ed@news.sonic.net> <87y68fwr89.fsf.mdw@metalzone.distorted.org.uk> <4cf0b232$0$1651$742ec2ed@news.sonic.net> <4cf18792$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <2100371.ySKtRVgNeu@news.perlig.de> * Steve Holden wrote: > Even inheritance itself isn't as useful as it at first > appears, and composition turns out in practice to be much more useful. > That goes double for multiple inheritance. Amen. nd -- my @japh = (sub{q~Just~},sub{q~Another~},sub{q~Perl~},sub{q~Hacker~}); my $japh = q[sub japh { }]; print join ######################### [ $japh =~ /{(.)}/] -> [0] => map $_ -> () # Andr? Malo # => @japh; # http://www.perlig.de/ # From usernet at ilthio.net Sun Nov 28 14:59:57 2010 From: usernet at ilthio.net (Tim Harig) Date: Sun, 28 Nov 2010 19:59:57 +0000 (UTC) Subject: How do I get the URL of the active tab in Firefox/IE/Chrome? References: <5a3c7ec0-1a6c-411b-bee1-91f8245ce295@k22g2000yqh.googlegroups.com> Message-ID: On 2010-11-28, He Jibo wrote: > I did a lot of Googling, and get the following code. The following > code can get the url of the first tab in internet explorer. My > question is, how can I get the url of the current active tab? Thanks. It would be beneficial to know what your ultimate goal is. The "InternetExplorer.Application" automation object doesn't contain any way to manipulate tabs directly; but, there are likely less direct methods of achieving whatever you are trying to accomplish if you let us know what that is. From python at bdurham.com Sun Nov 28 15:47:24 2010 From: python at bdurham.com (python at bdurham.com) Date: Sun, 28 Nov 2010 15:47:24 -0500 Subject: Using property() to extend Tkinter classes but Tkinter classes are old-style classes? Message-ID: <1290977244.17714.1407556497@webmail.messagingengine.com> I had planned on subclassing Tkinter.Toplevel() using property() to wrap access to properties like a window's title. After much head scratching and a peek at the Tkinter.py source, I realized that all Tkinter classes are old-style classes (even under Python 2.7). 1. Is there a technical reason why Tkinter classes are still old-style classes? 2. Is there a technique I can use to get property() to work with old-style classes? Or, must I use composition and wrap a reference to a Tkinter.Toplevel() window in a new style class? Thanks, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Sun Nov 28 15:54:44 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 28 Nov 2010 12:54:44 -0800 Subject: Standard module implementation In-Reply-To: <4cf2626e$0$21696$426a34cc@news.free.fr> References: <4cf2626e$0$21696$426a34cc@news.free.fr> Message-ID: On Sun, Nov 28, 2010 at 6:08 AM, candide wrote: > I was wondering if all the standard module are implemented in C. For > instance, I can't find a C implementation for the minidom xml parser under > Python 2.6. As was already said, no; a significant portion if not the majority of the std lib is written in pure Python, not C. You can usually determine how a module is implemented by looking at the file extension of the module's __file__ attribute. For example: $ python Python 2.6.6 (r266:84292, Oct 12 2010, 14:31:05) [GCC 4.2.1 (Apple Inc. build 5664)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import cPickle # obviously in C >>> cPickle.__file__ '/sw/lib/python2.6/lib-dynload/cPickle.so' >>> import pickle # pure Python version >>> pickle.__file__ '/sw/lib/python2.6/pickle.pyc' Cheers, Chris -- http://blog.rebertia.com From news1234 at free.fr Sun Nov 28 16:58:19 2010 From: news1234 at free.fr (News123) Date: Sun, 28 Nov 2010 22:58:19 +0100 Subject: remote control firefox with python In-Reply-To: References: <4cf273b9$0$19685$426a74cc@news.free.fr> Message-ID: <4cf2d07b$0$26085$426a74cc@news.free.fr> On 11/28/2010 06:19 PM, Tim Harig wrote: > On 2010-11-28, News123 wrote: >> Thanks in advance for any pointers ideas. > > google XPCOM thanks a lot From tjreedy at udel.edu Sun Nov 28 18:15:28 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 28 Nov 2010 18:15:28 -0500 Subject: Using property() to extend Tkinter classes but Tkinter classes are old-style classes? In-Reply-To: <1290977244.17714.1407556497@webmail.messagingengine.com> References: <1290977244.17714.1407556497@webmail.messagingengine.com> Message-ID: On 11/28/2010 3:47 PM, python at bdurham.com wrote: > I had planned on subclassing Tkinter.Toplevel() using property() to wrap > access to properties like a window's title. > After much head scratching and a peek at the Tkinter.py source, I > realized that all Tkinter classes are old-style classes (even under > Python 2.7). > 1. Is there a technical reason why Tkinter classes are still old-style > classes? To not break old code. Being able to break code by upgrading all classes in the stdlib was one of the reasons for 3.x. -- Terry Jan Reedy From nobody at nowhere.com Sun Nov 28 18:20:13 2010 From: nobody at nowhere.com (Nobody) Date: Sun, 28 Nov 2010 23:20:13 +0000 Subject: Comparing floats References: Message-ID: On Sat, 27 Nov 2010 18:23:48 -0500, Terry Reedy wrote: >> Therefore, to implement this multiplication operation I need to have a >> way to verify that the float tuples C and D are "equal". > > I might try the average relative difference: > sum(abs((i-j)/(i+j)) for i,j in zip(C,D))/n # assuming lengths constant The division is unstable if i and j are close to zero. For scalars, I'd use: abs(i-j) <= epsilon * (1 + abs(i+j)) This amounts to a relative error check for large values and an absolute error check for values close to zero. For a vector, I'd check that the above holds for all pairs. From hemant.dmp at gmail.com Sun Nov 28 18:36:45 2010 From: hemant.dmp at gmail.com (BansalMaddy) Date: Sun, 28 Nov 2010 15:36:45 -0800 (PST) Subject: Help required with Tranformation of coordinate system Message-ID: <1e8c75f4-e5c8-4263-9f4c-34fff241725a@t35g2000yqj.googlegroups.com> hi all! i need a help in python! i am struggling to implement this since last 2/3 days. suppose i have a 2D plot (say y=x**2). now on the same plot i want to transform my origin of coordinate system to a point (x',y' on this curve and again create a new plot with origin at x',y') can somebody help me how can i offset my cordinate system ... From goldtech at worldpost.com Sun Nov 28 18:58:19 2010 From: goldtech at worldpost.com (goldtech) Date: Sun, 28 Nov 2010 15:58:19 -0800 (PST) Subject: list of regex special characters Message-ID: <53e3530d-27b4-4d19-b96d-74429b28c119@o11g2000prf.googlegroups.com> I am looking for a list of special character in python regular expressions that need to be escaped if you want their literal meaning. I searched and can not find the list. Any help appreciated. From ben+python at benfinney.id.au Sun Nov 28 19:13:14 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 29 Nov 2010 11:13:14 +1100 Subject: list of regex special characters References: <53e3530d-27b4-4d19-b96d-74429b28c119@o11g2000prf.googlegroups.com> Message-ID: <87fwul56n9.fsf@benfinney.id.au> goldtech writes: > I am looking for a list of special character in python regular > expressions that need to be escaped if you want their literal meaning. You can avoid caring about that by using ?re.escape?, which escapes any characters in its input character that are not alphanumeric. > I searched and can not find the list. Any help appreciated. >>> import re >>> help(re) ? DESCRIPTION ? The special characters are: ? -- \ ?I got some new underwear the other day. Well, new to me.? ?Emo | `\ Philips | _o__) | Ben Finney From python.list at tim.thechases.com Sun Nov 28 19:23:46 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 28 Nov 2010 18:23:46 -0600 Subject: list of regex special characters In-Reply-To: <53e3530d-27b4-4d19-b96d-74429b28c119@o11g2000prf.googlegroups.com> References: <53e3530d-27b4-4d19-b96d-74429b28c119@o11g2000prf.googlegroups.com> Message-ID: <4CF2F292.7070105@tim.thechases.com> On 11/28/2010 05:58 PM, goldtech wrote: > I am looking for a list of special character in python regular > expressions that need to be escaped if you want their literal meaning. > > I searched and can not find the list. Any help appreciated. Trust the re module to tell you: >>> import re >>> chars = [chr(i) for i in range(0,256)] >>> escaped = [c for c in chars if re.escape(c) != c] >>> print len(escaped) 194 >>> print escaped [...] >>> can_use_unescaped = [c for c in chars if re.escape(c) == c] (adjust "chars" accordingly if you want to check unicode characters too). -tkc From ben+python at benfinney.id.au Sun Nov 28 19:49:27 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 29 Nov 2010 11:49:27 +1100 Subject: list of regex special characters References: <53e3530d-27b4-4d19-b96d-74429b28c119@o11g2000prf.googlegroups.com> Message-ID: <877hfx54yw.fsf@benfinney.id.au> Tim Chase writes: > On 11/28/2010 05:58 PM, goldtech wrote: > > I am looking for a list of special character in python regular > > expressions that need to be escaped if you want their literal > > meaning. > > Trust the re module to tell you: > > >>> import re > >>> chars = [chr(i) for i in range(0,256)] > >>> escaped = [c for c in chars if re.escape(c) != c] Note that, according to its docstring, ?re.escape? doesn't distinguish characters that *need to be* escaped for their literal meaning; it simply escapes any non-alphanumeric character. > >>> can_use_unescaped = [c for c in chars if re.escape(c) == c] Right. There are three classes of character for this purpose: * those that have a literal meaning *only if* escaped * those that have literal meaning whether or not they are escaped * those that have a literal meaning *only if not* escaped The ?re.escape? function, according to its docstring, simply says any non-alphanumerics can safely be said to exist in one of the first two classes, and both are safe to escape without bothering to distinguish between them. The OP was asking for the first class specifically, but I question whether that's actually needed for the purpose. -- \ ?The cost of education is trivial compared to the cost of | `\ ignorance.? ?Thomas Jefferson | _o__) | Ben Finney From tjreedy at udel.edu Sun Nov 28 20:03:29 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 28 Nov 2010 20:03:29 -0500 Subject: Help required with Tranformation of coordinate system In-Reply-To: <1e8c75f4-e5c8-4263-9f4c-34fff241725a@t35g2000yqj.googlegroups.com> References: <1e8c75f4-e5c8-4263-9f4c-34fff241725a@t35g2000yqj.googlegroups.com> Message-ID: On 11/28/2010 6:36 PM, BansalMaddy wrote: > hi all! > i need a help in python! i am struggling to implement this since last > 2/3 days. suppose i have a 2D plot (say y=x**2). > now on the same plot i want to transform my origin of coordinate > system to a point (x',y' on this curve and again create a new plot > with origin at x',y') > can somebody help me how can i offset my cordinate system ... Plot y-y' == (x-x')**2 - y' against x-x'. -- Terry Jan Reedy From sridatta9247 at gmail.com Sun Nov 28 21:38:25 2010 From: sridatta9247 at gmail.com (guru) Date: Sun, 28 Nov 2010 18:38:25 -0800 (PST) Subject: KARO HOT MASTI Message-ID: <9d37e093-e103-4612-891d-dfdbb6d67492@d24g2000prj.googlegroups.com> FOR HOT MASTI http://karomasti9.blogspot.com/ AMISHAPATEL HOT VIDEOS http://karomasti9.blogspot.com/search/label/amisha HANSIKHA HOT SEXY PHOTOS http://karomasti9.blogspot.com/search/label/HANSIKA HOT SEXY COLLEGE GIRLS http://karomasti9.blogspot.com/search/label/hot BEAUTIFUL LARADATTA http://karomasti9.blogspot.com/search/label/laradatta NIKISHA HOT BOOBS http://karomasti9.blogspot.com/search/label/nikisha PRIYANKA SPICY LATEST PICS http://karomasti9.blogspot.com/search/label/priyanka ONLY FOR YOUTH http://karomasti9.blogspot.com/search/label/spicy SRILEKHA UNSEENED PHOTOS http://karomasti9.blogspot.com/search/label/Srilekha CHOPRA UNBELIVABLE PHOTOS http://karomasti9.blogspot.com/search/label/chopra From sridharr at activestate.com Sun Nov 28 22:38:32 2010 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Sun, 28 Nov 2010 19:38:32 -0800 Subject: ANN: ActivePython 2.6.6.17 is now available Message-ID: ActiveState is pleased to announce ActivePython 2.6.6.17, a complete, ready-to-install binary distribution of Python 2.6. http://www.activestate.com/activepython/downloads What's New in ActivePython-2.6.6.17 =================================== *Release date: 19-Nov-2010* New Features & Upgrades ----------------------- - Security upgrade to openssl-0.9.8p - Upgrade to PyPM 1.2.5; noteworthy changes: - New command 'pypm log' to view log entries for last operation - depgraph bug fixes (Bug #88664, #88825) - Fix: ignore empty lines in requirements.txt - Ignore comments (starting with #) in the requirements file What's New in ActivePythonEE-2.6.6.16 ===================================== *Release date: 05-Nov-2010* New Features & Upgrades ----------------------- - Upgrade to PyPM 1.2.3; noteworthy changes: - Faster startup (performance) especially on Windows. - Rewrite of an improved dependency algorithm (#88038) - install/uninstall now accepts the --nodeps option - 'pypm install ' to directly download and install a .pypm file - 'pypm show' shows other installed packages depending on the shown package - 'pypm show' accepts --rdepends to show the list of dependents - 'pypm show' shows extra dependencies (for use in the 'install' cmd) - 'pypm show' lists all available versions in the repository - 'pypm freeze' to dump installed packages as requirements (like 'pip freeze') - Support for pip-stye requirements file ('pypm install -r requirements.txt') - Bug #87764: 'pypm upgrade' will not error out for missing packages - Bug #87902: fix infinite loops with cyclic package dependencies (eg: plone) - Bug #88370: Handle file-overwrite conflicts (implement --force) - Upgraded the following packages: - Distribute-0.6.14 - pip-0.8.1 - SQLAlchemy-0.6.5 - virtualenv-1.5.1 What is ActivePython? ===================== ActivePython is ActiveState's binary distribution of Python. Builds for Windows, Mac OS X, Linux are made freely available. Solaris, HP-UX and AIX builds, and access to older versions are available in ActivePython Business, Enterprise and OEM editions: http://www.activestate.com/python ActivePython includes the Python core and the many core extensions: zlib and bzip2 for data compression, the Berkeley DB (bsddb) and SQLite (sqlite3) database libraries, OpenSSL bindings for HTTPS support, the Tix GUI widgets for Tkinter, ElementTree for XML processing, ctypes (on supported platforms) for low-level library access, and others. The Windows distribution ships with PyWin32 -- a suite of Windows tools developed by Mark Hammond, including bindings to the Win32 API and Windows COM. ActivePython 2.6, 2.7 and 3.1 also include a binary package manager for Python (PyPM) that can be used to install packages much easily. For example: C:\>pypm install mysql-python [...] C:\>python >>> import MySQLdb >>> See this page for full details: http://docs.activestate.com/activepython/2.6/whatsincluded.html As well, ActivePython ships with a wealth of documentation for both new and experienced Python programmers. In addition to the core Python docs, ActivePython includes the "What's New in Python" series, "Dive into Python", the Python FAQs & HOWTOs, and the Python Enhancement Proposals (PEPs). An online version of the docs can be found here: http://docs.activestate.com/activepython/2.6/ We would welcome any and all feedback to: activepython-feedback at activestate.com Please file bugs against ActivePython at: http://bugs.activestate.com/enter_bug.cgi?product=ActivePython Supported Platforms =================== ActivePython is available for the following platforms: - Windows/x86 (32-bit) - Windows/x64 (64-bit) (aka "AMD64") - Mac OS X (32-bit and 64-bit; 10.5+) - Linux/x86 (32-bit) - Linux/x86_64 (64-bit) (aka "AMD64") - Solaris/SPARC (32-bit and 64-bit) (Business, Enterprise or OEM edition only) - Solaris/x86 (32-bit) (Business, Enterprise or OEM edition only) - HP-UX/PA-RISC (32-bit) (Business, Enterprise or OEM edition only) - HP-UX/IA-64 (32-bit and 64-bit) (Enterprise or OEM edition only) - AIX/PowerPC (32-bit and 64-bit) (Business, Enterprise or OEM edition only) More information about the Business Edition can be found here: http://www.activestate.com/business-edition Custom builds are available in the Enterprise Edition: http://www.activestate.com/enterprise-edition Thanks, and enjoy! The Python Team -- Sridhar Ratnakumar Python Developer ActiveState, The Dynamic Language Experts sridharr at activestate.com http://www.activestate.com Get insights on Open Source and Dynamic Languages at www.activestate.com/blog From timr at probo.com Sun Nov 28 23:22:15 2010 From: timr at probo.com (Tim Roberts) Date: Sun, 28 Nov 2010 20:22:15 -0800 Subject: SQLite date fields References: Message-ID: Duncan Booth wrote: >Tim Roberts wrote: > >>>However, when it comes to writing-back data to the table, SQLite is >>>very forgiving and is quite happy to store '25/06/2003' in a date >>>field, >> >> SQLite is essentially typeless. ALL fields are stored as strings, >> with no interpretation. You can store whatever you want in any >> column. The column types are basically there to remind YOU how to >> handle the data. > >Not all fields are stored as strings; they may also be stored as >integer, floating point values or binary data. Sorry. Up through SQLite version 2, ALL fields were stored as strings, even if you typed them as integers or floats. I see that has changed in v3. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From r1chardj0n3s at gmail.com Mon Nov 29 00:01:04 2010 From: r1chardj0n3s at gmail.com (Richard Jones) Date: Mon, 29 Nov 2010 16:01:04 +1100 Subject: Next Melbourne PUG meeting Monday 6th of December Message-ID: Hi all, The Melbourne Python Users Group will be meeting 6PM next Monday, the 6th of December at RMIT University. For details see http://bit.ly/mpug. From hejibo at gmail.com Mon Nov 29 00:53:52 2010 From: hejibo at gmail.com (He Jibo) Date: Sun, 28 Nov 2010 21:53:52 -0800 (PST) Subject: How do I get the URL of the active tab in Firefox/IE/Chrome? Message-ID: Hi, I am writing a small program, which needs to get the URL of the active tab in either of firefox, internet exploerer or chrome. My need is similar as the one posted at, http://stackoverflow.com/questions/3631216/how-do-i-get-the-url-of-the-visible-tab-in-firefox-ie-chrome I did a lot of Googling, and get the following code. The following code can get the url of the first tab in internet explorer. My question is, how can I get the url of the current active tab? Thanks. ''' http://efreedom.com/Question/1-2555905/Get-Internet-Explorer-Address-Bar-Python http://blogs.msdn.com/b/oldnewthing/archive/2005/07/05/435657.aspx http://mail.python.org/pipermail/python-win32/2004-June/002040.html http://code.activestate.com/recipes/302324-browser-automation-tool-py-class-file/ ''' from win32com.client import Dispatch import win32api, win32con,win32gui SHELL = Dispatch("Shell.Application") def get_ie(shell): for win in shell.Windows(): # print win if win.Name == "Windows Internet Explorer": return win return None def main(): ie = get_ie(SHELL) if ie: print ie.LocationURL print ie.LocationName print ie.ReadyState print ie print ie.Document.title print ie.Document.location print ie.Document.forms # title = win32gui.GetWindowText(ie) # print title else: print "no ie window" if __name__ == '__main__': main() From python.leojay at gmail.com Mon Nov 29 01:01:38 2010 From: python.leojay at gmail.com (Leo Jay) Date: Mon, 29 Nov 2010 14:01:38 +0800 Subject: How do you find out what's happening in a process? Message-ID: Hi all, I'd like to know how do you guys find out what's happening in your code if the process seems not work. In java, I will use jstack to check stacks of threads and lock status. But I don't know how to do it in python. -- Best Regards, Leo Jay From python at rcn.com Mon Nov 29 01:07:35 2010 From: python at rcn.com (Raymond Hettinger) Date: Sun, 28 Nov 2010 22:07:35 -0800 (PST) Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> <8b03c7fa-7751-4fc8-a518-caf3c9da515d@z9g2000yqz.googlegroups.com> Message-ID: <5ce6298b-56be-4d40-abe5-f18af83fe2b0@r31g2000prg.googlegroups.com> On Nov 28, 4:36?am, coldpizza wrote: > Did you try google code search? It is *not* the same as google code > hosting. > The site ishttp://www.google.com/codesearchand you can select Python > in the 'language' dropdown. Yes, I use Google's code search frequently and did try it for super(). However, you still need to drill into many of the hits manually, because it is difficult to disambiguate a single inheritance use of super() (which is very common) from a design with cooperative multiple inheritance. You have to read a lot of code and can still come up empty handed. Raymond From enleverLesX_XXmcX at XmclavXeauX.com.invalid Mon Nov 29 01:26:49 2010 From: enleverLesX_XXmcX at XmclavXeauX.com.invalid (Michel Claveau - MVP) Date: Mon, 29 Nov 2010 07:26:49 +0100 Subject: How do I get the URL of the active tab in Firefox/IE/Chrome? References: Message-ID: <4cf347aa$0$7701$ba4acef3@reader.news.orange.fr> Hello! > The "InternetExplorer.Application" automation object doesn't contain > any way to manipulate tabs directly False. Try this example: import win32com.client for instance in win32com.client.Dispatch('{9BA05972-F6A8-11CF-A442-00A0C90A8F39}'): print instance," URL :",instance.LocationURL @-salutations -- Michel Claveau From hemant.dmp at gmail.com Mon Nov 29 01:55:19 2010 From: hemant.dmp at gmail.com (BansalMaddy) Date: Sun, 28 Nov 2010 22:55:19 -0800 (PST) Subject: Help required with Tranformation of coordinate system References: <1e8c75f4-e5c8-4263-9f4c-34fff241725a@t35g2000yqj.googlegroups.com> Message-ID: <5f788fe7-eb82-4fb4-9476-ae95f3f89c2c@30g2000yql.googlegroups.com> On Nov 29, 2:03?am, Terry Reedy wrote: > On 11/28/2010 6:36 PM, BansalMaddy wrote: > > > hi all! > > i need a help in python! i am struggling to implement this since last > > 2/3 days. suppose i have a 2D plot (say y=x**2). > > now on the same plot i want to transform my origin of coordinate > > system to a point (x',y' on this curve and again create a new plot > > with origin at x',y') > > can somebody help me how can i offset my cordinate system ... > > Plot y-y' == (x-x')**2 - y' against x-x'. > > -- > Terry Jan Reedy Thanks for the reply, but i was looking for some built in function to offset coordinate system, because my problem is not very simple as i mentioned in my query, actually i need to plot some kind of closed loops. e..g 1. curve will be y=f(x) then i have to search for a point on y=f(x) curve and i have to plot another function y'=f(x'), where x' and y' are (-2x) and (-2y) repectively. 2. then again i hve to search for a pont on y'=f(x') and do some third kind of operations, on that. in that case if can shift my coordinate system to desired location on curve the computation becomes simpler. THanks again, hope i made myself clear :) From ben+python at benfinney.id.au Mon Nov 29 02:15:31 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 29 Nov 2010 18:15:31 +1100 Subject: Next Melbourne PUG meeting Monday 6th of December References: Message-ID: <87lj4c4n3g.fsf@benfinney.id.au> Richard Jones writes: > The Melbourne Python Users Group will be meeting 6PM next Monday, the > 6th of December at RMIT University. > > For details see http://bit.ly/mpug. Or for those who prefer their URLs to avoid unnecessary points of failure, that's . Hope to see you there! -- \ ?Killing the creator was the traditional method of patent | `\ protection? ?Terry Pratchett, _Small Gods_ | _o__) | Ben Finney From priyanka.2910 at gmail.com Mon Nov 29 02:23:24 2010 From: priyanka.2910 at gmail.com (Priyanka Kalpande) Date: Sun, 28 Nov 2010 23:23:24 -0800 (PST) Subject: Urgent requirement for Php Developer Message-ID: Urgent requirment for Python programmer. For the further details contact us on 9930698901 or eMail your resumes to hr.manager at pfhit.com From usernet at ilthio.net Mon Nov 29 02:28:24 2010 From: usernet at ilthio.net (Tim Harig) Date: Mon, 29 Nov 2010 07:28:24 +0000 (UTC) Subject: How do I get the URL of the active tab in Firefox/IE/Chrome? References: <4cf347aa$0$7701$ba4acef3@reader.news.orange.fr> Message-ID: On 2010-11-29, Michel Claveau - MVP wrote: > Hello! > >> The "InternetExplorer.Application" automation object doesn't contain >> any way to manipulate tabs directly > > False. Try this example: > import win32com.client > for instance in win32com.client.Dispatch('{9BA05972-F6A8-11CF-A442-00A0C90A8F39}'): > print instance," URL :",instance.LocationURL A Shell collection object != a InternetExplorer.Application object. The problem with using a ShellWindows object is that you could easily connect to the wrong instance, especially since the OP doesn't know the LocationURL of the instance that he is looking for. That is why I asked for clarification. Once we know what the OP is trying to do, we can make sure that he has a reliable method to connect to the proper instance. From michele.simionato at gmail.com Mon Nov 29 03:45:01 2010 From: michele.simionato at gmail.com (Michele Simionato) Date: Mon, 29 Nov 2010 00:45:01 -0800 (PST) Subject: STARTTLS extension not supported by server References: <6e4c8009-7d17-4d04-91dd-75e834b9cde0@o14g2000yqe.googlegroups.com> Message-ID: For future googlers: it turns out in my case the call to .starttls() was not needed: I removed it and everything worked. Dunno why I was there in the first place, the original code was written by somebody else. From simon at brunningonline.net Mon Nov 29 04:39:57 2010 From: simon at brunningonline.net (Simon Brunning) Date: Mon, 29 Nov 2010 09:39:57 +0000 Subject: remote control firefox with python In-Reply-To: <4cf273b9$0$19685$426a74cc@news.free.fr> References: <4cf273b9$0$19685$426a74cc@news.free.fr> Message-ID: On 28 November 2010 15:22, News123 wrote: > > I wondered whether there is a simpe way to > 'remote' control fire fox with python. Selenium might be worth a look, too: -- Cheers, Simon B. From dmw at coder.cl Mon Nov 29 04:50:51 2010 From: dmw at coder.cl (Daniel Molina Wegener) Date: Mon, 29 Nov 2010 06:50:51 -0300 Subject: remote control firefox with python References: <4cf273b9$0$19685$426a74cc@news.free.fr> <4cf2d07b$0$26085$426a74cc@news.free.fr> Message-ID: On Domingo 28 Noviembre 2010 18:58, News123 wrote: > On 11/28/2010 06:19 PM, Tim Harig wrote: >> On 2010-11-28, News123 wrote: >>> Thanks in advance for any pointers ideas. >> >> google XPCOM > thanks a lot For XPCOM (I've worked with it), you can try the following articles and references: "XPCOM" http://en.wikipedia.org/wiki/XPCOM "XPCOM Part 1: An introduction to XPCOM": http://www.ibm.com/developerworks/webservices/library/co-xpcom.html "XPCOM Part 2: XPCOM component basics": http://www.ibm.com/developerworks/webservices/library/co-xpcom2.html "XPCOM Part 3: Setting up XPCOM" http://www.ibm.com/developerworks/webservices/library/co-xpcom3.html "Mozilla Reference Documentation" https://developer.mozilla.org/en/XPCOM Best regards, -- Daniel Molina Wegener System Programmer & Web Developer Phone: +56 (2) 979-0277 | Blog: http://coder.cl/ From dmw at coder.cl Mon Nov 29 04:55:35 2010 From: dmw at coder.cl (Daniel Molina Wegener) Date: Mon, 29 Nov 2010 06:55:35 -0300 Subject: Standard module implementation References: <4cf2626e$0$21696$426a34cc@news.free.fr> Message-ID: On Domingo 28 Noviembre 2010 11:08, candide wrote: > I was wondering if all the standard module are implemented in C. For > instance, I can't find a C implementation for the minidom xml parser > under Python 2.6. If you are looking for a C implementation of DOM as Python Extension, you can try the lxml extension, which uses the LibXML2 bindings: http://codespeak.net/lxml/ Best regards, -- Daniel Molina Wegener System Programmer & Web Developer Phone: +56 (2) 979-0277 | Blog: http://coder.cl/ From vithyam6 at gmail.com Mon Nov 29 05:23:05 2010 From: vithyam6 at gmail.com (cinema) Date: Mon, 29 Nov 2010 02:23:05 -0800 (PST) Subject: EARN MONEY FROM FOREX TRADING ONLINE? Message-ID: http://forextradingonlinetoday.blogspot.com http://forextradingonlinetoday.blogspot.com http://forextradingonlinetoday.blogspot.com http://forextradingonlinetoday.blogspot.com http://forextradingonlinetoday.blogspot.com From michele.simionato at gmail.com Mon Nov 29 05:33:19 2010 From: michele.simionato at gmail.com (Michele Simionato) Date: Mon, 29 Nov 2010 02:33:19 -0800 (PST) Subject: Using property() to extend Tkinter classes but Tkinter classes are old-style classes? References: <1290977244.17714.1407556497@webmail.messagingengine.com> Message-ID: <053e6470-219d-4036-b5da-99d172654ff1@w18g2000vbe.googlegroups.com> On Nov 29, 12:15?am, Terry Reedy wrote: > On 11/28/2010 3:47 PM, pyt... at bdurham.com wrote: > > > I had planned on subclassing Tkinter.Toplevel() using property() to wrap > > access to properties like a window's title. > > After much head scratching and a peek at the Tkinter.py source, I > > realized that all Tkinter classes are old-style classes (even under > > Python 2.7). > > 1. Is there a technical reason why Tkinter classes are still old-style > > classes? > > To not break old code. Being able to break code by upgrading all classes > in the stdlib was one of the reasons for 3.x. > > -- > Terry Jan Reedy Notice that you can upgrade a Tkinter class to a new-style class simply by deriving from object. For instance you could define a new-style Label class as: class Label(Tkinter.Label, object): pass then you can attach properties to it. You have a good chance of not breaking anything in doing so, but you cannot know for sure unless you try. I don't know if Tkinter uses features of old-style classes which are inconsistent with new- style classes, but probably the answer is not much. Michele Simionato From michele.simionato at gmail.com Mon Nov 29 05:44:10 2010 From: michele.simionato at gmail.com (Michele Simionato) Date: Mon, 29 Nov 2010 02:44:10 -0800 (PST) Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> <4ceef381$0$1659$742ec2ed@news.sonic.net> <5c92a83e-9de1-4a03-828c-2cce79ce5a30@v17g2000prc.googlegroups.com> <4cf011b9$0$1619$742ec2ed@news.sonic.net> <87y68fwr89.fsf.mdw@metalzone.distorted.org.uk> <4cf0b232$0$1651$742ec2ed@news.sonic.net> <4cf18792$0$29997$c3e8da3$5496439d@news.astraweb.com> <87bp59vbyp.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <77166587-7dd8-43a2-8f48-7d2a90abd79f@e4g2000vbi.googlegroups.com> On Nov 28, 2:01?pm, m... at distorted.org.uk (Mark Wooding) wrote: > Steve Holden writes: > > It isn't. Even inheritance itself isn't as useful as it at first > > appears, and composition turns out in practice to be much more useful. > > That goes double for multiple inheritance. > > Composition /with a convenient notation for delegation/ works fairly > well. ?Indeed, this can be seen as the basis of Self. ?But downwards > delegation -- where a superclass leaves part of its behaviour > unspecified and requires (concrete) subclasses to fill in the resulting > blanks -- is hard to express like this without some kind of means of > identifying the original recipient of the delegated message. ?Once > you've done that, there isn't much of a difference between a superclass > and a component with implicit delegation. > > -- [mdw] For a long time I had the feeling that in a language with pattern matching inheritance (both single and double) is basically useless. You can easily define objects as functions responding to messages and classes becomes useless. However I have never implemented a large project with such techniques, so I am not sure how much my gut feeling is sound. Apparently here at work we are going to use Erlang in the near future and I hope to get my hand dirty and see in practice how well one can work with a language without inheritance. BTW, is there anybody here with experience on such languages and caring to share his learned lessons? Michele Simionato From nawijn at gmail.com Mon Nov 29 06:27:11 2010 From: nawijn at gmail.com (Marco Nawijn) Date: Mon, 29 Nov 2010 03:27:11 -0800 (PST) Subject: Comparing floats References: Message-ID: On 29 nov, 00:20, Nobody wrote: > On Sat, 27 Nov 2010 18:23:48 -0500, Terry Reedy wrote: > >> Therefore, to implement this multiplication operation I need to have a > >> way to verify that the float tuples C and D are "equal". > > > I might try the average relative difference: > > sum(abs((i-j)/(i+j)) for i,j in zip(C,D))/n # assuming lengths constant > > The division is unstable if i and j are close to zero. > > For scalars, I'd use: > > ? ? ? ? abs(i-j) <= epsilon * (1 + abs(i+j)) > > This amounts to a relative error check for large values and an absolute > error check for values close to zero. > > For a vector, I'd check that the above holds for all pairs. Hi All, Why don't you treat the C and D tuples as vectors? You can than check dot product and norm (length) for equality. Using scipy (www.scipy.org), you even get very nice performance. Marco From rustompmody at gmail.com Mon Nov 29 06:31:56 2010 From: rustompmody at gmail.com (rustom) Date: Mon, 29 Nov 2010 03:31:56 -0800 (PST) Subject: TDD in python References: Message-ID: On Nov 28, 7:52?pm, Stefan Behnel wrote: > Rustom Mody, 28.11.2010 11:58: > > > Does anyone know of something like this for python? > > >http://www.vimeo.com/13240481 > > The page seems to require a recent version of the Flash player. Could you > describe what exactly you are looking for? > > Stefan Well most modern languages have TDD frameworks. However TDD is learnt by doing and not from books (like swimming/ cycling). This screencast gives a detailed demo of *doing it* in eclipse/C++ I was hoping for something similar for python From kent37 at tds.net Mon Nov 29 06:51:51 2010 From: kent37 at tds.net (Kent Johnson) Date: Mon, 29 Nov 2010 03:51:51 -0800 (PST) Subject: Python 2.7.1 References: Message-ID: <80faa2c4-11ca-4b7e-9f66-01c1cb75a61b@fj16g2000vbb.googlegroups.com> On Nov 27, 11:33?pm, Benjamin Peterson wrote: > On behalf of the Python development team, I'm happy as a clam to announce the > immediate availability of Python 2.7.1. Will there be Mac binaries for 2.7.1 and 3.1.3? Currently the web site shows only source and Windows binaries. Thanks, Kent From andre.roberge at gmail.com Mon Nov 29 06:59:05 2010 From: andre.roberge at gmail.com (=?ISO-8859-1?Q?Andr=E9?=) Date: Mon, 29 Nov 2010 03:59:05 -0800 (PST) Subject: TDD in python References: Message-ID: <0906c010-709d-41d9-8b29-2f42afb87f94@32g2000yqz.googlegroups.com> On Nov 29, 7:31?am, rustom wrote: > On Nov 28, 7:52?pm, Stefan Behnel wrote: > > > Rustom Mody, 28.11.2010 11:58: > > > > Does anyone know of something like this for python? > > > >http://www.vimeo.com/13240481 > > > The page seems to require a recent version of the Flash player. Could you > > describe what exactly you are looking for? > > > Stefan > > Well most modern languages have TDD frameworks. > However TDD is learnt by doing and not from books (like swimming/ > cycling). > This screencast gives a detailed demo of *doing it* in eclipse/C++ > I was hoping for something similar for python Go to showmedo.com and do a search for "python tdd"; you'll find many such screencasts. Andr? From hv at tbz-pariv.de Mon Nov 29 08:50:50 2010 From: hv at tbz-pariv.de (Thomas Guettler) Date: Mon, 29 Nov 2010 14:50:50 +0100 Subject: hashlib in one line Message-ID: <8lhpcfF65iU1@mid.individual.net> Hi, I think it would be nice if you could use the hashlib in one line: hashlib.sha256().update('abc').hexdigest() Unfortunately update() returns None. Is there a way to convert a string to the hexdigest of sha256 in one line? Thomas -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de From gerlach_joerg at web.de Mon Nov 29 08:54:58 2010 From: gerlach_joerg at web.de (J. Gerlach) Date: Mon, 29 Nov 2010 14:54:58 +0100 Subject: hashlib in one line In-Reply-To: <8lhpcfF65iU1@mid.individual.net> References: <8lhpcfF65iU1@mid.individual.net> Message-ID: Am 29.11.2010 14:50, schrieb Thomas Guettler: > Hi, > > I think it would be nice if you could use the hashlib in one line: > > hashlib.sha256().update('abc').hexdigest() > > Unfortunately update() returns None. > > Is there a way to convert a string to the hexdigest of sha256 in one line? > > Thomas > > Yeah, something like this would be nice: ;) hashlib.sha256('abc').hexdigest() (tested in 2.6.6) From stefan.sonnenberg at pythonmeister.com Mon Nov 29 09:01:41 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Mon, 29 Nov 2010 15:01:41 +0100 Subject: hashlib in one line In-Reply-To: <8lhpcfF65iU1@mid.individual.net> References: <8lhpcfF65iU1@mid.individual.net> Message-ID: <4CF3B245.6030204@pythonmeister.com> Am 29.11.2010 14:50, schrieb Thomas Guettler: > Hi, > > I think it would be nice if you could use the hashlib in one line: > > hashlib.sha256().update('abc').hexdigest() > > Unfortunately update() returns None. > > Is there a way to convert a string to the hexdigest of sha256 in one line? > > Thomas > > Like so ? >>> hashlib.sha256('abc').hexdigest() 'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad' From python at bdurham.com Mon Nov 29 09:09:07 2010 From: python at bdurham.com (python at bdurham.com) Date: Mon, 29 Nov 2010 09:09:07 -0500 Subject: Using property() to extend Tkinter classes but Tkinter classes are old-style classes? In-Reply-To: <053e6470-219d-4036-b5da-99d172654ff1@w18g2000vbe.googlegroups.com> References: <1290977244.17714.1407556497@webmail.messagingengine.com> <053e6470-219d-4036-b5da-99d172654ff1@w18g2000vbe.googlegroups.com> Message-ID: <1291039747.28741.1407672133@webmail.messagingengine.com> Michele and Terry, > From: "Michele Simionato" > > Notice that you can upgrade a Tkinter class to a new-style class simply by deriving from object. For instance you could define a new-style Label class as: > > class Label(Tkinter.Label, object): > pass Michele - your technique is *exactly* what I was searching for (and works well so far!). Terry - your explanation why Tkinter still uses old style classes (for compatibility with existing code) makes sense. Thank you both. Malcolm From hv at tbz-pariv.de Mon Nov 29 09:14:03 2010 From: hv at tbz-pariv.de (Thomas Guettler) Date: Mon, 29 Nov 2010 15:14:03 +0100 Subject: hashlib in one line In-Reply-To: References: <8lhpcfF65iU1@mid.individual.net> Message-ID: <8lhqnvFek9U1@mid.individual.net> Thank you, I was blind: See "condensed": http://docs.python.org/library/hashlib.html Stefan Sonnenberg-Carstens wrote: > Am 29.11.2010 14:50, schrieb Thomas Guettler: >> Hi, >> >> I think it would be nice if you could use the hashlib in one line: >> >> hashlib.sha256().update('abc').hexdigest() >> >> Unfortunately update() returns None. >> >> Is there a way to convert a string to the hexdigest of sha256 in one >> line? >> >> Thomas >> >> > Like so ? > >>>> hashlib.sha256('abc').hexdigest() > 'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad' -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de From xi at gamma.dn.ua Mon Nov 29 10:00:48 2010 From: xi at gamma.dn.ua (Kirill Simonov) Date: Mon, 29 Nov 2010 10:00:48 -0500 Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance In-Reply-To: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> Message-ID: <4CF3C020.5000306@gamma.dn.ua> Hi Raymond, Another example: extensions in Mercurial. Mercurial is a VCS with a typical command line syntax: $ hg Mercurial has an extension mechanism for adding new and modifying existing commands. A big chunk of Mercurial functionality is implemented in `ui` and `repo` classes and extensions often patch those to override the default behavior. For instance, you could check the `color` extension, which patches `ui` to override `write*` methods: http://selenic.com/hg/file/3790452d499b/hgext/color.py#l152 Thanks, Kirill On 11/24/2010 03:08 PM, Raymond Hettinger wrote: > I'm writing-up more guidance on how to use super() and would like to > point at some real-world Python examples of cooperative multiple > inheritance. > > Google searches take me to old papers for C++ and Eiffel, but that > don't seem to be relevant to most Python programmers (i.e. a > WalkingMenu example where a submenu is both a Entry in a Menu and a > Menu itself). Another published example is in a graphic library where > some widgets inherit GraphicalFeature methods such as location, size > and NestingGroupingFeatures such as finding parents, siblings, and > children. I don't find either of those examples compelling because > there is no particular reason that they would have to have overlapping > method names. > > So far, the only situation I can find where method names necessarily > overlap is for the basics like __init__(), close(), flush(), and > save() where multiple parents need to have their own initialization > and finalization. > > If you guys know of good examples, I would appreciate a link or a > recap. > > Thanks, > > > Raymond > From klausfpga at gmail.com Mon Nov 29 10:11:29 2010 From: klausfpga at gmail.com (klausfpga) Date: Mon, 29 Nov 2010 07:11:29 -0800 (PST) Subject: How to start a windows application minimized (or hidden) Message-ID: Hi, I'd like to start a windows application minimized As an example I used calc.exe what I tried was using the startupinfo field of subprocess.Popen though I'm not sure, that 'hidden' is really the same as minimized. st_info = subprocess.STARTUPINFO() st_info.dwFlags |= subprocess.STARTF_USESHOWWINDOW st_info.wShowWindow = subprocess.SW_HIDE proc = Popen( [ "cmd.exe" ], startupinfo = st_info) I also tried creating a shortut of calc on my desktop and setting it to 'start minimized' if I click on the shortcut, then calc.exe shows up as a visible window What am I doing wrong/ Thanks in advance for any ideas somehow I do not see, that From ulrich.eckhardt at dominolaser.com Mon Nov 29 10:40:43 2010 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Mon, 29 Nov 2010 16:40:43 +0100 Subject: How do you find out what's happening in a process? References: Message-ID: Leo Jay wrote: > I'd like to know how do you guys find out what's happening in your > code if the process seems not work. > In java, I will use jstack to check stacks of threads and lock > status. But I don't know how to do it in python. import pdb pdb.set_trace() Generally, searching "python debugger howto" should turn up a few useful results. ;) Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From g.rodola at gmail.com Mon Nov 29 10:48:11 2010 From: g.rodola at gmail.com (=?ISO-8859-1?Q?Giampaolo_Rodol=E0?=) Date: Mon, 29 Nov 2010 16:48:11 +0100 Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance In-Reply-To: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> Message-ID: 2010/11/24 Raymond Hettinger : > I'm writing-up more guidance on how to use super() and would like to > point at some real-world Python examples of cooperative multiple > inheritance. > > Google searches take me to old papers for C++ and Eiffel, but that > don't seem to be relevant to most Python programmers (i.e. a > WalkingMenu example where a submenu is both a Entry in a Menu and a > Menu itself). ?Another published example is in a graphic library where > some widgets inherit GraphicalFeature methods such as location, size > and NestingGroupingFeatures such as finding parents, siblings, and > children. ?I don't find either of those examples compelling because > there is no particular reason that they would have to have overlapping > method names. > > So far, the only situation I can find where method names necessarily > overlap is for the basics like __init__(), close(), flush(), and > save() where multiple parents need to have their own initialization > and finalization. > > If you guys know of good examples, I would appreciate a link or a > recap. > > Thanks, > > > Raymond > > -- > http://mail.python.org/mailman/listinfo/python-list > In pyftpdlib I used multiple inheritance to implement FTP over SSL: http://code.google.com/p/pyftpdlib/source/browse/tags/release-0.5.2/demo/tls_ftpd.py#125 I can't say it's been natural/intuitive though, and it took me a while to make it work properly. super() is one of the few things in Python I really don't understand properly. --- Giampaolo http://code.google.com/p/pyftpdlib/ http://code.google.com/p/psutil/ From joe at goldthwaites.com Mon Nov 29 11:20:20 2010 From: joe at goldthwaites.com (Joe Goldthwaite) Date: Mon, 29 Nov 2010 09:20:20 -0700 Subject: Parsing markup. In-Reply-To: <4CEF318F.2090308@mrabarnett.plus.com> References: <4CEF318F.2090308@mrabarnett.plus.com> Message-ID: <2545A800F14347C3BF4847C7844377C4@NewMBP> Hi MRAB, I was trying to avoid regex because my poor old brain has trouble with it. I have to admin though, that line is slick! I'll have to go through my regex documentation to try and figure out what it actually means. Thanks! -----Original Message----- From: python-list-bounces+joe=goldthwaites.com at python.org [mailto:python-list-bounces+joe=goldthwaites.com at python.org] On Behalf Of MRAB Sent: Thursday, November 25, 2010 9:03 PM To: python-list at python.org Subject: Re: Parsing markup. On 26/11/2010 03:28, Joe Goldthwaite wrote: > I'm attempting to parse some basic tagged markup. The output of the > TinyMCE editor returns a string that looks something like this; > >

This is a paragraph with bold and italic elements in > it

It can be made up of multiple lines separated by pagagraph > tags.

> > I'm trying to render the paragraph into a bit mapped image. I need > to parse it out into the various paragraph and bold/italic pieces. > I'm not sure the best way to approach it. Elementree and lxml seem > to want a full formatted page, not a small segment like this one. > When I tried to feed a line similar to the above to lxml I got an > error; "XMLSyntaxError: Extra content at the end of the document". > I'd probably use a regex: >>> import re >>> text = "

This is a paragraph with bold and italic elements in it

It can be made up of multiple lines separated by pagagraph tags.

" >>> re.findall(r"|[^<>]+", text) ['

', 'This is a paragraph with ', '', 'bold', '', ' and ', '', 'italic', '', ' elements in it', '

', '

', 'It can be made up of multiple lines separated by pagagraph tags.', '

'] -- http://mail.python.org/mailman/listinfo/python-list From stefan_ml at behnel.de Mon Nov 29 11:34:10 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 29 Nov 2010 17:34:10 +0100 Subject: Parsing markup. In-Reply-To: <9cb996fe-39b0-4780-bd56-5323b7269b0f@t8g2000prh.googlegroups.com> References: <9cb996fe-39b0-4780-bd56-5323b7269b0f@t8g2000prh.googlegroups.com> Message-ID: Jon Clements, 26.11.2010 13:58: > On Nov 26, 4:03 am, MRAB wrote: >> On 26/11/2010 03:28, Joe Goldthwaite wrote: >> > I?m attempting to parse some basic tagged markup. The output of the >> > TinyMCE editor returns a string that looks something like this; >> > >> >

This is a paragraph withbold anditalic elements in >> > it

It can be made up of multiple lines separated by pagagraph >> > tags.

>> > >> > I?m trying to render the paragraph into a bit mapped image. I need >> > to parse it out into the various paragraph and bold/italic pieces. >> > I?m not sure the best way to approach it. Elementree and lxml seem >> > to want a full formatted page, not a small segment like this one. >> > When I tried to feed a line similar to the above to lxml I got an >> > error; ?XMLSyntaxError: Extra content at the end of the document?. This exception indicates that the OP is using the XML parser. > lxml works fine for me - have you tried: > > from lxml import html > text = "

This is a paragraph withbold anditalic > elements in it

It can be made up of multiple lines separated by > pagagraph tags.

" > tree = html.fromstring(text) > print tree.findall('p') > # should print [,] Yep, either use lxml.etree's HTML parser or lxml.html. Stefan From michele.simionato at gmail.com Mon Nov 29 11:53:09 2010 From: michele.simionato at gmail.com (Michele Simionato) Date: Mon, 29 Nov 2010 08:53:09 -0800 (PST) Subject: How do you find out what's happening in a process? References: Message-ID: On Nov 29, 7:01?am, Leo Jay wrote: > Hi all, > > I'd like to know how do you guys find out what's happening in your > code if the process seems not work. > In java, I will use jstack to check stacks of threads and lock status. > But I don't know how to do it in python. > > -- > Best Regards, > Leo Jay If you give a CTRL-C the Python process will die with a traceback showing the line where the process got stuck (assuming you started it from the command-line). You can even run the script under the debugger and give a CTRL-C after a while, as follows: $ python -m pdb thescript.py (Pdb) c CTRL-C Traceback ... ... (Pdb) From tinauser at libero.it Mon Nov 29 13:12:53 2010 From: tinauser at libero.it (tinauser) Date: Mon, 29 Nov 2010 10:12:53 -0800 (PST) Subject: sqlite autoincrement of primary key Message-ID: Dear List I'm writing an application that has to create and populate an SQLite database. I'm doing pretty well, but now I'm facing a problem I can not solve. I create a table with a primary key autoincrement, something like sqlcmd="CREATE TABLE foo (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)" cur.execute(sqlcmd) Now comes the time of populating the database. I perfectly know that if I do something like: sqlcmd="INSERT INTO foo (name) VALUES (?))" cur.execute(sqlcmd, ('xxx',)) The table will automatically insert the value of id. However, for readibility problem, I need to use the sqlite insert command giving all the entries. I want, however, to let sqlite to handle the primary key. Normally, the sqlite command that works would be INSERT INTO 'foo' VALUES (NULL, 'yyy' ) however, if in python i try to execute a script like: cur.execute( ''' INSERT INTO 'foo' VALUES (?,?) ''' ,('NULL','yyy')) I get a datatype mismatch error. Has anyone a workaround ? From mwilson at the-wire.com Mon Nov 29 13:19:19 2010 From: mwilson at the-wire.com (Mel) Date: Mon, 29 Nov 2010 13:19:19 -0500 Subject: sqlite autoincrement of primary key References: Message-ID: tinauser wrote: > Normally, the sqlite command that works would be > > INSERT INTO 'foo' VALUES (NULL, 'yyy' ) > > however, if in python i try to execute a script like: > > cur.execute( > ''' > INSERT INTO 'foo' VALUES (?,?) > ''' > ,('NULL','yyy')) > > I get a datatype mismatch error. > > Has anyone a workaround ? Have you tried '''INSERT INTO foo VALUES (NULL, ?)''' Mel. From john at castleamber.com Mon Nov 29 13:25:53 2010 From: john at castleamber.com (John Bokma) Date: Mon, 29 Nov 2010 12:25:53 -0600 Subject: sqlite autoincrement of primary key References: Message-ID: <87y68cyojy.fsf@castleamber.com> tinauser writes: > however, if in python i try to execute a script like: > > cur.execute( > ''' > INSERT INTO 'foo' VALUES (?,?) > ''' > ,('NULL','yyy')) ,(None, 'yyy')) Or use VALUES(NULL, ?) as suggested in another post. -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From usernet at ilthio.net Mon Nov 29 13:28:22 2010 From: usernet at ilthio.net (Tim Harig) Date: Mon, 29 Nov 2010 18:28:22 +0000 (UTC) Subject: sqlite autoincrement of primary key References: Message-ID: On 2010-11-29, tinauser wrote: > ''' > INSERT INTO 'foo' VALUES (?,?) > ''' > ,('NULL','yyy')) s/'NULL'/None/ > I get a datatype mismatch error. The sqlite module is smart enough to convert between Python types and Sqlite types. If you pass it 'NULL' it thinks you are passing it a string. Python uses None in much the same way that databases use NULL, so the module converts None to 'NULL' and vise versa. From darcy at druid.net Mon Nov 29 13:46:00 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Mon, 29 Nov 2010 13:46:00 -0500 Subject: sqlite autoincrement of primary key In-Reply-To: References: Message-ID: <20101129134600.e1f70d73.darcy@druid.net> On Mon, 29 Nov 2010 13:19:19 -0500 Mel wrote: > tinauser wrote: > '''INSERT INTO foo VALUES (NULL, ?)''' Does this work in SQLite: INSERT INTO foo (name) VALUES ('xxx') That's the standard SQL way. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From alice at gothcandy.com Mon Nov 29 13:47:02 2010 From: alice at gothcandy.com (=?utf-8?Q?Alice_Bevan=E2=80=93McGregor?=) Date: Mon, 29 Nov 2010 10:47:02 -0800 Subject: Strategies for unit testing an HTTP server. Message-ID: Hello! Two things are missing from the web server I've been developing before I can release 1.0: unit tests and documentation. Documentation being entirely my problem, I've run into a bit of a snag with unit testing; just how would you go about it? Specifically, I need to test things like HTTP/1.0 request/response cycles, HTTP/1.0 keep-alives, HTTP/1.1 pipelined reuqest/response cycles, HTTP/1.1 connection: close, HTTP/1.1 chunked requests/responses, etc. What is the recommended / best way to test a daemon in Python? (Note that some of the tests need to keep the "client" socket open.) Is there an easy way to run a daemon in another thread, then kill it after running some tests across it? Even better, are there any dedicated (Python or non-Python) HTTP/1.1 compliance testing suites? Thank you for any assistance, ? Alice. From usernet at ilthio.net Mon Nov 29 14:11:18 2010 From: usernet at ilthio.net (Tim Harig) Date: Mon, 29 Nov 2010 19:11:18 +0000 (UTC) Subject: sqlite autoincrement of primary key References: Message-ID: On 2010-11-29, D'Arcy J.M. Cain wrote: > On Mon, 29 Nov 2010 13:19:19 -0500 > Mel wrote: >> tinauser wrote: >> '''INSERT INTO foo VALUES (NULL, ?)''' > > Does this work in SQLite: > > INSERT INTO foo (name) VALUES ('xxx') > > That's the standard SQL way. Yes, it works; but, the OP asked specifically to be able to enter all of the field values, including the autoincrement field. From tinauser at libero.it Mon Nov 29 14:25:34 2010 From: tinauser at libero.it (tinauser) Date: Mon, 29 Nov 2010 11:25:34 -0800 (PST) Subject: sqlite autoincrement of primary key References: Message-ID: <99c2549a-75bf-49a6-be3d-cf202dabcc79@n30g2000vbb.googlegroups.com> On Nov 29, 7:28?pm, Tim Harig wrote: > On 2010-11-29, tinauser wrote: > > > ''' > > INSERT INTO 'foo' VALUES (?,?) > > ''' > > ,('NULL','yyy')) > > s/'NULL'/None/ > > > I get a datatype mismatch error. > > The sqlite module is smart enough to convert between Python types and > Sqlite types. ?If you pass it 'NULL' it thinks you are passing it a string. > Python uses None in much the same way that databases use NULL, so the > module converts None to 'NULL' and vise versa. Thanks all of you for the fast answers! From tjreedy at udel.edu Mon Nov 29 14:33:02 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 29 Nov 2010 14:33:02 -0500 Subject: Help required with Tranformation of coordinate system In-Reply-To: <5f788fe7-eb82-4fb4-9476-ae95f3f89c2c@30g2000yql.googlegroups.com> References: <1e8c75f4-e5c8-4263-9f4c-34fff241725a@t35g2000yqj.googlegroups.com> <5f788fe7-eb82-4fb4-9476-ae95f3f89c2c@30g2000yql.googlegroups.com> Message-ID: On 11/29/2010 1:55 AM, BansalMaddy wrote: > On Nov 29, 2:03 am, Terry Reedy wrote: >> On 11/28/2010 6:36 PM, BansalMaddy wrote: >> >>> hi all! >>> i need a help in python! i am struggling to implement this since last >>> 2/3 days. suppose i have a 2D plot (say y=x**2). >>> now on the same plot i want to transform my origin of coordinate >>> system to a point (x',y' on this curve and again create a new plot >>> with origin at x',y') >>> can somebody help me how can i offset my cordinate system ... >> >> Plot y-y' == (x-x')**2 - y' against x-x'. >> >> -- >> Terry Jan Reedy > > Thanks for the reply, but i was looking for some built in function to > offset coordinate system, because my problem is not very simple as i > mentioned in my query, actually i need to plot some kind of closed > loops. > e..g > 1. curve will be y=f(x) then i have to search for a point on y=f(x) > curve and i have to plot another function y'=f(x'), where x' and y' > are (-2x) and (-2y) repectively. > 2. then again i hve to search for a pont on y'=f(x') and do some third > kind of operations, on that. > in that case if can shift my coordinate system to desired location on > curve the computation becomes simpler. > > THanks again, hope i made myself clear :) You would have to look at the docs for particular third-party plotting libraries, such as you might find on PyPI. -- Terry Jan Reedy From tjreedy at udel.edu Mon Nov 29 14:35:21 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 29 Nov 2010 14:35:21 -0500 Subject: Python 2.7.1 In-Reply-To: <80faa2c4-11ca-4b7e-9f66-01c1cb75a61b@fj16g2000vbb.googlegroups.com> References: <80faa2c4-11ca-4b7e-9f66-01c1cb75a61b@fj16g2000vbb.googlegroups.com> Message-ID: On 11/29/2010 6:51 AM, Kent Johnson wrote: > On Nov 27, 11:33 pm, Benjamin Peterson wrote: >> On behalf of the Python development team, I'm happy as a clam to announce the >> immediate availability of Python 2.7.1. > > Will there be Mac binaries for 2.7.1 and 3.1.3? Currently the web site > shows only source and Windows binaries. I presume yes. Mac binaries typically trail each release. They are done by a different volunteer. -- Terry Jan Reedy From ameyer2 at yahoo.com Mon Nov 29 15:28:22 2010 From: ameyer2 at yahoo.com (Alan Meyer) Date: Mon, 29 Nov 2010 15:28:22 -0500 Subject: sqlite autoincrement of primary key In-Reply-To: References: Message-ID: <4CF40CE6.4090008@yahoo.com> On 11/29/2010 1:12 PM, tinauser wrote: > Dear List > I'm writing an application that has to create and populate an SQLite > database. > I'm doing pretty well, but now I'm facing a problem I can not solve. > > I create a table with a primary key autoincrement, something like > > sqlcmd="CREATE TABLE foo (id INTEGER PRIMARY KEY AUTOINCREMENT, name > TEXT)" > cur.execute(sqlcmd) > > Now comes the time of populating the database. > I perfectly know that if I do something like: > > sqlcmd="INSERT INTO foo (name) VALUES (?))" > cur.execute(sqlcmd, ('xxx',)) > The table will automatically insert the value of id. > > > However, for readibility problem, I need to use the sqlite insert > command giving all the entries. I want, however, to let sqlite to > handle the primary key. > Normally, the sqlite command that works would be > > INSERT INTO 'foo' VALUES (NULL, 'yyy' ) > > however, if in python i try to execute a script like: > > cur.execute( > ''' > INSERT INTO 'foo' VALUES (?,?) > ''' > ,('NULL','yyy')) > > I get a datatype mismatch error. > > Has anyone a workaround ? There are two red flags popping up for me here. The first is your switch from: "INSERT INTO foo ..." to "INSERT INTO 'foo' ..." I don't know sqllite, however, quotes around the foo is not standard SQL and should cause an error. "datatype mismatch" is not exactly the message I'd expect, but it could be appropriate. The second red flag is your desire to increase readability by inserting something into an auto-increment field. That might just confuse me if I were reading it and knew that NULL (or None) is an invalid and inappropriate value for that column. To me at least, readability is reduced by that, not increased. I'm a little surprised that sqllite would accept it no matter how you did it. You could do something like this: INSERT INTO foo (name) VALUES ('whatever') as another poster suggested. That seems to me more readable than leaving out the column name list but including an auto-increment field in the values list. It gives more, and more valid, information to the programmer who reads your code. Alan From chris at simplistix.co.uk Mon Nov 29 15:41:49 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 29 Nov 2010 20:41:49 +0000 Subject: Use company name for module In-Reply-To: References: Message-ID: <4CF4100D.1090901@simplistix.co.uk> On 12/11/2010 15:50, Robert Kern wrote: > On 11/12/10 8:12 AM, Micah Carrick wrote: >> My company is working on releasing some of our code as open-source python >> modules. I don't want my "foo" module conflicting with other modules >> called >> "foo" on PyPi or github or a user's system. Is there anything wrong, >> from a >> conventions standpoint, with having modules like company.foo and >> company.bar >> even if foo and bar are not necessarily related other than being >> released by us? >> I really don't like the cryptic module names or things like foo2 and >> the like. > > Yes, using namespace packages. You need to use `distribute` in your > setup.py in order to accomplish this. > > http://pypi.python.org/pypi/distribute/ > http://packages.python.org/distribute/setuptools.html#namespace-packages ...or setuptools. ...or just pick a different naming scheme, the Pyramid guys have gone for: company_foo ...and I'm inclined to do the same. Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From jkpeck at gmail.com Mon Nov 29 16:23:37 2010 From: jkpeck at gmail.com (JKPeck) Date: Mon, 29 Nov 2010 13:23:37 -0800 (PST) Subject: Use company name for module References: Message-ID: <220f0536-5a41-4e15-8e77-f6ec2fec513e@j18g2000prn.googlegroups.com> On Nov 29, 1:41?pm, Chris Withers wrote: > On 12/11/2010 15:50, Robert Kern wrote: > > > > > On 11/12/10 8:12 AM, Micah Carrick wrote: > >> My company is working on releasing some of our code as open-source python > >> modules. I don't want my "foo" module conflicting with other modules > >> called > >> "foo" on PyPi or github or a user's system. Is there anything wrong, > >> from a > >> conventions standpoint, with having modules like company.foo and > >> company.bar > >> even if foo and bar are not necessarily related other than being > >> released by us? > >> I really don't like the cryptic module names or things like foo2 and > >> the like. > > > Yes, using namespace packages. You need to use `distribute` in your > > setup.py in order to accomplish this. > > >http://pypi.python.org/pypi/distribute/ > >http://packages.python.org/distribute/setuptools.html#namespace-packages > > ...or setuptools. > > ...or just pick a different naming scheme, the Pyramid guys have gone for: > > company_foo > > ...and I'm inclined to do the same. > > Chris > > -- > Simplistix - Content Management, Batch Processing & Python Consulting > ? ? ? ? ? ? -http://www.simplistix.co.uk You might want to check with your company legal folks before adopting a naming rule base on the company name. Some companies whose names are trademarked will not allow their name to be used in certain contexts, possibly including this. (I am not a lawyer!) From drsalists at gmail.com Mon Nov 29 16:44:56 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 29 Nov 2010 13:44:56 -0800 Subject: Reading lines of null-terminated text? Message-ID: What's the best way of reading lines of null terminated (ASCII NUL, \0) text in Python 2.x? How about for 3.x? I've been using http://stromberg.dnsalias.org/~strombrg/readline0.html with 2.x, but I'm moving some of my stuff to 3.x, and am wondering if there's a way that would obviate readline0. TIA! -------------- next part -------------- An HTML attachment was scrubbed... URL: From darcy at druid.net Mon Nov 29 16:49:31 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Mon, 29 Nov 2010 16:49:31 -0500 Subject: sqlite autoincrement of primary key In-Reply-To: References: Message-ID: <20101129164931.8930f894.darcy@druid.net> On Mon, 29 Nov 2010 19:11:18 +0000 (UTC) Tim Harig wrote: > > INSERT INTO foo (name) VALUES ('xxx') > > > > That's the standard SQL way. > > Yes, it works; but, the OP asked specifically to be able to enter all of > the field values, including the autoincrement field. You're right, I missed that. However reading the OP's message I am still confused. How does removing the field name and adding a positional NULL or None improve readability. I now wonder if it was more of an assignment requirement rather than a real one. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From usernet at ilthio.net Mon Nov 29 16:58:29 2010 From: usernet at ilthio.net (Tim Harig) Date: Mon, 29 Nov 2010 21:58:29 +0000 (UTC) Subject: sqlite autoincrement of primary key References: Message-ID: On 2010-11-29, D'Arcy J.M. Cain wrote: > On Mon, 29 Nov 2010 19:11:18 +0000 (UTC) > Tim Harig wrote: >> > INSERT INTO foo (name) VALUES ('xxx') >> > >> > That's the standard SQL way. >> >> Yes, it works; but, the OP asked specifically to be able to enter all of >> the field values, including the autoincrement field. > > You're right, I missed that. However reading the OP's message I am > still confused. How does removing the field name and adding a > positional NULL or None improve readability. I now wonder if it was > more of an assignment requirement rather than a real one. That, I don't know. I would agree that it seems like a mis-guided approach; but, it is what he asked for. From hemant.dmp at gmail.com Mon Nov 29 17:06:10 2010 From: hemant.dmp at gmail.com (BansalMaddy) Date: Mon, 29 Nov 2010 14:06:10 -0800 (PST) Subject: Help required with Tranformation of coordinate system References: <1e8c75f4-e5c8-4263-9f4c-34fff241725a@t35g2000yqj.googlegroups.com> <5f788fe7-eb82-4fb4-9476-ae95f3f89c2c@30g2000yql.googlegroups.com> Message-ID: On Nov 29, 8:33?pm, Terry Reedy wrote: > On 11/29/2010 1:55 AM, BansalMaddy wrote: > > > > > On Nov 29, 2:03 am, Terry Reedy ?wrote: > >> On 11/28/2010 6:36 PM, BansalMaddy wrote: > > >>> hi all! > >>> i need a help in python! i am struggling to implement this since last > >>> 2/3 days. suppose i have a 2D plot (say y=x**2). > >>> now on the same plot i want to transform my origin of coordinate > >>> system to a point (x',y' on this curve and again create a new plot > >>> with origin at x',y') > >>> can somebody help me how can i offset my cordinate system ... > > >> Plot y-y' == (x-x')**2 - y' against x-x'. > > >> -- > >> Terry Jan Reedy > > > Thanks for the reply, but i was looking for some built in function to > > offset coordinate system, because my problem is not very simple as i > > mentioned in my query, actually i need to plot some kind of closed > > loops. > > e..g > > 1. curve will be y=f(x) then i have to search for a point on y=f(x) > > curve and i have to plot another function y'=f(x'), where x' and y' > > are (-2x) and (-2y) repectively. > > 2. then again i hve to search for a pont on y'=f(x') and do some third > > kind of operations, on that. > > in that case if can shift my coordinate system to desired location on > > curve the computation becomes simpler. > > > THanks again, hope i made myself clear :) > > You would have to look at the docs for particular third-party plotting > libraries, such as you might find on PyPI. > > -- > Terry Jan Reedy OK thanks From tinauser at libero.it Mon Nov 29 17:19:30 2010 From: tinauser at libero.it (tinauser) Date: Mon, 29 Nov 2010 14:19:30 -0800 (PST) Subject: sqlite autoincrement of primary key References: Message-ID: <34b9f7a8-9a91-436d-9cbf-96fa91268555@s4g2000yql.googlegroups.com> On Nov 29, 10:49?pm, "D'Arcy J.M. Cain" wrote: > On Mon, 29 Nov 2010 19:11:18 +0000 (UTC) > > Tim Harig wrote: > > > ? INSERT INTO foo (name) VALUES ('xxx') > > > > That's the standard SQL way. > > > Yes, it works; but, the OP asked specifically to be able to enter all of > > the field values, including the autoincrement field. > > You're right, I missed that. ?However reading the OP's message I am > still confused. ?How does removing the field name and adding a > positional NULL or None improve readability. ?I now wonder if it was > more of an assignment requirement rather than a real one. > > -- > D'Arcy J.M. Cain ? ? ? ? | ?Democracy is three wolveshttp://www.druid.net/darcy/? ? ? ? ? ? ? ?| ?and a sheep voting on > +1 416 425 1212 ? ? (DoD#0082) ? ?(eNTP) ? | ?what's for dinner. Was not an assignment. I created a general table class and several specific tables. The application I'm going to write is going to be used by scientist that might not have a strong computational background, but they might be willing of adding some new tables. Their code knowledge might be so low that they might not go further a copy-paste. The way I defined the table, they just have to create lists indicating the name of the columns, their content and eventually some initial values for instance. self.colNames= [ 'id' , 'name' , 'surname', 'age' ] self.colType = [INTEGER, TEXT , TEXT , INTEGER] self.init.append([ None , 'john' , 'Lennon' , '51' ]) i.e. the code has to resable the structure of the table and be easily copy and paste (this last thing makes this system better than, instead, using python dictionary...also because the future user might not be familiar at all with dictionary).I might think of doing an automatic substitution of the primarykey with None, that is not a problem Anyhow, as said, thanks for all the answers, you solved my question Regards From greg.ewing at canterbury.ac.nz Mon Nov 29 17:27:38 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 30 Nov 2010 11:27:38 +1300 Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance In-Reply-To: <7xsjyp2d12.fsf@ruckus.brouhaha.com> References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> <7xsjyp2d12.fsf@ruckus.brouhaha.com> Message-ID: <8linmqF99gU1@mid.individual.net> Paul Rubin wrote: > The classic example though is a window system, where you have a "window" > class, and a "scroll bar" class, and a "drop-down menu" class, etc. and > if you want a window with a scroll bar and a drop-down menu, you inherit > from all three of those classes. Not in any GUI library I've ever seen. Normally there would be three objects involved in such an arrangement, a Window, a ScrollBar and a DropDownMenu, connected to each other in some way. -- Greg From stackslip at gmail.com Mon Nov 29 17:55:31 2010 From: stackslip at gmail.com (Garland Fulton) Date: Mon, 29 Nov 2010 13:55:31 -0900 Subject: Arrays In-Reply-To: References: <4ceef22b.1a1c640a.442c.2e69@mx.google.com> Message-ID: At the top of the last post I didn't understand how I was supposed to have my e mail headers or my quotes formatted. I also would like to change the header to my e mail thread. To I appolpgize and thank you for clearing up my thinking. I just got done with a java class and I should have paid more attention. Now that I went back and reviewed. array[] // in java Is not the same as list[] // in python. I will go back and try my way again. I have a list of objects built to form numbers given to me already. I would like to take the list apart iterate over each component and replace it with the corresponding number, and put it back together again everytime I call that number(str object) to be printed from my list. To clear my goals up I don't want to be a bad to this e mail list. Thank you, Slie On Nov 25, 2010 8:43 PM, "Dennis Lee Bieber" wrote: > On Thu, 25 Nov 2010 14:32:57 -0900, Slie declaimed > the following in gmane.comp.python.general: > >> I have an exercise im working on. >> I have an array of strings, and I would like to take each peace of the array and assign it to a new array so I can iterate over each of those pieces and replace the sting I want then put it back together. >> >> I hope that is not too confusing. This is how im trying to solve the problem. >> >> I have a program that takes in integers and it prints out the integers in bigger ones made up of asterisks. Im supposed to alter the program so so that instead of asterisks it prints them in bigger ones made up of the number itself. >> >> I am given arrays built to look like the numbers, already. > > {Note: this newsgroup/list prefers the "trim and follow" method of > quoting; persist ant "top-posting" will earn the ire of the readers} > > We still have the problem that you are referring to "arrays" which > are NOT native data types in Python... There is an importable module for > "arrays", and most of the numerics packages (a la numpy) define arrays, > but Python itself has dynamically sized "lists" (and "lists of lists..." > to add additional dimensions). > > Off-hand, it sounds like you are just substituting a list-of-lists > (of strings) of asterisks with a list-of-lists containing characters of > each digit... > > Now which part are you having problems with? Extracting the digits > from the input "number", indexing into the list of digit data, indexing > into the row of digit data, collecting the data into one output > structure? > > I'm probably giving away too much here but using just 0/1 and input > as a string... > > -=-=-=-=-=- > > digits = [ [ " 000 ", > "0 0", > "0 0", > "0 0", > "0 0", > " 000 " ], > [ " 1 ", > " 11 ", > " 1 ", > " 1 ", > " 1 ", > " 111 " ] ] > > output = [] > > DATA = "01101" > > for row in range(6): > rowparts = [] > for d in DATA: > dint = int(d, 10) > rowparts.append(digits[dint][row]) > output.append(" ".join(rowparts)) > > print output > print > > for rout in output: > print rout > -=-=-=-=-=-=- (use fixed width font to view) > [' 000 1 1 000 1 ', '0 0 11 11 0 0 11 > ', '0 0 1 1 0 0 1 ', '0 0 1 1 0 0 1 > ', '0 0 1 1 0 0 1 ', ' 000 111 111 000 111 > '] > > 000 1 1 000 1 > 0 0 11 11 0 0 11 > 0 0 1 1 0 0 1 > 0 0 1 1 0 0 1 > 0 0 1 1 0 0 1 > 000 111 111 000 111 > > -- > Wulfraed Dennis Lee Bieber AF6VN > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From matthew at cuneiformsoftware.com Mon Nov 29 18:11:28 2010 From: matthew at cuneiformsoftware.com (Spider) Date: Mon, 29 Nov 2010 15:11:28 -0800 (PST) Subject: Python 2.7.1 References: Message-ID: <7c7d85f5-740c-4a29-8899-cdab38865ac9@32g2000yqz.googlegroups.com> > 2.7 includes many features that were first released in Python 3.1. The faster io module ... I understand that I/O in Python 3.0 was slower than 2.x (due to quite a lot of the code being in Python rather than C, I gather), and that this was fixed up in 3.1. So, io in 3.1 is faster than in 3.0. Is it also true that io is faster in 2.7 than 2.6? That's what the release notes imply, but I wonder whether that comment has been back- ported from the 3.1 release notes, and doesn't actually apply to 2.7. Of course, I probably should benchmark it, but if someone who knows the history of the io module can respond, that would be great. My specific interest is in file read/write speeds. Thanks From python at mrabarnett.plus.com Mon Nov 29 18:17:59 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 29 Nov 2010 23:17:59 +0000 Subject: Reading lines of null-terminated text? In-Reply-To: References: Message-ID: <4CF434A7.9010309@mrabarnett.plus.com> On 29/11/2010 21:44, Dan Stromberg wrote: > > What's the best way of reading lines of null terminated (ASCII NUL, \0) > text in Python 2.x? How about for 3.x? > > I've been using http://stromberg.dnsalias.org/~strombrg/readline0.html > with 2.x, but I'm moving some of my stuff to 3.x, and am wondering if > there's a way that would obviate readline0. > You could read as binary data and then split on b"\x00". In Python 3 it's possible to specify the newline character, but I've found that it won't accept the null character as newline. I don't know why. :-( From ian.g.kelly at gmail.com Mon Nov 29 19:00:02 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 29 Nov 2010 17:00:02 -0700 Subject: Reading lines of null-terminated text? In-Reply-To: <4CF434A7.9010309@mrabarnett.plus.com> References: <4CF434A7.9010309@mrabarnett.plus.com> Message-ID: On Mon, Nov 29, 2010 at 4:17 PM, MRAB wrote: > In Python 3 it's possible to specify the newline character, but I've > found that it won't accept the null character as newline. I don't know > why. :-( Because it isn't a legal value. "newline controls how universal newlines works (it only applies to text mode). It can be None, '', '\n', '\r', and '\r\n'." Why it was designed that way, I don't know. Maybe to avoid scenarios where the selected newline has more than one representation in the selected encoding. Cheers, Ian From ian.g.kelly at gmail.com Mon Nov 29 19:00:02 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 29 Nov 2010 17:00:02 -0700 Subject: Reading lines of null-terminated text? In-Reply-To: <4CF434A7.9010309@mrabarnett.plus.com> References: <4CF434A7.9010309@mrabarnett.plus.com> Message-ID: On Mon, Nov 29, 2010 at 4:17 PM, MRAB wrote: > In Python 3 it's possible to specify the newline character, but I've > found that it won't accept the null character as newline. I don't know > why. :-( Because it isn't a legal value. "newline controls how universal newlines works (it only applies to text mode). It can be None, '', '\n', '\r', and '\r\n'." Why it was designed that way, I don't know. Maybe to avoid scenarios where the selected newline has more than one representation in the selected encoding. Cheers, Ian From ameyer2 at yahoo.com Mon Nov 29 20:46:08 2010 From: ameyer2 at yahoo.com (Alan Meyer) Date: Mon, 29 Nov 2010 20:46:08 -0500 Subject: Parsing markup. In-Reply-To: References: <4CEF318F.2090308@mrabarnett.plus.com> Message-ID: <4CF45760.1080601@yahoo.com> On 11/29/2010 11:20 AM, Joe Goldthwaite wrote: > Hi MRAB, > > I was trying to avoid regex because my poor old brain has trouble with it. I > have to admin though, that line is slick! I'll have to go through my regex > documentation to try and figure out what it actually means. Personally, I'd be hesitant to use a regex. It can be done and I've done it myself on occasion when I had a simple job to do and a very, very, very well defined target. The problem with using regular expressions is that there is are many variations in the text of valid XML. There can be namespaces, attributes, newlines in surprising places, unexpected character encodings, alternative quoting styles (e.g. id='123' or id = "123"), character entities ("<") and possibly other things that I haven't thought of. The parser authors have thought of those things and written parsing code that works properly on legal XML, even in these surprising cases that rarely show up in your data but can. You might think there won't ever be any surprises that break your regexes, but then some new programmer appears on the project and thinks, Aha, this is XML, I can solve my problem by adding a new attribute to that 'p' tag. He will be tearing his hair and muttering sentences that happen to have your name in them when he discovers that his perfectly legal XML content won't parse correctly in your regex based parser. The muttering will get much louder if he only discovers this after much data has been processed and important items silently skipped over by the parser. Alan From rustompmody at gmail.com Mon Nov 29 23:50:48 2010 From: rustompmody at gmail.com (rustom) Date: Mon, 29 Nov 2010 20:50:48 -0800 (PST) Subject: TDD in python References: <0906c010-709d-41d9-8b29-2f42afb87f94@32g2000yqz.googlegroups.com> Message-ID: <58fe3680-21f5-42f8-9341-e069cbb88975@r19g2000prm.googlegroups.com> On Nov 29, 4:59?pm, Andr? wrote: > On Nov 29, 7:31?am, rustom wrote: > > > > > On Nov 28, 7:52?pm, Stefan Behnel wrote: > > > > Rustom Mody, 28.11.2010 11:58: > > > > > Does anyone know of something like this for python? > > > > >http://www.vimeo.com/13240481 > > > > The page seems to require a recent version of the Flash player. Could you > > > describe what exactly you are looking for? > > > > Stefan > > > Well most modern languages have TDD frameworks. > > However TDD is learnt by doing and not from books (like swimming/ > > cycling). > > This screencast gives a detailed demo of *doing it* in eclipse/C++ > > I was hoping for something similar for python > > Go to showmedo.com and do a search for "python tdd"; you'll find many > such screencasts. > > Andr? Looking around I found this: http://bytes.com/topic/python/answers/43330-unittest-vs-py-test where Raymond Hettinger no less says quite unequivocally that he prefers test.py to builtin unittest because it is not so heavy-weight Is this the general consensus nowadays among pythonistas? [Note I tend to agree but Ive no experience so asking] From goldtech at worldpost.com Tue Nov 30 00:17:16 2010 From: goldtech at worldpost.com (goldtech) Date: Mon, 29 Nov 2010 21:17:16 -0800 (PST) Subject: regular expression help Message-ID: <3276d8a0-422b-468c-b1e0-71cf562afc68@t8g2000prh.googlegroups.com> Hi, say: >>> import re >>>> m="oooocccvlvlvlvnnnflfllffccclfnnnooo" >>> re.compile(r'ccc.*nnn') >>> rtt=pppp.sub("||",m) >>> rtt 'oooo||ooo' The regex is eating up too much. What I want is every non-overlapping occurrence I think. so rtt would be: 'oooo||flfllff||ooo' just like findall acts but in this case I want sub to act like that. Thanks From drsalists at gmail.com Tue Nov 30 00:26:23 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 29 Nov 2010 21:26:23 -0800 Subject: Python 3 encoding question: Read a filename from stdin, subsequently open that filename Message-ID: I've got a couple of programs that read filenames from stdin, and then open those files and do things with them. These programs sort of do the *ix xargs thing, without requiring xargs. In Python 2, these work well. Irrespective of how filenames are encoded, things are opened OK, because it's all just a stream of single byte characters. In Python 3, I'm finding that I have encoding issues with characters with their high bit set.? Things are fine with strictly ASCII filenames. With high-bit-set characters, even if I change stdin's encoding with: ? ? ? import io ? ? ? STDIN = io.open(sys.stdin.fileno(), 'r', encoding='ISO-8859-1') ...even with that, when I read a filename from stdin with a single-character Spanish n~, the program cannot open that filename because the n~ is apparently internally converted to two bytes, but remains one byte in the filesystem. I decided to try ISO-8859-1 with Python 3, because I have a Java program that encountered a similar problem until I used en_US.ISO-8859-1 in an environment variable to set the JVM's encoding for stdin. Python 2 shows the n~ as 0xf1 in an os.listdir('.'). Python 3 with an encoding of ISO-8859-1 wants it to be 0xc3 followed by 0xb1. Does anyone know what I need to do to read filenames from stdin with Python 3.1 and subsequently open them, when some of those filenames include characters with their high bit set? TIA! From usernet at ilthio.net Tue Nov 30 00:34:59 2010 From: usernet at ilthio.net (Tim Harig) Date: Tue, 30 Nov 2010 05:34:59 +0000 (UTC) Subject: regular expression help References: <3276d8a0-422b-468c-b1e0-71cf562afc68@t8g2000prh.googlegroups.com> Message-ID: On 2010-11-30, goldtech wrote: > Hi, > > say: >>>> import re >>>>> m="oooocccvlvlvlvnnnflfllffccclfnnnooo" >>>> re.compile(r'ccc.*nnn') >>>> rtt=pppp.sub("||",m) >>>> rtt > 'oooo||ooo' > > The regex is eating up too much. What I want is every non-overlapping > occurrence I think. > > so rtt would be: > > 'oooo||flfllff||ooo' Python 3.1.2 (r312:79147, Oct 9 2010, 00:16:06) [GCC 4.4.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import re >>> m="oooocccvlvlvlvnnnflfllffccclfnnnooo" >>> pattern = re.compile(r'ccc[^n]*nnn') >>> pattern.sub("||", m) 'oooo||flfllff||ooo' >>> From lanyjie at yahoo.com Tue Nov 30 00:39:45 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Mon, 29 Nov 2010 21:39:45 -0800 (PST) Subject: regular expression help In-Reply-To: <3276d8a0-422b-468c-b1e0-71cf562afc68@t8g2000prh.googlegroups.com> Message-ID: <457935.48828.qm@web54207.mail.re2.yahoo.com> --- On Tue, 11/30/10, goldtech wrote: > From: goldtech > Subject: regular expression help > To: python-list at python.org > Date: Tuesday, November 30, 2010, 9:17 AM > The regex is eating up too much. What I want is every > non-overlapping > occurrence I think. > > so rtt would be: > > 'oooo||flfllff||ooo' > Hi, I'll just let Python do most of the talk here. >>> import re >>> m="oooocccvlvlvlvnnnflfllffccclfnnnooo" >>> p=re.compile(r'ccc.*?nnn') >>> p.sub("||", m) 'oooo||flfllff||ooo' Cheers, Yingjie From usernet at ilthio.net Tue Nov 30 00:45:39 2010 From: usernet at ilthio.net (Tim Harig) Date: Tue, 30 Nov 2010 05:45:39 +0000 (UTC) Subject: regular expression help References: <3276d8a0-422b-468c-b1e0-71cf562afc68@t8g2000prh.googlegroups.com> Message-ID: Python 3.1.2 (r312:79147, Oct 9 2010, 00:16:06) [GCC 4.4.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import re >>> m="oooocccvlvlvlvnnnflfllffccclfnnnooo" >>> pattern = re.compile(r'ccc[^n]*nnn') >>> pattern.sub("||", m) 'oooo||flfllff||ooo' >>> # or, assuming that the middle sequence might contain singular or >>> # double 'n's >>> pattern = re.compile(r'ccc.*?nnn') >>> pattern.sub("||", m) 'oooo||flfllff||ooo' >>> From lanyjie at yahoo.com Tue Nov 30 00:52:07 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Mon, 29 Nov 2010 21:52:07 -0800 (PST) Subject: Python 3 encoding question: Read a filename from stdin, subsequently open that filename In-Reply-To: Message-ID: <339421.80548.qm@web54205.mail.re2.yahoo.com> --- On Tue, 11/30/10, Dan Stromberg wrote: > In Python 3, I'm finding that I have encoding issues with > characters > with their high bit set.? Things are fine with strictly > ASCII > filenames.? With high-bit-set characters, even if I > change stdin's > encoding with: Co-ask. I have also had problems with file names in Chinese characters with Python 3. I unzipped the turtle demo files into the desktop folder (of course, the word 'desktop' is in Chinese, it is a windows XP system, localization is Chinese), then all in a sudden some of the demos won't work anymore. But if I move it to a folder whose path contains only english characters, everything comes back to normal. Another related issue on the same platform is this: if you have your source file in the chinese 'desktop' folder, and when you run the code and got some exceptions, the path information printed out by the tracer wrongly encoded the chinese name for 'desktop'. Yingjie From glyph at twistedmatrix.com Tue Nov 30 01:07:57 2010 From: glyph at twistedmatrix.com (Glyph Lefkowitz) Date: Tue, 30 Nov 2010 01:07:57 -0500 Subject: [ANNOUNCE] Twisted 10.2.0 Released Message-ID: <48EF5F73-CAE0-43CC-89A9-FD273C334E79@twistedmatrix.com> Twisted 10.2.0, the third Twisted release of 2010, has emerged from the mysterious depths of Twisted Matrix Labs, as so many releases before it. Survivors of the release process - what few there were of them - have been heard to claim that this version is "awesome", "even more robust", "fun-sized" and "oven fresh". Crossing several things that shouldn't ought to be, including the streams and the rubicon, I have assumed the triple responsibilities of feature author, project leader, *and* release manager for 10.2: with this dark and terrible power - a power which no man ought to wield alone - I have wrought a release which contains many exciting new features, including: - A plug-in API for adding new types of endpoint descriptions. - A new, simpler, substantially more robust CoreFoundation reactor. - Improvements to the implementation of Deferred which should both improve performance and fix certain runtime errors with long callback chains. - Deferred.setTimeout is (finally) gone. To quote the author of this change: "A new era of peace has started." - NetstringReceiver is substantially faster. And, of course, nearly one hundred smaller bug fixes, documentation updates, and general improvements. See the NEWS file included in the release for more details. Look upon our Twisted, ye mighty, and make your network applications event-driven: get it now, from: ... or simply install the 'Twisted' package from PyPI. Many thanks to Christopher Armstrong, for his work on release-automation tools that made this possible; to Jonathan Lange, for thoroughly documenting the process and thereby making my ascent to the throne of release manager possible, and to Jean-Paul Calderone for his tireless maintenance of our build and test infrastructure as well as his help with the release. Most of all, thanks to everyone who contributed a patch, reported a bug or reviewed a ticket for 10.2. Not including those already thanked, there are 41 of you, so it would be a bit tedious to go through everyone, but you know who you are and we absolutely couldn't do it without you! Thanks a ton! From goldtech at worldpost.com Tue Nov 30 01:08:03 2010 From: goldtech at worldpost.com (goldtech) Date: Mon, 29 Nov 2010 22:08:03 -0800 (PST) Subject: regular expression help References: <3276d8a0-422b-468c-b1e0-71cf562afc68@t8g2000prh.googlegroups.com> Message-ID: <8864cf46-f584-4a85-8857-e6a22a528a31@p7g2000prb.googlegroups.com> .*? fixed it. Every occurrence of the pattern is now affected, which is what I want. Thank you very much. From python at bdurham.com Tue Nov 30 03:59:44 2010 From: python at bdurham.com (python at bdurham.com) Date: Tue, 30 Nov 2010 03:59:44 -0500 Subject: Possible to determine number of rows affected by a SQLite update or delete command? Message-ID: <1291107584.8529.1407836997@webmail.messagingengine.com> Is there a cursor or connection property that returns the number of rows affected by a SQLite update or delete command? Or, if we want this information, do we have to pre-query our database for a count of records that will be affected by an operation? Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From kushal.kumaran+python at gmail.com Tue Nov 30 04:21:14 2010 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Tue, 30 Nov 2010 14:51:14 +0530 Subject: Possible to determine number of rows affected by a SQLite update or delete command? In-Reply-To: <1291107584.8529.1407836997@webmail.messagingengine.com> References: <1291107584.8529.1407836997@webmail.messagingengine.com> Message-ID: On Tue, Nov 30, 2010 at 2:29 PM, wrote: > Is there a cursor or connection property that returns the number of rows > affected by a SQLite update or delete command? > The cursor has a rowcount attribute. The documentation of the sqlite3 module says the implementation is "quirky". You might take a look at it and see if it fits your needs. > Or, if we want this information, do we have to pre-query our database for a > count of records that will be affected by an operation? > -- regards, kushal From usenet at solar-empire.de Tue Nov 30 05:06:45 2010 From: usenet at solar-empire.de (Marc Christiansen) Date: Tue, 30 Nov 2010 11:06:45 +0100 Subject: Python 3 encoding question: Read a filename from stdin, subsequently?open that filename References: Message-ID: Dan Stromberg wrote: > I've got a couple of programs that read filenames from stdin, and then > open those files and do things with them. These programs sort of do > the *ix xargs thing, without requiring xargs. > > In Python 2, these work well. Irrespective of how filenames are > encoded, things are opened OK, because it's all just a stream of > single byte characters. > > In Python 3, I'm finding that I have encoding issues with characters > with their high bit set.? Things are fine with strictly ASCII > filenames. With high-bit-set characters, even if I change stdin's > encoding with: > > ? ? ? import io > ? ? ? STDIN = io.open(sys.stdin.fileno(), 'r', encoding='ISO-8859-1') > > ...even with that, when I read a filename from stdin with a > single-character Spanish n~, the program cannot open that filename > because the n~ is apparently internally converted to two bytes, but > remains one byte in the filesystem. I decided to try ISO-8859-1 with > Python 3, because I have a Java program that encountered a similar > problem until I used en_US.ISO-8859-1 in an environment variable to > set the JVM's encoding for stdin. > > Python 2 shows the n~ as 0xf1 in an os.listdir('.'). Python 3 with an > encoding of ISO-8859-1 wants it to be 0xc3 followed by 0xb1. > > Does anyone know what I need to do to read filenames from stdin with > Python 3.1 and subsequently open them, when some of those filenames > include characters with their high bit set? > > TIA! Try using sys.stdin.buffer instead of sys.stdin. It gives you bytes instead of strings. Also use byteliterals instead of stringliterals for paths, i.e. os.listdir(b'.'). Marc From owgs at bii.a-star.edu.sg Tue Nov 30 05:29:35 2010 From: owgs at bii.a-star.edu.sg (OW Ghim Siong) Date: Tue, 30 Nov 2010 18:29:35 +0800 Subject: Memory issues when storing as List of Strings vs List of List Message-ID: <4CF4D20F.4060400@bii.a-star.edu.sg> Hi all, I have a big file 1.5GB in size, with about 6 million lines of tab-delimited data. I have to perform some filtration on the data and keep the good data. After filtration, I have about 5.5 million data left remaining. As you might already guessed, I have to read them in batches and I did so using .readlines(100000000). After reading each batch, I will split the line (in string format) to a list using .split("\t") and then check several conditions, after which if all conditions are satisfied, I will store the list into a matrix. The code is as follows: -----Start------ a=open("bigfile") matrix=[] while True: lines = a.readlines(100000000) for line in lines: data=line.split("\t") if several_conditions_are_satisfied: matrix.append(data) print "Number of lines read:", len(lines), "matrix.__sizeof__:", matrix.__sizeof__() if len(lines)==0: break -----End----- Results: Number of lines read: 461544 matrix.__sizeof__: 1694768 Number of lines read: 449840 matrix.__sizeof__: 3435984 Number of lines read: 455690 matrix.__sizeof__: 5503904 Number of lines read: 451955 matrix.__sizeof__: 6965928 Number of lines read: 452645 matrix.__sizeof__: 8816304 Number of lines read: 448555 matrix.__sizeof__: 9918368 Traceback (most recent call last): MemoryError The peak memory usage at the task manager is > 2GB which results in the memory error. However, if I modify the code, to store as a list of string rather than a list of list by changing the append statement stated above to "matrix.append("\t".join(data))", then I do not run out of memory. Results: Number of lines read: 461544 matrix.__sizeof__: 1694768 Number of lines read: 449840 matrix.__sizeof__: 3435984 Number of lines read: 455690 matrix.__sizeof__: 5503904 Number of lines read: 451955 matrix.__sizeof__: 6965928 Number of lines read: 452645 matrix.__sizeof__: 8816304 Number of lines read: 448555 matrix.__sizeof__: 9918368 Number of lines read: 453455 matrix.__sizeof__: 12552984 Number of lines read: 432440 matrix.__sizeof__: 14122132 Number of lines read: 432921 matrix.__sizeof__: 15887424 Number of lines read: 464259 matrix.__sizeof__: 17873376 Number of lines read: 450875 matrix.__sizeof__: 20107572 Number of lines read: 458552 matrix.__sizeof__: 20107572 Number of lines read: 453261 matrix.__sizeof__: 22621044 Number of lines read: 413456 matrix.__sizeof__: 22621044 Number of lines read: 166464 matrix.__sizeof__: 25448700 Number of lines read: 0 matrix.__sizeof__: 25448700 In this case, the peak memory according to the task manager is about 1.5 GB. Does anyone know why is there such a big difference memory usage when storing the matrix as a list of list, and when storing it as a list of string? According to __sizeof__ though, the values are the same whether storing it as a list of list, or storing it as a list of string. Is there any methods how I can store all the info into a list of list? I have tried creating such a matrix of equivalent size and it only uses 35mb of memory but I am not sure why when using the code above, the memory usage shot up so fast and exceeded 2GB. Any advice is greatly appreciated. Regards, Jinxiang From __peter__ at web.de Tue Nov 30 05:52:27 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 30 Nov 2010 11:52:27 +0100 Subject: Python 3 encoding question: Read a filename from stdin, subsequently open that filename References: Message-ID: Dan Stromberg wrote: > I've got a couple of programs that read filenames from stdin, and then > open those files and do things with them. These programs sort of do > the *ix xargs thing, without requiring xargs. > > In Python 2, these work well. Irrespective of how filenames are > encoded, things are opened OK, because it's all just a stream of > single byte characters. I think you're wrong. The filenames' encoding as they are read from stdin must be the same as the encoding used by the file system. If the file system expects UTF-8 and you feed it ISO-8859-1 you'll run into errors. You always have to know either (a) both the file system's and stdin's actual encoding, or (b) that both encodings are the same. If byte strings work you are in situation (b) or just lucky. I'd guess the latter ;) > In Python 3, I'm finding that I have encoding issues with characters > with their high bit set. Things are fine with strictly ASCII > filenames. With high-bit-set characters, even if I change stdin's > encoding with: > > import io > STDIN = io.open(sys.stdin.fileno(), 'r', encoding='ISO-8859-1') I suppose you can handle (b) with STDIN = sys.stdin.buffer or STDIN = io.TextIOWrapper(sys.stdin.buffer, encoding=sys.getfilesystemencoding()) in Python 3. I'd prefer the latter because it makes your assumptions explicit. (Disclaimer: I'm not sure whether I'm using the io API as Guido intended it) > ...even with that, when I read a filename from stdin with a > single-character Spanish n~, the program cannot open that filename > because the n~ is apparently internally converted to two bytes, but > remains one byte in the filesystem. I decided to try ISO-8859-1 with > Python 3, because I have a Java program that encountered a similar > problem until I used en_US.ISO-8859-1 in an environment variable to > set the JVM's encoding for stdin. > > Python 2 shows the n~ as 0xf1 in an os.listdir('.'). Python 3 with an > encoding of ISO-8859-1 wants it to be 0xc3 followed by 0xb1. > > Does anyone know what I need to do to read filenames from stdin with > Python 3.1 and subsequently open them, when some of those filenames > include characters with their high bit set? > > TIA! From ulrich.eckhardt at dominolaser.com Tue Nov 30 06:30:41 2010 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Tue, 30 Nov 2010 12:30:41 +0100 Subject: Memory issues when storing as List of Strings vs List of List References: Message-ID: OW Ghim Siong wrote: > I have a big file 1.5GB in size, with about 6 million lines of > tab-delimited data. How many fields are there an each line? > I have to perform some filtration on the data and > keep the good data. After filtration, I have about 5.5 million data left > remaining. As you might already guessed, I have to read them in batches > and I did so using .readlines(100000000). I'd have guessed differently. Typically, I would say that you read one line, apply whatever operation you want to it and then write out the result. At least that is the "typical" operation of filtering. > a=open("bigfile") I guess you are on MS Windows. There, you have different handling of textual and non-textual files with regards to the handling of line endings. Generally, using non-textual as input is easier, because it doesn't require any translations. However, textual input is the default, therefore: a = open("bigfile", "rb") Or, even better: with open("bigfile", "rb") as a: to make sure the file is closed correctly and in time. > matrix=[] > while True: > lines = a.readlines(100000000) > for line in lines: I believe you could do for line in a: # use line here > data=line.split("\t") Question here: How many elements does each line contain? And what is their content? The point is that each object has its overhead, and if the content is just e.g. an integral number or a short string, the ratio of interesting content to overhead is rather bad! Compare this to storing a longer string with just the overhead of a single string object instead, it should be obvious. > However, if I modify the code, to store as a list of string rather than > a list of list by changing the append statement stated above to > "matrix.append("\t".join(data))", then I do not run out of memory. You already have the result of that join: matrix.append(line) > Does anyone know why is there such a big difference memory usage when > storing the matrix as a list of list, and when storing it as a list of > string? According to __sizeof__ though, the values are the same whether > storing it as a list of list, or storing it as a list of string. I can barely believe that. How are you using __sizeof__? Why aren't you using sys.getsizeof() instead? Are you aware that the size of a list doesn't include the size for its content (even though it grows with the number of elements), while the size of a string does? > Is there any methods how I can store all the info into a list of list? I > have tried creating such a matrix of equivalent size and it only uses > 35mb of memory but I am not sure why when using the code above, the > memory usage shot up so fast and exceeded 2GB. The size of an empty list is 20 here, plus 4 per element (makes sense on a 32-bit machine), excluding the elements themselves. That means that you have around 8M elements (25448700/4). These take around 32MB of memory, which is what you are probably seeing. The point is that your 35mb don't include any content, probably just a single interned integer or None, so that all elements of your list are the same and only require memory once. In your real-world application that is obviously not so. My suggestions: 1. Find out what exactly is going on here, in particular why our interpretations of the memory usage differ. 2. Redesign your code to really use a filtering design, i.e. don't keep the whole data in memory. 3. If you still have memory issues, take a look at the array library, which should make storage of large arrays a bit more efficient. Good luck! Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From aotto1968 at users.berlios.de Tue Nov 30 06:56:28 2010 From: aotto1968 at users.berlios.de (Andreas Otto) Date: Tue, 30 Nov 2010 12:56:28 +0100 Subject: ANNOUNCE: NHI1-0.10, PLMK-1.8 und libmsgque-4.8 Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Dear User, ANNOUNCE: Major Feature Release ==================================== libmsgque: Application-Server-Toolkit for C, C++, JAVA, C#, Go, TCL, PERL, PHP, PYTHON, RUBY, VB.NET PLMK: Programming-Language-Microkernel NHI1: Non-Human-Intelligence #1 STATEMENT ========= "It takes 2 years" "and a team of qualified software developers" "to implement a new programming language," "but it takes only 2 weeks to add a micro-kernel" - - aotto1968 SUMMARY ======= Add support from the programming language "Go" from Google LINKS ===== UPDATE - PLMK definition > http://openfacts2.berlios.de/wikien/index.php/BerliosProject:NHI1_-_TheKernel ChangeLog: > http://nhi1.berlios.de/theLink/changelog.htm libmsgque including PHP documentation: > http://nhi1.berlios.de/theLink/index.htm NHI1: > http://nhi1.berlios.de/ DOWNLOAD: > http://developer.berlios.de/projects/nhi1/ Go man pages: > reference: gomsgqueref.n > tutorial: gomsgquetut.n mfg, Andreas Otto (aotto1968) -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.15 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org/ iQEcBAEBAgAGBQJM9OZsAAoJEGTcPijNG3/A+qwH/1WT3K8619eLzQ78dylS623r qrZtHXRxieD+4GIBgkU7KbNu+LGztxasLW9upafmmF2mGcWtIFuiOEJtw6MJM+07 0X7elXM5WZkXK65dbLE5bbSfO0DHw5T6aIweogA3zjcjDbB3rSC/T6WIlZB4HNYh nBj9xC6WMP7s/jEjs4i5FCRT6gTRzDDJbR+SXqNEEYc/z8wVKPUDfpU/6JGxl9MV rPSUsO+YdZX0XI7+imiUYSVyt+kniL3C36kGON/qGDahscoQYFS6GdoI5XDzI0c+ jN7Q2Ecrphd5F5G/2plNLbVy4mPVd9k/I8VjXMaHLm+skT2Z4Zt7aF29A1FFw68= =/O74 -----END PGP SIGNATURE----- From __peter__ at web.de Tue Nov 30 07:22:40 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 30 Nov 2010 13:22:40 +0100 Subject: Memory issues when storing as List of Strings vs List of List References: Message-ID: OW Ghim Siong wrote: > Hi all, > > I have a big file 1.5GB in size, with about 6 million lines of > tab-delimited data. I have to perform some filtration on the data and > keep the good data. After filtration, I have about 5.5 million data left > remaining. As you might already guessed, I have to read them in batches > and I did so using .readlines(100000000). After reading each batch, I > will split the line (in string format) to a list using .split("\t") and > then check several conditions, after which if all conditions are > satisfied, I will store the list into a matrix. > > The code is as follows: > -----Start------ > a=open("bigfile") > matrix=[] > while True: > lines = a.readlines(100000000) > for line in lines: > data=line.split("\t") > if several_conditions_are_satisfied: > matrix.append(data) > print "Number of lines read:", len(lines), "matrix.__sizeof__:", > matrix.__sizeof__() > if len(lines)==0: > break > -----End----- As Ulrich says, don't use readlines(), use for line in a: ... that way you have only one line in memory at a time instead of the huge lines list. > Results: > Number of lines read: 461544 matrix.__sizeof__: 1694768 > Number of lines read: 449840 matrix.__sizeof__: 3435984 > Number of lines read: 455690 matrix.__sizeof__: 5503904 > Number of lines read: 451955 matrix.__sizeof__: 6965928 > Number of lines read: 452645 matrix.__sizeof__: 8816304 > Number of lines read: 448555 matrix.__sizeof__: 9918368 > > Traceback (most recent call last): > MemoryError > > The peak memory usage at the task manager is > 2GB which results in the > memory error. > > However, if I modify the code, to store as a list of string rather than > a list of list by changing the append statement stated above to > "matrix.append("\t".join(data))", then I do not run out of memory. > > Results: > Number of lines read: 461544 matrix.__sizeof__: 1694768 > Number of lines read: 449840 matrix.__sizeof__: 3435984 > Number of lines read: 455690 matrix.__sizeof__: 5503904 > Number of lines read: 451955 matrix.__sizeof__: 6965928 > Number of lines read: 452645 matrix.__sizeof__: 8816304 > Number of lines read: 448555 matrix.__sizeof__: 9918368 > Number of lines read: 453455 matrix.__sizeof__: 12552984 > Number of lines read: 432440 matrix.__sizeof__: 14122132 > Number of lines read: 432921 matrix.__sizeof__: 15887424 > Number of lines read: 464259 matrix.__sizeof__: 17873376 > Number of lines read: 450875 matrix.__sizeof__: 20107572 > Number of lines read: 458552 matrix.__sizeof__: 20107572 > Number of lines read: 453261 matrix.__sizeof__: 22621044 > Number of lines read: 413456 matrix.__sizeof__: 22621044 > Number of lines read: 166464 matrix.__sizeof__: 25448700 > Number of lines read: 0 matrix.__sizeof__: 25448700 > > In this case, the peak memory according to the task manager is about 1.5 > GB. > > Does anyone know why is there such a big difference memory usage when > storing the matrix as a list of list, and when storing it as a list of > string? According to __sizeof__ though, the values are the same whether > storing it as a list of list, or storing it as a list of string. Is sizeof gives you the "shallow" size of the list, basically the memory to hold C pointers to the items in the list. A better approximation for the total size of a list of lists of string is >>> from sys import getsizeof as sizeof >>> matrix = [["alpha", "beta"], ["gamma", "delta"]] >>> sizeof(matrix), sum(sizeof(row) for row in matrix), sum(sizeof(entry) for row in matrix for entry in row) (88, 176, 179) >>> sum(_) 443 As you can see the outer list requires only a small portion of the total memory, and its relative size will decrease as the matrix grows. The above calculation may still be wrong because some of the strings could be identical. Collapsing identical strings into a single object is also a way to save memory if you have a significant number of repetitions. Try matrix = [] with open(...) as f: for line in f: data = line.split("\t") if ...: matrix.append(map(intern, data)) to see whether it sufficiently reduces the amount of memory needed. > there any methods how I can store all the info into a list of list? I > have tried creating such a matrix of equivalent size and it only uses > 35mb of memory but I am not sure why when using the code above, the > memory usage shot up so fast and exceeded 2GB. > > Any advice is greatly appreciated. > > Regards, > Jinxiang From hpj at urpla.net Tue Nov 30 08:30:30 2010 From: hpj at urpla.net (Hans-Peter Jansen) Date: Tue, 30 Nov 2010 14:30:30 +0100 Subject: remote control firefox with python In-Reply-To: <4cf273b9$0$19685$426a74cc@news.free.fr> References: <4cf273b9$0$19685$426a74cc@news.free.fr> Message-ID: <201011301430.30180.hpj@urpla.net> On Sunday 28 November 2010, 16:22:33 News123 wrote: > Hi, > > > I wondered whether there is a simpe way to > 'remote' control fire fox with python. > > > With remote controlling I mean: > - enter a url in the title bar and click on it > - create a new tab > - enter another url click on it > - save the html document of this page > - Probably the most difficult one: emulate a click or 'right click' > on a certain button or link of the current page. > - other interesting things would be to be able to enter the master > password from a script > - to enable disable proxy settings while running. > > The reason why I want to stay within Firefox and not use any other > 'mechanize' frame work is, that the pages I want to automate might > contain a lot of javascript for the construction of the actual page. If webkit based rendering in an option (since its javascript engine is respected by web developers nowadays..), you might want to check out PyQt, based on current versions of Qt. It provides very easy access to a full featured web browser engine without sacrificing low level details. All your requirements are provided easily (if you're able to grok the Qt documentation, e.g. ignore all C++ clutter, you're set). I've transcoded all available QtWebKit examples to python lately, available here: http://www.riverbankcomputing.com/pipermail/pyqt/2010-November/028614.html The attachment is a tar.bz2 archive, btw. Clicking is archived by: webelement.evaluateJavaScript( "var event = document.createEvent('MouseEvents');" "event.initEvent('click', true, true);" "this.dispatchEvent(event);" ) Cheers, Pete From roy at panix.com Tue Nov 30 08:33:11 2010 From: roy at panix.com (Roy Smith) Date: Tue, 30 Nov 2010 08:33:11 -0500 Subject: TDD in python References: <0906c010-709d-41d9-8b29-2f42afb87f94@32g2000yqz.googlegroups.com> <58fe3680-21f5-42f8-9341-e069cbb88975@r19g2000prm.googlegroups.com> Message-ID: In article <58fe3680-21f5-42f8-9341-e069cbb88975 at r19g2000prm.googlegroups.com>, rustom wrote: > Looking around I found this: > http://bytes.com/topic/python/answers/43330-unittest-vs-py-test > where Raymond Hettinger no less says quite unequivocally that he > prefers test.py to builtin unittest > because it is not so heavy-weight > > Is this the general consensus nowadays among pythonistas? > [Note I tend to agree but Ive no experience so asking] Both frameworks have their fans; I doubt you'll find any consensus. Pick one, learn it, and use it. What's important is that you write tests, write lots of tests, and write good tests. Which framework you use is a detail. From marduk at letterboxes.org Tue Nov 30 08:46:53 2010 From: marduk at letterboxes.org (Albert Hopkins) Date: Tue, 30 Nov 2010 08:46:53 -0500 Subject: Python 3 encoding question: Read a filename from stdin, subsequently open that filename In-Reply-To: References: Message-ID: <1291124813.414884.22.camel@WOPR> On Tue, 2010-11-30 at 11:52 +0100, Peter Otten wrote: Dan Stromberg wrote: > > > I've got a couple of programs that read filenames from stdin, and then > > open those files and do things with them. These programs sort of do > > the *ix xargs thing, without requiring xargs. > > > > In Python 2, these work well. Irrespective of how filenames are > > encoded, things are opened OK, because it's all just a stream of > > single byte characters. > > I think you're wrong. The filenames' encoding as they are read from stdin > must be the same as the encoding used by the file system. If the file system > expects UTF-8 and you feed it ISO-8859-1 you'll run into errors. > > I think this is wrong. In Unix there is no concept of filename encoding. Filenames can have any arbitrary set of bytes (except '/' and '\0'). But the filesystem itself neither knows nor cares about encoding. You always have to know either > > (a) both the file system's and stdin's actual encoding, or > (b) that both encodings are the same. > > If this is true, then I think that it is wrong to do in Python3. Any language should be able to deal with the filenames that the host OS allows. Anyway, going on with the OP.. can you open stdin so that you can accept arbitrary bytes instead of strings and then open using the bytes as the filename? I don't have that much experience with Python3 to say for sure. -a From jason.heeris at gmail.com Tue Nov 30 09:16:24 2010 From: jason.heeris at gmail.com (Jason) Date: Tue, 30 Nov 2010 06:16:24 -0800 (PST) Subject: How does GC affect generator context managers? Message-ID: <53061109-470b-4ea3-8718-cd383da796bd@a28g2000prb.googlegroups.com> I've been reading through the docs for contextlib and PEP 343, and came across this: Note that we're not guaranteeing that the finally-clause is executed immediately after the generator object becomes unused, even though this is how it will work in CPython. ...referring to context managers created via the contextlib.contextmanager decorator containing cleanup code in a "finally" clause. While I understand that Python-the-language does not specify GC semantics, and different implementations can do different things with that, what I don't get is how GC even relates to a context manager created from a generator. As I understood it, when the "with" block exits, the __exit__() method is called immediately. This calls the next() method on the underlying generator, which forces it to run to completion (and raise a StopIteration), which includes the finally clause... right? ? Jason From sda457 at gmail.com Tue Nov 30 09:21:29 2010 From: sda457 at gmail.com (SA sada) Date: Tue, 30 Nov 2010 06:21:29 -0800 (PST) Subject: nike shoes , fashi on clothes ; brand hand bags Message-ID: Dear customers, thank you for your support of our company. Here, there's good news to tell you: The company recently launched a number of new fashion items! ! Fashionable and welcome everyone to come buy. If necessary, please plut:==== http://www.vipshops.org ====== ==== http://www.vipshops.org ====== ==== http://www.vipshops.org ====== ==== http://www.vipshops.org ====== ==== http://www.vipshops.org ====== ==== http://www.vipshops.org ====== ==== http://www.vipshops.org ====== 1) More pictures available on our website (===== http://www.vipshops.org ====) 2) Many colors available . 3) Perfect quality, 4) 100% safe door to door delivery, Best reputation , Best services Posted: 4:13 pm on November 21st From xheruacles at gmail.com Tue Nov 30 09:37:47 2010 From: xheruacles at gmail.com (Xavier Heruacles) Date: Tue, 30 Nov 2010 22:37:47 +0800 Subject: how to go on learning python Message-ID: I'm basically a c/c++ programmer and recently come to python for some web development. Using django and javascript I'm afraid I can develop some web application now. But often I feel I'm not good at python. I don't know much about generators, descriptors and decorators(although I can use some of it to accomplish something, but I don't think I'm capable of knowing its internals). I find my code ugly, and it seems near everything are already gotten done by the libraries. When I want to do something, I just find some libraries or modules and then just finish the work. So I'm a bit tired of just doing this kind of high level scripting, only to find myself a bad programmer. Then my question is after one coded some kind of basic app, how one can keep on learning programming using python? Do some more interesting projects? Read more general books about programming? or...? -------------- next part -------------- An HTML attachment was scrubbed... URL: From duncan.booth at invalid.invalid Tue Nov 30 10:01:15 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 30 Nov 2010 15:01:15 GMT Subject: How does GC affect generator context managers? References: <53061109-470b-4ea3-8718-cd383da796bd@a28g2000prb.googlegroups.com> Message-ID: Jason wrote: > As I understood it, when the "with" block exits, the __exit__() method > is called immediately. This calls the next() method on the underlying > generator, which forces it to run to completion (and raise a > StopIteration), which includes the finally clause... right? > That is true if the "with" block exits, but if the "with" block (or "try".."finally" block) contains "yield" you have a generator. In that case if you simply drop the generator on the floor the cleanup at the end of the "with" will still happen, but maybe not until the generator is garbage collected. def foo(): with open("foo") as foo: for line in foo: yield line ... bar = foo() print bar.next() del bar # May close the file now or maybe later... -- Duncan Booth http://kupuguy.blogspot.com From sol2ray at gmail.com Tue Nov 30 10:03:26 2010 From: sol2ray at gmail.com (Sol Toure) Date: Tue, 30 Nov 2010 10:03:26 -0500 Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance In-Reply-To: <8linmqF99gU1@mid.individual.net> References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> <7xsjyp2d12.fsf@ruckus.brouhaha.com> <8linmqF99gU1@mid.individual.net> Message-ID: Most of the examples presented here can use the "decorator pattern" instead. Especially the window system On Mon, Nov 29, 2010 at 5:27 PM, Gregory Ewing wrote: > Paul Rubin wrote: > > The classic example though is a window system, where you have a "window" >> class, and a "scroll bar" class, and a "drop-down menu" class, etc. and >> if you want a window with a scroll bar and a drop-down menu, you inherit >> from all three of those classes. >> > > Not in any GUI library I've ever seen. Normally there would > be three objects involved in such an arrangement, a Window, > a ScrollBar and a DropDownMenu, connected to each other in > some way. > > -- > Greg > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://www.afroblend.com African news as it happens. -------------- next part -------------- An HTML attachment was scrubbed... URL: From bloom.dax at gmail.com Tue Nov 30 10:03:28 2010 From: bloom.dax at gmail.com (Dax Bloom) Date: Tue, 30 Nov 2010 07:03:28 -0800 (PST) Subject: Programming games in historical linguistics with Python Message-ID: Hello, Following a discussion that began 3 weeks ago I would like to ask a question regarding substitution of letters according to grammatical rules in historical linguistics. I would like to automate the transformation of words according to complex rules of phonology and integrate that script in a visual environment. Here follows the previous thread: http://groups.google.com/group/comp.lang.python/browse_thread/thread/3c55f9f044c3252f/fe7c2c82ecf0dbf5?lnk=gst&q=evolutionary+linguistics#fe7c2c82ecf0dbf5 Is there a way to refer to vowels and consonants as a subcategory of text? Is there a function to remove all vowels? How should one create and order the dictionary file for the rules? How to chain several transformations automatically from multiple rules? Finally can anyone show me what existing python program or phonological software can do this? What function could tag syllables, the word nucleus and the codas? How easy is it to bridge this with a more visual environment where interlinear, aligned text can be displayed with Greek notations and braces as usual in the phonology textbooks? Best regards, Dax Bloom From python.list at tim.thechases.com Tue Nov 30 10:15:47 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 30 Nov 2010 09:15:47 -0600 Subject: Memory issues when storing as List of Strings vs List of List In-Reply-To: <4CF4D20F.4060400@bii.a-star.edu.sg> References: <4CF4D20F.4060400@bii.a-star.edu.sg> Message-ID: <4CF51523.9000107@tim.thechases.com> On 11/30/2010 04:29 AM, OW Ghim Siong wrote: > a=open("bigfile") > matrix=[] > while True: > lines = a.readlines(100000000) > for line in lines: > data=line.split("\t") > if several_conditions_are_satisfied: > matrix.append(data) > print "Number of lines read:", len(lines), "matrix.__sizeof__:", > matrix.__sizeof__() > if len(lines)==0: > break As others have mentiond, don't use .readlines() but use the file-object as an iterator instead. This can even be rewritten as a simple list-comprehension: from csv import reader matrix = [data for data in reader(file('bigfile.txt', 'rb'), delimiter='\t') if several_conditions_are_satisfied(data) ] Assuming that you're throwing away most of the data (the final "matrix" fits well within memory, even if the source file doesn't). -tkc From ph.ton.sharma at gmail.com Tue Nov 30 10:15:55 2010 From: ph.ton.sharma at gmail.com (ton ph) Date: Tue, 30 Nov 2010 20:45:55 +0530 Subject: Help: problem in setting the background colour ListBox Message-ID: Hi everyone , I have a requirement of displaying my data in a textCtrl like widget , but i need that the data in the row be clickable , so as when i click the data i could be able to get fire and even and get me the selected data value.After a long search i found ListBox to be perfect for my use but When i try to set the backGround colour to the colour of my application requirement i am not able to do so, but i am able to set the foreground colour . Hope someone will guide me in solving my problem.... Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From solipsis at pitrou.net Tue Nov 30 10:16:52 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Tue, 30 Nov 2010 16:16:52 +0100 Subject: Python 2.7.1 References: <7c7d85f5-740c-4a29-8899-cdab38865ac9@32g2000yqz.googlegroups.com> Message-ID: <20101130161652.79117e8e@pitrou.net> On Mon, 29 Nov 2010 15:11:28 -0800 (PST) Spider wrote: > > 2.7 includes many features that were first released in Python 3.1. The faster io module ... > > I understand that I/O in Python 3.0 was slower than 2.x (due to quite > a lot of the code being in Python rather than C, I gather), and that > this was fixed up in 3.1. So, io in 3.1 is faster than in 3.0. > > Is it also true that io is faster in 2.7 than 2.6? That's what the > release notes imply, but I wonder whether that comment has been back- > ported from the 3.1 release notes, and doesn't actually apply to 2.7. The `io` module, which was backported from 3.1/3.2, is faster than in 2.6, but that's not what is used by default in 2.x when calling e.g. open() or file() (you'd have to use io.open() instead). So, as you suspect, the speed of I/O in 2.7 hasn't changed. The `io` module is available in 2.6/2.7 so that you can experiment with some 3.x features without switching, and in this case it's much faster than 2.6. Regards Antoine. From solipsis at pitrou.net Tue Nov 30 10:19:19 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Tue, 30 Nov 2010 16:19:19 +0100 Subject: Python 3 encoding question: Read a filename from stdin, subsequently open that filename References: <339421.80548.qm@web54205.mail.re2.yahoo.com> Message-ID: <20101130161919.693a1d78@pitrou.net> On Mon, 29 Nov 2010 21:52:07 -0800 (PST) Yingjie Lan wrote: > --- On Tue, 11/30/10, Dan Stromberg wrote: > > In Python 3, I'm finding that I have encoding issues with > > characters > > with their high bit set.? Things are fine with strictly > > ASCII > > filenames.? With high-bit-set characters, even if I > > change stdin's > > encoding with: > > Co-ask. I have also had problems with file names in > Chinese characters with Python 3. I unzipped the > turtle demo files into the desktop folder (of > course, the word 'desktop' is in Chinese, it is > a windows XP system, localization is Chinese), then > all in a sudden some of the demos won't work > anymore. But if I move it to a folder whose > path contains only english characters, everything > comes back to normal. Can you try the latest 3.2alpha4 (*) and check if this is fixed? If not, then could you please open a bug on http://bugs.python.org ? (*) http://python.org/download/releases/3.2/ Thank you Antoine. From solipsis at pitrou.net Tue Nov 30 10:27:40 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Tue, 30 Nov 2010 16:27:40 +0100 Subject: Memory issues when storing as List of Strings vs List of List References: <4CF4D20F.4060400@bii.a-star.edu.sg> Message-ID: <20101130162740.79789b34@pitrou.net> On Tue, 30 Nov 2010 18:29:35 +0800 OW Ghim Siong wrote: > > Does anyone know why is there such a big difference memory usage when > storing the matrix as a list of list, and when storing it as a list of > string? That's because any object has a fixed overhead (related to metadata and allocation), so storing a matrix line as a sequence of several objects rather than a single string makes the total overhead larger, especially when the payload of each object is small. If you want to mitigate the issue, you could store your lines as tuples rather than lists, since tuples have a smaller memory footprint: matrix.append(tuple(data)) > According to __sizeof__ though, the values are the same whether > storing it as a list of list, or storing it as a list of string. As mentioned by others, __sizeof__ only gives you the size of the container, not the size of the contained values (which is where the difference is here). Regards Antoine. From alice at gothcandy.com Tue Nov 30 10:30:09 2010 From: alice at gothcandy.com (=?utf-8?Q?Alice_Bevan=E2=80=93McGregor?=) Date: Tue, 30 Nov 2010 07:30:09 -0800 Subject: how to go on learning python References: Message-ID: Howdy Xavier! [Apologies for the length of this; I didn't expect to write so much!] I've been a Python programmer for many years now (having come from a PHP, Perl, C, and Pascal background) and I'm constantly learning new idioms and ways of doing things that are more "Pythonic"; cleaner, more efficient, or simply more beautiful. I learn by coding, rather than by reading books, taking lectures, or sitting idly watching screencasts. I constantly try to break the problems I come up with in my head into smaller and smaller pieces, then write the software for those pieces in as elegant a method as possible. Because of my "turtles all the way down" design philosophy, a lot of my spare time projects have no immediate demonstrable benefit; I code them for fun! I have a folder full of hundreds of these little projects, the vast majority of which never see a public release. I also collect little snippets of code that I come across[1] or write, and often experiment with performance tests[2] of small Python snippets. Often I'll assign myself the task of doing something far outside my comfort zone; a recent example is writing a HTTP/1.1 web server. I had no idea how to do low-level socket programming in Python, let alone how HTTP actually worked under-the-hood, and because my goal wasn't (originally) to produce a production-quality product for others it gave me the freedom to experiment, rewrite, and break things in as many ways as I wanted. :) I had people trying to convince me that I shouldn't re-invent the wheel ("just use Twisted!") though they mis-understood the reason for my re-invention: to learn. It started as a toy 20-line script to dump a static HTTP/1.0 response on each request and has grown into a ~270 line fully HTTP/1.1 compliant, ultra-performant multi-process HTTP server rivalling pretty much every other pure-Python web server I've tested. (I still don't consider it production ready, though.) Progressive enhancement as I came up with and implemented ideas meant that sometimes I had to rewrite it from scratch, but I'm quite proud of the result and have learned far more than I expected in the process. While I don't necessarily study books on Python, I did reference HTTP: The Definitive Guide and many websites in developing that server, and I often use the Python Quick Reference[3] when I zone out and forget something basic or need to find something more advanced. In terms of understanding how Python works, or how you can use certain semantics (or even better, why you'd want to!) Python Enhancement Proposals (PEPs) can be an invaluable resource. For example, PEP 318[4] defines what a decorator is, why they're useful, how they work, and how you can write your own. Pretty much everything built into Python after Python 2.0 was first described, reasoned, and discussed in a PEP. If you haven't seen this already, the Zen of Python[5] (a PEP) has many great guidelines. I try to live and breathe the Zen. So that's my story: how I learn to improve my own code. My motto, "re-inventing the wheel, every time," is the short version of the above. Of course, for commercial work I don't generally spend so much time on the nitty-gritty details; existing libraries are there for a reason, and, most of the time, Getting Things Done? is more important than linguistic purity! ;) ? Alice. [1] https://github.com/GothAlice/Random/ [2] https://gist.github.com/405354 [3] http://rgruet.free.fr/PQR26/PQR2.6.html [4] http://www.python.org/dev/peps/pep-0318/ [5] http://www.python.org/dev/peps/pep-0020/ From smallpox911 at gmail.com Tue Nov 30 10:56:32 2010 From: smallpox911 at gmail.com (small Pox) Date: Tue, 30 Nov 2010 07:56:32 -0800 (PST) Subject: Iran slams Wiki-release as US psywar - WIKILEAKS is replacing those BIN LADEN communiques of CIA (the global ELITE) intended to threaten MASSES Message-ID: <1fc67adb-212d-40a7-8602-c354ca5349dd@l17g2000yqe.googlegroups.com> Iran slams Wiki-release as US psywar - WIKILEAKS is replacing those BIN LADEN communiques of CIA (the global ELITE) intended to threaten MASSES CIA is the criminal agency of the global elite. They want to destroy the middle class from the planet and also create a global tyranny of a police state. http://presstv.ir/detail/153128.html http://presstv.ir/detail/153128.html http://presstv.ir/detail/153128.html Iran slams Wiki-release as US psywar Mon Nov 29, 2010 12:56PM Share | Email | Print Iran's President Mahmoud Ahmadinejad has questioned the recent 'leaked' documents published by Wikileaks website, describing them as part of a US "psychological warfare." In response to a question by Press TV on Monday over the whistleblower website's "leaks," President Mahmoud Ahmadinejad said "let me first correct you. The material was not leaked, but rather released in an organized effort." "The US administration releases documents and makes a judgment based on them. They are mostly like a psychological warfare and lack legal basis," President Ahmadinejad told reporters on Monday. "The documents will certainly have no political effects. Nations are vigilant today and such moves will have no impact on international relations," the Iranian chief executive added at the press briefing in Tehran. President Ahmadinejad stressed that the Wikileaks "game" is "not even worth a discussion and that no one would waste their time analysing them." "The countries in the region are like friends and brothers and these acts of mischief will not affect their relations," he concluded. Talks with the West The president announced that aside from Brazil and Turkey a number of other countries may take part in the new round of talks between Iran and the P5+1 -- Britain, China, France, Russia, the US, plus Germany. Human rights "They (Western powers) trample on the dignity of man, their identity and real freedom. They infringe all of these and then they call it human rights," Ahmadinejad said. Earlier this month, the UN General Assembly's Third Committee accused Iran of violating human rights regulations. The 118-member Non-Aligned Movement and the 57-member Organization of the Islamic Conference have condemned the resolution against the Islamic Republic. "In 2005, the human rights [issue] got a new mechanism in the United Nations ... human rights was pushed away and human rights was used for political manipulation," Secretary General of Iran's High Council for Human Rights Mohammed Javad Larijani told Press TV following the vote on the resolution. This is while the United Nations Human Rights Council reviewed the US human rights record for the first time in its history. The council then issued a document making 228 suggestions to the US to improve its rights record. IAEA 'leak' The president said that Iran has always had a positive relationship with the International Atomic Energy Agency but criticized the UN nuclear agency for caving under pressure from the "masters of power and wealth." The president said due to this pressure the IAEA has at times adopted "unfair and illegal stances" against the Islamic Republic. "Their recent one (IAEA report) is better than the previous ones and is closer to the truth but still all the facts are not reflected," he added. "Of course the latest report also has shortcomings, for example all [of Iran's nuclear] information has been released and these are secret and confidential documents belonging to the country." Ahmadinejad said since Iran was following a policy of nuclear transparency, it did not care about the leaks, but called the move 'illegal." New world order "The world needs order ? an order in which different people form different walks of life enjoy equal rights and proper dignity," the president said in his opening speech before taking questions form Iranian and foreign journalist. The president added that the world was already on the path to setting up this order. Iran isolation When asked to comment on the US and Western media claims that Iran has become highly isolated in the region despite an active diplomacy with Persian Gulf littoral states, the president said the remarks were part of the "discourse of hegemony." "In the hegemonic discourse, it seems that concepts and words take on different meanings than those offered by dictionaries," Ahmadinejad said. "When they say they have isolated Iran, it means that they themselves are isolated and when they say Iran is economically weak, it means that it has strengthened," the president reasoned. When they say there is a dictatorship somewhere, it means that country is really chosen by the people and vise a versa, the president further noted, adding, "I do not want to name names." ZHD/HGH/SF/MMN/MB Comments Add Comment Click Here Note: The views expressed and the links provided on our comment pages are the personal views of individual contributors and do not necessarily reflect the views of Press TV. check this out 11/30/2010 9:18:05 AMit is a coincidence that ?documents regarding Israel, their spying, influence peddling, suspicions of complicity in terrorism, Yemen, Iraq, Pakistan, Somalia, across Europe and even the Detroit bombing, those reports are there, they are classified but you will never see one on Wikileaks. In fact, they are the only classified information that never gets out to the news.? Ali 11/30/2010 7:47:47 AM"The world needs order ? an order in which different people form different walks of life enjoy equal rights and proper dignity,"very true! JHK 11/30/2010 7:37:09 AMIran should offer support to Western Media which is trying to portray the Truth. Moving these outlets outside the United States may help with this. Everyday American Citizens are at a loss as to what to do, and they need our support, some of them are Muslims. It's time4Africa 11/30/2010 7:19:25 AMDefinitely a zionist plot. All her enemies were bashed, and it was the only country to be praised in these 'leaks'. People are wiser and smarter now. "Fool me ones, shame on you. Fool me twice, shame on me!" SMARTI 11/30/2010 7:04:09 AMLOOK AT THE WESTERN MANIPULATING MEDIA, LIKE CNN FOX NEWS.FRONTPAGE HEADLINES LIKE; 'HOSTILITY TOWARDS IRAN BY NEIGHBORS'.BUT THIS LIE MEDIA ALWAYS FAILS TO MENTION THE ARAB PUBLIC OPINION TOWARDS IRAN! THEIR PROPAGANDA DON'T DISTINGUISH BETWEEN ARAB PEOPLE AND THEIR LEADERS! REASON?!: DIVIDE AND RULE!. THIS PRINCIPLE NEVER CHANGES!. IRAN BE CAREFULL, REMEMBER WHAT HIZBOLLAH LEADER ONCE SAID:THEY HAVE FAILED ON ALL THEIR PLOTS, THEY WILL TRY THEIR LAST ATTEMPT BY CREATING SUNNI-SHIA DIVISIONS 11/30/2010 6:49:48 AMI ask Sunni brothers to view Shiite not as a different religion but as a different school of thought. For example we have Hanafi, Hanbaly, etc... within Sunni Islam, why not view Shia also as such? The differences are not in the paradigm, therefore unity can be maintained. IRAN IS TOO WISE FOR CIA 11/30/2010 6:27:35 AMTHE USA IS USING WIKILEAKS TO CO-ORDINATE AND RELEASE MATERIAL WITH ALL THE OTHER STUFF TO MAKE IT LOOK LIKE IT WAS WIKILEAKS BUT IT ISNT IT IS THE CIA AND IN THIS WAY THEY CAN CAUSE PROBLEMS FOR IRAN AND NEIGHBOURING COUNTRIES. IRAN rules 11/30/2010 5:54:27 AMWIKILEAKS, IS AMERICA NEW PUBLIC RELATION TOOLS.WIKILEAKS IS HEAVELY INFLUENCED BY AMERICAN DOLLARS.AS USUAL AMERICA HIDE ITS CRIMES BY THIS TYPE OF MISINFORMATION. ify1979 11/30/2010 5:21:30 AMwiki leaks is just a proppganda game its playing wih iran! The Open Conspiracy 11/30/2010 4:36:52 AMThis is a plan that Winston Churchill had predicted would be the policy for the New World Order. Tony Blair was a typical "spill the beans" kind of speaker and the new ones are copying his style, sometimes chuckling as they make their statements. mumbo 11/30/2010 4:32:13 AMI almost think that there has never been a military coup in the US cause the military always gets (almost) all the money it wants. So the head of state has to take care of the military apparatus sustain their need for growing budgets and ongoing conflicts whether it was the red indians, french, spanish of the 19th century or the germans, vietnamese, arabs, soviets etc of the 20th and 21st century and beyond 11/30/2010 2:59:05 AMWhat many seem to have forgotten is that the so- called anti-Iranian sentiments of all the Arab PG states have been constantly touted by Western media for quite a while, long before these "leaks". Such news were also reported by PressTV and you don't think Iranians know what's going on? @ Political Game 11/30/2010 2:55:16 AMThe media is a great tool if one knows how to use it, and one of the oldest tricks in the game is a controlled leak. This is the case here. Sure, you can fool a few ignorant westerners with this trick, but Iran is an old and civilized country. Your tricks won't work here. The game is up. 11/30/2010 2:39:42 AMDamage Control by Iran's President who is rushing in, I would recommend him to be on "wait and see" mode rather than making any comments. Wikileaks may be RIGHT and maybe NOT. Political Game 11/30/2010 2:25:14 AMPresident Ahmadinejad is in denial, He knows that Wikileaks files are based on FACTS & TRUETH, however to show the world and assure the neighbouring countries(Saudis, UAE, Bahrain,etc) that Iran won't buy those facts. Just a little Political Game going on here. PEACE 11/30/2010 2:12:46 AMIt is a fabrication, how come 1/4 millions documents leak and some must br fake. @european 11/30/2010 2:07:23 AMThese are also not leaks because there are strategic elements in the contents to achieve certain agenda as with Iran and certain other countries only. Well said John Ellis 11/30/2010 1:56:06 AMThe Western media is owned by builderbergs who sees the public as dispensable items that can be best served at the lowest level of cognitive recall of events without inference, deduction, analysis, and any form of reasoning. The truth is the public may be ahead of the builderbergs in at least not tuning in as predicted. No body is in charge. So, the builderbergs have opted for offshore investments and outsourcing for the last couple of decades. The dynamics continue to indicate a bizarre future. Ranim Kalif 11/30/2010 1:46:55 AMRumour has it... That wikileaks is nothing but a CIA propaganda/counter propaganda program. The proof lies with The head honcho Julian Asange. Apparently Mr. Asange believes that 9/11 was done by fanatics from a cave in afghanistan, but anyone with half a brain can tell you that 3 steel framed building cannot collapse due to fire, its just not mathematically possible. And math does not lie, but people do. @Anti-bully 11/30/2010 12:54:13 AMAfter this week, you can retrospectively analyse and find more clues from the so-called WL documents that can be told now based on extrapolation using systemic hypocrisy templates. The West is so easy to read in either way. But, stay on the objective track. Anti-bully 11/30/2010 12:22:43 AM(Cont.) After the "Second Wikileaks" a month ago I said: "The answer to the Western idiocy is simple: Iran, Iraq & Afghanistan are neighbours, and you [[]the West INCL. Israel] DON'T BELONG THERE! SHOO!" Those neighbours of course include: Pakistan, Turkey, Azerbaijan, Syria, Lebanon, Central Asia, .... Revenge and Blessing 11/30/2010 12:12:39 AMRevenge is like Hurricane Katrina, California forest fire, American soldiers' suicides, Gulf of Mexico Spills, US rescue helicopters colliding and falling in an Iranian desert ....Blessings come with gentle earthquakes as wake-up calls to improve construction of buildings, wisdom to take technological leaps, intelligence to see the Wikileak psychological warfare,.... John Ellis 11/30/2010 12:06:17 AMWikiLeaks is doing to the public what Western corporate media does each and every day -- keep society locked in darkness by not saying a word about the root cause or solution to a problem, disclosing only the confusion, controversy, blood and guts of a problem, until finally the people in disgust back away and let the corporate rich to be enriched by the problem. Iranians know from their history 11/29/2010 11:57:39 PMthat when their leaders are liked by the West the country is in trouble and vice versa when the leaders are criticized by the West they must be very good leaders! New World Order = Slavery For All 11/29/2010 11:47:02 PMIt is already evident in the West through the public disenchantment and the authority's unwillingness to serve the public as before. The governments are not doing their usual services as if they are preparing to run slave camps soon. There are lots of telltales like trampling on constitutional rights that are bothersome. Saul 11/29/2010 11:36:33 PMI hear that the President Of Iran will soon be impeached. Is this true. Iran helps because Iran believes in God 11/29/2010 11:32:12 PM...and helps even those who have attacked Iran in the past. Because Iran does not believe in revenge like the West that is for ever occupying Germany, Japan, South Korea, etc. Iran knows better that revenge is best left to God. european 11/29/2010 10:51:03 PMThese are not leaks at all. They never compliment or give more attention to such things... just like 9/11, nobody could suggest a possiblity of an inside job. Nobody. So how come, Assange comes in and publish leaks and he becomes an idol of masses?This is one big joke.The US behaves like a shaitan, then issues a represantative to openly admit that their country belongs to the devil. AB 11/29/2010 10:49:56 PMToday popularity contest is base on economic liberty not on propaganda policy. If Iran didn?t help Lebanon or Iraq to back on their feet, today had no popularity the same as Egypt. Abd 11/29/2010 10:02:12 PMThe enemies of humanity who think they have saved a face behind addiction, corruption and oppression of even their citizens are actually at an ideological dead end. The US demons and their Salary worshiper pupits in the almost expired UN should cry their heart out and get drunk before lying about Iran. Sincerely.www.criesofdarwinism.com Iranian 11/29/2010 10:00:35 PMAnd some people criticize his foreign policy. this announcement is something that every Iranian can be proud of, proud of their president, unfortunately it is fashionable to criticize or insult Ahmadinejad without any reason thanks to zionist media. To Anti-Bully 11/29/2010 10:00:00 PMEven when there is a physical court, it is inconspicuously hollowed out in favour of the Western dictatorships that pretend to be democratic. scott68 11/29/2010 9:53:56 PMcertain comments that were leaked to the western media from Wikileaks is being used by western media to create a hostile climate on the subject of say for example Iran's nuclear program by using the names of certain key leaders in the middle east who have said the US should attack Iran to prevent them obtaining nuclear weapons it seems as though the western media want to create a hostile reaction towards Iran with this information Anti-bully 11/29/2010 9:51:10 PMThe 3-step Wikileaks (WL) rocket. First WL: US army atrocities. 2nd WL: People in ME kill and bribe each other (which according to West's fascist "logic" makes it OK if US/UK/NATO/Israel do it as well). 3rd WL: The big fish panjandrums are in on it. IOW: 1) "We, WEST, have the muscles", 2) "You, ME, deserve what's coming to you" 3) "WE-HAVE-THE-POWER". Conclusion: "You, the "REST", can do ZIT!". @Anti-bully 11/29/2010 9:38:54 PMAffirmative! Took me more than 45 years in the West to research the systemic anatomy of hypocricy. You have come a long way, and so have most of those who have commented here. Anti-bully 11/29/2010 9:18:07 PMWest, when it deems convenient, shows evidences of it's atrocities (Vietnam files, Wikileaks, Abu Ghraib pics) and boohoos "look how TERRIBLE we are", but you wouldn't SEE the smirk. Of course, some evidences could hold in a court of law, but what if there is NO court? This makes the Anglo-American psycho-West grin even wider. IOW, West gets off flaunting how disgusting it can be. You think Iran was joking when calling them "Great Satan"? PIONEER 11/29/2010 8:58:05 PMso it's true (and quoted by iran) when it's about the u.s. and the west, but untrue when it's about iran? EB 11/29/2010 8:30:55 PMSo when something bad about the US is released by wikileaks, Iran agrees with them, but when something bad about Iran comes out, they say it's not true and planned by the west.. Wonderful double standards. PressTV is a joke, and it's just like FoxNews, completely biased. Katifa 11/29/2010 8:22:24 PMI wish Ahmadinejad would go into more detail as to why he feels the US benefits from this leak. I don't understand his point of view and usually I do! mumbo 11/29/2010 7:52:07 PMsome of the statements by Bahraini, UAE or Saudi Arab leaders would have never been made, even in private if it weren't for certain imperialist powers constantly dabbling in this region. Now that they do dabble, it should be treated as private thoughts - nothing more nothing less. However let s remember that it was superpower support of Saddam Hussein that got many arab leaders to dole money to Saddam fighting the Persians. hussain mehdi 11/29/2010 7:33:06 PMthis is leak??? first they announce and then they publish leak!!! this is leak??? is this leak??? 11/29/2010 7:13:06 PMYhere was time Muslims were divided in Shia and Sunni but the Ediots of West have helped us to get rid of the prejudices and now Thanks God we are one. Iran was always Great Shia Nation and Turkey Great Sinni Nation. Now they Mashallah are Great Islamic Nation. subhan Allah. The enemy has cut its own throat. fred Kay 11/29/2010 6:15:06 PMALL ARAB COUNTRIES HAVE PUPPET GOVERNMENTS PUT IN POWER BY THE MASTERS IN THE WEST.MUSLIM BROTHERHOOD WITH ARABS?!MY FOOT,WHAT POSITIVE STEPS HAVE THEY TAKEN TOWARDS IRAN?,NONE.IRAN MUST PAY THEM IN KIND AND SHAKE THEIR GLASS HOUSES.ISRAEL IS RIGHT TO GIVE THEM A BLOW EVERY TIME THEY OPEN THEIR BRAINLESS MOUTHS. Pak 11/29/2010 6:12:52 PMHis Excellency Mr. AhamdiNejad is a great leader of Muslim nation.And the arrogant powers are scared from this thing.For Non Muslims nations there is nothing Shia or Sunni only Muslims.And these Non Muslims nations always try their best to use all resources to make difference between Muslims. RESON 11/29/2010 5:51:43 PMWEST HAVE BIG SOCIAL PROBLEM & THAT IS THRUST BETWEEN ITS PEAPOL V GOVT TO BUILD THAT THRUST NEED TO PROVE DOMACRECY EXCICT. IRAQ WAR PRODUCE BIG MASS OF SOCIAL UNREST INWEST IN TOTAL. THE LEAK WORKS LIKE PRESUR COOKER.HAVE RELISE AIR OUT Abu bukk 11/29/2010 5:34:50 PMVery well said asgar I'm a Muslim Sunni aswell and I agree that all Muslims are brothers wa Salam Albert Hakim 11/29/2010 4:56:39 PMWhat if this is a real leak?! Then what? I think if Iranians are smart, they should give it a possibility. I believe, Iranians should not trust Arabs who have proven to be America's servants in the Middle East. Truth seeker 11/29/2010 4:42:26 PMThe Council on Foreign Relations (most influential foreign-policy think tank), are the secret rulers of every country and they can knock out anyone who doesn't obey their rules. Make for Public 11/29/2010 4:27:41 PMWikileaks is an Zionist Agent Provocateur, Period. sana 11/29/2010 4:09:26 PMThis is a cheap game and will not work at all. if they think people in the ME are stupid; they prove themselves to be stupid. At the end of the day, they will be the losing party. We consider themselves brothers and sisters and will remains so. Days of colonialism and imperialism are over. You cannot rule the whole China with a bunch of colonial thiefs anymore. ASGAR 11/29/2010 3:43:47 PMIM a Sunni if the west or Arab Leaders are trying to divide shia and Sunni they will fail with me, my friends and people i talk to. We all see the Good Iran is doing and i hope it will bring us closer and end the man made divied of sunni /shia for good. south african 11/29/2010 3:39:24 PMAgreed. America would have stopped this if they were not behind it. They are a super power and should be able to stop some man from stealing their top secret documents, which are probably hidden inside a thick vault with 10 CIA agents guarding it. James 11/29/2010 3:38:07 PMIran has not fallen for childish Amreican tricks. Congratulations. Iran knows Wiki and other such attempts are ploys of its enemies. Every child can see throught them. Ernest in USA 11/29/2010 3:37:56 PMSince our government has lost all its credibility with us Americans due to its lies to get us in a war against Iraq, it has to release propaganda through other sources, like wikileaks. These are not leaks, but deliberate propaganda attempts to incite hatred against Iran, and division between Muslim governments. We Americans are not falling for it! Former US Marine 11/29/2010 3:27:28 PMWikileaks spreads the OFFICIAL 9/11 propaganda and even says Bin Laden is still alive. So funny. Anyone with half a brain knows that 9/11 was a DEMOLITION done by Israel and Zionist Traitors. Wikileaks is 100[[]%] Zionist approved propaganda. Wikileaks = controlled opposition NY 11/29/2010 3:22:45 PMPresident Ahmadinejad is absolutely correct in what he says. It is so nice to read facts and not the lies and deceptions in the US media that even a baby can see through. Long live Iran! Londoner 11/29/2010 3:20:37 PMThe leaks said Netanyahu is "a charming man." Most other leaders were insulted. Guess who is behind these "leaks." KIKI 11/29/2010 3:06:24 PMLOOK ONLY TO THE MEDIA THAT WIKILEAKS HAVE CHOSEN TO GIVE THEM THE SO/CALLED LEAKS, DER SPIEGEL AND LE MONDE ARE THE SAME MEDIA THAT PUBLISHED THE SO/CALLED ACCUSATIONS OF HIZBOLLAH ON THE HARIRI CASE. I WONDER WHY THE ISRAELI MEDIA LOOKS SOO HAPPY ABOUT ALL THIS. WHY THEIR IS SOO FEW THINGS ABOUT ISRAEL IN THE SO/CALLED LEAKS. IT DOESNT SEEM RATIONAL THAT ONE MAN CAN LEAK SOOO MUCH OF THE SO/CALLED SECRET DOC. bob 11/29/2010 3:03:01 PMWikileaks is israel!!!! Its so obvious!! truthseeker 11/29/2010 2:59:23 PMJulian Assange works for the cia and is also funded by George Soros. Do you really think that this guy would still be walking around as freely as he does if they did not want this info out. This guy is well known in the alternative media for being funded by soros and why does he release the info first to state controlled newspapers, why not alternative news, which is getting bigger by the day. CD 11/29/2010 2:58:04 PMYes, President Mahmoud Ahmadinejad is right and we should all come together united against western imperialisme. Unity and Tolerance amongst the people is the "Leitmotive" and a new equale world order,permetting us to secure the future of the humanity and making this world a better place to live for our children. Nick 11/29/2010 2:57:03 PMThe US government controls our finances eg. wall street derivatives... They control our business, eg. government motors (GM)... and they control our press, along with all these so-called 'Wiki leaks' ! To All Iranians 11/29/2010 2:22:30 PMAlways ask yourselve what is the consequence of what you say in reacting to hearsay accounts like WikiLeak stories. Your enemies live in hypocricy. They force international commissions like IAEA to act and report in hypocricy. They demonstrate in their own courts to judge as hypocrites. They blame you and find you guilty with hypocricy. Do not fall for it. Demand facts and proofs. Rely on the verified public statements of leaders. Show your enemies that they are the stupid ones. Iranian 11/29/2010 2:12:43 PMWell, it's quite obvious. lots of was about Iran and how Iran hated by american puppets in the middle east. and also some ridiculous useless about some other things that we already knew about them, just to make the whole thing acceptable. I really thought that they would prepare the material much better than the first time. but it was even more obvious who leaked those. Seems they are getting sloppy and desperate. Common Sense 11/29/2010 1:51:01 PMChances leak ever to survive World of Zionis regime that include US. Agent will be assassinate period (even their President). Infomation need to be filted carefully and wisely. To good to be true for sure. Pakistani 11/29/2010 1:49:44 PMAhmadinejad is very wise to ignore wikileaks revelations by branding it a propagenda.Although you have to be very naive to actually believe this is a propaganda but Ahmadinejad is right to call it a propaganda in public. I would have done the exact same thing. Disagreement between iran and saudiarabia should never turn into a war between sunni and shias. Mona Montgomery 11/29/2010 1:40:45 PMMohammed, thank you for explaing that. Mohammed 11/29/2010 1:16:40 PMYes, very smart man. I think the same thing. There is something not quite right about the Wikileaks. Maybe the this whole 'leak' thing is a controlled dissent by the Western powers. The real juicy stuff will stay in storage for the next 100 years. From baloand at googlemail.com Tue Nov 30 11:10:39 2010 From: baloand at googlemail.com (baloan) Date: Tue, 30 Nov 2010 08:10:39 -0800 (PST) Subject: remote control firefox with python References: <4cf273b9$0$19685$426a74cc@news.free.fr> Message-ID: <0b5e1c60-b594-4479-a429-35629b7e61d9@y23g2000yqd.googlegroups.com> On Nov 28, 4:22?pm, News123 wrote: > Hi, > > I wondered whether there is a simpe way to > 'remote' control fire fox with python. > > With remote controlling I mean: > - enter a url in the title bar and click on it > - create a new tab > - enter another url click on it > - save the html document of this page > - Probably the most difficult one: emulate a click or 'right click' on a > certain button or link of the current page. > - other interesting things would be to be able to enter the master > ? ? ? ? password from a script > - to enable disable proxy settings while running. > > The reason why I want to stay within Firefox and not use any other > 'mechanize' frame work is, that the pages I want to automate might > contain a lot of javascript for the construction of the actual page. > > Thanks in advance for any pointers ideas. I have had some good experience with Sikuli. http://sikuli.org/ Regards, Andreas baloan at gmail.com From giacomo.boffi at polimi.it Tue Nov 30 12:00:41 2010 From: giacomo.boffi at polimi.it (Giacomo Boffi) Date: Tue, 30 Nov 2010 18:00:41 +0100 Subject: Using property() to extend Tkinter classes but Tkinter classes are old-style classes? References: <1290977244.17714.1407556497@webmail.messagingengine.com> Message-ID: <8639qikapy.fsf@aiuole.stru.polimi.it> Terry Reedy writes: > On 11/28/2010 3:47 PM, python at bdurham.com wrote: >> I had planned on subclassing Tkinter.Toplevel() using property() to wrap >> access to properties like a window's title. >> After much head scratching and a peek at the Tkinter.py source, I >> realized that all Tkinter classes are old-style classes (even under >> Python 2.7). >> 1. Is there a technical reason why Tkinter classes are still old-style >> classes? > > To not break old code. Being able to break code by upgrading all > classes in the stdlib was one of the reasons for 3.x. In 3.x, are Tkinter classes still derived by old-style classes? From __peter__ at web.de Tue Nov 30 12:53:14 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 30 Nov 2010 18:53:14 +0100 Subject: Python 3 encoding question: Read a filename from stdin, subsequently open that filename References: <1291124813.414884.22.camel@WOPR> Message-ID: Albert Hopkins wrote: > On Tue, 2010-11-30 at 11:52 +0100, Peter Otten wrote: > Dan Stromberg wrote: >> >> > I've got a couple of programs that read filenames from stdin, and > then >> > open those files and do things with them. These programs sort of do >> > the *ix xargs thing, without requiring xargs. >> > >> > In Python 2, these work well. Irrespective of how filenames are >> > encoded, things are opened OK, because it's all just a stream of >> > single byte characters. >> >> I think you're wrong. The filenames' encoding as they are read from stdin >> must be the same as the encoding used by the file system. If the file >> system expects UTF-8 and you feed it ISO-8859-1 you'll run into errors. >> > I think this is wrong. In Unix there is no concept of filename > encoding. Filenames can have any arbitrary set of bytes (except '/' and > '\0'). But the filesystem itself neither knows nor cares about > encoding. I think you misunderstood what I was trying to say. If you write a list of filenames into files.txt, and use an encoding (ISO-8859-1, say) other than that used by the shell to display file names (on Linux typically UTF-8 these days) and then write a Python script exist.py that reads filenames and checks for the files' existence, $ python3 exist.py < files.txt will report that a file b'\xe4\xf6\xfc.txt' doesn't exist. The user looking at his editor with the encoding set to ISO-8859-1 seeing the line ???.txt and then going to the console typing $ ls ???.txt will be confused even though everything is working correctly. The system may be shuffling bytes, but the user thinks in codepoints and sometimes assumes that codepoints and bytes are the same. > You always have to know either >> >> (a) both the file system's and stdin's actual encoding, or >> (b) that both encodings are the same. >> >> > If this is true, then I think that it is wrong to do in Python3. Any > language should be able to deal with the filenames that the host OS > allows. > > Anyway, going on with the OP.. can you open stdin so that you can accept > arbitrary bytes instead of strings and then open using the bytes as the > filename? You can access the underlying stdin.buffer that feeds you the raw bytes with no attempt to shoehorn them into codepoints. You can use filenames that are not valid in the encoding that the system uses to display filenames: $ ls $ python3 Python 3.1.1+ (r311:74480, Nov 2 2009, 15:45:00) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> with open(b"\xe4\xf6\xfc.txt", "w") as f: ... f.write("hello\n") ... 6 >>> $ ls ???.txt > I don't have that much experience with Python3 to say for sure. Me neither. Peter From hansmu at xs4all.nl Tue Nov 30 13:01:05 2010 From: hansmu at xs4all.nl (Hans Mulder) Date: Tue, 30 Nov 2010 19:01:05 +0100 Subject: Using property() to extend Tkinter classes but Tkinter classes are old-style classes? In-Reply-To: <8639qikapy.fsf@aiuole.stru.polimi.it> References: <1290977244.17714.1407556497@webmail.messagingengine.com> <8639qikapy.fsf@aiuole.stru.polimi.it> Message-ID: <4cf53bf6$0$65870$e4fe514c@news.xs4all.nl> Giacomo Boffi wrote: > Terry Reedy writes: > >> On 11/28/2010 3:47 PM, python at bdurham.com wrote: >>> I had planned on subclassing Tkinter.Toplevel() using property() to wrap >>> access to properties like a window's title. >>> After much head scratching and a peek at the Tkinter.py source, I >>> realized that all Tkinter classes are old-style classes (even under >>> Python 2.7). >>> 1. Is there a technical reason why Tkinter classes are still old-style >>> classes? >> To not break old code. Being able to break code by upgrading all >> classes in the stdlib was one of the reasons for 3.x. > > In 3.x, are Tkinter classes still derived by old-style classes? 3.x does not provide old-style classes. Oh, and the name Tkinter was changed to tkinter: all modules in the standard library have lower case names in 3.x. HTH, -- HansM From iamforufriends at gmail.com Tue Nov 30 13:43:12 2010 From: iamforufriends at gmail.com (dating for ad^u lt girls) Date: Tue, 30 Nov 2010 10:43:12 -0800 (PST) Subject: HAI...THIS POST FOR GIRLS ONLY.. FREE DATING FOR GIRLS WAITING A GIRLS GROUP HERE. Message-ID: <5cf43f0d-73cf-4735-9788-5e0df97acba3@h17g2000pre.googlegroups.com> HAI...THIS POST FOR GIRLS ONLY.. FREE DATING FOR GIRLS WAITING A GIRLS GROUP HERE. http://u3.co.za/mm http://u3.co.za/mm http://u3.co.za/mm http://u3.co.za/mm http://u3.co.za/mm From robert.kern at gmail.com Tue Nov 30 13:49:05 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 30 Nov 2010 12:49:05 -0600 Subject: Using property() to extend Tkinter classes but Tkinter classes are old-style classes? In-Reply-To: <8639qikapy.fsf@aiuole.stru.polimi.it> References: <1290977244.17714.1407556497@webmail.messagingengine.com> <8639qikapy.fsf@aiuole.stru.polimi.it> Message-ID: On 11/30/10 11:00 AM, Giacomo Boffi wrote: > Terry Reedy writes: > >> On 11/28/2010 3:47 PM, python at bdurham.com wrote: >>> I had planned on subclassing Tkinter.Toplevel() using property() to wrap >>> access to properties like a window's title. >>> After much head scratching and a peek at the Tkinter.py source, I >>> realized that all Tkinter classes are old-style classes (even under >>> Python 2.7). >>> 1. Is there a technical reason why Tkinter classes are still old-style >>> classes? >> >> To not break old code. Being able to break code by upgrading all >> classes in the stdlib was one of the reasons for 3.x. > > In 3.x, are Tkinter classes still derived by old-style classes? No. [~]$ python3 Python 3.1.2 (r312:79360M, Mar 24 2010, 01:33:18) [GCC 4.0.1 (Apple Inc. build 5493)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import tkinter >>> tkinter.Tk.mro() [, , , ] >>> -- 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 eric.frederich at gmail.com Tue Nov 30 13:57:56 2010 From: eric.frederich at gmail.com (Eric Frederich) Date: Tue, 30 Nov 2010 13:57:56 -0500 Subject: C struct to Python Message-ID: I am not sure how to proceed. I am writing a Python interface to a C library. The C library uses structures. I was looking at the struct module but struct.unpack only seems to deal with data that was packed using struct.pack or some other buffer. All I have is the struct itself, a pointer in C. Is there a way to unpack directly from a memory address? Right now on the C side of things I can create a buffer of the struct data like so... MyStruct ms; unsigned char buffer[sizeof(MyStruct) + 1]; memcpy(buffer, &ms, sizeof(MyStruct)); return Py_BuildValue("s#", buffer, sizeof(MyStruct)); Then on the Python side I can unpack it using struct.unpack. I'm just wondering if I need to jump through these hoops of packing it on the C side or if I can do it directly from Python. Thanks, ~Eric From nbtulley at gmail.com Tue Nov 30 14:03:01 2010 From: nbtulley at gmail.com (iGet) Date: Tue, 30 Nov 2010 11:03:01 -0800 (PST) Subject: Almost free iPod Message-ID: I know nothing is ever free and that is true. However, you can get things really cheap. Two offers I am working on right now are: (Copy and Paste link into your web browser) A Free iPod 64gb - http://www.YouriPodTouch4free.com/index.php?ref=6695331 Here is how it works: You click on one of the links above, select the item you want, then enter your email in the sign-up section. The next page it will ask you if you want to do the offer as referral or points, I would suggest referral. Now it is going to take you to your main page. Here you will need to complete a level A offer or 50 points in level B offers. Now you may have the question, is this legit. Surf the internet about these sites and you will find out that they are legit. I will not lie; it is hard to get the referrals needed to get the items. A suggestion is try joining the Freebie Forums. There are several people at these forums doing the same thing we are doing and this may help you get some referrals quicker. From debatem1 at gmail.com Tue Nov 30 14:16:24 2010 From: debatem1 at gmail.com (geremy condra) Date: Tue, 30 Nov 2010 11:16:24 -0800 Subject: C struct to Python In-Reply-To: References: Message-ID: On Tue, Nov 30, 2010 at 10:57 AM, Eric Frederich wrote: > I am not sure how to proceed. > I am writing a Python interface to a C library. > The C library uses structures. > I was looking at the struct module but struct.unpack only seems to > deal with data that was packed using struct.pack or some other buffer. > All I have is the struct itself, a pointer in C. > Is there a way to unpack directly from a memory address? > > Right now on the C side of things I can create a buffer of the struct > data like so... > > ? ?MyStruct ms; > ? ?unsigned char buffer[sizeof(MyStruct) + 1]; > ? ?memcpy(buffer, &ms, sizeof(MyStruct)); > ? ?return Py_BuildValue("s#", buffer, sizeof(MyStruct)); > > Then on the Python side I can unpack it using struct.unpack. > > I'm just wondering if I need to jump through these hoops of packing it > on the C side or if I can do it directly from Python. > > Thanks, > ~Eric ctypes[0] sounds like a possible solution, although if you're already writing a C extension it might be better practice to just write a Python object that wraps your C struct appropriately. If you're not wedded to the C extension, though, I've had very good luck writing C interfaces with with ctypes and a few useful decorators [1], [2]. Others prefer Cython[3], which I like for speed but which sometimes seems to get in my way when I'm trying to interface with existing code. There's a good, if somewhat dated, overview of a few other strategies here[4]. Geremy Condra [0]: http://docs.python.org/library/ctypes.html [1]: http://code.activestate.com/recipes/576734-c-struct-decorator/ [2]: http://code.activestate.com/recipes/576731/ [3]: http://www.cython.org/ [4]: http://www.suttoncourtenay.org.uk/duncan/accu/integratingpython.html From martin at v.loewis.de Tue Nov 30 14:47:57 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Tue, 30 Nov 2010 20:47:57 +0100 Subject: Python 3 encoding question: Read a filename from stdin, subsequently open that filename In-Reply-To: References: Message-ID: <4CF554ED.9050706@v.loewis.de> > Does anyone know what I need to do to read filenames from stdin with > Python 3.1 and subsequently open them, when some of those filenames > include characters with their high bit set? If your files on disk use file names encoded in iso-8859-1, don't set your locale to a UTF-8 locale (as you apparently do), but set it to a locale that actually matches the encoding that you use. Regards, Martin From martin at v.loewis.de Tue Nov 30 14:47:57 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Tue, 30 Nov 2010 20:47:57 +0100 Subject: Python 3 encoding question: Read a filename from stdin, subsequently open that filename In-Reply-To: References: Message-ID: <4CF554ED.9050706@v.loewis.de> > Does anyone know what I need to do to read filenames from stdin with > Python 3.1 and subsequently open them, when some of those filenames > include characters with their high bit set? If your files on disk use file names encoded in iso-8859-1, don't set your locale to a UTF-8 locale (as you apparently do), but set it to a locale that actually matches the encoding that you use. Regards, Martin From portoms at gmail.com Tue Nov 30 15:09:14 2010 From: portoms at gmail.com (Thomas Portmann) Date: Tue, 30 Nov 2010 21:09:14 +0100 Subject: [Q] get device major/minor number Message-ID: Hello all, In a script I would like to extract all device infos from block or character device. The "stat" function gives me most of the infos (mode, timestamp, user and group id, ...), however I did not find how to get the devices major and minor numbers. Of course I could do it by calling an external program, but is it possible to stay within python? In the example below, I would like to get the major (8) and minor (0, 1, 2) numbers of /dev/sda{,1,2}. How can I get them? user at host:~$ ls -l /dev/sda /dev/sda1 /dev/sda2 brw-rw---- 1 root disk 8, 0 Nov 30 19:10 /dev/sda brw-rw---- 1 root disk 8, 1 Nov 30 19:10 /dev/sda1 brw-rw---- 1 root disk 8, 2 Nov 30 19:10 /dev/sda2 user at host:~$ python3.1 -c 'import os for el in ["","1","2"]: print(os.stat("/dev/sda"+el));' posix.stat_result(st_mode=25008, st_ino=1776, st_dev=5, st_nlink=1, st_uid=0, st_gid=6, st_size=0, st_atime=1291140641, st_mtime=1291140640, st_ctime=1291140640) posix.stat_result(st_mode=25008, st_ino=1780, st_dev=5, st_nlink=1, st_uid=0, st_gid=6, st_size=0, st_atime=1291140644, st_mtime=1291140641, st_ctime=1291140641) posix.stat_result(st_mode=25008, st_ino=1781, st_dev=5, st_nlink=1, st_uid=0, st_gid=6, st_size=0, st_atime=1291140644, st_mtime=1291140641, st_ctime=1291140641) Thanks Tom From dan at catfolks.net Tue Nov 30 15:18:38 2010 From: dan at catfolks.net (Dan M) Date: Tue, 30 Nov 2010 14:18:38 -0600 Subject: [Q] get device major/minor number References: Message-ID: <5O6dnWNw3MaDwWjRnZ2dnUVZ_vOdnZ2d@powerusenet.com> On Tue, 30 Nov 2010 21:09:14 +0100, Thomas Portmann wrote: > Hello all, > > In a script I would like to extract all device infos from block or > character device. The "stat" function gives me most of the infos (mode, > timestamp, user and group id, ...), however I did not find how to get > the devices major and minor numbers. Of course I could do it by calling > an external program, but is it possible to stay within python? > > In the example below, I would like to get the major (8) and minor (0, 1, > 2) numbers of /dev/sda{,1,2}. How can I get them? I think the os.major() and os.minor() calls ought to do what you want. >>> import os >>> s = os.stat('/dev/sda1') >>> os.major(s.st_rdev) 8 >>> os.minor(s.st_rdev) 1 >>> dan at dan:~$ ls -l /dev/sda1 brw-rw---- 1 root disk 8, 1 2010-11-18 05:41 /dev/sda1 From ben+python at benfinney.id.au Tue Nov 30 15:19:32 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 01 Dec 2010 07:19:32 +1100 Subject: Memory issues when storing as List of Strings vs List of List References: Message-ID: <87vd3e36p7.fsf@benfinney.id.au> OW Ghim Siong writes: > I have a big file 1.5GB in size, with about 6 million lines of > tab-delimited data. I have to perform some filtration on the data and > keep the good data. After filtration, I have about 5.5 million data > left remaining. As you might already guessed, I have to read them in > batches and I did so using .readlines(100000000). Why do you need to handle the batching in your code? Perhaps you're not aware that a file object is already an iterator for the lines of text in the file. > After reading each batch, I will split the line (in string format) to > a list using .split("\t") and then check several conditions, after > which if all conditions are satisfied, I will store the list into a > matrix. As I understand it, you don't need a line after moving to the next. So there's no need to maintain a manual buffer of lines at all; please explain if there is something additional requiring a huge buffer of input lines. > The code is as follows: > -----Start------ > a=open("bigfile") > matrix=[] > while True: > lines = a.readlines(100000000) > for line in lines: > data=line.split("\t") > if several_conditions_are_satisfied: > matrix.append(data) > print "Number of lines read:", len(lines), "matrix.__sizeof__:", > matrix.__sizeof__() > if len(lines)==0: > break > -----End----- Using the file's native line iterator:: infile = open("bigfile") matrix = [] for line in infile: record = line.split("\t") if several_conditions_are_satisfied: matrix.append(record) > Results: > Number of lines read: 461544 matrix.__sizeof__: 1694768 > Number of lines read: 449840 matrix.__sizeof__: 3435984 > Number of lines read: 455690 matrix.__sizeof__: 5503904 > Number of lines read: 451955 matrix.__sizeof__: 6965928 > Number of lines read: 452645 matrix.__sizeof__: 8816304 > Number of lines read: 448555 matrix.__sizeof__: 9918368 > > Traceback (most recent call last): > MemoryError If you still get a MemoryError, you can use the ?pdb? module to debug it interactively. Another option is to catch the MemoryError and construct a diagnostic message similar to the one you had above:: import sys infile = open("bigfile") matrix = [] for line in infile: record = line.split("\t") if several_conditions_are_satisfied: try: matrix.append(record) except MemoryError: matrix_len = len(matrix) sys.stderr.write( "len(matrix): %(matrix_len)d\n" % vars()) raise > I have tried creating such a matrix of equivalent size and it only > uses 35mb of memory but I am not sure why when using the code above, > the memory usage shot up so fast and exceeded 2GB. > > Any advice is greatly appreciated. With large data sets, and the manipulation and computation you will likely be wanting to perform, it's probably time to consider the NumPy library which has much more powerful array types, part of the SciPy library . -- \ ?[It's] best to confuse only one issue at a time.? ?Brian W. | `\ Kernighan, Dennis M. Ritchie, _The C programming language_, 1988 | _o__) | Ben Finney From goldtech at worldpost.com Tue Nov 30 15:28:38 2010 From: goldtech at worldpost.com (goldtech) Date: Tue, 30 Nov 2010 12:28:38 -0800 (PST) Subject: SAX unicode and ascii parsing problem Message-ID: Hi, I'm trying to parse an xml file using SAX. About half-way through a file I get this error: Traceback (most recent call last): File "C:\Python26\Lib\site-packages\pythonwin\pywin\framework \scriptutils.py", line 325, in RunScript exec codeObject in __main__.__dict__ File "E:\sc\b2.py", line 58, in parser.parse(open(r'ppb5.xml')) File "C:\Python26\Lib\xml\sax\expatreader.py", line 107, in parse xmlreader.IncrementalParser.parse(self, source) File "C:\Python26\Lib\xml\sax\xmlreader.py", line 123, in parse self.feed(buffer) File "C:\Python26\Lib\xml\sax\expatreader.py", line 207, in feed self._parser.Parse(data, isFinal) File "C:\Python26\Lib\xml\sax\expatreader.py", line 304, in end_element self._cont_handler.endElement(name) File "E:\sc\b2.py", line 51, in endElement d.write(csv+"\n") UnicodeEncodeError: 'ascii' codec can't encode characters in position 146-147: ordinal not in range(128) I'm using ActivePython 2.6. I trying to figure out the simplest fix. If there's a Python way to just take the source XML file and covert/ process it so this will not happen - that would be best. Or should I just update to Python 3 ? I tried this but nothing changed, I thought this might convert it and then I'd paerse the new file - didn't work: uc = open(r'E:\sc\ppb4.xml').read().decode('utf8') ascii = uc.decode('ascii') mex9 = open( r'E:\scrapes\ppb5.xml', 'w' ) mex9.write(ascii) Again I'm looking for something simple even it's a few more lines of codes...or upgrade(?) Thanks, appreciate any help. mex9.close() From mohammed.php.developer at gmail.com Tue Nov 30 15:30:28 2010 From: mohammed.php.developer at gmail.com (mohammed_a_o) Date: Tue, 30 Nov 2010 12:30:28 -0800 (PST) Subject: get a free domain , free design , and free host Message-ID: <83cc9e82-635d-46ce-b712-22b7b4b748ce@i32g2000pri.googlegroups.com> get a free domain , free design , and free host http://freedesignandhost.co.cc/ get a free domain , free design , and free host http://freedesignandhost.co.cc/free-design.php http://freedesignandhost.co.cc/free-host.php http://freedesignandhost.co.cc/free-domain.php From portoms at gmail.com Tue Nov 30 15:35:43 2010 From: portoms at gmail.com (Thomas Portmann) Date: Tue, 30 Nov 2010 21:35:43 +0100 Subject: [Q] get device major/minor number In-Reply-To: <5O6dnWNw3MaDwWjRnZ2dnUVZ_vOdnZ2d@powerusenet.com> References: <5O6dnWNw3MaDwWjRnZ2dnUVZ_vOdnZ2d@powerusenet.com> Message-ID: On Tue, Nov 30, 2010 at 9:18 PM, Dan M wrote: > On Tue, 30 Nov 2010 21:09:14 +0100, Thomas Portmann wrote: >> In the example below, I would like to get the major (8) and minor (0, 1, >> 2) numbers of /dev/sda{,1,2}. How can I get them? > > I think the os.major() and os.minor() calls ought to do what you want. > >>>> import os >>>> s = os.stat('/dev/sda1') >>>> os.major(s.st_rdev) > 8 >>>> os.minor(s.st_rdev) > 1 Thank you very much Dan, this is exactly what I was looking for. Tom From dan at catfolks.net Tue Nov 30 15:41:47 2010 From: dan at catfolks.net (Dan M) Date: Tue, 30 Nov 2010 14:41:47 -0600 Subject: [Q] get device major/minor number References: <5O6dnWNw3MaDwWjRnZ2dnUVZ_vOdnZ2d@powerusenet.com> Message-ID: <5O6dnWJw3MYW_GjRnZ2dnUVZ_vOdnZ2d@powerusenet.com> On Tue, 30 Nov 2010 21:35:43 +0100, Thomas Portmann wrote: > Thank you very much Dan, this is exactly what I was looking for. > > > Tom You're very welcome. From goldtech at worldpost.com Tue Nov 30 15:43:55 2010 From: goldtech at worldpost.com (goldtech) Date: Tue, 30 Nov 2010 12:43:55 -0800 (PST) Subject: SAX unicode and ascii parsing problem Message-ID: <7fd52fd8-c6e0-48fa-bc50-1cff3354c3a3@u9g2000pra.googlegroups.com> Hi, I'm trying to parse an xml file using SAX. About half-way through a file I get this error: Traceback (most recent call last): File "C:\Python26\Lib\site-packages\pythonwin\pywin\framework \scriptutils.py", line 325, in RunScript exec codeObject in __main__.__dict__ File "E:\sc\b2.py", line 58, in parser.parse(open(r'ppb5.xml')) File "C:\Python26\Lib\xml\sax\expatreader.py", line 107, in parse xmlreader.IncrementalParser.parse(self, source) File "C:\Python26\Lib\xml\sax\xmlreader.py", line 123, in parse self.feed(buffer) File "C:\Python26\Lib\xml\sax\expatreader.py", line 207, in feed self._parser.Parse(data, isFinal) File "C:\Python26\Lib\xml\sax\expatreader.py", line 304, in end_element self._cont_handler.endElement(name) File "E:\sc\b2.py", line 51, in endElement d.write(csv+"\n") UnicodeEncodeError: 'ascii' codec can't encode characters in position 146-147: ordinal not in range(128) I'm using ActivePython 2.6. I trying to figure out the simplest fix. If there's a Python way to just take the source XML file and covert/ process it so this will not happen - that would be best. Or should I just update to Python 3 ? I tried this but nothing changed, I thought this might convert it and then I'd paerse the new file - didn't work: uc = open(r'E:\sc\ppb4.xml').read().decode('utf8') ascii = uc.decode('ascii') mex9 = open( r'E:\scrapes\ppb5.xml', 'w' ) mex9.write(ascii) Again I'm looking for something simple even it's a few more lines of codes...or upgrade(?) Thanks, appreciate any help. mex9.close() From steve at holdenweb.com Tue Nov 30 16:02:30 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 30 Nov 2010 16:02:30 -0500 Subject: SAX unicode and ascii parsing problem In-Reply-To: <7fd52fd8-c6e0-48fa-bc50-1cff3354c3a3@u9g2000pra.googlegroups.com> References: <7fd52fd8-c6e0-48fa-bc50-1cff3354c3a3@u9g2000pra.googlegroups.com> Message-ID: On 11/30/2010 3:43 PM, goldtech wrote: > Hi, > > I'm trying to parse an xml file using SAX. About half-way through a > file I get this error: > > Traceback (most recent call last): > File "C:\Python26\Lib\site-packages\pythonwin\pywin\framework > \scriptutils.py", line 325, in RunScript > exec codeObject in __main__.__dict__ > File "E:\sc\b2.py", line 58, in > parser.parse(open(r'ppb5.xml')) > File "C:\Python26\Lib\xml\sax\expatreader.py", line 107, in parse > xmlreader.IncrementalParser.parse(self, source) > File "C:\Python26\Lib\xml\sax\xmlreader.py", line 123, in parse > self.feed(buffer) > File "C:\Python26\Lib\xml\sax\expatreader.py", line 207, in feed > self._parser.Parse(data, isFinal) > File "C:\Python26\Lib\xml\sax\expatreader.py", line 304, in > end_element > self._cont_handler.endElement(name) > File "E:\sc\b2.py", line 51, in endElement > d.write(csv+"\n") > UnicodeEncodeError: 'ascii' codec can't encode characters in position > 146-147: ordinal not in range(128) > > I'm using ActivePython 2.6. I trying to figure out the simplest fix. > If there's a Python way to just take the source XML file and covert/ > process it so this will not happen - that would be best. Or should I > just update to Python 3 ? > > I tried this but nothing changed, I thought this might convert it and > then I'd paerse the new file - didn't work: > > uc = open(r'E:\sc\ppb4.xml').read().decode('utf8') > ascii = uc.decode('ascii') > mex9 = open( r'E:\scrapes\ppb5.xml', 'w' ) > mex9.write(ascii) > > Again I'm looking for something simple even it's a few more lines of > codes...or upgrade(?) > > Thanks, appreciate any help. > mex9.close() I'm just as stumped as I was when you first asked this question 13 minutes ago. ;-) regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From pakalk at gmail.com Tue Nov 30 16:03:24 2010 From: pakalk at gmail.com (pakalk) Date: Tue, 30 Nov 2010 13:03:24 -0800 (PST) Subject: IMAP support References: <13ee8219-5925-4978-ba89-83ee0f7b7820@30g2000yqm.googlegroups.com> Message-ID: <8ec7b311-8278-4617-8de5-2c58d335d91d@e20g2000vbx.googlegroups.com> Please, give me an example of raw query to IMAP server? And why do you focus on "Nevermind is so ekhm... nevermind... "?? Cannot you just help? From goldtech at worldpost.com Tue Nov 30 16:15:53 2010 From: goldtech at worldpost.com (goldtech) Date: Tue, 30 Nov 2010 13:15:53 -0800 (PST) Subject: SAX unicode and ascii parsing problem References: <7fd52fd8-c6e0-48fa-bc50-1cff3354c3a3@u9g2000pra.googlegroups.com> Message-ID: snip... > > I'm just as stumped as I was when you first asked this question 13 > minutes ago. ;-) > > regards > ?Steve > snip... Hi Steve, Think I found it, for example: line = 'my big string' line.encode('ascii', 'ignore') I processed the problem strings during parsing with this and it works now. Got this from: http://stackoverflow.com/questions/2365411/python-convert-unicode-to-ascii-without-errors Best, Lee :^) From justin.mailinglists at gmail.com Tue Nov 30 16:20:45 2010 From: justin.mailinglists at gmail.com (Justin Ezequiel) Date: Tue, 30 Nov 2010 13:20:45 -0800 (PST) Subject: SAX unicode and ascii parsing problem References: Message-ID: can't check right now but are you sure it's the parser and not this line d.write(csv+"\n") that's failing? what is d? From awilliam at whitemice.org Tue Nov 30 16:26:19 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Tue, 30 Nov 2010 16:26:19 -0500 Subject: IMAP support In-Reply-To: <8ec7b311-8278-4617-8de5-2c58d335d91d@e20g2000vbx.googlegroups.com> References: <13ee8219-5925-4978-ba89-83ee0f7b7820@30g2000yqm.googlegroups.com> <8ec7b311-8278-4617-8de5-2c58d335d91d@e20g2000vbx.googlegroups.com> Message-ID: <1291152379.12209.1.camel@linux-yu4c.site> On Tue, 2010-11-30 at 13:03 -0800, pakalk wrote: > Please, give me an example of raw query to IMAP server? I'm not certain what you mean by "raw query". > And why do you focus on "Nevermind is so ekhm... nevermind... "?? > Cannot you just help? This list does suffer from a case of "attitude". Most programming forums have that; Python "attitude" has its own special flavor. From javiervandam at gmail.com Tue Nov 30 16:31:26 2010 From: javiervandam at gmail.com (javivd) Date: Tue, 30 Nov 2010 13:31:26 -0800 (PST) Subject: Reading by positions plain text files Message-ID: <39a07597-02b9-4ef8-9ca9-93e2d2425e66@p7g2000prb.googlegroups.com> Hi all, Sorry, newbie question: I have database in a plain text file (could be .txt or .dat, it's the same) that I need to read in python in order to do some data validation. In other files I read this kind of files with the split() method, reading line by line. But split() relies on a separator character (I think... all I know is that it's work OK). I have a case now in wich another file has been provided (besides the database) that tells me in wich column of the file is every variable, because there isn't any blank or tab character that separates the variables, they are stick together. This second file specify the variable name and his position: VARIABLE NAME POSITION (COLUMN) IN FILE var_name_1 123-123 var_name_2 124-125 var_name_3 126-126 .. .. var_name_N 512-513 (last positions) How can I read this so each position in the file it's associated with each variable name? Thanks a lot!! Javier From khamenya at gmail.com Tue Nov 30 16:35:32 2010 From: khamenya at gmail.com (Valery Khamenya) Date: Tue, 30 Nov 2010 22:35:32 +0100 Subject: How to initialize each multithreading Pool worker with an individual value? Message-ID: Hi, multithreading.pool Pool has a promissing initializer argument in its constructor. However it doesn't look possible to use it to initialize each Pool's worker with some individual value (I'd wish to be wrong here) So, how to initialize each multithreading Pool worker with the individual values? The typical use case might be a connection pool, say, of 3 workers, where each of 3 workers has its own TCP/IP port. from multiprocessing.pool import Pool def port_initializer(_port): global port port = _port def use_connection(some_packet): global _port print "sending data over port # %s" % port if __name__ == "__main__": ports=((4001,4002, 4003), ) p = Pool(3, port_initializer, ports) # oops... :-) some_data_to_send = range(20) p.map(use_connection, some_data_to_send) best regards -- Valery A.Khamenya From pakalk at gmail.com Tue Nov 30 16:36:44 2010 From: pakalk at gmail.com (pakalk) Date: Tue, 30 Nov 2010 13:36:44 -0800 (PST) Subject: IMAP support References: <13ee8219-5925-4978-ba89-83ee0f7b7820@30g2000yqm.googlegroups.com> <8ec7b311-8278-4617-8de5-2c58d335d91d@e20g2000vbx.googlegroups.com> Message-ID: <170a6933-6b1e-4abd-bc80-6e4bc2fbd661@p38g2000vbn.googlegroups.com> On 30 Lis, 22:26, Adam Tauno Williams wrote: > On Tue, 2010-11-30 at 13:03 -0800, pakalk wrote: > > Please, give me an example of raw query to IMAP server? > > > > I'm not certain what you mean by "raw query". m = imap() m.query('UID SORT ...') # etc. Thanks for link :) From usernet at ilthio.net Tue Nov 30 17:43:21 2010 From: usernet at ilthio.net (Tim Harig) Date: Tue, 30 Nov 2010 22:43:21 +0000 (UTC) Subject: Reading by positions plain text files References: <39a07597-02b9-4ef8-9ca9-93e2d2425e66@p7g2000prb.googlegroups.com> Message-ID: On 2010-11-30, javivd wrote: > I have a case now in wich another file has been provided (besides the > database) that tells me in wich column of the file is every variable, > because there isn't any blank or tab character that separates the > variables, they are stick together. This second file specify the > variable name and his position: > > VARIABLE NAME POSITION (COLUMN) IN FILE > var_name_1 123-123 > var_name_2 124-125 > var_name_3 126-126 > .. > .. > var_name_N 512-513 (last positions) I am unclear on the format of these positions. They do not look like what I would expect from absolute references in the data. For instance, 123-123 may only contain one byte??? which could change for different encodings and how you mark line endings. Frankly, the use of the world columns in the header suggests that the data *is* separated by line endings rather then absolute position and the position refers to the line number. In which case, you can use splitlines() to break up the data and then address the proper line by index. Nevertheless, you can use file.seek() to move to an absolute offset in the file, if that really is what you are looking for. From mpnordland at gmail.com Tue Nov 30 17:47:32 2010 From: mpnordland at gmail.com (mpnordland) Date: Tue, 30 Nov 2010 14:47:32 -0800 (PST) Subject: Catching user switching and getting current active user from root on linux Message-ID: <1a9bdbd4-2997-4e0f-a24f-cd148247e312@r40g2000prh.googlegroups.com> I have situation where I need to be able to get the current active user, and catch user switching eg user1 locks screen, leaves computer, user2 comes, and logs on. basically, when there is any type of user switch my script needs to know. From usernet at ilthio.net Tue Nov 30 17:54:49 2010 From: usernet at ilthio.net (Tim Harig) Date: Tue, 30 Nov 2010 22:54:49 +0000 (UTC) Subject: Catching user switching and getting current active user from root on linux References: <1a9bdbd4-2997-4e0f-a24f-cd148247e312@r40g2000prh.googlegroups.com> Message-ID: On 2010-11-30, mpnordland wrote: > I have situation where I need to be able to get the current active > user, and catch user switching eg user1 locks screen, leaves computer, > user2 comes, and logs on. > basically, when there is any type of user switch my script needs to > know. Well you could use inotify to trigger on any changes to /var/log/wtmp. When a change is detected, you could check of deltas in the output of "who -a" to figure out what has changed since the last time wtmp triggered. From prologic at shortcircuit.net.au Tue Nov 30 18:04:10 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 1 Dec 2010 09:04:10 +1000 Subject: Catching user switching and getting current active user from root on linux In-Reply-To: References: <1a9bdbd4-2997-4e0f-a24f-cd148247e312@r40g2000prh.googlegroups.com> Message-ID: On Wed, Dec 1, 2010 at 8:54 AM, Tim Harig wrote: > Well you could use inotify to trigger on any changes to /var/log/wtmp. > When a change is detected, you could check of deltas in the output of "who > -a" to figure out what has changed since the last time wtmp triggered. This is a good idea and you could also make use of the following library: http://pypi.python.org/pypi?:action=search&term=utmp&submit=search cheers James -- -- James Mills -- -- "Problems are solved by method" From tjreedy at udel.edu Tue Nov 30 18:30:36 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 30 Nov 2010 18:30:36 -0500 Subject: how to go on learning python In-Reply-To: References: Message-ID: On 11/30/2010 9:37 AM, Xavier Heruacles wrote: > I'm basically a c/c++ programmer and recently come to python for some > web development. Using django and javascript I'm afraid I can develop > some web application now. But often I feel I'm not good at python. I > don't know much about generators, descriptors and decorators(although I > can use some of it to accomplish something, but I don't think I'm > capable of knowing its internals). I find my code ugly, and it seems > near everything are already gotten done by the libraries. When I want to > do something, I just find some libraries or modules and then just finish > the work. So I'm a bit tired of just doing this kind of high level > scripting, only to find myself a bad programmer. Then my question is > after one coded some kind of basic app, how one can keep on learning > programming using python? > Do some more interesting projects? Read more general books about > programming? or...? You can use both your old C skills and new Python skills by helping to develop Python by working on issues on the tracker bugs.python.org. If you are interested but needed help getting started, ask. -- Terry Jan Reedy From python at mrabarnett.plus.com Tue Nov 30 18:36:49 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 30 Nov 2010 23:36:49 +0000 Subject: Reading by positions plain text files In-Reply-To: <39a07597-02b9-4ef8-9ca9-93e2d2425e66@p7g2000prb.googlegroups.com> References: <39a07597-02b9-4ef8-9ca9-93e2d2425e66@p7g2000prb.googlegroups.com> Message-ID: <4CF58A91.50100@mrabarnett.plus.com> On 30/11/2010 21:31, javivd wrote: > Hi all, > > Sorry, newbie question: > > I have database in a plain text file (could be .txt or .dat, it's the > same) that I need to read in python in order to do some data > validation. In other files I read this kind of files with the split() > method, reading line by line. But split() relies on a separator > character (I think... all I know is that it's work OK). > > I have a case now in wich another file has been provided (besides the > database) that tells me in wich column of the file is every variable, > because there isn't any blank or tab character that separates the > variables, they are stick together. This second file specify the > variable name and his position: > > > VARIABLE NAME POSITION (COLUMN) IN FILE > var_name_1 123-123 > var_name_2 124-125 > var_name_3 126-126 > .. > .. > var_name_N 512-513 (last positions) > > How can I read this so each position in the file it's associated with > each variable name? > It sounds like a similar problem to this: http://groups.google.com/group/comp.lang.python/browse_thread/thread/53ebbbb6f41bfff6/123422d510187dc3?show_docid=123422d510187dc3 From vlastimil.brom at gmail.com Tue Nov 30 19:45:48 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Wed, 1 Dec 2010 01:45:48 +0100 Subject: Programming games in historical linguistics with Python In-Reply-To: References: Message-ID: 2010/11/30 Dax Bloom : > Hello, > > Following a discussion that began 3 weeks ago I would like to ask a > question regarding substitution of letters according to grammatical > rules in historical linguistics. I would like to automate the > transformation of words according to complex rules of phonology and > integrate that script in a visual environment. > Here follows the previous thread: > http://groups.google.com/group/comp.lang.python/browse_thread/thread/3c55f9f044c3252f/fe7c2c82ecf0dbf5?lnk=gst&q=evolutionary+linguistics#fe7c2c82ecf0dbf5 > > Is there a way to refer to vowels and consonants as a subcategory of > text? Is there a function to remove all vowels? How should one create > and order the dictionary file for the rules? How to chain several > transformations automatically from multiple rules? Finally can anyone > show me what existing python program or phonological software can do > this? > > What function could tag syllables, the word nucleus and the codas? How > easy is it to bridge this with a more visual environment where > interlinear, aligned text can be displayed with Greek notations and > braces as usual in the phonology textbooks? > > Best regards, > > Dax Bloom > -- > http://mail.python.org/mailman/listinfo/python-list > Hi, as far as I know, there is no predefined function or library for distinguishing vowels or consonants, but these can be simply implemented individually according to the exact needs. e.g. regular expressions can be used here: to remove vowels, the code could be (example from the command prompt): >>> import re >>> re.sub(r"(?i)[aeiouy]", "", "This is a SAMPLE TEXT") 'Ths s SMPL TXT' >>> See http://docs.python.org/library/re.html or http://www.regular-expressions.info/ for the regexp features. You may eventually try the new development version regex, which adds many interesting new features and remove some limitations http://bugs.python.org/issue2636 In some cases regular expressions aren't really appropriate or may become too complicated. Sometimes a parsing library like pyparsing may be a more adequate tool: http://pyparsing.wikispaces.com/ If the rules are simple enough, that they can be formulated for single characters or character clusters with a regular expression, you can model the phonological changes as a series of replacements with matching patterns and the respective replacement patterns. For character-wise matching and replacing the regular expressions are very effective; using lookarounds http://www.regular-expressions.info/lookaround.html even some combinatorics for conditional changes can be expressed; however, i would find some more complex conditions, suprasegmentals, morpheme boundaries etc. rather difficult to formalise this way... hth, vbr From drsalists at gmail.com Tue Nov 30 19:51:44 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 30 Nov 2010 16:51:44 -0800 Subject: Python 3 encoding question: Read a filename from stdin, subsequently open that filename In-Reply-To: <4CF554ED.9050706@v.loewis.de> References: <4CF554ED.9050706@v.loewis.de> Message-ID: On Tue, Nov 30, 2010 at 11:47 AM, Martin v. Loewis wrote: >> Does anyone know what I need to do to read filenames from stdin with >> Python 3.1 and subsequently open them, when some of those filenames >> include characters with their high bit set? > > If your files on disk use file names encoded in iso-8859-1, don't set > your locale to a UTF-8 locale (as you apparently do), but set it to > a locale that actually matches the encoding that you use. > > Regards, > Martin > It'd be great if all programs used the same encoding on a given OS, but at least on Linux, I believe historically filenames have been created with different encodings. IOW, if I pick one encoding and go with it, filenames written in some other encoding are likely to cause problems. So I need something for which a filename is just a blob that shouldn't be monkeyed with. From drsalists at gmail.com Tue Nov 30 19:57:57 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 30 Nov 2010 16:57:57 -0800 Subject: Python 3 encoding question: Read a filename from stdin, subsequently open that filename In-Reply-To: <20101130161919.693a1d78@pitrou.net> References: <339421.80548.qm@web54205.mail.re2.yahoo.com> <20101130161919.693a1d78@pitrou.net> Message-ID: On Tue, Nov 30, 2010 at 7:19 AM, Antoine Pitrou wrote: > On Mon, 29 Nov 2010 21:52:07 -0800 (PST) > Yingjie Lan wrote: >> --- On Tue, 11/30/10, Dan Stromberg wrote: >> > In Python 3, I'm finding that I have encoding issues with >> > characters >> > with their high bit set.? Things are fine with strictly >> > ASCII >> > filenames.? With high-bit-set characters, even if I >> > change stdin's >> > encoding with: >> >> Co-ask. I have also had problems with file names in >> Chinese characters with Python 3. I unzipped the >> turtle demo files into the desktop folder (of >> course, the word 'desktop' is in Chinese, it is >> a windows XP system, localization is Chinese), then >> all in a sudden some of the demos won't work >> anymore. But if I move it to a folder whose >> path contains only english characters, everything >> comes back to normal. > > Can you try the latest 3.2alpha4 (*) and check if this is fixed? > If not, then could you please open a bug on http://bugs.python.org ? > > (*) http://python.org/download/releases/3.2/ > > Thank you > > Antoine. I have the same problem using 3.2alpha4: the word man~ana (6 characters long) in a filename causes problems (I'm catching the exception and skipping the file for now) despite using what I believe is an 8-bit, all 256-bytes-are-characters encoding: iso-8859-1. 'not sure if you wanted both of us to try this, or Yingjie alone though. From drsalists at gmail.com Tue Nov 30 20:03:14 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 30 Nov 2010 17:03:14 -0800 Subject: Python 3 encoding question: Read a filename from stdin, subsequently open that filename In-Reply-To: References: <1291124813.414884.22.camel@WOPR> Message-ID: On Tue, Nov 30, 2010 at 9:53 AM, Peter Otten <__peter__ at web.de> wrote: > $ ls > $ python3 > Python 3.1.1+ (r311:74480, Nov ?2 2009, 15:45:00) > [GCC 4.4.1] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> with open(b"\xe4\xf6\xfc.txt", "w") as f: > ... ? ? f.write("hello\n") > ... > 6 >>>> > $ ls > ???.txt This sounds like a strong prospect for how to get things working (I didn't realize open would accept a bytes argument for the filename), but I'm also interested in whether reading filenames from stdin and subsequently opening them is supposed to "just work" given a suitable encoding - like with Java which also uses unicode strings. In Java, I'm told that ISO-8859-1 is supposed to "guarantee a roundtrip conversion". From gnarlodious at gmail.com Tue Nov 30 20:08:57 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Tue, 30 Nov 2010 17:08:57 -0800 (PST) Subject: Change one list item in place Message-ID: <17175f49-087f-4d05-ada2-7e8c7e7e86dd@z17g2000prz.googlegroups.com> This works for me: def sendList(): return ["item0", "item1"] def query(): l=sendList() return ["Formatting only {0} into a string".format(l[0]), l[1]] query() However, is there a way to bypass the l=sendList() and change one list item in-place? Possibly a list comprehension operating on a numbered item? -- Gnarlie From drsalists at gmail.com Tue Nov 30 20:12:33 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 30 Nov 2010 17:12:33 -0800 Subject: How to initialize each multithreading Pool worker with an individual value? In-Reply-To: References: Message-ID: On Tue, Nov 30, 2010 at 1:35 PM, Valery Khamenya wrote: > Hi, > > multithreading.pool Pool has a promissing initializer argument in its > constructor. > However it doesn't look possible to use it to initialize each Pool's > worker with some individual value (I'd wish to be wrong here) > > So, how to initialize each multithreading Pool worker with the > individual values? > > The typical use case might be a connection pool, say, of 3 workers, > where each of 3 workers has its own TCP/IP port. > > from multiprocessing.pool import Pool > > def port_initializer(_port): > ? ?global port > ? ?port = _port > > def use_connection(some_packet): > ? ?global _port > ? ?print "sending data over port # %s" % port > > if __name__ == "__main__": > ? ?ports=((4001,4002, 4003), ) > ? ?p = Pool(3, port_initializer, ports) # oops... :-) > ? ?some_data_to_send = range(20) > ? ?p.map(use_connection, some_data_to_send) Using an initializer with multiprocessing is something I've never tried. I have used queues with multiprocessing though, and I believe you could use them, at least as a fallback plan if you prefer to get the initializer to work. If you create in the parent a queue in shared memory (multiprocessing facilitates this nicely), and fill that queue with the values in your ports tuple, then you could have each child in the worker pool extract a single value from this queue so each worker can have its own, unique port value. HTH From nobody at nowhere.com Tue Nov 30 20:14:05 2010 From: nobody at nowhere.com (Nobody) Date: Wed, 01 Dec 2010 01:14:05 +0000 Subject: Python 3 encoding question: Read a filename from stdin, subsequently open that filename References: Message-ID: On Mon, 29 Nov 2010 21:26:23 -0800, Dan Stromberg wrote: > Does anyone know what I need to do to read filenames from stdin with > Python 3.1 and subsequently open them, when some of those filenames > include characters with their high bit set? Use "bytes" rather than "str". Everywhere. This means reading names from sys.stdin.buffer (which is a binary stream) rather than sys.stdin (which is a text stream). If you pass a "bytes" to an I/O function (e.g. open()), it will just pass the bytes directly to the OS without any decoding. But really, if you're writing *nix system utilities, you should probably stick with Python 2.x until the end of time. Using 3.x will just make life difficult for no good reason (e.g. in 3.x, os.environ also contains Unicode strings). From drsalists at gmail.com Tue Nov 30 20:27:26 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 30 Nov 2010 17:27:26 -0800 Subject: Intro to Python slides, was Re: how to go on learning python Message-ID: On Tue, Nov 30, 2010 at 6:37 AM, Xavier Heruacles wrote: > I'm basically a c/c++ programmer and recently come to python for some web > development. Using django and javascript I'm afraid I can develop some web > application now. But often I feel I'm not good at python. I don't know much > about generators, descriptors and decorators(although I can use some of it > to accomplish something, but I don't think I'm capable of knowing its > internals). I find my code ugly, and it seems near everything are already > gotten done by the libraries. When I want to do something, I just find some > libraries or modules and then just finish the work. So I'm a bit tired of > just doing this kind of high level scripting, only to find myself a bad > programmer. Then my question is after one coded some kind of basic app, how > one can keep on learning programming using python? > Do some more interesting projects? Read more general books about > programming? or...? > -- > http://mail.python.org/mailman/listinfo/python-list You could check out these slides from an Intro to Python talk I'm giving tonight: http://stromberg.dnsalias.org/~dstromberg/Intro-to-Python/ ...perhaps especially the Further Resources section at the end. The Koans might be very nice for you, as might Dive Into Python. BTW, if you're interested in Python and looking into Javascript anew, you might look at Pyjamas. It lets you write web apps in Python that also run on a desktop; you can even call into Raphael from it. Only thing about it is it's kind of a young project compared to most Python implementations. PS: I mostly came from C too - knowing C can be a real advantage for a Python programmer sometimes. From python at mrabarnett.plus.com Tue Nov 30 20:28:11 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 01 Dec 2010 01:28:11 +0000 Subject: Change one list item in place In-Reply-To: <17175f49-087f-4d05-ada2-7e8c7e7e86dd@z17g2000prz.googlegroups.com> References: <17175f49-087f-4d05-ada2-7e8c7e7e86dd@z17g2000prz.googlegroups.com> Message-ID: <4CF5A4AB.7090600@mrabarnett.plus.com> On 01/12/2010 01:08, Gnarlodious wrote: > This works for me: > > def sendList(): > return ["item0", "item1"] > > def query(): > l=sendList() > return ["Formatting only {0} into a string".format(l[0]), l[1]] > > query() > > > However, is there a way to bypass the > > l=sendList() > > and change one list item in-place? Possibly a list comprehension > operating on a numbered item? > There's this: return ["Formatting only {0} into a string".format(x) if i == 0 else x for i, x in enumerate(sendList())] but that's too clever for its own good. Keep it simple. :-) From nobody at nowhere.com Tue Nov 30 20:28:50 2010 From: nobody at nowhere.com (Nobody) Date: Wed, 01 Dec 2010 01:28:50 +0000 Subject: Python 3 encoding question: Read a filename from stdin, subsequently open that filename References: <1291124813.414884.22.camel@WOPR> Message-ID: On Tue, 30 Nov 2010 18:53:14 +0100, Peter Otten wrote: >> I think this is wrong. In Unix there is no concept of filename >> encoding. Filenames can have any arbitrary set of bytes (except '/' and >> '\0'). But the filesystem itself neither knows nor cares about >> encoding. > > I think you misunderstood what I was trying to say. If you write a list of > filenames into files.txt, and use an encoding (ISO-8859-1, say) other than > that used by the shell to display file names (on Linux typically UTF-8 these > days) and then write a Python script exist.py that reads filenames and > checks for the files' existence, I think you misunderstood. In the Unix kernel, there aren't any encodings. Strings of bytes are /just/ strings of bytes. A text file containing a list of filenames doesn't /have/ an encoding. The filenames passed to API functions don't /have/ an encoding. This is why Unix filenames are case-sensitive: because there isn't any "case". The number 65 has no more in common with the number 97 than it does with the number 255. The fact that 65 is the ASCII code for "A" while 97 is the ASCII code for "a" doesn't come into it. Case-insensitive filenames require knowledge of the encoding in order to determine when filenames are "equivalent". DOS/Windows tried this and never really got it right (it works fine on a standalone system, or within later versions of a Windows-only ecosystem, but becomes a nightmare when files get transferred between systems via older or non-Microsoft channels). Python 3.x's decision to treat filenames (and environment variables) as text even on Unix is, in short, a bug. One which, IMNSHO, will mean that Python 2.x is still around when Python 4 is released. From gnarlodious at gmail.com Tue Nov 30 20:35:36 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Tue, 30 Nov 2010 17:35:36 -0800 (PST) Subject: Programming games in historical linguistics with Python References: Message-ID: Have you considered entering all this data into an SQLite database? You could do fast searches based on any features you deem relevant to the phoneme. Using an SQLite editor application you can get started building a database right away. You can add columns as you get the inspiration, along with any tags you want. Putting it all in database tables can really make chaotic linguistic data seem manageable. My own linguistics project uses mostly SQLite and a number of OrderedDict's based on .plist files. It is all working very nicely, although I haven't tried to deal with any phonetics (yet). -- Gnarlie http://Sectrum.com From gnarlodious at gmail.com Tue Nov 30 20:52:14 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Tue, 30 Nov 2010 17:52:14 -0800 (PST) Subject: Change one list item in place References: <17175f49-087f-4d05-ada2-7e8c7e7e86dd@z17g2000prz.googlegroups.com> Message-ID: Thanks. Unless someone has a simpler solution, I'll stick with 2 lines. -- Gnarlie From javiervandam at gmail.com Tue Nov 30 21:03:50 2010 From: javiervandam at gmail.com (javivd) Date: Tue, 30 Nov 2010 18:03:50 -0800 (PST) Subject: Reading by positions plain text files References: <39a07597-02b9-4ef8-9ca9-93e2d2425e66@p7g2000prb.googlegroups.com> Message-ID: On Nov 30, 11:43?pm, Tim Harig wrote: > On 2010-11-30, javivd wrote: > > > I have a case now in wich another file has been provided (besides the > > database) that tells me in wich column of the file is every variable, > > because there isn't any blank or tab character that separates the > > variables, they are stick together. This second file specify the > > variable name and his position: > > > VARIABLE NAME ? ? ?POSITION (COLUMN) IN FILE > > var_name_1 ? ? ? ? ? ? ? ? 123-123 > > var_name_2 ? ? ? ? ? ? ? ? 124-125 > > var_name_3 ? ? ? ? ? ? ? ? 126-126 > > .. > > .. > > var_name_N ? ? ? ? ? ? ? ? 512-513 (last positions) > > I am unclear on the format of these positions. ?They do not look like > what I would expect from absolute references in the data. ?For instance, > 123-123 may only contain one byte??? which could change for different > encodings and how you mark line endings. ?Frankly, the use of the > world columns in the header suggests that the data *is* separated by > line endings rather then absolute position and the position refers to > the line number. In which case, you can use splitlines() to break up > the data and then address the proper line by index. ?Nevertheless, > you can use file.seek() to move to an absolute offset in the file, > if that really is what you are looking for. I work in a survey research firm. the data im talking about has a lot of 0-1 variables, meaning yes or no of a lot of questions. so only one position of a character is needed (not byte), explaining the 123-123 kind of positions of a lot of variables. and no, MRAB, it's not the similar problem (at least what i understood of it). I have to associate the position this file give me with the variable name this file give me for those positions. thank you both and sorry for my english! J From python at mrabarnett.plus.com Tue Nov 30 21:14:09 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 01 Dec 2010 02:14:09 +0000 Subject: Python 3 encoding question: Read a filename from stdin, subsequently open that filename In-Reply-To: References: <1291124813.414884.22.camel@WOPR> Message-ID: <4CF5AF71.3090705@mrabarnett.plus.com> On 01/12/2010 01:28, Nobody wrote: > On Tue, 30 Nov 2010 18:53:14 +0100, Peter Otten wrote: > >>> I think this is wrong. In Unix there is no concept of filename >>> encoding. Filenames can have any arbitrary set of bytes (except '/' and >>> '\0'). But the filesystem itself neither knows nor cares about >>> encoding. >> >> I think you misunderstood what I was trying to say. If you write a list of >> filenames into files.txt, and use an encoding (ISO-8859-1, say) other than >> that used by the shell to display file names (on Linux typically UTF-8 these >> days) and then write a Python script exist.py that reads filenames and >> checks for the files' existence, > > I think you misunderstood. > > In the Unix kernel, there aren't any encodings. Strings of bytes are > /just/ strings of bytes. A text file containing a list of filenames > doesn't /have/ an encoding. The filenames passed to API functions don't > /have/ an encoding. > > This is why Unix filenames are case-sensitive: because there isn't any > "case". The number 65 has no more in common with the number 97 than it > does with the number 255. The fact that 65 is the ASCII code for "A" while > 97 is the ASCII code for "a" doesn't come into it. Case-insensitive > filenames require knowledge of the encoding in order to determine when > filenames are "equivalent". DOS/Windows tried this and never really got it > right (it works fine on a standalone system, or within later versions of > a Windows-only ecosystem, but becomes a nightmare when files get > transferred between systems via older or non-Microsoft channels). > > Python 3.x's decision to treat filenames (and environment variables) as > text even on Unix is, in short, a bug. One which, IMNSHO, will mean that > Python 2.x is still around when Python 4 is released. > If the filenames are to be shown to a user then there needs to be a mapping between bytes and glyphs. That's an encoding. If different users use different encodings then exchange of textual data becomes difficult. That's where encodings which can be used globally come in. By the time Python 4 is released I'd be surprised if Unix hadn't standardised on a single encoding like UTF-8. From python at mrabarnett.plus.com Tue Nov 30 21:20:57 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 01 Dec 2010 02:20:57 +0000 Subject: Reading by positions plain text files In-Reply-To: References: <39a07597-02b9-4ef8-9ca9-93e2d2425e66@p7g2000prb.googlegroups.com> Message-ID: <4CF5B109.4070203@mrabarnett.plus.com> On 01/12/2010 02:03, javivd wrote: > On Nov 30, 11:43 pm, Tim Harig wrote: >> On 2010-11-30, javivd wrote: >> >>> I have a case now in wich another file has been provided (besides the >>> database) that tells me in wich column of the file is every variable, >>> because there isn't any blank or tab character that separates the >>> variables, they are stick together. This second file specify the >>> variable name and his position: >> >>> VARIABLE NAME POSITION (COLUMN) IN FILE >>> var_name_1 123-123 >>> var_name_2 124-125 >>> var_name_3 126-126 >>> .. >>> .. >>> var_name_N 512-513 (last positions) >> >> I am unclear on the format of these positions. They do not look like >> what I would expect from absolute references in the data. For instance, >> 123-123 may only contain one byte??? which could change for different >> encodings and how you mark line endings. Frankly, the use of the >> world columns in the header suggests that the data *is* separated by >> line endings rather then absolute position and the position refers to >> the line number. In which case, you can use splitlines() to break up >> the data and then address the proper line by index. Nevertheless, >> you can use file.seek() to move to an absolute offset in the file, >> if that really is what you are looking for. > > I work in a survey research firm. the data im talking about has a lot > of 0-1 variables, meaning yes or no of a lot of questions. so only one > position of a character is needed (not byte), explaining the 123-123 > kind of positions of a lot of variables. > > and no, MRAB, it's not the similar problem (at least what i understood > of it). I have to associate the position this file give me with the > variable name this file give me for those positions. > > thank you both and sorry for my english! > You just have to parse the second file to build a list (or dict) containing the name, start position and end position of each variable: variables = [("var_name_1", 123, 123), ...] and then work through that list, extracting the data between those positions in the first file and putting the values in another list (or dict). You also need to check whether the positions are 1-based or 0-based (Python uses 0-based). From prologic at shortcircuit.net.au Tue Nov 30 21:24:14 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 1 Dec 2010 12:24:14 +1000 Subject: How to initialize each multithreading Pool worker with an individual value? In-Reply-To: References: Message-ID: On Wed, Dec 1, 2010 at 7:35 AM, Valery Khamenya wrote: > multithreading.pool Pool has a promissing initializer argument in its > constructor. > However it doesn't look possible to use it to initialize each Pool's > worker with some individual value (I'd wish to be wrong here) > > So, how to initialize each multithreading Pool worker with the > individual values? > > The typical use case might be a connection pool, say, of 3 workers, > where each of 3 workers has its own TCP/IP port. > > from multiprocessing.pool import Pool > > def port_initializer(_port): > ? ?global port > ? ?port = _port > > def use_connection(some_packet): > ? ?global _port > ? ?print "sending data over port # %s" % port > > if __name__ == "__main__": > ? ?ports=((4001,4002, 4003), ) > ? ?p = Pool(3, port_initializer, ports) # oops... :-) > ? ?some_data_to_send = range(20) > ? ?p.map(use_connection, some_data_to_send) I assume you are talking about multiprocessing despite you mentioning "multithreading" in the mix. Have a look at the source code for multiprocessing.pool and how the Pool object works and what it does with the initializer argument. I'm not entirely sure it does what you expect and yes documentation on this is lacking... cheers James -- -- James Mills -- -- "Problems are solved by method" From python.list at tim.thechases.com Tue Nov 30 21:32:56 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 30 Nov 2010 20:32:56 -0600 Subject: Reading by positions plain text files In-Reply-To: References: <39a07597-02b9-4ef8-9ca9-93e2d2425e66@p7g2000prb.googlegroups.com> Message-ID: <4CF5B3D8.3030206@tim.thechases.com> On 11/30/2010 08:03 PM, javivd wrote: > On Nov 30, 11:43 pm, Tim Harig wrote: >>> VARIABLE NAME POSITION (COLUMN) IN FILE >>> var_name_1 123-123 >>> var_name_2 124-125 >>> var_name_3 126-126 >>> .. >>> .. >>> var_name_N 512-513 (last positions) >> > and no, MRAB, it's not the similar problem (at least what i understood > of it). I have to associate the position this file give me with the > variable name this file give me for those positions. MRAB may be referring to my reply in that thread where you can do something like OFFSETS = 'offsets.txt' offsets = {} f = file(OFFSETS) f.next() # throw away the headers for row in f: varname, rest = row.split()[:2] # sanity check if varname in offsets: print "[%s] in %s twice?!" % (varname, OFFSETS) if '-' not in rest: continue start, stop = map(int, rest.split('-')) offsets[varname] = slice(start, stop+1) # 0-based offsets #offsets[varname] = slice(start+1, stop+2) # 1-based offsets f.close() def do_something_with(data): # your real code goes here print data['var_name_2'] for row in file('data.txt'): data = dict((name, row[offsets[name]]) for name in offsets) do_something_with(data) There's additional robustness-checks I'd include if your offsets-file isn't controlled by you (people send me daft data). -tkc From whatsjacksemail at gmail.com Tue Nov 30 21:45:50 2010 From: whatsjacksemail at gmail.com (Jack Keegan) Date: Wed, 1 Dec 2010 02:45:50 +0000 Subject: To Thread or not to Thread....? Message-ID: Hi there, I'm currently writing an application to control and take measurements during an experiments. This is to be done on an embedded computer running XPe so I am happy to have python available, although I am pretty new to it. The application basically runs as a state machine, which transitions through it's states based on inputs read in from a set of general purpose input/output (GPIO) lines. So when a certain line is pulled low/high, do something and move to another state. All good so far and since I get through main loop pretty quickly, I can just do a read of the GPIO lines on each pass through the loop and respond accordingly. However, in one of the states I have to start reading in, and storing frames from a camera. In another, I have to start reading accelerometer data from an I2C bus (which operates at 400kHz). I haven't implemented either yet but I would imagine that, in the case of the camera data, reading a frame would take a large amount of time as compared to other operations. Therefore, if I just tried to read one (or one set of) frames on each pass through the loop then I would hold up the rest of the application. Conversely, as the I2C bus will need to be read at such a high rate, I may not be able to get the required data rate I need even without the camera data. This naturally leads me to think I need to use threads. As I am no expert in either I2C, cameras, python or threading I thought I would chance asking for some advice on the subject. Do you think I need threads here or would I be better off using some other method. I was previously toying with the idea of using generators to create weightless threads (as detailed in http://www.ibm.com/developerworks/library/l-pythrd.html) for reading the GPIOs. Do you think this would work in this situation? Another option would be to write separately programs, perhaps even in C, and spawn these in the background when needed. I'm a little torn as to which way to go. If it makes a difference and more in case you are wondering, I will be interfacing to the GPIOs, cameras and I2C bus through a set of C DLLs using Ctypes. Any help or suggestions will be greatly appreciated, Thanks very much, Jack -------------- next part -------------- An HTML attachment was scrubbed... URL: From marduk at letterboxes.org Tue Nov 30 22:22:01 2010 From: marduk at letterboxes.org (Albert Hopkins) Date: Tue, 30 Nov 2010 22:22:01 -0500 Subject: Python 3 encoding question: Read a filename from stdin, subsequently open that filename In-Reply-To: <4CF5AF71.3090705@mrabarnett.plus.com> References: <1291124813.414884.22.camel@WOPR> <4CF5AF71.3090705@mrabarnett.plus.com> Message-ID: <1291173721.687410.18.camel@WOPR> On Wed, 2010-12-01 at 02:14 +0000, MRAB wrote: > If the filenames are to be shown to a user then there needs to be a > mapping between bytes and glyphs. That's an encoding. If different > users use different encodings then exchange of textual data becomes > difficult. That's presentation, that's separate. Indeed, I have my user encoding set to UTF-8, and if there is a filename that's not valid utf-8 then my GUI (GNOME will show "(invalid encoding)" and even allow me to rename it and my shell (bash) will show '?' next to the invalid "characters" (and make it a little more challenging to rename ;)). And I can freely copy these "invalid" files across different (Unix) systems, because the OS doesn't care about encoding. But that's completely different from the actual name of the file. Unix doesn't care about presentation in filenames. It just cares about the data. There are not "glyphs" in Unix, only in the UI that runs on top of it. Or to put it another way, Unix's filename encoding is RAW-DATA. It's not "textual" data. The fact that most filenames contain mainly human-readable text is a convenient convention, but not required or enforced by the OS. > That's where encodings which can be used globally come in. > By the time Python 4 is released I'd be surprised if Unix hadn't > standardised on a single encoding like UTF-8. I have serious doubts about that. At least in the Linux world the kernel wants to stay out of encoding debates (except where it has to like Window filesystems). But the point is that: The world does not revolve around Python. Unix filenames have been encoding-agnostic long before Python was around. If Python3 does not support this then it's a regression on Python's part. From steve at holdenweb.com Tue Nov 30 22:52:14 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 30 Nov 2010 22:52:14 -0500 Subject: Change one list item in place In-Reply-To: <4CF5A4AB.7090600@mrabarnett.plus.com> References: <17175f49-087f-4d05-ada2-7e8c7e7e86dd@z17g2000prz.googlegroups.com> <4CF5A4AB.7090600@mrabarnett.plus.com> Message-ID: On 11/30/2010 8:28 PM, MRAB wrote: > On 01/12/2010 01:08, Gnarlodious wrote: >> This works for me: >> >> def sendList(): >> return ["item0", "item1"] >> >> def query(): >> l=sendList() >> return ["Formatting only {0} into a string".format(l[0]), l[1]] >> >> query() >> >> >> However, is there a way to bypass the >> >> l=sendList() >> >> and change one list item in-place? Possibly a list comprehension >> operating on a numbered item? >> > There's this: > > return ["Formatting only {0} into a string".format(x) if i == 0 else > x for i, x in enumerate(sendList())] > > but that's too clever for its own good. Keep it simple. :-) I quite agree. That solution is so clever it would be asking for a fight walking into a bar in Glasgow. However, an unpacking assignment can make everything much more comprehensible [pun intended] by removing the index operations. The canonical solution would be something like: def query(): x, y = sendList() return ["Formatting only {0} into a string".format(x), y] regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/